mirror of
https://github.com/jscrane/r65emu.git
synced 2025-01-13 07:30:28 +00:00
update for latest SD
This commit is contained in:
parent
7fb04ebf17
commit
69f30e81a8
@ -1,4 +1,3 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
|
|
||||||
@ -23,8 +22,6 @@ static File file;
|
|||||||
static Dir dir;
|
static Dir dir;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define STORAGE defined(USE_SD) || defined(USE_SPIFFS) || defined(USE_FS)
|
|
||||||
|
|
||||||
bool flash_filer::start()
|
bool flash_filer::start()
|
||||||
{
|
{
|
||||||
#if defined(USE_FS)
|
#if defined(USE_FS)
|
||||||
@ -41,7 +38,7 @@ bool flash_filer::start()
|
|||||||
|
|
||||||
void flash_filer::stop()
|
void flash_filer::stop()
|
||||||
{
|
{
|
||||||
#if STORAGE
|
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(USE_FS)
|
||||||
file.close();
|
file.close();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -50,7 +47,7 @@ bool flash_filer::more()
|
|||||||
{
|
{
|
||||||
if (_pos >= _len) {
|
if (_pos >= _len) {
|
||||||
_pos = 0;
|
_pos = 0;
|
||||||
#if STORAGE
|
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(USE_FS)
|
||||||
_len = file.read(_buf, sizeof(_buf));
|
_len = file.read(_buf, sizeof(_buf));
|
||||||
#endif
|
#endif
|
||||||
if (_len == 0) // eof
|
if (_len == 0) // eof
|
||||||
@ -60,7 +57,7 @@ bool flash_filer::more()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *flash_filer::advance() {
|
const char *flash_filer::advance() {
|
||||||
#if STORAGE
|
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(USE_FS)
|
||||||
bool rewound = false;
|
bool rewound = false;
|
||||||
file.close();
|
file.close();
|
||||||
#if defined(USE_FS)
|
#if defined(USE_FS)
|
||||||
@ -108,17 +105,11 @@ static char chkpt[] = { "CHKPOINT" };
|
|||||||
static int cpid = 0;
|
static int cpid = 0;
|
||||||
|
|
||||||
const char *flash_filer::checkpoint() {
|
const char *flash_filer::checkpoint() {
|
||||||
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266)
|
#if defined(DISK)
|
||||||
stop();
|
stop();
|
||||||
snprintf(buf, sizeof(buf), "%s%s.%03d", _programs, chkpt, cpid++);
|
snprintf(buf, sizeof(buf), "%s%s.%03d", _programs, chkpt, cpid++);
|
||||||
|
|
||||||
#if defined(USE_SD)
|
File file = DISK.open(buf, FILE_WRITE);
|
||||||
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);
|
hardware_checkpoint(file);
|
||||||
file.close();
|
file.close();
|
||||||
start();
|
start();
|
||||||
@ -127,17 +118,11 @@ const char *flash_filer::checkpoint() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void flash_filer::restore(const char *filename) {
|
void flash_filer::restore(const char *filename) {
|
||||||
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266)
|
#if defined(DISK)
|
||||||
stop();
|
stop();
|
||||||
snprintf(buf, sizeof(buf), "%s%s", _programs, filename);
|
snprintf(buf, sizeof(buf), "%s%s", _programs, filename);
|
||||||
|
|
||||||
#if defined(USE_SD)
|
File file = DISK.open(buf, FILE_READ);
|
||||||
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);
|
hardware_restore(file);
|
||||||
file.close();
|
file.close();
|
||||||
int n = sscanf(buf + strlen(_programs), "%[A-Z0-9].%d", chkpt, &cpid);
|
int n = sscanf(buf + strlen(_programs), "%[A-Z0-9].%d", chkpt, &cpid);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user