From 5888a2b4a684cd31c7ca8dace886ca3688404c21 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sun, 21 Aug 2022 11:48:42 +0100 Subject: [PATCH] WOZ: Change track head movement positioning to work on bit (not nibble) offset. (#1022) --- source/Disk.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/source/Disk.cpp b/source/Disk.cpp index 1c8e53b1..8969ac21 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -301,8 +301,15 @@ void Disk2InterfaceCard::ReadTrack(const int drive, ULONG uExecutedCycles) UpdateBitStreamPosition(*pFloppy, bitCellDelta); } - const UINT32 currentPosition = pFloppy->m_byte; - const UINT32 currentTrackLength = pFloppy->m_nibbles; + if (ImageIsWOZ(pFloppy->m_imagehandle) && (pFloppy->m_bitCount == 0)) + { + // WOZ: m_bitCount only ever 0 on initial power on + pFloppy->m_bitOffset = 0; + pFloppy->m_bitCount = 8; + } + + const UINT32 currentBitPosition = pFloppy->m_bitOffset; + const UINT32 currentBitTrackLength = pFloppy->m_bitCount; ImageReadTrack( pFloppy->m_imagehandle, @@ -312,7 +319,7 @@ void Disk2InterfaceCard::ReadTrack(const int drive, ULONG uExecutedCycles) &pFloppy->m_bitCount, m_enhanceDisk); - if (!ImageIsWOZ(pFloppy->m_imagehandle) || (currentTrackLength == 0)) + if (!ImageIsWOZ(pFloppy->m_imagehandle)) { pFloppy->m_byte = 0; } @@ -325,14 +332,15 @@ void Disk2InterfaceCard::ReadTrack(const int drive, ULONG uExecutedCycles) pFloppy->m_bitCount = 8; } - pFloppy->m_byte = (currentPosition * pFloppy->m_nibbles) / currentTrackLength; // Ref: WOZ-1.01 - pFloppy->m_byte += 1; // Round-up for sensitive cross-track sync check (GH#1022) + pFloppy->m_bitOffset = (currentBitPosition * pFloppy->m_bitCount) / currentBitTrackLength; // Ref: WOZ-1.01 + pFloppy->m_bitOffset += 7; // Round-up for sensitive cross-track sync check (GH#1022) - if (pFloppy->m_byte >= (pFloppy->m_nibbles-1)) // Last nibble may not be complete, so advance by 1 nibble - pFloppy->m_byte = 0; + if (pFloppy->m_bitOffset >= pFloppy->m_bitCount) + pFloppy->m_bitOffset = 0; + + pFloppy->m_byte = pFloppy->m_bitOffset / 8; + pFloppy->m_bitMask = 1 << (7 - (pFloppy->m_bitOffset % 8)); - pFloppy->m_bitOffset = pFloppy->m_byte*8; - pFloppy->m_bitMask = 1 << 7; pFloppy->m_extraCycles = 0.0; pDrive->m_headWindow = 0; }