diff --git a/source/Disk.cpp b/source/Disk.cpp index c90c5447..4a951bce 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -872,7 +872,7 @@ void __stdcall Disk2InterfaceCard::ReadWrite(WORD pc, WORD addr, BYTE bWrite, BY if (!pFloppy->m_trackimagedata) { - m_floppyLatch = 0xFF; + m_floppyLatch = rand() & 0xFF; // GH#748 return; } @@ -1056,7 +1056,7 @@ void __stdcall Disk2InterfaceCard::DataLatchReadWriteWOZ(WORD pc, WORD addr, BYT if (!floppy.m_trackimagedata) { _ASSERT(0); // Can't happen for WOZ - ReadTrack() should return an empty track - m_floppyLatch = 0xFF; + m_floppyLatch = rand() & 0xFF; // GH#748 return; } @@ -1073,7 +1073,7 @@ void __stdcall Disk2InterfaceCard::DataLatchReadWriteWOZ(WORD pc, WORD addr, BYT // The first 1-bit will produce a latch nibble, and this 1-bit is unlikely to be the nibble's high bit. // So we need to ensure we run enough bits through the sequencer to re-sync. // NB. For Planetfall 13 bitcells(NG) / 14 bitcells(OK) - const UINT significantBitCells = floppy.m_bitCount; + const UINT significantBitCells = 50; // 5x 10-bit sync FF nibbles UINT bitCellDelta = GetBitCellDelta(ImageGetOptimalBitTiming(floppy.m_imagehandle)); UINT bitCellRemainder; @@ -1113,8 +1113,6 @@ void __stdcall Disk2InterfaceCard::DataLatchReadWriteWOZ(WORD pc, WORD addr, BYT FrameDrawDiskStatus((HDC)0); } -static int g_zeroFieldFlag = 1; -static int g_zeroFieldCount = 0; void Disk2InterfaceCard::DataLatchReadWOZ(WORD pc, WORD addr, UINT bitCellRemainder) { // m_diskLastReadLatchCycle = g_nCumulativeCycles; // Not used by WOZ (only by NIB) @@ -1137,8 +1135,11 @@ void Disk2InterfaceCard::DataLatchReadWOZ(WORD pc, WORD addr, UINT bitCellRemain } #endif +#define WOZ_ALT2 +#ifdef WOZ_ALT1 // Only extraCycles of 2 & 3 can hold the latch for another bitCell period, eg. m_latchDelay: 3->5 or 7->9 -// UINT extraLatchDelay = ((UINT)floppy.m_extraCycles >= 2) ? 2 : 0; // GH#733 (0,1->0; 2,3->2) + UINT extraLatchDelay = ((UINT)floppy.m_extraCycles >= 2) ? 2 : 0; // GH#733 (0,1->0; 2,3->2) +#endif for (UINT i = 0; i < bitCellRemainder; i++) { @@ -1149,23 +1150,6 @@ void Disk2InterfaceCard::DataLatchReadWOZ(WORD pc, WORD addr, UINT bitCellRemain BYTE outputBit = (drive.m_headWindow & 0xf) ? (drive.m_headWindow >> 1) & 1 : (rand() < ((RAND_MAX * 3) / 10)) ? 1 : 0; // ~30% chance of a 1 bit (Ref: WOZ-2.0) -#if 0 // DEBUG: insert an extra 0-bit into the field of 317 zero bits - bool doInc = true; - if (drive.m_phase == 0 && floppy.m_bitOffset == (0x5811 + 92)) - { - g_zeroFieldCount++; - if (regs.pc < 0x8ff) - { - if (g_zeroFieldFlag) - { - g_zeroFieldFlag = 0; - doInc = false; - } - } - } - if (doInc) -#endif - { floppy.m_bitMask >>= 1; if (!floppy.m_bitMask) { @@ -1180,7 +1164,6 @@ void Disk2InterfaceCard::DataLatchReadWOZ(WORD pc, WORD addr, UINT bitCellRemain floppy.m_bitOffset = 0; floppy.m_byte = 0; } - } if (m_resetSequencer) { @@ -1195,9 +1178,11 @@ void Disk2InterfaceCard::DataLatchReadWOZ(WORD pc, WORD addr, UINT bitCellRemain if (m_latchDelay) { -// if (i == bitCellRemainder-1) // On last bitCell -// m_latchDelay += extraLatchDelay; // +0 or +2 -// extraLatchDelay = 0; // and always clear (even when not last bitCell) +#ifdef WOZ_ALT1 + if (i == bitCellRemainder-1) // On last bitCell + m_latchDelay += extraLatchDelay; // +0 or +2 + extraLatchDelay = 0; // and always clear (even when not last bitCell) +#endif m_latchDelay -= 4; if (m_latchDelay < 0) @@ -1244,6 +1229,51 @@ void Disk2InterfaceCard::DataLatchReadWOZ(WORD pc, WORD addr, UINT bitCellRemain } } } // for + static int dbg=0; +#ifdef WOZ_ALT2 +#if 0 // NG: LOA2 (not tested others) + if (m_latchDelay && m_shiftReg) // if m_shiftReg==0, then it was a zero bitCell, so hold latch + { + if (m_latchDelay <= (int)floppy.m_extraCycles) // "< 0" never occurs + { + m_floppyLatch = m_shiftReg; + _ASSERT((m_shiftReg & 0x80) == 0); + } + } +#elif (0) // NG: LOA2 (not tested others) + if (m_latchDelay && m_shiftReg) // if m_shiftReg==0, then it was a zero bitCell, so hold latch + { + m_latchDelay -= (UINT)floppy.m_extraCycles; + if (m_latchDelay <= 0) // or "< 0" + { + m_latchDelay = 0; + m_floppyLatch = m_shiftReg; + _ASSERT((m_shiftReg & 0x80) == 0); + } + } +#elif (0) // NG: LOA2 (not tested others) + if (m_latchDelay) + { + if (m_latchDelay <= (int)floppy.m_extraCycles) // "< 0" never occurs + { + m_floppyLatch = m_shiftReg; + _ASSERT((m_shiftReg & 0x80) == 0); + } + } +#else + if (m_latchDelay) + { + m_latchDelay -= (UINT)floppy.m_extraCycles; + if (m_latchDelay <= 0) // NG: Wasteland, OK: LOA1/2 + { + _ASSERT(m_shiftReg); + m_latchDelay = 0; + m_floppyLatch = m_shiftReg; + _ASSERT((m_shiftReg & 0x80) == 0); + } + } +#endif +#endif #if LOG_DISK_NIBBLES_READ if (m_floppyLatch & 0x80)