📄 ps2key.asm
字号:
;
; Returns:
; C = 1 if key was handled
; C = 0 if not
;
;
;========================================================================
test_153_154:
cmp A,153
jz .make
cmp A,154
jnz .no
.make: ;these keys generate
push X ;make codes only
TSTMAKE
jz .yes
call base_case
.yes:
pop X
SETC
ret
.no:
CLEARC
ret
;========================================================================
; Function: test_extended_codes
;
; check for all special keys in scan sets 1 and 2 that require an extension
; byte (0xe0) prepended to their scan code, but with NO OTHER special rules
; applied to them
;
; Returns:
; C = 1 if key was handled
; C = 0 if not
;========================================================================
test_extended_codes:
cmp A,AT101KB_SLEEP ;if sleep key
jnz .next
push X ;and a make
TSTMAKE
pop X
jz .yes1
call extended_make_break ;generate an extended make/break sequence
jmp .yes1
.next: ;check for other extended kets
cmp A,62 ; right now, keys 62,64, and 108
jz .yes ; R_Alt, R_Ctrl, R_GUI
cmp A,64 ; all meet this requirement
jz .yes
cmp A,108
jz .yes
cmp A,127 ;as do left_gui, right_gui, and app keys
jz .yes
cmp A,128
jz .yes
cmp A,129
jz .yes
cmp A,151 ; check for keys 136 thru 151 inclusive
jnc .no ;
cmp A,136
jc .no
.yes:
call extended_base_case ; generate an extension code
.yes1:
SETC ; set carry to indicate we handled this char
ret
.no:
CLEARC ;clear carry to indicate we did not handle
ret ;the char
;========================================================================
; Function: extended_make_break
;
; generates an extended make and an extended break sequence for the key in question
;
;========================================================================
extended_make_break:
SETBIT PS2KEY_EXTENDED_FLAG,ps2key_flags ;yes, generate an extended
SETBIT PS2KEY_MAKE_FLAG,ps2key_flags ;make and an extended break for this code
mov A,X
call put_code
CLRBIT PS2KEY_MAKE_FLAG,ps2key_flags
mov A,X
call put_code ;
ret
;========================================================================
; test_75_89
;
; keys 75 through 89 all have the same set of rules governing their code
; generation.
;-------------------------------------------------------------------------
; For SCAN CODE 1
;-----------------
; These keys may have additional "shift" and/or "unshift" scan codes
; preceding the Base Make code and following the Base Break code,
; depending upon the current state of Num Lock and the state of Shift key/s
; (when multiple keys are held down at the same time).
;
; These Keys are Typematic:
;
; Key assignment Base Make Base Break
; 75 Insert E0 52 E0 D2
; 76 Delete E0 53 E0 D3
; 79 Left Arrow E0 4B E0 CB
; 80 Home E0 47 E0 C7
; 81 End E0 4F E0 CF
; 83 Up Arrow E0 48 E0 C8
; 84 Dn Arrow E0 50 E0 D0
; 85 Page Up E0 49 E0 C9
; 86 Page Down E0 51 E0 D1
; 89 Right Arrow E0 4D E0 CD
;
; Num Lock ON Make code Break code
; Final Key only E0 2A + Base Make Base Break + E0 AA
;
; Num Lock OFF
; Final Key only
; With LSHIFT E0 AA + Base Make Base Break + E0 2A
; With RSHIFT E0 B6 + Base Make Base Break + E0 36
; With L&RSHIFT E0 AA E0 B6 + Base Make Base Break + E0 36 E0 2A
;
; As an example, consider the case where
; Num Lock is OFF and
; push and hold Left SHIFT,
; then push and hold Right SHIFT,
; and finally push Insert.
; 2A (LSHIFT make)
; 36 (RSHIFT make)
; E0 AA E0 B6 E0 52 (Insert make)
;
; When these keys are released,
; the keys still held down at the time a key is released determine it's scan code.
; Assume Insert is released first then Right SHIFT and last Left SHIFT.
; E0 D2 E0 36 E0 2A (Insert break)
; B6 (RSHIFT break)
; AA (LSHIFT break)
;
; For SCAN CODE 2
;-----------------
; These keys may have additional "shift" and/or "unshift" scan codes
; preceding the Base Make code and following the Base Break code,
; depending upon the current state of Num Lock and the state of Shift key/s
; (when multiple keys are held down at the same time).
;
; These Keys are Typematic:
;
; Key assignment Base Make Base Break
; 75 Insert E0 70 E0 F0 70
; 76 Delete E0 71 E0 F0 71
; 79 Left Arrow E0 6B E0 F0 6B
; 80 Home E0 6C E0 F0 6C
; 81 End E0 69 E0 F0 69
; 83 Up Arrow E0 75 E0 F0 75
; 84 Dn Arrow E0 72 E0 F0 72
; 85 Page Up E0 7D E0 F0 7D
; 86 Page Down E0 7A E0 F0 7A
; 89 Right Arrow E0 74 E0 F0 74
;
; Num Lock ON Make code Break code
; Final Key only E0 12 + Base Make Base Break + E0 F0 12
;
; Num Lock OFF
; Final Key only
; With LSHIFT E0 F0 12 + Base Make Base Break + E0 12
; With RSHIFT E0 F0 59 + Base Make Base Break + E0 59
; With L&RSHIFT E0 F0 12 E0 F0 59 + Base Make Base Break + E0 59 E0 12
;
;-------------------------------------------------------------------------
; Returns:
; C = 1 if key was handled
; C = 0 if not
;========================================================================
test_75_89:
cmp A,90 ;check for keys 75 through 89 inclusive
jnc .no
cmp A,75
jc .no
mov A,[ps2key_numlock] ;test for numlock on/off
cmp A,0
jnz .numlock_on
;numlock is off
mov A,[ksc_mod0] ;check for shift states
and A,(LEFT_SHIFT_BIT+RIGHT_SHIFT_BIT)
jz .base ;numlock off, some sort of shift
;
call shift_case ;so handle as shift case
jmp .yes
.base:
call extended_base_case ;numlock off, no shift, use extended base case
jmp .yes
.numlock_on: ;numlock on, check for shift states
mov A,[ksc_mod0]
and A,(LEFT_SHIFT_BIT + RIGHT_SHIFT_BIT)
jz .numlock_only
call extended_base_case ;numlock on, some shift, use extended base case
jmp .yes
.numlock_only:
call numlock_case ;numlock on only, use numlock case
.yes:
SETC ;set carry to indicate we handled this char
ret
.no:
CLEARC
ret
;========================================================================
; Function: test_95 [AT101KP_SLASH]
;
; key 95 has a special consideration as well
; generation.
;-------------------------------------------------------------------------
; This Key is Typematic (Numeric / on US keyboards)
;
; Scan Code base L-SHIFT + base R-SHIFT + base L-SHIFT + R-SHIFT + base
; 1 make E0 35 E0 AA E0 35 E0 B6 E0 35 E0 AA E0 B6 E0 35
; 1 break E0 B5 E0 B5 E0 2A E0 B5 E0 36 E0 B5 E0 36 E0 2A
; 2 make E0 4A E0 F0 12 E0 4A E0 F0 59 E0 4A E0 F0 12 E0 F0 59 E0 4A
; 2 break E0 F0 4A E0 F0 4A E0 12 E0 F0 4A E0 59 E0 F0 4A E0 59 E0 12
;-------------------------------------------------------------------------
; Returns:
; C = 1 if key was handled
; C = 0 if not
;========================================================================
test_95:
cmp A,95
jnz .no ;key is 95
;test for shifting
mov A,[ksc_mod0]
and A,(LEFT_SHIFT_BIT+RIGHT_SHIFT_BIT)
jz .no_shift
call shift_case ;there's shifting, use shift case
jmp .yes
.no_shift:
call extended_base_case ;else use extended base case
.yes:
SETC
ret
.no:
CLEARC
ret
;=================================================================================================================
; FUNCTION: test_124 [AT101KB_PRINTSCREEN]
;-----------------------------------------------------------------------------------------------------------------
; This Key is Typematic (Print Screen on US keyboards)
;
; Code Make Break LCtrl LCtrl LAlt LAlt
; or RCtrl + LSHIFT or RCtrl + LSHIFT or RAlt + Make or RAlt + Break
; or RSHIFT + Make or RSHIFT + Break
; 1 E0 2A E0 37 E0 B7 E0 AA E0 37 E0 B7 54 D4
; 2 E0 12 E0 7C E0 F0 7C E0 F0 12 E0 7C E0 F0 7C 84 F0 84
;
;-----------------------------------------------------------------------------------------------------------------
; key 124 has a special consideration as well
;
; Returns:
; C = 1 if key was handled
; C = 0 if not
;=================================================================================================================
test_124:
cmp a,124
jnz .no
;test for ctrl,shift, or alt keys
;in other words, any modifier key
;except the gui keys
mov A,[ksc_mod0]
and A,~(LEFT_GUI_BIT+RIGHT_GUI_BIT)
jnz .special_case
;no modifier keys are pressed. in this
;case, use the "numlock" rule used for
;keys 75 through 89
call numlock_case
jmp .yes
.special_case: ;some modifier keys are pressed.
mov A,[ksc_mod0]
and A,(LEFT_ALT_BIT+RIGHT_ALT_BIT) ;if an alt key
jz .shiftctrl
mov X,AT101KB_ALT_124 ; use special alt code for this key
call base_case ; and non-extended case
jmp .yes
.shiftctrl: ;else
call extended_base_case ; use extended case for this key
.yes:
SETC
ret
.no:
CLEARC
ret
;========================================================================
; FUNCTION: extended base case
;
; sets extension flag so that scan code generation will prepend an 0xE0
; to the scan code
;
;========================================================================
extended_base_case:
SETBIT PS2KEY_EXTENDED_FLAG,ps2key_flags
;========================================================================
; FUNCTION: base_case
;
; generates base-case scan code for character
; to the scan code
;
;========================================================================
base_case:
CLRBIT PS2KEY_MAKE_FLAG,ps2key_flags
TSTMAKE
jz .base1
SETBIT PS2KEY_MAKE_FLAG,ps2key_flags
.base1:
mov A,X ;get character in A
call put_code ;put scan code
ret ;and exit
;========================================================================
; FUNCTION: shift_case
;
; generates altered scan code for shifted character
;
;========================================================================
shift_case:
SETBIT PS2KEY_EXTENDED_FLAG,ps2key_flags ;set extended flag
TSTMAKE ;if make
jz .break
mov A,[ksc_mod0] ;and left-shift
and A,LEFT_SHIFT_BIT
jz .rightbreak
; we need to prepend a left-shift break code
CLRBIT PS2KEY_MAKE_FLAG,ps2key_flags ; so set up a left-shift break
mov A,AT101KB_LEFTSHIFT
call put_code ; and put it
.rightbreak:
mov A,[ksc_mod0] ;now check for right shift
and A,RIGHT_SHIFT_BIT ;if right-shift
jz .next
;prepend right-shift break code
CLRBIT PS2KEY_MAKE_FLAG,ps2key_flags
mov A,AT101KB_RIGHTSHIFT
call put_code
.next:
SETBIT PS2KEY_MAKE_FLAG,ps2key_flags ;now generate a make scan code for the character
mov A,X
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -