diff --git a/checkpoint.cpp b/checkpoint.cpp deleted file mode 100644 index b67132e..0000000 --- a/checkpoint.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include -#include "hardware.h" -#include "serialio.h" -#include "filer.h" -#include "checkpoint.h" - -#if defined(USE_SD) -#include -#elif defined(USE_SPIFFS) -#include -#elif defined(ESP8266) -#include -#endif - -static char buf[32]; -static char chkpt[] = { "CHKPOINT" }; -static int cpid = 0; - -const char *checkpoint(filer &f, const char *dir) { -#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266) - f.stop(); - snprintf(buf, sizeof(buf), "%s%s.%03d", dir, chkpt, cpid++); - -#if defined(USE_SD) - File file = SD.open(buf, O_WRITE | O_CREAT | O_TRUNC); -#elif defined(USE_SPIFFS) - File file = SPIFFS.open(buf, FILE_WRITE); -#else - File file = SPIFFS.open(buf, "w"); -#endif - hardware_checkpoint(file); - file.close(); - f.start(dir); -#endif - return buf; -} - -void restore(filer &f, const char *dir, const char *filename) { -#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266) - f.stop(); - snprintf(buf, sizeof(buf), "%s%s", dir, filename); - -#if defined(USE_SD) - File file = SD.open(buf, O_READ); -#elif defined(USE_SPIFFS) - File file = SPIFFS.open(buf, FILE_READ); -#else - File file = SPIFFS.open(buf, "r"); -#endif - hardware_restore(file); - file.close(); - int n = sscanf(buf + strlen(dir), "%[A-Z0-9].%d", chkpt, &cpid); - cpid = (n == 1)? 0: cpid+1; -#endif - f.start(dir); -} diff --git a/checkpoint.h b/checkpoint.h deleted file mode 100644 index 2e95576..0000000 --- a/checkpoint.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __CHECKPOINT_H__ -#define __CHECKPOINT_H__ - -// utility checkpoint functions -const char *checkpoint(filer &f, const char *dir); -void restore(filer &f, const char *dir, const char *filename); - -#endif diff --git a/filer.cpp b/filer.cpp index 1edae58..18716e8 100644 --- a/filer.cpp +++ b/filer.cpp @@ -1,3 +1,4 @@ +#include #include #include "hardware.h" @@ -19,15 +20,16 @@ static File file, dir; #elif defined(USE_FS) static File file; static Dir dir; -static const char *programs; #endif +static const char *programs; + #define STORAGE defined(USE_SD) || defined(USE_SPIFFS) || defined(USE_FS) bool flash_filer::start(const char *programs) { -#if defined(USE_FS) ::programs = programs; +#if defined(USE_FS) dir = SPIFFS.openDir(programs); #elif defined(DISK) dir = DISK.open(programs); @@ -101,3 +103,46 @@ const char *flash_filer::rewind() { #endif return advance(); } + +static char buf[32]; +static char chkpt[] = { "CHKPOINT" }; +static int cpid = 0; + +const char *flash_filer::checkpoint() { +#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266) + stop(); + snprintf(buf, sizeof(buf), "%s%s.%03d", ::programs, chkpt, cpid++); + +#if defined(USE_SD) + File file = SD.open(buf, O_WRITE | O_CREAT | O_TRUNC); +#elif defined(USE_SPIFFS) + File file = SPIFFS.open(buf, FILE_WRITE); +#else + File file = SPIFFS.open(buf, "w"); +#endif + hardware_checkpoint(file); + file.close(); + start(::programs); +#endif + return buf; +} + +void flash_filer::restore(const char *filename) { +#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266) + stop(); + snprintf(buf, sizeof(buf), "%s%s", ::programs, filename); + +#if defined(USE_SD) + File file = SD.open(buf, O_READ); +#elif defined(USE_SPIFFS) + File file = SPIFFS.open(buf, FILE_READ); +#else + File file = SPIFFS.open(buf, "r"); +#endif + hardware_restore(file); + file.close(); + int n = sscanf(buf + strlen(::programs), "%[A-Z0-9].%d", chkpt, &cpid); + cpid = (n == 1)? 0: cpid+1; +#endif + start(::programs); +} diff --git a/filer.h b/filer.h index 491e180..a300efa 100644 --- a/filer.h +++ b/filer.h @@ -6,6 +6,9 @@ public: virtual const char *advance() =0; virtual const char *rewind() =0; + virtual const char *checkpoint() =0; + virtual void restore(const char *) = 0; + virtual bool start(const char *) =0; virtual void stop() =0; }; @@ -17,6 +20,9 @@ public: const char *advance(); const char *rewind(); + const char *checkpoint(); + void restore(const char *); + bool start(const char *); void stop(); diff --git a/r65emu.h b/r65emu.h index 2ab8013..0113082 100644 --- a/r65emu.h +++ b/r65emu.h @@ -13,7 +13,6 @@ #include "filer.h" #include "timed.h" #include "hardware.h" -#include "checkpoint.h" #include "sound_dac.h" #include "sound_pwm.h"