1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-07-14 20:29:02 +00:00

cleanup disk

This commit is contained in:
Stephen Crane 2018-11-10 09:32:33 +00:00
parent 971f34f1b3
commit 67540df29f
7 changed files with 34 additions and 12 deletions

View File

@ -1,9 +1,11 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "hardware.h"
#include "sdtape.h"
#include "checkpoint.h"
#if defined(SD_CS)
#if defined(USE_SD)
#include <SD.h>
#elif defined(USE_SPIFFS)
#include <SPIFFS.h>
@ -17,13 +19,15 @@ const char *checkpoint(sdtape &tape, const char *dir) {
tape.stop();
snprintf(buf, sizeof(buf), "%s%s.%03d", dir, chkpt, cpid++);
#if defined(SD_CS)
#if defined(USE_SD) || defined(USE_SPIFFS)
#if defined(USE_SD)
File file = SD.open(buf, O_WRITE | O_CREAT | O_TRUNC);
#elif defined(USE_SPIFFS)
#else
File file = SPIFFS.open(buf, FILE_WRITE);
#endif
hardware_checkpoint(file);
file.close();
#endif
tape.start(dir);
return buf;
}
@ -32,13 +36,15 @@ void restore(sdtape &tape, const char *dir, const char *filename) {
tape.stop();
snprintf(buf, sizeof(buf), "%s%s", dir, filename);
#if defined(SD_CS)
#if defined(USE_SD) || defined(USE_SPIFFS)
#if defined(USE_SD)
File file = SD.open(buf, O_READ);
#elif defined(USE_SPIFFS)
#else
File file = SPIFFS.open(buf, FILE_READ);
#endif
hardware_restore(file);
file.close();
#endif
int n = sscanf(buf + strlen(dir), "%[A-Z0-9].%d", chkpt, &cpid);
cpid = (n == 1)? 0: cpid+1;
tape.start(dir);

View File

@ -2,7 +2,7 @@
#include <SPI.h>
#if defined(SD_CS)
#if defined(USE_SD)
#include <SD.h>
#endif
@ -36,7 +36,7 @@ bool hardware_reset() {
SPIRAM_DEV.setDataMode(SPI_MODE0);
#endif
#if defined(SD_CS)
#if defined(USE_SD)
success = SD.begin(SD_CS, 2, SD_SPI);
pinMode(SPI_CS, OUTPUT); // without this, the SPI-RAM isn't seen
#endif
@ -62,7 +62,7 @@ void hardware_init(CPU &cpu) {
pinMode(TFT_BACKLIGHT, OUTPUT);
#endif
#if defined(SD_CS)
#if defined(USE_SD)
pinMode(SD_CS, OUTPUT);
digitalWrite(SD_CS, HIGH);
#endif

View File

@ -19,7 +19,7 @@
#undef SPIRAM_CS
// "tape" storage...
#undef SD_CS
#undef USE_SD
#define USE_SPIFFS
// sound: dac and pwm

View File

@ -15,7 +15,7 @@
#undef SPIRAM_CS
// "tape" storage...
#undef SD_CS
#undef USE_SD
#define USE_SPIFFS
// sound: dac and pwm

View File

@ -19,7 +19,7 @@
#undef SPIRAM_CS
// "tape" storage...
#undef SD_CS
#undef USE_SD
#undef USE_SPIFFS
// sound

View File

@ -19,6 +19,7 @@
#define SPIRAM_SIZE 65536
// "tape" storage...
#define USE_SD
#define SD_CS PF_3
#define SD_SPI 1

View File

@ -1,6 +1,7 @@
#include <stdint.h>
#include "hardware.h"
#if defined(SD_CS)
#if defined(USE_SD)
#include <SD.h>
#define DISK SD
#elif defined(USE_SPIFFS)
@ -10,13 +11,17 @@
#include "sdtape.h"
#if defined(DISK)
static File file, dir;
#endif
bool sdtape::start(const char *programs)
{
#if defined(DISK)
dir = DISK.open(programs);
if (!dir)
return false;
#endif
_pos = _len = 0;
return true;
@ -24,11 +29,14 @@ bool sdtape::start(const char *programs)
void sdtape::stop()
{
#if defined(DISK)
file.close();
#endif
}
bool sdtape::more()
{
#if defined(DISK)
if (_pos >= _len) {
_pos = 0;
_len = file.read(_buf, sizeof(_buf));
@ -36,10 +44,12 @@ bool sdtape::more()
if (_len == 0) // eof
return false;
}
#endif
return true;
}
const char *sdtape::advance() {
#if defined(DISK)
bool rewound = false;
file.close();
while (true) {
@ -56,9 +66,14 @@ const char *sdtape::advance() {
return 0;
}
return file.name();
#else
return 0;
#endif
}
const char *sdtape::rewind() {
#if defined(DISK)
dir.rewindDirectory();
#endif
return advance();
}