Fixing style and inputs

This commit is contained in:
SergioMartin86 2024-07-28 16:52:05 +02:00
parent 6ca0537d45
commit c7f1c233ca
102 changed files with 2483 additions and 1684 deletions

View File

@ -4,10 +4,10 @@
// by eien86 // by eien86
#include <cstdint> #include <cstdint>
#include <string>
#include <sstream>
#include <jaffarCommon/exceptions.hpp> #include <jaffarCommon/exceptions.hpp>
#include <jaffarCommon/json.hpp> #include <jaffarCommon/json.hpp>
#include <sstream>
#include <string>
namespace jaffar namespace jaffar
{ {
@ -22,12 +22,16 @@ struct input_t
port_t port2 = 0; port_t port2 = 0;
}; };
class InputParser class InputParser
{ {
public: public:
enum controller_t
enum controller_t { none, joypad, fourscore1, fourscore2 }; {
none,
joypad,
fourscore1,
fourscore2
};
InputParser(const nlohmann::json &config) InputParser(const nlohmann::json &config)
{ {
@ -35,10 +39,26 @@ public:
{ {
bool isTypeRecognized = false; bool isTypeRecognized = false;
const auto controller1Type = jaffarCommon::json::getString(config, "Controller 1 Type"); const auto controller1Type = jaffarCommon::json::getString(config, "Controller 1 Type");
if (controller1Type == "None") { _controller1Type = controller_t::none; isTypeRecognized = true; } if (controller1Type == "None")
if (controller1Type == "Joypad") { _controller1Type = controller_t::joypad; isTypeRecognized = true; } {
if (controller1Type == "FourScore1") { _controller1Type = controller_t::fourscore1; isTypeRecognized = true; } _controller1Type = controller_t::none;
if (controller1Type == "FourScore2") { _controller1Type = controller_t::fourscore2; isTypeRecognized = true; } 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()); if (isTypeRecognized == false) JAFFAR_THROW_LOGIC("Controller 1 type not recognized: '%s'\n", controller1Type.c_str());
} }
@ -46,16 +66,31 @@ public:
{ {
bool isTypeRecognized = false; bool isTypeRecognized = false;
const auto controller2Type = jaffarCommon::json::getString(config, "Controller 2 Type"); const auto controller2Type = jaffarCommon::json::getString(config, "Controller 2 Type");
if (controller2Type == "None") { _controller2Type = controller_t::none; isTypeRecognized = true; } if (controller2Type == "None")
if (controller2Type == "Joypad") { _controller2Type = controller_t::joypad; isTypeRecognized = true; } {
if (controller2Type == "FourScore1") { _controller2Type = controller_t::fourscore1; isTypeRecognized = true; } _controller2Type = controller_t::none;
if (controller2Type == "FourScore2") { _controller2Type = controller_t::fourscore2; isTypeRecognized = true; } 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()); 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 // Storage for the input
input_t input; input_t input;
@ -86,13 +121,12 @@ public:
} }
private: 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()); 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 // Currently read character
char c; char c;
@ -141,10 +175,14 @@ public:
if (c == 'A') code |= 0b00000001; 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 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 // Controller separator
if (ss.get() != '|') reportBadInputString(inputString); if (ss.get() != '|') reportBadInputString(inputString);
@ -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 // Currently read character
char c; char c;

View File

@ -1,9 +1,9 @@
#pragma once #pragma once
#include "inputParser.hpp"
#include "jaffarCommon/logger.hpp"
#include "jaffarCommon/serializers/contiguous.hpp" #include "jaffarCommon/serializers/contiguous.hpp"
#include "jaffarCommon/serializers/differential.hpp" #include "jaffarCommon/serializers/differential.hpp"
#include "jaffarCommon/logger.hpp"
#include "inputParser.hpp"
// Size of image generated in graphics buffer // Size of image generated in graphics buffer
static const uint16_t image_width = 256; static const uint16_t image_width = 256;
@ -12,8 +12,7 @@ static const uint16_t image_height = 240;
class NESInstanceBase class NESInstanceBase
{ {
public: public:
NESInstanceBase(const nlohmann::json &config)
NESInstanceBase(const nlohmann::json& config)
{ {
_inputParser = std::make_unique<jaffar::InputParser>(config); _inputParser = std::make_unique<jaffar::InputParser>(config);
} }
@ -25,7 +24,7 @@ class NESInstanceBase
inline void enableRendering() { _doRendering = true; }; inline void enableRendering() { _doRendering = true; };
inline void disableRendering() { _doRendering = false; }; 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 // Actually loading rom file
auto status = loadROMImpl(romData, romSize); auto status = loadROMImpl(romData, romSize);
@ -37,7 +36,7 @@ class NESInstanceBase
return status; return status;
} }
void enableStateBlock(const std::string& block) void enableStateBlock(const std::string &block)
{ {
// Calling implementation // Calling implementation
enableStateBlockImpl(block); enableStateBlockImpl(block);
@ -46,7 +45,7 @@ class NESInstanceBase
_stateSize = getFullStateSize(); _stateSize = getFullStateSize();
} }
void disableStateBlock(const std::string& block) void disableStateBlock(const std::string &block)
{ {
// Calling implementation // Calling implementation
disableStateBlockImpl(block); disableStateBlockImpl(block);
@ -57,27 +56,26 @@ class NESInstanceBase
virtual size_t getFullStateSize() const = 0; virtual size_t getFullStateSize() const = 0;
virtual size_t getDifferentialStateSize() 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 functions
virtual uint8_t *getLowMem() const = 0; virtual uint8_t *getLowMem() const = 0;
virtual size_t getLowMemSize() const = 0; virtual size_t getLowMemSize() const = 0;
virtual void serializeState(jaffarCommon::serializer::Base& serializer) const = 0; virtual void serializeState(jaffarCommon::serializer::Base &serializer) const = 0;
virtual void deserializeState(jaffarCommon::deserializer::Base& deserializer) = 0; virtual void deserializeState(jaffarCommon::deserializer::Base &deserializer) = 0;
virtual void doSoftReset() = 0; virtual void doSoftReset() = 0;
virtual void doHardReset() = 0; virtual void doHardReset() = 0;
virtual std::string getCoreName() const = 0; virtual std::string getCoreName() const = 0;
virtual void *getInternalEmulatorPointer() = 0; virtual void *getInternalEmulatorPointer() = 0;
virtual void setNTABBlockSize(const size_t size) { }; virtual void setNTABBlockSize(const size_t size) {};
protected: protected:
virtual void enableStateBlockImpl(const std::string &block) = 0;
virtual void enableStateBlockImpl(const std::string& block) = 0; virtual void disableStateBlockImpl(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 bool loadROMImpl(const uint8_t* romData, const size_t romSize) = 0;
// Storage for the light state size // Storage for the light state size
size_t _stateSize; size_t _stateSize;
@ -86,8 +84,6 @@ class NESInstanceBase
bool _doRendering = true; bool _doRendering = true;
private: private:
// Input parser instance // Input parser instance
std::unique_ptr<jaffar::InputParser> _inputParser; std::unique_ptr<jaffar::InputParser> _inputParser;
}; };

View File

@ -1,15 +1,15 @@
#pragma once #pragma once
#include <string> #include "nesInstance.hpp"
#include <unistd.h>
#include <SDL.h> #include <SDL.h>
#include <SDL_image.h> #include <SDL_image.h>
#include <extern/hqn/hqn.h> #include <extern/hqn/hqn.h>
#include <extern/hqn/hqn_gui_controller.h> #include <extern/hqn/hqn_gui_controller.h>
#include <jaffarCommon/serializers/contiguous.hpp>
#include <jaffarCommon/deserializers/contiguous.hpp> #include <jaffarCommon/deserializers/contiguous.hpp>
#include <jaffarCommon/hash.hpp> #include <jaffarCommon/hash.hpp>
#include "nesInstance.hpp" #include <jaffarCommon/serializers/contiguous.hpp>
#include <string>
#include <unistd.h>
#define _INVERSE_FRAME_RATE 16667 #define _INVERSE_FRAME_RATE 16667
@ -106,13 +106,13 @@ class PlaybackInstance
addStep("<End Of Sequence>"); addStep("<End Of Sequence>");
} }
void enableRendering(SDL_Window* window) void enableRendering(SDL_Window *window)
{ {
// Allocating video buffer // Allocating video buffer
_video_buffer = (uint8_t *)malloc(image_width * image_height); _video_buffer = (uint8_t *)malloc(image_width * image_height);
// Setting video buffer // 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 // Loading Emulator instance HQN
_hqnState.setEmulatorPointer(_emu->getInternalEmulatorPointer()); _hqnState.setEmulatorPointer(_emu->getInternalEmulatorPointer());
@ -233,7 +233,6 @@ class PlaybackInstance
} }
private: private:
// Internal sequence information // Internal sequence information
std::vector<stepData_t> _stepSequence; std::vector<stepData_t> _stepSequence;

View File

@ -1,12 +1,12 @@
#include <cstdlib>
#include "argparse/argparse.hpp" #include "argparse/argparse.hpp"
#include "jaffarCommon/serializers/contiguous.hpp"
#include "jaffarCommon/deserializers/contiguous.hpp" #include "jaffarCommon/deserializers/contiguous.hpp"
#include "jaffarCommon/file.hpp" #include "jaffarCommon/file.hpp"
#include "jaffarCommon/logger.hpp" #include "jaffarCommon/logger.hpp"
#include "jaffarCommon/serializers/contiguous.hpp"
#include "jaffarCommon/string.hpp" #include "jaffarCommon/string.hpp"
#include "nesInstance.hpp" #include "nesInstance.hpp"
#include "playbackInstance.hpp" #include "playbackInstance.hpp"
#include <cstdlib>
SDL_Window *launchOutputWindow() SDL_Window *launchOutputWindow()
{ {
@ -120,7 +120,7 @@ int main(int argc, char *argv[])
// Loading ROM File // Loading ROM File
std::string romFileData; std::string romFileData;
if (jaffarCommon::file::loadStringFromFile(romFileData, romFilePath) == false) JAFFAR_THROW_LOGIC("Could not rom file: %s\n", romFilePath.c_str()); 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 an initial state is provided, load it now
if (stateFilePath != "") if (stateFilePath != "")
@ -135,7 +135,7 @@ int main(int argc, char *argv[])
auto p = PlaybackInstance(&e); auto p = PlaybackInstance(&e);
// If render is enabled then, create window now // If render is enabled then, create window now
SDL_Window* window = nullptr; SDL_Window *window = nullptr;
if (disableRender == false) if (disableRender == false)
{ {
window = launchOutputWindow(); window = launchOutputWindow();

View File

@ -1,10 +1,10 @@
#pragma once #pragma once
#include "jaffarCommon/serializers/base.hpp" #include "../nesInstanceBase.hpp"
#include "jaffarCommon/deserializers/base.hpp"
#include "core/nes_emu/Nes_Emu.h" #include "core/nes_emu/Nes_Emu.h"
#include "core/nes_emu/Nes_State.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 #define _DUMMY_SIZE 65536
@ -17,8 +17,7 @@ extern void register_mapper_70();
class NESInstance final : public NESInstanceBase class NESInstance final : public NESInstanceBase
{ {
public: public:
NESInstance(const nlohmann::json &config) : NESInstanceBase(config)
NESInstance(const nlohmann::json& config) : NESInstanceBase(config)
{ {
// If running the original QuickNES, register extra mappers now // If running the original QuickNES, register extra mappers now
register_misc_mappers(); register_misc_mappers();
@ -29,14 +28,14 @@ class NESInstance final : public NESInstanceBase
uint8_t *getLowMem() const override { return _nes.low_mem(); }; uint8_t *getLowMem() const override { return _nes.low_mem(); };
size_t getLowMemSize() const override { return 0x800; }; 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); Mem_Writer w(serializer.getOutputDataBuffer(), _stateSize, 0);
Auto_File_Writer a(w); Auto_File_Writer a(w);
_nes.save_state(a); _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); Mem_File_Reader r(deserializer.getInputDataBuffer(), _stateSize);
Auto_File_Reader a(r); Auto_File_Reader a(r);
@ -68,8 +67,7 @@ class NESInstance final : public NESInstanceBase
} }
protected: 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 // Loading rom data
Mem_File_Reader romReader(romData, (int)romSize); Mem_File_Reader romReader(romData, (int)romSize);
@ -78,12 +76,10 @@ class NESInstance final : public NESInstanceBase
return result == 0; return result == 0;
} }
void enableStateBlockImpl(const std::string& block) override {}; void enableStateBlockImpl(const std::string &block) override {};
void disableStateBlockImpl(const std::string& block) override {}; void disableStateBlockImpl(const std::string &block) override {};
private: private:
// Emulator instance // Emulator instance
emulator_t _nes; emulator_t _nes;
}; };

View File

@ -82,4 +82,4 @@ void Nes_Effects_Buffer::RestoreAudioBufferState()
{ {
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -3,8 +3,8 @@
// Effects_Buffer with non-linear sound // Effects_Buffer with non-linear sound
// Nes_Emu 0.7.0 // Nes_Emu 0.7.0
#include "effectsBuffer.hpp"
#include "buffer.hpp" #include "buffer.hpp"
#include "effectsBuffer.hpp"
namespace quickerNES namespace quickerNES
{ {
@ -38,4 +38,4 @@ class Nes_Effects_Buffer : public Effects_Buffer
friend Multi_Buffer *set_apu(Nes_Effects_Buffer *, Apu *); friend Multi_Buffer *set_apu(Nes_Effects_Buffer *, Apu *);
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -19,7 +19,7 @@ namespace quickerNES
int const amp_range = 15; int const amp_range = 15;
Apu::Apu() : square1(&square_synth), Apu::Apu() : square1(&square_synth),
square2(&square_synth) square2(&square_synth)
{ {
dmc.apu = this; dmc.apu = this;
dmc.prg_reader = 0; dmc.prg_reader = 0;
@ -372,4 +372,4 @@ int Apu::read_status(nes_time_t time)
return result; return result;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -3,9 +3,9 @@
// NES 2A03 APU sound chip emulator // NES 2A03 APU sound chip emulator
// Snd_Emu 0.1.7 // Snd_Emu 0.1.7
#include "oscs.hpp"
#include <climits> #include <climits>
#include <cstdint> #include <cstdint>
#include "oscs.hpp"
namespace quickerNES namespace quickerNES
{ {
@ -360,4 +360,4 @@ inline void Apu::load_state(apu_state_t const &state)
dmc.run(last_time, last_time); dmc.run(last_time, last_time);
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -1,11 +1,11 @@
// Blip_Buffer 0.4.0. http://www.slack.net/~ant/ // Blip_Buffer 0.4.0. http://www.slack.net/~ant/
#include "blipBuffer.hpp"
#include <climits> #include <climits>
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include "blipBuffer.hpp"
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you /* 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 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)); memcpy(buffer_, extra_buffer, sizeof(extra_buffer));
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -377,4 +377,4 @@ inline int Blip_Reader::begin(Blip_Buffer &blip_buf)
int const blip_max_length = 0; int const blip_max_length = 0;
int const blip_default_length = 250; int const blip_default_length = 250;
} // namespace quickNES } // namespace quickerNES

View File

@ -227,4 +227,4 @@ void Nonlinearizer::RestoreAudioBufferState()
prev = extra_prev; prev = extra_prev;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -3,8 +3,8 @@
// NES non-linear audio buffer // NES non-linear audio buffer
// Emu 0.7.0 // Emu 0.7.0
#include <cstdint>
#include "multiBuffer.hpp" #include "multiBuffer.hpp"
#include <cstdint>
namespace quickerNES namespace quickerNES
{ {
@ -79,4 +79,4 @@ class Buffer : public Multi_Buffer
virtual void RestoreAudioBufferState(); virtual void RestoreAudioBufferState();
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -1,7 +1,7 @@
// Game_Music_Emu 0.3.0. http://www.slack.net/~ant/ // Game_Music_Emu 0.3.0. http://www.slack.net/~ant/
#include <cstring>
#include "effectsBuffer.hpp" #include "effectsBuffer.hpp"
#include <cstring>
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you /* 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 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]); r2.end(bufs[6]);
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -3,8 +3,8 @@
// Multi-channel effects buffer with panning, echo and reverb // Multi-channel effects buffer with panning, echo and reverb
// Game_Music_Emu 0.3.0 // Game_Music_Emu 0.3.0
#include <stdint.h>
#include "multiBuffer.hpp" #include "multiBuffer.hpp"
#include <stdint.h>
namespace quickerNES namespace quickerNES
{ {
@ -101,4 +101,4 @@ inline Effects_Buffer::channel_t Effects_Buffer::channel(int i)
return channels[i % chan_count]; return channels[i % chan_count];
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -105,4 +105,4 @@ void Fme7_Apu::run_until(blip_time_t end_time)
last_time = end_time; last_time = end_time;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -3,8 +3,8 @@
// Sunsoft FME-7 sound emulator // Sunsoft FME-7 sound emulator
// Emu 0.7.0 // Emu 0.7.0
#include <cstdint>
#include "../blipBuffer.hpp" #include "../blipBuffer.hpp"
#include <cstdint>
namespace quickerNES namespace quickerNES
{ {
@ -152,4 +152,4 @@ inline void Fme7_Apu::load_state(fme7_apu_state_t const &in)
run_until(last_time); run_until(last_time);
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -1,8 +1,8 @@
// Blip_Buffer 0.4.0. http://www.slack.net/~ant/ // Blip_Buffer 0.4.0. http://www.slack.net/~ant/
#include <cstdint>
#include "multiBuffer.hpp" #include "multiBuffer.hpp"
#include <cstdint>
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you /* 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 can redistribute it and/or modify it under the terms of the GNU Lesser
@ -284,4 +284,4 @@ void Stereo_Buffer::RestoreAudioBufferState()
right()->RestoreAudioBufferState(); right()->RestoreAudioBufferState();
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -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(); } inline long Mono_Buffer::samples_avail() const { return buf.samples_avail(); }
} // namespace quickNES } // namespace quickerNES

View File

@ -180,4 +180,4 @@ void Namco_Apu::load_state(namco_state_t const &in)
run_until(last_time); run_until(last_time);
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -3,8 +3,8 @@
// Namco 106 sound chip emulator // Namco 106 sound chip emulator
// Snd_Emu 0.1.7 // Snd_Emu 0.1.7
#include <cstdint>
#include "../apu.hpp" #include "../apu.hpp"
#include <cstdint>
namespace quickerNES namespace quickerNES
{ {
@ -112,4 +112,4 @@ inline void Namco_Apu::write_data(nes_time_t time, int data)
access() = data; access() = data;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -679,4 +679,4 @@ void Noise::run(nes_time_t time, nes_time_t end_time)
delay = time - end_time; delay = time - end_time;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -169,4 +169,4 @@ struct Dmc : Osc
nes_time_t next_read_time() const; nes_time_t next_read_time() const;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -212,4 +212,4 @@ void Vrc6_Apu::run_saw(nes_time_t end_time)
osc.last_amp = last_amp; osc.last_amp = last_amp;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -4,9 +4,9 @@
// Konami VRC6 sound chip emulator // Konami VRC6 sound chip emulator
// Snd_Emu 0.1.7 // Snd_Emu 0.1.7
#include <cstdint>
#include "../blipBuffer.hpp"
#include "../apu.hpp" #include "../apu.hpp"
#include "../blipBuffer.hpp"
#include <cstdint>
namespace quickerNES namespace quickerNES
{ {
@ -109,4 +109,4 @@ inline void Vrc6_Apu::treble_eq(blip_eq_t const &eq)
square_synth.treble_eq(eq); square_synth.treble_eq(eq);
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -1,6 +1,6 @@
#include <cstring>
#include "apu_vrc7.hpp" #include "apu_vrc7.hpp"
#include "emu2413.hpp" #include "emu2413.hpp"
#include <cstring>
namespace quickerNES namespace quickerNES
{ {
@ -208,4 +208,4 @@ void Vrc7::update_last_amp()
} }
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -4,9 +4,9 @@
// Konami VRC7 sound chip emulator // Konami VRC7 sound chip emulator
// Snd_Emu 0.1.7. Copyright (C) 2003-2005 Shay Green. GNU LGPL license. // Snd_Emu 0.1.7. Copyright (C) 2003-2005 Shay Green. GNU LGPL license.
#include <cstdint>
#include "../blipBuffer.hpp" #include "../blipBuffer.hpp"
#include "emu2413_state.hpp" #include "emu2413_state.hpp"
#include <cstdint>
namespace quickerNES namespace quickerNES
{ {
@ -76,4 +76,4 @@ inline void Vrc7::osc_output(int i, Blip_Buffer *buf)
oscs[i].output = buf; oscs[i].output = buf;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -108,7 +108,7 @@ static const unsigned char default_inst[15][8] = {
/* AM speed(Hz) and depth(dB) */ /* AM speed(Hz) and depth(dB) */
#define AM_SPEED 3.7 #define AM_SPEED 3.7
//#define AM_DEPTH 4.8 // #define AM_DEPTH 4.8
#define AM_DEPTH 2.4 #define AM_DEPTH 2.4
/* Cut the lower b bit(s) off. */ /* Cut the lower b bit(s) off. */
@ -243,7 +243,7 @@ static void makeDphaseTable(OPLL *opll)
static void makeTllTable(OPLL *opll) static void makeTllTable(OPLL *opll)
{ {
#define dB2(x) ((x)*2) #define dB2(x) ((x) * 2)
static const double kltable[16] = { 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)}; 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; opll->adr = val;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -220,4 +220,4 @@ extern "C"
} }
#endif #endif
} // namespace quickNES } // namespace quickerNES

View File

@ -38,4 +38,4 @@ extern "C"
} }
#endif #endif
} // namespace quickNES } // namespace quickerNES

View File

@ -114,4 +114,4 @@ class Cart
unsigned mapper; unsigned mapper;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -15,16 +15,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
// Emu 0.7.0 // Emu 0.7.0
#include <stdexcept>
#include "cpu.hpp"
#include "apu/apu.hpp" #include "apu/apu.hpp"
#include "cpu.hpp"
#include "mappers/mapper.hpp" #include "mappers/mapper.hpp"
#include "ppu/ppu.hpp" #include "ppu/ppu.hpp"
#include <cstdio>
#include <string>
#include <cstdint> #include <cstdint>
#include <jaffarCommon/serializers/base.hpp> #include <cstdio>
#include <jaffarCommon/deserializers/base.hpp> #include <jaffarCommon/deserializers/base.hpp>
#include <jaffarCommon/serializers/base.hpp>
#include <stdexcept>
#include <string>
namespace quickerNES namespace quickerNES
{ {
@ -54,11 +54,10 @@ struct nes_state_t
struct nes_state_lite_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 uint8_t frame_count; // number of frames emulated since power-up
}; };
struct joypad_state_t struct joypad_state_t
{ {
uint32_t joypad_latches[2]; // joypad 1 & 2 shift registers uint32_t joypad_latches[2]; // joypad 1 & 2 shift registers
@ -84,7 +83,6 @@ class Core : private Cpu
typedef Cpu cpu; typedef Cpu cpu;
public: public:
size_t _NTABBlockSize = 0x1000; size_t _NTABBlockSize = 0x1000;
// Flags for lite state storage // Flags for lite state storage
@ -156,7 +154,7 @@ class Core : private Cpu
reset(true, true); reset(true, true);
} }
inline void serializeState(jaffarCommon::serializer::Base& serializer) const inline void serializeState(jaffarCommon::serializer::Base &serializer) const
{ {
// TIME Block // TIME Block
if (TIMEBlockEnabled == true) 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(); disable_rendering();
error_count = 0; error_count = 0;
@ -277,7 +275,7 @@ class Core : private Cpu
// TIME Block // TIME Block
if (TIMEBlockEnabled == true) if (TIMEBlockEnabled == true)
{ {
const auto outputData = (uint8_t*) &nes; const auto outputData = (uint8_t *)&nes;
const auto inputDataSize = sizeof(nes_state_t); const auto inputDataSize = sizeof(nes_state_t);
deserializer.popContiguous(outputData, inputDataSize); deserializer.popContiguous(outputData, inputDataSize);
@ -289,7 +287,7 @@ class Core : private Cpu
{ {
cpu_state_t s; cpu_state_t s;
const auto outputData = (uint8_t*) &s; const auto outputData = (uint8_t *)&s;
const auto inputDataSize = sizeof(cpu_state_t); const auto inputDataSize = sizeof(cpu_state_t);
deserializer.popContiguous(outputData, inputDataSize); deserializer.popContiguous(outputData, inputDataSize);
@ -304,7 +302,7 @@ class Core : private Cpu
// PPUR Block // PPUR Block
if (PPURBlockEnabled == true) if (PPURBlockEnabled == true)
{ {
const auto outputData = (uint8_t*) &ppu; const auto outputData = (uint8_t *)&ppu;
const auto inputDataSize = sizeof(ppu_state_t); const auto inputDataSize = sizeof(ppu_state_t);
deserializer.popContiguous(outputData, inputDataSize); deserializer.popContiguous(outputData, inputDataSize);
} }
@ -314,7 +312,7 @@ class Core : private Cpu
{ {
Apu::apu_state_t apuState; 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); const auto inputDataSize = sizeof(Apu::apu_state_t);
deserializer.popContiguous(outputData, inputDataSize); deserializer.popContiguous(outputData, inputDataSize);
@ -325,7 +323,7 @@ class Core : private Cpu
// CTRL Block // CTRL Block
if (CTRLBlockEnabled == true) if (CTRLBlockEnabled == true)
{ {
const auto outputData = (uint8_t*) &joypad; const auto outputData = (uint8_t *)&joypad;
const auto inputDataSize = sizeof(joypad_state_t); const auto inputDataSize = sizeof(joypad_state_t);
deserializer.popContiguous(outputData, inputDataSize); deserializer.popContiguous(outputData, inputDataSize);
} }
@ -335,7 +333,7 @@ class Core : private Cpu
{ {
mapper->default_reset_state(); mapper->default_reset_state();
const auto outputData = (uint8_t*) mapper->state; const auto outputData = (uint8_t *)mapper->state;
const auto inputDataSize = mapper->state_size; const auto inputDataSize = mapper->state_size;
deserializer.popContiguous(outputData, inputDataSize); deserializer.popContiguous(outputData, inputDataSize);
@ -345,7 +343,7 @@ class Core : private Cpu
// LRAM Block // LRAM Block
if (LRAMBlockEnabled == true) if (LRAMBlockEnabled == true)
{ {
const auto outputData = (uint8_t*) low_mem; const auto outputData = (uint8_t *)low_mem;
const auto inputDataSize = low_ram_size; const auto inputDataSize = low_ram_size;
deserializer.pop(outputData, inputDataSize); deserializer.pop(outputData, inputDataSize);
} }
@ -353,7 +351,7 @@ class Core : private Cpu
// SPRT Block // SPRT Block
if (SPRTBlockEnabled == true) 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; const auto inputDataSize = Ppu::spr_ram_size;
deserializer.pop(outputData, inputDataSize); deserializer.pop(outputData, inputDataSize);
} }
@ -361,7 +359,7 @@ class Core : private Cpu
// NTAB Block // NTAB Block
if (NTABBlockEnabled == true) 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; const auto inputDataSize = _NTABBlockSize;
deserializer.pop(outputData, inputDataSize); deserializer.pop(outputData, inputDataSize);
} }
@ -371,7 +369,7 @@ class Core : private Cpu
{ {
if (ppu.chr_is_writable) 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; const auto inputDataSize = ppu.chr_size;
deserializer.pop(outputData, inputDataSize); deserializer.pop(outputData, inputDataSize);
@ -384,7 +382,7 @@ class Core : private Cpu
{ {
if (sram_present) if (sram_present)
{ {
const auto outputData = (uint8_t*) impl->sram; const auto outputData = (uint8_t *)impl->sram;
const auto inputDataSize = impl->sram_size; const auto inputDataSize = impl->sram_size;
deserializer.pop(outputData, inputDataSize); deserializer.pop(outputData, inputDataSize);
} }
@ -393,47 +391,141 @@ class Core : private Cpu
if (sram_present) enable_sram(true); 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) void enableStateBlock(const std::string &block)
{ {
bool recognizedBlock = false; bool recognizedBlock = false;
if (block == "TIME") { TIMEBlockEnabled = true; recognizedBlock = true; } if (block == "TIME")
if (block == "CPUR") { CPURBlockEnabled = true; recognizedBlock = true; } {
if (block == "PPUR") { PPURBlockEnabled = true; recognizedBlock = true; } TIMEBlockEnabled = true;
if (block == "APUR") { APURBlockEnabled = true; recognizedBlock = true; } recognizedBlock = true;
if (block == "CTRL") { CTRLBlockEnabled = true; recognizedBlock = true; } }
if (block == "MAPR") { MAPRBlockEnabled = true; recognizedBlock = true; } if (block == "CPUR")
if (block == "LRAM") { LRAMBlockEnabled = true; recognizedBlock = true; } {
if (block == "SPRT") { SPRTBlockEnabled = true; recognizedBlock = true; } CPURBlockEnabled = true;
if (block == "NTAB") { NTABBlockEnabled = true; recognizedBlock = true; } recognizedBlock = true;
if (block == "CHRR") { CHRRBlockEnabled = true; recognizedBlock = true; } }
if (block == "SRAM") { SRAMBlockEnabled = 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);} if (recognizedBlock == false)
}; {
fprintf(stderr, "Unrecognized block type: %s\n", block.c_str());
exit(-1);
}
};
void disableStateBlock(const std::string &block)
{
bool recognizedBlock = false;
void disableStateBlock(const std::string& block) if (block == "TIME")
{ {
bool recognizedBlock = false; TIMEBlockEnabled = false;
recognizedBlock = true;
if (block == "TIME") { TIMEBlockEnabled = false; recognizedBlock = true; } }
if (block == "CPUR") { CPURBlockEnabled = false; recognizedBlock = true; } if (block == "CPUR")
if (block == "PPUR") { PPURBlockEnabled = false; recognizedBlock = true; } {
if (block == "APUR") { APURBlockEnabled = false; recognizedBlock = true; } CPURBlockEnabled = false;
if (block == "CTRL") { CTRLBlockEnabled = false; recognizedBlock = true; } recognizedBlock = true;
if (block == "MAPR") { MAPRBlockEnabled = false; recognizedBlock = true; } }
if (block == "LRAM") { LRAMBlockEnabled = false; recognizedBlock = true; } if (block == "PPUR")
if (block == "SPRT") { SPRTBlockEnabled = false; recognizedBlock = true; } {
if (block == "NTAB") { NTABBlockEnabled = false; recognizedBlock = true; } PPURBlockEnabled = false;
if (block == "CHRR") { CHRRBlockEnabled = false; recognizedBlock = true; } recognizedBlock = true;
if (block == "SRAM") { SRAMBlockEnabled = false; recognizedBlock = true; } }
if (block == "APUR")
if (recognizedBlock == false) { fprintf(stderr, "Unrecognized block type: %s\n", block.c_str()); exit(-1);} {
}; 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) 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) 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; joypad_read_count = 0;
#endif #endif
current_joypad[0] = joypad1; current_joypad[0] = joypad1;
current_joypad[1] = joypad2; current_joypad[1] = joypad2;
@ -612,10 +704,10 @@ void disableStateBlock(const std::string& block)
{ {
if ((addr & 0xFFFE) == 0x4016) if ((addr & 0xFFFE) == 0x4016)
{ {
// For performance's sake, this counter is only kept on demand // For performance's sake, this counter is only kept on demand
#ifdef _QUICKERNES_DETECT_JOYPAD_READS #ifdef _QUICKERNES_DETECT_JOYPAD_READS
joypad_read_count++; joypad_read_count++;
#endif #endif
// to do: to aid with recording, doesn't emulate transparent latch, // 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 // 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) \ #define NES_CPU_READ(cpu, addr, time) \
static_cast<Core &>(*cpu).cpu_read(addr, time) static_cast<Core &>(*cpu).cpu_read(addr, time)
#define NES_CPU_WRITEX(cpu, addr, data, time) \ #define NES_CPU_WRITEX(cpu, addr, data, time) \
{ \ { \
static_cast<Core &>(*cpu).cpu_write(addr, data, time); \ static_cast<Core &>(*cpu).cpu_write(addr, data, time); \
} }
#define NES_CPU_WRITE(cpu, addr, data, time) \ #define NES_CPU_WRITE(cpu, addr, data, time) \
{ \ { \
if (addr < 0x800) \ if (addr < 0x800) \
cpu->low_mem[addr] = data; \ cpu->low_mem[addr] = data; \
else if (addr == 0x2007) \ else if (addr == 0x2007) \
static_cast<Core &>(*cpu).cpu_write_2007(data); \ static_cast<Core &>(*cpu).cpu_write_2007(data); \
else \ else \
static_cast<Core &>(*cpu).cpu_write(addr, data, time); \ static_cast<Core &>(*cpu).cpu_write(addr, data, time); \
} }
} // namespace quickNES } // namespace quickerNES

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,6 @@ typedef unsigned nes_addr_t; // 16-bit address
class Cpu class Cpu
{ {
public: public:
void set_tracecb(void (*cb)(unsigned int *data)) void set_tracecb(void (*cb)(unsigned int *data))
{ {
tracecb = cb; tracecb = cb;
@ -152,10 +151,10 @@ class Cpu
return (uint8_t *)code_map[addr >> page_bits] + addr; 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; return (const uint8_t *)code_map[addr >> page_bits] + addr;
} }
}; };
} // namespace quickNES } // namespace quickerNES

File diff suppressed because it is too large Load Diff

View File

@ -4,9 +4,9 @@
// Emu 0.7.0 // Emu 0.7.0
#include "apu/multiBuffer.hpp"
#include "cart.hpp" #include "cart.hpp"
#include "core.hpp" #include "core.hpp"
#include "apu/multiBuffer.hpp"
namespace quickerNES namespace quickerNES
{ {
@ -47,12 +47,12 @@ class Emu
int get_joypad_read_count() const { return emu.joypad_read_count; } int get_joypad_read_count() const { return emu.joypad_read_count; }
void set_tracecb(void (*cb)(unsigned int *dest)) { emu.set_tracecb(cb); } void set_tracecb(void (*cb)(unsigned int *dest)) { emu.set_tracecb(cb); }
// Save emulator state variants // Save emulator state variants
void serializeState(jaffarCommon::serializer::Base& serializer) const { emu.serializeState(serializer); } void serializeState(jaffarCommon::serializer::Base &serializer) const { emu.serializeState(serializer); }
void deserializeState(jaffarCommon::deserializer::Base& deserializer) { emu.deserializeState(deserializer); } void deserializeState(jaffarCommon::deserializer::Base &deserializer) { emu.deserializeState(deserializer); }
void setNTABBlockSize(const size_t size) { emu.setNTABBlockSize(size); } void setNTABBlockSize(const size_t size) { emu.setNTABBlockSize(size); }
void enableStateBlock(const std::string& block) { emu.enableStateBlock(block); }; void enableStateBlock(const std::string &block) { emu.enableStateBlock(block); };
void disableStateBlock(const std::string& block) { emu.disableStateBlock(block); }; void disableStateBlock(const std::string &block) { emu.disableStateBlock(block); };
// Basic emulation // Basic emulation
@ -72,7 +72,7 @@ class Emu
{ {
static const uint8_t left = 8; 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 sample_count; // number of samples (always a multiple of chan_count)
int chan_count; // 1: mono, 2: stereo int chan_count; // 1: mono, 2: stereo
@ -207,7 +207,7 @@ class Emu
low_mem_size = 0x800 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; } size_t get_low_mem_size() const { return low_mem_size; }
// Optional 8K memory // Optional 8K memory
@ -232,11 +232,11 @@ class Emu
uint8_t *pal_mem() const { return emu.ppu.getPaletteRAM(); } uint8_t *pal_mem() const { return emu.ppu.getPaletteRAM(); }
uint16_t pal_mem_size() const { return emu.ppu.getPaletteRAMSize(); } uint16_t pal_mem_size() const { return emu.ppu.getPaletteRAMSize(); }
uint8_t peek_prg(nes_addr_t addr) const { return *emu.get_code(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; } 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_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 void get_regs(unsigned int *dest) const
{ {
@ -257,7 +257,7 @@ class Emu
virtual void loading_state(State const &) {} virtual void loading_state(State const &) {}
long timestamp() const { return 0; } long timestamp() const { return 0; }
void set_timestamp(long t) { } void set_timestamp(long t) {}
private: private:
// noncopyable // noncopyable
@ -276,7 +276,7 @@ class Emu
void clear_sound_buf(); void clear_sound_buf();
void fade_samples(blip_sample_t *, int size, int step); void fade_samples(blip_sample_t *, int size, int step);
void* pixels_base_ptr; void *pixels_base_ptr;
char *host_pixels; char *host_pixels;
int host_palette_size; int host_palette_size;
frame_t single_frame; frame_t single_frame;
@ -294,14 +294,12 @@ class Emu
void SaveAudioBufferState(); void SaveAudioBufferState();
void RestoreAudioBufferState(); void RestoreAudioBufferState();
inline void *get_pixels_base_ptr()
inline void* get_pixels_base_ptr()
{ {
return pixels_base_ptr; return pixels_base_ptr;
} }
}; };
inline void Emu::set_pixels(void *p, long n) inline void Emu::set_pixels(void *p, long n)
{ {
pixels_base_ptr = p; pixels_base_ptr = p;
@ -319,4 +317,4 @@ inline long Emu::chr_size() const
return cart()->chr_size() ? cart()->chr_size() : emu.ppu.chr_addr_size; return cart()->chr_size() ? cart()->chr_size() : emu.ppu.chr_addr_size;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -291,4 +291,4 @@ Mapper *Mapper::getMapperFromCode(const int mapperCode)
return mapper; return mapper;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -3,9 +3,9 @@
// NES mapper interface // NES mapper interface
// Emu 0.7.0 // Emu 0.7.0
#include <climits>
#include "../cart.hpp" #include "../cart.hpp"
#include "../cpu.hpp" #include "../cpu.hpp"
#include <climits>
namespace quickerNES 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 inline int Mapper::read(nes_time_t, nes_addr_t) { return -1; } // signal to caller
} // namespace quickNES } // namespace quickerNES

View File

@ -35,4 +35,4 @@ class Mapper000 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -126,4 +126,4 @@ class Mapper001 : public Mapper, mmc1_state_t
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -45,4 +45,4 @@ class Mapper002 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -44,4 +44,4 @@ class Mapper003 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -255,4 +255,4 @@ class Mapper004 : public Mapper, mmc3_state_t
int counter_just_clocked; // used only for debugging int counter_just_clocked; // used only for debugging
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -149,4 +149,4 @@ class Mapper005 : public Mapper, mmc5_state_t
nes_time_t irq_time; nes_time_t irq_time;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -52,4 +52,4 @@ class Mapper007 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -78,4 +78,4 @@ class Mapper009 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -76,4 +76,4 @@ class Mapper010 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -52,4 +52,4 @@ class Mapper011 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -94,4 +94,4 @@ class Mapper015 : public Mapper, Mapper015_state_t
unsigned long int i; unsigned long int i;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -199,4 +199,4 @@ class Mapper019 : public Mapper, namco106_state_t
nes_time_t last_time; nes_time_t last_time;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -256,4 +256,4 @@ void Mapper_VRC2_4<type_a, type_b>::write_irq(nes_time_t time,
typedef Mapper_VRC2_4<true, true> Mapper021; typedef Mapper_VRC2_4<true, true> Mapper021;
} // namespace quickNES } // namespace quickerNES

View File

@ -34,4 +34,4 @@ namespace quickerNES
typedef Mapper_VRC2_4<false, true> Mapper022; typedef Mapper_VRC2_4<false, true> Mapper022;
} // namespace quickNES } // namespace quickerNES

View File

@ -33,4 +33,4 @@ namespace quickerNES
typedef Mapper_VRC2_4<false, false> Mapper023; typedef Mapper_VRC2_4<false, false> Mapper023;
} // namespace quickNES } // namespace quickerNES

View File

@ -233,4 +233,4 @@ class Mapper_Vrc6 : public Mapper, vrc6_state_t
typedef Mapper_Vrc6<0> Mapper024; typedef Mapper_Vrc6<0> Mapper024;
} // namespace quickNES } // namespace quickerNES

View File

@ -33,4 +33,4 @@ namespace quickerNES
typedef Mapper_VRC2_4<true, false> Mapper025; typedef Mapper_VRC2_4<true, false> Mapper025;
} // namespace quickNES } // namespace quickerNES

View File

@ -11,4 +11,4 @@ namespace quickerNES
typedef Mapper_Vrc6<3> Mapper026; typedef Mapper_Vrc6<3> Mapper026;
} // namespace quickNES } // namespace quickerNES

View File

@ -53,4 +53,4 @@ class Mapper030 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -126,4 +126,4 @@ class Mapper032 : public Mapper, mapper32_state_t
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -103,4 +103,4 @@ class Mapper033 : public Mapper, tc0190_state_t
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -44,4 +44,4 @@ class Mapper034 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -53,4 +53,4 @@ class Mapper060 : public Mapper
uint8_t game_sel, last_game; uint8_t game_sel, last_game;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -52,4 +52,4 @@ class Mapper066 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -190,4 +190,4 @@ class Mapper069 : public Mapper, fme7_state_t
Fme7_Apu sound; Fme7_Apu sound;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -84,4 +84,4 @@ class Mapper_74x161x162x32 : public Mapper
typedef Mapper_74x161x162x32<70> Mapper070; typedef Mapper_74x161x162x32<70> Mapper070;
} // namespace quickNES } // namespace quickerNES

View File

@ -54,4 +54,4 @@ class Mapper071 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -134,4 +134,4 @@ class Mapper073 : public Mapper, vrc3_state_t
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -110,4 +110,4 @@ class Mapper075 : public Mapper, vrc1_state_t
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -77,4 +77,4 @@ class Mapper078 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -95,4 +95,4 @@ void Mapper_AveNina<multicart>::write_regs()
typedef Mapper_AveNina<false> Mapper079; typedef Mapper_AveNina<false> Mapper079;
} // namespace quickNES } // namespace quickerNES

View File

@ -225,4 +225,4 @@ class Mapper085 : public Mapper, vrc7_state_t
}; };
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -26,4 +26,4 @@ namespace quickerNES
typedef Mapper_74x161x162x32<86> Mapper086; typedef Mapper_74x161x162x32<86> Mapper086;
} // namespace quickNES } // namespace quickerNES

View File

@ -50,4 +50,4 @@ class Mapper087 : public Mapper
void write(nes_time_t, nes_addr_t, int) {} void write(nes_time_t, nes_addr_t, int) {}
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -111,5 +111,4 @@ class Mapper_Namco_34x3 : public Mapper, namco_34x3_state_t
typedef Mapper_Namco_34x3<false> Mapper088; typedef Mapper_Namco_34x3<false> Mapper088;
} // namespace quickerNES
} // namespace quickNES

View File

@ -59,4 +59,4 @@ class Mapper089 : public Mapper
uint8_t regs; uint8_t regs;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -58,4 +58,4 @@ class Mapper093 : public Mapper
uint8_t regs; uint8_t regs;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -57,4 +57,4 @@ class Mapper094 : public Mapper
uint8_t bank; uint8_t bank;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -66,4 +66,4 @@ class Mapper097 : public Mapper
uint8_t bank; uint8_t bank;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -30,4 +30,4 @@ namespace quickerNES
typedef Mapper_AveNina<true> Mapper113; typedef Mapper_AveNina<true> Mapper113;
} // namespace quickNES } // namespace quickerNES

View File

@ -66,4 +66,4 @@ class Mapper140 : public Mapper
uint8_t regs; uint8_t regs;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -26,4 +26,4 @@ namespace quickerNES
typedef Mapper_74x161x162x32<152> Mapper152; typedef Mapper_74x161x162x32<152> Mapper152;
} // namespace quickNES } // namespace quickerNES

View File

@ -30,4 +30,4 @@ namespace quickerNES
typedef Mapper_Namco_34x3<true> Mapper154; typedef Mapper_Namco_34x3<true> Mapper154;
} // namespace quickNES } // namespace quickerNES

View File

@ -62,4 +62,4 @@ class Mapper156 : public Mapper, m156_state_t
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -57,4 +57,4 @@ class Mapper180 : public Mapper
uint8_t bank; uint8_t bank;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -67,4 +67,4 @@ class Mapper184 : public Mapper
uint8_t regs; uint8_t regs;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -57,4 +57,4 @@ class Mapper190 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -78,4 +78,4 @@ class Mapper193 : public Mapper
uint8_t regs[4]; uint8_t regs[4];
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -100,4 +100,4 @@ class Mapper206 : public Mapper, namco_34xx_state_t
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -93,4 +93,4 @@ class Mapper207 : public Mapper, taito_x1005_state_t
virtual void write(nes_time_t, nes_addr_t addr, int data) {} virtual void write(nes_time_t, nes_addr_t addr, int data) {}
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -56,4 +56,4 @@ class Mapper232 : public Mapper
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -66,4 +66,4 @@ class Mapper240 : public Mapper
uint8_t regs; uint8_t regs;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -55,4 +55,4 @@ class Mapper241 : public Mapper
uint8_t bank; uint8_t bank;
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -72,4 +72,4 @@ class Mapper244 : public Mapper, mapper244_state_t
} }
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -77,4 +77,4 @@ class Mapper246 : public Mapper
uint8_t regs[8]; uint8_t regs[8];
}; };
} // namespace quickNES } // namespace quickerNES

View File

@ -3,9 +3,9 @@
// Emu 0.7.0. http://www.slack.net/~ant/ // Emu 0.7.0. http://www.slack.net/~ant/
#include <cstring>
#include "ppu.hpp" #include "ppu.hpp"
#include "../core.hpp" #include "../core.hpp"
#include <cstring>
namespace quickerNES namespace quickerNES
{ {
@ -656,4 +656,4 @@ nes_time_t Ppu::earliest_open_bus_decay()
return (decay_low < decay_high) ? decay_low : decay_high; return (decay_low < decay_high) ? decay_low : decay_high;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -3,8 +3,8 @@
// NES PPU emulator // NES PPU emulator
// Emu 0.7.0 // Emu 0.7.0
#include <climits>
#include "ppuRendering.hpp" #include "ppuRendering.hpp"
#include <climits>
namespace quickerNES namespace quickerNES
{ {
@ -143,4 +143,4 @@ inline void Ppu::update_open_bus(nes_time_t time)
if (time >= decay_high) open_bus &= ~0xE0; if (time >= decay_high) open_bus &= ~0xE0;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -433,4 +433,4 @@ long Ppu_Impl::recalc_sprite_max(int scanline)
return 0; return 0;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -89,10 +89,10 @@ class Ppu_Impl : public ppu_state_t
}; };
impl_t *impl; impl_t *impl;
long map_chr_addr_peek( unsigned a ) const long map_chr_addr_peek(unsigned a) const
{ {
return chr_pages[a / chr_page_size] + a; return chr_pages[a / chr_page_size] + a;
} }
int peekaddr(int addr) int peekaddr(int addr)
{ {
@ -104,10 +104,10 @@ class Ppu_Impl : public ppu_state_t
static const uint16_t scanline_len = 341; 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; } 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); } uint16_t getPaletteRAMSize() const { return sizeof(palette); }
uint8_t spr_ram[spr_ram_size]; uint8_t spr_ram[spr_ram_size];
@ -260,4 +260,4 @@ inline void Ppu_Impl::begin_frame()
addr_inc = w2000 & 4 ? 32 : 1; addr_inc = w2000 & 4 ? 32 : 1;
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -503,4 +503,4 @@ void Ppu_Rendering::draw_background(int start, int count)
} }
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -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); draw_scanlines(start, count, host_pixels + host_row_bytes * start, host_row_bytes, 2);
} }
} // namespace quickNES } // namespace quickerNES

