]> Shamusworld >> Repos - thunder/blobdiff - src/thunder.cpp
Code cleanup.
[thunder] / src / thunder.cpp
index 4fd1f32e5d2984c45cf20b111a32127ea0fdfef6..d3134ed62db44ff5d5f84bf57f421836b474e1c5 100644 (file)
@@ -1,18 +1,18 @@
 //
 // Thunder: A Rolling Thunder Emulator w/6809 debugger
 //
-// by James L. Hammons
-// (c) 2004, 2009 Underground Software
+// by James Hammons
+// (C) 2004, 2014 Underground Software
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // 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                "1.0.0"
 
 #include <iostream>
 #include <iomanip>
 #include <new>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 //#include <conio.h>                   // For getch()
 #include <curses.h>                    // For getch()
 #include <time.h>
 #include "SDL.h"                                                               // Get yer SDL out...!
-#include "types.h"
 #include "v6809.h"
 #include "screen.h"
 #include "gui.h"
 
 using namespace std;                                                   // Yes!
 
-#if 0
-#define ROM1  "RT3-1B.ROM"
-#define ROM2  "RT3-2B.ROM"
-#define ROM3  "RT3-3.ROM"
-#define ROM4  "RT3-4.ROM"
-#define ROM5  "RT1-5.ROM"
-#define ROM6  "RT1-6.ROM"
-#define ROM7  "RT1-7.ROM"
-#define ROM8  "RT1-8.ROM"
-#define ROM9  "RT1-9.ROM"
-#define ROM10 "RT1-10.ROM"
-#define ROM11 "RT1-11.ROM"
-#define ROM12 "RT1-12.ROM"
-#define ROM13 "RT1-13.ROM"
-#define ROM14 "RT1-14.ROM"
-#define ROM15 "RT1-15.ROM"
-#define ROM16 "RT1-16.ROM"
-#define ROM17 "RT1-17.ROM"
-#define ROM18 "RT1-18.ROM"
-#define ROM19 "RT3-19.ROM"
-#define ROM20 "RT3-20.ROM"
-#define ROM21 "RT1-21.ROM"
-#define ROM22 "RT2-22.ROM"
-#define PROM1 "RT1-1.BIN"
-#define PROM2 "RT1-2.BIN"
-#define PROM3 "RT1-3.BIN"
-#define PROM4 "RT1-4.BIN"
-#define PROM5 "RT1-5.BIN"
-#else
+
 #define ROM1   "rt3-1b.9c"
 #define ROM2   "rt3-2b.12c"
 #define ROM3   "rt3-3.12d"
@@ -90,44 +62,44 @@ using namespace std;                                                        // Yes!
 #define PROM4  "mb7138h.6v"
 #define PROM5  "mb7112e.6u"
 #define MCUROM "rt1-mcu.bin"
-#endif
+
 
 // Global defines
 
 SDL_Surface * screen;
 
-uint8 * gram, * grom;                                                  // Allocate RAM & ROM pointers
-uint8 gram1[0x10000], gram2[0x10000], grom1[0x10000], grom2[0x10000];  // Actual memory
-uint8 grom3[0x8000], grom4[0x8000], data_rom[0x40000], spr_rom[0x80000], voice_rom[0x20000];
-uint8 chr_rom[0x60000];                                                        // Character ROM pointer
+uint8_t * gram, * grom;                                // Allocate RAM & ROM pointers
+uint8_t gram1[0x10000], gram2[0x10000], grom1[0x10000], grom2[0x10000];        // Actual memory
+uint8_t grom3[0x8000], grom4[0x8000], data_rom[0x40000], spr_rom[0x80000], voice_rom[0x20000];
+uint8_t 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_t banksw1, banksw2;                     // Bank switch addresses
+uint16_t game_over_switch;                     // Game over delay
+uint16_t 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_t 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 };
-uint8 * psg_adrs[16];
-uint32 voc_lens[32] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+uint32_t psg_lens[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+uint8_t * psg_adrs[16];
+uint32_t voc_lens[32] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-uint8 * voc_adrs[32];
-uint32 fm_lens[14] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-uint8 * fm_adrs[14];
+uint8_t * voc_adrs[32];
+uint32_t fm_lens[14] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+uint8_t * fm_adrs[14];
 
-fstream tr;    // Tracelog hook
-uint16 pcx;   // Where we at?
+fstream tr;                                                    // Tracelog hook
+uint16_t pcx;                                          // Where we at?
 
-static uint8 * keys;                                                   // SDL raw keyboard matrix
+static uint8_t * keys;                         // SDL raw keyboard matrix
 
 static char op_mat1[256] = {
   1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
@@ -284,12 +256,13 @@ tregs[16][3] = {
   "A",  "B", "CC", "DP", "??", "??", "??", "??" },
 iregs[4][2] = {"X", "Y", "U", "S" };
 
+
 //
 // Read a byte from memory (without touching PC. Not a Fetch!)
 //
-uint8 RdMem(uint16 addr)
+uint8_t RdMem(uint16_t addr)
 {
-       uint8 b;
+       uint8_t b;
 
        // $4000-4300 is RAM shared with the microcontroller...
 
@@ -306,22 +279,23 @@ uint8 RdMem(uint16 addr)
        return b;
 }
 
+
 //
 // Write a byte to memory
 //
-void WrMem(uint16 addr, uint8 b)
+void WrMem(uint16_t addr, uint8_t 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;
+  //extern uint16_t sr, ur, xr, yr;            // Needed for tracelog
+  //extern uint16_t pcr;
 /*  if ((addr>0x40FF) && (addr<0x4390))
   {
     tr << hex << addr << ":" << (int)b;
     //for(int i=0; i<32; i++)
     //{
     //  if (gram1[0x4400+i]<0x10)  tr << "0";
-    //  tr << hex << (uint16)gram1[0x4400+i] << " ";
+    //  tr << hex << (uint16_t)gram1[0x4400+i] << " ";
     //}
     tr << endl;
   }//*/
@@ -337,7 +311,7 @@ void WrMem(uint16 addr, uint8 b)
        if (addr == 0x6400)
                SpawnSound(GAMESOUND, gram1[0x6600], 1);                // Do voice chan 2
        if (addr == 0x6800)
-               banksw1 = (uint32)b << 13;                                              // Set char data bankswitch base address
+               banksw1 = (uint32_t)b << 13;                                            // Set char data bankswitch base address
        if (addr > 0x4284 && addr < 0x42A5 && b)
                SpawnSound(PSGSOUND, addr - 0x4285);                    // Do PSG sound on chans 2, 3
        if (addr == 0x4380)
@@ -369,13 +343,14 @@ void WrMem(uint16 addr, uint8 b)
        }
 }
 
+
 //
 // Read a byte from memory (without touching PC. Not a Fetch!) (2nd processor)
 //
-uint8 RdMemB(uint16 addr)
+uint8_t RdMemB(uint16_t addr)
 {
-//  extern uint16 cpu2.s, cpu2.u, cpu2.x, cpu2.y;            // Needed for tracelog
-       uint8 b;
+//  extern uint16_t cpu2.s, cpu2.u, cpu2.x, cpu2.y;            // Needed for tracelog
+       uint8_t b;
 
        if (addr < 0x8000)
        {
@@ -399,22 +374,23 @@ uint8 RdMemB(uint16 addr)
        return b;
 }
 
+
 //
 // Write a byte to memory (2nd processor)
 //
-void WrMemB(uint16 addr, uint8 b)
+void WrMemB(uint16_t addr, uint8_t b)
 {
        extern bool disasm;
        extern bool charbase;
-  //extern uint16 sr, ur, xr, yr;            // Needed for tracelog
-  //extern uint16 pcr;
+  //extern uint16_t sr, ur, xr, yr;            // Needed for tracelog
+  //extern uint16_t pcr;
 /*  if ((addr>0x00FF) && (addr<0x0390))
   {
     tr << hex << addr << ":" << (int)b;
     //for(int i=0; i<32; i++)
     //{
     //  if (gram1[0x4400+i]<0x10)  tr << "0";
-    //  tr << hex << (uint16)gram1[0x4400+i] << " ";
+    //  tr << hex << (uint16_t)gram1[0x4400+i] << " ";
     //}
     tr << endl;
   }//*/
@@ -432,7 +408,7 @@ void WrMemB(uint16 addr, uint8 b)
        if (addr > 0x0284 && addr < 0x02A5 && b)
                SpawnSound(PSGSOUND, addr - 0x0285);                    // Do PSG sound on chans 2, 3
        if (addr == 0xD803)
-               banksw2 = (uint32)(b & 0x03) << 13;                             // Set sprite data bank switch
+               banksw2 = (uint32_t)(b & 0x03) << 13;                           // Set sprite data bank switch
        if (addr == 0x0380)
        {
                SpawnSound(FMSOUND, b);                                                 // Do FM sound on chan 4
@@ -459,412 +435,462 @@ void WrMemB(uint16 addr, uint8 b)
        }
 }
 
+
 //
 // Display bytes in mem in hex
 //
-void DisplayBytes(uint16 src, unsigned long dst)
+void DisplayBytes(uint16_t src, unsigned long dst)
 {
-  uint8 cnt;
-  unsigned long i;
+       uint8_t cnt = 0;
+       WriteLog("%04X: ", src);
 
-  WriteLog("%04X: ", src);
-  cnt = 0;                               // Init counter...
-  if (src > dst)  dst += 0x10000;        // That should fix the FFFF bug...
-  for(i=src; i<dst; i++)
-  {
-    WriteLog("%02X ", (uint8)(looking_at_rom ? RdMem(i) : RdMemB(i)));
-    cnt++;                               // Bump counter...
-  }
-  for(i=cnt; i<5; i++)                   // Pad the leftover spaces...
-  {
-    WriteLog("   ");
-  }
+       if (src > dst)
+               dst += 0x10000;        // That should fix the FFFF bug...
+
+       for(unsigned long i=src; i<dst; i++)
+       {
+               WriteLog("%02X ", (uint8_t)(looking_at_rom ? RdMem(i) : RdMemB(i)));
+               cnt++;
+       }
+
+       // Pad the leftover spaces...
+       for(unsigned long i=cnt; i<5; i++)
+               WriteLog("   ");
 }
 
+
 // temp crap...
-uint8 Fetch(void) { return RdMem(dpc); }
-uint16 FetchW(void) { return (uint16)((RdMem(dpc) << 8) | RdMem(dpc+1)); }
-uint8 FetchB(void) { return RdMemB(dpc); }
-uint16 FetchWB(void) { return (uint16)((RdMemB(dpc) << 8) | RdMemB(dpc+1)); }
+uint8_t Fetch(void) { return RdMem(dpc); }
+uint16_t FetchW(void) { return (uint16_t)((RdMem(dpc) << 8) | RdMem(dpc+1)); }
+uint8_t FetchB(void) { return RdMemB(dpc); }
+uint16_t FetchWB(void) { return (uint16_t)((RdMemB(dpc) << 8) | RdMemB(dpc+1)); }
+
 
 //
 // Decode a 6809 instruction at 'addr'
 //
 void Decode_6809()
 {
-  uint8 (* DFetch)();           // Decode Fetch() pointer...
-  uint16 (* DFetchW)();          // Decode FetchW() pointer...
-  DFetch  = (looking_at_rom ? Fetch : FetchB);
-  DFetchW = (looking_at_rom ? FetchW : FetchWB);
-
-/*  extern*/ uint16 pcr, pcrB;              // Pull in 'pcr' from '6809.cpp'
-  uint16 pc_save = pcr, pcB_save = pcrB;
-  pcr  = dpc;  pcrB = dpc;
-  uint8 opcode = DFetch();             // Get the opcode ('fetch' cycle)
-  uint8 opcode2, operand;
-  uint16 loperand;
-  uint8 admode = op_mat1[opcode];     // addressing mode
-  char outbuf[80], mnem[6], tmp[30];
-
-  strcpy(mnem, mnemonics[opcode]);  // Copy page 1 opcode
-  if (opcode == 0x10)             // Extended opcode?
-  {
-    opcode2 = DFetch();     // Then get next byte
-    admode = op_mat2[opcode2];    // And use it as index into 'op_mat2'
-    strcpy(mnem, mnemonics2[opcode2]);  // Overwrite mnemonic
-  }
-  if (opcode == 0x11)             // Same as above...
-  {
-    opcode2 = DFetch();
-    admode = op_mat3[opcode2];
-    strcpy(mnem, mnemonics3[opcode2]);  // Overwrite mnemonic
-  }
-  switch(admode)                  // Decode it...
-  {
-    case 0:  // Illegal
-    { sprintf(outbuf, "???");  break; }
-    case 1:  // Zero page
-    { operand = DFetch();   // Get ZP address
-      sprintf(outbuf, "%s $%02X", mnem, operand);
-      break; }
-    case 2:  // Absolute
-    { loperand = DFetchW(); // Get ABS address
-      sprintf(outbuf, "%s $%04X", mnem, loperand);
-      break; }
-    case 3:  // Relative
-    { operand = DFetch();   // Get offset
-      uint16 tmpc = (looking_at_rom ? pcr : pcrB);
-      sprintf(outbuf, "%s $%04X", mnem, tmpc+(int16)(int8)operand);
-      break; }
-    case 4:  // Long Relative
-    { loperand = DFetchW(); // Get long offset
-      uint16 tmpc = (looking_at_rom ? pcr : pcrB);
-      sprintf(outbuf, "%s $%04X", mnem, tmpc+(int16)loperand);
-      break; }
-    case 5:  // Inherent
-    { sprintf(outbuf, "%s ", mnem);
-      break; }
-    case 6:  // Txfr/exchg/push/pull
-    { operand = DFetch();   // Get txfr/exg/push/pull byte
-      if ((opcode == 0x1E) || (opcode == 0x1F))  // Is it TXF/EXG?
-      {
-        sprintf(tmp, "%s,%s", tregs[operand>>4], tregs[operand&0x0F]);
-      }
-      else
-      {
-        tmp[0] = 0;
-        if (operand&0x01)  strcat(tmp, "CC ");
-        if (operand&0x02)  strcat(tmp, "A ");
-        if (operand&0x04)  strcat(tmp, "B ");
-        if (operand&0x08)  strcat(tmp, "DP ");
-        if (operand&0x10)  strcat(tmp, "X ");
-        if (operand&0x20)  strcat(tmp, "Y ");
-        if (operand&0x40)  (((opcode==0x34)||(opcode==0x35))
-                       ? strcat(tmp, "U ") : strcat(tmp, "S "));
-        if (operand&0x80)  strcat(tmp, "PC");
-      }
-      sprintf(outbuf, "%s %s", mnem, tmp);
-      break; }
-    case 7:  // Indexed (the tough one!)
-    { operand = DFetch();   // Get IDX byte
-      uint8 reg = ((operand & 0x60) >> 5), idxind = ((operand & 0x10) >> 4),
-           lo_nyb = (operand & 0x0F),  boff;
-      uint16 woff;
-
-      strcpy(tmp, "??");
-      if (!(operand & 0x80))      // Hi bit set? Then decode 4 bit offset
-      {
-        sprintf(tmp, "(%d),%s", (idxind ? -(16-lo_nyb) : lo_nyb),
-                iregs[reg]);
-      }
-      else   // Add the ($nnnn,R) code dude...
-      {
-        if (idxind)
-        {
-          switch(lo_nyb)
-          {
-            case 1:   sprintf(tmp, "(,%s++)", iregs[reg]);  break;
-            case 3:   sprintf(tmp, "(,--%s)", iregs[reg]);  break;
-            case 4:   sprintf(tmp, "(,%s)", iregs[reg]);  break;
-            case 5:   sprintf(tmp, "(B,%s)", iregs[reg]);  break;
-            case 6:   sprintf(tmp, "(A,%s)", iregs[reg]);  break;
-            case 8:
-            { boff = DFetch();  sprintf(tmp, "($%02X,%s)", boff,
-                                       iregs[reg]);  break; }
-            case 9:
-            { woff = DFetchW();  sprintf(tmp, "($%04X,%s)", woff,
-                                        iregs[reg]);  break; }
-            case 11:  sprintf(tmp, "(D,%s)", iregs[reg]);  break;
-            case 12:
-            { boff = DFetch();  sprintf(tmp, "($%02X,PC)", boff);  break; }
-            case 13:
-            { woff = DFetchW();  sprintf(tmp, "($%04X,PC)", woff);  break; }
-            case 15:
-            { woff = DFetchW();  sprintf(tmp, "[$%04X]", woff);  break; }
-            default:  strcpy(tmp, "??");
-          }
-        }
-        else
-        {
-          switch(lo_nyb)
-          {
-            case 0:   sprintf(tmp, ",%s+", iregs[reg]);  break;
-            case 1:   sprintf(tmp, ",%s++", iregs[reg]);  break;
-            case 2:   sprintf(tmp, ",-%s", iregs[reg]);  break;
-            case 3:   sprintf(tmp, ",--%s", iregs[reg]);  break;
-            case 4:   sprintf(tmp, ",%s", iregs[reg]);  break;
-            case 5:   sprintf(tmp, "(B),%s", iregs[reg]);  break;
-            case 6:   sprintf(tmp, "(A),%s", iregs[reg]);  break;
-            case 8:
-            { boff = DFetch();  sprintf(tmp, "($%02X),%s", boff,
-                                       iregs[reg]);  break; }
-            case 9:
-            { woff = DFetchW();  sprintf(tmp, "($%04X),%s", woff,
-                                       iregs[reg]);  break; }
-            case 11:  sprintf(tmp, "(D),%s", iregs[reg]);  break;
-            case 12:
-            { boff = DFetch();  sprintf(tmp, "($%02X),PC", boff);  break; }
-            case 13:
-            { woff = DFetchW();  sprintf(tmp, "($%04X),PC", woff);  break; }
-            default:  strcpy(tmp, "??");
-          }
-        }
-      }
-      sprintf(outbuf, "%s %s", mnem, tmp);
-      break; }
-    case 8:  // Immediate
-    { operand = DFetch();   // Get IMM byte
-      sprintf(outbuf, "%s #$%02X", mnem, operand);
-      break; }
-    case 9:  // Long Immediate
-    { loperand = DFetchW(); // Get IMM word
-      sprintf(outbuf, "%s #$%04X", mnem, loperand);
-      break; }
-  }
-  DisplayBytes(dpc, (looking_at_rom ? pcr : pcrB));  // Show bytes
-  WriteLog(outbuf); WriteLog("\n");     // display opcode & addressing, etc
-  dpc = (looking_at_rom ? pcr : pcrB);  // Advance debug PC
-  pcr = pc_save;  pcrB = pcB_save;  // Restore PCs
+       uint8_t (* DFetch)();           // Decode Fetch() pointer...
+       uint16_t (* DFetchW)();          // Decode FetchW() pointer...
+       DFetch  = (looking_at_rom ? Fetch : FetchB);
+       DFetchW = (looking_at_rom ? FetchW : FetchWB);
+
+       /*  extern*/ uint16_t pcr, pcrB;              // Pull in 'pcr' from '6809.cpp'
+       uint16_t pc_save = pcr, pcB_save = pcrB;
+       pcr  = dpc;  pcrB = dpc;
+       uint8_t opcode = DFetch();             // Get the opcode ('fetch' cycle)
+       uint8_t opcode2, operand;
+       uint16_t loperand;
+       uint8_t admode = op_mat1[opcode];     // addressing mode
+       char outbuf[80], mnem[6], tmp[30];
+
+       strcpy(mnem, mnemonics[opcode]);  // Copy page 1 opcode
+
+       if (opcode == 0x10)             // Extended opcode?
+       {
+               opcode2 = DFetch();     // Then get next byte
+               admode = op_mat2[opcode2];    // And use it as index into 'op_mat2'
+               strcpy(mnem, mnemonics2[opcode2]);  // Overwrite mnemonic
+       }
+
+       if (opcode == 0x11)             // Same as above...
+       {
+               opcode2 = DFetch();
+               admode = op_mat3[opcode2];
+               strcpy(mnem, mnemonics3[opcode2]);  // Overwrite mnemonic
+       }
+
+       // Decode it...
+       switch (admode)
+       {
+       case 0:  // Illegal
+               sprintf(outbuf, "???");
+               break;
+       case 1:  // Zero page
+               operand = DFetch();   // Get ZP address
+               sprintf(outbuf, "%s $%02X", mnem, operand);
+               break;
+       case 2:  // Absolute
+               loperand = DFetchW(); // Get ABS address
+               sprintf(outbuf, "%s $%04X", mnem, loperand);
+               break;
+       case 3:  // Relative
+       {
+               operand = DFetch();   // Get offset
+               uint16_t tmpc = (looking_at_rom ? pcr : pcrB);
+               sprintf(outbuf, "%s $%04X", mnem, tmpc+(int16_t)(int8_t)operand);
+               break;
+       }
+       case 4:  // Long Relative
+       {
+               loperand = DFetchW(); // Get long offset
+               uint16_t tmpc = (looking_at_rom ? pcr : pcrB);
+               sprintf(outbuf, "%s $%04X", mnem, tmpc+(int16_t)loperand);
+               break;
+       }
+       case 5:  // Inherent
+               sprintf(outbuf, "%s ", mnem);
+               break;
+       case 6:  // Txfr/exchg/push/pull
+       {
+               operand = DFetch();   // Get txfr/exg/push/pull byte
+
+               if ((opcode == 0x1E) || (opcode == 0x1F))  // Is it TXF/EXG?
+               {
+                       sprintf(tmp, "%s,%s", tregs[operand>>4], tregs[operand&0x0F]);
+               }
+               else
+               {
+                       tmp[0] = 0;
+                       if (operand&0x01)  strcat(tmp, "CC ");
+                       if (operand&0x02)  strcat(tmp, "A ");
+                       if (operand&0x04)  strcat(tmp, "B ");
+                       if (operand&0x08)  strcat(tmp, "DP ");
+                       if (operand&0x10)  strcat(tmp, "X ");
+                       if (operand&0x20)  strcat(tmp, "Y ");
+                       if (operand&0x40)  (((opcode==0x34)||(opcode==0x35))
+                                               ? strcat(tmp, "U ") : strcat(tmp, "S "));
+                       if (operand&0x80)  strcat(tmp, "PC");
+               }
+               sprintf(outbuf, "%s %s", mnem, tmp);
+               break;
+       }
+       case 7:  // Indexed (the tough one!)
+       {
+               operand = DFetch();   // Get IDX byte
+               uint8_t reg = ((operand & 0x60) >> 5), idxind = ((operand & 0x10) >> 4),
+                       lo_nyb = (operand & 0x0F),  boff;
+               uint16_t woff;
+
+               strcpy(tmp, "??");
+
+               if (!(operand & 0x80))      // Hi bit set? Then decode 4 bit offset
+               {
+                       sprintf(tmp, "(%d),%s", (idxind ? -(16-lo_nyb) : lo_nyb),
+                                       iregs[reg]);
+               }
+               else   // Add the ($nnnn,R) code dude...
+               {
+                       if (idxind)
+                       {
+                               switch (lo_nyb)
+                               {
+                               case 1:   sprintf(tmp, "(,%s++)", iregs[reg]);  break;
+                               case 3:   sprintf(tmp, "(,--%s)", iregs[reg]);  break;
+                               case 4:   sprintf(tmp, "(,%s)", iregs[reg]);  break;
+                               case 5:   sprintf(tmp, "(B,%s)", iregs[reg]);  break;
+                               case 6:   sprintf(tmp, "(A,%s)", iregs[reg]);  break;
+                               case 8:
+                               { boff = DFetch();  sprintf(tmp, "($%02X,%s)", boff,
+                                                                               iregs[reg]);  break; }
+                               case 9:
+                               { woff = DFetchW();  sprintf(tmp, "($%04X,%s)", woff,
+                                                                                       iregs[reg]);  break; }
+                               case 11:  sprintf(tmp, "(D,%s)", iregs[reg]);  break;
+                               case 12:
+                               { boff = DFetch();  sprintf(tmp, "($%02X,PC)", boff);  break; }
+                               case 13:
+                               { woff = DFetchW();  sprintf(tmp, "($%04X,PC)", woff);  break; }
+                               case 15:
+                               { woff = DFetchW();  sprintf(tmp, "[$%04X]", woff);  break; }
+                               default:  strcpy(tmp, "??");
+                               }
+                       }
+                       else
+                       {
+                               switch (lo_nyb)
+                               {
+                               case 0:   sprintf(tmp, ",%s+", iregs[reg]);  break;
+                               case 1:   sprintf(tmp, ",%s++", iregs[reg]);  break;
+                               case 2:   sprintf(tmp, ",-%s", iregs[reg]);  break;
+                               case 3:   sprintf(tmp, ",--%s", iregs[reg]);  break;
+                               case 4:   sprintf(tmp, ",%s", iregs[reg]);  break;
+                               case 5:   sprintf(tmp, "(B),%s", iregs[reg]);  break;
+                               case 6:   sprintf(tmp, "(A),%s", iregs[reg]);  break;
+                               case 8:
+                               { boff = DFetch();  sprintf(tmp, "($%02X),%s", boff,
+                                                                               iregs[reg]);  break; }
+                               case 9:
+                               { woff = DFetchW();  sprintf(tmp, "($%04X),%s", woff,
+                                                                               iregs[reg]);  break; }
+                               case 11:  sprintf(tmp, "(D),%s", iregs[reg]);  break;
+                               case 12:
+                               { boff = DFetch();  sprintf(tmp, "($%02X),PC", boff);  break; }
+                               case 13:
+                               { woff = DFetchW();  sprintf(tmp, "($%04X),PC", woff);  break; }
+                               default:  strcpy(tmp, "??");
+                               }
+                       }
+               }
+
+               sprintf(outbuf, "%s %s", mnem, tmp);
+               break;
+       }
+       case 8:  // Immediate
+               operand = DFetch();   // Get IMM byte
+               sprintf(outbuf, "%s #$%02X", mnem, operand);
+               break;
+       case 9:  // Long Immediate
+               loperand = DFetchW(); // Get IMM word
+               sprintf(outbuf, "%s #$%04X", mnem, loperand);
+               break;
+       }
+
+       DisplayBytes(dpc, (looking_at_rom ? pcr : pcrB));  // Show bytes
+       WriteLog(outbuf);
+       WriteLog("\n");     // display opcode & addressing, etc
+       dpc = (looking_at_rom ? pcr : pcrB);  // Advance debug PC
+       pcr = pc_save;
+       pcrB = pcB_save;  // Restore PCs
 }
 
+
 //
 // Convert hex to dec
 //
-uint16 htod(char *str)
+uint16_t htod(char * str)
 {
-  uint16 value = 0;
-  int len = strlen(str);
+       uint16_t value = 0;
+       int len = strlen(str);
 
-  for(int i=0; i<len; i++)
-  {
-    if (str[i]>='0' && str[i]<='9')
-    {
-      value = (value<<4) | (unsigned)(str[i]-'0');
-    }
-    if (str[i]>='a' && str[i]<='f')
-    {
-      value = (value<<4) | (unsigned)(str[i]-'a')+10;
-    }
-    if (str[i]>='A' && str[i]<='F')
-    {
-      value = (value<<4) | (unsigned)(str[i]-'A')+10;
-    }
-  }
-  return(value);
+       for(int i=0; i<len; i++)
+       {
+               if (str[i] >= '0' && str[i] <= '9')
+               {
+                       value = (value << 4) | (unsigned)(str[i] - '0');
+               }
+               else if (str[i] >= 'a' && str[i] <= 'f')
+               {
+                       value = (value << 4) | (unsigned)((str[i] - 'a') + 10);
+               }
+               else if (str[i] >= 'A' && str[i] <= 'F')
+               {
+                       value = (value << 4) | (unsigned)((str[i] - 'A') + 10);
+               }
+       }
+
+       return value;
 }
 
+
 //
 // Load 32K file into ROM image space
 //
-bool Load32KImg(char * filename, uint16 address)
+bool Load32KImg(char * filename, uint16_t address)
 {
-  ifstream ff;
-  char ch;
+       ifstream ff;
+       char ch;
 
-  ff.open(filename, ios::binary | ios::in);  // Open 'da file...
-  if (ff)
-  {
-    for(long i=0; i<32768; i++)                // Read it in...
-    {
-      ff.get(ch);
-      grom[address+i] = ch;
-    }
-    ff.close();                                // Close 'da file...
-  }
-  return(ff);
+       ff.open(filename, ios::binary | ios::in);  // Open 'da file...
+
+       if (ff)
+       {
+               for(long i=0; i<32768; i++)                // Read it in...
+               {
+                       ff.get(ch);
+                       grom[address+i] = ch;
+               }
+
+               ff.close();                                // Close 'da file...
+       }
+
+       return ff;
 }
 
+
 //
 // Generic Load file into image space
 // (No error checking performed!  Responsibility of caller!)
 //
-bool LoadImg(const char * filename, uint8 * mem, uint32 address, uint32 length)
+bool LoadImg(const char * filename, uint8_t * mem, uint32_t address, uint32_t length)
 {
-  ifstream ff;
-  char path[80];
-  char ch;
+       ifstream ff;
+       char path[80];
+       char ch;
 
-  strcpy(path, "./ROMs/");
-  strcat(path, filename);
+       strcpy(path, "./ROMs/");
+       strcat(path, filename);
 //  ff.open(filename, ios::binary | ios::in);  // Open 'da file...
-  ff.open(path, ios::binary | ios::in);       // Open 'da file...
-  if (ff)
-  {
-    for(uint32 i=0; i<length; i++)             // Read it in...
-    {
-      ff.get(ch);
-      mem[address+i] = ch;
-    }
-    ff.close();                               // Close 'da file...
-  }
-  return(ff);
+       ff.open(path, ios::binary | ios::in);       // Open 'da file...
+
+       if (ff)
+       {
+               for(uint32_t i=0; i<length; i++)             // Read it in...
+               {
+                       ff.get(ch);
+                       mem[address+i] = ch;
+               }
+
+               ff.close();                               // Close 'da file...
+       }
+
+       return ff;
 }
 
+
 //
 // Read color PROMs
 //
 bool ReadColorPROMs(void)
 {
-  fstream ff1, ff2;
-//  uint8 ch;
-  char ch;
-  extern uint8 palette[768];     // Screen physical palette
-  extern uint8 ccolor[256][8];   // Character color PROM values
-  extern uint8 scolor[128][16];  // Sprite color PROM values
-
-  ff1.open("./ROMs/"PROM3, ios::binary|ios::in);
-  if (ff1)
-  {
-    for(int i=0; i<256; i++) // Load char pallete with PROM values
-    {
-      for(int j=0; j<8; j++)
-      {
-        ff1.get(ch);
-        ccolor[i][j] = (uint8)ch;
-      }
-    }
-    ff1.close();
-  }
-  ff1.open("./ROMs/"PROM4, ios::binary|ios::in);
-  if (ff1)
-  {
-    for(int i=0; i<128; i++) // Load sprite pallete with PROM values
-    {
-      for(int j=0; j<16; j++)
-      {
-        ff1.get(ch);
-        scolor[i][j] = (uint8)ch;
-      }
-    }
-    ff1.close();
-  }
-
-  ff1.open("./ROMs/"PROM1, ios::binary|ios::in);
-  ff2.open("./ROMs/"PROM2, ios::binary|ios::in);
-  if (ff1)    // If open was successful...
-  {
-    for(int i=0; i<768; i+=3)
-    {
-      ff1.get(ch);
-      palette[i]   = (uint8)(ch&0x0F);
-      palette[i+1] = (uint8)(ch>>4);
-      ff2.get(ch);
-      palette[i+2] = (uint8)ch;
-    }
-
-    // Do palette stretching here... I.e. add 0 to hinyb 0, 1 to hinyb 1, etc.
-
-    for(int i=0; i<768; i++)
-      palette[i] = ((palette[i]<<4)&0xF0) | (palette[i]&0x0F);
-
-    ff1.close();
-    ff2.close();
-  }
-  return ff1;
+       fstream ff1, ff2;
+       //  uint8_t ch;
+       char ch;
+       extern uint8_t palette[768];     // Screen physical palette
+       extern uint8_t ccolor[256][8];   // Character color PROM values
+       extern uint8_t scolor[128][16];  // Sprite color PROM values
+
+       ff1.open("./ROMs/"PROM3, ios::binary|ios::in);
+
+       if (ff1)
+       {
+               for(int i=0; i<256; i++) // Load char pallete with PROM values
+               {
+                       for(int j=0; j<8; j++)
+                       {
+                               ff1.get(ch);
+                               ccolor[i][j] = (uint8_t)ch;
+                       }
+               }
+
+               ff1.close();
+       }
+
+       ff1.open("./ROMs/"PROM4, ios::binary|ios::in);
+
+       if (ff1)
+       {
+               for(int i=0; i<128; i++) // Load sprite pallete with PROM values
+               {
+                       for(int j=0; j<16; j++)
+                       {
+                               ff1.get(ch);
+                               scolor[i][j] = (uint8_t)ch;
+                       }
+               }
+
+               ff1.close();
+       }
+
+       ff1.open("./ROMs/"PROM1, ios::binary|ios::in);
+       ff2.open("./ROMs/"PROM2, ios::binary|ios::in);
+
+       if (ff1)    // If open was successful...
+       {
+               for(int i=0; i<768; i+=3)
+               {
+                       ff1.get(ch);
+                       palette[i]   = (uint8_t)(ch&0x0F);
+                       palette[i+1] = (uint8_t)(ch>>4);
+                       ff2.get(ch);
+                       palette[i+2] = (uint8_t)ch;
+               }
+
+               // Do palette stretching here... I.e. add 0 to hinyb 0, 1 to hinyb 1, etc.
+
+               for(int i=0; i<768; i++)
+               palette[i] = ((palette[i]<<4)&0xF0) | (palette[i]&0x0F);
+
+               ff1.close();
+               ff2.close();
+       }
+
+       return ff1;
 }
 
+
 //
 // Unpack font data
 //
 bool UnpackFonts(void)
 {
-//  uint8 b1, b2, b3;
-  char b1, b2, b3;
-  fstream f1, f2;
-  //0x4000 $800 chars
-  f1.open("./ROMs/"ROM7, ios::binary | ios::in);
-  f2.open("./ROMs/"ROM8, ios::binary | ios::in);
-  if ((!f1) || (!f2))  return false;  // Return if not found...
-  for(long i=0; i<0x40000; i+=64)
-  {
-    for(int j=0; j<64; j+=8)
-    {
-      f1.get(b1);  f1.get(b2);  f2.get(b3);
-      b3 ^= 0xFF; // Invert top data...
-      chr_rom[i+j] = ((b3 & 0x80) >> 5) | ((b1 & 0x80) >> 6) | ((b1 & 0x08) >> 3);
-      chr_rom[i+j+1] = ((b3 & 0x40) >> 4) | ((b1 & 0x40) >> 5) | ((b1 & 0x04) >> 2);
-      chr_rom[i+j+2] = ((b3 & 0x20) >> 3) | ((b1 & 0x20) >> 4) | ((b1 & 0x02) >> 1);
-      chr_rom[i+j+3] = ((b3 & 0x10) >> 2) | ((b1 & 0x10) >> 3) | (b1 & 0x01);
-      chr_rom[i+j+4] = ((b3 & 0x08) >> 1) | ((b2 & 0x80) >> 6) | ((b2 & 0x08) >> 3);
-      chr_rom[i+j+5] = (b3 & 0x04)        | ((b2 & 0x40) >> 5) | ((b2 & 0x04) >> 2);
-      chr_rom[i+j+6] = ((b3 & 0x02) << 1) | ((b2 & 0x20) >> 4) | ((b2 & 0x02) >> 1);
-      chr_rom[i+j+7] = ((b3 & 0x01) << 2) | ((b2 & 0x10) >> 3) | (b2 & 0x01);
-    }
-  }
-  f1.close();
-  f2.close();
-
-  f1.open("./ROMs/"ROM5, ios::binary | ios::in);
-  f2.open("./ROMs/"ROM6, ios::binary | ios::in);
-  for(long i=0x40000; i<0x60000; i+=64)
-  {
-    for(int j=0; j<64; j+=8)
-    {
-      f1.get(b1);  f1.get(b2);  f2.get(b3);
-      b3 ^= 0xFF;                             // Invert top data
-      chr_rom[i+j] = ((b3 & 0x80) >> 5) | ((b1 & 0x80) >> 6) | ((b1 & 0x08) >> 3);
-      chr_rom[i+j+1] = ((b3 & 0x40) >> 4) | ((b1 & 0x40) >> 5) | ((b1 & 0x04) >> 2);
-      chr_rom[i+j+2] = ((b3 & 0x20) >> 3) | ((b1 & 0x20) >> 4) | ((b1 & 0x02) >> 1);
-      chr_rom[i+j+3] = ((b3 & 0x10) >> 2) | ((b1 & 0x10) >> 3) | (b1 & 0x01);
-      chr_rom[i+j+4] = ((b3 & 0x08) >> 1) | ((b2 & 0x80) >> 6) | ((b2 & 0x08) >> 3);
-      chr_rom[i+j+5] = (b3 & 0x04)        | ((b2 & 0x40) >> 5) | ((b2 & 0x04) >> 2);
-      chr_rom[i+j+6] = ((b3 & 0x02) << 1) | ((b2 & 0x20) >> 4) | ((b2 & 0x02) >> 1);
-      chr_rom[i+j+7] = ((b3 & 0x01) << 2) | ((b2 & 0x10) >> 3) | (b2 & 0x01);
-    }
-  }
-  f1.close();
-  f2.close();
-  return true;                                // Made it!
+//  uint8_t b1, b2, b3;
+       char b1, b2, b3;
+       fstream f1, f2;
+       //0x4000 $800 chars
+       f1.open("./ROMs/"ROM7, ios::binary | ios::in);
+       f2.open("./ROMs/"ROM8, ios::binary | ios::in);
+
+       if ((!f1) || (!f2))
+               return false;  // Return if not found...
+
+       for(long i=0; i<0x40000; i+=64)
+       {
+               for(int j=0; j<64; j+=8)
+               {
+                       f1.get(b1);  f1.get(b2);  f2.get(b3);
+                       b3 ^= 0xFF; // Invert top data...
+                       chr_rom[i+j] = ((b3 & 0x80) >> 5) | ((b1 & 0x80) >> 6) | ((b1 & 0x08) >> 3);
+                       chr_rom[i+j+1] = ((b3 & 0x40) >> 4) | ((b1 & 0x40) >> 5) | ((b1 & 0x04) >> 2);
+                       chr_rom[i+j+2] = ((b3 & 0x20) >> 3) | ((b1 & 0x20) >> 4) | ((b1 & 0x02) >> 1);
+                       chr_rom[i+j+3] = ((b3 & 0x10) >> 2) | ((b1 & 0x10) >> 3) | (b1 & 0x01);
+                       chr_rom[i+j+4] = ((b3 & 0x08) >> 1) | ((b2 & 0x80) >> 6) | ((b2 & 0x08) >> 3);
+                       chr_rom[i+j+5] = (b3 & 0x04)        | ((b2 & 0x40) >> 5) | ((b2 & 0x04) >> 2);
+                       chr_rom[i+j+6] = ((b3 & 0x02) << 1) | ((b2 & 0x20) >> 4) | ((b2 & 0x02) >> 1);
+                       chr_rom[i+j+7] = ((b3 & 0x01) << 2) | ((b2 & 0x10) >> 3) | (b2 & 0x01);
+               }
+       }
+
+       f1.close();
+       f2.close();
+
+       f1.open("./ROMs/"ROM5, ios::binary | ios::in);
+       f2.open("./ROMs/"ROM6, ios::binary | ios::in);
+
+       for(long i=0x40000; i<0x60000; i+=64)
+       {
+               for(int j=0; j<64; j+=8)
+               {
+                       f1.get(b1);  f1.get(b2);  f2.get(b3);
+                       b3 ^= 0xFF;                             // Invert top data
+                       chr_rom[i+j] = ((b3 & 0x80) >> 5) | ((b1 & 0x80) >> 6) | ((b1 & 0x08) >> 3);
+                       chr_rom[i+j+1] = ((b3 & 0x40) >> 4) | ((b1 & 0x40) >> 5) | ((b1 & 0x04) >> 2);
+                       chr_rom[i+j+2] = ((b3 & 0x20) >> 3) | ((b1 & 0x20) >> 4) | ((b1 & 0x02) >> 1);
+                       chr_rom[i+j+3] = ((b3 & 0x10) >> 2) | ((b1 & 0x10) >> 3) | (b1 & 0x01);
+                       chr_rom[i+j+4] = ((b3 & 0x08) >> 1) | ((b2 & 0x80) >> 6) | ((b2 & 0x08) >> 3);
+                       chr_rom[i+j+5] = (b3 & 0x04)        | ((b2 & 0x40) >> 5) | ((b2 & 0x04) >> 2);
+                       chr_rom[i+j+6] = ((b3 & 0x02) << 1) | ((b2 & 0x20) >> 4) | ((b2 & 0x02) >> 1);
+                       chr_rom[i+j+7] = ((b3 & 0x01) << 2) | ((b2 & 0x10) >> 3) | (b2 & 0x01);
+               }
+       }
+
+       f1.close();
+       f2.close();
+
+       return true;                                // Made it!
 }
 
+
 //
 // Get length of sample from WAV format
 //
-uint32 GetWAVLength(fstream &file)
+uint32_t GetWAVLength(fstream & file)
 {
        char ch;
-       uint32 len;
+       uint32_t len;
 
        file.ignore(16);                                                                        // Skip header BS
 
        for(int i=0; i<2; i++)
        {
-               file.get(ch);  len = (int)(uint8)ch;
-               file.get(ch);  len |= (int)(uint8)ch << 8;
-               file.get(ch);  len |= (int)(uint8)ch << 16;
-               file.get(ch);  len |= (int)(uint8)ch << 24;
+               file.get(ch);  len = (int)(uint8_t)ch;
+               file.get(ch);  len |= (int)(uint8_t)ch << 8;
+               file.get(ch);  len |= (int)(uint8_t)ch << 16;
+               file.get(ch);  len |= (int)(uint8_t)ch << 24;
 
                file.ignore(len + 4);                                                   // Skip intermediate data
        }
 
-       file.get(ch);  len = (int)(uint8)ch;                                    // & finally get length of data
-       file.get(ch);  len |= (int)(uint8)ch << 8;
-       file.get(ch);  len |= (int)(uint8)ch << 16;
-       file.get(ch);  len |= (int)(uint8)ch << 24;
+       file.get(ch);  len = (int)(uint8_t)ch;                                  // & finally get length of data
+       file.get(ch);  len |= (int)(uint8_t)ch << 8;
+       file.get(ch);  len |= (int)(uint8_t)ch << 16;
+       file.get(ch);  len |= (int)(uint8_t)ch << 24;
 
        return len;
 }
 
+
 //
 // Load PSG samples from disk
 //
@@ -872,7 +898,7 @@ void LoadPSGs(void)
 {
        char file[40];
        char ch;
-       uint32 len;
+       uint32_t len;
 
        for(int i=0; i<16; i++)
        {
@@ -886,7 +912,7 @@ void LoadPSGs(void)
                if (fp)
                {
                        len = GetWAVLength(fp);                                         // Get WAV data length...
-                       psg_adrs[i] = new uint8[len];                           // Attempt to allocate space...
+                       psg_adrs[i] = new uint8_t[len];                         // Attempt to allocate space...
 
                        if (psg_adrs[i] != NULL)
                        {
@@ -906,6 +932,7 @@ void LoadPSGs(void)
        }
 }
 
+
 //
 // Load FM samples from disk
 //
@@ -913,7 +940,7 @@ void LoadFMs(void)
 {
        char file[200];
        char ch;
-       uint32 len;
+       uint32_t len;
 
        for(int i=0; i<14; i++)
        {
@@ -927,7 +954,7 @@ void LoadFMs(void)
                if (fp)
                {
                        len = GetWAVLength(fp);                                         // Get WAV length...
-                       fm_adrs[i] = new uint8[len];                                    // Attempt to allocate space...
+                       fm_adrs[i] = new uint8_t[len];                                  // Attempt to allocate space...
 
                        if (fm_adrs[i] != NULL)
                        {
@@ -947,6 +974,7 @@ void LoadFMs(void)
        }
 }
 
+
 //
 // Main loop
 //
@@ -958,27 +986,27 @@ extern bool disasm;       // From 'V6809.CPP'
        extern bool charbase;                                           // From 'SCREEN.CPP'
        charbase = false;
 
-  char lbuff[80];
-  fstream ff;                       // Declare fstream without file hooks...
-  bool brk = false, brk2 = false;   // Breakpoint set flag
-  uint16 brkpnt, brkpnt2;             // Where the breakpoint is...
-  bool running;                     // CPU running state flag...
-  bool self_test = false;           // Self-test switch
-  bool scr_type = false;            // false=chars, true=pixels
-  uint16 debounce = 0;                // Key de-bounce counter
-  uint16 fire_debounce = 0;           // Fire button debounce counter
+       char lbuff[80];
+       fstream ff;                       // Declare fstream without file hooks...
+       bool brk = false, brk2 = false;   // Breakpoint set flag
+       uint16_t brkpnt, brkpnt2;             // Where the breakpoint is...
+       bool running;                     // CPU running state flag...
+       bool self_test = false;           // Self-test switch
+       bool scr_type = false;            // false=chars, true=pixels
+       uint16_t debounce = 0;                // Key de-bounce counter
+       uint16_t fire_debounce = 0;           // Fire button debounce counter
 //  bool refresh2 = true;             // Default to 60 Hz...
-  uint8 x;                           // General placeholder...
-  bool active = true;                                          // Program running flag
+       uint8_t x;                           // General placeholder...
+       bool active = true;                                             // Program running flag
 
-  SDL_Event event;                                                             // SDL "event"
-  extern uint8 palette[768];                                   // Screen physical palette
-  uint32 ticks, oldTicks;
+       SDL_Event event;                                                                // SDL "event"
+       extern uint8_t palette[768];                                    // Screen physical palette
+       uint32_t ticks, oldTicks;
 
        cout << endl << "THUNDER v"THUNDER_VERSION" ";
        cout << "by James Hammons" << endl;
-       cout << "Serial #20090723 / Prerelease" << endl;
-       cout << "(C) 2003, 2009 Underground Software" << endl << endl;
+       cout << "Serial #20149404 / Prerelease" << endl;
+       cout << "© 2003, 2014 Underground Software" << endl << endl;
 
        cout << "This emulator is free software. If you paid for it you were RIPPED OFF"
                << endl << endl;
@@ -995,87 +1023,88 @@ extern bool disasm;      // From 'V6809.CPP'
 
        keys = SDL_GetKeyState(NULL);                           // Get the SDL keyboard matrix
 
-  gram = gram1;  grom = grom1;           // Needed only for debugger
+       gram = gram1;  grom = grom1;           // Needed only for debugger
 
-  for(long i=0; i<0x10000; i++)
-  {
-    gram[i] = 0;  grom[i] = 0;           // Zero out memory
-    gram2[i] = 0;  grom2[i] = 0;
-  }
-  game_over_switch = 0;   // Init game over delay
+       for(long i=0; i<0x10000; i++)
+       {
+               gram[i] = 0;  grom[i] = 0;           // Zero out memory
+               gram2[i] = 0;  grom2[i] = 0;
+       }
+
+       game_over_switch = 0;   // Init game over delay
 //  cpu1.a = 0; cpu1.b = 0; cpu1.cc = 0; cpu1.dp = 0; cpu1.x = 0; cpu1.y = 0; cpu1.s = 0; ur = 0; cpu1.pc = 0;
 
-  cout << "Loading ROMs..." << endl;
+       cout << "Loading ROMs..." << endl;
 //  LoadCMOS();                            // Load CMOS at $CC00-$CFFF
-  if (!ReadColorPROMs())                   // Load virtual PROMs
-  { cout << "Could not open PROM files!" << endl;  return -1; }
+       if (!ReadColorPROMs())                   // Load virtual PROMs
+       { cout << "Could not open PROM files!" << endl;  return -1; }
 
-  if (!LoadImg(ROM1, grom1, 0x8000, 0x8000)) // Load $8000-$FFFF 1st ROM
-  { cout << "Could not open file '" << ROM1 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM1, grom1, 0x8000, 0x8000)) // Load $8000-$FFFF 1st ROM
+       { cout << "Could not open file '" << ROM1 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM2, grom2, 0x8000, 0x8000)) // Load $8000-$FFFF 2nd ROM
-  { cout << "Could not open file '" << ROM2 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM2, grom2, 0x8000, 0x8000)) // Load $8000-$FFFF 2nd ROM
+       { cout << "Could not open file '" << ROM2 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM3, grom3, 0, 0x8000))      // Load 3rd ROM into its own space
-  { cout << "Could not open file '" << ROM3 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM3, grom3, 0, 0x8000))      // Load 3rd ROM into its own space
+       { cout << "Could not open file '" << ROM3 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM4, grom4, 0, 0x8000))      // Load 4rd ROM into its own space
-  { cout << "Could not open file '" << ROM4 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM4, grom4, 0, 0x8000))      // Load 4rd ROM into its own space
+       { cout << "Could not open file '" << ROM4 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM17, data_rom, 0,       0x10000))  // Load 17th ROM
-  { cout << "Could not open file '" << ROM17 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM17, data_rom, 0,       0x10000))  // Load 17th ROM
+       { cout << "Could not open file '" << ROM17 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM18, data_rom, 0x10000, 0x10000))  // Load 18th ROM
-  { cout << "Could not open file '" << ROM18 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM18, data_rom, 0x10000, 0x10000))  // Load 18th ROM
+       { cout << "Could not open file '" << ROM18 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM19, data_rom, 0x20000, 0x10000))  // Load 19th ROM
-  { cout << "Could not open file '" << ROM19 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM19, data_rom, 0x20000, 0x10000))  // Load 19th ROM
+       { cout << "Could not open file '" << ROM19 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM20, data_rom, 0x30000, 0x10000))  // Load 20th ROM
-  { cout << "Could not open file '" << ROM20 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM20, data_rom, 0x30000, 0x10000))  // Load 20th ROM
+       { cout << "Could not open file '" << ROM20 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM9,  spr_rom, 0,       0x10000))   // Load 9th ROM
-  { cout << "Could not open file '" << ROM9 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM9,  spr_rom, 0,       0x10000))   // Load 9th ROM
+       { cout << "Could not open file '" << ROM9 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM10, spr_rom, 0x10000, 0x10000))   // Load 10th ROM
-  { cout << "Could not open file '" << ROM10 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM10, spr_rom, 0x10000, 0x10000))   // Load 10th ROM
+       { cout << "Could not open file '" << ROM10 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM11, spr_rom, 0x20000, 0x10000))   // Load 11th ROM
-  { cout << "Could not open file '" << ROM11 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM11, spr_rom, 0x20000, 0x10000))   // Load 11th ROM
+       { cout << "Could not open file '" << ROM11 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM12, spr_rom, 0x30000, 0x10000))   // Load 12th ROM
-  { cout << "Could not open file '" << ROM12 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM12, spr_rom, 0x30000, 0x10000))   // Load 12th ROM
+       { cout << "Could not open file '" << ROM12 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM13, spr_rom, 0x40000, 0x10000))   // Load 13th ROM
-  { cout << "Could not open file '" << ROM13 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM13, spr_rom, 0x40000, 0x10000))   // Load 13th ROM
+       { cout << "Could not open file '" << ROM13 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM14, spr_rom, 0x50000, 0x10000))   // Load 14th ROM
-  { cout << "Could not open file '" << ROM14 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM14, spr_rom, 0x50000, 0x10000))   // Load 14th ROM
+       { cout << "Could not open file '" << ROM14 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM15, spr_rom, 0x60000, 0x10000))   // Load 15th ROM
-  { cout << "Could not open file '" << ROM15 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM15, spr_rom, 0x60000, 0x10000))   // Load 15th ROM
+       { cout << "Could not open file '" << ROM15 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM16, spr_rom, 0x70000, 0x10000))   // Load 16th ROM
-  { cout << "Could not open file '" << ROM16 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM16, spr_rom, 0x70000, 0x10000))   // Load 16th ROM
+       { cout << "Could not open file '" << ROM16 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM21, voice_rom, 0, 0x10000))  // Load 21st ROM
-  { cout << "Could not open file '" << ROM21 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM21, voice_rom, 0, 0x10000))  // Load 21st ROM
+       { cout << "Could not open file '" << ROM21 << "'!" << endl;  return -1; }
 
-  if (!LoadImg(ROM22, voice_rom, 0x10000, 0x10000))  // Load 22nd ROM
-  { cout << "Could not open file '" << ROM22 << "'!" << endl;  return -1; }
+       if (!LoadImg(ROM22, voice_rom, 0x10000, 0x10000))  // Load 22nd ROM
+       { cout << "Could not open file '" << ROM22 << "'!" << endl;  return -1; }
 
-  if (!UnpackFonts())                         // Load 5, 6, 7, 8th ROMs
-  {
-    cout << "Could not open font files!" << endl;
-    return -1;
-  }
+       if (!UnpackFonts())                         // Load 5, 6, 7, 8th ROMs
+       {
+               cout << "Could not open font files!" << endl;
+               return -1;
+       }
 
        // Load samples if they're there...
        LoadPSGs();
        LoadFMs();
 
   // Quick 'n' Dirty voice dump (sound 0x0E)
-/*  uint32 adc = (voice_rom[26]<<8) | voice_rom[27];
+/*  uint32_t adc = (voice_rom[26]<<8) | voice_rom[27];
   bool doneWitIt = false;
   int crh = 0;
   while (!doneWitIt)
@@ -1123,7 +1152,7 @@ WriteLog("About to go to the main loop...\n");
                                dpc = htod(lbuff);
                        }
                        printf("%04X: ", dpc);
-                       uint16 pc_save = cpu1.pc, pcB_save = cpu2.pc;
+                       uint16_t pc_save = cpu1.pc, pcB_save = cpu2.pc;
                        cpu1.pc = dpc;  cpu2.pc = dpc;
                        for(int i=0; i<16; i++)
                                printf("%02X ", (looking_at_rom ? Fetch() : FetchB()));
@@ -1131,7 +1160,7 @@ WriteLog("About to go to the main loop...\n");
                        cpu1.pc = dpc;  cpu2.pc = dpc;
                        for(int i=0; i<16; i++)
                        {
-                               uint8 a = (looking_at_rom ? Fetch() : FetchB());
+                               uint8_t a = (looking_at_rom ? Fetch() : FetchB());
                                if (a<10)             cout << (char)(a+48);
                                if ((a>9) && (a<37))  cout << (char)(a+55);
                                if (a>36)             cout << ".";
@@ -1148,7 +1177,7 @@ WriteLog("About to go to the main loop...\n");
                                dpc = htod(lbuff);
                        }
                        printf("%04X: ", dpc);
-                       for(int i=0; i<16; i++)  printf("%02X ", (uint8)gram[dpc++]);
+                       for(int i=0; i<16; i++)  printf("%02X ", (uint8_t)gram[dpc++]);
                        cout << endl;
                }
                else if (lbuff[0] == 'l')
@@ -1192,11 +1221,11 @@ WriteLog("About to go to the main loop...\n");
                else if ((lbuff[0] == 'r') || (lbuff[0] == 'c')) // Run/continue...
                {
 WriteLog("Executing 'run' command...\n");
-                       uint32 my_clock = 0;
+                       uint32_t my_clock = 0;
                        running = true;                                                         // Set running status...
                        trace1 = false;
                        SetRefreshRate(refresh2);                                       // Tell GUI our refresh rate
-      //for(uint16 i=0; i<0x8000; i++)  gram2[i] = grom3[i]; //Temp
+      //for(uint16_t i=0; i<0x8000; i++)  gram2[i] = grom3[i]; //Temp
 
                        if (lbuff[0] == 'r')                                            // If run, then reset CPUs
                        {
@@ -1240,9 +1269,6 @@ WriteLog("--> CPU clock #1: %u\n", cpu1.clock);
                        }
 
 WriteLog("About to set up screen...\n");
-//      if (!SetVESA2())  running = false;        // Set up screen
-                       // Set up screen (windowed)
-//                     screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); //video_bpp, videoflags);
                        screen = SDL_SetVideoMode(VIRTUAL_SCREEN_WIDTH * 2, VIRTUAL_SCREEN_HEIGHT * 2, 8, SDL_SWSURFACE  | SDL_DOUBLEBUF);
                        if (screen == NULL)
                        {
@@ -1251,23 +1277,25 @@ WriteLog("About to set up screen...\n");
                        }
 
                        SDL_Color colors[256];
+
                        for(int i=0; i<256; i++)
                        {
                                colors[i].r = palette[i*3+0];
                                colors[i].g = palette[i*3+1];
                                colors[i].b = palette[i*3+2];
                        }
+
                        SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL, colors, 0, 256);
 
 #if 0
        // This confirms that we're getting video to the screen...
        SDL_LockSurface(screen);
 
-       uint8 pixel = 0;
-       uint8 * pixels = (uint8 *)(screen->pixels);
+       uint8_t pixel = 0;
+       uint8_t * pixels = (uint8_t *)(screen->pixels);
 
-       for(uint32 y=0; y<480; y++)
-               for(uint32 x=0; x<640; x++)
+       for(uint32_t y=0; y<480; y++)
+               for(uint32_t x=0; x<640; x++)
                        pixels[(y * 640) + x] = pixel++;
 
        SDL_UnlockSurface(screen);
@@ -1294,6 +1322,7 @@ WriteLog("About to set up audio...\n");
                                cout << "Couldn't open audio: " << SDL_GetError() << endl;
                                return -1;
                        }
+
                        SDL_PauseAudio(0);                                                      // Get that audio going!
 
 WriteLog("About to enter main loop...\n");
@@ -1423,7 +1452,7 @@ WriteLog("About to enter main loop...\n");
                                }
                                if (keys[SDLK_RETURN])                                                  // Return
                                {
-                                       uint8 retval = UserSelectedSomething();
+                                       uint8_t retval = UserSelectedSomething();
                                        if (retval == EXIT)
                                                running = false;
                                        if (retval == REFRESH)
@@ -1527,8 +1556,8 @@ WriteLog("About to enter main loop...\n");
 // 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++)
+                                       for(uint32_t i=0; i<640; i++)
+//                                     for(uint32_t 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...
@@ -1602,61 +1631,68 @@ BlitChar(screen, chr_rom, gram1);
                }
                else if (lbuff[0] == 'i')  // Inspect registers
                {
-      printf("CPU1: A=%02X B=%02X CC=%02X DP=%02X X=%04X Y=%04X S=%04X U=%04X PC=%04X",
-              cpu1.a, cpu1.b, cpu1.cc, cpu1.dp, cpu1.x, cpu1.y, cpu1.s, cpu1.u, cpu1.pc);
-      cout << " iclk=" << dec << cpu1.clock << endl;
-      printf("CPU2: A=%02X B=%02X CC=%02X DP=%02X X=%04X Y=%04X S=%04X U=%04X PC=%04X",
-              cpu2.a, cpu2.b, cpu2.cc, cpu2.dp, cpu2.x, cpu2.y, cpu2.s, cpu2.u, cpu2.pc);
-      cout << " iclk=" << dec << cpu2.clock << endl;
-      if (brk)
-        cout << "Breakpoint #1 set at " << hex << brkpnt << dec << endl;
-      if (brk2)
-        cout << "Breakpoint #2 set at " << hex << brkpnt2 << dec << endl;
-    }
+                       printf("CPU1: A=%02X B=%02X CC=%02X DP=%02X X=%04X Y=%04X S=%04X U=%04X PC=%04X",
+                                       cpu1.a, cpu1.b, cpu1.cc, cpu1.dp, cpu1.x, cpu1.y, cpu1.s, cpu1.u, cpu1.pc);
+                       cout << " iclk=" << dec << cpu1.clock << endl;
+                       printf("CPU2: A=%02X B=%02X CC=%02X DP=%02X X=%04X Y=%04X S=%04X U=%04X PC=%04X",
+                                       cpu2.a, cpu2.b, cpu2.cc, cpu2.dp, cpu2.x, cpu2.y, cpu2.s, cpu2.u, cpu2.pc);
+                       cout << " iclk=" << dec << cpu2.clock << endl;
+
+                       if (brk)
+                               cout << "Breakpoint #1 set at " << hex << brkpnt << dec << endl;
+
+                       if (brk2)
+                               cout << "Breakpoint #2 set at " << hex << brkpnt2 << dec << endl;
+               }
                else if (strncmp(lbuff, "swap", 4) == 0)  // Swap ROMs
-    {
-      looking_at_rom = !looking_at_rom;
-      cout << "Swapped:  Looking at ";
-      (looking_at_rom ? cout << "ROM #1" : cout << "ROM #2");
-      cout << endl;
-    }
+               {
+                       looking_at_rom = !looking_at_rom;
+                       cout << "Swapped:  Looking at ";
+                       (looking_at_rom ? cout << "ROM #1" : cout << "ROM #2");
+                       cout << endl;
+               }
                else if (strncmp(lbuff, "seek", 4) == 0)  // Seek non-zero bytes in RAM
-    {
-      if (lbuff[4] != 0)
-      {
-        for(int i=0; i<4; i++)
-          lbuff[i] = 32;
-        dpc = htod(lbuff);
-      }
-      do
-      {
-        x = gram1[dpc++];
-      }
-      while ((x == 0) && (dpc != 0xFFFF)); // Keep going until something found
-      dpc--;
-
-      printf("%04X: ", dpc);       // Show data found...
-      for(int i=0; i<16; i++)
-        printf("%02X ", gram1[(uint16)(dpc+i)]);
-      cout << " ";
-      for(int i=0; i<16; i++)
-      {
-        uint8 a = gram1[dpc++];
-        if (a<10)
-          cout << (char)(a+48);
-        if ((a>9) && (a<37))
-          cout << (char)(a+55);
-        if (a>36)
-          cout << ".";
-      }
-      cout << endl;
-    }
+               {
+
+                       if (lbuff[4] != 0)
+                       {
+                               for(int i=0; i<4; i++)
+                               lbuff[i] = 32;
+                               dpc = htod(lbuff);
+                       }
+
+                       do
+                       {
+                               x = gram1[dpc++];
+                       }
+                       while ((x == 0) && (dpc != 0xFFFF)); // Keep going until something found
+                       dpc--;
+
+                       printf("%04X: ", dpc);       // Show data found...
+
+                       for(int i=0; i<16; i++)
+                               printf("%02X ", gram1[(uint16_t)(dpc+i)]);
+
+                       cout << " ";
+
+                       for(int i=0; i<16; i++)
+                       {
+                               uint8_t a = gram1[dpc++];
+
+                               if (a<10)
+                                       cout << (char)(a+48);
+                               if ((a>9) && (a<37))
+                                       cout << (char)(a+55);
+                               if (a>36)
+                                       cout << ".";
+                       }
+
+                       cout << endl;
+               }
                else if (lbuff[0] == 'v')    // View screen
                {
-//                     SetVESA2();                           // Set up screen
                        BlitChar(screen, chr_rom, gram1);
                        getch();
-//                     RestoreOldMode();
                }
 
                if (lbuff[0] == 'q')
@@ -1688,12 +1724,14 @@ Rolling Thunder Memory map
 Most of the decoding is done by custom chips (CUS47 and CUS41), so the memory
 map is inferred by program behaviour. The customs also handle internally irq
 and watchdog.
+
 The main CPU memory map is the same in all games because CUS47 is used by all
 games. The sub CPU and sound CPU, on the other hand, change because CUS41 is
 replaced by other chips.
-All RAM is shared between main and sub CPU, except for sound RAM which is shared
-between main and sound CPU; the portion of object RAM that is overlapped by sound
-RAM is used exclusively by the sub CPU.
+
+All RAM is shared between main and sub CPU, except for sound RAM which is
+shared between main and sound CPU; the portion of object RAM that is overlapped
+by sound RAM is used exclusively by the sub CPU.
 
 MAIN CPU:
 
@@ -1804,3 +1842,4 @@ TODO:
   stop receiving interrupts.
 
 #endif
+