From cc1c6568ff2ab4666a7e9e1cfbd843a277c44aa0 Mon Sep 17 00:00:00 2001 From: Dirk Hoffmann Date: Fri, 6 Sep 2024 12:09:31 +0200 Subject: [PATCH] Passing all QuickReuTest-1.1.1 tests (#809) --- .../Media/Cartridges/CustomCartridges/Reu.cpp | 36 ++++++++++++------- .../Media/Cartridges/CustomCartridges/Reu.h | 6 ++++ Emulator/config.cpp | 2 +- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Emulator/Media/Cartridges/CustomCartridges/Reu.cpp b/Emulator/Media/Cartridges/CustomCartridges/Reu.cpp index cbbd91932..24ba31510 100644 --- a/Emulator/Media/Cartridges/CustomCartridges/Reu.cpp +++ b/Emulator/Media/Cartridges/CustomCartridges/Reu.cpp @@ -442,10 +442,14 @@ Reu::initiateDma() void Reu::processEvent(EventID id) { + delay = 0; + switch (id) { case EXP_REU_PREPARE: + verifyError = false; + switch (cr & 0x3) { case 0: id = EXP_REU_STASH; break; @@ -471,7 +475,10 @@ Reu::processEvent(EventID id) // Perform a DMA cycle auto remaining = doDma(id); - if (remaining == -1) { + // Set or clear the END_OF_BLOCK_BIT + tlength == 1 ? SET_BIT(sr, 6) : CLR_BIT(sr, 6); + + if (remaining == -1 && tlength != 1) { // Verify error: Emulate a 1 cycle delay c64.scheduleRel(1, EXP_REU_AUTOLOAD); @@ -485,6 +492,7 @@ Reu::processEvent(EventID id) break; } + if (delay) { c64.scheduleRel(delay, EXP_REU_AUTOLOAD); break; } [[fallthrough]]; } case EXP_REU_AUTOLOAD: @@ -498,23 +506,18 @@ Reu::processEvent(EventID id) tlength = tlengthLatched; // Emulate a 4 cycle delay - if (id != EXP_REU_SWAP) { - - c64.scheduleRel(4, EXP_REU_FINALIZE); - break; - } + if (id != EXP_REU_SWAP) delay = 4; } else { debug(REU_DEBUG, "No autoload\n"); } + + if (delay) { c64.scheduleRel(delay, EXP_REU_FINALIZE); break; } [[fallthrough]]; case EXP_REU_FINALIZE: - // Set or clear the END_OF_BLOCK_BIT - tlength == 1 ? SET_BIT(sr, 6) : CLR_BIT(sr, 6); - finalizeDma(id); c64.cancel(); break; @@ -587,6 +590,9 @@ Reu::doDma(EventID id) // Trigger interrupt if enabled triggerVerifyErrorIrq(); + verifyError = true; + delay = tlength == 1 ? 0 : 1; + if (tlength != 1) U16_DEC(tlength, 1); return -1; } break; @@ -595,7 +601,11 @@ Reu::doDma(EventID id) fatalError; } - if (tlength == 1) return 0; + if (tlength == 1) { + + triggerEndOfBlockIrq(); + return 0; + } U16_DEC(tlength, 1); return tlength; @@ -604,7 +614,7 @@ Reu::doDma(EventID id) void Reu::finalizeDma(EventID id) { - triggerEndOfBlockIrq(); + // if (!verifyError) triggerEndOfBlockIrq(); // Release the CPU cpu.releaseRdyLine(INTSRC_EXP); @@ -618,7 +628,7 @@ Reu::triggerEndOfBlockIrq() sr |= 0x80; cpu.pullDownIrqLine(INTSRC_EXP); - debug(REU_DEBUG, "IRQ triggered (sr = %02x)\n", sr); + debug(REU_DEBUG, "End-of-block IRQ triggered (sr = %02x)\n", sr); } } @@ -629,6 +639,8 @@ Reu::triggerVerifyErrorIrq() sr |= 0x80; cpu.pullDownIrqLine(INTSRC_EXP); + + debug(REU_DEBUG, "Verify-error IRQ triggered (sr = %02x)\n", sr); } } diff --git a/Emulator/Media/Cartridges/CustomCartridges/Reu.h b/Emulator/Media/Cartridges/CustomCartridges/Reu.h index 1f8c12a10..8ebb3f1e8 100644 --- a/Emulator/Media/Cartridges/CustomCartridges/Reu.h +++ b/Emulator/Media/Cartridges/CustomCartridges/Reu.h @@ -87,9 +87,15 @@ class Reu final : public Cartridge { // Address control register (0x0A) u8 acr = 0; + // Signals a verify error + bool verifyError = false; + // Flipflop used to control the swap operation bool swapff = false; + // Used inside processEvent() to emulate additional delay cycles + isize delay = 0; + // // Emulation specific variables diff --git a/Emulator/config.cpp b/Emulator/config.cpp index f98e3a9d6..d4a401731 100644 --- a/Emulator/config.cpp +++ b/Emulator/config.cpp @@ -80,7 +80,7 @@ debugflag USR_DEBUG = 0; // Other components debugflag REC_DEBUG = 0; -debugflag REU_DEBUG = 1; +debugflag REU_DEBUG = 0; debugflag SCK_DEBUG = 0; debugflag SRV_DEBUG = 0;