]> Shamusworld >> Repos - thunder/blobdiff - src/thunder.cpp
Added missing files... D'oh!
[thunder] / src / thunder.cpp
index 5fdd7a88fd114daf1cee260c3d98a5da61b43d49..8ee60f525a32c1fe713f3f9ce2fe5d3ac2710caf 100755 (executable)
@@ -9,9 +9,10 @@
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
 // JLH  07/23/2009  Added changelog ;-)
+// JLH  08/12/2009  Stabilized emulation so that it works
 //
 
-#define THUNDER_VERSION       "0.9.9"
+#define THUNDER_VERSION                "0.9.9"
 
 #include <iostream>
 #include <iomanip>
 //#include <conio.h>                   // For getch()
 #include <curses.h>                    // For getch()
 #include <time.h>
-#include "SDL.h"                                                                               // Get yer SDL out...!
+#include "SDL.h"                                                               // Get yer SDL out...!
 #include "types.h"
 #include "v6809.h"
 #include "screen.h"
 #include "gui.h"
 #include "log.h"
 
-using namespace std;                                                                   // Yes!
+using namespace std;                                                   // Yes!
 
 #if 0
 #define ROM1  "RT3-1B.ROM"
@@ -102,17 +103,17 @@ uint8 chr_rom[0x60000];                                                   // Character ROM pointer
 
 V6809REGS cpu1, cpu2;
 
-bool trace1 = false;                 // ditto...
-bool looking_at_rom = true;         // true = R1, false = R2
-uint32 banksw1, banksw2;             // Bank switch addresses
-uint16 game_over_switch;              // Game over delay
-uint16 dpc;                           // Debug pc reg...
-bool show_scr = true;            // Whether or not to show background
-bool enable_cpu = true;          // Whether or not to enable CPUs
-bool irqGoA = true;              // IRQ switch for CPU #1
-bool irqGoB = true;              // IRQ switch for CPU #2
-
-uint16 refresh_ = 0;                // Crappy global screen stuff...
+bool trace1 = false;                                                   // ditto...
+bool looking_at_rom = true;                                            // true = R1, false = R2
+uint32 banksw1, banksw2;                                               // Bank switch addresses
+uint16 game_over_switch;                                               // Game over delay
+uint16 dpc;                                                                            // Debug pc reg...
+bool show_scr = true;                                                  // Whether or not to show background
+bool enable_cpu = true;                                                        // Whether or not to enable CPUs
+bool irqGoA = true;                                                            // IRQ switch for CPU #1
+bool irqGoB = true;                                                            // IRQ switch for CPU #2
+
+uint16 refresh_ = 0;                                                   // Crappy global screen stuff...
 bool refresh2 = true;
 
 uint32 psg_lens[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@@ -124,7 +125,7 @@ uint32 fm_lens[14] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 uint8 * fm_adrs[14];
 
 fstream tr;    // Tracelog hook
-uint16    pcx;   // Where we at?
+uint16 pcx;   // Where we at?
 
 static uint8 * keys;                                                   // SDL raw keyboard matrix
 
@@ -310,6 +311,7 @@ uint8 RdMem(uint16 addr)
 //
 void WrMem(uint16 addr, uint8 b)
 {
+       extern bool disasm;
        extern bool charbase;                                                           // Needed for screen. Extern it in it??
   //extern uint16 sr, ur, xr, yr;            // Needed for tracelog
   //extern uint16 pcr;
@@ -323,7 +325,7 @@ void WrMem(uint16 addr, uint8 b)
     //}
     tr << endl;
   }//*/
-#if 1
+#if 0
        if (addr == 0x4182)
        {
                WriteLog("\nWriteMem: CPU #1 writing $%02X to $4182!\n\n", b);
@@ -357,12 +359,13 @@ void WrMem(uint16 addr, uint8 b)
                        BlitChar(screen, chr_rom, gram1);
                        refresh_ = (refresh2 ? 1 : 0);                          // 60/30 Hz...
                }
-//Seems they're more regular than this...
-//             irqGoA = true; // Will this work??? no...
-//             cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ;//wil wok???
+
                // IRQ Ack (may also be frame go...
-//             cpu1.cpuFlags &= ~V6809_ASSERT_LINE_IRQ;
                ClearLineOfCurrentV6809(V6809_ASSERT_LINE_IRQ);
+#if 1
+       if (disasm)
+               WriteLog("WriteMem: CPU #1 Acknowledging IRQ...\n", b);
+#endif
        }
 }
 
@@ -401,6 +404,7 @@ uint8 RdMemB(uint16 addr)
 //
 void WrMemB(uint16 addr, uint8 b)
 {
+       extern bool disasm;
        extern bool charbase;
   //extern uint16 sr, ur, xr, yr;            // Needed for tracelog
   //extern uint16 pcr;
@@ -414,17 +418,13 @@ void WrMemB(uint16 addr, uint8 b)
     //}
     tr << endl;
   }//*/
