2018-02-01 23:19:34 +00:00
|
|
|
#ifndef __URDE_CNESEMULATOR_HPP__
|
|
|
|
#define __URDE_CNESEMULATOR_HPP__
|
|
|
|
|
|
|
|
#include "RetroTypes.hpp"
|
|
|
|
#include "zeus/CColor.hpp"
|
|
|
|
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
|
|
|
|
#include "boo/audiodev/IAudioVoice.hpp"
|
|
|
|
#include "zeus/CMatrix4f.hpp"
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
2018-02-04 06:46:47 +00:00
|
|
|
struct CFinalInput;
|
2018-02-01 23:19:34 +00:00
|
|
|
class IDvdRequest;
|
|
|
|
|
|
|
|
namespace MP1
|
|
|
|
{
|
|
|
|
|
|
|
|
#define NUM_AUDIO_BUFFERS 10
|
|
|
|
|
|
|
|
class CNESEmulator : public boo::IAudioVoiceCallback
|
|
|
|
{
|
2018-02-03 00:35:19 +00:00
|
|
|
public:
|
|
|
|
enum class EPasswordEntryState
|
|
|
|
{
|
|
|
|
NotPasswordScreen,
|
|
|
|
NotEntered,
|
|
|
|
Entered
|
|
|
|
};
|
|
|
|
private:
|
2018-02-01 23:19:34 +00:00
|
|
|
static bool EmulatorConstructed;
|
|
|
|
|
|
|
|
std::unique_ptr<u8[]> m_nesEmuPBuf;
|
|
|
|
std::shared_ptr<IDvdRequest> m_dvdReq;
|
|
|
|
|
|
|
|
struct Vert
|
|
|
|
{
|
|
|
|
zeus::CVector3f m_pos;
|
|
|
|
zeus::CVector2f m_uv;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Uniform
|
|
|
|
{
|
|
|
|
zeus::CMatrix4f m_matrix;
|
|
|
|
zeus::CColor m_color;
|
|
|
|
};
|
|
|
|
|
|
|
|
boo::ObjToken<boo::ITextureD> m_texture;
|
|
|
|
boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
|
|
|
|
boo::ObjToken<boo::IGraphicsBufferS> m_vbo;
|
|
|
|
boo::ObjToken<boo::IShaderDataBinding> m_shadBind;
|
|
|
|
|
|
|
|
std::unique_ptr<u8[]> m_audioBufBlock;
|
|
|
|
u8* m_audioBufs[NUM_AUDIO_BUFFERS];
|
|
|
|
int m_headBuf = 0;
|
|
|
|
int m_tailBuf = 0;
|
|
|
|
int m_procBufs = NUM_AUDIO_BUFFERS;
|
|
|
|
size_t m_posInBuf = 0;
|
|
|
|
boo::ObjToken<boo::IAudioVoice> m_booVoice;
|
|
|
|
|
2018-02-03 00:35:19 +00:00
|
|
|
bool x20_gameOver = false;
|
|
|
|
u8 x21_passwordFromNES[18];
|
|
|
|
EPasswordEntryState x34_passwordEntryState = EPasswordEntryState::NotPasswordScreen;
|
|
|
|
bool x38_passwordPending = false;
|
|
|
|
u8 x39_passwordToNES[18];
|
2018-02-01 23:19:34 +00:00
|
|
|
static void DecompressROM(u8* dataIn, u8* dataOut, u32 dataOutLen = 0x20000, u8 descrambleSeed = 0xe9,
|
|
|
|
u32 checkDataLen = 0x1FFFC, u32 checksumMagic = 0xA663);
|
|
|
|
void InitializeEmulator();
|
|
|
|
void DeinitializeEmulator();
|
2018-02-03 03:00:21 +00:00
|
|
|
void NesEmuMainLoop(bool forceDraw = false);
|
2018-02-03 00:35:19 +00:00
|
|
|
static bool CheckForGameOver(const u8* vram, u8* passwordOut = nullptr);
|
|
|
|
static EPasswordEntryState CheckForPasswordEntryScreen(const uint8_t* vram);
|
|
|
|
static bool SetPasswordIntoEntryScreen(u8* vram, u8* wram, const u8* password);
|
2018-02-01 23:19:34 +00:00
|
|
|
public:
|
|
|
|
CNESEmulator();
|
|
|
|
~CNESEmulator();
|
|
|
|
void ProcessUserInput(const CFinalInput& input, int);
|
|
|
|
void Update();
|
|
|
|
void Draw(const zeus::CColor& mulColor, bool filtering);
|
2018-02-03 00:35:19 +00:00
|
|
|
void LoadPassword(const u8* state);
|
|
|
|
const u8* GetPassword() const { return x21_passwordFromNES; }
|
|
|
|
bool IsGameOver() const { return x20_gameOver; }
|
|
|
|
EPasswordEntryState GetPasswordEntryState() const { return x34_passwordEntryState; }
|
2018-02-01 23:19:34 +00:00
|
|
|
|
|
|
|
int audioUpdate();
|
|
|
|
void preSupplyAudio(boo::IAudioVoice& voice, double dt) {}
|
|
|
|
size_t supplyAudio(boo::IAudioVoice& voice, size_t frames, int16_t* data);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __URDE_CNESEMULATOR_HPP__
|