Add ability to Save/Load Snapshot F11/F12.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2020-12-06 18:03:41 +00:00
parent 74cb18a7a1
commit 1d07215f78
9 changed files with 47 additions and 13 deletions

View file

@ -34,6 +34,7 @@ bool getEmulatorOptions(int argc, const char * argv [], const std::string & edit
po::options_description snapshotDesc("Snapshot");
snapshotDesc.add_options()
("state-filename,f", po::value<std::string>(), "Set snapshot filename")
("load-state,s", po::value<std::string>(), "Load snapshot from file");
desc.add(snapshotDesc);
@ -87,7 +88,14 @@ bool getEmulatorOptions(int argc, const char * argv [], const std::string & edit
if (vm.count("load-state"))
{
options.snapshot = vm["load-state"].as<std::string>();
options.snapshotFilename = vm["load-state"].as<std::string>();
options.loadSnapshot = true;
}
if (vm.count("state-filename"))
{
options.snapshotFilename = vm["state-filename"].as<std::string>();
options.loadSnapshot = false;
}
const int memclear = vm["memclear"].as<int>();

View file

@ -9,7 +9,8 @@ struct EmulatorOptions
std::string disk1;
std::string disk2;
std::string snapshot;
std::string snapshotFilename;
bool loadSnapshot = false;
int memclear = 0;

View file

@ -6,9 +6,14 @@
Speed::Speed(const bool fixedSpeed)
: myFixedSpeed(fixedSpeed)
, myStartTime(std::chrono::steady_clock::now())
, myStartCycles(g_nCumulativeCycles)
{
reset();
}
void Speed::reset()
{
myStartTime = std::chrono::steady_clock::now();
myStartCycles = g_nCumulativeCycles;
}
size_t Speed::getCyclesTillNext(const size_t milliseconds) const

View file

@ -7,6 +7,8 @@ class Speed
public:
Speed(const bool fixedSpeed);
void reset();
// calculate the number of cycles to execute in the current period
// assuming the next call will happen in x milliseconds
size_t getCyclesTillNext(const size_t milliseconds) const;

View file

@ -6,7 +6,7 @@
#include <libgen.h>
#include <unistd.h>
void setSnapshotFilename(const std::string & filename)
void setSnapshotFilename(const std::string & filename, const bool load)
{
// same logic as qapple
// setting chdir allows to load relative disks from the snapshot file (tests?)
@ -23,6 +23,10 @@ void setSnapshotFilename(const std::string & filename)
free(temp);
free(absPath);
Snapshot_LoadState();
if (load)
{
Snapshot_LoadState();
}
}
}

View file

@ -2,4 +2,4 @@
#include <string>
void setSnapshotFilename(const std::string & filename);
void setSnapshotFilename(const std::string & filename, const bool load);

View file

@ -189,9 +189,9 @@ namespace
cardManager.GetDisk2CardMgr().Reset();
HD_Reset();
if (!options.snapshot.empty())
if (!options.snapshotFilename.empty())
{
setSnapshotFilename(options.snapshot);
setSnapshotFilename(options.snapshotFilename, options.loadSnapshot);
}
if (options.benchmark)

View file

@ -20,6 +20,9 @@
#include "Mockingboard.h"
#include "Speaker.h"
#include "Utilities.h"
#include "SaveState.h"
// #define KEY_LOGGING_VERBOSE
namespace
{
@ -221,6 +224,17 @@ void Emulator::processKeyDown(const SDL_KeyboardEvent & key, bool & quit)
{
switch (key.keysym.sym)
{
case SDLK_F12:
{
Snapshot_SaveState();
break;
}
case SDLK_F11:
{
Snapshot_LoadState();
mySpeed.reset();
break;
}
case SDLK_F9:
{
cycleVideoType(myWindow);
@ -287,7 +301,7 @@ void Emulator::processKeyDown(const SDL_KeyboardEvent & key, bool & quit)
processAppleKey(key);
#if LOGGING_VERBOSE
#ifdef KEY_LOGGING_VERBOSE
std::cerr << "KEY DOWN: " << key.keysym.scancode << "," << key.keysym.sym << "," << key.keysym.mod << "," << bool(key.repeat) << std::endl;
#endif
@ -309,7 +323,7 @@ void Emulator::processKeyUp(const SDL_KeyboardEvent & key)
}
}
#if LOGGING_VERBOSE
#ifdef KEY_LOGGING_VERBOSE
std::cerr << "KEY UP: " << key.keysym.scancode << "," << key.keysym.sym << "," << key.keysym.mod << "," << bool(key.repeat) << std::endl;
#endif

View file

@ -128,9 +128,9 @@ namespace
LogFileOutput("Init: DoDiskInsert(D2), res=%d\n", ok);
}
if (!options.snapshot.empty())
if (!options.snapshotFilename.empty())
{
setSnapshotFilename(options.snapshot);
setSnapshotFilename(options.snapshotFilename, options.loadSnapshot);
}
Paddle::setSquaring(options.squaring);