More simplfiication

This commit is contained in:
Sergio Martin 2024-01-28 19:57:24 +01:00
parent b07f5521af
commit 2a7dfdc74a
5 changed files with 62 additions and 81 deletions

View File

@ -95,11 +95,8 @@ class NESInstanceBase
// Virtual functions // Virtual functions
virtual uint8_t *getLowMem() const = 0; virtual uint8_t *getLowMem() = 0;
virtual uint8_t *getNametableMem() const = 0;
virtual uint8_t *getHighMem() const = 0;
virtual const uint8_t *getChrMem() const = 0;
virtual size_t getChrMemSize() const = 0;
virtual void serializeState(uint8_t *state) const = 0; virtual void serializeState(uint8_t *state) const = 0;
virtual void deserializeState(const uint8_t *state) = 0; virtual void deserializeState(const uint8_t *state) = 0;
virtual size_t getStateSize() const = 0; virtual size_t getStateSize() const = 0;
@ -107,7 +104,7 @@ class NESInstanceBase
virtual void doSoftReset() = 0; virtual void doSoftReset() = 0;
virtual void doHardReset() = 0; virtual void doHardReset() = 0;
virtual std::string getCoreName() const = 0; virtual std::string getCoreName() const = 0;
virtual void *getInternalEmulatorPointer() const = 0; virtual void *getInternalEmulatorPointer() = 0;
protected: protected:

View File

@ -39,6 +39,12 @@ class PlaybackInstance
// Initializes the playback module instance // Initializes the playback module instance
PlaybackInstance(NESInstance *emu, const std::vector<std::string> &sequence, const std::string &overlayPath = "") : _emu(emu) PlaybackInstance(NESInstance *emu, const std::vector<std::string> &sequence, const std::string &overlayPath = "") : _emu(emu)
{ {
// Allocating video buffer
_video_buffer = (uint8_t *)malloc(image_width * image_height);
// Setting video buffer
((emulator_t*)_emu->getInternalEmulatorPointer())->set_pixels(_video_buffer, image_width + 8);
// Enabling emulation rendering // Enabling emulation rendering
_emu->enableRendering(); _emu->enableRendering();
@ -224,6 +230,7 @@ class PlaybackInstance
} }
private: private:
// Internal sequence information // Internal sequence information
std::vector<stepData_t> _stepSequence; std::vector<stepData_t> _stepSequence;
@ -239,6 +246,9 @@ class PlaybackInstance
// Flag to store whether to use the button overlay // Flag to store whether to use the button overlay
bool _useOverlay = false; bool _useOverlay = false;
// Video buffer
uint8_t *_video_buffer;
// Overlay info // Overlay info
std::string _overlayPath; std::string _overlayPath;
SDL_Surface *_overlayBaseSurface = NULL; SDL_Surface *_overlayBaseSurface = NULL;

View File

@ -12,56 +12,31 @@ extern void register_misc_mappers();
extern void register_extra_mappers(); extern void register_extra_mappers();
extern void register_mapper_70(); extern void register_mapper_70();
class NESInstance : public NESInstanceBase class NESInstance final : public NESInstanceBase
{ {
public: public:
NESInstance() : NESInstanceBase() NESInstance() : NESInstanceBase()
{ {
// Creating new emulator
_nes = new Nes_Emu;
// Allocating video buffer
video_buffer = (uint8_t *)malloc(image_width * image_height);
// Setting video buffer
_nes->set_pixels(video_buffer, image_width + 8);
// If running the original QuickNES, register extra mappers now // If running the original QuickNES, register extra mappers now
register_misc_mappers(); register_misc_mappers();
register_extra_mappers(); register_extra_mappers();
register_mapper_70(); register_mapper_70();
} }
virtual bool loadROMImpl(const uint8_t* romData, const size_t romSize) override uint8_t *getLowMem() override { return _nes.low_mem(); };
{
// Loading rom data
Mem_File_Reader romReader(romData, (int)romSize);
Auto_File_Reader romFile(romReader);
auto result = _nes->load_ines(romFile);
return result == 0;
}
uint8_t *getLowMem() const override { return _nes->low_mem(); };
uint8_t *getNametableMem() const override { return _nes->nametable_mem(); };
uint8_t *getHighMem() const override { return _nes->high_mem(); };
const uint8_t *getChrMem() const override { return _nes->chr_mem(); };
size_t getChrMemSize() const override { return _nes->chr_size(); };
void enableStateBlockImpl(const std::string& block) override {};
void disableStateBlockImpl(const std::string& block) override {};
void serializeState(uint8_t *state) const override void serializeState(uint8_t *state) const override
{ {
Mem_Writer w(state, _stateSize, 0); Mem_Writer w(state, _stateSize, 0);
Auto_File_Writer a(w); Auto_File_Writer a(w);
_nes->save_state(a); _nes.save_state(a);
} }
void deserializeState(const uint8_t *state) override void deserializeState(const uint8_t *state) override
{ {
Mem_File_Reader r(state, _stateSize); Mem_File_Reader r(state, _stateSize);
Auto_File_Reader a(r); Auto_File_Reader a(r);
_nes->load_state(a); _nes.load_state(a);
} }
inline size_t getStateSize() const override inline size_t getStateSize() const override
@ -69,28 +44,39 @@ class NESInstance : public NESInstanceBase
uint8_t *data = (uint8_t *)malloc(_DUMMY_SIZE); uint8_t *data = (uint8_t *)malloc(_DUMMY_SIZE);
Mem_Writer w(data, _DUMMY_SIZE); Mem_Writer w(data, _DUMMY_SIZE);
Auto_File_Writer a(w); Auto_File_Writer a(w);
_nes->save_state(a); _nes.save_state(a);
free(data); free(data);
return w.size(); return w.size();
} }
void advanceStateImpl(const Controller::port_t controller1, const Controller::port_t controller2) override std::string getCoreName() const override { return "QuickNES"; }
void doSoftReset() override { _nes.reset(false); }
void doHardReset() override { _nes.reset(true); }
void *getInternalEmulatorPointer() override { return &_nes; }
protected:
bool loadROMImpl(const uint8_t* romData, const size_t romSize) override
{ {
if (_doRendering == true) _nes->emulate_frame(controller1, controller2); // Loading rom data
if (_doRendering == false) _nes->emulate_skip_frame(controller1, controller2); Mem_File_Reader romReader(romData, (int)romSize);
Auto_File_Reader romFile(romReader);
auto result = _nes.load_ines(romFile);
return result == 0;
} }
std::string getCoreName() const override { return "QuickNES"; } void enableStateBlockImpl(const std::string& block) override {};
void doSoftReset() override { _nes->reset(false); } void disableStateBlockImpl(const std::string& block) override {};
void doHardReset() override { _nes->reset(true); }
void *getInternalEmulatorPointer() const override { return _nes; } void advanceStateImpl(const Controller::port_t controller1, const Controller::port_t controller2) override
{
if (_doRendering == true) _nes.emulate_frame(controller1, controller2);
if (_doRendering == false) _nes.emulate_skip_frame(controller1, controller2);
}
private: private:
// Video buffer
uint8_t *video_buffer;
// Emulator instance // Emulator instance
Nes_Emu *_nes; emulator_t _nes;
}; };

