From fa2e10a964b5f0305656d858a3a8273baad12624 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Thu, 23 Jul 2009 21:07:08 +0000 Subject: [PATCH] Changed main emu code to use preallocated arrays --- src/gui.cpp | 4 +- src/screen.cpp | 4 +- src/thunder.cpp | 179 ++++++++++++++++++++++-------------------------- 3 files changed, 87 insertions(+), 100 deletions(-) diff --git a/src/gui.cpp b/src/gui.cpp index cd21ca5..df8275c 100755 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -26,11 +26,11 @@ using namespace std; // Yes! extern SDL_Surface * screen; extern uint8 my_scr[0x14000]; // Screen buffer... -extern uint8 * gram1; // Game RAM (do here??) +extern uint8 gram1[]; // Game RAM (do here??) extern uint8 hScrollOffset; // Horizontal scroll offset extern uint8 vScrollOffset; // Vertical scroll offset extern uint32 voffsets[8]; -extern uint8 * voice_rom; // PCM data pointer +extern uint8 voice_rom[]; // PCM data pointer extern fstream tr; // Tracelog // Global shit diff --git a/src/screen.cpp b/src/screen.cpp index 353229f..654c277 100755 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -264,7 +264,7 @@ void BlitChar(SDL_Surface * scr, uint8 * chr, uint8 * ram) // void DrawSprites(uint8 priority) { - extern uint8 * gram1; // Game RAM space + extern uint8 gram1[]; // Game RAM space for(uint16 i=0x5800; i<0x6000; i+=0x10) { @@ -291,7 +291,7 @@ void DrawSprites(uint8 priority) // void Sprite(uint32 sprnum, uint16 x, uint16 y, uint8 flip, uint16 spr_id) { - extern uint8 * spr_rom; + extern uint8 spr_rom[]; // To show or not to show a 16x16 block in the 4x4 grid... bool horiz_bl = false, vert_bl = false; uint32 sc_addr; diff --git a/src/thunder.cpp b/src/thunder.cpp index ed3f6c2..3a9d8ae 100755 --- a/src/thunder.cpp +++ b/src/thunder.cpp @@ -95,10 +95,22 @@ using namespace std; // Yes! SDL_Surface * screen; -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 +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 +/* + gram1 = new uint8[0x10000]; + grom1 = new uint8[0x10000]; + gram2 = new uint8[0x10000]; + grom2 = new uint8[0x10000]; + chr_rom = new uint8[0x60000]; + grom3 = new uint8[0x8000]; + grom4 = new uint8[0x8000]; + data_rom = new uint8[0x40000]; + spr_rom = new uint8[0x80000]; + voice_rom = new uint8[0x20000]; +*/ V6809REGS cpu1, cpu2; @@ -927,23 +939,8 @@ int main(int argc, char * argv[]) { InitLog("thunder.log"); -/* 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 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... - extern void (* exec_op1[256])(); // Array of page one opcode functions... - extern void (* exec_op2[256])(); // Array of page two opcode functions... - extern void (* exec_op0B[256])(); // Array of page zero opcode functions... - extern void (* exec_op1B[256])(); // Array of page one opcode functions... - extern void (* exec_op2B[256])(); // Array of page two opcode functions...*/ - extern bool charbase; // From 'SCREEN.CPP' -// extern unsigned int vesa_memptr; - charbase = false; + extern bool charbase; // From 'SCREEN.CPP' + charbase = false; char lbuff[80]; fstream ff; // Declare fstream without file hooks... @@ -956,36 +953,33 @@ int main(int argc, char * argv[]) uint16 fire_debounce = 0; // Fire button debounce counter // bool refresh2 = true; // Default to 60 Hz... uint8 x; // General placeholder... - bool active = true; // Program running flag + bool active = true; // Program running flag -// SDL_Surface * screen = NULL; // SDL screen pointer - SDL_Event event; // SDL "event" -// int keyPressed; // SDL key pressed... - extern uint8 palette[768]; // Screen physical palette + SDL_Event event; // SDL "event" + extern uint8 palette[768]; // Screen physical palette uint32 ticks, oldTicks; -// tr.open("exe.log", ios::binary | ios::out); // Tracelog + 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 << endl << "THUNDER v"THUNDER_VERSION" "; - cout << "by James Hammons" << endl; - cout << "Serial #20090723 / Prerelease" << endl; - cout << "(C) 2003, 2009 Underground Software" << endl << endl; + cout << "This emulator is free software. If you paid for it you were RIPPED OFF" + << endl << endl; - cout << "This emulator is free software. If you paid for it you were RIPPED OFF" - << endl << endl; + cout << "Initializing SDL..." << endl; - cout << "Initializing SDL..." << endl; - - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) - { - cout << "Couldn't initialize SDL: " << SDL_GetError() << endl; - return -1; - } + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) + { + cout << "Couldn't initialize SDL: " << SDL_GetError() << endl; + return -1; + } - SDL_WM_SetCaption("Thunder v"THUNDER_VERSION" ", "Thunder"); + SDL_WM_SetCaption("Thunder v"THUNDER_VERSION" ", "Thunder"); keys = SDL_GetKeyState(NULL); // Get the SDL keyboard matrix +#if 0 cout << "Allocating memory..." << endl; //Does this anyway... set_new_handler(0); // Make 'new' return NULL on failure... gram1 = new uint8[0x10000]; @@ -1018,6 +1012,7 @@ int main(int argc, char * argv[]) voice_rom = new uint8[0x20000]; if (voice_rom == NULL) { cout << "Could not allocate ROM voice data!" << endl << "Aborting!" << endl; return -1; } +#endif gram = gram1; grom = grom1; // Needed only for debugger @@ -1335,18 +1330,8 @@ WriteLog("About to enter main loop...\n"); // SDL key handling... -#warning "KEYS ARE FUCKED UP! !!! FIX !!!" - SDL_PumpEvents(); // Force key events into the buffer. -// keyPressed = 0; // Reset keypress -// while (SDL_PollEvent(&event) != 0) // Bleed out all pending key events... -// { -// if (event.type == SDL_KEYDOWN) -// keys[event.key.keysym.scancode] = 1; -// if (event.type == SDL_KEYUP) -// keys[event.key.keysym.scancode] = 0; -// } + SDL_PumpEvents(); // Force key events into the buffer. -// { if (keys[SDLK_ESCAPE]) running = false; // ESC to exit... @@ -1457,59 +1442,56 @@ WriteLog("About to enter main loop...\n"); } } if (keys[SDLK_1]) - gram1[0x427A] = 1; // (1) + gram1[0x427A] = 1; // (1) if (keys[SDLK_2]) - gram1[0x427C] = 1; // (2) + gram1[0x427C] = 1; // (2) if (keys[SDLK_3]) - gram1[0x427E] = 1; // (3) + gram1[0x427E] = 1; // (3) if (keys[SDLK_5]) - gram1[0x4280] = 1; // (5) - if (keys[0x10]|keys[29]) - gram1[0x4276] = 1; // (Q) Jump - if (keys[0x11]) - gram1[0x426A] = 1; // (W) + gram1[0x4280] = 1; // (5) + if (keys[SDLK_q] | keys[29]) + gram1[0x4276] = 1; // (Q) Jump + if (keys[SDLK_w]) + gram1[0x426A] = 1; // (W) if (fire_debounce) fire_debounce--; - if (keys[0x12]|keys[56]) // (E) Fire + if (keys[SDLK_e] | keys[56]) // (E) Fire { if (!fire_debounce) { gram1[0x4278] = 1; + if (gram1[0x3F08] == 0xFF) // Ugly kludge for debouncing gun - { fire_debounce = 8; - } else - { fire_debounce = 2; - } } } - if (keys[0x13]) - gram1[0x426C] = 1; // (R) - if (keys[0x14]) - gram1[0x4262] = 1; // (T) - if (keys[0x15]) - gram1[0x4260] = 1; // (Y) + if (keys[SDLK_r]) + gram1[0x426C] = 1; // (R) + if (keys[SDLK_t]) + gram1[0x4262] = 1; // (T) + if (keys[SDLK_y]) + gram1[0x4260] = 1; // (Y) if (keys[SDLK_F10]) - gram1[0x41A5]++; // Coin? (F10) + gram1[0x41A5]++; // Coin? (F10) if (keys[SDLK_z]) - gram1[0x4189]++; // ? (Z) credits l dig + gram1[0x4189]++; // ? (Z) credits l dig if (keys[SDLK_x]) - gram1[0x418A]++; // ? (X) credits r dig + gram1[0x418A]++; // ? (X) credits r dig if (keys[SDLK_c]) - gram1[0x418C]++; // ? (C) Start + gram1[0x418C]++; // ? (C) Start if (keys[SDLK_v]) - gram1[0x418D]++; // ? (V) + gram1[0x418D]++; // ? (V) if (keys[SDLK_F7]) - SpawnSound(USERSOUND, 0); // Do user sound (F7) -// if (keys[0x42]) + SpawnSound(USERSOUND, 0); // Do user sound (F7) +// if (keys[SDLK_F8]) // { -// gram1[0x4380] = 0; // (F8) kill music (this worx) -// charbase = false; // Switch chars out... +// gram1[0x4380] = 0; // (F8) kill music (this worx) +// charbase = false; // Switch chars out... // } -// if (keys[0x43]) gram1[0x4285] = 1; // (F9) strobe unknown loc - if (keys[SDLK_F1]) // (F11) +// if (keys[SDLK_F9]) gram1[0x4285] = 1; // (F9) strobe unknown loc + if (keys[SDLK_F11]) // (F11) { Execute6809(&cpu1, 10); Execute6809(&cpu2, 10); @@ -1519,7 +1501,8 @@ WriteLog("About to enter main loop...\n"); // if (enable_cpu) if (true) { -/*// if (irqGoA) +#if 0 +// if (irqGoA) cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ; Execute6809(&cpu1, 25000); @@ -1530,19 +1513,21 @@ WriteLog("About to enter main loop...\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; - while (cpu1.clock < 25000) +#else + cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ; + cpu2.cpuFlags |= V6809_ASSERT_LINE_IRQ; +// while (cpu1.clock < 25000) + for(uint32 i=0; i<250; i++) { // Gay, but what are ya gonna do? - Execute6809(&cpu1, 5); - Execute6809(&cpu2, 5); + // There's better ways, such as keeping track of when slave writes to master, etc... + Execute6809(&cpu1, 100); + Execute6809(&cpu2, 100); } cpu1.clock -= 25000; // Remove 25K ticks from clock (in case it overflowed) cpu2.clock -= 25000; // Remove 25K ticks from clock (in case it overflowed)//*/ - +#endif } // END: enable_cpu // if (refresh_++ == 1) // 30 Hz... @@ -1553,6 +1538,7 @@ WriteLog("About to enter main loop...\n"); // BlitChar(screen, chr_rom, gram1); // refresh_ = (refresh2 ? 1 : 0); // 60/30 Hz... // } + //temp, for testing... BlitChar(screen, chr_rom, gram1); @@ -1668,8 +1654,9 @@ BlitChar(screen, chr_rom, gram1); active = false; //break; // Quit } - SDL_Quit(); // Shut down SDL + SDL_Quit(); // Shut down SDL +#if 0 delete[] gram1; // Deallocate RAM & ROM spaces delete[] grom1; delete[] gram2; @@ -1680,16 +1667,16 @@ BlitChar(screen, chr_rom, gram1); delete[] data_rom; delete[] spr_rom; delete[] voice_rom; +#endif for(int i=0; i<16; i++) - if (psg_adrs[i] != NULL) - delete[] psg_adrs[i]; // Deallocate if loaded + if (psg_adrs[i]) + delete[] psg_adrs[i]; // Deallocate if loaded for(int i=0; i<14; i++) - if (fm_adrs[i] != NULL) - delete[] fm_adrs[i]; // Deallocate if loaded + if (fm_adrs[i]) + delete[] fm_adrs[i]; // Deallocate if loaded -// tr.close(); // Close tracelog LogDone(); return 1; -- 2.37.2