mirror of https://github.com/JorjBauer/aiie.git
remove legacy filemanager methods
This commit is contained in:
parent
8591df2745
commit
ff58f43e02
|
@ -20,60 +20,50 @@ LRingBuffer::~LRingBuffer()
|
||||||
|
|
||||||
bool LRingBuffer::Serialize(int8_t fd)
|
bool LRingBuffer::Serialize(int8_t fd)
|
||||||
{
|
{
|
||||||
g_filemanager->writeByte(fd, RINGBUFFERMAGIC);
|
uint8_t buf[9] = { RINGBUFFERMAGIC,
|
||||||
|
(max >> 8) & 0xFF,
|
||||||
|
(max ) & 0xFF,
|
||||||
|
(ptr >> 8) & 0xFF,
|
||||||
|
(ptr ) & 0xFF,
|
||||||
|
(fill >> 8) & 0xFF,
|
||||||
|
(fill ) & 0xFF,
|
||||||
|
(cursor >> 8) & 0xFF,
|
||||||
|
(cursor ) & 0xFF };
|
||||||
|
if (g_filemanager->write(fd, buf, 9) != 9)
|
||||||
|
return false;
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, (max >> 8) & 0xFF);
|
if (g_filemanager->write(fd, buffer, max) != max)
|
||||||
g_filemanager->writeByte(fd, (max ) & 0xFF);
|
return false;
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, (ptr >> 8) & 0xFF);
|
if (g_filemanager->write(fd, buf, 1) != 1)
|
||||||
g_filemanager->writeByte(fd, (ptr ) & 0xFF);
|
return false;
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, (fill >> 8) & 0xFF);
|
|
||||||
g_filemanager->writeByte(fd, (fill ) & 0xFF);
|
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, (cursor >> 8) & 0xFF);
|
|
||||||
g_filemanager->writeByte(fd, (cursor ) & 0xFF);
|
|
||||||
|
|
||||||
for (uint16_t i=0; i<max; i++) {
|
|
||||||
g_filemanager->writeByte(fd, buffer[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, RINGBUFFERMAGIC);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LRingBuffer::Deserialize(int8_t fd)
|
bool LRingBuffer::Deserialize(int8_t fd)
|
||||||
{
|
{
|
||||||
if (g_filemanager->readByte(fd) != RINGBUFFERMAGIC)
|
uint8_t buf[9];
|
||||||
|
if (g_filemanager->read(fd, buf, 9) != 9)
|
||||||
|
return false;
|
||||||
|
if (buf[0] != RINGBUFFERMAGIC)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
max = g_filemanager->readByte(fd);
|
max = (buf[1] << 8) | buf[2];
|
||||||
max <<= 8;
|
ptr = (buf[3] << 8) | buf[4];
|
||||||
max |= g_filemanager->readByte(fd);
|
fill = (buf[5] << 8) | buf[6];
|
||||||
|
cursor = (buf[7] << 8) | buf[8];
|
||||||
ptr = g_filemanager->readByte(fd);
|
|
||||||
ptr <<= 8;
|
|
||||||
ptr |= g_filemanager->readByte(fd);
|
|
||||||
|
|
||||||
fill = g_filemanager->readByte(fd);
|
|
||||||
fill <<= 8;
|
|
||||||
fill |= g_filemanager->readByte(fd);
|
|
||||||
|
|
||||||
cursor = g_filemanager->readByte(fd);
|
|
||||||
cursor <<= 8;
|
|
||||||
cursor |= g_filemanager->readByte(fd);
|
|
||||||
|
|
||||||
if (buffer)
|
if (buffer)
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
buffer = (uint8_t *)malloc(max);
|
buffer = (uint8_t *)malloc(max);
|
||||||
|
|
||||||
for (uint16_t i=0; i<max; i++) {
|
|
||||||
buffer[i] = g_filemanager->readByte(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_filemanager->readByte(fd) != RINGBUFFERMAGIC)
|
if (g_filemanager->read(fd, buffer, max) != max)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (g_filemanager->read(fd, buf, 1) != 1 ||
|
||||||
|
buf[0] != RINGBUFFERMAGIC)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -162,22 +162,22 @@ AppleMMU::~AppleMMU()
|
||||||
|
|
||||||
bool AppleMMU::Serialize(int8_t fd)
|
bool AppleMMU::Serialize(int8_t fd)
|
||||||
{
|
{
|
||||||
g_filemanager->writeByte(fd, MMUMAGIC);
|
uint8_t buf[13] = { MMUMAGIC,
|
||||||
|
(switches >> 8) & 0xFF,
|
||||||
g_filemanager->writeByte(fd, (switches >> 8) & 0xFF);
|
(switches ) & 0xFF,
|
||||||
g_filemanager->writeByte(fd, (switches ) & 0xFF);
|
auxRamRead ? 1 : 0,
|
||||||
|
auxRamWrite ? 1 : 0,
|
||||||
g_filemanager->writeByte(fd, auxRamRead ? 1 : 0);
|
bank2 ? 1 : 0,
|
||||||
g_filemanager->writeByte(fd, auxRamWrite ? 1 : 0);
|
readbsr ? 1 : 0,
|
||||||
g_filemanager->writeByte(fd, bank2 ? 1 : 0);
|
writebsr ? 1 : 0,
|
||||||
g_filemanager->writeByte(fd, readbsr ? 1 : 0);
|
altzp ? 1 : 0,
|
||||||
g_filemanager->writeByte(fd, writebsr ? 1 : 0);
|
intcxrom ? 1 : 0,
|
||||||
g_filemanager->writeByte(fd, altzp ? 1 : 0);
|
slot3rom ? 1 : 0,
|
||||||
g_filemanager->writeByte(fd, intcxrom ? 1 : 0);
|
slotLatch,
|
||||||
g_filemanager->writeByte(fd, slot3rom ? 1 : 0);
|
preWriteFlag ? 1 : 0 };
|
||||||
g_filemanager->writeByte(fd, slotLatch);
|
if (g_filemanager->write(fd, buf, 13) != 13)
|
||||||
g_filemanager->writeByte(fd, preWriteFlag ? 1 : 0);
|
return false;
|
||||||
|
|
||||||
if (!g_ram.Serialize(fd))
|
if (!g_ram.Serialize(fd))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -187,36 +187,41 @@ bool AppleMMU::Serialize(int8_t fd)
|
||||||
// Not suspending/resuming slots b/c they're a fixed configuration
|
// Not suspending/resuming slots b/c they're a fixed configuration
|
||||||
// in this project. Should probably checksum them though. FIXME.
|
// in this project. Should probably checksum them though. FIXME.
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, MMUMAGIC);
|
if (g_filemanager->write(fd, buf, 1) != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppleMMU::Deserialize(int8_t fd)
|
bool AppleMMU::Deserialize(int8_t fd)
|
||||||
{
|
{
|
||||||
if (g_filemanager->readByte(fd) != MMUMAGIC) {
|
uint8_t buf[13];
|
||||||
|
|
||||||
|
if (g_filemanager->read(fd, buf, 13) != 13)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
switches = g_filemanager->readByte(fd);
|
if (buf[0] != MMUMAGIC)
|
||||||
switches <<= 8;
|
return false;
|
||||||
switches |= g_filemanager->readByte(fd);
|
|
||||||
|
|
||||||
auxRamRead = g_filemanager->readByte(fd);
|
|
||||||
auxRamWrite = g_filemanager->readByte(fd);
|
|
||||||
bank2 = g_filemanager->readByte(fd);
|
|
||||||
readbsr = g_filemanager->readByte(fd);
|
|
||||||
writebsr = g_filemanager->readByte(fd);
|
|
||||||
altzp = g_filemanager->readByte(fd);
|
|
||||||
intcxrom = g_filemanager->readByte(fd);
|
|
||||||
slot3rom = g_filemanager->readByte(fd);
|
|
||||||
slotLatch = g_filemanager->readByte(fd);
|
|
||||||
preWriteFlag = g_filemanager->readByte(fd);
|
|
||||||
|
|
||||||
|
switches = (buf[1] << 8) | buf[2];
|
||||||
|
auxRamRead = buf[3];
|
||||||
|
auxRamWrite = buf[4];
|
||||||
|
bank2 = buf[5];
|
||||||
|
readbsr = buf[6];
|
||||||
|
writebsr = buf[7];
|
||||||
|
altzp = buf[8];
|
||||||
|
intcxrom = buf[9];
|
||||||
|
slot3rom = buf[10];
|
||||||
|
slotLatch = buf[11];
|
||||||
|
preWriteFlag = buf[12];
|
||||||
|
|
||||||
if (!g_ram.Deserialize(fd)) {
|
if (!g_ram.Deserialize(fd)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_filemanager->readByte(fd) != MMUMAGIC)
|
if (g_filemanager->read(fd, buf, 1) != 1)
|
||||||
|
return false;
|
||||||
|
if (buf[0] != MMUMAGIC)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Reset readPages[] and writePages[] and the display
|
// Reset readPages[] and writePages[] and the display
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
const char *suspendHdr = "Sus1";
|
const char *suspendHdr = "Sus2";
|
||||||
|
|
||||||
AppleVM::AppleVM()
|
AppleVM::AppleVM()
|
||||||
{
|
{
|
||||||
|
@ -48,19 +48,18 @@ void AppleVM::Suspend(const char *fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Header */
|
/* Header */
|
||||||
for (int i=0; i<strlen(suspendHdr); i++) {
|
if (g_filemanager->write(fh, suspendHdr, strlen(suspendHdr)) != strlen(suspendHdr))
|
||||||
g_filemanager->writeByte(fh, suspendHdr[i]);
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/* Tell all of the peripherals to suspend */
|
/* Tell all of the peripherals to suspend */
|
||||||
if (g_cpu->Serialize(fh) &&
|
if (g_cpu->Serialize(fh) &&
|
||||||
disk6->Serialize(fh) &&
|
disk6->Serialize(fh) &&
|
||||||
hd32->Serialize(fh)
|
hd32->Serialize(fh)
|
||||||
) {
|
) {
|
||||||
#ifndef TEENSYDUINO
|
#ifdef TEENSYDUINO
|
||||||
printf("All serialized successfully\n");
|
|
||||||
#else
|
|
||||||
Serial.println("All serialized successfully");
|
Serial.println("All serialized successfully");
|
||||||
|
#else
|
||||||
|
printf("All serialized successfully\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +85,10 @@ void AppleVM::Resume(const char *fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Header */
|
/* Header */
|
||||||
|
uint8_t c;
|
||||||
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->read(fh, &c, 1) != 1 ||
|
||||||
|
c != suspendHdr[i]) {
|
||||||
/* Failed to read correct header; abort */
|
/* Failed to read correct header; abort */
|
||||||
g_filemanager->closeFile(fh);
|
g_filemanager->closeFile(fh);
|
||||||
return;
|
return;
|
||||||
|
|
209
apple/diskii.cpp
209
apple/diskii.cpp
|
@ -53,144 +53,144 @@ DiskII::~DiskII()
|
||||||
|
|
||||||
bool DiskII::Serialize(int8_t fd)
|
bool DiskII::Serialize(int8_t fd)
|
||||||
{
|
{
|
||||||
g_filemanager->writeByte(fd, DISKIIMAGIC);
|
uint8_t buf[23] = { DISKIIMAGIC,
|
||||||
|
readWriteLatch,
|
||||||
g_filemanager->writeByte(fd, readWriteLatch);
|
sequencer,
|
||||||
g_filemanager->writeByte(fd, sequencer);
|
dataRegister,
|
||||||
g_filemanager->writeByte(fd, dataRegister);
|
writeMode,
|
||||||
g_filemanager->writeByte(fd, writeMode);
|
writeProt,
|
||||||
g_filemanager->writeByte(fd, writeProt);
|
selectedDisk };
|
||||||
g_filemanager->writeByte(fd, selectedDisk);
|
|
||||||
|
if (g_filemanager->write(fd, buf, 7) != 7) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i=0; i<2; i++) {
|
for (int i=0; i<2; i++) {
|
||||||
g_filemanager->writeByte(fd, curHalfTrack[i]);
|
uint8_t ptr = 0;
|
||||||
g_filemanager->writeByte(fd, curWozTrack[i]);
|
buf[ptr++] = curHalfTrack[i];
|
||||||
g_filemanager->writeByte(fd, curPhase[i]);
|
buf[ptr++] = curWozTrack[i];
|
||||||
|
buf[ptr++] = curPhase[i];
|
||||||
g_filemanager->writeByte(fd,
|
buf[ptr++] = ((driveSpinupCycles[i] >> 56) & 0xFF);
|
||||||
((driveSpinupCycles[i] >> 56) & 0xFF));
|
buf[ptr++] = ((driveSpinupCycles[i] >> 48) & 0xFF);
|
||||||
g_filemanager->writeByte(fd,
|
buf[ptr++] = ((driveSpinupCycles[i] >> 40) & 0xFF);
|
||||||
((driveSpinupCycles[i] >> 48) & 0xFF));
|
buf[ptr++] = ((driveSpinupCycles[i] >> 32) & 0xFF);
|
||||||
g_filemanager->writeByte(fd,
|
buf[ptr++] = ((driveSpinupCycles[i] >> 24) & 0xFF);
|
||||||
((driveSpinupCycles[i] >> 40) & 0xFF));
|
buf[ptr++] = ((driveSpinupCycles[i] >> 16) & 0xFF);
|
||||||
g_filemanager->writeByte(fd,
|
buf[ptr++] = ((driveSpinupCycles[i] >> 8) & 0xFF);
|
||||||
((driveSpinupCycles[i] >> 32) & 0xFF));
|
buf[ptr++] = ((driveSpinupCycles[i] ) & 0xFF);
|
||||||
g_filemanager->writeByte(fd,
|
buf[ptr++] = ((deliveredDiskBits[i] >> 56) & 0xFF);
|
||||||
((driveSpinupCycles[i] >> 24) & 0xFF));
|
buf[ptr++] = ((deliveredDiskBits[i] >> 48) & 0xFF);
|
||||||
g_filemanager->writeByte(fd,
|
buf[ptr++] = ((deliveredDiskBits[i] >> 40) & 0xFF);
|
||||||
((driveSpinupCycles[i] >> 16) & 0xFF));
|
buf[ptr++] = ((deliveredDiskBits[i] >> 32) & 0xFF);
|
||||||
g_filemanager->writeByte(fd,
|
buf[ptr++] = ((deliveredDiskBits[i] >> 24) & 0xFF);
|
||||||
((driveSpinupCycles[i] >> 8) & 0xFF));
|
buf[ptr++] = ((deliveredDiskBits[i] >> 16) & 0xFF);
|
||||||
g_filemanager->writeByte(fd,
|
buf[ptr++] = ((deliveredDiskBits[i] >> 8) & 0xFF);
|
||||||
((driveSpinupCycles[i] ) & 0xFF));
|
buf[ptr++] = ((deliveredDiskBits[i] ) & 0xFF);
|
||||||
|
buf[ptr++] = (diskIsSpinningUntil[i] >> 24) & 0xFF;
|
||||||
g_filemanager->writeByte(fd,
|
buf[ptr++] = (diskIsSpinningUntil[i] >> 16) & 0xFF;
|
||||||
((deliveredDiskBits[i] >> 56) & 0xFF));
|
buf[ptr++] = (diskIsSpinningUntil[i] >> 8) & 0xFF;
|
||||||
g_filemanager->writeByte(fd,
|
buf[ptr++] = (diskIsSpinningUntil[i] ) & 0xFF;
|
||||||
((deliveredDiskBits[i] >> 48) & 0xFF));
|
// Safety check: keeping the hard-coded 23 and comparing against ptr.
|
||||||
g_filemanager->writeByte(fd,
|
// If we change the 23, also need to change the size of buf[] above
|
||||||
((deliveredDiskBits[i] >> 40) & 0xFF));
|
if (g_filemanager->write(fd, buf, 23) != ptr) {
|
||||||
g_filemanager->writeByte(fd,
|
return false;
|
||||||
((deliveredDiskBits[i] >> 32) & 0xFF));
|
}
|
||||||
g_filemanager->writeByte(fd,
|
|
||||||
((deliveredDiskBits[i] >> 24) & 0xFF));
|
|
||||||
g_filemanager->writeByte(fd,
|
|
||||||
((deliveredDiskBits[i] >> 16) & 0xFF));
|
|
||||||
g_filemanager->writeByte(fd,
|
|
||||||
((deliveredDiskBits[i] >> 8) & 0xFF));
|
|
||||||
g_filemanager->writeByte(fd,
|
|
||||||
((deliveredDiskBits[i] ) & 0xFF));
|
|
||||||
|
|
||||||
g_filemanager->writeByte(fd,
|
|
||||||
(diskIsSpinningUntil[i] >> 24) & 0xFF);
|
|
||||||
g_filemanager->writeByte(fd,
|
|
||||||
(diskIsSpinningUntil[i] >> 16) & 0xFF);
|
|
||||||
g_filemanager->writeByte(fd,
|
|
||||||
(diskIsSpinningUntil[i] >> 8) & 0xFF);
|
|
||||||
g_filemanager->writeByte(fd,
|
|
||||||
(diskIsSpinningUntil[i] ) & 0xFF);
|
|
||||||
|
|
||||||
if (disk[i]) {
|
if (disk[i]) {
|
||||||
// Make sure we have flushed the disk images
|
// Make sure we have flushed the disk images
|
||||||
disk[i]->flush();
|
disk[i]->flush();
|
||||||
flushAt[i] = 0; // and there's no need to re-flush them now
|
flushAt[i] = 0; // and there's no need to re-flush them now
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, 1);
|
buf[0] = 1;
|
||||||
|
if (g_filemanager->write(fd, buf, 1) != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
// FIXME: this ONLY works for builds using the filemanager to read
|
// FIXME: this ONLY works for builds using the filemanager to read
|
||||||
// the disk image, so it's broken until we port Woz to do that!
|
// the disk image, so it's broken until we port Woz to do that!
|
||||||
const char *fn = disk[i]->diskName();
|
const char *fn = disk[i]->diskName();
|
||||||
for (int j=0; j<strlen(fn); j++) {
|
if (g_filemanager->write(fd, fn, strlen(fn)+1) != strlen(fn)+1) // include null terminator
|
||||||
g_filemanager->writeByte(fd, fn[j]);
|
return false;
|
||||||
}
|
|
||||||
g_filemanager->writeByte(fd, 0);
|
|
||||||
if (!disk[i]->Serialize(fd))
|
if (!disk[i]->Serialize(fd))
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
g_filemanager->writeByte(fd, 0);
|
buf[0] = 0;
|
||||||
|
if (g_filemanager->write(fd, buf, 0) != 1)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, DISKIIMAGIC);
|
buf[0] = DISKIIMAGIC;
|
||||||
|
if (g_filemanager->write(fd, buf, 1) != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DiskII::Deserialize(int8_t fd)
|
bool DiskII::Deserialize(int8_t fd)
|
||||||
{
|
{
|
||||||
if (g_filemanager->readByte(fd) != DISKIIMAGIC) {
|
uint8_t buf[23];
|
||||||
|
if (g_filemanager->read(fd, buf, 7) != 7)
|
||||||
return false;
|
return false;
|
||||||
}
|
if (buf[0] != DISKIIMAGIC)
|
||||||
|
return false;
|
||||||
readWriteLatch = g_filemanager->readByte(fd);
|
|
||||||
sequencer = g_filemanager->readByte(fd);
|
readWriteLatch = buf[1];
|
||||||
dataRegister = g_filemanager->readByte(fd);
|
sequencer = buf[2];
|
||||||
writeMode = g_filemanager->readByte(fd);
|
dataRegister = buf[3];
|
||||||
writeProt = g_filemanager->readByte(fd);
|
writeMode = buf[4];
|
||||||
selectedDisk = g_filemanager->readByte(fd);
|
writeProt = buf[5];
|
||||||
|
selectedDisk = buf[6];
|
||||||
|
|
||||||
for (int i=0; i<2; i++) {
|
for (int i=0; i<2; i++) {
|
||||||
curHalfTrack[i] = g_filemanager->readByte(fd);
|
uint8_t ptr = 0;
|
||||||
curWozTrack[i] = g_filemanager->readByte(fd);
|
if (g_filemanager->read(fd, buf, 23) != 23)
|
||||||
curPhase[i] = g_filemanager->readByte(fd);
|
return false;
|
||||||
|
|
||||||
driveSpinupCycles[i] = g_filemanager->readByte(fd);
|
curHalfTrack[i] = buf[ptr++];
|
||||||
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= g_filemanager->readByte(fd);
|
curWozTrack[i] = buf[ptr++];
|
||||||
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= g_filemanager->readByte(fd);
|
curPhase[i] = buf[ptr++];
|
||||||
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= g_filemanager->readByte(fd);
|
|
||||||
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= g_filemanager->readByte(fd);
|
|
||||||
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= g_filemanager->readByte(fd);
|
|
||||||
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= g_filemanager->readByte(fd);
|
|
||||||
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= g_filemanager->readByte(fd);
|
|
||||||
|
|
||||||
deliveredDiskBits[i] = g_filemanager->readByte(fd);
|
driveSpinupCycles[i] = buf[ptr++];
|
||||||
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= g_filemanager->readByte(fd);
|
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= buf[ptr++];
|
||||||
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= g_filemanager->readByte(fd);
|
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= buf[ptr++];
|
||||||
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= g_filemanager->readByte(fd);
|
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= buf[ptr++];
|
||||||
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= g_filemanager->readByte(fd);
|
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= buf[ptr++];
|
||||||
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= g_filemanager->readByte(fd);
|
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= buf[ptr++];
|
||||||
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= g_filemanager->readByte(fd);
|
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= buf[ptr++];
|
||||||
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= g_filemanager->readByte(fd);
|
driveSpinupCycles[i] <<= 8; driveSpinupCycles[i] |= buf[ptr++];
|
||||||
|
|
||||||
diskIsSpinningUntil[i] = g_filemanager->readByte(fd);
|
deliveredDiskBits[i] = buf[ptr++];
|
||||||
diskIsSpinningUntil[i] <<= 8; diskIsSpinningUntil[i] |= g_filemanager->readByte(fd);
|
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= buf[ptr++];
|
||||||
diskIsSpinningUntil[i] <<= 8; diskIsSpinningUntil[i] |= g_filemanager->readByte(fd);
|
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= buf[ptr++];
|
||||||
diskIsSpinningUntil[i] <<= 8; diskIsSpinningUntil[i] |= g_filemanager->readByte(fd);
|
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= buf[ptr++];
|
||||||
|
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= buf[ptr++];
|
||||||
|
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= buf[ptr++];
|
||||||
|
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= buf[ptr++];
|
||||||
|
deliveredDiskBits[i] <<= 8; deliveredDiskBits[i] |= buf[ptr++];
|
||||||
|
|
||||||
|
diskIsSpinningUntil[i] = buf[ptr++];
|
||||||
|
diskIsSpinningUntil[i] <<= 8; diskIsSpinningUntil[i] |= buf[ptr++];
|
||||||
|
diskIsSpinningUntil[i] <<= 8; diskIsSpinningUntil[i] |= buf[ptr++];
|
||||||
|
diskIsSpinningUntil[i] <<= 8; diskIsSpinningUntil[i] |= buf[ptr++];
|
||||||
|
|
||||||
if (disk[i])
|
if (disk[i])
|
||||||
delete disk[i];
|
delete disk[i];
|
||||||
if (g_filemanager->readByte(fd) == 1) {
|
if (g_filemanager->read(fd, buf, 1) != 1)
|
||||||
|
return false;
|
||||||
|
if (buf[0]) {
|
||||||
disk[i] = new WozSerializer();
|
disk[i] = new WozSerializer();
|
||||||
char buf[MAXPATH];
|
|
||||||
char c;
|
ptr = 0;
|
||||||
int ptr = 0;
|
while (1) {
|
||||||
while ( (c = g_filemanager->readByte(fd) != 0) ) {
|
if (g_filemanager->read(fd, &buf[ptr++], 1) != 1)
|
||||||
buf[ptr++] = c;
|
return false;
|
||||||
|
if (buf[ptr-1] == 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
buf[ptr] = 0;
|
|
||||||
if (buf[0]) {
|
if (buf[0]) {
|
||||||
// Important we don't read all the tracks, so we can also flush
|
// Important we don't read all the tracks, so we can also flush
|
||||||
// writes back to the fd...
|
// writes back to the fd...
|
||||||
disk[i]->readFile(buf, false, T_AUTO); // FIXME error checking
|
disk[i]->readFile((char *)buf, false, T_AUTO); // FIXME error checking
|
||||||
} else {
|
} else {
|
||||||
// ERROR: there's a disk but we don't have the path to its image?
|
// ERROR: there's a disk but we don't have the path to its image?
|
||||||
return false;
|
return false;
|
||||||
|
@ -203,9 +203,10 @@ bool DiskII::Deserialize(int8_t fd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_filemanager->readByte(fd) != DISKIIMAGIC) {
|
if (g_filemanager->read(fd, buf, 1) != 1)
|
||||||
|
return false;
|
||||||
|
if (buf[0] != DISKIIMAGIC)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,9 +212,9 @@ uint8_t HD32::readNextByteFromSelectedDrive()
|
||||||
// FIXME: assumes file is open & cursor is valid
|
// FIXME: assumes file is open & cursor is valid
|
||||||
|
|
||||||
uint8_t v;
|
uint8_t v;
|
||||||
|
|
||||||
v = g_filemanager->readByteAt(fd[driveSelected], cursor[driveSelected]);
|
|
||||||
// FIXME: error handling
|
// FIXME: error handling
|
||||||
|
g_filemanager->lseek(fd[driveSelected], cursor[driveSelected], SEEK_SET);
|
||||||
|
g_filemanager->read(fd[driveSelected], &v, 1);
|
||||||
|
|
||||||
cursor[driveSelected]++;
|
cursor[driveSelected]++;
|
||||||
|
|
||||||
|
@ -224,17 +224,20 @@ uint8_t HD32::readNextByteFromSelectedDrive()
|
||||||
bool HD32::writeBlockToSelectedDrive()
|
bool HD32::writeBlockToSelectedDrive()
|
||||||
{
|
{
|
||||||
// FIXME: assumes file is open & cursor is valid
|
// FIXME: assumes file is open & cursor is valid
|
||||||
// FIXME: need a better filemanager interface that holds the file open
|
|
||||||
|
// FIXME: is there a better static 512-char buf somewhere we can reuse instead of allocing new? (The teensy is low on ram.)
|
||||||
|
uint8_t buf[512];
|
||||||
|
|
||||||
for (uint16_t i=0; i<512; i++) {
|
for (uint16_t i=0; i<512; i++) {
|
||||||
uint8_t b = mmu->read(memBlock[driveSelected] + i);
|
buf[i] = mmu->read(memBlock[driveSelected] + i);
|
||||||
if (!g_filemanager->writeByteAt(fd[driveSelected], b, diskBlock[driveSelected] * 512 + i)) {
|
}
|
||||||
// FIXME
|
if (g_filemanager->lseek(fd[driveSelected], diskBlock[driveSelected]*512, SEEK_SET) == -1 ||
|
||||||
|
g_filemanager->write(fd[driveSelected], buf, 512) != 512) {
|
||||||
|
// FIXME
|
||||||
#ifndef TEENSYDUINO
|
#ifndef TEENSYDUINO
|
||||||
printf("ERROR: failed to write to hd file? errno %d\n", errno);
|
printf("ERROR: failed to write to hd file? errno %d\n", errno);
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -19,57 +19,50 @@ bool WozSerializer::Serialize(int8_t fd)
|
||||||
{
|
{
|
||||||
// If we're being asked to serialize, make sure we've flushed any data first
|
// If we're being asked to serialize, make sure we've flushed any data first
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, WOZMAGIC);
|
|
||||||
|
|
||||||
// We need the internal state about data but not much else
|
uint8_t buf[13] = { WOZMAGIC,
|
||||||
g_filemanager->writeByte(fd,
|
(trackPointer >> 24) & 0xFF,
|
||||||
(trackPointer >> 24) & 0xFF);
|
(trackPointer >> 16) & 0xFF,
|
||||||
g_filemanager->writeByte(fd,
|
(trackPointer >> 8) & 0xFF,
|
||||||
(trackPointer >> 16) & 0xFF);
|
(trackPointer ) & 0xFF,
|
||||||
g_filemanager->writeByte(fd,
|
(trackBitCounter >> 24) & 0xFF,
|
||||||
(trackPointer >> 8) & 0xFF);
|
(trackBitCounter >> 16) & 0xFF,
|
||||||
g_filemanager->writeByte(fd,
|
(trackBitCounter >> 8) & 0xFF,
|
||||||
(trackPointer ) & 0xFF);
|
(trackBitCounter ) & 0xFF,
|
||||||
|
trackByte,
|
||||||
|
trackBitIdx,
|
||||||
|
trackLoopCounter,
|
||||||
|
WOZMAGIC };
|
||||||
|
if (g_filemanager->write(fd, buf, 13) != 13)
|
||||||
|
return false;
|
||||||
|
|
||||||
g_filemanager->writeByte(fd,
|
|
||||||
(trackBitCounter >> 24) & 0xFF);
|
|
||||||
g_filemanager->writeByte(fd,
|
|
||||||
(trackBitCounter >> 16) & 0xFF);
|
|
||||||
g_filemanager->writeByte(fd,
|
|
||||||
(trackBitCounter >> 8) & 0xFF);
|
|
||||||
g_filemanager->writeByte(fd,
|
|
||||||
(trackBitCounter ) & 0xFF);
|
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, trackByte);
|
|
||||||
g_filemanager->writeByte(fd, trackBitIdx);
|
|
||||||
g_filemanager->writeByte(fd, trackLoopCounter);
|
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, WOZMAGIC);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WozSerializer::Deserialize(int8_t fd)
|
bool WozSerializer::Deserialize(int8_t fd)
|
||||||
{
|
{
|
||||||
// Before deserializing, the caller has to re-load the right disk image!
|
// Before deserializing, the caller has to re-load the right disk image!
|
||||||
if (g_filemanager->readByte(fd) != WOZMAGIC)
|
uint8_t buf[13];
|
||||||
|
if (g_filemanager->read(fd, buf, 13) != 13)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (buf[0] != WOZMAGIC)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
trackPointer = g_filemanager->readByte(fd);
|
trackPointer = buf[1];
|
||||||
trackPointer <<= 8; trackPointer |= g_filemanager->readByte(fd);
|
trackPointer <<= 8; trackPointer |= buf[2];
|
||||||
trackPointer <<= 8; trackPointer |= g_filemanager->readByte(fd);
|
trackPointer <<= 8; trackPointer |= buf[3];
|
||||||
trackPointer <<= 8; trackPointer |= g_filemanager->readByte(fd);
|
trackPointer <<= 8; trackPointer |= buf[4];
|
||||||
|
|
||||||
trackBitCounter = g_filemanager->readByte(fd);
|
trackBitCounter = buf[5];
|
||||||
trackBitCounter <<= 8; trackBitCounter |= g_filemanager->readByte(fd);
|
trackBitCounter <<= 8; trackBitCounter |= buf[6];
|
||||||
trackBitCounter <<= 8; trackBitCounter |= g_filemanager->readByte(fd);
|
trackBitCounter <<= 8; trackBitCounter |= buf[7];
|
||||||
trackBitCounter <<= 8; trackBitCounter |= g_filemanager->readByte(fd);
|
trackBitCounter <<= 8; trackBitCounter |= buf[8];
|
||||||
|
|
||||||
trackByte = g_filemanager->readByte(fd);
|
trackByte = buf[9];
|
||||||
trackBitIdx = g_filemanager->readByte(fd);
|
trackBitIdx = buf[10];
|
||||||
trackLoopCounter = g_filemanager->readByte(fd);
|
trackLoopCounter = buf[11];
|
||||||
|
if (buf[12] != WOZMAGIC)
|
||||||
if (g_filemanager->readByte(fd) != WOZMAGIC)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
71
cpu.cpp
71
cpu.cpp
|
@ -318,23 +318,22 @@ Cpu::~Cpu()
|
||||||
|
|
||||||
bool Cpu::Serialize(int8_t fh)
|
bool Cpu::Serialize(int8_t fh)
|
||||||
{
|
{
|
||||||
g_filemanager->writeByte(fh, CPUMAGIC);
|
uint8_t buf[13] = { CPUMAGIC,
|
||||||
|
(pc >> 8) & 0xFF,
|
||||||
|
(pc ) & 0xFF,
|
||||||
|
sp,
|
||||||
|
a,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
flags,
|
||||||
|
(cycles >> 24) & 0xFF,
|
||||||
|
(cycles >> 16) & 0xFF,
|
||||||
|
(cycles >> 8) & 0xFF,
|
||||||
|
(cycles ) & 0xFF,
|
||||||
|
irqPending ? 1 : 0 };
|
||||||
|
|
||||||
g_filemanager->writeByte(fh, (pc >> 8) & 0xFF);
|
if (g_filemanager->write(fh, buf, 13) != 13)
|
||||||
g_filemanager->writeByte(fh, (pc ) & 0xFF);
|
return false;
|
||||||
|
|
||||||
g_filemanager->writeByte(fh, sp);
|
|
||||||
g_filemanager->writeByte(fh, a);
|
|
||||||
g_filemanager->writeByte(fh, x);
|
|
||||||
g_filemanager->writeByte(fh, y);
|
|
||||||
g_filemanager->writeByte(fh, flags);
|
|
||||||
|
|
||||||
g_filemanager->writeByte(fh, (cycles >> 24) & 0xFF);
|
|
||||||
g_filemanager->writeByte(fh, (cycles >> 16) & 0xFF);
|
|
||||||
g_filemanager->writeByte(fh, (cycles >> 8) & 0xFF);
|
|
||||||
g_filemanager->writeByte(fh, (cycles ) & 0xFF);
|
|
||||||
|
|
||||||
g_filemanager->writeByte(fh, irqPending ? 1 : 0);
|
|
||||||
|
|
||||||
if (!mmu->Serialize(fh)) {
|
if (!mmu->Serialize(fh)) {
|
||||||
#ifndef TEENSYDUINO
|
#ifndef TEENSYDUINO
|
||||||
|
@ -345,35 +344,29 @@ bool Cpu::Serialize(int8_t fh)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_filemanager->writeByte(fh, CPUMAGIC);
|
if (g_filemanager->write(fh, buf, 1) != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true; // FIXME: no error checking on writes
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Cpu::Deserialize(int8_t fh)
|
bool Cpu::Deserialize(int8_t fh)
|
||||||
{
|
{
|
||||||
if (g_filemanager->readByte(fh) != CPUMAGIC)
|
uint8_t buf[13];
|
||||||
|
if (g_filemanager->read(fh, buf, 13) != 13)
|
||||||
return false;
|
return false;
|
||||||
|
if (buf[0] != CPUMAGIC)
|
||||||
|
return false;
|
||||||
|
pc = (buf[1] << 8) | buf[2];
|
||||||
|
sp = buf[3];
|
||||||
|
a = buf[4];
|
||||||
|
x = buf[5];
|
||||||
|
y = buf[6];
|
||||||
|
flags = buf[7];
|
||||||
|
|
||||||
pc = g_filemanager->readByte(fh);
|
cycles = (buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11];
|
||||||
pc <<= 8;
|
|
||||||
pc |= g_filemanager->readByte(fh);
|
|
||||||
|
|
||||||
sp = g_filemanager->readByte(fh);
|
irqPending = buf[12];
|
||||||
a = g_filemanager->readByte(fh);
|
|
||||||
x = g_filemanager->readByte(fh);
|
|
||||||
y = g_filemanager->readByte(fh);
|
|
||||||
flags = g_filemanager->readByte(fh);
|
|
||||||
|
|
||||||
cycles = g_filemanager->readByte(fh);
|
|
||||||
cycles <<= 8;
|
|
||||||
cycles |= g_filemanager->readByte(fh);
|
|
||||||
cycles <<= 8;
|
|
||||||
cycles |= g_filemanager->readByte(fh);
|
|
||||||
cycles <<= 8;
|
|
||||||
cycles |= g_filemanager->readByte(fh);
|
|
||||||
|
|
||||||
irqPending = g_filemanager->readByte(fh) ? true : false;
|
|
||||||
|
|
||||||
if (!mmu->Deserialize(fh)) {
|
if (!mmu->Deserialize(fh)) {
|
||||||
#ifndef TEENSYDUINO
|
#ifndef TEENSYDUINO
|
||||||
|
@ -382,7 +375,9 @@ bool Cpu::Deserialize(int8_t fh)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_filemanager->readByte(fh) != CPUMAGIC)
|
if (g_filemanager->read(fh, buf, 1) != 1)
|
||||||
|
return false;
|
||||||
|
if (buf[0] != CPUMAGIC)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#ifndef TEENSYDUINO
|
#ifndef TEENSYDUINO
|
||||||
|
|
|
@ -22,6 +22,8 @@ class FileManager {
|
||||||
public:
|
public:
|
||||||
virtual ~FileManager() {};
|
virtual ~FileManager() {};
|
||||||
|
|
||||||
|
#define writeByte(fd,x) {static uint8_t c = x; write(outfd, &c, 1);}
|
||||||
|
|
||||||
virtual bool SerializeFile(int8_t outfd, int8_t fd) {
|
virtual bool SerializeFile(int8_t outfd, int8_t fd) {
|
||||||
writeByte(outfd, FMMAGIC);
|
writeByte(outfd, FMMAGIC);
|
||||||
|
|
||||||
|
@ -61,13 +63,21 @@ class FileManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int8_t DeserializeFile(int8_t infd) {
|
virtual int8_t DeserializeFile(int8_t infd) {
|
||||||
if (readByte(infd) != FMMAGIC)
|
uint8_t b;
|
||||||
|
if (read(infd, &b, 1) != 1)
|
||||||
|
return -1;
|
||||||
|
if (b != FMMAGIC)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (readByte(infd) == 0) {
|
if (read(infd, &b, 1) != 1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (b == 0) {
|
||||||
// No file was cached. Verify footer and we're done without error
|
// No file was cached. Verify footer and we're done without error
|
||||||
|
|
||||||
if (readByte(infd) != FMMAGIC) {
|
if (read(infd, &b, 1) != 1)
|
||||||
|
return -1;
|
||||||
|
if (b != FMMAGIC) {
|
||||||
// FIXME: no way to raise this error.
|
// FIXME: no way to raise this error.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -76,25 +86,36 @@ class FileManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[MAXPATH];
|
char buf[MAXPATH];
|
||||||
int8_t l = readByte(infd);
|
if (read(infd, &b, 1) != 1)
|
||||||
for (int i=0; i<l; i++) {
|
return -1;
|
||||||
buf[i] = readByte(infd);
|
|
||||||
|
int8_t len = b;
|
||||||
|
for (int i=0; i<len; i++) {
|
||||||
|
if (read(infd, &buf[i], 1) != 1)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
buf[l] = '\0';
|
buf[len] = '\0';
|
||||||
|
|
||||||
int8_t ret = openFile(buf);
|
int8_t ret = openFile(buf);
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
fileSeekPositions[ret] = readByte(infd);
|
if (read(infd, &b, 1) != 1)
|
||||||
fileSeekPositions[ret] <<= 8;
|
return -1;
|
||||||
fileSeekPositions[ret] = readByte(infd);
|
fileSeekPositions[ret] <<= 8; fileSeekPositions[ret] |= b;
|
||||||
fileSeekPositions[ret] <<= 8;
|
if (read(infd, &b, 1) != 1)
|
||||||
fileSeekPositions[ret] = readByte(infd);
|
return -1;
|
||||||
fileSeekPositions[ret] <<= 8;
|
fileSeekPositions[ret] <<= 8; fileSeekPositions[ret] |= b;
|
||||||
fileSeekPositions[ret] = readByte(infd);
|
if (read(infd, &b, 1) != 1)
|
||||||
|
return -1;
|
||||||
if (readByte(infd) != FMMAGIC)
|
fileSeekPositions[ret] <<= 8; fileSeekPositions[ret] |= b;
|
||||||
|
if (read(infd, &b, 1) != 1)
|
||||||
|
return -1;
|
||||||
|
fileSeekPositions[ret] <<= 8; fileSeekPositions[ret] |= b;
|
||||||
|
|
||||||
|
if (read(infd, &b, 1) != 1)
|
||||||
|
return -1;
|
||||||
|
if (b != FMMAGIC)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -107,11 +128,6 @@ class FileManager {
|
||||||
|
|
||||||
virtual int8_t readDir(const char *where, const char *suffix, char *outputFN, int8_t startIdx, uint16_t maxlen) = 0;
|
virtual int8_t readDir(const char *where, const char *suffix, char *outputFN, int8_t startIdx, uint16_t maxlen) = 0;
|
||||||
|
|
||||||
virtual uint8_t readByteAt(int8_t fd, uint32_t pos) = 0;
|
|
||||||
virtual bool writeByteAt(int8_t fd, uint8_t v, uint32_t pos) = 0;
|
|
||||||
virtual uint8_t readByte(int8_t fd) = 0;
|
|
||||||
virtual bool writeByte(int8_t fd, uint8_t v) = 0;
|
|
||||||
|
|
||||||
virtual void getRootPath(char *toWhere, int8_t maxLen) = 0;
|
virtual void getRootPath(char *toWhere, int8_t maxLen) = 0;
|
||||||
|
|
||||||
virtual uint32_t getSeekPosition(int8_t fd) {
|
virtual uint32_t getSeekPosition(int8_t fd) {
|
||||||
|
@ -131,4 +147,6 @@ class FileManager {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#undef writeByte
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -153,111 +153,6 @@ int8_t NixFileManager::readDir(const char *where, const char *suffix, char *outp
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t NixFileManager::readByteAt(int8_t fd, uint32_t pos)
|
|
||||||
{
|
|
||||||
if (fd < 0 || fd >= numCached)
|
|
||||||
return -1; // FIXME: error handling?
|
|
||||||
|
|
||||||
if (cachedNames[fd][0] == 0)
|
|
||||||
return -1; // FIXME: error handling?
|
|
||||||
|
|
||||||
uint8_t v = 0;
|
|
||||||
|
|
||||||
// open, seek, read, close.
|
|
||||||
bool ret = false;
|
|
||||||
int ffd = open(cachedNames[fd], O_RDONLY);
|
|
||||||
if (ffd != -1) {
|
|
||||||
lseek(ffd, pos, SEEK_SET);
|
|
||||||
ret = (read(ffd, &v, 1) == 1);
|
|
||||||
close(ffd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ret) {
|
|
||||||
printf("ERROR reading byte at %u: %d\n", pos, errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: error handling?
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NixFileManager::writeByteAt(int8_t fd, uint8_t v, uint32_t pos)
|
|
||||||
{
|
|
||||||
if (fd < 0 || fd >= numCached)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (cachedNames[fd][0] == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// open, seek, write, close.
|
|
||||||
bool ret = false;
|
|
||||||
int ffd = open(cachedNames[fd], O_WRONLY|O_CREAT, 0644);
|
|
||||||
if (ffd != -1) {
|
|
||||||
lseek(ffd, pos, SEEK_SET);
|
|
||||||
ret = (write(ffd, &v, 1) == 1);
|
|
||||||
close(ffd);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NixFileManager::writeByte(int8_t fd, uint8_t v)
|
|
||||||
{
|
|
||||||
if (fd < 0 || fd >= numCached)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (cachedNames[fd][0] == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
uint32_t pos = fileSeekPositions[fd];
|
|
||||||
|
|
||||||
// open, seek, write, close.
|
|
||||||
bool ret = false;
|
|
||||||
int ffd = open(cachedNames[fd], O_WRONLY|O_CREAT, 0644);
|
|
||||||
if (ffd != -1) {
|
|
||||||
lseek(ffd, pos, SEEK_SET);
|
|
||||||
ret = (write(ffd, &v, 1) == 1);
|
|
||||||
if (!ret) {
|
|
||||||
printf("error writing: %d\n", errno);
|
|
||||||
}
|
|
||||||
close(ffd);
|
|
||||||
} else {
|
|
||||||
printf("Failed to open '%s' for writing: %d\n",
|
|
||||||
cachedNames[fd], errno);
|
|
||||||
}
|
|
||||||
fileSeekPositions[fd]++;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t NixFileManager::readByte(int8_t fd)
|
|
||||||
{
|
|
||||||
if (fd < 0 || fd >= numCached)
|
|
||||||
return -1; // FIXME: error handling?
|
|
||||||
|
|
||||||
if (cachedNames[fd][0] == 0)
|
|
||||||
return -1; // FIXME: error handling?
|
|
||||||
|
|
||||||
uint8_t v = 0;
|
|
||||||
|
|
||||||
uint32_t pos = fileSeekPositions[fd];
|
|
||||||
|
|
||||||
// open, seek, read, close.
|
|
||||||
bool ret = false;
|
|
||||||
int ffd = open(cachedNames[fd], O_RDONLY);
|
|
||||||
if (ffd != -1) {
|
|
||||||
lseek(ffd, pos, SEEK_SET);
|
|
||||||
ret = (read(ffd, &v, 1) == 1);
|
|
||||||
close(ffd);
|
|
||||||
}
|
|
||||||
fileSeekPositions[fd]++;
|
|
||||||
|
|
||||||
if (!ret) {
|
|
||||||
printf("ERROR reading from pos %d: %d\n", pos, errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: error handling?
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NixFileManager::getRootPath(char *toWhere, int8_t maxLen)
|
void NixFileManager::getRootPath(char *toWhere, int8_t maxLen)
|
||||||
{
|
{
|
||||||
strcpy(toWhere, ROOTDIR);
|
strcpy(toWhere, ROOTDIR);
|
||||||
|
|
|
@ -16,12 +16,6 @@ class NixFileManager : public FileManager {
|
||||||
|
|
||||||
virtual int8_t readDir(const char *where, const char *suffix, char *outputFN, int8_t startIdx, uint16_t maxlen);
|
virtual int8_t readDir(const char *where, const char *suffix, char *outputFN, int8_t startIdx, uint16_t maxlen);
|
||||||
|
|
||||||
virtual uint8_t readByteAt(int8_t fd, uint32_t pos);
|
|
||||||
virtual bool writeByteAt(int8_t fd, uint8_t v, uint32_t pos);
|
|
||||||
|
|
||||||
virtual uint8_t readByte(int8_t fd);
|
|
||||||
virtual bool writeByte(int8_t fd, uint8_t v);
|
|
||||||
|
|
||||||
void getRootPath(char *toWhere, int8_t maxLen);
|
void getRootPath(char *toWhere, int8_t maxLen);
|
||||||
|
|
||||||
virtual bool setSeekPosition(int8_t fd, uint32_t pos);
|
virtual bool setSeekPosition(int8_t fd, uint32_t pos);
|
||||||
|
|
|
@ -182,102 +182,6 @@ bool TeensyFileManager::_prepCache(int8_t fd)
|
||||||
return true; // FIXME error handling
|
return true; // FIXME error handling
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t TeensyFileManager::readByteAt(int8_t fd, uint32_t pos)
|
|
||||||
{
|
|
||||||
// open, seek, read, close.
|
|
||||||
if (fd < 0 || fd >= numCached)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (cachedNames[fd][0] == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
_prepCache(fd);
|
|
||||||
|
|
||||||
if (!rawFile.seek(pos)) {
|
|
||||||
Serial.print("readByteAt: seek failed to pos ");
|
|
||||||
Serial.println(pos);
|
|
||||||
Serial.println("Trying to continue anyway");
|
|
||||||
// return false;
|
|
||||||
}
|
|
||||||
uint8_t b;
|
|
||||||
return (rawFile.read(&b, 1) == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TeensyFileManager::writeByteAt(int8_t fd, uint8_t v, uint32_t pos)
|
|
||||||
{
|
|
||||||
// open, seek, write, close.
|
|
||||||
if (fd < 0 || fd >= numCached)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (cachedNames[fd][0] == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
_prepCache(fd);
|
|
||||||
|
|
||||||
if (!rawFile.seek(pos))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return (rawFile.write(&v, 1) == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: the semantics of this are wrong - lots of 'return false' for a uint8_t
|
|
||||||
uint8_t TeensyFileManager::readByte(int8_t fd)
|
|
||||||
{
|
|
||||||
// open, seek, read, close.
|
|
||||||
if (fd < 0 || fd >= numCached)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (cachedNames[fd][0] == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
_prepCache(fd);
|
|
||||||
|
|
||||||
uint32_t pos = fileSeekPositions[fd];
|
|
||||||
|
|
||||||
if (!rawFile.seek(pos)) {
|
|
||||||
Serial.print("readByte: seek failed to byte ");
|
|
||||||
Serial.println(pos);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t b;
|
|
||||||
rawFile.read(&b, 1);
|
|
||||||
fileSeekPositions[fd]++;
|
|
||||||
|
|
||||||
// FIXME: check v == 1 & handle error
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TeensyFileManager::writeByte(int8_t fd, uint8_t v)
|
|
||||||
{
|
|
||||||
// open, seek, write, close.
|
|
||||||
if (fd < 0 || fd >= numCached) {
|
|
||||||
Serial.println("failed writeByte - invalid fd");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cachedNames[fd][0] == 0) {
|
|
||||||
Serial.println("failed writeByte - no cache name");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_prepCache(fd);
|
|
||||||
|
|
||||||
uint32_t pos = fileSeekPositions[fd];
|
|
||||||
|
|
||||||
if (!rawFile.seek(pos)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rawFile.write(&v, 1) != 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fileSeekPositions[fd]++;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TeensyFileManager::getRootPath(char *toWhere, int8_t maxLen)
|
void TeensyFileManager::getRootPath(char *toWhere, int8_t maxLen)
|
||||||
{
|
{
|
||||||
strcpy(toWhere, "/A2DISKS/");
|
strcpy(toWhere, "/A2DISKS/");
|
||||||
|
|
|
@ -16,12 +16,6 @@ class TeensyFileManager : public FileManager {
|
||||||
|
|
||||||
virtual int8_t readDir(const char *where, const char *suffix, char *outputFN, int8_t startIdx, uint16_t maxlen);
|
virtual int8_t readDir(const char *where, const char *suffix, char *outputFN, int8_t startIdx, uint16_t maxlen);
|
||||||
|
|
||||||
virtual uint8_t readByteAt(int8_t fd, uint32_t pos);
|
|
||||||
virtual bool writeByteAt(int8_t fd, uint8_t v, uint32_t pos);
|
|
||||||
|
|
||||||
virtual uint8_t readByte(int8_t fd);
|
|
||||||
virtual bool writeByte(int8_t fd, uint8_t v);
|
|
||||||
|
|
||||||
virtual void getRootPath(char *toWhere, int8_t maxLen);
|
virtual void getRootPath(char *toWhere, int8_t maxLen);
|
||||||
|
|
||||||
virtual bool setSeekPosition(int8_t fd, uint32_t pos);
|
virtual bool setSeekPosition(int8_t fd, uint32_t pos);
|
||||||
|
|
55
vmram.cpp
55
vmram.cpp
|
@ -39,48 +39,45 @@ void VMRam::writeByte(uint32_t addr, uint8_t value)
|
||||||
|
|
||||||
bool VMRam::Serialize(int8_t fd)
|
bool VMRam::Serialize(int8_t fd)
|
||||||
{
|
{
|
||||||
g_filemanager->writeByte(fd, RAMMAGIC);
|
|
||||||
uint32_t size = sizeof(preallocatedRam);
|
uint32_t size = sizeof(preallocatedRam);
|
||||||
g_filemanager->writeByte(fd, (size >> 24) & 0xFF);
|
uint8_t buf[5] = { RAMMAGIC,
|
||||||
g_filemanager->writeByte(fd, (size >> 16) & 0xFF);
|
(size >> 24) & 0xFF,
|
||||||
g_filemanager->writeByte(fd, (size >> 8) & 0xFF);
|
(size >> 16) & 0xFF,
|
||||||
g_filemanager->writeByte(fd, (size ) & 0xFF);
|
(size >> 8) & 0xFF,
|
||||||
|
(size ) & 0xFF };
|
||||||
|
if (g_filemanager->write(fd, buf, 5) != 5)
|
||||||
|
return false;
|
||||||
|
|
||||||
for (uint32_t pos = 0; pos < sizeof(preallocatedRam); pos++) {
|
if (g_filemanager->write(fd, preallocatedRam, sizeof(preallocatedRam)) != sizeof(preallocatedRam))
|
||||||
g_filemanager->writeByte(fd, preallocatedRam[pos]);
|
return false;
|
||||||
}
|
|
||||||
|
if (g_filemanager->write(fd, buf, 1) != 1)
|
||||||
g_filemanager->writeByte(fd, RAMMAGIC);
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VMRam::Deserialize(int8_t fd)
|
bool VMRam::Deserialize(int8_t fd)
|
||||||
{
|
{
|
||||||
if (g_filemanager->readByte(fd) != RAMMAGIC) {
|
uint8_t buf[5];
|
||||||
|
if (g_filemanager->read(fd, buf, 5) != 5)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t size = 0;
|
if (buf[0] != RAMMAGIC)
|
||||||
size = g_filemanager->readByte(fd);
|
|
||||||
size <<= 8;
|
|
||||||
size |= g_filemanager->readByte(fd);
|
|
||||||
size <<= 8;
|
|
||||||
size |= g_filemanager->readByte(fd);
|
|
||||||
size <<= 8;
|
|
||||||
size |= g_filemanager->readByte(fd);
|
|
||||||
|
|
||||||
if (size != sizeof(preallocatedRam)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
uint32_t size = (buf[1] << 24) | (buf[2] << 16) | (buf[3] << 8) | buf[4];
|
||||||
|
|
||||||
for (uint32_t pos = 0; pos < sizeof(preallocatedRam); pos++) {
|
if (size != sizeof(preallocatedRam))
|
||||||
preallocatedRam[pos] = g_filemanager->readByte(fd);
|
return false;
|
||||||
}
|
|
||||||
|
if (g_filemanager->read(fd, preallocatedRam, size) != size)
|
||||||
if (g_filemanager->readByte(fd) != RAMMAGIC) {
|
return false;
|
||||||
|
|
||||||
|
if (g_filemanager->read(fd, buf, 1) != 1)
|
||||||
|
return false;
|
||||||
|
if (buf[0] != RAMMAGIC)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue