Skip to content

Commit

Permalink
MEGA65: mouse mods, D610 HELP key
Browse files Browse the repository at this point in the history
* Mouse position query modifications suggested by M3wP on Discord
* Mouse grab mode now switches to joy port-1 automatically
* Missing HELP key in $D610 keyboard scanner
* make showmatrix2ascii target to extract mat2asc tables from VHDL
  • Loading branch information
lgblgblgb committed Feb 23, 2022
1 parent d7d9406 commit 5511091
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
10 changes: 5 additions & 5 deletions build/m65-import-matrix2ascii.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ BEGIN {
print "/* from src/vhdl/matrix_to_ascii.vhdl in mega65-core project */"
grab = ""
}
/^\s*signal\s+matrix_(normal|shift|control|cbm)/ {
/^\s*signal\s+matrix_(normal|shift|control|cbm|alt)/ {
grab = $2
gsub(":.*$","",grab)
grab = "static const Uint8 " grab "_to_ascii [] = {"
comma = " "
grab = "static const Uint8 " grab "_to_ascii[MAT2ASC_TAB_SIZE] = {"
comma = ""
next
}
grab && ($1 ~ /^others|)/) {
print grab " };"
print grab "};"
grab = ""
next
}
Expand All @@ -24,4 +24,4 @@ grab && $0 ~ /^\s*[0-9]+\s*=>\s*[xX]"/ {
comma = ","
next
}
' < ../../../mega65-core/src/vhdl/matrix_to_ascii.vhdl
'
3 changes: 3 additions & 0 deletions targets/mega65/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ recreatememcontent:
echo "const int meminitdata_freezer_size = sizeof(meminitdata_freezer);" >> memcontent.c.tmp
cp memcontent.c memcontent.c.BAK
@echo "*** OK. Please rename memcontent.c.tmp to memcontent.c and memcontent_sizes.h.tmp to memcontent_sizes.h to really apply these changes, then re-compile the emulator ***"

showmatrix2ascii:
$(TOPDIR)/build/m65-import-matrix2ascii.sh < $(MEGA65_CORE)/src/vhdl/matrix_to_ascii.vhdl
44 changes: 26 additions & 18 deletions targets/mega65/input_devices.c
Original file line number Diff line number Diff line change
@@ -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-2021 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
Copyright (C)2016-2022 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
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
Expand Down Expand Up @@ -42,11 +42,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
// 64 possibility of C64 keys (ie, the 8*8 matrix) + 8 extra C65 keys = 72
#define MAT2ASC_TAB_SIZE 72

static const Uint8 matrix_normal_to_ascii[MAT2ASC_TAB_SIZE] ={0x14,0x0D,0x1d,0xf7,0xf1,0xf3,0xf5,0x11,0x33,0x77,0x61,0x34,0x7a,0x73,0x65,0x00,0x35,0x72,0x64,0x36,0x63,0x66,0x74,0x78,0x37,0x79,0x67,0x38,0x62,0x68,0x75,0x76,0x39,0x69,0x6a,0x30,0x6d,0x6b,0x6f,0x6e,0x2b,0x70,0x6c,0x2d,0x2e,0x3a,0x40,0x2c,0x00,0x2a,0x3b,0x13,0x00,0x3d,0x00,0x2f,0x31,0x5f,0x00,0x32,0x20,0x00,0x71,0x03,0x00,0x09,0x00,0x00,0xf9,0xfb,0xfd,0x1b};
static const Uint8 matrix_shift_to_ascii[MAT2ASC_TAB_SIZE] ={0x94,0x0D,0x9d,0xf8,0xf2,0xf4,0xf6,0x91,0x23,0x57,0x41,0x24,0x5a,0x53,0x45,0x00,0x25,0x52,0x44,0x26,0x43,0x46,0x54,0x58,0x27,0x59,0x47,0x28,0x42,0x48,0x55,0x56,0x29,0x49,0x4a,0x7b,0x4d,0x4b,0x4f,0x4e,0x00,0x50,0x4c,0x00,0x3e,0x5b,0x00,0x3c,0x00,0x00,0x5d,0x93,0x00,0x5f,0x00,0x3f,0x21,0x60,0x00,0x22,0x20,0x00,0x51,0xa3,0x00,0x0f,0x00,0x00,0xfa,0xfc,0xfe,0x1b};
static const Uint8 matrix_control_to_ascii[MAT2ASC_TAB_SIZE]={0x94,0x0D,0x9d,0xf8,0xf2,0xf4,0xf6,0x91,0x1c,0x17,0x01,0x9f,0x1a,0x13,0x05,0x00,0x9c,0x12,0x04,0x1e,0x03,0x06,0x14,0x18,0x1f,0x19,0x07,0x9e,0x02,0x08,0x15,0x16,0x12,0x09,0x0a,0x00,0x0d,0x0b,0x0f,0x0e,0x2b,0x10,0x0c,0x2d,0x2e,0x3a,0x40,0x2c,0x00,0xEF,0x3b,0x93,0x00,0x3d,0x00,0x2f,0x90,0x60,0x00,0x05,0x20,0x00,0x11,0xa3,0x00,0x0f,0x00,0x00,0xfa,0xfc,0xfe,0x1b};
static const Uint8 matrix_cbm_to_ascii[MAT2ASC_TAB_SIZE] ={0x94,0x0D,0xED,0xf8,0xf2,0xf4,0xf6,0xEE,0x96,0xd7,0xc1,0x97,0xda,0xd3,0xc5,0x00,0x98,0xd2,0xc4,0x99,0xc3,0xc6,0xd4,0xd8,0x9a,0xd9,0xc7,0x9b,0xc2,0xc8,0xd5,0xd6,0x92,0xc9,0xca,0x81,0xcd,0xcb,0xcf,0xce,0x2b,0xd0,0xcc,0x2d,0x7c,0x7b,0x40,0x7e,0x00,0x2A,0x7d,0x93,0x00,0x5f,0x00,0x5c,0x81,0x60,0x00,0x95,0x20,0x00,0xd1,0xa3,0x00,0xef,0x00,0x00,0xfa,0xfc,0xfe,0x1b};
static const Uint8 matrix_alt_to_ascii[MAT2ASC_TAB_SIZE] ={0x00,0x00,0x00,0x00,0xB9,0xB2,0xB3,0x00,0xA4,0xAE,0xE5,0xA2,0xF7,0xA7,0xE6,0x00,0xB0,0xAE,0xF0,0xA5,0xE7,0x00,0xFE,0xD7,0xB4,0xFF,0x00,0x00,0xFA,0xFD,0xFC,0x00,0x00,0xED,0xE9,0x00,0xB5,0xE1,0xF8,0xF1,0xB1,0xB6,0xF3,0xAC,0xBB,0xE4,0xA8,0xAB,0xA3,0xB7,0xE4,0x00,0x00,0xAF,0x00,0xBF,0xA1,0x00,0x00,0x00,0x00,0x00,0xA9,0x00,0x00,0x00,0x00,0x00,0xBC,0xBD,0xBE,0x00};
static const Uint8 matrix_normal_to_ascii[MAT2ASC_TAB_SIZE] ={0x14,0x0D,0x1d,0xf7,0xf1,0xf3,0xf5,0x11,0x33,0x77,0x61,0x34,0x7a,0x73,0x65,0x00,0x35,0x72,0x64,0x36,0x63,0x66,0x74,0x78,0x37,0x79,0x67,0x38,0x62,0x68,0x75,0x76,0x39,0x69,0x6a,0x30,0x6d,0x6b,0x6f,0x6e,0x2b,0x70,0x6c,0x2d,0x2e,0x3a,0x40,0x2c,0x00,0x2a,0x3b,0x13,0x00,0x3d,0x00,0x2f,0x31,0x5f,0x00,0x32,0x20,0x00,0x71,0x03,0x00,0x09,0x00,0x1f,0xf9,0xfb,0xfd,0x1b};
static const Uint8 matrix_shift_to_ascii[MAT2ASC_TAB_SIZE] ={0x94,0x0D,0x9d,0xf8,0xf2,0xf4,0xf6,0x91,0x23,0x57,0x41,0x24,0x5a,0x53,0x45,0x00,0x25,0x52,0x44,0x26,0x43,0x46,0x54,0x58,0x27,0x59,0x47,0x28,0x42,0x48,0x55,0x56,0x29,0x49,0x4a,0x7b,0x4d,0x4b,0x4f,0x4e,0x00,0x50,0x4c,0x00,0x3e,0x5b,0x00,0x3c,0x00,0x00,0x5d,0x93,0x00,0x5f,0x00,0x3f,0x21,0x60,0x00,0x22,0x20,0x00,0x51,0xa3,0x00,0x0f,0x00,0x1f,0xfa,0xfc,0xfe,0x1b};
static const Uint8 matrix_control_to_ascii[MAT2ASC_TAB_SIZE]={0x94,0x0D,0x9d,0xf8,0xf2,0xf4,0xf6,0x91,0x1c,0x17,0x01,0x9f,0x1a,0x13,0x05,0x00,0x9c,0x12,0x04,0x1e,0x03,0x06,0x14,0x18,0x1f,0x19,0x07,0x9e,0x02,0x08,0x15,0x16,0x12,0x09,0x0a,0x00,0x0d,0x0b,0x0f,0x0e,0x2b,0x10,0x0c,0x2d,0x2e,0x3a,0x40,0x2c,0x00,0xEF,0x3b,0x93,0x00,0x3d,0x00,0x2f,0x90,0x60,0x00,0x05,0x20,0x00,0x11,0xa3,0x00,0x0f,0x00,0x1f,0xfa,0xfc,0xfe,0x1b};
static const Uint8 matrix_cbm_to_ascii[MAT2ASC_TAB_SIZE] ={0x94,0x0D,0xED,0xf8,0xf2,0xf4,0xf6,0xEE,0x96,0xd7,0xc1,0x97,0xda,0xd3,0xc5,0x00,0x98,0xd2,0xc4,0x99,0xc3,0xc6,0xd4,0xd8,0x9a,0xd9,0xc7,0x9b,0xc2,0xc8,0xd5,0xd6,0x92,0xc9,0xca,0x81,0xcd,0xcb,0xcf,0xce,0x2b,0xd0,0xcc,0x2d,0x7c,0x7b,0x40,0x7e,0x00,0x2A,0x7d,0x93,0x00,0x5f,0x00,0x5c,0x81,0x60,0x00,0x95,0x20,0x00,0xd1,0xa3,0x00,0xef,0x00,0x1f,0xfa,0xfc,0xfe,0x1b};
static const Uint8 matrix_alt_to_ascii[MAT2ASC_TAB_SIZE] ={0x00,0x00,0x00,0x00,0xB9,0xB2,0xB3,0x00,0xA4,0xAE,0xE5,0xA2,0xF7,0xA7,0xE6,0x00,0xB0,0xAE,0xF0,0xA5,0xE7,0x00,0xFE,0xD7,0xB4,0xFF,0x00,0x00,0xFA,0xFD,0xFC,0x00,0x00,0xED,0xE9,0x00,0xB5,0xE1,0xF8,0xF1,0xB1,0xB6,0xF3,0xAC,0xBB,0xE4,0xA8,0xAB,0xA3,0xB7,0xE4,0x00,0x00,0xAF,0x00,0xBF,0xA1,0x00,0x00,0x00,0x00,0x00,0xA9,0x00,0x00,0x00,0x00,0x1f,0xBC,0xBD,0xBE,0x00};

