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