working joystick

This commit is contained in:
Dagen Brock 2016-01-29 12:13:04 -06:00
parent 300e766fcb
commit d55965c129
2 changed files with 93 additions and 13 deletions

View File

@ -32,9 +32,16 @@
# include <time.h> # include <time.h>
#endif #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_type1; /* in paddles.c */
extern int g_joystick_native_type2; /* 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_native_type; /* in paddles.c */
extern int g_joystick_type;
extern int g_paddle_buttons; extern int g_paddle_buttons;
extern int g_paddle_val[]; extern int g_paddle_val[];
@ -248,6 +255,74 @@ joystick_update_buttons()
} }
#endif #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 #ifndef JOYSTICK_DEFINED
/* stubs for the routines */ /* stubs for the routines */
void void

View File

@ -19,6 +19,10 @@
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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: mouse clip bugs.. great western shootout.
// @todo: force refresh after screen mode change // @todo: force refresh after screen mode change
@ -293,8 +297,7 @@ void sdl_push_kimage(Kimage *kimage_ptr,
int pixel_size = 4; int pixel_size = 4;
src_ptr = kimage_ptr->data_ptr + (srcy * kimage_ptr->width_act + srcx) * pixel_size; 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 = kimage_ptr->data_ptr;
//src_ptr = xim->data;
SDL_Rect dstrect; SDL_Rect dstrect;
dstrect.x = destx; dstrect.x = destx;
dstrect.y = desty; dstrect.y = desty;
@ -303,6 +306,7 @@ void sdl_push_kimage(Kimage *kimage_ptr,
int pitch = 640; int pitch = 640;
if (width < 560) { if (width < 560) {
pitch = EFF_BORDER_WIDTH; pitch = EFF_BORDER_WIDTH;
// This is another bad hack. Possibly not cross platform.
pitch = BORDER_WIDTH+72; pitch = BORDER_WIDTH+72;
//printf("EFF_BORDER_WIDTH : %d" ,EFF_BORDER_WIDTH); //printf("EFF_BORDER_WIDTH : %d" ,EFF_BORDER_WIDTH);
} }
@ -340,12 +344,14 @@ x_get_kimage(Kimage *kimage_ptr) {
kimage_ptr->data_ptr = data; kimage_ptr->data_ptr = data;
} }
void void
check_input_events() check_input_events()
{ {
check_input_events_sdl(); check_input_events_sdl();
} }
void void
check_input_events_sdl() check_input_events_sdl()
{ {
@ -379,7 +385,6 @@ check_input_events_sdl()
} }
int int
sdl_keysym_to_a2code(int keysym, int is_up) sdl_keysym_to_a2code(int keysym, int is_up)
{ {
@ -423,7 +428,6 @@ sdl_keysym_to_a2code(int keysym, int is_up)
} }
void void
handle_sdl_key_event(SDL_Event event) 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); sdl_push_kimage(kimage_ptr, destx, desty, srcx, srcy, width, height);
} }
// called by src/sim65816.c // called by src/sim65816.c
void void
x_dialog_create_gsport_conf(const char *str) x_dialog_create_gsport_conf(const char *str)