summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2003-09-09 07:34:32 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2003-09-09 07:34:32 (GMT)
commitbaedd03c8dcf0673faf8e59e7a987158051a46c7 (patch)
tree7620f214751ad50144093a5e4f110c0e1ea9a0f9
parent2d7483b97fc6d4542fda957f24c7f4cb0d849ba7 (diff)
downloadkeyboard-baedd03c8dcf0673faf8e59e7a987158051a46c7.zip
keyboard-baedd03c8dcf0673faf8e59e7a987158051a46c7.tar.gz
keyboard-baedd03c8dcf0673faf8e59e7a987158051a46c7.tar.bz2
keyboard-baedd03c8dcf0673faf8e59e7a987158051a46c7.tar.xz
*** empty log message ***
-rw-r--r--data/keyboard.asm374
1 files changed, 369 insertions, 5 deletions
diff --git a/data/keyboard.asm b/data/keyboard.asm
index 839431f..a893bd5 100644
--- a/data/keyboard.asm
+++ b/data/keyboard.asm
@@ -1,3 +1,4 @@
+; -*- fundamental -*-
; Keyboard controller program written in Z80 assembly
;
; This is a test...
@@ -255,26 +256,389 @@ swa_reply
jr swa_reply
_start
+ ld iy,variables ; Point to variable area
+
; Test
ld a,#0x69
call (printhex)
+kt_reset
ld a,#0xff ; Reset keyboard
call (send_with_ack)
call (read_byte) ; Post-reset status code
call (printhex)
ld a,#0xed ; Set LEDs
call (send_with_ack)
- ld a,#0x05 ; Caps+Scroll
+ ld a,(lock_mask) ; Match the current lock mask
call (send_with_ack)
ld a,#0xf0 ; Set scan code set
call (send_with_ack)
- ld a,#0x03 ; Scan code set 3
+ ld a,#0x03
call (send_with_ack)
- ld a,#0xfa ; Set all keys Make/Break/Typematic
+ ld a,#0xf8 ; Set all keys Make/Break
call (send_with_ack)
-read_and_print
+main_loop_clear
+kt_ignore
+ ; Clear the break flag
+ xor a
+ ld (break_flag),a
+
+ ;
+ ; Keyboard main loop - read a char, decode, and emit
+ ;
+main_loop
call (read_byte)
call (printhex)
- jr read_and_print
+ ld hl,keytype_table
+ ld d,#0
+ ld e,a ; DE <- keynum
+ add hl,de
+ ld ix,keydata_table
+ add ix,de
+ add ix,de
+ add ix,de
+ add ix,de ; IX <- kd_t+4*keynum
+ ; D=0 still
+ ld e,(hl) ; DE = keytype
+ ld hl,keytype_handlers
+ add hl,de
+ add hl,de
+ add hl,de ; HL = kt_h+3*type
+ ld bc,(break_flag) ; B <- status_byte, C <- break_flag
+ bit 0,c ; Lots of things need this
+ jp (hl)
+;
+; Entry condititions:
+; A = keysym
+; B = status_byte
+; C = break_flag
+; D = 0
+; E = type code
+; HL = handler
+; IX = keydata_table+4*keynum
+; IY = variables
+; ZF = set if break_flag=0
+
+kt_break
+ ld a,#0xFF
+ ld (break_flag),a
+ jp (main_loop)
+
+kt_shift
+ jr nz,kts_break
+
+ ld a,(shift_l_mask)
+ or (ix+0)
+ ld (shift_l_mask),a
+ ld a,(shift_r_mask)
+ or (ix+1)
+ ld (shift_r_mask),a
+ jr set_status
+
+kts_break
+ ld a,(shift_l_mask)
+ and (ix+2)
+ ld (shift_l_mask),a
+ ld a,(shift_r_mask)
+ and (ix+3)
+ ld (shift_r_mask),a
+ jr set_status
+
+kt_lock
+ jr nz,main_loop_clear
+ ld a,#0xed ; Set LEDs
+ call (send_with_ack)
+ ld a,(lock_mask)
+ xor (ix+0)
+ ld (lock_mask),a
+ call (send_with_ack)
+ ; jr set_status
+
+set_status
+ ld de,(status_byte) ; E <- status_byte, D <- lock_mask
+ ld a,e
+ and #0x80
+ sla d
+ sla d
+ sla d
+ sla d
+ or d
+ ld de,(shift_l_mask)
+ or e ; shift_l_mask
+ or d ; shift_r_mask
+ ld (status_byte),a
+ out (#3),a
+ jp (main_loop_clear)
+
+kt_symbol
+ jr nz,kts_break
+ ld (down_key),a
+ ld a,b ; status_byte
+ and #0x03
+ ld e,a
+ ; D=0
+ add ix,de
+ ld a,(ix+0)
+ out (#2),a
+ ld a,b ; status_byte
+ or #0x80
+ ld (status_byte),a
+ out (#3),a
+ jp (main_loop_clear)
+
+kts_break
+ cp (iy+5) ; down_key
+ jp nz,(main_loop_clear)
+ ld a,b ; status_byte
+ and #0x7F
+ ld (status_byte),a
+ out (#3),a
+ jp (main_loop_clear)
+
+kt_alpha
+ jr nz,kts_break
+ ld (down_key),a
+ ld a,b ; status_byte
+ and #0x42
+ cp #0x40
+ ld a,b ; status_byte
+ jr nz,kta_nocaps
+ xor #0x01 ; Invert sense of shift
+kta_nocaps
+ and #0x03
+ ld e,a
+ ; D=0
+ add ix,de
+ ld a,(ix+0)
+ out (#2),a
+ ld a,b ; status_byte
+ or #0x80
+ ld (status_byte),a
+ out (#3),a
+ jp (main_loop_clear)
+
+;
+; Handlers for the various entries
+;
+keytype_handlers
+ jp (kt_ignore) ; 0
+ jp (kt_reset) ; 1
+ jp (kt_break) ; 2
+ jp (kt_shift) ; 3
+ jp (kt_lock) ; 4
+ jp (kt_symbol) ; 5
+ jp (kt_alpha) ; 6
+ ; jp (kt_number) ; 7 - not used
+
+;
+; Status variables
+;
+variables ; IY points here
+shift_l_mask ; (iy+0)
+ byte 0
+shift_r_mask ; (iy+1)
+ byte 0
+break_flag ; (iy+2)
+ byte 0 ; 0 for no break, ~0 for break
+status_byte ; (iy+3)
+ byte 0 ; Current value for the status byte
+lock_mask ; (iy+4)
+ byte 02h ; Num Lock on
+down_key ; (iy+5)
+ byte 0 ; Currently "down" key, if any
+
+;
+; Primary code table -- for each possible receive code classify
+; it by type
+;
+; Types are as follows:
+; 0 - Ignore
+; 1 - Reset (keyboard needs reinitialization)
+; 2 - Break prefix
+; 3 - Shift key
+; 4 - Lock key
+; 5 - Symbol key
+; 6 - Alpha key (symbol key sensitive to caps lock)
+; 7 - Number key (symbol key sensitive to num lock)
+;
+keytype_table
+ byte 0,0,0,0,0,0,0,0, 5,0,0,0,0,5,0,0 ; 0x00
+ byte 0,3,3,5,4,6,5,0, 0,3,6,6,6,6,5,0 ; 0x10
+ byte 0,6,6,6,6,5,5,0, 0,5,6,6,6,6,5,0 ; 0x20
+ byte 0,6,6,6,6,6,5,0, 0,3,6,6,6,5,5,0 ; 0x30
+ byte 0,5,6,6,6,5,5,0, 0,5,5,6,6,6,5,0 ; 0x40
+ byte 0,0,6,5,6,6,0,0, 3,3,5,6,0,0,0,4 ; 0x50
+ byte 0,5,0,0,0,0,0,0, 0,0,5,5,5,0,0,0 ; 0x60
+ byte 5,5,5,5,5,5,4,5, 0,5,5,0,5,5,5,0 ; 0x70
+ byte 0,0,0,0,5,0,0,0, 0,0,0,3,3,0,0,0 ; 0x80
+ byte 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 ; 0x90
+ byte 0,0,0,0,0,0,0,0, 0,0,1,0,0,0,0,0 ; 0xA0
+ byte 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 ; 0xB0
+ byte 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 ; 0xC0
+ byte 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 ; 0xD0
+ byte 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 ; 0xE0
+ byte 2,0,0,0,0,0,0,0, 0,0,1,0,0,0,1,1 ; 0xF0
+
+;
+; Data table. Each entry is four bytes; the meaning
+; is as follows:
+;
+; Type Byte 0 Byte 1 Byte 2 Byte 3
+; ------------------------------------
+; 0 - - - -
+; 1 - - - -
+; 2 - - - -
+; 3 LMask RMask ~LMask ~RMask
+; 4 Mask - - -
+; 5 Normsl Shift Ctrl S+C
+; 6 Normal Caps Ctrl S+C
+; 7 Normal Num Ctrl S+C
+;
+; This table only need to extend to cover the range
+; that has types 3-7 in the keytype_table.
+keydata_table
+ byte 0x00,0x00,0x00,0x00 ; 0x00
+ byte 0x00,0x00,0x00,0x00 ; 0x01
+ byte 0x00,0x00,0x00,0x00 ; 0x02
+ byte 0x00,0x00,0x00,0x00 ; 0x03
+ byte 0x00,0x00,0x00,0x00 ; 0x04
+ byte 0x00,0x00,0x00,0x00 ; 0x05
+ byte 0x00,0x00,0x00,0x00 ; 0x06
+ byte 0x00,0x00,0x00,0x00 ; 0x07
+ byte 0x1B,0x1B,0x1B,0x1B ; 0x08
+ byte 0x00,0x00,0x00,0x00 ; 0x09
+ byte 0x00,0x00,0x00,0x00 ; 0x0A
+ byte 0x00,0x00,0x00,0x00 ; 0x0B
+ byte 0x00,0x00,0x00,0x00 ; 0x0C
+ byte 0x09,0x09,0x09,0x09 ; 0x0D
+ byte 0x00,0x00,0x00,0x00 ; 0x0E
+ byte 0x00,0x00,0x00,0x00 ; 0x0F
+ byte 0x00,0x00,0x00,0x00 ; 0x10
+ byte 0x02,0x00,0xFD,0xFF ; 0x11
+ byte 0x01,0x00,0xFE,0xFF ; 0x12
+ byte "<" ,">" ,0x7F,0x7F ; 0x13
+ byte 0x04,0x00,0x00,0x00 ; 0x14
+ byte "q" ,"Q" ,0x11,0x01 ; 0x15
+ byte "1" ,0x21,"1" ,0x21 ; 0x16
+ byte 0x00,0x00,0x00,0x00 ; 0x17
+ byte 0x00,0x00,0x00,0x00 ; 0x18
+ byte 0x04,0x00,0xFB,0xFF ; 0x19
+ byte "z" ,"Z" ,0x1A,0x0A ; 0x1A
+ byte "s" ,"S" ,0x13,0x03 ; 0x1B
+ byte "a" ,"A" ,0x01,0x11 ; 0x1C
+ byte "w" ,"W" ,0x17,0x07 ; 0x1D
+ byte "2" ,0x22,"2" ,0x22 ; 0x1E
+ byte 0x00,0x00,0x00,0x00 ; 0x1F
+ byte 0x00,0x00,0x00,0x00 ; 0x20
+ byte "c" ,"C" ,0x03,0x13 ; 0x21
+ byte "x" ,"X" ,0x18,0x08 ; 0x22
+ byte "d" ,"D" ,0x04,0x14 ; 0x23
+ byte "e" ,"E" ,0x05,0x15 ; 0x24
+ byte "4" ,"$" ,"4" ,"$" ; 0x25
+ byte "3" ,"#" ,"3" ,"#" ; 0x26
+ byte 0x00,0x00,0x00,0x00 ; 0x27
+ byte 0x00,0x00,0x00,0x00 ; 0x28
+ byte " " ," " ,0x00,0x00 ; 0x29
+ byte "v" ,"V" ,0x16,0x06 ; 0x2A
+ byte "f" ,"F" ,0x06,0x16 ; 0x2B
+ byte "t" ,"T" ,0x14,0x04 ; 0x2C
+ byte "r" ,"R" ,0x12,0x02 ; 0x2D
+ byte "5" ,"%" ,"5" ,"%" ; 0x2E
+ byte 0x00,0x00,0x00,0x00 ; 0x2F
+ byte 0x00,0x00,0x00,0x00 ; 0x30
+ byte "n" ,"N" ,0x0E,0x1E ; 0x31
+ byte "b" ,"B" ,0x02,0x12 ; 0x32
+ byte "h", "H", 0x08,0x18 ; 0x33
+ byte "g" ,"G" ,0x07,0x17 ; 0x34
+ byte "y" ,"Y" ,0x19,0x09 ; 0x35
+ byte "6" ,"&" ,"6" ,"&" ; 0x36
+ byte 0x00,0x00,0x00,0x00 ; 0x37
+ byte 0x00,0x00,0x00,0x00 ; 0x38
+ byte 0x00,0x04,0xFF,0xFB ; 0x39
+ byte "m" ,"M" ,0x0D,0x1D ; 0x3A
+ byte "j" ,"J" ,0x0A,0x1A ; 0x3B
+ byte "u" ,"U" ,0x15,0x05 ; 0x3C
+ byte "7" ,"/" ,"7" ,"/" ; 0x3D
+ byte "8" ,"(" ,"8" ,"(" ; 0x3E
+ byte 0x00,0x00,0x00,0x00 ; 0x3F
+ byte 0x00,0x00,0x00,0x00 ; 0x40
+ byte "," ,0x3B,"," ,0x3B ; 0x41
+ byte "k" ,"K" ,0x0B,0x1B ; 0x42
+ byte "i" ,"I" ,0x09,0x19 ; 0x43
+ byte "o" ,"O" ,0x0F,0x1F ; 0x44
+ byte "0" ,"=" ,"0" ,"=" ; 0x45
+ byte "9" ,")" ,"9" ,")" ; 0x46
+ byte 0x00,0x00,0x00,0x00 ; 0x47
+ byte 0x00,0x00,0x00,0x00 ; 0x48
+ byte "." ,":" ,"." ,":" ; 0x49
+ byte "-" ,"_" ,0x1F,0x1F ; 0x4A
+ byte "l" ,"L" ,0x0C,0x1C ; 0x4B
+ byte 0x7C,0x5C,0x1C,0x0C ; 0x4C
+ byte "p" ,"P" ,0x10,0x00 ; 0x4D
+ byte "+" ,"?" ,0x7F,0x7F ; 0x4E
+ byte 0x00,0x00,0x00,0x00 ; 0x4F
+ byte 0x00,0x00,0x00,0x00 ; 0x50
+ byte 0x00,0x00,0x00,0x00 ; 0x51
+ byte "{" ,"[" ,0x1B,0x0B ; 0x52
+ byte "'" ,"*" ,"'" ,"*" ; 0x53
+ byte "}" ,"]" ,0x1D,0x0D ; 0x54
+ byte "@" ,"`" ,0x00,0x10 ; 0x55
+ byte 0x00,0x00,0x00,0x00 ; 0x56
+ byte 0x00,0x00,0x00,0x00 ; 0x57
+ byte 0x00,0x02,0xFF,0xFD ; 0x58
+ byte 0x00,0x01,0xFF,0xFE ; 0x59
+ byte 0x0D,0x0D,0x0D,0x0D ; 0x5A
+ byte "~" ,"^" ,0x1E,0x0E ; 0x5B
+ byte 0x00,0x00,0x00,0x00 ; 0x5C
+ byte 0x00,0x00,0x00,0x00 ; 0x5D
+ byte 0x00,0x00,0x00,0x00 ; 0x5E
+ byte 0x01,0x00,0x00,0x00 ; 0x5F
+ byte 0x00,0x00,0x00,0x00 ; 0x60
+ byte 0x08,0x08,0x08,0x08 ; 0x61
+ byte 0x00,0x00,0x00,0x00 ; 0x62
+ byte 0x00,0x00,0x00,0x00 ; 0x63
+ byte 0x00,0x00,0x00,0x00 ; 0x64
+ byte 0x00,0x00,0x00,0x00 ; 0x65
+ byte 0x00,0x00,0x00,0x00 ; 0x66
+ byte 0x00,0x00,0x00,0x00 ; 0x67
+ byte 0x00,0x00,0x00,0x00 ; 0x68
+ byte 0x00,0x00,0x00,0x00 ; 0x69
+ byte 0x09,0x09,0x09,0x09 ; 0x6A
+ byte "4" ,"4" ,"4" ,"4" ; 0x6B
+ byte "7" ,"7" ,"7" ,"7" ; 0x6C
+ byte 0x00,0x00,0x00,0x00 ; 0x6D
+ byte 0x00,0x00,0x00,0x00 ; 0x6E
+ byte 0x00,0x00,0x00,0x00 ; 0x6F
+ byte "0" ,"0" ,"0" ,"0" ; 0x70
+ byte "." ,"." ,"." ,"." ; 0x71
+ byte "2" ,"2" ,"2" ,"2" ; 0x72
+ byte "5" ,"5" ,"5" ,"5" ; 0x73
+ byte "6" ,"6" ,"6" ,"6" ; 0x74
+ byte "8" ,"8" ,"8" ,"8" ; 0x75
+ byte 0x02,0x00,0x00,0x00 ; 0x76
+ byte "/" ,"/" ,"/" ,"/" ; 0x77
+ byte 0x00,0x00,0x00,0x00 ; 0x78
+ byte 0x0D,0x0D,0x0D,0x0D ; 0x79
+ byte "3" ,"3" ,"3" ,"3" ; 0x7A
+ byte 0x00,0x00,0x00,0x00 ; 0x7B
+ byte "+" ,"+" ,"+" ,"+" ; 0x7C
+ byte "9" ,"9" ,"9" ,"9" ; 0x7D
+ byte "*" ,"*" ,"*" ,"*" ; 0x7E
+ byte 0x00,0x00,0x00,0x00 ; 0x7F
+ byte 0x00,0x00,0x00,0x00 ; 0x80
+ byte 0x00,0x00,0x00,0x00 ; 0x81
+ byte 0x00,0x00,0x00,0x00 ; 0x82
+ byte 0x00,0x00,0x00,0x00 ; 0x83
+ byte "-" ,"-" ,"-" ,"-" ; 0x84
+ byte 0x00,0x00,0x00,0x00 ; 0x85
+ byte 0x00,0x00,0x00,0x00 ; 0x86
+ byte 0x00,0x00,0x00,0x00 ; 0x87
+ byte 0x00,0x00,0x00,0x00 ; 0x88
+ byte 0x00,0x00,0x00,0x00 ; 0x89
+ byte 0x00,0x00,0x00,0x00 ; 0x8A
+ byte 0x08,0x00,0xF7,0xFF ; 0x8B
+ byte 0x00,0x08,0xFF,0xF7 ; 0x8C
+ byte 0x00,0x00,0x00,0x00 ; 0x8D
+ byte 0x00,0x00,0x00,0x00 ; 0x8E
+ byte 0x00,0x00,0x00,0x00 ; 0x8F