2013-02-19 20:57:07 -08:00
|
|
|
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.
|
|
|
|
reti
|
|
|
|
; 92f
|
|
|
|
|
|
|
|
ClearJoypadPublic: ; 92f
|
|
|
|
xor a
|
|
|
|
; Pressed this frame (delta)
|
2013-03-20 19:55:09 -07:00
|
|
|
ld [hJoyPressed], a
|
2013-02-19 20:57:07 -08:00
|
|
|
; Currently pressed
|
2013-03-20 19:55:09 -07:00
|
|
|
ld [hJoyDown], a
|
2013-02-19 20:57:07 -08:00
|
|
|
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:
|
|
|
|
|
2013-03-20 19:55:09 -07:00
|
|
|
; hJoypadReleased: released this frame (delta)
|
|
|
|
; hJoypadPressed: pressed this frame (delta)
|
|
|
|
; hJoypadDown: currently pressed
|
|
|
|
; hJoypadSum: pressed so far
|
2013-02-19 20:57:07 -08:00
|
|
|
|
|
|
|
; Any of these three bits can be used to disable input.
|
|
|
|
ld a, [$cfbe]
|
|
|
|
and %11010000
|
|
|
|
ret nz
|
|
|
|
|
|
|
|
; If we're saving, input is disabled.
|
|
|
|
ld a, [$c2cd]
|
|
|
|
and a
|
|
|
|
ret nz
|
|
|
|
|
|
|
|
; We can only get four inputs at a time.
|
|
|
|
; We take d-pad first for no particular reason.
|
|
|
|
ld a, D_PAD
|
2013-02-19 23:46:40 -08:00
|
|
|
ld [rJOYP], a
|
2013-02-19 20:57:07 -08:00
|
|
|
; Read twice to give the request time to take.
|
2013-02-19 23:46:40 -08:00
|
|
|
ld a, [rJOYP]
|
|
|
|
ld a, [rJOYP]
|
2013-02-19 20:57:07 -08:00
|
|
|
|
|
|
|
; The Joypad register output is in the lo nybble (inversed).
|
|
|
|
; We make the hi nybble of our new container d-pad input.
|
|
|
|
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, BUTTONS
|
2013-02-19 23:46:40 -08:00
|
|
|
ld [rJOYP], a
|
2013-02-19 20:57:07 -08:00
|
|
|
; Wait for input to stabilize.
|
2013-02-19 23:46:40 -08:00
|
|
|
ld a, [rJOYP]
|
|
|
|
ld a, [rJOYP]
|
|
|
|
ld a, [rJOYP]
|
|
|
|
ld a, [rJOYP]
|
|
|
|
ld a, [rJOYP]
|
|
|
|
ld a, [rJOYP]
|
2013-02-19 20:57:07 -08:00
|
|
|
; Buttons take the lo nybble.
|
|
|
|
cpl
|
|
|
|
and $f
|
|
|
|
or b
|
|
|
|
ld b, a
|
|
|
|
|
|
|
|
; Reset the joypad register since we're done with it.
|
|
|
|
ld a, $30
|
2013-02-19 23:46:40 -08:00
|
|
|
ld [rJOYP], a
|
2013-02-19 20:57:07 -08:00
|
|
|
|
|
|
|
; To get the delta we xor the last frame's input with the new one.
|
2013-03-20 19:55:09 -07:00
|
|
|
ld a, [hJoypadDown] ; last frame
|
2013-02-19 20:57:07 -08:00
|
|
|
ld e, a
|
|
|
|
xor b
|
|
|
|
ld d, a
|
|
|
|
; Released this frame:
|
|
|
|
and e
|
2013-03-20 19:55:09 -07:00
|
|
|
ld [hJoypadReleased], a
|
2013-02-19 20:57:07 -08:00
|
|
|
; Pressed this frame:
|
|
|
|
ld a, d
|
|
|
|
and b
|
2013-03-20 19:55:09 -07:00
|
|
|
ld [hJoypadPressed], a
|
2013-02-19 20:57:07 -08:00
|
|
|
|
|
|
|
; Add any new presses to the list of collective presses:
|
|
|
|
ld c, a
|
2013-03-20 19:55:09 -07:00
|
|
|
ld a, [hJoypadSum]
|
2013-02-19 20:57:07 -08:00
|
|
|
or c
|
2013-03-20 19:55:09 -07:00
|
|
|
ld [hJoypadSum], a
|
2013-02-19 20:57:07 -08:00
|
|
|
|
|
|
|
; Currently pressed:
|
|
|
|
ld a, b
|
2013-03-20 19:55:09 -07:00
|
|
|
ld [hJoypadDown], a
|
2013-02-19 20:57:07 -08:00
|
|
|
|
|
|
|
; Now that we have the input, we can do stuff with it.
|
|
|
|
|
|
|
|
; For example, soft reset:
|
|
|
|
and BUTTON_A | BUTTON_B | SELECT | START
|
|
|
|
cp BUTTON_A | BUTTON_B | SELECT | START
|
2013-07-26 20:49:33 -07:00
|
|
|
jp z, Reset
|
2013-02-19 20:57:07 -08:00
|
|
|
|
|
|
|
ret
|
|
|
|
; 984
|
|
|
|
|
|
|
|
|
|
|
|
GetJoypadPublic: ; 984
|
2013-03-20 19:55:09 -07:00
|
|
|
; Update mirror joypad input from hJoypadDown (real input)
|
2013-02-19 20:57:07 -08:00
|
|
|
|
2013-03-20 19:55:09 -07:00
|
|
|
; hJoyReleased: released this frame (delta)
|
|
|
|
; hJoyPressed: pressed this frame (delta)
|
|
|
|
; hJoyDown: currently pressed
|
2013-02-19 20:57:07 -08:00
|
|
|
|
|
|
|
; bit 0 A
|
|
|
|
; 1 B
|
|
|
|
; 2 SELECT
|
|
|
|
; 3 START
|
|
|
|
; 4 RIGHT
|
|
|
|
; 5 LEFT
|
|
|
|
; 6 UP
|
|
|
|
; 7 DOWN
|
|
|
|
|
|
|
|
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.
|
2013-03-20 19:55:09 -07:00
|
|
|
ld a, [hJoypadDown] ; real input
|
2013-02-19 20:57:07 -08:00
|
|
|
ld b, a
|
2013-03-20 19:55:09 -07:00
|
|
|
ld a, [hJoyDown] ; last frame mirror
|
2013-02-19 20:57:07 -08:00
|
|
|
ld e, a
|
|
|
|
|
|
|
|
; Released this frame:
|
|
|
|
xor b
|
|
|
|
ld d, a
|
|
|
|
and e
|
2013-03-20 19:55:09 -07:00
|
|
|
ld [hJoyReleased], a
|
2013-02-19 20:57:07 -08:00
|
|
|
|
|
|
|
; Pressed this frame:
|
|
|
|
ld a, d
|
|
|
|
and b
|
2013-03-20 19:55:09 -07:00
|
|
|
ld [hJoyPressed], a
|
2013-02-19 20:57:07 -08:00
|
|
|
|
|
|
|
; It looks like the collective presses got commented out here.
|
|
|
|
ld c, a
|
|
|
|
|
|
|
|
; Currently pressed:
|
|
|
|
ld a, b
|
2013-03-20 19:55:09 -07:00
|
|
|
ld [hJoyDown], a ; frame input
|
2013-02-19 20:57:07 -08:00
|
|
|
|
|
|
|
.quit
|
|
|
|
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.
|
2013-03-20 19:55:09 -07:00
|
|
|
ld a, [hROMBank]
|
2013-02-19 20:57:07 -08:00
|
|
|
push af
|
|
|
|
ld a, [AutoInputBank]
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ld hl, AutoInputAddress
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
|
|
|
|
; We only update when the input duration has expired.
|
|
|
|
ld a, [AutoInputLength]
|
|
|
|
and a
|
|
|
|
jr z, .updateauto
|
|
|
|
|
|
|
|
; Until then, don't change anything.
|
|
|
|
dec a
|
|
|
|
ld [AutoInputLength], a
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
jr .quit
|
|
|
|
|
|
|
|
|
|
|
|
.updateauto
|
|
|
|
; An input of $ff will end the stream.
|
|
|
|
ld a, [hli]
|
|
|
|
cp a, $ff
|
|
|
|
jr z, .stopauto
|
|
|
|
ld b, a
|
|
|
|
|
|
|
|
; A duration of $ff will end the stream indefinitely.
|
|
|
|
ld a, [hli]
|
|
|
|
ld [AutoInputLength], a
|
|
|
|
cp a, $ff
|
|
|
|
jr nz, .next
|
|
|
|
|
|
|
|
; The current input is overwritten.
|
|
|
|
dec hl
|
|
|
|
dec hl
|
|
|
|
ld b, NO_INPUT
|
|
|
|
jr .finishauto
|
|
|
|
|
|
|
|
.next
|
|
|
|
; On to the next input...
|
|
|
|
ld a, l
|
|
|
|
ld [AutoInputAddress], a
|
|
|
|
ld a, h
|
|
|
|
ld [AutoInputAddress+1], a
|
|
|
|
jr .finishauto
|
|
|
|
|
|
|
|
.stopauto
|
|
|
|
call StopAutoInput
|
|
|
|
ld b, NO_INPUT
|
|
|
|
|
|
|
|
.finishauto
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
ld a, b
|
2013-03-20 19:55:09 -07:00
|
|
|
ld [hJoyPressed], a ; pressed
|
|
|
|
ld [hJoyDown], a ; input
|
2013-02-19 20:57:07 -08:00
|
|
|
jr .quit
|
|
|
|
; 9ee
|
|
|
|
|
|
|
|
|
|
|
|
StartAutoInput: ; 9ee
|
|
|
|
; Start reading automated input stream at a:hl.
|
|
|
|
|
|
|
|
ld [AutoInputBank], a
|
|
|
|
ld a, l
|
|
|
|
ld [AutoInputAddress], a
|
|
|
|
ld a, h
|
|
|
|
ld [AutoInputAddress+1], a
|
|
|
|
; Start reading the stream immediately.
|
|
|
|
xor a
|
|
|
|
ld [AutoInputLength], a
|
|
|
|
; Reset input mirrors.
|
|
|
|
xor a
|
2013-03-20 19:55:09 -07:00
|
|
|
ld [hJoyPressed], a ; pressed this frame
|
|
|
|
ld [hJoyReleased], a ; released this frame
|
|
|
|
ld [hJoyDown], a ; currently pressed
|
2013-02-19 20:57:07 -08:00
|
|
|
|
|
|
|
ld a, AUTO_INPUT
|
|
|
|
ld [InputType], a
|
|
|
|
ret
|
|
|
|
; a0a
|
|
|
|
|
|
|
|
|
|
|
|
StopAutoInput: ; a0a
|
|
|
|
; Clear variables related to automated input.
|
|
|
|
xor a
|
|
|
|
ld [AutoInputBank], a
|
|
|
|
ld [AutoInputAddress], a
|
|
|
|
ld [AutoInputAddress+1], a
|
|
|
|
ld [AutoInputLength], a
|
|
|
|
; Back to normal input.
|
|
|
|
ld [InputType], a
|
|
|
|
ret
|
|
|
|
; a1b
|
|
|
|
|