summaryrefslogtreecommitdiff
path: root/home
diff options
context:
space:
mode:
Diffstat (limited to 'home')
-rw-r--r--home/init.asm4
-rw-r--r--home/math.asm25
-rw-r--r--home/misc_32c8.asm98
-rw-r--r--home/mon_stats.asm82
-rw-r--r--home/print_text.asm21
-rw-r--r--home/scrolling_menu.asm93
-rw-r--r--home/tilemap.asm70
-rw-r--r--home/unknown_388f.asm101
-rw-r--r--home/util.asm85
9 files changed, 572 insertions, 7 deletions
diff --git a/home/init.asm b/home/init.asm
index 515ce84..98fa129 100644
--- a/home/init.asm
+++ b/home/init.asm
@@ -104,9 +104,7 @@ Init: ; 052f
call DisableAudio
call _2007
- ; predef ???
- ld a, $4B ; TODO: add predefs so the line above can be uncommented
- call Predef
+ predef CheckSGB
ld a, $1F
ld [rIE], a
ld a, HIGH($9C00)
diff --git a/home/math.asm b/home/math.asm
new file mode 100644
index 0000000..8b3db6f
--- /dev/null
+++ b/home/math.asm
@@ -0,0 +1,25 @@
+include "constants.asm"
+
+if DEBUG
+SECTION "Math utility functions", ROM0 [$3380]
+else
+SECTION "Math utility functions", ROM0 [$3344]
+endc
+
+Multiply::
+ push hl
+ push bc
+ callab _Multiply
+ pop bc
+ pop hl
+ ret
+
+Divide::
+ push hl
+ push de
+ push bc
+ homecall _Divide
+ pop bc
+ pop de
+ pop hl
+ ret
diff --git a/home/misc_32c8.asm b/home/misc_32c8.asm
new file mode 100644
index 0000000..3eabb12
--- /dev/null
+++ b/home/misc_32c8.asm
@@ -0,0 +1,98 @@
+include "constants.asm"
+
+if DEBUG
+SECTION "Unknown 32c8", ROM0[$32c8]
+else
+SECTION "Unknown 32c8", ROM0[$328c]
+endc
+
+Function32c8::
+ predef Functionce10
+ ld a, b
+ and a
+ ret
+
+Function32d0::
+ ld hl, .Data
+ ret
+
+.Data: ; 00:32d4
+ db "@"
+
+SubtractSigned::
+ sub b
+ ret nc
+ cpl
+ 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/home/mon_stats.asm b/home/mon_stats.asm
new file mode 100644
index 0000000..8d702e8
--- /dev/null
+++ b/home/mon_stats.asm
@@ -0,0 +1,82 @@
+include "constants.asm"
+
+if DEBUG
+SECTION "Mon Stats", ROM0 [$394b]
+else
+SECTION "Mon Stats", ROM0 [$390f]
+endc
+
+DrawBattleHPBar::
+ push hl
+ push de
+ push bc
+ ld a, $60
+ ld [hli], a
+ ld a, $61
+ ld [hli], a
+ push hl
+ ld a, $62
+.asm_3957: ; 00:3957
+ ld [hli], a
+ dec d
+ jr nz, .asm_3957
+ ld a, $6b
+ add b
+ ld [hl], a
+ pop hl
+ ld a, e
+ and a
+ jr nz, .asm_396a
+ ld a, c
+ and a
+ jr z, .asm_397d
+ ld e, $1
+.asm_396a: ; 00:396a
+ ld a, e
+ sub $8
+ jr c, .asm_3979
+ ld e, a
+ ld a, $6a
+ ld [hli], a
+ ld a, e
+ and a
+ jr z, .asm_397d
+ jr .asm_396a
+
+.asm_3979: ; 00:3979
+ ld a, $62
+ add e
+ ld [hl], a
+.asm_397d: ; 00:397d
+ pop bc
+ pop de
+ pop hl
+ ret
+
+PrepMonFrontpic::
+ ld a, $1
+ ld [wSpriteFlipped], a
+_PrepMonFrontpic::
+ ld a, [wMonDexIndex]
+ and a
+ jr z, .asm_39a8
+ cp 252
+ jr nc, .asm_39a8
+ push hl
+ ld de, $9000
+ call LoadMonFrontSprite
+ pop hl
+ xor a
+ ldh [hGraphicStartTile], a
+ lb bc, 7, 7
+ predef PlaceGraphic
+ xor a
+ ld [wSpriteFlipped], a
+ ret
+
+.asm_39a8: ; 00:39a8
+ xor a
+ ld [wSpriteFlipped], a
+ inc a
+ ld [wMonDexIndex], a
+ ret
diff --git a/home/print_text.asm b/home/print_text.asm
index e8b4eeb..0a17688 100644
--- a/home/print_text.asm
+++ b/home/print_text.asm
@@ -48,4 +48,23 @@ PrintLetterDelay:: ; 33a3 (0:33a3)
pop de
pop hl
ret
-; 0x33e3 \ No newline at end of file
+; 0x33e3
+
+CopyDataUntil:: ; 33e3
+; Copy [hl .. bc) to de.
+
+; In other words, the source data is
+; from hl up to but not including bc,
+; and the destination is de.
+
+.asm_33e3: ; 00:33e3
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld a, h
+ cp b
+ jr nz, .asm_33e3
+ ld a, l
+ cp c
+ jr nz, .asm_33e3
+ ret
diff --git a/home/scrolling_menu.asm b/home/scrolling_menu.asm
new file mode 100644
index 0000000..28d3d3e
--- /dev/null
+++ b/home/scrolling_menu.asm
@@ -0,0 +1,93 @@
+include "constants.asm"
+
+if DEBUG
+SECTION "Scrolling Menu", ROM0 [$3810]
+else
+SECTION "Scrolling Menu", ROM0 [$37D4]
+endc
+
+Function3810::
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ inc hl
+ push hl
+ ld h, d
+ ld l, e
+ call CopyMenuHeader
+ pop hl
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ inc hl
+ ld a, [de]
+ ld [wMenuCursorBuffer], a
+ push de
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ inc hl
+ ld a, [de]
+ ld [wMenuScrollPosition], a
+ push de
+ call ScrollingMenu
+ pop de
+ ld a, [wMenuScrollPosition]
+ ld [de], a
+ pop de
+ ld a, [wMenuCursorY]
+ ld [de], a
+ ld a, [wMenuJoypad]
+ ret
+
+ScrollingMenu:: ; 00:383e
+ call CopyMenuData
+ ldh a, [hROMBank]
+ push af
+
+ ld a, BANK(_InitScrollingMenu) ; and BANK(_ScrollingMenu)
+ call Bankswitch
+
+ call _InitScrollingMenu
+ call SetPalettes
+ call _ScrollingMenu
+
+ pop af
+ call Bankswitch
+
+ ld a, [wMenuJoypad]
+ ret
+
+Function385a::
+ push hl
+ jr asm_3865
+
+Function385d::
+ callab Function_8f1cb
+asm_3865: ; 00:3865
+ pop hl
+ call MenuTextBox
+ ld c, $0
+ call Function3872
+ call CloseWindow
+ ret
+
+Function3872:: ; 00:3872
+ push bc
+ jr asm_387d
+
+Function3875::
+ callab Function8cd0c
+asm_387d: ; 00:387d
+ pop bc
+ call GetJoypad
+ ldh a, [hJoyDown]
+ and A_BUTTON | B_BUTTON
+ jr nz, .asm_388e
+ ld a, c
+ and a
+ jr z, Function3872
+ dec c
+ jr z, Function3872
+.asm_388e: ; 00:388e
+ ret
diff --git a/home/tilemap.asm b/home/tilemap.asm
new file mode 100644
index 0000000..ca97f42
--- /dev/null
+++ b/home/tilemap.asm
@@ -0,0 +1,70 @@
+include "constants.asm"
+
+if DEBUG
+SECTION "Tilemap Functions", ROM0 [$360B]
+else
+SECTION "Tilemap Functions", ROM0 [$35CF]
+endc
+
+Function360b::
+ call ClearSprites
+ ld hl, wVramState
+ set 0, [hl]
+ call Function3657
+ call LoadFontExtra
+ call GetMemSGBLayout
+ jr WaitBGMap
+
+ClearBGPalettes::
+ call ClearPalettes
+WaitBGMap:: ; 00:3621
+; Tell VBlank to update BG Map
+ ld a, $1
+ ldh [hBGMapMode], a
+; Wait for it to do its magic
+ ld c, 3
+ call DelayFrames
+ ret
+
+SetPalettes:: ; 00:362b
+ ld a, %11100100
+ ldh [rBGP], a
+ ld a, %11010000
+ ldh [rOBP0], a
+ ret
+
+ClearPalettes:: ; 00:3634
+ xor a
+ ldh [rBGP], a
+ ldh [rOBP0], a
+ ldh [rOBP1], a
+ ret
+
+GetMemSGBLayout:: ; 00:363c
+ ld b, SGB_RAM
+GetSGBLayout:: ; 00:363e
+ ld a, [wSGB]
+ and a
+ ret z
+ predef_jump Function928b
+
+SetHPPal:: ; 00:3648
+ ld a, e
+ cp 27 ; 56.25%
+ ld d, $0
+ jr nc, .done
+ cp 10 ; 20.83%
+ inc d
+ jr nc, .done
+ inc d
+.done: ; 00:3655
+ ld [hl], d
+ ret
+
+Function3657:: ; 00:3657
+ call DisableLCD
+ callab Function140d9
+ call LoadFont
+ call UpdateSprites
+ call EnableLCD
+ ret
diff --git a/home/unknown_388f.asm b/home/unknown_388f.asm
new file mode 100644
index 0000000..54aea4d
--- /dev/null
+++ b/home/unknown_388f.asm
@@ -0,0 +1,101 @@
+include "constants.asm"
+
+if DEBUG
+SECTION "Unknown 388F", ROM0 [$388F]
+else
+SECTION "Unknown 388F", ROM0 [$3853]
+endc
+
+
+Function388f::
+ ret
+
+Function3890::
+ callba Function14cac
+ ret
+
+Function3899::
+ callba Function14dac
+ ret
+
+Function38a2::
+ callba Function14dc4
+ ret
+
+Function38ab::
+ callba Function14ddd
+ ret
+
+Function38b4::
+ callba Function14e00
+ ret
+
+Function38bd::
+ callba Function14e5f
+ ret
+
+Function38c6::
+ callba Function14e27
+ ret
+
+Function38cf::
+ callba Function14e4a
+ ret
+
+Function38d8::
+ ld hl, wc5ed
+ set 7, [hl]
+ ld a, $8
+ ld [wd637], a
+ ret
+
+Function38e3::
+ ldh a, [hJoyState]
+ and $f0
+ ret z
+ call Function3233
+ jp nz, Function323e
+ callab Function3ee3e
+ ld a, [wBattleMode]
+ and a
+ ret z
+ ld a, $3
+ call Function2117
+ call Function3240
+ ret
+
+Function3904::
+ predef Function3ef19
+ ld a, $f3
+ ldh [hMapEntryMethod], a
+ ld hl, wd4a9
+ set 5, [hl]
+ ld hl, wJoypadFlags
+ set 4, [hl]
+ set 6, [hl]
+ ld a, $b
+ call Function2117
+ ret
+
+Function391f::
+ ret
+
+Function3910::
+ ld a, [wcd5d]
+ cp $1
+ jr z, .asm_392d
+ ld a, $4
+ call Function2117
+ ret
+
+.asm_392d: ; 00:392d
+ ld hl, wJoypadFlags
+ res 4, [hl]
+ ld hl, .text
+ call Function3111
+ call RotateFourPalettesLeft
+ jp Init
+
+.text:
+ text "つぎは がんばるぞ!!"
+ done
diff --git a/home/util.asm b/home/util.asm
index 6591da2..880513b 100644
--- a/home/util.asm
+++ b/home/util.asm
@@ -1,12 +1,59 @@
INCLUDE "constants.asm"
if DEBUG
-SECTION "Misc Utility Functions", ROM0[$341F]
+SECTION "Misc Utility Functions", ROM0[$33EF]
else
-SECTION "Misc Utility Functions", ROM0[$33E3]
+SECTION "Misc Utility Functions", ROM0[$33B3]
endc
-_341F:: ; 341f
+Function33ef::
+ ; hl = src
+ ; de = dest
+ ; b = y
+ ; c = x
+ push hl
+ push de
+ push bc
+ ld a, b
+ dec a
+ dec a
+ ld b, $0
+.asm_33f7: ; 00:33f7
+ add hl, bc
+ dec a
+ jr nz, .asm_33f7
+ pop bc
+ dec b
+ ld a, b
+ push hl
+ add hl, bc
+ ld d, h
+ ld e, l
+ pop hl
+.asm_3403: ; 00:3403
+ push af
+ push bc
+ call CopyBytes
+ pop bc
+ push bc
+ ld a, c
+ xor $ff
+ ld c, a
+ ld b, $ff
+ inc bc
+ add hl, bc
+ ld d, h
+ ld e, l
+ add hl, bc
+ pop bc
+ pop af
+ dec a
+ jr nz, .asm_3403
+ pop hl
+ pop de
+ jp CopyBytes
+
+SkipNames:: ; 341f
; Returns hl + a * 6
and a
ret z
@@ -39,3 +86,35 @@ memcmp:: ; 3430
dec c
jr nz, .loop
ret
+
+Function3439:: ; 3439
+; Place 2x2 sprite from *de into OAM at slot a
+ ld h, HIGH(wVirtualOAM)
+ swap a
+ ld l, a
+ call .Load
+ push bc
+ ld a, $8
+ add c
+ ld c, a
+ call .Load
+ pop bc
+ ld a, $8
+ add b
+ ld b, a
+ call .Load
+ ld a, $8
+ add c
+ ld c, a
+.Load: ; 00:3455
+ ld [hl], b
+ inc hl
+ ld [hl], c
+ inc hl
+ ld a, [de]
+ inc de
+ ld [hli], a
+ ld a, [de]
+ inc de
+ ld [hli], a
+ ret