Reading ps/2 keyboard, but somehow, keycodes are decremented by 1
This commit is contained in:
parent
2366408679
commit
a1a858a701
BIN
assets/misc/ps2_modeset_2_to_ascii.ods
Normal file
BIN
assets/misc/ps2_modeset_2_to_ascii.ods
Normal file
Binary file not shown.
@ -20,7 +20,7 @@
|
|||||||
; behave strangely (will drop next pressed key). This is not a problem, as the computer, once completed, will
|
; behave strangely (will drop next pressed key). This is not a problem, as the computer, once completed, will
|
||||||
; have a 60% keyboard, without any of the unusable keys.
|
; have a 60% keyboard, without any of the unusable keys.
|
||||||
|
|
||||||
include 'ps2_keyboard_scancodeset2.asm' ; PS/2 Scan Codeset 2 mappings
|
include 'drivers/ps2_keyboard_scancodeset2.asm' ; PS/2 Scan Codeset 2 mappings
|
||||||
|
|
||||||
; config (IO port 1)
|
; config (IO port 1)
|
||||||
PS2KEYB_CLEAR_REG: EQU IO_2
|
PS2KEYB_CLEAR_REG: EQU IO_2
|
||||||
@ -35,19 +35,20 @@ PS2KEYB_BREAK: EQU 0xF0 - %10000000 ; The MSB is dropped: see NOTE on intro a
|
|||||||
PS2Keyb_readc:
|
PS2Keyb_readc:
|
||||||
in a, (PS2KEYB_DATA_REG) ; reads a character
|
in a, (PS2KEYB_DATA_REG) ; reads a character
|
||||||
add a, 0
|
add a, 0
|
||||||
jp z, Term_readc ; if char is 0 (NULL), user didn't press any key: wait for character
|
jp z, PS2Keyb_readc ; if char is 0 (NULL), user didn't press any key: wait for character
|
||||||
; we found something, allow the keyboard to complete data transmission
|
; we found something, but it may still be shifting in bits. Allow the keyboard to complete data transmission
|
||||||
ld a, PS2KEYB_TRANSMISSION_DURATION/5 ; every cycle is 5 CPU cycles
|
ld a, PS2KEYB_TRANSMISSION_DURATION/5 ; every cycle is 5 CPU cycles
|
||||||
ps2keyb_readc_waitloop:
|
ps2keyb_readc_waitloop:
|
||||||
sub 1
|
sub 1
|
||||||
jr nz, ps2keyb_readc_waitloop
|
jr nz, ps2keyb_readc_waitloop
|
||||||
; data transmission should now be complete.
|
; data transmission should now be complete.
|
||||||
; check if code is a Break Code. If it is, discard next key as it is a released key
|
; check if code is a Break Code. If it is, discard next key as it is a released key
|
||||||
ld c, a ; save a
|
in a, (PS2KEYB_DATA_REG) ; re-reads the character (it should now be complete)
|
||||||
|
ld c, a ; save a, because it will be modified by next compare
|
||||||
cp PS2KEYB_BREAK ; compare a with Break Code
|
cp PS2KEYB_BREAK ; compare a with Break Code
|
||||||
jp z, ps2keyb_readc_discard ; if it is a Break Code, jump to discarder routine
|
jp z, ps2keyb_readc_discard ; if it is a Break Code, jump to discarder routine
|
||||||
; we read a valid character: clean key registers
|
; we read a valid character: clean key registers
|
||||||
in a, PS2KEYB_CLEAR_REG
|
in a, (PS2KEYB_CLEAR_REG)
|
||||||
; now we will convert keycode in c to ASCII code
|
; now we will convert keycode in c to ASCII code
|
||||||
ld hl, PS2KEYB_SCANCODESET_ASCII_MAP ; load start of codeset to ascii map
|
ld hl, PS2KEYB_SCANCODESET_ASCII_MAP ; load start of codeset to ascii map
|
||||||
ld b, 0 ; reset b, as we are going to do a sum with bc (where c contains the read scancode)
|
ld b, 0 ; reset b, as we are going to do a sum with bc (where c contains the read scancode)
|
||||||
@ -56,7 +57,7 @@ PS2Keyb_readc:
|
|||||||
ret ; returns in the a register
|
ret ; returns in the a register
|
||||||
ps2keyb_readc_discard:
|
ps2keyb_readc_discard:
|
||||||
; clean key registers
|
; clean key registers
|
||||||
in a, PS2KEYB_CLEAR_REG
|
in a, (PS2KEYB_CLEAR_REG)
|
||||||
ps2keyb_readc_discard_waitfordata:
|
ps2keyb_readc_discard_waitfordata:
|
||||||
; wait for next non-0 keycode and discards it (it is the code of the released key)
|
; wait for next non-0 keycode and discards it (it is the code of the released key)
|
||||||
in a, (PS2KEYB_DATA_REG) ; reads a character
|
in a, (PS2KEYB_DATA_REG) ; reads a character
|
||||||
@ -68,5 +69,5 @@ PS2Keyb_readc:
|
|||||||
sub 1
|
sub 1
|
||||||
jr nz, ps2keyb_readc_discard_waitloop
|
jr nz, ps2keyb_readc_discard_waitloop
|
||||||
; data transmission should now be complete, throw away key code
|
; data transmission should now be complete, throw away key code
|
||||||
in a, PS2KEYB_CLEAR_REG
|
in a, (PS2KEYB_CLEAR_REG)
|
||||||
jp PS2Keyb_readc ; go back and wait for another keycode
|
jp PS2Keyb_readc ; go back and wait for another keycode
|
||||||
|
@ -2,136 +2,136 @@
|
|||||||
;
|
;
|
||||||
; Keycodes 0 to 83
|
; Keycodes 0 to 83
|
||||||
|
|
||||||
.db PS2KEYB_SCANCODESET_ASCII_MAP: .db 0 ; (Unused)
|
PS2KEYB_SCANCODESET_ASCII_MAP: DB 0 ; (Unused)
|
||||||
.db 0 ; F9
|
DB 0 ; F9
|
||||||
.db 0 ; (Control key)
|
DB 0 ; (Control key)
|
||||||
.db 0 ; F5
|
DB 0 ; F5
|
||||||
.db 0 ; F3
|
DB 0 ; F3
|
||||||
.db 0 ; F1
|
DB 0 ; F1
|
||||||
.db 0 ; F2
|
DB 0 ; F2
|
||||||
.db 0 ; F12
|
DB 0 ; F12
|
||||||
.db 0 ; (Control key)
|
DB 0 ; (Control key)
|
||||||
.db 0 ; F10
|
DB 0 ; F10
|
||||||
.db 0 ; F8
|
DB 0 ; F8
|
||||||
.db 0 ; F6
|
DB 0 ; F6
|
||||||
.db 0 ; F4
|
DB 0 ; F4
|
||||||
.db 9 ; TAB
|
DB 9 ; TAB
|
||||||
.db 96 ; `
|
DB 96 ; `
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; L ALT
|
DB 0 ; L ALT
|
||||||
.db 0 ; L SHFT
|
DB 0 ; L SHFT
|
||||||
.db 0 ; (Control key)
|
DB 0 ; (Control key)
|
||||||
.db 0 ; L CTRL
|
DB 0 ; L CTRL
|
||||||
.db 1 ; Q
|
DB 1 ; Q
|
||||||
.db 2 ; 1
|
DB 2 ; 1
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 3 ; Z
|
DB 3 ; Z
|
||||||
.db 4 ; S
|
DB 4 ; S
|
||||||
.db 65 ; A
|
DB 65 ; A
|
||||||
.db 66 ; W
|
DB 66 ; W
|
||||||
.db 67 ; 2
|
DB 67 ; 2
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 68 ; C
|
DB 68 ; C
|
||||||
.db 69 ; X
|
DB 69 ; X
|
||||||
.db 70 ; D
|
DB 70 ; D
|
||||||
.db 71 ; E
|
DB 71 ; E
|
||||||
.db 72 ; 4
|
DB 72 ; 4
|
||||||
.db 73 ; 3
|
DB 73 ; 3
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 32 ; SPACE
|
DB 32 ; SPACE
|
||||||
.db 33 ; V
|
DB 33 ; V
|
||||||
.db 34 ; F
|
DB 34 ; F
|
||||||
.db 35 ; T
|
DB 35 ; T
|
||||||
.db 36 ; R
|
DB 36 ; R
|
||||||
.db 37 ; 5
|
DB 37 ; 5
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 38 ; N
|
DB 38 ; N
|
||||||
.db 39 ; B
|
DB 39 ; B
|
||||||
.db 40 ; H
|
DB 40 ; H
|
||||||
.db 41 ; G
|
DB 41 ; G
|
||||||
.db 42 ; Y
|
DB 42 ; Y
|
||||||
.db 43 ; 6
|
DB 43 ; 6
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 44 ; M
|
DB 44 ; M
|
||||||
.db 45 ; J
|
DB 45 ; J
|
||||||
.db 46 ; U
|
DB 46 ; U
|
||||||
.db 47 ; 7
|
DB 47 ; 7
|
||||||
.db 48 ; 8
|
DB 48 ; 8
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 44 ; ,
|
DB 44 ; ,
|
||||||
.db 45 ; K
|
DB 45 ; K
|
||||||
.db 46 ; I
|
DB 46 ; I
|
||||||
.db 47 ; O
|
DB 47 ; O
|
||||||
.db 48 ; 0
|
DB 48 ; 0
|
||||||
.db 49 ; 9
|
DB 49 ; 9
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 46 ; .
|
DB 46 ; .
|
||||||
.db 47 ; /
|
DB 47 ; /
|
||||||
.db 48 ; L
|
DB 48 ; L
|
||||||
.db 59 ; ;
|
DB 59 ; ;
|
||||||
.db 60 ; P
|
DB 60 ; P
|
||||||
.db 45 ; -
|
DB 45 ; -
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 39 ; '
|
DB 39 ; '
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 91 ; [
|
DB 91 ; [
|
||||||
.db 61 ; =
|
DB 61 ; =
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; CAPS
|
DB 0 ; CAPS
|
||||||
.db 0 ; R SHFT
|
DB 0 ; R SHFT
|
||||||
.db 10 ; ENTER
|
DB 10 ; ENTER
|
||||||
.db 93 ; ]
|
DB 93 ; ]
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 92 ; \
|
DB 92 ; \
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 8 ; BKSP
|
DB 8 ; BKSP
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 9 ; KP 1
|
DB 9 ; KP 1
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 10 ; KP 4 -- NOTE: shadowed by break code (see the NOTE in ps2_keyboard.asm)
|
DB 10 ; KP 4 -- NOTE: shadowed by break code (see the NOTE in ps2_keyboard.asm)
|
||||||
.db 11 ; KP 7
|
DB 11 ; KP 7
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 0 ; (Unused)
|
DB 0 ; (Unused)
|
||||||
.db 48 ; KP 0
|
DB 48 ; KP 0
|
||||||
.db 46 ; KP .
|
DB 46 ; KP .
|
||||||
.db 47 ; KP 2
|
DB 47 ; KP 2
|
||||||
.db 48 ; KP 5
|
DB 48 ; KP 5
|
||||||
.db 49 ; KP 6
|
DB 49 ; KP 6
|
||||||
.db 50 ; KP 8
|
DB 50 ; KP 8
|
||||||
.db 27 ; ESC
|
DB 27 ; ESC
|
||||||
.db 0 ; NUM
|
DB 0 ; NUM
|
||||||
.db 0 ; F11
|
DB 0 ; F11
|
||||||
.db 43 ; KP +
|
DB 43 ; KP +
|
||||||
.db 44 ; KP 3
|
DB 44 ; KP 3
|
||||||
; The following codes are unrecognized by PAT80, as it uses only 7 bits (see the NOTE in ps2_keyboard.asm)
|
; The following codes are unrecognized by PAT80, as it uses only 7 bits (see the NOTE in ps2_keyboard.asm)
|
||||||
; .db 45 ; KP -
|
; DB 45 ; KP -
|
||||||
; .db 42 ; KP *
|
; DB 42 ; KP *
|
||||||
; .db 43 ; KP 9
|
; DB 43 ; KP 9
|
||||||
; .db 0 ; SCROLL
|
; DB 0 ; SCROLL
|
||||||
; .db 0 ; (Control key)
|
; DB 0 ; (Control key)
|
||||||
; .db 0 ; (Control key)
|
; DB 0 ; (Control key)
|
||||||
; .db 0 ; (Control key)
|
; DB 0 ; (Control key)
|
||||||
; .db 0 ; (Control key)
|
; DB 0 ; (Control key)
|
||||||
; .db 0 ; F7
|
; DB 0 ; F7
|
@ -116,9 +116,19 @@ Sysinit:
|
|||||||
call Sys_Beep
|
call Sys_Beep
|
||||||
|
|
||||||
; Run memory monitor
|
; Run memory monitor
|
||||||
ei ; enable maskabpe interrupts
|
; ei ; enable maskabpe interrupts
|
||||||
im 1 ; set interrupt mode 1 (on interrupt jumps to 0x38)
|
; im 1 ; set interrupt mode 1 (on interrupt jumps to 0x38)
|
||||||
rst 0x38 ; throw fake interrupt: jump to interrupt routine to start monitor
|
; rst 0x38 ; throw fake interrupt: jump to interrupt routine to start monitor
|
||||||
|
|
||||||
|
; Keyboard test
|
||||||
|
ld a, 0x3E
|
||||||
|
call Sys_Printc
|
||||||
|
ktestloop:
|
||||||
|
call Sys_Readc
|
||||||
|
call Sys_Printc
|
||||||
|
ld a, 46
|
||||||
|
call Sys_Printc
|
||||||
|
jp ktestloop
|
||||||
|
|
||||||
; User exited from memory monitor without loading a program. Do nothing.
|
; User exited from memory monitor without loading a program. Do nothing.
|
||||||
mloop:
|
mloop:
|
||||||
|
Loading…
Reference in New Issue
Block a user