1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-12-21 12:29:51 +00:00
r65emu/sdtape.cpp
2018-09-06 14:21:17 +01:00

65 lines
912 B
C++

#include "hardware.h"
#if defined(SD_CS)
#include <SD.h>
#define DISK SD
#elif defined(USE_SPIFFS)
#include <SPIFFS.h>
#define DISK SPIFFS
#endif
#include "sdtape.h"
static File file, dir;
bool sdtape::start(const char *programs)
{
dir = DISK.open(programs);
if (!dir)
return false;
_pos = _len = 0;
return true;
}
void sdtape::stop()
{
file.close();
}
bool sdtape::more()
{
if (_pos >= _len) {
_pos = 0;
_len = file.read(_buf, sizeof(_buf));
if (_len == 0) // eof
return false;
}
return true;
}
const char *sdtape::advance() {
bool rewound = false;
file.close();
while (true) {
file = dir.openNextFile();
if (file) {
if (file.isDirectory())
file.close();
else
break;
} else if (!rewound) {
dir.rewindDirectory();
rewound = true;
} else
return 0;
}
return file.name();
}
const char *sdtape::rewind() {
dir.rewindDirectory();
return advance();
}