2019-02-20 12:50:51 +00:00
|
|
|
#include "woz-serializer.h"
|
2020-06-28 03:09:43 +00:00
|
|
|
#include "globals.h"
|
|
|
|
|
|
|
|
#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
|
|
|
|
2020-07-01 02:44:50 +00:00
|
|
|
uint8_t buf[17] = { WOZMAGIC,
|
2020-06-28 19:24:49 +00:00
|
|
|
(trackPointer >> 24) & 0xFF,
|
|
|
|
(trackPointer >> 16) & 0xFF,
|
|
|
|
(trackPointer >> 8) & 0xFF,
|
|
|
|
(trackPointer ) & 0xFF,
|
|
|
|
(trackBitCounter >> 24) & 0xFF,
|
|
|
|
(trackBitCounter >> 16) & 0xFF,
|
|
|
|
(trackBitCounter >> 8) & 0xFF,
|
|
|
|
(trackBitCounter ) & 0xFF,
|
2020-07-01 02:44:50 +00:00
|
|
|
(lastReadPointer >> 24) & 0xFF,
|
|
|
|
(lastReadPointer >> 16) & 0xFF,
|
|
|
|
(lastReadPointer >> 8) & 0xFF,
|
|
|
|
(lastReadPointer ) & 0xFF,
|
2020-06-28 19:24:49 +00:00
|
|
|
trackByte,
|
|
|
|
trackBitIdx,
|
|
|
|
trackLoopCounter,
|
|
|
|
WOZMAGIC };
|
2020-07-01 02:44:50 +00:00
|
|
|
if (g_filemanager->write(fd, buf, 17) != 17)
|
2020-06-28 19:24:49 +00:00
|
|
|
return false;
|
2020-06-28 03:09:43 +00:00
|
|
|
|
|
|
|
return true;
|
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!
|
2020-07-01 02:44:50 +00:00
|
|
|
uint8_t buf[17];
|
|
|
|
if (g_filemanager->read(fd, buf, 17) != 17)
|
2020-06-28 03:09:43 +00:00
|
|
|
return false;
|
|
|
|
|
2020-06-28 19:24:49 +00:00
|
|
|
if (buf[0] != WOZMAGIC)
|
|
|
|
return false;
|
2020-06-28 03:09:43 +00:00
|
|
|
|
2020-06-28 19:24:49 +00:00
|
|
|
trackPointer = buf[1];
|
|
|
|
trackPointer <<= 8; trackPointer |= buf[2];
|
|
|
|
trackPointer <<= 8; trackPointer |= buf[3];
|
|
|
|
trackPointer <<= 8; trackPointer |= buf[4];
|
|
|
|
|
|
|
|
trackBitCounter = buf[5];
|
|
|
|
trackBitCounter <<= 8; trackBitCounter |= buf[6];
|
|
|
|
trackBitCounter <<= 8; trackBitCounter |= buf[7];
|
|
|
|
trackBitCounter <<= 8; trackBitCounter |= buf[8];
|
|
|
|
|
2020-07-01 02:44:50 +00:00
|
|
|
lastReadPointer = buf[9];
|
|
|
|
lastReadPointer <<= 8; lastReadPointer |= buf[10];
|
|
|
|
lastReadPointer <<= 8; lastReadPointer |= buf[11];
|
|
|
|
lastReadPointer <<= 8; lastReadPointer |= buf[12];
|
|
|
|
|
|
|
|
trackByte = buf[13];
|
|
|
|
trackBitIdx = buf[14];
|
|
|
|
trackLoopCounter = buf[15];
|
|
|
|
if (buf[16] != WOZMAGIC)
|
2020-06-28 03:09:43 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2019-02-20 12:50:51 +00:00
|
|
|
}
|
|
|
|
|