summaryrefslogtreecommitdiff
path: root/home/joypad.asm
diff options
context:
space:
mode:
Diffstat (limited to 'home/joypad.asm')
-rw-r--r--home/joypad.asm425
1 files changed, 131 insertions, 294 deletions
diff --git a/home/joypad.asm b/home/joypad.asm
index 390166be..58e00eac 100644
--- a/home/joypad.asm
+++ b/home/joypad.asm
@@ -1,457 +1,295 @@
-JoypadInt:: ; 92e
-; Replaced by Joypad, called from VBlank instead of the useless
-; joypad interrupt.
-
-; This is a placeholder in case the interrupt is somehow enabled.
+JoypadInt:: ; 8df (0:08df)
reti
-; 92f
-
-ClearJoypad:: ; 92f
xor a
-; Pressed this frame (delta)
ld [hJoyPressed], a
-; Currently pressed
ld [hJoyDown], a
ret
-; 935
-
-Joypad:: ; 935
-; Read the joypad register and translate it to something more
-; workable for use in-game. There are 8 buttons, so we can use
-; one byte to contain all player input.
-
-; Updates:
-
-; hJoypadReleased: released this frame (delta)
-; hJoypadPressed: pressed this frame (delta)
-; hJoypadDown: currently pressed
-; hJoypadSum: pressed so far
-
-; Any of these three bits can be used to disable input.
- ld a, [wcfbe]
- and %11010000
+Joypad:: ; 8e6 (0:08e6)
+ ld a, [wd8ba]
+ and $d0
ret nz
-
-; If we're saving, input is disabled.
- ld a, [wc2cd]
+ ld a, [wc1cc]
and a
ret nz
-
-; We can only get four inputs at a time.
-; We take d-pad first for no particular reason.
- ld a, R_DPAD
+ ld a, $20
ld [rJOYP], a
-; Read twice to give the request time to take.
-rept 2
ld a, [rJOYP]
-endr
-
-; The Joypad register output is in the lo nybble (inversed).
-; We make the hi nybble of our new container d-pad input.
+ ld a, [rJOYP]
cpl
and $f
swap a
-
-; We'll keep this in b for now.
ld b, a
-
-; Buttons make 8 total inputs (A, B, Select, Start).
-; We can fit this into one byte.
- ld a, R_BUTTONS
+ ld a, $10
ld [rJOYP], a
-; Wait for input to stabilize.
-rept 6
ld a, [rJOYP]
-endr
-; Buttons take the lo nybble.
+ ld a, [rJOYP]
+ ld a, [rJOYP]
+ ld a, [rJOYP]
+ ld a, [rJOYP]
+ ld a, [rJOYP]
cpl
and $f
or b
ld b, a
-
-; Reset the joypad register since we're done with it.
ld a, $30
ld [rJOYP], a
-
-; To get the delta we xor the last frame's input with the new one.
- ld a, [hJoypadDown] ; last frame
+ ld a, [hJoypadDown]
ld e, a
xor b
ld d, a
-; Released this frame:
and e
ld [hJoypadReleased], a
-; Pressed this frame:
ld a, d
and b
ld [hJoypadPressed], a
-
-; Add any new presses to the list of collective presses:
ld c, a
ld a, [hJoypadSum]
or c
ld [hJoypadSum], a
-
-; Currently pressed:
ld a, b
ld [hJoypadDown], a
-
-; Now that we have the input, we can do stuff with it.
-
-; For example, soft reset:
- and A_BUTTON | B_BUTTON | SELECT | START
- cp A_BUTTON | B_BUTTON | SELECT | START
+ and $f
+ cp $f
jp z, Reset
-
ret
-; 984
-
-
-GetJoypad:: ; 984
-; Update mirror joypad input from hJoypadDown (real input)
-
-; hJoyReleased: released this frame (delta)
-; hJoyPressed: pressed this frame (delta)
-; hJoyDown: currently pressed
-
-; bit 0 A
-; 1 B
-; 2 SELECT
-; 3 START
-; 4 RIGHT
-; 5 LEFT
-; 6 UP
-; 7 DOWN
-
+Function935:: ; 935 (0:0935)
push af
push hl
push de
push bc
-
-; The player input can be automated using an input stream.
-; See more below.
- ld a, [InputType]
- cp a, AUTO_INPUT
- jr z, .auto
-
-; To get deltas, take this and last frame's input.
- ld a, [hJoypadDown] ; real input
+ ld a, [wc1c6]
+ cp $ff
+ jr z, .asm_958
+ ld a, [hJoypadDown]
ld b, a
- ld a, [hJoyDown] ; last frame mirror
+ ld a, [hJoyDown]
ld e, a
-
-; Released this frame:
xor b
ld d, a
and e
ld [hJoyReleased], a
-
-; Pressed this frame:
ld a, d
and b
ld [hJoyPressed], a
-
-; It looks like the collective presses got commented out here.
ld c, a
-
-; Currently pressed:
ld a, b
- ld [hJoyDown], a ; frame input
-
-.quit
+ ld [hJoyDown], a
+.asm_953
pop bc
pop de
pop hl
pop af
- ret
-
-.auto
-; Use a predetermined input stream (used in the catching tutorial).
-
-; Stream format: [input][duration]
-; A value of $ff will immediately end the stream.
-
-; Read from the input stream.
+ ret
+.asm_958
ld a, [hROMBank]
push af
- ld a, [AutoInputBank]
+ ld a, [wc1c9]
rst Bankswitch
-
- ld hl, AutoInputAddress
+ ld hl, wc1c7
ld a, [hli]
ld h, [hl]
ld l, a
-
-; We only update when the input duration has expired.
- ld a, [AutoInputLength]
+ ld a, [wc1ca]
and a
- jr z, .updateauto
-
-; Until then, don't change anything.
+ jr z, .asm_973
dec a
- ld [AutoInputLength], a
+ ld [wc1ca], a
pop af
rst Bankswitch
- jr .quit
-
-
-.updateauto
-; An input of $ff will end the stream.
+ jr .asm_953
+.asm_973
ld a, [hli]
- cp a, -1
- jr z, .stopauto
+ cp $ff
+ jr z, .asm_991
ld b, a
-
-; A duration of $ff will end the stream indefinitely.
ld a, [hli]
- ld [AutoInputLength], a
- cp a, -1
- jr nz, .next
-
-; The current input is overwritten.
-rept 2
+ ld [wc1ca], a
+ cp $ff
+ jr nz, .asm_987
+ dec hl
dec hl
-endr
- ld b, NO_INPUT
- jr .finishauto
-
-.next
-; On to the next input...
+ ld b, $0
+ jr .asm_996
+.asm_987
ld a, l
- ld [AutoInputAddress], a
+ ld [wc1c7], a
ld a, h
- ld [AutoInputAddress+1], a
- jr .finishauto
-
-.stopauto
- call StopAutoInput
- ld b, NO_INPUT
-
-.finishauto
+ ld [wc1c8], a
+ jr .asm_996
+.asm_991
+ call Function9bb
+ ld b, $0
+.asm_996
pop af
rst Bankswitch
ld a, b
- ld [hJoyPressed], a ; pressed
- ld [hJoyDown], a ; input
- jr .quit
-; 9ee
-
-
-StartAutoInput:: ; 9ee
-; Start reading automated input stream at a:hl.
-
- ld [AutoInputBank], a
+ ld [hJoyPressed], a
+ ld [hJoyDown], a
+ jr .asm_953
+ ld [wc1c9], a
ld a, l
- ld [AutoInputAddress], a
+ ld [wc1c7], a
ld a, h
- ld [AutoInputAddress+1], a
-; Start reading the stream immediately.
+ ld [wc1c8], a
xor a
- ld [AutoInputLength], a
-; Reset input mirrors.
+ ld [wc1ca], a
xor a
- ld [hJoyPressed], a ; pressed this frame
- ld [hJoyReleased], a ; released this frame
- ld [hJoyDown], a ; currently pressed
-
- ld a, AUTO_INPUT
- ld [InputType], a
+ ld [hJoyPressed], a
+ ld [hJoyReleased], a
+ ld [hJoyDown], a
+ ld a, $ff
+ ld [wc1c6], a
ret
-; a0a
-
-
-StopAutoInput:: ; a0a
-; Clear variables related to automated input.
+Function9bb:: ; 9bb (0:09bb)
xor a
- ld [AutoInputBank], a
- ld [AutoInputAddress], a
- ld [AutoInputAddress+1], a
- ld [AutoInputLength], a
-; Back to normal input.
- ld [InputType], a
+ ld [wc1c9], a
+ ld [wc1c7], a
+ ld [wc1c8], a
+ ld [wc1ca], a
+ ld [wc1c6], a
ret
-; a1b
-
-
-JoyTitleScreenInput:: ; a1b
-.loop
-
+.asm_9cc
call DelayFrame
-
push bc
- call JoyTextDelay
+ call Functiona08
pop bc
-
ld a, [hJoyDown]
- cp D_UP | SELECT | B_BUTTON
- jr z, .keycombo
-
+ cp $46
+ jr z, .asm_9e5
ld a, [hJoyLast]
- and START | A_BUTTON
- jr nz, .keycombo
-
+ and $9
+ jr nz, .asm_9e5
dec c
- jr nz, .loop
-
+ jr nz, .asm_9cc
and a
ret
-
-.keycombo
+.asm_9e5
scf
ret
-; a36
-
-
-JoyWaitAorB:: ; a36
-.loop
+.asm_9e7
call DelayFrame
- call GetJoypad
+ call Function935
ld a, [hJoyPressed]
- and A_BUTTON | B_BUTTON
+ and $3
ret nz
- call RTC
- jr .loop
-; a46
-
-WaitButton:: ; a46
+ call Function343
+ jr .asm_9e7
ld a, [hOAMUpdate]
push af
- ld a, 1
+ ld a, $1
ld [hOAMUpdate], a
- call WaitBGMap
- call JoyWaitAorB
+ call Function344c
+ call .asm_9e7
pop af
ld [hOAMUpdate], a
ret
-; a57
-
-JoyTextDelay:: ; a57
- call GetJoypad
+Functiona08:: ; a08 (0:0a08)
+ call Function935
ld a, [hInMenu]
and a
ld a, [hJoyPressed]
- jr z, .ok
+ jr z, .asm_a14
ld a, [hJoyDown]
-.ok
+.asm_a14
ld [hJoyLast], a
ld a, [hJoyPressed]
and a
- jr z, .checkframedelay
- ld a, 15
- ld [TextDelayFrames], a
+ jr z, .asm_a21
+ ld a, $f
+ ld [wTextDelayFrames], a
ret
-
-.checkframedelay
- ld a, [TextDelayFrames]
+.asm_a21
+ ld a, [wTextDelayFrames]
and a
- jr z, .restartframedelay
+ jr z, .asm_a2b
xor a
ld [hJoyLast], a
ret
-
-.restartframedelay
- ld a, 5
- ld [TextDelayFrames], a
+.asm_a2b
+ ld a, $5
+ ld [wTextDelayFrames], a
ret
-; a80
-
-WaitPressAorB_BlinkCursor:: ; a80
ld a, [hMapObjectIndexBuffer]
push af
ld a, [hObjectStructIndexBuffer]
push af
xor a
ld [hMapObjectIndexBuffer], a
- ld a, 6
+ ld a, $6
ld [hObjectStructIndexBuffer], a
-
-.loop
+.asm_a3e
push hl
hlcoord 18, 17
- call BlinkCursor
+ call Functionab6
pop hl
-
- call JoyTextDelay
+ call Functiona08
ld a, [hJoyLast]
- and A_BUTTON | B_BUTTON
- jr z, .loop
-
+ and $3
+ jr z, .asm_a3e
pop af
ld [hObjectStructIndexBuffer], a
pop af
ld [hMapObjectIndexBuffer], a
ret
-; aa5
-
-SimpleWaitPressAorB:: ; aa5
-.loop
- call JoyTextDelay
+.asm_a56
+ call Functiona08
ld a, [hJoyLast]
- and A_BUTTON | B_BUTTON
- jr z, .loop
+ and $3
+ jr z, .asm_a56
ret
-; aaf
-
-ButtonSound:: ; aaf
ld a, [wLinkMode]
and a
- jr nz, .link
- call .wait_input
+ jr nz, .asm_a72
+ call Functiona77
push de
- ld de, SFX_READ_TEXT_2
- call PlaySFX
+ ld de, $8
+ call Function3e24
pop de
ret
-
-.link
- ld c, 65
+.asm_a72
+ ld c, $41
jp DelayFrames
-; ac6
-
-.wait_input: ; ac6
+Functiona77:: ; a77 (0:0a77)
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
- ld a, [InputType]
+ ld a, [wc1c6]
or a
- jr z, .input_wait_loop
- callba _DudeAutoInput_A
-
-.input_wait_loop
- call .blink_cursor
- call JoyTextDelay
+ jr z, .asm_a8a
+ ld a, $70
+ ld hl, $4de9
+ rst FarCall
+.asm_a8a
+ call Functionaa6
+ call Functiona08
ld a, [hJoyPressed]
- and A_BUTTON | B_BUTTON
- jr nz, .received_input
- call RTC
+ and $3
+ jr nz, .asm_aa2
+ call Function343
ld a, $1
ld [hBGMapMode], a
call DelayFrame
- jr .input_wait_loop
-
-.received_input
+ jr .asm_a8a
+.asm_aa2
pop af
ld [hOAMUpdate], a
ret
-; af5
-.blink_cursor: ; af5
+Functionaa6:: ; aa6 (0:0aa6)
ld a, [hVBlankCounter]
- and %00010000 ; bit 4, a
+ and $10
jr z, .cursor_off
ld a, "▼"
jr .load_cursor_state
.cursor_off
- ld a, [TileMap + 17 + 17 * SCREEN_WIDTH]
-
+ ld a, "─"
.load_cursor_state
- ld [TileMap + 18 + 17 * SCREEN_WIDTH], a
+ Coorda 18, 17
ret
-; b06
-BlinkCursor:: ; b06
+Functionab6:: ; ab6 (0:0ab6)
push bc
ld a, [hl]
ld b, a
@@ -493,4 +331,3 @@ BlinkCursor:: ; b06
ld a, "▼"
ld [hl], a
ret
-; b40