Better support for keypad emulated joystick

* Allow for automatic recentering of keypad emulated joystick
    * Force X11 to give us a detectable auto-repeat
This commit is contained in:
Aaron Culliney 2013-12-28 21:48:42 -08:00
parent f8d338b382
commit ffd78508ba
6 changed files with 43 additions and 14 deletions

View File

@ -4,7 +4,7 @@ mode = //e
disk path = /usr/local/games/apple2/disks
color = interpolated
volume = 8
joystick = pc joystick
joystick = joy keypad
system path = /usr/local/games/apple2/rom
pc joystick parms = 128 128 255 1 255 1 6
keypad joystick parms = 16
keypad joystick parms = 8 1

View File

@ -39,7 +39,8 @@ unsigned char joy_button0 = 0;
unsigned char joy_button1 = 0;
#ifdef KEYPAD_JOYSTICK
short joy_step;
short joy_step = 1;
uint8_t auto_recenter = 0;
#endif
#ifdef PC_JOYSTICK
@ -360,8 +361,8 @@ static void c_calibrate_keypad_joystick()
"| | . | 1 @ 3 |",
"| | | Alt-l Alt-r |",
"| | | |",
"| | | |",
"| | | |",
"| | | + toggles auto- |",
"| | | recentering: @@@ |",
"| | | < or > to change |",
"| ||||||||||||||||| sensitivity: @@ |",
"| |",
@ -393,6 +394,9 @@ static void c_calibrate_keypad_joystick()
snprintf(temp, TEMPSIZE, "%02x", (uint8_t)joy_step);
copy_and_pad_string(&submenu[KEYPAD_SUBMENU_H-4][36], temp, ' ', 3, ' ');
snprintf(temp, TEMPSIZE, "%s", auto_recenter ? " on" : "off" );
copy_and_pad_string(&submenu[KEYPAD_SUBMENU_H-6][35], temp, ' ', 4, ' ');
int x_plot = CALIBRATE_TURTLE_KP_X0 + (int)(joy_x * CALIBRATE_TURTLE_KP_STEP_X);
int y_plot = CALIBRATE_TURTLE_KP_Y0 + (int)(joy_y * CALIBRATE_TURTLE_STEP_Y);
@ -426,6 +430,15 @@ static void c_calibrate_keypad_joystick()
++joy_step;
}
}
else if (ch == '+')
{
auto_recenter = (auto_recenter+1) % 2;
if (auto_recenter)
{
joy_x = HALF_JOY_RANGE;
joy_y = HALF_JOY_RANGE;
}
}
static struct timespec ts = { .tv_sec=0, .tv_nsec=33333333 };
nanosleep(&ts, NULL);

View File

@ -398,6 +398,14 @@ void c_handle_input(int scancode, int pressed)
#if defined(KEYPAD_JOYSTICK)
else if (joy_mode == JOY_KPAD)
{
bool joy_axis_unpressed = (!pressed && ((scancode == SCODE_J_U) || (scancode == SCODE_J_D) || (scancode == SCODE_J_L) || (scancode == SCODE_J_R)) );
if (key_pressed[ SCODE_J_C ] || (auto_recenter && joy_axis_unpressed))
{
joy_x = HALF_JOY_RANGE;
joy_y = HALF_JOY_RANGE;
}
if (key_pressed[ SCODE_J_U ])
{
if (joy_y > joy_step)
@ -445,14 +453,9 @@ void c_handle_input(int scancode, int pressed)
joy_x = JOY_RANGE-1;
}
}
if (key_pressed[ SCODE_J_C ])
{
joy_x = HALF_JOY_RANGE;
joy_y = HALF_JOY_RANGE;
}
}
#endif
#if defined(PC_JOYSTICK)
else if ((joy_mode == JOY_PCJOY) && !(js_fd < 0))
{

View File

@ -330,11 +330,13 @@ void load_settings(void)
{
joy_step = 1;
}
else
if (joy_step > 255)
else if (joy_step > 255)
{
joy_step = 255;
}
auto_recenter = strtol(argument, &argument, 10);
break;
#endif
@ -415,7 +417,7 @@ bool save_settings(void)
#ifdef KEYPAD_JOYSTICK
err = fprintf(config_file,
"keypad joystick parms = %d\n", joy_step);
"keypad joystick parms = %d %u\n", joy_step, auto_recenter ? 1 : 0);
#endif
anErr = anErr || (err < 0);

View File

@ -55,6 +55,7 @@ extern joystick_mode_t joy_mode;
#ifdef KEYPAD_JOYSTICK
extern short joy_step;
extern uint8_t auto_recenter;
#endif
#ifdef PC_JOYSTICK

View File

@ -898,6 +898,16 @@ void video_init() {
// reset Apple2 softframebuffers
memset(video__fb1,0,SCANWIDTH*SCANHEIGHT);
memset(video__fb2,0,SCANWIDTH*SCANHEIGHT);
#ifdef KEYPAD_JOYSTICK
int autorepeat_supported = 0;
XkbGetDetectableAutoRepeat(display, &autorepeat_supported);
if (autorepeat_supported)
{
LOG("Xkb Setting detectable autorepeat ...");
XkbSetDetectableAutoRepeat(display, true, NULL);
}
#endif
}
void video_shutdown(void)