ref: bb8990dc3cb19787e08c29409cfc674e2478fbc9
parent: 226729d1750bc6ee0c45d96e3f6b7dcf0844a609
parent: 90c18c5cf320be70b0507deda0dd7611052f2bec
author: Bryan Bishop <[email protected]>
date: Fri Jul 12 15:16:49 EDT 2013
Merge pull request #157 from yenatch/overworld overworld loop and movement
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@
rm -f pokecrystal.o pokecrystal.gbc
@echo 'rm -f $(TEXTFILES:.asm=.tx)'
@rm -f $(TEXTFILES:.asm=.tx)
-pokecrystal.o: $(TEXTFILES:.asm=.tx) $(LZ_GFX) $(TWOBPP_GFX)
+pokecrystal.o: $(TEXTFILES:.asm=.tx) wram.asm constants.asm $(shell find constants/ -type f -name '*constants.asm') hram.asm gbhw.asm $(LZ_GFX) $(TWOBPP_GFX)
python prequeue.py $(TEXTQUEUE)
rgbasm -o pokecrystal.o pokecrystal.asm
.asm.tx:
--- a/battle/effect_commands.asm
+++ b/battle/effect_commands.asm
@@ -6796,7 +6796,7 @@
; jump
dec a
ld hl, .ptrs
- rst $28
+ rst JumpTable
ret
.ptrs
dw BattleCommand19 ; paralyze
@@ -9953,7 +9953,7 @@
ld [$d123], a
ld a, [hl]
ld [$d124], a
- ld a, $3
+ ld a, 3
ld [MonType], a
ld a, $14
ld hl, $4bdd
--- a/constants.asm
+++ b/constants.asm
@@ -1,5 +1,11 @@
_CRYSTAL EQU 1
+if _CRYSTAL
+VERSION EQU 0
+else
+VERSION EQU 1
+endc
+
INCLUDE "constants/pokemon_constants.asm"
INCLUDE "constants/move_constants.asm"
INCLUDE "constants/battle_constants.asm"
@@ -10,9 +16,10 @@
INCLUDE "constants/music_constants.asm"
-; rst vectors
+; macros require rst vectors to be defined
FarCall EQU $08
Bankswitch EQU $10
+JumpTable EQU $28
dwb: MACRO
@@ -184,22 +191,6 @@
ICON_BIGMON EQU $26
-; days of the week
-SUNDAY EQU 0
-MONDAY EQU 1
-TUESDAY EQU 2
-WEDNESDAY EQU 3
-THURSDAY EQU 4
-FRIDAY EQU 5
-SATURDAY EQU 6
-
-; time of day
-MORN EQU 0
-DAY EQU 1
-NITE EQU 2
-DARKNESS EQU 3
-
-
; evolution types
EVOLVE_LEVEL EQU 1
EVOLVE_ITEM EQU 2
@@ -220,23 +211,6 @@
ATK_EQ_DEF EQU 3
-; main menu
-CONTINUE EQU 0
-NEW_GAME EQU 1
-OPTION EQU 2
-MYSTERY_GIFT EQU 3
-MOBILE EQU 4
-MOBILE_STUDIUM EQU 5
-
-; kris's pc menu items
-WITHDRAW_ITEM EQU 0
-DEPOSIT_ITEM EQU 1
-TOSS_ITEM EQU 2
-MAIL_BOX EQU 3
-DECORATION EQU 4
-TURN_OFF EQU 5
-LOG_OFF EQU 6
-
; name length
PLAYER_NAME_LENGTH EQU 8
PKMN_NAME_LENGTH EQU 11
@@ -258,20 +232,10 @@
CHECK_FLAG EQU 2
-; player states
-PLAYER_NORMAL EQU 0
-PLAYER_BIKE EQU 1
-PLAYER_SLIP EQU 2
-PLAYER_SURF EQU 4
-PLAYER_SURF_PIKA EQU 8
-
-
; joypad
BUTTONS EQU %00010000
D_PAD EQU %00100000
-AUTO_INPUT EQU $ff
-
NO_INPUT EQU %00000000
BUTTON_A EQU %00000001
BUTTON_B EQU %00000010
@@ -284,12 +248,6 @@
; movement
-STANDING EQU -1
-DOWN EQU 0
-UP EQU 1
-LEFT EQU 2
-RIGHT EQU 3
-
STEP_SLOW EQU 0
STEP_WALK EQU 1
STEP_BIKE EQU 2
@@ -299,19 +257,4 @@
STEP_BACK_LEDGE EQU 6
STEP_WALK_IN_PLACE EQU 7
-; facing
-FACE_CURRENT EQU 0
-FACE_DOWN EQU 8
-FACE_UP EQU 4
-FACE_LEFT EQU 2
-FACE_RIGHT EQU 1
-
-
-; Provisional wram bank 5 labels:
-
-; 8 4-color palettes
-Unkn1Pals EQU $d000
-Unkn2Pals EQU $d040
-BGPals EQU $d080
-OBPals EQU $d0c0
--- a/engine/scripting.asm
+++ b/engine/scripting.asm
@@ -171,22 +171,22 @@
dw Script_unknown0xa9
; 0x96e05
-Unknown_0x96e05: ; 0x96e05
- ld hl, $d434
- set 2, [hl]
- ret
+StartScript: ; 0x96e05
+ ld hl, ScriptFlags
+ set SCRIPT_RUNNING, [hl]
+ ret
; 0x96e0b
-Unknown_0x96e0b: ; 0x96e0b
- ld hl, $d434
- bit 2, [hl]
- ret
+CheckScript: ; 0x96e0b
+ ld hl, ScriptFlags
+ bit SCRIPT_RUNNING, [hl]
+ ret
; 0x96e11
-Unknown_0x96e11: ; 0x96e11
- ld hl, $d434
- res 2, [hl]
- ret
+StopScript: ; 0x96e11
+ ld hl, ScriptFlags
+ res SCRIPT_RUNNING, [hl]
+ ret
; 0x96e17
Script_3callasm: ; 0x96e17
@@ -250,8 +250,8 @@
ld [$d44f], a
call GetScriptByte
ld [$d450], a
- ld b, $25
- ld hl, $6e79
+ ld b, BANK(JumpTextFacePlayerScript)
+ ld hl, JumpTextFacePlayerScript
jp ScriptJump
; 0x96e5f
@@ -266,12 +266,20 @@
ld [$d44f], a
call GetScriptByte
ld [$d450], a
- ld b, $25
- ld hl, $6e7a
+ ld b, BANK(JumpTextScript)
+ ld hl, JumpTextScript
jp ScriptJump
; 0x96e79
-INCBIN "baserom.gbc",$96e79,$96e81 - $96e79
+JumpTextFacePlayerScript: ; 0x96e79
+ faceplayer
+JumpTextScript: ; 0x96e7a
+ loadfont
+ repeattext $ff, $ff
+ closetext
+ loadmovesprites
+ end
+; 0x96e81
Script_3jumptext: ; 0x96e81
; script command 0x52
@@ -284,8 +292,8 @@
ld [$d44f], a
call GetScriptByte
ld [$d450], a
- ld b, $25
- ld hl, $6e7a
+ ld b, BANK(JumpTextScript)
+ ld hl, JumpTextScript
jp ScriptJump
; 0x96e9b
@@ -478,17 +486,42 @@
; quantity (DecimalParam)
call $77ca
- call $7051
- ld de, $d073
+ call CurItemName
+ ld de, StringBuffer1
ld a, $1
call $76c8
- ld b, $25
- ld de, $6f77
- jp $74cb
+ ld b, BANK(GiveItemScript)
+ ld de, GiveItemScript
+ jp ScriptCall
; 0x96f76
-INCBIN "baserom.gbc",$96f76,$96f8e - $96f76
+Function96f76: ; 96f76
+ ret
+; 96f77
+
+GiveItemScript: ; 96f77
+ 3callasm BANK(Function96f76), Function96f76
+ 2writetext ReceivedItemText
+ iffalse .Full
+ waitbutton
+ specialsound
+ closetext
+ itemnotify
+ end
+
+.Full
+ keeptextopen
+ pocketisfull
+ end
+; 96f89
+
+ReceivedItemText: ; 96f89
+ text_jump UnknownText_0x1c4719, BANK(UnknownText_0x1c4719)
+ db "@"
+; 96f8e
+
+
Script_verbosegiveitem2: ; 0x96f8e
; script command 0x9f
; parameters:
@@ -512,22 +545,22 @@
xor a
.asm_96fb0
ld [$c2dd], a
- call $7051
- ld de, $d073
+ call CurItemName
+ ld de, StringBuffer1
ld a, $1
call $76c8
- ld b, $25
- ld de, $6f77
- jp $74cb
+ ld b, BANK(GiveItemScript)
+ ld de, GiveItemScript
+ jp ScriptCall
; 0x96fc6
Script_itemnotify: ; 0x96fc6
; script command 0x45
- call $6ffe
- call $7051
- ld b, $25
- ld hl, $705b
+ call GetPocketName
+ call CurItemName
+ ld b, BANK(PutItemInPocketText)
+ ld hl, PutItemInPocketText
call $269a
ret
; 0x96fd5
@@ -535,10 +568,10 @@
Script_pocketisfull: ; 0x96fd5
; script command 0x46
- call $6ffe
- call $7051
- ld b, $25
- ld hl, $7060
+ call GetPocketName
+ call CurItemName
+ ld b, BANK(PocketIsFullText)
+ ld hl, PocketIsFullText
call $269a
ret
; 0x96fe4
@@ -560,8 +593,59 @@
ret
; 0x96ffe
-INCBIN "baserom.gbc",$96ffe,$97065 - $96ffe
+GetPocketName: ; 96ffe
+ callba CheckItemPocket
+ ld a, [$d142]
+ dec a
+ ld hl, .Pockets
+ and 3
+ add a
+ ld e, a
+ ld d, 0
+ add hl, de
+ ld a, [hli]
+ ld d, [hl]
+ ld e, a
+ ld hl, StringBuffer3
+ call CopyName2
+ ret
+
+.Pockets
+ dw .Item
+ dw .Key
+ dw .Ball
+ dw .TM
+
+.Item
+ db "ITEM POCKET@"
+.Key
+ db "KEY POCKET@"
+.Ball
+ db "BALL POCKET@"
+.TM
+ db "TM POCKET@"
+; 97051
+
+CurItemName: ; 97051
+ ld a, [CurItem]
+ ld [$d265], a
+ call GetItemName
+ ret
+; 9705b
+
+
+PutItemInPocketText: ; 9705b
+ text_jump UnknownText_0x1c472c, BANK(UnknownText_0x1c472c)
+ db "@"
+; 97060
+
+PocketIsFullText: ; 97060
+ text_jump UnknownText_0x1c474b, BANK(UnknownText_0x1c474b)
+ db "@"
+; 97065
+
+
Script_pokemart: ; 0x97065
; script command 0x94
; parameters:
@@ -793,7 +877,7 @@
ld a, [$d04d]
and a
ret z
- jp $7b74
+ jp Script_end
; 0x9716b
Script_talkaftercheck: ; 0x9716b
@@ -909,12 +993,12 @@
; 0x971e3
Unknown_0x971e3: ; 0x971e3
- and a
- ret z
- cp $fe
- ret z
- dec a
- ret
+ and a
+ ret z
+ cp $fe
+ ret z
+ dec a
+ ret
; 0x971ea
Script_setlasttalked: ; 0x971ea
@@ -954,17 +1038,17 @@
ld b, a
call $26c7
ret c
- ld a, $2
- ld [$d437], a
- call Unknown_0x96e11
+ ld a, SCRIPT_WAIT_MOVEMENT
+ ld [ScriptMode], a
+ call StopScript
ret
; 0x97221
Unknown_0x97221: ; 0x97221
- ld a, $1
- ld hl, $5897
- rst $8
- ret
+ ld a, $1
+ ld hl, $5897
+ rst $8
+ ret
; 0x97228
Script_applymovement2: ; 0x97228
@@ -1056,49 +1140,49 @@
; 0x9728b
Unknown_0x9728b: ; 0x9728b
- ld a, d
- push de
- call $18de
- jr c, .asm_972b9 ; 0x97290 $27
- ld hl, $0000
- add hl, bc
- ld a, [hl]
- push bc
- call $1836
- pop bc
- jr c, .asm_972b9 ; 0x9729c $1b
- ld hl, $0004
- add hl, bc
- bit 2, [hl]
- jr nz, .asm_972b9 ; 0x972a4 $13
- pop de
- ld a, e
- call $1af8
- ld hl, $d0ed
- bit 6, [hl]
- jr nz, .asm_972b5 ; 0x972b0 $3
- call $72bc
+ ld a, d
+ push de
+ call $18de
+ jr c, .asm_972b9 ; 0x97290 $27
+ ld hl, $0000
+ add hl, bc
+ ld a, [hl]
+ push bc
+ call $1836
+ pop bc
+ jr c, .asm_972b9 ; 0x9729c $1b
+ ld hl, $0004
+ add hl, bc
+ bit 2, [hl]
+ jr nz, .asm_972b9 ; 0x972a4 $13
+ pop de
+ ld a, e
+ call $1af8
+ ld hl, $d0ed
+ bit 6, [hl]
+ jr nz, .asm_972b5 ; 0x972b0 $3
+ call $72bc
.asm_972b5
- call $1ad2
- ret
+ call $1ad2
+ ret
.asm_972b9
- pop de
- scf
- ret
+ pop de
+ scf
+ ret
; 0x972bc
Unknown_0x972bc: ; 0x972bc
- call $217a
- ld hl, $c4a0
- ld bc, $0168
+ call $217a
+ ld hl, $c4a0
+ ld bc, $0168
.asm_972c5
- res 7, [hl]
- inc hl
- dec bc
- ld a, b
- or c
- jr nz, .asm_972c5 ; 0x972cb $f8
- ret
+ res 7, [hl]
+ inc hl
+ dec bc
+ ld a, b
+ or c
+ jr nz, .asm_972c5 ; 0x972cb $f8
+ ret
; 0x972ce
Script_variablesprite: ; 0x972ce
@@ -1153,24 +1237,24 @@
; 0x9730b
Unknown_0x9730b: ; 0x9730b
- push bc
- call $18d2
- ld hl, $000c
- add hl, bc
- pop bc
- ld e, [hl]
- inc hl
- ld d, [hl]
- ld a, $ff
- cp e
- jr nz, .asm_97321 ; 0x9731a $5
- cp d
- jr nz, .asm_97321 ; 0x9731d $2
- xor a
- ret
+ push bc
+ call $18d2
+ ld hl, $000c
+ add hl, bc
+ pop bc
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ ld a, $ff
+ cp e
+ jr nz, .asm_97321 ; 0x9731a $5
+ cp d
+ jr nz, .asm_97321 ; 0x9731d $2
+ xor a
+ ret
.asm_97321
- call BitTable1Func
- ret
+ call BitTable1Func
+ ret
; 0x97325
Script_follow: ; 0x97325
@@ -1291,34 +1375,62 @@
ld [$ffe0], a
.asm_973a8
call GetScriptByte
- ld [$d44d], a
- ld b, $25
- ld de, $73b6
- jp $74cb
+ ld [ScriptDelay], a
+ ld b, BANK(ShowEmoteScript)
+ ld de, ShowEmoteScript
+ jp ScriptCall
; 0x973b6
-INCBIN "baserom.gbc",$973b6,$973c7 - $973b6
+ShowEmoteScript: ; 973b6
+ loademote $ff
+ applymovement2 .Show
+ pause 0
+ applymovement2 .Hide
+ end
+.Show
+ show_emote
+ show_person
+ step_end
+
+.Hide
+ hide_emote
+ show_person
+ step_end
+; 973c7
+
+
Script_earthquake: ; 0x973c7
; script command 0x78
; parameters:
; param (DecimalParam)
- ld hl, $73eb
+ ld hl, EarthquakeMovement
ld de, $d002
- ld bc, $0005
+ ld bc, EarthquakeMovementEnd - EarthquakeMovement
call CopyBytes
call GetScriptByte
ld [$d003], a
and $3f
ld [$d005], a
- ld b, $25
- ld de, $73e6
- jp $74cb
+ ld b, BANK(UnknownScript_0x973e6)
+ ld de, UnknownScript_0x973e6
+ jp ScriptCall
; 0x973e6
-INCBIN "baserom.gbc",$973e6,$973f0 - $973e6
+UnknownScript_0x973e6: ; 973e6
+ applymovement $0, $d002
+ end
+; 973eb
+EarthquakeMovement: ; 973eb
+ step_shake 16
+ step_sleep 16
+ step_end
+EarthquakeMovementEnd
+; 973f0
+
+
Script_loadpikachudata: ; 0x973f0
; script command 0x5a
@@ -1402,7 +1514,7 @@
ld a, $13
ld hl, $6554
rst $8
- jp $7491
+ jp Script_reloadmap
; 0x97459
Script_returnafterbattle: ; 0x97459
@@ -1435,7 +1547,7 @@
ld hl, $7c4f
rst $8
.asm_9748e
- jp $7491
+ jp Script_reloadmap
; 0x97491
Script_reloadmap: ; 0x97491
@@ -1447,7 +1559,7 @@
ld [$ff9f], a
ld a, $1
call $261b
- call Unknown_0x96e11
+ call StopScript
ret
; 0x974a2
@@ -1522,10 +1634,10 @@
; 0x974f3
Unknown_0x974f3: ; 0x974f3
- ld a, [ScriptBank]
- or $80
- ld [ScriptBank], a
- jp $74cb
+ ld a, [ScriptBank]
+ or $80
+ ld [ScriptBank], a
+ jp ScriptCall
; 0x974fe
Script_2jump: ; 0x974fe
@@ -1580,7 +1692,7 @@
ld a, [$c2dd]
and a
- jp nz, $7596
+ jp nz, SkipTwoScriptBytes
jp Script_2jump
; 0x97536
@@ -1592,7 +1704,7 @@
ld a, [$c2dd]
and a
jp nz, Script_2jump
- jp $7596
+ jp SkipTwoScriptBytes
; 0x97540
Script_if_equal: ; 0x97540
@@ -1605,7 +1717,7 @@
ld hl, $c2dd
cp [hl]
jr z, Script_2jump ; 0x97547 $b5
- jr Unknown_97596 ; 0x97549 $4b
+ jr SkipTwoScriptBytes ; 0x97549 $4b
; 0x9754b
Script_if_not_equal: ; 0x9754b
@@ -1618,7 +1730,7 @@
ld hl, $c2dd
cp [hl]
jr nz, Script_2jump ; 0x97552 $aa
- jr Unknown_97596 ; 0x97554 $40
+ jr SkipTwoScriptBytes ; 0x97554 $40
; 0x97556
Script_if_less_than: ; 0x97556
@@ -1632,7 +1744,7 @@
call GetScriptByte
cp b
jr c, Script_2jump ; 0x9755e $9e
- jr Unknown_97596 ; 0x97560 $34
+ jr SkipTwoScriptBytes ; 0x97560 $34
; 0x97562
Script_if_greater_than: ; 0x97562
@@ -1646,7 +1758,7 @@
ld a, [$c2dd]
cp b
jr c, Script_2jump ; 0x9756a $92
- jr Unknown_97596 ; 0x9756c $28
+ jr SkipTwoScriptBytes ; 0x9756c $28
; 0x9756e
Script_jumpstd: ; 0x9756e
@@ -1654,7 +1766,7 @@
; parameters:
; predefined_script (MultiByteParam)
- call $757b
+ call StdScript
jr ScriptJump ; 0x97571 $2a
; 0x97573
@@ -1663,31 +1775,31 @@
; parameters:
; predefined_script (MultiByteParam)
- call $757b
+ call StdScript
ld d, h
ld e, l
- jp $74cb
+ jp ScriptCall
; 0x9757b
-Unknown_0x9757b: ; 0x9757b
- call GetScriptByte
- ld e, a
- call GetScriptByte
- ld d, a
- ld hl, $4000
- add hl, de
- add hl, de
- add hl, de
- ld a, $2f
- call GetFarByte
- ld b, a
- inc hl
- ld a, $2f
- call GetFarHalfword
- ret
+StdScript: ; 0x9757b
+ call GetScriptByte
+ ld e, a
+ call GetScriptByte
+ ld d, a
+ ld hl, $4000 ; StdScripts
+ add hl, de
+ add hl, de
+ add hl, de
+ ld a, $2f ; BANK(StdScripts)
+ call GetFarByte
+ ld b, a
+ inc hl
+ ld a, $2f ; BANK(StdScripts)
+ call GetFarHalfword
+ ret
; 0x97596
-Unknown_97596: ; 0x97596
+SkipTwoScriptBytes: ; 0x97596
call GetScriptByte
call GetScriptByte
ret
@@ -1714,7 +1826,7 @@
ld [$d44f], a
call GetScriptByte
ld [$d450], a
- ld hl, $d434
+ ld hl, ScriptFlags
set 3, [hl]
ret
; 0x975c2
@@ -1897,16 +2009,16 @@
; 0x97673
Unknown_0x97673: ; 0x97673
- xor a
- ld b, a
- sub c
+ xor a
+ ld b, a
+ sub c
.asm_97676
- inc b
- sub c
- jr nc, .asm_97676 ; 0x97678 $fc
- dec b
- add c
- ret
+ inc b
+ sub c
+ jr nc, .asm_97676 ; 0x97678 $fc
+ dec b
+ add c
+ ret
; 0x9767d
Script_checkcode: ; 0x9767d
@@ -1947,22 +2059,24 @@
; 0x9769e
Unknown_0x9769e: ; 0x9769e
- ld c, a
- ld a, $20
- ld hl, $4648
- rst $8
- ret
+ ld c, a
+ ld a, $20
+ ld hl, $4648
+ rst $8
+ ret
; 0x976a6
Script_checkver: ; 0x976a6
; script command 0x18
- ld a, [$76ad]
+ ld a, [Version]
ld [$c2dd], a
ret
; 0x976ad
-INCBIN "baserom.gbc",$976ad,$976ae - $976ad
+Version: ; 976ad
+ db VERSION
+; 976ae
Script_pokenamemem: ; 0x976ae
; script command 0x40
@@ -1977,7 +2091,7 @@
.asm_976b7
ld [$d265], a
call $343b
- ld de, $d073
+ ld de, StringBuffer1
Unknown_976c0: ; 0x976c0
call GetScriptByte
@@ -1985,8 +2099,8 @@
jr c, .asm_976c8 ; 0x976c5 $1
xor a
.asm_976c8
- ld hl, $d099
- ld bc, $0013
+ ld hl, StringBuffer3
+ ld bc, 19
call AddNTimes
call CopyName2
ret
@@ -2005,7 +2119,7 @@
.asm_976de
ld [$d265], a
call GetItemName
- ld de, $d073
+ ld de, StringBuffer1
jr Unknown_976c0 ; 0x976e7 $d7
; 0x976e9
@@ -2025,8 +2139,8 @@
ld a, $72
ld hl, $68a5
rst $8
- ld de, $d073
- jp $76c0
+ ld de, StringBuffer1
+ jp Unknown_976c0
; 0x97701
Script_displaylocation: ; 0x97701
@@ -2065,8 +2179,8 @@
call GetScriptByte
ld [$cf60], a
call GetName
- ld de, $d073
- jp $76c0
+ ld de, StringBuffer1
+ jp Unknown_976c0
; 0x9772b
Script_unknown0xa6: ; 0x9772b
@@ -2085,11 +2199,11 @@
call $7771
call $7861
- ld hl, $d073
+ ld hl, StringBuffer1
ld bc, $4306
call $3198
- ld de, $d073
- jp $76c0
+ ld de, StringBuffer1
+ jp Unknown_976c0
; 0x97747
Script_readcoins: ; 0x97747
@@ -2098,12 +2212,12 @@
; memory (SingleByteParam)
call $7771
- ld hl, $d073
+ ld hl, StringBuffer1
ld de, $d855
ld bc, $4206
call $3198
- ld de, $d073
- jp $76c0
+ ld de, StringBuffer1
+ jp Unknown_976c0
; 0x9775c
Script_RAM2MEM: ; 0x9775c
@@ -2113,19 +2227,19 @@
call $7771
ld de, $c2dd
- ld hl, $d073
+ ld hl, StringBuffer1
ld bc, $4103
call $3198
- ld de, $d073
- jp $76c0
+ ld de, StringBuffer1
+ jp Unknown_976c0
; 0x97771
Unknown_0x97771: ; 0x97771
- ld hl, $d073
- ld bc, $000b
- ld a, $50
- call ByteFill
- ret
+ ld hl, StringBuffer1
+ ld bc, $000b
+ ld a, "@"
+ call ByteFill
+ ret
; 0x9777d
Script_stringtotext: ; 0x9777d
@@ -2141,8 +2255,8 @@
ld a, [ScriptBank]
ld hl, $30d6
rst $8
- ld de, $d086
- jp $76c0
+ ld de, StringBuffer2
+ jp Unknown_976c0
; 0x97792
Script_givepokeitem: ; 0x97792
@@ -2309,27 +2423,27 @@
; 0x97861
Unknown_0x97861: ; 0x97861
- call GetScriptByte
- and a
- ld de, $d84e
- ret z
- ld de, $d851
- ret
+ call GetScriptByte
+ and a
+ ld de, $d84e
+ ret z
+ ld de, $d851
+ ret
; 0x9786d
Unknown_0x9786d: ; 0x9786d
- ld bc, $ffc3
- push bc
- call GetScriptByte
- ld [bc], a
- inc bc
- call GetScriptByte
- ld [bc], a
- inc bc
- call GetScriptByte
- ld [bc], a
- pop bc
- ret
+ ld bc, $ffc3
+ push bc
+ call GetScriptByte
+ ld [bc], a
+ inc bc
+ call GetScriptByte
+ ld [bc], a
+ inc bc
+ call GetScriptByte
+ ld [bc], a
+ pop bc
+ ret
; 0x97881
Script_givecoins: ; 0x97881
@@ -2643,10 +2757,10 @@
; 0x979ee
Unknown_0x979ee: ; 0x979ee
- ld a, $20
- ld hl, $4430
- rst $8
- ret
+ ld a, $20
+ ld hl, $4430
+ rst $8
+ ret
; 0x979f5
Script_wildon: ; 0x979f5
@@ -2719,7 +2833,7 @@
ld [$ff9f], a
ld a, $1
call $261b
- call Unknown_0x96e11
+ call StopScript
ret
.asm_97a4a
call GetScriptByte
@@ -2731,7 +2845,7 @@
ld [$ff9f], a
ld a, $1
call $261b
- call Unknown_0x96e11
+ call StopScript
ret
; 0x97a65
@@ -2869,10 +2983,10 @@
; 0x97b01
Unknown_0x97b01: ; 0x97b01
- ld a, $25
- ld hl, $66d0
- rst $8
- ret
+ ld a, $25
+ ld hl, $66d0
+ rst $8
+ ret
; 0x97b08
Script_newloadmap: ; 0x97b08
@@ -2884,7 +2998,7 @@
ld [$ff9f], a
ld a, $1
call $261b
- call Unknown_0x96e11
+ call StopScript
ret
; 0x97b16
@@ -2892,7 +3006,7 @@
; script command 0x92
call $7b08
- jp $7b74
+ jp Script_end
; 0x97b1c
Script_loadfont: ; 0x97b1c
@@ -2922,8 +3036,11 @@
ret
; 0x97b2e
-INCBIN "baserom.gbc",$97b2e,$97b2f - $97b2e
+LoadMoveSpritesScript: ; 97b2e
+ loadmovesprites
+; 97b2f
+
Script_loadmovesprites: ; 0x97b2f
; script command 0x49
@@ -2932,6 +3049,7 @@
ret
; 0x97b36
+
Script_passtoengine: ; 0x97b36
; script command 0x89
; parameters:
@@ -2956,11 +3074,11 @@
call GetScriptByte
and a
jr z, .asm_97b50 ; 0x97b4b $3
- ld [$d44d], a
+ ld [ScriptDelay], a
.asm_97b50
- ld c, $2
+ ld c, 2
call DelayFrames
- ld hl, $d44d
+ ld hl, ScriptDelay
dec [hl]
jr nz, .asm_97b50 ; 0x97b59 $f5
ret
@@ -2974,11 +3092,11 @@
call GetScriptByte
and a
jr z, .asm_97b65 ; 0x97b60 $3
- ld [$d44d], a
+ ld [ScriptDelay], a
.asm_97b65
- ld a, $3
- ld [$d437], a
- call Unknown_0x96e11
+ ld a, SCRIPT_WAIT
+ ld [ScriptMode], a
+ call StopScript
ret
; 0x97b6e
@@ -2987,7 +3105,7 @@
; parameters:
; pointer (ScriptPointerLabelParam)
- call Unknown_0x96e11
+ call StopScript
jp Script_2jump
; 0x97b74
@@ -2994,17 +3112,17 @@
Script_end: ; 0x97b74
; script command 0x91
- call $7b9a
- jr c, .asm_97b7a ; 0x97b77 $1
+ call ExitScriptSubroutine
+ jr c, .asm_97b7a
ret
.asm_97b7a
xor a
- ld [$d438], a
- ld a, $0
- ld [$d437], a
- ld hl, $d434
+ ld [ScriptRunning], a
+ ld a, SCRIPT_OFF
+ ld [ScriptMode], a
+ ld hl, ScriptFlags
res 0, [hl]
- call Unknown_0x96e11
+ call StopScript
ret
; 0x97b8c
@@ -3011,42 +3129,44 @@
Script_return: ; 0x97b8c
; script command 0x90
- call $7b9a
- jr c, .asm_97b91 ; 0x97b8f $0
+ call ExitScriptSubroutine
+ jr c, .asm_97b91
.asm_97b91
- ld hl, $d434
+ ld hl, ScriptFlags
res 0, [hl]
- call Unknown_0x96e11
+ call StopScript
ret
; 0x97b9a
-Unknown_0x97b9a: ; 0x97b9a
- ld hl, $d43c
- ld a, [hl]
- and a
- jr z, .asm_97bbe ; 0x97b9f $1d
- dec [hl]
- ld e, [hl]
- ld d, $0
- ld hl, $d43d
- add hl, de
- add hl, de
- add hl, de
- ld a, [hli]
- ld b, a
- and $7f
- ld [ScriptBank], a
- ld a, [hli]
- ld e, a
- ld [ScriptPos], a
- ld a, [hl]
- ld d, a
- ld [ScriptPos + 1], a
- and a
- ret
+ExitScriptSubroutine: ; 0x97b9a
+; Return carry if there's no parent to return to.
+
+ ld hl, $d43c
+ ld a, [hl]
+ and a
+ jr z, .asm_97bbe ; 0x97b9f $1d
+ dec [hl]
+ ld e, [hl]
+ ld d, $0
+ ld hl, $d43d
+ add hl, de
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld b, a
+ and $7f
+ ld [ScriptBank], a
+ ld a, [hli]
+ ld e, a
+ ld [ScriptPos], a
+ ld a, [hl]
+ ld d, a
+ ld [ScriptPos + 1], a
+ and a
+ ret
.asm_97bbe
- scf
- ret
+ scf
+ ret
; 0x97bc0
Script_resetfuncs: ; 0x97bc0
@@ -3054,12 +3174,12 @@
xor a
ld [$d43c], a
- ld [$d438], a
- ld a, $0
- ld [$d437], a
- ld hl, $d434
+ ld [ScriptRunning], a
+ ld a, SCRIPT_OFF
+ ld [ScriptMode], a
+ ld hl, ScriptFlags
res 0, [hl]
- call Unknown_0x96e11
+ call StopScript
ret
; 0x97bd5
@@ -3068,15 +3188,9 @@
ld hl, $cfbc
res 0, [hl]
- ld a, BANK(HallOfFame1)
- ld hl, HallOfFame1
- rst $8
- ld a, BANK(HallOfFame2)
- ld hl, HallOfFame2
- rst $8
- ld a, BANK(HallOfFame3)
- ld hl, HallOfFame3
- rst $8
+ callba HallOfFame1
+ callba HallOfFame2
+ callba HallOfFame3
ld hl, $cfbc
set 0, [hl]
jr DisplayCredits
@@ -3093,7 +3207,7 @@
call $7bc0
ld a, $3
call $261b
- call Unknown_0x96e11
+ call StopScript
ret
; 0x97c05
@@ -3106,7 +3220,7 @@
call GetScriptByte
.asm_97c09
push af
- ld c, $6
+ ld c, 6
call DelayFrames
pop af
dec a
@@ -3125,3 +3239,4 @@
ld [$c2dd], a
ret
; 0x97c20
+
--- a/extras/chars.py
+++ b/extras/chars.py
@@ -98,6 +98,7 @@
0xE9: "&",
0xEA: "é",
0xEB: "→",
+ 0xEC: "▷",
0xED: "▶",
0xEE: "▼",
0xEF: "♂",
--- a/extras/crystal.py
+++ b/extras/crystal.py
@@ -1989,6 +1989,7 @@
0x3A: "remove_fixed_facing",
0x3B: "fix_facing",
0x3D: "hide_person",
+ 0x3E: "show_person",
0x45: "accelerate_last",
0x46: ["step_sleep", ["duration", DecimalParam]],
0x47: "step_end",
@@ -2000,6 +2001,8 @@
0x4E: "skyfall",
0x4F: "step_wait5",
+ 0x53: "hide_emote",
+ 0x54: "show_emote",
0x55: ["step_shake", ["displacement", DecimalParam]],
}
--- a/items/item_effects.asm
+++ b/items/item_effects.asm
@@ -448,7 +448,7 @@
xor a
ld [CurPartyMon], a
- ld a, $2
+ ld a, BOXMON
ld [MonType], a
ld de, $d050
ld b, $0
@@ -775,7 +775,7 @@
push de
ld a, [TempEnemyMonSpecies]
ld [CurPartySpecies], a
- ld a, $4
+ ld a, WILDMON
ld [MonType], a
ld a, $14
ld hl, $4bdd
--- a/main.asm
+++ b/main.asm
@@ -2155,8 +2155,17 @@
ret
; 1875
-INCBIN "baserom.gbc", $1875, $18ac - $1875
+INCBIN "baserom.gbc", $1875, $18a0 - $1875
+CheckCounterTile: ; 18a0
+ cp $90
+ ret z
+ cp $98
+ ret
+; 18a6
+
+INCBIN "baserom.gbc", $18a6, $18ac - $18a6
+
CheckIceTile: ; 18ac
cp $23
ret z
@@ -2183,8 +2192,36 @@
ret
; 18c3
-INCBIN "baserom.gbc", $18c3, $1c07 - $18c3
+INCBIN "baserom.gbc", $18c3, $18d2 - $18c3
+
+
+GetMapObject: ; 18d2
+; Return the location of map object a in bc.
+ ld hl, MapObjects
+ ld bc, $10
+ call AddNTimes
+ ld b, h
+ ld c, l
+ ret
+; 18de
+
+
+INCBIN "baserom.gbc", $18de, $1b07 - $18de
+
+
+GetSpriteDirection: ; 1b07
+ ld hl, $0008
+ add hl, bc
+ ld a, [hl]
+ and %00001100
+ ret
+; 1b0f
+
+
+INCBIN "baserom.gbc", $1b0f, $1c07 - $1b0f
+
+
Function1c07: ; 0x1c07
push af
ld hl, $43e8
@@ -2737,29 +2774,25 @@
PushScriptPointer: ; 261f
-; used to call a script from asm
-; input:
-; a: bank
-; hl: address
+; Call a script at a:hl.
-; bank
- ld [$d439], a ; ScriptBank
-
-; address
+ ld [ScriptBank], a
ld a, l
- ld [$d43a], a ; ScriptAddressLo
+ ld [ScriptPos], a
ld a, h
- ld [$d43b], a ; ScriptAddressHi
+ ld [ScriptPos + 1], a
ld a, $ff
- ld [$d438], a
+ ld [ScriptRunning], a
scf
ret
; 2631
+
INCBIN "baserom.gbc", $2631, $26d4 - $2631
+
GetScriptByte: ; 0x26d4
; Return byte at ScriptBank:ScriptPos in a.
@@ -2803,8 +2836,140 @@
db "@"
; 0x26f7
-INCBIN "baserom.gbc", $26f7, $2b74-$26f7
+INCBIN "baserom.gbc", $26f7, $2a07 - $26f7
+
+
+GetFacingTileCoord: ; 2a07
+; Return map coordinates in (d, e) and tile id in a
+; of the tile the player is facing.
+
+ ld a, [PlayerDirection]
+ and %1100
+ srl a
+ srl a
+ ld l, a
+ ld h, 0
+ add hl, hl
+ add hl, hl
+ ld de, .Directions
+ add hl, de
+
+ ld d, [hl]
+ inc hl
+ ld e, [hl]
+ inc hl
+
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+
+ ld a, [MapX]
+ add d
+ ld d, a
+ ld a, [MapY]
+ add e
+ ld e, a
+ ld a, [hl]
+ ret
+
+.Directions
+ ; x, y
+ db 0, 1
+ dw TileDown
+ db 0, -1
+ dw TileUp
+ db -1, 0
+ dw TileLeft
+ db 1, 0
+ dw TileRight
+; 2a3c
+
+
+INCBIN "baserom.gbc", $2a3c, $2a8b - $2a3c
+
+
+CheckFacingSign: ; 2a8b
+ call GetFacingTileCoord
+ ld b, a
+ ld a, d
+ sub 4
+ ld d, a
+ ld a, e
+ sub 4
+ ld e, a
+ ld a, [$dc01]
+ and a
+ ret z
+ ld c, a
+ ld a, [hROMBank]
+ push af
+ call $2c52
+ call $2aaa
+ pop hl
+ ld a, h
+ rst Bankswitch
+ ret
+; 2aaa
+
+; 2aaa
+ ld hl, $dc02
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+.asm_2ab0
+ push hl
+ ld a, [hli]
+ cp e
+ jr nz, .asm_2abb
+ ld a, [hli]
+ cp d
+ jr nz, .asm_2abb
+ jr .asm_2ac8
+
+.asm_2abb
+ pop hl
+ ld a, 5
+ add l
+ ld l, a
+ jr nc, .asm_2ac3
+ inc h
+
+.asm_2ac3
+ dec c
+ jr nz, .asm_2ab0
+ xor a
+ ret
+
+.asm_2ac8
+ pop hl
+ ld de, EngineBuffer1
+ ld bc, 5
+ call CopyBytes
+ scf
+ ret
+; 0x2ad4
+
+
+INCBIN "baserom.gbc", $2ad4, $2b29 - $2ad4
+
+
+FadeToMenu: ; 2b29
+ xor a
+ ld [hBGMapMode], a
+ call $1d6e
+ ld a, $23
+ ld hl, $4084
+ rst FarCall
+ call ClearSprites
+ call Function2ed3
+ ret
+; 2b3c
+
+
+INCBIN "baserom.gbc", $2b3c, $2b74 - $2b3c
+
+
Function2b74: ; 0x2b74
push af
ld a, $1
@@ -3076,8 +3241,28 @@
ret
; 2dba
-INCBIN "baserom.gbc", $2dba, $2e6f-$2dba
+ResetWindow: ; 2dba
+
+ call $1fbf
+ ld a, [hROMBank]
+ push af
+ ld a, $1
+ rst Bankswitch
+
+ call $6454
+ call $2e20
+ call $64bf
+
+ pop af
+ rst Bankswitch
+ ret
+; 2dcf
+
+
+INCBIN "baserom.gbc", $2dcf, $2e6f-$2dcf
+
+
BitTable1Func: ; 0x2e6f
ld hl, $da72
call BitTableFunc
@@ -3198,8 +3383,31 @@
ret
; 0x2f17
-INCBIN "baserom.gbc", $2f17, $2f8c - $2f17
+INCBIN "baserom.gbc", $2f17, $2f3f - $2f17
+
+
+DoItemEffect: ; 2f3f
+ callba _DoItemEffect
+ ret
+; 2f46
+
+
+CheckTossableItem: ; 2f46
+ push hl
+ push de
+ push bc
+ callba _CheckTossableItem
+ pop bc
+ pop de
+ pop hl
+ ret
+; 2f53
+
+
+INCBIN "baserom.gbc", $2f53, $2f8c - $2f53
+
+
RNG: ; 2f8c
; Two random numbers are generated by adding and subtracting
; the divider to the respective values every time it's called.
@@ -4216,9 +4424,225 @@
; 350c
-INCBIN "baserom.gbc", $350c, $3856 - $350c
+INCBIN "baserom.gbc", $350c, $3600 - $350c
+CheckTrainerBattle2: ; 3600
+
+ ld a, [hROMBank]
+ push af
+ call $2c52
+
+ call CheckTrainerBattle
+
+ pop bc
+ ld a, b
+ rst Bankswitch
+ ret
+; 360d
+
+
+CheckTrainerBattle: ; 360d
+; Check if any trainer on the map sees the player and wants to battle.
+
+; Skip the player object.
+ ld a, 1
+ ld de, MapObjects + OBJECT_LENGTH
+
+.loop
+
+; Start a battle if the object:
+
+ push af
+ push de
+
+; Has a sprite
+ ld hl, $0001
+ add hl, de
+ ld a, [hl]
+ and a
+ jr z, .next
+
+; Is a trainer
+ ld hl, $0008
+ add hl, de
+ ld a, [hl]
+ and $f
+ cp $2
+ jr nz, .next
+
+; Is visible on the map
+ ld hl, $0000
+ add hl, de
+ ld a, [hl]
+ cp $ff
+ jr z, .next
+
+; Is facing the player...
+ call $1ae5
+ call FacingPlayerDistance_bc
+ jr nc, .next
+
+; ...within their sight range
+ ld hl, $0009
+ add hl, de
+ ld a, [hl]
+ cp b
+ jr c, .next
+
+; And hasn't already been beaten
+ push bc
+ push de
+ ld hl, $000a
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ ld b, CHECK_FLAG
+ call BitTable1Func
+ ld a, c
+ pop de
+ pop bc
+ and a
+ jr z, .asm_3666
+
+.next
+ pop de
+ ld hl, OBJECT_LENGTH
+ add hl, de
+ ld d, h
+ ld e, l
+
+ pop af
+ inc a
+ cp NUM_OBJECTS
+ jr nz, .loop
+ xor a
+ ret
+
+.asm_3666
+ pop de
+ pop af
+ ld [$ffe0], a
+ ld a, b
+ ld [$d03f], a
+ ld a, c
+ ld [$d040], a
+ jr .asm_367e
+
+ ld a, $1
+ ld [$d03f], a
+ ld a, $ff
+ ld [$d040], a
+
+.asm_367e
+ call $2c57
+ ld [EngineBuffer1], a
+ ld a, [$ffe0]
+ call GetMapObject
+ ld hl, $000a
+ add hl, bc
+ ld a, [EngineBuffer1]
+ call GetFarHalfword
+ ld de, $d041
+ ld bc, $000d
+ ld a, [EngineBuffer1]
+ call FarCopyBytes
+ xor a
+ ld [$d04d], a
+ scf
+ ret
+; 36a5d
+
+
+FacingPlayerDistance_bc: ; 36a5
+
+ push de
+ call FacingPlayerDistance
+ ld b, d
+ ld c, e
+ pop de
+ ret
+; 36ad
+
+
+FacingPlayerDistance: ; 36ad
+; Return carry if the sprite at bc is facing the player,
+; and its distance in d.
+
+ ld hl, $0010 ; x
+ add hl, bc
+ ld d, [hl]
+
+ ld hl, $0011 ; y
+ add hl, bc
+ ld e, [hl]
+
+ ld a, [MapX]
+ cp d
+ jr z, .CheckY
+
+ ld a, [MapY]
+ cp e
+ jr z, .CheckX
+
+ and a
+ ret
+
+.CheckY
+ ld a, [MapY]
+ sub e
+ jr z, .NotFacing
+ jr nc, .Above
+
+; Below
+ cpl
+ inc a
+ ld d, a
+ ld e, UP << 2
+ jr .CheckFacing
+
+.Above
+ ld d, a
+ ld e, DOWN << 2
+ jr .CheckFacing
+
+.CheckX
+ ld a, [MapX]
+ sub d
+ jr z, .NotFacing
+ jr nc, .Left
+
+; Right
+ cpl
+ inc a
+ ld d, a
+ ld e, LEFT << 2
+ jr .CheckFacing
+
+.Left
+ ld d, a
+ ld e, RIGHT << 2
+
+.CheckFacing
+ call GetSpriteDirection
+ cp e
+ jr nz, .NotFacing
+ scf
+ ret
+
+.NotFacing
+ and a
+ ret
+; 36f5
+
+
+INCBIN "baserom.gbc", $36f5, $3856 - $36f5
+
+
GetBaseData: ; 3856
push bc
push de
@@ -5653,9 +6077,54 @@
; 6f07
-INCBIN "baserom.gbc", $6f07, $7305 - $6f07
+INCBIN "baserom.gbc", $6f07, $6fd9 - $6f07
+CheckFacingObject: ; 6fd9
+
+ call GetFacingTileCoord
+
+; Double the distance for counter tiles.
+ call CheckCounterTile
+ jr nz, .asm_6ff1
+
+ ld a, [MapX]
+ sub d
+ cpl
+ inc a
+ add d
+ ld d, a
+
+ ld a, [MapY]
+ sub e
+ cpl
+ inc a
+ add e
+ ld e, a
+
+.asm_6ff1
+ ld bc, $d4d6
+ ld a, 0
+ ld [hConnectionStripLength], a
+ call $7041
+ ret nc
+ ld hl, $0007
+ add hl, bc
+ ld a, [hl]
+ cp $ff
+ jr z, .asm_7007
+ xor a
+ ret
+
+.asm_7007
+ scf
+ ret
+; 7009
+
+
+INCBIN "baserom.gbc", $7009, $7305 - $7009
+
+
SpecialGiveShuckle: ; 7305
; Adding to the party.
@@ -6593,7 +7062,7 @@
; d427
-CheckTossableItem: ; d427
+_CheckTossableItem: ; d427
; Return 1 in $d142 and carry if CurItem can't be removed from the bag.
ld a, 4
call GetItemAttr
@@ -6702,7 +7171,7 @@
INCBIN "baserom.gbc", $e5bb, $e722 - $e5bb
-DoItemEffect: ; e722
+_DoItemEffect: ; e722
ld a, [CurItem]
ld [$d265], a
call GetItemName
@@ -6712,7 +7181,7 @@
ld a, [CurItem]
dec a
ld hl, ItemEffects
- rst $28
+ rst JumpTable
ret
; e73c
@@ -7040,54 +7509,62 @@
INCBIN "baserom.gbc", $12527, $125cd - $12527
-OpenMenu: ; 0x125cd
+StartMenu: ; 125cd
+
call $1fbf
+
ld de, SFX_MENU
call StartSFX
+
ld a, $1
ld hl, $6454
rst FarCall
- ld hl, $d84d
- bit 2, [hl]
- ld hl, $66d3
- jr z, .asm_125e9
- ld hl, $66db ; draw the menu a little lower
-.asm_125e9
+
+ ld hl, StatusFlags2
+ bit 2, [hl] ; bug catching contest
+ ld hl, .MenuDataHeader
+ jr z, .GotMenuData
+ ld hl, .ContestMenuDataHeader
+.GotMenuData
+
call Function1d35
- call SetUpMenuItems
+ call .SetUpMenuItems
ld a, [$d0d2]
ld [$cf88], a
- call DrawMenuAccount_
- call $1e7f
- call $68d1
+ call .DrawMenuAccount_
+ call MenuFunc_1e7f
+ call .DrawBugContestStatusBox
call $2e31
call $2e20
ld a, $1
ld hl, $64bf
rst $8
- call $68de
+ call .DrawBugContestStatus
call $0485
- jr .wait
-.reopen
+ jr .Select
+
+.Reopen
call $1ad2
call $0485
- call $6829
+ call .SetUpMenuItems
ld a, [$d0d2]
ld [$cf88], a
-.wait
- call MenuWait
- jr c, .exit
- call DrawMenuAccount
+
+.Select
+ call .GetInput
+ jr c, .Exit
+ call .DrawMenuAccount
ld a, [$cf88]
ld [$d0d2], a
call PlayClickSFX
call $1bee
- call $67e5
-; code when you return from a submenu. some submenus force you to quit
-; the menu, like save. option forces it to redraw completely.
- ld hl, .MenuReturnPointerTable
+ call .OpenMenu
+
+; Menu items have different return functions.
+; For example, saving exits the menu.
+ ld hl, .MenuReturns
ld e, a
- ld d, $0
+ ld d, 0
add hl, de
add hl, de
ld a, [hli]
@@ -7095,122 +7572,182 @@
ld l, a
jp [hl]
-.MenuReturnPointerTable: ; $6644
- dw .reopen
- dw .exit
- dw $66a2 ; invalid?
- dw $6699 ; invalid?
- dw $6691 ; invalid?
- dw .end
- dw $66b1 ; redraw
+.MenuReturns
+ dw .Reopen
+ dw .Exit
+ dw .ReturnTwo
+ dw .ReturnThree
+ dw .ReturnFour
+ dw .ReturnEnd
+ dw .ReturnRedraw
-.exit
- ld a, [$ffd8]
+.Exit
+ ld a, [hOAMUpdate]
push af
- ld a, $1
+ ld a, 1
ld [hOAMUpdate], a
call $0e5f
pop af
ld [hOAMUpdate], a
-.end
+.ReturnEnd
call Function1c07
+.ReturnEnd2
call $2dcf
call $0485
ret
-MenuWait: ; 0x12669
-; returns nc if A was pressed, c if B.
+.GetInput
+; Return carry on exit, and no-carry on selection.
xor a
ld [hBGMapMode], a
- call DrawMenuAccount
+ call .DrawMenuAccount
call SetUpMenu
ld a, $ff
ld [MenuSelection], a
.loop
- call PrintMenuAccount
+ call .PrintMenuAccount
call $1f1a
ld a, [$cf73]
cp BUTTON_B
- jr z, .b_button
+ jr z, .b
cp BUTTON_A
- jr z, .a_button
+ jr z, .a
jr .loop
-.a_button
+.a
call PlayClickSFX
and a
ret
-.b_button
+.b
scf
ret
-; 0x12691
+; 12691
+.ReturnFour ; 12691
+ call Function1c07
+ ld a, $80
+ ld [$ffa0], a
+ ret
+; 12699
-INCBIN "baserom.gbc", $12691, $12721 - $12691
+.ReturnThree ; 12699
+ call Function1c07
+ ld a, $80
+ ld [$ffa0], a
+ jr .ReturnEnd2
+; 126a2
-MenuStringDex: ; 0x12721
- db "#DEX@"
+.ReturnTwo ; 126a2
+ call Function1c07
+ ld hl, $d0e9
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld a, [$d0e8]
+ rst FarCall
+ jr .ReturnEnd2
+; 126b1
-MenuStringMon: ; 0x12726
- db "#MON@"
+.ReturnRedraw ; 126b1
+ call .Clear
+ jp .Reopen
+; 126b7
-MenuStringPack: ; 0x1272b
- db "PACK@"
+.Clear ; 126b7
+ call WhiteBGMap
+ call $1d7d
+ call $2bae
+ call .DrawMenuAccount_
+ call MenuFunc_1e7f
+ call .DrawBugContestStatus
+ call $1ad2
+ call $0d90
+ call $2b5c
+ ret
+; 126d3
-MenuStringProfile: ; 0x12730
- db $52, "@"
-MenuStringSave: ; 0x12732
- db "SAVE@"
+.MenuDataHeader
+ db $40 ; tile backup
+ db 0, 10 ; start coords
+ db 17, 19 ; end coords
+ dw .MenuData
+ db 1 ; default selection
-MenuStringOption: ; 0x12737
- db "OPTION@"
+.ContestMenuDataHeader
+ db $40 ; tile backup
+ db 2, 10 ; start coords
+ db 17, 19 ; end coords
+ dw .MenuData
+ db 1 ; default selection
-MenuStringExit: ; 0x1273e
- db "EXIT@"
+.MenuData
+ db %10101000 ; x padding, wrap around, start can close
+ dn 0, 0 ; rows, columns
+ dw MenuItemsList
+ dw .MenuString
+ dw .Items
-MenuStringGear: ; 0x12743
- db $24, "GEAR@"
+.Items
+ dw StartMenu_Pokedex, .PokedexString, .PokedexDesc
+ dw StartMenu_Pokemon, .PartyString, .PartyDesc
+ dw StartMenu_Pack, .PackString, .PackDesc
+ dw StartMenu_Status, .StatusString, .StatusDesc
+ dw StartMenu_Save, .SaveString, .SaveDesc
+ dw StartMenu_Option, .OptionString, .OptionDesc
+ dw StartMenu_Exit, .ExitString, .ExitDesc
+ dw StartMenu_Pokegear, .PokegearString, .PokegearDesc
+ dw StartMenu_Quit, .QuitString, .QuitDesc
-MenuStringQuit: ; 0x12749
- db "QUIT@"
+.PokedexString db "#DEX@"
+.PartyString db "#MON@"
+.PackString db "PACK@"
+.StatusString db $52, "@"
+.SaveString db "SAVE@"
+.OptionString db "OPTION@"
+.ExitString db "EXIT@"
+.PokegearString db $24, "GEAR@"
+.QuitString db "QUIT@"
-MenuStringDescDex: ; 0x1274e
- db "#MON", $4e, "database@"
+.PokedexDesc db "#MON", $4e, "database@"
+.PartyDesc db "Party ", $4a, $4e, "status@"
+.PackDesc db "Contains", $4e, "items@"
+.PokegearDesc db "Trainer's", $4e, "key device@"
+.StatusDesc db "Your own", $4e, "status@"
+.SaveDesc db "Save your", $4e, "progress@"
+.OptionDesc db "Change", $4e, "settings@"
+.ExitDesc db "Close this", $4e, "menu@"
+.QuitDesc db "Quit and", $4e, "be judged.@"
-MenuStringDescParty: ; 0x1275c
- db "Party ", $4a, $4e, "status@"
-MenuStringDescPack: ; 0x1276b
- db "Contains", $4e, "items@"
+.OpenMenu ; 127e5
+ ld a, [MenuSelection]
+ call .GetMenuAccountTextPointer
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+; 127ef
-MenuStringDescGear: ; 0x1277a
- db "Trainer's", $4e, "key device@"
+.MenuString ; 127ef
+ push de
+ ld a, [MenuSelection]
+ call .GetMenuAccountTextPointer
+ inc hl
+ inc hl
+ ld a, [hli]
+ ld d, [hl]
+ ld e, a
+ pop hl
+ call PlaceString
+ ret
+; 12800
-MenuStringDescProfile: ; 0x1278e
- db "Your own", $4e, "status@"
-
-MenuStringDescSave: ; 0x1279e
- db "Save your", $4e, "progress@"
-
-MenuStringDescOption: ; 0x127b1
- db "Change", $4e, "settings@"
-
-MenuStringDescExit: ; 0x127c1
- db "Close this", $4e, "menu@"
-
-MenuStringDescRetire: ; 0x127d1
- db "Quit and", $4e, "be judged.@"
-
-; 0x127e5
-
-INCBIN "baserom.gbc", $127e5, $12800 - $127e5
-
-WriteMenuAccount:
+.MenuDesc ; 12800
push de
ld a, [MenuSelection]
cp $ff
jr z, .none
- call GetMenuAccountTextPointer
+ call .GetMenuAccountTextPointer
inc hl
inc hl
inc hl
@@ -7224,11 +7761,13 @@
.none
pop de
ret
+; 12819
-GetMenuAccountTextPointer: ; 0x12819
+
+.GetMenuAccountTextPointer ; 12819
ld e, a
- ld d, $0
- ld hl, $cf97 ; table is dynamic and stored in memory
+ ld d, 0
+ ld hl, $cf97
ld a, [hli]
ld h, [hl]
ld l, a
@@ -7239,60 +7778,71 @@
add hl, de
add hl, de
ret
+; 12829
-SetUpMenuItems: ; 4:6829 = 0x12829
+
+.SetUpMenuItems ; 12829
xor a
ld [$cf76], a
- call $688d
+ call .FillMenuList
+
ld hl, $d84c
bit 0, [hl]
jr z, .no_pokedex
- ld a, $0
- call AppendMenuList
+ ld a, 0 ; pokedex
+ call .AppendMenuList
.no_pokedex
+
ld a, [PartyCount]
and a
jr z, .no_pokemon
- ld a, $1
- call AppendMenuList
+ ld a, 1 ; pokemon
+ call .AppendMenuList
.no_pokemon
+
ld a, [InLinkBattle]
and a
jr nz, .no_pack
- ld hl, $d84d
- bit 2, [hl]
+ ld hl, StatusFlags2
+ bit 2, [hl] ; bug catching contest
jr nz, .no_pack
- ld a, $2
- call AppendMenuList
+ ld a, 2 ; pack
+ call .AppendMenuList
.no_pack
+
ld hl, $d957
bit 7, [hl]
- jr z, .no_exit
- ld a, $7
- call AppendMenuList
-.no_exit
- ld a, $3
- call AppendMenuList
+ jr z, .no_pokegear
+ ld a, 7 ; pokegear
+ call .AppendMenuList
+.no_pokegear
+
+ ld a, 3 ; status
+ call .AppendMenuList
+
ld a, [InLinkBattle]
and a
jr nz, .no_save
- ld hl, $d84d
- bit 2, [hl]
- ld a, $8
+ ld hl, StatusFlags2
+ bit 2, [hl] ; bug catching contest
+ ld a, 8 ; quit
jr nz, .write
- ld a, $4
+ ld a, 4 ; save
.write
- call AppendMenuList
+ call .AppendMenuList
.no_save
- ld a, $5
- call AppendMenuList
- ld a, $6
- call AppendMenuList
+
+ ld a, 5 ; option
+ call .AppendMenuList
+ ld a, 6 ; exit
+ call .AppendMenuList
ld a, c
ld [MenuItemsList], a
ret
+; 1288d
-FillMenuList: ; 0x1288d
+
+.FillMenuList ; 1288d
xor a
ld hl, MenuItemsList
ld [hli], a
@@ -7299,55 +7849,204 @@
ld a, $ff
ld bc, $000f
call ByteFill
- ld de, MenuItemsList+1
+ ld de, MenuItemsList + 1
ld c, 0
ret
+; 128a0
-AppendMenuList: ; 0x128a0
+.AppendMenuList ; 128a0
ld [de], a
inc de
inc c
ret
+; 128a4
-DrawMenuAccount_:; 0x128a4
- jp DrawMenuAccount
+.DrawMenuAccount_ ; 128a4
+ jp .DrawMenuAccount
+; 128a7
-PrintMenuAccount: ; 4:68a7 0x128a7
- call IsMenuAccountOn
+.PrintMenuAccount ; 128a7
+ call .IsMenuAccountOn
ret z
- call DrawMenuAccount
- decoord 0, 14 ; $c5b8
- jp $6800
+ call .DrawMenuAccount
+ decoord 0, 14
+ jp .MenuDesc
+; 128b4
-DrawMenuAccount: ; 4:68b4 0x128b4
- call IsMenuAccountOn
+.DrawMenuAccount ; 128b4
+ call .IsMenuAccountOn
ret z
- hlcoord 0, 13 ; $c5a4
+ hlcoord 0, 13
ld bc, $050a
call ClearBox
- hlcoord 0, 13 ; $c5a4
- ld b, $3
- ld c, $8
+ hlcoord 0, 13
+ ld b, 3
+ ld c, 8
jp TextBoxPalette
+; 128cb
-IsMenuAccountOn: ; 0x128cb
+.IsMenuAccountOn ; 128cb
ld a, [Options2]
- and $1
+ and 1
ret
-; 0x128d1
+; 128d1
-INCBIN "baserom.gbc", $128d1, $12976 - $128d1
+.DrawBugContestStatusBox ; 128d1
+ ld hl, StatusFlags2
+ bit 2, [hl] ; bug catching contest
+ ret z
+ ld a, $9
+ ld hl, $4bdc
+ rst FarCall
+ ret
+; 128de
-OpenPartyMenu: ; $12976
+.DrawBugContestStatus ; 128de
+ ld hl, StatusFlags2
+ bit 2, [hl] ; bug catching contest
+ jr nz, .contest
+ ret
+.contest
+ ld a, $9
+ ld hl, $4be7
+ rst FarCall
+ ret
+; 128ed
+
+
+StartMenu_Exit: ; 128ed
+; Exit the menu.
+
+ ld a, 1
+ ret
+; 128f0
+
+
+StartMenu_Quit: ; 128f0
+; Retire from the bug catching contest.
+
+ ld hl, .EndTheContestText
+ call $6cf5
+ jr c, .asm_12903
+ ld a, $4
+ ld hl, $760b
+ call $31cf
+ ld a, 4
+ ret
+.asm_12903
+ ld a, 0
+ ret
+
+.EndTheContestText
+ text_jump UnknownText_0x1c1a6c, BANK(UnknownText_0x1c1a6c)
+ db "@"
+; 1290b
+
+
+StartMenu_Save: ; 1290b
+; Save the game.
+
+ call $2879
+ ld a, $5
+ ld hl, $4a1a
+ rst FarCall
+ jr nc, .asm_12919
+ ld a, 0
+ ret
+.asm_12919
+ ld a, 1
+ ret
+; 1291c
+
+
+StartMenu_Option: ; 1291c
+; Game options.
+
+ call FadeToMenu
+ ld a, $1
+ ld hl, $5b64
+ rst FarCall
+ ld a, 6
+ ret
+; 12928
+
+
+StartMenu_Status: ; 12928
+; Player status.
+
+ call FadeToMenu
+ ld a, $9
+ ld hl, $5105
+ rst FarCall
+ call $2b3c
+ ld a, 0
+ ret
+; 12937
+
+
+StartMenu_Pokedex: ; 12937
+
ld a, [PartyCount]
and a
- jr z, .return ; no pokémon in party
- call $2b29 ; fade in?
-.choosemenu ; 1297f
+ jr z, .asm_12949
+
+ call FadeToMenu
+ ld a, $10
+ ld hl, $4000
+ rst FarCall
+ call $2b3c
+
+.asm_12949
+ ld a, 0
+ ret
+; 1294c
+
+
+StartMenu_Pokegear: ; 1294c
+
+ call FadeToMenu
+ ld a, $24
+ ld hl, $4b8d
+ rst FarCall
+ call $2b3c
+ ld a, 0
+ ret
+; 1295b
+
+
+StartMenu_Pack: ; 1295b
+
+ call FadeToMenu
+ ld a, $4
+ ld hl, $4000
+ rst FarCall
+ ld a, [$cf66]
+ and a
+ jr nz, .asm_12970
+ call $2b3c
+ ld a, 0
+ ret
+.asm_12970
+ call $2b4d
+ ld a, 4
+ ret
+; 12976
+
+
+StartMenu_Pokemon: ; 12976
+
+ ld a, [PartyCount]
+ and a
+ jr z, .return
+
+ call FadeToMenu
+
+.choosemenu
xor a
ld [PartyMenuActionText], a ; Choose a POKéMON.
call WhiteBGMap
-.menu ; 12986
+
+.menu
ld a, $14
ld hl, $404f
rst FarCall ; load gfx
@@ -7357,108 +8056,671 @@
ld a, $14
ld hl, $43e0
rst FarCall ; load menu pokémon sprites
-.menunoreload ; 12998
- ld a, BANK(WritePartyMenuTilemap)
- ld hl, WritePartyMenuTilemap
- rst FarCall
- ld a, BANK(PrintPartyMenuText)
- ld hl, PrintPartyMenuText
- rst FarCall
+
+.menunoreload
+ callba WritePartyMenuTilemap
+ callba PrintPartyMenuText
call WaitBGMap
call $32f9 ; load regular palettes?
call DelayFrame
- ld a, BANK(PartyMenuSelect)
- ld hl, PartyMenuSelect
- rst FarCall
+ callba PartyMenuSelect
jr c, .return ; if cancelled or pressed B
+
call PokemonActionSubmenu
- cp $3
+ cp 3
jr z, .menu
- cp $0
+ cp 0
jr z, .choosemenu
- cp $1
+ cp 1
jr z, .menunoreload
- cp $2
+ cp 2
jr z, .quit
-.return ; 129c8
+
+.return
call $2b3c
- ld a, $0
+ ld a, 0
ret
-.quit ; 129ce
+
+.quit
ld a, b
push af
call $2b4d
pop af
ret
-; 0x129d5
+; 129d5
-INCBIN "baserom.gbc", $129d5, $12a88 - $129d5
-PokemonActionSubmenu ; 0x12a88
- ld hl, $c5cd ; coord
+INCBIN "baserom.gbc", $129d5, $12a60 - $129d5
+
+
+CantUseItem: ; 12a60
+ ld hl, CantUseItemText
+ call $2012
+ ret
+; 12a67
+
+CantUseItemText: ; 12a67
+ text_jump UnknownText_0x1c1b03, BANK(UnknownText_0x1c1b03)
+ db "@"
+; 12a6c
+
+
+PartyMonItemName: ; 12a6c
+ ld a, [CurItem]
+ ld [$d265], a
+ call GetItemName
+ call CopyName1
+ ret
+; 12a79
+
+
+CancelPokemonAction: ; 12a79
+ ld a, $14
+ ld hl, $4405
+ rst FarCall
+ ld a, $23
+ ld hl, $6a71
+ rst FarCall
+ ld a, 1
+ ret
+; 12a88
+
+
+PokemonActionSubmenu: ; 12a88
+ hlcoord 1, 15
ld bc, $0212 ; box size
- call $0fb6 ; draw box
+ call ClearBox
ld a, $9
ld hl, $4d19
rst FarCall
call $389c
ld a, [MenuSelection]
- ld hl, PokemonSubmenuActionPointerTable
- ld de, $0003 ; skip 3 bytes each time
+ ld hl, .Actions
+ ld de, 3
call IsInArray
jr nc, .nothing
+
inc hl
ld a, [hli]
ld h, [hl]
ld l, a
jp [hl]
+
.nothing
- ld a, $0
+ ld a, 0
ret
-; 0x12ab0
-PokemonSubmenuActionPointerTable: ; 0x12ab0
- dbw $01, $6e1b
- dbw $02, $6e30
- dbw $03, $6ebd
- dbw $04, $6e6a
- dbw $06, $6e55
- dbw $07, $6e7f
- dbw $08, $6ed1
- dbw $09, $6ea9
- dbw $0a, $6ee6
- dbw $0d, $6ee6
- dbw $0b, $6f26
- dbw $05, $6e94
- dbw $0c, $6f3b
- dbw $0e, $6f50
- dbw $0f, OpenPartyStats ; stats
- dbw $10, $6aec ; switch
- dbw $11, $6b60 ; item
- dbw $12, $6a79
- dbw $13, $6fba ; move
- dbw $14, $6d45 ; mail
-; no terminator?
-; 0x12aec
+.Actions
+ dbw $01, $6e1b
+ dbw $02, $6e30
+ dbw $03, $6ebd
+ dbw $04, $6e6a
+ dbw $06, $6e55
+ dbw $07, $6e7f
+ dbw $08, $6ed1
+ dbw $09, $6ea9
+ dbw $0a, $6ee6
+ dbw $0d, $6ee6
+ dbw $0b, $6f26
+ dbw $05, $6e94
+ dbw $0c, $6f3b
+ dbw $0e, $6f50
+ dbw $0f, OpenPartyStats
+ dbw $10, SwitchPartyMons
+ dbw $11, GiveTakePartyMonItem
+ dbw $12, CancelPokemonAction
+ dbw $13, $6fba ; move
+ dbw $14, $6d45 ; mail
+; 12aec
-INCBIN "baserom.gbc", $12aec, $12e00 - $12aec
+SwitchPartyMons: ; 12aec
+
+; Don't try if there's nothing to switch!
+ ld a, [PartyCount]
+ cp 2
+ jr c, .DontSwitch
+
+ ld a, [CurPartyMon]
+ inc a
+ ld [$d0e3], a
+
+ ld a, $23
+ ld hl, $6a8c
+ rst FarCall
+ ld a, $14
+ ld hl, $442d
+ rst FarCall
+
+ ld a, 4
+ ld [PartyMenuActionText], a
+ callba WritePartyMenuTilemap
+ callba PrintPartyMenuText
+
+ hlcoord 0, 1
+ ld bc, 20 * 2
+ ld a, [$d0e3]
+ dec a
+ call AddNTimes
+ ld [hl], "▷"
+ call WaitBGMap
+ call $32f9
+ call DelayFrame
+
+ callba PartyMenuSelect
+ bit 1, b
+ jr c, .DontSwitch
+
+ ld a, $14
+ ld hl, $4f12
+ rst FarCall
+
+ xor a
+ ld [PartyMenuActionText], a
+
+ ld a, $14
+ ld hl, $404f
+ rst FarCall
+ ld a, $14
+ ld hl, $4405
+ rst FarCall
+ ld a, $14
+ ld hl, $43e0
+ rst FarCall
+
+ ld a, 1
+ ret
+
+.DontSwitch
+ xor a
+ ld [PartyMenuActionText], a
+ call CancelPokemonAction
+ ret
+; 12b60
+
+
+GiveTakePartyMonItem: ; 12b60
+
+; Eggs can't hold items!
+ ld a, [CurPartySpecies]
+ cp EGG
+ jr z, .asm_12ba6
+
+ ld hl, GiveTakeItemMenuData
+ call Function1d35
+ call Function1d81
+ call Function1c07
+ jr c, .asm_12ba6
+
+ call $389c
+ ld hl, StringBuffer1
+ ld de, $d050
+ ld bc, $b
+ call CopyBytes
+ ld a, [$cfa9]
+ cp 1
+ jr nz, .asm_12ba0
+
+ call $1d6e
+ call ClearPalettes
+ call Function12ba9
+ call ClearPalettes
+ call $0e58
+ call Function1c07
+ ld a, 0
+ ret
+
+.asm_12ba0
+ call TakePartyItem
+ ld a, 3
+ ret
+
+.asm_12ba6
+ ld a, 3
+ ret
+; 12ba9
+
+
+Function12ba9: ; 12ba9
+
+ ld a, $4
+ ld hl, $46a5
+ rst FarCall
+
+.loop
+ ld a, $4
+ ld hl, $46be
+ rst FarCall
+
+ ld a, [$cf66]
+ and a
+ jr z, .quit
+
+ ld a, [$cf65]
+ cp 2
+ jr z, .next
+
+ call CheckTossableItem
+ ld a, [$d142]
+ and a
+ jr nz, .next
+
+ call Function12bd9
+ jr .quit
+
+.next
+ ld hl, CantBeHeldText
+ call $1d67
+ jr .loop
+
+.quit
+ ret
+; 12bd9
+
+
+Function12bd9: ; 12bd9
+
+ call SpeechTextBox
+ call PartyMonItemName
+ call GetPartyItemLocation
+ ld a, [hl]
+ and a
+ jr z, .asm_12bf4
+
+ push hl
+ ld d, a
+ ld a, $2e
+ ld hl, $5e76
+ rst FarCall
+ pop hl
+ jr c, .asm_12c01
+ ld a, [hl]
+ jr .asm_12c08
+
+.asm_12bf4
+ call $6cea
+ ld hl, MadeHoldText
+ call $1d67
+ call GivePartyItem
+ ret
+
+.asm_12c01
+ ld hl, PleaseRemoveMailText
+ call $1d67
+ ret
+
+.asm_12c08
+ ld [$d265], a
+ call GetItemName
+ ld hl, SwitchAlreadyHoldingText
+ call $6cf5
+ jr c, .asm_12c4b
+
+ call $6cea
+ ld a, [$d265]
+ push af
+ ld a, [CurItem]
+ ld [$d265], a
+ pop af
+ ld [CurItem], a
+ call $6cdf
+ jr nc, .asm_12c3c
+
+ ld hl, TookAndMadeHoldText
+ call $1d67
+ ld a, [$d265]
+ ld [CurItem], a
+ call GivePartyItem
+ ret
+
+.asm_12c3c
+ ld a, [$d265]
+ ld [CurItem], a
+ call $6cdf
+ ld hl, ItemStorageIsFullText
+ call $1d67
+
+.asm_12c4b
+ ret
+; 12c4c
+
+
+GivePartyItem: ; 12c4c
+
+ call GetPartyItemLocation
+ ld a, [CurItem]
+ ld [hl], a
+ ld d, a
+ ld a, $2e
+ ld hl, $5e76
+ rst FarCall
+ jr nc, .asm_12c5f
+ call $6cfe
+
+.asm_12c5f
+ ret
+; 12c60
+
+
+TakePartyItem: ; 12c60
+
+ call SpeechTextBox
+ call GetPartyItemLocation
+ ld a, [hl]
+ and a
+ jr z, .asm_12c8c
+
+ ld [CurItem], a
+ call $6cdf
+ jr nc, .asm_12c94
+
+ ld a, $2e
+ ld hl, $5e76
+ rst FarCall
+ call GetPartyItemLocation
+ ld a, [hl]
+ ld [$d265], a
+ ld [hl], NO_ITEM
+ call GetItemName
+ ld hl, TookFromText
+ call $1d67
+ jr .asm_12c9a
+
+.asm_12c8c
+ ld hl, IsntHoldingAnythingText
+ call $1d67
+ jr .asm_12c9a
+
+.asm_12c94
+ ld hl, ItemStorageIsFullText
+ call $1d67
+
+.asm_12c9a
+ ret
+; 12c9b
+
+
+GiveTakeItemMenuData: ; 12c9b
+ db %01010000
+ db 12, 12 ; start coords
+ db 17, 19 ; end coords
+ dw .Items
+ db 1 ; default option
+
+.Items
+ db %10000000 ; x padding
+ db 2 ; # items
+ db "GIVE@"
+ db "TAKE@"
+; 12caf
+
+
+TookAndMadeHoldText: ; 12caf
+ text_jump UnknownText_0x1c1b2c, BANK(UnknownText_0x1c1b2c)
+ db "@"
+; 12cb4
+
+MadeHoldText: ; 12cb4
+ text_jump UnknownText_0x1c1b57, BANK(UnknownText_0x1c1b57)
+ db "@"
+; 12cb9
+
+PleaseRemoveMailText: ; 12cb9
+ text_jump UnknownText_0x1c1b6f, BANK(UnknownText_0x1c1b6f)
+ db "@"
+; 12cbe
+
+IsntHoldingAnythingText: ; 12cbe
+ text_jump UnknownText_0x1c1b8e, BANK(UnknownText_0x1c1b8e)
+ db "@"
+; 12cc3
+
+ItemStorageIsFullText: ; 12cc3
+ text_jump UnknownText_0x1c1baa, BANK(UnknownText_0x1c1baa)
+ db "@"
+; 12cc8
+
+TookFromText: ; 12cc8
+ text_jump UnknownText_0x1c1bc4, BANK(UnknownText_0x1c1bc4)
+ db "@"
+; 12ccd
+
+SwitchAlreadyHoldingText: ; 12ccd
+ text_jump UnknownText_0x1c1bdc, BANK(UnknownText_0x1c1bdc)
+ db "@"
+; 12cd2
+
+CantBeHeldText: ; 12cd2
+ text_jump UnknownText_0x1c1c09, BANK(UnknownText_0x1c1c09)
+ db "@"
+; 12cd7
+
+
+GetPartyItemLocation: ; 12cd7
+ push af
+ ld a, PartyMon1Item - PartyMon1
+ call GetPartyParamLocation
+ pop af
+ ret
+; 12cdf
+
+
+INCBIN "baserom.gbc", $12cdf, $12e00 - $12cdf
+
+
OpenPartyStats: ; 12e00
call $1d6e
call ClearSprites
+; PartyMon
xor a
- ld [MonType], a ; partymon
+ ld [MonType], a
call LowVolume
ld a, $25
call Predef
call MaxVolume
call $1d7d
- ld a, $0
+ ld a, 0
ret
-; 0x12e1b
+; 12e1b
-INCBIN "baserom.gbc", $12e1b, $13b87 - $12e1b
+INCBIN "baserom.gbc", $12e1b, $13327 - $12e1b
+
+
+SelectMenu: ; 13327
+
+ call CheckRegisteredItem
+ jr c, .NotRegistered
+ jp UseRegisteredItem
+
+.NotRegistered
+ call $2e08
+ ld b, BANK(ItemMayBeRegisteredText)
+ ld hl, ItemMayBeRegisteredText
+ call $269a
+ call $0a46
+ jp $2dcf
+; 13340
+
+
+ItemMayBeRegisteredText: ; 13340
+ text_jump UnknownText_0x1c1cf3, BANK(UnknownText_0x1c1cf3)
+ db "@"
+; 13345
+
+
+CheckRegisteredItem: ; 13345
+
+ ld a, [WhichRegisteredItem]
+ and a
+ jr z, .NoRegisteredItem
+ and REGISTERED_POCKET
+ rlca
+ rlca
+ ld hl, .Pockets
+ rst JumpTable
+ ret
+
+.Pockets
+ dw .CheckItem
+ dw .CheckBall
+ dw .CheckKeyItem
+ dw .CheckTMHM
+
+.CheckItem
+ ld hl, NumItems
+ call .CheckRegisteredNo
+ jr c, .NoRegisteredItem
+ inc hl
+ ld e, a
+ ld d, 0
+ add hl, de
+ add hl, de
+ call .IsSameItem
+ jr c, .NoRegisteredItem
+ and a
+ ret
+
+.CheckKeyItem
+ ld a, [RegisteredItem]
+ ld hl, KeyItems
+ ld de, 1
+ call IsInArray
+ jr nc, .NoRegisteredItem
+ ld a, [RegisteredItem]
+ ld [CurItem], a
+ and a
+ ret
+
+.CheckBall
+ ld hl, NumBalls
+ call .CheckRegisteredNo
+ jr nc, .NoRegisteredItem
+ inc hl
+ ld e, a
+ ld d, 0
+ add hl, de
+ add hl, de
+ call .IsSameItem
+ jr c, .NoRegisteredItem
+ ret
+
+.CheckTMHM
+ jr .NoRegisteredItem
+
+.NoRegisteredItem
+ xor a
+ ld [WhichRegisteredItem], a
+ ld [RegisteredItem], a
+ scf
+ ret
+; 133a6
+
+
+.CheckRegisteredNo ; 133a6
+ ld a, [WhichRegisteredItem]
+ and REGISTERED_NUMBER
+ dec a
+ cp [hl]
+ jr nc, .NotEnoughItems
+ ld [$d107], a
+ and a
+ ret
+
+.NotEnoughItems
+ scf
+ ret
+; 133b6
+
+
+.IsSameItem ; 133b6
+ ld a, [RegisteredItem]
+ cp [hl]
+ jr nz, .NotSameItem
+ ld [CurItem], a
+ and a
+ ret
+
+.NotSameItem
+ scf
+ ret
+; 133c3
+
+
+UseRegisteredItem: ; 133c3
+
+ callba CheckItemMenu
+ ld a, [$d142]
+ ld hl, .SwitchTo
+ rst JumpTable
+ ret
+
+.SwitchTo
+ dw .CantUse
+ dw .NoFunction
+ dw .NoFunction
+ dw .NoFunction
+ dw .Current
+ dw .Party
+ dw .Overworld
+; 133df
+
+.NoFunction ; 133df
+ call $2e08
+ call CantUseItem
+ call $2dcf
+ and a
+ ret
+; 133ea
+
+.Current ; 133ea
+ call $2e08
+ call DoItemEffect
+ call $2dcf
+ and a
+ ret
+; 133f5
+
+.Party ; 133f5
+ call ResetWindow
+ call FadeToMenu
+ call DoItemEffect
+ call $2b3c
+ call $2dcf
+ and a
+ ret
+; 13406
+
+.Overworld ; 13406
+ call ResetWindow
+ ld a, 1
+ ld [$d0ef], a
+ call DoItemEffect
+ xor a
+ ld [$d0ef], a
+ ld a, [$d0ec]
+ cp 1
+ jr nz, .asm_13425
+ scf
+ ld a, $80
+ ld [$ffa0], a
+ ret
+; 13422
+
+.CantUse ; 13422
+ call ResetWindow
+
+.asm_13425
+ call CantUseItem
+ call $2dcf
+ and a
+ ret
+; 1342d
+
+
+INCBIN "baserom.gbc", $1342d, $13b87 - $1342d
+
+
GetSquareRoot: ; 13b87
; Return the square root of de in b.
@@ -7499,7 +8761,7 @@
GetTimeOfDay: ; 14032
; get time of day based on the current hour
ld a, [hHours] ; hour
- ld hl, TimeOfDayTable
+ ld hl, TimesOfDay
.check
; if we're within the given time period,
@@ -7520,14 +8782,13 @@
ret
; 14044
-TimeOfDayTable: ; 14044
-; boundaries for the time of day
+TimesOfDay: ; 14044
+; hours for the time of day
; 04-09 morn | 10-17 day | 18-03 nite
-; hr, time of day
- db 04, $02 ; NITE
- db 10, $00 ; MORN
- db 18, $01 ; DAY
- db 24, $02 ; NITE
+ db 04, NITE
+ db 10, MORN
+ db 18, DAY
+ db 24, NITE
; 1404c
INCBIN "baserom.gbc", $1404c, $152ab - $1404c
@@ -7567,8 +8828,8 @@
KrissPCMenuData: ; 0x15736
db %01000000
- db 0, 0 ; top left corner coords (y, x)
- db $c, $f ; bottom right corner coords (y, x)
+ db 0, 0 ; top left corner coords (y, x)
+ db 12, 15 ; bottom right corner coords (y, x)
dw .KrissPCMenuData2
db 1 ; default selected option
@@ -7581,36 +8842,30 @@
dw .KrissPCMenuPointers
.KrissPCMenuPointers ; 0x15746
- dw KrisWithdrawItemMenu ; 57d1
- dw .WithdrawItem
- dw KrisDepositItemMenu ; 588b
- dw .DepositItem
- dw KrisTossItemMenu ; 585f
- dw .TossItem
- dw KrisMailBoxMenu ; 587d
- dw .MailBox
- dw KrisDecorationMenu ; 597d
- dw .Decoration
- dw KrisLogOffMenu ; 5888
- dw .LogOff
- dw KrisLogOffMenu ; 5888
- dw .TurnOff
+ dw KrisWithdrawItemMenu, .WithdrawItem
+ dw KrisDepositItemMenu, .DepositItem
+ dw KrisTossItemMenu, .TossItem
+ dw KrisMailBoxMenu, .MailBox
+ dw KrisDecorationMenu, .Decoration
+ dw KrisLogOffMenu, .LogOff
+ dw KrisLogOffMenu, .TurnOff
-.WithdrawItem
- db "WITHDRAW ITEM@"
-.DepositItem
- db "DEPOSIT ITEM@"
-.TossItem
- db "TOSS ITEM@"
-.MailBox
- db "MAIL BOX@"
-.Decoration
- db "DECORATION@"
-.TurnOff
- db "TURN OFF@"
-.LogOff
- db "LOG OFF@"
+.WithdrawItem db "WITHDRAW ITEM@"
+.DepositItem db "DEPOSIT ITEM@"
+.TossItem db "TOSS ITEM@"
+.MailBox db "MAIL BOX@"
+.Decoration db "DECORATION@"
+.TurnOff db "TURN OFF@"
+.LogOff db "LOG OFF@"
+WITHDRAW_ITEM EQU 0
+DEPOSIT_ITEM EQU 1
+TOSS_ITEM EQU 2
+MAIL_BOX EQU 3
+DECORATION EQU 4
+TURN_OFF EQU 5
+LOG_OFF EQU 6
+
.KrissPCMenuList1
db 5
db WITHDRAW_ITEM
@@ -7618,7 +8873,7 @@
db TOSS_ITEM
db MAIL_BOX
db TURN_OFF
- db $FF
+ db $ff
.KrissPCMenuList2
db 6
@@ -7628,7 +8883,7 @@
db MAIL_BOX
db DECORATION
db LOG_OFF
- db $FF
+ db $ff
INCBIN "baserom.gbc", $157bb, $157d1 - $157bb
@@ -7651,8 +8906,8 @@
Function157e9: ; 0x157e9
; check if the item has a quantity
- ld a, BANK(CheckTossableItem)
- ld hl, CheckTossableItem
+ ld a, BANK(_CheckTossableItem)
+ ld hl, _CheckTossableItem
rst $8
ld a, [$d142]
and a
@@ -7775,7 +9030,7 @@
jr z, .asm_158b3
call Function158cc
ld a, $4
- ld hl, $7345
+ ld hl, CheckRegisteredItem
rst $8
jr .asm_1589c
@@ -7813,7 +9068,7 @@
rst $8
ld a, [$d142]
ld hl, JumpTable158e7
- rst $28
+ rst JumpTable
pop af
ld [$c2ce], a
ret
@@ -8355,8 +9610,8 @@
push de
ld a, [MenuSelection]
ld [CurItem], a
- ld a, BANK(CheckTossableItem)
- ld hl, CheckTossableItem
+ ld a, BANK(_CheckTossableItem)
+ ld hl, _CheckTossableItem
rst $8
ld a, [$d142]
pop hl
@@ -11040,7 +12295,7 @@
ld a, [$cfa9]
dec a
ld hl, $4861
- rst $28
+ rst JumpTable
.asm_44860
ret
@@ -11053,7 +12308,7 @@
dw .Cancel
.ReadMail ; 0x44869
- call $2b29
+ call FadeToMenu
ld a, [MenuSelection]
dec a
ld b, a
@@ -11113,7 +12368,7 @@
; 0x448d2
.AttachMail ; 0x448d2
- call $2b29
+ call FadeToMenu
xor a
ld [$d141], a
call $31f3
@@ -11254,6 +12509,13 @@
dw $5efc ; XXX is this MobileASM?
dw $6496 ; XXX is this MobileStudiumASM?
+CONTINUE EQU 0
+NEW_GAME EQU 1
+OPTION EQU 2
+MYSTERY_GIFT EQU 3
+MOBILE EQU 4
+MOBILE_STUDIUM EQU 5
+
NewGameMenu: ; 0x49d6c
db 2
db NEW_GAME
@@ -12153,7 +13415,7 @@
ld a, [$cf63]
and $7f
ld hl, StatsScreenPointerTable
- rst $28
+ rst JumpTable
call $5d3a ; check for keys?
ld a, [$cf63]
bit 7, a
@@ -12303,7 +13565,7 @@
jr z, .asm_50084 ; 0x5007a $8
push hl
ld hl, $4089
- rst $28
+ rst JumpTable
pop hl
jr .asm_50077 ; 0x50082 $f3
.asm_50084
@@ -12602,7 +13864,7 @@
; BoxMon data is read directly from SRAM.
ld a, [MonType]
- cp 2
+ cp BOXMON
ld a, 1
call z, GetSRAMBank
@@ -12620,8 +13882,8 @@
ld b, a
; Close SRAM if we were dealing with a BoxMon.
- ld a, [MonType] ; MonType
- cp 2 ; BOXMON
+ ld a, [MonType]
+ cp BOXMON
call z, CloseSRAM
@@ -15810,11 +17072,664 @@
INCLUDE "maps/second_map_headers.asm"
-INCBIN "baserom.gbc", $966b0, $96cb1 - $966b0
+INCBIN "baserom.gbc", $966b0, $96795 - $966b0
+
+
+DoEvents: ; 96795
+ ld a, [$d433]
+ ld hl, .pointers
+ rst JumpTable
+ ret
+; 9679d
+
+.pointers
+ dw Function967a1
+ dw Function967ae
+
+Function967a1: ; 967a1
+ call PlayerEvents
+ call $66cb
+ callba ScriptEvents
+ ret
+; 967ae
+
+Function967ae: ; 967ae
+ ret
+; 967af
+
+
+INCBIN "baserom.gbc", $967af, $9681f - $967af
+
+
+PlayerEvents: ; 9681f
+
+; Reset carry.
+ xor a
+
+ ld a, [ScriptRunning]
+ and a
+ ret nz
+
+ call $68e4
+
+ call CheckTrainerBattle3
+ jr c, .asm_96848
+
+ call CheckTileEvent
+ jr c, .asm_96848
+
+ call $7c30
+ jr c, .asm_96848
+
+ call $68ec
+ jr c, .asm_96848
+
+ call $693a
+ jr c, .asm_96848
+
+ call OWPlayerInput
+ jr c, .asm_96848
+
+ xor a
+ ret
+
+
+.asm_96848
+ push af
+ ld a, $25
+ ld hl, $6c56
+ rst FarCall
+ pop af
+
+ ld [ScriptRunning], a
+ call $6beb
+ ld a, [ScriptRunning]
+ cp 4
+ jr z, .asm_96865
+ cp 9
+ jr z, .asm_96865
+
+ xor a
+ ld [$c2da], a
+
+.asm_96865
+ scf
+ ret
+; 96867
+
+
+CheckTrainerBattle3: ; 96867
+ nop
+ nop
+ call CheckTrainerBattle2
+ jr nc, .asm_96872
+ ld a, 1
+ scf
+ ret
+
+.asm_96872
+ xor a
+ ret
+; 96874
+
+
+CheckTileEvent: ; 96874
+; Check for warps, tile triggers or wild battles.
+
+ call $670c
+ jr z, .asm_96886
+
+ ld a, $41
+ ld hl, $4820
+ rst FarCall
+ jr c, .asm_968a6
+
+ call $2238
+ jr c, .asm_968aa
+
+.asm_96886
+ call $6712
+ jr z, .asm_96890
+
+ call $2ad4
+ jr c, .asm_968ba
+
+.asm_96890
+ call $6718
+ jr z, .asm_96899
+
+ call $6b79
+ ret c
+
+.asm_96899
+ call $671e
+ jr z, .asm_968a4
+
+ call $7cc0
+ ret c
+
+ jr .asm_968a4
+
+.asm_968a4
+ xor a
+ ret
+
+.asm_968a6
+ ld a, 4
+ scf
+ ret
+
+.asm_968aa
+ ld a, [StandingTile]
+ call $18a6
+ jr nz, .asm_968b6
+ ld a, 6
+ scf
+ ret
+
+.asm_968b6
+ ld a, 5
+ scf
+ ret
+
+.asm_968ba
+ ld hl, MovementAnimation
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call $2c57
+ call PushScriptPointer
+ ret
+; 968c7
+
+
+INCBIN "baserom.gbc", $968c7, $96974 - $968c7
+
+
+OWPlayerInput: ; 96974
+
+ call PlayerMovement
+ ret c
+ and a
+ jr nz, .NoAction
+
+; Can't perform button actions while sliding on ice.
+ callba Function80404
+ jr c, .NoAction
+
+ call CheckAPressOW
+ jr c, .Action
+
+ call CheckMenuOW
+ jr c, .Action
+
+.NoAction
+ xor a
+ ret
+
+.Action
+ push af
+ callba Function80422
+ pop af
+ scf
+ ret
+; 96999
+
+
+CheckAPressOW: ; 96999
+ ld a, [hJoyPressed]
+ and BUTTON_A
+ ret z
+ call TryObjectEvent
+ ret c
+ call TryReadSign
+ ret c
+ call $7c5f
+ ret c
+ xor a
+ ret
+; 969ac
+
+
+PlayTalkObject: ; 969ac
+ push de
+ ld de, SFX_READ_TEXT_2
+ call StartSFX
+ pop de
+ ret
+; 969b5
+
+
+TryObjectEvent: ; 969b5
+ callba CheckFacingObject
+ jr c, .IsObject
+ xor a
+ ret
+
+.IsObject
+ call PlayTalkObject
+ ld a, [hConnectedMapWidth]
+ call $1ae5
+ ld hl, $0001
+ add hl, bc
+ ld a, [hl]
+ ld [$ffe0], a
+
+ ld a, [$ffe0]
+ call GetMapObject
+ ld hl, $0008
+ add hl, bc
+ ld a, [hl]
+ and $f
+
+; Bug: If IsInArray returns nc, data at bc will be executed as code.
+ push bc
+ ld de, 3
+ ld hl, .data_969ee
+ call IsInArray
+ jr nc, .asm_969ec
+ pop bc
+
+ inc hl
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+
+.asm_969ec
+ xor a
+ ret
+
+.data_969ee
+ dbw 0, .zero
+ dbw 1, .one
+ dbw 2, .two
+ dbw 3, .three
+ dbw 4, .four
+ dbw 5, .five
+ dbw 6, .six
+ db $ff
+; 96a04
+
+.zero ; 96a04
+ ld hl, $000a
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call $2c57
+ call PushScriptPointer
+; ld a, -1
+ ret
+; 96a12
+
+.one ; 96a12
+ ld hl, $000a
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call $2c57
+ ld de, EngineBuffer1
+ ld bc, 2
+ call FarCopyBytes
+ ld a, $3
+ scf
+ ret
+; 96a29
+
+.two ; 96a29
+ call $3674
+ ld a, $2
+ scf
+ ret
+; 96a30
+
+.three ; 96a30
+ xor a
+ ret
+; 96a32
+
+.four ; 96a32
+ xor a
+ ret
+; 96a34
+
+.five ; 96a34
+ xor a
+ ret
+; 96a36
+
+.six ; 96a36
+ xor a
+ ret
+; 96a38
+
+
+TryReadSign: ; 96a38
+ call CheckFacingSign
+ jr c, .IsSign
+ xor a
+ ret
+
+.IsSign
+ ld a, [$d040]
+ ld hl, .signs
+ rst JumpTable
+ ret
+
+.signs
+ dw .read
+ dw .up
+ dw .down
+ dw .right
+ dw .left
+ dw .ifset
+ dw .ifnotset
+ dw .itemifset
+ dw .asm_96aa2
+; 96a59
+
+.up
+ ld b, UP << 2
+ jr .checkdir
+.down
+ ld b, DOWN << 2
+ jr .checkdir
+.right
+ ld b, RIGHT << 2
+ jr .checkdir
+.left
+ ld b, LEFT << 2
+ jr .checkdir
+
+.checkdir
+ ld a, [PlayerDirection]
+ and %1100
+ cp b
+ jp nz, $6ad6
+
+.read
+ call PlayTalkObject
+ ld hl, $d041
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call $2c57
+ call PushScriptPointer
+ scf
+ ret
+
+.itemifset
+ call CheckSignFlag
+ jp nz, $6ad6
+ call PlayTalkObject
+ call $2c57
+ ld de, EngineBuffer1
+ ld bc, 3
+ call FarCopyBytes
+ ld a, $4
+ ld hl, $7625
+ call PushScriptPointer
+ scf
+ ret
+
+.asm_96aa2
+ call CheckSignFlag
+ jr nz, .dontread
+ call $2c57
+ ld de, EngineBuffer1
+ ld bc, 3
+ call FarCopyBytes
+ jr .dontread
+
+.ifset
+ call CheckSignFlag
+ jr z, .dontread
+ jr .asm_96ac1
+
+.ifnotset
+ call CheckSignFlag
+ jr nz, .dontread
+
+.asm_96ac1
+ push hl
+ call PlayTalkObject
+ pop hl
+ inc hl
+ inc hl
+ call $2c57
+ call GetFarHalfword
+ call $2c57
+ call PushScriptPointer
+ scf
+ ret
+
+.dontread
+ xor a
+ ret
+; 96ad8
+
+
+CheckSignFlag: ; 96ad8
+ ld hl, $d041
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ push hl
+ call $2c57
+ call GetFarHalfword
+ ld e, l
+ ld d, h
+ ld b, $2
+ call BitTable1Func
+ ld a, c
+ and a
+ pop hl
+ ret
+; 96af0
+
+
+PlayerMovement: ; 96af0
+ callba DoPlayerMovement
+ ld a, c
+ ld hl, .pointers
+ rst JumpTable
+ ld a, c
+ ret
+; 96afd
+
+.pointers
+ dw .zero
+ dw .one
+ dw .two
+ dw .three
+ dw .four
+ dw .five
+ dw .six
+ dw .seven
+
+.zero
+.four ; 96b0d
+ xor a
+ ld c, a
+ ret
+; 96b10
+
+.seven ; 96b10
+ call $68d7 ; empty
+ xor a
+ ld c, a
+ ret
+; 96b16
+
+.one ; 96b16
+ ld a, 5
+ ld c, a
+ scf
+ ret
+; 96b1b
+
+.two ; 96b1b
+ ld a, 9
+ ld c, a
+ scf
+ ret
+; 96b20
+
+.three ; 96b20
+; force the player to move in some direction
+ ld a, $4
+ ld hl, $653d
+ call PushScriptPointer
+; ld a, -1
+ ld c, a
+ scf
+ ret
+; 96b2b
+
+.five
+.six ; 96b2b
+ ld a, -1
+ ld c, a
+ and a
+ ret
+; 96b30
+
+
+CheckMenuOW: ; 96b30
+ xor a
+ ld [$ffa0], a
+ ld [$ffa1], a
+ ld a, [hJoyPressed]
+
+ bit 2, a ; SELECT
+ jr nz, .Select
+
+ bit 3, a ; START
+ jr z, .NoMenu
+
+ ld a, BANK(StartMenuScript)
+ ld hl, StartMenuScript
+ call PushScriptPointer
+ scf
+ ret
+
+.NoMenu
+ xor a
+ ret
+
+.Select
+ call PlayTalkObject
+ ld a, BANK(SelectMenuScript)
+ ld hl, SelectMenuScript
+ call PushScriptPointer
+ scf
+ ret
+; 96b58
+
+
+StartMenuScript: ; 96b58
+ 3callasm BANK(StartMenu), StartMenu
+ 2jump StartMenuCallback
+; 96b5f
+
+SelectMenuScript: ; 96b5f
+ 3callasm BANK(SelectMenu), SelectMenu
+ 2jump SelectMenuCallback
+; 96b66
+
+StartMenuCallback:
+SelectMenuCallback: ; 96b66
+ copybytetovar $ffa0
+ if_equal $80, .Script
+ if_equal $ff, .Asm
+ end
+; 96b72
+
+.Script ; 96b72
+ 2ptjump $d0e8
+; 96b75
+
+.Asm ; 96b75
+ 2ptcallasm $d0e8
+ end
+; 96b79
+
+
+INCBIN "baserom.gbc", $96b79, $96c5e - $96b79
+
+
+ScriptEvents: ; 96c5e
+ call StartScript
+.loop
+ ld a, [ScriptMode]
+ ld hl, .modes
+ rst JumpTable
+ call CheckScript
+ jr nz, .loop
+ ret
+; 96c6e
+
+.modes ; 96c6e
+ dw EndScript
+ dw RunScriptCommand
+ dw WaitScriptMovement
+ dw WaitScript
+
+EndScript: ; 96c76
+ call StopScript
+ ret
+; 96c7a
+
+WaitScript: ; 96c7a
+ call StopScript
+
+ ld hl, ScriptDelay
+ dec [hl]
+ ret nz
+
+ ld a, $1
+ ld hl, $58b9
+ rst FarCall
+
+ ld a, SCRIPT_READ
+ ld [ScriptMode], a
+ call StartScript
+ ret
+; 96c91
+
+WaitScriptMovement: ; 96c91
+ call StopScript
+
+ ld hl, VramState
+ bit 7, [hl]
+ ret nz
+
+ ld a, $1
+ ld hl, $58b9
+ rst FarCall
+
+ ld a, SCRIPT_READ
+ ld [ScriptMode], a
+ call StartScript
+ ret
+; 96ca9
+
+RunScriptCommand: ; 96ca9
+ call GetScriptByte
+ ld hl, ScriptCommandTable
+ rst JumpTable
+ ret
+; 96cb1
+
+
INCLUDE "engine/scripting.asm"
-INCBIN "baserom.gbc", $97c20, $35e
+
+INCBIN "baserom.gbc", $97c20, $97f7e - $97c20
+
SECTION "bank26",DATA,BANK[$26]
--- a/preprocessor.py
+++ b/preprocessor.py
@@ -286,6 +286,7 @@
"&": 0xE9,
"é": 0xEA,
"→": 0xEB,
+"▷": 0xEC,
"▶": 0xED,
"▼": 0xEE,
"♂": 0xEF,
--- a/wram.asm
+++ b/wram.asm
@@ -10,12 +10,14 @@
VBGMap1:
-; So far, WRAM banks 0 and 1 are included in this file.
-; Any bank 2-7 labels are in constants.asm.
+; WRAM banks 0 and 1 are included as BSS labels.
+; Other WRAM banks (2-7) are constants for now.
+SECTION "WRAMBank0",BSS[$c000]
+
SECTION "stack",BSS[$c000]
- ds 256
+ ds $100
Stack: ; c100
@@ -65,10 +67,7 @@
Channel1LastMusicAddress: ; c109
ds 2
; could have been meant as a third-level address
-; unused? ; c10b
- ds 1
-; unused? ; c10c
- ds 1
+ ds 2
Channel1NoteFlags: ; c10d
; 0:
; 1:
@@ -312,8 +311,7 @@
SECTION "auto",BSS[$c2c7]
InputType: ; c2c7
-; 00 normal
-; ff auto
+AUTO_INPUT EQU $ff
ds 1
AutoInputAddress: ; c2c8
ds 2
@@ -824,11 +822,10 @@
ds 30
MonType: ; cf5f
-; 0 partymon
-; 1 otpartymon
-; 2 boxmon
-; 3 ????mon
-; 4 wildmon
+PARTYMON EQU 0
+OTPARTYMON EQU 1
+BOXMON EQU 2
+WILDMON EQU 4
ds 1
CurSpecies: ; cf60
@@ -837,10 +834,10 @@
ds $13
MenuSelection:; cf74
- ds 1
-
- ds $cf82-$cf74
+ ds 1
+ ds 14
+
TileY: ; cf82
ds 1
TileX: ; cf83
@@ -907,7 +904,9 @@
ds 46
-; d000
+
+SECTION "WRAMBank1",BSS[$d000]
+
ds 2
DefaultFlypoint: ; d002
@@ -937,10 +936,23 @@
MovementAnimation: ; d042
ds 1
+
WalkingDirection: ; d043
+STANDING EQU -1
+DOWN EQU 0
+UP EQU 1
+LEFT EQU 2
+RIGHT EQU 3
ds 1
+
FacingDirection: ; d044
+FACE_CURRENT EQU 0
+FACE_DOWN EQU 8
+FACE_UP EQU 4
+FACE_LEFT EQU 2
+FACE_RIGHT EQU 1
ds 1
+
WalkingX: ; d045
ds 1
WalkingY: ; d046
@@ -1058,14 +1070,13 @@
ds 2
TempMonSpclDef: ; d13c
ds 2
-TempMonEnd: ; d13e
+TempMonEnd ; d13e
ds 3
-PartyMenuActionText ; d141
- ds 1
-
- ds 1
+PartyMenuActionText: ; d141
+ ds 1
+ ds 1
CurPartyLevel: ; d143
ds 1
@@ -1379,10 +1390,10 @@
SECTION "TimeOfDay",BSS[$d269]
TimeOfDay: ; d269
-; 0 morn
-; 1 day
-; 2 nite
-; 3 darkness
+MORN EQU 0
+DAY EQU 1
+NITE EQU 2
+DARKNESS EQU 3
ds 1
SECTION "OTParty",BSS[$d280]
@@ -1515,13 +1526,31 @@
OTPartyMon6Nickname: ; d421
ds 11
-SECTION "Scripting",BSS[$d439]
+SECTION "Scripting",BSS[$d434]
+ScriptFlags: ; d434
+SCRIPT_RUNNING EQU 2
+ ds 1
+ ds 2
+
+ScriptMode: ; d437
+SCRIPT_OFF EQU 0
+SCRIPT_READ EQU 1
+SCRIPT_WAIT_MOVEMENT EQU 2
+SCRIPT_WAIT EQU 3
+ ds 1
+ScriptRunning: ; d438
+ ds 1
ScriptBank: ; d439
ds 1
ScriptPos: ; d43a
ds 2
+ ds 17
+
+ScriptDelay: ; d44d
+ ds 1
+
SECTION "Player",BSS[$d472]
PlayerGender: ; d472
; bit 0:
@@ -1569,6 +1598,13 @@
ds 2
CurDay: ; d4cb
+SUNDAY EQU 0
+MONDAY EQU 1
+TUESDAY EQU 2
+WEDNESDAY EQU 3
+THURSDAY EQU 4
+FRIDAY EQU 5
+SATURDAY EQU 6
ds 1
ds 12
@@ -1612,6 +1648,16 @@
ds 1
+SECTION "Objects",BSS[$d71e]
+MapObjects: ; d71e
+
+PLAYER_OBJECT EQU 0
+
+NUM_OBJECTS EQU $10
+OBJECT_LENGTH EQU $10
+ ds OBJECT_LENGTH * NUM_OBJECTS
+
+
SECTION "Status",BSS[$d841]
TimeOfDayPal: ; d841
ds 1
@@ -1622,8 +1668,13 @@
CurTimeOfDay: ; d848
ds 1
- ds 5
+ ds 3
+StatusFlags: ; d84c
+ ds 1
+StatusFlags2: ; d84d
+ ds 1
+
Money: ; d84e
ds 3
@@ -1642,24 +1693,32 @@
NumItems: ; d892
ds 1
Items: ; d893
- ds 69
+ ds 41
NumKeyItems: ; d8bc
ds 1
KeyItems: ; d8bd
- ds 13
-
+ ds 26
+
NumBalls: ; d8d7
ds 1
Balls: ; d8d8
ds 25
-SECTION "overworld",BSS[$d95d]
+SECTION "overworld",BSS[$d95b]
+WhichRegisteredItem: ; d95b
+REGISTERED_POCKET EQU %11000000
+REGISTERED_NUMBER EQU %00111111
+ ds 1
+RegisteredItem: ; d95c
+ ds 1
+
PlayerState: ; d95d
-; $00: normal
-; $01: bicycle
-; $04: surf
-; $08: surf (pikachu)
+PLAYER_NORMAL EQU 0
+PLAYER_BIKE EQU 1
+PLAYER_SLIP EQU 2
+PLAYER_SURF EQU 4
+PLAYER_SURF_PIKA EQU 8
ds 1
SECTION "scriptram",BSS[$d962]
@@ -2001,3 +2060,17 @@
ds 1
RoamMon3DVs: ; dfe2
ds 2
+
+
+
+; SECTION "WRAMBank5",BSS[$d000]
+
+; 8 4-color palettes
+Unkn1Pals EQU $d000
+Unkn2Pals EQU $d040
+BGPals EQU $d080
+OBPals EQU $d0c0
+
+
+
+