⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb-scan.asm

📁 MC68HC608JB8的固件例程源程序.zip
💻 ASM
📖 第 1 页 / 共 3 页
字号:
GKEY_NILOOP:
*
* --- Locate Overlapped Keys -------------------------
        ldx     VP_ChkCol
        lda     Q_CScan,x
        and     V_ColVal
        beq     GKEY_NICOL              ; no overlapped keys ?
*
        jsr     COUNT_ONE               ; count no. of '1' in <reg_A>
        lda     VC_One
        lsra
        beq     GKEY_NICOL              ; < 2 overlapped keys ?
*
* --- Ghost Keys Found -------------------------------
        bset    b_Kghost,VS_Scan        ; set ghost key flag
        bra     GKEY_EXIT
*
* --- Check Next Overlapped Column -------------------
GKEY_NICOL:
        dec     VP_ChkCol
        bpl     GKEY_NILOOP             ; ~last overlapped column ?
*
* --- Check Next Column ----------------------------------------
GKEY_NECOL:
        dec     VP_Col
        bne     GKEY_NELOOP             ; ~last check column ?
*
*
*
* -----------------------------------------------------------------------
GKEY_EXIT:
        rts




* --------------------------------------------------------------------- *
* COUNT_ONE - count the no. of '1' in <reg_A>                           *
* In       :  <reg_A>       byte under test                             *
* Out      :  VC_One        no. of '1' in <reg_A>                       *
* Call     :  <nil>                                                     *
* --------------------------------------------------------------------- *
COUNT_ONE:
        clr     VC_One                  ; reset 1's counter
        ldx     #K_RowMax               ; count the no. of pressed keys
CONE_AGN:
        lsra
        bcc     CONE_ZERO
CONE_ONE:
        inc     VC_One
CONE_ZERO:
        DBNZX   CONE_AGN
*
* -------------------------------------------------------------------
CONE_EXIT:
        Rts




* --------------------------------------------------------------------- *
* SCAN_HDLR - process scan results                                      *
* In       :  Q_CScan[0..17]    current scan result                     *
*             b_CKPress         =1 key(s) press detected for curr. scan *
* Out      :  QP_IN0_RPT        prev. keyboard report                   *
*             QC_IN0_RPT        curr. keyboard report                   *
* Call     :  LOCATE_KEY, ADD_KEY                                       *
* --------------------------------------------------------------------- *
USCAN_HDLR:

	clr	V_KeyNum		; clear the LOCATE_KEY buffer
	bclr	b_K_FN_FND,VS_SCAN	; clear the flag first.
* ------------------------------------------------------------------------
*
	brclr	b_3Z_KEY,V_3_ZERO,SHDL_END_3Z
	bclr	b_3Z_KEY_P,V_3_ZERO	; reset the '000' key flag

	lda	V_3_ZERO		; Check if end of sequence
	and	#%00000111
	beq	ALL_SND_OVR		; Always set '0' afterward

	dec	V_3_ZERO
	and	#%00000001
	beq	SET_INH_3Z
; ---------------------------------------
CLR_INH_3Z:
	bclr	b_INH_3Z,V_3_ZERO	; Set the '0' key ON

	bra	SHDL_END_3Z
; ---------------------------------------
ALL_SND_OVR:

	bset	b_SEND_OVR,V_3_ZERO

	mov	#KC_40ms,VC_40ms	; restore the scan rate

	bra	CLR_INH_3Z
; ---------------------------------------
SET_INH_3Z:
	bset	b_INH_3Z,V_3_ZERO	; Set the '0' key OFF

SHDL_END_3Z:
; ---------------------------------------
*
*
* --- Handle Ghost Key Detected ------------------------------------------
USHDL_GHOST_KEY:
        brclr   b_Kghost,VS_Scan,USHDL_GKEY_END  ; ~ghost key detect ?
*
        mov     V_MKey,VP_MKey         ; push V_MKey
        clr     V_MKey
*
        ldx     #K_KNCsize
USHDL_GKEY_NXT:
        lda     {Q_NKey-1},x           ; push keycode report
        sta     {QP_NKey-1},x
*
        lda     #Key_ERO                ; fill all keycodes with #Key_EROvr
        sta     {Q_NKey-1},x
        DBNZX   USHDL_GKEY_NXT
* ------------------------------------------------------------------------
        jmp     USHDL_NKEY
*
* --- End of Handle Ghost Key Detected -----------------------------------
USHDL_GKEY_END:
*
*
*
* --- Record Pressed Key(s) to Report ------------------------------------
*
*  Clear the working buffer first
USHDL_ON:
        ldx     #{K_KNCSize+K_KNCSize} ; move key# and FN status
SHDLN_Clr_Scan_Buf:
        lda     {Q_N_Key-1},x        ; push kbd report
        sta     {Q_P_Key-1},x
*
;        clra
;        sta     {Q_N_Key-1},x        ; reset kbd report
        clr     {Q_N_Key-1},x           ; reset kbd report
	DBNZX   SHDLN_Clr_Scan_Buf
* ----------------------------------------------------------------------
        mov     V_MKey,VP_MKey
        mov     V_RKey,VP_RKey
* ----------------------------------------------------------------------

        mov	V_ACPI_Key,V_PreACPI_RPT	; push the ACPI KEY STATUS
        mov	V_HOT_Key1,V_PreHot_Rpt1	; push the hot key
        mov	V_HOT_Key2,V_PreHot_Rpt2
        mov	V_HOT_Key3,V_PreHot_Rpt3
        mov	V_HOT_Key4,V_PreHot_Rpt4


* ----------------------------------------------------------------------
	clr     V_MKey
	clr	V_ACPI_Key	        ; clear ACPI key working buffer
	clr	V_Hot_Key1		; clear hot key buffer
	clr	V_Hot_Key2
	clr	V_Hot_Key3
	clr	V_Hot_Key4

* ----------------------------------------------------------------------
        clr     VP_KCode	; Count # of pressed key ?
*
        brclr   b_CKPress,VS_Scan,USHDLN_END  ; ~key press detected in curr.
                                             ;  scan ?
*
* --- Extract Make Key Codes at current Column ----------------------
        clr     VP_Col                  ; start with col #0
USHDLN_NCOL:
        ldx     VP_Col
        lda     Q_CScan,x               ; get curr. column value
        beq     USHDLN_CCOL              ; column with no key press ?
*
        sta     V_ColVal
*
* --- Extract Make Key Codes at current (Row,Column) -----------
        clr     VP_Row                  ; start with row #0
USHDLN_NROW:
        lsr     V_ColVal
        bcc     USHDLN_CROW              ; ~make key at (VP_Col,VP_Row) ?
*
        lda     VP_Row
        ldx     VP_Col
        jsr     ULOCATE_KEY              ; return key code in V_KeyNum
*
        lda     V_KeyNum
        jsr     ADD_SCAN_BUFFER          ; add pressed key to keyboard
                                        ;   report
*
* --- Next Row -------------------------------------------------
USHDLN_CROW:
        inc     VP_Row
        ldx     VP_Row
        KCPXNE  K_RowMax,USHDLN_NROW     ; ~last Row ?
*
* --- Next Column ---------------------------------------------------
USHDLN_CCOL:
        inc     VP_Col
        ldx     VP_Col
        KCPXNE  K_ColMax,USHDLN_NCOL     ; ~last Column ?
*
* ------------------------------------------------------------------------
USHDLN_END:
*
*
	brclr	b_3Z_KEY,V_3_ZERO,SHDL_END_3Z_2

	brset	b_3Z_KEY_P,V_3_ZERO,SHDL_END_3Z_2	; SEQ. is not over
							;  and Key is ON
; -----------------------------------------
	brclr	b_SEND_OVR,V_3_ZERO,SEQ_NOT_END	; SEQ. is not over and key is off

	clr	V_3_ZERO		; ON-OFF sequence is over and
					;     '000' key is released
	bra	SHDL_END_3Z_2
