summaryrefslogtreecommitdiff
path: root/main.asm
diff options
context:
space:
mode:
authoryenatch <yenatch@gmail.com>2013-02-19 23:57:07 -0500
committeryenatch <yenatch@gmail.com>2013-02-22 20:02:03 -0500
commitda406973c565c24c089d137d056e03be8451242e (patch)
tree40b6a05c7fcdecb9ae7f91662bbe36024f14a9a3 /main.asm
parent9102b9a498c1f3073b89367945330b7de6baf016 (diff)
Split out joypad
Diffstat (limited to 'main.asm')
-rw-r--r--main.asm247
1 files changed, 3 insertions, 244 deletions
diff --git a/main.asm b/main.asm
index 8c4cdd88a..fd2a1965f 100644
--- a/main.asm
+++ b/main.asm
@@ -47,7 +47,7 @@ SECTION "serial",HOME[$58] ; serial interrupt
jp $06ef
SECTION "joypad",HOME[$60] ; joypad interrupt
- jp $092e
+ jp JoypadInt
SECTION "romheader",HOME[$100]
Start:
@@ -425,252 +425,11 @@ SetClock: ; 691
ret
; 6c4
-INCBIN "baserom.gbc",$6c4,$935 - $6c4
+INCBIN "baserom.gbc",$6c4,$92e - $6c4
-Joypad: ; 935
-; update joypad state
-; $ffa2: released
-; $ffa3: pressed
-; $ffa4: input
-; $ffa5: total pressed
-;
- ld a, [$cfbe]
- and $d0
- ret nz
-
-; pause game update?
- ld a, [$c2cd]
- and a
- ret nz
-
-; d-pad
- ld a, $20
- ld [$ff00], a
- ld a, [$ff00]
- ld a, [$ff00]
-; hi nybble
- cpl
- and $f
- swap a
- ld b, a
-
-; buttons
- ld a, $10
- ld [$ff00], a
-; wait to stabilize
- ld a, [$ff00]
- ld a, [$ff00]
- ld a, [$ff00]
- ld a, [$ff00]
- ld a, [$ff00]
- ld a, [$ff00]
-; lo nybble
- cpl
- and $f
- or b
- ld b, a
-
-; reset joypad
- ld a, $30
- ld [$ff00], a
-
-; get change in input
- ld a, [$ffa4] ; last frame's input
- ld e, a
- xor b ; current frame input
- ld d, a
-; released
- and e
- ld [$ffa2], a
-; pressed
- ld a, d
- and b
- ld [$ffa3], a
-
-; total pressed
- ld c, a
- ld a, [$ffa5]
- or c
- ld [$ffa5], a
-
-; original input
- ld a, b
- ld [$ffa4], a
-
-; A+B+SELECT+START
- and $f
- cp $f
- jp z, $0150 ; reset
-
- ret
-; 984
-
-
-GetJoypadPublic: ; 984
-; update mirror joypad input from $ffa4 (real input)
+INCLUDE "joypad.asm"
-; $ffa6: released
-; $ffa7: pressed
-; $ffa8: input
-
-; 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
-
-; automated input?
- ld a, [InputType]
- cp a, $ff ; INPUT_AUTO
- jr z, .auto
-
-; get input
- ld a, [$ffa4] ; real input
- ld b, a
- ld a, [$ffa8] ; last frame mirror
- ld e, a
-
-; released
- xor b
- ld d, a
- and e
- ld [$ffa6], a
-
-; pressed
- ld a, d
- and b
- ld [$ffa7], a
-
-; leftover from pasted code
- ld c, a
-
-;
- ld a, b
- ld [$ffa8], a ; frame input
-.quit
- pop bc
- pop de
- pop hl
- pop af
- ret
-
-.auto
-; use predetermined input feed (used in catch tutorial)
-; struct: [input][duration]
-
-; save bank
- ld a, [$ff9d]
- push af
-;
- ld a, [AutoInputBank]
- rst Bankswitch
-;
- ld hl, AutoInputAddress ; AutoInputAddress-9
- ld a, [hli]
- ld h, [hl]
- ld l, a
-
-; update when frame count hits 0
- ld a, [AutoInputLength]
- and a
- jr z, .updateauto
-
-; until then, do nothing
- dec a
- ld [AutoInputLength], a
-; restore bank
- pop af
- rst Bankswitch
-; we're done
- jr .quit
-
-.updateauto
-; get input
- ld a, [hli]
-; stop?
- cp a, $ff
- jr z, .stopinput
- ld b, a
-
-; duration
- ld a, [hli]
- ld [AutoInputLength], a
-; duration $ff = end at input
- cp a, $ff
- jr nz, .next
-
-; no input
- dec hl
- dec hl
- ld b, $00 ; no input
- jr .finishauto
-
-.next
-; output recorded
- ld a, l
- ld [AutoInputAddress], a
- ld a, h
- ld [AutoInputAddress+1], a
- jr .finishauto
-
-.stopinput
- call StopAutoInput
- ld b, $00 ; no input
-
-.finishauto
-; restore bank
- pop af
- rst Bankswitch
-; update mirrors
- ld a, b
- ld [$ffa7], a ; pressed
- ld [$ffa8], a ; input
- jr .quit
-; 9ee
-
-StartAutoInput: ; 9ee
-; start auto input stream at a:hl
-; bank
- ld [AutoInputBank], a
-; address
- ld a, l
- ld [AutoInputAddress], a
- ld a, h
- ld [AutoInputAddress+1], a
-; don't wait to update
- xor a
- ld [AutoInputLength], a
-; clear input mirrors
- xor a
- ld [$ffa7], a ; pressed
- ld [$ffa6], a ; released
- ld [$ffa8], a ; input
-; start reading input stream instead of player input
- ld a, $ff ; INPUT_AUTO
- ld [InputType], a
- ret
-; a0a
-
-StopAutoInput: ; a0a
-; clear autoinput ram
- xor a
- ld [AutoInputBank], a
- ld [AutoInputAddress], a
- ld [AutoInputAddress+1], a
- ld [AutoInputLength], a
-; normal input
- ld [InputType], a
- ret
-; a1b
INCBIN "baserom.gbc",$a1b,$b40 - $a1b