-#if 1
+#if 0
        if (addr == 0x0182)
        {
                WriteLog("\nWriteMem: CPU #2 writing $%02X to $0182 ($4182)!\n\n", b);
        }
 #endif
 
-// Bah. Dunno if this is accurate or not!
-//     if (addr == 0x8800)
-//             irqGoB = true;                                                                  // Will it work??? no...
-//             cpu2.cpuFlags |= V6809_ASSERT_LINE_IRQ;//wil wok???
        if (addr == 0x6000)
                SpawnSound(GAMESOUND, gram1[0x6200], 0);                // Do voice chan 1
        if (addr == 0x6400)
@@ -451,8 +451,11 @@ void WrMemB(uint16 addr, uint8 b)
        if (addr == 0x8800)
        {
                // IRQ Ack (may also be frame go...)
-//             cpu2.cpuFlags &= ~V6809_ASSERT_LINE_IRQ;
                ClearLineOfCurrentV6809(V6809_ASSERT_LINE_IRQ);
+#if 1
+       if (disasm)
+               WriteLog("WriteMem: CPU #2 Acknowledging IRQ...\n", b);
+#endif
        }
 }
 
@@ -883,7 +886,6 @@ void LoadPSGs(void)
                if (fp)
                {
                        len = GetWAVLength(fp);                                         // Get WAV data length...
-
                        psg_adrs[i] = new uint8[len];                           // Attempt to allocate space...
 
                        if (psg_adrs[i] != NULL)
@@ -925,7 +927,6 @@ void LoadFMs(void)
                if (fp)
                {
                        len = GetWAVLength(fp);                                         // Get WAV length...
-
                        fm_adrs[i] = new uint8[len];                                    // Attempt to allocate space...
 
                        if (fm_adrs[i] != NULL)
@@ -1494,7 +1495,7 @@ WriteLog("About to enter main loop...\n");
                                }
                                if (keys[SDLK_d])                               // (D) start disassembly
                                        disasm = true;
-#if 1
+#if 0
        if (keys[SDLK_k])
                gram1[0x5606] = 0x00;
        if (keys[SDLK_l])
@@ -1510,22 +1511,9 @@ WriteLog("About to enter main loop...\n");
 #endif
 
 
-//                             if (enable_cpu)
-                               if (true)
+                               if (enable_cpu)
+//                             if (true)
                                {
-#if 0
-//                                     if (irqGoA)
-                                               cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ;
-
-                                       Execute6809(&cpu1, 25000);
-                                       cpu1.clock -= 25000;                            // Remove 25K ticks from clock (in case it overflowed)
-
-//                                     if (irqGoB)
-                                               cpu2.cpuFlags |= V6809_ASSERT_LINE_IRQ;
-
-                                       Execute6809(&cpu2, 25000);
-                                       cpu2.clock -= 25000;                            // Remove 25K ticks from clock (in case it overflowed)//*/
-#else
                                        // We can do this here because we're not executing the cores yet.
                                        cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ;
                                        cpu2.cpuFlags |= V6809_ASSERT_LINE_IRQ;
@@ -1533,15 +1521,19 @@ WriteLog("About to enter main loop...\n");
 // 1.538 MHz = 25633.333... cycles per frame (1/60 s)
 // 25600 cycles/frame
 // Setting interleave to 25 and below causes the V6809 core to hang...
+// 32 gets to the title screen before hanging...
 // 40 works, until it doesn't... :-P
+// 640 * 40
+// 800 * 32
+// Interesting, putting IRQs at 30 Hz makes it run at the correct speed. Still hangs in the demo, though.
                                        for(uint32 i=0; i<640; i++)
+//                                     for(uint32 i=0; i<1280; i++)
                                        {
                                                // Gay, but what are ya gonna do?
                                                // There's better ways, such as keeping track of when slave writes to master, etc...
                                                Execute6809(&cpu1, 40);
                                                Execute6809(&cpu2, 40);
                                        }
-#endif
                                } // END: enable_cpu
 
 //        if (refresh_++ == 1)                // 30 Hz...
@@ -1553,11 +1545,13 @@ WriteLog("About to enter main loop...\n");
 //          refresh_ = (refresh2 ? 1 : 0);    // 60/30 Hz...
 //        }
 
+#if 0
 //temp, for testing...
 BlitChar(screen, chr_rom, gram1);
-
+#endif
                                // Speed throttling happens here...
                                while (SDL_GetTicks() - oldTicks < 16)  // Actually, it's 16.66... Need to account for that somehow
+//                             while (SDL_GetTicks() - oldTicks < 32)  // Actually, it's 16.66... Need to account for that somehow
                                        SDL_Delay(1);                           // Release our timeslice...
 
                                oldTicks = SDL_GetTicks();
@@ -1684,6 +1678,10 @@ BlitChar(screen, chr_rom, gram1);
 }
 
 #if 0
+Hitachi uC runs at 6.144 MHz
+YM2151 runs at 3.579580 MHz
+
+
 Rolling Thunder Memory map
 --------------------------
 Most of the decoding is done by custom chips (CUS47 and CUS41), so the memory