summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPikalaxALT <pikalaxalt@gmail.com>2018-06-07 11:16:55 -0400
committerPikalaxALT <pikalaxalt@gmail.com>2018-06-07 11:16:55 -0400
commit04117dcec0931bd18c2d03de2ede7859d4f5868b (patch)
tree234f920fca5d874c25160c98a0e888e58f680f87
parent709ed0314d03e0a6dc1e3838875311c0f12ee46d (diff)
CountSetBits, GiveMonToPlayer, WaitPressedAny
-rw-r--r--home/misc_32c8.asm70
-rw-r--r--shim.sym1
-rw-r--r--wram.asm4
3 files changed, 73 insertions, 2 deletions
diff --git a/home/misc_32c8.asm b/home/misc_32c8.asm
index f371d39..3eabb12 100644
--- a/home/misc_32c8.asm
+++ b/home/misc_32c8.asm
@@ -26,3 +26,73 @@ SubtractSigned::
add $1
scf
ret
+
+if DEBUG
+SECTION "Unknown 3686", ROM0[$3686]
+else
+SECTION "Unknown 3686", ROM0[$364a]
+endc
+
+GiveMonToPlayer:: ; 3686
+; Give to the player Pokemon of species b at level c.
+ ld a, b
+ ld [wMonDexIndex], a
+ ld a, c
+ ld [wCurPartyLevel], a
+ xor a
+ ld [wMonType], a
+ jpba Function1130a
+
+WaitPressedAny:: ; 369a
+; Waits for one of the buttons in d to be pressed.
+; If bc is negative, waits forever.
+; Otherwise, times out after bc frames then returns z.
+
+; Reset hJoypadSum to clear button history
+ xor a
+ ldh [hJoypadSum], a
+.loop: ; 00:369d
+; Wait for joypad polling.
+ call DelayFrame
+
+; If any of the buttons in d were pressed, return nz.
+ ldh a, [hJoypadSum]
+ and a
+ jr z, .not_pressed
+ and d
+ ret nz
+.not_pressed: ; 00:36a7
+
+; If bc < 0, don't check timeout.
+ bit 7, b
+ jr nz, .loop
+
+; Count down to timeout.
+ dec bc
+ ld a, b
+ or c
+ jr nz, .loop
+
+; Return z, signifying that the request timed out.
+ ret
+
+CountSetBits:: ; 36b1
+; Count the number of bits set in b bytes at hl.
+; Return to a, c, and wce37.
+ ld c, $0
+.asm_36b3: ; 00:36b3
+ ld a, [hli]
+ ld e, a
+ ld d, $8
+.asm_36b7: ; 00:36b7
+ srl e
+ ld a, $0
+ adc c
+ ld c, a
+ dec d
+ jr nz, .asm_36b7
+ dec b
+ jr nz, .asm_36b3
+ ld a, c
+ ld [wce37], a
+ ret
diff --git a/shim.sym b/shim.sym
index 594a8ba..f17d027 100644
--- a/shim.sym
+++ b/shim.sym
@@ -90,6 +90,7 @@
04:528F Function1128f
04:52C1 Function112c1
+04:530A Function1130a
04:5677 DoPlayerMovement
04:5DBE DisplayStartMenu
04:640B Function1240b
diff --git a/wram.asm b/wram.asm
index 954b80b..180b83d 100644
--- a/wram.asm
+++ b/wram.asm
@@ -215,8 +215,7 @@ wPlayerLinkAction:: db ; cb51
wLinkTimeoutFrames:: dw ; cb56
wcb58:: ds 2 ; cb58
-; cb5a
- ds 1 ; TODO
+wMonType:: db ; cb5a
wCurSpecies:: db ; cb5b
wNamedObjectTypeBuffer:: db ; cb5c
@@ -404,6 +403,7 @@ wItemQuantityBuffer:: db ; cd7e
SECTION "CDBA", WRAM0[$CDBA]
wItemAttributeParamBuffer:: db ; cdba
+wCurPartyLevel:: db ; cdbb
SECTION "CDBD", WRAM0[$CDBD]