Updating jaffarCommon subproect

This commit is contained in:
SergioMartin86 2024-03-06 16:21:04 +01:00
parent 9f42942268
commit 8bdfd4fa2a
9 changed files with 126 additions and 120 deletions

16
extern/hqn/meson.build vendored Normal file
View File

@ -0,0 +1,16 @@
project('hqn','c','cpp',
version: '1.0.0',
license: 'GPL-3.0-only',
default_options : ['cpp_std=c++20', 'default_library=shared', 'buildtype=release']
)
hqnSrc = [
'hqn.cpp',
'hqn_gui_controller.cpp',
'hqn_surface.cpp',
]
hqnDependency = declare_dependency(
sources : hqnSrc,
include_directories : '.'
)

2
extern/jaffarCommon vendored

@ -1 +1 @@
Subproject commit 101ad3ff4f548da7f0550877f27027d8141e2d8a Subproject commit 91a8e6cbd0ca08b2859cfe47521765191c246f16

View File

@ -1,7 +1,8 @@
project('quickerNES','c','cpp', project('quickerNES','c','cpp',
version: '1.0.0', version: '1.0.0',
license: 'GPL-3.0-only', license: 'GPL-3.0-only',
default_options : ['cpp_std=c++20', 'default_library=shared', 'buildtype=release'] default_options : ['cpp_std=c++20', 'default_library=shared', 'buildtype=release'],
subproject_dir : 'extern'
) )
# Loading dependencies # Loading dependencies
@ -10,23 +11,18 @@ subdir('source')
# Common application flags # Common application flags
commonCompileArgs = [ '-Wfatal-errors', '-Wall'] commonCompileArgs = [ '-Wfatal-errors', '-Wall']
# Common includes # Grabbing jaffarCommon dependency
commonIncludes = include_directories(['extern'])
# Common sources jaffarCommonSubproject = subproject('jaffarCommon')
commonSources = [ jaffarCommonDependency = jaffarCommonSubproject.get_variable('jaffarCommonDependency')
'extern/jaffarCommon/extern/metrohash128/metrohash128.cpp',
'extern/jaffarCommon/extern/xdelta3/xdelta3.c', # Grabbing hqn dependency
]
hqnSubproject = subproject('hqn')
hqnDependency = hqnSubproject.get_variable('hqnDependency')
# Building playback tool # Building playback tool
quickerNESPlayerSrc = [
'extern/hqn/hqn.cpp',
'extern/hqn/hqn_gui_controller.cpp',
'extern/hqn/hqn_surface.cpp',
]
# Do not build any targets if this is a subproject # Do not build any targets if this is a subproject
if meson.is_subproject() == false if meson.is_subproject() == false
@ -34,10 +30,8 @@ if meson.is_subproject() == false
executable('player', executable('player',
'source/player.cpp', 'source/player.cpp',
cpp_args : [ commonCompileArgs, '-DNCURSES' ], cpp_args : [ commonCompileArgs, '-DNCURSES' ],
dependencies : [ quickerNESDependency, toolDependency, dependency('sdl2'), dependency('SDL2_image') ], dependencies : [ jaffarCommonDependency, quickerNESDependency, toolDependency, dependency('sdl2'), dependency('SDL2_image'), hqnDependency ],
link_args : [ '-lncurses' ], link_args : [ '-lncurses' ]
sources : [ commonSources, quickerNESPlayerSrc ],
include_directories : [ commonIncludes ]
) )
endif endif
@ -46,9 +40,7 @@ if meson.is_subproject() == false
quickerNESTester = executable('quickerNESTester', quickerNESTester = executable('quickerNESTester',
'source/tester.cpp', 'source/tester.cpp',
cpp_args : [ commonCompileArgs, '-Werror' ], cpp_args : [ commonCompileArgs, '-Werror' ],
dependencies : [ quickerNESDependency, toolDependency ], dependencies : [ jaffarCommonDependency, quickerNESDependency, toolDependency ]
sources : [ commonSources ],
include_directories : [ commonIncludes ]
) )
# Building tester tool for the original QuickNES # Building tester tool for the original QuickNES
@ -57,9 +49,7 @@ if meson.is_subproject() == false
quickNESTester = executable('quickNESTester', quickNESTester = executable('quickNESTester',
'source/tester.cpp', 'source/tester.cpp',
cpp_args : [ commonCompileArgs, '-w', '-DDISABLE_AUTO_FILE', '-D__LIBRETRO__', '-DNDEBUG', '-DBLARGG_NONPORTABLE' ], cpp_args : [ commonCompileArgs, '-w', '-DDISABLE_AUTO_FILE', '-D__LIBRETRO__', '-DNDEBUG', '-DBLARGG_NONPORTABLE' ],
dependencies : [ quickNESDependency, toolDependency ], dependencies : [ jaffarCommonDependency, quickNESDependency, toolDependency ]
sources : [ commonSources ],
include_directories : [ commonIncludes ]
) )
endif endif

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "jaffarCommon/include/serializers/contiguous.hpp" #include "jaffarCommon/serializers/contiguous.hpp"
#include "jaffarCommon/include/serializers/differential.hpp" #include "jaffarCommon/serializers/differential.hpp"
#include "jaffarCommon/include/logger.hpp" #include "jaffarCommon/logger.hpp"
#include "controller.hpp" #include "controller.hpp"
// Size of image generated in graphics buffer // Size of image generated in graphics buffer
@ -19,10 +19,10 @@ class NESInstanceBase
inline void advanceState(const std::string &move) inline void advanceState(const std::string &move)
{ {
bool isInputValid = _controller.parseInputString(move); bool isInputValid = _controller.parseInputString(move);
if (isInputValid == false) EXIT_WITH_ERROR("Move provided cannot be parsed: '%s'\n", move.c_str()); if (isInputValid == false) JAFFAR_THROW_LOGIC("Move provided cannot be parsed: '%s'\n", move.c_str());
// Parsing power // Parsing power
if (_controller.getPowerButtonState() == true) EXIT_WITH_ERROR("Power button pressed, but not supported: '%s'\n", move.c_str()); if (_controller.getPowerButtonState() == true) JAFFAR_THROW_LOGIC("Power button pressed, but not supported: '%s'\n", move.c_str());
// Parsing reset // Parsing reset
if (_controller.getResetButtonState() == true) doSoftReset(); if (_controller.getResetButtonState() == true) doSoftReset();
@ -43,7 +43,7 @@ class NESInstanceBase
if (type == "FourScore1") { _controller.setController1Type(Controller::controller_t::fourscore1); isTypeRecognized = true; } if (type == "FourScore1") { _controller.setController1Type(Controller::controller_t::fourscore1); isTypeRecognized = true; }
if (type == "FourScore2") { _controller.setController1Type(Controller::controller_t::fourscore2); isTypeRecognized = true; } if (type == "FourScore2") { _controller.setController1Type(Controller::controller_t::fourscore2); isTypeRecognized = true; }
if (isTypeRecognized == false) EXIT_WITH_ERROR("Input type not recognized: '%s'\n", type.c_str()); if (isTypeRecognized == false) JAFFAR_THROW_LOGIC("Input type not recognized: '%s'\n", type.c_str());
} }
inline void setController2Type(const std::string& type) inline void setController2Type(const std::string& type)
@ -55,7 +55,7 @@ class NESInstanceBase
if (type == "FourScore1") { _controller.setController2Type(Controller::controller_t::fourscore1); isTypeRecognized = true; } if (type == "FourScore1") { _controller.setController2Type(Controller::controller_t::fourscore1); isTypeRecognized = true; }
if (type == "FourScore2") { _controller.setController2Type(Controller::controller_t::fourscore2); isTypeRecognized = true; } if (type == "FourScore2") { _controller.setController2Type(Controller::controller_t::fourscore2); isTypeRecognized = true; }
if (isTypeRecognized == false) EXIT_WITH_ERROR("Input type not recognized: '%s'\n", type.c_str()); if (isTypeRecognized == false) JAFFAR_THROW_LOGIC("Input type not recognized: '%s'\n", type.c_str());
} }
inline void enableRendering() { _doRendering = true; }; inline void enableRendering() { _doRendering = true; };

