diff --git a/src/drivers/sdl/config.cpp b/src/drivers/sdl/config.cpp index cf4cc427..b33755b1 100644 --- a/src/drivers/sdl/config.cpp +++ b/src/drivers/sdl/config.cpp @@ -32,6 +32,21 @@ char *soundrecfn; int ntsccol, ntschue, ntsctint; char *DrBaseDirectory; +static int srendlinev[2]={8,0}; +static int erendlinev[2]={231,239}; + +static int soundvol=100; +static long soundq=0; + +int _sound=1; +long soundrate=48000; +#ifdef WIN32 +long soundbufsize=52; +#else +long soundbufsize=24; +#endif + + DSETTINGS Settings; CFGSTRUCT DriverConfig[]={ #ifdef OPENGL diff --git a/src/drivers/sdl/dface.h b/src/drivers/sdl/dface.h index 90d0ec5e..812fc3b3 100644 --- a/src/drivers/sdl/dface.h +++ b/src/drivers/sdl/dface.h @@ -20,19 +20,10 @@ uint32 GetWriteSound(void); void SilenceSound(int s); /* DOS and SDL */ -int InitMouse(void); -void KillMouse(void); -void GetMouseData(uint32 *MouseData); - int InitJoysticks(void); int KillJoysticks(void); uint32 *GetJSOr(void); -int InitKeyboard(void); -int UpdateKeyboard(void); -char *GetKeyboard(void); -void KillKeyboard(void); - int InitVideo(FCEUGI *gi); int KillVideo(void); void BlitScreen(uint8 *XBuf); @@ -42,20 +33,6 @@ void ToggleFS(); /* SDL */ int LoadGame(const char *path); int CloseGame(void); -int GUI_Init(int argc, char **argv, int (*dofunc)(void)); -int GUI_Idle(void); -int GUI_Update(void); -void GUI_Hide(int); -void GUI_RequestExit(void); -int GUI_SetVideo(int fullscreen, int width, int height); -char *GUI_GetKeyboard(void); -void GUI_GetMouseState(uint32 *b, int *x, int *y); - -void UpdatePhysicalInput(void); -int DTestButton(ButtConfig *bc); -int DWaitButton(const uint8 *text, ButtConfig *bc, int wb); -int ButtonConfigBegin(void); -void ButtonConfigEnd(void); void Giggles(int); void DoFun(void); diff --git a/src/drivers/sdl/input.cpp b/src/drivers/sdl/input.cpp index cc00eb97..f30d6d12 100644 --- a/src/drivers/sdl/input.cpp +++ b/src/drivers/sdl/input.cpp @@ -24,6 +24,8 @@ #include "dface.h" #include "input.h" +#include "sdl-video.h" + #include "../common/cheat.h" /** GLOBALS **/ @@ -102,12 +104,10 @@ static void DoCheatSeq() { SilenceSound(1); - KillKeyboard(); KillVideo(); DoConsoleCheatConfig(); InitVideo(CurGame); - InitKeyboard(); SilenceSound(0); } @@ -136,6 +136,17 @@ _keyonly(int a) static int cidisabled=0; +/** + * Get and return the keyboard state from the SDL. + */ +static uint8 *KeyState = NULL; +static char * +GetKeyboard() +{ + KeyState = SDL_GetKeyState(0); + return ((char *)KeyState); +} + /** * Parse keyboard commands and execute accordingly. */ @@ -369,6 +380,212 @@ static ButtConfig GamePadConfig[4][10]={ }; +/** + * Return the state of the mouse buttons. Input 'd' is an array of 3 + * integers that store . + */ +static void +GetMouseData(uint32 *d) +{ + int x,y; + uint32 t; + + // XXX soules - why don't we do this when a movie is active? + if(FCEUI_IsMovieActive() < 0) + return; + + // retrieve the state of the mouse from SDL + t = SDL_GetMouseState(&x, &y); + + d[2] = 0; + if(t & SDL_BUTTON(1)) { + d[2] |= 0x1; + } + if(t & SDL_BUTTON(3)) { + d[2] |= 0x2; + } + + // get the mouse position from the SDL video driver + t = PtoV(x, y); + d[0] = t & 0xFFFF; + d[1] = (t >> 16) & 0xFFFF; +} + +/** + * Handles outstanding SDL events. + */ +static void +UpdatePhysicalInput() +{ + SDL_Event event; + + // loop, handling all pending events + while(SDL_PollEvent(&event)) { + switch(event.type) { + case SDL_QUIT: + CloseGame(); + puts("Quit"); + break; + default: + // do nothing + break; + } + } + //SDL_PumpEvents(); +} + + +static int bcpv,bcpj; + +/** + * Begin configuring the buttons by placing the video and joystick + * subsystems into a well-known state. Button configuration really + * needs to be cleaned up after the new config system is in place. + */ +static int +ButtonConfigBegin() +{ + SDL_Surface *screen; + + // XXX soules - why are we doing this right before KillVideo()? + SDL_QuitSubSystem(SDL_INIT_VIDEO); + + // shut down the video and joystick subsystems + bcpv=KillVideo(); + bcpj=KillJoysticks(); + + // reactivate the video subsystem + if(!SDL_WasInit(SDL_INIT_VIDEO)) { + if(SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) { + FCEUD_Message(SDL_GetError()); + return(0); + } + } + + // set the screen and notify the user of button configuration + screen = SDL_SetVideoMode(300, 1, 8, 0); + SDL_WM_SetCaption("Button Config",0); + + // XXX soules - why did we shut this down? + // initialize the joystick subsystem + InitJoysticks(); + + return(1); +} + +/** + * Finish configuring the buttons by reverting the video and joystick + * subsystems to their previous state. Button configuration really + * needs to be cleaned up after the new config system is in place. + */ +static void +ButtonConfigEnd() +{ + extern FCEUGI *CurGame; + + // shutdown the joystick and video subsystems + KillJoysticks(); + SDL_QuitSubSystem(SDL_INIT_VIDEO); + + // re-initialize joystick and video subsystems if they were active before + if(!bcpv) { + InitVideo(CurGame); + } + if(!bcpj) { + InitJoysticks(); + } +} + +/** + * Involved with updating the button configuration, but not entirely + * sure how yet - soules. + */ +static int +DTestButton(ButtConfig *bc) +{ + int x; + + for(x = 0; x < bc->NumC; x++) { + if(bc->ButtType[x] == BUTTC_KEYBOARD) { + if(KeyState[bc->ButtonNum[x]]) { + return(1); + } + } else if(bc->ButtType[x] == BUTTC_JOYSTICK) { + if(DTestButtonJoy(bc)) { + return(1); + } + } + } + return(0); +} + + +/** + * Waits for a button input and returns the information as to which + * button was pressed. Used in button configuration. + */ +static int +DWaitButton(const uint8 *text, + ButtConfig *bc, + int wb) +{ + SDL_Event event; + static int32 LastAx[64][64]; + int x,y; + + SDL_WM_SetCaption((const char *)text,0); + puts((const char *)text); + for(x = 0; x < 64; x++) { + for(y = 0; y < 64; y++) { + LastAx[x][y]=0x100000; + } + } + + while(SDL_WaitEvent(&event)) { + switch(event.type) { + case SDL_KEYDOWN: + bc->ButtType[wb] = BUTTC_KEYBOARD; + bc->DeviceNum[wb] = 0; + bc->ButtonNum[wb] = event.key.keysym.sym; + return(1); + case SDL_JOYBUTTONDOWN: + bc->ButtType[wb] = BUTTC_JOYSTICK; + bc->DeviceNum[wb] = event.jbutton.which; + bc->ButtonNum[wb] = event.jbutton.button; + return(1); + case SDL_JOYHATMOTION: + if(event.jhat.value != SDL_HAT_CENTERED) { + bc->ButtType[wb] = BUTTC_JOYSTICK; + bc->DeviceNum[wb] = event.jhat.which; + bc->ButtonNum[wb] = (0x2000 | ((event.jhat.hat & 0x1F) << 8) | + event.jhat.value); + return(1); + } + break; + case SDL_JOYAXISMOTION: + if(LastAx[event.jaxis.which][event.jaxis.axis] == 0x100000) { + if(abs(event.jaxis.value) < 1000) { + LastAx[event.jaxis.which][event.jaxis.axis] = event.jaxis.value; + } + } else { + if(abs(LastAx[event.jaxis.which][event.jaxis.axis] - event.jaxis.value) >= 8192) { + bc->ButtType[wb] = BUTTC_JOYSTICK; + bc->DeviceNum[wb] = event.jaxis.which; + bc->ButtonNum[wb] = (0x8000 | event.jaxis.axis | + ((event.jaxis.value < 0) + ? 0x4000 : 0)); + return(1); + } + } + break; + } + } + + return(0); +} + + + /** * Update the gamepad button configurations. */ @@ -613,10 +830,6 @@ InitOtherInput() FCEUI_SetInputFC(InputType[2], InputDPtr, attrib); FCEUI_DisableFourScore(eoptions & EO_NOFOURSCORE); - - if(t) { - InitMouse(); - } } diff --git a/src/drivers/sdl/input.h b/src/drivers/sdl/input.h index f9fbf36e..0a835771 100644 --- a/src/drivers/sdl/input.h +++ b/src/drivers/sdl/input.h @@ -34,5 +34,7 @@ extern ButtConfig FTrainerButtons[12]; void IncreaseEmulationSpeed(void); void DecreaseEmulationSpeed(void); +int DTestButtonJoy(ButtConfig *bc); + void FCEUD_UpdateInput(void); #endif diff --git a/src/drivers/sdl/main.h b/src/drivers/sdl/main.h index dd70f30f..8663e1a8 100644 --- a/src/drivers/sdl/main.h +++ b/src/drivers/sdl/main.h @@ -34,11 +34,8 @@ extern int eoptions; #define EO_LOWPASS 512 #define EO_AUTOHIDE 1024 -extern int srendlinev[2],erendlinev[2]; extern int NoWaiting; -extern int soundvol; -extern long soundq; extern int _sound; extern long soundrate; extern long soundbufsize; diff --git a/src/drivers/sdl/sdl.cpp b/src/drivers/sdl/sdl.cpp index e542f6b6..1d73340b 100644 --- a/src/drivers/sdl/sdl.cpp +++ b/src/drivers/sdl/sdl.cpp @@ -28,116 +28,6 @@ #endif -/** - * Unimplemented. Returns 0. - */ -int -InitMouse(void) -{ - return 0; -} - -/** - * Unimplemented. - */ -void -KillMouse() -{ } - -/** - * Return the state of the mouse buttons. Input 'd' is an array of 3 - * integers that store . - */ -void -GetMouseData(uint32 *d) -{ - int x,y; - uint32 t; - - // XXX soules - why don't we do this when a movie is active? - if(FCEUI_IsMovieActive() < 0) - return; - - // retrieve the state of the mouse from SDL - t = SDL_GetMouseState(&x, &y); - - d[2] = 0; - if(t & SDL_BUTTON(1)) { - d[2] |= 0x1; - } - if(t & SDL_BUTTON(3)) { - d[2] |= 0x2; - } - - // get the mouse position from the SDL video driver - t = PtoV(x, y); - d[0] = t & 0xFFFF; - d[1] = (t >> 16) & 0xFFFF; -} - -/** - * Unimplemented. Returns 1. - */ -int -InitKeyboard() -{ - return 1; -} - -/** - * Unimplemented. Returns 1. - */ -int -UpdateKeyboard() -{ - return 1; -} - -/** - * Unimplemented. - */ -void -KillKeyboard() -{ - -} - - -/** - * Handles outstanding SDL events. - */ -void -UpdatePhysicalInput() -{ - SDL_Event event; - - // loop, handling all pending events - while(SDL_PollEvent(&event)) { - switch(event.type) { - case SDL_QUIT: - CloseGame(); - puts("Quit"); - break; - default: - // do nothing - break; - } - } - //SDL_PumpEvents(); -} - -/** - * Get and return the keyboard state from the SDL. - */ -static uint8 *KeyState = NULL; -char * -GetKeyboard() -{ - KeyState = SDL_GetKeyState(0); - return ((char *)KeyState); -} - - #ifdef OPENGL int sdlhaveogl; #endif @@ -147,23 +37,9 @@ extern int32 fps_scale; int CloseGame(void); -int soundvol=100; -long soundq=0; -int _sound=1; -long soundrate=48000; -#ifdef WIN32 -long soundbufsize=52; -#else -long soundbufsize=24; -#endif - static int inited=0; static int isloaded=0; // Is game loaded? -int srendlinev[2]={8,0}; -int erendlinev[2]={231,239}; - - int eoptions=0; static void DriverKill(void); @@ -172,15 +48,6 @@ int gametype = 0; FCEUGI *CurGame=NULL; -/** - * Wrapper for ParseGIInput(). - */ -static void -ParseGI(FCEUGI *gi) -{ - ParseGIInput(gi); - gametype = gi->type; -} /** * Prints an error string to STDOUT. @@ -260,8 +127,8 @@ int LoadGame(const char *path) if(!(tmp = FCEUI_LoadGame(path, 1))) { return 0; } - CurGame=tmp; - ParseGI(tmp); + CurGame = tmp; + ParseGIInput(tmp); RefreshThrottleFPS(); if(!DriverInitialize(tmp)) { @@ -273,7 +140,7 @@ int LoadGame(const char *path) soundrecfn=0; } } - isloaded=1; + isloaded = 1; FCEUD_NetworkConnect(); return 1; @@ -290,8 +157,8 @@ CloseGame() } FCEUI_CloseGame(); DriverKill(); - isloaded=0; - CurGame=0; + isloaded = 0; + CurGame = 0; if(soundrecfn) { FCEUI_EndWaveRecord(); @@ -308,13 +175,13 @@ void DoFun(void) uint8 *gfx; int32 *sound; int32 ssize; - static int fskipc=0; - static int opause=0; + static int fskipc = 0; + static int opause = 0; #ifdef FRAMESKIP - fskipc=(fskipc+1)%(frameskip+1); + fskipc = (fskipc + 1) % (frameskip + 1); #endif - + if(NoWaiting) { gfx = 0; } @@ -329,14 +196,14 @@ void DoFun(void) /** - * Initialize all of the subsystem drivers: video, audio, joystick, - * keyboard, mouse. + * Initialize all of the subsystem drivers: video, audio, and joystick. */ static int DriverInitialize(FCEUGI *gi) { #ifndef WIN32 - SetSignals(CloseStuff); + // XXX soules - capturing all these signals seems pointless + //SetSignals(CloseStuff); #endif /* Initialize video before all else, due to some wacko dependencies @@ -352,16 +219,12 @@ DriverInitialize(FCEUGI *gi) if(InitJoysticks()) inited|=2; - if(!InitKeyboard()) return 0; - inited|=8; - InitOtherInput(); return 1; } /** - * Shut down all of the subsystem drivers: video, audio, joystick, - * keyboard. + * Shut down all of the subsystem drivers: video, audio, and joystick. */ static void DriverKill() @@ -369,19 +232,16 @@ DriverKill() SaveConfig(); #ifndef WIN32 - SetSignals(SIG_IGN); + // XXX soules - capturing all these signals seems pointless + //SetSignals(SIG_IGN); #endif if(inited&2) KillJoysticks(); - if(inited&8) - KillKeyboard(); if(inited&4) KillVideo(); if(inited&1) KillSound(); - if(inited&16) - KillMouse(); inited=0; } @@ -494,153 +354,6 @@ void FCEUD_TraceInstruction() { } -/** - * Involved with updating the button configuration, but not entirely - * sure how yet - soules. - */ -int DTestButton(ButtConfig *bc) -{ - int x; - - for(x = 0; x < bc->NumC; x++) { - if(bc->ButtType[x] == BUTTC_KEYBOARD) { - if(KeyState[bc->ButtonNum[x]]) { - return(1); - } - } else if(bc->ButtType[x] == BUTTC_JOYSTICK) { - if(DTestButtonJoy(bc)) { - return(1); - } - } - } - return(0); -} - -static int bcpv,bcpj; - -/** - * Begin configuring the buttons by placing the video and joystick - * subsystems into a well-known state. Button configuration really - * needs to be cleaned up after the new config system is in place. - */ -int -ButtonConfigBegin() -{ - SDL_Surface *screen; - - // XXX soules - why are we doing this right before KillVideo()? - SDL_QuitSubSystem(SDL_INIT_VIDEO); - - // shut down the video and joystick subsystems - bcpv=KillVideo(); - bcpj=KillJoysticks(); - - // reactivate the video subsystem - if(!SDL_WasInit(SDL_INIT_VIDEO)) { - if(SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) { - FCEUD_Message(SDL_GetError()); - return(0); - } - } - - // set the screen and notify the user of button configuration - screen = SDL_SetVideoMode(300, 1, 8, 0); - SDL_WM_SetCaption("Button Config",0); - - // XXX soules - why did we shut this down? - // initialize the joystick subsystem - InitJoysticks(); - - return(1); -} - -/** - * Finish configuring the buttons by reverting the video and joystick - * subsystems to their previous state. Button configuration really - * needs to be cleaned up after the new config system is in place. - */ -void -ButtonConfigEnd() -{ - extern FCEUGI *CurGame; - - // shutdown the joystick and video subsystems - KillJoysticks(); - SDL_QuitSubSystem(SDL_INIT_VIDEO); - - // re-initialize joystick and video subsystems if they were active before - if(!bcpv) { - InitVideo(CurGame); - } - if(!bcpj) { - InitJoysticks(); - } -} - -/** - * Waits for a button input and returns the information as to which - * button was pressed. Used in button configuration. - */ -int -DWaitButton(const uint8 *text, - ButtConfig *bc, - int wb) -{ - SDL_Event event; - static int32 LastAx[64][64]; - int x,y; - - SDL_WM_SetCaption((const char *)text,0); - puts((const char *)text); - for(x = 0; x < 64; x++) { - for(y = 0; y < 64; y++) { - LastAx[x][y]=0x100000; - } - } - - while(SDL_WaitEvent(&event)) { - switch(event.type) { - case SDL_KEYDOWN: - bc->ButtType[wb] = BUTTC_KEYBOARD; - bc->DeviceNum[wb] = 0; - bc->ButtonNum[wb] = event.key.keysym.sym; - return(1); - case SDL_JOYBUTTONDOWN: - bc->ButtType[wb] = BUTTC_JOYSTICK; - bc->DeviceNum[wb] = event.jbutton.which; - bc->ButtonNum[wb] = event.jbutton.button; - return(1); - case SDL_JOYHATMOTION: - if(event.jhat.value != SDL_HAT_CENTERED) { - bc->ButtType[wb] = BUTTC_JOYSTICK; - bc->DeviceNum[wb] = event.jhat.which; - bc->ButtonNum[wb] = (0x2000 | ((event.jhat.hat & 0x1F) << 8) | - event.jhat.value); - return(1); - } - break; - case SDL_JOYAXISMOTION: - if(LastAx[event.jaxis.which][event.jaxis.axis] == 0x100000) { - if(abs(event.jaxis.value) < 1000) { - LastAx[event.jaxis.which][event.jaxis.axis] = event.jaxis.value; - } - } else { - if(abs(LastAx[event.jaxis.which][event.jaxis.axis] - event.jaxis.value) >= 8192) { - bc->ButtType[wb] = BUTTC_JOYSTICK; - bc->DeviceNum[wb] = event.jaxis.which; - bc->ButtonNum[wb] = (0x8000 | event.jaxis.axis | - ((event.jaxis.value < 0) - ? 0x4000 : 0)); - return(1); - } - } - break; - } - } - - return(0); -} - /** * The main loop for the SDL. */ diff --git a/src/drivers/sdl/sdl.h b/src/drivers/sdl/sdl.h index 791316a8..feaf07a4 100644 --- a/src/drivers/sdl/sdl.h +++ b/src/drivers/sdl/sdl.h @@ -3,8 +3,6 @@ #include "dface.h" #include "input.h" -int DTestButtonJoy(ButtConfig *bc); - typedef struct { int xres; int yres;