View File

@ -1,15 +1,14 @@
#pragma once #pragma once
#include "core/emu.hpp"
#include "../nesInstanceBase.hpp" #include "../nesInstanceBase.hpp"
#include "core/emu.hpp"
typedef quickerNES::Emu emulator_t; typedef quickerNES::Emu emulator_t;
class NESInstance final : public NESInstanceBase class NESInstance final : public NESInstanceBase
{ {
public: 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(); }; uint8_t *getLowMem() const override { return _nes.get_low_mem(); };
size_t getLowMemSize() const override { return _nes.get_low_mem_size(); }; size_t getLowMemSize() const override { return _nes.get_low_mem_size(); };
@ -26,8 +25,8 @@ class NESInstance final : public NESInstanceBase
uint8_t *getCHRMem() const { return _nes.chr_mem(); }; uint8_t *getCHRMem() const { return _nes.chr_mem(); };
size_t getCHRMemSize() const { return _nes.chr_size(); }; size_t getCHRMemSize() const { return _nes.chr_size(); };
void serializeState(jaffarCommon::serializer::Base& serializer) const override { _nes.serializeState(serializer); } void serializeState(jaffarCommon::serializer::Base &serializer) const override { _nes.serializeState(serializer); }
void deserializeState(jaffarCommon::deserializer::Base& deserializer) override { _nes.deserializeState(deserializer); } void deserializeState(jaffarCommon::deserializer::Base &deserializer) override { _nes.deserializeState(deserializer); }
std::string getCoreName() const override { return "QuickerNES"; } std::string getCoreName() const override { return "QuickerNES"; }
@ -59,20 +58,17 @@ class NESInstance final : public NESInstanceBase
} }
protected: 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 // Loading rom data
_nes.load_ines(romData); _nes.load_ines(romData);
return true; return true;
} }
void enableStateBlockImpl(const std::string& block) override { _nes.enableStateBlock(block); }; void enableStateBlockImpl(const std::string &block) override { _nes.enableStateBlock(block); };
void disableStateBlockImpl(const std::string& block) override { _nes.disableStateBlock(block); }; void disableStateBlockImpl(const std::string &block) override { _nes.disableStateBlock(block); };
private: private:
// Emulator instance // Emulator instance
emulator_t _nes; emulator_t _nes;
}; };

Some files were not shown because too many files have changed in this diff Show More