2019-02-20 12:50:51 +00:00
|
|
|
#include "woz-serializer.h"
|
2020-06-28 03:09:43 +00:00
|
|
|
#include "globals.h"
|
|
|
|
|
2021-01-10 02:32:40 +00:00
|
|
|
#include "serialize.h"
|
|
|
|
|
|
|
|
#ifdef TEENSYDUINO
|
|
|
|
#include "iocompat.h"
|
|
|
|
#endif
|
|
|
|
|
2020-06-28 03:09:43 +00:00
|
|
|
#define WOZMAGIC 0xD5
|
2019-02-20 12:50:51 +00:00
|
|
|
|
2020-06-27 22:00:59 +00:00
|
|
|
WozSerializer::WozSerializer() : Woz(0,0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-28 03:09:43 +00:00
|
|
|
const char *WozSerializer::diskName()
|
|
|
|
{
|
|
|
|
if (fd != -1) {
|
|
|
|
return g_filemanager->fileName(fd);
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2019-02-20 12:50:51 +00:00
|
|
|
bool WozSerializer::Serialize(int8_t fd)
|
|
|
|
{
|
2020-06-28 12:29:26 +00:00
|
|
|
// If we're being asked to serialize, make sure we've flushed any data first
|
|
|
|
flush();
|
2020-06-28 03:09:43 +00:00
|
|
|
|
2021-01-10 02:32:40 +00:00
|
|
|
serializeMagic(WOZMAGIC);
|
|
|
|
serialize32(trackPointer);
|
|
|
|
serialize32(trackBitCounter);
|
|
|
|
serialize32(lastReadPointer);
|
|
|
|
serialize8(trackByte);
|
|
|
|
serialize8(trackBitIdx);
|
|
|
|
serialize8(trackLoopCounter);
|
|
|
|
serializeMagic(WOZMAGIC);
|
2020-06-28 03:09:43 +00:00
|
|
|
|
|
|
|
return true;
|
2021-01-10 02:32:40 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
return false;
|
2019-02-20 12:50:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WozSerializer::Deserialize(int8_t fd)
|
|
|
|
{
|
2020-06-28 03:09:43 +00:00
|
|
|
// Before deserializing, the caller has to re-load the right disk image!
|
2021-01-10 02:32:40 +00:00
|
|
|
deserializeMagic(WOZMAGIC);
|
|
|
|
deserialize32(trackPointer);
|
|
|
|
deserialize32(trackBitCounter);
|
|
|
|
deserialize32(lastReadPointer);
|
|
|
|
deserialize8(trackByte);
|
|
|
|
deserialize8(trackBitIdx);
|
|
|
|
deserialize8(trackLoopCounter);
|
|
|
|
deserializeMagic(WOZMAGIC);
|
2020-06-28 03:09:43 +00:00
|
|
|
|
|
|
|
return true;
|
2021-01-10 02:32:40 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
return false;
|
2019-02-20 12:50:51 +00:00
|
|
|
}
|
|
|
|
|