MCPcopy Index your code
hub / github.com/AppleWin/AppleWin / DecodeLatchNibble

Method DecodeLatchNibble

source/DiskFormatTrack.cpp:223–325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223void FormatTrack::DecodeLatchNibble(BYTE floppylatch, bool bIsWrite, bool bIsSyncFF)
224{
225 m_uLast3Bytes <<= 8;
226 m_uLast3Bytes |= floppylatch;
227 m_uLast3Bytes &= 0xFFFFFF;
228
229 if (m_trackState == TS_GAP2_START && bIsWrite) // NB. bIsWrite, as there's a read between writing Addr Field & Gap2
230 m_trackState = TS_GAP2;
231
232#if LOG_DISK_NIBBLES_WRITE_TRACK_GAPS
233 if (bIsSyncFF && (m_trackState == TS_GAP1 || m_trackState == TS_GAP2 || m_trackState == TS_GAP3))
234 {
235 if (m_bmWrittenSectorAddrFields == 0x0000 && m_trackState == TS_GAP1)
236 m_DbgGap1Size++;
237 else if (m_bmWrittenSectorAddrFields == 0x0001 && m_trackState == TS_GAP2)
238 m_DbgGap2Size++; // Only count Gap2 after sector0 Addr Field (assume other inter-sectors gap2's have same count)
239 else if (m_bmWrittenSectorAddrFields == 0x0001 && m_trackState == TS_GAP3)
240 m_DbgGap3Size++; // Only count Gap3 between sector0 & 1 (assume other inter-sectors gap3's have same count)
241 return;
242 }
243#endif
244
245 // Beneath Apple ProDOS 3-14: NB. $D5 and $AA are reserved (never written as data)
246 const UINT32 kADDR_PROLOGUE_DOS3_3 = 0xD5AA96; // D5AA96 is used by DOS3.3/ProDOS
247 const UINT32 kADDR_PROLOGUE_DOS3_2 = 0xD5AAB5; // D5AAB5 is used by DOS3.2/3.2.1
248 if (m_uLast3Bytes == kADDR_PROLOGUE_DOS3_3 || m_uLast3Bytes == kADDR_PROLOGUE_DOS3_2)
249 {
250 m_bAddressPrologueIsDOS3_2 = (m_uLast3Bytes == kADDR_PROLOGUE_DOS3_2);
251 m_trackState = TS_ADDRFIELD;
252 m_4and4idx = 0;
253 return;
254 }
255
256 // NB. If TS_ADDRFIELD && m_4and4idx == 8, then writing Address Field's epilogue
257 if (m_trackState == TS_ADDRFIELD && m_4and4idx < 8)
258 {
259 m_VolTrkSecChk4and4[m_4and4idx++] = floppylatch;
260
261 if (m_4and4idx == 8)
262 {
263 for (UINT i=0; i<4; i++)
264 m_VolTrkSecChk[i] = ((m_VolTrkSecChk4and4[i*2] & 0x55) << 1) | (m_VolTrkSecChk4and4[i*2+1] & 0x55);
265
266#if LOG_DISK_NIBBLES_READ
267 const bool chk = (m_VolTrkSecChk[0] ^ m_VolTrkSecChk[1] ^ m_VolTrkSecChk[2] ^ m_VolTrkSecChk[3]) == 0;
268 if (!bIsWrite)
269 {
270 BYTE addrPrologue = m_bAddressPrologueIsDOS3_2 ? (BYTE)kADDR_PROLOGUE_DOS3_2 : (BYTE)kADDR_PROLOGUE_DOS3_3;
271 m_strReadD5AAxxDetected = StrFormat("read D5AA%02X detected - Vol:%02X Trk:%02X Sec:%02X Chk:%02X %s",
272 addrPrologue, m_VolTrkSecChk[0], m_VolTrkSecChk[1], m_VolTrkSecChk[2], m_VolTrkSecChk[3], chk?"":"(bad)");
273 if (!m_bSuppressReadD5AAxxDetected)
274 {
275 LOG_DISK("%s\r\n", m_strReadD5AAxxDetected.c_str());
276 }
277 }
278#endif
279#if LOG_DISK_NIBBLES_WRITE
280 if (bIsWrite)

Callers

nothing calls this directly

Calls 1

StrFormatFunction · 0.85

Tested by

no test coverage detected