This shows you the differences between two versions of the page.
— | base:scanning_the_keyboard_without_joysticks_interfere [2022-03-11 22:40] (current) – created erhan | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Scanning the keyboard without joysticks interfere ====== | ||
+ | Converts keycode ($00-$3F) to $DC00-$DC01 values and scans without interfering from joysticks at port 1 or 2. Also keeps history, to detect key press & hold. | ||
+ | |||
+ | < | ||
+ | |||
+ | ;64tass format | ||
+ | ;with default $dc02 - $dc03 values ($ff and $00) | ||
+ | ;taken from Platoon game, shortened and key history integrated. | ||
+ | ;code to key conversion table below, from c64-wiki.com | ||
+ | |||
+ | ;to use inside irq, below code is enough : | ||
+ | ; lda #$keycode | ||
+ | ; jsr keyscan | ||
+ | ; bcc + | ||
+ | ; inc $d020 | ||
+ | ; | ||
+ | |||
+ | ; | ||
+ | ; | ||
+ | ;$02 Crsr ←→ $12 D $22 J $32 ] | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | ;$07 Crsr ↑↓ $17 X $27 N $37 ? | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | |||
+ | |||
+ | * = $1000 | ||
+ | |||
+ | lda #$3e ;scan for key " | ||
+ | jsr keyscan | ||
+ | bcc + | ||
+ | inc $d020 ; | ||
+ | + | ||
+ | - lda $d011 | ||
+ | bpl - | ||
+ | - lda $d011 | ||
+ | bmi - | ||
+ | |||
+ | jmp $1000 | ||
+ | |||
+ | keyscan | ||
+ | ; sty backy+1 ; | ||
+ | pha | ||
+ | lsr | ||
+ | lsr | ||
+ | lsr | ||
+ | tay | ||
+ | lda row,y | ||
+ | sta $dc00 | ||
+ | pla | ||
+ | and #$07 | ||
+ | tay | ||
+ | lda $dc01 | ||
+ | and column,y | ||
+ | bne nokey | ||
+ | lda #$ff ;key is checked 2nd time, to be sure of | ||
+ | sta $dc00 ;joy #1 and #2 are not interfering | ||
+ | lda $dc01 | ||
+ | and column,y | ||
+ | beq nokey | ||
+ | |||
+ | cmp histv ; | ||
+ | bne + | ||
+ | clc | ||
+ | bcc backy | ||
+ | |||
+ | nokey asl ; | ||
+ | clc | ||
+ | .byte $24 | ||
+ | + sec ; | ||
+ | sta histv | ||
+ | |||
+ | backy | ||
+ | ; ldy # | ||
+ | lda #$ff | ||
+ | sta $dc00 ;set default value | ||
+ | lda #$7f | ||
+ | sta $dc01 ;set default value | ||
+ | rts | ||
+ | |||
+ | |||
+ | row .byte $fe, | ||
+ | column .byte $01, | ||
+ | histv .byte $00 | ||
+ | |||
+ | </ |