#pragma once // TBD: The API will be extended to handle I/O devices (controllers, expansion ports) namespace Breaknes { struct RGB_Triplet { uint8_t r; uint8_t g; uint8_t b; }; class Board { protected: // These basic chips are on all variations of motherboards, so we make them available to all inherited classes. M6502Core::M6502* core = nullptr; APUSim::APU* apu = nullptr; PPUSim::PPU* ppu = nullptr; BaseLogic::TriState CLK = BaseLogic::TriState::Zero; // CPU Bus uint8_t data_bus = 0; bool data_bus_dirty = false; uint16_t addr_bus = 0; APUSim::AudioOutSignal aux{}; PPUSim::VideoOutSignal vidSample{}; // The cartridge slot supports hotplugging during simulation. Mappers::AbstractCartridge* cart = nullptr; Mappers::ConnectorType p1_type = Mappers::ConnectorType::None; // Pre-calculated PPU palette RGB_Triplet* pal = nullptr; bool pal_cached = false; BaseLogic::TriState gnd = BaseLogic::TriState::Zero; BaseLogic::TriState vdd = BaseLogic::TriState::One; public: Board(APUSim::Revision apu_rev, PPUSim::Revision ppu_rev, Mappers::ConnectorType p1); virtual ~Board(); /// /// Simulate 1 half cycle of the board. The simulation of the signal edge is not supported, this is overkill. /// virtual void Step() = 0; /// /// "Insert" the cartridge as a .nes ROM. In this implementation we are simply trying to instantiate an NROM, but in a more advanced emulation, Cartridge Factory will take care of "inserting" the cartridge. /// /// A pointer to the ROM image in memory. /// ROM image size in bytes. /// virtual int InsertCartridge(uint8_t* nesImage, size_t nesImageSize); /// /// Remove the cartridge. Logically this means that all terminals associated with the cartridge take the value of `z`. /// virtual void EjectCartridge(); /// /// Make the board /RES pins = 0 for a few CLK half cycles so that the APU/PPU resets all of its internal circuits. /// virtual void Reset(); /// /// The parent application can check that the board is in the reset process and ignore the audio/video signal for that time. /// /// virtual bool InResetState(); /// /// Get the values of the ACLK cycle counter. /// /// virtual size_t GetACLKCounter(); /// /// Get the value of the 6502 core cycle counter (PHI Counter) /// /// virtual size_t GetPHICounter(); /// /// Get the current resulting AUX value in normalized [0.0; 1.0] format. /// /// virtual void SampleAudioSignal(float* sample); /// /// Load APU/PPU registers dump (APUPlayer/PPUPlayer only) /// /// RegDumpEntry records /// Dump size (bytes) virtual void LoadRegDump(uint8_t* data, size_t data_size); /// /// Get audio signal settings that help with its rendering on the consumer side. /// /// virtual void GetApuSignalFeatures(APUSim::AudioSignalFeatures* features); /// /// Get the "pixel" counter. Keep in mind that pixels refers to an abstract entity representing the visible or invisible part of the video signal. /// /// virtual size_t GetPCLKCounter(); /// /// Get 1 sample of the video signal. /// /// virtual void SampleVideoSignal(PPUSim::VideoOutSignal* sample); /// /// Get the direct value from the PPU H counter. /// /// virtual size_t GetHCounter(); /// /// Get the direct value from the PPU V counter. /// /// virtual size_t GetVCounter(); /// /// Forcibly enable rendering ($2001[3] = $2001[4] always equals 1). /// Used for debugging PPU signals, when the CPU I/F register dump is limited, or when you want to get faster simulation results. /// Keep in mind that with permanently enabled rendering the PPU becomes unstable and this hack should be applied when you know what you're doing. /// /// virtual void RenderAlwaysEnabled(bool enable); /// /// Get video signal settings that help with its rendering on the consumer side. /// /// virtual void GetPpuSignalFeatures(PPUSim::VideoSignalFeatures* features); /// /// Convert the raw color to RGB. Can be used for palette generation or PPU video output in RAW mode. /// The SYNC level (RAW.Sync) check must be done from the outside. /// virtual void ConvertRAWToRGB(uint16_t raw, uint8_t* r, uint8_t* g, uint8_t* b); /// /// Use RAW color output. /// RAW color refers to the Chroma/Luma combination that comes to the video generator and the Emphasis bit combination. /// /// virtual void SetRAWColorMode(bool enable); /// /// Set one of the ways to decay OAM cells. /// virtual void SetOamDecayBehavior(PPUSim::OAMDecayBehavior behavior); /// /// Set the noise for the composite video signal (in volts). /// /// virtual void SetNoiseLevel(float volts); /// /// Return all core debugging information for BreaksDebug. /// /// virtual void GetAllCoreDebugInfo(M6502Core::DebugInfo* info); }; }