#define MODKEY_LSHIFT 0x01
#define MODKEY_RSHIFT 0x02
Expand Down Expand Up @@ -313,6 +313,7 @@ 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 (pos == TAB_KEY_POS && (hwa_kbd.modifiers & MODKEY_ALT)) {
Expand All @@ -339,6 +340,7 @@ int emu_callback_key ( int pos, SDL_Scancode key, int pressed, int handled )
input_toggle_joy_emu();
} else if (((hwa_kbd.modifiers & (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 @@ -347,6 +349,8 @@ 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\nboth 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 All @@ -359,21 +363,25 @@ int emu_callback_key ( int pos, SDL_Scancode key, int pressed, int handled )

Uint8 get_mouse_x_via_sid ( void )
{
if (!is_mouse_grab())
return 0xFF;
static int mouse_x = 0;
mouse_x = (mouse_x + hid_read_mouse_rel_x(-31, 31)) & 63;
DEBUG("MOUSE-X: reading X as %d" NL, mouse_x << 1);
return mouse_x << 1;
static Uint8 result = 0;
if (is_mouse_grab()) {
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;
}


Uint8 get_mouse_y_via_sid ( void )
{
if (!is_mouse_grab())
return 0xFF;
static int mouse_y = 0;
mouse_y = (mouse_y - hid_read_mouse_rel_y(-31, 31)) & 63;
DEBUG("MOUSE-Y: reading Y as %d" NL, mouse_y << 1);
return mouse_y << 1;
static Uint8 result = 0;
if (is_mouse_grab()) {
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;
}
2 changes: 1 addition & 1 deletion targets/mega65/input_devices.h
Original file line number Diff line number Diff line change
@@ -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-2021 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
Copyright (C)2016-2022 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
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
Expand Down

1 comment on commit 5511091

@lgblgblgb
Copy link
Owner Author

@lgblgblgb lgblgblgb commented on 5511091 Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change in mega65-core reflected here with the HELP key: MEGA65/mega65-core@9412a83 according to bug MEGA65/mega65-core#296 Also see xemu bug: #148
Mouse emulation change suggested by M3wP: #321

Please sign in to comment.