| 1336 | } |
| 1337 | |
| 1338 | void __stdcall Disk2InterfaceCard::DataLatchReadWriteWOZ(WORD pc, WORD addr, BYTE bWrite, ULONG uExecutedCycles) |
| 1339 | { |
| 1340 | _ASSERT(m_seqFunc.function != dataShiftWrite); |
| 1341 | |
| 1342 | FloppyDrive& drive = m_floppyDrive[m_currDrive]; |
| 1343 | FloppyDisk& floppy = drive.m_disk; |
| 1344 | |
| 1345 | if (!floppy.m_trackimagedata && floppy.m_imagehandle) |
| 1346 | { |
| 1347 | ReadTrack(m_currDrive, uExecutedCycles); |
| 1348 | // NB. ReadTrack() has called GetBitCellDelta(), so the subsequent call to GetBitCellDelta() below just returns bitCellDelta==0 |
| 1349 | // So could just return at this point. |
| 1350 | } |
| 1351 | |
| 1352 | if (!floppy.m_trackimagedata) |
| 1353 | { |
| 1354 | _ASSERT(0); // Can't happen for WOZ - ReadTrack() should return an empty track |
| 1355 | return UpdateLatchForEmptyDrive(&drive); |
| 1356 | } |
| 1357 | |
| 1358 | // Don't change latch if drive off after 1 second drive-off delay (UTAIIe page 9-13) |
| 1359 | // "DRIVES OFF forces the data register to hold its present state." (UTAIIe page 9-12) |
| 1360 | // Note: Sherwood Forest sets shift mode and reads with the drive off. |
| 1361 | // TODO: And same for a write? |
| 1362 | if (!drive.m_spinning) // GH#599 |
| 1363 | return; |
| 1364 | |
| 1365 | // Skipping forward a large amount of bitcells means the bitstream will very likely be out-of-sync. |
| 1366 | // The first 1-bit will produce a latch nibble, and this 1-bit is unlikely to be the nibble's high bit. |
| 1367 | // So we need to ensure we run enough bits through the sequencer to re-sync. |
| 1368 | const UINT significantBitCells = 100; // eg. long stream of weak bits and/or 5x 10-bit sync FF nibbles (GH#1020) |
| 1369 | UINT bitCellDelta = GetBitCellDelta(uExecutedCycles); |
| 1370 | |
| 1371 | UINT bitCellRemainder; |
| 1372 | if (bitCellDelta <= significantBitCells) |
| 1373 | { |
| 1374 | bitCellRemainder = bitCellDelta; |
| 1375 | } |
| 1376 | else |
| 1377 | { |
| 1378 | bitCellRemainder = significantBitCells; |
| 1379 | bitCellDelta -= significantBitCells; |
| 1380 | |
| 1381 | UpdateBitStreamPosition(floppy, bitCellDelta); |
| 1382 | |
| 1383 | m_latchDelay = 0; |
| 1384 | drive.m_headWindow = 0; |
| 1385 | |
| 1386 | AddJitter(drive.m_phase, floppy); // Only call when skipping a big number of bit-cells (ie. >significantBitCells) |
| 1387 | } |
| 1388 | |
| 1389 | if (!bWrite) |
| 1390 | { |
| 1391 | if (m_seqFunc.function != readSequencing) |
| 1392 | { |
| 1393 | _ASSERT(m_seqFunc.function == checkWriteProtAndInitWrite); |
| 1394 | UpdateBitStreamPosition(floppy, bitCellRemainder); |
| 1395 | return; |
no test coverage detected