summaryrefslogtreecommitdiff
path: root/home
diff options
context:
space:
mode:
authorTauwasser <Tauwasser@tauwasser.eu>2018-06-01 21:41:02 +0200
committerTauwasser <Tauwasser@tauwasser.eu>2018-06-01 21:46:11 +0200
commit46435be6a1840eff9038c9e5a300f92006bff321 (patch)
treeb25406f5d72d1c1408fc115cab722608ed37afbb /home
parentc8e99019471f5f7b5e1824687043ac92bc7a424b (diff)
home/joypad: disassemble more functions
- add misc_constants and add joypad constants. - rename one of the VBlank counters as it's exclusively used to time joypad functionality. Signed-off-by: Tauwasser <Tauwasser@tauwasser.eu>
Diffstat (limited to 'home')
-rw-r--r--home/joypad.asm230
-rw-r--r--home/vblank.asm12
2 files changed, 233 insertions, 9 deletions
diff --git a/home/joypad.asm b/home/joypad.asm
index 8f8e7e6..e0740f2 100644
--- a/home/joypad.asm
+++ b/home/joypad.asm
@@ -54,8 +54,232 @@ Joypad:: ; 7fe (0:7fe)
ld a, b
ldh [hJoypadState], a
ldh [hJoypadState2], a
- and $0f
- cp $0f
+ ; Soft-Reset by holding A+B+SELECT+START
+ and (A_BUTTON | B_BUTTON | SELECT | START)
+ cp (A_BUTTON | B_BUTTON | SELECT | START)
jp z, Reset
ret
-; 0x84a
+
+GetJoypad:: ; 84a (0:84a)
+; Update mirror joypad input from hJoypadState (real input)
+
+; hJoyReleased, hJoyDown and hJoyState are synchronized
+; copies of their hJoypad* counterparts.
+
+; bit 0 A
+; 1 B
+; 2 SELECT
+; 3 START
+; 4 RIGHT
+; 5 LEFT
+; 6 UP
+; 7 DOWN
+ push af
+ push hl
+ push de
+ ld hl, wJoypadFlags
+ set 6, [hl] ; mutex
+ ld hl, hJoypadDown
+ ld de, hJoyDown
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld a, [hl]
+ ld [de], a
+ ld hl, wJoypadFlags
+ res 6, [hl]
+ pop de
+ pop hl
+ pop af
+ ret
+
+JoyTitleScreenInput:: ; 869 (0:869)
+; Check if any of the following conditions
+; is met for c frames
+; - B, Select and Up keys are pressed in same frame
+; - A is pressed
+; - START is pressed
+;
+; Inputs: c - number of frames to check for
+; Return: carry set if condition met, else reset
+.loop
+ call DelayFrame
+ push bc
+ call GetJoypadDebounced
+ pop bc
+ ldh a, [hJoyState]
+ cp (D_UP | SELECT | B_BUTTON)
+ jr z, .done
+ ldh a, [hJoySum]
+ and (START | A_BUTTON)
+ jr nz, .done
+ dec c
+ jr nz, .loop
+ and a
+ ret
+.done
+ scf
+ ret
+
+GetJoypadDebounced:: ; 884 (0:884)
+; Update hJoySum joypad input from either hJoyDown or
+; hJoyState depending on hJoyDebounceSrc.
+; hJoyState is only updated every 5 frames and
+; the update is delayed by 15 frames after any button
+; press.
+ call GetJoypad
+ ldh a, [hJoyDebounceSrc]
+ and a
+ ldh a, [hJoyDown]
+ jr z, .joyDownSrc
+.joyStateSrc
+ ldh a, [hJoyState]
+.joyDownSrc
+ ldh [hJoySum], a
+ ldh a, [hJoyDown]
+ and a
+ jr z, .sampleAfterPress
+ ld a, $0f
+ ld [wVBlankJoyFrameCounter], a
+ ret
+.sampleAfterPress
+ ld a, [wVBlankJoyFrameCounter]
+ and a
+ jr z, .sampleRegular
+ xor a
+ ldh [hJoySum], a
+ ret
+.sampleRegular
+ ld a, $05
+ ld [wVBlankJoyFrameCounter], a
+ ret
+; 0x8ad
+
+TextboxWaitPressAorB_BlinkCursor: ; 8ad (0:8ad)
+; Show a blinking cursor in the lower right-hand
+; corner of a textbox and wait until A or B is
+; pressed.
+;
+; CAUTION: The cursor has to be shown when calling
+; this function or no cursor will be shown at all.
+; Waiting on button presses is unaffected by this.
+ ldh a, [hSpriteWidth] ; hTextBoxCursorBlinkInterval is shared with
+ push af ; hSpriteWidth and hSpriteHeight, so we need
+ ldh a, [hSpriteHeight] ; to back them up
+ push af
+ xor a
+ ldh [hTextBoxCursorBlinkInterval], a
+ ld a, $06
+ ldh [hTextBoxCursorBlinkInterval + 1], a ; initially, 0x600 iterations
+.loop
+ push hl
+ coord hl, (TEXTBOX_WIDTH - 2), (TEXTBOX_Y + TEXTBOX_HEIGHT - 1)
+ call TextboxBlinkCursor
+ pop hl
+ call GetJoypadDebounced
+ ldh a, [hJoySum]
+ and (A_BUTTON | B_BUTTON)
+ jr z, .loop
+ pop af
+ ldh [hSpriteHeight], a
+ pop af
+ ldh [hSpriteWidth], a
+ ret
+
+ButtonSound:: ; 8d2 (0:8d2)
+ ld a, [wLinkMode]
+ cp $03
+ jr z, .link
+ call WaitAorB_BlinkCursor
+ push de
+ ld de, $5
+ call PlaySFX
+ pop de
+ ret
+.link
+ ld c, $41
+ jp DelayFrames
+
+WaitAorB_BlinkCursor:: ; 8ea (0:8ea)
+.loop
+ call BlinkCursor
+ call GetJoypadDebounced
+ ldh a, [hJoySum]
+ and (A_BUTTON | B_BUTTON)
+ ret nz
+ call RTC
+ call UpdateTimeOfDayPalettes
+ ld a, $01
+ ldh [hBGMapMode], a
+ call DelayFrame
+ jr .loop
+
+BlinkCursor: ; 904 (0:904)
+; Show a blinking cursor in the lower right-hand
+; corner of the screen
+; Will toggle between cursor and blank every
+; 16 frames.
+ ldh a, [hVBlankCounter]
+ and $10
+ jr z, .cursor_off
+ ld a, "▼"
+ jr .save_cursor_state
+.cursor_off
+ ld a, " "
+.save_cursor_state
+ ldcoord_a (SCREEN_WIDTH - 2), (SCREEN_HEIGHT - 1)
+ ret
+
+TextboxBlinkCursor:: ; 914 (0:914)
+; Show a blinking cursor at the specified position
+; that toggles between down arrow and horizontal textbox
+; frame tile.
+; hl - address of cursor
+; hTextBoxCursorBlinkInterval - initial delay between toggling
+; subsequent delays will be 0x6FF
+; calls of this function
+; CAUTION: if the cursor is not shown initially, even initial
+; hTextBoxCursorBlinkInterval values will cause no cursor
+; to be shown at all.
+ ld a, [hl]
+ ld b, a
+ ld a, "▼"
+ cp b
+ jr nz, .showCursorCountdown
+.showTextboxFrameCountdown
+ ldh a, [hTextBoxCursorBlinkInterval]
+ dec a
+ ldh [hTextBoxCursorBlinkInterval], a
+ ret nz
+ ldh a, [hTextBoxCursorBlinkInterval + 1]
+ dec a
+ ldh [hTextBoxCursorBlinkInterval + 1], a
+ ret nz
+ ld a, "─"
+ ld [hl], a
+ ld a, $ff
+ ldh [hTextBoxCursorBlinkInterval], a
+ ld a, $06
+ ldh [hTextBoxCursorBlinkInterval + 1], a ; reset to 0x6FF iterations
+ ret
+.showCursorCountdown
+ ldh a, [hTextBoxCursorBlinkInterval]
+ and a
+ ret z
+ dec a
+ ldh [hTextBoxCursorBlinkInterval], a
+ ret nz
+ dec a
+ ldh [hTextBoxCursorBlinkInterval], a
+ ldh a, [hTextBoxCursorBlinkInterval + 1]
+ dec a
+ ldh [hTextBoxCursorBlinkInterval + 1], a
+ ret nz
+ ld a, $06
+ ldh [hTextBoxCursorBlinkInterval + 1], a ; reset to 0x6FF iterations
+ ld a, "▼"
+ ld [hl], a
+ ret
diff --git a/home/vblank.asm b/home/vblank.asm
index 05e9f7b..33bbd40 100644
--- a/home/vblank.asm
+++ b/home/vblank.asm
@@ -91,11 +91,11 @@ VBlank0:: ; 175 (0:175)
call hOAMDMA
xor a
ld [wVBlankOccurred], a
- ld a, [wVBlankCounter]
+ ld a, [wVBlankJoyFrameCounter]
and a
jr z, .skipDec
dec a
- ld [wVBlankCounter], a
+ ld [wVBlankJoyFrameCounter], a
.skipDec
call Joypad
xor a
@@ -212,11 +212,11 @@ VBlank2:: ; 241 (0:241)
call hOAMDMA
xor a
ld [wVBlankOccurred], a
- ld a, [wVBlankCounter]
+ ld a, [wVBlankJoyFrameCounter]
and a
jr z, .skipDec
dec a
- ld [wVBlankCounter], a
+ ld [wVBlankJoyFrameCounter], a
.skipDec
call UpdateSound
ld a, [wVBlankSavedROMBank]
@@ -276,11 +276,11 @@ VBlank3:: ; 2a0 (0:2a0)
call hOAMDMA
xor a
ld [wVBlankOccurred], a
- ld a, [wVBlankCounter]
+ ld a, [wVBlankJoyFrameCounter]
and a
jr z, .skipDec
dec a
- ld [wVBlankCounter], a
+ ld [wVBlankJoyFrameCounter], a
.skipDec
xor a
ldh [rIF], a