6502-OS/system/keyboard.h65
2023-12-31 01:59:06 +01:00

152 lines
3.7 KiB
Plaintext

;;********************************************************************************
;; @module keyboard
;; @type drive
;; @details:
;; Support for a PS2 Keyboard using the shift register of a 6522 VIA
;; Pressing a key causes 11 bits to be sent: 1 start - 8 scancode - 1 parity - 1 stop
;; The VIA is set up to interrupt after 8 bits have been shifted into the shift register
;; from the external clock pulses of the keyboard (additional hardware required to
;; address the hardware bug of the VIA, where bit get lost when the external clock
;; transition happens during falling edge of PHI2). After reading the shift register,
;; the VIAs T2 timer is set to interrupt after the last 3 bits have been shifted in,
;; which takes about ~230ms.
;;********************************************************************************
.ifndef INCLUDE_KEYBOARD
INCLUDE_KEYBOARD = 1
.include "system.h65"
.scope kb
Import kb,init,irq_shift_reg_handler,irq_timer_handler,scancode,key_read
Import kb, CHARS_NOMOD, CHARS_MODSHIFT
ImportZp kb,status
KB_IO = IO1
.enum STATUS
RELEASE = %10000000
TWOBYTE = %01000000
SHIFT = %00100000
CAPSLOCK = %00010000
CAPSLOCK_HELD = %00000010
RIGHTALT = %00001000
NUMLOCK = %00000100
.endenum
K_TWOBYTE = $E0
K_RELEASE = $F0
.enum K
F9 = $01
F5 = $03
F3 = $04
F1 = $05
F2 = $06
F12 = $07
F10 = $09
F8 = $0A
F6 = $0B
F4 = $0C
TAB = $0D
GRAVE = $0E
LEFTALT = $11
LEFTSHIFT = $12
LEFTCTRL = $14
K_Q = $15
K_1 = $16
K_Y = $1A
K_S = $1B
K_A = $1C
K_W = $1D
K_2 = $1E
K_C = $21
K_X = $22
K_D = $23
K_E = $24
K_4 = $25
K_3 = $26
SPACE = $29
K_V = $2A
K_F = $2B
K_T = $2C
K_R = $2D
K_5 = $2E
K_N = $31
K_B = $32
K_H = $33
K_G = $34
K_Z = $35
K_6 = $36
K_M = $3A
K_J = $3B
K_U = $3C
K_7 = $3D
K_8 = $3E
COMMA = $41
K_K = $42
K_I = $43
K_O = $44
K_0 = $45
K_9 = $46
DOT = $49
DASH = $4A
K_L = $4B
OUML = $4C
K_P = $4D
SSHARP = $4E
AUML = $52
UUML = $54
BACKTICK = $55
CAPSLOCK = $58
RIGHTSHIFT = $59
ENTER = $5A
PLUS = $5B
HASH = $5D
LESSTHAN = $61
BACKSPACE = $66
KP1 = $69
KP4 = $6B
KP7 = $6C
KP0 = $70
KPDOT = $71
KP2 = $72
KP5 = $73
KP6 = $74
KP8 = $75
ESCAPE = $76
NUMLOCK = $77
F11 = $78
KPPLUS = $79
KP3 = $7A
KPMINUS = $7B
KPASTERISK = $7C
KP9 = $7D
SCROLLLOCK = $7E
F7 = $83
.endenum
.enum K2
RIGHTALT = $11
RIGHTCTRL = $14
LEFTMETA = $1F
RIGHTMETA = $27
MENU = $2F
BREAK = $37
SYSRQ = $3F
KPDIVIDE = $4A
KPENTER = $5A
END = $69
LEFT = $6B
POS1 = $6C
INSERT = $70
DELETE = $71
DOWN = $72
RIGHT = $74
UP = $75
PAGEDOWN = $7A
PAGEUP = $7D
.endenum
.endscope
.endif ; guard