Files
86Box/src/include/86box/keyboard.h

303 lines
9.6 KiB
C
Raw Normal View History

/*
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
* PC systems and compatibles from 1981 through fairly recent
* system designs based on the PCI bus.
*
* This file is part of the 86Box distribution.
*
* Definitions for the keyboard interface.
*
2020-03-25 00:46:02 +02:00
*
*
2023-01-06 15:36:29 -05:00
* Authors: Sarah Walker, <https://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com>
*
* Copyright 2008-2019 Sarah Walker.
* Copyright 2016-2025 Miran Grca.
* Copyright 2017-2019 Fred N. van Kempen.
*/
2022-02-18 19:42:21 -05:00
#ifndef EMU_KEYBOARD_H
2022-09-18 17:15:38 -04:00
#define EMU_KEYBOARD_H
2025-07-27 15:23:43 +02:00
#define FLAG_AT 0x00 /* dev is AT */
#define FLAG_PS2_KBD 0x10 /* dev is AT or PS/2 */
#define FLAG_AX 0x08 /* dev is AX */
#define FLAG_TYPE_MASK 0x07 /* mask for type */
enum {
KBD_83_KEY = 0,
KBD_84_KEY,
KBD_101_KEY,
KBD_102_KEY,
KBD_JIS,
KBD_KSC,
KBD_ABNT2
};
enum {
DEV_KBD = 0,
2023-06-26 12:47:04 -04:00
DEV_AUX = 1
};
enum {
2023-06-26 12:47:04 -04:00
DEV_STATE_MAIN_1 = 0,
DEV_STATE_MAIN_OUT = 1,
DEV_STATE_MAIN_2 = 2,
DEV_STATE_MAIN_CMD = 3,
DEV_STATE_MAIN_WANT_IN = 4,
DEV_STATE_MAIN_IN = 5,
DEV_STATE_EXECUTE_BAT = 6,
DEV_STATE_MAIN_WANT_EXECUTE_BAT = 7
};
2025-07-27 15:23:43 +02:00
enum {
KEYBOARD_TYPE_INTERNAL = 0,
KEYBOARD_TYPE_PC_XT,
KEYBOARD_TYPE_AT,
KEYBOARD_TYPE_AX,
KEYBOARD_TYPE_PS2,
KEYBOARD_TYPE_PS55
};
/* Used by the AT / PS/2 keyboard controller, common device, keyboard, and mouse. */
2023-06-28 13:46:28 -04:00
typedef struct kbc_at_port_t {
2023-06-26 12:47:04 -04:00
uint8_t wantcmd;
uint8_t dat;
2023-04-20 14:28:37 +02:00
int16_t out_new;
void *priv;
2023-08-21 20:26:11 -04:00
void (*poll)(void *priv);
} kbc_at_port_t;
/* Used by the AT / PS/2 common device, keyboard, and mouse. */
2023-06-28 13:46:28 -04:00
typedef struct atkbc_dev_t {
const char *name; /* name of this device */
2025-03-08 02:13:14 +06:00
uint8_t type;
uint8_t command;
uint8_t last_scan_code;
uint8_t state;
uint8_t resolution;
uint8_t rate;
uint8_t cmd_queue_start;
uint8_t cmd_queue_end;
uint8_t queue_start;
uint8_t queue_end;
uint16_t flags;
/* Internal FIFO, not present on real devices, needed for commands that
output multiple bytes. */
uint8_t cmd_queue[16];
uint8_t queue[64];
2023-06-26 12:47:04 -04:00
int fifo_mask;
int mode;
int x;
int y;
int z;
int b;
2024-01-20 17:27:24 +01:00
int ignore;
int *scan;
void (*process_cmd)(void *priv);
void (*execute_bat)(void *priv);
kbc_at_port_t *port;
} atkbc_dev_t;
2023-06-28 13:46:28 -04:00
typedef struct scancode {
2022-09-18 17:15:38 -04:00
const uint8_t mk[4];
const uint8_t brk[4];
} scancode;
2025-08-23 02:39:10 +02:00
#define STATE_SHIFT_MASK 0x22
#define STATE_RSHIFT 0x20
#define STATE_LSHIFT 0x02
#define FAKE_LSHIFT_ON 0x100
#define FAKE_LSHIFT_OFF 0x101
#define LSHIFT_ON 0x102
#define LSHIFT_OFF 0x103
#define RSHIFT_ON 0x104
#define RSHIFT_OFF 0x105
#define KBC_TYPE_ISA 0x00 /* AT ISA-based chips */
#define KBC_TYPE_PS2_1 0x01 /* PS2 on PS/2, type 1 */
#define KBC_TYPE_PS2_2 0x02 /* PS2 on PS/2, type 2 */
#define KBC_TYPE_GREEN 0x03 /* PS2 green controller */
#define KBC_TYPE_MASK 0x03
#define KBC_VEN_GENERIC 0x00
#define KBC_VEN_ACER 0x04
#define KBC_VEN_ALI 0x08
#define KBC_VEN_AMI 0x0c
#define KBC_VEN_AMI_TRIGEM 0x10
#define KBC_VEN_AWARD 0x14
#define KBC_VEN_CHIPS 0x18
#define KBC_VEN_COMPAQ 0x1c
#define KBC_VEN_HOLTEK 0x20
#define KBC_VEN_IBM 0x24
#define KBC_VEN_NCR 0x28
#define KBC_VEN_OLIVETTI 0x2c
#define KBC_VEN_QUADTEL 0x30
#define KBC_VEN_PHOENIX 0x34
#define KBC_VEN_SIEMENS 0x38
#define KBC_VEN_TOSHIBA 0x3c
#define KBC_VEN_VIA 0x40
#define KBC_VEN_UMC 0x44
#define KBC_VEN_SIS 0x48
#define KBC_VEN_MASK 0x7c
#define KBC_FLAG_IS_ASIC 0x80000000
2022-07-19 18:51:18 -04:00
#ifdef __cplusplus
extern "C" {
#endif
2025-07-27 15:23:43 +02:00
extern int keyboard_type;
extern uint8_t keyboard_mode;
extern int keyboard_scan;
extern uint16_t scancode_map[768];
2022-09-18 17:15:38 -04:00
extern void (*keyboard_send)(uint16_t val);
extern void kbd_adddata_process(uint16_t val, void (*adddata)(uint16_t val));
2022-09-18 17:15:38 -04:00
extern const scancode scancode_xt[512];
2017-11-08 16:29:54 -05:00
2022-09-18 17:15:38 -04:00
extern uint8_t keyboard_set3_flags[512];
extern uint8_t keyboard_set3_all_repeat;
extern uint8_t keyboard_set3_all_break;
2023-05-11 03:02:36 -04:00
extern int mouse_queue_start;
extern int mouse_queue_end;
extern int mouse_cmd_queue_start;
extern int mouse_cmd_queue_end;
2022-09-18 17:15:38 -04:00
extern int mouse_scan;
extern kbc_at_port_t *kbc_at_ports[2];
#ifdef EMU_DEVICE_H
2025-07-27 15:23:43 +02:00
extern const device_t kbc_pc_device;
extern const device_t kbc_pc82_device;
extern const device_t kbc_pravetz_device;
extern const device_t kbc_xt_device;
extern const device_t kbc_xt86_device;
extern const device_t kbc_xt_compaq_device;
extern const device_t kbc_xt_t1x00_device;
extern const device_t kbc_tandy_device;
extern const device_t kbc_xt_lxt3_device;
extern const device_t kbc_xt_olivetti_device;
extern const device_t kbc_xt_zenith_device;
extern const device_t kbc_xt_hyundai_device;
extern const device_t kbc_xt_fe2010_device;
extern const device_t kbc_xtclone_device;
2025-08-23 02:39:10 +02:00
2025-07-27 15:23:43 +02:00
extern const device_t kbc_at_device;
extern const device_t kbc_at_ami_device;
extern const device_t kbc_at_award_device;
extern const device_t kbc_at_chips_device;
2025-07-27 15:23:43 +02:00
extern const device_t kbc_at_compaq_device;
2025-08-23 02:39:10 +02:00
extern const device_t kbc_at_holtek_device;
2025-07-27 15:23:43 +02:00
extern const device_t kbc_at_ncr_device;
extern const device_t kbc_at_olivetti_device;
2025-08-23 02:39:10 +02:00
extern const device_t kbc_at_phoenix_device;
extern const device_t kbc_at_quadtel_device;
2025-07-27 15:23:43 +02:00
extern const device_t kbc_at_siemens_device;
extern const device_t kbc_at_tg_ami_device;
extern const device_t kbc_at_toshiba_device;
2025-08-23 02:39:10 +02:00
extern const device_t kbc_at_umc_device;
extern const device_t kbc_at_via_device;
2025-07-27 15:23:43 +02:00
extern const device_t kbc_ps2_device;
extern const device_t kbc_ps2_acer_device;
2025-08-23 02:39:10 +02:00
extern const device_t kbc_ps2_ali_device;
2025-07-27 15:23:43 +02:00
extern const device_t kbc_ps2_ami_device;
extern const device_t kbc_ps2_award_device;
2025-07-27 15:23:43 +02:00
extern const device_t kbc_ps2_compaq_device;
extern const device_t kbc_ps2_holtek_device;
extern const device_t kbc_ps2_mca_1_device;
extern const device_t kbc_ps2_mca_2_device;
extern const device_t kbc_ps2_olivetti_device;
extern const device_t kbc_ps2_phoenix_device;
extern const device_t kbc_ps2_quadtel_device;
extern const device_t kbc_ps2_sis_device;
extern const device_t kbc_ps2_umc_device;
extern const device_t kbc_ps2_via_device;
2025-07-27 15:23:43 +02:00
extern const device_t kbc_ps2_tg_ami_device;
extern const device_t kbc_ps2_tg_ami_green_device;
2025-08-23 02:39:10 +02:00
extern const device_t kbc_ps2_xi8088_device;
2025-07-27 15:23:43 +02:00
extern const device_t keyboard_pc_xt_device;
2022-09-18 17:15:38 -04:00
extern const device_t keyboard_at_device;
2025-07-27 15:23:43 +02:00
extern const device_t keyboard_ax_device;
2022-09-18 17:15:38 -04:00
extern const device_t keyboard_ps2_device;
2025-07-27 15:23:43 +02:00
extern const device_t keyboard_ps55_device;
extern const device_t keyboard_at_generic_device;
2023-01-08 15:58:36 -05:00
#endif /*EMU_DEVICE_H*/
2022-09-18 17:15:38 -04:00
extern void keyboard_init(void);
extern void keyboard_close(void);
extern void keyboard_set_table(const scancode *ptr);
extern void keyboard_poll_host(void);
extern void keyboard_process(void);
extern uint16_t keyboard_convert(int ch);
extern void keyboard_input(int down, uint16_t scan);
extern void keyboard_all_up(void);
extern void keyboard_update_states(uint8_t cl, uint8_t nl, uint8_t sl, uint8_t kl);
2022-09-18 17:15:38 -04:00
extern uint8_t keyboard_get_shift(void);
extern void keyboard_set_in_reset(uint8_t in_reset);
extern uint8_t keyboard_get_in_reset(void);
extern void keyboard_get_states(uint8_t *cl, uint8_t *nl, uint8_t *sl, uint8_t *kl);
2022-09-18 17:15:38 -04:00
extern void keyboard_set_states(uint8_t cl, uint8_t nl, uint8_t sl);
extern int keyboard_recv(uint16_t key);
extern int keyboard_recv_ui(uint16_t key);
extern int keyboard_isfsenter(void);
extern int keyboard_isfsenter_up(void);
2022-09-18 17:15:38 -04:00
extern int keyboard_isfsexit(void);
extern int keyboard_isfsexit_up(void);
2022-09-18 17:15:38 -04:00
extern void keyboard_set_is_amstrad(int ams);
extern void kbc_at_set_ps2(void *priv, uint8_t ps2);
extern uint8_t kbc_at_read_p(void *priv, uint8_t port, uint8_t mask);
2025-04-12 17:54:36 +02:00
extern void kbc_at_write_p(void *priv, uint8_t port, uint8_t mask, uint8_t val);
2022-09-18 17:15:38 -04:00
extern void kbc_at_set_fast_reset(uint8_t new_fast_reset);
extern void kbc_at_port_handler(int num, int set, uint16_t port, void *priv);
extern void kbc_at_handler(int set, uint16_t port, void *priv);
extern void kbc_at_set_irq(int num, uint16_t irq, void *priv);
extern void kbc_at_dev_queue_reset(atkbc_dev_t *dev, uint8_t reset_main);
extern uint8_t kbc_at_dev_queue_pos(atkbc_dev_t *dev, uint8_t main);
extern void kbc_at_dev_queue_add(atkbc_dev_t *dev, uint8_t val, uint8_t main);
extern void kbc_at_dev_reset(atkbc_dev_t *dev, int do_fa);
extern atkbc_dev_t *kbc_at_dev_init(uint8_t inst);
/* This is so we can disambiguate scan codes that would otherwise conflict and get
passed on incorrectly. */
extern uint16_t convert_scan_code(uint16_t scan_code);
2025-07-27 15:23:43 +02:00
extern const char * keyboard_get_name(int mouse);
extern const char * keyboard_get_internal_name(int mouse);
extern int keyboard_get_from_internal_name(char *s);
extern int keyboard_has_config(int mouse);
#ifdef EMU_DEVICE_H
extern const device_t *keyboard_get_device(int mouse);
#endif
extern int keyboard_get_ndev(void);
extern void keyboard_add_device(void);
extern const scancode scancode_set1[512];
#ifdef __cplusplus
}
#endif
2022-09-18 17:15:38 -04:00
#endif /*EMU_KEYBOARD_H*/