X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fthunder.cpp;h=b6776d55707783d438a9d46935e29f9c03c95dcd;hb=43a80363f784b8dc10e438024149da0d993c7eca;hp=6413b4c239a59934fed4bc5e2b8372261616e123;hpb=27ad8041c00ff80e50ba0ad9022c3eaa7a05b8b0;p=thunder diff --git a/src/thunder.cpp b/src/thunder.cpp index 6413b4c..b6776d5 100755 --- a/src/thunder.cpp +++ b/src/thunder.cpp @@ -1,14 +1,17 @@ // -// Thunder: A Rolling Thunder Emulator w/6809 debugger v0.40 -// (Last build: 3/6/2004) +// Thunder: A Rolling Thunder Emulator w/6809 debugger // // by James L. Hammons +// (c) 2004, 2009 Underground Software // -// (c) 2004 Underground Software +// JLH = James L. Hammons +// +// WHO WHEN WHAT +// --- ---------- ------------------------------------------------------------ +// JLH 07/23/2009 Added changelog ;-) // -#define THUNDER_VERSION "0.4.0" -#define THUNDER_BETA_VERSION "6" +#define THUNDER_VERSION "0.5.0" #include #include @@ -17,7 +20,8 @@ #include #include #include -#include // For getch() +//#include // For getch() +#include // For getch() #include #include "SDL.h" // Get yer SDL out...! #include "types.h" @@ -28,7 +32,7 @@ using namespace std; // Yes! -/* +#if 0 #define ROM1 "RT3-1B.ROM" #define ROM2 "RT3-2B.ROM" #define ROM3 "RT3-3.ROM" @@ -56,7 +60,7 @@ using namespace std; // Yes! #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" @@ -85,6 +89,7 @@ using namespace std; // Yes! #define PROM4 "mb7138h.6v" #define PROM5 "mb7112e.6u" #define MCUROM "rt1-mcu.bin" +#endif // Global defines @@ -97,7 +102,7 @@ BYTE * chr_rom; // Character ROM pointer V6809REGS cpu1, cpu2; -bool trace = false; // ditto... +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 @@ -107,7 +112,7 @@ 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... +WORD 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 }; @@ -276,30 +281,6 @@ tregs[16][3] = { "A", "B", "CC", "DP", "??", "??", "??", "??" }, iregs[4][2] = {"X", "Y", "U", "S" }; -// -// Fetch a byte out of memory -// -/*BYTE Fetch() -{ -// extern WORD sr, ur, xr, yr; // Needed for tracelog - extern WORD pcr; - BYTE b; - - b = (pcr < 0x8000 ? gram1[pcr] : grom1[pcr]); - pcr++; - - return b; -}*/ - -// -// Fetch a word out of memory (little endian format) -// -/*WORD FetchW() -{ - WORD w = Fetch() << 8; w |= Fetch(); - return w; -}*/ - // // Read a byte from memory (without touching PC. Not a Fetch!) // @@ -361,50 +342,16 @@ void WrMem(WORD addr, BYTE b) charbase = true; // Char banksw2 if (addr == 0x8400) // Frame go strobe? VBlank acknowledge? { - if (refresh++ == 1) // 30 Hz... + if (refresh_++ == 1) // 30 Hz... { BlitChar(screen, chr_rom, gram1); - refresh = (refresh2 ? 1 : 0); // 60/30 Hz... + refresh_ = (refresh2 ? 1 : 0); // 60/30 Hz... } // irqGoA = true; // Will this work??? no... cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ;//wil wok??? } } -// -// Fetch a byte out of memory (2nd processor) -// -/*BYTE FetchB() -{ -// extern WORD sr, ur, xr, yr; // Needed for tracelog - extern WORD pcrB; - BYTE b; - - if (pcrB<0x8000) - { - if (pcrB<0x2000) - b = gram1[pcrB+0x4000]; - if ((pcrB>0x1FFF) && (pcrB<0x6000)) - b = gram1[pcrB-0x2000]; - if (pcrB>0x5FFF) - b = gram1[pcrB]; - } - else - b = grom2[pcrB]; - pcrB++; - - return b; -} - -// -// Fetch a word out of memory (little endian format) (2nd processor) -// -WORD FetchWB() -{ - WORD w = FetchB() << 8; w |= FetchB(); - return w; -}*/ - // // Read a byte from memory (without touching PC. Not a Fetch!) (2nd processor) // @@ -583,7 +530,7 @@ void Decode_6809() 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 ")); + ? strcat(tmp, "U ") : strcat(tmp, "S ")); if (operand&0x80) strcat(tmp, "PC"); } sprintf(outbuf, "%s %s", mnem, tmp); @@ -614,17 +561,17 @@ void Decode_6809() case 8: { boff = DFetch(); sprintf(tmp, "($%02X,%s)", boff, iregs[reg]); break; } - case 9: + 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: + case 13: { woff = DFetchW(); sprintf(tmp, "($%04X,PC)", woff); break; } case 15: { woff = DFetchW(); sprintf(tmp, "[$%04X]", woff); break; } - default: strcpy(tmp, "??"); + default: strcpy(tmp, "??"); } } else @@ -641,15 +588,15 @@ void Decode_6809() case 8: { boff = DFetch(); sprintf(tmp, "($%02X),%s", boff, iregs[reg]); break; } - case 9: + 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: + case 13: { woff = DFetchW(); sprintf(tmp, "($%04X),PC", woff); break; } - default: strcpy(tmp, "??"); + default: strcpy(tmp, "??"); } } } @@ -681,15 +628,15 @@ WORD htod(char *str) for(int i=0; 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; } } @@ -706,7 +653,7 @@ bool Load32KImg(char * filename, WORD address) 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); @@ -721,7 +668,7 @@ bool Load32KImg(char * filename, WORD address) // Generic Load file into image space // (No error checking performed! Responsibility of caller!) // -bool LoadImg(char * filename, BYTE * mem, DWORD address, DWORD length) +bool LoadImg(const char * filename, BYTE * mem, DWORD address, DWORD length) { ifstream ff; char path[80]; @@ -732,7 +679,7 @@ bool LoadImg(char * filename, BYTE * mem, DWORD address, DWORD length) // ff.open(filename, ios::binary | ios::in); // Open 'da file... ff.open(path, ios::binary | ios::in); // Open 'da file... if (ff) - { + { for(DWORD i=0; i" << endl; - cout << "Serial #20030313 / Prerelease" << endl; - cout << "(C) 2003 Underground Software" << endl << endl; + cout << endl << "THUNDER v"THUNDER_VERSION" "; + cout << "by James Hammmmons" << endl; + cout << "Serial #20090723 / Prerelease" << endl; + cout << "(C) 2003, 2009 Underground Software" << endl << endl; - cout << "This emulator is freeware. If you paid for it you were RIPPED OFF" + cout << "This emulator is free software. If you paid for it you were RIPPED OFF" << endl << endl; cout << "Initializing SDL..." << endl; @@ -1034,7 +981,7 @@ int main(int argc, char * argv[]) return -1; } - SDL_WM_SetCaption("Thunder Beta 6", "Thunder"); + SDL_WM_SetCaption("Thunder v"THUNDER_VERSION" ", "Thunder"); cout << "Allocating memory..." << endl; //Does this anyway... set_new_handler(0); // Make 'new' return NULL on failure... @@ -1137,14 +1084,15 @@ int main(int argc, char * argv[]) 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; } - LoadPSGs(); // Load samples if they're there... + // Load samples if they're there... + LoadPSGs(); LoadFMs(); // Quick 'n' Dirty voice dump (sound 0x0E) @@ -1163,12 +1111,12 @@ int main(int argc, char * argv[]) // Set up V6809 execution contexts - memset(&cpu1, sizeof(V6809REGS), 0); + memset(&cpu1, 0, sizeof(V6809REGS)); cpu1.RdMem = RdMem; cpu1.WrMem = WrMem; cpu1.cpuFlags |= V6809_ASSERT_LINE_RESET; - memset(&cpu2, sizeof(V6809REGS), 0); + memset(&cpu2, 0, sizeof(V6809REGS)); cpu2.RdMem = RdMemB; cpu2.WrMem = WrMemB; cpu2.cpuFlags |= V6809_ASSERT_LINE_RESET; @@ -1195,7 +1143,7 @@ WriteLog("About to go to the main loop...\n"); lbuff[0] = 32; dpc = htod(lbuff); } - printf("%04X: ", dpc); + printf("%04X: ", dpc); WORD pc_save = cpu1.pc, pcB_save = cpu2.pc; cpu1.pc = dpc; cpu2.pc = dpc; for(int i=0; i<16; i++) @@ -1267,7 +1215,7 @@ WriteLog("About to go to the main loop...\n"); WriteLog("Executing 'run' command...\n"); DWORD my_clock = 0; running = true; // Set running status... - trace = false; + trace1 = false; SetRefreshRate(refresh2); // Tell GUI our refresh rate //for(WORD i=0; i<0x8000; i++) gram2[i] = grom3[i]; //Temp @@ -1291,7 +1239,7 @@ WriteLog("Executing secondary 'run' command...\n"); else cpu1.cc = 0xFF; // Set CC register cpu2.pc = ((grom2[0xFFFE]<<8) | grom2[0xFFFF]); // Reset 6809 #2 - cpu2.cc = 0xFF; // Set CC register + cpu2.cc = 0xFF; // Set CC register while(iclock < 8000) // was 17000, 20000, 5000 { Execute6809(&cpu1, 1); Execute6809(&cpu2, 1); @@ -1322,13 +1270,29 @@ WriteLog("About to set up screen...\n"); colors[i].g = palette[i*3+1]; colors[i].b = palette[i*3+2]; } - SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256); + SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL, colors, 0, 256); + +#if 1 + // This confirms that we're getting video to the screen... + SDL_LockSurface(screen); + + uint8 pixel = 0; + uint8 * pixels = (uint8 *)(screen->pixels); + + for(uint32 y=0; y<480; y++) + for(uint32 x=0; x<640; x++) + pixels[(y * 640) + x] = pixel++; + + SDL_UnlockSurface(screen); + SDL_UpdateRect(screen, 0, 0, 0, 0); +#endif for(int i=0; i<256; i++) keys[i] = 0; // Clear keyboard buffer... oldTicks = SDL_GetTicks(); +WriteLog("About to set up audio...\n"); // This crap SHOULD be in sound.cpp (not yet created)... SDL_AudioSpec desired, obtained; desired.freq = 22050; @@ -1345,6 +1309,7 @@ WriteLog("About to set up screen...\n"); } SDL_PauseAudio(0); // Get that audio going! +WriteLog("About to enter main loop...\n"); while (running) { HandleGUIDebounce(); // Debounce GUI keys @@ -1367,6 +1332,9 @@ WriteLog("About to set up screen...\n"); // SDL key handling... +#warning "MAKE REPOSITORY FOR THIS THING! !!! FIX !!!" +#warning "AND USE THE OLD SOURCE FOR THE BASE!!!" +#warning "KEYS ARE FUCKED UP! !!! FIX !!!" // keyPressed = 0; // Reset keypress while (SDL_PollEvent(&event) != 0) // Bleed out all pending key events... { @@ -1421,7 +1389,7 @@ WriteLog("About to set up screen...\n"); } if (keys[0x3E]) // Do PCX snapshot (F4) { - SpawnSound(USERSOUND, SCAMERA); + SpawnSound(USERSOUND, SCAMERA); SnapPCX(screen); debounce = 10; } @@ -1545,7 +1513,9 @@ WriteLog("About to set up screen...\n"); Execute6809(&cpu2, 10); } // } - if (enable_cpu) + +// if (enable_cpu) + if (true) { /*// if (irqGoA) cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ; @@ -1559,125 +1529,37 @@ WriteLog("About to set up screen...\n"); Execute6809(&cpu2, 25000); cpu2.clock -= 25000; // Remove 25K ticks from clock (in case it overflowed)//*/ - cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ; - cpu2.cpuFlags |= V6809_ASSERT_LINE_IRQ; +// cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ; +// cpu2.cpuFlags |= V6809_ASSERT_LINE_IRQ; while (cpu1.clock < 25000) { // Gay, but what are ya gonna do? Execute6809(&cpu1, 5); Execute6809(&cpu2, 5); } + cpu1.clock -= 25000; // Remove 25K ticks from clock (in case it overflowed) cpu2.clock -= 25000; // Remove 25K ticks from clock (in case it overflowed)//*/ -/* while (my_clock < 25000) // Cycles in 60th of a sec at 1.5 Mhz - { - // pcx = cpu1.pc; // Tracelog stuff - if (brk && (cpu1.pc == brkpnt)) - { - running = false; - break; - } - if (brk2 && (cpu2.pc == brkpnt2)) - { - running = false; - break; - } - DWORD prev = iclock; - - BYTE opcode = Fetch(); // Get the opcode - if (opcode == 0x10) - { - exec_op1[Fetch()](); - goto TEXE_NEXT; - } - if (opcode == 0x11) - { - exec_op2[Fetch()](); - goto TEXE_NEXT; - } - exec_op0[opcode](); -TEXE_NEXT: - - if (iclock > 25000) - { - iclock = 0; -// if (irqGoA) -// { - if ((!(cpu1.cc&0x10)) && irqGoA) - { - irqGoA = false; -// if (!(cpu1.cc&0x10)) // Process an interrupt? -// { - cpu1.cc |= 0x80; // Set E - WrMem(--cpu1.s, cpu1.pc&0xFF); WrMem(--cpu1.s, cpu1.pc>>8); // Save all regs... - WrMem(--cpu1.s, cpu1.u&0xFF); WrMem(--cpu1.s, cpu1.u>>8); - WrMem(--cpu1.s, cpu1.y&0xFF); WrMem(--cpu1.s, cpu1.y>>8); - WrMem(--cpu1.s, cpu1.x&0xFF); WrMem(--cpu1.s, cpu1.x>>8); - WrMem(--cpu1.s, cpu1.dp); WrMem(--cpu1.s, cpu1.b); - WrMem(--cpu1.s, cpu1.a); WrMem(--cpu1.s, cpu1.cc); - cpu1.cc |= 0x50; // Set F,I - cpu1.pc = (grom1[0xFFF8]<<8) | grom1[0xFFF9]; // And do it! - // Need to find out why RdMem is returning wrong values here... - } - } -// }//irgGoA - if (iclock > prev) - my_clock += (iclock - prev); // Increment my_clock - - // pcx = cpu2.pc; // Tracelog stuff - opcode = FetchB(); // Get the opcode - if (opcode == 0x10) - { - exec_op1B[FetchB()](); - goto TEXE_NEXT2; - } - if (opcode == 0x11) - { - exec_op2B[FetchB()](); - goto TEXE_NEXT2; - } - exec_op0B[opcode](); -TEXE_NEXT2: - - if (iclockB > 25000)//24550) // Slightly faster IRQs for SUB processor - { - iclockB = 0; -// if (irqGoB) -// { - if ((!(cpu2.cc&0x10)) && irqGoB) - { - irqGoB = false; -// if (!(cpu2.cc&0x10)) // Process an interrupt? -// { - cpu2.cc |= 0x80; // Set E - WrMemB(--cpu2.s, cpu2.pc&0xFF); WrMemB(--cpu2.s, cpu2.pc>>8); // Save all regs... - WrMemB(--cpu2.s, cpu2.u&0xFF); WrMemB(--cpu2.s, cpu2.u>>8); - WrMemB(--cpu2.s, cpu2.y&0xFF); WrMemB(--cpu2.s, cpu2.y>>8); - WrMemB(--cpu2.s, cpu2.x&0xFF); WrMemB(--cpu2.s, cpu2.x>>8); - WrMemB(--cpu2.s, cpu2.dp); WrMemB(--cpu2.s, cpu2.b); - WrMemB(--cpu2.s, cpu2.a); WrMemB(--cpu2.s, cpu2.cc); - cpu2.cc |= 0x50; // Set F,I - cpu2.pc = (grom2[0xFFF8]<<8) | grom2[0xFFF9]; // And do it! - } - } -// } // irqGoB - // if (brk && (cpu1.pc == brkpnt)) running = false; // Stop running! - } - my_clock -= 25000; // Remove frame count from iclock*/ } // END: enable_cpu -// if (refresh++ == 1) // 30 Hz... + +// if (refresh_++ == 1) // 30 Hz... // { // if (scr_type) // BlitWilliamsScreen(gram1); // Display the screen... // else // BlitChar(screen, chr_rom, gram1); -// refresh = (refresh2 ? 1 : 0); // 60/30 Hz... +// refresh_ = (refresh2 ? 1 : 0); // 60/30 Hz... // } +//temp, for testing... +BlitChar(screen, chr_rom, gram1); // Speed throttling happens here... - while (SDL_GetTicks() - oldTicks < 16); // Actually, it's 16.66... Need to account for that somehow + while (SDL_GetTicks() - oldTicks < 16) // Actually, it's 16.66... Need to account for that somehow + SDL_Delay(1); // Release our timeslice... + oldTicks = SDL_GetTicks(); +//cout << "Finished frame..." << endl; } // Stop_audio_output();