From daddbc234577dec4d318337f7ee0cf32517f0540 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Fri, 4 Apr 2014 17:40:38 -0500 Subject: [PATCH] Fixed pointer size problem that caused GUI crash. --- src/gui.cpp | 1171 ++++++++++++++++++++++++++-------------------- src/resource.asm | 80 ++-- src/thunder.cpp | 23 + 3 files changed, 734 insertions(+), 540 deletions(-) diff --git a/src/gui.cpp b/src/gui.cpp index a84ab6f..7764041 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -7,7 +7,7 @@ // JLH = James Hammons // // WHO WHEN WHAT -// --- ---------- ------------------------------------------------------------ +// --- ---------- ----------------------------------------------------------- // JLH 07/23/2009 Added changelog ;-) // @@ -15,44 +15,43 @@ #include #include // Needed for tracelog -//#include "SDL.h" // Needed for screen.h #include "screen.h" #include "resource.h" // Thunder graphics & sounds -using namespace std; // Yes! +using namespace std; // External shit extern SDL_Surface * screen; -extern uint8_t my_scr[0x14000]; // Screen buffer... -extern uint8_t gram1[]; // Game RAM (do here??) -extern uint8_t hScrollOffset; // Horizontal scroll offset -extern uint8_t vScrollOffset; // Vertical scroll offset +extern uint8_t my_scr[0x14000]; // Screen buffer... +extern uint8_t gram1[]; // Game RAM (do here??) +extern uint8_t hScrollOffset; // Horizontal scroll offset +extern uint8_t vScrollOffset; // Vertical scroll offset extern uint32_t voffsets[8]; -extern uint8_t voice_rom[]; // PCM data pointer -extern fstream tr; // Tracelog +extern uint8_t voice_rom[]; // PCM data pointer +extern fstream tr; // Tracelog // Global shit -uint16_t text_life; // How long text is visible -bool show_text; // Whether or not to show text -uint16_t show_which_msg; // Which message to show -bool show_gui; // Whether or not to show GUI -uint16_t selection; // Which GUI item currently selected +uint16_t text_life; // How long text is visible +bool show_text; // Whether or not to show text +uint16_t show_which_msg; // Which message to show +bool show_gui; // Whether or not to show GUI +uint16_t selection; // Which GUI item currently selected uint16_t snd_num; -uint16_t gui_debounce; // GUI key debounce value -uint16_t num_coins; // Number of coins dropped -uint16_t blink = 0; // Used to blink player 1 & 2 start buttons -uint16_t flash = 23; // Used to flash GUI lights -uint16_t iline = 0; // Used to roll line -uint16_t dcurcol = 179; // dipswitch cursor color -int dcurdir = 1; // Initially going up... +uint16_t gui_debounce; // GUI key debounce value +uint16_t num_coins; // Number of coins dropped +uint16_t blink = 0; // Used to blink player 1 & 2 start buttons +uint16_t flash = 23; // Used to flash GUI lights +uint16_t iline = 0; // Used to roll line +uint16_t dcurcol = 179; // dipswitch cursor color +int dcurdir = 1; // Initially going up... bool blink_on = false; -bool game_refresh; // Refresh rate user set -bool do_decrement; // Flag to handle decrement... -bool user_selected_something; // Flag for well, you know... -uint16_t dswitch; // Which dipswitch is selected... +bool game_refresh; // Refresh rate user set +bool do_decrement; // Flag to handle decrement... +bool user_selected_something; // Flag for well, you know... +uint16_t dswitch; // Which dipswitch is selected... // The following are global for the sound routines... @@ -263,7 +262,8 @@ uint8_t bnF[] = { 0,0,0,0,0,0 }; -// + + // // Initialize GUI // void InitGUI(void) @@ -273,554 +273,704 @@ void InitGUI(void) user_selected_something = false; } + // // Handle key debounce // void HandleGUIDebounce(void) { - if (gui_debounce) gui_debounce--; // Debounce GUI keys... - do_decrement = !do_decrement; // Called at 60Hz, so skip decrementing blink - if (do_decrement) - { - if (blink) blink--; // Handle blinking stuff (Should prb go in DrawGUI) - - flash-=2; // Handle flashing stuff (Should prb go in DrawGUI) - if (flash == 0xFFFF) flash = 23; - - iline++; - if (iline > 30) iline = 0; // 30 pixels high, going past by 1 - - dcurcol += dcurdir; - if (dcurcol == 186) dcurdir = -1; - if (dcurcol == 179) dcurdir = 1; - } + if (gui_debounce) + gui_debounce--; // Debounce GUI keys... + + do_decrement = !do_decrement; // Called at 60Hz, so skip decrementing blink + + if (do_decrement) + { + if (blink) + blink--; // Handle blinking stuff (Should prb go in DrawGUI) + + flash -= 2; // Handle flashing stuff (Should prb go in DrawGUI) + + if (flash == 0xFFFF) + flash = 23; + + iline++; + + if (iline > 30) + iline = 0; // 30 pixels high, going past by 1 + + dcurcol += dcurdir; + + if (dcurcol == 186) + dcurdir = -1; + + if (dcurcol == 179) + dcurdir = 1; + } } + // // Set the refresh rate (30/60 Hz) // void SetRefreshRate(bool refresh) { - game_refresh = refresh; + game_refresh = refresh; } + // // Whether or not GUI is showing // -bool ShowGUI(void) { return show_gui; } +bool ShowGUI(void) +{ + return show_gui; +} + // // Turn the GUI on // -void ActivateGUI(void) { show_gui = true; } +void ActivateGUI(void) +{ + show_gui = true; +} + // // Turn the GUI off // -void DeactivateGUI(void) { show_gui = false; } +void DeactivateGUI(void) +{ + show_gui = false; +} + // // Draw the small icons... // void DrawSmallIcons(uint16_t icon_not_to_draw) { - uint8_t * iconmem; - uint8_t xl, yl; - uint8_t * sIcons[12] = { inoguis, icoinus, ipl1sts, ipl2sts, ii30hzs, ii60hzs, - idipsws, ichecks, ikeycns, isnapss, iresets, ibyebys }; - uint8_t xlens[12] = { 31, 18, 32, 35, 37, 37, 29, 23, 28, 32, 19, 19 }; - uint8_t ylens[12] = { 31, 18, 19, 19, 21, 21, 23, 20, 16, 17, 20, 23 }; - uint8_t xpos[11] = { 33, 48, 63, 78, 104, 0, 184, 210, 225, 240, 255 }; - uint8_t iconidx[11] = { 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 6 }; - - if (game_refresh) iconidx[9] = 5; // 60 Hz... - - // Draw small icons 1 to 5 on left, then 11 to 7 on right. - - for(int i=0; i<5; i++) - { - uint16_t idx = i + icon_not_to_draw; // Get correct start pos. - if (idx > 10) idx -= 11; - - iconmem = sIcons[iconidx[idx]]; - xl = xlens[iconidx[idx]]; yl = ylens[iconidx[idx]]; - - uint32_t scadr = hScrollOffset + voffsets[vScrollOffset]; - scadr += 320*((224-yl)/2); // Center vertically - scadr += xpos[i] - (xl/2); // Center around horiz. pos. - uint16_t bmpptr = 0; - - for(int yy=0; yy5; i--) - { - uint16_t idx = i + icon_not_to_draw; // Get correct start pos. - if (idx > 10) idx -= 11; - - iconmem = sIcons[iconidx[idx]]; - xl = xlens[iconidx[idx]]; yl = ylens[iconidx[idx]]; - - uint32_t scadr = hScrollOffset + voffsets[vScrollOffset]; - scadr += 320*((224-yl)/2); // Center vertically - scadr += xpos[i] - (xl/2); // Center around horiz. pos. - uint16_t bmpptr = 0; - - for(int yy=0; yy 10) + idx -= 11; + + iconmem = sIcons[iconidx[idx]]; + xl = xlens[iconidx[idx]]; + yl = ylens[iconidx[idx]]; + + uint32_t scadr = hScrollOffset + voffsets[vScrollOffset]; + scadr += 320 * ((224 - yl) / 2); // Center vertically + scadr += xpos[i] - (xl / 2); // Center around horiz. pos. + uint16_t bmpptr = 0; + + for(int yy=0; yy5; i--) + { + uint16_t idx = i + icon_not_to_draw; // Get correct start pos. + + if (idx > 10) + idx -= 11; + + iconmem = sIcons[iconidx[idx]]; + xl = xlens[iconidx[idx]]; + yl = ylens[iconidx[idx]]; + + uint32_t scadr = hScrollOffset + voffsets[vScrollOffset]; + scadr += 320 * ((224 - yl) / 2); // Center vertically + scadr += xpos[i] - (xl / 2); // Center around horiz. pos. + uint16_t bmpptr = 0; + + for(int yy=0; yy7) scadr += 17*320; // Adjust for DSW #2 - bmpptr = 0; - if (gram1[0x423D+(i<<1)]) scadr += 12; // Adjust position if ON - for(int yy=0; yy<5; yy++) - { - for(int xx=0; xx<5; xx++) - { - my_scr[scadr++] = idsbutton[bmpptr++]; - } - scadr += 315; // Adjust position... - } - } - uint8_t dselected_text = dseloff[dswitch]; - for(int i=0; i<13; i++) - { - if (dselected_text != i) - { - scadr = dbase + dtxtoff[i]; - if (i>5) scadr += (73*320); - bmpptr = 0; - for(int yy=0; yy5) scadr += (73*320); - bmpptr = 0; - for(int yy=0; yy7) scadr += 17*320; // Adjust for DSW #2 - for(int xx=0; xx<19; xx++) my_scr[scadr++] = dcurcol; - scadr += 301; - for(int xx=0; xx<5; xx++) - { - my_scr[scadr] = dcurcol; scadr += 18; - my_scr[scadr] = dcurcol; scadr += 302; - } - for(int xx=0; xx<19; xx++) my_scr[scadr++] = dcurcol; - } + uint8_t dseloff[16] = { 0, 1, 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 11, 12 }; + uint8_t * dtxt[13] = { idstext1, idstext2, idstext3, idstext4, idstext5, + idstext2, idstext6, idstext7, idstext8, idstext9, idstext10, idstext11, + idstext12 }; + + uint8_t dtx[13] = { 48, 80, 96, 82, 60, 80, 76, 57, 33, 50, 62, 65, 63 }, + dty[13] = { 7, 9, 7, 9, 7, 9, 7, 7, 7, 9, 7, 9, 7 }; + uint32_t dtxtoff[13] = { 4*320+24, 14*320-78, 25*320+24, 32*320-80, + 39*320+24, 49*320-78, 4*320+24, 11*320-55, 18*320+24, 25*320-48, + 32*320+24, 42*320-63, 53*320+24 }; + uint32_t scadr, bmpptr; + //dsx = //26x65 + + uint32_t dbase = hScrollOffset + voffsets[vScrollOffset]; + dbase += (288 - 26) / 2; // Center horizontally + dbase += 320 * ((224 - ((65 * 2) + 8)) / 2); // Center vertically + + scadr = dbase; // Reset screen address + bmpptr = 0; + + for(int yy=0; yy<65; yy++) + { + for(int xx=0; xx<26; xx++) + { + uint8_t b = idswitch[bmpptr++]; + + if (b) + my_scr[scadr + xx + yy * 320] = b; + } + } + + scadr = dbase + (320*73); // Reset screen address + bmpptr = 0; + + for(int yy=0; yy<65; yy++) + { + for(int xx=0; xx<26; xx++) + { + uint8_t b = idswitch[bmpptr++]; + + if (b) + my_scr[scadr + xx + yy * 320] = b; + } + } + + for(int i=0; i<16; i++) + { + scadr = dbase + (5 * 320 + 5) + i * 7 * 320; + + if (i > 7) + scadr += 17*320; // Adjust for DSW #2 + + bmpptr = 0; + + if (gram1[0x423D + (i << 1)]) + scadr += 12; // Adjust position if ON + + for(int yy=0; yy<5; yy++) + { + for(int xx=0; xx<5; xx++) + { + my_scr[scadr++] = idsbutton[bmpptr++]; + } + + scadr += 315; // Adjust position... + } + } + + uint8_t dselected_text = dseloff[dswitch]; + + for(int i=0; i<13; i++) + { + if (dselected_text != i) + { + scadr = dbase + dtxtoff[i]; + + if (i > 5) + scadr += (73 * 320); + + bmpptr = 0; + + for(int yy=0; yy5) + scadr += (73 * 320); + + bmpptr = 0; + + for(int yy=0; yy7) + scadr += 17 * 320; // Adjust for DSW #2 + + for(int xx=0; xx<19; xx++) + my_scr[scadr++] = dcurcol; + + scadr += 301; + + for(int xx=0; xx<5; xx++) + { + my_scr[scadr] = dcurcol; + scadr += 18; + my_scr[scadr] = dcurcol; + scadr += 302; + } + + for(int xx=0; xx<19; xx++) + my_scr[scadr++] = dcurcol; + } } + // // The actual GUI display routine // void DrawGUI(void) { - if (!user_selected_something) // i.e. we're not inside a selection... - { - DrawSmallIcons(selection); // 'selection' is icon *not* to draw - DrawLargeIcon(selection); - } - else - { - if (selection == DIPSWITCH) DrawDipswitch(); - } + if (!user_selected_something) // i.e. we're not inside a selection... + { + DrawSmallIcons(selection); // 'selection' is icon *not* to draw + DrawLargeIcon(selection); + } + else + { + if (selection == DIPSWITCH) + DrawDipswitch(); + } } + // // User pressed left arrow handler // void SelectLeft(void) { - if (!gui_debounce) - { - gui_debounce = 6; - if (!user_selected_something) - { - selection++; - if (selection > 10) selection = 0; - } - else - { - if (gram1[0x423D+(dswitch<<1)]) // It's switchable... - {} //SpawnSound(USERSOUND, SCLICK); - else - {} //SpawnSound(USERSOUND, SUNGH); - gram1[0x423D+(dswitch<<1)] = 0; // & turn it off - } - } + if (!gui_debounce) + { + gui_debounce = 6; + + if (!user_selected_something) + { + selection++; + + if (selection > 10) + selection = 0; + } + else + { + if (gram1[0x423D + (dswitch << 1)]) // It's switchable... + {} //SpawnSound(USERSOUND, SCLICK); + else + {} //SpawnSound(USERSOUND, SUNGH); + + gram1[0x423D + (dswitch << 1)] = 0; // & turn it off + } + } } + // // User pressed right arrow handler // void SelectRight(void) { - if (!gui_debounce) - { - gui_debounce = 6; - if (!user_selected_something) - { - selection--; - if (selection > 10) selection = 10; // Unsigned compare - } - else - { - if (!gram1[0x423D+(dswitch<<1)]) // It's switchable... - {} //SpawnSound(USERSOUND, SCLICK); - else - {} //SpawnSound(USERSOUND, SUNGH); - gram1[0x423D+(dswitch<<1)] = 1; // & turn it on - } - } + if (!gui_debounce) + { + gui_debounce = 6; + + if (!user_selected_something) + { + selection--; + + if (selection > 10) + selection = 10; // Unsigned compare + } + else + { + if (!gram1[0x423D + (dswitch << 1)]) // It's switchable... + {} //SpawnSound(USERSOUND, SCLICK); + else + {} //SpawnSound(USERSOUND, SUNGH); + + gram1[0x423D+(dswitch<<1)] = 1; // & turn it on + } + } } + // // User pressed Up arrow handler // void SelectUp(void) { - if (!gui_debounce) - { - gui_debounce = 6; - if (user_selected_something) - { - if (selection == DIPSWITCH) - { - dswitch--; - if (dswitch > 16) dswitch = 16; // Wrap non-int - //snd_num = dswitch; SpawnMsg(MSHOWNUMS); // Temp... - } - } - } + if (!gui_debounce) + { + gui_debounce = 6; + + if (user_selected_something) + { + if (selection == DIPSWITCH) + { + dswitch--; + + if (dswitch > 16) + dswitch = 16; // Wrap non-int + //snd_num = dswitch; SpawnMsg(MSHOWNUMS); // Temp... + } + } + } } + // // User pressed down arrow handler // void SelectDown(void) { - if (!gui_debounce) - { - gui_debounce = 6; - if (user_selected_something) - { - if (selection == DIPSWITCH) - { - dswitch++; - if (dswitch > 16) dswitch = 0; - //snd_num = dswitch; SpawnMsg(MSHOWNUMS); // Temp... - } - } - } + if (!gui_debounce) + { + gui_debounce = 6; + + if (user_selected_something) + { + if (selection == DIPSWITCH) + { + dswitch++; + + if (dswitch > 16) + dswitch = 0; + //snd_num = dswitch; SpawnMsg(MSHOWNUMS); // Temp... + } + } + } } + // // User selected something! Handle it! // uint8_t UserSelectedSomething(void) { - //extern uint8_t * gram1; - - if (!gui_debounce) - { - gui_debounce = 6; - if (!user_selected_something) // Inside a selection? no... - { - if (selection == NOGUI) // Turn off GUI - { - show_gui = false; - } - if (selection == COINUP) // Coin up machine - { - gram1[0x41A5]++; // Add one coin... (prob. need sep. counter) - num_coins++; - gram1[0x4189] = num_coins/10; // Should be in THUNDER.CPP? - gram1[0x418A] = num_coins - (gram1[0x4189]*10); - } - if (selection == PL1START) // 1 Player start - { - if (num_coins) - { - num_coins--; - show_gui = false; // Shut off GUI only if coined up - } - gram1[0x418C] = 1; // Strobe start location - } - if (selection == PL2START) // 2 Player start - { - if (num_coins > 1) - { - num_coins -= 2; - show_gui = false; - } - } - if (selection == REFRESH) // Toggle refresh rate - { - //SpawnSound(USERSOUND, SCLICK); - } - if (selection == DIPSWITCH) // Edit game settings - { - //SpawnSound(USERSOUND, SBLAH); - user_selected_something = true; - dswitch = 0; // Set at first dipswitch - } - if (selection == OPTIONS) // Edit emulator settings - { - } - if (selection == KEYCONFIG) // Edit game keys - { - } - if (selection == SNAPSHOT) // Snapshot - { - SpawnSound(USERSOUND, SCAMERA); - SnapPCX(screen); - } - if (selection == RESET) // Reset machine - { - //SpawnSound(USERSOUND, SRESET); - } - if (selection == EXIT) - { - SpawnSound(USERSOUND, SCYA); - } - return selection; - } - else // Selected something inside selection... - { - if (selection == DIPSWITCH) - { - if (dswitch == 16) // Selected 'back to GUI' - { - //SpawnSound(USERSOUND, SBLAH2); - user_selected_something = false; - } - else - { - //SpawnSound(USERSOUND, SCLICK); - gram1[0x423D + (dswitch<<1)] = !gram1[0x423D + (dswitch<<1)]; - } - } - return 0xFF; // Nothing for main to do... - } - } - else return 0xFF; // Wasn't debounced, so return invalid + //extern uint8_t * gram1; + + if (!gui_debounce) + { + gui_debounce = 6; + + if (!user_selected_something) // Inside a selection? no... + { + + if (selection == NOGUI) // Turn off GUI + { + show_gui = false; + } + + if (selection == COINUP) // Coin up machine + { + gram1[0x41A5]++; // Add one coin... (prob. need sep. counter) + num_coins++; + gram1[0x4189] = num_coins / 10; // Should be in THUNDER.CPP? + gram1[0x418A] = num_coins - (gram1[0x4189] * 10); + } + + if (selection == PL1START) // 1 Player start + { + if (num_coins) + { + num_coins--; + show_gui = false; // Shut off GUI only if coined up + } + + gram1[0x418C] = 1; // Strobe start location + } + + if (selection == PL2START) // 2 Player start + { + if (num_coins > 1) + { + num_coins -= 2; + show_gui = false; + } + } + + if (selection == REFRESH) // Toggle refresh rate + { + //SpawnSound(USERSOUND, SCLICK); + } + + if (selection == DIPSWITCH) // Edit game settings + { + //SpawnSound(USERSOUND, SBLAH); + user_selected_something = true; + dswitch = 0; // Set at first dipswitch + } + + if (selection == OPTIONS) // Edit emulator settings + { + } + + if (selection == KEYCONFIG) // Edit game keys + { + } + + if (selection == SNAPSHOT) // Snapshot + { + SpawnSound(USERSOUND, SCAMERA); + SnapPCX(screen); + } + + if (selection == RESET) // Reset machine + { + //SpawnSound(USERSOUND, SRESET); + } + + if (selection == EXIT) + { + SpawnSound(USERSOUND, SCYA); + } + + return selection; + } + else // Selected something inside selection... + { + if (selection == DIPSWITCH) + { + if (dswitch == 16) // Selected 'back to GUI' + { + //SpawnSound(USERSOUND, SBLAH2); + user_selected_something = false; + } + else + { + //SpawnSound(USERSOUND, SCLICK); + gram1[0x423D + (dswitch << 1)] = !gram1[0x423D + (dswitch << 1)]; + } + } + + return 0xFF; // Nothing for main to do... + } + } + else + return 0xFF; // Wasn't debounced, so return invalid } + // // Show byte passed to it // void ShowNumbers(int number) { - uint8_t * bnarray[16] = { bn0, bn1, bn2, bn3, bn4, bn5, bn6, bn7, bn8, bn9, - bnA, bnB, bnC, bnD, bnE, bnF }; - uint32_t scadr = hScrollOffset + voffsets[vScrollOffset] + 642 + 2560; - uint16_t bmpptr = 0; - - uint8_t first_dig = number>>4, second_dig = number&0x0F; - for(int y=0; y<7; y++) - { - for(int x=0; x<6; x++) - { - if (bnarray[first_dig][bmpptr++] == 1) my_scr[scadr+x+y*320] = 7; - else my_scr[scadr+x+y*320] = 0; - } - } - bmpptr = 0; scadr += 6; - for(int y=0; y<7; y++) - { - for(int x=0; x<6; x++) - { - if (bnarray[second_dig][bmpptr++] == 1) my_scr[scadr+x+y*320] = 7; - else my_scr[scadr+x+y*320] = 0; - } - } + uint8_t * bnarray[16] = { bn0, bn1, bn2, bn3, bn4, bn5, bn6, bn7, bn8, bn9, + bnA, bnB, bnC, bnD, bnE, bnF }; + uint32_t scadr = hScrollOffset + voffsets[vScrollOffset] + 642 + 2560; + uint16_t bmpptr = 0; + + uint8_t first_dig = number >> 4, second_dig = number & 0x0F; + + for(int y=0; y<7; y++) + { + for(int x=0; x<6; x++) + { + if (bnarray[first_dig][bmpptr++] == 1) + my_scr[scadr + x + y * 320] = 7; + else + my_scr[scadr + x + y * 320] = 0; + } + } + + bmpptr = 0; + scadr += 6; + + for(int y=0; y<7; y++) + { + for(int x=0; x<6; x++) + { + if (bnarray[second_dig][bmpptr++] == 1) + my_scr[scadr + x + y * 320] = 7; + else + my_scr[scadr + x + y * 320] = 0; + } + } } + // // Spawn a message // void SpawnMsg(uint8_t msg) { - text_life = 60; // 1 second... - show_text = true; // Show the damn thing... - show_which_msg = msg; // And tell it which message to show... + text_life = 60; // 1 second... + show_text = true; // Show the damn thing... + show_which_msg = msg; // And tell it which message to show... } + // // Draw text message // void DrawText(void) { - if (!text_life) // Kill text if it's time + // Kill text if it's time + if (!text_life) { show_text = false; return; } - text_life--; // Your life force is running out... + // Your life force is running out... + text_life--; // Draw the message here... uint32_t scadr = hScrollOffset + voffsets[vScrollOffset] + 642; @@ -858,6 +1008,7 @@ void DrawText(void) ShowNumbers(snd_num); } + // // Sound stuff (Will go elsewhere??? Perhaps in sound.cpp?) // @@ -953,17 +1104,20 @@ void SpawnSound(int type, int snd, int channel/* = 0*/) } } + // // Sound card IRQ handler // void SoundFunc(void * userdata, Uint8 * buff, int num) { - uint16_t cnt = 0, sample; // 0-22 different sounds... + // 0-22 different sounds... + uint16_t cnt = 0, sample; uint8_t start_samp1, end_samp1, start_samp2, end_samp2; uint8_t samp1 = 128, samp2 = 128, samp3 = 128, samp4 = 128, samp5 = 128, samp6 = 128; // Zero samples... - memset(buff, 128, num); // Kill sound... + // Kill sound... + memset(buff, 128, num); if (chan1_go || chan2_go || chan3_go || chan4_go || chan5_go || chan6_go) { @@ -975,22 +1129,27 @@ void SoundFunc(void * userdata, Uint8 * buff, int num) { samp1 = voice_rom[spos1++]; + // Kill channel 1 if done... if (samp1 == 0xFF) { chan1_go = false; - samp1 = 128; // Kill channel 1 if done... + samp1 = 128; } - else if (samp1 == 0x00) // RLE compression... + // RLE compression... + else if (samp1 == 0x00) { - sample1 += (float)voice_rom[spos1++] * sampleBase; // # of repeats - samp1 = prevSamp1; // Get last good sample + // # of repeats + sample1 += (float)voice_rom[spos1++] * sampleBase; + // Get last good sample + samp1 = prevSamp1; } else - sample1 += sampleBase; // Keep fractional part intact + // Keep fractional part intact + sample1 += sampleBase; } - prevSamp1 = samp1; // Save last sample value - sample1 -= 1.0; // Decrement repeat counter + prevSamp1 = samp1; // Save last sample value + sample1 -= 1.0; // Decrement repeat counter } // Stretching 5KHz samples to 22KHz: @@ -1022,47 +1181,59 @@ void SoundFunc(void * userdata, Uint8 * buff, int num) sample2 -= 1.0; } - if (chan3_go) - { - samp3 = sndp3[spos3++]; - if (spos3 == end_pos3) - { - chan3_go = false; samp3 = 128; // Kill channel 3 if done... - } - } - - if (chan4_go) - { - samp4 = sndp4[spos4++]; - if (spos4 == end_pos4) - { - chan4_go = false; samp4 = 128; // Kill channel 4 if done... - } - } - - if (chan5_go) - { - samp5 = sndp5[spos5++]; - if (spos5 == end_pos5) - { - chan5_go = false; samp5 = 128; // Kill channel 5 if done... - } - } + if (chan3_go) + { + samp3 = sndp3[spos3++]; + + if (spos3 == end_pos3) + { + chan3_go = false; + samp3 = 128; // Kill channel 3 if done... + } + } + + if (chan4_go) + { + samp4 = sndp4[spos4++]; + + if (spos4 == end_pos4) + { + chan4_go = false; + samp4 = 128; // Kill channel 4 if done... + } + } + + if (chan5_go) + { + samp5 = sndp5[spos5++]; + + if (spos5 == end_pos5) + { + chan5_go = false; + samp5 = 128; // Kill channel 5 if done... + } + } if (chan6_go) { samp6 = sndp6[spos6++]; if (spos6 == end_pos6) - chan6_go = false, samp6 = 128; // Kill channel 6... + { + chan6_go = false; + samp6 = 128; // Kill channel 6... + } } - sample = samp1 + samp2 + samp3 + samp4 + samp5 + samp6 - 640; // Mix 'em... + // Mix 'em... + sample = samp1 + samp2 + samp3 + samp4 + samp5 + samp6 - 640; - if (sample & 0xFF00) // i.e., it overflowed - sample = (sample&0x8000 ? 0x00 : 0xFF); // Clip it + // If it overflowed, clip it + if (sample & 0xFF00) + sample = (sample & 0x8000 ? 0x00 : 0xFF); - buff[cnt++] = sample; // & store it... + buff[cnt++] = sample; } } } + diff --git a/src/resource.asm b/src/resource.asm index e702566..b0fa8b8 100644 --- a/src/resource.asm +++ b/src/resource.asm @@ -54,9 +54,9 @@ ; Sounds -sunknown DD sunknownlen+4 -scya DD scyalen+4 -scamera DD scameralen+4 +sunknown DQ sunknownlen+4 +scya DQ scyalen+4 +scamera DQ scameralen+4 sunknownlen: incbin "unknown.wav", 54 ; Skip header, keep length @@ -67,45 +67,45 @@ scameralen: ; Graphics -inoguib DD fnoguib -idipswb DD fdipswb -ipl1stb DD fpl1stb -ipl2stb DD fpl2stb -ii30hzb DD fi30hzb -ii60hzb DD fi60hzb -icoinub DD fcoinub -isnapsb DD fsnapsb -iresetb DD fresetb -ibyebyb DD fbyebyb -ikeycnb DD fkeycnb +inoguib DQ fnoguib +idipswb DQ fdipswb +ipl1stb DQ fpl1stb +ipl2stb DQ fpl2stb +ii30hzb DQ fi30hzb +ii60hzb DQ fi60hzb +icoinub DQ fcoinub +isnapsb DQ fsnapsb +iresetb DQ fresetb +ibyebyb DQ fbyebyb +ikeycnb DQ fkeycnb -inoguis DD fnoguis -idipsws DD fdipsws -ipl1sts DD fpl1sts -ipl2sts DD fpl2sts -ii30hzs DD fi30hzs -ii60hzs DD fi60hzs -icoinus DD fcoinus -isnapss DD fsnapss -iresets DD fresets -ibyebys DD fbyebys -ikeycns DD fkeycns -ichecks DD fchecks +inoguis DQ fnoguis +idipsws DQ fdipsws +ipl1sts DQ fpl1sts +ipl2sts DQ fpl2sts +ii30hzs DQ fi30hzs +ii60hzs DQ fi60hzs +icoinus DQ fcoinus +isnapss DQ fsnapss +iresets DQ fresets +ibyebys DQ fbyebys +ikeycns DQ fkeycns +ichecks DQ fchecks -idswitch DD fdswitch -idsbutton DD fdsbutton -idstext1 DD fdstext1 -idstext2 DD fdstext2 -idstext3 DD fdstext3 -idstext4 DD fdstext4 -idstext5 DD fdstext5 -idstext6 DD fdstext6 -idstext7 DD fdstext7 -idstext8 DD fdstext8 -idstext9 DD fdstext9 -idstext10 DD fdstext10 -idstext11 DD fdstext11 -idstext12 DD fdstext12 +idswitch DQ fdswitch +idsbutton DQ fdsbutton +idstext1 DQ fdstext1 +idstext2 DQ fdstext2 +idstext3 DQ fdstext3 +idstext4 DQ fdstext4 +idstext5 DQ fdstext5 +idstext6 DQ fdstext6 +idstext7 DQ fdstext7 +idstext8 DQ fdstext8 +idstext9 DQ fdstext9 +idstext10 DQ fdstext10 +idstext11 DQ fdstext11 +idstext12 DQ fdstext12 fnoguib: incbin "noguib.raw" ; 44x44 diff --git a/src/thunder.cpp b/src/thunder.cpp index d3134ed..4cd035c 100644 --- a/src/thunder.cpp +++ b/src/thunder.cpp @@ -1406,6 +1406,7 @@ WriteLog("About to enter main loop...\n"); DeactivateGUI(); else ActivateGUI(); + debounce = 10; } } @@ -1453,28 +1454,38 @@ WriteLog("About to enter main loop...\n"); if (keys[SDLK_RETURN]) // Return { uint8_t retval = UserSelectedSomething(); + if (retval == EXIT) running = false; + if (retval == REFRESH) { refresh2 = !refresh2; SetRefreshRate(refresh2); } } + if (keys[SDLK_1]) gram1[0x427A] = 1; // (1) + if (keys[SDLK_2]) gram1[0x427C] = 1; // (2) + if (keys[SDLK_3]) gram1[0x427E] = 1; // (3) + if (keys[SDLK_5]) 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[SDLK_e] | keys[56]) // (E) Fire { if (!fire_debounce) @@ -1487,30 +1498,41 @@ WriteLog("About to enter main loop...\n"); fire_debounce = 2; } } + 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) + if (keys[SDLK_z]) gram1[0x4189]++; // ? (Z) credits l dig + if (keys[SDLK_x]) gram1[0x418A]++; // ? (X) credits r dig + if (keys[SDLK_c]) gram1[0x418C]++; // ? (C) Start + if (keys[SDLK_v]) gram1[0x418D]++; // ? (V) + if (keys[SDLK_F7]) SpawnSound(USERSOUND, 0); // Do user sound (F7) + // if (keys[SDLK_F8]) // { // gram1[0x4380] = 0; // (F8) kill music (this worx) // charbase = false; // Switch chars out... // } // if (keys[SDLK_F9]) gram1[0x4285] = 1; // (F9) strobe unknown loc + if (keys[SDLK_F11]) // (F11) { Execute6809(&cpu1, 10); @@ -1523,6 +1545,7 @@ WriteLog("About to enter main loop...\n"); cpu1.cpuFlags |= V6809_ASSERT_LINE_RESET; cpu2.cpuFlags |= V6809_ASSERT_LINE_RESET; } + if (keys[SDLK_d]) // (D) start disassembly disasm = true; #if 0 -- 2.37.2