Skip to content

Commit

Permalink
Work on REU timing (SWAP mode)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed Sep 6, 2024
1 parent ea47c38 commit f9157df
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
29 changes: 17 additions & 12 deletions Emulator/Media/Cartridges/CustomCartridges/Reu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,17 +469,16 @@ Reu::processEvent(EventID id)
}

// Perform a DMA cycle
bool lastCycle = tlength == 1;
bool success = doDma(id);
auto remaining = doDma(id);

if (!success) {
if (remaining == -1) {

// Emulate a 1 cycle delay
// Verify error: Emulate a 1 cycle delay
c64.scheduleRel<SLOT_EXP>(1, EXP_REU_AUTOLOAD);
break;
}

if (!lastCycle) {
if (remaining > 0) {

// Process the event again in the next cycle
c64.rescheduleRel<SLOT_EXP>(1);
Expand All @@ -499,8 +498,11 @@ Reu::processEvent(EventID id)
tlength = tlengthLatched;

// Emulate a 4 cycle delay
c64.scheduleRel<SLOT_EXP>(4, EXP_REU_FINALIZE);
break;
if (id != EXP_REU_SWAP) {

c64.scheduleRel<SLOT_EXP>(4, EXP_REU_FINALIZE);
break;
}

} else {

Expand All @@ -522,11 +524,10 @@ Reu::processEvent(EventID id)
}
}

bool
isize
Reu::doDma(EventID id)
{
u8 c64Val, reuVal;
bool result = true;

switch (id) {

Expand All @@ -552,6 +553,9 @@ Reu::doDma(EventID id)

case EXP_REU_SWAP:

// Only proceed every second cycle
if ((swapff = !swapff) == true) return tlength;

c64Val = readFromC64Ram(c64Base);
reuVal = readFromReuRam((u32)reuBank << 16 | reuBase);

Expand Down Expand Up @@ -583,17 +587,18 @@ Reu::doDma(EventID id)
// Trigger interrupt if enabled
triggerVerifyErrorIrq();

result = false;
return -1;
}
break;

default:
fatalError;
}

if (tlength != 1) U16_DEC(tlength, 1);
if (tlength == 1) return 0;

return result;
U16_DEC(tlength, 1);
return tlength;
}

void
Expand Down
6 changes: 3 additions & 3 deletions Emulator/Media/Cartridges/CustomCartridges/Reu.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class Reu final : public Cartridge {
u8 acr = 0;

// Flipflop used to control the swap operation
// bool swapff = false;
bool swapff = false;


//
// Emulation specific variables
Expand Down Expand Up @@ -273,7 +273,7 @@ class Reu final : public Cartridge {
void processEvent(EventID id) override;

// Performs a single DMA cycle
bool doDma(EventID id);
isize doDma(EventID id);

void finalizeDma(EventID id);

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 = 0;
debugflag REU_DEBUG = 1;
debugflag SCK_DEBUG = 0;
debugflag SRV_DEBUG = 0;

Expand Down

0 comments on commit f9157df

Please sign in to comment.