📄 keyscan.asm
字号:
;==================================================
; keyboard scan program
;==================================================
F_ScanKeyPad:
lda R_KeyState
and #D_KstDebounce
beq ?non_scan_key_debounce
lda R_DebounceCnt
cmp #10
bcc ?scan_key_exit1
?non_scan_key_debounce:
jsr F_PollingKey
lda R_Keycode
cmp #D_KeyNone
beq ?ClearAllKeyFlagAndSleep
lda R_KeyState
and #D_KstDebounce
bne ?end_of_debounce_mode
lda R_KeyState
and #D_KstRelease
bne ?some_key_no_release
lda #D_KstDebounce
ora R_KeyState
sta R_KeyState
lda #0
sta R_DebounceCnt
ldx R_Keycode
stx R_OldKey
?scan_key_exit1:
rts
;; jmp J_SleepMode
?ClearAllKeyFlagAndSleep:
lda #(.not.(D_KstDebounce+D_KstRelease+D_KstMult))
and R_KeyState
sta R_KeyState
jmp ?scan_key_exit1
?end_of_debounce_mode:
lda #(.not.D_KstDebounce)
and R_KeyState
sta R_KeyState
lda R_OldKey
cmp R_Keycode
bne ?reget_key_code
lda #D_KstRelease
ora R_KeyState
sta R_KeyState
?ok_mult_key_in:
jmp F_KeyDecode
?some_key_no_release:
lda R_KeyState
and #D_KstMult
bne ?check_repeat_cnt
;; lda R_Keycode
;; cmp #KEY_LEFT
;; beq ?gen_a_repeat_key
;; cmp #KEY_RIGHT
;; beq ?gen_a_repeat_key
;; cmp #KEY_UP
;; beq ?gen_a_repeat_key
;; cmp #KEY_DOWN
;; beq ?gen_a_repeat_key
;;?scan_key_exit:
jmp ?scan_key_exit1
;=========
?gen_a_repeat_key:
;; lda mode
;; and #MODE_MASK
;; and #.not.SUB_MODE_MASK
;; cmp #M_TIME_CALENDAR ;
;; beq ?real_gen_a_repeat_key
;; cmp #M_TIME_SET
;; beq ?real_gen_a_repeat_key
;; cmp #M_TIMER_SET
;; beq ?real_gen_a_repeat_key
;; cmp #M_ALARM_SET
;; bne ?scan_key_exit1
;check if calendar mode
;
;
?real_gen_a_repeat_key:
ldx R_Keycode
stx R_OldKey
lda R_KeyState
ora #D_KstMult
sta R_KeyState
ldx #0
stx R_RepeatCnt
stx R_FastCnt
beq ?scan_key_exit1
;=========
?check_repeat_cnt:
lda #30
ldx R_FastCnt
cpx #5
bcc ?slowest_mult
lda #20
cpx #10
bcc ?slowest_mult
lda #10
?slowest_mult:
cmp R_RepeatCnt
bcs ?scan_key_exit1
ldx R_FastCnt
inx
stx R_FastCnt
bne ?non_reset_it
ldx #10
stx R_FastCnt
?non_reset_it:
lda #0
sta R_RepeatCnt
lda R_OldKey
cmp R_Keycode
beq ?ok_mult_key_in
?reget_key_code:
lda #(.not.(D_KstDebounce+D_KstRelease+D_KstMult))
and R_KeyState
sta R_KeyState
jmp F_ScanKeyPad
;============================================================================
;============================================================================
F_PollingKey:
ldx #0
stx tmp6
stx R_Keycode
;=++++++++++++++++++++++++
;;;;------PortCDType--------
;; lda #%00000000
;; sta p_portCD_config ;;all set to be IO porrt
;;;-----------------------------------------------------------------------
;; lda #%00000000 ;;0: input 1:output
;; sta p_portA_dir_ctrl
;; lda #%00000000 ;;
;; sta p_portA_config ;;$06
;; lda #%11111111
;; sta p_portA
;;;;------------------------
;; lda #%11111111 ;;1: output
;; sta p_portC_dir_ctrl
;; lda #%00000000 ;;0: buffer when it is output
;; sta p_portC_config
;;;;------------------------
;; lda #%00011111
;; sta p_portD_dir_ctrl
;; lda #%00000000
;; sta p_portD_config
;;;;------------------------
;; lda #%00000000
;; sta p_portC
;; lda #%00000000
;; sta p_portD
;;;;-------------------------
;=++++++++++++++++++++++++
nop
nop
lda p_portA
and #%00000001
bne ?Not_OnOffKey
ldx #D_KeyOnOff
stx R_Keycode
jmp L_ScanKeyEnd
?Not_OnOffKey:
lda #0
sta p_portD
sta p_portC
nop
nop
lda p_portA
eor #%00111110
and #%00111110
beq ScanKeyEnd_NoKey
L_LoopScanKey:
ldx tmp6
lda F_keyConvToBitTab,X
;=- eor #$ff
sta p_portD
lda #%00001000
sta p_portC
nop
nop
nop
lda p_portA
eor #%00111110
and #%00111110
bne L_shift_in_key
clc
lda R_Keycode
adc #5
sta R_Keycode
inc tmp6
lda tmp6
cmp #6 ;;0-->7
bcc L_LoopScanKey
lda #$ff
sta p_portD
lda #%00000000
sta p_portC
nop
nop
nop
lda p_portA
eor #%00111110
and #%00111110
bne L_shift_in_key
ScanKeyEnd_NoKey:
lda #D_KeyNone
sta R_Keycode
jmp L_ScanKeyEnd
;;----------------------------------|
L_shift_in_key:
ror a
?L_shift_in_key:
ror a
bcs L_ShiftInKeyOk
inc R_Keycode
jmp ?L_shift_in_key
;;----------------|
L_ShiftInKeyOk:
ldx R_Keycode
lda T_KeycodeTab,x
sta R_Keycode
L_ScanKeyEnd:
;=+++++++++++++++++++++++++++++
;=+++++++++++++++++++++++++++++
lda #0
sta p_portC
sta p_portD
lda R_Keycode
rts
;==================================================
F_keyConvToBitTab:
db %11111110
db %11111101
db %11111011
db %11110111
db %11101111
db %11011111
db %10111111
db %01111111
db %11111111
T_KeycodeTab:
db D_KeyAutoPlay
db D_KeyClaim
db D_KeyReview
db D_KeyScore
db D_KeyUndo
db D_KeyA
db D_Key10
db D_Key5
db D_KeySpade
db D_KeyNone
db D_KeyK
db D_Key9
db D_Key4
db D_KeyHeart
db D_KeyLeft
db D_KeyQ
db D_Key8
db D_Key3
db D_KeyNone
db D_KeyUp
db D_KeyJ
db D_Key7
db D_Key2
db D_KeyDiamond
db D_KeyDown
db D_KeyNone
db D_Key6
db D_Key1
db D_KeyClub
db D_KeyRight
db D_KeyNone
db D_KeyDouble
db D_KeyNT
db D_KeyPass
db D_KeyEnter
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -