📄 usb-scan.asm
字号:
brclr b_INH_3Z,V_3_ZERO,GO_SET_0
rts ; '0' report is inhibited (OFF)
*
*
* --- Handle Normal Keycode Bytes ----------------------------------------
NOT_MDFY_KEY:
*
KCMPLO KEY_H0,NOT_HOTK1 ; HOT KEY GROUP 1 ??
KCMPHI KEY_H7,NOT_HOTK1 ;
*
sub #KEY_H0 ; calculate index to BIT_TABLE
tax
*
lda BIT_TABLE,x ; set corresp. bit in HOT_KEY3
ora V_HOT_KEY1
sta V_HOT_KEY1
*
rts
*
NOT_HOTK1:
KCMPLO KEY_H8,NOT_HOTK2 ; HOT KEY GROUP 2 ??
KCMPHI KEY_H15,NOT_HOTK2 ;
*
sub #KEY_H8 ; calculate index to BIT_TABLE
tax
*
lda BIT_TABLE,x ; set corresp. bit in HOT_KEY2
ora V_HOT_KEY2
sta V_HOT_KEY2
*
rts
*
NOT_HOTK2:
KCMPLO KEY_H16,NOT_HOTK3 ; HOT KEY GROUP 3 ??
KCMPHI KEY_H23,NOT_HOTK3 ;
*
sub #KEY_H16 ; calculate index to BIT_TABLE
tax
*
lda BIT_TABLE,x ; set corresp. bit in HOT_KEY1
ora V_HOT_KEY3
sta V_HOT_KEY3
*
rts
* -----------------------------------------
NOT_HOTK3:
KCMPNE KEY_000,NOT_TRI_0
bset b_3Z_KEY_P,V_3_ZERO ; The '000' key is pressed
brset b_3Z_KEY,V_3_ZERO,CHK_3Z_STATE
mov #%11000100,V_3_ZERO ; Set b_3Z_KEY and set counter
; to send out two off, two on
mov #{KC_40ms/4},VC_40ms ; shorten the scan rate
GO_SET_0:
lda #KEY_0 ; Put the KEY_0 in the buffer
bra AKEY_STORE
NOT_TRI_0:
*
* --- Handle Keys Reported in ACPI Byte ------------------------------
*
KCMPNE #PKEY_PWR,NOT_PWR_KEY ; Check if = POWER DOWN key ?
mov #{1<b_PwrKey_Prs},V_ACPI_KEY ; Set flag and clear other ACPI key
rts
NOT_PWR_KEY:
KCMPNE #PKEY_SLP,NOT_SLP_KEY ; Check if = SLEEP key ?
mov #{1<b_SlpKey_Prs},V_ACPI_KEY ; Set flag and clear other ACPI key
rts
NOT_SLP_KEY:
KCMPNE #PKEY_WKE,NOT_WAK_KEY ; Check if = WAKE UP key ?
mov #{1<b_WakKey_Prs},V_ACPI_KEY ; Set flag and clear other ACPI key
rts
NOT_WAK_KEY:
KCMPNE #KEY_FN,NOT_FN_KEY ; Check if = FN key ?
bset b_K_FN_FND,VS_SCAN ; Set flag that the FN key is pressed
bset b_FN_STATE,VS_SCAN ; Set the FN state bit
NO_CHNG_FN:
rts
NOT_FN_KEY:
; ---------------------------------------------------------------------------
*
* When the "000" is pressed, ignore the rest keys before the "000" is
* sent over.
*
brset b_3Z_KEY,V_3_ZERO,IGNORE_REST
; ---------------------------------------------------------------------------
*
* --- Put store byte to Q_NKey[VP_KCode++] ---------------------
AKEY_STORE:
ldx VP_KCode
KCPXEQ {K_KNCsize},ADD_S_OVR ; keycode queue overflow ?
sta Q_N_Key,x ; store byte
inc VP_KCode ; point to next keycode loc.
*
* -----------------------------------------------------------------------
KCMPLO SKEY_0,EXIT_ADD_SCAN
KCMPHI SKEY_15,EXIT_ADD_SCAN ; Skip if not SKEY_#
* -----------------------------------------------------------------------
*
* It's SKEY_#, so check if it's pressed before?
*
sta V_TEMP_REG ; Save it in temp. register first.
clrx
* -------------------------------
FIND_SAME_SKEY:
lda Q_P_KEY,x ; Try to find same SKEY in the
; previouse scan buffer
* beq SET_NEW_FN ; If it's zero, that means no more
; key in the rest bytes of buffer
cmp V_TEMP_REG ; Compare with current SKEY_#
beq SET_OLD_FN ; Get back the previouse FN status
; if it's pressed before
incx
KCPXNE K_KNCSize,FIND_SAME_SKEY
; If the loop is over, same key is not found
* -----------------------------------------------------------------------
SET_NEW_FN:
lda VS_SCAN ; Get the current state of FN key
and #{1<b_FN_STATE} ; Extract the FN status
SET_FN:
ldx VP_KCODE ; get the current index
sta {Q_N_FN-1},x ; because VP_KCODE is increased
rts
* -----------------------------------------------------------------------
SET_OLD_FN:
lda Q_P_FN,x ; Get back the last reported FN state
bra SET_FN
* -----------------------------------------------------------------------
ADD_S_OVR:
ldx #{K_KNCsize + K_KNCsize}
lda #Key_ERO
CLR_SCAN_BUFFER_1:
sta {Q_N_KEY-1},x
dbnzx CLR_SCAN_BUFFER_1
* ------------------------------------------------------------------------
EXIT_ADD_SCAN:
IGNORE_REST:
rts
* --------------------------------------------------------------------- *
* PARSE_KEY - Parse the key scan buffer *
* *
* In : Q_N_KEY[0..5] current KBD scan buffer *
* Q_N_FN[0..5] *
* *
* Out : QC_IN0_RPT update new make key *
* Call : ADD_KEY *
* --------------------------------------------------------------------- *
PARSE_KEY:
*
* ------------------------------------------------------------------------
*
clra
sta V_Temp_Reg
; clr V_Temp_Reg ; reset the index to put data into report
PARSE_LOOP:
ldx VP_KCode ; Get the pointer for the buffer
inc VP_KCode
*
lda Q_N_KEY,x ; Get one key code from KBD scan buffer
beq EXIT_PARSE ; IT's over if reach end of data
* --------------------------------------
KCMPLO SKEY_0,NOT_SKEY
KCMPHI SKEY_15,NOT_SKEY ; Skip if not SKEY_#
* --------------------------------------
* *******************************************************
* It's SKEY_#, so convert it to a prper key usage code?
* *******************************************************
sub #SKEY_0
sta V_TEMP_REG1 ; Save the index for converting
lda Q_N_FN,x ; Get the new FN status for this key code
ldx V_TEMP_REG1 ; Restore the index for converting
tsta
bne FN_IS_ON ; FN_key >< 0, pressed
*
* ---------------------------------------------
* FN key is OFF
lda SKEY_TABLE_OFF,x ; Convert code with a table
bra FN_CONVERTED
* ---------------------------------------------
* FN key is ON
FN_IS_ON:
lda SKEY_TABLE_OFF,x
KCMPNE KEY_F12,FN_NF12
lda V_MKey
ora #%00000001
sta V_MKey ; left control key for break
FN_NF12:
lda SKEY_TABLE_ON,x ; Convert code with a table
FN_CONVERTED:
* ----------------------------------------------------
* *****************************************************
* It's NOT a SKEY_#, just put it in the report buffer
* *****************************************************
NOT_SKEY:
*
KCMPLO Key_LCTL,PARSE_N_MDFY_KEY ; < Left Ctrl usage index ?
KCMPHI Key_RGUI,PARSE_N_MDFY_KEY ; > Right GUI usage index ?
*
sub #Key_LCTL ; calculate index to BIT_TABLE
tax
*
lda BIT_TABLE,x ; set corresp. bit in V_MKey
ora V_MKey
sta V_MKey
bra PARSE_MDFY_KEY
*
PARSE_N_MDFY_KEY:
jsr ADD_KEY ; Put the key code in report buffer
PARSE_MDFY_KEY:
*
lda VP_KCode
KCMPNE K_KNCsize,PARSE_LOOP
* ------------------------------------------------------------------------
EXIT_PARSE:
rts
* --------------------------------------------------------------------- *
* ADD_KEY - add reg_A to USB keyboard report *
* In : reg_A key# to be added *
* Out : QC_IN0_RPT update new make key *
* Call : <nil> *
* --------------------------------------------------------------------- *
ADD_KEY:
*
* --- Handle Keys Reported in Modifier Byte ------------------------------
AKEY_MODIFIER:
KCMPLO Key_LCTL,NOT_MDFY_KEY_1 ; < Left Ctrl usage index ?
KCMPHI Key_RGUI,NOT_MDFY_KEY_1 ; > Right GUI usage index ?
*
sub #Key_LCTL ; calculate index to BIT_TABLE
tax
*
lda BIT_TABLE,x ; set corresp. bit in V_MKey
ora V_MKey
sta V_MKey
*
* --- Put store byte to Q_NKey[VP_KCode++] ---------------------
NOT_MDFY_KEY_1:
ldx V_TEMP_REG ; get the index to put data into report
*
sta Q_NKey,x ; store byte
inc V_TEMP_REG ; point to next keycode loc.
* ------------------------------------------------------------------------
AKEY_EXIT:
rts
* --------------------------------------------------------------------- *
* DLY_20US - delay 20us (HC08, Fcpu=3MHz) - by inst. cycles *
* In : K_Nd20us no. of CPU clocks for 20us delay *
* Out : <nil> *
* Call : <nil> *
* --------------------------------------------------------------------- *
* (jsr DLY_20US [5] clk)
DLY_20US:
pshx ; [2] clk
ldx #{(K_Nd20us-15)/3} ; [2] clk
DLY_NEXT:
DBNZX DLY_NEXT ; (3) clk
*
pulx ; [2] clk
*
* ------------------------------------------------------------------------
DLY_EXIT:
rts ; [4] clk
* --------------------------------------------------------------------- *
* Table : return bit position in a byte *
* Example : ldx <bit position> *
* lda Bit_Table,x *
* --------------------------------------------------------------------- *
BIT_TABLE:
db %00000001
db %00000010
db %00000100
db %00001000
db %00010000
db %00100000
db %01000000
db %10000000
* ====== End of File =====================================================
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -