From 73949895d9051c63c1a90cb5b13416fb45474201 Mon Sep 17 00:00:00 2001 From: "LGB (Gabor Lenart)" Date: Mon, 21 Oct 2024 23:12:18 +0200 Subject: [PATCH] MEGA65: adding option to disable mouse emulation The problem: Xemu user may leave mouse grab mode to do something with their mouse. To avoid bothering the mouse-aware MEGA65 program running, I returned zero for relative mouse position change in this case. However that can cause problems with certain programs which are not mouse based and expecting $FF if mouse is not there. --- targets/mega65/configdb.c | 1 + targets/mega65/configdb.h | 1 + targets/mega65/input_devices.c | 24 ++++++++++++++++++------ targets/mega65/ui.c | 4 +++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/targets/mega65/configdb.c b/targets/mega65/configdb.c index cd7bbb39..2e3979b2 100644 --- a/targets/mega65/configdb.c +++ b/targets/mega65/configdb.c @@ -114,6 +114,7 @@ static const struct xemutools_configdef_switch_st switch_options[] = { { "matrixstart", "Start with matrix-mode activated", &configdb.matrixstart }, { "matrixdisable", "Disable the matrix hotkey", &configdb.matrixdisable }, { "ramcheckread", "Enabled warnings on reading unwritten memory (first 126K only)", &configdb.ramcheckread }, + { "nomouseemu", "Disable mouse emulation", &configdb.nomouseemu }, { NULL } }; diff --git a/targets/mega65/configdb.h b/targets/mega65/configdb.h index 90cf2f5c..fbdca089 100644 --- a/targets/mega65/configdb.h +++ b/targets/mega65/configdb.h @@ -115,6 +115,7 @@ struct configdb_st { int ramcheckread; char *init_attic; int joyport; + int nomouseemu; }; extern struct configdb_st configdb; diff --git a/targets/mega65/input_devices.c b/targets/mega65/input_devices.c index 75d4d5fc..2ea1c59b 100644 --- a/targets/mega65/input_devices.c +++ b/targets/mega65/input_devices.c @@ -1,6 +1,6 @@ /* A work-in-progess MEGA65 (Commodore-65 clone origins) emulator Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu - Copyright (C)2016-2023 LGB (Gábor Lénárt) + Copyright (C)2016-2024 LGB (Gábor Lénárt) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -519,9 +519,15 @@ int emu_callback_key ( int pos, SDL_Scancode key, int pressed, int handled ) if (pos == RESTORE_KEY_POS) restore_is_held = 0; if (pos == -2 && key == 0) { // special case pos = -2, key = 0, handled = mouse button (which?) and release event! - 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); + if ((handled == SDL_BUTTON_LEFT)) { + if (configdb.nomouseemu) { + OSD(-1, -1, "Mouse emulation is disabled.\nCannot enter mouse grab mode."); + } else { + if (set_mouse_grab(SDL_TRUE, 0)) { + OSD(-1, -1, "Mouse grab activated. Press\nboth SHIFTs together to cancel."); + DEBUGPRINT("UI: mouse grab activated" NL); + } + } } if (handled == SDL_BUTTON_RIGHT) { ui_enter(); @@ -534,26 +540,32 @@ int emu_callback_key ( int pos, SDL_Scancode key, int pressed, int handled ) Uint8 get_mouse_x_via_sid ( void ) { - static Uint8 result = 0; if (is_mouse_grab()) { + static Uint8 result = 0; static int mouse_x = 0; mouse_x = (mouse_x + (hid_read_mouse_rel_x(-23, 23) / 3)) & 0x3F; DEBUG("MOUSE: X is %d, result byte is %d" NL, mouse_x, result); result = mouse_x << 1; + return result; } + const Uint8 result = configdb.nomouseemu ? 0xFF : 0x00; + DEBUG("MOUSE: X query without mouse-grab is $%02X" NL, result); return result; } Uint8 get_mouse_y_via_sid ( void ) { - static Uint8 result = 0; if (is_mouse_grab()) { + static Uint8 result = 0; static int mouse_y = 0; mouse_y = (mouse_y - (hid_read_mouse_rel_y(-23, 23) / 3)) & 0x3F; DEBUG("MOUSE: Y is %d, result byte is %d" NL, mouse_y, result); result = mouse_y << 1; + return result; } + const Uint8 result = configdb.nomouseemu ? 0xFF : 0x00; + DEBUG("MOUSE: Y query without mouse-grab is $%02X" NL, result); return result; } diff --git a/targets/mega65/ui.c b/targets/mega65/ui.c index b193d0b9..3bc97cd9 100644 --- a/targets/mega65/ui.c +++ b/targets/mega65/ui.c @@ -862,8 +862,10 @@ static const struct menu_st menu_reset[] = { { NULL } }; static const struct menu_st menu_inputdevices[] = { - { "Enable mouse grab + emu", XEMUGUI_MENUID_CALLABLE | + { "Enable mouse grab", XEMUGUI_MENUID_CALLABLE | XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_set_mouse_grab, NULL }, + { "Disable mouse emulation", XEMUGUI_MENUID_CALLABLE | + XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_toggle_int, (void*)&configdb.nomouseemu }, { "Use OSD key debugger", XEMUGUI_MENUID_CALLABLE | XEMUGUI_MENUFLAG_QUERYBACK, xemugui_cb_osd_key_debugger, NULL }, { "Cursor keys as joystick", XEMUGUI_MENUID_CALLABLE |