; ----------------------------------------
SEQ_NOT_END:

	brset	b_INH_3Z,V_3_ZERO,SHDL_END_3Z_2

	lda	#KEY_000
	jsr	ADD_SCAN_BUFFER			; Force to put a KEY_0

SHDL_END_3Z_2:
* ----------------------------------------------------------------
*
*  Back up the last report to QP_KBD_RPT buffer
*   The Modifier key left unchanged
*
        ldx     #K_KNCSize       ; not include the Modifier, reserved keys)
SHDLN_RST_NXT:
        lda     {Q_NKey-1},x        ; back up kbd report
        sta     {QP_NKey-1},x
*
        clr     {Q_NKey-1},x        ; clear current kbd report
        DBNZX   SHDLN_RST_NXT
* -----------------------------------------------------------------------
	brset	b_K_FN_FND,VS_SCAN,FN_K_PRSD

	bclr	b_FN_STATE,VS_SCAN	; THe FN key is released

FN_K_PRSD:
* -----------------------------------------------------------------------
	lda	VP_KCODE		; Get # of pressed key

	beq	NO_KEY_PRS		; Skip parsing if no key is pressed
*
* ------------------------------------------------------------------------
	clr	VP_KCODE		; Reset the index pointer
* ------------------------------------------------------------------------
					; check the content of scan buffer
	jsr	PARSE_KEY		; & translate FN key if exist

	bra	USHDL_NKEY
*					;
*
*
* === Not any key pressed =================================================
NO_KEY_PRS:

        ldx     #{K_KNCsize+K_KNCsize}
        clra

CLR_FNKY_NXT_1:
        sta     {Q_N_KEY-1},x
        sta     {Q_P_KEY-1},x

        DBNZX   CLR_FNKY_NXT_1
*

*
*

*
* --- Check Keyboard Report Change ---------------------------------------
USHDL_NKEY:
        ldx     #K_IRPT0_Size
USHDL_NKY_NXT:
        lda     {QC_IN0_RPT-1},x
        cmp     {QP_IN0_RPT-1},x
        beq     USHDL_NKY_CTI            ;  prev. value = curr. value ?
*
        bset    b_NIRpt0,V_Dev_Status    ; signal kbd status update
        bra     USHDL_NKY_END
USHDL_NKY_CTI:
        DBNZX   USHDL_NKY_NXT
; ................................................................
        lda	V_ACPI_KEY
        cmp	V_PreACPI_Rpt		; Check if Key status changed?
        beq	USHDL_End_ACPI

        bset    b_ACPI_NRpt,V_HK_Status   ; signal ACPI Key status update
; ................................................................
USHDL_End_ACPI:

        ldx     #K_H_Rpt_Size
CHK_NXT_Hot:
        lda     {V_Hot_Key1-1},x
        cmp     {V_PreHot_Rpt1-1},x
        beq     No_New_H1               ;  prev. value = curr. value ?
*
        bset    b_HK_NRpt,V_HK_STATUS   ; signal HOT Key status update
        bra     USHDL_NKY_END

NO_NEW_H1:
        DBNZX   CHK_NXT_HOT
* ------------------------------------------------------------------------
*
* ------------------------------------------------------------------------
USHDL_NKY_END:
        rts

* --------------------------------------------------------------------- *
* ADD_SCAN_BUFFER - add reg_A to Keyboard scan buffer                   *
* In        :  	reg_A           key# to be added                        *
*              	b_FN_key	the FN state				*
*		Q_P_KEY[0..5]	the last result				*
*		Q_P_FN[0..5]	the last FN state			*
* Out       :  	Q_N_KEY[0..5]	update new make key                     *
*     		Q_N_FN[0..5]						*
* Call      :  	<nil>                                                   *
* --------------------------------------------------------------------- *
ADD_SCAN_BUFFER:
*
* --- Handle Keys Reported in Modifier Byte ------------------------------
ASKEY_MODIFIER:
        KCMPLO  Key_LCTL,NOT_MDFY_KEY   ; < Left Ctrl usage index ?
        KCMPHI  Key_RGUI,NOT_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
*
	rts
*
*
* --- Handle "000" Keys ---------------------------------------------------
CHK_3Z_STATE:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -