2018-08-14 05:28:03 +00:00
|
|
|
#include "hardware.h"
|
|
|
|
|
|
|
|
#if defined(SD_CS)
|
2014-10-26 17:54:01 +00:00
|
|
|
#include <SD.h>
|
2018-08-14 05:28:03 +00:00
|
|
|
#define DISK SD
|
|
|
|
#elif defined(USE_SPIFFS)
|
|
|
|
#include <SPIFFS.h>
|
|
|
|
#define DISK SPIFFS
|
|
|
|
#endif
|
|
|
|
|
2014-10-26 17:54:01 +00:00
|
|
|
#include "sdtape.h"
|
|
|
|
|
|
|
|
static File file, dir;
|
|
|
|
|
|
|
|
void sdtape::start(const char *programs)
|
|
|
|
{
|
2018-08-14 05:28:03 +00:00
|
|
|
dir = DISK.open(programs);
|
2014-11-15 23:24:47 +00:00
|
|
|
_pos = _len = 0;
|
2014-10-26 17:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sdtape::stop()
|
|
|
|
{
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool sdtape::more()
|
|
|
|
{
|
|
|
|
if (_pos >= _len) {
|
|
|
|
_pos = 0;
|
|
|
|
_len = file.read(_buf, sizeof(_buf));
|
|
|
|
|
2014-11-02 17:34:19 +00:00
|
|
|
if (_len == 0) // eof
|
|
|
|
return false;
|
2014-10-26 17:54:01 +00:00
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|