From ea60cb912fdf1e7980fbe0dd2d23f982e5c423f2 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sun, 13 Oct 2019 21:25:24 +0200 Subject: [PATCH] small code optimization --- c64/kernal/keyboard/scnkey.s | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/c64/kernal/keyboard/scnkey.s b/c64/kernal/keyboard/scnkey.s index 1cdd63ea..89e7dea9 100644 --- a/c64/kernal/keyboard/scnkey.s +++ b/c64/kernal/keyboard/scnkey.s @@ -81,38 +81,35 @@ scnkey_bucky_loop: // Scan the keyboard matrix - ldy #$07 // XXX adapt for C128 and C65 keyboards - ldx #$FF // offset in key matrix table, $FF for not found yet + ldx #$07 // XXX adapt for C128 and C65 keyboards + ldy #$FF // offset in key matrix table, $FF for not found yet scnkey_matrix_loop: - lda kb_matrix_row_keys, y + lda kb_matrix_row_keys, x 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 cmp #$FF 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 // 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: - cmp kb_matrix_row_keys, x + cmp kb_matrix_row_keys, y bne !+ // not this particular key - txa // now .A contains key offset within a row + tya // now .A contains key offset within a row sec - adc kb_matrix_row_offsets, y // now .A contains key offset from the matrix start - tax + adc kb_matrix_row_offsets, x // now .A contains key offset from the matrix start + tay jmp scnkey_matrix_loop_next !: - dex + dey bpl scnkey_matrix_loop_inner bmi scnkey_no_keys // branch always, multiple keys must have been pressed scnkey_matrix_loop_next: - dey + dex bpl scnkey_matrix_loop - txa // XXX switch registers upwards!!! - tay - // Scanning complete cpy #$FF