]> Shamusworld >> Repos - apple2/blobdiff - src/apple2.cpp
Changed clock on v65C02 to 64-bit, more GUI refactoring
[apple2] / src / apple2.cpp
index 8365ef4a58ce12d9d27eff88d0e20332d376212a..42f59e4b8377fe6691eb6847844d35cd11bb97af 100755 (executable)
@@ -62,13 +62,14 @@ uint8 ram[0x10000], rom[0x10000];                           // RAM & ROM spaces
 uint8 diskRom[0x100];                                                  // Disk ROM space
 V65C02REGS mainCPU;
 uint8 appleType = APPLE_TYPE_II;
+FloppyDrive floppyDrive;
 
 // Local variables
 
 static uint8 lastKeyPressed = 0;
 static bool keyDown = false;
 
-static FloppyDrive floppyDrive;
+//static FloppyDrive floppyDrive;
 
 enum { LC_BANK_1, LC_BANK_2 };
 
@@ -256,7 +257,7 @@ deltaT to zero. In the sound IRQ, if deltaT > buffer size, then subtract buffer
 A = PEEK($C082)
 */
 
-#define DEBUG_LC
+//#define DEBUG_LC
        else if ((addr & 0xFFFB) == 0xC080)
        {
 #ifdef DEBUG_LC
@@ -371,23 +372,76 @@ WriteLog("LC(R): $C08B 49291 OECG RR Read/Write RAM bank 1\n");
                floppyDrive.SetWriteMode();
        }
 
+//#define LC_DEBUGGING
+#ifdef LC_DEBUGGING
+bool showpath = false;
+if (addr >= 0xD000 && addr <= 0xD00F)
+       showpath = true;
+#endif
 //This sux...
        if (addr >= 0xC100 && addr <= 0xCFFF)   // The $C000-$CFFF block is *never* RAM
+#ifdef LC_DEBUGGING
+       {
+#endif
                b = rom[addr];
+#ifdef LC_DEBUGGING
+if (showpath)
+       WriteLog("b is from $C100-$CFFF block...\n");
+       }
+#endif
        else if (addr >= 0xD000)
        {
                if (readRAM)
                {
                        if (addr <= 0xDFFF && visibleBank == LC_BANK_1)
+#ifdef LC_DEBUGGING
+       {
+#endif
                                b = ram[addr - 0x1000];
+#ifdef LC_DEBUGGING
+if (showpath)
+       WriteLog("b is from LC bank #1 (ram[addr - 0x1000])...\n");
+       }
+#endif
                        else
+#ifdef LC_DEBUGGING
+       {
+#endif
                                b = ram[addr];
+#ifdef LC_DEBUGGING
+if (showpath)
+       WriteLog("b is from LC bank #2 (ram[addr])...\n");
+       }
+#endif
                }
                else
+#ifdef LC_DEBUGGING
+       {
+#endif
                        b = rom[addr];
+#ifdef LC_DEBUGGING
+if (showpath)
+       WriteLog("b is from LC ROM (rom[addr])...\n");
+       }
+#endif
        }
        else
+#ifdef LC_DEBUGGING
+       {
+#endif
                b = ram[addr];
+#ifdef LC_DEBUGGING
+if (showpath)
+       WriteLog("b is from ram[addr]...\n");
+       }
+#endif
+
+#ifdef LC_DEBUGGING
+if (addr >= 0xD000 && addr <= 0xD00F)
+{
+       WriteLog("*** Read from $%04X: $%02X (readRAM=%s, PC=%04X, ram$D000=%02X)\n", addr, b, (readRAM ? "T" : "F"), mainCPU.pc, ram[0xC000]);
+}
+#endif
 
        return b;
 }
@@ -502,7 +556,8 @@ SETALTCH = $C00F ;use alt char set- norm inverse, LC; no Flash (WR-only)
        {
 //Actually, according to the A2 ref, this should do nothing since a write
 //is immediately preceded by a read leaving it in the same state it was...
-//             keyDown = false;
+//But leaving this out seems to fuck up the key handling of some games...
+               keyDown = false;
        }
        else if (addr == 0xC050)
        {
@@ -648,6 +703,16 @@ WriteLog("LC(R): $C08B 49291 OECG RR Read/Write RAM bank 1\n");
        }
 //Still need to add missing I/O switches here...
 
+//DEEE: BD 10 BF       LDA   $BF10,X    [PC=DEF1, SP=01F4, CC=--.B-IZ-, A=00, X=0C, Y=07]
+#if 0
+if (addr >= 0xD000 && addr <= 0xD00F)
+{
+       WriteLog("*** Write to $%04X: $%02X (writeRAM=%s, PC=%04X, ram$D000=%02X)\n", addr, b, (writeRAM ? "T" : "F"), mainCPU.pc, ram[0xC000]);
+}
+#endif
+       if (addr >= 0xC000 && addr <= 0xCFFF)
+               return; // Protect LC bank #1 from being written to!
+
        if (addr >= 0xD000)
        {
                if (writeRAM)
@@ -689,6 +754,11 @@ static bool LoadApple2State(const char * filename)
        return false;
 }
 
