Updating jaffarCommon subproect
This commit is contained in:
parent
9f42942268
commit
8bdfd4fa2a
|
@ -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 : '.'
|
||||
)
|
|
@ -1 +1 @@
|
|||
Subproject commit 101ad3ff4f548da7f0550877f27027d8141e2d8a
|
||||
Subproject commit 91a8e6cbd0ca08b2859cfe47521765191c246f16
|
38
meson.build
38
meson.build
|
@ -1,7 +1,8 @@
|
|||
project('quickerNES','c','cpp',
|
||||
version: '1.0.0',
|
||||
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
|
||||
|
@ -10,23 +11,18 @@ subdir('source')
|
|||
# Common application flags
|
||||
commonCompileArgs = [ '-Wfatal-errors', '-Wall']
|
||||
|
||||
# Common includes
|
||||
commonIncludes = include_directories(['extern'])
|
||||
# Grabbing jaffarCommon dependency
|
||||
|
||||
# Common sources
|
||||
commonSources = [
|
||||
'extern/jaffarCommon/extern/metrohash128/metrohash128.cpp',
|
||||
'extern/jaffarCommon/extern/xdelta3/xdelta3.c',
|
||||
]
|
||||
jaffarCommonSubproject = subproject('jaffarCommon')
|
||||
jaffarCommonDependency = jaffarCommonSubproject.get_variable('jaffarCommonDependency')
|
||||
|
||||
# Grabbing hqn dependency
|
||||
|
||||
hqnSubproject = subproject('hqn')
|
||||
hqnDependency = hqnSubproject.get_variable('hqnDependency')
|
||||
|
||||
# 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
|
||||
if meson.is_subproject() == false
|
||||
|
||||
|
@ -34,10 +30,8 @@ if meson.is_subproject() == false
|
|||
executable('player',
|
||||
'source/player.cpp',
|
||||
cpp_args : [ commonCompileArgs, '-DNCURSES' ],
|
||||
dependencies : [ quickerNESDependency, toolDependency, dependency('sdl2'), dependency('SDL2_image') ],
|
||||
link_args : [ '-lncurses' ],
|
||||
sources : [ commonSources, quickerNESPlayerSrc ],
|
||||
include_directories : [ commonIncludes ]
|
||||
dependencies : [ jaffarCommonDependency, quickerNESDependency, toolDependency, dependency('sdl2'), dependency('SDL2_image'), hqnDependency ],
|
||||
link_args : [ '-lncurses' ]
|
||||
)
|
||||
endif
|
||||
|
||||
|
@ -46,9 +40,7 @@ if meson.is_subproject() == false
|
|||
quickerNESTester = executable('quickerNESTester',
|
||||
'source/tester.cpp',
|
||||
cpp_args : [ commonCompileArgs, '-Werror' ],
|
||||
dependencies : [ quickerNESDependency, toolDependency ],
|
||||
sources : [ commonSources ],
|
||||
include_directories : [ commonIncludes ]
|
||||
dependencies : [ jaffarCommonDependency, quickerNESDependency, toolDependency ]
|
||||
)
|
||||
|
||||
# Building tester tool for the original QuickNES
|
||||
|
@ -57,9 +49,7 @@ if meson.is_subproject() == false
|
|||
quickNESTester = executable('quickNESTester',
|
||||
'source/tester.cpp',
|
||||
cpp_args : [ commonCompileArgs, '-w', '-DDISABLE_AUTO_FILE', '-D__LIBRETRO__', '-DNDEBUG', '-DBLARGG_NONPORTABLE' ],
|
||||
dependencies : [ quickNESDependency, toolDependency ],
|
||||
sources : [ commonSources ],
|
||||
include_directories : [ commonIncludes ]
|
||||
dependencies : [ jaffarCommonDependency, quickNESDependency, toolDependency ]
|
||||
)
|
||||
endif
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "jaffarCommon/include/serializers/contiguous.hpp"
|
||||
#include "jaffarCommon/include/serializers/differential.hpp"
|
||||
#include "jaffarCommon/include/logger.hpp"
|
||||
#include "jaffarCommon/serializers/contiguous.hpp"
|
||||
#include "jaffarCommon/serializers/differential.hpp"
|
||||
#include "jaffarCommon/logger.hpp"
|
||||
#include "controller.hpp"
|
||||
|
||||
// Size of image generated in graphics buffer
|
||||
|
@ -19,10 +19,10 @@ class NESInstanceBase
|
|||
inline void advanceState(const std::string &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
|
||||
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
|
||||
if (_controller.getResetButtonState() == true) doSoftReset();
|
||||
|
@ -43,7 +43,7 @@ class NESInstanceBase
|
|||
if (type == "FourScore1") { _controller.setController1Type(Controller::controller_t::fourscore1); isTypeRecognized = true; }
|
||||
if (type == "FourScore2") { _controller.setController1Type(Controller::controller_t::fourscore2); isTypeRecognized = true; }
|
||||
|
||||
if (isTypeRecognized == false) EXIT_WITH_ERROR("Input type not recognized: '%s'\n", type.c_str());
|
||||
if (isTypeRecognized == false) JAFFAR_THROW_LOGIC("Input type not recognized: '%s'\n", type.c_str());
|
||||
}
|
||||
|
||||
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 == "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; };
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
#include <unistd.h>
|
||||
#include <SDL.h>
|
||||
#include <SDL_image.h>
|
||||
#include <hqn/hqn.h>
|
||||
#include <hqn/hqn_gui_controller.h>
|
||||
#include <jaffarCommon/include/serializers/contiguous.hpp>
|
||||
#include <jaffarCommon/include/deserializers/contiguous.hpp>
|
||||
#include <jaffarCommon/include/hash.hpp>
|
||||
#include <extern/hqn/hqn.h>
|
||||
#include <extern/hqn/hqn_gui_controller.h>
|
||||
#include <jaffarCommon/serializers/contiguous.hpp>
|
||||
#include <jaffarCommon/deserializers/contiguous.hpp>
|
||||
#include <jaffarCommon/hash.hpp>
|
||||
#include "nesInstance.hpp"
|
||||
|
||||
#define _INVERSE_FRAME_RATE 16667
|
||||
|
@ -17,7 +17,7 @@ struct stepData_t
|
|||
{
|
||||
std::string input;
|
||||
uint8_t *stateData;
|
||||
jaffarCommon::hash_t hash;
|
||||
jaffarCommon::hash::hash_t hash;
|
||||
};
|
||||
|
||||
class PlaybackInstance
|
||||
|
@ -34,7 +34,7 @@ class PlaybackInstance
|
|||
|
||||
jaffarCommon::serializer::Contiguous serializer(step.stateData);
|
||||
_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
|
||||
_stepSequence.push_back(step);
|
||||
|
@ -81,39 +81,39 @@ class PlaybackInstance
|
|||
|
||||
imagePath = _overlayPath + std::string("/base.png");
|
||||
_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");
|
||||
_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");
|
||||
_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");
|
||||
_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");
|
||||
_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");
|
||||
_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");
|
||||
_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");
|
||||
_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");
|
||||
_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
|
||||
|
@ -122,7 +122,7 @@ class PlaybackInstance
|
|||
// We can only call SDL_InitSubSystem once
|
||||
if (!SDL_WasInit(SDL_INIT_VIDEO))
|
||||
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
|
||||
_hqnGUI = hqn::GUIController::create(_hqnState);
|
||||
|
@ -133,7 +133,7 @@ class PlaybackInstance
|
|||
void renderFrame(const size_t stepId)
|
||||
{
|
||||
// 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
|
||||
const auto &step = _stepSequence[stepId];
|
||||
|
@ -189,7 +189,7 @@ class PlaybackInstance
|
|||
const std::string getInput(const size_t stepId) const
|
||||
{
|
||||
// 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
|
||||
const auto &step = _stepSequence[stepId];
|
||||
|
@ -201,7 +201,7 @@ class PlaybackInstance
|
|||
const uint8_t *getStateData(const size_t stepId) const
|
||||
{
|
||||
// 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
|
||||
const auto &step = _stepSequence[stepId];
|
||||
|
@ -210,10 +210,10 @@ class PlaybackInstance
|
|||
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
|
||||
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
|
||||
const auto &step = _stepSequence[stepId];
|
||||
|
@ -225,7 +225,7 @@ class PlaybackInstance
|
|||
const std::string getStateInput(const size_t stepId) const
|
||||
{
|
||||
// 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
|
||||
const auto &step = _stepSequence[stepId];
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include <cstdlib>
|
||||
#include "jaffarCommon/extern/argparse/argparse.hpp"
|
||||
#include "jaffarCommon/include/serializers/contiguous.hpp"
|
||||
#include "jaffarCommon/include/deserializers/contiguous.hpp"
|
||||
#include "jaffarCommon/include/file.hpp"
|
||||
#include "jaffarCommon/include/logger.hpp"
|
||||
#include "jaffarCommon/include/string.hpp"
|
||||
#include "argparse/argparse.hpp"
|
||||
#include "jaffarCommon/serializers/contiguous.hpp"
|
||||
#include "jaffarCommon/deserializers/contiguous.hpp"
|
||||
#include "jaffarCommon/file.hpp"
|
||||
#include "jaffarCommon/logger.hpp"
|
||||
#include "jaffarCommon/string.hpp"
|
||||
#include "nesInstance.hpp"
|
||||
#include "playbackInstance.hpp"
|
||||
|
||||
|
@ -50,7 +50,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
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
|
||||
|
@ -76,14 +76,14 @@ int main(int argc, char *argv[])
|
|||
|
||||
// Loading sequence file
|
||||
std::string inputSequence;
|
||||
auto status = jaffarCommon::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());
|
||||
auto status = jaffarCommon::file::loadStringFromFile(inputSequence, 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
|
||||
const auto sequence = jaffarCommon::split(inputSequence, ' ');
|
||||
const auto sequence = jaffarCommon::string::split(inputSequence, ' ');
|
||||
|
||||
// Initializing terminal
|
||||
jaffarCommon::initializeTerminal();
|
||||
jaffarCommon::logger::initializeTerminal();
|
||||
|
||||
// Printing provided parameters
|
||||
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("[] Generating Sequence...\n");
|
||||
|
||||
jaffarCommon::refreshTerminal();
|
||||
jaffarCommon::logger::refreshTerminal();
|
||||
|
||||
// Creating emulator instance
|
||||
NESInstance e;
|
||||
|
@ -103,14 +103,14 @@ int main(int argc, char *argv[])
|
|||
|
||||
// Loading ROM File
|
||||
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());
|
||||
|
||||
// If an initial state is provided, load it now
|
||||
if (stateFilePath != "")
|
||||
{
|
||||
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());
|
||||
e.deserializeState(deserializer);
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ int main(int argc, char *argv[])
|
|||
// Printing data and commands
|
||||
if (showFrameInfo)
|
||||
{
|
||||
jaffarCommon::clearTerminal();
|
||||
jaffarCommon::logger::clearTerminal();
|
||||
|
||||
printw("[] ----------------------------------------------------------------\n");
|
||||
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
|
||||
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
|
||||
showFrameInfo = true;
|
||||
|
||||
// Get command
|
||||
auto command = jaffarCommon::waitForKeyPress();
|
||||
auto command = jaffarCommon::logger::waitForKeyPress();
|
||||
|
||||
// Advance/Rewind commands
|
||||
if (command == 'n') currentStep = currentStep - 1;
|
||||
|
@ -191,7 +191,7 @@ int main(int argc, char *argv[])
|
|||
std::string saveData;
|
||||
saveData.resize(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());
|
||||
|
||||
// Do no show frame info again after this action
|
||||
|
@ -206,5 +206,5 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
// Ending ncurses window
|
||||
jaffarCommon::finalizeTerminal();
|
||||
jaffarCommon::logger::finalizeTerminal();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "jaffarCommon/include/serializers/base.hpp"
|
||||
#include "jaffarCommon/include/deserializers/base.hpp"
|
||||
#include "jaffarCommon/serializers/base.hpp"
|
||||
#include "jaffarCommon/deserializers/base.hpp"
|
||||
#include "core/nes_emu/Nes_Emu.h"
|
||||
#include "core/nes_emu/Nes_State.h"
|
||||
#include "../nesInstanceBase.hpp"
|
||||
|
|
|
@ -22,8 +22,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|||
#include "ppu/ppu.hpp"
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <jaffarCommon/include/serializers/base.hpp>
|
||||
#include <jaffarCommon/include/deserializers/base.hpp>
|
||||
#include <jaffarCommon/serializers/base.hpp>
|
||||
#include <jaffarCommon/deserializers/base.hpp>
|
||||
|
||||
namespace quickerNES
|
||||
{
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#include <jaffarCommon/extern/argparse/argparse.hpp>
|
||||
#include <jaffarCommon/include/json.hpp>
|
||||
#include <jaffarCommon/include/serializers/contiguous.hpp>
|
||||
#include <jaffarCommon/include/serializers/differential.hpp>
|
||||
#include <jaffarCommon/include/deserializers/contiguous.hpp>
|
||||
#include <jaffarCommon/include/deserializers/differential.hpp>
|
||||
#include <jaffarCommon/include/hash.hpp>
|
||||
#include <jaffarCommon/include/string.hpp>
|
||||
#include <jaffarCommon/include/file.hpp>
|
||||
#include <argparse/argparse.hpp>
|
||||
#include <jaffarCommon/json.hpp>
|
||||
#include <jaffarCommon/serializers/contiguous.hpp>
|
||||
#include <jaffarCommon/serializers/differential.hpp>
|
||||
#include <jaffarCommon/deserializers/contiguous.hpp>
|
||||
#include <jaffarCommon/deserializers/differential.hpp>
|
||||
#include <jaffarCommon/hash.hpp>
|
||||
#include <jaffarCommon/string.hpp>
|
||||
#include <jaffarCommon/file.hpp>
|
||||
#include "nesInstance.hpp"
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
|
@ -37,7 +37,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
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
|
||||
|
@ -51,68 +51,68 @@ int main(int argc, char *argv[])
|
|||
|
||||
// Loading script file
|
||||
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
|
||||
const auto scriptJson = nlohmann::json::parse(scriptJsonRaw);
|
||||
|
||||
// Getting rom file path
|
||||
if (scriptJson.contains("Rom File") == false) EXIT_WITH_ERROR("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.contains("Rom File") == false) JAFFAR_THROW_LOGIC("Script file missing 'Rom File' entry\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>();
|
||||
|
||||
// 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["Initial State File"].is_string() == false) EXIT_WITH_ERROR("Script file 'Initial State File' entry is not a string\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) JAFFAR_THROW_LOGIC("Script file 'Initial State File' entry is not a string\n");
|
||||
std::string initialStateFilePath = scriptJson["Initial State File"].get<std::string>();
|
||||
|
||||
// Getting sequence file path
|
||||
if (scriptJson.contains("Sequence File") == false) EXIT_WITH_ERROR("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.contains("Sequence File") == false) JAFFAR_THROW_LOGIC("Script file missing 'Sequence File' entry\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>();
|
||||
|
||||
// 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["Expected ROM SHA1"].is_string() == false) EXIT_WITH_ERROR("Script file 'Expected ROM SHA1' entry is not a string\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) JAFFAR_THROW_LOGIC("Script file 'Expected ROM SHA1' entry is not a string\n");
|
||||
std::string expectedROMSHA1 = scriptJson["Expected ROM SHA1"].get<std::string>();
|
||||
|
||||
// Parsing disabled blocks in lite state serialization
|
||||
std::vector<std::string> stateDisabledBlocks;
|
||||
std::string stateDisabledBlocksOutput;
|
||||
if (scriptJson.contains("Disable State Blocks") == false) EXIT_WITH_ERROR("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.contains("Disable State Blocks") == false) JAFFAR_THROW_LOGIC("Script file missing 'Disable State Blocks' entry\n");
|
||||
if (scriptJson["Disable State Blocks"].is_array() == false) JAFFAR_THROW_LOGIC("Script file 'Disable State Blocks' is not an array\n");
|
||||
for (const auto& entry : scriptJson["Disable State Blocks"])
|
||||
{
|
||||
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>());
|
||||
stateDisabledBlocksOutput += entry.get<std::string>() + std::string(" ");
|
||||
}
|
||||
|
||||
// Getting Controller 1 type
|
||||
if (scriptJson.contains("Controller 1 Type") == false) EXIT_WITH_ERROR("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.contains("Controller 1 Type") == false) JAFFAR_THROW_LOGIC("Script file missing 'Controller 1 Type' entry\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>();
|
||||
|
||||
// Getting Controller 2 type
|
||||
if (scriptJson.contains("Controller 2 Type") == false) EXIT_WITH_ERROR("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.contains("Controller 2 Type") == false) JAFFAR_THROW_LOGIC("Script file missing 'Controller 2 Type' entry\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>();
|
||||
|
||||
// Getting differential compression configuration
|
||||
if (scriptJson.contains("Differential Compression") == false) EXIT_WITH_ERROR("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.contains("Differential Compression") == false) JAFFAR_THROW_LOGIC("Script file missing 'Differential Compression' entry\n");
|
||||
if (scriptJson["Differential Compression"].is_object() == false) JAFFAR_THROW_LOGIC("Script file 'Differential Compression' entry is not a key/value object\n");
|
||||
const auto& differentialCompressionJs = scriptJson["Differential Compression"];
|
||||
|
||||
if (differentialCompressionJs.contains("Enabled") == false) EXIT_WITH_ERROR("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.contains("Enabled") == false) JAFFAR_THROW_LOGIC("Script file missing 'Differential Compression / Enabled' entry\n");
|
||||
if (differentialCompressionJs["Enabled"].is_boolean() == false) JAFFAR_THROW_LOGIC("Script file 'Differential Compression / Enabled' entry is not a boolean\n");
|
||||
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["Max Differences"].is_number() == false) EXIT_WITH_ERROR("Script file 'Differential Compression / Max Differences' entry is not a number\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) JAFFAR_THROW_LOGIC("Script file 'Differential Compression / Max Differences' entry is not a number\n");
|
||||
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["Use Zlib"].is_boolean() == false) EXIT_WITH_ERROR("Script file 'Differential Compression / Use Zlib' entry is not a boolean\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) JAFFAR_THROW_LOGIC("Script file 'Differential Compression / Use Zlib' entry is not a boolean\n");
|
||||
const auto differentialCompressionUseZlib = differentialCompressionJs["Use Zlib"].get<bool>();
|
||||
|
||||
// Creating emulator instance
|
||||
|
@ -124,17 +124,17 @@ int main(int argc, char *argv[])
|
|||
|
||||
// Loading ROM File
|
||||
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());
|
||||
|
||||
// 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 (initialStateFilePath != "")
|
||||
{
|
||||
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());
|
||||
e.deserializeState(d);
|
||||
}
|
||||
|
@ -153,14 +153,14 @@ int main(int argc, char *argv[])
|
|||
const auto fullDifferentialStateSize = fixedDiferentialStateSize + differentialCompressionMaxDifferences;
|
||||
|
||||
// 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
|
||||
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
|
||||
const auto sequence = jaffarCommon::split(sequenceRaw, ' ');
|
||||
const auto sequence = jaffarCommon::string::split(sequenceRaw, ' ');
|
||||
|
||||
// Getting sequence lenght
|
||||
const auto sequenceLength = sequence.size();
|
||||
|
@ -262,7 +262,7 @@ int main(int argc, char *argv[])
|
|||
double elapsedTimeSeconds = (double)dt * 1.0e-9;
|
||||
|
||||
// Calculating final state hash
|
||||
auto result = jaffarCommon::calculateMetroHash(e.getLowMem(), e.getLowMemSize());
|
||||
auto result = jaffarCommon::hash::calculateMetroHash(e.getLowMem(), e.getLowMemSize());
|
||||
|
||||
// Creating hash string
|
||||
char hashStringBuffer[256];
|
||||
|
@ -277,7 +277,7 @@ int main(int argc, char *argv[])
|
|||
printf("[] Differential State Max Size Detected: %lu\n", differentialStateMaxSizeDetected);
|
||||
}
|
||||
// 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
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue