abstracting aiie-specific changes to WozSerializer

This commit is contained in:
Jorj Bauer 2021-01-21 23:06:08 -05:00
parent 2082f07d62
commit 2fb6a5fe8d
4 changed files with 84 additions and 48 deletions

View File

@ -59,3 +59,59 @@ bool WozSerializer::Deserialize(int8_t fd)
return false;
}
bool WozSerializer::flush()
{
// Flush the entire disk image if it's dirty. We could make this
// smarter later.
if (!trackDirty)
return true;
// The fd should still be open. If it's not, then we can't flush.
if (fd == -1)
return false;
bool ret = true;
switch (imageType) {
case T_WOZ:
ret = writeWozFile(fd, imageType);
break;
case T_DSK:
case T_PO:
ret = writeDskFile(fd, imageType);
break;
case T_NIB:
ret = writeNibFile(fd);
break;
default:
fprintf(stderr, "Error: unknown imageType; can't flush\n");
ret = false;
break;
}
// fsync(fd); // FIXME should not be needed
trackDirty = false;
return true;
}
bool WozSerializer::writeNextWozBit(uint8_t datatrack, uint8_t bit)
{
return Woz::writeNextWozBit(datatrack, bit);
}
bool WozSerializer::writeNextWozByte(uint8_t datatrack, uint8_t b)
{
return Woz::writeNextWozByte(datatrack, b);
}
uint8_t WozSerializer::nextDiskBit(uint8_t datatrack)
{
return Woz::nextDiskBit(datatrack);
}
uint8_t WozSerializer::nextDiskByte(uint8_t datatrack)
{
return Woz::nextDiskByte(datatrack);
}

View File

@ -10,6 +10,13 @@ public:
public:
bool Serialize(int8_t fd);
bool Deserialize(int8_t fd);
virtual bool flush();
virtual bool writeNextWozBit(uint8_t datatrack, uint8_t bit);
virtual bool writeNextWozByte(uint8_t datatrack, uint8_t b);
virtual uint8_t nextDiskBit(uint8_t datatrack);
virtual uint8_t nextDiskByte(uint8_t datatrack);
};

View File

@ -85,18 +85,18 @@ bool Woz::writeNextWozBit(uint8_t datatrack, uint8_t bit)
return false;
}
if (trackByteFromDataTrack != datatrack) {
// if (trackByteFromDataTrack != datatrack) {
// FIXME what if trackPointer is out of bounds for this track
trackByte = tracks[datatrack].trackData[trackPointer];
trackByteFromDataTrack = datatrack;
}
// }
if (bit)
trackByte |= trackBitIdx;
else
trackByte &= ~trackBitIdx;
tracks[datatrack].trackData[trackPointer-1] = trackByte;
tracks[datatrack].trackData[trackPointer] = trackByte;
advanceBitStream(datatrack);
trackDirty = true;
@ -1603,35 +1603,5 @@ uint8_t Woz::dataTrackNumberForQuarterTrack(uint16_t qt)
bool Woz::flush()
{
// Flush the entire disk image if it's dirty. We could make this
// smarter later.
if (!trackDirty)
return true;
// The fd should still be open. If it's not, then we can't flush.
if (fd == -1)
return false;
bool ret = true;
switch (imageType) {
case T_WOZ:
ret = writeWozFile(fd, imageType);
break;
case T_DSK:
case T_PO:
ret = writeDskFile(fd, imageType);
break;
case T_NIB:
ret = writeNibFile(fd);
break;
default:
fprintf(stderr, "Error: unknown imageType; can't flush\n");
ret = false;
break;
}
// fsync(fd); // FIXME should not be needed
trackDirty = false;
return true;
return false;
}

View File

@ -41,7 +41,11 @@ typedef struct _trackInfo {
uint8_t *trackData;
} trackInfo;
class WozSerializer;
class Woz {
friend class WozSerializer;
public:
Woz(bool verbose, uint8_t dumpflags);
~Woz();
@ -57,17 +61,23 @@ class Woz {
uint8_t dataTrackNumberForQuarterTrack(uint16_t qt);
bool flush();
virtual bool flush();
void debug();
//protected:
protected:
// Interface for AiiE
bool writeNextWozBit(uint8_t datatrack, uint8_t bit);
bool writeNextWozByte(uint8_t datatrack, uint8_t b);
uint8_t nextDiskBit(uint8_t datatrack);
uint8_t nextDiskByte(uint8_t datatrack);
bool skipByte(uint8_t datatrack);
virtual bool writeNextWozBit(uint8_t datatrack, uint8_t bit);
virtual bool writeNextWozByte(uint8_t datatrack, uint8_t b);
virtual uint8_t nextDiskBit(uint8_t datatrack);
virtual uint8_t nextDiskByte(uint8_t datatrack);
bool writeWozFile(const char *filename, uint8_t subtype);
bool writeWozFile(int fd, uint8_t subtype);
bool writeDskFile(const char *filename, uint8_t subtype);
bool writeDskFile(int fd, uint8_t subtype);
bool writeNibFile(const char *filename);
bool writeNibFile(int fd);
private:
void loadTrackByte(uint8_t datatrack);
@ -80,13 +90,6 @@ class Woz {
bool decodeWozTrackToNibFromDataTrack(uint8_t datatrack, nibSector sectorData[16]);
bool decodeWozTrackToDsk(uint8_t phystrack, uint8_t subtype, uint8_t sectorData[256*16]);
bool writeWozFile(const char *filename, uint8_t subtype);
bool writeWozFile(int fd, uint8_t subtype);
bool writeDskFile(const char *filename, uint8_t subtype);
bool writeDskFile(int fd, uint8_t subtype);
bool writeNibFile(const char *filename);
bool writeNibFile(int fd);
bool writeWozTrack(int fd, uint8_t trackToWrite, uint8_t imageType);
bool writeDskTrack(int fd, uint8_t trackToWrite, uint8_t imageType);
bool writeNibTrack(int fd, uint8_t trackToWrite, uint8_t imageType);