diff --git a/src/Drive.cpp b/src/Drive.cpp index b16ae4a..bd3ccd6 100644 --- a/src/Drive.cpp +++ b/src/Drive.cpp @@ -487,7 +487,9 @@ bool Drive::Update() DriveLoopReadNoCycles(); } else + { DriveLoopRead(); + } } #else for (int cycles = 0; cycles < 16; ++cycles) @@ -580,6 +582,7 @@ bool Drive::Update() return dataReady; } + #if defined(EXPERIMENTALZERO) #define min(a,b) (((a) < (b)) ? (a) : (b)) #define max(a,b) (((a) > (b)) ? (a) : (b)) @@ -597,7 +600,6 @@ void Drive::DriveLoopReadNoFluxNoCycles() cycles = 0; return; } - cycles -= UE7Counter; UE7Counter = 16 - CLOCK_SEL_AB; // A and B inputs of UE7 come from the VIA's CLOCK SEL A/B outputs (ie PB5/6) ie preload the encoder/decoder clock for the current density settings. @@ -649,14 +651,8 @@ void Drive::DriveLoopReadNoFlux() if (cyclesLeftForBit == 0) { - //which is faster? single loop ceil check or the 3 lines below? - float fn = 2.0f * cyclesPerBit - cyclesForBit; - cyclesLeftForBit = (int)fn; - cyclesForBit = cyclesPerBit; - if (fn != (float)cyclesLeftForBit) { - ++cyclesLeftForBit; - ++cyclesForBit; - } + cyclesForBitErrorCounter -= cyclesPerBitErrorConstant; + cyclesLeftForBit = cyclesPerBitInt + (cyclesForBitErrorCounter < cyclesPerBitErrorConstant); //cyclesForBit -= cyclesPerBit; //cyclesLeftForBit = ceil(cyclesPerBit - cyclesForBit); @@ -772,13 +768,8 @@ void Drive::DriveLoopRead() if (cyclesLeftForBit == 0) { //which is faster? single loop ceil check or the 3 lines below? - float fn = 2.0f * cyclesPerBit - cyclesForBit; - cyclesLeftForBit = (int)fn; - cyclesForBit = cyclesPerBit; - if (fn != (float)cyclesLeftForBit) { - ++cyclesLeftForBit; - ++cyclesForBit; - } + cyclesForBitErrorCounter -= cyclesPerBitErrorConstant; + cyclesLeftForBit = cyclesPerBitInt + (cyclesForBitErrorCounter < cyclesPerBitErrorConstant); //cyclesForBit -= cyclesPerBit; //cyclesLeftForBit = ceil(cyclesPerBit - cyclesForBit); diff --git a/src/Drive.h b/src/Drive.h index 6713ee4..1ad0933 100644 --- a/src/Drive.h +++ b/src/Drive.h @@ -96,6 +96,12 @@ private: bitsInTrack = diskImage->BitsInTrack(headTrackPos); headBitOffset %= bitsInTrack; cyclesPerBit = CYCLES_16Mhz_PER_ROTATION / (float)bitsInTrack; +#if defined(EXPERIMENTALZERO) + cyclesPerBitInt = cyclesPerBit; + cyclesPerBitErrorConstant = (unsigned int)((cyclesPerBit - ((float)cyclesPerBitInt)) * static_cast(0xffffffff)); + cyclesForBitErrorCounter = (unsigned int)(((cyclesForBit)-(int)(cyclesForBit)) * static_cast(0xffffffff)); +#endif + } inline void MoveHead(unsigned char headDirection) @@ -118,6 +124,15 @@ private: void DumpTrack(unsigned track); // Used for debugging disk images. +#if defined(EXPERIMENTALZERO) + inline u32 AdvanceSectorPositionR(int& byteOffset) + { + if (++headBitOffset == bitsInTrack) + headBitOffset = 0; + byteOffset = headBitOffset >> 3; + return (~headBitOffset) & 7; + } +#else // No reason why I seperate these into individual read and write versions. I was just trying to get the bit stream to line up when rewriting over existing data. inline u32 AdvanceSectorPositionR(int& byteOffset) { @@ -125,7 +140,7 @@ private: byteOffset = headBitOffset >> 3; return (~headBitOffset) & 7; } - +#endif inline u32 AdvanceSectorPositionW(int& byteOffset) { byteOffset = headBitOffset >> 3; @@ -167,6 +182,9 @@ private: unsigned int fluxReversalCyclesLeft; unsigned int UE7Counter; u32 writeShiftRegister; + unsigned int cyclesForBitErrorCounter; + unsigned int cyclesPerBitErrorConstant; + unsigned int cyclesPerBitInt; #else int UE7Counter; u8 writeShiftRegister;