small code optimization

This commit is contained in:
FeralChild64 committed 2019-10-13 21:25:24 +02:00
1 parent 5c8a29095b
commit ea60cb912f
1 file changed
+12 -15
+12 -15
View File
@@ -81,38 +81,35 @@ scnkey_bucky_loop:
// Scan the keyboard matrix // Scan the keyboard matrix
ldy #$07 // XXX adapt for C128 and C65 keyboards ldx #$07 // XXX adapt for C128 and C65 keyboards
ldx #$FF // offset in key matrix table, $FF for not found yet ldy #$FF // offset in key matrix table, $FF for not found yet
scnkey_matrix_loop: scnkey_matrix_loop:
lda kb_matrix_row_keys, y lda kb_matrix_row_keys, x
sta CIA1_PRA sta CIA1_PRA
lda kb_matrix_bucky_filter, y // filter out bucky keys lda kb_matrix_bucky_filter, x // filter out bucky keys
ora CIA1_PRB ora CIA1_PRB
cmp #$FF cmp #$FF
beq scnkey_matrix_loop_next // skip if no key pressed from this row beq scnkey_matrix_loop_next // skip if no key pressed from this row
cpx #$FF cpy #$FF
bne scnkey_no_keys // clash, more than one key pressed bne scnkey_no_keys // clash, more than one key pressed
// We have at least one key pressed in this row, we need to find which one exactly // We have at least one key pressed in this row, we need to find which one exactly
ldx #$07 ldy #$07
scnkey_matrix_loop_inner: scnkey_matrix_loop_inner:
cmp kb_matrix_row_keys, x cmp kb_matrix_row_keys, y
bne !+ // not this particular key bne !+ // not this particular key
txa // now .A contains key offset within a row tya // now .A contains key offset within a row
sec sec
adc kb_matrix_row_offsets, y // now .A contains key offset from the matrix start adc kb_matrix_row_offsets, x // now .A contains key offset from the matrix start
tax tay
jmp scnkey_matrix_loop_next jmp scnkey_matrix_loop_next
!: !:
dex dey
bpl scnkey_matrix_loop_inner bpl scnkey_matrix_loop_inner
bmi scnkey_no_keys // branch always, multiple keys must have been pressed bmi scnkey_no_keys // branch always, multiple keys must have been pressed
scnkey_matrix_loop_next: scnkey_matrix_loop_next:
dey dex
bpl scnkey_matrix_loop bpl scnkey_matrix_loop
txa // XXX switch registers upwards!!!
tay
// Scanning complete // Scanning complete
cpy #$FF cpy #$FF