View File

@ -4,11 +4,11 @@
#include <unistd.h> #include <unistd.h>
#include <SDL.h> #include <SDL.h>
#include <SDL_image.h> #include <SDL_image.h>
#include <hqn/hqn.h> #include <extern/hqn/hqn.h>
#include <hqn/hqn_gui_controller.h> #include <extern/hqn/hqn_gui_controller.h>
#include <jaffarCommon/include/serializers/contiguous.hpp> #include <jaffarCommon/serializers/contiguous.hpp>
#include <jaffarCommon/include/deserializers/contiguous.hpp> #include <jaffarCommon/deserializers/contiguous.hpp>
#include <jaffarCommon/include/hash.hpp> #include <jaffarCommon/hash.hpp>
#include "nesInstance.hpp" #include "nesInstance.hpp"
#define _INVERSE_FRAME_RATE 16667 #define _INVERSE_FRAME_RATE 16667
@ -17,7 +17,7 @@ struct stepData_t
{ {
std::string input; std::string input;
uint8_t *stateData; uint8_t *stateData;
jaffarCommon::hash_t hash; jaffarCommon::hash::hash_t hash;
}; };
class PlaybackInstance class PlaybackInstance
@ -34,7 +34,7 @@ class PlaybackInstance
jaffarCommon::serializer::Contiguous serializer(step.stateData); jaffarCommon::serializer::Contiguous serializer(step.stateData);
_emu->serializeState(serializer); _emu->serializeState(serializer);
step.hash = jaffarCommon::calculateMetroHash(_emu->getLowMem(), _emu->getLowMemSize()); step.hash = jaffarCommon::hash::calculateMetroHash(_emu->getLowMem(), _emu->getLowMemSize());
// Adding the step into the sequence // Adding the step into the sequence
_stepSequence.push_back(step); _stepSequence.push_back(step);
@ -81,39 +81,39 @@ class PlaybackInstance
imagePath = _overlayPath + std::string("/base.png"); imagePath = _overlayPath + std::string("/base.png");
_overlayBaseSurface = IMG_Load(imagePath.c_str()); _overlayBaseSurface = IMG_Load(imagePath.c_str());
if (_overlayBaseSurface == NULL) EXIT_WITH_ERROR("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError()); if (_overlayBaseSurface == NULL) JAFFAR_THROW_LOGIC("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError());
imagePath = _overlayPath + std::string("/button_a.png"); imagePath = _overlayPath + std::string("/button_a.png");
_overlayButtonASurface = IMG_Load(imagePath.c_str()); _overlayButtonASurface = IMG_Load(imagePath.c_str());
if (_overlayButtonASurface == NULL) EXIT_WITH_ERROR("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError()); if (_overlayButtonASurface == NULL) JAFFAR_THROW_LOGIC("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError());
imagePath = _overlayPath + std::string("/button_b.png"); imagePath = _overlayPath + std::string("/button_b.png");
_overlayButtonBSurface = IMG_Load(imagePath.c_str()); _overlayButtonBSurface = IMG_Load(imagePath.c_str());
if (_overlayButtonBSurface == NULL) EXIT_WITH_ERROR("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError()); if (_overlayButtonBSurface == NULL) JAFFAR_THROW_LOGIC("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError());
imagePath = _overlayPath + std::string("/button_select.png"); imagePath = _overlayPath + std::string("/button_select.png");
_overlayButtonSelectSurface = IMG_Load(imagePath.c_str()); _overlayButtonSelectSurface = IMG_Load(imagePath.c_str());
if (_overlayButtonSelectSurface == NULL) EXIT_WITH_ERROR("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError()); if (_overlayButtonSelectSurface == NULL) JAFFAR_THROW_LOGIC("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError());
imagePath = _overlayPath + std::string("/button_start.png"); imagePath = _overlayPath + std::string("/button_start.png");
_overlayButtonStartSurface = IMG_Load(imagePath.c_str()); _overlayButtonStartSurface = IMG_Load(imagePath.c_str());
if (_overlayButtonStartSurface == NULL) EXIT_WITH_ERROR("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError()); if (_overlayButtonStartSurface == NULL) JAFFAR_THROW_LOGIC("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError());
imagePath = _overlayPath + std::string("/button_left.png"); imagePath = _overlayPath + std::string("/button_left.png");
_overlayButtonLeftSurface = IMG_Load(imagePath.c_str()); _overlayButtonLeftSurface = IMG_Load(imagePath.c_str());
if (_overlayButtonLeftSurface == NULL) EXIT_WITH_ERROR("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError()); if (_overlayButtonLeftSurface == NULL) JAFFAR_THROW_LOGIC("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError());
imagePath = _overlayPath + std::string("/button_right.png"); imagePath = _overlayPath + std::string("/button_right.png");
_overlayButtonRightSurface = IMG_Load(imagePath.c_str()); _overlayButtonRightSurface = IMG_Load(imagePath.c_str());
if (_overlayButtonRightSurface == NULL) EXIT_WITH_ERROR("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError()); if (_overlayButtonRightSurface == NULL) JAFFAR_THROW_LOGIC("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError());
imagePath = _overlayPath + std::string("/button_up.png"); imagePath = _overlayPath + std::string("/button_up.png");
_overlayButtonUpSurface = IMG_Load(imagePath.c_str()); _overlayButtonUpSurface = IMG_Load(imagePath.c_str());
if (_overlayButtonUpSurface == NULL) EXIT_WITH_ERROR("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError()); if (_overlayButtonUpSurface == NULL) JAFFAR_THROW_LOGIC("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError());
imagePath = _overlayPath + std::string("/button_down.png"); imagePath = _overlayPath + std::string("/button_down.png");
_overlayButtonDownSurface = IMG_Load(imagePath.c_str()); _overlayButtonDownSurface = IMG_Load(imagePath.c_str());
if (_overlayButtonDownSurface == NULL) EXIT_WITH_ERROR("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError()); if (_overlayButtonDownSurface == NULL) JAFFAR_THROW_LOGIC("[Error] Could not load image: %s, Reason: %s\n", imagePath.c_str(), SDL_GetError());
} }
// Opening rendering window // Opening rendering window
@ -122,7 +122,7 @@ class PlaybackInstance
// We can only call SDL_InitSubSystem once // We can only call SDL_InitSubSystem once
if (!SDL_WasInit(SDL_INIT_VIDEO)) if (!SDL_WasInit(SDL_INIT_VIDEO))
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0)
EXIT_WITH_ERROR("Failed to initialize video: %s", SDL_GetError()); JAFFAR_THROW_LOGIC("Failed to initialize video: %s", SDL_GetError());
// Creating HQN GUI // Creating HQN GUI
_hqnGUI = hqn::GUIController::create(_hqnState); _hqnGUI = hqn::GUIController::create(_hqnState);
@ -133,7 +133,7 @@ class PlaybackInstance
void renderFrame(const size_t stepId) void renderFrame(const size_t stepId)
{ {
// Checking the required step id does not exceed contents of the sequence // Checking the required step id does not exceed contents of the sequence
if (stepId > _stepSequence.size()) EXIT_WITH_ERROR("[Error] Attempting to render a step larger than the step sequence"); if (stepId > _stepSequence.size()) JAFFAR_THROW_LOGIC("[Error] Attempting to render a step larger than the step sequence");
// Getting step information // Getting step information
const auto &step = _stepSequence[stepId]; const auto &step = _stepSequence[stepId];
@ -189,7 +189,7 @@ class PlaybackInstance
const std::string getInput(const size_t stepId) const const std::string getInput(const size_t stepId) const
{ {
// Checking the required step id does not exceed contents of the sequence // Checking the required step id does not exceed contents of the sequence
if (stepId > _stepSequence.size()) EXIT_WITH_ERROR("[Error] Attempting to render a step larger than the step sequence"); if (stepId > _stepSequence.size()) JAFFAR_THROW_LOGIC("[Error] Attempting to render a step larger than the step sequence");
// Getting step information // Getting step information
const auto &step = _stepSequence[stepId]; const auto &step = _stepSequence[stepId];
@ -201,7 +201,7 @@ class PlaybackInstance
const uint8_t *getStateData(const size_t stepId) const const uint8_t *getStateData(const size_t stepId) const
{ {
// Checking the required step id does not exceed contents of the sequence // Checking the required step id does not exceed contents of the sequence
if (stepId > _stepSequence.size()) EXIT_WITH_ERROR("[Error] Attempting to render a step larger than the step sequence"); if (stepId > _stepSequence.size()) JAFFAR_THROW_LOGIC("[Error] Attempting to render a step larger than the step sequence");
// Getting step information // Getting step information
const auto &step = _stepSequence[stepId]; const auto &step = _stepSequence[stepId];
@ -210,10 +210,10 @@ class PlaybackInstance
return step.stateData; return step.stateData;
} }
const jaffarCommon::hash_t getStateHash(const size_t stepId) const const jaffarCommon::hash::hash_t getStateHash(const size_t stepId) const
{ {
// Checking the required step id does not exceed contents of the sequence // Checking the required step id does not exceed contents of the sequence
if (stepId > _stepSequence.size()) EXIT_WITH_ERROR("[Error] Attempting to render a step larger than the step sequence"); if (stepId > _stepSequence.size()) JAFFAR_THROW_LOGIC("[Error] Attempting to render a step larger than the step sequence");
// Getting step information // Getting step information
const auto &step = _stepSequence[stepId]; const auto &step = _stepSequence[stepId];
@ -225,7 +225,7 @@ class PlaybackInstance
const std::string getStateInput(const size_t stepId) const const std::string getStateInput(const size_t stepId) const
{ {
// Checking the required step id does not exceed contents of the sequence // Checking the required step id does not exceed contents of the sequence
if (stepId > _stepSequence.size()) EXIT_WITH_ERROR("[Error] Attempting to render a step larger than the step sequence"); if (stepId > _stepSequence.size()) JAFFAR_THROW_LOGIC("[Error] Attempting to render a step larger than the step sequence");
// Getting step information // Getting step information
const auto &step = _stepSequence[stepId]; const auto &step = _stepSequence[stepId];

View File

@ -1,10 +1,10 @@
#include <cstdlib> #include <cstdlib>
#include "jaffarCommon/extern/argparse/argparse.hpp" #include "argparse/argparse.hpp"
#include "jaffarCommon/include/serializers/contiguous.hpp" #include "jaffarCommon/serializers/contiguous.hpp"
#include "jaffarCommon/include/deserializers/contiguous.hpp" #include "jaffarCommon/deserializers/contiguous.hpp"
#include "jaffarCommon/include/file.hpp" #include "jaffarCommon/file.hpp"
#include "jaffarCommon/include/logger.hpp" #include "jaffarCommon/logger.hpp"
#include "jaffarCommon/include/string.hpp" #include "jaffarCommon/string.hpp"
#include "nesInstance.hpp" #include "nesInstance.hpp"
#include "playbackInstance.hpp" #include "playbackInstance.hpp"
@ -50,7 +50,7 @@ int main(int argc, char *argv[])
} }
catch (const std::runtime_error &err) catch (const std::runtime_error &err)
{ {
EXIT_WITH_ERROR("%s\n%s", err.what(), program.help().str().c_str()); JAFFAR_THROW_LOGIC("%s\n%s", err.what(), program.help().str().c_str());
} }
// Getting ROM file path // Getting ROM file path
@ -76,14 +76,14 @@ int main(int argc, char *argv[])
// Loading sequence file // Loading sequence file
std::string inputSequence; std::string inputSequence;
auto status = jaffarCommon::loadStringFromFile(inputSequence, sequenceFilePath.c_str()); auto status = jaffarCommon::file::loadStringFromFile(inputSequence, sequenceFilePath.c_str());
if (status == false) EXIT_WITH_ERROR("[ERROR] Could not find or read from sequence file: %s\n", sequenceFilePath.c_str()); if (status == false) JAFFAR_THROW_LOGIC("[ERROR] Could not find or read from sequence file: %s\n", sequenceFilePath.c_str());
// Building sequence information // Building sequence information
const auto sequence = jaffarCommon::split(inputSequence, ' '); const auto sequence = jaffarCommon::string::split(inputSequence, ' ');
// Initializing terminal // Initializing terminal
jaffarCommon::initializeTerminal(); jaffarCommon::logger::initializeTerminal();
// Printing provided parameters // Printing provided parameters
printw("[] Rom File Path: '%s'\n", romFilePath.c_str()); printw("[] Rom File Path: '%s'\n", romFilePath.c_str());
@ -92,7 +92,7 @@ int main(int argc, char *argv[])
printw("[] State File Path: '%s'\n", stateFilePath.empty() ? "<Boot Start>" : stateFilePath.c_str()); printw("[] State File Path: '%s'\n", stateFilePath.empty() ? "<Boot Start>" : stateFilePath.c_str());
printw("[] Generating Sequence...\n"); printw("[] Generating Sequence...\n");
jaffarCommon::refreshTerminal(); jaffarCommon::logger::refreshTerminal();
// Creating emulator instance // Creating emulator instance
NESInstance e; NESInstance e;
@ -103,14 +103,14 @@ int main(int argc, char *argv[])
// Loading ROM File // Loading ROM File
std::string romFileData; std::string romFileData;
if (jaffarCommon::loadStringFromFile(romFileData, romFilePath) == false) EXIT_WITH_ERROR("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 != "")
{ {
std::string stateFileData; std::string stateFileData;
if (jaffarCommon::loadStringFromFile(stateFileData, stateFilePath) == false) EXIT_WITH_ERROR("Could not initial state file: %s\n", stateFilePath.c_str()); if (jaffarCommon::file::loadStringFromFile(stateFileData, stateFilePath) == false) JAFFAR_THROW_LOGIC("Could not initial state file: %s\n", stateFilePath.c_str());
jaffarCommon::deserializer::Contiguous deserializer(stateFileData.data()); jaffarCommon::deserializer::Contiguous deserializer(stateFileData.data());
e.deserializeState(deserializer); e.deserializeState(deserializer);
} }
@ -149,7 +149,7 @@ int main(int argc, char *argv[])
// Printing data and commands // Printing data and commands
if (showFrameInfo) if (showFrameInfo)
{ {
jaffarCommon::clearTerminal(); jaffarCommon::logger::clearTerminal();
printw("[] ----------------------------------------------------------------\n"); printw("[] ----------------------------------------------------------------\n");
printw("[] Current Step #: %lu / %lu\n", currentStep + 1, sequenceLength); printw("[] Current Step #: %lu / %lu\n", currentStep + 1, sequenceLength);
@ -159,14 +159,14 @@ int main(int argc, char *argv[])
// Only print commands if not in reproduce mode // Only print commands if not in reproduce mode
if (isReproduce == false) printw("[] Commands: n: -1 m: +1 | h: -10 | j: +10 | y: -100 | u: +100 | k: -1000 | i: +1000 | s: quicksave | p: play | q: quit\n"); if (isReproduce == false) printw("[] Commands: n: -1 m: +1 | h: -10 | j: +10 | y: -100 | u: +100 | k: -1000 | i: +1000 | s: quicksave | p: play | q: quit\n");
jaffarCommon::refreshTerminal(); jaffarCommon::logger::refreshTerminal();
} }
// Resetting show frame info flag // Resetting show frame info flag
showFrameInfo = true; showFrameInfo = true;
// Get command // Get command
auto command = jaffarCommon::waitForKeyPress(); auto command = jaffarCommon::logger::waitForKeyPress();
// Advance/Rewind commands // Advance/Rewind commands
if (command == 'n') currentStep = currentStep - 1; if (command == 'n') currentStep = currentStep - 1;
@ -191,7 +191,7 @@ int main(int argc, char *argv[])
std::string saveData; std::string saveData;
saveData.resize(stateSize); saveData.resize(stateSize);
memcpy(saveData.data(), stateData, stateSize); memcpy(saveData.data(), stateData, stateSize);
if (jaffarCommon::saveStringToFile(saveData, saveFileName.c_str()) == false) EXIT_WITH_ERROR("[ERROR] Could not save state file: %s\n", saveFileName.c_str()); if (jaffarCommon::file::saveStringToFile(saveData, saveFileName.c_str()) == false) JAFFAR_THROW_LOGIC("[ERROR] Could not save state file: %s\n", saveFileName.c_str());
printw("[] Saved state to %s\n", saveFileName.c_str()); printw("[] Saved state to %s\n", saveFileName.c_str());
// Do no show frame info again after this action // Do no show frame info again after this action
@ -206,5 +206,5 @@ int main(int argc, char *argv[])
} }
// Ending ncurses window // Ending ncurses window
jaffarCommon::finalizeTerminal(); jaffarCommon::logger::finalizeTerminal();
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "jaffarCommon/include/serializers/base.hpp" #include "jaffarCommon/serializers/base.hpp"
#include "jaffarCommon/include/deserializers/base.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 "../nesInstanceBase.hpp"

View File

@ -22,8 +22,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "ppu/ppu.hpp" #include "ppu/ppu.hpp"
#include <cstdio> #include <cstdio>
#include <string> #include <string>
#include <jaffarCommon/include/serializers/base.hpp> #include <jaffarCommon/serializers/base.hpp>
#include <jaffarCommon/include/deserializers/base.hpp> #include <jaffarCommon/deserializers/base.hpp>
namespace quickerNES namespace quickerNES
{ {

View File

@ -1,12 +1,12 @@
#include <jaffarCommon/extern/argparse/argparse.hpp> #include <argparse/argparse.hpp>
#include <jaffarCommon/include/json.hpp> #include <jaffarCommon/json.hpp>
#include <jaffarCommon/include/serializers/contiguous.hpp> #include <jaffarCommon/serializers/contiguous.hpp>
#include <jaffarCommon/include/serializers/differential.hpp> #include <jaffarCommon/serializers/differential.hpp>
#include <jaffarCommon/include/deserializers/contiguous.hpp> #include <jaffarCommon/deserializers/contiguous.hpp>
#include <jaffarCommon/include/deserializers/differential.hpp> #include <jaffarCommon/deserializers/differential.hpp>
#include <jaffarCommon/include/hash.hpp> #include <jaffarCommon/hash.hpp>
#include <jaffarCommon/include/string.hpp> #include <jaffarCommon/string.hpp>
#include <jaffarCommon/include/file.hpp> #include <jaffarCommon/file.hpp>
#include "nesInstance.hpp" #include "nesInstance.hpp"
#include <chrono> #include <chrono>
#include <sstream> #include <sstream>
@ -37,7 +37,7 @@ int main(int argc, char *argv[])
} }
catch (const std::runtime_error &err) catch (const std::runtime_error &err)
{ {
EXIT_WITH_ERROR("%s\n%s", err.what(), program.help().str().c_str()); JAFFAR_THROW_LOGIC("%s\n%s", err.what(), program.help().str().c_str());
} }
// Getting test script file path // Getting test script file path
@ -51,68 +51,68 @@ int main(int argc, char *argv[])
// Loading script file // Loading script file
std::string scriptJsonRaw; std::string scriptJsonRaw;
if (jaffarCommon::loadStringFromFile(scriptJsonRaw, scriptFilePath) == false) EXIT_WITH_ERROR("Could not find/read script file: %s\n", scriptFilePath.c_str()); if (jaffarCommon::file::loadStringFromFile(scriptJsonRaw, scriptFilePath) == false) JAFFAR_THROW_LOGIC("Could not find/read script file: %s\n", scriptFilePath.c_str());
// Parsing script // Parsing script
const auto scriptJson = nlohmann::json::parse(scriptJsonRaw); const auto scriptJson = nlohmann::json::parse(scriptJsonRaw);
// Getting rom file path // Getting rom file path
if (scriptJson.contains("Rom File") == false) EXIT_WITH_ERROR("Script file missing 'Rom File' entry\n"); if (scriptJson.contains("Rom File") == false) JAFFAR_THROW_LOGIC("Script file missing 'Rom File' entry\n");
if (scriptJson["Rom File"].is_string() == false) EXIT_WITH_ERROR("Script file 'Rom File' entry is not a string\n"); if (scriptJson["Rom File"].is_string() == false) JAFFAR_THROW_LOGIC("Script file 'Rom File' entry is not a string\n");
std::string romFilePath = scriptJson["Rom File"].get<std::string>(); std::string romFilePath = scriptJson["Rom File"].get<std::string>();
// Getting initial state file path // Getting initial state file path
if (scriptJson.contains("Initial State File") == false) EXIT_WITH_ERROR("Script file missing 'Initial State File' entry\n"); if (scriptJson.contains("Initial State File") == false) JAFFAR_THROW_LOGIC("Script file missing 'Initial State File' entry\n");
if (scriptJson["Initial State File"].is_string() == false) EXIT_WITH_ERROR("Script file 'Initial State File' entry is not a string\n"); if (scriptJson["Initial State File"].is_string() == false) JAFFAR_THROW_LOGIC("Script file 'Initial State File' entry is not a string\n");
std::string initialStateFilePath = scriptJson["Initial State File"].get<std::string>(); std::string initialStateFilePath = scriptJson["Initial State File"].get<std::string>();
// Getting sequence file path // Getting sequence file path
if (scriptJson.contains("Sequence File") == false) EXIT_WITH_ERROR("Script file missing 'Sequence File' entry\n"); if (scriptJson.contains("Sequence File") == false) JAFFAR_THROW_LOGIC("Script file missing 'Sequence File' entry\n");
if (scriptJson["Sequence File"].is_string() == false) EXIT_WITH_ERROR("Script file 'Sequence File' entry is not a string\n"); if (scriptJson["Sequence File"].is_string() == false) JAFFAR_THROW_LOGIC("Script file 'Sequence File' entry is not a string\n");
std::string sequenceFilePath = scriptJson["Sequence File"].get<std::string>(); std::string sequenceFilePath = scriptJson["Sequence File"].get<std::string>();
// Getting expected ROM SHA1 hash // Getting expected ROM SHA1 hash
if (scriptJson.contains("Expected ROM SHA1") == false) EXIT_WITH_ERROR("Script file missing 'Expected ROM SHA1' entry\n"); if (scriptJson.contains("Expected ROM SHA1") == false) JAFFAR_THROW_LOGIC("Script file missing 'Expected ROM SHA1' entry\n");
if (scriptJson["Expected ROM SHA1"].is_string() == false) EXIT_WITH_ERROR("Script file 'Expected ROM SHA1' entry is not a string\n"); if (scriptJson["Expected ROM SHA1"].is_string() == false) JAFFAR_THROW_LOGIC("Script file 'Expected ROM SHA1' entry is not a string\n");
std::string expectedROMSHA1 = scriptJson["Expected ROM SHA1"].get<std::string>(); std::string expectedROMSHA1 = scriptJson["Expected ROM SHA1"].get<std::string>();
// Parsing disabled blocks in lite state serialization // Parsing disabled blocks in lite state serialization
std::vector<std::string> stateDisabledBlocks; std::vector<std::string> stateDisabledBlocks;
std::string stateDisabledBlocksOutput; std::string stateDisabledBlocksOutput;
if (scriptJson.contains("Disable State Blocks") == false) EXIT_WITH_ERROR("Script file missing 'Disable State Blocks' entry\n"); 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) EXIT_WITH_ERROR("Script file 'Disable State Blocks' is not an array\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) EXIT_WITH_ERROR("Script file 'Disable State Blocks' entry is not a string\n"); if (entry.is_string() == false) JAFFAR_THROW_LOGIC("Script file 'Disable State Blocks' entry is not a string\n");
stateDisabledBlocks.push_back(entry.get<std::string>()); stateDisabledBlocks.push_back(entry.get<std::string>());
stateDisabledBlocksOutput += entry.get<std::string>() + std::string(" "); stateDisabledBlocksOutput += entry.get<std::string>() + std::string(" ");
} }
// Getting Controller 1 type // Getting Controller 1 type
if (scriptJson.contains("Controller 1 Type") == false) EXIT_WITH_ERROR("Script file missing 'Controller 1 Type' entry\n"); if (scriptJson.contains("Controller 1 Type") == false) JAFFAR_THROW_LOGIC("Script file missing 'Controller 1 Type' entry\n");
if (scriptJson["Controller 1 Type"].is_string() == false) EXIT_WITH_ERROR("Script file 'Controller 1 Type' entry is not a string\n"); if (scriptJson["Controller 1 Type"].is_string() == false) JAFFAR_THROW_LOGIC("Script file 'Controller 1 Type' entry is not a string\n");
std::string controller1Type = scriptJson["Controller 1 Type"].get<std::string>(); std::string controller1Type = scriptJson["Controller 1 Type"].get<std::string>();
// Getting Controller 2 type // Getting Controller 2 type
if (scriptJson.contains("Controller 2 Type") == false) EXIT_WITH_ERROR("Script file missing 'Controller 2 Type' entry\n"); if (scriptJson.contains("Controller 2 Type") == false) JAFFAR_THROW_LOGIC("Script file missing 'Controller 2 Type' entry\n");
if (scriptJson["Controller 2 Type"].is_string() == false) EXIT_WITH_ERROR("Script file 'Controller 2 Type' entry is not a string\n"); if (scriptJson["Controller 2 Type"].is_string() == false) JAFFAR_THROW_LOGIC("Script file 'Controller 2 Type' entry is not a string\n");
std::string controller2Type = scriptJson["Controller 2 Type"].get<std::string>(); std::string controller2Type = scriptJson["Controller 2 Type"].get<std::string>();
// Getting differential compression configuration // Getting differential compression configuration
if (scriptJson.contains("Differential Compression") == false) EXIT_WITH_ERROR("Script file missing 'Differential Compression' entry\n"); if (scriptJson.contains("Differential Compression") == false) JAFFAR_THROW_LOGIC("Script file missing 'Differential Compression' entry\n");
if (scriptJson["Differential Compression"].is_object() == false) EXIT_WITH_ERROR("Script file 'Differential Compression' entry is not a key/value object\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) EXIT_WITH_ERROR("Script file missing 'Differential Compression / Enabled' entry\n"); if (differentialCompressionJs.contains("Enabled") == false) JAFFAR_THROW_LOGIC("Script file missing 'Differential Compression / Enabled' entry\n");
if (differentialCompressionJs["Enabled"].is_boolean() == false) EXIT_WITH_ERROR("Script file 'Differential Compression / Enabled' entry is not a boolean\n"); if (differentialCompressionJs["Enabled"].is_boolean() == false) JAFFAR_THROW_LOGIC("Script file 'Differential Compression / Enabled' entry is not a boolean\n");
const auto differentialCompressionEnabled = differentialCompressionJs["Enabled"].get<bool>(); const auto differentialCompressionEnabled = differentialCompressionJs["Enabled"].get<bool>();
if (differentialCompressionJs.contains("Max Differences") == false) EXIT_WITH_ERROR("Script file missing 'Differential Compression / Max Differences' entry\n"); if (differentialCompressionJs.contains("Max Differences") == false) JAFFAR_THROW_LOGIC("Script file missing 'Differential Compression / Max Differences' entry\n");
if (differentialCompressionJs["Max Differences"].is_number() == false) EXIT_WITH_ERROR("Script file 'Differential Compression / Max Differences' entry is not a number\n"); if (differentialCompressionJs["Max Differences"].is_number() == false) JAFFAR_THROW_LOGIC("Script file 'Differential Compression / Max Differences' entry is not a number\n");
const auto differentialCompressionMaxDifferences = differentialCompressionJs["Max Differences"].get<size_t>(); const auto differentialCompressionMaxDifferences = differentialCompressionJs["Max Differences"].get<size_t>();
if (differentialCompressionJs.contains("Use Zlib") == false) EXIT_WITH_ERROR("Script file missing 'Differential Compression / Use Zlib' entry\n"); if (differentialCompressionJs.contains("Use Zlib") == false) JAFFAR_THROW_LOGIC("Script file missing 'Differential Compression / Use Zlib' entry\n");
if (differentialCompressionJs["Use Zlib"].is_boolean() == false) EXIT_WITH_ERROR("Script file 'Differential Compression / Use Zlib' entry is not a boolean\n"); if (differentialCompressionJs["Use Zlib"].is_boolean() == false) JAFFAR_THROW_LOGIC("Script file 'Differential Compression / Use Zlib' entry is not a boolean\n");
const auto differentialCompressionUseZlib = differentialCompressionJs["Use Zlib"].get<bool>(); const auto differentialCompressionUseZlib = differentialCompressionJs["Use Zlib"].get<bool>();
// Creating emulator instance // Creating emulator instance
@ -124,17 +124,17 @@ int main(int argc, char *argv[])
// Loading ROM File // Loading ROM File
std::string romFileData; std::string romFileData;
if (jaffarCommon::loadStringFromFile(romFileData, romFilePath) == false) EXIT_WITH_ERROR("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());
// Calculating ROM SHA1 // Calculating ROM SHA1
auto romSHA1 = SHA1::GetHash((uint8_t *)romFileData.data(), romFileData.size()); auto romSHA1 = jaffarCommon::hash::getSHA1String(romFileData);
// If an initial state is provided, load it now // If an initial state is provided, load it now
if (initialStateFilePath != "") if (initialStateFilePath != "")
{ {
std::string stateFileData; std::string stateFileData;
if (jaffarCommon::loadStringFromFile(stateFileData, initialStateFilePath) == false) EXIT_WITH_ERROR("Could not initial state file: %s\n", initialStateFilePath.c_str()); if (jaffarCommon::file::loadStringFromFile(stateFileData, initialStateFilePath) == false) JAFFAR_THROW_LOGIC("Could not initial state file: %s\n", initialStateFilePath.c_str());
jaffarCommon::deserializer::Contiguous d(stateFileData.data()); jaffarCommon::deserializer::Contiguous d(stateFileData.data());
e.deserializeState(d); e.deserializeState(d);
} }
@ -153,14 +153,14 @@ int main(int argc, char *argv[])
const auto fullDifferentialStateSize = fixedDiferentialStateSize + differentialCompressionMaxDifferences; const auto fullDifferentialStateSize = fixedDiferentialStateSize + differentialCompressionMaxDifferences;
// Checking with the expected SHA1 hash // Checking with the expected SHA1 hash
if (romSHA1 != expectedROMSHA1) EXIT_WITH_ERROR("Wrong ROM SHA1. Found: '%s', Expected: '%s'\n", romSHA1.c_str(), expectedROMSHA1.c_str()); if (romSHA1 != expectedROMSHA1) JAFFAR_THROW_LOGIC("Wrong ROM SHA1. Found: '%s', Expected: '%s'\n", romSHA1.c_str(), expectedROMSHA1.c_str());
// Loading sequence file // Loading sequence file
std::string sequenceRaw; std::string sequenceRaw;
if (jaffarCommon::loadStringFromFile(sequenceRaw, sequenceFilePath) == false) EXIT_WITH_ERROR("[ERROR] Could not find or read from input sequence file: %s\n", sequenceFilePath.c_str()); if (jaffarCommon::file::loadStringFromFile(sequenceRaw, sequenceFilePath) == false) JAFFAR_THROW_LOGIC("[ERROR] Could not find or read from input sequence file: %s\n", sequenceFilePath.c_str());
// Building sequence information // Building sequence information
const auto sequence = jaffarCommon::split(sequenceRaw, ' '); const auto sequence = jaffarCommon::string::split(sequenceRaw, ' ');
// Getting sequence lenght // Getting sequence lenght
const auto sequenceLength = sequence.size(); const auto sequenceLength = sequence.size();
@ -262,7 +262,7 @@ int main(int argc, char *argv[])
double elapsedTimeSeconds = (double)dt * 1.0e-9; double elapsedTimeSeconds = (double)dt * 1.0e-9;
// Calculating final state hash // Calculating final state hash
auto result = jaffarCommon::calculateMetroHash(e.getLowMem(), e.getLowMemSize()); auto result = jaffarCommon::hash::calculateMetroHash(e.getLowMem(), e.getLowMemSize());
// Creating hash string // Creating hash string
char hashStringBuffer[256]; char hashStringBuffer[256];
@ -277,7 +277,7 @@ int main(int argc, char *argv[])
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 saving hash, do it now
if (hashOutputFile != "") jaffarCommon::saveStringToFile(std::string(hashStringBuffer), hashOutputFile.c_str()); if (hashOutputFile != "") jaffarCommon::file::saveStringToFile(std::string(hashStringBuffer), hashOutputFile.c_str());
// If reached this point, everything ran ok // If reached this point, everything ran ok
return 0; return 0;