X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fthunder.cpp;h=fde0f3ef48289d66db1b384421d113357cab70ac;hb=87647f03b4d7cf53948ed8f9f25ad30da5e596bf;hp=b6776d55707783d438a9d46935e29f9c03c95dcd;hpb=43a80363f784b8dc10e438024149da0d993c7eca;p=thunder diff --git a/src/thunder.cpp b/src/thunder.cpp index b6776d5..fde0f3e 100755 --- a/src/thunder.cpp +++ b/src/thunder.cpp @@ -11,7 +11,7 @@ // JLH 07/23/2009 Added changelog ;-) // -#define THUNDER_VERSION "0.5.0" +#define THUNDER_VERSION "0.9.9" #include #include @@ -95,36 +95,36 @@ using namespace std; // Yes! SDL_Surface * screen; -BYTE * gram, * grom; // Allocate RAM & ROM pointers -BYTE * gram1, * gram2, * grom1, * grom2; // Actual memory -BYTE * grom3, * grom4, * data_rom, * spr_rom, * voice_rom; -BYTE * chr_rom; // Character ROM pointer +uint8 * gram, * grom; // Allocate RAM & ROM pointers +uint8 * gram1, * gram2, * grom1, * grom2; // Actual memory +uint8 * grom3, * grom4, * data_rom, * spr_rom, * voice_rom; +uint8 * chr_rom; // Character ROM pointer V6809REGS cpu1, cpu2; bool trace1 = false; // ditto... bool looking_at_rom = true; // true = R1, false = R2 -DWORD banksw1, banksw2; // Bank switch addresses -WORD game_over_switch; // Game over delay -WORD dpc; // Debug pc reg... +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 -WORD refresh_ = 0; // Crappy global screen stuff... +uint16 refresh_ = 0; // Crappy global screen stuff... bool refresh2 = true; -DWORD psg_lens[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -BYTE * psg_adrs[16]; -DWORD voc_lens[32] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -BYTE * voc_adrs[32]; -DWORD fm_lens[14] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -BYTE * fm_adrs[14]; +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]; fstream tr; // Tracelog hook -WORD pcx; // Where we at? +uint16 pcx; // Where we at? static char op_mat1[256] = { 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, @@ -284,9 +284,9 @@ iregs[4][2] = {"X", "Y", "U", "S" }; // // Read a byte from memory (without touching PC. Not a Fetch!) // -BYTE RdMem(WORD addr) +uint8 RdMem(uint16 addr) { - BYTE b; + uint8 b; if (addr < 0x8000) { @@ -304,18 +304,18 @@ BYTE RdMem(WORD addr) // // Write a byte to memory // -void WrMem(WORD addr, BYTE b) +void WrMem(uint16 addr, uint8 b) { extern bool charbase; // Needed for screen. Extern it in it?? - //extern WORD sr, ur, xr, yr; // Needed for tracelog - //extern WORD pcr; + //extern uint16 sr, ur, xr, yr; // Needed for tracelog + //extern uint16 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 << (WORD)gram1[0x4400+i] << " "; + // tr << hex << (uint16)gram1[0x4400+i] << " "; //} tr << endl; }//*/ @@ -325,7 +325,7 @@ void WrMem(WORD addr, BYTE b) if (addr == 0x6400) SpawnSound(GAMESOUND, gram1[0x6600], 1); // Do voice chan 2 if (addr == 0x6800) - banksw1 = (DWORD)b << 13; // Set char data bankswitch base address + banksw1 = (uint32)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) @@ -355,10 +355,10 @@ void WrMem(WORD addr, BYTE b) // // Read a byte from memory (without touching PC. Not a Fetch!) (2nd processor) // -BYTE RdMemB(WORD addr) +uint8 RdMemB(uint16 addr) { -// extern WORD cpu2.s, cpu2.u, cpu2.x, cpu2.y; // Needed for tracelog - BYTE b; +// extern uint16 cpu2.s, cpu2.u, cpu2.x, cpu2.y; // Needed for tracelog + uint8 b; if (addr < 0x8000) { @@ -385,18 +385,18 @@ BYTE RdMemB(WORD addr) // // Write a byte to memory (2nd processor) // -void WrMemB(WORD addr, BYTE b) +void WrMemB(uint16 addr, uint8 b) { extern bool charbase; - //extern WORD sr, ur, xr, yr; // Needed for tracelog - //extern WORD pcr; + //extern uint16 sr, ur, xr, yr; // Needed for tracelog + //extern uint16 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 << (WORD)gram1[0x4400+i] << " "; + // tr << hex << (uint16)gram1[0x4400+i] << " "; //} tr << endl; }//*/ @@ -411,7 +411,7 @@ void WrMemB(WORD addr, BYTE b) if (addr > 0x0284 && addr < 0x02A5 && b) SpawnSound(PSGSOUND, addr - 0x0285); // Do PSG sound on chans 2, 3 if (addr == 0xD803) - banksw2 = (DWORD)(b & 0x03) << 13; // Set sprite data bank switch + banksw2 = (uint32)(b & 0x03) << 13; // Set sprite data bank switch if (addr == 0x0380) { SpawnSound(FMSOUND, b); // Do FM sound on chan 4 @@ -432,9 +432,9 @@ void WrMemB(WORD addr, BYTE b) // // Display bytes in mem in hex // -void DisplayBytes(WORD src, unsigned long dst) +void DisplayBytes(uint16 src, unsigned long dst) { - BYTE cnt; + uint8 cnt; unsigned long i; printf("%04X: ", src); @@ -442,7 +442,7 @@ void DisplayBytes(WORD src, unsigned long dst) if (src > dst) dst += 0x10000; // That should fix the FFFF bug... for(i=src; i> 5), idxind = ((operand & 0x10) >> 4), + uint8 reg = ((operand & 0x60) >> 5), idxind = ((operand & 0x10) >> 4), lo_nyb = (operand & 0x0F), boff; - WORD woff; + uint16 woff; strcpy(tmp, "??"); if (!(operand & 0x80)) // Hi bit set? Then decode 4 bit offset @@ -620,9 +620,9 @@ void Decode_6809() // // Convert hex to dec // -WORD htod(char *str) +uint16 htod(char *str) { - WORD value = 0; + uint16 value = 0; int len = strlen(str); for(int i=0; i>4); + palette[i] = (uint8)(ch&0x0F); + palette[i+1] = (uint8)(ch>>4); ff2.get(ch); - palette[i+2] = (BYTE)ch; + palette[i+2] = (uint8)ch; } // Do palette stretching here... I.e. add 0 to hinyb 0, 1 to hinyb 1, etc. @@ -758,7 +758,7 @@ bool ReadColorPROMs(void) // bool UnpackFonts(void) { -// BYTE b1, b2, b3; +// uint8 b1, b2, b3; char b1, b2, b3; fstream f1, f2; //0x4000 $800 chars @@ -810,27 +810,27 @@ bool UnpackFonts(void) // // Get length of sample from WAV format // -DWORD GetWAVLength(fstream &file) +uint32 GetWAVLength(fstream &file) { char ch; - DWORD len; + uint32 len; file.ignore(16); // Skip header BS for(int i=0; i<2; i++) { - file.get(ch); len = (int)(BYTE)ch; - file.get(ch); len |= (int)(BYTE)ch << 8; - file.get(ch); len |= (int)(BYTE)ch << 16; - file.get(ch); len |= (int)(BYTE)ch << 24; + 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.ignore(len + 4); // Skip intermediate data } - file.get(ch); len = (int)(BYTE)ch; // & finally get length of data - file.get(ch); len |= (int)(BYTE)ch << 8; - file.get(ch); len |= (int)(BYTE)ch << 16; - file.get(ch); len |= (int)(BYTE)ch << 24; + 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; return len; } @@ -842,7 +842,7 @@ void LoadPSGs(void) { char file[40]; char ch; - DWORD len; + uint32 len; for(int i=0; i<16; i++) { @@ -857,7 +857,7 @@ void LoadPSGs(void) { len = GetWAVLength(fp); // Get WAV data length... - psg_adrs[i] = new BYTE[len]; // Attempt to allocate space... + psg_adrs[i] = new uint8[len]; // Attempt to allocate space... if (psg_adrs[i] != NULL) { @@ -883,7 +883,7 @@ void LoadFMs(void) { char file[200]; char ch; - DWORD len; + uint32 len; for(int i=0; i<14; i++) { @@ -898,7 +898,7 @@ void LoadFMs(void) { len = GetWAVLength(fp); // Get WAV length... - fm_adrs[i] = new BYTE[len]; // Attempt to allocate space... + fm_adrs[i] = new uint8[len]; // Attempt to allocate space... if (fm_adrs[i] != NULL) { @@ -925,12 +925,12 @@ int main(int argc, char * argv[]) { InitLog("thunder.log"); -/* extern WORD cpu1.pc, cpu1.s, cpu1.u, cpu1.x, cpu1.y; // Pull in vars from '6809.cpp' - extern BYTE cpu1.a, cpu1.b, cpu1.cc, cpu1.dp; +/* extern uint16 cpu1.pc, cpu1.s, cpu1.u, cpu1.x, cpu1.y; // Pull in vars from '6809.cpp' + extern uint8 cpu1.a, cpu1.b, cpu1.cc, cpu1.dp; extern long iclock; extern bool illegal; - extern WORD cpu2.pc, cpu2.s, cpu2.u, cpu2.x, cpu2.y; // Pull in vars from '6809B.cpp' - extern BYTE cpu2.a, cpu2.b, cpu2.cc, cpu2.dp; + extern uint16 cpu2.pc, cpu2.s, cpu2.u, cpu2.x, cpu2.y; // Pull in vars from '6809B.cpp' + extern uint8 cpu2.a, cpu2.b, cpu2.cc, cpu2.dp; extern long iclockB; extern bool illegalB; extern void (* exec_op0[256])(); // Array of page zero opcode functions... @@ -946,22 +946,22 @@ int main(int argc, char * argv[]) char lbuff[80]; fstream ff; // Declare fstream without file hooks... bool brk = false, brk2 = false; // Breakpoint set flag - WORD brkpnt, brkpnt2; // Where the breakpoint is... + 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 - WORD debounce = 0; // Key de-bounce counter - WORD fire_debounce = 0; // Fire button debounce counter + uint16 debounce = 0; // Key de-bounce counter + uint16 fire_debounce = 0; // Fire button debounce counter // bool refresh2 = true; // Default to 60 Hz... - BYTE x; // General placeholder... + uint8 x; // General placeholder... bool active = true; // Program running flag // SDL_Surface * screen = NULL; // SDL screen pointer SDL_Event event; // SDL "event" // int keyPressed; // SDL key pressed... - BYTE keys[256]; // Keyboard "switch-like" buffer - extern BYTE palette[768]; // Screen physical palette - DWORD ticks, oldTicks; + uint8 keys[256]; // Keyboard "switch-like" buffer + extern uint8 palette[768]; // Screen physical palette + uint32 ticks, oldTicks; // tr.open("exe.log", ios::binary | ios::out); // Tracelog @@ -985,34 +985,34 @@ int main(int argc, char * argv[]) cout << "Allocating memory..." << endl; //Does this anyway... set_new_handler(0); // Make 'new' return NULL on failure... - gram1 = new BYTE[0x10000]; + gram1 = new uint8[0x10000]; if (gram1 == NULL) { cout << "Could not allocate RAM space #1!" << endl << "Aborting!" << endl; return -1; } - grom1 = new BYTE[0x10000]; + grom1 = new uint8[0x10000]; if (grom1 == NULL) { cout << "Could not allocate ROM space #1!" << endl << "Aborting!" << endl; return -1; } - gram2 = new BYTE[0x10000]; + gram2 = new uint8[0x10000]; if (gram2 == NULL) { cout << "Could not allocate RAM space #2!" << endl << "Aborting!" << endl; return -1; } - grom2 = new BYTE[0x10000]; + grom2 = new uint8[0x10000]; if (grom2 == NULL) { cout << "Could not allocate ROM space #2!" << endl << "Aborting!" << endl; return -1; } - chr_rom = new BYTE[0x60000]; + chr_rom = new uint8[0x60000]; if (chr_rom == NULL) { cout << "Could not allocate character RAM!" << endl << "Aborting!" << endl; return -1; } - grom3 = new BYTE[0x8000]; + grom3 = new uint8[0x8000]; if (grom3 == NULL) { cout << "Could not allocate ROM space #4!" << endl << "Aborting!" << endl; return -1; } - grom4 = new BYTE[0x8000]; + grom4 = new uint8[0x8000]; if (grom4 == NULL) { cout << "Could not allocate ROM space #5!" << endl << "Aborting!" << endl; return -1; } - data_rom = new BYTE[0x40000]; + data_rom = new uint8[0x40000]; if (data_rom == NULL) { cout << "Could not allocate ROM level data!" << endl << "Aborting!" << endl; return -1; } - spr_rom = new BYTE[0x80000]; + spr_rom = new uint8[0x80000]; if (spr_rom == NULL) { cout << "Could not allocate ROM sprite data!" << endl << "Aborting!" << endl; return -1; } - voice_rom = new BYTE[0x20000]; + voice_rom = new uint8[0x20000]; if (voice_rom == NULL) { cout << "Could not allocate ROM voice data!" << endl << "Aborting!" << endl; return -1; } @@ -1096,7 +1096,7 @@ int main(int argc, char * argv[]) LoadFMs(); // Quick 'n' Dirty voice dump (sound 0x0E) -/* DWORD adc = (voice_rom[26]<<8) | voice_rom[27]; +/* uint32 adc = (voice_rom[26]<<8) | voice_rom[27]; bool doneWitIt = false; int crh = 0; while (!doneWitIt) @@ -1144,7 +1144,7 @@ WriteLog("About to go to the main loop...\n"); dpc = htod(lbuff); } printf("%04X: ", dpc); - WORD pc_save = cpu1.pc, pcB_save = cpu2.pc; + uint16 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())); @@ -1152,7 +1152,7 @@ WriteLog("About to go to the main loop...\n"); cpu1.pc = dpc; cpu2.pc = dpc; for(int i=0; i<16; i++) { - BYTE a = (looking_at_rom ? Fetch() : FetchB()); + uint8 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 << "."; @@ -1169,7 +1169,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 ", (BYTE)gram[dpc++]); + for(int i=0; i<16; i++) printf("%02X ", (uint8)gram[dpc++]); cout << endl; } else if (lbuff[0] == 'l') @@ -1213,11 +1213,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"); - DWORD my_clock = 0; + uint32 my_clock = 0; running = true; // Set running status... trace1 = false; SetRefreshRate(refresh2); // Tell GUI our refresh rate - //for(WORD i=0; i<0x8000; i++) gram2[i] = grom3[i]; //Temp + //for(uint16 i=0; i<0x8000; i++) gram2[i] = grom3[i]; //Temp if (lbuff[0] == 'r') // If run, then reset CPUs { @@ -1445,7 +1445,7 @@ WriteLog("About to enter main loop...\n"); } if (keys[28]) // Return { - BYTE retval = UserSelectedSomething(); + uint8 retval = UserSelectedSomething(); if (retval == EXIT) running = false; if (retval == REFRESH) @@ -1640,11 +1640,11 @@ BlitChar(screen, chr_rom, gram1); printf("%04X: ", dpc); // Show data found... for(int i=0; i<16; i++) - printf("%02X ", gram1[(WORD)(dpc+i)]); + printf("%02X ", gram1[(uint16)(dpc+i)]); cout << " "; for(int i=0; i<16; i++) { - BYTE a = gram1[dpc++]; + uint8 a = gram1[dpc++]; if (a<10) cout << (char)(a+48); if ((a>9) && (a<37))