diff options
author | Tauwasser <Tauwasser@tauwasser.eu> | 2018-06-01 21:41:02 +0200 |
---|---|---|
committer | Tauwasser <Tauwasser@tauwasser.eu> | 2018-06-01 21:46:11 +0200 |
commit | 46435be6a1840eff9038c9e5a300f92006bff321 (patch) | |
tree | b25406f5d72d1c1408fc115cab722608ed37afbb | |
parent | c8e99019471f5f7b5e1824687043ac92bc7a424b (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>
-rw-r--r-- | constants.asm | 2 | ||||
-rw-r--r-- | constants/misc_constants.asm | 24 | ||||
-rw-r--r-- | home/joypad.asm | 230 | ||||
-rw-r--r-- | home/vblank.asm | 12 | ||||
-rw-r--r-- | hram.asm | 16 | ||||
-rw-r--r-- | shim.sym | 4 | ||||
-rw-r--r-- | wram.asm | 16 |
7 files changed, 289 insertions, 15 deletions
diff --git a/constants.asm b/constants.asm index d3d8b3f..5d58985 100644 --- a/constants.asm +++ b/constants.asm @@ -19,3 +19,5 @@ INCLUDE "constants/battle_constants.asm" INCLUDE "constants/palette_constants.asm" INCLUDE "constants/serial_constants.asm" + +INCLUDE "constants/misc_constants.asm"
\ No newline at end of file diff --git a/constants/misc_constants.asm b/constants/misc_constants.asm new file mode 100644 index 0000000..19deb8e --- /dev/null +++ b/constants/misc_constants.asm @@ -0,0 +1,24 @@ +; joypad + + const_def + const A_BUTTON_F + const B_BUTTON_F + const SELECT_F + const START_F + const D_RIGHT_F + const D_LEFT_F + const D_UP_F + const D_DOWN_F + +NO_INPUT EQU %00000000 +A_BUTTON EQU 1 << A_BUTTON_F +B_BUTTON EQU 1 << B_BUTTON_F +SELECT EQU 1 << SELECT_F +START EQU 1 << START_F +D_RIGHT EQU 1 << D_RIGHT_F +D_LEFT EQU 1 << D_LEFT_F +D_UP EQU 1 << D_UP_F +D_DOWN EQU 1 << D_DOWN_F + +BUTTONS EQU A_BUTTON | B_BUTTON | SELECT | START +D_PAD EQU D_RIGHT | D_LEFT | D_UP | D_DOWN
\ No newline at end of file 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 @@ -39,17 +39,29 @@ hJoypadSum:: db ; ffa0 hJoyDown:: db ; ffa2 hJoyState:: db ; ffa3 hJoySum:: db ; ffa4 - ds 1; TODO + +hJoyDebounceSrc:: db ; ffa5 +; hJoySum will be updated from +; 00 - hJoyDown +; <> - hJoyState +; See GetJoypadDebounced hJoypadState2:: db ; ffa6 ds 8 ; TODO +UNION + +hTextBoxCursorBlinkInterval:: ds 2 ; ffaf + +NEXTU hSpriteWidth:: ; ffaf hSpriteInterlaceCounter:: ; ffaf db hSpriteHeight:: ; ffb0 - db + db +ENDU + hSpriteOffset:: ; ffb1 db @@ -1,6 +1,7 @@ ; ROM0 +00:032b UpdateTimeOfDayPalettes +00:0436 RTC 00:051C Reset -00:0884 UpdateJoypad 00:0d1a LoadFontExtra 00:0d0a LoadFont 00:0E2A ClearTileMap @@ -12,7 +13,6 @@ 00:10B7 DoTextUntilTerminator 00:10C1 DoTextUntilTerminator.continue 00:10E2 Text_TX -00:120C TextCommands 00:1d49 LoadMenuHeader 00:1e58 OpenMenu 00:1F9E ClearWindowData @@ -121,7 +121,7 @@ wVBCopyFarSrcBank:: ds 1 ; cb76 SECTION "CC32", WRAM0[$CC32] ; Please merge when more is disassembled -wVBlankCounter: db ; cc32 +wVBlankJoyFrameCounter: db ; cc32 wVBlankOccurred: db ; cc33 @@ -180,7 +180,11 @@ SECTION "CD31", WRAM0[$CD31] wcd31:: ; cd31 db -SECTION "CD4F", WRAM0[$CD4F] +SECTION "CD4A", WRAM0[$CD4A] + +wTextDest:: ds 2; cd4a + + ds 3 ; TODO wPredefID:: ; cd4f db @@ -209,6 +213,14 @@ SECTION "CD7D", WRAM0[$CD7D] wItemQuantity:: ; cd7d db +SECTION "CDBD", WRAM0[$CDBD] + +wLinkMode:: db ; cdbd +; 00 - +; 01 - +; 02 - +; 03 - + SECTION "CE00", WRAM0[$CE00] wBattleMode:: ; ce00 |