Skip to content

Commit

Permalink
MEGA65: fix joy port swap with mouse grab #415
Browse files Browse the repository at this point in the history
Also adding an config option '-joyport N' (N can be 1 or 2) as a CLI
option to select the default emulated port. Also, now the configuration
can be saved which preserves the "swap state" of ports.

The original problem was discovered by @gurcei when he noticed that
using the UI menu's "swap port" functionalty does nothing. It was
because for some reason I wrote code to force port-1 when in mouse grab
mode. Which is bad ...
  • Loading branch information
lgblgblgb committed Sep 24, 2024
1 parent dae4fa2 commit a2c06b7
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions targets/mega65/configdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ static const struct xemutools_configdef_num_st num_options[] = {
{ "sidmask", 15, "Enabled SIDs of the four, in form of a bitmask", &configdb.sidmask, 0, 15 },
{ "audiobuffersize", AUDIO_BUFFER_SAMPLES_DEFAULT, "Audio buffer size in BYTES", &configdb.audiobuffersize, AUDIO_BUFFER_SAMPLES_MIN, AUDIO_BUFFER_SAMPLES_MAX },
{ "coloureffect", 0, "Colour effect to be applied to the SDL output (0=none, 1=grayscale, 2=green-monitor, ...)", &configdb.colour_effect, 0, 255 },
{ "joyport", 2, "Default joystick port to emulate (1 or 2)", &configdb.joyport, 1, 2 },
{ NULL }
};

Expand Down
1 change: 1 addition & 0 deletions targets/mega65/configdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ struct configdb_st {
char *winpos;
int ramcheckread;
char *init_attic;
int joyport;
};

extern struct configdb_st configdb;
Expand Down
5 changes: 1 addition & 4 deletions targets/mega65/input_devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ void clear_emu_events ( void )
void input_toggle_joy_emu ( void )
{
c64_toggle_joy_emu();
configdb.joyport = joystick_emu;
OSD(-1, -1, "Joystick emulation on port #%d", joystick_emu);
}

Expand Down Expand Up @@ -482,7 +483,6 @@ int emu_callback_key ( int pos, SDL_Scancode key, int pressed, int handled )
#endif
;
DEBUGKBD("KBD: HWA: pos = %d sdl_key = %d, pressed = %d, handled = %d" NL, pos, key, pressed, handled);
static int old_joystick_emu_port; // used to remember emulated joy port, as with mouse grab, we need to switch to port-1, and we want to restore user's one on leaving grab mode
if (pressed) {
// check if we have the ALT-TAB trap triggered (TAB is pressed now, and ALT is hold)
if (key == SDL_SCANCODE_TAB && (modkeys & MODKEY_CTRL)) {
Expand Down Expand Up @@ -514,7 +514,6 @@ int emu_callback_key ( int pos, SDL_Scancode key, int pressed, int handled )
input_toggle_joy_emu();
} else if (((modkeys & (MODKEY_LSHIFT | MODKEY_RSHIFT)) == (MODKEY_LSHIFT | MODKEY_RSHIFT)) && set_mouse_grab(SDL_FALSE, 0)) {
DEBUGPRINT("UI: mouse grab cancelled" NL);
joystick_emu = old_joystick_emu_port;
}
} else {
if (pos == RESTORE_KEY_POS)
Expand All @@ -523,8 +522,6 @@ int emu_callback_key ( int pos, SDL_Scancode key, int pressed, int handled )
if ((handled == SDL_BUTTON_LEFT) && set_mouse_grab(SDL_TRUE, 0)) {
OSD(-1, -1, " Mouse grab activated. Press \n both SHIFTs together to cancel.");
DEBUGPRINT("UI: mouse grab activated" NL);
old_joystick_emu_port = joystick_emu;
joystick_emu = 1;
}
if (handled == SDL_BUTTON_RIGHT) {
ui_enter();
Expand Down
2 changes: 1 addition & 1 deletion targets/mega65/mega65.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ static void mega65_init ( void )
#ifdef HID_KBD_MAP_CFG_SUPPORT
hid_keymap_from_config_file(configdb.keymap);
#endif
joystick_emu = 2; // use joystick port #2 by default
joystick_emu = configdb.joyport;
nmi_level = 0;
// *** FPGA switches ...
do {
Expand Down

0 comments on commit a2c06b7

Please sign in to comment.