From c7f1c233ca4f97ab20f1ce5d7897f2915a601be4 Mon Sep 17 00:00:00 2001 From: SergioMartin86 Date: Sun, 28 Jul 2024 16:52:05 +0200 Subject: [PATCH] Fixing style and inputs --- source/inputParser.hpp | 88 +- source/nesInstanceBase.hpp | 32 +- source/playbackInstance.hpp | 13 +- source/player.cpp | 8 +- source/quickNES/nesInstance.hpp | 24 +- .../quickerNES/core/apu/NESEffectsBuffer.cpp | 2 +- .../quickerNES/core/apu/NESEffectsBuffer.hpp | 4 +- source/quickerNES/core/apu/apu.cpp | 4 +- source/quickerNES/core/apu/apu.hpp | 4 +- source/quickerNES/core/apu/blipBuffer.cpp | 4 +- source/quickerNES/core/apu/blipBuffer.hpp | 2 +- source/quickerNES/core/apu/buffer.cpp | 2 +- source/quickerNES/core/apu/buffer.hpp | 4 +- source/quickerNES/core/apu/effectsBuffer.cpp | 4 +- source/quickerNES/core/apu/effectsBuffer.hpp | 6 +- source/quickerNES/core/apu/fme7/apu_fme7.cpp | 2 +- source/quickerNES/core/apu/fme7/apu_fme7.hpp | 4 +- source/quickerNES/core/apu/multiBuffer.cpp | 4 +- source/quickerNES/core/apu/multiBuffer.hpp | 2 +- .../quickerNES/core/apu/namco/apu_namco.cpp | 2 +- .../quickerNES/core/apu/namco/apu_namco.hpp | 4 +- source/quickerNES/core/apu/oscs.cpp | 2 +- source/quickerNES/core/apu/oscs.hpp | 2 +- source/quickerNES/core/apu/vrc6/apu_vrc6.cpp | 2 +- source/quickerNES/core/apu/vrc6/apu_vrc6.hpp | 6 +- source/quickerNES/core/apu/vrc7/apu_vrc7.cpp | 4 +- source/quickerNES/core/apu/vrc7/apu_vrc7.hpp | 4 +- source/quickerNES/core/apu/vrc7/emu2413.cpp | 6 +- source/quickerNES/core/apu/vrc7/emu2413.hpp | 2 +- .../core/apu/vrc7/emu2413_state.hpp | 4 +- source/quickerNES/core/cart.hpp | 2 +- source/quickerNES/core/core.hpp | 236 +- source/quickerNES/core/cpu.cpp | 2342 ++++++++++------- source/quickerNES/core/cpu.hpp | 5 +- source/quickerNES/core/emu.cpp | 1050 +++++--- source/quickerNES/core/emu.hpp | 40 +- source/quickerNES/core/mappers/mapper.cpp | 2 +- source/quickerNES/core/mappers/mapper.hpp | 4 +- source/quickerNES/core/mappers/mapper000.hpp | 2 +- source/quickerNES/core/mappers/mapper001.hpp | 2 +- source/quickerNES/core/mappers/mapper002.hpp | 2 +- source/quickerNES/core/mappers/mapper003.hpp | 2 +- source/quickerNES/core/mappers/mapper004.hpp | 2 +- source/quickerNES/core/mappers/mapper005.hpp | 2 +- source/quickerNES/core/mappers/mapper007.hpp | 2 +- source/quickerNES/core/mappers/mapper009.hpp | 2 +- source/quickerNES/core/mappers/mapper010.hpp | 2 +- source/quickerNES/core/mappers/mapper011.hpp | 2 +- source/quickerNES/core/mappers/mapper015.hpp | 2 +- source/quickerNES/core/mappers/mapper019.hpp | 2 +- source/quickerNES/core/mappers/mapper021.hpp | 2 +- source/quickerNES/core/mappers/mapper022.hpp | 2 +- source/quickerNES/core/mappers/mapper023.hpp | 2 +- source/quickerNES/core/mappers/mapper024.hpp | 2 +- source/quickerNES/core/mappers/mapper025.hpp | 2 +- source/quickerNES/core/mappers/mapper026.hpp | 2 +- source/quickerNES/core/mappers/mapper030.hpp | 2 +- source/quickerNES/core/mappers/mapper032.hpp | 2 +- source/quickerNES/core/mappers/mapper033.hpp | 2 +- source/quickerNES/core/mappers/mapper034.hpp | 2 +- source/quickerNES/core/mappers/mapper060.hpp | 2 +- source/quickerNES/core/mappers/mapper066.hpp | 2 +- source/quickerNES/core/mappers/mapper069.hpp | 2 +- source/quickerNES/core/mappers/mapper070.hpp | 2 +- source/quickerNES/core/mappers/mapper071.hpp | 2 +- source/quickerNES/core/mappers/mapper073.hpp | 2 +- source/quickerNES/core/mappers/mapper075.hpp | 2 +- source/quickerNES/core/mappers/mapper078.hpp | 2 +- source/quickerNES/core/mappers/mapper079.hpp | 2 +- source/quickerNES/core/mappers/mapper085.hpp | 2 +- source/quickerNES/core/mappers/mapper086.hpp | 2 +- source/quickerNES/core/mappers/mapper087.hpp | 2 +- source/quickerNES/core/mappers/mapper088.hpp | 3 +- source/quickerNES/core/mappers/mapper089.hpp | 2 +- source/quickerNES/core/mappers/mapper093.hpp | 2 +- source/quickerNES/core/mappers/mapper094.hpp | 2 +- source/quickerNES/core/mappers/mapper097.hpp | 2 +- source/quickerNES/core/mappers/mapper113.hpp | 2 +- source/quickerNES/core/mappers/mapper140.hpp | 2 +- source/quickerNES/core/mappers/mapper152.hpp | 2 +- source/quickerNES/core/mappers/mapper154.hpp | 2 +- source/quickerNES/core/mappers/mapper156.hpp | 2 +- source/quickerNES/core/mappers/mapper180.hpp | 2 +- source/quickerNES/core/mappers/mapper184.hpp | 2 +- source/quickerNES/core/mappers/mapper190.hpp | 2 +- source/quickerNES/core/mappers/mapper193.hpp | 2 +- source/quickerNES/core/mappers/mapper206.hpp | 2 +- source/quickerNES/core/mappers/mapper207.hpp | 2 +- source/quickerNES/core/mappers/mapper232.hpp | 2 +- source/quickerNES/core/mappers/mapper240.hpp | 2 +- source/quickerNES/core/mappers/mapper241.hpp | 2 +- source/quickerNES/core/mappers/mapper244.hpp | 2 +- source/quickerNES/core/mappers/mapper246.hpp | 2 +- source/quickerNES/core/ppu/ppu.cpp | 4 +- source/quickerNES/core/ppu/ppu.hpp | 4 +- source/quickerNES/core/ppu/ppuImpl.cpp | 2 +- source/quickerNES/core/ppu/ppuImpl.hpp | 18 +- source/quickerNES/core/ppu/ppuRendering.cpp | 2 +- source/quickerNES/core/ppu/ppuRendering.hpp | 2 +- source/quickerNES/nesInstance.hpp | 26 +- source/tester.cpp | 64 +- tests/solarJetman.anyPercent.test | 2 +- 102 files changed, 2483 insertions(+), 1684 deletions(-) diff --git a/source/inputParser.hpp b/source/inputParser.hpp index 4f90543..d8641c4 100644 --- a/source/inputParser.hpp +++ b/source/inputParser.hpp @@ -4,10 +4,10 @@ // by eien86 #include -#include -#include #include #include +#include +#include namespace jaffar { @@ -22,12 +22,16 @@ struct input_t port_t port2 = 0; }; - class InputParser { -public: - - enum controller_t { none, joypad, fourscore1, fourscore2 }; + public: + enum controller_t + { + none, + joypad, + fourscore1, + fourscore2 + }; InputParser(const nlohmann::json &config) { @@ -35,10 +39,26 @@ public: { bool isTypeRecognized = false; const auto controller1Type = jaffarCommon::json::getString(config, "Controller 1 Type"); - if (controller1Type == "None") { _controller1Type = controller_t::none; isTypeRecognized = true; } - if (controller1Type == "Joypad") { _controller1Type = controller_t::joypad; isTypeRecognized = true; } - if (controller1Type == "FourScore1") { _controller1Type = controller_t::fourscore1; isTypeRecognized = true; } - if (controller1Type == "FourScore2") { _controller1Type = controller_t::fourscore2; isTypeRecognized = true; } + if (controller1Type == "None") + { + _controller1Type = controller_t::none; + isTypeRecognized = true; + } + if (controller1Type == "Joypad") + { + _controller1Type = controller_t::joypad; + isTypeRecognized = true; + } + if (controller1Type == "FourScore1") + { + _controller1Type = controller_t::fourscore1; + isTypeRecognized = true; + } + if (controller1Type == "FourScore2") + { + _controller1Type = controller_t::fourscore2; + isTypeRecognized = true; + } if (isTypeRecognized == false) JAFFAR_THROW_LOGIC("Controller 1 type not recognized: '%s'\n", controller1Type.c_str()); } @@ -46,16 +66,31 @@ public: { bool isTypeRecognized = false; const auto controller2Type = jaffarCommon::json::getString(config, "Controller 2 Type"); - if (controller2Type == "None") { _controller2Type = controller_t::none; isTypeRecognized = true; } - if (controller2Type == "Joypad") { _controller2Type = controller_t::joypad; isTypeRecognized = true; } - if (controller2Type == "FourScore1") { _controller2Type = controller_t::fourscore1; isTypeRecognized = true; } - if (controller2Type == "FourScore2") { _controller2Type = controller_t::fourscore2; isTypeRecognized = true; } + if (controller2Type == "None") + { + _controller2Type = controller_t::none; + isTypeRecognized = true; + } + if (controller2Type == "Joypad") + { + _controller2Type = controller_t::joypad; + isTypeRecognized = true; + } + if (controller2Type == "FourScore1") + { + _controller2Type = controller_t::fourscore1; + isTypeRecognized = true; + } + if (controller2Type == "FourScore2") + { + _controller2Type = controller_t::fourscore2; + isTypeRecognized = true; + } if (isTypeRecognized == false) JAFFAR_THROW_LOGIC("Controller 2 type not recognized: '%s'\n", controller2Type.c_str()); } - } - inline input_t parseInputString(const std::string& inputString) const + inline input_t parseInputString(const std::string &inputString) const { // Storage for the input input_t input; @@ -86,13 +121,12 @@ public: } private: - - static inline void reportBadInputString(const std::string& inputString) + static inline void reportBadInputString(const std::string &inputString) { JAFFAR_THROW_LOGIC("Could not decode input string: '%s'\n", inputString.c_str()); } - static void parseJoyPadInput(uint8_t& code, std::istringstream& ss, const std::string& inputString) + static void parseJoyPadInput(uint8_t &code, std::istringstream &ss, const std::string &inputString) { // Currently read character char c; @@ -141,16 +175,20 @@ public: if (c == 'A') code |= 0b00000001; } - static void parseControllerInputs(const controller_t type, port_t& port, std::istringstream& ss, const std::string& inputString) + static void parseControllerInputs(const controller_t type, port_t &port, std::istringstream &ss, const std::string &inputString) { // If no controller assigned then, its port is all zeroes. - if (type == controller_t::none) { port = 0; return; } + if (type == controller_t::none) + { + port = 0; + return; + } // Controller separator if (ss.get() != '|') reportBadInputString(inputString); // If normal joypad, parse its code now - if (type == controller_t::joypad) + if (type == controller_t::joypad) { // Storage for joypad's code uint8_t code = 0; @@ -167,7 +205,7 @@ public: } // If its fourscore, its like two joypads separated by a | - if (type == controller_t::fourscore1 || type == controller_t::fourscore2) + if (type == controller_t::fourscore1 || type == controller_t::fourscore2) { // Storage for joypad's code uint8_t code1 = 0; @@ -198,7 +236,7 @@ public: } } - static void parseConsoleInputs(bool& reset, bool& power, std::istringstream& ss, const std::string& inputString) + static void parseConsoleInputs(bool &reset, bool &power, std::istringstream &ss, const std::string &inputString) { // Currently read character char c; @@ -218,7 +256,7 @@ public: controller_t _controller1Type; controller_t _controller2Type; - + }; // class InputParser } // namespace jaffar \ No newline at end of file diff --git a/source/nesInstanceBase.hpp b/source/nesInstanceBase.hpp index d4e49d9..165414a 100644 --- a/source/nesInstanceBase.hpp +++ b/source/nesInstanceBase.hpp @@ -1,9 +1,9 @@ #pragma once +#include "inputParser.hpp" +#include "jaffarCommon/logger.hpp" #include "jaffarCommon/serializers/contiguous.hpp" #include "jaffarCommon/serializers/differential.hpp" -#include "jaffarCommon/logger.hpp" -#include "inputParser.hpp" // Size of image generated in graphics buffer static const uint16_t image_width = 256; @@ -12,8 +12,7 @@ static const uint16_t image_height = 240; class NESInstanceBase { public: - - NESInstanceBase(const nlohmann::json& config) + NESInstanceBase(const nlohmann::json &config) { _inputParser = std::make_unique(config); } @@ -25,7 +24,7 @@ class NESInstanceBase inline void enableRendering() { _doRendering = true; }; inline void disableRendering() { _doRendering = false; }; - inline bool loadROM(const uint8_t* romData, const size_t romSize) + inline bool loadROM(const uint8_t *romData, const size_t romSize) { // Actually loading rom file auto status = loadROMImpl(romData, romSize); @@ -37,7 +36,7 @@ class NESInstanceBase return status; } - void enableStateBlock(const std::string& block) + void enableStateBlock(const std::string &block) { // Calling implementation enableStateBlockImpl(block); @@ -46,7 +45,7 @@ class NESInstanceBase _stateSize = getFullStateSize(); } - void disableStateBlock(const std::string& block) + void disableStateBlock(const std::string &block) { // Calling implementation disableStateBlockImpl(block); @@ -57,27 +56,26 @@ class NESInstanceBase virtual size_t getFullStateSize() const = 0; virtual size_t getDifferentialStateSize() const = 0; - inline jaffar::InputParser* getInputParser() const { return _inputParser.get(); } - + inline jaffar::InputParser *getInputParser() const { return _inputParser.get(); } + // Virtual functions virtual uint8_t *getLowMem() const = 0; virtual size_t getLowMemSize() const = 0; - virtual void serializeState(jaffarCommon::serializer::Base& serializer) const = 0; - virtual void deserializeState(jaffarCommon::deserializer::Base& deserializer) = 0; + virtual void serializeState(jaffarCommon::serializer::Base &serializer) const = 0; + virtual void deserializeState(jaffarCommon::deserializer::Base &deserializer) = 0; virtual void doSoftReset() = 0; virtual void doHardReset() = 0; virtual std::string getCoreName() const = 0; virtual void *getInternalEmulatorPointer() = 0; - virtual void setNTABBlockSize(const size_t size) { }; + virtual void setNTABBlockSize(const size_t size) {}; 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 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; // Storage for the light state size size_t _stateSize; @@ -86,8 +84,6 @@ class NESInstanceBase bool _doRendering = true; private: - // Input parser instance std::unique_ptr _inputParser; - }; diff --git a/source/playbackInstance.hpp b/source/playbackInstance.hpp index dfe8536..9e44eaa 100644 --- a/source/playbackInstance.hpp +++ b/source/playbackInstance.hpp @@ -1,15 +1,15 @@ #pragma once -#include -#include +#include "nesInstance.hpp" #include #include #include #include -#include #include #include -#include "nesInstance.hpp" +#include +#include +#include #define _INVERSE_FRAME_RATE 16667 @@ -106,13 +106,13 @@ class PlaybackInstance addStep(""); } - void enableRendering(SDL_Window* window) + void enableRendering(SDL_Window *window) { // 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); + ((emulator_t *)_emu->getInternalEmulatorPointer())->set_pixels(_video_buffer, image_width + 8); // Loading Emulator instance HQN _hqnState.setEmulatorPointer(_emu->getInternalEmulatorPointer()); @@ -233,7 +233,6 @@ class PlaybackInstance } private: - // Internal sequence information std::vector _stepSequence; diff --git a/source/player.cpp b/source/player.cpp index bea6436..2efd041 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -1,12 +1,12 @@ -#include #include "argparse/argparse.hpp" -#include "jaffarCommon/serializers/contiguous.hpp" #include "jaffarCommon/deserializers/contiguous.hpp" #include "jaffarCommon/file.hpp" #include "jaffarCommon/logger.hpp" +#include "jaffarCommon/serializers/contiguous.hpp" #include "jaffarCommon/string.hpp" #include "nesInstance.hpp" #include "playbackInstance.hpp" +#include SDL_Window *launchOutputWindow() { @@ -120,7 +120,7 @@ int main(int argc, char *argv[]) // Loading ROM File std::string romFileData; if (jaffarCommon::file::loadStringFromFile(romFileData, romFilePath) == false) JAFFAR_THROW_LOGIC("Could not rom file: %s\n", romFilePath.c_str()); - e.loadROM((uint8_t*)romFileData.data(), romFileData.size()); + e.loadROM((uint8_t *)romFileData.data(), romFileData.size()); // If an initial state is provided, load it now if (stateFilePath != "") @@ -135,7 +135,7 @@ int main(int argc, char *argv[]) auto p = PlaybackInstance(&e); // If render is enabled then, create window now - SDL_Window* window = nullptr; + SDL_Window *window = nullptr; if (disableRender == false) { window = launchOutputWindow(); diff --git a/source/quickNES/nesInstance.hpp b/source/quickNES/nesInstance.hpp index 6db7464..2bd1bab 100644 --- a/source/quickNES/nesInstance.hpp +++ b/source/quickNES/nesInstance.hpp @@ -1,10 +1,10 @@ #pragma once -#include "jaffarCommon/serializers/base.hpp" -#include "jaffarCommon/deserializers/base.hpp" +#include "../nesInstanceBase.hpp" #include "core/nes_emu/Nes_Emu.h" #include "core/nes_emu/Nes_State.h" -#include "../nesInstanceBase.hpp" +#include "jaffarCommon/deserializers/base.hpp" +#include "jaffarCommon/serializers/base.hpp" #define _DUMMY_SIZE 65536 @@ -17,8 +17,7 @@ extern void register_mapper_70(); class NESInstance final : public NESInstanceBase { public: - - NESInstance(const nlohmann::json& config) : NESInstanceBase(config) + NESInstance(const nlohmann::json &config) : NESInstanceBase(config) { // If running the original QuickNES, register extra mappers now register_misc_mappers(); @@ -29,14 +28,14 @@ class NESInstance final : public NESInstanceBase uint8_t *getLowMem() const override { return _nes.low_mem(); }; size_t getLowMemSize() const override { return 0x800; }; - void serializeState(jaffarCommon::serializer::Base& serializer) const override + void serializeState(jaffarCommon::serializer::Base &serializer) const override { Mem_Writer w(serializer.getOutputDataBuffer(), _stateSize, 0); Auto_File_Writer a(w); _nes.save_state(a); } - void deserializeState(jaffarCommon::deserializer::Base& deserializer) override + void deserializeState(jaffarCommon::deserializer::Base &deserializer) override { Mem_File_Reader r(deserializer.getInputDataBuffer(), _stateSize); Auto_File_Reader a(r); @@ -66,10 +65,9 @@ class NESInstance final : public NESInstanceBase if (_doRendering == true) _nes.emulate_frame(input.port1, input.port2); if (_doRendering == false) _nes.emulate_skip_frame(input.port1, input.port2); } - - protected: - bool loadROMImpl(const uint8_t* romData, const size_t romSize) override + protected: + bool loadROMImpl(const uint8_t *romData, const size_t romSize) override { // Loading rom data Mem_File_Reader romReader(romData, (int)romSize); @@ -78,12 +76,10 @@ class NESInstance final : public NESInstanceBase return result == 0; } - void enableStateBlockImpl(const std::string& block) override {}; - void disableStateBlockImpl(const std::string& block) override {}; - + void enableStateBlockImpl(const std::string &block) override {}; + void disableStateBlockImpl(const std::string &block) override {}; private: - // Emulator instance emulator_t _nes; }; diff --git a/source/quickerNES/core/apu/NESEffectsBuffer.cpp b/source/quickerNES/core/apu/NESEffectsBuffer.cpp index 60e5098..83955c5 100644 --- a/source/quickerNES/core/apu/NESEffectsBuffer.cpp +++ b/source/quickerNES/core/apu/NESEffectsBuffer.cpp @@ -82,4 +82,4 @@ void Nes_Effects_Buffer::RestoreAudioBufferState() { } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/NESEffectsBuffer.hpp b/source/quickerNES/core/apu/NESEffectsBuffer.hpp index 7d5e539..1eeff75 100644 --- a/source/quickerNES/core/apu/NESEffectsBuffer.hpp +++ b/source/quickerNES/core/apu/NESEffectsBuffer.hpp @@ -3,8 +3,8 @@ // Effects_Buffer with non-linear sound // Nes_Emu 0.7.0 -#include "effectsBuffer.hpp" #include "buffer.hpp" +#include "effectsBuffer.hpp" namespace quickerNES { @@ -38,4 +38,4 @@ class Nes_Effects_Buffer : public Effects_Buffer friend Multi_Buffer *set_apu(Nes_Effects_Buffer *, Apu *); }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/apu.cpp b/source/quickerNES/core/apu/apu.cpp index a62af88..bd72f34 100644 --- a/source/quickerNES/core/apu/apu.cpp +++ b/source/quickerNES/core/apu/apu.cpp @@ -19,7 +19,7 @@ namespace quickerNES int const amp_range = 15; Apu::Apu() : square1(&square_synth), - square2(&square_synth) + square2(&square_synth) { dmc.apu = this; dmc.prg_reader = 0; @@ -372,4 +372,4 @@ int Apu::read_status(nes_time_t time) return result; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/apu.hpp b/source/quickerNES/core/apu/apu.hpp index 104ef1e..c93791f 100644 --- a/source/quickerNES/core/apu/apu.hpp +++ b/source/quickerNES/core/apu/apu.hpp @@ -3,9 +3,9 @@ // NES 2A03 APU sound chip emulator // Snd_Emu 0.1.7 +#include "oscs.hpp" #include #include -#include "oscs.hpp" namespace quickerNES { @@ -360,4 +360,4 @@ inline void Apu::load_state(apu_state_t const &state) dmc.run(last_time, last_time); } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/blipBuffer.cpp b/source/quickerNES/core/apu/blipBuffer.cpp index 568db77..153c5f1 100644 --- a/source/quickerNES/core/apu/blipBuffer.cpp +++ b/source/quickerNES/core/apu/blipBuffer.cpp @@ -1,11 +1,11 @@ // Blip_Buffer 0.4.0. http://www.slack.net/~ant/ +#include "blipBuffer.hpp" #include #include #include #include -#include "blipBuffer.hpp" /* Copyright (C) 2003-2006 Shay Green. This module is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser @@ -419,4 +419,4 @@ void Blip_Buffer::RestoreAudioBufferState() memcpy(buffer_, extra_buffer, sizeof(extra_buffer)); } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/blipBuffer.hpp b/source/quickerNES/core/apu/blipBuffer.hpp index 3cc9c50..d3682a7 100644 --- a/source/quickerNES/core/apu/blipBuffer.hpp +++ b/source/quickerNES/core/apu/blipBuffer.hpp @@ -377,4 +377,4 @@ inline int Blip_Reader::begin(Blip_Buffer &blip_buf) int const blip_max_length = 0; int const blip_default_length = 250; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/buffer.cpp b/source/quickerNES/core/apu/buffer.cpp index 6200592..68a513a 100644 --- a/source/quickerNES/core/apu/buffer.cpp +++ b/source/quickerNES/core/apu/buffer.cpp @@ -227,4 +227,4 @@ void Nonlinearizer::RestoreAudioBufferState() prev = extra_prev; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/buffer.hpp b/source/quickerNES/core/apu/buffer.hpp index c55642a..9a4b4a9 100644 --- a/source/quickerNES/core/apu/buffer.hpp +++ b/source/quickerNES/core/apu/buffer.hpp @@ -3,8 +3,8 @@ // NES non-linear audio buffer // Emu 0.7.0 -#include #include "multiBuffer.hpp" +#include namespace quickerNES { @@ -79,4 +79,4 @@ class Buffer : public Multi_Buffer virtual void RestoreAudioBufferState(); }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/effectsBuffer.cpp b/source/quickerNES/core/apu/effectsBuffer.cpp index b623de1..b60006b 100644 --- a/source/quickerNES/core/apu/effectsBuffer.cpp +++ b/source/quickerNES/core/apu/effectsBuffer.cpp @@ -1,7 +1,7 @@ // Game_Music_Emu 0.3.0. http://www.slack.net/~ant/ -#include #include "effectsBuffer.hpp" +#include /* Copyright (C) 2003-2006 Shay Green. This module is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser @@ -515,4 +515,4 @@ void Effects_Buffer::mix_enhanced(blip_sample_t *out, long count) r2.end(bufs[6]); } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/effectsBuffer.hpp b/source/quickerNES/core/apu/effectsBuffer.hpp index 6878c58..46809a9 100644 --- a/source/quickerNES/core/apu/effectsBuffer.hpp +++ b/source/quickerNES/core/apu/effectsBuffer.hpp @@ -3,11 +3,11 @@ // Multi-channel effects buffer with panning, echo and reverb // Game_Music_Emu 0.3.0 -#include #include "multiBuffer.hpp" +#include namespace quickerNES -{ +{ // Effects_Buffer uses several buffers and outputs stereo sample pairs. class Effects_Buffer : public Multi_Buffer @@ -101,4 +101,4 @@ inline Effects_Buffer::channel_t Effects_Buffer::channel(int i) return channels[i % chan_count]; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/fme7/apu_fme7.cpp b/source/quickerNES/core/apu/fme7/apu_fme7.cpp index f050307..40159e0 100644 --- a/source/quickerNES/core/apu/fme7/apu_fme7.cpp +++ b/source/quickerNES/core/apu/fme7/apu_fme7.cpp @@ -105,4 +105,4 @@ void Fme7_Apu::run_until(blip_time_t end_time) last_time = end_time; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/fme7/apu_fme7.hpp b/source/quickerNES/core/apu/fme7/apu_fme7.hpp index b317d20..440b464 100644 --- a/source/quickerNES/core/apu/fme7/apu_fme7.hpp +++ b/source/quickerNES/core/apu/fme7/apu_fme7.hpp @@ -3,8 +3,8 @@ // Sunsoft FME-7 sound emulator // Emu 0.7.0 -#include #include "../blipBuffer.hpp" +#include namespace quickerNES { @@ -152,4 +152,4 @@ inline void Fme7_Apu::load_state(fme7_apu_state_t const &in) run_until(last_time); } -} // namespace quickNES +} // namespace quickerNES diff --git a/source/quickerNES/core/apu/multiBuffer.cpp b/source/quickerNES/core/apu/multiBuffer.cpp index 5583c94..e40b910 100644 --- a/source/quickerNES/core/apu/multiBuffer.cpp +++ b/source/quickerNES/core/apu/multiBuffer.cpp @@ -1,8 +1,8 @@ // Blip_Buffer 0.4.0. http://www.slack.net/~ant/ -#include #include "multiBuffer.hpp" +#include /* Copyright (C) 2003-2006 Shay Green. This module is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser @@ -284,4 +284,4 @@ void Stereo_Buffer::RestoreAudioBufferState() right()->RestoreAudioBufferState(); } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/multiBuffer.hpp b/source/quickerNES/core/apu/multiBuffer.hpp index 461af0f..f673ebd 100644 --- a/source/quickerNES/core/apu/multiBuffer.hpp +++ b/source/quickerNES/core/apu/multiBuffer.hpp @@ -199,4 +199,4 @@ inline long Mono_Buffer::read_samples(blip_sample_t *p, long s) { return buf.rea inline long Mono_Buffer::samples_avail() const { return buf.samples_avail(); } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/namco/apu_namco.cpp b/source/quickerNES/core/apu/namco/apu_namco.cpp index f5136b3..bc9c544 100644 --- a/source/quickerNES/core/apu/namco/apu_namco.cpp +++ b/source/quickerNES/core/apu/namco/apu_namco.cpp @@ -180,4 +180,4 @@ void Namco_Apu::load_state(namco_state_t const &in) run_until(last_time); } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/namco/apu_namco.hpp b/source/quickerNES/core/apu/namco/apu_namco.hpp index 27c48e2..f747eed 100644 --- a/source/quickerNES/core/apu/namco/apu_namco.hpp +++ b/source/quickerNES/core/apu/namco/apu_namco.hpp @@ -3,8 +3,8 @@ // Namco 106 sound chip emulator // Snd_Emu 0.1.7 -#include #include "../apu.hpp" +#include namespace quickerNES { @@ -112,4 +112,4 @@ inline void Namco_Apu::write_data(nes_time_t time, int data) access() = data; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/oscs.cpp b/source/quickerNES/core/apu/oscs.cpp index f7f9033..ef91854 100644 --- a/source/quickerNES/core/apu/oscs.cpp +++ b/source/quickerNES/core/apu/oscs.cpp @@ -679,4 +679,4 @@ void Noise::run(nes_time_t time, nes_time_t end_time) delay = time - end_time; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/oscs.hpp b/source/quickerNES/core/apu/oscs.hpp index 302f0dd..c26a267 100644 --- a/source/quickerNES/core/apu/oscs.hpp +++ b/source/quickerNES/core/apu/oscs.hpp @@ -169,4 +169,4 @@ struct Dmc : Osc nes_time_t next_read_time() const; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/vrc6/apu_vrc6.cpp b/source/quickerNES/core/apu/vrc6/apu_vrc6.cpp index 93c348b..1ea2b44 100644 --- a/source/quickerNES/core/apu/vrc6/apu_vrc6.cpp +++ b/source/quickerNES/core/apu/vrc6/apu_vrc6.cpp @@ -212,4 +212,4 @@ void Vrc6_Apu::run_saw(nes_time_t end_time) osc.last_amp = last_amp; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/vrc6/apu_vrc6.hpp b/source/quickerNES/core/apu/vrc6/apu_vrc6.hpp index e26bfe6..40f0337 100644 --- a/source/quickerNES/core/apu/vrc6/apu_vrc6.hpp +++ b/source/quickerNES/core/apu/vrc6/apu_vrc6.hpp @@ -4,9 +4,9 @@ // Konami VRC6 sound chip emulator // Snd_Emu 0.1.7 -#include -#include "../blipBuffer.hpp" #include "../apu.hpp" +#include "../blipBuffer.hpp" +#include namespace quickerNES { @@ -109,4 +109,4 @@ inline void Vrc6_Apu::treble_eq(blip_eq_t const &eq) square_synth.treble_eq(eq); } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/vrc7/apu_vrc7.cpp b/source/quickerNES/core/apu/vrc7/apu_vrc7.cpp index 591e848..b9abb17 100644 --- a/source/quickerNES/core/apu/vrc7/apu_vrc7.cpp +++ b/source/quickerNES/core/apu/vrc7/apu_vrc7.cpp @@ -1,6 +1,6 @@ -#include #include "apu_vrc7.hpp" #include "emu2413.hpp" +#include namespace quickerNES { @@ -208,4 +208,4 @@ void Vrc7::update_last_amp() } } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/vrc7/apu_vrc7.hpp b/source/quickerNES/core/apu/vrc7/apu_vrc7.hpp index eac86d9..4b34036 100644 --- a/source/quickerNES/core/apu/vrc7/apu_vrc7.hpp +++ b/source/quickerNES/core/apu/vrc7/apu_vrc7.hpp @@ -4,9 +4,9 @@ // Konami VRC7 sound chip emulator // Snd_Emu 0.1.7. Copyright (C) 2003-2005 Shay Green. GNU LGPL license. -#include #include "../blipBuffer.hpp" #include "emu2413_state.hpp" +#include namespace quickerNES { @@ -76,4 +76,4 @@ inline void Vrc7::osc_output(int i, Blip_Buffer *buf) oscs[i].output = buf; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/vrc7/emu2413.cpp b/source/quickerNES/core/apu/vrc7/emu2413.cpp index 37aa13e..deca0d7 100644 --- a/source/quickerNES/core/apu/vrc7/emu2413.cpp +++ b/source/quickerNES/core/apu/vrc7/emu2413.cpp @@ -108,7 +108,7 @@ static const unsigned char default_inst[15][8] = { /* AM speed(Hz) and depth(dB) */ #define AM_SPEED 3.7 -//#define AM_DEPTH 4.8 +// #define AM_DEPTH 4.8 #define AM_DEPTH 2.4 /* Cut the lower b bit(s) off. */ @@ -243,7 +243,7 @@ static void makeDphaseTable(OPLL *opll) static void makeTllTable(OPLL *opll) { -#define dB2(x) ((x)*2) +#define dB2(x) ((x) * 2) static const double kltable[16] = { dB2(0.000), dB2(9.000), dB2(12.000), dB2(13.875), dB2(15.000), dB2(16.125), dB2(16.875), dB2(17.625), dB2(18.000), dB2(18.750), dB2(19.125), dB2(19.500), dB2(19.875), dB2(20.250), dB2(20.625), dB2(21.000)}; @@ -1152,4 +1152,4 @@ void OPLL_writeIO(OPLL *opll, e_uint32 adr, e_uint32 val) opll->adr = val; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/vrc7/emu2413.hpp b/source/quickerNES/core/apu/vrc7/emu2413.hpp index 4c508ae..a9d6e34 100644 --- a/source/quickerNES/core/apu/vrc7/emu2413.hpp +++ b/source/quickerNES/core/apu/vrc7/emu2413.hpp @@ -220,4 +220,4 @@ extern "C" } #endif -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/apu/vrc7/emu2413_state.hpp b/source/quickerNES/core/apu/vrc7/emu2413_state.hpp index 2a97a60..ebd2e25 100644 --- a/source/quickerNES/core/apu/vrc7/emu2413_state.hpp +++ b/source/quickerNES/core/apu/vrc7/emu2413_state.hpp @@ -4,7 +4,7 @@ namespace quickerNES { - + typedef struct { e_int32 feedback; @@ -38,4 +38,4 @@ extern "C" } #endif -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/cart.hpp b/source/quickerNES/core/cart.hpp index f67fba2..abf1a42 100644 --- a/source/quickerNES/core/cart.hpp +++ b/source/quickerNES/core/cart.hpp @@ -114,4 +114,4 @@ class Cart unsigned mapper; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/core.hpp b/source/quickerNES/core/core.hpp index b83770f..122b0d0 100644 --- a/source/quickerNES/core/core.hpp +++ b/source/quickerNES/core/core.hpp @@ -15,16 +15,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // Emu 0.7.0 -#include -#include "cpu.hpp" #include "apu/apu.hpp" +#include "cpu.hpp" #include "mappers/mapper.hpp" #include "ppu/ppu.hpp" -#include -#include #include -#include +#include #include +#include +#include +#include namespace quickerNES { @@ -54,11 +54,10 @@ struct nes_state_t struct nes_state_lite_t { - uint16_t timestamp; // CPU clocks * 15 (for NTSC) + uint16_t timestamp; // CPU clocks * 15 (for NTSC) uint8_t frame_count; // number of frames emulated since power-up }; - struct joypad_state_t { uint32_t joypad_latches[2]; // joypad 1 & 2 shift registers @@ -84,7 +83,6 @@ class Core : private Cpu typedef Cpu cpu; public: - size_t _NTABBlockSize = 0x1000; // Flags for lite state storage @@ -156,7 +154,7 @@ class Core : private Cpu reset(true, true); } - inline void serializeState(jaffarCommon::serializer::Base& serializer) const + inline void serializeState(jaffarCommon::serializer::Base &serializer) const { // TIME Block if (TIMEBlockEnabled == true) @@ -268,7 +266,7 @@ class Core : private Cpu } } - inline void deserializeState(jaffarCommon::deserializer::Base& deserializer) + inline void deserializeState(jaffarCommon::deserializer::Base &deserializer) { disable_rendering(); error_count = 0; @@ -277,10 +275,10 @@ class Core : private Cpu // TIME Block if (TIMEBlockEnabled == true) { - const auto outputData = (uint8_t*) &nes; + const auto outputData = (uint8_t *)&nes; const auto inputDataSize = sizeof(nes_state_t); deserializer.popContiguous(outputData, inputDataSize); - + nes.timestamp /= 5; } @@ -288,8 +286,8 @@ class Core : private Cpu if (CPURBlockEnabled == true) { cpu_state_t s; - - const auto outputData = (uint8_t*) &s; + + const auto outputData = (uint8_t *)&s; const auto inputDataSize = sizeof(cpu_state_t); deserializer.popContiguous(outputData, inputDataSize); @@ -304,7 +302,7 @@ class Core : private Cpu // PPUR Block if (PPURBlockEnabled == true) { - const auto outputData = (uint8_t*) &ppu; + const auto outputData = (uint8_t *)&ppu; const auto inputDataSize = sizeof(ppu_state_t); deserializer.popContiguous(outputData, inputDataSize); } @@ -314,7 +312,7 @@ class Core : private Cpu { Apu::apu_state_t apuState; - const auto outputData = (uint8_t*) &apuState; + const auto outputData = (uint8_t *)&apuState; const auto inputDataSize = sizeof(Apu::apu_state_t); deserializer.popContiguous(outputData, inputDataSize); @@ -325,7 +323,7 @@ class Core : private Cpu // CTRL Block if (CTRLBlockEnabled == true) { - const auto outputData = (uint8_t*) &joypad; + const auto outputData = (uint8_t *)&joypad; const auto inputDataSize = sizeof(joypad_state_t); deserializer.popContiguous(outputData, inputDataSize); } @@ -335,7 +333,7 @@ class Core : private Cpu { mapper->default_reset_state(); - const auto outputData = (uint8_t*) mapper->state; + const auto outputData = (uint8_t *)mapper->state; const auto inputDataSize = mapper->state_size; deserializer.popContiguous(outputData, inputDataSize); @@ -345,7 +343,7 @@ class Core : private Cpu // LRAM Block if (LRAMBlockEnabled == true) { - const auto outputData = (uint8_t*) low_mem; + const auto outputData = (uint8_t *)low_mem; const auto inputDataSize = low_ram_size; deserializer.pop(outputData, inputDataSize); } @@ -353,7 +351,7 @@ class Core : private Cpu // SPRT Block if (SPRTBlockEnabled == true) { - const auto outputData = (uint8_t*) ppu.spr_ram; + const auto outputData = (uint8_t *)ppu.spr_ram; const auto inputDataSize = Ppu::spr_ram_size; deserializer.pop(outputData, inputDataSize); } @@ -361,7 +359,7 @@ class Core : private Cpu // NTAB Block if (NTABBlockEnabled == true) { - const auto outputData = (uint8_t*) ppu.impl->nt_ram; + const auto outputData = (uint8_t *)ppu.impl->nt_ram; const auto inputDataSize = _NTABBlockSize; deserializer.pop(outputData, inputDataSize); } @@ -371,7 +369,7 @@ class Core : private Cpu { if (ppu.chr_is_writable) { - const auto outputData = (uint8_t*) ppu.impl->chr_ram; + const auto outputData = (uint8_t *)ppu.impl->chr_ram; const auto inputDataSize = ppu.chr_size; deserializer.pop(outputData, inputDataSize); @@ -384,7 +382,7 @@ class Core : private Cpu { if (sram_present) { - const auto outputData = (uint8_t*) impl->sram; + const auto outputData = (uint8_t *)impl->sram; const auto inputDataSize = impl->sram_size; deserializer.pop(outputData, inputDataSize); } @@ -393,47 +391,141 @@ class Core : private Cpu if (sram_present) enable_sram(true); } -void setNTABBlockSize(const size_t size) { _NTABBlockSize = size; } + void setNTABBlockSize(const size_t size) { _NTABBlockSize = size; } -void enableStateBlock(const std::string& block) -{ - bool recognizedBlock = false; - - if (block == "TIME") { TIMEBlockEnabled = true; recognizedBlock = true; } - if (block == "CPUR") { CPURBlockEnabled = true; recognizedBlock = true; } - if (block == "PPUR") { PPURBlockEnabled = true; recognizedBlock = true; } - if (block == "APUR") { APURBlockEnabled = true; recognizedBlock = true; } - if (block == "CTRL") { CTRLBlockEnabled = true; recognizedBlock = true; } - if (block == "MAPR") { MAPRBlockEnabled = true; recognizedBlock = true; } - if (block == "LRAM") { LRAMBlockEnabled = true; recognizedBlock = true; } - if (block == "SPRT") { SPRTBlockEnabled = true; recognizedBlock = true; } - if (block == "NTAB") { NTABBlockEnabled = true; recognizedBlock = true; } - if (block == "CHRR") { CHRRBlockEnabled = true; recognizedBlock = true; } - if (block == "SRAM") { SRAMBlockEnabled = true; recognizedBlock = true; } + void enableStateBlock(const std::string &block) + { + bool recognizedBlock = false; - if (recognizedBlock == false) { fprintf(stderr, "Unrecognized block type: %s\n", block.c_str()); exit(-1);} -}; + if (block == "TIME") + { + TIMEBlockEnabled = true; + recognizedBlock = true; + } + if (block == "CPUR") + { + CPURBlockEnabled = true; + recognizedBlock = true; + } + if (block == "PPUR") + { + PPURBlockEnabled = true; + recognizedBlock = true; + } + if (block == "APUR") + { + APURBlockEnabled = true; + recognizedBlock = true; + } + if (block == "CTRL") + { + CTRLBlockEnabled = true; + recognizedBlock = true; + } + if (block == "MAPR") + { + MAPRBlockEnabled = true; + recognizedBlock = true; + } + if (block == "LRAM") + { + LRAMBlockEnabled = true; + recognizedBlock = true; + } + if (block == "SPRT") + { + SPRTBlockEnabled = true; + recognizedBlock = true; + } + if (block == "NTAB") + { + NTABBlockEnabled = true; + recognizedBlock = true; + } + if (block == "CHRR") + { + CHRRBlockEnabled = true; + recognizedBlock = true; + } + if (block == "SRAM") + { + SRAMBlockEnabled = true; + recognizedBlock = true; + } + if (recognizedBlock == false) + { + fprintf(stderr, "Unrecognized block type: %s\n", block.c_str()); + exit(-1); + } + }; -void disableStateBlock(const std::string& block) -{ - bool recognizedBlock = false; - - if (block == "TIME") { TIMEBlockEnabled = false; recognizedBlock = true; } - if (block == "CPUR") { CPURBlockEnabled = false; recognizedBlock = true; } - if (block == "PPUR") { PPURBlockEnabled = false; recognizedBlock = true; } - if (block == "APUR") { APURBlockEnabled = false; recognizedBlock = true; } - if (block == "CTRL") { CTRLBlockEnabled = false; recognizedBlock = true; } - if (block == "MAPR") { MAPRBlockEnabled = false; recognizedBlock = true; } - if (block == "LRAM") { LRAMBlockEnabled = false; recognizedBlock = true; } - if (block == "SPRT") { SPRTBlockEnabled = false; recognizedBlock = true; } - if (block == "NTAB") { NTABBlockEnabled = false; recognizedBlock = true; } - if (block == "CHRR") { CHRRBlockEnabled = false; recognizedBlock = true; } - if (block == "SRAM") { SRAMBlockEnabled = false; recognizedBlock = true; } + void disableStateBlock(const std::string &block) + { + bool recognizedBlock = false; - if (recognizedBlock == false) { fprintf(stderr, "Unrecognized block type: %s\n", block.c_str()); exit(-1);} -}; + if (block == "TIME") + { + TIMEBlockEnabled = false; + recognizedBlock = true; + } + if (block == "CPUR") + { + CPURBlockEnabled = false; + recognizedBlock = true; + } + if (block == "PPUR") + { + PPURBlockEnabled = false; + recognizedBlock = true; + } + if (block == "APUR") + { + APURBlockEnabled = false; + recognizedBlock = true; + } + if (block == "CTRL") + { + CTRLBlockEnabled = false; + recognizedBlock = true; + } + if (block == "MAPR") + { + MAPRBlockEnabled = false; + recognizedBlock = true; + } + if (block == "LRAM") + { + LRAMBlockEnabled = false; + recognizedBlock = true; + } + if (block == "SPRT") + { + SPRTBlockEnabled = false; + recognizedBlock = true; + } + if (block == "NTAB") + { + NTABBlockEnabled = false; + recognizedBlock = true; + } + if (block == "CHRR") + { + CHRRBlockEnabled = false; + recognizedBlock = true; + } + if (block == "SRAM") + { + SRAMBlockEnabled = false; + recognizedBlock = true; + } + if (recognizedBlock == false) + { + fprintf(stderr, "Unrecognized block type: %s\n", block.c_str()); + exit(-1); + } + }; void reset(bool full_reset, bool erase_battery_ram) { @@ -482,9 +574,9 @@ void disableStateBlock(const std::string& block) nes_time_t emulate_frame(uint32_t joypad1, uint32_t joypad2) { - #ifdef _QUICKERNES_DETECT_JOYPAD_READS +#ifdef _QUICKERNES_DETECT_JOYPAD_READS joypad_read_count = 0; - #endif +#endif current_joypad[0] = joypad1; current_joypad[1] = joypad2; @@ -612,10 +704,10 @@ void disableStateBlock(const std::string& block) { if ((addr & 0xFFFE) == 0x4016) { - // For performance's sake, this counter is only kept on demand - #ifdef _QUICKERNES_DETECT_JOYPAD_READS +// For performance's sake, this counter is only kept on demand +#ifdef _QUICKERNES_DETECT_JOYPAD_READS joypad_read_count++; - #endif +#endif // to do: to aid with recording, doesn't emulate transparent latch, // so a game that held strobe at 1 and read $4016 or $4017 would not get @@ -986,19 +1078,19 @@ inline void Core::cpu_write(nes_addr_t addr, int data, nes_time_t time) #define NES_CPU_READ(cpu, addr, time) \ static_cast(*cpu).cpu_read(addr, time) -#define NES_CPU_WRITEX(cpu, addr, data, time) \ - { \ +#define NES_CPU_WRITEX(cpu, addr, data, time) \ + { \ static_cast(*cpu).cpu_write(addr, data, time); \ } -#define NES_CPU_WRITE(cpu, addr, data, time) \ - { \ - if (addr < 0x800) \ - cpu->low_mem[addr] = data; \ - else if (addr == 0x2007) \ +#define NES_CPU_WRITE(cpu, addr, data, time) \ + { \ + if (addr < 0x800) \ + cpu->low_mem[addr] = data; \ + else if (addr == 0x2007) \ static_cast(*cpu).cpu_write_2007(data); \ - else \ + else \ static_cast(*cpu).cpu_write(addr, data, time); \ } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/cpu.cpp b/source/quickerNES/core/cpu.cpp index af12954..3a3f20e 100644 --- a/source/quickerNES/core/cpu.cpp +++ b/source/quickerNES/core/cpu.cpp @@ -1,15 +1,15 @@ // Emu 0.7.0. http://www.slack.net/~ant/nes-emu/ -#include -#include -#include #include "cpu.hpp" #include "core.hpp" +#include +#include +#include /** * Optimizations by Sergio Martin (eien86) 2023-2024 * The license below (LGPLv2) applies. -*/ + */ /* Copyright (C) 2003-2006 Shay Green. This module is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser @@ -32,1159 +32,1463 @@ namespace quickerNES #define st_d 0x08 #define st_i 0x04 #define st_z 0x02 -#define st_c 0x01 +#define st_c 0x01 // Macros -#define GET_OPERAND( addr ) page [addr] -#define GET_OPERAND16( addr ) *(uint16_t*)( &page [addr] ) +#define GET_OPERAND(addr) page[addr] +#define GET_OPERAND16(addr) *(uint16_t *)(&page[addr]) -#define ADD_PAGE (pc++, data += 0x100 * GET_OPERAND( pc )); -#define GET_ADDR() GET_OPERAND16( pc ) +#define ADD_PAGE (pc++, data += 0x100 * GET_OPERAND(pc)); +#define GET_ADDR() GET_OPERAND16(pc) -#define HANDLE_PAGE_CROSSING( lsb ) clock_count += (lsb) >> 8; +#define HANDLE_PAGE_CROSSING(lsb) clock_count += (lsb) >> 8; -#define INC_DEC_XY( reg, n ) reg = uint8_t (nz = reg + n); goto loop; +#define INC_DEC_XY(reg, n) \ + reg = uint8_t(nz = reg + n); \ + goto loop; -#define IND_Y(r,c) { \ - int32_t temp = READ_LOW( data ) + y; \ - data = temp + 0x100 * READ_LOW( uint8_t (data + 1) ); \ - if (c) HANDLE_PAGE_CROSSING( temp ); \ - if (!(r) || (temp & 0x100)) \ - READ( data - ( temp & 0x100 ) ); \ - } +#define IND_Y(r, c) \ + { \ + int32_t temp = READ_LOW(data) + y; \ + data = temp + 0x100 * READ_LOW(uint8_t(data + 1)); \ + if (c) HANDLE_PAGE_CROSSING(temp); \ + if (!(r) || (temp & 0x100)) \ + READ(data - (temp & 0x100)); \ + } -#define IND_X { \ - int32_t temp = data + x; \ - data = 0x100 * READ_LOW( uint8_t (temp + 1) ) + READ_LOW( uint8_t (temp) ); \ - } +#define IND_X \ + { \ + int32_t temp = data + x; \ + data = 0x100 * READ_LOW(uint8_t(temp + 1)) + READ_LOW(uint8_t(temp)); \ + } -#define ARITH_ADDR_MODES( op ) \ -case op - 0x04: /* (ind,x) */ \ - IND_X \ - goto ptr##op; \ -case op + 0x0C: /* (ind),y */ \ - IND_Y(true,true) \ - goto ptr##op; \ -case op + 0x10: /* zp,X */ \ - data = uint8_t (data + x); \ -case op + 0x00: /* zp */ \ - data = READ_LOW( data ); \ - goto imm##op; \ -case op + 0x14: /* abs,Y */ \ - data += y; \ - goto ind##op; \ -case op + 0x18: /* abs,X */ \ - data += x; \ -ind##op: { \ - HANDLE_PAGE_CROSSING( data ); \ - uint32_t temp = data; \ - ADD_PAGE \ - if ( temp & 0x100 ) \ - READ( data - 0x100 ); \ - goto ptr##op; \ -} \ -case op + 0x08: /* abs */ \ - ADD_PAGE \ -ptr##op: \ - data = READ( data ); \ -case op + 0x04: /* imm */ \ -imm##op: \ +#define ARITH_ADDR_MODES(op) \ + case op - 0x04: /* (ind,x) */ \ + IND_X \ + goto ptr##op; \ + case op + 0x0C: /* (ind),y */ \ + IND_Y(true, true) \ + goto ptr##op; \ + case op + 0x10: /* zp,X */ \ + data = uint8_t(data + x); \ + case op + 0x00: /* zp */ \ + data = READ_LOW(data); \ + goto imm##op; \ + case op + 0x14: /* abs,Y */ \ + data += y; \ + goto ind##op; \ + case op + 0x18: /* abs,X */ \ + data += x; \ + ind##op: \ + { \ + HANDLE_PAGE_CROSSING(data); \ + uint32_t temp = data; \ + ADD_PAGE \ + if (temp & 0x100) \ + READ(data - 0x100); \ + goto ptr##op; \ + } \ + case op + 0x08: /* abs */ \ + ADD_PAGE \ + ptr##op : data = READ(data); \ + case op + 0x04: /* imm */ \ + imm##op: -#define ARITH_ADDR_MODES_PTR( op ) \ -case op - 0x04: /* (ind,x) */ \ - IND_X \ - goto imm##op; \ -case op + 0x0C: \ - IND_Y(false,false) \ - goto imm##op; \ -case op + 0x10: /* zp,X */ \ - data = uint8_t (data + x); \ - goto imm##op; \ -case op + 0x14: /* abs,Y */ \ - data += y; \ - goto ind##op; \ -case op + 0x18: /* abs,X */ \ - data += x; \ -ind##op: { \ - uint32_t temp = data; \ - ADD_PAGE \ - READ( data - ( temp & 0x100 ) ); \ - goto imm##op; \ -} \ -case op + 0x08: /* abs */ \ - ADD_PAGE \ -case op + 0x00: /* zp */ \ -imm##op: \ +#define ARITH_ADDR_MODES_PTR(op) \ + case op - 0x04: /* (ind,x) */ \ + IND_X \ + goto imm##op; \ + case op + 0x0C: \ + IND_Y(false, false) \ + goto imm##op; \ + case op + 0x10: /* zp,X */ \ + data = uint8_t(data + x); \ + goto imm##op; \ + case op + 0x14: /* abs,Y */ \ + data += y; \ + goto ind##op; \ + case op + 0x18: /* abs,X */ \ + data += x; \ + ind##op: \ + { \ + uint32_t temp = data; \ + ADD_PAGE \ + READ(data - (temp & 0x100)); \ + goto imm##op; \ + } \ + case op + 0x08: /* abs */ \ + ADD_PAGE \ + case op + 0x00: /* zp */ \ + imm##op: // Adding likely to fail because typically for loops exit conditions fail until the last one -#define BRANCH( cond ) \ -{ \ - pc++; \ - int offset = (int8_t) data; \ - int extra_clock = (pc & 0xFF) + offset; \ - if ( !(cond) ) {clock_count--; goto loop; } \ - pc += offset; \ - pc = uint16_t( pc ); \ - clock_count += (extra_clock >> 8) & 1; \ - goto loop; \ -} +#define BRANCH(cond) \ + { \ + pc++; \ + int offset = (int8_t)data; \ + int extra_clock = (pc & 0xFF) + offset; \ + if (!(cond)) \ + { \ + clock_count--; \ + goto loop; \ + } \ + pc += offset; \ + pc = uint16_t(pc); \ + clock_count += (extra_clock >> 8) & 1; \ + goto loop; \ + } - -void Cpu::reset( void const* unmapped_page ) +void Cpu::reset(void const *unmapped_page) { - r.status = 0; - r.sp = 0; - r.pc = 0; - r.a = 0; - r.x = 0; - r.y = 0; + r.status = 0; + r.sp = 0; + r.pc = 0; + r.a = 0; + r.x = 0; + r.y = 0; - error_count_ = 0; - clock_count = 0; - clock_limit = 0; - irq_time_ = LONG_MAX / 2 + 1; - end_time_ = LONG_MAX / 2 + 1; + error_count_ = 0; + clock_count = 0; + clock_limit = 0; + irq_time_ = LONG_MAX / 2 + 1; + end_time_ = LONG_MAX / 2 + 1; - set_code_page(0, low_mem); - set_code_page(1, low_mem); - set_code_page(2, low_mem); - set_code_page(3, low_mem); - for ( int32_t i = 4; i < page_count + 1; i++ ) - set_code_page(i, (uint8_t *) unmapped_page); + set_code_page(0, low_mem); + set_code_page(1, low_mem); + set_code_page(2, low_mem); + set_code_page(3, low_mem); + for (int32_t i = 4; i < page_count + 1; i++) + set_code_page(i, (uint8_t *)unmapped_page); - isCorrectExecution = true; + isCorrectExecution = true; } // Note: 'addr' is evaulated more than once in the following macros, so it // must not contain side-effects. -//static void log_read( int32_t opcode ) { LOG_FREQ( "read", 256, opcode ); } +// static void log_read( int32_t opcode ) { LOG_FREQ( "read", 256, opcode ); } -#define READ_LIKELY_PPU( addr ) (NES_CPU_READ_PPU( this, (addr), (clock_count) )) -#define READ( addr ) (NES_CPU_READ( this, (addr), (clock_count) )) -#define WRITE( addr, data ) {NES_CPU_WRITE( this, (addr), (data), (clock_count) );} +#define READ_LIKELY_PPU(addr) (NES_CPU_READ_PPU(this, (addr), (clock_count))) +#define READ(addr) (NES_CPU_READ(this, (addr), (clock_count))) +#define WRITE(addr, data) \ + { \ + NES_CPU_WRITE(this, (addr), (data), (clock_count)); \ + } -#define READ_LOW( addr ) (low_mem [int32_t (addr)]) -#define WRITE_LOW( addr, data ) (void) (READ_LOW( addr ) = (data)) +#define READ_LOW(addr) (low_mem[int32_t(addr)]) +#define WRITE_LOW(addr, data) (void)(READ_LOW(addr) = (data)) -#define READ_PROG( addr ) (code_map [(addr) >> page_bits] [addr]) -#define READ_PROG16( addr ) GET_LE16( &READ_PROG( addr ) ) +#define READ_PROG(addr) (code_map[(addr) >> page_bits][addr]) +#define READ_PROG16(addr) GET_LE16(&READ_PROG(addr)) -#define SET_SP( v ) (sp = ((v) + 1) | 0x100) -#define GET_SP() ((sp - 1) & 0xFF) -#define PUSH( v ) ((sp = (sp - 1) | 0x100), WRITE_LOW( sp, v )) +#define SET_SP(v) (sp = ((v) + 1) | 0x100) +#define GET_SP() ((sp - 1) & 0xFF) +#define PUSH(v) ((sp = (sp - 1) | 0x100), WRITE_LOW(sp, v)) - #define IS_NEG (nz & 0x880) +#define IS_NEG (nz & 0x880) - #define CALC_STATUS( out ) do { \ - out = status & (st_v | st_d | st_i); \ - out |= (c >> 8) & st_c; \ - if ( IS_NEG ) out |= st_n; \ - if ( !(nz & 0xFF) ) out |= st_z; \ - } while ( 0 ) +#define CALC_STATUS(out) \ + do { \ + out = status & (st_v | st_d | st_i); \ + out |= (c >> 8) & st_c; \ + if (IS_NEG) out |= st_n; \ + if (!(nz & 0xFF)) out |= st_z; \ + } while (0) - #define SET_STATUS( in ) do { \ - status = in & (st_v | st_d | st_i); \ - c = in << 8; \ - nz = (in << 4) & 0x800; \ - nz |= ~in & st_z; \ - } while ( 0 ) +#define SET_STATUS(in) \ + do { \ + status = in & (st_v | st_d | st_i); \ + c = in << 8; \ + nz = (in << 4) & 0x800; \ + nz |= ~in & st_z; \ + } while (0) -inline int32_t Cpu::read( nes_addr_t addr ) +inline int32_t Cpu::read(nes_addr_t addr) { - return READ( addr ); + return READ(addr); } -inline void Cpu::write( nes_addr_t addr, int value ) +inline void Cpu::write(nes_addr_t addr, int value) { - WRITE( addr, value ); + WRITE(addr, value); } - // status flags -uint8_t clock_table [256] = { -// 0 1 2 3 4 5 6 7 8 9 A B C D E F - 7,6,2,8,3,3,5,5,3,2,2,2,4,4,6,6,// 0 - 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 1 - 6,6,2,8,3,3,5,5,4,2,2,2,4,4,6,6,// 2 - 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 3 - 6,6,2,8,3,3,5,5,3,2,2,2,3,4,6,6,// 4 - 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 5 - 6,6,2,8,3,3,5,5,4,2,2,2,5,4,6,6,// 6 - 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// 7 - 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,// 8 - 3,6,2,6,4,4,4,4,2,5,2,5,5,5,5,5,// 9 - 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,// A - 3,5,2,5,4,4,4,4,2,4,2,4,4,4,4,4,// B - 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6,// C - 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,// D - 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6,// E - 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7 // F +// status flags +uint8_t clock_table[256] = { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F + 7, + 6, + 2, + 8, + 3, + 3, + 5, + 5, + 3, + 2, + 2, + 2, + 4, + 4, + 6, + 6, // 0 + 3, + 5, + 2, + 8, + 4, + 4, + 6, + 6, + 2, + 4, + 2, + 7, + 4, + 4, + 7, + 7, // 1 + 6, + 6, + 2, + 8, + 3, + 3, + 5, + 5, + 4, + 2, + 2, + 2, + 4, + 4, + 6, + 6, // 2 + 3, + 5, + 2, + 8, + 4, + 4, + 6, + 6, + 2, + 4, + 2, + 7, + 4, + 4, + 7, + 7, // 3 + 6, + 6, + 2, + 8, + 3, + 3, + 5, + 5, + 3, + 2, + 2, + 2, + 3, + 4, + 6, + 6, // 4 + 3, + 5, + 2, + 8, + 4, + 4, + 6, + 6, + 2, + 4, + 2, + 7, + 4, + 4, + 7, + 7, // 5 + 6, + 6, + 2, + 8, + 3, + 3, + 5, + 5, + 4, + 2, + 2, + 2, + 5, + 4, + 6, + 6, // 6 + 3, + 5, + 2, + 8, + 4, + 4, + 6, + 6, + 2, + 4, + 2, + 7, + 4, + 4, + 7, + 7, // 7 + 2, + 6, + 2, + 6, + 3, + 3, + 3, + 3, + 2, + 2, + 2, + 2, + 4, + 4, + 4, + 4, // 8 + 3, + 6, + 2, + 6, + 4, + 4, + 4, + 4, + 2, + 5, + 2, + 5, + 5, + 5, + 5, + 5, // 9 + 2, + 6, + 2, + 6, + 3, + 3, + 3, + 3, + 2, + 2, + 2, + 2, + 4, + 4, + 4, + 4, // A + 3, + 5, + 2, + 5, + 4, + 4, + 4, + 4, + 2, + 4, + 2, + 4, + 4, + 4, + 4, + 4, // B + 2, + 6, + 2, + 8, + 3, + 3, + 5, + 5, + 2, + 2, + 2, + 2, + 4, + 4, + 6, + 6, // C + 3, + 5, + 2, + 8, + 4, + 4, + 6, + 6, + 2, + 4, + 2, + 7, + 4, + 4, + 7, + 7, // D + 2, + 6, + 2, + 8, + 3, + 3, + 5, + 5, + 2, + 2, + 2, + 2, + 4, + 4, + 6, + 6, // E + 3, + 5, + 2, + 8, + 4, + 4, + 6, + 6, + 2, + 4, + 2, + 7, + 4, + 4, + 7, + 7 // F }; // This optimization is only possible with the GNU compiler -- MSVC does not allow function alignment #ifdef __GNUC__ __attribute__((optimize("align-functions=1024"))) #endif - Cpu::result_t Cpu::run ( nes_time_t end ) +Cpu::result_t +Cpu::run(nes_time_t end) { - set_end_time_( end ); - clock_count = 0; - isCorrectExecution = true; + set_end_time_(end); + clock_count = 0; + isCorrectExecution = true; - volatile result_t result = result_cycles; + volatile result_t result = result_cycles; - // registers - uint32_t pc = r.pc; - int32_t sp; - SET_SP( r.sp ); - int32_t a = r.a; - int32_t x = r.x; - int32_t y = r.y; + // registers + uint32_t pc = r.pc; + int32_t sp; + SET_SP(r.sp); + int32_t a = r.a; + int32_t x = r.x; + int32_t y = r.y; - int32_t status; - int32_t c; // carry set if (c & 0x100) != 0 - int32_t nz; // Z set if (nz & 0xFF) == 0, N set if (nz & 0x880) != 0 - { - int32_t temp = r.status; - SET_STATUS( temp ); - } + int32_t status; + int32_t c; // carry set if (c & 0x100) != 0 + int32_t nz; // Z set if (nz & 0xFF) == 0, N set if (nz & 0x880) != 0 + { + int32_t temp = r.status; + SET_STATUS(temp); + } - uint32_t data; - uint8_t const* page; - uint8_t opcode; + uint32_t data; + uint8_t const *page; + uint8_t opcode; loop: - page = code_map [pc >> page_bits]; - opcode = page [pc++]; - data = page [pc]; - - if ( clock_count >= clock_limit ) [[unlikely]] goto stop; + page = code_map[pc >> page_bits]; + opcode = page[pc++]; + data = page[pc]; - // If traceback support is enabled, trigger it here - #ifdef _QUICKERNES_ENABLE_TRACEBACK_SUPPORT + if (clock_count >= clock_limit) [[unlikely]] + goto stop; + +// If traceback support is enabled, trigger it here +#ifdef _QUICKERNES_ENABLE_TRACEBACK_SUPPORT if (tracecb) - { - unsigned int scratch[7]; - scratch[0] = a; - scratch[1] = x; - scratch[2] = y; - scratch[3] = sp; - scratch[4] = pc - 1; - scratch[5] = status; - scratch[6] = opcode; - tracecb(scratch); - } - #endif + { + unsigned int scratch[7]; + scratch[0] = a; + scratch[1] = x; + scratch[2] = y; + scratch[3] = sp; + scratch[4] = pc - 1; + scratch[5] = status; + scratch[6] = opcode; + tracecb(scratch); + } +#endif - clock_count += clock_table [opcode]; + clock_count += clock_table[opcode]; - switch ( opcode ) - { + switch (opcode) + { + // Often-Used -// Often-Used + case 0xB5: // LDA zp,x + data = uint8_t(data + x); + case 0xA5: // LDA zp + a = nz = READ_LOW(data); + pc++; + goto loop; - case 0xB5: // LDA zp,x - data = uint8_t (data + x); - case 0xA5: // LDA zp - a = nz = READ_LOW( data ); - pc++; - goto loop; + case 0xD0: // BNE + BRANCH((uint8_t)nz); - case 0xD0: // BNE - BRANCH( (uint8_t) nz ); + case 0x20: + { // JSR + int32_t temp = pc + 1; + pc = GET_OPERAND16(pc); + WRITE_LOW(0x100 | (sp - 1), temp >> 8); + sp = (sp - 2) | 0x100; + WRITE_LOW(sp, temp); + goto loop; + } - case 0x20: { // JSR - int32_t temp = pc + 1; - pc = GET_OPERAND16( pc ); - WRITE_LOW( 0x100 | (sp - 1), temp >> 8 ); - sp = (sp - 2) | 0x100; - WRITE_LOW( sp, temp ); - goto loop; - } + case 0x4C: // JMP abs + pc = GET_OPERAND16(pc); + goto loop; - case 0x4C: // JMP abs - pc = GET_OPERAND16( pc ); - goto loop; + case 0xE8: INC_DEC_XY(x, 1) // INX - case 0xE8: INC_DEC_XY( x, 1 ) // INX + case 0x10: // BPL + BRANCH(!IS_NEG) - case 0x10: // BPL - BRANCH( !IS_NEG ) + ARITH_ADDR_MODES(0xC5) // CMP + nz = a - data; + pc++; + c = ~nz; + nz &= 0xFF; + goto loop; - ARITH_ADDR_MODES( 0xC5 ) // CMP - nz = a - data; - pc++; - c = ~nz; - nz &= 0xFF; - goto loop; + case 0x30: // BMI + BRANCH(IS_NEG) - case 0x30: // BMI - BRANCH( IS_NEG ) + case 0xF0: // BEQ + BRANCH(!(uint8_t)nz); - case 0xF0: // BEQ - BRANCH( !(uint8_t) nz ); + case 0x95: // STA zp,x + data = uint8_t(data + x); + case 0x85: // STA zp + pc++; + WRITE_LOW(data, a); + goto loop; - case 0x95: // STA zp,x - data = uint8_t (data + x); - case 0x85: // STA zp - pc++; - WRITE_LOW( data, a ); - goto loop; + case 0xC8: INC_DEC_XY(y, 1) // INY - case 0xC8: INC_DEC_XY( y, 1 ) // INY + case 0xA8: // TAY + y = a; + case 0x98: // TYA + a = nz = y; + goto loop; - case 0xA8: // TAY - y = a; - case 0x98: // TYA - a = nz = y; - goto loop; + case 0xAD: // LDA abs + data = GET_ADDR(); + pc += 2; + a = nz = READ_LIKELY_PPU(data); + goto loop; - case 0xAD: // LDA abs - data = GET_ADDR(); - pc += 2; - a = nz = READ_LIKELY_PPU( data ); - goto loop; + case 0x60: // RTS + pc = 1 + READ_LOW(sp); + pc += READ_LOW(0x100 | (sp - 0xFF)) * 0x100; + sp = (sp - 0xFE) | 0x100; + goto loop; - case 0x60: // RTS - pc = 1 + READ_LOW( sp ); - pc += READ_LOW( 0x100 | (sp - 0xFF) ) * 0x100; - sp = (sp - 0xFE) | 0x100; - goto loop; + case 0x99: // STA abs,Y + data += y; + goto sta_ind_common; - case 0x99: // STA abs,Y - data += y; - goto sta_ind_common; + case 0x9D: // STA abs,X + data += x; + sta_ind_common: + ADD_PAGE + READ(data - (data & 0x100)); + goto sta_ptr; - case 0x9D: // STA abs,X - data += x; - sta_ind_common: - ADD_PAGE - READ( data - ( data & 0x100 ) ); - goto sta_ptr; - - case 0x8D: // STA abs - ADD_PAGE - sta_ptr: - pc++; - WRITE( data, a ); - goto loop; + case 0x8D: // STA abs + ADD_PAGE + sta_ptr: + pc++; + WRITE(data, a); + goto loop; - case 0xA9: // LDA #imm - pc++; - a = data; - nz = data; - goto loop; + case 0xA9: // LDA #imm + pc++; + a = data; + nz = data; + goto loop; - case 0xB9:// LDA abs,Y - data += y; - data -= x; - case 0xBD:{// LDA abs,X - pc++; - uint32_t msb = GET_OPERAND( pc ); - data += x; - // indexed common - pc++; - HANDLE_PAGE_CROSSING( data ); - int32_t temp = data; - data += msb * 0x100; - a = nz = READ_PROG( uint16_t( data ) ); - if ( (uint32_t) (data - 0x2000) >= 0x6000 ) - goto loop; - if ( temp & 0x100 ) - READ( data - 0x100 ); - a = nz = READ( data ); - goto loop; - } + case 0xB9: // LDA abs,Y + data += y; + data -= x; + case 0xBD: + { // LDA abs,X + pc++; + uint32_t msb = GET_OPERAND(pc); + data += x; + // indexed common + pc++; + HANDLE_PAGE_CROSSING(data); + int32_t temp = data; + data += msb * 0x100; + a = nz = READ_PROG(uint16_t(data)); + if ((uint32_t)(data - 0x2000) >= 0x6000) + goto loop; + if (temp & 0x100) + READ(data - 0x100); + a = nz = READ(data); + goto loop; + } - case 0xB1:{// LDA (ind),Y - uint32_t msb = READ_LOW( (uint8_t) (data + 1) ); - data = READ_LOW( data ) + y; - // indexed common - pc++; - HANDLE_PAGE_CROSSING( data ); - int32_t temp = data; - data += msb * 0x100; - a = nz = READ_PROG( uint16_t( data ) ); - if ( (uint32_t) (data - 0x2000) >= 0x6000 ) - goto loop; - if ( temp & 0x100 ) - READ( data - 0x100 ); - a = nz = READ( data ); - goto loop; - } + case 0xB1: + { // LDA (ind),Y + uint32_t msb = READ_LOW((uint8_t)(data + 1)); + data = READ_LOW(data) + y; + // indexed common + pc++; + HANDLE_PAGE_CROSSING(data); + int32_t temp = data; + data += msb * 0x100; + a = nz = READ_PROG(uint16_t(data)); + if ((uint32_t)(data - 0x2000) >= 0x6000) + goto loop; + if (temp & 0x100) + READ(data - 0x100); + a = nz = READ(data); + goto loop; + } - case 0xA1: // LDA (ind,X) - IND_X - a = nz = READ( data ); - pc++; - goto loop; + case 0xA1: // LDA (ind,X) + IND_X + a = nz = READ(data); + pc++; + goto loop; -// Branch + // Branch - case 0x50: // BVC - BRANCH( !(status & st_v) ) + case 0x50: // BVC + BRANCH(!(status & st_v)) - case 0x70: // BVS - BRANCH( status & st_v ) + case 0x70: // BVS + BRANCH(status & st_v) - case 0xB0: // BCS - BRANCH( c & 0x100 ) + case 0xB0: // BCS + BRANCH(c & 0x100) - case 0x90: // BCC - BRANCH( !(c & 0x100) ) + case 0x90: // BCC + BRANCH(!(c & 0x100)) -// Load/store + // Load/store - case 0x94: // STY zp,x - data = uint8_t (data + x); - case 0x84: // STY zp - pc++; - WRITE_LOW( data, y ); - goto loop; + case 0x94: // STY zp,x + data = uint8_t(data + x); + case 0x84: // STY zp + pc++; + WRITE_LOW(data, y); + goto loop; - case 0x96: // STX zp,y - data = uint8_t (data + y); - case 0x86: // STX zp - pc++; - WRITE_LOW( data, x ); - goto loop; + case 0x96: // STX zp,y + data = uint8_t(data + y); + case 0x86: // STX zp + pc++; + WRITE_LOW(data, x); + goto loop; - case 0xB6: // LDX zp,y - data = uint8_t (data + y); - case 0xA6: // LDX zp - data = READ_LOW( data ); - case 0xA2: // LDX #imm - pc++; - x = data; - nz = data; - goto loop; + case 0xB6: // LDX zp,y + data = uint8_t(data + y); + case 0xA6: // LDX zp + data = READ_LOW(data); + case 0xA2: // LDX #imm + pc++; + x = data; + nz = data; + goto loop; - case 0xB4: // LDY zp,x - data = uint8_t (data + x); - case 0xA4: // LDY zp - data = READ_LOW( data ); - case 0xA0: // LDY #imm - pc++; - y = data; - nz = data; - goto loop; + case 0xB4: // LDY zp,x + data = uint8_t(data + x); + case 0xA4: // LDY zp + data = READ_LOW(data); + case 0xA0: // LDY #imm + pc++; + y = data; + nz = data; + goto loop; - case 0x91: // STA (ind),Y - IND_Y(false,false) - goto sta_ptr; + case 0x91: // STA (ind),Y + IND_Y(false, false) + goto sta_ptr; - case 0x81: // STA (ind,X) - IND_X - goto sta_ptr; + case 0x81: // STA (ind,X) + IND_X + goto sta_ptr; - case 0xBC: // LDY abs,X - data += x; - HANDLE_PAGE_CROSSING( data ); - case 0xAC:{// LDY abs - pc++; - uint32_t addr = data + 0x100 * GET_OPERAND( pc ); - if ( data & 0x100 ) - READ( addr - 0x100 ); - pc++; - y = nz = READ( addr ); - goto loop; - } + case 0xBC: // LDY abs,X + data += x; + HANDLE_PAGE_CROSSING(data); + case 0xAC: + { // LDY abs + pc++; + uint32_t addr = data + 0x100 * GET_OPERAND(pc); + if (data & 0x100) + READ(addr - 0x100); + pc++; + y = nz = READ(addr); + goto loop; + } - case 0xBE: // LDX abs,y - data += y; - HANDLE_PAGE_CROSSING( data ); - case 0xAE:{// LDX abs - pc++; - uint32_t addr = data + 0x100 * GET_OPERAND( pc ); - pc++; - if ( data & 0x100 ) - READ( addr - 0x100 ); - x = nz = READ( addr ); - goto loop; - } + case 0xBE: // LDX abs,y + data += y; + HANDLE_PAGE_CROSSING(data); + case 0xAE: + { // LDX abs + pc++; + uint32_t addr = data + 0x100 * GET_OPERAND(pc); + pc++; + if (data & 0x100) + READ(addr - 0x100); + x = nz = READ(addr); + goto loop; + } - { - int32_t temp; - case 0x8C: // STY abs - temp = y; - goto store_abs; + { + int32_t temp; + case 0x8C: // STY abs + temp = y; + goto store_abs; - case 0x8E: // STX abs - temp = x; - store_abs: - uint32_t addr = GET_ADDR(); - WRITE( addr, temp ); - pc += 2; - goto loop; - } - -// Compare - - case 0xEC:{// CPX abs - uint32_t addr = GET_ADDR(); - pc++; - data = READ( addr ); - goto cpx_data; - } - - case 0xE4: // CPX zp - data = READ_LOW( data ); - case 0xE0: // CPX #imm - cpx_data: - nz = x - data; - pc++; - c = ~nz; - nz &= 0xFF; - goto loop; - - case 0xCC:{// CPY abs - uint32_t addr = GET_ADDR(); - pc++; - data = READ( addr ); - goto cpy_data; - } - - case 0xC4: // CPY zp - data = READ_LOW( data ); - case 0xC0: // CPY #imm - cpy_data: - nz = y - data; - pc++; - c = ~nz; - nz &= 0xFF; - goto loop; - -// Logical - - ARITH_ADDR_MODES( 0x25 ) // AND - nz = (a &= data); - pc++; - goto loop; - - ARITH_ADDR_MODES( 0x45 ) // EOR - nz = (a ^= data); - pc++; - goto loop; - - ARITH_ADDR_MODES( 0x05 ) // ORA - nz = (a |= data); - pc++; - goto loop; - - case 0x2C:{// BIT abs - uint32_t addr = GET_ADDR(); - pc += 2; - status &= ~st_v; - nz = READ_LIKELY_PPU( addr ); - status |= nz & st_v; - if ( a & nz ) - goto loop; - // result must be zero, even if N bit is set - nz = nz << 4 & 0x800; - goto loop; - } - - case 0x24: // BIT zp - nz = READ_LOW( data ); - pc++; - status &= ~st_v; - status |= nz & st_v; - if ( a & nz ) - goto loop; - // result must be zero, even if N bit is set - nz = nz << 4 & 0x800; - goto loop; - -// Add/subtract - - ARITH_ADDR_MODES( 0xE5 ) // SBC - case 0xEB: // unofficial equivalent - data ^= 0xFF; - goto adc_imm; - - ARITH_ADDR_MODES( 0x65 ) // ADC - adc_imm: { - int32_t carry = (c >> 8) & 1; - int32_t ov = (a ^ 0x80) + carry + (int8_t) data; // sign-extend - status &= ~st_v; - status |= (ov >> 2) & 0x40; - c = nz = a + data + carry; - pc++; - a = (uint8_t) nz; - goto loop; - } - -// Shift/rotate - - case 0x4A: // LSR A - lsr_a: - c = 0; - case 0x6A: // ROR A - nz = (c >> 1) & 0x80; // could use bit insert macro here - c = a << 8; - nz |= a >> 1; - a = nz; - goto loop; - - case 0x0A: // ASL A - nz = a << 1; - c = nz; - a = (uint8_t) nz; - goto loop; - - case 0x2A: { // ROL A - nz = a << 1; - int32_t temp = (c >> 8) & 1; - c = nz; - nz |= temp; - a = (uint8_t) nz; - goto loop; - } - - case 0x3E: // ROL abs,X - data += x; - goto rol_abs; - - case 0x1E: // ASL abs,X - data += x; - case 0x0E: // ASL abs - c = 0; - case 0x2E: // ROL abs - rol_abs: { - int32_t temp = data; - ADD_PAGE - if ( opcode == 0x1E || opcode == 0x3E ) READ( data - ( temp & 0x100 ) ); - WRITE( data, temp = READ( data ) ); - nz = (c >> 8) & 1; - nz |= (c = temp << 1); + case 0x8E: // STX abs + temp = x; + store_abs: + uint32_t addr = GET_ADDR(); + WRITE(addr, temp); + pc += 2; + goto loop; } - rotate_common: - pc++; - WRITE( data, (uint8_t) nz ); - goto loop; - case 0x7E: // ROR abs,X - data += x; - goto ror_abs; + // Compare - case 0x5E: // LSR abs,X - data += x; - case 0x4E: // LSR abs - c = 0; - case 0x6E: // ROR abs - ror_abs: { - int32_t temp = data; - ADD_PAGE - if ( opcode == 0x5E || opcode == 0x7E ) READ( data - ( temp & 0x100 ) ); - WRITE( data, temp = READ( data ) ); - nz = ((c >> 1) & 0x80) | (temp >> 1); - c = temp << 8; - goto rotate_common; - } - - case 0x76: // ROR zp,x - data = uint8_t (data + x); - goto ror_zp; - - case 0x56: // LSR zp,x - data = uint8_t (data + x); - case 0x46: // LSR zp - c = 0; - case 0x66: // ROR zp - ror_zp: { - int32_t temp = READ_LOW( data ); - nz = ((c >> 1) & 0x80) | (temp >> 1); - c = temp << 8; - goto write_nz_zp; - } - - case 0x36: // ROL zp,x - data = uint8_t (data + x); - goto rol_zp; - - case 0x16: // ASL zp,x - data = uint8_t (data + x); - case 0x06: // ASL zp - c = 0; - case 0x26: // ROL zp - rol_zp: - nz = (c >> 8) & 1; - nz |= (c = READ_LOW( data ) << 1); - goto write_nz_zp; - -// Increment/decrement - - case 0xCA: INC_DEC_XY( x, -1 ) // DEX - - case 0x88: INC_DEC_XY( y, -1 ) // DEY - - case 0xF6: // INC zp,x - data = uint8_t (data + x); - case 0xE6: // INC zp - nz = 1; - goto add_nz_zp; - - case 0xD6: // DEC zp,x - data = uint8_t (data + x); - case 0xC6: // DEC zp - nz = -1; - add_nz_zp: - nz += READ_LOW( data ); - write_nz_zp: - pc++; - WRITE_LOW( data, nz ); - goto loop; - - case 0xFE: { // INC abs,x - int32_t temp = data + x; - data = x + GET_ADDR(); - READ( data - ( temp & 0x100 ) ); - goto inc_ptr; - } - - case 0xEE: // INC abs - data = GET_ADDR(); - inc_ptr: - nz = 1; - goto inc_common; - - case 0xDE: { // DEC abs,x - int32_t temp = data + x; - data = x + GET_ADDR(); - READ( data - ( temp & 0x100 ) ); - goto dec_ptr; - } - - case 0xCE: // DEC abs - data = GET_ADDR(); - dec_ptr: - nz = -1; - inc_common: { - int32_t temp; - WRITE( data, temp = READ( data ) ); - nz += temp; - pc += 2; - WRITE( data, (uint8_t) nz ); - goto loop; - } - -// Transfer - - case 0xAA: // TAX - x = a; - case 0x8A: // TXA - a = nz = x; - goto loop; - - case 0x9A: // TXS - SET_SP( x ); // verified (no flag change) - goto loop; - - case 0xBA: // TSX - x = nz = GET_SP(); - goto loop; - -// Stack - - case 0x48: // PHA - PUSH( a ); // verified - goto loop; - - case 0x68: // PLA - a = nz = READ_LOW( sp ); - sp = (sp - 0xFF) | 0x100; - goto loop; - - case 0x40: // RTI - { - int32_t temp = READ_LOW( sp ); - pc = READ_LOW( 0x100 | (sp - 0xFF) ); - pc |= READ_LOW( 0x100 | (sp - 0xFE) ) * 0x100; - sp = (sp - 0xFD) | 0x100; - data = status; - SET_STATUS( temp ); + case 0xEC: + { // CPX abs + uint32_t addr = GET_ADDR(); + pc++; + data = READ(addr); + goto cpx_data; } - if ( !((data ^ status) & st_i) ) - goto loop; // I flag didn't change - i_flag_changed: - //dprintf( "%6d %s\n", time(), (status & st_i ? "SEI" : "CLI") ); - this->r.status = status; // update externally-visible I flag - // update clock_limit based on modified I flag - clock_limit = end_time_; - if ( end_time_ <= irq_time_ ) - goto loop; - if ( status & st_i ) - goto loop; - clock_limit = irq_time_; - goto loop; - case 0x28:{// PLP - int32_t temp = READ_LOW( sp ); - sp = (sp - 0xFF) | 0x100; - data = status; - SET_STATUS( temp ); - if ( !((data ^ status) & st_i) ) - goto loop; // I flag didn't change - if ( !(status & st_i) ) - goto handle_cli; - goto handle_sei; - } + case 0xE4: // CPX zp + data = READ_LOW(data); + case 0xE0: // CPX #imm + cpx_data: + nz = x - data; + pc++; + c = ~nz; + nz &= 0xFF; + goto loop; - case 0x08: { // PHP - int32_t temp; - CALC_STATUS( temp ); - PUSH( temp | st_b | st_r ); - goto loop; - } - - case 0x6C: // JMP (ind) - data = GET_ADDR(); - pc = READ( data ); - pc |= READ( (data & 0xFF00) | ((data + 1) & 0xFF) ) << 8; - goto loop; - - case 0x00: { // BRK - pc++; - WRITE_LOW( 0x100 | (sp - 1), pc >> 8 ); - WRITE_LOW( 0x100 | (sp - 2), pc ); - int32_t temp; - CALC_STATUS( temp ); - sp = (sp - 3) | 0x100; - WRITE_LOW( sp, temp | st_b | st_r ); - pc = *(uint16_t*)( &code_map [0xFFFE >> page_bits] [0xFFFE] ); - status |= st_i; - goto i_flag_changed; - } - -// Flags - - case 0x38: // SEC - c = ~0; - goto loop; - - case 0x18: // CLC - c = 0; - goto loop; - - case 0xB8: // CLV - status &= ~st_v; - goto loop; - - case 0xD8: // CLD - status &= ~st_d; - goto loop; - - case 0xF8: // SED - status |= st_d; - goto loop; - - case 0x58: // CLI - if ( !(status & st_i) ) - goto loop; - status &= ~st_i; - handle_cli: - //dprintf( "%6d CLI\n", time() ); - this->r.status = status; // update externally-visible I flag - if ( clock_count < end_time_ ) - { - if ( end_time_ <= irq_time_ ) - goto loop; // irq is later - if ( clock_count >= irq_time_ ) - irq_time_ = clock_count + 1; // delay IRQ until after next instruction - clock_limit = irq_time_; - goto loop; + case 0xCC: + { // CPY abs + uint32_t addr = GET_ADDR(); + pc++; + data = READ(addr); + goto cpy_data; } - // execution is stopping now, so delayed CLI must be handled by caller - result = result_cli; - goto end; - case 0x78: // SEI - if ( status & st_i ) - goto loop; - status |= st_i; - handle_sei: - //dprintf( "%6d SEI\n", time() ); - this->r.status = status; // update externally-visible I flag - clock_limit = end_time_; - if ( clock_count < irq_time_ ) - goto loop; - result = result_sei; // IRQ will occur now, even though I flag is set - goto end; + case 0xC4: // CPY zp + data = READ_LOW(data); + case 0xC0: // CPY #imm + cpy_data: + nz = y - data; + pc++; + c = ~nz; + nz &= 0xFF; + goto loop; -// Unofficial - case 0x1C: case 0x3C: case 0x5C: case 0x7C: case 0xDC: case 0xFC: { // SKW - data += x; - HANDLE_PAGE_CROSSING( data ); - int32_t addr = GET_ADDR() + x; - if ( data & 0x100 ) - READ( addr - 0x100 ); - READ( addr ); - } - case 0x0C: // SKW - pc++; - case 0x74: case 0x04: case 0x14: case 0x34: case 0x44: case 0x54: case 0x64: // SKB - case 0x80: case 0x82: case 0x89: case 0xC2: case 0xD4: case 0xE2: case 0xF4: - pc++; - case 0xEA: case 0x1A: case 0x3A: case 0x5A: case 0x7A: case 0xDA: case 0xFA: // NOP - goto loop; + // Logical - ARITH_ADDR_MODES_PTR( 0xC7 ) // DCP - WRITE( data, nz = READ( data ) ); - nz = uint8_t( nz - 1 ); - WRITE( data, nz ); - pc++; - nz = a - nz; - c = ~nz; - nz &= 0xFF; - goto loop; + ARITH_ADDR_MODES(0x25) // AND + nz = (a &= data); + pc++; + goto loop; - ARITH_ADDR_MODES_PTR( 0xE7 ) // ISC - WRITE( data, nz = READ( data ) ); - nz = uint8_t( nz + 1 ); - WRITE( data, nz ); - data = nz ^ 0xFF; - goto adc_imm; + ARITH_ADDR_MODES(0x45) // EOR + nz = (a ^= data); + pc++; + goto loop; - ARITH_ADDR_MODES_PTR( 0x27 ) { // RLA - WRITE( data, nz = READ( data ) ); - int32_t temp = c; - c = nz << 1; - nz = uint8_t( c ) | ( ( temp >> 8 ) & 0x01 ); - WRITE( data, nz ); - pc++; - nz = a &= nz; - goto loop; - } + ARITH_ADDR_MODES(0x05) // ORA + nz = (a |= data); + pc++; + goto loop; - ARITH_ADDR_MODES_PTR( 0x67 ) { // RRA - int32_t temp; - WRITE( data, temp = READ( data ) ); - nz = ((c >> 1) & 0x80) | (temp >> 1); - WRITE( data, nz ); - data = nz; - c = temp << 8; - goto adc_imm; - } + case 0x2C: + { // BIT abs + uint32_t addr = GET_ADDR(); + pc += 2; + status &= ~st_v; + nz = READ_LIKELY_PPU(addr); + status |= nz & st_v; + if (a & nz) + goto loop; + // result must be zero, even if N bit is set + nz = nz << 4 & 0x800; + goto loop; + } - ARITH_ADDR_MODES_PTR( 0x07 ) // SLO - WRITE( data, nz = READ( data ) ); - c = nz << 1; - nz = uint8_t( c ); - WRITE( data, nz ); - nz = (a |= nz); - pc++; - goto loop; + case 0x24: // BIT zp + nz = READ_LOW(data); + pc++; + status &= ~st_v; + status |= nz & st_v; + if (a & nz) + goto loop; + // result must be zero, even if N bit is set + nz = nz << 4 & 0x800; + goto loop; - ARITH_ADDR_MODES_PTR( 0x47 ) // SRE - WRITE( data, nz = READ( data ) ); - c = nz << 8; - nz >>= 1; - WRITE( data, nz ); - nz = a ^= nz; - pc++; - goto loop; + // Add/subtract - case 0x4B: // ALR - nz = (a &= data); - pc++; - goto lsr_a; + ARITH_ADDR_MODES(0xE5) // SBC + case 0xEB: // unofficial equivalent + data ^= 0xFF; + goto adc_imm; - case 0x0B: // ANC - case 0x2B: - nz = a &= data; - c = a << 1; - pc++; - goto loop; + ARITH_ADDR_MODES(0x65) // ADC + adc_imm: + { + int32_t carry = (c >> 8) & 1; + int32_t ov = (a ^ 0x80) + carry + (int8_t)data; // sign-extend + status &= ~st_v; + status |= (ov >> 2) & 0x40; + c = nz = a + data + carry; + pc++; + a = (uint8_t)nz; + goto loop; + } - case 0x6B: // ARR - nz = a = uint8_t( ( ( data & a ) >> 1 ) | ( ( c >> 1 ) & 0x80 ) ); - c = a << 2; - status = ( status & ~st_v ) | ( ( a ^ a << 1 ) & st_v ); - pc++; - goto loop; + // Shift/rotate - case 0xAB: // LXA - a = data; - x = data; - nz = data; - pc++; - goto loop; + case 0x4A: // LSR A + lsr_a: + c = 0; + case 0x6A: // ROR A + nz = (c >> 1) & 0x80; // could use bit insert macro here + c = a << 8; + nz |= a >> 1; + a = nz; + goto loop; - case 0xA3: // LAX - IND_X - goto lax_ptr; + case 0x0A: // ASL A + nz = a << 1; + c = nz; + a = (uint8_t)nz; + goto loop; - case 0xB3: - IND_Y(true,true) - goto lax_ptr; + case 0x2A: + { // ROL A + nz = a << 1; + int32_t temp = (c >> 8) & 1; + c = nz; + nz |= temp; + a = (uint8_t)nz; + goto loop; + } - case 0xB7: - data = uint8_t (data + y); + case 0x3E: // ROL abs,X + data += x; + goto rol_abs; - case 0xA7: - data = READ_LOW( data ); - goto lax_imm; + case 0x1E: // ASL abs,X + data += x; + case 0x0E: // ASL abs + c = 0; + case 0x2E: // ROL abs + rol_abs: + { + int32_t temp = data; + ADD_PAGE + if (opcode == 0x1E || opcode == 0x3E) READ(data - (temp & 0x100)); + WRITE(data, temp = READ(data)); + nz = (c >> 8) & 1; + nz |= (c = temp << 1); + } + rotate_common: + pc++; + WRITE(data, (uint8_t)nz); + goto loop; - case 0xBF: { - data += y; - HANDLE_PAGE_CROSSING( data ); - int32_t temp = data; - ADD_PAGE; - if ( temp & 0x100 ) - READ( data - 0x100 ); - goto lax_ptr; - } + case 0x7E: // ROR abs,X + data += x; + goto ror_abs; - case 0xAF: - ADD_PAGE + case 0x5E: // LSR abs,X + data += x; + case 0x4E: // LSR abs + c = 0; + case 0x6E: // ROR abs + ror_abs: + { + int32_t temp = data; + ADD_PAGE + if (opcode == 0x5E || opcode == 0x7E) READ(data - (temp & 0x100)); + WRITE(data, temp = READ(data)); + nz = ((c >> 1) & 0x80) | (temp >> 1); + c = temp << 8; + goto rotate_common; + } - lax_ptr: - data = READ( data ); - lax_imm: - nz = x = a = data; - pc++; - goto loop; + case 0x76: // ROR zp,x + data = uint8_t(data + x); + goto ror_zp; - case 0x83: // SAX - IND_X - goto sax_imm; + case 0x56: // LSR zp,x + data = uint8_t(data + x); + case 0x46: // LSR zp + c = 0; + case 0x66: // ROR zp + ror_zp: + { + int32_t temp = READ_LOW(data); + nz = ((c >> 1) & 0x80) | (temp >> 1); + c = temp << 8; + goto write_nz_zp; + } - case 0x97: - data = uint8_t (data + y); - goto sax_imm; + case 0x36: // ROL zp,x + data = uint8_t(data + x); + goto rol_zp; - case 0x8F: - ADD_PAGE + case 0x16: // ASL zp,x + data = uint8_t(data + x); + case 0x06: // ASL zp + c = 0; + case 0x26: // ROL zp + rol_zp: + nz = (c >> 8) & 1; + nz |= (c = READ_LOW(data) << 1); + goto write_nz_zp; - case 0x87: - sax_imm: - WRITE( data, a & x ); - pc++; - goto loop; + // Increment/decrement - case 0xCB: // SBX - data = ( a & x ) - data; - c = ( data <= 0xFF ) ? 0x100 : 0; - nz = x = uint8_t( data ); - pc++; - goto loop; + case 0xCA: INC_DEC_XY(x, -1) // DEX - case 0x93: // SHA (ind),Y - IND_Y(false,false) - pc++; - WRITE( data, uint8_t( a & x & ( ( data >> 8 ) + 1 ) ) ); - goto loop; + case 0x88: INC_DEC_XY(y, -1) // DEY - case 0x9F: { // SHA abs,Y - data += y; - int32_t temp = data; - ADD_PAGE - READ( data - ( temp & 0x100 ) ); - pc++; - WRITE( data, uint8_t( a & x & ( ( data >> 8 ) + 1 ) ) ); - goto loop; - } + case 0xF6: // INC zp,x + data = uint8_t(data + x); + case 0xE6: // INC zp + nz = 1; + goto add_nz_zp; - case 0x9E: { // SHX abs,Y - data += y; - int32_t temp = data; - ADD_PAGE - READ( data - ( temp & 0x100 ) ); - pc++; - if ( !( temp & 0x100 ) ) - WRITE( data, uint8_t( x & ( ( data >> 8 ) + 1 ) ) ); - goto loop; - } + case 0xD6: // DEC zp,x + data = uint8_t(data + x); + case 0xC6: // DEC zp + nz = -1; + add_nz_zp: + nz += READ_LOW(data); + write_nz_zp: + pc++; + WRITE_LOW(data, nz); + goto loop; - case 0x9C: { // SHY abs,X - data += x; - int32_t temp = data; - ADD_PAGE - READ( data - ( temp & 0x100 ) ); - pc++; - if ( !( temp & 0x100) ) - WRITE( data, uint8_t( y & ( ( data >> 8 ) + 1 ) ) ); - goto loop; - } + case 0xFE: + { // INC abs,x + int32_t temp = data + x; + data = x + GET_ADDR(); + READ(data - (temp & 0x100)); + goto inc_ptr; + } - case 0x9B: { // SHS abs,Y - data += y; - int32_t temp = data; - ADD_PAGE - READ( data - ( temp & 0x100 ) ); - pc++; - SET_SP( a & x ); - WRITE( data, uint8_t( a & x & ( ( data >> 8 ) + 1 ) ) ); - goto loop; - } + case 0xEE: // INC abs + data = GET_ADDR(); + inc_ptr: + nz = 1; + goto inc_common; - case 0xBB: { // LAS abs,Y - data += y; - HANDLE_PAGE_CROSSING( data ); - int32_t temp = data; - ADD_PAGE - if ( temp & 0x100 ) - READ( data - 0x100 ); - pc++; - a = GET_SP(); - x = a &= READ( data ); - SET_SP( a ); - goto loop; - } + case 0xDE: + { // DEC abs,x + int32_t temp = data + x; + data = x + GET_ADDR(); + READ(data - (temp & 0x100)); + goto dec_ptr; + } - // KIL (JAM) [HLT] - default: - //case 0x02: case 0x12: case 0x22: case 0x32: case 0x42: case 0x52: case 0x62: case 0x72: case 0x92: case 0xB2: case 0xD2: case 0xF2: - isCorrectExecution = false; - goto stop; + case 0xCE: // DEC abs + data = GET_ADDR(); + dec_ptr: + nz = -1; + inc_common: + { + int32_t temp; + WRITE(data, temp = READ(data)); + nz += temp; + pc += 2; + WRITE(data, (uint8_t)nz); + goto loop; + } -// Unimplemented + // Transfer -// case page_wrap_opcode: // HLT -// if ( pc > 0x10000 ) -// { -// // handle wrap-around (assumes caller has put page of HLT at 0x10000) -// pc = (pc - 1) & 0xFFFF; -// clock_count -= 2; -// goto loop; -// } - // fall through -// default: -// // skip over proper number of bytes -// static uint32_t char const row [8] = { 0x95, 0x95, 0x95, 0xd5, 0x95, 0x95, 0xd5, 0xf5 }; -// int len = row [opcode >> 2 & 7] >> (opcode << 1 & 6) & 3; -// if ( opcode == 0x9C ) -// len = 3; -// pc += len - 1; -// error_count_++; -// goto loop; + case 0xAA: // TAX + x = a; + case 0x8A: // TXA + a = nz = x; + goto loop; - //result = result_badop; // TODO: re-enable - goto stop; - } + case 0x9A: // TXS + SET_SP(x); // verified (no flag change) + goto loop; + + case 0xBA: // TSX + x = nz = GET_SP(); + goto loop; + + // Stack + + case 0x48: // PHA + PUSH(a); // verified + goto loop; + + case 0x68: // PLA + a = nz = READ_LOW(sp); + sp = (sp - 0xFF) | 0x100; + goto loop; + + case 0x40: // RTI + { + int32_t temp = READ_LOW(sp); + pc = READ_LOW(0x100 | (sp - 0xFF)); + pc |= READ_LOW(0x100 | (sp - 0xFE)) * 0x100; + sp = (sp - 0xFD) | 0x100; + data = status; + SET_STATUS(temp); + } + if (!((data ^ status) & st_i)) + goto loop; // I flag didn't change + i_flag_changed: + // dprintf( "%6d %s\n", time(), (status & st_i ? "SEI" : "CLI") ); + this->r.status = status; // update externally-visible I flag + // update clock_limit based on modified I flag + clock_limit = end_time_; + if (end_time_ <= irq_time_) + goto loop; + if (status & st_i) + goto loop; + clock_limit = irq_time_; + goto loop; + + case 0x28: + { // PLP + int32_t temp = READ_LOW(sp); + sp = (sp - 0xFF) | 0x100; + data = status; + SET_STATUS(temp); + if (!((data ^ status) & st_i)) + goto loop; // I flag didn't change + if (!(status & st_i)) + goto handle_cli; + goto handle_sei; + } + + case 0x08: + { // PHP + int32_t temp; + CALC_STATUS(temp); + PUSH(temp | st_b | st_r); + goto loop; + } + + case 0x6C: // JMP (ind) + data = GET_ADDR(); + pc = READ(data); + pc |= READ((data & 0xFF00) | ((data + 1) & 0xFF)) << 8; + goto loop; + + case 0x00: + { // BRK + pc++; + WRITE_LOW(0x100 | (sp - 1), pc >> 8); + WRITE_LOW(0x100 | (sp - 2), pc); + int32_t temp; + CALC_STATUS(temp); + sp = (sp - 3) | 0x100; + WRITE_LOW(sp, temp | st_b | st_r); + pc = *(uint16_t *)(&code_map[0xFFFE >> page_bits][0xFFFE]); + status |= st_i; + goto i_flag_changed; + } + + // Flags + + case 0x38: // SEC + c = ~0; + goto loop; + + case 0x18: // CLC + c = 0; + goto loop; + + case 0xB8: // CLV + status &= ~st_v; + goto loop; + + case 0xD8: // CLD + status &= ~st_d; + goto loop; + + case 0xF8: // SED + status |= st_d; + goto loop; + + case 0x58: // CLI + if (!(status & st_i)) + goto loop; + status &= ~st_i; + handle_cli: + // dprintf( "%6d CLI\n", time() ); + this->r.status = status; // update externally-visible I flag + if (clock_count < end_time_) + { + if (end_time_ <= irq_time_) + goto loop; // irq is later + if (clock_count >= irq_time_) + irq_time_ = clock_count + 1; // delay IRQ until after next instruction + clock_limit = irq_time_; + goto loop; + } + // execution is stopping now, so delayed CLI must be handled by caller + result = result_cli; + goto end; + + case 0x78: // SEI + if (status & st_i) + goto loop; + status |= st_i; + handle_sei: + // dprintf( "%6d SEI\n", time() ); + this->r.status = status; // update externally-visible I flag + clock_limit = end_time_; + if (clock_count < irq_time_) + goto loop; + result = result_sei; // IRQ will occur now, even though I flag is set + goto end; + + // Unofficial + case 0x1C: + case 0x3C: + case 0x5C: + case 0x7C: + case 0xDC: + case 0xFC: + { // SKW + data += x; + HANDLE_PAGE_CROSSING(data); + int32_t addr = GET_ADDR() + x; + if (data & 0x100) + READ(addr - 0x100); + READ(addr); + } + case 0x0C: // SKW + pc++; + case 0x74: + case 0x04: + case 0x14: + case 0x34: + case 0x44: + case 0x54: + case 0x64: // SKB + case 0x80: + case 0x82: + case 0x89: + case 0xC2: + case 0xD4: + case 0xE2: + case 0xF4: + pc++; + case 0xEA: + case 0x1A: + case 0x3A: + case 0x5A: + case 0x7A: + case 0xDA: + case 0xFA: // NOP + goto loop; + + ARITH_ADDR_MODES_PTR(0xC7) // DCP + WRITE(data, nz = READ(data)); + nz = uint8_t(nz - 1); + WRITE(data, nz); + pc++; + nz = a - nz; + c = ~nz; + nz &= 0xFF; + goto loop; + + ARITH_ADDR_MODES_PTR(0xE7) // ISC + WRITE(data, nz = READ(data)); + nz = uint8_t(nz + 1); + WRITE(data, nz); + data = nz ^ 0xFF; + goto adc_imm; + + ARITH_ADDR_MODES_PTR(0x27) + { // RLA + WRITE(data, nz = READ(data)); + int32_t temp = c; + c = nz << 1; + nz = uint8_t(c) | ((temp >> 8) & 0x01); + WRITE(data, nz); + pc++; + nz = a &= nz; + goto loop; + } + + ARITH_ADDR_MODES_PTR(0x67) + { // RRA + int32_t temp; + WRITE(data, temp = READ(data)); + nz = ((c >> 1) & 0x80) | (temp >> 1); + WRITE(data, nz); + data = nz; + c = temp << 8; + goto adc_imm; + } + + ARITH_ADDR_MODES_PTR(0x07) // SLO + WRITE(data, nz = READ(data)); + c = nz << 1; + nz = uint8_t(c); + WRITE(data, nz); + nz = (a |= nz); + pc++; + goto loop; + + ARITH_ADDR_MODES_PTR(0x47) // SRE + WRITE(data, nz = READ(data)); + c = nz << 8; + nz >>= 1; + WRITE(data, nz); + nz = a ^= nz; + pc++; + goto loop; + + case 0x4B: // ALR + nz = (a &= data); + pc++; + goto lsr_a; + + case 0x0B: // ANC + case 0x2B: + nz = a &= data; + c = a << 1; + pc++; + goto loop; + + case 0x6B: // ARR + nz = a = uint8_t(((data & a) >> 1) | ((c >> 1) & 0x80)); + c = a << 2; + status = (status & ~st_v) | ((a ^ a << 1) & st_v); + pc++; + goto loop; + + case 0xAB: // LXA + a = data; + x = data; + nz = data; + pc++; + goto loop; + + case 0xA3: // LAX + IND_X + goto lax_ptr; + + case 0xB3: + IND_Y(true, true) + goto lax_ptr; + + case 0xB7: + data = uint8_t(data + y); + + case 0xA7: + data = READ_LOW(data); + goto lax_imm; + + case 0xBF: + { + data += y; + HANDLE_PAGE_CROSSING(data); + int32_t temp = data; + ADD_PAGE; + if (temp & 0x100) + READ(data - 0x100); + goto lax_ptr; + } + + case 0xAF: + ADD_PAGE + + lax_ptr: + data = READ(data); + lax_imm: + nz = x = a = data; + pc++; + goto loop; + + case 0x83: // SAX + IND_X + goto sax_imm; + + case 0x97: + data = uint8_t(data + y); + goto sax_imm; + + case 0x8F: + ADD_PAGE + + case 0x87: + sax_imm: + WRITE(data, a & x); + pc++; + goto loop; + + case 0xCB: // SBX + data = (a & x) - data; + c = (data <= 0xFF) ? 0x100 : 0; + nz = x = uint8_t(data); + pc++; + goto loop; + + case 0x93: // SHA (ind),Y + IND_Y(false, false) + pc++; + WRITE(data, uint8_t(a & x & ((data >> 8) + 1))); + goto loop; + + case 0x9F: + { // SHA abs,Y + data += y; + int32_t temp = data; + ADD_PAGE + READ(data - (temp & 0x100)); + pc++; + WRITE(data, uint8_t(a & x & ((data >> 8) + 1))); + goto loop; + } + + case 0x9E: + { // SHX abs,Y + data += y; + int32_t temp = data; + ADD_PAGE + READ(data - (temp & 0x100)); + pc++; + if (!(temp & 0x100)) + WRITE(data, uint8_t(x & ((data >> 8) + 1))); + goto loop; + } + + case 0x9C: + { // SHY abs,X + data += x; + int32_t temp = data; + ADD_PAGE + READ(data - (temp & 0x100)); + pc++; + if (!(temp & 0x100)) + WRITE(data, uint8_t(y & ((data >> 8) + 1))); + goto loop; + } + + case 0x9B: + { // SHS abs,Y + data += y; + int32_t temp = data; + ADD_PAGE + READ(data - (temp & 0x100)); + pc++; + SET_SP(a & x); + WRITE(data, uint8_t(a & x & ((data >> 8) + 1))); + goto loop; + } + + case 0xBB: + { // LAS abs,Y + data += y; + HANDLE_PAGE_CROSSING(data); + int32_t temp = data; + ADD_PAGE + if (temp & 0x100) + READ(data - 0x100); + pc++; + a = GET_SP(); + x = a &= READ(data); + SET_SP(a); + goto loop; + } + + // KIL (JAM) [HLT] + default: + // case 0x02: case 0x12: case 0x22: case 0x32: case 0x42: case 0x52: case 0x62: case 0x72: case 0x92: case 0xB2: case 0xD2: case 0xF2: + isCorrectExecution = false; + goto stop; + + // Unimplemented + + // case page_wrap_opcode: // HLT + // if ( pc > 0x10000 ) + // { + // // handle wrap-around (assumes caller has put page of HLT at 0x10000) + // pc = (pc - 1) & 0xFFFF; + // clock_count -= 2; + // goto loop; + // } + // fall through + // default: + // // skip over proper number of bytes + // static uint32_t char const row [8] = { 0x95, 0x95, 0x95, 0xd5, 0x95, 0x95, 0xd5, 0xf5 }; + // int len = row [opcode >> 2 & 7] >> (opcode << 1 & 6) & 3; + // if ( opcode == 0x9C ) + // len = 3; + // pc += len - 1; + // error_count_++; + // goto loop; + + // result = result_badop; // TODO: re-enable + goto stop; + } stop: - pc--; + pc--; end: - { +{ int temp; - CALC_STATUS( temp ); + CALC_STATUS(temp); r.status = temp; - } - - this->clock_count = clock_count; - r.pc = pc; - r.sp = GET_SP(); - r.a = a; - r.x = x; - r.y = y; - irq_time_ = LONG_MAX / 2 + 1; - - return result; } + this->clock_count = clock_count; + r.pc = pc; + r.sp = GET_SP(); + r.a = a; + r.x = x; + r.y = y; + irq_time_ = LONG_MAX / 2 + 1; -} // namespace quickNES \ No newline at end of file + return result; +} + +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/cpu.hpp b/source/quickerNES/core/cpu.hpp index 4b2a798..7466395 100644 --- a/source/quickerNES/core/cpu.hpp +++ b/source/quickerNES/core/cpu.hpp @@ -14,7 +14,6 @@ typedef unsigned nes_addr_t; // 16-bit address class Cpu { public: - void set_tracecb(void (*cb)(unsigned int *data)) { tracecb = cb; @@ -152,10 +151,10 @@ class Cpu return (uint8_t *)code_map[addr >> page_bits] + addr; } - inline const uint8_t *get_code(nes_addr_t addr) const + inline const uint8_t *get_code(nes_addr_t addr) const { return (const uint8_t *)code_map[addr >> page_bits] + addr; } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/emu.cpp b/source/quickerNES/core/emu.cpp index b66cadf..beeb28e 100644 --- a/source/quickerNES/core/emu.cpp +++ b/source/quickerNES/core/emu.cpp @@ -1,10 +1,10 @@ // Emu 0.7.0. http://www.slack.net/~ant/ -#include -#include "mappers/mapper.hpp" #include "emu.hpp" #include "apu/NESEffectsBuffer.hpp" #include "apu/buffer.hpp" +#include "mappers/mapper.hpp" +#include /* Copyright (C) 2004-2006 Shay Green. This module is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser @@ -22,163 +22,162 @@ namespace quickerNES int const sound_fade_size = 384; -Emu::equalizer_t const Emu::nes_eq = { -1.0, 80 }; -Emu::equalizer_t const Emu::famicom_eq = { -15.0, 80 }; -Emu::equalizer_t const Emu::tv_eq = { -12.0, 180 }; -Emu::equalizer_t const Emu::flat_eq = { 0.0, 1 }; -Emu::equalizer_t const Emu::crisp_eq = { 5.0, 1 }; -Emu::equalizer_t const Emu::tinny_eq = { -47.0, 2000 }; +Emu::equalizer_t const Emu::nes_eq = {-1.0, 80}; +Emu::equalizer_t const Emu::famicom_eq = {-15.0, 80}; +Emu::equalizer_t const Emu::tv_eq = {-12.0, 180}; +Emu::equalizer_t const Emu::flat_eq = {0.0, 1}; +Emu::equalizer_t const Emu::crisp_eq = {5.0, 1}; +Emu::equalizer_t const Emu::tinny_eq = {-47.0, 2000}; Emu::Emu() { - frame_ = &single_frame; - buffer_height_ = Ppu::buffer_height + 2; - default_sound_buf = NULL; - sound_buf = &silent_buffer; - sound_buf_changed_count = 0; - equalizer_ = nes_eq; - channel_count_ = 0; - sound_enabled = false; - host_pixels = NULL; - single_frame.pixels = 0; - single_frame.top = 0; - init_called = false; - set_palette_range( 0 ); - memset( single_frame.palette, 0, sizeof single_frame.palette ); + frame_ = &single_frame; + buffer_height_ = Ppu::buffer_height + 2; + default_sound_buf = NULL; + sound_buf = &silent_buffer; + sound_buf_changed_count = 0; + equalizer_ = nes_eq; + channel_count_ = 0; + sound_enabled = false; + host_pixels = NULL; + single_frame.pixels = 0; + single_frame.top = 0; + init_called = false; + set_palette_range(0); + memset(single_frame.palette, 0, sizeof single_frame.palette); - extra_fade_sound_in = false; - extra_fade_sound_out = false; - extra_sound_buf_changed_count = 0; + extra_fade_sound_in = false; + extra_fade_sound_out = false; + extra_sound_buf_changed_count = 0; } Emu::~Emu() { - delete default_sound_buf; + delete default_sound_buf; } -const char * Emu::init_() +const char *Emu::init_() { - return emu.init(); + return emu.init(); } -inline const char * Emu::auto_init() +inline const char *Emu::auto_init() { - if ( !init_called ) - { - init_(); - init_called = true; - } - return 0; + if (!init_called) + { + init_(); + init_called = true; + } + return 0; } - inline void Emu::clear_sound_buf() { - fade_sound_out = false; - fade_sound_in = true; - sound_buf->clear(); + fade_sound_out = false; + fade_sound_in = true; + sound_buf->clear(); } -void Emu::set_cart( Cart const* new_cart ) +void Emu::set_cart(Cart const *new_cart) { - auto_init(); - emu.open( new_cart ); + auto_init(); + emu.open(new_cart); - channel_count_ = Apu::osc_count + emu.mapper->channel_count(); - sound_buf->set_channel_count( channel_count() ); - set_equalizer( equalizer_ ); - enable_sound( true ); - reset(); + channel_count_ = Apu::osc_count + emu.mapper->channel_count(); + sound_buf->set_channel_count(channel_count()); + set_equalizer(equalizer_); + enable_sound(true); + reset(); } -void Emu::reset( bool full_reset, bool erase_battery_ram ) +void Emu::reset(bool full_reset, bool erase_battery_ram) { - clear_sound_buf(); - set_timestamp( 0 ); - emu.reset( full_reset, erase_battery_ram ); + clear_sound_buf(); + set_timestamp(0); + emu.reset(full_reset, erase_battery_ram); } -void Emu::set_palette_range( int begin, int end ) +void Emu::set_palette_range(int begin, int end) { - // round up to alignment - emu.ppu.palette_begin = (begin + palette_alignment - 1) & ~(palette_alignment - 1); - host_palette_size = end - emu.ppu.palette_begin; + // round up to alignment + emu.ppu.palette_begin = (begin + palette_alignment - 1) & ~(palette_alignment - 1); + host_palette_size = end - emu.ppu.palette_begin; } -const char * Emu::emulate_skip_frame( uint32_t joypad1, uint32_t joypad2 ) +const char *Emu::emulate_skip_frame(uint32_t joypad1, uint32_t joypad2) { - char *old_host_pixels = host_pixels; - host_pixels = NULL; - emu.emulate_frame(joypad1, joypad2); - host_pixels = old_host_pixels; - return 0; + char *old_host_pixels = host_pixels; + host_pixels = NULL; + emu.emulate_frame(joypad1, joypad2); + host_pixels = old_host_pixels; + return 0; } -const char * Emu::emulate_frame( uint32_t joypad1, uint32_t joypad2 ) +const char *Emu::emulate_frame(uint32_t joypad1, uint32_t joypad2) { - emu.ppu.host_pixels = NULL; + emu.ppu.host_pixels = NULL; - unsigned changed_count = sound_buf->channels_changed_count(); - bool new_enabled = (frame_ != NULL); + unsigned changed_count = sound_buf->channels_changed_count(); + bool new_enabled = (frame_ != NULL); - if ( sound_buf_changed_count != changed_count || sound_enabled != new_enabled ) - { - sound_buf_changed_count = changed_count; - sound_enabled = new_enabled; - enable_sound( sound_enabled ); - } + if (sound_buf_changed_count != changed_count || sound_enabled != new_enabled) + { + sound_buf_changed_count = changed_count; + sound_enabled = new_enabled; + enable_sound(sound_enabled); + } - frame_t* f = frame_; - if ( f ) - { - emu.ppu.max_palette_size = host_palette_size; - emu.ppu.host_palette = f->palette + emu.ppu.palette_begin; - // add black and white for emulator to use (unless emulator uses entire - // palette for frame) - f->palette [252] = 0x0F; - f->palette [254] = 0x30; - f->palette [255] = 0x0F; - if ( host_pixels ) - emu.ppu.host_pixels = (uint8_t*) host_pixels + - emu.ppu.host_row_bytes * f->top; + frame_t *f = frame_; + if (f) + { + emu.ppu.max_palette_size = host_palette_size; + emu.ppu.host_palette = f->palette + emu.ppu.palette_begin; + // add black and white for emulator to use (unless emulator uses entire + // palette for frame) + f->palette[252] = 0x0F; + f->palette[254] = 0x30; + f->palette[255] = 0x0F; + if (host_pixels) + emu.ppu.host_pixels = (uint8_t *)host_pixels + + emu.ppu.host_row_bytes * f->top; - if ( sound_buf->samples_avail() ) - clear_sound_buf(); + if (sound_buf->samples_avail()) + clear_sound_buf(); - nes_time_t frame_len = emu.emulate_frame(joypad1, joypad2); - sound_buf->end_frame( frame_len, false ); + nes_time_t frame_len = emu.emulate_frame(joypad1, joypad2); + sound_buf->end_frame(frame_len, false); - f = frame_; - f->sample_count = sound_buf->samples_avail(); - f->chan_count = sound_buf->samples_per_frame(); - f->palette_begin = emu.ppu.palette_begin; - f->palette_size = emu.ppu.palette_size; - f->burst_phase = emu.ppu.burst_phase; - f->pitch = emu.ppu.host_row_bytes; - f->pixels = emu.ppu.host_pixels + f->left; - } - else - { - emu.ppu.max_palette_size = 0; - emu.emulate_frame(joypad1, joypad2); - } + f = frame_; + f->sample_count = sound_buf->samples_avail(); + f->chan_count = sound_buf->samples_per_frame(); + f->palette_begin = emu.ppu.palette_begin; + f->palette_size = emu.ppu.palette_size; + f->burst_phase = emu.ppu.burst_phase; + f->pitch = emu.ppu.host_row_bytes; + f->pixels = emu.ppu.host_pixels + f->left; + } + else + { + emu.ppu.max_palette_size = 0; + emu.emulate_frame(joypad1, joypad2); + } - return 0; + return 0; } // Extras -void Emu::load_ines( const uint8_t* buffer ) +void Emu::load_ines(const uint8_t *buffer) { - private_cart.load_ines( buffer ); - set_cart( &private_cart ); + private_cart.load_ines(buffer); + set_cart(&private_cart); } -void Emu::write_chr( void const* p, long count, long offset ) +void Emu::write_chr(void const *p, long count, long offset) { - long end = offset + count; - memcpy( (uint8_t*) chr_mem() + offset, p, count ); - emu.ppu.rebuild_chr( offset, end ); + long end = offset + count; + memcpy((uint8_t *)chr_mem() + offset, p, count); + emu.ppu.rebuild_chr(offset, end); } Multi_Buffer *set_apu(Nes_Effects_Buffer *buf, Apu *apu) @@ -193,268 +192,651 @@ Multi_Buffer *set_apu(Buffer *buf, Apu *apu) return buf; } -const char * Emu::set_sample_rate( long rate, class Buffer* buf ) +const char *Emu::set_sample_rate(long rate, class Buffer *buf) { - auto_init(); - return set_sample_rate( rate, set_apu( buf, &emu.impl->apu ) ); + auto_init(); + return set_sample_rate(rate, set_apu(buf, &emu.impl->apu)); } -const char * Emu::set_sample_rate( long rate, class Nes_Effects_Buffer* buf ) +const char *Emu::set_sample_rate(long rate, class Nes_Effects_Buffer *buf) { - auto_init(); - return set_sample_rate( rate, set_apu( buf, &emu.impl->apu ) ); + auto_init(); + return set_sample_rate(rate, set_apu(buf, &emu.impl->apu)); } // Sound -void Emu::set_frame_rate( double rate ) +void Emu::set_frame_rate(double rate) { - sound_buf->clock_rate( (long) (1789773 / 60.0 * rate) ); + sound_buf->clock_rate((long)(1789773 / 60.0 * rate)); } -const char * Emu::set_sample_rate( long rate, Multi_Buffer* new_buf ) +const char *Emu::set_sample_rate(long rate, Multi_Buffer *new_buf) { - auto_init(); - emu.impl->apu.volume( 1.0 ); // cancel any previous non-linearity - new_buf->set_sample_rate( rate, 1200 / frame_rate ); - sound_buf = new_buf; - sound_buf_changed_count = 0; - if ( new_buf != default_sound_buf ) - { - delete default_sound_buf; - default_sound_buf = NULL; - } - set_frame_rate( frame_rate ); - return 0; + auto_init(); + emu.impl->apu.volume(1.0); // cancel any previous non-linearity + new_buf->set_sample_rate(rate, 1200 / frame_rate); + sound_buf = new_buf; + sound_buf_changed_count = 0; + if (new_buf != default_sound_buf) + { + delete default_sound_buf; + default_sound_buf = NULL; + } + set_frame_rate(frame_rate); + return 0; } -const char * Emu::set_sample_rate( long rate ) +const char *Emu::set_sample_rate(long rate) { - if ( !default_sound_buf ) default_sound_buf = new Mono_Buffer; - return set_sample_rate( rate, default_sound_buf ); + if (!default_sound_buf) default_sound_buf = new Mono_Buffer; + return set_sample_rate(rate, default_sound_buf); } -void Emu::set_equalizer( equalizer_t const& eq ) +void Emu::set_equalizer(equalizer_t const &eq) { - equalizer_ = eq; - if ( cart() ) - { - blip_eq_t blip_eq( eq.treble, 0, sound_buf->sample_rate() ); - emu.impl->apu.treble_eq( blip_eq ); - emu.mapper->set_treble( blip_eq ); - sound_buf->bass_freq( equalizer_.bass ); - } + equalizer_ = eq; + if (cart()) + { + blip_eq_t blip_eq(eq.treble, 0, sound_buf->sample_rate()); + emu.impl->apu.treble_eq(blip_eq); + emu.mapper->set_treble(blip_eq); + sound_buf->bass_freq(equalizer_.bass); + } } -void Emu::enable_sound( bool enabled ) +void Emu::enable_sound(bool enabled) { - if ( enabled ) - { - for ( int i = channel_count(); i-- > 0; ) - { - Blip_Buffer* buf = sound_buf->channel( i ).center; - int mapper_index = i - Apu::osc_count; - if ( mapper_index < 0 ) - emu.impl->apu.osc_output( i, buf ); - else - emu.mapper->set_channel_buf( mapper_index, buf ); - } - } - else - { - emu.impl->apu.output( NULL ); - for ( int i = channel_count() - Apu::osc_count; i-- > 0; ) - emu.mapper->set_channel_buf( i, NULL ); - } + if (enabled) + { + for (int i = channel_count(); i-- > 0;) + { + Blip_Buffer *buf = sound_buf->channel(i).center; + int mapper_index = i - Apu::osc_count; + if (mapper_index < 0) + emu.impl->apu.osc_output(i, buf); + else + emu.mapper->set_channel_buf(mapper_index, buf); + } + } + else + { + emu.impl->apu.output(NULL); + for (int i = channel_count() - Apu::osc_count; i-- > 0;) + emu.mapper->set_channel_buf(i, NULL); + } } -void Emu::fade_samples( blip_sample_t* p, int size, int step ) +void Emu::fade_samples(blip_sample_t *p, int size, int step) { - if ( size >= sound_fade_size ) - { - if ( step < 0 ) - p += size - sound_fade_size; + if (size >= sound_fade_size) + { + if (step < 0) + p += size - sound_fade_size; - int const shift = 15; - int mul = (1 - step) << (shift - 1); - step *= (1 << shift) / sound_fade_size; + int const shift = 15; + int mul = (1 - step) << (shift - 1); + step *= (1 << shift) / sound_fade_size; - for ( int n = sound_fade_size; n--; ) - { - *p = (*p * mul) >> 15; - ++p; - mul += step; - } - } + for (int n = sound_fade_size; n--;) + { + *p = (*p * mul) >> 15; + ++p; + mul += step; + } + } } -long Emu::read_samples( short* out, long out_size ) +long Emu::read_samples(short *out, long out_size) { - long count = sound_buf->read_samples( out, out_size ); - if ( fade_sound_in ) - { - fade_sound_in = false; - if (out != NULL) - fade_samples( out, count, 1 ); - } + long count = sound_buf->read_samples(out, out_size); + if (fade_sound_in) + { + fade_sound_in = false; + if (out != NULL) + fade_samples(out, count, 1); + } - if ( fade_sound_out ) - { - fade_sound_out = false; - fade_sound_in = true; // next buffer should be faded in - if (out != NULL) - fade_samples( out, count, -1 ); - } - return count; + if (fade_sound_out) + { + fade_sound_out = false; + fade_sound_in = true; // next buffer should be faded in + if (out != NULL) + fade_samples(out, count, -1); + } + return count; } -Emu::rgb_t const Emu::nes_colors [color_table_size] = -{ - // generated with nes_ntsc default settings - {102,102,102},{ 0, 42,136},{ 20, 18,168},{ 59, 0,164}, - { 92, 0,126},{110, 0, 64},{108, 7, 0},{ 87, 29, 0}, - { 52, 53, 0},{ 12, 73, 0},{ 0, 82, 0},{ 0, 79, 8}, - { 0, 64, 78},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {174,174,174},{ 21, 95,218},{ 66, 64,254},{118, 39,255}, - {161, 27,205},{184, 30,124},{181, 50, 32},{153, 79, 0}, - {108,110, 0},{ 56,135, 0},{ 13,148, 0},{ 0,144, 50}, - { 0,124,142},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {254,254,254},{100,176,254},{147,144,254},{199,119,254}, - {243,106,254},{254,110,205},{254,130,112},{235,159, 35}, - {189,191, 0},{137,217, 0},{ 93,229, 48},{ 69,225,130}, - { 72,206,223},{ 79, 79, 79},{ 0, 0, 0},{ 0, 0, 0}, - {254,254,254},{193,224,254},{212,211,254},{233,200,254}, - {251,195,254},{254,197,235},{254,205,198},{247,217,166}, - {229,230,149},{208,240,151},{190,245,171},{180,243,205}, - {181,236,243},{184,184,184},{ 0, 0, 0},{ 0, 0, 0}, +Emu::rgb_t const Emu::nes_colors[color_table_size] = + { + // generated with nes_ntsc default settings + {102, 102, 102}, + {0, 42, 136}, + {20, 18, 168}, + {59, 0, 164}, + {92, 0, 126}, + {110, 0, 64}, + {108, 7, 0}, + {87, 29, 0}, + {52, 53, 0}, + {12, 73, 0}, + {0, 82, 0}, + {0, 79, 8}, + {0, 64, 78}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {174, 174, 174}, + {21, 95, 218}, + {66, 64, 254}, + {118, 39, 255}, + {161, 27, 205}, + {184, 30, 124}, + {181, 50, 32}, + {153, 79, 0}, + {108, 110, 0}, + {56, 135, 0}, + {13, 148, 0}, + {0, 144, 50}, + {0, 124, 142}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {254, 254, 254}, + {100, 176, 254}, + {147, 144, 254}, + {199, 119, 254}, + {243, 106, 254}, + {254, 110, 205}, + {254, 130, 112}, + {235, 159, 35}, + {189, 191, 0}, + {137, 217, 0}, + {93, 229, 48}, + {69, 225, 130}, + {72, 206, 223}, + {79, 79, 79}, + {0, 0, 0}, + {0, 0, 0}, + {254, 254, 254}, + {193, 224, 254}, + {212, 211, 254}, + {233, 200, 254}, + {251, 195, 254}, + {254, 197, 235}, + {254, 205, 198}, + {247, 217, 166}, + {229, 230, 149}, + {208, 240, 151}, + {190, 245, 171}, + {180, 243, 205}, + {181, 236, 243}, + {184, 184, 184}, + {0, 0, 0}, + {0, 0, 0}, - {114, 83, 79},{ 0, 23,113},{ 32, 0,145},{ 71, 0,141}, - {104, 0,103},{122, 0, 41},{120, 0, 0},{ 99, 10, 0}, - { 64, 34, 0},{ 24, 54, 0},{ 0, 63, 0},{ 0, 60, 0}, - { 0, 45, 54},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {190,148,143},{ 37, 69,187},{ 83, 38,228},{134, 13,224}, - {177, 1,174},{200, 4, 92},{198, 24, 1},{170, 53, 0}, - {124, 84, 0},{ 73,109, 0},{ 30,122, 0},{ 6,118, 19}, - { 9, 98,110},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {254,222,215},{122,142,254},{168,110,254},{220, 85,254}, - {254, 72,247},{254, 76,164},{254, 96, 71},{254,125, 0}, - {210,157, 0},{158,183, 0},{114,195, 7},{ 90,191, 89}, - { 93,172,182},{ 79, 79, 79},{ 0, 0, 0},{ 0, 0, 0}, - {254,222,215},{214,190,233},{233,177,250},{254,166,248}, - {254,161,228},{254,163,194},{254,171,157},{254,183,125}, - {250,196,108},{229,206,110},{211,211,130},{201,210,164}, - {203,202,202},{184,184,184},{ 0, 0, 0},{ 0, 0, 0}, - { 75,106, 64},{ 0, 46, 98},{ 0, 22,130},{ 32, 3,126}, - { 65, 0, 88},{ 82, 0, 26},{ 80, 11, 0},{ 59, 34, 0}, - { 24, 58, 0},{ 0, 77, 0},{ 0, 86, 0},{ 0, 83, 0}, - { 0, 68, 39},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {136,180,122},{ 0,101,166},{ 29, 69,208},{ 80, 44,203}, - {123, 32,153},{146, 36, 72},{144, 55, 0},{116, 84, 0}, - { 70,116, 0},{ 19,141, 0},{ 0,153, 0},{ 0,149, 0}, - { 0,130, 90},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {207,254,188},{ 51,183,233},{ 98,151,254},{150,126,254}, - {193,113,220},{217,117,137},{214,137, 45},{186,166, 0}, - {140,198, 0},{ 88,224, 0},{ 44,236, 0},{ 20,232, 63}, - { 23,213,155},{ 79, 79, 79},{ 0, 0, 0},{ 0, 0, 0}, - {207,254,188},{144,231,207},{163,218,224},{184,207,222}, - {201,202,201},{211,204,168},{210,212,130},{198,224, 99}, - {180,237, 81},{159,247, 83},{141,252,104},{131,251,137}, - {132,243,175},{184,184,184},{ 0, 0, 0},{ 0, 0, 0}, - { 83, 83, 55},{ 0, 23, 89},{ 0, 0,121},{ 40, 0,117}, - { 73, 0, 79},{ 90, 0, 17},{ 88, 0, 0},{ 67, 10, 0}, - { 32, 34, 0},{ 0, 53, 0},{ 0, 63, 0},{ 0, 60, 0}, - { 0, 45, 30},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {147,148,110},{ 0, 69,154},{ 40, 38,196},{ 91, 12,191}, - {134, 0,141},{157, 4, 60},{155, 23, 0},{127, 52, 0}, - { 81, 84, 0},{ 30,109, 0},{ 0,121, 0},{ 0,117, 0}, - { 0, 98, 78},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {221,222,173},{ 65,142,217},{112,110,254},{164, 84,255}, - {208, 72,204},{231, 76,122},{229, 95, 29},{200,125, 0}, - {154,157, 0},{102,182, 0},{ 58,195, 0},{ 34,191, 47}, - { 37,171,140},{ 79, 79, 79},{ 0, 0, 0},{ 0, 0, 0}, - {221,222,173},{158,189,191},{177,176,208},{198,166,206}, - {216,161,185},{225,163,152},{224,171,114},{213,183, 83}, - {194,195, 66},{173,206, 68},{155,211, 88},{145,209,122}, - {146,201,159},{184,184,184},{ 0, 0, 0},{ 0, 0, 0}, - { 87, 87,133},{ 0, 26,167},{ 5, 2,198},{ 44, 0,195}, - { 77, 0,157},{ 95, 0, 94},{ 93, 0, 25},{ 71, 14, 0}, - { 36, 38, 0},{ 0, 57, 0},{ 0, 66, 0},{ 0, 63, 38}, - { 0, 49,108},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {153,153,216},{ 0, 74,254},{ 46, 43,254},{ 97, 17,254}, - {140, 5,247},{164, 9,165},{161, 28, 74},{133, 57, 0}, - { 87, 89, 0},{ 36,114, 0},{ 0,126, 10},{ 0,122, 92}, - { 0,103,183},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {229,228,254},{ 74,148,254},{120,116,254},{172, 91,254}, - {216, 78,254},{239, 82,254},{237,102,166},{208,131, 89}, - {162,163, 46},{110,189, 51},{ 66,201,102},{ 42,197,184}, - { 45,178,254},{ 79, 79, 79},{ 0, 0, 0},{ 0, 0, 0}, - {229,228,254},{166,196,254},{185,183,254},{206,172,254}, - {224,167,254},{233,169,254},{232,177,252},{221,189,220}, - {202,202,203},{181,212,205},{163,217,226},{153,216,254}, - {154,208,254},{184,184,184},{ 0, 0, 0},{ 0, 0, 0}, - { 90, 71, 97},{ 0, 11,130},{ 8, 0,162},{ 47, 0,158}, - { 80, 0,120},{ 98, 0, 58},{ 96, 0, 0},{ 74, 0, 0}, - { 39, 22, 0},{ 0, 42, 0},{ 0, 51, 0},{ 0, 48, 2}, - { 0, 33, 72},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {158,132,166},{ 4, 53,210},{ 50, 22,252},{101, 0,247}, - {144, 0,197},{168, 0,116},{165, 7, 25},{137, 36, 0}, - { 91, 68, 0},{ 40, 93, 0},{ 0,105, 0},{ 0,101, 42}, - { 0, 82,134},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {234,201,246},{ 79,121,254},{125, 89,254},{177, 63,254}, - {221, 51,254},{245, 55,195},{242, 74,102},{214,104, 24}, - {167,136, 0},{115,161, 0},{ 71,174, 37},{ 48,170,120}, - { 50,150,213},{ 79, 79, 79},{ 0, 0, 0},{ 0, 0, 0}, - {234,201,246},{171,168,254},{190,155,254},{211,145,254}, - {229,140,254},{239,142,225},{237,150,187},{226,162,156}, - {207,174,139},{186,185,141},{168,190,161},{159,188,195}, - {160,180,232},{184,184,184},{ 0, 0, 0},{ 0, 0, 0}, - { 66, 85, 88},{ 0, 25,121},{ 0, 1,153},{ 23, 0,149}, - { 56, 0,111},{ 74, 0, 49},{ 72, 0, 0},{ 51, 12, 0}, - { 16, 36, 0},{ 0, 55, 0},{ 0, 65, 0},{ 0, 62, 0}, - { 0, 47, 63},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {125,151,154},{ 0, 72,198},{ 17, 40,240},{ 69, 15,235}, - {112, 3,185},{135, 7,104},{132, 26, 12},{104, 55, 0}, - { 59, 87, 0},{ 7,112, 0},{ 0,124, 0},{ 0,120, 30}, - { 0,101,121},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {192,225,230},{ 37,145,254},{ 83,114,254},{135, 88,254}, - {179, 76,254},{202, 80,179},{200, 99, 86},{171,129, 8}, - {125,160, 0},{ 73,186, 0},{ 29,198, 21},{ 5,194,104}, - { 8,175,197},{ 79, 79, 79},{ 0, 0, 0},{ 0, 0, 0}, - {192,225,230},{129,193,248},{148,180,254},{169,170,254}, - {187,165,242},{196,166,209},{195,174,171},{184,186,140}, - {165,199,123},{144,209,125},{126,214,145},{116,213,179}, - {118,205,216},{184,184,184},{ 0, 0, 0},{ 0, 0, 0}, - { 69, 69, 69},{ 0, 16,110},{ 0, 0,142},{ 33, 0,138}, - { 66, 0,100},{ 84, 0, 38},{ 82, 0, 0},{ 60, 3, 0}, - { 25, 27, 0},{ 0, 46, 0},{ 0, 56, 0},{ 0, 53, 0}, - { 0, 38, 51},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {134,134,134},{ 0, 64,187},{ 35, 32,228},{ 86, 7,223}, - {129, 0,174},{153, 0, 92},{150, 18, 1},{122, 47, 0}, - { 76, 79, 0},{ 25,104, 0},{ 0,116, 0},{ 0,112, 19}, - { 0, 93,110},{ 0, 0, 0},{ 0, 0, 0},{ 0, 0, 0}, - {207,207,207},{ 60,136,254},{107,104,254},{159, 79,254}, - {203, 66,248},{226, 70,165},{224, 90, 72},{195,119, 0}, - {149,151, 0},{ 97,177, 0},{ 53,189, 8},{ 29,185, 91}, - { 32,166,183},{ 79, 79, 79},{ 0, 0, 0},{ 0, 0, 0}, - {207,207,207},{148,178,229},{166,165,246},{188,155,244}, - {205,150,224},{215,152,190},{214,159,152},{202,171,121}, - {183,184,104},{162,195,106},{145,200,126},{135,198,160}, - {136,190,197},{184,184,184},{ 0, 0, 0},{ 0, 0, 0} -}; + {114, 83, 79}, + {0, 23, 113}, + {32, 0, 145}, + {71, 0, 141}, + {104, 0, 103}, + {122, 0, 41}, + {120, 0, 0}, + {99, 10, 0}, + {64, 34, 0}, + {24, 54, 0}, + {0, 63, 0}, + {0, 60, 0}, + {0, 45, 54}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {190, 148, 143}, + {37, 69, 187}, + {83, 38, 228}, + {134, 13, 224}, + {177, 1, 174}, + {200, 4, 92}, + {198, 24, 1}, + {170, 53, 0}, + {124, 84, 0}, + {73, 109, 0}, + {30, 122, 0}, + {6, 118, 19}, + {9, 98, 110}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {254, 222, 215}, + {122, 142, 254}, + {168, 110, 254}, + {220, 85, 254}, + {254, 72, 247}, + {254, 76, 164}, + {254, 96, 71}, + {254, 125, 0}, + {210, 157, 0}, + {158, 183, 0}, + {114, 195, 7}, + {90, 191, 89}, + {93, 172, 182}, + {79, 79, 79}, + {0, 0, 0}, + {0, 0, 0}, + {254, 222, 215}, + {214, 190, 233}, + {233, 177, 250}, + {254, 166, 248}, + {254, 161, 228}, + {254, 163, 194}, + {254, 171, 157}, + {254, 183, 125}, + {250, 196, 108}, + {229, 206, 110}, + {211, 211, 130}, + {201, 210, 164}, + {203, 202, 202}, + {184, 184, 184}, + {0, 0, 0}, + {0, 0, 0}, + {75, 106, 64}, + {0, 46, 98}, + {0, 22, 130}, + {32, 3, 126}, + {65, 0, 88}, + {82, 0, 26}, + {80, 11, 0}, + {59, 34, 0}, + {24, 58, 0}, + {0, 77, 0}, + {0, 86, 0}, + {0, 83, 0}, + {0, 68, 39}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {136, 180, 122}, + {0, 101, 166}, + {29, 69, 208}, + {80, 44, 203}, + {123, 32, 153}, + {146, 36, 72}, + {144, 55, 0}, + {116, 84, 0}, + {70, 116, 0}, + {19, 141, 0}, + {0, 153, 0}, + {0, 149, 0}, + {0, 130, 90}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {207, 254, 188}, + {51, 183, 233}, + {98, 151, 254}, + {150, 126, 254}, + {193, 113, 220}, + {217, 117, 137}, + {214, 137, 45}, + {186, 166, 0}, + {140, 198, 0}, + {88, 224, 0}, + {44, 236, 0}, + {20, 232, 63}, + {23, 213, 155}, + {79, 79, 79}, + {0, 0, 0}, + {0, 0, 0}, + {207, 254, 188}, + {144, 231, 207}, + {163, 218, 224}, + {184, 207, 222}, + {201, 202, 201}, + {211, 204, 168}, + {210, 212, 130}, + {198, 224, 99}, + {180, 237, 81}, + {159, 247, 83}, + {141, 252, 104}, + {131, 251, 137}, + {132, 243, 175}, + {184, 184, 184}, + {0, 0, 0}, + {0, 0, 0}, + {83, 83, 55}, + {0, 23, 89}, + {0, 0, 121}, + {40, 0, 117}, + {73, 0, 79}, + {90, 0, 17}, + {88, 0, 0}, + {67, 10, 0}, + {32, 34, 0}, + {0, 53, 0}, + {0, 63, 0}, + {0, 60, 0}, + {0, 45, 30}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {147, 148, 110}, + {0, 69, 154}, + {40, 38, 196}, + {91, 12, 191}, + {134, 0, 141}, + {157, 4, 60}, + {155, 23, 0}, + {127, 52, 0}, + {81, 84, 0}, + {30, 109, 0}, + {0, 121, 0}, + {0, 117, 0}, + {0, 98, 78}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {221, 222, 173}, + {65, 142, 217}, + {112, 110, 254}, + {164, 84, 255}, + {208, 72, 204}, + {231, 76, 122}, + {229, 95, 29}, + {200, 125, 0}, + {154, 157, 0}, + {102, 182, 0}, + {58, 195, 0}, + {34, 191, 47}, + {37, 171, 140}, + {79, 79, 79}, + {0, 0, 0}, + {0, 0, 0}, + {221, 222, 173}, + {158, 189, 191}, + {177, 176, 208}, + {198, 166, 206}, + {216, 161, 185}, + {225, 163, 152}, + {224, 171, 114}, + {213, 183, 83}, + {194, 195, 66}, + {173, 206, 68}, + {155, 211, 88}, + {145, 209, 122}, + {146, 201, 159}, + {184, 184, 184}, + {0, 0, 0}, + {0, 0, 0}, + {87, 87, 133}, + {0, 26, 167}, + {5, 2, 198}, + {44, 0, 195}, + {77, 0, 157}, + {95, 0, 94}, + {93, 0, 25}, + {71, 14, 0}, + {36, 38, 0}, + {0, 57, 0}, + {0, 66, 0}, + {0, 63, 38}, + {0, 49, 108}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {153, 153, 216}, + {0, 74, 254}, + {46, 43, 254}, + {97, 17, 254}, + {140, 5, 247}, + {164, 9, 165}, + {161, 28, 74}, + {133, 57, 0}, + {87, 89, 0}, + {36, 114, 0}, + {0, 126, 10}, + {0, 122, 92}, + {0, 103, 183}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {229, 228, 254}, + {74, 148, 254}, + {120, 116, 254}, + {172, 91, 254}, + {216, 78, 254}, + {239, 82, 254}, + {237, 102, 166}, + {208, 131, 89}, + {162, 163, 46}, + {110, 189, 51}, + {66, 201, 102}, + {42, 197, 184}, + {45, 178, 254}, + {79, 79, 79}, + {0, 0, 0}, + {0, 0, 0}, + {229, 228, 254}, + {166, 196, 254}, + {185, 183, 254}, + {206, 172, 254}, + {224, 167, 254}, + {233, 169, 254}, + {232, 177, 252}, + {221, 189, 220}, + {202, 202, 203}, + {181, 212, 205}, + {163, 217, 226}, + {153, 216, 254}, + {154, 208, 254}, + {184, 184, 184}, + {0, 0, 0}, + {0, 0, 0}, + {90, 71, 97}, + {0, 11, 130}, + {8, 0, 162}, + {47, 0, 158}, + {80, 0, 120}, + {98, 0, 58}, + {96, 0, 0}, + {74, 0, 0}, + {39, 22, 0}, + {0, 42, 0}, + {0, 51, 0}, + {0, 48, 2}, + {0, 33, 72}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {158, 132, 166}, + {4, 53, 210}, + {50, 22, 252}, + {101, 0, 247}, + {144, 0, 197}, + {168, 0, 116}, + {165, 7, 25}, + {137, 36, 0}, + {91, 68, 0}, + {40, 93, 0}, + {0, 105, 0}, + {0, 101, 42}, + {0, 82, 134}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {234, 201, 246}, + {79, 121, 254}, + {125, 89, 254}, + {177, 63, 254}, + {221, 51, 254}, + {245, 55, 195}, + {242, 74, 102}, + {214, 104, 24}, + {167, 136, 0}, + {115, 161, 0}, + {71, 174, 37}, + {48, 170, 120}, + {50, 150, 213}, + {79, 79, 79}, + {0, 0, 0}, + {0, 0, 0}, + {234, 201, 246}, + {171, 168, 254}, + {190, 155, 254}, + {211, 145, 254}, + {229, 140, 254}, + {239, 142, 225}, + {237, 150, 187}, + {226, 162, 156}, + {207, 174, 139}, + {186, 185, 141}, + {168, 190, 161}, + {159, 188, 195}, + {160, 180, 232}, + {184, 184, 184}, + {0, 0, 0}, + {0, 0, 0}, + {66, 85, 88}, + {0, 25, 121}, + {0, 1, 153}, + {23, 0, 149}, + {56, 0, 111}, + {74, 0, 49}, + {72, 0, 0}, + {51, 12, 0}, + {16, 36, 0}, + {0, 55, 0}, + {0, 65, 0}, + {0, 62, 0}, + {0, 47, 63}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {125, 151, 154}, + {0, 72, 198}, + {17, 40, 240}, + {69, 15, 235}, + {112, 3, 185}, + {135, 7, 104}, + {132, 26, 12}, + {104, 55, 0}, + {59, 87, 0}, + {7, 112, 0}, + {0, 124, 0}, + {0, 120, 30}, + {0, 101, 121}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {192, 225, 230}, + {37, 145, 254}, + {83, 114, 254}, + {135, 88, 254}, + {179, 76, 254}, + {202, 80, 179}, + {200, 99, 86}, + {171, 129, 8}, + {125, 160, 0}, + {73, 186, 0}, + {29, 198, 21}, + {5, 194, 104}, + {8, 175, 197}, + {79, 79, 79}, + {0, 0, 0}, + {0, 0, 0}, + {192, 225, 230}, + {129, 193, 248}, + {148, 180, 254}, + {169, 170, 254}, + {187, 165, 242}, + {196, 166, 209}, + {195, 174, 171}, + {184, 186, 140}, + {165, 199, 123}, + {144, 209, 125}, + {126, 214, 145}, + {116, 213, 179}, + {118, 205, 216}, + {184, 184, 184}, + {0, 0, 0}, + {0, 0, 0}, + {69, 69, 69}, + {0, 16, 110}, + {0, 0, 142}, + {33, 0, 138}, + {66, 0, 100}, + {84, 0, 38}, + {82, 0, 0}, + {60, 3, 0}, + {25, 27, 0}, + {0, 46, 0}, + {0, 56, 0}, + {0, 53, 0}, + {0, 38, 51}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {134, 134, 134}, + {0, 64, 187}, + {35, 32, 228}, + {86, 7, 223}, + {129, 0, 174}, + {153, 0, 92}, + {150, 18, 1}, + {122, 47, 0}, + {76, 79, 0}, + {25, 104, 0}, + {0, 116, 0}, + {0, 112, 19}, + {0, 93, 110}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {207, 207, 207}, + {60, 136, 254}, + {107, 104, 254}, + {159, 79, 254}, + {203, 66, 248}, + {226, 70, 165}, + {224, 90, 72}, + {195, 119, 0}, + {149, 151, 0}, + {97, 177, 0}, + {53, 189, 8}, + {29, 185, 91}, + {32, 166, 183}, + {79, 79, 79}, + {0, 0, 0}, + {0, 0, 0}, + {207, 207, 207}, + {148, 178, 229}, + {166, 165, 246}, + {188, 155, 244}, + {205, 150, 224}, + {215, 152, 190}, + {214, 159, 152}, + {202, 171, 121}, + {183, 184, 104}, + {162, 195, 106}, + {145, 200, 126}, + {135, 198, 160}, + {136, 190, 197}, + {184, 184, 184}, + {0, 0, 0}, + {0, 0, 0}}; void Emu::SaveAudioBufferState() { - extra_fade_sound_in = fade_sound_in; - extra_fade_sound_out = fade_sound_out; - extra_sound_buf_changed_count = sound_buf_changed_count; - sound_buf->SaveAudioBufferState(); + extra_fade_sound_in = fade_sound_in; + extra_fade_sound_out = fade_sound_out; + extra_sound_buf_changed_count = sound_buf_changed_count; + sound_buf->SaveAudioBufferState(); } void Emu::RestoreAudioBufferState() { - fade_sound_in = extra_fade_sound_in; - fade_sound_out = extra_fade_sound_out; - sound_buf_changed_count = extra_sound_buf_changed_count; - sound_buf->RestoreAudioBufferState(); + fade_sound_in = extra_fade_sound_in; + fade_sound_out = extra_fade_sound_out; + sound_buf_changed_count = extra_sound_buf_changed_count; + sound_buf->RestoreAudioBufferState(); } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/emu.hpp b/source/quickerNES/core/emu.hpp index 58bd8db..09e218e 100644 --- a/source/quickerNES/core/emu.hpp +++ b/source/quickerNES/core/emu.hpp @@ -4,9 +4,9 @@ // Emu 0.7.0 +#include "apu/multiBuffer.hpp" #include "cart.hpp" #include "core.hpp" -#include "apu/multiBuffer.hpp" namespace quickerNES { @@ -46,13 +46,13 @@ class Emu int get_joypad_read_count() const { return emu.joypad_read_count; } void set_tracecb(void (*cb)(unsigned int *dest)) { emu.set_tracecb(cb); } - -// Save emulator state variants - void serializeState(jaffarCommon::serializer::Base& serializer) const { emu.serializeState(serializer); } - void deserializeState(jaffarCommon::deserializer::Base& deserializer) { emu.deserializeState(deserializer); } + + // Save emulator state variants + void serializeState(jaffarCommon::serializer::Base &serializer) const { emu.serializeState(serializer); } + void deserializeState(jaffarCommon::deserializer::Base &deserializer) { emu.deserializeState(deserializer); } void setNTABBlockSize(const size_t size) { emu.setNTABBlockSize(size); } - void enableStateBlock(const std::string& block) { emu.enableStateBlock(block); }; - void disableStateBlock(const std::string& block) { emu.disableStateBlock(block); }; + void enableStateBlock(const std::string &block) { emu.enableStateBlock(block); }; + void disableStateBlock(const std::string &block) { emu.disableStateBlock(block); }; // Basic emulation @@ -72,7 +72,7 @@ class Emu { static const uint8_t left = 8; - int burst_phase; // NTSC burst phase for frame (0, 1, or 2) + int burst_phase; // NTSC burst phase for frame (0, 1, or 2) int sample_count; // number of samples (always a multiple of chan_count) int chan_count; // 1: mono, 2: stereo @@ -206,8 +206,8 @@ class Emu { low_mem_size = 0x800 }; - - uint8_t *get_low_mem() const { return (uint8_t*)emu.low_mem; } + + uint8_t *get_low_mem() const { return (uint8_t *)emu.low_mem; } size_t get_low_mem_size() const { return low_mem_size; } // Optional 8K memory @@ -232,11 +232,11 @@ class Emu uint8_t *pal_mem() const { return emu.ppu.getPaletteRAM(); } uint16_t pal_mem_size() const { return emu.ppu.getPaletteRAMSize(); } - uint8_t peek_prg(nes_addr_t addr) const { return *emu.get_code(addr); } - void poke_prg(nes_addr_t addr, uint8_t value) { *emu.get_code(addr) = value; } - uint8_t peek_ppu(int addr) { return emu.ppu.peekaddr(addr); } + uint8_t peek_prg(nes_addr_t addr) const { return *emu.get_code(addr); } + void poke_prg(nes_addr_t addr, uint8_t value) { *emu.get_code(addr) = value; } + uint8_t peek_ppu(int addr) { return emu.ppu.peekaddr(addr); } - uint8_t get_ppu2000() const { return emu.ppu.w2000; } + uint8_t get_ppu2000() const { return emu.ppu.w2000; } void get_regs(unsigned int *dest) const { @@ -257,7 +257,7 @@ class Emu virtual void loading_state(State const &) {} long timestamp() const { return 0; } - void set_timestamp(long t) { } + void set_timestamp(long t) {} private: // noncopyable @@ -276,7 +276,7 @@ class Emu void clear_sound_buf(); void fade_samples(blip_sample_t *, int size, int step); - void* pixels_base_ptr; + void *pixels_base_ptr; char *host_pixels; int host_palette_size; frame_t single_frame; @@ -294,17 +294,15 @@ class Emu void SaveAudioBufferState(); void RestoreAudioBufferState(); - - inline void* get_pixels_base_ptr() + inline void *get_pixels_base_ptr() { return pixels_base_ptr; } }; - inline void Emu::set_pixels(void *p, long n) { - pixels_base_ptr = p; + pixels_base_ptr = p; host_pixels = (char *)p + n; emu.ppu.host_row_bytes = n; } @@ -319,4 +317,4 @@ inline long Emu::chr_size() const return cart()->chr_size() ? cart()->chr_size() : emu.ppu.chr_addr_size; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper.cpp b/source/quickerNES/core/mappers/mapper.cpp index f58cbce..7becb10 100644 --- a/source/quickerNES/core/mappers/mapper.cpp +++ b/source/quickerNES/core/mappers/mapper.cpp @@ -291,4 +291,4 @@ Mapper *Mapper::getMapperFromCode(const int mapperCode) return mapper; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper.hpp b/source/quickerNES/core/mappers/mapper.hpp index 4ab50b2..d7b083f 100644 --- a/source/quickerNES/core/mappers/mapper.hpp +++ b/source/quickerNES/core/mappers/mapper.hpp @@ -3,9 +3,9 @@ // NES mapper interface // Emu 0.7.0 -#include #include "../cart.hpp" #include "../cpu.hpp" +#include namespace quickerNES { @@ -209,4 +209,4 @@ inline bool Mapper::write_intercepted(nes_time_t, nes_addr_t, int) { return fals inline int Mapper::read(nes_time_t, nes_addr_t) { return -1; } // signal to caller -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper000.hpp b/source/quickerNES/core/mappers/mapper000.hpp index fb94544..f624809 100644 --- a/source/quickerNES/core/mappers/mapper000.hpp +++ b/source/quickerNES/core/mappers/mapper000.hpp @@ -35,4 +35,4 @@ class Mapper000 : public Mapper } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper001.hpp b/source/quickerNES/core/mappers/mapper001.hpp index 1ed89bc..0e609ee 100644 --- a/source/quickerNES/core/mappers/mapper001.hpp +++ b/source/quickerNES/core/mappers/mapper001.hpp @@ -126,4 +126,4 @@ class Mapper001 : public Mapper, mmc1_state_t } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper002.hpp b/source/quickerNES/core/mappers/mapper002.hpp index 44cdd47..5d2b552 100644 --- a/source/quickerNES/core/mappers/mapper002.hpp +++ b/source/quickerNES/core/mappers/mapper002.hpp @@ -45,4 +45,4 @@ class Mapper002 : public Mapper } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper003.hpp b/source/quickerNES/core/mappers/mapper003.hpp index c0896da..d4bc5f3 100644 --- a/source/quickerNES/core/mappers/mapper003.hpp +++ b/source/quickerNES/core/mappers/mapper003.hpp @@ -44,4 +44,4 @@ class Mapper003 : public Mapper } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper004.hpp b/source/quickerNES/core/mappers/mapper004.hpp index 1f195c9..ad751dc 100644 --- a/source/quickerNES/core/mappers/mapper004.hpp +++ b/source/quickerNES/core/mappers/mapper004.hpp @@ -255,4 +255,4 @@ class Mapper004 : public Mapper, mmc3_state_t int counter_just_clocked; // used only for debugging }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper005.hpp b/source/quickerNES/core/mappers/mapper005.hpp index 41c184d..b1806d5 100644 --- a/source/quickerNES/core/mappers/mapper005.hpp +++ b/source/quickerNES/core/mappers/mapper005.hpp @@ -149,4 +149,4 @@ class Mapper005 : public Mapper, mmc5_state_t nes_time_t irq_time; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper007.hpp b/source/quickerNES/core/mappers/mapper007.hpp index 786ae09..d557782 100644 --- a/source/quickerNES/core/mappers/mapper007.hpp +++ b/source/quickerNES/core/mappers/mapper007.hpp @@ -52,4 +52,4 @@ class Mapper007 : public Mapper } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper009.hpp b/source/quickerNES/core/mappers/mapper009.hpp index 2ba6741..709c1d7 100644 --- a/source/quickerNES/core/mappers/mapper009.hpp +++ b/source/quickerNES/core/mappers/mapper009.hpp @@ -78,4 +78,4 @@ class Mapper009 : public Mapper } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper010.hpp b/source/quickerNES/core/mappers/mapper010.hpp index 3764076..7d0d5b7 100644 --- a/source/quickerNES/core/mappers/mapper010.hpp +++ b/source/quickerNES/core/mappers/mapper010.hpp @@ -76,4 +76,4 @@ class Mapper010 : public Mapper } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper011.hpp b/source/quickerNES/core/mappers/mapper011.hpp index b5b0c45..535070c 100644 --- a/source/quickerNES/core/mappers/mapper011.hpp +++ b/source/quickerNES/core/mappers/mapper011.hpp @@ -52,4 +52,4 @@ class Mapper011 : public Mapper } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper015.hpp b/source/quickerNES/core/mappers/mapper015.hpp index 8d65b41..069d367 100644 --- a/source/quickerNES/core/mappers/mapper015.hpp +++ b/source/quickerNES/core/mappers/mapper015.hpp @@ -94,4 +94,4 @@ class Mapper015 : public Mapper, Mapper015_state_t unsigned long int i; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper019.hpp b/source/quickerNES/core/mappers/mapper019.hpp index ad6ec7e..315cdd2 100644 --- a/source/quickerNES/core/mappers/mapper019.hpp +++ b/source/quickerNES/core/mappers/mapper019.hpp @@ -199,4 +199,4 @@ class Mapper019 : public Mapper, namco106_state_t nes_time_t last_time; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper021.hpp b/source/quickerNES/core/mappers/mapper021.hpp index 5b011cb..a3b6292 100644 --- a/source/quickerNES/core/mappers/mapper021.hpp +++ b/source/quickerNES/core/mappers/mapper021.hpp @@ -256,4 +256,4 @@ void Mapper_VRC2_4::write_irq(nes_time_t time, typedef Mapper_VRC2_4 Mapper021; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper022.hpp b/source/quickerNES/core/mappers/mapper022.hpp index 05e350a..22920b8 100644 --- a/source/quickerNES/core/mappers/mapper022.hpp +++ b/source/quickerNES/core/mappers/mapper022.hpp @@ -34,4 +34,4 @@ namespace quickerNES typedef Mapper_VRC2_4 Mapper022; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper023.hpp b/source/quickerNES/core/mappers/mapper023.hpp index c0cbc22..37e29c9 100644 --- a/source/quickerNES/core/mappers/mapper023.hpp +++ b/source/quickerNES/core/mappers/mapper023.hpp @@ -33,4 +33,4 @@ namespace quickerNES typedef Mapper_VRC2_4 Mapper023; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper024.hpp b/source/quickerNES/core/mappers/mapper024.hpp index 4b9aefd..bb9b092 100644 --- a/source/quickerNES/core/mappers/mapper024.hpp +++ b/source/quickerNES/core/mappers/mapper024.hpp @@ -233,4 +233,4 @@ class Mapper_Vrc6 : public Mapper, vrc6_state_t typedef Mapper_Vrc6<0> Mapper024; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper025.hpp b/source/quickerNES/core/mappers/mapper025.hpp index bb14d30..8ec42ee 100644 --- a/source/quickerNES/core/mappers/mapper025.hpp +++ b/source/quickerNES/core/mappers/mapper025.hpp @@ -33,4 +33,4 @@ namespace quickerNES typedef Mapper_VRC2_4 Mapper025; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper026.hpp b/source/quickerNES/core/mappers/mapper026.hpp index 6243432..22774f0 100644 --- a/source/quickerNES/core/mappers/mapper026.hpp +++ b/source/quickerNES/core/mappers/mapper026.hpp @@ -11,4 +11,4 @@ namespace quickerNES typedef Mapper_Vrc6<3> Mapper026; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper030.hpp b/source/quickerNES/core/mappers/mapper030.hpp index 09a814b..5b9635e 100644 --- a/source/quickerNES/core/mappers/mapper030.hpp +++ b/source/quickerNES/core/mappers/mapper030.hpp @@ -53,4 +53,4 @@ class Mapper030 : public Mapper } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper032.hpp b/source/quickerNES/core/mappers/mapper032.hpp index d0bde18..bf1a962 100644 --- a/source/quickerNES/core/mappers/mapper032.hpp +++ b/source/quickerNES/core/mappers/mapper032.hpp @@ -126,4 +126,4 @@ class Mapper032 : public Mapper, mapper32_state_t } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper033.hpp b/source/quickerNES/core/mappers/mapper033.hpp index b78c01a..fcce4d2 100644 --- a/source/quickerNES/core/mappers/mapper033.hpp +++ b/source/quickerNES/core/mappers/mapper033.hpp @@ -103,4 +103,4 @@ class Mapper033 : public Mapper, tc0190_state_t } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper034.hpp b/source/quickerNES/core/mappers/mapper034.hpp index 9e20885..c8c5e17 100644 --- a/source/quickerNES/core/mappers/mapper034.hpp +++ b/source/quickerNES/core/mappers/mapper034.hpp @@ -44,4 +44,4 @@ class Mapper034 : public Mapper } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper060.hpp b/source/quickerNES/core/mappers/mapper060.hpp index 638e5c1..c4ee3fe 100644 --- a/source/quickerNES/core/mappers/mapper060.hpp +++ b/source/quickerNES/core/mappers/mapper060.hpp @@ -53,4 +53,4 @@ class Mapper060 : public Mapper uint8_t game_sel, last_game; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper066.hpp b/source/quickerNES/core/mappers/mapper066.hpp index 53bf077..d58b427 100644 --- a/source/quickerNES/core/mappers/mapper066.hpp +++ b/source/quickerNES/core/mappers/mapper066.hpp @@ -52,4 +52,4 @@ class Mapper066 : public Mapper } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper069.hpp b/source/quickerNES/core/mappers/mapper069.hpp index cd8cb82..6055bd2 100644 --- a/source/quickerNES/core/mappers/mapper069.hpp +++ b/source/quickerNES/core/mappers/mapper069.hpp @@ -190,4 +190,4 @@ class Mapper069 : public Mapper, fme7_state_t Fme7_Apu sound; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper070.hpp b/source/quickerNES/core/mappers/mapper070.hpp index e4a2495..a25b468 100644 --- a/source/quickerNES/core/mappers/mapper070.hpp +++ b/source/quickerNES/core/mappers/mapper070.hpp @@ -84,4 +84,4 @@ class Mapper_74x161x162x32 : public Mapper typedef Mapper_74x161x162x32<70> Mapper070; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper071.hpp b/source/quickerNES/core/mappers/mapper071.hpp index a80af9d..4edc182 100644 --- a/source/quickerNES/core/mappers/mapper071.hpp +++ b/source/quickerNES/core/mappers/mapper071.hpp @@ -54,4 +54,4 @@ class Mapper071 : public Mapper } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper073.hpp b/source/quickerNES/core/mappers/mapper073.hpp index 3543431..a17dfa5 100644 --- a/source/quickerNES/core/mappers/mapper073.hpp +++ b/source/quickerNES/core/mappers/mapper073.hpp @@ -134,4 +134,4 @@ class Mapper073 : public Mapper, vrc3_state_t } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper075.hpp b/source/quickerNES/core/mappers/mapper075.hpp index 84e1b0f..583e36a 100644 --- a/source/quickerNES/core/mappers/mapper075.hpp +++ b/source/quickerNES/core/mappers/mapper075.hpp @@ -110,4 +110,4 @@ class Mapper075 : public Mapper, vrc1_state_t } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper078.hpp b/source/quickerNES/core/mappers/mapper078.hpp index 757555d..7408cc7 100644 --- a/source/quickerNES/core/mappers/mapper078.hpp +++ b/source/quickerNES/core/mappers/mapper078.hpp @@ -77,4 +77,4 @@ class Mapper078 : public Mapper } }; -} // namespace quickNES +} // namespace quickerNES diff --git a/source/quickerNES/core/mappers/mapper079.hpp b/source/quickerNES/core/mappers/mapper079.hpp index e46648e..8142c39 100644 --- a/source/quickerNES/core/mappers/mapper079.hpp +++ b/source/quickerNES/core/mappers/mapper079.hpp @@ -95,4 +95,4 @@ void Mapper_AveNina::write_regs() typedef Mapper_AveNina Mapper079; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper085.hpp b/source/quickerNES/core/mappers/mapper085.hpp index 603c895..c61068f 100644 --- a/source/quickerNES/core/mappers/mapper085.hpp +++ b/source/quickerNES/core/mappers/mapper085.hpp @@ -225,4 +225,4 @@ class Mapper085 : public Mapper, vrc7_state_t }; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper086.hpp b/source/quickerNES/core/mappers/mapper086.hpp index 4d718e5..7d70f56 100644 --- a/source/quickerNES/core/mappers/mapper086.hpp +++ b/source/quickerNES/core/mappers/mapper086.hpp @@ -26,4 +26,4 @@ namespace quickerNES typedef Mapper_74x161x162x32<86> Mapper086; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper087.hpp b/source/quickerNES/core/mappers/mapper087.hpp index 1e57216..8c94515 100644 --- a/source/quickerNES/core/mappers/mapper087.hpp +++ b/source/quickerNES/core/mappers/mapper087.hpp @@ -50,4 +50,4 @@ class Mapper087 : public Mapper void write(nes_time_t, nes_addr_t, int) {} }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper088.hpp b/source/quickerNES/core/mappers/mapper088.hpp index 7652074..53ae611 100644 --- a/source/quickerNES/core/mappers/mapper088.hpp +++ b/source/quickerNES/core/mappers/mapper088.hpp @@ -111,5 +111,4 @@ class Mapper_Namco_34x3 : public Mapper, namco_34x3_state_t typedef Mapper_Namco_34x3 Mapper088; - -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper089.hpp b/source/quickerNES/core/mappers/mapper089.hpp index 95576ba..20ff215 100644 --- a/source/quickerNES/core/mappers/mapper089.hpp +++ b/source/quickerNES/core/mappers/mapper089.hpp @@ -59,4 +59,4 @@ class Mapper089 : public Mapper uint8_t regs; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper093.hpp b/source/quickerNES/core/mappers/mapper093.hpp index 445003d..a04d891 100644 --- a/source/quickerNES/core/mappers/mapper093.hpp +++ b/source/quickerNES/core/mappers/mapper093.hpp @@ -58,4 +58,4 @@ class Mapper093 : public Mapper uint8_t regs; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper094.hpp b/source/quickerNES/core/mappers/mapper094.hpp index 73cc504..e5b4e65 100644 --- a/source/quickerNES/core/mappers/mapper094.hpp +++ b/source/quickerNES/core/mappers/mapper094.hpp @@ -57,4 +57,4 @@ class Mapper094 : public Mapper uint8_t bank; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper097.hpp b/source/quickerNES/core/mappers/mapper097.hpp index 6554e53..a5b524b 100644 --- a/source/quickerNES/core/mappers/mapper097.hpp +++ b/source/quickerNES/core/mappers/mapper097.hpp @@ -66,4 +66,4 @@ class Mapper097 : public Mapper uint8_t bank; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper113.hpp b/source/quickerNES/core/mappers/mapper113.hpp index d60b138..2cd28d2 100644 --- a/source/quickerNES/core/mappers/mapper113.hpp +++ b/source/quickerNES/core/mappers/mapper113.hpp @@ -30,4 +30,4 @@ namespace quickerNES typedef Mapper_AveNina Mapper113; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper140.hpp b/source/quickerNES/core/mappers/mapper140.hpp index 723d7e1..9c2223f 100644 --- a/source/quickerNES/core/mappers/mapper140.hpp +++ b/source/quickerNES/core/mappers/mapper140.hpp @@ -66,4 +66,4 @@ class Mapper140 : public Mapper uint8_t regs; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper152.hpp b/source/quickerNES/core/mappers/mapper152.hpp index 6b5071f..97246d4 100644 --- a/source/quickerNES/core/mappers/mapper152.hpp +++ b/source/quickerNES/core/mappers/mapper152.hpp @@ -26,4 +26,4 @@ namespace quickerNES typedef Mapper_74x161x162x32<152> Mapper152; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper154.hpp b/source/quickerNES/core/mappers/mapper154.hpp index d8e74c6..0573c80 100644 --- a/source/quickerNES/core/mappers/mapper154.hpp +++ b/source/quickerNES/core/mappers/mapper154.hpp @@ -30,4 +30,4 @@ namespace quickerNES typedef Mapper_Namco_34x3 Mapper154; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper156.hpp b/source/quickerNES/core/mappers/mapper156.hpp index bf43a20..9306b6e 100644 --- a/source/quickerNES/core/mappers/mapper156.hpp +++ b/source/quickerNES/core/mappers/mapper156.hpp @@ -62,4 +62,4 @@ class Mapper156 : public Mapper, m156_state_t } }; -} // namespace quickNES +} // namespace quickerNES diff --git a/source/quickerNES/core/mappers/mapper180.hpp b/source/quickerNES/core/mappers/mapper180.hpp index dd37ad8..6614efe 100644 --- a/source/quickerNES/core/mappers/mapper180.hpp +++ b/source/quickerNES/core/mappers/mapper180.hpp @@ -57,4 +57,4 @@ class Mapper180 : public Mapper uint8_t bank; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper184.hpp b/source/quickerNES/core/mappers/mapper184.hpp index b2a120b..6d8f1d7 100644 --- a/source/quickerNES/core/mappers/mapper184.hpp +++ b/source/quickerNES/core/mappers/mapper184.hpp @@ -67,4 +67,4 @@ class Mapper184 : public Mapper uint8_t regs; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper190.hpp b/source/quickerNES/core/mappers/mapper190.hpp index 87fc53b..9190ff6 100644 --- a/source/quickerNES/core/mappers/mapper190.hpp +++ b/source/quickerNES/core/mappers/mapper190.hpp @@ -57,4 +57,4 @@ class Mapper190 : public Mapper } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper193.hpp b/source/quickerNES/core/mappers/mapper193.hpp index b2c0bfa..642cfb6 100644 --- a/source/quickerNES/core/mappers/mapper193.hpp +++ b/source/quickerNES/core/mappers/mapper193.hpp @@ -78,4 +78,4 @@ class Mapper193 : public Mapper uint8_t regs[4]; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper206.hpp b/source/quickerNES/core/mappers/mapper206.hpp index ba6d40b..2f2d224 100644 --- a/source/quickerNES/core/mappers/mapper206.hpp +++ b/source/quickerNES/core/mappers/mapper206.hpp @@ -100,4 +100,4 @@ class Mapper206 : public Mapper, namco_34xx_state_t } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper207.hpp b/source/quickerNES/core/mappers/mapper207.hpp index a56fca6..262f292 100644 --- a/source/quickerNES/core/mappers/mapper207.hpp +++ b/source/quickerNES/core/mappers/mapper207.hpp @@ -93,4 +93,4 @@ class Mapper207 : public Mapper, taito_x1005_state_t virtual void write(nes_time_t, nes_addr_t addr, int data) {} }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper232.hpp b/source/quickerNES/core/mappers/mapper232.hpp index 1fe5ccb..c6c86f5 100644 --- a/source/quickerNES/core/mappers/mapper232.hpp +++ b/source/quickerNES/core/mappers/mapper232.hpp @@ -56,4 +56,4 @@ class Mapper232 : public Mapper } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper240.hpp b/source/quickerNES/core/mappers/mapper240.hpp index 29b7a3a..aa2ee35 100644 --- a/source/quickerNES/core/mappers/mapper240.hpp +++ b/source/quickerNES/core/mappers/mapper240.hpp @@ -66,4 +66,4 @@ class Mapper240 : public Mapper uint8_t regs; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper241.hpp b/source/quickerNES/core/mappers/mapper241.hpp index 0cca757..ec6999d 100644 --- a/source/quickerNES/core/mappers/mapper241.hpp +++ b/source/quickerNES/core/mappers/mapper241.hpp @@ -55,4 +55,4 @@ class Mapper241 : public Mapper uint8_t bank; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper244.hpp b/source/quickerNES/core/mappers/mapper244.hpp index d21a743..fb5a771 100644 --- a/source/quickerNES/core/mappers/mapper244.hpp +++ b/source/quickerNES/core/mappers/mapper244.hpp @@ -72,4 +72,4 @@ class Mapper244 : public Mapper, mapper244_state_t } }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/mappers/mapper246.hpp b/source/quickerNES/core/mappers/mapper246.hpp index e25fdef..cc0f60b 100644 --- a/source/quickerNES/core/mappers/mapper246.hpp +++ b/source/quickerNES/core/mappers/mapper246.hpp @@ -77,4 +77,4 @@ class Mapper246 : public Mapper uint8_t regs[8]; }; -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/ppu/ppu.cpp b/source/quickerNES/core/ppu/ppu.cpp index aeb8b40..ebddebd 100644 --- a/source/quickerNES/core/ppu/ppu.cpp +++ b/source/quickerNES/core/ppu/ppu.cpp @@ -3,9 +3,9 @@ // Emu 0.7.0. http://www.slack.net/~ant/ -#include #include "ppu.hpp" #include "../core.hpp" +#include namespace quickerNES { @@ -656,4 +656,4 @@ nes_time_t Ppu::earliest_open_bus_decay() return (decay_low < decay_high) ? decay_low : decay_high; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/ppu/ppu.hpp b/source/quickerNES/core/ppu/ppu.hpp index 9eee0b0..c786ed9 100644 --- a/source/quickerNES/core/ppu/ppu.hpp +++ b/source/quickerNES/core/ppu/ppu.hpp @@ -3,8 +3,8 @@ // NES PPU emulator // Emu 0.7.0 -#include #include "ppuRendering.hpp" +#include namespace quickerNES { @@ -143,4 +143,4 @@ inline void Ppu::update_open_bus(nes_time_t time) if (time >= decay_high) open_bus &= ~0xE0; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/ppu/ppuImpl.cpp b/source/quickerNES/core/ppu/ppuImpl.cpp index ffe48d9..2790b10 100644 --- a/source/quickerNES/core/ppu/ppuImpl.cpp +++ b/source/quickerNES/core/ppu/ppuImpl.cpp @@ -433,4 +433,4 @@ long Ppu_Impl::recalc_sprite_max(int scanline) return 0; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/ppu/ppuImpl.hpp b/source/quickerNES/core/ppu/ppuImpl.hpp index eecda2d..a380589 100644 --- a/source/quickerNES/core/ppu/ppuImpl.hpp +++ b/source/quickerNES/core/ppu/ppuImpl.hpp @@ -89,11 +89,11 @@ class Ppu_Impl : public ppu_state_t }; impl_t *impl; - long map_chr_addr_peek( unsigned a ) const - { - return chr_pages[a / chr_page_size] + a; - } - + long map_chr_addr_peek(unsigned a) const + { + return chr_pages[a / chr_page_size] + a; + } + int peekaddr(int addr) { if (addr < 0x2000) @@ -104,10 +104,10 @@ class Ppu_Impl : public ppu_state_t static const uint16_t scanline_len = 341; - uint8_t *getSpriteRAM() const { return (uint8_t*)spr_ram; } + uint8_t *getSpriteRAM() const { return (uint8_t *)spr_ram; } uint16_t getSpriteRAMSize() const { return spr_ram_size; } - - uint8_t *getPaletteRAM() const { return (uint8_t*)palette; } + + uint8_t *getPaletteRAM() const { return (uint8_t *)palette; } uint16_t getPaletteRAMSize() const { return sizeof(palette); } uint8_t spr_ram[spr_ram_size]; @@ -260,4 +260,4 @@ inline void Ppu_Impl::begin_frame() addr_inc = w2000 & 4 ? 32 : 1; } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/ppu/ppuRendering.cpp b/source/quickerNES/core/ppu/ppuRendering.cpp index 0fef109..5f89f8b 100644 --- a/source/quickerNES/core/ppu/ppuRendering.cpp +++ b/source/quickerNES/core/ppu/ppuRendering.cpp @@ -503,4 +503,4 @@ void Ppu_Rendering::draw_background(int start, int count) } } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/core/ppu/ppuRendering.hpp b/source/quickerNES/core/ppu/ppuRendering.hpp index e2e8cf1..31ac831 100644 --- a/source/quickerNES/core/ppu/ppuRendering.hpp +++ b/source/quickerNES/core/ppu/ppuRendering.hpp @@ -61,4 +61,4 @@ inline void Ppu_Rendering::draw_sprites(int start, int count) draw_scanlines(start, count, host_pixels + host_row_bytes * start, host_row_bytes, 2); } -} // namespace quickNES \ No newline at end of file +} // namespace quickerNES \ No newline at end of file diff --git a/source/quickerNES/nesInstance.hpp b/source/quickerNES/nesInstance.hpp index 32721b8..fc08861 100644 --- a/source/quickerNES/nesInstance.hpp +++ b/source/quickerNES/nesInstance.hpp @@ -1,15 +1,14 @@ #pragma once -#include "core/emu.hpp" #include "../nesInstanceBase.hpp" +#include "core/emu.hpp" typedef quickerNES::Emu emulator_t; class NESInstance final : public NESInstanceBase { public: - - NESInstance(const nlohmann::json& config) : NESInstanceBase(config) {} + NESInstance(const nlohmann::json &config) : NESInstanceBase(config) {} uint8_t *getLowMem() const override { return _nes.get_low_mem(); }; size_t getLowMemSize() const override { return _nes.get_low_mem_size(); }; @@ -26,16 +25,16 @@ class NESInstance final : public NESInstanceBase uint8_t *getCHRMem() const { return _nes.chr_mem(); }; size_t getCHRMemSize() const { return _nes.chr_size(); }; - void serializeState(jaffarCommon::serializer::Base& serializer) const override { _nes.serializeState(serializer); } - void deserializeState(jaffarCommon::deserializer::Base& deserializer) override { _nes.deserializeState(deserializer); } + void serializeState(jaffarCommon::serializer::Base &serializer) const override { _nes.serializeState(serializer); } + void deserializeState(jaffarCommon::deserializer::Base &deserializer) override { _nes.deserializeState(deserializer); } std::string getCoreName() const override { return "QuickerNES"; } - + void doSoftReset() override { _nes.reset(false); } void doHardReset() override { _nes.reset(true); } - + void *getInternalEmulatorPointer() override { return &_nes; } - + inline size_t getFullStateSize() const override { jaffarCommon::serializer::Contiguous serializer; @@ -51,7 +50,7 @@ class NESInstance final : public NESInstanceBase } void setNTABBlockSize(const size_t size) override { _nes.setNTABBlockSize(size); } - + void advanceState(const jaffar::input_t &input) override { if (_doRendering == true) _nes.emulate_frame(input.port1, input.port2); @@ -59,20 +58,17 @@ class NESInstance final : public NESInstanceBase } protected: - - bool loadROMImpl(const uint8_t* romData, const size_t romSize) override + bool loadROMImpl(const uint8_t *romData, const size_t romSize) override { // Loading rom data _nes.load_ines(romData); return true; } - void enableStateBlockImpl(const std::string& block) override { _nes.enableStateBlock(block); }; - void disableStateBlockImpl(const std::string& block) override { _nes.disableStateBlock(block); }; - + void enableStateBlockImpl(const std::string &block) override { _nes.enableStateBlock(block); }; + void disableStateBlockImpl(const std::string &block) override { _nes.disableStateBlock(block); }; private: - // Emulator instance emulator_t _nes; }; diff --git a/source/tester.cpp b/source/tester.cpp index 91d63b0..1c539d9 100644 --- a/source/tester.cpp +++ b/source/tester.cpp @@ -1,17 +1,17 @@ +#include "nesInstance.hpp" #include +#include +#include +#include +#include +#include #include #include #include -#include -#include -#include #include -#include -#include "nesInstance.hpp" -#include #include -#include #include +#include int main(int argc, char *argv[]) { @@ -81,12 +81,12 @@ int main(int argc, char *argv[]) std::string stateDisabledBlocksOutput; if (scriptJson.contains("Disable State Blocks") == false) JAFFAR_THROW_LOGIC("Script file missing 'Disable State Blocks' entry\n"); if (scriptJson["Disable State Blocks"].is_array() == false) JAFFAR_THROW_LOGIC("Script file 'Disable State Blocks' is not an array\n"); - for (const auto& entry : scriptJson["Disable State Blocks"]) + for (const auto &entry : scriptJson["Disable State Blocks"]) { if (entry.is_string() == false) JAFFAR_THROW_LOGIC("Script file 'Disable State Blocks' entry is not a string\n"); stateDisabledBlocks.push_back(entry.get()); stateDisabledBlocksOutput += entry.get() + std::string(" "); - } + } // Getting Controller 1 type if (scriptJson.contains("Controller 1 Type") == false) JAFFAR_THROW_LOGIC("Script file missing 'Controller 1 Type' entry\n"); @@ -101,7 +101,7 @@ int main(int argc, char *argv[]) // Getting differential compression configuration if (scriptJson.contains("Differential Compression") == false) JAFFAR_THROW_LOGIC("Script file missing 'Differential Compression' entry\n"); if (scriptJson["Differential Compression"].is_object() == false) JAFFAR_THROW_LOGIC("Script file 'Differential Compression' entry is not a key/value object\n"); - const auto& differentialCompressionJs = scriptJson["Differential Compression"]; + const auto &differentialCompressionJs = scriptJson["Differential Compression"]; if (differentialCompressionJs.contains("Enabled") == false) JAFFAR_THROW_LOGIC("Script file missing 'Differential Compression / Enabled' entry\n"); if (differentialCompressionJs["Enabled"].is_boolean() == false) JAFFAR_THROW_LOGIC("Script file 'Differential Compression / Enabled' entry is not a boolean\n"); @@ -121,7 +121,7 @@ int main(int argc, char *argv[]) // Loading ROM File std::string romFileData; if (jaffarCommon::file::loadStringFromFile(romFileData, romFilePath) == false) JAFFAR_THROW_LOGIC("Could not rom file: %s\n", romFilePath.c_str()); - e.loadROM((uint8_t*)romFileData.data(), romFileData.size()); + e.loadROM((uint8_t *)romFileData.data(), romFileData.size()); // Calculating ROM SHA1 auto romSHA1 = jaffarCommon::hash::getSHA1String(romFileData); @@ -134,9 +134,9 @@ int main(int argc, char *argv[]) jaffarCommon::deserializer::Contiguous d(stateFileData.data()); e.deserializeState(d); } - + // Disabling requested blocks from state serialization - for (const auto& block : stateDisabledBlocks) e.disableStateBlock(block); + for (const auto &block : stateDisabledBlocks) e.disableStateBlock(block); // Disable rendering e.disableRendering(); @@ -166,7 +166,7 @@ int main(int argc, char *argv[]) // Getting decoded emulator input for each entry in the sequence std::vector decodedSequence; - for (const auto& inputString : sequence) decodedSequence.push_back(inputParser->parseInputString(inputString)); + for (const auto &inputString : sequence) decodedSequence.push_back(inputParser->parseInputString(inputString)); // Getting emulation core name std::string emulationCoreName = e.getCoreName(); @@ -182,12 +182,12 @@ int main(int argc, char *argv[]) printf("[] Sequence Length: %lu\n", sequenceLength); printf("[] State Size: %lu bytes - Disabled Blocks: [ %s ]\n", stateSize, stateDisabledBlocksOutput.c_str()); printf("[] Use Differential Compression: %s\n", differentialCompressionEnabled ? "true" : "false"); - if (differentialCompressionEnabled == true) - { - printf("[] + Max Differences: %lu\n", differentialCompressionMaxDifferences); - printf("[] + Use Zlib: %s\n", differentialCompressionUseZlib ? "true" : "false"); - printf("[] + Fixed Diff State Size: %lu\n", fixedDiferentialStateSize); - printf("[] + Full Diff State Size: %lu\n", fullDifferentialStateSize); + if (differentialCompressionEnabled == true) + { + printf("[] + Max Differences: %lu\n", differentialCompressionMaxDifferences); + printf("[] + Use Zlib: %s\n", differentialCompressionUseZlib ? "true" : "false"); + printf("[] + Fixed Diff State Size: %lu\n", fixedDiferentialStateSize); + printf("[] + Full Diff State Size: %lu\n", fullDifferentialStateSize); } printf("[] ********** Running Test **********\n"); @@ -205,7 +205,7 @@ int main(int argc, char *argv[]) size_t differentialStateMaxSizeDetected = 0; // Allocating memory for differential data and performing the first serialization - if (differentialCompressionEnabled == true) + if (differentialCompressionEnabled == true) { differentialStateData = (uint8_t *)malloc(fullDifferentialStateSize); auto s = jaffarCommon::serializer::Differential(differentialStateData, fullDifferentialStateSize, currentState, stateSize, differentialCompressionUseZlib); @@ -223,22 +223,22 @@ int main(int argc, char *argv[]) for (const auto &input : decodedSequence) { if (doPreAdvance == true) e.advanceState(input); - + if (doDeserialize == true) { - if (differentialCompressionEnabled == true) + if (differentialCompressionEnabled == true) { - jaffarCommon::deserializer::Differential d(differentialStateData, fullDifferentialStateSize, currentState, stateSize, differentialCompressionUseZlib); - e.deserializeState(d); + jaffarCommon::deserializer::Differential d(differentialStateData, fullDifferentialStateSize, currentState, stateSize, differentialCompressionUseZlib); + e.deserializeState(d); } if (differentialCompressionEnabled == false) { jaffarCommon::deserializer::Contiguous d(currentState, stateSize); e.deserializeState(d); - } - } - + } + } + e.advanceState(input); if (doSerialize == true) @@ -248,14 +248,14 @@ int main(int argc, char *argv[]) auto s = jaffarCommon::serializer::Differential(differentialStateData, fullDifferentialStateSize, currentState, stateSize, differentialCompressionUseZlib); e.serializeState(s); differentialStateMaxSizeDetected = std::max(differentialStateMaxSizeDetected, s.getOutputSize()); - } + } - if (differentialCompressionEnabled == false) + if (differentialCompressionEnabled == false) { auto s = jaffarCommon::serializer::Contiguous(currentState, stateSize); e.serializeState(s); } - } + } } auto tf = std::chrono::high_resolution_clock::now(); @@ -276,7 +276,7 @@ int main(int argc, char *argv[]) printf("[] Final State Hash: %s\n", hashStringBuffer); if (differentialCompressionEnabled == true) { - printf("[] Differential State Max Size Detected: %lu\n", differentialStateMaxSizeDetected); + printf("[] Differential State Max Size Detected: %lu\n", differentialStateMaxSizeDetected); } // If saving hash, do it now if (hashOutputFile != "") jaffarCommon::file::saveStringToFile(std::string(hashStringBuffer), hashOutputFile.c_str()); diff --git a/tests/solarJetman.anyPercent.test b/tests/solarJetman.anyPercent.test index b4bb5c5..bd36349 100644 --- a/tests/solarJetman.anyPercent.test +++ b/tests/solarJetman.anyPercent.test @@ -5,7 +5,7 @@ "Expected ROM SHA1": "872B91A2F7A2F635061EF43F79E7F7E9F59F5C50", "Initial State File": "", "Sequence File": "solarJetman.anyPercent.sol", - "Disable State Blocks": [ "SRAM", "CHRR", "NTAB", "SPRT", "CTRL" ], + "Disable State Blocks": [ "SRAM", "CHRR", "SPRT", "CTRL" ], "Controller 1 Type": "Joypad", "Controller 2 Type": "None", "Differential Compression":