mirror of
https://github.com/jscrane/r65emu.git
synced 2024-05-29 03:41:36 +00:00
checkpointing utilities
This commit is contained in:
parent
4ff9f685f1
commit
b7a9efe914
29
checkpoint.cpp
Normal file
29
checkpoint.cpp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include <SD.h>
|
||||||
|
#include "sdtape.h"
|
||||||
|
#include "checkpoint.h"
|
||||||
|
#include "hardware.h"
|
||||||
|
|
||||||
|
static char buf[32];
|
||||||
|
static char chkpt[] = { "CHKPOINT" };
|
||||||
|
static int cpid = 0;
|
||||||
|
|
||||||
|
const char *checkpoint(sdtape &tape, const char *dir) {
|
||||||
|
tape.stop();
|
||||||
|
snprintf(buf, sizeof(buf), "%s%s.%03d", dir, chkpt, cpid++);
|
||||||
|
File file = SD.open(buf, O_WRITE | O_CREAT | O_TRUNC);
|
||||||
|
hardware_checkpoint(file);
|
||||||
|
file.close();
|
||||||
|
tape.start(dir);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void restore(sdtape &tape, const char *dir, const char *filename) {
|
||||||
|
tape.stop();
|
||||||
|
snprintf(buf, sizeof(buf), "%s%s", dir, filename);
|
||||||
|
File file = SD.open(buf, O_READ);
|
||||||
|
hardware_restore(file);
|
||||||
|
file.close();
|
||||||
|
int n = sscanf(buf + strlen(dir), "%[A-Z0-9].%d", chkpt, &cpid);
|
||||||
|
cpid = (n == 1)? 0: cpid+1;
|
||||||
|
tape.start(dir);
|
||||||
|
}
|
8
checkpoint.h
Normal file
8
checkpoint.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef __CHECKPOINT_H__
|
||||||
|
#define __CHECKPOINT_H__
|
||||||
|
|
||||||
|
// utility checkpoint functions
|
||||||
|
const char *checkpoint(sdtape &tape, const char *dir);
|
||||||
|
void restore(sdtape &tape, const char *dir, const char *filename);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user