Reduce repeated code in key selection routine

This commit is contained in:
Neil McPhail 2024-10-21 22:18:21 +00:00
parent 7e02520c24
commit 223d284939

View File

@ -26,49 +26,30 @@ read_keyboard:
jr read_keyboard jr read_keyboard
key_1: key_1:
ld e, 0 ld de, 0x0000
call highlight_key jr invoke
ld a, (counter)
call play
ld e, 0
jr keyoff
key_2: key_2:
ld e, 3 ld de, 0x0103
call highlight_key jr invoke
ld a, (counter)
inc a
call play
ld e, 3
jr keyoff
key_3: key_3:
ld e, 6 ld de, 0x0206
call highlight_key jr invoke
ld a, (counter)
inc a
inc a
call play
ld e, 6
jr keyoff
key_4: key_4:
ld e, 9 ld de, 0x0309
call highlight_key jr invoke
ld a, (counter)
add a, 3
call play
ld e, 9
jr keyoff
key_5: key_5:
ld e, 12 ld de, 0x040C
invoke:
push de
call highlight_key call highlight_key
ld a, (counter) ld a, (counter)
add a, 4 add a, d
call play call play
ld e, 12 pop de
keyoff:
call highlight_key call highlight_key
inc_counter: inc_counter:
@ -80,21 +61,22 @@ inc_counter:
highlight_key: highlight_key:
ld hl, xylo ld hl, xylo
push de
ld d, 0 ld d, 0
add hl, de add hl, de
ld e, 30
ld b, 15 ld b, 15
highlight_row:
ld c, 3
highlight_block: highlight_block:
ld a, (hl) ld a, (hl)
xor %01000000 xor %01000000
ld (hl), a ld (hl), a
inc hl inc hl
dec c ld (hl), a
jr nz, highlight_block inc hl
ld e, 29 ld (hl), a
add hl, de add hl, de
djnz highlight_row djnz highlight_block
pop de
ret ret
INCLUDE "sample.asm" INCLUDE "sample.asm"