add serialize/deserialize for hd32

This commit is contained in:
Jorj Bauer 2020-07-04 14:46:31 -04:00
parent ebf5d716c8
commit 1da4817e86

View File

@ -27,6 +27,7 @@
#include "hd32-rom.h"
#define HD32MAGIC 0xF5
#define DEVICE_OK 0x00
#define DEVICE_UNKNOWN_ERROR 0x28
@ -61,11 +62,89 @@ HD32::~HD32()
bool HD32::Serialize(int8_t fd)
{
return true;
uint8_t buf[19] = { HD32MAGIC,
driveSelected,
unitSelected,
command,
enabled,
errorState[0],
errorState[1],
(uint8_t)((memBlock[0] >> 8) & 0xFF),
(uint8_t)((memBlock[0] ) & 0xFF),
(uint8_t)((memBlock[1] >> 8) & 0xFF),
(uint8_t)((memBlock[1] ) & 0xFF),
(uint8_t)((cursor[0] >> 24) & 0xFF),
(uint8_t)((cursor[0] >> 16) & 0xFF),
(uint8_t)((cursor[0] >> 8) & 0xFF),
(uint8_t)((cursor[0] ) & 0xFF),
(uint8_t)((cursor[1] >> 24) & 0xFF),
(uint8_t)((cursor[1] >> 16) & 0xFF),
(uint8_t)((cursor[1] >> 8) & 0xFF),
(uint8_t)((cursor[1] ) & 0xFF)
};
if (g_filemanager->write(fd, buf, 19) != 10)
return false;
for (int i=0; i<2; i++) {
const char *fn = diskName(i);
if (g_filemanager->write(fd, fn, strlen(fn)+1) != strlen(fn)+1) {
return false;
}
}
buf[0] = HD32MAGIC;
return (g_filemanager->write(fd, buf, 1) == 1);
}
bool HD32::Deserialize(int8_t fd)
{
uint8_t buf[255];
if (g_filemanager->read(fd, buf, 19) != 19) {
return false;
}
if (buf[0] != HD32MAGIC)
return false;
driveSelected = buf[1];
unitSelected = buf[2];
command = buf[3];
enabled = buf[4];
errorState[0] = buf[5];
errorState[1] = buf[6];
memBlock[0] = buf[7];
memBlock[0] <<= 8; memBlock[0] |= buf[8];
memBlock[1] = buf[9];
memBlock[1] <<= 8; memBlock[1] |= buf[10];
cursor[0] = buf[11];
cursor[0] <<= 8; cursor[0] |= buf[12];
cursor[0] <<= 8; cursor[0] |= buf[13];
cursor[0] <<= 8; cursor[0] |= buf[14];
cursor[1] = buf[15];
cursor[1] <<= 8; cursor[1] |= buf[16];
cursor[1] <<= 8; cursor[1] |= buf[17];
cursor[1] <<= 8; cursor[1] |= buf[18];
for (int i=0; i<2; i++) {
uint32_t ptr = 0;
// FIXME: MAXPATH check!
while (1) {
if (g_filemanager->read(fd, &buf[ptr++], 1) != 1)
return false;
if (buf[ptr-1] == 0)
break;
}
if (strlen((char *)buf)) {
// FIXME: this tromps on error and some other vars ... that we just restored
insertDisk(i, (char *)buf);
}
}
if (g_filemanager->read(fd, buf, 1) != 1)
return false;
if (buf[0] != HD32MAGIC)
return false;
return true;
}