]> Shamusworld >> Repos - apple2/blobdiff - src/v65c02.cpp
Fixed problem with frames running ahead of the sound thread.
[apple2] / src / v65c02.cpp
index 5ef1709eed6a5fd91def85c06ca01443c79138cc..7f86895c6927f5ff3afff81299bcebe13fc566df 100755 (executable)
@@ -2807,6 +2807,7 @@ void (* exec_op[256])() = {
        OpF0, OpF1, OpF2, Op__, Op__, OpF5, OpF6, OpF7, OpF8, OpF9, OpFA, Op__, Op__, OpFD, OpFE, OpFF
 };
 
+
 //
 // Internal "memcpy" (so we don't have to link with any external libraries!)
 //
@@ -2849,6 +2850,9 @@ bool dumpDis = false;
 //bleh.
 //static uint32_t limit = 0;
 
+// This should be in the regs struct, in case we have multiple CPUs...
+#warning "!!! Move overflow into regs struct !!!"
+static uint64_t overflow = 0;
 //
 // Function to execute 65C02 for "cycles" cycles
 //
@@ -2874,7 +2878,7 @@ Let's see...
        if (regs.clock + cycles > 0xFFFFFFFF)
                wraparound = true;
 */
-       uint64_t endCycles = regs.clock + (uint64_t)cycles;
+       uint64_t endCycles = regs.clock + (uint64_t)cycles - overflow;
 
        while (regs.clock < endCycles)
        {
@@ -3019,14 +3023,16 @@ WriteLog("\n*** IRQ ***\n\n");
                }
        }
 
-//This is a lame way of doing it, but in the end the simplest--however, it destroys any
-//record of elasped CPU time. Not sure that it's important to keep track, but there it is.
-// Now we use a 64-bit integer, so it won't wrap for about 500 millenia. ;-)
-//     regs.clock -= cycles;
+       // If we went longer than the passed in cycles, make a note of it so we can
+       // subtract it out from a subsequent run. It's guaranteed to be positive,
+       // because the condition that exits the main loop above is written such
+       // that regs.clock has to be larger than endCycles to exit from it.
+       overflow = regs.clock - endCycles;
 
        myMemcpy(context, &regs, sizeof(V65C02REGS));
 }
 
+
 //
 // Get the clock of the currently executing CPU
 //
@@ -3034,3 +3040,4 @@ uint64_t GetCurrentV65C02Clock(void)
 {
        return regs.clock;
 }
+