+//#define CPU_CLOCK_CHECKING
+#ifdef CPU_CLOCK_CHECKING
+uint8 counter = 0;
+uint32 totalCPU = 0;
+#endif
 //
 // Main loop
 //
@@ -724,7 +794,7 @@ int main(int /*argc*/, char * /*argv*/[])
 
 //Load up disk image from config file (for now)...
        floppyDrive.LoadImage(settings.diskImagePath1, 0);
-//     floppyDrive.LoadImage(settings.diskImagePath2, 1);
+       floppyDrive.LoadImage(settings.diskImagePath2, 1);
 //     floppyDrive.LoadImage("./disks/temp.nib", 1);   // Load temp .nib file into second drive...
 
 //Kill the DOS ROM in slot 6 for now...
@@ -785,12 +855,15 @@ memcpy(ram + 0xD000, ram + 0xC000, 0x1000);
        SoundInit();
        SDL_EnableUNICODE(1);                                           // Needed to do key translation shit
 
-       gui = new GUI(surface);                                         // Set up the GUI system object...
+//     gui = new GUI(surface);                                         // Set up the GUI system object...
+       gui = new GUI(mainSurface);                                     // Set up the GUI system object...
+#if 0
        gui->AddMenuTitle("Apple2");
        gui->AddMenuItem("Test!", TestWindow/*, hotkey*/);
        gui->AddMenuItem("");
        gui->AddMenuItem("Quit", QuitEmulator, SDLK_q);
        gui->CommitItemsToMenu();
+#endif
 
        SetupBlurTable();                                                       // Set up the color TV emulation blur table
        running = true;                                                         // Set running status...
@@ -809,8 +882,12 @@ memcpy(ram + 0xD000, ram + 0xC000, 0x1000);
 //(Fix so that this is not a requirement!)
 //Fixed, but mainCPU.clock is destroyed in the bargain. Oh well.
 //             mainCPU.clock -= USEC_TO_M6502_CYCLES(timeToNextEvent);
+#ifdef CPU_CLOCK_CHECKING
+totalCPU += USEC_TO_M6502_CYCLES(timeToNextEvent);
+#endif
                // Handle CPU time delta for sound...
-               AddToSoundTimeBase(USEC_TO_M6502_CYCLES(timeToNextEvent));
+//Don't need this anymore now that we use absolute time...
+//             AddToSoundTimeBase(USEC_TO_M6502_CYCLES(timeToNextEvent));
                HandleNextEvent();
        }
 
@@ -927,8 +1004,8 @@ static void FrameCallback(void)
 
                        if (event.key.keysym.sym == SDLK_F12)
                                dumpDis = !dumpDis;                             // Toggle the disassembly process
-                       else if (event.key.keysym.sym == SDLK_F11)
-                               floppyDrive.LoadImage("./disks/bt1_char.dsk");//Kludge to load char disk...
+//                     else if (event.key.keysym.sym == SDLK_F11)
+//                             floppyDrive.LoadImage("./disks/bt1_char.dsk");//Kludge to load char disk...
 else if (event.key.keysym.sym == SDLK_F9)
 {
        floppyDrive.CreateBlankImage();
@@ -951,16 +1028,39 @@ else if (event.key.keysym.sym == SDLK_F10)
 //      to quit completely... !!! FIX !!!
                                gui->Run();
 
+                       if (event.key.keysym.sym == SDLK_F5)
+                       {
+                               VolumeDown();
+                               char volStr[10] = "*********";
+                               volStr[GetVolume()] = 0;
+                               SpawnMessage("Volume: %s", volStr);
+                       }
+                       else if (event.key.keysym.sym == SDLK_F6)
+                       {
+                               VolumeUp();
+                               char volStr[10] = "*********";
+                               volStr[GetVolume()] = 0;
+                               SpawnMessage("Volume: %s", volStr);
+                       }
+
                        break;
                case SDL_QUIT:
                        running = false;
                }
        }
 
-//ick. HandleSoundAtFrameEdge();                                       // Sound stuff... (ick)
        RenderVideoFrame();
        SetCallbackTime(FrameCallback, 16666.66666667);
 
+#ifdef CPU_CLOCK_CHECKING
+counter++;
+if (counter == 60)
+{
+       printf("Executed %u cycles...\n", totalCPU);
+       totalCPU = 0;
+       counter = 0;
+}
+#endif
 //Instead of this, we should yield remaining time to other processes... !!! FIX !!!
 //lessee...
 //nope. SDL_Delay(10);