📄 ps2key.asm
字号:
mov A,PS2KeyBuffer ;initialize buffer pointers
mov [ps2key_inptr],A
mov [ps2key_outptr],A
mov A,0
mov [ps2key_key_count],A
pop A
ret
;========================================================================
; FUNCTION: ps2key_at101_2_ss3
;
; returns the scan-set3 code for the at101 code passed in A
;
;
;
;
;========================================================================
IFDEF SCANSET3
ps2key_at101_2_ss3:
index scan_set_3_table
ret
ENDIF
;========================================================================
; FUNCTION: ps2key_save_key_type
;
; saves the key type (in X) for the associated key (in A) in the key
; type array. The key is specified by its scan set 3 make code. The key
; type array is a packed array of 2-bit fields, into which the key type
; is inserted.
;
;========================================================================
IFDEF SCANSET3
XPAGEOFF
;
;define a lookup which returns the mask for each of the 4 possible 2-bit
;fields within a byte
ps2_key_mask:
db 03,0ch,030h,0c0h
;define another lookup which returns the 2-bit values shifted into their
;proper fields for insertion into a byte
ps2_key_value:
db 00h,01h,02h,03h ;values for bits 1-0
db 00h,04h,08h,0ch ;values for bits 3-2
db 00h,10h,20h,30h ;values for bits 5-4
db 00h,40h,80h,c0h ;values for bits 7-6
XPAGEON
ps2key_save_key_type:
push A ;save key code
push X ;save X register
swap A,X ;A <- key type
mov [ps2_temp0],A ;save type in working register
swap A,X ;get scan code back in A
cmp A,LAST_SCAN3_CODE ;if valid code
jnc .exit
push A ;save scan code
rrc A ;divide code by 4
rrc A
and A,03fh ;make sure bits 6 and 7 are clear
;this is now the byte-index into type array
mov X,A ;put it in index reg
pop A ;restore scan code
and A,3 ;mask off all but 2 ls bits
push A ;and save it
index ps2_key_mask ;get mask for this pair of bits within byte
cpl A ;complement it
and A,[X + ps2key_type_array] ;apply it to array at byte index
mov [X + ps2key_type_array],A ;and save it
pop A ;get bits 1 and 0 of scan code AGAIN
asl A ;shift left by 2 bits
asl A
add a,[ps2_temp0] ;add in value to set bits to
index ps2_key_value ;look up this value
or a,[X + ps2key_type_array] ;apply it to type ram array
mov [X + ps2key_type_array],A ;and save it there
.exit:
pop X ;restore X and A registers
pop A
ret
;========================================================================
; FUNCTION: ps2key_get_key_type
;
;
;returns the key type in X, for the given key code specified in A.
;
;the key is identified by its scan set 3 make code.
;
;========================================================================
ps2key_get_key_type:
push A ;save A
push A ;save it again
rrc A ;divide code by 4
rrc A
and A,03fh ;make sure bits 6 and 7 are clear
;this is now the byte-index into ram array
mov X,A ;put it in index reg
mov A,[X + ps2key_type_array] ;get the byte that contains the setting into A
mov X,A ;put it in X
pop A ;restore scan code
and A,3 ;mask off all but 2 ls bits
swap A,X ;A now contains byte with settings, X the bit offset
.lp:
dec X ;loop, shifting by two bits until
jc .lp1 ;desired bits are in bits 1 and 0
asr a
asr a
jmp .lp
.lp1:
and A,3 ;clean up bits 7-2
mov X,A ;move into x register
pop A ;restore a register
ret ;return
;========================================================================
; FUNCTION: ps2key_set_all_keys
;
;
;sets the type of all keys to the type specified in the A register
;
;the key is identified by its scan set 3 make code.
;
;========================================================================
XPAGEOFF
;define a table of 3 entries that defines key types as either
;all typematic, make_break, or make
set_keys_table:
TYPE TYPEMATIC,TYPEMATIC,TYPEMATIC,TYPEMATIC
TYPE MAKE_BREAK,MAKE_BREAK,MAKE_BREAK,MAKE_BREAK
TYPE MAKE,MAKE,MAKE,MAKE
XPAGEON
ps2key_set_all_keys:
index set_keys_table ;translate key type into entire byte
mov X,PS2_TYPE_ARRAY_SIZE-1 ;and fill key type array with this byte
.lp1:
mov [X+ps2key_type_array],A
dec X
jnc .lp1
ret
ENDIF
;========================================================================
; FUNCTION: ps2key_set_default_key_types
;
;
;sets the type of all keys to the defaults
;
;
;========================================================================
ps2key_set_default_key_types:
push A
;save regs
IFDEF SCANSET3
push X
mov X,PS2_TYPE_ARRAY_SIZE-1 ;set A and X to length of copy
mov A,PS2_TYPE_ARRAY_SIZE-1
.l1:
push A ;save A
index typematic_default_table ;get ROM value
mov [x+ps2key_type_array],a ;move it into RAM
pop A ;restore A
dec A ;decrement pointers
dec X
jnc .l1
ENDIF
;now restore rate and interval to the defaults
mov A,PS2_DEFAULT_TYPEMATIC_DELAY
mov [ps2key_type_delay],A
mov A,PS2_DFFAULT_TYPEMATIC_INTERVAL
mov [ps2key_type_period],A
IFDEF SCANSET3
pop X
ENDIF
pop A
ret
XPAGEOFF
;-------------------------------------------------------------------------
; KEY 29 is available on the US only
; KEY 42, 45 are available on the international keyboard only (Not US)
; KEY 56, 107 are used on Brazilian and some Far East keyboards only.
;-------------------------------------------------------------------------
;this table is sorted according to scan 3 make codes!!!
IFDEF SCANSET3
typematic_default_table: ;set3 code
TYPE TYPEMATIC,TYPEMATIC,MAKE_BREAK,MAKE_BREAK ;0-3
TYPE MAKE_BREAK,MAKE_BREAK,MAKE_BREAK,MAKE ;4-7
TYPE MAKE,MAKE_BREAK,TYPEMATIC,TYPEMATIC ;8-b
TYPE TYPEMATIC,TYPEMATIC,TYPEMATIC,MAKE ;c-f
TYPE TYPEMATIC,MAKE_BREAK,MAKE_BREAK,TYPEMATIC ;10-13
TYPE MAKE_BREAK,TYPEMATIC,TYPEMATIC,MAKE ;14-17
TYPE MAKE_BREAK,MAKE_BREAK,TYPEMATIC,TYPEMATIC ;18-1b
TYPE TYPEMATIC,TYPEMATIC,TYPEMATIC,MAKE ;1c-1f
TYPE MAKE_BREAK,TYPEMATIC,TYPEMATIC,TYPEMATIC ;20-23
TYPE TYPEMATIC,TYPEMATIC,TYPEMATIC,MAKE ;24-27
TYPE MAKE_BREAK,TYPEMATIC,TYPEMATIC,TYPEMATIC ;28-2b
TYPE TYPEMATIC,TYPEMATIC,TYPEMATIC,MAKE ;2c-2f
TYPE MAKE_BREAK,TYPEMATIC,TYPEMATIC,TYPEMATIC ;30-33
TYPE TYPEMATIC,TYPEMATIC,TYPEMATIC,MAKE ;34-37
TYPE MAKE_BREAK,MAKE,TYPEMATIC,TYPEMATIC ;38-3b
TYPE TYPEMATIC,TYPEMATIC,TYPEMATIC,MAKE ;3c-3f
TYPE MAKE_BREAK,TYPEMATIC,TYPEMATIC,TYPEMATIC ;40-43
TYPE TYPEMATIC,TYPEMATIC,TYPEMATIC,MAKE ;44-47
TYPE MAKE_BREAK,TYPEMATIC,TYPEMATIC,TYPEMATIC ;48-4b
TYPE TYPEMATIC,TYPEMATIC,TYPEMATIC,MAKE ;4c-4f
TYPE MAKE_BREAK,TYPEMATIC,TYPEMATIC,TYPEMATIC ;50-53
TYPE TYPEMATIC,TYPEMATIC,MAKE,MAKE ;54-57
TYPE MAKE,MAKE_BREAK,TYPEMATIC,TYPEMATIC ;58-5b
TYPE TYPEMATIC,TYPEMATIC,MAKE,MAKE ;5c-5f
TYPE TYPEMATIC,TYPEMATIC,MAKE,TYPEMATIC ;60-63
TYPE TYPEMATIC,MAKE,TYPEMATIC,MAKE ;64-67
TYPE MAKE,MAKE,TYPEMATIC,MAKE ;68-6b
TYPE MAKE,MAKE,MAKE,MAKE ;6c-6f
TYPE MAKE,MAKE,MAKE,MAKE ;70-73
TYPE MAKE,MAKE,MAKE,MAKE ;74-77
TYPE MAKE,MAKE,MAKE,TYPEMATIC ;78-7b
TYPE TYPEMATIC,MAKE,MAKE,MAKE ;7c-7f
TYPE TYPEMATIC,TYPEMATIC,TYPEMATIC,TYPEMATIC ;80-83
TYPE MAKE,MAKE,MAKE,MAKE ;84-87
TYPE MAKE,MAKE,MAKE,MAKE_BREAK ;88-8b
TYPE MAKE_BREAK,MAKE_BREAK,MAKE,MAKE ;8c-8f
ENDIF
;-------------------------------------------------------------------------
; KEYS not exist in SCAN 1 : 59, 63, 65 ~ 74, 109, 111
;-------------------------------------------------------------------------
; Normal code
; SCAN 1 BREAK (1 Byte) = SCAN 1 MAKE (1 Byte) + 80h
;
; KEYS not exist normal code : 62, 64, 108
;-------------------------------------------------------------------------
; Extended code (2 Byte)
; E0h + Normal code (1 Byte)
;
; KEYS not exist extended code : 43, 58, 91 ~ 99, 101 ~ 106, 122 ~ 124
;-------------------------------------------------------------------------
scan_set_1_table: ;IBM key no.
db 000h,029h,002h,003h,004h,005h,006h,007h ;0-7
db 008h,009h,00ah,00bh,00ch,00dh,07dh,00eh ;8-15
db 00fh,010h,011h,012h,013h,014h,015h,016h ;16-23
db 017h,018h,019h,01ah,01bh,02bh,03ah,01eh ;24-31
db 01fh,020h,021h,022h,023h,024h,025h,026h ;32-39
db 027h,028h,02bh,01ch,02ah,056h,02ch,02dh ;40-47
db 02eh,02fh,030h,031h,032h,033h,034h,035h ;48-55
db 073h,036h,01dh,000h,038h,039h,038h,000h ;56-63
db 01dh,000h,000h,000h,000h,000h,000h,000h ;64-71
db 000h,000h,000h,052h,053h,000h,000h,04bh ;72-79
db 047h,04fh,000h,048h,050h,049h,051h,000h ;80-87
db 000h,04dh,045h,047h,04bh,04fh,000h,035h ;88-95
db 048h,04ch,050h,052h,037h,049h,04dh,051h ;96-103
db 053h,04ah,04eh,07eh,01ch,000h,001h,000h ;104-111
db 03bh,03ch,03dh,03eh,03fh,040h,041h,042h ;112-119
db 043h,044h,057h,058h,037h,046h,046h,05bh ;120-127
db 05ch,05dh,000h,07bh,079h,070h,000h,054h ;128-135
db 000h,05fh,000h,020h,02eh,030h,022h,024h ;136-143
db 010h,019h,06ch,021h,065h,032h,066h,000h ;144-151
db 000h,0f1h,0f2h,000h,000h,000h,000h,000h ;152-159
;-------------------------------------------------------------------------
; Normal code
; SCAN 2 BREAK (2 Byte) = F0h + SCAN 2 MAKE (1 Byte)
;-------------------------------------------------------------------------
; Extended code (MAKE : 2 Byte, BREAK : 3 Byte)
; E0h + Normal code
;-------------------------------------------------------------------------
scan_set_2_table: ;IBM key no.
db 000h,00eh,016h,01eh,026h,025h,02eh,036h ;0-7
db 03dh,03eh,046h,045h,04eh,055h,06ah,066h ;8-15
db 00dh,015h,01dh,024h,02dh,02ch,035h,03ch ;16-23
db 043h,044h,04dh,054h,05bh,05dh,058h,01ch ;24-31
db 01bh,023h,02bh,034h,033h,03bh,042h,04bh ;32-39
db 04ch,052h,05dh,05ah,012h,061h,01ah,022h ;40-47
db 021h,02ah,032h,031h,03ah,041h,049h,04ah ;48-55
db 051h,059h,014h,000h,011h,029h,011h,000h ;56-63
db 014h,000h,000h,000h,000h,000h,000h,000h ;64-71
db 000h,000h,000h,070h,071h,000h,000h,06bh ;72-79
db 06ch,069h,000h,075h,072h,07dh,07ah,000h ;80-87
db 000h,074h,077h,06ch,06bh,069h,000h,04ah ;88-95
db 075h,073h,072h,070h,07ch,07dh,074h,07ah ;96-103
db 071h,07bh,079h,06dh,05ah,000h,076h,000h ;104-111
db 005h,006h,004h,00ch,003h,00bh,083h,00ah ;112-119
db 001h,009h,078h,007h,07ch,07eh,07eh,01fh ;120-127
db 027h,02fh,037h,067h,064h,013h,000h,084h, ;128-135
db 000h,03fh,000h,023h,021h,032h,034h,03bh ;136-143
db 015h,04dh,048h,02bh,010h,03ah,018h,000h ;144-151
db 000h,0f1h,0f2h,000h,000h,000h,000h,000h ;152-159
scan_set_3_table: ;IBM key no.
IFDEF SCANSET3
db 000h,00eh,016h,01eh,026h,025h,02eh,036h ;0-7
db 03dh,03eh,046h,045h,04eh,055h,000h,066h ;8-15
db 00dh,015h,01dh,024h,02dh,02ch,035h,03ch ;16-23
db 043h,044h,04dh,054h,05bh,05ch,014h,01ch ;24-31
db 01bh,023h,02bh,034h,033h,03bh,042h,04bh ;32-39
db 04ch,052h,053h,05ah,012h,013h,01ah,022h ;40-47
db 021h,02ah,032h,031h,03ah,041h,049h,04ah ;48-55
db 000h,059h,011h,000h,019h,029h,039h,000h ;56-63
db 058h,000h,000h,000h,000h,000h,000h,000h ;64-71
db 000h,000h,000h,067h,064h,000h,000h,061h ;72-79
db 06eh,065h,000h,063h,060h,06fh,06dh,000h ;80-87
db 000h,06ah,076h,06ch,06bh,069h,000h,077h ;88-95
db 075h,073h,072h,070h,07eh,07dh,074h,07ah ;96-103
db 071h,084h,07ch,000h,079h,000h,008h,000h ;104-111
db 007h,00fh,017h,01fh,027h,02fh,037h,03fh ;112-119
db 047h,04fh,056h,05eh,057h,05fh,062h,08bh ;120-127
db 08ch,08dh,081h,082h,083h,000h,000h,000h ;128-235
db 002h,003h,004h,005h,006h,018h,000h,028h
db 030h,038h,040h,048h,050h,009h,000h,000h
ENDIF
;-------------------------------------------------------------------------
; PAUSE on US Keyboard
;
; This is not Typematic and has no Break code
;-------------------------------------------------------------------------
; SCAN SET 1
ss1_key126_make_scan_code:
db 0e1h,01dh,045h,0e1h,09dh,0c5h,EndOfTable ;
; SCAN SET 2
ss2_key126_make_scan_code:
db 0e1h,014h,077h,0e1h,0f0h,014h,0f0h,077h,EndOfTable ;
XPAGEON
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -