X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fv6809.cpp;h=cb670726874d0ab4cdad5e1bf31722bb76aae8d0;hb=f51c96856129613e8aefd07a777dc59812ded4c7;hp=197cdea906a88ae1b653aecc253499be4220e8ae;hpb=d1485d7c8a16bf3dd7601bbf6016998eb28bf989;p=stargem2 diff --git a/src/v6809.cpp b/src/v6809.cpp index 197cdea..cb67072 100755 --- a/src/v6809.cpp +++ b/src/v6809.cpp @@ -3049,34 +3049,60 @@ static void myMemcpy(void * dst, void * src, uint32 size) // // Function to execute 6809 instructions // -#define NON_DESTRUCTIVE_CLOCK -#ifdef NON_DESTRUCTIVE_CLOCK -//static uint32 leftover = 0; -//#include "log.h" +//#define DEBUG_ILLEGAL +#ifdef DEBUG_ILLEGAL +#include "log.h" +#include "dis6809.h" +uint8 btPtr = 0; +uint8 backTrace[256]; +V6809REGS btRegs[256]; +bool tripped = false; #endif void Execute6809(V6809REGS * context, uint32 cycles) { - // This seriously fucks up the leftover counting... - if (cycles == 0) + // If this is not in place, the clockOverrun calculations can cause the V6809 to get + // stuck in an infinite loop. + if (cycles == 0) // Nothing to do, so bail! return; -//WriteLog("V6809: cycles = %u, regs.clock = %u, leftover = %u \n", cycles, regs.clock, leftover); myMemcpy(®s, context, sizeof(V6809REGS)); // Execute here... -#ifdef NON_DESTRUCTIVE_CLOCK -//Very odd.. It fucks up when using the following code for a timeslice! -// cycles -= regs.clockOverrun;//leftover; -// uint64 endCycles = regs.clock + (uint64)(cycles - leftover); + + // Since we can't guarantee that we'll execute the number of cycles passed in + // exactly, we have to keep track of how much we overran the number of cycles + // the last time we executed. Since we already executed those cycles, this time + // through we remove them from the cycles passed in in order to come out + // approximately even. Over the long run, this unevenness in execution times + // evens out. uint64 endCycles = regs.clock + (uint64)(cycles - regs.clockOverrun); -// uint64 endCycles = regs.clock + (uint64)cycles; -//WriteLog("V6809: endCycles = %u, regs.clock = %u, leftover = %u \n", endCycles, regs.clock, leftover); while (regs.clock < endCycles) -#else - while (regs.clock < cycles) -#endif { +#ifdef DEBUG_ILLEGAL +if (!tripped) +{ + backTrace[btPtr] = regs.RdMem(regs.pc); + btRegs[btPtr] = regs; + btPtr = (btPtr + 1) & 0xFF; + + if (regs.cpuFlags & V6809_STATE_ILLEGAL_INST) + { + WriteLog("V6809: Executed illegal instruction!!!!\n\nBacktrace:\n\n"); + regs.cpuFlags &= ~V6809_STATE_ILLEGAL_INST; + + for(uint16 i=btPtr; i