]> Shamusworld >> Repos - apple2/blobdiff - src/v65c02.cpp
Added floppy #2 saving, statistics to makefile.
[apple2] / src / v65c02.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 7f86895..1eec874
@@ -1,10 +1,10 @@
 //
 // Virtual 65C02 Emulator v1.0
 //
-// by James L. Hammons
+// by James Hammons
 // (c) 2005 Underground Software
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
@@ -1142,7 +1142,6 @@ static void Op90(void)                                                    // BCC
 
        if (!(regs.cc & FLAG_C))
                HANDLE_BRANCH_TAKEN(m)
-//             regs.pc += m;
 }
 
 static void OpB0(void)                                                 // BCS
@@ -1151,7 +1150,6 @@ static void OpB0(void)                                                    // BCS
 
        if (regs.cc & FLAG_C)
                HANDLE_BRANCH_TAKEN(m)
-//             regs.pc += m;
 }
 
 static void OpF0(void)                                                 // BEQ
@@ -1160,7 +1158,6 @@ static void OpF0(void)                                                    // BEQ
 
        if (regs.cc & FLAG_Z)
                HANDLE_BRANCH_TAKEN(m)
-//             regs.pc += m;
 }
 
 /*
@@ -1263,6 +1260,16 @@ BRK      Implied         BRK                     00      1       7
 
 static void Op00(void)                                                 // BRK
 {
+//#ifdef __DEBUG__
+#if 1
+WriteLog("\n*** BRK ***\n\n");
+WriteLog(" [PC=%04X, SP=%04X, CC=%s%s.%s%s%s%s%s, A=%02X, X=%02X, Y=%02X]\n",
+       regs.pc, 0x0100 + regs.sp,
+       (regs.cc & FLAG_N ? "N" : "-"), (regs.cc & FLAG_V ? "V" : "-"),
+       (regs.cc & FLAG_B ? "B" : "-"), (regs.cc & FLAG_D ? "D" : "-"),
+       (regs.cc & FLAG_I ? "I" : "-"), (regs.cc & FLAG_Z ? "Z" : "-"),
+       (regs.cc & FLAG_C ? "C" : "-"), regs.a, regs.x, regs.y);
+#endif
        regs.cc |= FLAG_B;                                                      // Set B
        regs.pc++;                                                                      // RTI comes back to the instruction one byte after the BRK
        regs.WrMem(0x0100 + regs.sp--, regs.pc >> 8);   // Save PC and CC
@@ -2606,7 +2613,9 @@ static void Op86(void)
 
 static void Op96(void)
 {
-       regs.WrMem(EA_ZP_X, regs.x);
+// BUG!!! [FIXED]
+//WAS: regs.WrMem(EA_ZP_X, regs.x);
+       regs.WrMem(EA_ZP_Y, regs.x);
 }
 
 static void Op8E(void)
@@ -2844,15 +2853,27 @@ FBEF: 60        602  RTS2B    RTS
 //int instCount[256];
 #ifdef __DEBUG__
 bool dumpDis = false;
+//bool dumpDis = true;
 #endif
 
+/*
+On //e, $FCAA is the delay routine. (seems to not have changed from ][+)
+*/
+
+
 //Note: could enforce regs.clock to zero on starting the CPU with an Init() function...
 //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;
+// Or, we could just say that initializing the CPU struct is the responsibility
+// of the caller. :-)
+
+#define DO_BACKTRACE
+#ifdef DO_BACKTRACE
+#define BACKTRACE_SIZE 16384
+uint32_t btQueuePtr = 0;
+V65C02REGS btQueue[BACKTRACE_SIZE];
+uint8_t btQueueInst[BACKTRACE_SIZE][4];
+#endif
 //
 // Function to execute 65C02 for "cycles" cycles
 //
@@ -2861,24 +2882,7 @@ void Execute65C02(V65C02REGS * context, uint32_t 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_t limit = regs.clock + cycles;
-       while (regs.clock < limit)
-*/
-// but have wraparound to deal with. :-/
-/*
-Let's see...
-
-       if (regs.clock + cycles > 0xFFFFFFFF)
-               wraparound = true;
-*/
-       uint64_t endCycles = regs.clock + (uint64_t)cycles - overflow;
+       uint64_t endCycles = regs.clock + (uint64_t)cycles - regs.overflow;
 
        while (regs.clock < endCycles)
        {
@@ -2898,7 +2902,73 @@ if (regs.pc == 0x444E)
        dumpDis = false;
 }//*/
 #endif
+/*if (regs.pc >= 0xC600 && regs.pc <=0xC6FF)
+{
+       dumpDis = true;
+}
+else
+       dumpDis = false;//*/
+/*if (regs.pc == 0xE039)
+{
+       dumpDis = true;
+}//*/
+
+#if 0
+/*if (regs.pc == 0x0801)
+{
+       WriteLog("\n*** DISK BOOT subroutine...\n\n");
+       dumpDis = true;
+}//*/
+if (regs.pc == 0xE000)
+{
+#if 0
+       WriteLog("\n*** Dump of $E000 routine ***\n\n");
 
+       for(uint32_t addr=0xE000; addr<0xF000;)
+       {
+               addr += Decode65C02(addr);
+               WriteLog("\n");
+       }
+#endif
+       WriteLog("\n*** DISK part II subroutine...\n\n");
+       dumpDis = true;
+}//*/
+if (regs.pc == 0xD000)
+{
+       WriteLog("\n*** CUSTOM DISK READ subroutine...\n\n");
+       dumpDis = false;
+}//*/
+if (regs.pc == 0xD1BE)
+{
+//     WriteLog("\n*** DISK part II subroutine...\n\n");
+       dumpDis = true;
+}//*/
+if (regs.pc == 0xD200)
+{
+       WriteLog("\n*** CUSTOM SCREEN subroutine...\n\n");
+       dumpDis = false;
+}//*/
+if (regs.pc == 0xD269)
+{
+//     WriteLog("\n*** DISK part II subroutine...\n\n");
+       dumpDis = true;
+}//*/
+#endif
+//if (regs.pc == 0xE08E)
+/*if (regs.pc == 0xAD33)
+{
+       WriteLog("\n*** After loader ***\n\n");
+       dumpDis = true;
+}//*/
+/*if (regs.pc == 0x0418)
+{
+       WriteLog("\n*** CUSTOM DISK READ subroutine...\n\n");
+       dumpDis = false;
+}
+if (regs.pc == 0x0)
+{
+       dumpDis = true;
+}//*/
 #ifdef __DEBUGMON__
 //WAIT is commented out here because it's called by BELL1...
 if (regs.pc == 0xFCA8)
@@ -2929,8 +2999,12 @@ if (regs.pc == 0x2000)
 #endif
 
 #ifdef __DEBUG__
+static char disbuf[80];
 if (dumpDis)
-       Decode65C02(regs.pc);
+{
+       Decode65C02(disbuf, regs.pc);
+       WriteLog("%s", disbuf);
+}
 #endif
                uint8_t opcode = regs.RdMem(regs.pc++);
 
@@ -3027,7 +3101,7 @@ WriteLog("\n*** IRQ ***\n\n");
        // 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;
+       regs.overflow = regs.clock - endCycles;
 
        myMemcpy(context, &regs, sizeof(V65C02REGS));
 }