int MainMenu(void *bkg) { int cmd, prev = 0; int mode; PaletteAdjust(); mode = MODE_MAIN; while (mode != MODE_QUIT && mode != MODE_PLAY) { memcpy(GetDstScreen(), bkg, SCREEN_MEMSIZE); ShowControls(); if (mode == MODE_MAIN) ShowCredits(); GetMenuCmd(&cmd); if (cmd == prev) cmd = 0; else prev = cmd; mode = MakeSelection(mode, cmd); CopyToScreen(); SDL_Delay(10); } WaitForRelease(); return mode == MODE_PLAY; }
int PlayerEquip(void *bkg) { int cmd1, cmd2, prev1 = 0, prev2 = 0; int done1 = 0, done2; debug(D_NORMAL, "\n"); done2 = gOptions.twoPlayers ? 0 : 1; while (!done1 || !done2) { memcpy(GetDstScreen(), bkg, SCREEN_MEMSIZE); GetPlayerCmd(&cmd1, &cmd2); if (KeyDown(keyEsc)) return 0; // hack to exit from menu if (gOptions.twoPlayers) { if (cmd1 == prev1) cmd1 = 0; else prev1 = cmd1; // if (!done1) // || !gPlayer1Data.weaponCount < MAX_WEAPONS) done1 = !WeaponSelection(CenterOfLeft(50), CHARACTER_PLAYER1, &gPlayer1Data, cmd1, done1); ShowSelection(CenterOfLeft(50), &gPlayer1Data,CHARACTER_PLAYER1); ShowPlayerControls(CenterOfLeft(100), &gPlayer1Data); if (cmd2 == prev2) cmd2 = 0; else prev2 = cmd2; // if (!done2) // || gPlayer2Data.weaponCount < MAX_WEAPONS) done2 = !WeaponSelection(CenterOfRight(50), CHARACTER_PLAYER2, &gPlayer2Data, cmd2, done2); ShowSelection(CenterOfRight(50), &gPlayer2Data, CHARACTER_PLAYER2); ShowPlayerControls(CenterOfRight(100), &gPlayer2Data); } else { if (cmd1 == prev1) cmd1 = 0; else prev1 = cmd1; if (!done1) // || gPlayer1Data.weaponCount <= 0) done1 = !WeaponSelection(CenterX(80), CHARACTER_PLAYER1, &gPlayer1Data, cmd1, done1); ShowSelection(CenterX(80), &gPlayer1Data, CHARACTER_PLAYER1); ShowPlayerControls(CenterX(100), &gPlayer1Data); } CopyToScreen(); } WaitForRelease(); return 1; }
int PlayerSelection(int twoPlayers, void *bkg) { int cmd1, cmd2, prev1 = 0, prev2 = 0; int mode1, mode2; mode1 = MODE_MAIN; mode2 = twoPlayers ? MODE_MAIN : MODE_DONE; SetPlayer(0, &gPlayer1Data); SetPlayer(1, &gPlayer2Data); while (mode1 != MODE_DONE || mode2 != MODE_DONE) { memcpy(GetDstScreen(), bkg, SCREEN_MEMSIZE); GetPlayerCmd(&cmd1, &cmd2); if (KeyDown(keyEsc)) return 0; // hack to allow exit if (twoPlayers) { if (cmd1 == prev1) cmd1 = 0; else prev1 = cmd1; mode1 = MakeSelection(mode1, CenterOfLeft(50), CHARACTER_PLAYER1, &gPlayer1Data, cmd1); if (cmd2 == prev2) cmd2 = 0; else prev2 = cmd2; mode2 = MakeSelection(mode2, CenterOfRight(50), CHARACTER_PLAYER2, &gPlayer2Data, cmd2); } else { if (cmd1 == prev1) cmd1 = 0; else prev1 = cmd1; mode1 = MakeSelection(mode1, CenterX(50), CHARACTER_PLAYER1, &gPlayer1Data, cmd1); } CopyToScreen(); } WaitForRelease(); return 1; }
// Timer A0 interrupt service routine. void timera_isr(void) __interrupt[TIMERA0_VECTOR] { // Toggle LED. //P1OUT ^= 0x01; //OPTIMIZATION: disable this interrupt most of the time: it should only be enabled at the end //of the serial/keypad interrupt //most of the time = if tasks[button] == 0 && tasks[keypad] == 0 //do not optimize for this as the variables mey be re-enabled by an interrupt if (tasks[button] == 1){ //the actual key value is scanned in the interrupt routine if (time == 0){ //debounce done KeyScan(); if (edge == 1){ //falling edge if (keyDown == 1){ //a key is down, which means it was NOT a real falling edge event time = BOUNCE_DELAY; return; } #ifdef DEBUG debug_printf("Button was released\n"); #endif //check if key code is correct? //check if it matches rising edge code? //send data to cpld, depending on game logic SetForPress(); } else { //rising edge if (keyDown == 0){ //no key is down, which means it was noise tasks[button] = 0; //nothing to do, it was just a glitch } WaitForRelease(); #ifdef DEBUG debug_printf("Button is Down\n"); #endif } } else{ //decrease the waiting time time --; } } }
void ShowTitle( void ) { SDL_FillRect( g_frontSurface, &g_frontSurface->clip_rect, SDL_MapRGB( g_frontSurface->format, 0, 0, 0 ) ); SDLU_Present(); RetrieveResources( ); int time = MTickCount() + 120; while( time > MTickCount() && !SDLU_Button() ) { DrawPICTInSurface( g_frontSurface, picTitle ); SDLU_Present(); SDLU_Yield(); } WaitForRelease(); QuickFadeOut( NULL ); SDL_FillRect( g_frontSurface, &g_frontSurface->clip_rect, SDL_MapRGB( g_frontSurface->format, 0, 0, 0 ) ); SDLU_Present(); }
void Wait(void) { WaitForRelease(); WaitForPress(); WaitForRelease(); }
int main(int argc, char *argv[]) { // Initialize the SDL library // This is required to avoid _main errors at runtime. #ifdef UseSDLMixer if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) { #else if ( SDL_Init(SDL_INIT_VIDEO ) < 0 ) { #endif fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } // Init SDL_Image - only applies above 1.2.7 // load support for the JPG and PNG image formats int IMGflags=IMG_INIT_JPG|IMG_INIT_PNG; int initted=IMG_Init(IMGflags); if(initted && IMGflags != IMGflags) { printf("IMG_Init: Failed to init required jpg and png support!\n"); printf("IMG_Init: %s\n", IMG_GetError()); // handle error } #ifdef UseSDLMixer // Initialize SDL mixer. if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) != 0) { fprintf(stderr, "Unable to initialize audio: %s\n", Mix_GetError()); exit(1); } #endif // Retrieve display gamma for reference in fade in/fade out routines. SDL_GetGammaRamp(redGamma, greenGamma, blueGamma); // printf("%u", *redGamma); Initialize( ); LoadPrefs( ); ReserveMonitor( ); ShowTitle( ); ChooseMusic( 13 ); while( !finished ) { if( showStartMenu ) { GameStartMenu( ); showStartMenu = false; } if( !finished ) { DoFullRepaint = NeedRefresh; CheckKeys( ); HandlePlayers( ); UpdateOpponent( ); UpdateBalloon( ); UpdateSound( ); DoFullRepaint = NoPaint; if( needsRefresh ) { RefreshAll(); needsRefresh = false; } if( !showStartMenu && pauseKey ) { FreezeGameTickCount( ); PauseMusic( ); MaskRect( &playerWindowRect[0] ); MaskRect( &playerWindowRect[1] ); WaitForRelease( ); HandleDialog( kPauseDialog ); WaitForRelease( ); RefreshPlayerWindow( 0 ); RefreshPlayerWindow( 1 ); ResumeMusic( ); UnfreezeGameTickCount( ); } } } SavePrefs( ); ReleaseMonitor( ); return 0; } void NoPaint( void ) { } void MaskRect( MRect *r ) { SDL_Rect sdlRect; SDLU_MRectToSDLRect( r, &sdlRect ); SDLU_BlitFrontSurface( backdropSurface, &sdlRect, &sdlRect ); }