mirror of
https://github.com/digarok/gsplus.git
synced 2024-11-28 04:49:18 +00:00
working joystick
This commit is contained in:
parent
300e766fcb
commit
d55965c129
@ -32,9 +32,16 @@
|
||||
# include <time.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SDL
|
||||
# include "SDL.h"
|
||||
static SDL_Joystick *joy0, *joy1;
|
||||
SDL_Joystick *gGameController = NULL;
|
||||
#endif
|
||||
|
||||
extern int g_joystick_native_type1; /* in paddles.c */
|
||||
extern int g_joystick_native_type2; /* in paddles.c */
|
||||
extern int g_joystick_native_type; /* in paddles.c */
|
||||
extern int g_joystick_type;
|
||||
extern int g_paddle_buttons;
|
||||
extern int g_paddle_val[];
|
||||
|
||||
@ -248,6 +255,74 @@ joystick_update_buttons()
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_SDL
|
||||
# define JOYSTICK_DEFINED
|
||||
void
|
||||
joystick_init()
|
||||
{
|
||||
int i;
|
||||
if( SDL_Init( SDL_INIT_JOYSTICK ) < 0 ) {
|
||||
printf( "SDL could not initialize joystick! SDL Error: %s\n", SDL_GetError() );
|
||||
} else {
|
||||
printf( "SDL initialize joystick successfully.\n");
|
||||
}
|
||||
if (SDL_NumJoysticks()<1) {
|
||||
printf ("No joysticks detected\n");
|
||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||
}
|
||||
gGameController = SDL_JoystickOpen( 0 );
|
||||
if( gGameController == NULL ) {
|
||||
printf( "Warning: Unable to open game controller! SDL Error: %s\n", SDL_GetError() );
|
||||
}
|
||||
g_joystick_native_type = 2;
|
||||
g_joystick_native_type1 = 2;
|
||||
g_joystick_native_type2 = -1;
|
||||
for(i = 0; i < 4; i++) {
|
||||
g_paddle_val[i] = 180;
|
||||
}
|
||||
g_paddle_buttons = 1;
|
||||
g_joystick_type = JOYSTICK_TYPE_NATIVE_1;
|
||||
SDL_JoystickUpdate();
|
||||
joystick_update(0.0);
|
||||
}
|
||||
|
||||
void
|
||||
joystick_update(double dcycs)
|
||||
{
|
||||
if (gGameController) {
|
||||
SDL_JoystickUpdate();
|
||||
g_paddle_val[0] = (int)SDL_JoystickGetAxis(gGameController, 0);
|
||||
g_paddle_val[1] = (int)SDL_JoystickGetAxis(gGameController, 1);
|
||||
if (SDL_JoystickGetButton(gGameController, 0)) {
|
||||
g_paddle_buttons = g_paddle_buttons | 1;
|
||||
} else {
|
||||
g_paddle_buttons = g_paddle_buttons & (~1);
|
||||
}
|
||||
if (SDL_JoystickGetButton(gGameController, 1)) {
|
||||
g_paddle_buttons = g_paddle_buttons | 2;
|
||||
} else {
|
||||
g_paddle_buttons = g_paddle_buttons & (~2);
|
||||
}
|
||||
paddle_update_trigger_dcycs(dcycs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
joystick_update_buttons()
|
||||
{
|
||||
}
|
||||
|
||||
void joystick_shut() {
|
||||
SDL_JoystickClose( gGameController );
|
||||
gGameController = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef JOYSTICK_DEFINED
|
||||
/* stubs for the routines */
|
||||
void
|
||||
|
@ -19,6 +19,10 @@
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
// This is an experimental video driver for the KEGS/GSport emulator.
|
||||
// It requires SDL2 libraries to build. I've tested on Mac, but should
|
||||
// be easy to port to other platforms. -DagenBrock
|
||||
|
||||
// @todo: mouse clip bugs.. great western shootout.
|
||||
// @todo: force refresh after screen mode change
|
||||
|
||||
@ -293,8 +297,7 @@ void sdl_push_kimage(Kimage *kimage_ptr,
|
||||
int pixel_size = 4;
|
||||
src_ptr = kimage_ptr->data_ptr + (srcy * kimage_ptr->width_act + srcx) * pixel_size;
|
||||
//src_ptr = kimage_ptr->data_ptr;
|
||||
//src_ptr = kimage_ptr->data_ptr;
|
||||
//src_ptr = xim->data;
|
||||
|
||||
SDL_Rect dstrect;
|
||||
dstrect.x = destx;
|
||||
dstrect.y = desty;
|
||||
@ -303,6 +306,7 @@ void sdl_push_kimage(Kimage *kimage_ptr,
|
||||
int pitch = 640;
|
||||
if (width < 560) {
|
||||
pitch = EFF_BORDER_WIDTH;
|
||||
// This is another bad hack. Possibly not cross platform.
|
||||
pitch = BORDER_WIDTH+72;
|
||||
//printf("EFF_BORDER_WIDTH : %d" ,EFF_BORDER_WIDTH);
|
||||
}
|
||||
@ -340,12 +344,14 @@ x_get_kimage(Kimage *kimage_ptr) {
|
||||
kimage_ptr->data_ptr = data;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
check_input_events()
|
||||
{
|
||||
check_input_events_sdl();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
check_input_events_sdl()
|
||||
{
|
||||
@ -379,7 +385,6 @@ check_input_events_sdl()
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
sdl_keysym_to_a2code(int keysym, int is_up)
|
||||
{
|
||||
@ -423,7 +428,6 @@ sdl_keysym_to_a2code(int keysym, int is_up)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
handle_sdl_key_event(SDL_Event event)
|
||||
{
|
||||
@ -517,6 +521,7 @@ x_push_kimage(Kimage *kimage_ptr, int destx, int desty, int srcx, int srcy, int
|
||||
sdl_push_kimage(kimage_ptr, destx, desty, srcx, srcy, width, height);
|
||||
}
|
||||
|
||||
|
||||
// called by src/sim65816.c
|
||||
void
|
||||
x_dialog_create_gsport_conf(const char *str)
|
||||
|
Loading…
Reference in New Issue
Block a user