repeat directions when keeping buttons pressed

This commit is contained in:
2019-01-06 22:08:27 +01:00
parent 103965a135
commit 83bf451af0
3 changed files with 61 additions and 12 deletions

View File

@@ -2,10 +2,14 @@ INCLUDE "hardware.inc"
INCLUDE "utils.inc" INCLUDE "utils.inc"
SPRITE_ANIM_DELAY EQU 12 SPRITE_ANIM_DELAY EQU 12
REPEAT_START_DELAY EQU 24
REPEAT_DELAY EQU 3
Section "Edit memory", HRAM Section "Edit memory", HRAM
SelectX: ds 1 SelectX: ds 1
SelectY: ds 1 SelectY: ds 1
Down: ds 1
RepeatDelay: ds 1
SpriteAnimation: ds 1 SpriteAnimation: ds 1
SpriteDelay: ds 1 SpriteDelay: ds 1
@@ -16,6 +20,10 @@ InitEdit:
ldh [SelectX], a ldh [SelectX], a
ld a, 18 ld a, 18
ldh [SelectY], a ldh [SelectY], a
xor a
ldh [Down], a
ld a, REPEAT_START_DELAY
ldh [RepeatDelay], a
ret ret
EXPORT EditOldBuffer EXPORT EditOldBuffer
@@ -89,8 +97,47 @@ EditOldBuffer:
and a, JOYPAD_START and a, JOYPAD_START
jr nz, .exit jr nz, .exit
; check left direction ; reset input
xor a
ldh [Down], a
; if a direction is pressed, handle repeat
ldh a, [JoypadPressed]
and JOYPAD_DIRECTIONS
ld b, a
jr z, .addDown
; check if time to repeat
ldh a, [RepeatDelay]
dec a
ldh [RepeatDelay], a
jr nz, .addDown
; reset repeat delay and add pressed to inputs
ld a, REPEAT_DELAY
ldh [RepeatDelay], a
ld a, b
ldh [Down], a
; add just down keys
.addDown
ldh a, [JoypadDown] ldh a, [JoypadDown]
and JOYPAD_DIRECTIONS
ld b, a
ldh a, [Down]
or a, b
ldh [Down], a
ldh a, [JoypadPressed]
or a
jr nz, .do
ld a, REPEAT_START_DELAY
ldh [RepeatDelay], a
.do
; check left direction
ldh a, [Down]
and a, JOYPAD_LEFT and a, JOYPAD_LEFT
jr z, .endLeft jr z, .endLeft
ldh a, [SelectX] ldh a, [SelectX]
@@ -101,7 +148,7 @@ EditOldBuffer:
.endLeft .endLeft
; check up direction ; check up direction
ldh a, [JoypadDown] ldh a, [Down]
and a, JOYPAD_UP and a, JOYPAD_UP
jr z, .endUp jr z, .endUp
ldh a, [SelectY] ldh a, [SelectY]
@@ -112,7 +159,7 @@ EditOldBuffer:
.endUp .endUp
; check right direction ; check right direction
ldh a, [JoypadDown] ldh a, [Down]
and a, JOYPAD_RIGHT and a, JOYPAD_RIGHT
jr z, .endRight jr z, .endRight
ldh a, [SelectX] ldh a, [SelectX]
@@ -123,7 +170,7 @@ EditOldBuffer:
.endRight .endRight
; check down direction ; check down direction
ldh a, [JoypadDown] ldh a, [Down]
and a, JOYPAD_DOWN and a, JOYPAD_DOWN
jr z, .endDown jr z, .endDown
ldh a, [SelectY] ldh a, [SelectY]
@@ -134,6 +181,7 @@ EditOldBuffer:
.endDown .endDown
; wait v-blank ; wait v-blank
.skip
halt halt
jp .loop jp .loop

View File

@@ -8,6 +8,7 @@ JOYPAD_RIGHT EQU $10
JOYPAD_LEFT EQU $20 JOYPAD_LEFT EQU $20
JOYPAD_UP EQU $40 JOYPAD_UP EQU $40
JOYPAD_DOWN EQU $80 JOYPAD_DOWN EQU $80
JOYPAD_DIRECTIONS EQU $F0
; destroys A ; destroys A
ClearAndEnableInterrupts: MACRO ClearAndEnableInterrupts: MACRO

BIN
rom.gb

Binary file not shown.