View File

@ -5,57 +5,45 @@
typedef quickerNES::Emu emulator_t; typedef quickerNES::Emu emulator_t;
class NESInstance : public NESInstanceBase class NESInstance final : public NESInstanceBase
{ {
public: public:
NESInstance() : NESInstanceBase()
{
// Creating new emulator
_nes = new emulator_t;
// Allocating video buffer uint8_t *getLowMem() override { return _nes.low_mem(); };
video_buffer = (uint8_t *)malloc(image_width * image_height);
// Setting video buffer void serializeState(uint8_t *state) const override { _nes.serializeState(state); }
_nes->set_pixels(video_buffer, image_width + 8); void deserializeState(const uint8_t *state) override { _nes.deserializeState(state); }
} size_t getStateSize() const override { return _nes.getStateSize(); }
~NESInstance() = default; std::string getCoreName() const override { return "QuickerNES"; }
virtual bool loadROMImpl(const uint8_t* romData, const size_t romSize) override void doSoftReset() override { _nes.reset(false); }
void doHardReset() override { _nes.reset(true); }
void *getInternalEmulatorPointer() override { return &_nes; }
protected:
bool loadROMImpl(const uint8_t* romData, const size_t romSize) override
{ {
// Loading rom data // Loading rom data
_nes->load_ines(romData); _nes.load_ines(romData);
return true; return true;
} }
uint8_t *getLowMem() const override { return _nes->low_mem(); }; void enableStateBlockImpl(const std::string& block) override { _nes.enableStateBlock(block); };
uint8_t *getNametableMem() const override { return _nes->nametable_mem(); }; void disableStateBlockImpl(const std::string& block) override { _nes.disableStateBlock(block); };
uint8_t *getHighMem() const override { return _nes->high_mem(); };
const uint8_t *getChrMem() const override { return _nes->chr_mem(); };
size_t getChrMemSize() const override { return _nes->chr_size(); };
void serializeState(uint8_t *state) const override { _nes->serializeState(state); }
void deserializeState(const uint8_t *state) override { _nes->deserializeState(state); }
size_t getStateSize() const override { return _nes->getStateSize(); }
void enableStateBlockImpl(const std::string& block) override { _nes->enableStateBlock(block); };
void disableStateBlockImpl(const std::string& block) override { _nes->disableStateBlock(block); };
void advanceStateImpl(const Controller::port_t controller1, const Controller::port_t controller2) override void advanceStateImpl(const Controller::port_t controller1, const Controller::port_t controller2) override
{ {
if (_doRendering == true) _nes->emulate_frame(controller1, controller2); if (_doRendering == true) _nes.emulate_frame(controller1, controller2);
if (_doRendering == false) _nes->emulate_skip_frame(controller1, controller2); if (_doRendering == false) _nes.emulate_skip_frame(controller1, controller2);
} }
std::string getCoreName() const override { return "QuickerNES"; } private:
void doSoftReset() override { _nes->reset(false); }
void doHardReset() override { _nes->reset(true); }
void *getInternalEmulatorPointer() const override { return _nes; }
// Video buffer // Video buffer
uint8_t *video_buffer; uint8_t *video_buffer;
// Emulator instance // Emulator instance
emulator_t *_nes; emulator_t _nes;
}; };

View File

@ -167,7 +167,7 @@ inline hash_t calculateMetroHash(uint8_t *data, size_t size)
return result; return result;
} }
inline hash_t calculateStateHash(const NESInstance* nes) inline hash_t calculateStateHash(NESInstance* nes)
{ {
return calculateMetroHash(nes->getLowMem(), _LOW_MEM_SIZE); return calculateMetroHash(nes->getLowMem(), _LOW_MEM_SIZE);
} }