diff --git a/src/diskcontroller.cpp b/src/diskcontroller.cpp index 95101a3..9e765ba 100644 --- a/src/diskcontroller.cpp +++ b/src/diskcontroller.cpp @@ -85,8 +85,7 @@ unsigned char DiskController::io(const unsigned short addr, const unsigned char * (When the motor is on, that is.) */ void DiskController::tick() { - this->drive1.tick(); - this->drive2.tick(); + this->currentDrive->tick(); if (this->ioStepped) { // if we already ran it, above in io(), skip here this->ioStepped = false; @@ -105,21 +104,24 @@ void DiskController::tick() { * then inject the next bit and subtract the optimal bit timing from your bit timing clock. * That will give you 125ns resolution on your bits being fed to the sequencer. */ - rotateCurrentDisk(); // run two LSS cycles = 2MHz + + rotateCurrentDisk(); stepLss(); + // pulse lasts only 500 nanoseconds (1 LSS clock cycle), so clear it now: this->currentDrive->clearPulse(); + rotateCurrentDisk(); stepLss(); } void DiskController::rotateCurrentDisk() { - ++this->t; - if (4 <= this->t) { // 4us interval between bits + this->t += 1.0f; + if (this->currentDrive->optimal_timing()/4.0f <= this->t) { // 4us interval between bits this->currentDrive->rotateDiskOneBit(); // (will also generate a read-pulse when it reads a 1-bit) - this->t = 0; + this->t -= this->currentDrive->optimal_timing()/4.0f; } } diff --git a/src/diskcontroller.h b/src/diskcontroller.h index ad37fda..bc321bd 100644 --- a/src/diskcontroller.h +++ b/src/diskcontroller.h @@ -55,7 +55,7 @@ private: // On the real Apple the read pulse goes thru this LS174 too, but we don't emulate that here. std::uint8_t prev_seq; // remember previous seq, to determine if A7 changes (indicating write a 1 bit) - std::uint8_t t; // used to keep track of 4 MPU cycles + double t; // used to keep track of optimal bit timing interval // TODO for a rev. 0 motherboard, the disk controller will auto reset the CPU (see UA2, 9-13) diff --git a/src/drive.cpp b/src/drive.cpp index 8270a38..5e4af15 100644 --- a/src/drive.cpp +++ b/src/drive.cpp @@ -47,6 +47,10 @@ bool Disk2Drive::isModified() const { return this->disk.isModified(); } +int Disk2Drive::optimal_timing() const { + return this->disk.optimal_timing(); +} + int Disk2Drive::position() const { return this->head.position(); } diff --git a/src/drive.h b/src/drive.h index 95f0712..4c1f5fd 100644 --- a/src/drive.h +++ b/src/drive.h @@ -53,6 +53,7 @@ public: void saveDisk(); bool isWriteProtected() const; bool isModified() const; + int optimal_timing() const; int position() const; void tick(); void set_phase(int i_phase_0_to_3, bool on); diff --git a/src/wozfile.h b/src/wozfile.h index d475e8c..07bfb04 100644 --- a/src/wozfile.h +++ b/src/wozfile.h @@ -134,6 +134,13 @@ public: bool getBit(std::uint8_t currentQuarterTrack); void setBit(std::uint8_t currentQuarterTrack, bool on); void rawSet(); + + int optimal_timing() const { + if (this->loaded) { + return this->timing; + } + return 32; + } }; #endif // WOZFILE_H