quickerNES/source/nesInstanceBase.hpp

90 lines
2.5 KiB
C++
Raw Normal View History

2024-01-10 18:48:57 +00:00
#pragma once
2024-07-28 14:52:05 +00:00
#include "inputParser.hpp"
#include "jaffarCommon/logger.hpp"
2024-03-06 15:21:04 +00:00
#include "jaffarCommon/serializers/contiguous.hpp"
#include "jaffarCommon/serializers/differential.hpp"
2024-07-28 14:54:26 +00:00
#include "jaffarCommon/deserializers/base.hpp"
2024-01-10 18:48:57 +00:00
// Size of image generated in graphics buffer
2024-01-20 10:21:34 +00:00
static const uint16_t image_width = 256;
static const uint16_t image_height = 240;
class NESInstanceBase
2024-01-10 18:48:57 +00:00
{
2024-01-20 10:21:34 +00:00
public:
2024-07-28 14:52:05 +00:00
NESInstanceBase(const nlohmann::json &config)
{
2024-07-28 14:43:09 +00:00
_inputParser = std::make_unique<jaffar::InputParser>(config);
}
2024-07-28 14:43:09 +00:00
virtual ~NESInstanceBase() = default;
2024-01-10 19:11:49 +00:00
2024-07-28 14:43:09 +00:00
virtual void advanceState(const jaffar::input_t &input) = 0;
2024-01-10 18:48:57 +00:00
2024-01-20 10:21:34 +00:00
inline void enableRendering() { _doRendering = true; };
inline void disableRendering() { _doRendering = false; };
2024-01-10 18:48:57 +00:00
2024-07-28 14:52:05 +00:00
inline bool loadROM(const uint8_t *romData, const size_t romSize)
2024-01-20 10:21:34 +00:00
{
// Actually loading rom file
auto status = loadROMImpl(romData, romSize);
2024-01-20 10:21:34 +00:00
// Detecting full state size
2024-02-09 19:43:42 +00:00
_stateSize = getFullStateSize();
// Returning status
return status;
}
2024-07-28 14:52:05 +00:00
void enableStateBlock(const std::string &block)
{
// Calling implementation
enableStateBlockImpl(block);
// Recalculating State size
2024-02-09 19:43:42 +00:00
_stateSize = getFullStateSize();
}
2024-07-28 14:52:05 +00:00
void disableStateBlock(const std::string &block)
{
// Calling implementation
disableStateBlockImpl(block);
2024-01-20 10:21:34 +00:00
// Recalculating State Size
2024-02-09 19:43:42 +00:00
_stateSize = getFullStateSize();
2024-01-20 10:21:34 +00:00
}
2024-02-09 19:43:42 +00:00
virtual size_t getFullStateSize() const = 0;
virtual size_t getDifferentialStateSize() const = 0;
2024-07-28 14:52:05 +00:00
inline jaffar::InputParser *getInputParser() const { return _inputParser.get(); }
2024-01-20 10:21:34 +00:00
// Virtual functions
2024-01-29 18:47:52 +00:00
virtual uint8_t *getLowMem() const = 0;
virtual size_t getLowMemSize() const = 0;
2024-01-28 18:57:24 +00:00
2024-07-28 14:52:05 +00:00
virtual void serializeState(jaffarCommon::serializer::Base &serializer) const = 0;
virtual void deserializeState(jaffarCommon::deserializer::Base &deserializer) = 0;
2024-02-06 16:54:39 +00:00
2024-01-20 10:21:34 +00:00
virtual void doSoftReset() = 0;
virtual void doHardReset() = 0;
virtual std::string getCoreName() const = 0;
2024-01-28 18:57:24 +00:00
virtual void *getInternalEmulatorPointer() = 0;
2024-07-28 14:52:05 +00:00
virtual void setNTABBlockSize(const size_t size) {};
2024-01-20 10:21:34 +00:00
protected:
2024-07-28 14:52:05 +00:00
virtual void enableStateBlockImpl(const std::string &block) = 0;
virtual void disableStateBlockImpl(const std::string &block) = 0;
virtual bool loadROMImpl(const uint8_t *romData, const size_t romSize) = 0;
2024-01-20 10:21:34 +00:00
// Storage for the light state size
size_t _stateSize;
2024-01-20 10:21:34 +00:00
// Flag to determine whether to enable/disable rendering
bool _doRendering = true;
2024-07-28 14:43:09 +00:00
// Input parser instance
std::unique_ptr<jaffar::InputParser> _inputParser;
2024-01-10 18:48:57 +00:00
};