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