quickerNES/source/nesInstanceBase.hpp

130 lines
4.3 KiB
C++
Raw Normal View History

2024-01-10 18:48:57 +00:00
#pragma once
#include "logger.hpp"
#include "controller.hpp"
2024-01-10 18:48:57 +00:00
#define _LOW_MEM_SIZE 0x800
#define _HIGH_MEM_SIZE 0x2000
2024-01-12 20:13:51 +00:00
#define _NAMETABLES_MEM_SIZE 0x1000
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:
NESInstanceBase() = default;
virtual ~NESInstanceBase() = default;
2024-01-20 10:21:34 +00:00
inline void advanceState(const std::string &move)
2024-01-20 10:21:34 +00:00
{
bool isInputValid = _controller.parseInputString(move);
if (isInputValid == false) EXIT_WITH_ERROR("Move provided cannot be parsed: '%s'\n", move.c_str());
// Parsing power
if (_controller.getPowerButtonState() == true) EXIT_WITH_ERROR("Power button pressed, but not supported: '%s'\n", move.c_str());
// Parsing reset
if (_controller.getResetButtonState() == true) doSoftReset();
// Parsing Controllers
const auto controller1 = _controller.getController1Code();
const auto controller2 = _controller.getController2Code();
advanceStateImpl(controller1, controller2);
2024-01-20 10:21:34 +00:00
}
2024-01-10 18:48:57 +00:00
inline void setController1Type(const std::string& type)
2024-01-20 10:21:34 +00:00
{
bool isTypeRecognized = false;
if (type == "None") { _controller.setController1Type(Controller::controller_t::none); isTypeRecognized = true; }
if (type == "Joypad") { _controller.setController1Type(Controller::controller_t::joypad); isTypeRecognized = true; }
if (type == "FourScore1") { _controller.setController1Type(Controller::controller_t::fourscore1); isTypeRecognized = true; }
if (type == "FourScore2") { _controller.setController1Type(Controller::controller_t::fourscore2); isTypeRecognized = true; }
if (isTypeRecognized == false) EXIT_WITH_ERROR("Input type not recognized: '%s'\n", type.c_str());
2024-01-20 10:21:34 +00:00
}
2024-01-10 19:11:49 +00:00
inline void setController2Type(const std::string& type)
2024-01-20 10:21:34 +00:00
{
bool isTypeRecognized = false;
if (type == "None") { _controller.setController2Type(Controller::controller_t::none); isTypeRecognized = true; }
if (type == "Joypad") { _controller.setController2Type(Controller::controller_t::joypad); isTypeRecognized = true; }
if (type == "FourScore1") { _controller.setController2Type(Controller::controller_t::fourscore1); isTypeRecognized = true; }
if (type == "FourScore2") { _controller.setController2Type(Controller::controller_t::fourscore2); isTypeRecognized = true; }
if (isTypeRecognized == false) EXIT_WITH_ERROR("Input type not recognized: '%s'\n", type.c_str());
2024-01-20 10:21:34 +00:00
}
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
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
_stateSize = getStateSize();
// Returning status
return status;
}
void enableStateBlock(const std::string& block)
{
// Calling implementation
enableStateBlockImpl(block);
// Recalculating State size
_stateSize = getStateSize();
}
void disableStateBlock(const std::string& block)
{
// Calling implementation
disableStateBlockImpl(block);
2024-01-20 10:21:34 +00:00
// Recalculating State Size
_stateSize = getStateSize();
2024-01-20 10:21:34 +00:00
}
// Virtual functions
virtual uint8_t *getLowMem() const = 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 deserializeState(const uint8_t *state) = 0;
virtual size_t getStateSize() const = 0;
2024-01-20 10:21:34 +00:00
virtual void doSoftReset() = 0;
virtual void doHardReset() = 0;
virtual std::string getCoreName() const = 0;
virtual void *getInternalEmulatorPointer() const = 0;
protected:
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;
virtual void advanceStateImpl(const Controller::port_t controller1, const Controller::port_t controller2) = 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;
private:
// Controller class for input parsing
Controller _controller;
2024-01-10 18:48:57 +00:00
};