Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
emutools_hid.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-2022 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_EMUTOOLS_HID_H_INCLUDED
19 #define XEMU_COMMON_EMUTOOLS_HID_H_INCLUDED
20 
21 /* Note: HID stands for "Human Input Devices" or something like that :)
22  That is: keyboard, joystick, mouse. */
23 
25  SDL_Scancode scan; // SDL scancode for the given key we want to map
26  int pos; // BCD packed, high nibble / low nibble (x <= 7) for col/row to map to, -1 end of table, > 0xFF is special key event
27  const char* name; // name of the emulated key. It's just for "comment" or layout config load/save whatever, the emulation itself does not use it
28 };
30  SDL_Scancode scan;
31  int pos;
32  int set;
33 };
34 
35 #ifdef HID_KBD_MAP_CFG_SUPPORT
36 #define KEYMAP_DEFAULT_FILENAME "@keymap-default.cfg"
37 #define KEYMAP_USER_FILENAME "@keymap.cfg"
38 extern void hid_keymap_from_config_file ( const char *fn );
39 #endif
40 
41 extern Uint8 kbd_matrix[16];
42 extern int hid_show_osd_keys;
43 extern int hid_joy_on_cursor_keys;
44 
45 #define KBD_CLEAR_MATRIX() memset(kbd_matrix, 0xFF, sizeof kbd_matrix)
46 #define KBD_PRESS_KEY(a) kbd_matrix[(a) >> 4] &= ~(1 << ((a) & 0x7))
47 #define KBD_RELEASE_KEY(a) kbd_matrix[(a) >> 4] |= 1 << ((a) & 0x7)
48 #define KBD_SET_KEY(a,state) do { \
49  if (state) \
50  KBD_PRESS_KEY(a); \
51  else \
52  KBD_RELEASE_KEY(a); \
53 } while (0)
54 
55 extern int hid_mouse_enabled;
56 
57 // This one must be defined by the emulator!
58 extern int emu_callback_key ( int pos, SDL_Scancode key, int pressed, int handled ) ;
59 // Optinally can be defined by the emulator:
60 extern void emu_dropfile_callback ( const char *fn );
61 extern void emu_quit_callback ( void );
62 
63 typedef int (*hid_sdl_keyboard_event_callback_t ) (SDL_KeyboardEvent* ); // REMOVED: void emu_callback_key_raw_sdl ( SDL_KeyboardEvent* )
64 typedef int (*hid_sdl_textediting_event_callback_t)(SDL_TextEditingEvent*); // REMOVED: void emu_callback_key_textediting_sdl ( SDL_TextEditingEvent*);
65 typedef int (*hid_sdl_textinput_event_callback_t )(SDL_TextInputEvent* ); // REMOVED: void emu_callback_key_textinput_sdl ( SDL_TextInputEvent* );
66 
67 extern void hid_register_sdl_keyboard_event_callback ( const unsigned int level, hid_sdl_keyboard_event_callback_t cb );
69 extern void hid_register_sdl_textinput_event_callback ( const unsigned int level, hid_sdl_textinput_event_callback_t cb );
70 
71 #define HID_CB_LEVEL_CORE 0
72 #define HID_CB_LEVEL_CONSOLE 1
73 #define HID_CB_LEVEL_EMU 2
74 
75 extern void hid_sdl_synth_key_event ( int matrix_pos, int is_press );
76 
77 // Provided HID functions:
78 extern void hid_set_autoreleased_key ( int key );
79 extern int hid_key_event ( SDL_Scancode key, int pressed ) ;
80 extern void hid_reset_events ( int burn ) ;
81 extern void hid_init ( const struct KeyMappingDefault *key_map_in, Uint8 virtual_shift_pos_in, int joy_enable ) ;
82 extern void hid_mouse_motion_event ( int xrel, int yrel ) ;
83 extern void hid_mouse_button_event ( int button, int pressed ) ;
84 extern void hid_joystick_device_event ( int which , int is_attach ) ;
85 extern void hid_joystick_motion_event ( int is_vertical, int value ) ;
86 extern void hid_joystick_button_event ( int pressed ) ;
87 extern void hid_joystick_hat_event ( int value ) ;
88 extern int hid_read_joystick_up ( int on, int off ) ;
89 extern int hid_read_joystick_down ( int on, int off ) ;
90 extern int hid_read_joystick_left ( int on, int off ) ;
91 extern int hid_read_joystick_right ( int on, int off ) ;
92 extern int hid_read_joystick_button ( int on, int off ) ;
93 extern int hid_read_mouse_button_left ( int on, int off ) ;
94 extern int hid_read_mouse_button_right ( int on, int off ) ;
95 extern int hid_read_mouse_rel_x ( int min, int max ) ;
96 extern int hid_read_mouse_rel_y ( int min, int max ) ;
97 extern int hid_handle_one_sdl_event ( SDL_Event *event ) ;
98 extern void hid_handle_all_sdl_events ( void ) ;
99 
100 #define XEMU_EVENT_EXIT 0x100
101 #define XEMU_EVENT_FAKE_JOY_UP 0x101
102 #define XEMU_EVENT_FAKE_JOY_DOWN 0x102
103 #define XEMU_EVENT_FAKE_JOY_LEFT 0x103
104 #define XEMU_EVENT_FAKE_JOY_RIGHT 0x104
105 #define XEMU_EVENT_FAKE_JOY_FIRE 0x105
106 #define XEMU_EVENT_TOGGLE_FULLSCREEN 0x106
107 
108 #define STD_XEMU_SPECIAL_KEYS \
109  { SDL_SCANCODE_F9, XEMU_EVENT_EXIT, "XEMU-EXIT" }, \
110  { SDL_SCANCODE_F11, XEMU_EVENT_TOGGLE_FULLSCREEN, "XEMU-FULLSCREEN" }, \
111  { SDL_SCANCODE_KP_5, XEMU_EVENT_FAKE_JOY_FIRE, "XEMU-JOY-FIRE" }, /* for joy FIRE we map PC num keypad 5 */ \
112  { SDL_SCANCODE_KP_0, XEMU_EVENT_FAKE_JOY_FIRE, "XEMU-JOY-FIRE" }, /* PC num keypad 0 is also the FIRE ... */ \
113  { SDL_SCANCODE_RCTRL, XEMU_EVENT_FAKE_JOY_FIRE, "XEMU-JOY-FIRE" }, /* and RIGHT controll is also the FIRE ... to make Sven happy :) */ \
114  { SDL_SCANCODE_KP_8, XEMU_EVENT_FAKE_JOY_UP, "XEMU-JOY-UP" }, /* for joy UP we map PC num keypad 8 */ \
115  { SDL_SCANCODE_KP_2, XEMU_EVENT_FAKE_JOY_DOWN, "XEMU-JOY-DOWN" }, /* for joy DOWN we map PC num keypad 2 */ \
116  { SDL_SCANCODE_KP_4, XEMU_EVENT_FAKE_JOY_LEFT, "XEMU-JOY-LEFT" }, /* for joy LEFT we map PC num keypad 4 */ \
117  { SDL_SCANCODE_KP_6, XEMU_EVENT_FAKE_JOY_RIGHT, "XEMU-JOY-RIGHT" } /* for joy RIGHT we map PC num keypad 6 */
118 
119 #if defined(CONFIG_KBD_ALSO_TEXTEDITING_SDL_CALLBACK) || defined(CONFIG_KBD_ALSO_TEXTINPUT_SDL_CALLBACK) || defined(CONFIG_KBD_ALSO_RAW_SDL_CALLBACK)
120 #error "Feature request macros CONFIG_KBD_ALSO_TEXTEDITING_SDL_CALLBACK / CONFIG_KBD_ALSO_TEXTINPUT_SDL_CALLBACK / CONFIG_KBD_ALSO_RAW_SDL_CALLBACK has been **REMOVED**, emulator code **MUST** be reworked for the new API!"
121 #endif
122 
123 #endif
hid_read_mouse_rel_y
int hid_read_mouse_rel_y(int min, int max)
Definition: emutools_hid.c:497
KeyMappingUsed::scan
SDL_Scancode scan
Definition: emutools_hid.h:30
hid_joystick_motion_event
void hid_joystick_motion_event(int is_vertical, int value)
Definition: emutools_hid.c:414
hid_set_autoreleased_key
void hid_set_autoreleased_key(int key)
Definition: emutools_hid.c:66
hid_handle_all_sdl_events
void hid_handle_all_sdl_events(void)
Definition: emutools_hid.c:613
hid_register_sdl_keyboard_event_callback
void hid_register_sdl_keyboard_event_callback(const unsigned int level, hid_sdl_keyboard_event_callback_t cb)
Definition: emutools_hid.c:621
hid_handle_one_sdl_event
int hid_handle_one_sdl_event(SDL_Event *event)
Definition: emutools_hid.c:528
hid_joystick_device_event
void hid_joystick_device_event(int which, int is_attach)
Definition: emutools_hid.c:390
hid_read_joystick_left
int hid_read_joystick_left(int on, int off)
Definition: emutools_hid.c:467
hid_reset_events
void hid_reset_events(int burn)
Definition: emutools_hid.c:170
hid_read_joystick_button
int hid_read_joystick_button(int on, int off)
Definition: emutools_hid.c:479
hid_joystick_hat_event
void hid_joystick_hat_event(int value)
Definition: emutools_hid.c:441
hid_register_sdl_textediting_event_callback
void hid_register_sdl_textediting_event_callback(const unsigned int level, hid_sdl_textediting_event_callback_t cb)
Definition: emutools_hid.c:626
hid_mouse_button_event
void hid_mouse_button_event(int button, int pressed)
Definition: emutools_hid.c:374
hid_sdl_textediting_event_callback_t
int(* hid_sdl_textediting_event_callback_t)(SDL_TextEditingEvent *)
Definition: emutools_hid.h:64
emu_quit_callback
void emu_quit_callback(void)
Definition: primo.c:483
hid_sdl_textinput_event_callback_t
int(* hid_sdl_textinput_event_callback_t)(SDL_TextInputEvent *)
Definition: emutools_hid.h:65
fn
const char * fn
Definition: roms.c:42
hid_register_sdl_textinput_event_callback
void hid_register_sdl_textinput_event_callback(const unsigned int level, hid_sdl_textinput_event_callback_t cb)
Definition: emutools_hid.c:631
Uint8
uint8_t Uint8
Definition: fat32.c:51
hid_sdl_keyboard_event_callback_t
int(* hid_sdl_keyboard_event_callback_t)(SDL_KeyboardEvent *)
Definition: emutools_hid.h:63
hid_read_joystick_down
int hid_read_joystick_down(int on, int off)
Definition: emutools_hid.c:461
KeyMappingDefault::scan
SDL_Scancode scan
Definition: emutools_hid.h:25
KeyMappingDefault
Definition: emutools_hid.h:24
hid_read_mouse_rel_x
int hid_read_mouse_rel_x(int min, int max)
Definition: emutools_hid.c:485
hid_read_mouse_button_left
int hid_read_mouse_button_left(int on, int off)
Definition: emutools_hid.c:509
emu_callback_key
int emu_callback_key(int pos, SDL_Scancode key, int pressed, int handled)
Definition: commodore_65.c:807
hid_show_osd_keys
int hid_show_osd_keys
Definition: emutools_hid.c:34
KeyMappingUsed::pos
int pos
Definition: emutools_hid.h:31
hid_mouse_enabled
int hid_mouse_enabled
hid_mouse_motion_event
void hid_mouse_motion_event(int xrel, int yrel)
Definition: emutools_hid.c:366
hid_read_joystick_right
int hid_read_joystick_right(int on, int off)
Definition: emutools_hid.c:473
hid_key_event
int hid_key_event(SDL_Scancode key, int pressed)
Definition: emutools_hid.c:72
value
int value
Definition: dma65.c:90
hid_sdl_synth_key_event
void hid_sdl_synth_key_event(int matrix_pos, int is_press)
Definition: emutools_hid.c:145
hid_joy_on_cursor_keys
int hid_joy_on_cursor_keys
Definition: emutools_hid.c:35
emu_dropfile_callback
void emu_dropfile_callback(const char *fn)
Definition: primo.c:675
kbd_matrix
Uint8 kbd_matrix[16]
Definition: dave.c:30
KeyMappingUsed::set
int set
Definition: emutools_hid.h:32
KeyMappingDefault::name
const char * name
Definition: emutools_hid.h:27
KeyMappingDefault::pos
int pos
Definition: emutools_hid.h:26
button
Uint32 button
Definition: joystick.c:43
hid_joystick_button_event
void hid_joystick_button_event(int pressed)
Definition: emutools_hid.c:432
hid_init
void hid_init(const struct KeyMappingDefault *key_map_in, Uint8 virtual_shift_pos_in, int joy_enable)
Definition: emutools_hid.c:300
KeyMappingUsed
Definition: emutools_hid.h:29
hid_read_mouse_button_right
int hid_read_mouse_button_right(int on, int off)
Definition: emutools_hid.c:515
hid_read_joystick_up
int hid_read_joystick_up(int on, int off)
Definition: emutools_hid.c:455