mirror of
https://github.com/jscrane/r65emu.git
synced 2024-06-08 07:29:37 +00:00
esp8266 disk storage
This commit is contained in:
parent
8836367767
commit
bbfc553e29
|
@ -9,6 +9,8 @@
|
||||||
#include <SD.h>
|
#include <SD.h>
|
||||||
#elif defined(USE_SPIFFS)
|
#elif defined(USE_SPIFFS)
|
||||||
#include <SPIFFS.h>
|
#include <SPIFFS.h>
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
#include <FS.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char buf[32];
|
static char buf[32];
|
||||||
|
@ -19,11 +21,13 @@ const char *checkpoint(sdtape &tape, const char *dir) {
|
||||||
tape.stop();
|
tape.stop();
|
||||||
snprintf(buf, sizeof(buf), "%s%s.%03d", dir, chkpt, cpid++);
|
snprintf(buf, sizeof(buf), "%s%s.%03d", dir, chkpt, cpid++);
|
||||||
|
|
||||||
#if defined(USE_SD) || defined(USE_SPIFFS)
|
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266)
|
||||||
#if defined(USE_SD)
|
#if defined(USE_SD)
|
||||||
File file = SD.open(buf, O_WRITE | O_CREAT | O_TRUNC);
|
File file = SD.open(buf, O_WRITE | O_CREAT | O_TRUNC);
|
||||||
#else
|
#elif defined(USE_SPIFFS)
|
||||||
File file = SPIFFS.open(buf, FILE_WRITE);
|
File file = SPIFFS.open(buf, FILE_WRITE);
|
||||||
|
#else
|
||||||
|
File file = SPIFFS.open(buf, "w");
|
||||||
#endif
|
#endif
|
||||||
hardware_checkpoint(file);
|
hardware_checkpoint(file);
|
||||||
file.close();
|
file.close();
|
||||||
|
@ -36,11 +40,13 @@ void restore(sdtape &tape, const char *dir, const char *filename) {
|
||||||
tape.stop();
|
tape.stop();
|
||||||
snprintf(buf, sizeof(buf), "%s%s", dir, filename);
|
snprintf(buf, sizeof(buf), "%s%s", dir, filename);
|
||||||
|
|
||||||
#if defined(USE_SD) || defined(USE_SPIFFS)
|
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266)
|
||||||
#if defined(USE_SD)
|
#if defined(USE_SD)
|
||||||
File file = SD.open(buf, O_READ);
|
File file = SD.open(buf, O_READ);
|
||||||
#else
|
#elif defined(USE_SPIFFS)
|
||||||
File file = SPIFFS.open(buf, FILE_READ);
|
File file = SPIFFS.open(buf, FILE_READ);
|
||||||
|
#else
|
||||||
|
File file = SPIFFS.open(buf, "r");
|
||||||
#endif
|
#endif
|
||||||
hardware_restore(file);
|
hardware_restore(file);
|
||||||
file.close();
|
file.close();
|
||||||
|
|
31
sdtape.cpp
31
sdtape.cpp
|
@ -7,17 +7,25 @@
|
||||||
#elif defined(USE_SPIFFS)
|
#elif defined(USE_SPIFFS)
|
||||||
#include <SPIFFS.h>
|
#include <SPIFFS.h>
|
||||||
#define DISK SPIFFS
|
#define DISK SPIFFS
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
#include <FS.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "sdtape.h"
|
#include "sdtape.h"
|
||||||
|
|
||||||
#if defined(DISK)
|
#if defined(DISK)
|
||||||
static File file, dir;
|
static File file, dir;
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
static File file;
|
||||||
|
static Dir dir;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool sdtape::start(const char *programs)
|
bool sdtape::start(const char *programs)
|
||||||
{
|
{
|
||||||
#if defined(DISK)
|
#if defined(ESP8266)
|
||||||
|
SPIFFS.begin();
|
||||||
|
dir = SPIFFS.openDir("/");
|
||||||
|
#else if defined(DISK)
|
||||||
dir = DISK.open(programs);
|
dir = DISK.open(programs);
|
||||||
if (!dir)
|
if (!dir)
|
||||||
return false;
|
return false;
|
||||||
|
@ -29,14 +37,14 @@ bool sdtape::start(const char *programs)
|
||||||
|
|
||||||
void sdtape::stop()
|
void sdtape::stop()
|
||||||
{
|
{
|
||||||
#if defined(DISK)
|
#if defined(DISK) || defined(ESP8266)
|
||||||
file.close();
|
file.close();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sdtape::more()
|
bool sdtape::more()
|
||||||
{
|
{
|
||||||
#if defined(DISK)
|
#if defined(DISK) || defined(ESP8266)
|
||||||
if (_pos >= _len) {
|
if (_pos >= _len) {
|
||||||
_pos = 0;
|
_pos = 0;
|
||||||
_len = file.read(_buf, sizeof(_buf));
|
_len = file.read(_buf, sizeof(_buf));
|
||||||
|
@ -49,9 +57,21 @@ bool sdtape::more()
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *sdtape::advance() {
|
const char *sdtape::advance() {
|
||||||
#if defined(DISK)
|
#if defined(DISK) || defined(ESP8266)
|
||||||
bool rewound = false;
|
bool rewound = false;
|
||||||
file.close();
|
file.close();
|
||||||
|
#if defined(ESP8266)
|
||||||
|
static char buf[32];
|
||||||
|
while (true) {
|
||||||
|
if (dir.next()) {
|
||||||
|
file = dir.openFile("r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dir = SPIFFS.openDir("/");
|
||||||
|
}
|
||||||
|
strncpy(buf, dir.fileName().c_str(), sizeof(buf));
|
||||||
|
return buf;
|
||||||
|
#else
|
||||||
while (true) {
|
while (true) {
|
||||||
file = dir.openNextFile();
|
file = dir.openNextFile();
|
||||||
if (file) {
|
if (file) {
|
||||||
|
@ -66,13 +86,14 @@ const char *sdtape::advance() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return file.name();
|
return file.name();
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *sdtape::rewind() {
|
const char *sdtape::rewind() {
|
||||||
#if defined(DISK)
|
#if defined(DISK) && !defined(ESP8266)
|
||||||
dir.rewindDirectory();
|
dir.rewindDirectory();
|
||||||
#endif
|
#endif
|
||||||
return advance();
|
return advance();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user