32 #define DEBUGKBD(...) DEBUG(__VA_ARGS__)
33 #define DEBUGKBDHWA(...) DEBUG(__VA_ARGS__)
34 #define DEBUGKBDHWACOM(...) //DEBUGPRINT(__VA_ARGS__)
45 #define MAT2ASC_TAB_SIZE 72
47 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,0xa3,0x2a,0x3b,0x13,0x00,0x3d,0xAF,0x2f,0x31,0x5f,0x00,0x32,0x20,0x00,0x71,0x03,0x00,0x09,0x00,0x1f,0xf9,0xfb,0xfd,0x1b};
48 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};
49 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};
50 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};
51 static const Uint8 matrix_alt_to_ascii[
MAT2ASC_TAB_SIZE] ={0x7f,0x00,0xdf,0xde,0xB9,0xB2,0xB3,0x00,0xA4,0xAE,0xE5,0xA2,0xF7,0xA7,0xE6,0x00,0xB0,0xAE,0xF0,0xA5,0xE7,0x00,0xFE,0xD7,0xB4,0xFF,0xE8,0xE2,0xFA,0xFD,0xFC,0xd3,0xda,0xED,0xE9,0xdb,0xB5,0xE1,0xF8,0xF1,0xB1,0xB6,0xF3,0xAC,0xBB,0xE4,0xA8,0xAB,0xA3,0xB7,0xE4,0xDC,0xDD,0xA6,0xAF,0xBF,0xA1,0xB8,0x00,0xAA,0xa0,0x00,0xA9,0xBA,0x00,0xC0,0x00,0x1f,0xBC,0xBD,0xBE,0xDB};
53 #define MODKEY_LSHIFT 0x01
54 #define MODKEY_RSHIFT 0x02
55 #define MODKEY_CTRL 0x04
56 #define MODKEY_CBM 0x08
57 #define MODKEY_ALT 0x10
58 #define MODKEY_SCRL 0x20
62 static const Uint8 *matrix_to_ascii_table_selector[32] = {
63 matrix_normal_to_ascii, matrix_shift_to_ascii, matrix_shift_to_ascii, matrix_shift_to_ascii,
64 matrix_control_to_ascii, matrix_control_to_ascii, matrix_control_to_ascii, matrix_control_to_ascii,
65 matrix_cbm_to_ascii, matrix_cbm_to_ascii, matrix_cbm_to_ascii, matrix_cbm_to_ascii,
66 matrix_cbm_to_ascii, matrix_cbm_to_ascii, matrix_cbm_to_ascii, matrix_cbm_to_ascii,
67 matrix_alt_to_ascii, matrix_alt_to_ascii, matrix_alt_to_ascii, matrix_alt_to_ascii,
68 matrix_alt_to_ascii, matrix_alt_to_ascii, matrix_alt_to_ascii, matrix_alt_to_ascii,
69 matrix_cbm_to_ascii, matrix_cbm_to_ascii, matrix_cbm_to_ascii, matrix_cbm_to_ascii,
70 matrix_cbm_to_ascii, matrix_cbm_to_ascii, matrix_cbm_to_ascii, matrix_cbm_to_ascii
73 #define HWA_SINGLE_ITEM
82 static int restore_is_held = 0;
83 static Uint8 virtkey_state[3] = { 0xFF, 0xFF, 0xFF };
89 if (state != hwa_kbd.active_selector) {
90 hwa_kbd.active_selector = state;
91 DEBUGPRINT(
"KBD: hardware accelerated keyboard scanner selector is now %s" NL, state ?
"ENABLED" :
"DISABLED");
106 if (hwa_kbd.next && !hwa_kbd.last) {
107 hwa_kbd.last = hwa_kbd.next;
110 DEBUGKBDHWACOM(
"KBD: HWA: reading key @ PC=$%04X result = $%02X" NL, cpu65.pc, hwa_kbd.last);
118 const Uint8 result = hwa_kbd.modifiers | (hwa_kbd.active_selector ? 0 : 0x80);
119 DEBUGKBDHWACOM(
"KBD: HWA: reading key modifiers @ PC=$%04X result = $%02X" NL, cpu65.pc, result);
127 DEBUGKBDHWACOM(
"KBD: HWA: moving to next key @ PC=$%04X previous queued key = $%02X" NL, cpu65.pc, hwa_kbd.last);
132 #define CHR_EQU(i) ((i >= 32 && i < 127) ? (char)i : '?')
144 static void hwa_kbd_convert_and_push (
int pos )
147 if (pos >= (C65_KEYBOARD_EXTRA_POS) && pos < ((C65_KEYBOARD_EXTRA_POS) + 8)) {
149 scan = pos - (C65_KEYBOARD_EXTRA_POS) + 64;
150 DEBUGKBDHWA(
"KBD: HWA: PUSH: doing C65 extra key translation from kbd pos $%02X to table index $%02X ..." NL, pos, scan);
156 scan = ((pos & 0xF0) >> 1) | (pos & 7);
158 DEBUGKBDHWA(
"KBD: HWA: PUSH: NOT storing key (outside of translation table) from kbd pos $%02X and table index $%02X at PC=$%04X" NL, pos, scan, cpu65.pc);
164 const int ascii = matrix_to_ascii_table_selector[hwa_kbd.active_selector ? (hwa_kbd.modifiers & 0x1F) : 0][scan];
167 DEBUGKBDHWA(
"KBD: HWA: PUSH: storing key $%02X '%c' from kbd pos $%02X and table index $%02X at PC=$%04X" NL, ascii,
CHR_EQU(ascii), pos, scan, cpu65.pc);
168 hwa_kbd.next = ascii;
170 DEBUGKBDHWA(
"KBD: HWA: PUSH: NOT storing key (already waiting) $%02X '%c' from kbd pos $%02X and table index $%02X at PC=$%04X" NL, ascii,
CHR_EQU(ascii), pos, scan, cpu65.pc);
172 DEBUGKBDHWA(
"KBD: HWA: PUSH: NOT storing key (zero in translation table) from kbd pos $%02X and table index $%02X at PC=$%04X" NL, pos, scan, cpu65.pc);
186 return kbd_matrix[(C65_KEYBOARD_EXTRA_POS) >> 4];
196 hwa_kbd.modifiers = 0;
199 for (
int a = 0; a < 3; a++) {
200 if (virtkey_state[0] != 0xFF) {
202 virtkey_state[a] = 0xFF;
221 else if (scancode < 64)
222 scancode = ((scancode & (32 + 16 + 8)) << 1) | (scancode & 7);
224 scancode += C65_KEYBOARD_EXTRA_POS - 64;
225 if (virtkey_state[rno] == scancode)
227 if (virtkey_state[rno] != 0xFF)
229 virtkey_state[rno] = scancode;
230 if (scancode != 0xFF)
237 #ifdef FAKE_TYPING_SUPPORT
238 if (
XEMU_UNLIKELY(c64_fake_typing_enabled) && (((cia1.PRA | (~cia1.DDRA)) & 0xFF) != 0xFF) && (((cia1.PRB | (~cia1.DDRB)) & 0xFF) == 0xFF))
239 c64_handle_fake_typing_internals(cia1.PRA | (~cia1.DDRA));
241 return c64_keyboard_read_on_CIA1_B(
242 cia1.PRA | (~cia1.DDRA),
243 cia1.PRB | (~cia1.DDRB),
252 return c64_keyboard_read_on_CIA1_A(
253 cia1.PRB | (~cia1.DDRB),
254 cia1.PRA | (~cia1.DDRA),
264 if (restore_is_held >= 20) {
271 DEBUGPRINT(
"KBD: *IGNORING* RESTORE trap trigger, already in hypervisor mode!" NL);
277 static void kbd_trigger_alttab_trap (
void )
293 DEBUGPRINT(
"KBD: *IGNORING* MATRIX trap trigger, already in hypervisor mode!" NL);
307 static SDL_Scancode last_scancode_seen = SDL_SCANCODE_UNKNOWN;
308 static int last_poscode_seen = 0;
310 static int emu_callback_key_raw_sdl ( SDL_KeyboardEvent *ev )
312 if (ev->repeat && ev->state == SDL_PRESSED && ev->keysym.scancode == last_scancode_seen) {
313 hwa_kbd_convert_and_push(last_poscode_seen);
335 DEBUGKBD(
"KBD: HWA: pos = %d sdl_key = %d, pressed = %d, handled = %d" NL, pos, key, pressed, handled);
336 static int old_joystick_emu_port;
339 if (pos == TAB_KEY_POS && (hwa_kbd.modifiers &
MODKEY_ALT)) {
340 kbd_trigger_alttab_trap();
350 if (pos >= 0 && pos < 0x100) {
351 hwa_kbd_convert_and_push(pos);
353 last_scancode_seen = key;
354 last_poscode_seen = pos;
357 if (key == SDL_SCANCODE_F10) {
359 }
else if (key == SDL_SCANCODE_KP_ENTER) {
368 if (pos == -2 && key == 0) {
369 if ((handled == SDL_BUTTON_LEFT) &&
set_mouse_grab(SDL_TRUE, 0)) {
370 OSD(-1, -1,
"Mouse grab activated. Press\nboth SHIFTs together to cancel.");
375 if (handled == SDL_BUTTON_RIGHT) {
386 static Uint8 result = 0;
388 static int mouse_x = 0;
390 DEBUG(
"MOUSE: X is %d, result byte is %d" NL, mouse_x, result);
391 result = mouse_x << 1;
399 static Uint8 result = 0;
401 static int mouse_y = 0;
403 DEBUG(
"MOUSE: Y is %d, result byte is %d" NL, mouse_y, result);
404 result = mouse_y << 1;
413 hwa_kbd.active_selector = 1;