mirror of https://github.com/JorjBauer/aiie.git
fix serialization of woz data
This commit is contained in:
parent
d56f9665ba
commit
290b3e5a58
|
@ -49,8 +49,6 @@ DiskII::~DiskII()
|
||||||
|
|
||||||
bool DiskII::Serialize(int8_t fd)
|
bool DiskII::Serialize(int8_t fd)
|
||||||
{
|
{
|
||||||
return false;
|
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, DISKIIMAGIC);
|
g_filemanager->writeByte(fd, DISKIIMAGIC);
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, readWriteLatch);
|
g_filemanager->writeByte(fd, readWriteLatch);
|
||||||
|
@ -110,11 +108,18 @@ bool DiskII::Serialize(int8_t fd)
|
||||||
|
|
||||||
if (disk[i]) {
|
if (disk[i]) {
|
||||||
g_filemanager->writeByte(fd, 1);
|
g_filemanager->writeByte(fd, 1);
|
||||||
|
// 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!
|
||||||
|
const char *fn = disk[i]->diskName();
|
||||||
|
for (int j=0; j<strlen(fn); j++) {
|
||||||
|
g_filemanager->writeByte(fd, fn[j]);
|
||||||
|
}
|
||||||
|
g_filemanager->writeByte(fd, 0);
|
||||||
|
if (!disk[i]->Serialize(fd))
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
g_filemanager->writeByte(fd, 0);
|
g_filemanager->writeByte(fd, 0);
|
||||||
}
|
}
|
||||||
if (!disk[i]->Serialize(fd))
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_filemanager->writeByte(fd, DISKIIMAGIC);
|
g_filemanager->writeByte(fd, DISKIIMAGIC);
|
||||||
|
@ -167,6 +172,24 @@ bool DiskII::Deserialize(int8_t fd)
|
||||||
delete disk[i];
|
delete disk[i];
|
||||||
if (g_filemanager->readByte(fd) == 1) {
|
if (g_filemanager->readByte(fd) == 1) {
|
||||||
disk[i] = new WozSerializer();
|
disk[i] = new WozSerializer();
|
||||||
|
char buf[MAXPATH];
|
||||||
|
char c;
|
||||||
|
int ptr = 0;
|
||||||
|
while ( (c = g_filemanager->readByte(fd) != 0) ) {
|
||||||
|
buf[ptr++] = c;
|
||||||
|
}
|
||||||
|
buf[ptr] = 0;
|
||||||
|
if (buf[0]) {
|
||||||
|
#ifdef TEENSYDUINO
|
||||||
|
disk[i]->readFile(buf, false, T_AUTO); // FIXME error checking
|
||||||
|
#else
|
||||||
|
disk[i]->readFile(buf, true, T_AUTO); // FIXME error checking
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
// ERROR: there's a disk but we don't have the path to its image?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!disk[i]->Deserialize(fd))
|
if (!disk[i]->Deserialize(fd))
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,18 +1,76 @@
|
||||||
#include "woz-serializer.h"
|
#include "woz-serializer.h"
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
|
#define WOZMAGIC 0xD5
|
||||||
|
|
||||||
WozSerializer::WozSerializer() : Woz(0,0)
|
WozSerializer::WozSerializer() : Woz(0,0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *WozSerializer::diskName()
|
||||||
|
{
|
||||||
|
if (fd != -1) {
|
||||||
|
return g_filemanager->fileName(fd);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
bool WozSerializer::Serialize(int8_t fd)
|
bool WozSerializer::Serialize(int8_t fd)
|
||||||
{
|
{
|
||||||
// ***
|
// FIXME: if trackDirty is set, we MUST flush first before exiting!
|
||||||
return false;
|
|
||||||
|
g_filemanager->writeByte(fd, WOZMAGIC);
|
||||||
|
|
||||||
|
// We need the internal state about data but not much else
|
||||||
|
g_filemanager->writeByte(fd,
|
||||||
|
(trackPointer >> 24) & 0xFF);
|
||||||
|
g_filemanager->writeByte(fd,
|
||||||
|
(trackPointer >> 16) & 0xFF);
|
||||||
|
g_filemanager->writeByte(fd,
|
||||||
|
(trackPointer >> 8) & 0xFF);
|
||||||
|
g_filemanager->writeByte(fd,
|
||||||
|
(trackPointer ) & 0xFF);
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WozSerializer::Deserialize(int8_t fd)
|
bool WozSerializer::Deserialize(int8_t fd)
|
||||||
{
|
{
|
||||||
// ***
|
// Before deserializing, the caller has to re-load the right disk image!
|
||||||
return false;
|
if (g_filemanager->readByte(fd) != WOZMAGIC)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
trackPointer = g_filemanager->readByte(fd);
|
||||||
|
trackPointer <<= 8; trackPointer |= g_filemanager->readByte(fd);
|
||||||
|
trackPointer <<= 8; trackPointer |= g_filemanager->readByte(fd);
|
||||||
|
trackPointer <<= 8; trackPointer |= g_filemanager->readByte(fd);
|
||||||
|
|
||||||
|
trackBitCounter = g_filemanager->readByte(fd);
|
||||||
|
trackBitCounter <<= 8; trackBitCounter |= g_filemanager->readByte(fd);
|
||||||
|
trackBitCounter <<= 8; trackBitCounter |= g_filemanager->readByte(fd);
|
||||||
|
trackBitCounter <<= 8; trackBitCounter |= g_filemanager->readByte(fd);
|
||||||
|
|
||||||
|
trackByte = g_filemanager->readByte(fd);
|
||||||
|
trackBitIdx = g_filemanager->readByte(fd);
|
||||||
|
trackLoopCounter = g_filemanager->readByte(fd);
|
||||||
|
|
||||||
|
if (g_filemanager->readByte(fd) != WOZMAGIC)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
class WozSerializer: public virtual Woz {
|
class WozSerializer: public virtual Woz {
|
||||||
public:
|
public:
|
||||||
WozSerializer();
|
WozSerializer();
|
||||||
|
const char *diskName();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool Serialize(int8_t fd);
|
bool Serialize(int8_t fd);
|
||||||
|
|
|
@ -100,7 +100,6 @@ class Woz {
|
||||||
void _initInfo();
|
void _initInfo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int fd;
|
|
||||||
uint8_t imageType;
|
uint8_t imageType;
|
||||||
|
|
||||||
bool verbose;
|
bool verbose;
|
||||||
|
@ -114,11 +113,15 @@ class Woz {
|
||||||
trackInfo tracks[160];
|
trackInfo tracks[160];
|
||||||
|
|
||||||
// cursor for track enumeration
|
// cursor for track enumeration
|
||||||
|
protected:
|
||||||
|
int fd;
|
||||||
|
|
||||||
uint32_t trackPointer;
|
uint32_t trackPointer;
|
||||||
uint32_t trackBitCounter;
|
uint32_t trackBitCounter;
|
||||||
uint8_t trackByte;
|
uint8_t trackByte;
|
||||||
uint8_t trackBitIdx;
|
uint8_t trackBitIdx;
|
||||||
uint8_t trackLoopCounter;
|
uint8_t trackLoopCounter;
|
||||||
|
private:
|
||||||
char *metaData;
|
char *metaData;
|
||||||
uint8_t randData, randPtr;
|
uint8_t randData, randPtr;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue