bool8_32 S9xDeinitUpdate (int Width, int Height, bool8_32) { if(mInMenu) return TRUE; u32 newTimer; if (mMenuOptions.showFps) { mFps++; newTimer=sal_TimerRead(); if(newTimer-mLastTimer>Memory.ROMFramesPerSecond) { mLastTimer=newTimer; sprintf(mFpsDisplay,"FPS: %d / %d", mFps, Memory.ROMFramesPerSecond); mFps=0; } sal_VideoDrawRect(0,0,13*8,8,SAL_RGB(0,0,0)); sal_VideoPrint(0,0,mFpsDisplay,SAL_RGB(31,31,31)); } if(mVolumeDisplayTimer>0) { sal_VideoDrawRect(100,0,8*8,8,SAL_RGB(0,0,0)); sal_VideoPrint(100,0,mVolumeDisplay,SAL_RGB(31,31,31)); } if(mQuickStateTimer>0) { sal_VideoDrawRect(200,0,8*8,8,SAL_RGB(0,0,0)); sal_VideoPrint(200,0,mQuickStateDisplay,SAL_RGB(31,31,31)); } sal_VideoFlip(0); }
static u32 sal_Input(int held) { #if 1 SDL_Event event; int i=0; u32 timer=0; if (!SDL_PollEvent(&event)) { if (held) return inputHeld; return 0; } Uint8 type = (event.key.state == SDL_PRESSED); switch(event.key.keysym.sym) { CASE(LCTRL, A); CASE(LALT, B); CASE(SPACE, X); CASE(LSHIFT, Y); CASE(TAB, L); CASE(BACKSPACE, R); CASE(RETURN, START); CASE(ESCAPE, SELECT); CASE(UP, UP); CASE(DOWN, DOWN); CASE(LEFT, LEFT); CASE(RIGHT, RIGHT); } mInputRepeat = inputHeld; #else int i=0; u32 inputHeld=0; u32 timer=0; u8 *keystate; SDL_PumpEvents(); keystate = SDL_GetKeyState(NULL); if ( keystate[SDLK_LCTRL] ) inputHeld|=SAL_INPUT_A; if ( keystate[SDLK_LALT] ) inputHeld|=SAL_INPUT_B; if ( keystate[SDLK_SPACE] ) inputHeld|=SAL_INPUT_X; if ( keystate[SDLK_LSHIFT] ) inputHeld|=SAL_INPUT_Y; if ( keystate[SDLK_TAB] ) inputHeld|=SAL_INPUT_L; if ( keystate[SDLK_BACKSPACE] ) inputHeld|=SAL_INPUT_R; if ( keystate[SDLK_RETURN] ) inputHeld|=SAL_INPUT_START; if ( keystate[SDLK_ESCAPE] ) inputHeld|=SAL_INPUT_SELECT; if ( keystate[SDLK_UP] ) inputHeld|=SAL_INPUT_UP; if ( keystate[SDLK_DOWN] ) inputHeld|=SAL_INPUT_DOWN; if ( keystate[SDLK_LEFT] ) inputHeld|=SAL_INPUT_LEFT; if ( keystate[SDLK_RIGHT] ) inputHeld|=SAL_INPUT_RIGHT; // Process key repeats timer=sal_TimerRead(); for (i=0;i<32;i++) { if (inputHeld&(1<<i)) { if(mInputFirst&(1<<i)) { if (mInputRepeatTimer[i]<timer) { mInputRepeat|=1<<i; mInputRepeatTimer[i]=timer+10; } else { mInputRepeat&=~(1<<i); } } else { //First press of button //set timer to expire later than usual mInputFirst|=(1<<i); mInputRepeat|=1<<i; mInputRepeatTimer[i]=timer+50; } } else { mInputRepeatTimer[i]=timer-10; mInputRepeat&=~(1<<i); mInputFirst&=~(1<<i); } } if(mInputIgnore) { //A request to ignore all key presses until all keys have been released has been made //check for release and clear flag, otherwise clear inputHeld and mInputRepeat if (inputHeld == 0) { mInputIgnore=0; } inputHeld=0; mInputRepeat=0; } #endif return inputHeld; }
static u32 sal_Input(int held) { #if 1 SDL_Event event; int i=0; u32 timer=0; #ifdef GCW_JOYSTICK int deadzone = 10000; Sint32 x_move = 0; Sint32 y_move = 0; #endif if (!SDL_PollEvent(&event)) { if (held) return inputHeld; return 0; } Uint8 type = (event.key.state == SDL_PRESSED); switch(event.key.keysym.sym) { CASE( LCTRL, A ); CASE( LALT, B ); CASE( SPACE, X );//this triggers for some reason on the gcw0 when analogue joystick is on and in a diagonal position if sdl_updatejoystick is called before this point. CASE( LSHIFT, Y ); CASE( TAB, L ); CASE( BACKSPACE, R ); CASE( RETURN, START ); CASE( ESCAPE, SELECT ); CASE( UP, UP ); CASE( DOWN, DOWN ); CASE( LEFT, LEFT ); CASE( RIGHT, RIGHT ); CASE( HOME, MENU ); default: break; } #ifdef GCW_JOYSTICK if(analogJoy && !key_repeat_enabled) { static int j_left = 0; static int j_right = 0; static int j_up = 0; static int j_down = 0; //Update joystick position if (SDL_NumJoysticks() > 0) { SDL_Joystick *joy; joy = SDL_JoystickOpen(0); SDL_JoystickUpdate(); x_move = SDL_JoystickGetAxis(joy, 0); y_move = SDL_JoystickGetAxis(joy, 1); } //Emulate keypresses with joystick if (x_move < -deadzone || x_move > deadzone) { if (x_move < -deadzone) inputHeld |= SAL_INPUT_LEFT; if (x_move > deadzone) inputHeld |= SAL_INPUT_RIGHT; if (x_move < -deadzone) j_left = 1; if (x_move > deadzone) j_right = 1; } else { //stop movement if previously triggered by analogue stick if (j_left) { j_left = 0; inputHeld &= ~(SAL_INPUT_LEFT ); } if (j_right) { j_right = 0; inputHeld &= ~(SAL_INPUT_RIGHT ); } } if (y_move < -deadzone || y_move > deadzone) { if (y_move < -deadzone) inputHeld |= SAL_INPUT_UP; if (y_move > deadzone) inputHeld |= SAL_INPUT_DOWN; if (y_move < -deadzone) j_up = 1; if (y_move > deadzone) j_down = 1; } else { //stop movement if previously triggered by analogue stick if (j_up) { j_up = 0; inputHeld &= ~(SAL_INPUT_UP ); } if (j_down) { j_down = 0; inputHeld &= ~(SAL_INPUT_DOWN ); } } } #endif mInputRepeat = inputHeld; #else int i=0; u32 inputHeld=0; u32 timer=0; u8 *keystate; SDL_PumpEvents(); keystate = SDL_GetKeyState(NULL); if ( keystate[SDLK_LCTRL] ) inputHeld|=SAL_INPUT_A; if ( keystate[SDLK_LALT] ) inputHeld|=SAL_INPUT_B; if ( keystate[SDLK_SPACE] ) inputHeld|=SAL_INPUT_X; if ( keystate[SDLK_LSHIFT] ) inputHeld|=SAL_INPUT_Y; if ( keystate[SDLK_TAB] ) inputHeld|=SAL_INPUT_L; if ( keystate[SDLK_BACKSPACE] ) inputHeld|=SAL_INPUT_R; if ( keystate[SDLK_RETURN] ) inputHeld|=SAL_INPUT_START; if ( keystate[SDLK_ESCAPE] ) inputHeld|=SAL_INPUT_SELECT; if ( keystate[SDLK_UP] ) inputHeld|=SAL_INPUT_UP; if ( keystate[SDLK_DOWN] ) inputHeld|=SAL_INPUT_DOWN; if ( keystate[SDLK_LEFT] ) inputHeld|=SAL_INPUT_LEFT; if ( keystate[SDLK_RIGHT] ) inputHeld|=SAL_INPUT_RIGHT; // Process key repeats timer=sal_TimerRead(); for (i=0; i<32; i++) { if (inputHeld&(1<<i)) { if(mInputFirst&(1<<i)) { if (mInputRepeatTimer[i]<timer) { mInputRepeat|=1<<i; mInputRepeatTimer[i]=timer+10; } else { mInputRepeat&=~(1<<i); } } else { //First press of button //set timer to expire later than usual mInputFirst|=(1<<i); mInputRepeat|=1<<i; mInputRepeatTimer[i]=timer+50; } } else { mInputRepeatTimer[i]=timer-10; mInputRepeat&=~(1<<i); mInputFirst&=~(1<<i); } } if(mInputIgnore) { //A request to ignore all key presses until all keys have been released has been made //check for release and clear flag, otherwise clear inputHeld and mInputRepeat if (inputHeld == 0) { mInputIgnore=0; } inputHeld=0; mInputRepeat=0; } #endif return inputHeld; }
bool8_32 S9xDeinitUpdate (int Width, int Height, bool8_32) { if(mInMenu) return TRUE; // After returning from the menu, clear the background of 3 frames. // This prevents remnants of the menu from appearing. if (mFramesCleared < 3) { sal_VideoClear(0); mFramesCleared++; } // If the height changed from 224 to 239, or from 239 to 224, // possibly change the resolution. bool PAL = !!(Memory.FillRAM[0x2133] & 4); if (PAL != LastPAL) { sal_VideoSetPAL(mMenuOptions.fullScreen, PAL); LastPAL = PAL; } switch (mMenuOptions.fullScreen) { case 0: /* No scaling */ case 3: /* Hardware scaling */ { u32 h = PAL ? SNES_HEIGHT_EXTENDED : SNES_HEIGHT; u32 y, pitch = sal_VideoGetPitch(); u8 *src = (u8*) IntermediateScreen, *dst = (u8*) sal_VideoGetBuffer() + ((sal_VideoGetWidth() - SNES_WIDTH) / 2) * sizeof(u16) + ((sal_VideoGetHeight() - h) / 2) * pitch; for (y = 0; y < h; y++) { memcpy(dst, src, SNES_WIDTH * sizeof(u16)); src += SNES_WIDTH * sizeof(u16); dst += pitch; } break; } case 1: /* Fast software scaling */ if (PAL) { upscale_256x240_to_320x240((uint32_t*) sal_VideoGetBuffer(), (uint32_t*) IntermediateScreen, SNES_WIDTH); } else { upscale_p((uint32_t*) sal_VideoGetBuffer(), (uint32_t*) IntermediateScreen, SNES_WIDTH); } break; case 2: /* Smooth software scaling */ if (PAL) { upscale_256x240_to_320x240_bilinearish((uint32_t*) sal_VideoGetBuffer() + 160, (uint32_t*) IntermediateScreen, SNES_WIDTH); } else { upscale_256x224_to_320x240_bilinearish((uint32_t*) sal_VideoGetBuffer() + 160, (uint32_t*) IntermediateScreen, SNES_WIDTH); } break; } u32 newTimer; if (mMenuOptions.showFps) { mFps++; newTimer=sal_TimerRead(); if(newTimer-mLastTimer>Memory.ROMFramesPerSecond) { mLastTimer=newTimer; sprintf(mFpsDisplay,"%2d/%2d", mFps, Memory.ROMFramesPerSecond); mFps=0; } sal_VideoDrawRect(0,0,5*8,8,SAL_RGB(0,0,0)); sal_VideoPrint(0,0,mFpsDisplay,SAL_RGB(31,31,31)); } if(mVolumeDisplayTimer>0) { sal_VideoDrawRect(100,0,8*8,8,SAL_RGB(0,0,0)); sal_VideoPrint(100,0,mVolumeDisplay,SAL_RGB(31,31,31)); } if(mQuickStateTimer>0) { sal_VideoDrawRect(200,0,8*8,8,SAL_RGB(0,0,0)); sal_VideoPrint(200,0,mQuickStateDisplay,SAL_RGB(31,31,31)); } sal_VideoFlip(0); }
static int Run(int sound) { int skip=0, done=0, doneLast=0,aim=0,i; Settings.NextAPUEnabled = Settings.APUEnabled = sound; sal_TimerInit(Settings.FrameTime); done=sal_TimerRead()-1; if (sound) { /* Settings.SoundPlaybackRate = mMenuOptions.soundRate; Settings.Stereo = mMenuOptions.stereo ? TRUE : FALSE; */ Settings.SixteenBitSound=true; sal_AudioInit(mMenuOptions.soundRate, 16, mMenuOptions.stereo, Memory.ROMFramesPerSecond); S9xInitSound (mMenuOptions.soundRate, mMenuOptions.stereo, sal_AudioGetBufferSize()); S9xSetPlaybackRate(mMenuOptions.soundRate); S9xSetSoundMute (FALSE); } else { S9xSetSoundMute (TRUE); } while(!mEnterMenu) { for (i=0;i<10;i++) { aim=sal_TimerRead(); if (done < aim) { done++; if (mMenuOptions.frameSkip == 0) //Auto IPPU.RenderThisFrame = (done >= aim); else if (IPPU.RenderThisFrame = (--skip <= 0)) skip = mMenuOptions.frameSkip; //Run SNES for one glorious frame S9xMainLoop (); if (sound) { S9xMixSamples((uint8 *) sal_GetCurrentAudioBuffer(), sal_AudioGetSampleCount()); sal_SubmitSamples(); } // HandleQuickStateRequests(); } if (done>=aim) break; // Up to date now if (mEnterMenu) break; } done=aim; // Make sure up to date HandleQuickStateRequests(); } if (sound) sal_AudioClose(); mEnterMenu=0; return mEnterMenu; }