mirror of
https://github.com/jscrane/r65emu.git
synced 2024-10-31 13:05:08 +00:00
53 lines
741 B
C++
53 lines
741 B
C++
|
#include <SD.h>
|
||
|
#include "sdtape.h"
|
||
|
|
||
|
static File file, dir;
|
||
|
|
||
|
void sdtape::start(const char *programs)
|
||
|
{
|
||
|
dir = SD.open(programs);
|
||
|
}
|
||
|
|
||
|
void sdtape::stop()
|
||
|
{
|
||
|
file.close();
|
||
|
}
|
||
|
|
||
|
bool sdtape::more()
|
||
|
{
|
||
|
if (_pos >= _len) {
|
||
|
_pos = 0;
|
||
|
_len = file.read(_buf, sizeof(_buf));
|
||
|
|
||
|
if (_len == 0) {
|
||
|
file.close();
|
||
|
return false; // eof
|
||
|
}
|
||
|
}
|
||
|
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();
|
||
|
}
|