Skip to content

Commit

Permalink
Passing all QuickReuTest-1.1.1 tests (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed Sep 6, 2024
1 parent f9157df commit cc1c656
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
36 changes: 24 additions & 12 deletions Emulator/Media/Cartridges/CustomCartridges/Reu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<SLOT_EXP>(1, EXP_REU_AUTOLOAD);
Expand All @@ -485,6 +492,7 @@ Reu::processEvent(EventID id)
break;
}

if (delay) { c64.scheduleRel<SLOT_EXP>(delay, EXP_REU_AUTOLOAD); break; }
[[fallthrough]];
}
case EXP_REU_AUTOLOAD:
Expand All @@ -498,23 +506,18 @@ Reu::processEvent(EventID id)
tlength = tlengthLatched;

// Emulate a 4 cycle delay
if (id != EXP_REU_SWAP) {

c64.scheduleRel<SLOT_EXP>(4, EXP_REU_FINALIZE);
break;
}
if (id != EXP_REU_SWAP) delay = 4;

} else {

debug(REU_DEBUG, "No autoload\n");
}

if (delay) { c64.scheduleRel<SLOT_EXP>(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<SLOT_EXP>();
break;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -604,7 +614,7 @@ Reu::doDma(EventID id)
void
Reu::finalizeDma(EventID id)
{
triggerEndOfBlockIrq();
// if (!verifyError) triggerEndOfBlockIrq();

// Release the CPU
cpu.releaseRdyLine(INTSRC_EXP);
Expand All @@ -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);
}
}

Expand All @@ -629,6 +639,8 @@ Reu::triggerVerifyErrorIrq()

sr |= 0x80;
cpu.pullDownIrqLine(INTSRC_EXP);

debug(REU_DEBUG, "Verify-error IRQ triggered (sr = %02x)\n", sr);
}
}

Expand Down
6 changes: 6 additions & 0 deletions Emulator/Media/Cartridges/CustomCartridges/Reu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Emulator/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit cc1c656

Please sign in to comment.