]> Shamusworld >> Repos - apple2/commitdiff
Moved CPU cycle subtraction into CPU core.
authorShamus Hammons <jlhamm@acm.org>
Wed, 4 Jul 2007 23:29:48 +0000 (23:29 +0000)
committerShamus Hammons <jlhamm@acm.org>
Wed, 4 Jul 2007 23:29:48 +0000 (23:29 +0000)
src/apple2.cpp
src/v65c02.cpp
src/v65c02.h

index 1edce9fa140969172d0b38b80517fe4bb486ab94..729dc23cc80206dbeee31fad906e592e3b5bcd70 100755 (executable)
@@ -644,7 +644,8 @@ memcpy(ram + 0xD000, ram + 0xC000, 0x1000);
                Execute65C02(&mainCPU, USEC_TO_M6502_CYCLES(timeToNextEvent));
 //We MUST remove a frame's worth of time in order for the CPU to function... !!! FIX !!!
 //(Fix so that this is not a requirement!)
-               mainCPU.clock -= USEC_TO_M6502_CYCLES(timeToNextEvent);
+//Fixed, but mainCPU.clock is destroyed in the bargain. Oh well.
+//             mainCPU.clock -= USEC_TO_M6502_CYCLES(timeToNextEvent);
                HandleNextEvent();
        }
 
index a98c16f7b677dc3e9692384b491967c40bce6d8e..24ba4a8926ad05de5bf41b0cf452d67e61eadb28 100755 (executable)
@@ -2214,14 +2214,37 @@ FBEF: 60        602  RTS2B    RTS
 #ifdef __DEBUG__
 bool dumpDis = false;
 #endif
+
+//Note: could enforce regs.clock to zero on starting the CPU with an Init() function...
+//bleh.
+//static uint32 limit = 0;
+
 //
-// Function to execute 6808 for "cycles" cycles
+// Function to execute 65C02 for "cycles" cycles
 //
 void Execute65C02(V65C02REGS * context, uint32 cycles)
 {
        myMemcpy(&regs, context, sizeof(V65C02REGS));
 
        // Execute here...
+// NOTE: There *must* be some way of doing this without requiring the caller to subtract out
+//       the previous run's cycles. !!! FIX !!!
+// Could try:
+//     while (regs.clock < regs.clock + cycles) <-- won't work
+/*
+       // This isn't as accurate as subtracting out cycles from regs.clock...
+       // Unless limit is a static variable, adding cycles to it each time through...
+       uint32 limit = regs.clock + cycles;
+       while (regs.clock < limit)
+*/
+// but have wraparound to deal with. :-/
+/*
+Let's see...
+
+       if (regs.clock + cycles > 0xFFFFFFFF)
+               wraparound = true;
+*/
+
        while (regs.clock < cycles)
        {
 #if 0
@@ -2360,6 +2383,10 @@ 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.
+       regs.clock -= cycles;
+
        myMemcpy(context, &regs, sizeof(V65C02REGS));
 }
 
index 96e62178289424f02493c87a02efd8ed241a4d58..7a557ab5848ca567a128adbc1a41dae58021f0e8 100755 (executable)
@@ -37,7 +37,7 @@ struct V65C02REGS
        uint8 a;                                                // 65C02 A register
        uint8 x;                                                // 65C02 X index register
        uint8 y;                                                // 65C02 Y register
-       uint32 clock;                                   // 65C02 clock
+       uint32 clock;                                   // 65C02 clock (@ 1 MHz, wraps at 71.5 minutes)
        uint8 (* RdMem)(uint16);                // Address of BYTE read routine
        void (* WrMem)(uint16, uint8);  // Address of BYTE write routine
        uint16 cpuFlags;                                // v65C02 IRQ/RESET flags