mirror of
https://github.com/cmosher01/Epple-II.git
synced 2025-02-05 17:30:41 +00:00
revised random-bit generation algorithm
This commit is contained in:
parent
57f9dc3045
commit
b531bc96f5
20
src/drive.h
20
src/drive.h
@ -32,7 +32,7 @@ private:
|
||||
StepperMotor& arm;
|
||||
|
||||
bool pulse;
|
||||
std::uint8_t cContiguousZeroBits;
|
||||
std::uint8_t bitBufferRead;
|
||||
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ public:
|
||||
disk(disk),
|
||||
arm(arm),
|
||||
pulse(false),
|
||||
cContiguousZeroBits(0),
|
||||
bitBufferRead(0),
|
||||
generator(std::chrono::system_clock::now().time_since_epoch().count()),
|
||||
distribution(0,1) {
|
||||
}
|
||||
@ -93,18 +93,12 @@ public:
|
||||
void rotateDiskOneBit() {
|
||||
this->disk.rotateOneBit(this->arm.getQuarterTrack());
|
||||
|
||||
if (this->disk.getBit(this->arm.getQuarterTrack())) {
|
||||
this->pulse = true;
|
||||
cContiguousZeroBits = 0;
|
||||
bitBufferRead <<= 1;
|
||||
bitBufferRead |= this->disk.getBit(this->arm.getQuarterTrack());
|
||||
if (bitBufferRead & 0x0Fu) {
|
||||
this->pulse = (bitBufferRead & 0x02u) >> 1;
|
||||
} else {
|
||||
// keep a count of contiguous zero-bits and generate random bits when
|
||||
// we see more than three (emulating the MC3470, see UA2, 9-11)
|
||||
++cContiguousZeroBits;
|
||||
if (3 < cContiguousZeroBits) {
|
||||
if (randomBit()) {
|
||||
this->pulse = true;
|
||||
}
|
||||
}
|
||||
this->pulse = randomBit();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user