Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
c64_kbd_mapping.h
Go to the documentation of this file.
1 /* Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
2  Copyright (C)2016-2020 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17 
18 #ifndef __XEMU_COMMON_C64_KBD_MAPPING
19 #define __XEMU_COMMON_C64_KBD_MAPPING
20 
21 // Keyboard position of "shift" which is "virtually pressed" ie for cursor up/left
22 #define VIRTUAL_SHIFT_POS 0x64
23 
24 #define LSHIFT_KEY_POS 0x17
25 #define RSHIFT_KEY_POS 0x64
26 #define CBM_KEY_POS 0x75
27 #define CTRL_KEY_POS 0x72
28 
29 #define IS_KEY_PRESSED(pos) (!(kbd_matrix[(pos) >> 4] & (1 << ((pos) & 7))))
30 
31 #define RESTORE_KEY_POS 0x80
32 #define CAPSLOCK_KEY_POS 0x81
33 #define IS_RESTORE_PRESSED() IS_KEY_PRESSED(RESTORE_KEY_POS)
34 //#define IS_RESTORE_PRESSED() (!(kbd_matrix[RESTORE_KEY_POS >> 4] & (1 << (RESTORE_KEY_POS & 7))))
35 
36 #ifdef C65_KEYBOARD
37 #define C65_KEYBOARD_EXTRA_POS 0x90
38 #define SCRL_KEY_POS (C65_KEYBOARD_EXTRA_POS + 0)
39 #define TAB_KEY_POS (C65_KEYBOARD_EXTRA_POS + 1)
40 #define ALT_KEY_POS (C65_KEYBOARD_EXTRA_POS + 2)
41 #endif
42 
43 extern const struct KeyMappingDefault c64_key_map[];
44 extern int joystick_emu;
45 
46 extern Uint8 c64_get_joy_state ( void );
47 extern void c64_toggle_joy_emu ( void );
48 
49 static XEMU_INLINE Uint8 c64_keyboard_read_on_CIA1_B ( Uint8 kbsel_a, Uint8 effect_b, Uint8 joy_state
50 #ifdef C65_KEYBOARD
51  , int kbsel_c65_special
52 #endif
53 )
54 {
55  // selected line(s) for scan: LOW pin state on port A, while reading in port B
56  // CIA uses pull-ups, output can be LOW only, if port data is zero, and ddr is output (thus being 1)
57  // so the "caller" of this func will do something like this:
58  // kbsel_a = cia1.PRA | (~cia1.DDRA)
59  // effect_b = cia1.PRB | (~cia1.DDRB)
60  // the second is needed: the read value is still low, if the port we're reading on is configured for output with port value set 0
61  //DEBUGPRINT("USING#1, extra row = %02X" NL, kbd_matrix[(C65_KEYBOARD_EXTRA_POS) >> 4]);
62  return
63 #ifdef C65_KEYBOARD
64  ((kbsel_c65_special) ? 0xFF : kbd_matrix[(C65_KEYBOARD_EXTRA_POS) >> 4]) &
65 #endif
66  ((kbsel_a & 1) ? 0xFF : kbd_matrix[0]) &
67  ((kbsel_a & 2) ? 0xFF : kbd_matrix[1]) &
68  ((kbsel_a & 4) ? 0xFF : kbd_matrix[2]) &
69  ((kbsel_a & 8) ? 0xFF : kbd_matrix[3]) &
70  ((kbsel_a & 16) ? 0xFF : kbd_matrix[4]) &
71  ((kbsel_a & 32) ? 0xFF : kbd_matrix[5]) &
72  ((kbsel_a & 64) ? 0xFF : kbd_matrix[6]) &
73  ((kbsel_a & 128) ? 0xFF : kbd_matrix[7]) &
74  joy_state &
75  effect_b
76  ;
77 }
78 
79 static XEMU_INLINE Uint8 c64_keyboard_read_on_CIA1_A ( Uint8 kbsel_b, Uint8 effect_a, Uint8 joy_state )
80 {
81  // For description on this logic, please see comments at c64_keyboard_read_on_CIA1_B() above.
82  // The theory is the same, however here we use the negated value. it's not because it's different by hardware
83  // but because we handle kbsel_b value differently than with c64_keyboard_read_on_CIA1_B(), that's all!
84  kbsel_b = ~kbsel_b;
85  return (
86 #ifdef C65_KEYBOARD
87 #endif
88  (((kbd_matrix[0] & kbsel_b) == kbsel_b) ? 1 : 0) |
89  (((kbd_matrix[1] & kbsel_b) == kbsel_b) ? 2 : 0) |
90  (((kbd_matrix[2] & kbsel_b) == kbsel_b) ? 4 : 0) |
91  (((kbd_matrix[3] & kbsel_b) == kbsel_b) ? 8 : 0) |
92  (((kbd_matrix[4] & kbsel_b) == kbsel_b) ? 16 : 0) |
93  (((kbd_matrix[5] & kbsel_b) == kbsel_b) ? 32 : 0) |
94  (((kbd_matrix[6] & kbsel_b) == kbsel_b) ? 64 : 0) |
95  (((kbd_matrix[7] & kbsel_b) == kbsel_b) ? 128 : 0)
96  ) &
97  joy_state &
98  effect_a
99  ;
100 }
101 
102 #ifdef FAKE_TYPING_SUPPORT
103 
104 #ifdef C65_FAKE_TYPING_LOAD_SEQS
105 extern const Uint8 fake_typing_for_go64[];
106 extern const Uint8 fake_typing_for_load64[];
107 extern const Uint8 fake_typing_for_load65[];
108 #endif
109 
110 extern void c64_register_fake_typing ( const Uint8 *keys );
111 extern void c64_stop_fake_typing ( void );
112 extern void c64_handle_fake_typing_internals ( Uint8 keysel );
113 
114 extern int c64_fake_typing_enabled;
115 
116 #endif
117 
118 #endif
c64_get_joy_state
Uint8 c64_get_joy_state(void)
Definition: c64_kbd_mapping.c:151
XEMU_INLINE
#define XEMU_INLINE
Definition: emutools_basicdefs.h:126
C65_KEYBOARD
#define C65_KEYBOARD
Definition: xemu-target.h:21
Uint8
uint8_t Uint8
Definition: fat32.c:51
c64_key_map
const struct KeyMappingDefault c64_key_map[]
Definition: c64_kbd_mapping.c:33
KeyMappingDefault
Definition: emutools_hid.h:24
kbd_matrix
Uint8 kbd_matrix[16]
Definition: dave.c:30
c64_toggle_joy_emu
void c64_toggle_joy_emu(void)
Definition: c64_kbd_mapping.c:140
joystick_emu
int joystick_emu
Definition: c64_kbd_mapping.c:137