mirror of
https://github.com/JorjBauer/aiie.git
synced 2024-06-19 16:29:33 +00:00
filemanager cache file fixes for suspend/resume
This commit is contained in:
parent
99d0c8e72c
commit
fd51162ede
|
@ -94,6 +94,7 @@ void AppleVM::Resume(const char *fn)
|
||||||
#else
|
#else
|
||||||
printf("Unable to open resume file\n");
|
printf("Unable to open resume file\n");
|
||||||
#endif
|
#endif
|
||||||
|
g_filemanager->closeFile(fh);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +102,7 @@ void AppleVM::Resume(const char *fn)
|
||||||
for (int i=0; i<strlen(suspendHdr); i++) {
|
for (int i=0; i<strlen(suspendHdr); i++) {
|
||||||
if (g_filemanager->readByte(fh) != suspendHdr[i]) {
|
if (g_filemanager->readByte(fh) != suspendHdr[i]) {
|
||||||
/* Failed to read correct header; abort */
|
/* Failed to read correct header; abort */
|
||||||
|
g_filemanager->closeFile(fh);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +112,9 @@ void AppleVM::Resume(const char *fn)
|
||||||
disk6->Deserialize(fh) &&
|
disk6->Deserialize(fh) &&
|
||||||
hd32->Deserialize(fh)
|
hd32->Deserialize(fh)
|
||||||
) {
|
) {
|
||||||
#ifndef TEENSYDUINO
|
#ifdef TEENSYDUINO
|
||||||
|
Serial.println("Deserialization successful");
|
||||||
|
#else
|
||||||
printf("All deserialized successfully\n");
|
printf("All deserialized successfully\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
|
@ -121,7 +125,6 @@ void AppleVM::Resume(const char *fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
g_filemanager->closeFile(fh);
|
g_filemanager->closeFile(fh);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fixme: make member vars
|
// fixme: make member vars
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
SdFatSdio sd;
|
SdFatSdio sd;
|
||||||
File file;
|
File file;
|
||||||
|
|
||||||
uint8_t rawFd;
|
int8_t rawFd;
|
||||||
File rawFile;
|
File rawFile;
|
||||||
|
|
||||||
TeensyFileManager::TeensyFileManager()
|
TeensyFileManager::TeensyFileManager()
|
||||||
|
@ -270,14 +270,16 @@ bool TeensyFileManager::_prepCache(int8_t fd)
|
||||||
// Not our cached file, or we have no cached file
|
// Not our cached file, or we have no cached file
|
||||||
if (rawFd != -1) {
|
if (rawFd != -1) {
|
||||||
// Close the old one if we had one
|
// Close the old one if we had one
|
||||||
Serial.println("closing old cache file");
|
Serial.print("closing old cache file ");
|
||||||
|
Serial.println(rawFd);
|
||||||
rawFile.close();
|
rawFile.close();
|
||||||
rawFd = -1;
|
rawFd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("opening new cache file");
|
Serial.println("opening new cache file");
|
||||||
// Open the new one
|
// Open the new one
|
||||||
if (!sd.open(cachedNames[fd], O_RDWR | O_CREAT)) {
|
rawFile = sd.open(cachedNames[fd], O_RDWR | O_CREAT);
|
||||||
|
if (!rawFile) {
|
||||||
Serial.print("_prepCache: failed to open ");
|
Serial.print("_prepCache: failed to open ");
|
||||||
Serial.println(cachedNames[fd]);
|
Serial.println(cachedNames[fd]);
|
||||||
return false;
|
return false;
|
||||||
|
@ -304,8 +306,10 @@ uint8_t TeensyFileManager::readByteAt(int8_t fd, uint32_t pos)
|
||||||
_prepCache(fd);
|
_prepCache(fd);
|
||||||
|
|
||||||
if (!rawFile.seek(pos)) {
|
if (!rawFile.seek(pos)) {
|
||||||
Serial.println("readByteAt: seek failed");
|
Serial.print("readByteAt: seek failed to pos ");
|
||||||
return false;
|
Serial.println(pos);
|
||||||
|
Serial.println("Trying to continue anyway");
|
||||||
|
// return false;
|
||||||
}
|
}
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
return (rawFile.read(&b, 1) == 1);
|
return (rawFile.read(&b, 1) == 1);
|
||||||
|
@ -342,12 +346,14 @@ uint8_t TeensyFileManager::readByte(int8_t fd)
|
||||||
uint32_t pos = fileSeekPositions[fd];
|
uint32_t pos = fileSeekPositions[fd];
|
||||||
|
|
||||||
if (!rawFile.seek(pos)) {
|
if (!rawFile.seek(pos)) {
|
||||||
Serial.println("readByteAt: seek failed");
|
Serial.print("readByte: seek failed to byte ");
|
||||||
|
Serial.println(pos);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
rawFile.read(&b, 1);
|
rawFile.read(&b, 1);
|
||||||
|
fileSeekPositions[fd]++;
|
||||||
|
|
||||||
// FIXME: check v == 1 & handle error
|
// FIXME: check v == 1 & handle error
|
||||||
return b;
|
return b;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user