?? ps2key.asm
字號:
; key 95 has a special consideration as well
; generation.
;
; 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
;
; 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
call put_code ;and return
ret
.break: ;key was a break situation
;we need to append shift-make codes
CLRBIT PS2KEY_MAKE_FLAG,ps2key_flags ;put a break code for the character in question
mov A,X
call put_code
mov A,[ksc_mod0]
and A,LEFT_SHIFT_BIT ;if a left shift
jz .rightmake
SETBIT PS2KEY_MAKE_FLAG,ps2key_flags ;append a left-make code
mov A,AT101KB_LEFTSHIFT
call put_code
.rightmake:
mov A,[ksc_mod0] ;if a right shift
and A,RIGHT_SHIFT_BIT
jz .exit
SETBIT PS2KEY_MAKE_FLAG,ps2key_flags ;prepend a right-make code
mov A,AT101KB_RIGHTSHIFT
call put_code
.exit:
ret
;========================================================================
; FUNCTION: numlock_case
;
; generates altered scan code for numlock'ed character
;
;========================================================================
numlock_case:
;numlock codes use extended byte
SETBIT PS2KEY_EXTENDED_FLAG,ps2key_flags ;so set flag
TSTMAKE
jz .break
;key was a make
SETBIT PS2KEY_MAKE_FLAG,ps2key_flags ;so prepend a left-shift make
mov A,AT101KB_LEFTSHIFT
call put_code
mov A,X
call put_code
ret ;and return
.break: ;key was a break
CLRBIT PS2KEY_MAKE_FLAG,ps2key_flags ;generate make code for the character
mov A,X
call put_code
mov A,AT101KB_LEFTSHIFT
call put_code
ret
;========================================================================
; FUNCTION: put_code
;
; generates scan code
;
; uses the value in the local variables extended_flag and make_flag
;
;========================================================================
put_code:
push X ;save X register
mov X,A ;save character in X
TSTBIT PS2KEY_EXTENDED_FLAG,ps2key_flags
jz .next
mov A,0e0h ; prepend an 0xe0
call putch
.next: ;check for make/break
TSTBIT PS2KEY_MAKE_FLAG,ps2key_flags
jz .break
.make: ;it is a make
mov A,[ps2key_scan_set]
cmp A,SCAN_SET_1 ;if scan set 1,
jnz .makescan2
mov A,X
index scan_set_1_table ; look up using set 1's table
call putch ; put character, and exit
jmp .exit
.makescan2:
cmp A,SCAN_SET_2
jnz .makescan3 ;if scan set 2,
mov A,X ; look up using set 2's table
index scan_set_2_table
call putch ; put character, and exit
jmp .exit
.makescan3: ;scan set 3
mov A,X ;just do it
index scan_set_3_table
call putch
jmp .exit
.break: ;it is a break
mov A,[ps2key_scan_set]
cmp A,SCAN_SET_1 ;
jnz .breakscan2
mov A,X ;if scan set 1,
index scan_set_1_table ; look up code and set bit 7
or A,080h
call putch ; put code and exit
jmp .exit
.breakscan2:
cmp A,SCAN_SET_2
jnz .breakscan3
mov A,0f0h ;if scan set 2,
call putch ; prepend an 0xf0 byte and exit
mov A,X
index scan_set_2_table
call putch
jmp .exit
.breakscan3:
mov A,0f0h ;if scan set 3,
call putch ; prepend an 0xf0 byte and exit
mov A,X
index scan_set_3_table
call putch
.exit:
pop X
ret
;========================================================================
; FUNCTION: ps2_getkey
;
; gets a character from ring buffer.
;
; Returns:
; C = 1 if no characters are
; available, otherwise, C = 0 and character returned in acc.
;
;========================================================================
ps2_getkey:
mov A,[ps2key_key_count] ;if key count is zero, return
cmp A,0
jnz .yes
SETC
ret
.yes:
push X
dec [ps2key_key_count] ;else decrement key count
mov X,[ps2key_outptr] ;get char pointed to
mov A,[X + 0] ;by out pointer
mov X,A ;save it in X
inc [ps2key_outptr] ;increment out pointer
mov A,key_buffer_end ;check for wrap
cmp A,[ps2key_outptr]
jnz .loop
mov A,ps2key_key_buffer ;wrap, restore pointer to beginning
mov [ps2key_outptr],A
.loop:
mov A,X
pop X
CLEARC ;return with carry clear
ret
;========================================================================
; FUNCTION: put_error
;
; inserts an overrun error code into the ring buffer
;
; Returns:
;
;
;========================================================================
put_error:
mov A,[ps2key_key_count] ;get current buffer size
cmp A,BUFFER_LEN ;if == to max
jnz .put ;quit now
ret ;else
.put:
push X ;save X
mov X,0ffh ;if scan set 1, use 0xff for error code
mov A,[ps2key_scan_set]
cmp A,SCAN_SET_1
jz .l1
mov X,0 ;sets 2 and 3 use a 0 for overrun
.l1:
mov A,X
.l2:
call put ;put the character into the ring buffer
pop X ;restore X
ret
;========================================================================
; FUNCTION: putch
;
; putch inserts a character into the ring buffer. if the ring buffer
; is full or has only room for 1 byte, putch will set the overflow flag
; and return. In other words, putch always leaves room, if possible,
; in the key buffer for insertion of an error code if an overflow occurs.
;
; Returns:
;
;
;========================================================================
putch:
push A ;save the character
mov A,[ps2key_key_count] ;get current buffer length
cmp A,BUFFER_LEN-1 ;if not full,
pop A ; retrieve the character
jc put ; and put it it buffer
SETBIT PS2KEY_OVERFLOW_FLAG,ps2key_flags ;else
ret ; quit now
put:
push X
inc [ps2key_key_count] ;increment the key count
mov X,[ps2key_inptr] ;get current in pointer
mov [X +0],A ;put character there
pop X
inc [ps2key_inptr] ;increment the pointer
mov A,key_buffer_end ;check for wraparound
cmp A,[ps2key_inptr]
jnz .l1
mov A,ps2key_key_buffer ;buffer wrap -- restore pointer to beginning
mov [ps2key_inptr],A
.l1:
ret
;========================================================================
; FUNCTION: ps2key_disable_typematic_action
;
; Disables a typematic key function
;
;
; Returns: nada
;
;
;========================================================================
ps2key_disable_typematic_action:
push A ;save A
mov A,0 ;clear out typematic key and delay
mov [ps2key_last_key_made],A
mov [ps2key_delay_ctr],A
pop A
ret
;========================================================================
; FUNCTION: ps2key_enable_typematic_action
;
;
; Stores the contents of A as the typematic key, and initializes
; the delay counter to the initial typematic delay.
;
; Returns:
;
;
;========================================================================
ps2key_enable_typematic_action:
push A ;save key code
mov [ps2key_last_key_made],A ;store it
mov A,[ps2key_flags]
mov [ps2key_last_flags],A ;save the flags associated with it
mov A,[ps2key_type_delay] ;initialize delay counter
mov [ps2key_delay_ctr],A ;to typematic delay
.exit:
pop A
ret
;========================================================================
; FUNCTION: ps2key_check_typematic
;
;
; Checks for expiration of the typematic delay counter and generates
; a key make for the typematic key, if the delay has expired.
;
; Returns:
;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -