fix random bit generation if no disk or no track

This commit is contained in:
Christopher A. Mosher 2020-04-18 13:26:21 -04:00
parent b6b2fde6ea
commit 55a43d19f0
3 changed files with 11 additions and 13 deletions

View File

@ -72,8 +72,13 @@ void Disk2Drive::rotateDiskOneBit() {
this->disk.rotateOneBit(this->head.position());
bitBufferRead <<= 1;
bitBufferRead |= this->disk.getBit(this->head.position());
if (bitBufferRead & 0x0Fu) {
const bool exists(this->disk.exists(this->head.position()));
if (exists) {
bitBufferRead |= this->disk.getBit(this->head.position());
}
if ((bitBufferRead & 0x0Fu) && exists) {
this->pulse = (bitBufferRead & 0x02u) >> 1;
} else {
this->pulse = randomBit();

View File

@ -533,19 +533,11 @@ void WozFile::rotateOneBit(std::uint8_t currentQuarterTrack) {
}
}
bool WozFile::exists(std::uint8_t currentQuarterTrack) {
return isLoaded() && (this->tmap[currentQuarterTrack] != 0xFFu);
}
bool WozFile::getBit(std::uint8_t currentQuarterTrack) {
if (!isLoaded()) {
// printf("No disk to read from; will generate random data.\n");
return false; // there's no disk, so no pulse
}
if (this->tmap[currentQuarterTrack] == 0xFFu) {
// printf("Reading from uninitialized track; will generate random data.\n");
return false; // empty track
}
return this->trk[this->tmap[currentQuarterTrack]][this->byt] & this->bit;
}

View File

@ -131,6 +131,7 @@ public:
}
void rotateOneBit(std::uint8_t currentQuarterTrack);
bool exists(std::uint8_t currentQuarterTrack);
bool getBit(std::uint8_t currentQuarterTrack);
void setBit(std::uint8_t currentQuarterTrack, bool on);
void rawSet();