summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/constants/gfx_constants.asm2
-rw-r--r--src/constants/menu_constants.asm7
-rw-r--r--src/constants/npc_constants.asm30
-rw-r--r--src/constants/script_constants.asm5
-rw-r--r--src/data/npcs.asm18
-rw-r--r--src/data/sequences/credits_sequence.asm400
-rw-r--r--src/data/sequences/opening_sequence.asm48
-rw-r--r--src/engine/bank01.asm6
-rw-r--r--src/engine/bank03.asm76
-rw-r--r--src/engine/bank04.asm1255
-rw-r--r--src/engine/bank05.asm4
-rw-r--r--src/engine/bank06.asm8
-rw-r--r--src/engine/bank07.asm1511
-rw-r--r--src/engine/bank20.asm5
-rw-r--r--src/engine/home.asm42
-rw-r--r--src/engine/sequences/credits_sequence_commands.asm484
-rw-r--r--src/engine/sequences/opening_sequence_commands.asm350
-rw-r--r--src/hram.asm3
-rw-r--r--src/layout.link1
-rw-r--r--src/macros/credits_sequence.asm99
-rw-r--r--src/macros/opening_sequence.asm63
-rw-r--r--src/macros/scripts.asm8
-rw-r--r--src/main.asm4
-rw-r--r--src/sram.asm39
-rw-r--r--src/text/text3.asm28
-rw-r--r--src/text/text9.asm70
-rw-r--r--src/text/text_offsets.asm100
-rw-r--r--src/wram.asm125
28 files changed, 4242 insertions, 549 deletions
diff --git a/src/constants/gfx_constants.asm b/src/constants/gfx_constants.asm
index 6ec2e0b..a32e255 100644
--- a/src/constants/gfx_constants.asm
+++ b/src/constants/gfx_constants.asm
@@ -13,6 +13,8 @@ palettes EQUS "* CGB_PAL_SIZE"
NUM_BACKGROUND_PALETTES EQU 8
NUM_OBJECT_PALETTES EQU 8
+PALRGB_WHITE EQU (31 << 10 | 31 << 5 | 31)
+
; tile size
TILE_SIZE EQU 16 ; bytes
tiles EQUS "* TILE_SIZE"
diff --git a/src/constants/menu_constants.asm b/src/constants/menu_constants.asm
index 86df8bf..007a354 100644
--- a/src/constants/menu_constants.asm
+++ b/src/constants/menu_constants.asm
@@ -46,3 +46,10 @@ NUM_CARDS_PROMOTIONAL EQU 20
const_def
const VENUSAUR_OWNED_PHANTOM_F ; $0
const MEW_OWNED_PHANTOM_F ; $1
+
+; wStartMenuChoice enums
+ const_def
+ const START_MENU_CARD_POP ; 0
+ const START_MENU_CONTINUE_FROM_DIARY ; 1
+ const START_MENU_NEW_GAME ; 2
+ const START_MENU_CONTINUE_DUEL ; 3
diff --git a/src/constants/npc_constants.asm b/src/constants/npc_constants.asm
index 4a64993..1aac946 100644
--- a/src/constants/npc_constants.asm
+++ b/src/constants/npc_constants.asm
@@ -7,12 +7,12 @@ LOADED_NPC_MAX EQU $08
const LOADED_NPC_COORD_X
const LOADED_NPC_COORD_Y
const LOADED_NPC_DIRECTION
- const LOADED_NPC_FIELD_05
- const LOADED_NPC_FIELD_06
- const LOADED_NPC_FIELD_07
- const LOADED_NPC_FIELD_08
- const LOADED_NPC_FIELD_09
- const LOADED_NPC_FIELD_0A
+ const LOADED_NPC_FLAGS
+ const LOADED_NPC_ANIM
+ const LOADED_NPC_UNKNOWN
+ const LOADED_NPC_MOVEMENT_STEP
+ const LOADED_NPC_MOVEMENT_PTR
+const_value = const_value+1
const LOADED_NPC_FIELD_0B
LOADED_NPC_LENGTH EQU const_value
@@ -20,9 +20,9 @@ LOADED_NPC_LENGTH EQU const_value
const_def
const NPC_DATA_ID
const NPC_DATA_SPRITE_ID
- const NPC_DATA_FIELD_02 ; 02-04 Seem to relate to sprites
- const NPC_DATA_FIELD_03
- const NPC_DATA_FIELD_04
+ const NPC_DATA_ANIM
+ const NPC_DATA_ANIM_CGB
+ const NPC_DATA_FLAGS
const NPC_DATA_SCRIPT_PTR
const_value = const_value+1
const NPC_DATA_NAME_TEXT
@@ -191,4 +191,14 @@ NPC_DATA_LENGTH EQU const_value
const NPC_MURRAY2 ; $70
const NPC_RONALD2 ; $71
const NPC_RONALD3 ; $72
- const NPC_73 ; $73 (unused)
+ const NPC_PLAYER_CREDITS ; $73
+
+; flags in LOADED_NPC_FLAGS
+ const_def 4
+ const NPC_FLAG_DIRECTIONLESS_F ; $4
+ const NPC_FLAG_MOVING_F ; $5
+ const NPC_FLAG_UNKNOWN_F ; $6
+
+NPC_FLAG_DIRECTIONLESS EQU 1 << NPC_FLAG_DIRECTIONLESS_F
+NPC_FLAG_MOVING EQU 1 << NPC_FLAG_MOVING_F
+NPC_FLAG_UNKNOWN EQU 1 << NPC_FLAG_UNKNOWN_F
diff --git a/src/constants/script_constants.asm b/src/constants/script_constants.asm
index d7ae7d6..3a44694 100644
--- a/src/constants/script_constants.asm
+++ b/src/constants/script_constants.asm
@@ -276,6 +276,7 @@ EAST EQU $01
SOUTH EQU $02
WEST EQU $03
NO_MOVE EQU %10000000 ; For rotations without movement
+DIRECTION_MASK EQU $ff ^ NO_MOVE
VARIABLE_CARD EQU 0 ; use the card located in wCardReceived instead of using the script's argument
@@ -300,3 +301,7 @@ SCIENCE_MEDAL EQU 1 << SCIENCE_MEDAL_F
GRASS_MEDAL EQU 1 << GRASS_MEDAL_F
NUM_MEDALS EQU 8
+
+; total number of packs that are obtained through the PC
+NUM_PC_PACKS EQU 15
+PACK_OPENED EQU %10000000
diff --git a/src/data/npcs.asm b/src/data/npcs.asm
index 34885d6..d03147f 100644
--- a/src/data/npcs.asm
+++ b/src/data/npcs.asm
@@ -553,7 +553,7 @@ AmyNPCHeader:
db SPRITE_OW_AMY
db $08
db $2e
- db $10
+ db NPC_FLAG_DIRECTIONLESS
dw Script_Amy
tx AmyNPCName
db AMY_PIC
@@ -722,7 +722,7 @@ Murray2NPCHeader:
db SPRITE_OW_MURRAY
db $03
db $15
- db $10
+ db NPC_FLAG_DIRECTIONLESS
dw Script_Murray
tx MurrayNPCName
db MURRAY_PIC
@@ -1463,7 +1463,7 @@ TorchNPCHeader:
db $26
db $3a
db $3a
- db $10
+ db NPC_FLAG_DIRECTIONLESS
dw Script_Torch
LegendaryCardTopLeftNPCHeader:
@@ -1471,7 +1471,7 @@ LegendaryCardTopLeftNPCHeader:
db $27
db $3b
db $41
- db $50
+ db NPC_FLAG_DIRECTIONLESS | NPC_FLAG_UNKNOWN
dw Script_LegendaryCardTopLeft
LegendaryCardTopRightNPCHeader:
@@ -1479,7 +1479,7 @@ LegendaryCardTopRightNPCHeader:
db $27
db $3c
db $42
- db $50
+ db NPC_FLAG_DIRECTIONLESS | NPC_FLAG_UNKNOWN
dw Script_LegendaryCardTopRight
LegendaryCardLeftSparkNPCHeader:
@@ -1487,7 +1487,7 @@ LegendaryCardLeftSparkNPCHeader:
db $27
db $3d
db $43
- db $50
+ db NPC_FLAG_DIRECTIONLESS | NPC_FLAG_UNKNOWN
dw Script_LegendaryCardLeftSpark
LegendaryCardBottomLeftNPCHeader:
@@ -1495,7 +1495,7 @@ LegendaryCardBottomLeftNPCHeader:
db $27
db $3e
db $44
- db $50
+ db NPC_FLAG_DIRECTIONLESS | NPC_FLAG_UNKNOWN
dw Script_LegendaryCardBottomLeft
LegendaryCardBottomRightNPCHeader:
@@ -1503,7 +1503,7 @@ LegendaryCardBottomRightNPCHeader:
db $27
db $3f
db $45
- db $50
+ db NPC_FLAG_DIRECTIONLESS | NPC_FLAG_UNKNOWN
dw Script_LegendaryCardBottomRight
LegendaryCardRightSparkNPCHeader:
@@ -1511,7 +1511,7 @@ LegendaryCardRightSparkNPCHeader:
db $27
db $40
db $46
- db $50
+ db NPC_FLAG_DIRECTIONLESS | NPC_FLAG_UNKNOWN
dw Script_LegendaryCardRightSpark
DummyNPCHeader:
diff --git a/src/data/sequences/credits_sequence.asm b/src/data/sequences/credits_sequence.asm
new file mode 100644
index 0000000..2c12413
--- /dev/null
+++ b/src/data/sequences/credits_sequence.asm
@@ -0,0 +1,400 @@
+INCLUDE "macros/credits_sequence.asm"
+
+CreditsSequence: ; 1daef (7:5aef)
+ credits_seq_disable_lcd
+ credits_seq_load_ow_map 0, 0, OVERWORLD_MAP
+ credits_seq_init_volcano_sprite
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_print_text_box 2, 1, OverworldMapPokemonDomeText
+ credits_seq_print_text 0, 0, PokemonTradingCardGameStaffText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 32, 144, 0
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_ow_map 0, 0, MASON_LABORATORY
+ credits_seq_load_npc 14, 6, SOUTH, NPC_DRMASON
+ credits_seq_load_npc 4, 14, EAST, NPC_SAM
+ credits_seq_load_npc 6, 4, SOUTH, NPC_TECH5
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 3
+ credits_seq_print_text 0, 0, ProducersText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 104, 40
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_ow_map 0, 0, DECK_MACHINE_ROOM
+ credits_seq_load_npc 6, 8, SOUTH, NPC_TECH6
+ credits_seq_load_npc 6, 22, WEST, NPC_TECH7
+ credits_seq_load_npc 10, 18, WEST, NPC_TECH8
+ credits_seq_load_npc 12, 12, WEST, NPC_AARON
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 7
+ credits_seq_print_text 0, 0, DirectorText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 120, 24
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_club_map 0
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 5
+ credits_seq_print_text 0, 0, ProgrammersText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 104, 40
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_club_map 1
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 7
+ credits_seq_print_text 0, 0, GBGraphicDesigners1Text
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 104, 40
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_draw_rectangle 4, 3
+ credits_seq_print_text 0, 4, GBGraphicDesigners2Text
+ credits_seq_transform_overlay 0, 24, 104, 40
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_draw_rectangle 4, 3
+ credits_seq_print_text 0, 4, GBGraphicDesigners3Text
+ credits_seq_transform_overlay 0, 24, 104, 40
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_club_map 2
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 7
+ credits_seq_print_text 0, 0, MusicText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 120, 24
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 5
+ credits_seq_print_text 0, 0, SoundEffectsText
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 120, 24
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_club_map 3
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 7
+ credits_seq_print_text 0, 0, SoundDirectorText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 120, 24
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 5
+ credits_seq_print_text 0, 0, SoundSystemSupportText
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 112, 32
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_booster 6, 3, SCENE_CHARIZARD_INTRO
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 6
+ credits_seq_print_text 0, 0, CardGameCreator1Text
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 120, 24
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_booster 6, 3, SCENE_SCYTHER_INTRO
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 5
+ credits_seq_print_text 0, 0, CardGameCreator2Text
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 120, 24
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_booster 6, 3, SCENE_AERODACTYL_INTRO
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 5
+ credits_seq_print_text 0, 0, CardGameCreator3Text
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 120, 24
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_ow_map 0, 0, ISHIHARAS_HOUSE
+ credits_seq_load_npc 8, 8, SOUTH, NPC_ISHIHARA
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 8
+ credits_seq_print_text 0, 0, CardIllustrators1Text
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 96, 48
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_draw_rectangle 4, 4
+ credits_seq_print_text 0, 4, CardIllustrators2Text
+ credits_seq_transform_overlay 0, 24, 96, 48
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_ow_map 16, 8, LIGHTNING_CLUB_LOBBY
+ credits_seq_load_npc 6, 4, SOUTH, NPC_CLERK10
+ credits_seq_load_npc 10, 4, SOUTH, NPC_GIFT_CENTER_CLERK
+ credits_seq_load_npc 18, 16, WEST, NPC_CHAP2
+ credits_seq_load_npc 18, 2, NORTH, NPC_IMAKUNI
+ credits_seq_load_npc 8, 12, SOUTH, NPC_LASS4
+ credits_seq_load_npc 20, 8, SOUTH, NPC_HOOD1
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 8
+ credits_seq_print_text 0, 0, SpecialAppearances1Text
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 112, 32
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_draw_rectangle 4, 4
+ credits_seq_print_text 0, 4, SpecialAppearances2Text
+ credits_seq_transform_overlay 0, 24, 112, 32
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_ow_map 48, 0, CHALLENGE_HALL
+ credits_seq_load_npc 14, 4, SOUTH, NPC_HOST
+ credits_seq_load_npc 18, 8, WEST, NPC_RONALD1
+ credits_seq_load_npc 12, 8, EAST, NPC_PLAYER_CREDITS
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 7
+ credits_seq_print_text 0, 0, USCoordination1Text
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 32, 144, 0
+ credits_seq_transform_overlay 0, 32, 112, 32
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 32, 144, 0
+ credits_seq_draw_rectangle 4, 4
+ credits_seq_print_text 0, 5, USCoordination2Text
+ credits_seq_transform_overlay 0, 32, 112, 32
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 32, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 7
+ credits_seq_print_text 0, 0, USCoordination3Text
+ credits_seq_transform_overlay 0, 40, 144, 0
+ credits_seq_transform_overlay 0, 40, 112, 32
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 40, 144, 0
+ credits_seq_draw_rectangle 6, 4
+ credits_seq_print_text 0, 6, USCoordination4Text
+ credits_seq_transform_overlay 0, 40, 104, 40
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 40, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_booster 6, 3, SCENE_COLOSSEUM_BOOSTER
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 8
+ credits_seq_print_text 0, 0, TranslationDraftText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 120, 24
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_booster 6, 3, SCENE_EVOLUTION_BOOSTER
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 6
+ credits_seq_print_text 0, 0, MasteringText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 120, 24
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_booster 6, 3, SCENE_MYSTERY_BOOSTER
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 6
+ credits_seq_print_text 0, 0, ManualCreationText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 120, 24
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_booster 6, 3, SCENE_LABORATORY_BOOSTER
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 6
+ credits_seq_print_text 0, 0, ManualIllustrationsText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 120, 24
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_club_map 4
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 7
+ credits_seq_print_text 0, 0, PokemonOriginalStoryText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 120, 24
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 7
+ credits_seq_print_text 0, 0, CreatedInCooperationWithText
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 104, 40
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_club_map 5
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 7
+ credits_seq_print_text 0, 0, WithCooperation1Text
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 104, 40
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_draw_rectangle 4, 5
+ credits_seq_print_text 0, 4, WithCooperation2Text
+ credits_seq_transform_overlay 0, 24, 96, 48
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_draw_rectangle 4, 4
+ credits_seq_print_text 0, 4, WithCooperation3Text
+ credits_seq_transform_overlay 0, 24, 96, 48
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_club_map 6
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 8
+ credits_seq_print_text 0, 0, ProjectManagerText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 120, 24
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_club_map 7
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 7
+ credits_seq_print_text 0, 0, SupervisorText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 104, 40
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_club_map 8
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 7
+ credits_seq_print_text 0, 0, ExecutiveProducerText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 104, 40
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_ow_map 16, 16, HALL_OF_HONOR
+ credits_seq_load_npc 10, 8, NORTH, NPC_LEGENDARY_CARD_TOP_LEFT
+ credits_seq_load_npc 12, 8, NORTH, NPC_LEGENDARY_CARD_TOP_RIGHT
+ credits_seq_load_npc 8, 10, NORTH, NPC_LEGENDARY_CARD_LEFT_SPARK
+ credits_seq_load_npc 10, 10, NORTH, NPC_LEGENDARY_CARD_BOTTOM_LEFT
+ credits_seq_load_npc 12, 10, NORTH, NPC_LEGENDARY_CARD_BOTTOM_RIGHT
+ credits_seq_load_npc 14, 10, NORTH, NPC_LEGENDARY_CARD_RIGHT_SPARK
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_draw_rectangle 0, 7
+ credits_seq_print_text 0, 0, CreatedByText
+ credits_seq_fade_in
+ credits_seq_wait 60
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 24, 104, 40
+ credits_seq_wait 225
+ credits_seq_transform_overlay 0, 24, 144, 0
+ credits_seq_transform_overlay 0, 0, 144, 0
+ credits_seq_fade_out
+
+ credits_seq_load_scene 0, 0, SCENE_COMPANIES
+ credits_seq_init_overlay 0, 0, 144, 0
+ credits_seq_fade_in
+ credits_seq_wait 225
+ credits_seq_end
+; 0x1e1c4
diff --git a/src/data/sequences/opening_sequence.asm b/src/data/sequences/opening_sequence.asm
new file mode 100644
index 0000000..1a25c31
--- /dev/null
+++ b/src/data/sequences/opening_sequence.asm
@@ -0,0 +1,48 @@
+INCLUDE "macros/opening_sequence.asm"
+
+OpeningSequence: ; 1d59d (7:559d)
+ opening_seq_load_charizard_scene
+ opening_seq_play_sfx SFX_58
+ opening_seq_set_orbs_coordinates OpeningOrbCoordinates_CharizardScene
+ opening_seq_set_orbs_animations OpeningOrbAnimations_CharizardScene
+ opening_seq_wait 44
+ opening_seq_fade_in
+ opening_seq_wait 44
+ opening_seq_fade_out
+ opening_seq_wait 30
+
+ opening_seq_load_scyther_scene
+ opening_seq_play_sfx SFX_58
+ opening_seq_set_orbs_coordinates OpeningOrbCoordinates_ScytherScene
+ opening_seq_set_orbs_animations OpeningOrbAnimations_ScytherScene
+ opening_seq_wait 44
+ opening_seq_fade_in
+ opening_seq_wait 44
+ opening_seq_fade_out
+ opening_seq_wait 30
+
+ opening_seq_load_aerodactyl_scene
+ opening_seq_play_sfx SFX_59
+ opening_seq_set_orbs_coordinates OpeningOrbCoordinates_AerodactylScene
+ opening_seq_set_orbs_animations OpeningOrbAnimations_AerodactylScene
+ opening_seq_wait 44
+ opening_seq_fade_in
+ opening_seq_wait 100
+ opening_seq_fade_out
+ opening_seq_wait 60
+
+ opening_seq_load_title_screen_scene
+ opening_seq_play_sfx SFX_5A
+ opening_seq_set_orbs_coordinates OpeningOrbCoordinates_InitialTitleScreen
+ opening_seq_set_orbs_animations OpeningOrbAnimations_InitialTitleScreen
+ opening_seq_wait_orbs_animation
+ opening_seq_fade_in
+ opening_seq_wait 16
+ opening_seq_play_sfx SFX_5B
+ opening_seq_set_orbs_coordinates OpeningOrbCoordinates_InTitleScreen
+ opening_seq_set_orbs_animations OpeningOrbAnimations_InTitleScreen
+ opening_seq_wait_sfx
+ opening_seq_play_title_screen_music
+ opening_seq_wait 60
+ opening_seq_end
+; 0x1d614
diff --git a/src/engine/bank01.asm b/src/engine/bank01.asm
index 449cd75..358aabf 100644
--- a/src/engine/bank01.asm
+++ b/src/engine/bank01.asm
@@ -1643,7 +1643,7 @@ DrawDuelistPortraitsAndNames: ; 4a97 (1:4a97)
call ProcessText
; player's portrait
lb bc, 0, 5
- call Func_3e10
+ call DrawPlayerPortrait
; opponent's name (aligned to the right)
ld de, wDefaultText
push de
@@ -6159,9 +6159,9 @@ Func_66e9: ; 66e9 (1:66e9)
ret c
ld de, sCurrentDuel
call LoadSavedDuelData
- call Func_3a45
+ call ValidateGeneralSaveData
ret nc
- call Func_3a40
+ call LoadGeneralSaveData
or a
ret
diff --git a/src/engine/bank03.asm b/src/engine/bank03.asm
index 75e3081..3468a54 100644
--- a/src/engine/bank03.asm
+++ b/src/engine/bank03.asm
@@ -28,7 +28,7 @@ LoadMap: ; c000 (3:4000)
call Func_3ca0
ld a, PLAYER_TURN
ldh [hWhoseTurn], a
- farcall Func_1c440
+ farcall ClearNPCs
ld a, [wTempMap]
ld [wCurMap], a
ld a, [wTempPlayerXCoord]
@@ -184,7 +184,7 @@ Func_c158: ; c158 (3:4158)
call GetItemInLoadedNPCIndex
ld a, [wd0c5]
ld [hl], a
- farcall Func_1c58e
+ farcall UpdateNPCAnimation
.asm_c179
ret
@@ -238,10 +238,10 @@ Func_c1b1: ; c1b1 (3:41b1)
ld [wTempPlayerYCoord], a
ld a, SOUTH
ld [wTempPlayerDirection], a
- call Func_c9cb
- call Func_c9dd
+ call ClearEvents
+ call DetermineImakuniAndChallengeHall
farcall Func_80b7a
- farcall Func_1c82e
+ farcall ClearMasterBeatenList
farcall Func_131b3
xor a
ld [wPlayTimeCounter + 0], a
@@ -252,9 +252,9 @@ Func_c1b1: ; c1b1 (3:41b1)
ret
Func_c1ed: ; c1ed (3:41ed)
- call Func_c9cb
- farcall Func_11416
- call Func_c9dd
+ call ClearEvents
+ farcall LoadBackupSaveData
+ call DetermineImakuniAndChallengeHall
ret
Func_c1f8: ; c1f8 (3:41f8)
@@ -266,7 +266,7 @@ Func_c1f8: ; c1f8 (3:41f8)
ld [wd0c2], a
ld [wDefaultSong], a
ld [wd112], a
- ld [wd3b8], a
+ ld [wRonaldIsInMap], a
call EnableSRAM
ld a, [sAnimationsDisabled]
ld [wAnimationsDisabled], a
@@ -409,7 +409,7 @@ Func_c2db: ; c2db (3:42db)
res 0, [hl]
call Func_c34e
farcall Func_12c5e
- farcall Func_1c6f8
+ farcall SetAllNPCTilePermissions
ld hl, wd0c1
res 7, [hl]
ld hl, wd10f
@@ -698,7 +698,7 @@ Func_c4b9: ; c4b9 (3:44b9)
xor a
ld [wVRAMTileOffset], a
ld [wd4cb], a
- ld a, $1d
+ ld a, PALETTE_29
farcall LoadPaletteData
ld b, $0
ld a, [wConsole]
@@ -759,7 +759,7 @@ HandlePlayerMoveMode: ; c510 (3:4510)
.not_moving
ldh a, [hKeysPressed]
and START
- call nz, OpenStartMenu
+ call nz, OpenPauseMenu
ret
Func_c53d: ; c53d (3:453d)
@@ -1104,18 +1104,18 @@ FindNPCOrObject: ; c71e (3:471e)
scf
ret
-OpenStartMenu: ; c74d (3:474d)
+OpenPauseMenu: ; c74d (3:474d)
push hl
push bc
push de
- call StartMenu
+ call PauseMenu
call CloseAdvancedDialogueBox
pop de
pop bc
pop hl
ret
-StartMenu: ; c75a (3:475a)
+PauseMenu: ; c75a (3:475a)
call PauseSong
ld a, MUSIC_PAUSE_MENU
call PlaySong
@@ -1148,7 +1148,7 @@ StartMenu: ; c75a (3:475a)
Func_c797: ; c797 (3:4797)
ld a, [wd0b8]
ld hl, Unknown_10d98
- farcall Func_111e9
+ farcall InitAndPrintPauseMenu
ret
PointerTable_c7a2: ; c7a2 (3:47a2)
@@ -1245,7 +1245,7 @@ PointerTable_c846: ; c846 (3:4846)
Func_c84e: ; c84e (3:484e)
ld a, [wd0b9]
ld hl, Unknown_10da9
- farcall Func_111e9
+ farcall InitAndPrintPauseMenu
ret
Func_c859: ; c859 (3:4859)
@@ -1430,7 +1430,7 @@ Func_c943: ; c943 (3:4943)
ld a, [wTempNPC]
farcall LoadNPCSpriteData
call Func_c998
- farcall Func_1c485
+ farcall LoadNPC
.next_npc
pop hl
ld bc, NPC_MAP_SIZE
@@ -1458,9 +1458,9 @@ Func_c998: ; c998 (3:4998)
ld b, $e
.not_cgb
ld a, b
- ld [wd3b1], a
+ ld [wNPCAnim], a
ld a, $0
- ld [wd3b2], a
+ ld [wNPCAnimFlags], a
ret
Func_c9b8: ; c9b8 (3:49b8)
@@ -1483,7 +1483,7 @@ Func_c9c7: ; c9c7 (3:49c7)
ld l, MAP_SCRIPT_CLOSE_TEXTBOX
jr CallMapScriptPointerIfExists
-Func_c9cb: ; c9cb (3:49cb)
+ClearEvents: ; c9cb (3:49cb)
push hl
push bc
ld hl, wEventVars
@@ -1500,11 +1500,11 @@ Func_c9cb: ; c9cb (3:49cb)
ret
; Clears temporary event vars before determining Imakuni Room
-Func_c9dd: ; c9dd (3:49dd)
+DetermineImakuniAndChallengeHall: ; c9dd (3:49dd)
xor a
ld [wEventVars + EVENT_VAR_BYTES - 1], a
call DetermineImakuniRoom
- call Func_ca0e
+ call DetermineChallengeHallEvent
ret
; Determines what room Imakuni is in when you reset
@@ -1535,7 +1535,7 @@ ImakuniPossibleRooms: ; ca0a (3:4a04)
db LIGHTNING_CLUB_LOBBY
db WATER_CLUB_LOBBY
-Func_ca0e: ; ca0e (3:4a0e)
+DetermineChallengeHallEvent: ; ca0e (3:4a0e)
ld a, [wOverworldMapSelection]
cp OWMAP_CHALLENGE_HALL
jr z, .done
@@ -2195,7 +2195,7 @@ ScriptCommand_UnloadActiveNPC: ; cdcb (3:4dcb)
ld a, [wScriptNPC]
ld [wLoadedNPCTempIndex], a
Func_cdd1: ; cdd1 (3:4dd1)
- farcall Func_1c50a
+ farcall UnloadNPC
jp IncreaseScriptPointerBy1
ScriptCommand_UnloadChallengeHallNPC: ; cdd8 (3:4dd8)
@@ -2228,7 +2228,7 @@ ScriptCommand_SetChallengeHallNPCCoords: ; cdf5 (3:4df5)
ld [wLoadNPCDirection], a
ld a, [wTempNPC]
farcall LoadNPCSpriteData
- farcall Func_1c485
+ farcall LoadNPC
pop af
ld [wTempNPC], a
pop af
@@ -2255,10 +2255,10 @@ ScriptCommand_MoveActiveNPCByDirection: ; ce26 (3:4e26)
; Moves an NPC given the list of directions pointed to by bc
; set bit 7 to only rotate the NPC
ExecuteNPCMovement: ; ce3a (3:4e3a)
- farcall Func_1c78d
+ farcall StartNPCMovement
.loop
call DoFrameIfLCDEnabled
- farcall Func_1c7de
+ farcall CheckIsAnNPCMoving
jr nz, .loop
jp IncreaseScriptPointerBy3
@@ -2376,7 +2376,7 @@ ScriptCommand_ShowCardReceivedScreen: ; cee2 (3:4ee2)
.show_card
push af
farcall Func_10000
- farcall Func_10031
+ farcall FlashWhiteScreen
pop af
bank1call Func_7594
call WhiteOutDMGPals
@@ -2656,9 +2656,9 @@ ScriptCommand_SetSpriteAttributes: ; d095 (3:5095)
push bc
call GetScriptArgs3AfterPointer
ld a, [wScriptNPC]
- ld l, LOADED_NPC_FIELD_05
+ ld l, LOADED_NPC_FLAGS
call GetItemInLoadedNPCIndex
- res 4, [hl]
+ res NPC_FLAG_DIRECTIONLESS_F, [hl]
ld a, [hl]
or c
ld [hl], a
@@ -2670,7 +2670,7 @@ ScriptCommand_SetSpriteAttributes: ; d095 (3:5095)
ld e, b
.not_cgb
ld a, e
- farcall Func_1c57b
+ farcall SetNPCAnimation
jp IncreaseScriptPointerBy4
ScriptCommand_SetActiveNPCCoords: ; d0be (3:50be)
@@ -2679,7 +2679,7 @@ ScriptCommand_SetActiveNPCCoords: ; d0be (3:50be)
ld a, c
ld c, b
ld b, a
- farcall Func_1c461
+ farcall SetNPCPosition
jp IncreaseScriptPointerBy3
ScriptCommand_DoFrames: ; d0ce (3:50ce)
@@ -2695,7 +2695,7 @@ ScriptCommand_JumpIfActiveNPCCoordsMatch: ; d0d9 (3:50d9)
ld [wLoadedNPCTempIndex], a
ld d, c
ld e, b
- farcall Func_1c477
+ farcall GetNPCPosition
ld a, e
cp c
jp nz, ScriptCommand_JumpIfEventEqual.fail
@@ -2817,7 +2817,7 @@ ScriptCommand_PickChallengeHallOpponent: ; d195 (3:5195)
jp IncreaseScriptPointerBy1
ScriptCommand_OpenMenu: ; d1ad (3:51ad)
- call StartMenu
+ call PauseMenu
jp IncreaseScriptPointerBy1
ScriptCommand_PickChallengeCupPrizeCard: ; d1b3 (3:51b3)
@@ -3025,7 +3025,7 @@ ShowMultichoiceTextbox: ; d28c (3:528c)
ld h, [hl]
ld l, a
ld a, [wd416]
- farcall Func_111e9
+ farcall InitAndPrintPauseMenu
pop hl
inc hl
ld a, [hli]
@@ -3181,7 +3181,7 @@ ScriptCommand_GiftCenter: ; d39d (3:539d)
jp IncreaseScriptPointerBy2
ScriptCommand_PlayCredits: ; d3b9 (3:53b9)
- call Func_3917
+ call GetReceivedLegendaryCards
ld a, GAME_EVENT_CREDITS
ld [wGameEvent], a
ld hl, wd0b4
@@ -3256,7 +3256,7 @@ ScriptCommand_WaitForSongToFinish: ; d42f (3:542f)
ScriptCommand_RecordMasterWin: ; d435 (3:5435)
ld a, c
- farcall Func_1c83d
+ farcall AddMasterBeatenToList
jp IncreaseScriptPointerBy2
ScriptCommand_ChallengeMachine: ; d43d (3:543d)
diff --git a/src/engine/bank04.asm b/src/engine/bank04.asm
index 38b1271..d1d6bfa 100644
--- a/src/engine/bank04.asm
+++ b/src/engine/bank04.asm
@@ -23,20 +23,24 @@ Func_10000: ; 10000 (4:4000)
ld [wVBlankOAMCopyToggle], a
ret
-Func_10031: ; 10031 (4:4031)
+; saves all pals to SRAM, then fills them with white.
+; after flushing, it loads back the saved pals from SRAM.
+FlashWhiteScreen: ; 10031 (4:4031)
ldh a, [hBankSRAM]
+
push af
- ld a, $1
+ ld a, BANK("SRAM1")
call BankswitchSRAM
- call Func_10cbb
+ call CopyPalsToSRAMBuffer
call DisableSRAM
call Func_10b28
call FlushAllPalettes
call EnableLCD
call DoFrameIfLCDEnabled
- call Func_10cea
+ call LoadPalsFromSRAMBuffer
call FlushAllPalettes
pop af
+
call BankswitchSRAM
call DisableSRAM
ret
@@ -51,7 +55,13 @@ Func_1010c: ; 1010c (4:410c)
INCROM $1010c, $10197
Func_10197: ; 10197 (4:4197)
- INCROM $10197, $1029e
+ INCROM $10197, $101df
+
+Func_101df: ; 101df (4:41df)
+ INCROM $101df, $1024f
+
+Func_1024f: ; 1024f (4:424f)
+ INCROM $1024f, $1029e
Medal_1029e: ; 1029e (4:429e)
sub $8
@@ -80,7 +90,7 @@ Medal_1029e: ; 1029e (4:429e)
ld [wTxRam2], a
ld a, [hl]
ld [wTxRam2 + 1], a
- call Func_10031
+ call FlashWhiteScreen
ld a, MUSIC_MEDAL
call PlaySong
ld a, $ff
@@ -148,7 +158,7 @@ GiveBoosterPack: ; 1031b (4:431b)
ld [wTxRam2], a
ld a, [hl]
ld [wTxRam2 + 1], a
- call Func_10031
+ call FlashWhiteScreen
call PauseSong
ld a, MUSIC_BOOSTER_PACK
call PlaySong
@@ -272,7 +282,7 @@ Duel_Init: ; 103d3 (4:43d3)
call Func_3e2a ; LoadDuelistPortrait
ld a, [wMatchStartTheme]
call PlaySong
- call Func_10031
+ call FlashWhiteScreen
call DoFrameIfLCDEnabled
lb bc, $2f, $1d ; cursor tile, tile behind cursor
lb de, 18, 17 ; x, y
@@ -285,10 +295,14 @@ Duel_Init: ; 103d3 (4:43d3)
ret
Unknown_10451: ; 10451 (4:4451)
- INCROM $10451, $10456
+ db 1, 14
+ tx Text0395
+ db $ff
Unknown_10456: ; 10456 (4:4456)
- INCROM $10456, $1045b
+ db 1, 16
+ tx Text0396
+ db $ff
Unknown_1045b: ; 1045b (4:445b)
INCROM $1045b, $1052f
@@ -311,7 +325,7 @@ TryGivePCPack: ; 10a70 (4:4a70)
push bc
push de
ld b, a
- ld c, $f ; number of packs possible
+ ld c, NUM_PC_PACKS
ld hl, wPCPacks
.searchLoop1
ld a, [hli]
@@ -320,7 +334,7 @@ TryGivePCPack: ; 10a70 (4:4a70)
jr z, .quit
dec c
jr nz, .searchLoop1
- ld c, $f
+ ld c, NUM_PC_PACKS
ld hl, wPCPacks
.findFreeSlotLoop
ld a, [hl]
@@ -334,7 +348,7 @@ TryGivePCPack: ; 10a70 (4:4a70)
.foundFreeSlot
ld a, b
- or $80 ; mark pack as unopened
+ or PACK_OPENED ; mark pack as unopened
ld [hl], a
.quit
@@ -343,17 +357,400 @@ TryGivePCPack: ; 10a70 (4:4a70)
pop hl
ret
+; writes wd293 with byte depending on console
+; every entry in the list is $00
Func_10a9b: ; 10a9b (4:4a9b)
- INCROM $10a9b, $10ab4
+ push hl
+ ld a, [wConsole]
+ add LOW(.data_10ab1)
+ ld l, a
+ ld a, HIGH(.data_10ab1)
+ adc $00
+ ld h, a
+ ld a, [hl]
+ ld [wd293], a
+ xor a
+ ld [wd317], a
+ pop hl
+ ret
+
+.data_10ab1
+ db $00 ; CONSOLE_DMG
+ db $00 ; CONSOLE_SGB
+ db $00 ; CONSOLE_CGB
+; 0x10ab4
Func_10ab4: ; 10ab4 (4:4ab4)
- INCROM $10ab4, $10af9
+ ld a, [wLCDC]
+ bit 7, a
+ jr z, .lcd_off
+ ld a, [wd293]
+ ld [wd294], a
+ ld [wd295], a
+ ld [wd296], a
+ ld de, PALRGB_WHITE
+ ld hl, wTempBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes
+ call FillMemoryWithDE
+ call RestoreFirstColorInOBPals
+ call FadeScreenToTempPals
+ call DisableLCD
+ ret
+
+.lcd_off
+ ld a, [wd293]
+ ld [wBGP], a
+ ld [wOBP0], a
+ ld [wOBP1], a
+ ld de, PALRGB_WHITE
+ ld hl, wBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes
+ call FillMemoryWithDE
+ call FlushAllPalettes
+ ret
+; 0x10af9
Func_10af9: ; 10af9 (4:4af9)
- INCROM $10af9, $10b28
+ call BackupPalsAndSetWhite
+ call RestoreFirstColorInOBPals
+ call FlushAllPalettes
+ call EnableLCD
+ jp FadeScreenToTempPals
+; 0x10b08
+
+BackupPalsAndSetWhite: ; 10b08 (4:4b08)
+ ld a, [wBGP]
+ ld [wd294], a
+ ld a, [wOBP0]
+ ld [wd295], a
+ ld a, [wOBP1]
+ ld [wd296], a
+ ld hl, wBackgroundPalettesCGB
+ ld de, wTempBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes + NUM_OBJECT_PALETTES palettes
+ call CopyDataHLtoDE_SaveRegisters
+ jr Func_10b28 ; can be fallthrough
+; fills wBackgroundPalettesCGB with white pal
Func_10b28: ; 10b28 (4:4b28)
- INCROM $10b28, $10c96
+ ld a, [wd293]
+ ld [wBGP], a
+ ld [wOBP0], a
+ ld [wOBP1], a
+ ld de, PALRGB_WHITE
+ ld hl, wBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes
+ call FillMemoryWithDE
+ ret
+; 0x10b41
+
+; gets from backup OB pals the first color
+; of each pal and writes them in wObjectPalettesCGB
+RestoreFirstColorInOBPals: ; 10b41 (4:4b41)
+ ld hl, wTempObjectPalettesCGB
+ ld de, wObjectPalettesCGB
+ ld c, NUM_OBJECT_PALETTES
+.loop_pals
+ push bc
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld a, [hl]
+ ld [de], a
+ ld bc, CGB_PAL_SIZE - 1
+ add hl, bc
+ ld a, c
+ add e
+ ld e, a
+ ld a, b
+ adc d
+ ld d, a
+ pop bc
+ dec c
+ jr nz, .loop_pals
+ ret
+; 0x10b5e
+
+FadeScreenToTempPals: ; 10b5e (4:4b5e)
+ ld a, [wVBlankCounter]
+ push af
+ ld c, $10
+.loop
+ push bc
+ ld a, c
+ and %11
+ cp 0
+ call z, Func_10b85
+ call FadeBGPalIntoTemp3
+ call FadeOBPalIntoTemp
+ call FlushAllPalettes
+ call DoFrameIfLCDEnabled
+ pop bc
+ dec c
+ dec c
+ jr nz, .loop
+ pop af
+ ld b, a
+ ld a, [wVBlankCounter]
+ sub b
+ ret
+; 0x10b85
+
+; does something with wBGP given wd294
+; mixes them into a single value?
+Func_10b85: ; 10b85 (4:4b85)
+ push bc
+ ld c, $03
+ ld hl, wBGP
+ ld de, wd294
+.asm_10b8e
+ push bc
+ ld b, [hl]
+ ld a, [de]
+ ld c, a
+ call .Func_10b9e
+ ld [hl], a
+ pop bc
+ inc de
+ inc hl
+ dec c
+ jr nz, .asm_10b8e
+ pop bc
+ ret
+
+.Func_10b9e
+ push bc
+ push de
+ ld e, 4
+ ld d, $00
+.loop
+ call .Func_10bba
+ or d
+ rlca
+ rlca
+ ld d, a
+ rlc b
+ rlc b
+ rlc c
+ rlc c
+ dec e
+ jr nz, .loop
+ ld a, d
+ pop de
+ pop bc
+ ret
+
+; calculates ((b & %11) << 2) | (c & %11)
+; that is, %0000xxyy, where x and y are
+; the 2 lower bits of b and c respectively
+; and outputs the entry from a table given that value
+.Func_10bba
+ push hl
+ push bc
+ ld a, %11
+ and b
+ add a
+ add a
+ ld b, a
+ ld a, %11
+ and c
+ or b
+ ld c, a
+ ld b, $00
+ ld hl, .data_10bd1
+ add hl, bc
+ ld a, [hl]
+ pop bc
+ pop hl
+ ret
+
+.data_10bd1
+ db %00 ; b = %00 | c = %00
+ db %01 ; b = %00 | c = %01
+ db %01 ; b = %00 | c = %10
+ db %01 ; b = %00 | c = %11
+ db %00 ; b = %01 | c = %00
+ db %01 ; b = %01 | c = %01
+ db %10 ; b = %01 | c = %10
+ db %10 ; b = %01 | c = %11
+ db %01 ; b = %10 | c = %00
+ db %01 ; b = %10 | c = %01
+ db %10 ; b = %10 | c = %10
+ db %11 ; b = %10 | c = %11
+ db %10 ; b = %11 | c = %00
+ db %10 ; b = %11 | c = %01
+ db %10 ; b = %11 | c = %10
+ db %11 ; b = %11 | c = %11
+; 0x10be1
+
+FadeOBPalIntoTemp: ; 10be1 (4:4be1)
+ push bc
+ ld c, 4 palettes
+ ld hl, wObjectPalettesCGB
+ ld de, wTempObjectPalettesCGB
+ jr FadePalIntoAnother
+; 0x10bec
+
+FadeBGPalIntoTemp1: ; 10bec (4:4bec)
+ push bc
+ ld c, 2 palettes
+ ld hl, wBackgroundPalettesCGB
+ ld de, wTempBackgroundPalettesCGB
+ jr FadePalIntoAnother
+
+FadeBGPalIntoTemp2: ; 10bf7 (4:4bf7)
+ push bc
+ ld c, 2 palettes
+ ld hl, wBackgroundPalettesCGB + 4 palettes
+ ld de, wTempBackgroundPalettesCGB + 4 palettes
+ jr FadePalIntoAnother
+
+FadeBGPalIntoTemp3: ; 10c02 (4:4c02)
+ push bc
+ ld c, 4 palettes
+ ld hl, wBackgroundPalettesCGB
+ ld de, wTempBackgroundPalettesCGB
+; fallthrough
+
+; hl = input pal to modify
+; de = pal to fade into
+; c = number of colors to fade
+FadePalIntoAnother: ; 10c0b (4:4c0b)
+ push bc
+ ld a, [de]
+ inc de
+ ld c, a
+ ld a, [de]
+ inc de
+ ld b, a
+ push de
+ push bc
+ ld c, [hl]
+ inc hl
+ ld b, [hl]
+ pop de
+ call .GetFadedColor
+ ; overwrite with new color
+ ld [hld], a
+ ld [hl], c
+ inc hl
+ inc hl
+ pop de
+ pop bc
+ dec c
+ jr nz, FadePalIntoAnother
+ pop bc
+ ret
+
+; fade pal bc to de
+; output resulting pal in a and c
+.GetFadedColor
+ push hl
+ ld a, c
+ cp e
+ jr nz, .unequal
+ ld a, b
+ cp d
+ jr z, .skip
+
+.unequal
+ ; red
+ ld a, e
+ and %11111
+ ld l, a
+ ld a, c
+ and %11111
+ call .FadeColor
+ ldh [hffb6], a
+
+ ; green
+ ld a, e
+ and %11100000
+ ld l, a
+ ld a, d
+ and %11
+ or l
+ swap a
+ rrca
+ ld l, a
+ ld a, c
+ and %11100000
+ ld h, a
+ ld a, b
+ and %11
+ or h
+ swap a
+ rrca
+ call .FadeColor
+ rlca
+ swap a
+ ld h, a
+ and %11
+ ldh [hffb7], a
+ ld a, %11100000
+ and h
+ ld h, a
+ ldh a, [hffb6]
+ or h
+ ld h, a
+
+ ; blue
+ ld a, d
+ and %1111100
+ rrca
+ rrca
+ ld l, a
+ ld a, b
+ and %1111100
+ rrca
+ rrca
+ call .FadeColor
+ rlca
+ rlca
+ ld b, a
+ ldh a, [hffb7]
+ or b
+ ld c, h
+.skip
+ pop hl
+ ret
+
+; compares color in a and in l
+; if a is smaller/greater than l, then
+; increase/decrease its value up to l
+; up to a maximum of 4
+; a = pal color (red, green or blue)
+; l = pal color (red, green or blue)
+.FadeColor
+ cp l
+ ret z ; same value
+ jr c, .incr_a
+; decr a
+ dec a
+ cp l
+ ret z
+ dec a
+ cp l
+ ret z
+ dec a
+ cp l
+ ret z
+ dec a
+ ret
+
+.incr_a
+ inc a
+ cp l
+ ret z
+ inc a
+ cp l
+ ret z
+ inc a
+ cp l
+ ret z
+ inc a
+ ret
+; 0x10c96
Func_10c96: ; 10c96 (4:4c96)
ldh a, [hBankSRAM]
@@ -361,13 +758,13 @@ Func_10c96: ; 10c96 (4:4c96)
push bc
ld a, $1
call BankswitchSRAM
- call Func_10cbb
+ call CopyPalsToSRAMBuffer
call Func_10ab4
pop bc
ld a, c
or a
jr nz, .asm_10cb0
- call Func_10cea
+ call LoadPalsFromSRAMBuffer
call Func_10af9
.asm_10cb0
@@ -377,11 +774,137 @@ Func_10c96: ; 10c96 (4:4c96)
call DisableSRAM
ret
-Func_10cbb: ; 10cbb (4:4cbb)
- INCROM $10cbb, $10cea
+; copies current BG and OP pals,
+; wBackgroundPalettesCGB and wObjectPalettesCGB
+; to sGfxBuffer2
+CopyPalsToSRAMBuffer: ; 10cbb (4:4cbb)
+ ldh a, [hBankSRAM]
+
+ push af
+ cp BANK("SRAM1")
+ jr z, .ok
+ debug_nop
+.ok
+ ld a, BANK("SRAM1")
+ call BankswitchSRAM
+ ld hl, sGfxBuffer2
+ ld a, [wBGP]
+ ld [hli], a
+ ld a, [wOBP0]
+ ld [hli], a
+ ld a, [wOBP1]
+ ld [hli], a
+ ld e, l
+ ld d, h
+ ld hl, wBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes + NUM_OBJECT_PALETTES palettes
+ call CopyDataHLtoDE_SaveRegisters
+ pop af
+
+ call BankswitchSRAM
+ call DisableSRAM
+ ret
+; 0x10cea
+
+; loads BG and OP pals,
+; wBackgroundPalettesCGB and wObjectPalettesCGB
+; from sGfxBuffer2
+LoadPalsFromSRAMBuffer: ; 10cea (4:4cea)
+ ldh a, [hBankSRAM]
+
+ push af
+ cp BANK("SRAM1")
+ jr z, .ok
+ debug_nop
+.ok
+ ld a, BANK("SRAM1")
+ call BankswitchSRAM
+ ld hl, sGfxBuffer2
+ ld a, [hli]
+ ld [wBGP], a
+ ld a, [hli]
+ ld [wOBP0], a
+ ld a, [hli]
+ ld [wOBP1], a
+ ld de, wBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes + NUM_OBJECT_PALETTES palettes
+ call CopyDataHLtoDE_SaveRegisters
+ pop af
+
+ call BankswitchSRAM
+ call DisableSRAM
+ ret
+; 0x10d17
+
+; backs up all palettes
+; and writes 4 BG pals with white pal
+Func_10d17: ; 10d17 (4:4d17)
+ ld a, [wBGP]
+ ld [wd294], a
+ ld a, [wOBP0]
+ ld [wd295], a
+ ld a, [wOBP1]
+ ld [wd296], a
+ ld hl, wBackgroundPalettesCGB
+ ld de, wTempBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes + NUM_OBJECT_PALETTES palettes
+ call CopyDataHLtoDE_SaveRegisters
+
+ ld a, [wd293]
+ ld [wBGP], a
+ ld de, PALRGB_WHITE
+ ld hl, wBackgroundPalettesCGB
+ ld bc, 4 palettes
+ call FillMemoryWithDE
+ call FlushAllPalettes
-Func_10cea: ; 10cea (4:4cea)
- INCROM $10cea, $10d98
+ ld a, $10
+ ld [wd317], a
+ ret
+; 0x10d50
+
+Func_10d50: ; 10d50 (4:4d50)
+ ld a, [wd293]
+ ld [wd294], a
+ ld a, [wOBP0]
+ ld [wd295], a
+ ld a, [wOBP1]
+ ld [wd296], a
+ ld de, PALRGB_WHITE
+ ld hl, wTempBackgroundPalettesCGB
+ ld bc, 4 palettes
+ call FillMemoryWithDE
+ ld a, $10
+ ld [wd317], a
+ ret
+; 0x10d74
+
+; does stuff according to bottom 2 bits from wd317:
+; - if equal to %01, modify wBGP
+; - if bottom bit not set, fade BG pals 0 and 1
+; - if bottom bit is set, fade BG pals 4 and 5
+; and Flush Palettes
+; then decrements wd317
+; does nothing if wd317 is 0
+Func_10d74: ; 10d74 (4:4d74)
+ ld a, [wd317]
+ or a
+ ret z
+ and %11
+ ld c, a
+ cp $1
+ call z, Func_10b85
+ bit 0, c
+ call z, FadeBGPalIntoTemp1
+ bit 0, c
+ call nz, FadeBGPalIntoTemp2
+ bit 0, c
+ call nz, FlushAllPalettes
+ ld a, [wd317]
+ dec a
+ ld [wd317], a
+ ret
+; 0x10d98
Unknown_10d98: ; 10d98 (4:4d98)
INCROM $10d98, $10da9
@@ -394,7 +917,7 @@ Func_10dba: ; 10dba (4:4dba)
farcall Func_c29b
ld a, [wd0ba]
ld hl, Unknown_10e17
- farcall Func_111e9
+ farcall InitAndPrintPauseMenu
.asm_10dca
call DoFrameIfLCDEnabled
call HandleMenuInput
@@ -1079,17 +1602,153 @@ OverworldMap_ContinuePlayerWalkingAnimation: ; 11184 (4:5184)
dec [hl]
ret
+; prints $ff-terminated list of text to text box
+; given 2 bytes for text alignment and 2 bytes for text ID
Func_111b3: ; 111b3 (4:51b3)
- INCROM $111b3, $111e9
+ ldh a, [hffb0]
+ push af
+ ld a, $02
+ ldh [hffb0], a
-Func_111e9: ; 111e9 (4:51e9)
- INCROM $111e9, $11238
+ push hl
+.loop_text_print_1
+ ld d, [hl]
+ inc hl
+ bit 7, d
+ jr nz, .next
+ inc hl
+ ld a, [hli]
+ push hl
+ ld h, [hl]
+ ld l, a
+ call PrintTextNoDelay
+ pop hl
+ inc hl
+ jr .loop_text_print_1
-Func_11238: ; 11238 (4:5238)
- INCROM $11238, $1124d
+.next
+ pop hl
+ pop af
+ ldh [hffb0], a
+.loop_text_print_2
+ ld d, [hl]
+ inc hl
+ bit 7, d
+ ret nz
+ ld e, [hl]
+ inc hl
+ call AdjustCoordinatesForBGScroll
+ call InitTextPrinting
+ ld a, [hli]
+ push hl
+ ld h, [hl]
+ ld l, a
+ call PrintTextNoDelay
+ pop hl
+ inc hl
+ jr .loop_text_print_2
+; 0x111e9
-Func_1124d: ; 1124d (4:524d)
- INCROM $1124d, $1127f
+InitAndPrintPauseMenu: ; 111e9 (4:51e9)
+ push hl
+ push bc
+ push de
+ push af
+ ld d, [hl]
+ inc hl
+ ld e, [hl]
+ inc hl
+ ld b, [hl]
+ inc hl
+ ld c, [hl]
+ inc hl
+ push hl
+ call AdjustCoordinatesForBGScroll
+ farcall Func_c3ca
+ call DrawRegularTextBox
+ call DoFrameIfLCDEnabled
+ pop hl
+ call Func_111b3
+ pop af
+ call InitializeMenuParameters
+ pop de
+ pop bc
+ pop hl
+ ret
+; 0x1120f
+
+; xors sb800
+; this has the effect of invalidating the save data checksum
+; which the game interprets as being having no save data
+InvalidateSaveData: ; 1120f (4:520f)
+ push hl
+ ldh a, [hBankSRAM]
+
+ push af
+ ld a, $02
+ call BankswitchSRAM
+ ld a, $08
+ xor $ff
+ ld [sb800 + 0], a
+ ld a, $00
+ xor $ff
+ ld [sb800 + 1], a
+ pop af
+
+ call BankswitchSRAM
+ call DisableSRAM
+ call EnableSRAM
+ bank1call DiscardSavedDuelData
+ call DisableSRAM
+ pop hl
+ ret
+; 0x11238
+
+; saves all data to SRAM, including
+; General save data and Album/Deck data
+; and backs up in SRAM2
+SaveAndBackupData: ; 11238 (4:5238)
+ push de
+ ld de, sGeneralSaveData
+ call SaveGeneralSaveDataFromDE
+ ld de, sAlbumProgress
+ call UpdateAlbumProgress
+ call WriteBackupGeneralSaveData
+ call WriteBackupCardAndDeckSaveData
+ pop de
+ ret
+; 0x1124d
+
+_SaveGeneralSaveData: ; 1124d (4:524d)
+ push de
+ call GetReceivedLegendaryCards
+ ld de, sGeneralSaveData
+ call SaveGeneralSaveDataFromDE
+ ld de, sAlbumProgress
+ call UpdateAlbumProgress
+ pop de
+ ret
+; 0x1125f
+
+; de = pointer to general game data in SRAM
+SaveGeneralSaveDataFromDE: ; 1125f (4:525f)
+ push hl
+ push bc
+ call EnableSRAM
+ push de
+ farcall TryGiveMedalPCPacks
+ ld [wMedalCount], a
+ farcall OverworldMap_GetOWMapID
+ ld [wCurOverworldMap], a
+ pop de
+ push de
+ call CopyGeneralSaveDataToSRAM
+ pop de
+ call DisableSRAM
+ pop bc
+ pop hl
+ ret
+; 0x1127f
; writes in de total num of cards collected
; and in (de + 1) total num of cards to collect
@@ -1113,45 +1772,324 @@ UpdateAlbumProgress: ; 1127f (4:527f)
ret
; 0x11299
- INCROM $11299, $11320
+; save values that are listed in WRAMToSRAMMapper
+; from WRAM to SRAM, and calculate its checksum
+CopyGeneralSaveDataToSRAM: ; 11299 (4:5299)
+ push hl
+ push bc
+ push de
+ push de
+ ld hl, sGeneralSaveDataHeaderEnd - sGeneralSaveData
+ add hl, de
+ ld e, l
+ ld d, h
+ xor a
+ ld [wGeneralSaveDataByteCount + 0], a
+ ld [wGeneralSaveDataByteCount + 1], a
+ ld [wGeneralSaveDataCheckSum + 0], a
+ ld [wGeneralSaveDataCheckSum + 1], a
+
+ ld hl, WRAMToSRAMMapper
+.loop_map
+ ld a, [hli]
+ ld [wTempPointer + 0], a
+ ld c, a
+ ld a, [hli]
+ ld [wTempPointer + 1], a
+ or c
+ jr z, .done_copy
+ ld a, [hli]
+ ld c, a ; number of bytes LO
+ ld a, [hli]
+ ld b, a ; number of bytes HI
+ ld a, [wGeneralSaveDataByteCount + 0]
+ add c
+ ld [wGeneralSaveDataByteCount + 0], a
+ ld a, [wGeneralSaveDataByteCount + 1]
+ adc b
+ ld [wGeneralSaveDataByteCount + 1], a
+ call .CopyBytesToSRAM
+ inc hl
+ inc hl
+ jr .loop_map
-Func_11320: ; 11320 (4:5320)
- INCROM $11320, $11343
+.done_copy
+ pop hl
+ ld a, $08
+ ld [hli], a
+ ld a, $00
+ ld [hli], a
+ ld a, [wGeneralSaveDataByteCount + 0]
+ ld [hli], a
+ ld a, [wGeneralSaveDataByteCount + 1]
+ ld [hli], a
+ ld a, [wGeneralSaveDataCheckSum + 0]
+ ld [hli], a
+ ld a, [wGeneralSaveDataCheckSum + 1]
+ ld [hli], a
+ pop de
+ pop bc
+ pop hl
+ ret
-Func_11343: ; 11343 (4:5343)
- INCROM $11343, $11416
+.CopyBytesToSRAM
+ push hl
+ ld a, [wTempPointer + 0]
+ ld l, a
+ ld a, [wTempPointer + 1]
+ ld h, a
+.loop_bytes
+ push bc
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld c, a
+ ld a, [wGeneralSaveDataCheckSum + 0]
+ add c
+ ld [wGeneralSaveDataCheckSum + 0], a
+ ld a, [wGeneralSaveDataCheckSum + 1]
+ adc 0
+ ld [wGeneralSaveDataCheckSum + 1], a
+ pop bc
+ dec bc
+ ld a, c
+ or b
+ jr nz, .loop_bytes
+ ld a, l
+ ld [wTempPointer + 0], a
+ ld a, h
+ ld [wTempPointer + 1], a
+ pop hl
+ ret
+; 0x11320
-Func_11416: ; 11416 (4:5416)
- INCROM $11416, $11430
+; returns carry if no error
+; is found in sBackupGeneralSaveData
+ValidateBackupGeneralSaveData: ; 11320 (4:5320)
+ push de
+ ldh a, [hBankSRAM]
+ push af
+ ld a, BANK(sBackupGeneralSaveData)
+ call BankswitchSRAM
+ ld de, sBackupGeneralSaveData
+ call ValidateGeneralSaveDataFromDE
+ ld de, sAlbumProgress
+ call LoadAlbumProgressFromSRAM
+ pop af
+ call BankswitchSRAM
+ call DisableSRAM
+ pop de
+ ld a, [wNumSRAMValidationErrors]
+ cp 1
+ ret
+; 0x11343
-Func_11430: ; 11430 (4:5430)
+; returns carry if no error
+; is found in sGeneralSaveData
+_ValidateGeneralSaveData: ; 11343 (4:5343)
push de
- ld de, sb800
- call .Func_11439
+ call EnableSRAM
+ ld de, sGeneralSaveData
+ call ValidateGeneralSaveDataFromDE
+ ld de, sAlbumProgress
+ call LoadAlbumProgressFromSRAM
+ call DisableSRAM
pop de
+ ld a, [wNumSRAMValidationErrors]
+ cp 1
ret
+; 0x1135d
-.Func_11439
+; validates the general game data saved in SRAM
+; de = pointer to general game data in SRAM
+ValidateGeneralSaveDataFromDE: ; 1135d (4:535d)
push hl
push bc
+ push de
+ xor a
+ ld [wNumSRAMValidationErrors], a
+ push de
+
+ push de
+ inc de
+ inc de
+ ld a, [de]
+ inc de
+ ld [wGeneralSaveDataByteCount + 0], a
+ ld a, [de]
+ inc de
+ ld [wGeneralSaveDataByteCount + 1], a
+ ld a, [de]
+ inc de
+ ld [wGeneralSaveDataCheckSum + 0], a
+ ld a, [de]
+ inc de
+ ld [wGeneralSaveDataCheckSum + 1], a
+ pop de
+
+ ld hl, sGeneralSaveDataHeaderEnd - sGeneralSaveData
+ add hl, de
+ ld e, l
+ ld d, h
+ ld hl, WRAMToSRAMMapper
+.loop
+ ld a, [hli]
+ ld c, a
+ ld a, [hli]
+ or c
+ jr z, .exit_loop
+ ld a, [hli]
+ ld c, a ; number of bytes LO
+ ld a, [hli]
+ ld b, a ; number of bytes HI
+ ld a, [wGeneralSaveDataByteCount + 0]
+ sub c
+ ld [wGeneralSaveDataByteCount + 0], a
+ ld a, [wGeneralSaveDataByteCount + 1]
+ sbc b
+ ld [wGeneralSaveDataByteCount + 1], a
+
+; loop all the bytes of this struct
+.loop_bytes
+ push hl
+ push bc
+ ld a, [de]
+ push af
+ ld c, a
+ ld a, [wGeneralSaveDataCheckSum + 0]
+ sub c
+ ld [wGeneralSaveDataCheckSum + 0], a
+ ld a, [wGeneralSaveDataCheckSum + 1]
+ sbc 0
+ ld [wGeneralSaveDataCheckSum + 1], a
+ pop af
+
+ ; check if it's within the specified values
+ cp [hl] ; min value
+ jr c, .error
+ inc hl
+ cp [hl] ; max value
+ jr z, .next_byte
+ jr c, .next_byte
+.error
+ ld a, [wNumSRAMValidationErrors]
+ inc a
+ ld [wNumSRAMValidationErrors], a
+.next_byte
+ inc de
+ pop bc
+ pop hl
+ dec bc
+ ld a, c
+ or b
+ jr nz, .loop_bytes
+ ; next mapped struct
+ inc hl
+ inc hl
+ jr .loop
+
+.exit_loop
+ pop hl
+ ld a, [hli]
+ sub $8
+ ld c, a
+ ld a, [hl]
+ sub 0
+ or c
+ ld hl, wGeneralSaveDataByteCount
+ or [hl]
+ inc hl
+ or [hl]
+ ld hl, wGeneralSaveDataCheckSum
+ or [hl]
+ inc hl
+ or [hl]
+ jr z, .no_header_error
+ ld hl, wNumSRAMValidationErrors
+ inc [hl]
+.no_header_error
+ pop de
+ ; copy play time minutes and hours
+ ld hl, (sPlayTimeCounter + 2) - sGeneralSaveData
+ add hl, de
+ ld a, [hli]
+ ld [wPlayTimeHourMinutes + 0], a
+ ld a, [hli]
+ ld [wPlayTimeHourMinutes + 1], a
+ ld a, [hli]
+ ld [wPlayTimeHourMinutes + 2], a
+
+ ; copy medal count and current overworld map
+ ld hl, sGeneralSaveDataHeaderEnd - sGeneralSaveData
+ add hl, de
+ ld a, [hli]
+ ld [wMedalCount], a
+ ld a, [hl]
+ ld [wCurOverworldMap], a
+ pop bc
+ pop hl
+ ret
+; 0x1140a
+
+LoadAlbumProgressFromSRAM: ; 1140a (4:540a)
+ push de
+ ld a, [de]
+ ld [wTotalNumCardsCollected], a
+ inc de
+ ld a, [de]
+ ld [wTotalNumCardsToCollect], a
+ pop de
+ ret
+; 0x11416
+
+; first copies data from backup SRAM to main SRAM
+; then loads it to WRAM from main SRAM
+LoadBackupSaveData: ; 11416 (4:5416)
+ push hl
+ push de
call EnableSRAM
- call .Func_11447
+ bank1call DiscardSavedDuelData
+ call DisableSRAM
+ call LoadBackupGeneralSaveData
+ call LoadBackupCardAndDeckSaveData
+ ld de, sGeneralSaveData
+ call LoadGeneralSaveDataFromDE
+ pop de
+ pop hl
+ ret
+; 0x11430
+
+_LoadGeneralSaveData: ; 11430 (4:5430)
+ push de
+ ld de, sGeneralSaveData
+ call LoadGeneralSaveDataFromDE
+ pop de
+ ret
+; 0x11439
+
+; de = pointer to save data
+LoadGeneralSaveDataFromDE: ; 11439 (4:5439)
+ push hl
+ push bc
+ call EnableSRAM
+ call .LoadData
call DisableSRAM
pop bc
pop hl
ret
-.Func_11447
+.LoadData
push hl
push bc
push de
ld a, e
- add $08
- ld [wTempPointer], a
+ add sGeneralSaveDataHeaderEnd - sGeneralSaveData
+ ld [wTempPointer + 0], a
ld a, d
adc 0
ld [wTempPointer + 1], a
- ld hl, .wram_map
+
+ ld hl, WRAMToSRAMMapper
.asm_11459
ld a, [hli]
ld e, a
@@ -1166,7 +2104,7 @@ Func_11430: ; 11430 (4:5430)
; copy bc bytes from wTempPointer to de
push hl
- ld a, [wTempPointer]
+ ld a, [wTempPointer + 0]
ld l, a
ld a, [wTempPointer + 1]
ld h, a
@@ -1180,7 +2118,7 @@ Func_11430: ; 11430 (4:5430)
jr nz, .loop_copy
ld a, l
- ld [wTempPointer], a
+ ld [wTempPointer + 0], a
ld a, h
ld [wTempPointer + 1], a
pop hl
@@ -1199,48 +2137,61 @@ Func_11430: ; 11430 (4:5430)
pop bc
pop hl
ret
-
-.wram_map
+; 0x11498
+
+wram_sram_map: MACRO
+ dw \1 ; WRAM address
+ dw \2 ; number of bytes
+ db \3 ; min allowed value
+ db \4 ; max allowed value
+ENDM
+
+; maps WRAM addresses to SRAM addresses in order
+; to save and subsequently retreive them on game load
+; also works as a test in order check whether
+; the saved values is SRAM are legal, within the given value range
+WRAMToSRAMMapper: ; 11498 (4:5498)
; pointer, number of bytes, unknown
- dw wd3cc, 1, $ff00 ; sb808
- dw wd3cb, 1, $ff00 ; sb809
- dw wPlayTimeCounter + 0, 1, $ff00 ; sPlayTimeCounter
- dw wPlayTimeCounter + 1, 1, $ff00
- dw wPlayTimeCounter + 2, 1, $ff00
- dw wPlayTimeCounter + 3, 2, $ff00
- dw wOverworldMapSelection, 1, $ff00 ; sOverworldMapSelection
- dw wTempMap, 1, $ff00 ; sTempMap
- dw wTempPlayerXCoord, 1, $ff00 ; sTempPlayerXCoord
- dw wTempPlayerYCoord, 1, $ff00 ; sTempPlayerYCoord
- dw wTempPlayerDirection, 1, $ff00 ; sTempPlayerDirection
- dw wd0c2, 1, $ff00 ; sb814
- dw wDuelResult, 1, $ff00 ; sDuelResult
- dw wNPCDuelist, 1, $ff00 ; sNPCDuelist
- dw wChallengeHallNPC, 1, $ff00 ; sChallengeHallNPC
- dw wd698, 4, $ff00 ; sb818
- dw wOWMapEvents, 11, $ff00 ; sOWMapEvents
- dw Data_1156c, 1, $ff00 ; sb827
- dw wd0b8, 1, $ff00 ; sb828
- dw wd0b9, 1, $ff00 ; sb829
- dw wd11b, 1, $ff00 ; sb82a
- dw wd0ba, 1, $ff00 ; sb82b
- dw wPCPackSelection, 1, $0e00 ; sPCPackSelection
- dw wPCPacks, 15, $ff00 ; sPCPacks
- dw wDefaultSong, 1, $ff00 ; sDefaultSong
- dw wcad5, 1, $ff00 ; sb83d
- dw wd3b8, 1, $ff00 ; sb83e
- dw wd3bb, 10, $ff00 ; sb83f
- dw wd0c5, 1, $ff00 ; sb849
- dw wMultichoiceTextboxResult_ChooseDeckToDuelAgainst, 1, $ff00 ; sMultichoiceTextboxResult_ChooseDeckToDuelAgainst
- dw wd10e, 1, $ff00 ; sb84b
- dw Data_1156c, 15, $ff00 ; sb84c
- dw Data_1156c, 16, $ff00 ; sb85b
- dw Data_1156c, 16, $ff00 ; sb86b
- dw wEventVars, 64, $ff00 ; sEventVars
+ wram_sram_map wMedalCount, 1, $00, $ff ; sMedalCount
+ wram_sram_map wCurOverworldMap, 1, $00, $ff ; sCurOverworldMap
+ wram_sram_map wPlayTimeCounter + 0, 1, $00, $ff ; sPlayTimeCounter
+ wram_sram_map wPlayTimeCounter + 1, 1, $00, $ff
+ wram_sram_map wPlayTimeCounter + 2, 1, $00, $ff
+ wram_sram_map wPlayTimeCounter + 3, 2, $00, $ff
+ wram_sram_map wOverworldMapSelection, 1, $00, $ff ; sOverworldMapSelection
+ wram_sram_map wTempMap, 1, $00, $ff ; sTempMap
+ wram_sram_map wTempPlayerXCoord, 1, $00, $ff ; sTempPlayerXCoord
+ wram_sram_map wTempPlayerYCoord, 1, $00, $ff ; sTempPlayerYCoord
+ wram_sram_map wTempPlayerDirection, 1, $00, $ff ; sTempPlayerDirection
+ wram_sram_map wd0c2, 1, $00, $ff ; sb814
+ wram_sram_map wDuelResult, 1, $00, $ff ; sDuelResult
+ wram_sram_map wNPCDuelist, 1, $00, $ff ; sNPCDuelist
+ wram_sram_map wChallengeHallNPC, 1, $00, $ff ; sChallengeHallNPC
+ wram_sram_map wd698, 4, $00, $ff ; sb818
+ wram_sram_map wOWMapEvents, NUM_MAP_EVENTS, $00, $ff ; sOWMapEvents
+ wram_sram_map .EmptySRAMSlot, 1, $00, $ff ; sb827
+ wram_sram_map wd0b8, 1, $00, $ff ; sb828
+ wram_sram_map wd0b9, 1, $00, $ff ; sb829
+ wram_sram_map wd11b, 1, $00, $ff ; sb82a
+ wram_sram_map wd0ba, 1, $00, $ff ; sb82b
+ wram_sram_map wPCPackSelection, 1, 0, 14 ; sPCPackSelection
+ wram_sram_map wPCPacks, NUM_PC_PACKS, $00, $ff ; sPCPacks
+ wram_sram_map wDefaultSong, 1, $00, $ff ; sDefaultSong
+ wram_sram_map wcad5, 1, $00, $ff ; sb83d
+ wram_sram_map wRonaldIsInMap, 1, $00, $ff ; sRonaldIsInMap
+ wram_sram_map wMastersBeatenList, 10, $00, $ff ; sMastersBeatenList
+ wram_sram_map wd0c5, 1, $00, $ff ; sb849
+ wram_sram_map wMultichoiceTextboxResult_ChooseDeckToDuelAgainst, 1, $00, $ff ; sMultichoiceTextboxResult_ChooseDeckToDuelAgainst
+ wram_sram_map wd10e, 1, $00, $ff ; sb84b
+ wram_sram_map .EmptySRAMSlot, 15, $00, $ff ; sb84c
+ wram_sram_map .EmptySRAMSlot, 16, $00, $ff ; sb85b
+ wram_sram_map .EmptySRAMSlot, 16, $00, $ff ; sb86b
+ wram_sram_map wEventVars, 64, $00, $ff ; sEventVars
dw NULL
; 0x1156c
-Data_1156c: ; 1156c (4:556c)
+; fills an empty SRAM slot with zero
+.EmptySRAMSlot: ; 1156c (4:556c)
db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
; 0x1157c
@@ -1267,7 +2218,7 @@ _SaveGame: ; 1157c (4:557c)
ld [wOverworldMapSelection], a
.save
- call Func_11238
+ call SaveAndBackupData
ret
_AddCardToCollectionAndUpdateAlbumProgress: ; 115a3 (4:55a3)
@@ -1299,7 +2250,74 @@ _AddCardToCollectionAndUpdateAlbumProgress: ; 115a3 (4:55a3)
ret
; 0x115d4
- INCROM $115d4, $1162a
+WriteBackupCardAndDeckSaveData: ; 115d4 (4:55d4)
+ ld bc, sCardAndDeckSaveDataEnd - sCardAndDeckSaveData
+ ld hl, sCardCollection
+ jr WriteDataToBackup
+
+WriteBackupGeneralSaveData: ; 115dc (4:55dc)
+ ld bc, sGeneralSaveDataEnd - sGeneralSaveData
+ ld hl, sGeneralSaveData
+; fallthrough
+
+; bc = number of bytes to copy to backup
+; hl = pointer in SRAM of data to backup
+WriteDataToBackup: ; 115e2 (4:55e2)
+ ldh a, [hBankSRAM]
+ push af
+.loop
+ xor a ; SRAM0
+ call BankswitchSRAM
+ ld a, [hl]
+ push af
+ ld a, BANK("SRAM2")
+ call BankswitchSRAM
+ pop af
+ ld [hli], a
+ dec bc
+ ld a, b
+ or c
+ jr nz, .loop
+ pop af
+ call BankswitchSRAM
+ call DisableSRAM
+ ret
+; 0x115ff
+
+LoadBackupCardAndDeckSaveData: ; 115ff (4:55ff)
+ ld bc, sCardAndDeckSaveDataEnd - sCardAndDeckSaveData
+ ld hl, sCardCollection
+ jr LoadDataFromBackup
+
+LoadBackupGeneralSaveData: ; 11607 (4:5607)
+ ld bc, sGeneralSaveDataEnd - sGeneralSaveData
+ ld hl, sGeneralSaveData
+; fallthrough
+
+; bc = number of bytes to load from backup
+; hl = pointer in SRAM of backup data
+LoadDataFromBackup: ; 1160d (4:560d)
+ ldh a, [hBankSRAM]
+ push af
+
+.loop
+ ld a, BANK("SRAM2")
+ call BankswitchSRAM
+ ld a, [hl]
+ push af
+ xor a
+ call BankswitchSRAM
+ pop af
+ ld [hli], a
+ dec bc
+ ld a, b
+ or c
+ jr nz, .loop
+ pop af
+ call BankswitchSRAM
+ call DisableSRAM
+ ret
+; 0x1162a
INCLUDE "data/map_scripts.asm"
@@ -1325,17 +2343,17 @@ LoadNPCSpriteData: ; 11857 (4:5857)
ld a, [hli]
ld [wNPCSpriteID], a
ld a, [hli]
- ld [wd3b1], a
+ ld [wNPCAnim], a
ld a, [hli]
push af
ld a, [hli]
- ld [wd3b2], a
+ ld [wNPCAnimFlags], a
pop bc
ld a, [wConsole]
cp CONSOLE_CGB
jr nz, .not_cgb
ld a, b
- ld [wd3b1], a
+ ld [wNPCAnim], a
.not_cgb
pop bc
pop hl
@@ -2812,13 +3830,13 @@ _GameLoop: ; 126d1 (4:66d1)
inc [hl]
farcall SetIntroSGBBorder
ld a, $ff
- ld [wd627], a
+ ld [wLastSelectedStartMenuItem], a
.main_menu_loop
ld a, PLAYER_TURN
ldh [hWhoseTurn], a
farcall Func_c1f8
- farcall Func_1d078
- ld a, [wd628]
+ farcall HandleTitleScreen
+ ld a, [wStartMenuChoice]
ld hl, MainMenuFunctionTable
call JumpToFunctionInTable
jr c, .main_menu_loop ; return to main menu
@@ -2850,7 +3868,7 @@ MainMenu_NewGame: ; 12704 (4:6704)
ld a, MUSIC_OVERWORLD
ld [wDefaultSong], a
call PlayDefaultSong
- farcall Func_1d306
+ farcall DrawPlayerPortraitAndPrintNewGameText
ld a, GAME_EVENT_OVERWORLD
ld [wGameEvent], a
farcall $03, ExecuteGameEvent
@@ -2860,7 +3878,7 @@ MainMenu_NewGame: ; 12704 (4:6704)
MainMenu_ContinueFromDiary: ; 12741 (4:6741)
ld a, MUSIC_STOP
call PlaySong
- call Func_11320
+ call ValidateBackupGeneralSaveData
jr nc, MainMenu_NewGame
farcall Func_c1ed
farcall SetMainSGBBorder
@@ -2888,8 +3906,8 @@ MainMenu_CardPop: ; 12768 (4:6768)
MainMenu_ContinueDuel: ; 1277e (4:677e)
ld a, MUSIC_STOP
call PlaySong
- farcall Func_c9cb
- farcall $04, Func_3a40
+ farcall ClearEvents
+ farcall $04, LoadGeneralSaveData
farcall SetMainSGBBorder
ld a, GAME_EVENT_CONTINUE_DUEL
ld [wGameEvent], a
@@ -2907,7 +3925,22 @@ Func_12871: ; 12871 (4:6871)
INCROM $12871, $1288c
Func_1288c: ; 1288c (4:688c)
- INCROM $1288c, $128a9
+ push hl
+ push bc
+ push de
+ ld a, %11100100
+ ld [wBGP], a
+ ld [wOBP0], a
+ ld [wOBP1], a
+ ld a, 4
+ ld [wTextBoxFrameType], a
+ bank1call SetDefaultPalettes
+ call FlushAllPalettes
+ pop de
+ pop bc
+ pop hl
+ ret
+; 0x128a9
DisplayPlayerNamingScreen:: ; 128a9 (4:68a9)
; clear the name buffer.
@@ -3061,24 +4094,26 @@ FillNewSpriteAnimBufferEntry: ; 129d9 (4:69d9)
pop hl
ret
-Func_129fa: ; 129fa (4:69fa)
+DisableCurSpriteAnim: ; 129fa (4:69fa)
ld a, [wWhichSprite]
; fallthrough
-Func_129fd: ; 129fd (4:69fd)
+; sets SPRITE_ANIM_ENABLED to false
+; of sprite in register a
+DisableSpriteAnim: ; 129fd (4:69fd)
push af
ld a, [wd5d7]
or a
- jr z, .asm_12a06
+ jr z, .disable
pop af
ret
-.asm_12a06
+.disable
pop af
push hl
push bc
ld c, SPRITE_ANIM_ENABLED
call GetSpriteAnimBufferProperty_SpriteInA
- ld [hl], $00
+ ld [hl], FALSE
pop bc
pop hl
ret
@@ -3096,7 +4131,7 @@ GetSpriteAnimCounter: ; 12a13 (4:6a13)
ret
; 0x12a21
-HandleAllSpriteAnimations: ; 12a21 (4:6a21)
+_HandleAllSpriteAnimations: ; 12a21 (4:6a21)
push af
ld a, [wd5d7] ; skip animating this frame if enabled
or a
@@ -3220,6 +4255,8 @@ StartSpriteAnimation: ; 12ac0 (4:6ac0)
ret
; 0x12ac9
+; a = sprite animation
+; c = animation counter value
Func_12ac9: ; 12ac9 (4:6ac9)
push bc
ld b, a
@@ -3259,7 +4296,7 @@ LoadSpriteAnimPointers: ; 12ae2 (4:6ae2)
pop hl ; hl is animation bank
ld a, [wTempPointerBank]
ld [hli], a
- ld a, [wTempPointer]
+ ld a, [wTempPointer + 0]
ld [hli], a
ld c, a
ld a, [wTempPointer + 1]
@@ -3293,7 +4330,7 @@ HandleAnimationFrame: ; 12b13 (4:6b13)
inc hl
inc hl
ld a, [hl] ; SPRITE_ANIM_FRAME_OFFSET_POINTER
- ld [wTempPointer], a
+ ld [wTempPointer + 0], a
add SPRITE_FRAME_OFFSET_SIZE ; advance FRAME_OFFSET_POINTER by 1 frame, 4 bytes
ld [hli], a
ld a, [hl]
@@ -3357,7 +4394,7 @@ GetAnimFramePointerFromOffset: ; 12b6a (4:6b6a)
ld a, [hli]
ld [wTempPointerBank], a
ld a, [hli]
- ld [wTempPointer], a
+ ld [wTempPointer + 0], a
ld a, [hli]
ld [wTempPointer + 1], a
pop hl
diff --git a/src/engine/bank05.asm b/src/engine/bank05.asm
index f8ed5d7..6927121 100644
--- a/src/engine/bank05.asm
+++ b/src/engine/bank05.asm
@@ -7064,10 +7064,10 @@ CheckIfOpponentHasBossDeckID: ; 17414 (5:7414)
ret
; sets carry if not a boss fight
-; and if s0a00a == 0
+; and if hasn't received legendary cards yet
CheckIfNotABossDeckID: ; 17426 (5:7426)
call EnableSRAM
- ld a, [s0a00a]
+ ld a, [sReceivedLegendaryCards]
call DisableSRAM
or a
jr nz, .no_carry
diff --git a/src/engine/bank06.asm b/src/engine/bank06.asm
index 1e728fd..d0c928c 100644
--- a/src/engine/bank06.asm
+++ b/src/engine/bank06.asm
@@ -1955,7 +1955,7 @@ LoadRegistersFromIRDataBuffer: ; 198d0 (6:58d0)
; 0x198e7
; empties screen and replaces
-; wVBlankFunctionTrampoline with Func_3cb4
+; wVBlankFunctionTrampoline with HandleAllSpriteAnimations
Func_198e7: ; 198e7 (6:58e7)
call EmptyScreen
call Set_OBJ_8x8
@@ -1966,9 +1966,9 @@ Func_198e7: ; 198e7 (6:58e7)
ld de, wVBlankFunctionTrampolineBackup
call BackupVBlankFunctionTrampoline
di
- ld [hl], LOW(Func_3cb4)
+ ld [hl], LOW(HandleAllSpriteAnimations)
inc hl
- ld [hl], HIGH(Func_3cb4)
+ ld [hl], HIGH(HandleAllSpriteAnimations)
ei
ret
; 0x19907
@@ -2101,7 +2101,7 @@ Func_1996e: ; 1996e (6:596e)
ld [s0a009], a
ld [s0a004], a
ld [sTotalCardPopsDone], a
- ld [s0a00a], a
+ ld [sReceivedLegendaryCards], a
farcall Func_8cf9
call DisableSRAM
ret
diff --git a/src/engine/bank07.asm b/src/engine/bank07.asm
index 85de56b..2286921 100644
--- a/src/engine/bank07.asm
+++ b/src/engine/bank07.asm
@@ -1,4 +1,55 @@
- INCROM $1c000, $1c056
+Func_1c000: ; 1c000 (7:4000)
+ jp Set_WD_off
+; 0x1c003
+
+; unreferenced debug function
+; prints player's coordinates by pressing B
+; and draws palettes by pressing A
+Func_1c003: ; 1c003 (7:4003)
+ ld a, [wCurMap]
+ or a
+ jr z, Func_1c000
+ ld a, [wOverworldMode]
+ cp OWMODE_START_SCRIPT
+ jr nc, Func_1c000
+
+ ldh a, [hKeysHeld]
+ ld b, a
+ and A_BUTTON | B_BUTTON
+ cp b
+ jr nz, Func_1c000
+ and B_BUTTON
+ jr z, Func_1c000
+
+ ld bc, $20
+ ld a, [wPlayerXCoord]
+ bank1call WriteTwoByteNumberInTxSymbolFormat
+ ld bc, $320
+ ld a, [wPlayerYCoord]
+ bank1call WriteTwoByteNumberInTxSymbolFormat
+ ld a, $77
+ ldh [hWX], a
+ ld a, $88
+ ldh [hWY], a
+
+ ldh a, [hKeysPressed]
+ and A_BUTTON
+ jr z, .skip_load_scene
+ ld a, SCENE_COLOR_PALETTE
+ lb bc, 0, 33
+ call LoadScene
+.skip_load_scene
+ ldh a, [hKeysHeld]
+ and A_BUTTON
+ jr z, .set_wd_on
+ ld a, $67
+ ldh [hWX], a
+ ld a, $68
+ ldh [hWY], a
+.set_wd_on
+ call Set_WD_on
+ ret
+; 0x1c056
Func_1c056: ; 1c056 (7:4056)
push hl
@@ -94,8 +145,22 @@ LoadMapHeader: ; 1c33b (7:433b)
INCLUDE "data/map_headers.asm"
-Func_1c440: ; 1c440 (7:4440)
- INCROM $1c440, $1c455
+ClearNPCs: ; 1c440 (7:4440)
+ push hl
+ push bc
+ ld hl, wLoadedNPCs
+ ld c, LOADED_NPC_MAX * LOADED_NPC_LENGTH
+ xor a
+.loop
+ ld [hli], a
+ dec c
+ jr nz, .loop
+ ld [wNumLoadedNPCs], a
+ ld [wRonaldIsInMap], a
+ pop bc
+ pop hl
+ ret
+; 0x1c455
GetNPCDirection: ; 1c455 (7:4455)
push hl
@@ -106,22 +171,25 @@ GetNPCDirection: ; 1c455 (7:4455)
pop hl
ret
-Func_1c461: ; 1c461 (7:4461)
+; sets new position to active NPC
+; and updates its tile permissions
+; bc = new coords
+SetNPCPosition: ; 1c461 (7:4461)
push hl
push bc
- call Func_1c719
+ call UpdateNPCsTilePermission
ld a, [wLoadedNPCTempIndex]
ld l, LOADED_NPC_COORD_X
call GetItemInLoadedNPCIndex
ld a, b
ld [hli], a
ld [hl], c
- call Func_1c6e3
+ call SetNPCsTilePermission
pop bc
pop hl
ret
-Func_1c477: ; 1c477 (7:4477)
+GetNPCPosition: ; 1c477 (7:4477)
push hl
ld a, [wLoadedNPCTempIndex]
ld l, LOADED_NPC_COORD_X
@@ -133,7 +201,7 @@ Func_1c477: ; 1c477 (7:4477)
ret
; Loads NPC Sprite Data
-Func_1c485: ; 1c485 (7:4485)
+LoadNPC: ; 1c485 (7:4485)
push hl
push bc
push de
@@ -173,65 +241,68 @@ Func_1c485: ; 1c485 (7:4485)
ld [hli], a
ld a, [wLoadNPCDirection]
ld [hli], a
- ld a, [wd3b2]
+ ld a, [wNPCAnimFlags]
ld [hli], a
- ld a, [wd3b1]
+ ld a, [wNPCAnim]
ld [hli], a
ld a, [wLoadNPCDirection]
ld [hli], a
- call Func_1c58e
- call Func_1c5b9
- ld hl, wd349
+ call UpdateNPCAnimation
+ call ApplyRandomCountToNPCAnim
+ ld hl, wNumLoadedNPCs
inc [hl]
pop hl
- call Func_1c665
- call Func_1c6e3
+
+ call UpdateNPCSpritePosition
+ call SetNPCsTilePermission
+
ld a, [wTempNPC]
- call Func_1c4fa
+ call CheckIfNPCIsRonald
jr nc, .exit
- ld a, $01
- ld [wd3b8], a
+ ld a, TRUE
+ ld [wRonaldIsInMap], a
.exit
pop de
pop bc
pop hl
ret
-Func_1c4fa: ; 1c4fa (7:44fa)
+; returns carry if input NPC ID in register a is Ronald
+CheckIfNPCIsRonald: ; 1c4fa (7:44fa)
cp NPC_RONALD1
- jr z, .asm_1c508
+ jr z, .set_carry
cp NPC_RONALD2
- jr z, .asm_1c508
+ jr z, .set_carry
cp NPC_RONALD3
- jr z, .asm_1c508
+ jr z, .set_carry
or a
ret
-.asm_1c508
+.set_carry
scf
ret
-Func_1c50a: ; 1c50a (7:450a)
+UnloadNPC: ; 1c50a (7:450a)
push hl
- call Func_1c719
+ call UpdateNPCsTilePermission
ld a, [wLoadedNPCTempIndex]
call GetLoadedNPCID
ld a, [hl]
or a
- jr z, .asm_1c52c
- call Func_1c4fa
- jr nc, .asm_1c521
- xor a
- ld [wd3b8], a
+ jr z, .exit
+ call CheckIfNPCIsRonald
+ jr nc, .not_ronald
+ xor a ; FALSE
+ ld [wRonaldIsInMap], a
+.not_ronald
-.asm_1c521
xor a
ld [hli], a
ld a, [hl]
- farcall Func_129fd
- ld hl, wd349
+ farcall DisableSpriteAnim
+ ld hl, wNumLoadedNPCs
dec [hl]
-.asm_1c52c
+.exit
pop hl
ret
@@ -239,7 +310,7 @@ Func_1c52e: ; 1c52e (7:452e)
push hl
push af
ld a, [wLoadedNPCTempIndex]
- ld l, LOADED_NPC_FIELD_07
+ ld l, LOADED_NPC_UNKNOWN
call GetItemInLoadedNPCIndex
pop af
ld [hl], a
@@ -254,7 +325,7 @@ Func_1c53f: ; 1c53f (7:453f)
ld l, LOADED_NPC_DIRECTION
call GetItemInLoadedNPCIndex
ld a, [hl]
- ld bc, $0003
+ ld bc, LOADED_NPC_UNKNOWN - LOADED_NPC_DIRECTION
add hl, bc
ld [hl], a
push af
@@ -288,21 +359,22 @@ Func_1c557: ; 1c557 (7:4557)
pop bc
ret
-Func_1c57b: ; 1c57b (7:457b)
+; a = NPC animation
+SetNPCAnimation: ; 1c57b (7:457b)
push hl
push bc
push af
ld a, [wLoadedNPCTempIndex]
- ld l, LOADED_NPC_FIELD_06
+ ld l, LOADED_NPC_ANIM
call GetItemInLoadedNPCIndex
pop af
ld [hl], a
- call Func_1c58e
+ call UpdateNPCAnimation
pop bc
pop hl
ret
-Func_1c58e: ; 1c58e (7:458e)
+UpdateNPCAnimation: ; 1c58e (7:458e)
push hl
push bc
ld a, [wWhichSprite]
@@ -314,13 +386,13 @@ Func_1c58e: ; 1c58e (7:458e)
jr z, .quit
ld a, [hl]
ld [wWhichSprite], a
- ld bc, LOADED_NPC_FIELD_06 - LOADED_NPC_SPRITE
+ ld bc, LOADED_NPC_ANIM - LOADED_NPC_SPRITE
add hl, bc
- ld a, [hld]
- bit 4, [hl]
+ ld a, [hld] ; LOADED_NPC_ANIM
+ bit NPC_FLAG_DIRECTIONLESS_F, [hl] ; LOADED_NPC_FLAGS
jr nz, .asm_1c5ae
dec hl
- add [hl]
+ add [hl] ; LOADED_NPC_ANIM + LOADED_NPC_DIRECTION
inc hl
.asm_1c5ae
farcall StartNewSpriteAnimation
@@ -330,36 +402,250 @@ Func_1c58e: ; 1c58e (7:458e)
pop bc
pop hl
ret
+; 0x1c5b9
-Func_1c5b9: ; 1c5b9 (7:45b9)
- INCROM $1c5b9, $1c5e9
+; if NPC's sprite has an animation,
+; give it a random initial value
+; this makes it so that all NPCs are out of phase
+; when they are loaded into a map
+ApplyRandomCountToNPCAnim: ; 1c5b9 (7:45b9)
+ push hl
+ push bc
+ ld a, [wWhichSprite]
+ push af
+ ld a, [wLoadedNPCTempIndex]
+ call GetLoadedNPCID
+ ld a, [hli]
+ or a
+ jr z, .done
+ ld a, [hl]
+ ld [wWhichSprite], a
+ ld c, SPRITE_ANIM_COUNTER
+ call GetSpriteAnimBufferProperty
+ ld a, [hl]
+ or a
+ jr z, .done
+ cp $ff
+ jr z, .done
+ dec a
+ call Random
+ ld c, a
+ ld a, [hl]
+ sub c
+ ld [hl], a
+.done
+ pop af
+ ld [wWhichSprite], a
+ pop bc
+ pop hl
+ ret
+; 0x1c5e9
+; sets the loaded NPC's direction
+; to the direction that is in LOADED_NPC_UNKNOWN
Func_1c5e9: ; 1c5e9 (7:45e9)
push hl
push bc
ld a, [wLoadedNPCTempIndex]
- ld l, LOADED_NPC_FIELD_07
+ ld l, LOADED_NPC_UNKNOWN
call GetItemInLoadedNPCIndex
ld a, [hl]
- ld bc, -3
+ ld bc, LOADED_NPC_DIRECTION - LOADED_NPC_UNKNOWN
add hl, bc
ld [hl], a
- call Func_1c58e
+ call UpdateNPCAnimation
pop bc
pop hl
ret
; 0x1c5ff
-Func_1c5ff: ; 1c5ff (7:45ff)
- INCROM $1c5ff, $1c610
+; a = new direction
+SetNPCDirection: ; 1c5ff (7:45ff)
+ push hl
+ push af
+ ld a, [wLoadedNPCTempIndex]
+ ld l, LOADED_NPC_DIRECTION
+ call GetItemInLoadedNPCIndex
+ pop af
+ ld [hl], a
+ call UpdateNPCAnimation
+ pop hl
+ ret
+; 0x1c610
+
+HandleAllNPCMovement: ; 1c610 (7:4610)
+ push hl
+ push bc
+ push de
+ xor a
+ ld [wIsAnNPCMoving], a
+ ld a, [wNumLoadedNPCs]
+ or a
+ jr z, .exit
+
+ ld c, LOADED_NPC_MAX
+ ld hl, wLoadedNPCs
+ ld de, LOADED_NPC_LENGTH
+.loop_npcs
+ ld a, [hl]
+ or a
+ jr z, .next_npc
+ push bc
+ inc hl
+ ld a, [hld]
+ ld [wWhichSprite], a
+ call UpdateNPCMovementStep
+ call .UpdateSpriteAnimFlag
+ call UpdateNPCSpritePosition
+ call UpdateIsAnNPCMovingFlag
+ pop bc
+.next_npc
+ add hl, de
+ dec c
+ jr nz, .loop_npcs
+.exit
+ pop de
+ pop bc
+ pop hl
+ ret
+
+.UpdateSpriteAnimFlag
+ push hl
+ push bc
+ ld bc, LOADED_NPC_COORD_X
+ add hl, bc
+ ld b, [hl]
+ inc hl
+ ld c, [hl]
+ call GetPermissionOfMapPosition
+ and $10
+ push af
+ ld c, SPRITE_ANIM_FLAGS
+ call GetSpriteAnimBufferProperty
+ pop af
+ ld a, [hl]
+ jr z, .reset_flag
+ set SPRITE_ANIM_FLAG_UNSKIPPABLE, [hl]
+ jr .done
+.reset_flag
+ res SPRITE_ANIM_FLAG_UNSKIPPABLE, [hl]
+.done
+ pop bc
+ pop hl
+ ret
+; 0x1c665
+
+UpdateNPCSpritePosition: ; 1c665 (7:4665)
+ push hl
+ push bc
+ push de
+ call .GetOffset
+
+ ; get NPC and sprite coords
+ push bc
+ ld de, LOADED_NPC_COORD_X
+ add hl, de
+ ld e, l
+ ld d, h
+ ld c, SPRITE_ANIM_COORD_X
+ call GetSpriteAnimBufferProperty
+ pop bc
+
+ ; hl = sprite coords
+ ; de = NPC coords
+ ld a, [de] ; x
+ sla a
+ sla a
+ sla a
+ add $8
+ sub b
+ ld [hli], a
+ inc de
+ ld a, [de] ; y
+ sla a
+ sla a
+ sla a
+ add $10
+ sub c
+ ld [hli], a
+ pop de
+ pop bc
+ pop hl
+ ret
+
+; outputs in bc the coordinate offsets
+; given NPCs direction and its movement step
+.GetOffset
+ push hl
+ ld bc, $0
+ ld de, LOADED_NPC_FLAGS
+ add hl, de
+ ld e, 0
+ ld a, [hl]
+ and NPC_FLAG_MOVING
+ jr z, .got_direction
+ dec hl
+ ld a, [hl] ; LOADED_NPC_DIRECTION
+ ld de, LOADED_NPC_MOVEMENT_STEP - LOADED_NPC_DIRECTION
+ add hl, de
+ ld e, [hl] ; LOADED_NPC_MOVEMENT_STEP
+.got_direction
+ ld hl, .function_table
+ call JumpToFunctionInTable
+ pop hl
+ ret
+
+.function_table
+ dw .north
+ dw .east
+ dw .south
+ dw .west
+
+.west
+ ld a, e
+ cpl
+ inc a
+ ld e, a
+.east
+ ld b, e
+ ldh a, [hSCX]
+ sub b
+ ld b, a
+ ldh a, [hSCY]
+ ld c, a
+ ret
-Func_1c610: ; 1c610 (7:4610)
- INCROM $1c610, $1c665
+.north
+ ld a, e
+ cpl
+ inc a
+ ld e, a
+.south
+ ld c, e
+ ldh a, [hSCY]
+ sub c
+ ld c, a
+ ldh a, [hSCX]
+ ld b, a
+ ret
+; 0x1c6d3
-Func_1c665: ; 1c665 (7:4665)
- INCROM $1c665, $1c6e3
+; ands wIsAnNPCMoving with the current
+; NPC's NPC_FLAG_MOVING_F
+UpdateIsAnNPCMovingFlag: ; 1c6d3 (7:46d3)
+ push hl
+ push bc
+ ld bc, LOADED_NPC_FLAGS
+ add hl, bc
+ ld a, [wIsAnNPCMoving]
+ or [hl]
+ ld [wIsAnNPCMoving], a
+ pop bc
+ pop hl
+ ret
+; 0x1c6e3
-Func_1c6e3: ; 1c6e3 (7:46e3)
+SetNPCsTilePermission: ; 1c6e3 (7:46e3)
push hl
push bc
ld a, [wLoadedNPCTempIndex]
@@ -374,10 +660,33 @@ Func_1c6e3: ; 1c6e3 (7:46e3)
pop hl
ret
-Func_1c6f8: ; 1c6f8 (7:46f8)
- INCROM $1c6f8, $1c719
+SetAllNPCTilePermissions: ; 1c6f8 (7:46f8)
+ push hl
+ push bc
+ push de
+ ld b, $00
+ ld c, LOADED_NPC_MAX
+ ld hl, wLoadedNPCs
+ ld de, LOADED_NPC_LENGTH
+.loop_npcs
+ ld a, [hl]
+ or a
+ jr z, .next_npc
+ ld a, b
+ ld [wLoadedNPCTempIndex], a
+ call SetNPCsTilePermission
+.next_npc
+ add hl, de
+ inc b
+ dec c
+ jr nz, .loop_npcs
+ pop de
+ pop bc
+ pop hl
+ ret
+; 0x1c719
-Func_1c719: ; 1c719 (7:4719)
+UpdateNPCsTilePermission: ; 1c719 (7:4719)
push hl
push bc
ld a, [wLoadedNPCTempIndex]
@@ -452,7 +761,7 @@ SetNewScriptNPC: ; 1c768 (7:4768)
ld a, [wPlayerDirection]
xor $02
ld [hl], a
- call Func_1c58e
+ call UpdateNPCAnimation
ld a, $02
farcall Func_c29b
ld a, [wLoadedNPCTempIndex]
@@ -462,103 +771,264 @@ SetNewScriptNPC: ; 1c768 (7:4768)
pop hl
ret
-Func_1c78d: ; 1c78d (7:478d)
+StartNPCMovement: ; 1c78d (7:478d)
push hl
+; set NPC as moving
ld a, [wLoadedNPCTempIndex]
- ld l, LOADED_NPC_FIELD_05
+ ld l, LOADED_NPC_FLAGS
call GetItemInLoadedNPCIndex
- set 5, [hl]
+ set NPC_FLAG_MOVING_F, [hl]
+
+; reset its movement step
ld a, [wLoadedNPCTempIndex]
- ld l, LOADED_NPC_FIELD_08
+ ld l, LOADED_NPC_MOVEMENT_STEP
call GetItemInLoadedNPCIndex
xor a
ld [hli], a
-.asm_1c7a2
- ld [hl], c
+.loop_movement
+ ld [hl], c ; LOADED_NPC_MOVEMENT_PTR
inc hl
ld [hl], b
dec hl
call GetNextNPCMovementByte
cp $f0
- jr nc, .asm_1c7bb
+ jr nc, .special_command
push af
- and $7f
- call Func_1c5ff
+ and DIRECTION_MASK
+ call SetNPCDirection
pop af
+ ; if it was not a rotation, exit...
bit 7, a
- jr z, .asm_1c7dc
+ jr z, .exit
+ ; ...otherwise jump to next movement instruction
inc bc
- jr .asm_1c7a2
+ jr .loop_movement
-.asm_1c7bb
+.special_command
cp $ff
- jr z, .asm_1c7d2
+ jr z, .stop_movement
+; jump to a movement command
+ ; read its argument
inc bc
call GetNextNPCMovementByte
push hl
ld l, a
ld h, $0
bit 7, l
- jr z, .asm_1c7cc
- dec h
-
-.asm_1c7cc
+ jr z, .got_offset
+ dec h ; $ff
+.got_offset
+ ; add the offset to bc
add hl, bc
ld c, l
ld b, h
pop hl
- jr .asm_1c7a2
+ jr .loop_movement
-.asm_1c7d2
+.stop_movement
ld a, [wLoadedNPCTempIndex]
- ld l, LOADED_NPC_FIELD_05
+ ld l, LOADED_NPC_FLAGS
call GetItemInLoadedNPCIndex
- res 5, [hl]
+ res NPC_FLAG_MOVING_F, [hl]
-.asm_1c7dc
+.exit
pop hl
ret
-Func_1c7de: ; 1c7de (7:47de)
- ld a, [wc3b7]
- and $20
+; returns nz if there is an NPC currently moving
+CheckIsAnNPCMoving: ; 1c7de (7:47de)
+ ld a, [wIsAnNPCMoving]
+ and NPC_FLAG_MOVING
ret
; 0x1c7e4
- INCROM $1c7e4, $1c82e
+; while the NPC is moving, increment its movement step by 1
+; once it reaches a value greater than 16, update
+; its tile permission and its position and start next movement
+UpdateNPCMovementStep: ; 1c7e4 (7:47e4)
+ push hl
+ push bc
+ push de
+ ld bc, LOADED_NPC_FLAGS
+ add hl, bc
+ bit NPC_FLAG_MOVING_F, [hl]
+ jr z, .exit
+ ld bc, LOADED_NPC_MOVEMENT_STEP - LOADED_NPC_FLAGS
+ add hl, bc
+ inc [hl] ; increment movement step
+ bit 4, [hl]
+ jr z, .exit ; still hasn't reached the next tile
+ call UpdateNPCsTilePermission
+ call UpdateNPCPosition
+ inc hl
+ ld c, [hl] ; LOADED_NPC_MOVEMENT_PTR
+ inc hl
+ ld b, [hl]
+ inc bc
+ call StartNPCMovement
+ call SetNPCsTilePermission
+.exit
+ pop de
+ pop bc
+ pop hl
+ ret
+; 0x1c80d
-Func_1c82e: ; 1c82e (7:482e)
- INCROM $1c82e, $1c83d
+UpdateNPCPosition: ; 1c80d (7:480d)
+ push hl
+ push bc
+ ld a, [wLoadedNPCTempIndex]
+ ld l, LOADED_NPC_DIRECTION
+ call GetItemInLoadedNPCIndex
+ ld a, [hld]
+ push hl
+ rlca ; *2
+ ld c, a
+ ld b, $00
+ ld hl, PlayerMovementOffsetTable_Tiles
+ add hl, bc
+ ld b, [hl] ; x offset
+ inc hl
+ ld c, [hl] ; y offset
+ pop hl
+ ld a, [hl] ; LOADED_NPC_COORD_Y
+ add c
+ ld [hld], a
+ ld a, [hl] ; LOADED_NPC_COORD_X
+ add b
+ ld [hl], a
+ pop bc
+ pop hl
+ ret
+; 0x1c82e
-Func_1c83d: ; 1c83d (7:483d)
+ClearMasterBeatenList: ; 1c82e (7:482e)
+ push hl
+ push bc
+ ld c, $a
+ ld hl, wMastersBeatenList
+ xor a
+.loop
+ ld [hli], a
+ dec c
+ jr nz, .loop
+ pop bc
+ pop hl
+ ret
+; 0x1c83d
+
+; writes Master in register a to
+; first empty slot in wMastersBeatenList
+AddMasterBeatenToList: ; 1c83d (7:483d)
push hl
push bc
ld b, a
ld c, $a
- ld hl, wd3bb
-.asm_1c845
+ ld hl, wMastersBeatenList
+.loop
ld a, [hl]
or a
- jr z, .asm_1c853
+ jr z, .found_empty_slot
cp b
- jr z, .asm_1c855
+ jr z, .exit
inc hl
dec c
- jr nz, .asm_1c845
+ jr nz, .loop
debug_nop
- jr .asm_1c855
+ jr .exit
-.asm_1c853
+.found_empty_slot
ld a, b
ld [hl], a
-.asm_1c855
+.exit
pop bc
pop hl
ret
-Func_1c858: ; 1c858 (7:4858)
- INCROM $1c858, $1c8bc
+; iterates all masters and attempts to
+; add each of them to wMastersBeatenList
+AddAllMastersToMastersBeatenList: ; 1c858 (7:4858)
+ ld a, $01
+.loop
+ push af
+ call AddMasterBeatenToList
+ pop af
+ inc a
+ cp $0b
+ jr c, .loop
+ ret
+; 0x1c865
+
+ ret ; stray ret
+
+; unreferenced debug function
+; adjusts hSCX and hSCY by using the arrow keys
+; pressing B makes it scroll faster
+Func_1c866: ; 1c866 (7:4866)
+ ldh a, [hKeysHeld]
+ and B_BUTTON
+ call nz, .asm_1c86d ; executes following part twice
+.asm_1c86d
+ ldh a, [hSCX]
+ ld b, a
+ ldh a, [hSCY]
+ ld c, a
+ ldh a, [hKeysHeld]
+ bit D_UP_F, a
+ jr z, .check_d_down
+ inc c
+.check_d_down
+ bit D_DOWN_F, a
+ jr z, .check_d_left
+ dec c
+.check_d_left
+ bit D_LEFT_F, a
+ jr z, .check_d_right
+ inc b
+.check_d_right
+ bit D_RIGHT_F, a
+ jr z, .asm_1c889
+ dec b
+.asm_1c889
+ ld a, b
+ ldh [hSCX], a
+ ld a, c
+ ldh [hSCY], a
+ ret
+; 0x1c890
+
+; unreferenced
+; sets some flags on a given sprite
+Func_1c890: ; 1c890 (7:4890)
+ ld a, [wVBlankCounter]
+ and %111111
+ ret nz
+
+ ld a, [wd41b]
+ cp $11
+ jr z, .asm_1c8a3
+ cp $0e
+ ret c
+ cp $10
+ ret nc
+
+; wd41b == $11 || (wd41b >= $0e && wd41b < $10)
+.asm_1c8a3
+ ld a, [wd41c]
+ ld [wWhichSprite], a
+ ld c, SPRITE_ANIM_FLAGS
+ call GetSpriteAnimBufferProperty
+ call UpdateRNGSources
+ and (1 << SPRITE_ANIM_FLAG_X_SUBTRACT)
+ jr nz, .asm_1c8b9
+ res SPRITE_ANIM_FLAG_SPEED, [hl]
+ jr .asm_1c8bb
+.asm_1c8b9
+ set SPRITE_ANIM_FLAG_SPEED, [hl]
+.asm_1c8bb
+ ret
+; 0x1c8bc
Func_1c8bc: ; 1c8bc (7:48bc)
push hl
@@ -962,7 +1432,7 @@ Func_1cac5: ; 1cac5 (7:4ac5)
farcall GetSpriteAnimCounter
cp $ff
jr nz, .next
- farcall Func_129fa
+ farcall DisableCurSpriteAnim
ld a, $ff
ld [hl], a
@@ -1019,7 +1489,7 @@ Func_1cb18: ; 1cb18 (7:4b18)
cp $ff
jr z, .asm_1cb4b
ld [wWhichSprite], a
- farcall Func_129fa
+ farcall DisableCurSpriteAnim
ld a, $ff
ld [hl], a
.asm_1cb4b
@@ -1060,7 +1530,7 @@ Func_1cb5e: ; 1cb5e (7:4b5e)
ld [wVRAMTileOffset], a
ld [wd4cb], a
- ld a, $25
+ ld a, PALETTE_37
farcall LoadPaletteData
call Func_1cba6
@@ -1140,7 +1610,9 @@ Func_1cbcc: ; 1cbcc (7:4bcc)
ret
; 0x1cbfd
- INCROM $1cbfd, $1cc03
+; unreferenced data?
+ db $f0, $f8, $00, $08, $f8, $f0
+; 0x1cc03
Func_1cc03: ; 1cc03 (7:4c03)
ld a, [wDuelAnimDamage]
@@ -1429,7 +1901,7 @@ WhiteFlashScreen: ; 1cd76 (7:4d76)
ld de, wTempBackgroundPalettesCGB
ld bc, 8 palettes
call CopyDataHLtoDE_SaveRegisters
- ld de, $7fff ; rgb 31, 31, 31
+ ld de, PALRGB_WHITE
ld hl, wBackgroundPalettesCGB
ld bc, (8 palettes) / 2
call FillMemoryWithDE
@@ -1522,76 +1994,112 @@ Func_1ce03: ; 1ce03 (7:4e03)
INCLUDE "data/duel_animations.asm"
-Func_1d078: ; 1d078 (7:5078)
- ld a, [wd627]
+; plays the Opening sequence, and handles player selection
+; in the Title Screen and Start Menu
+HandleTitleScreen: ; 1d078 (7:5078)
+; if last selected item in Start Menu is 0 (Card Pop!)
+; then skip straight to the Start Menu
+; this makes it so that returning from Card Pop!
+; doesn't play the Opening sequence
+ ld a, [wLastSelectedStartMenuItem]
or a
- jr z, .asm_1d0c7
-.asm_1d07e
+ jr z, .start_menu
+
+.play_opening
ld a, MUSIC_STOP
call PlaySong
call Func_3ca0
- call Func_1d335
- call Func_1d3ce
+ call PlayOpeningSequence
+ call LoadTitleScreenSprites
+
xor a
ld [wd635], a
ld a, $3c
- ld [wd626], a
-.asm_1d095
+ ld [wTitleScreenIgnoreInputCounter], a
+.loop
call DoFrameIfLCDEnabled
call UpdateRNGSources
- call Func_1d614
+ call AnimateRandomTitleScreenOrb
ld hl, wd635
inc [hl]
call AssertSongFinished
or a
- jr nz, .asm_1d0ae
+ jr nz, .song_playing
+ ; reset back to the opening sequence
farcall Func_10ab4
- jr .asm_1d07e
-.asm_1d0ae
- ld hl, wd626
+ jr .play_opening
+
+.song_playing
+ ; should we ignore user input?
+ ld hl, wTitleScreenIgnoreInputCounter
ld a, [hl]
or a
- jr z, .asm_1d0b8
+ jr z, .check_keys
+ ; ignore input, decrement the counter
dec [hl]
- jr .asm_1d095
-.asm_1d0b8
+ jr .loop
+
+.check_keys
ldh a, [hKeysPressed]
and A_BUTTON | START
- jr z, .asm_1d095
+ jr z, .loop
ld a, SFX_02
call PlaySFX
farcall Func_10ab4
-.asm_1d0c7
- call Func_1d0fa
- call Func_1d11c
- ld a, [wd628]
- cp $2
- jr nz, .asm_1d0db
- call Func_1d289
- jr c, Func_1d078
- jr .asm_1d0e7
-.asm_1d0db
- ld a, [wd628]
- cp $1
- jr nz, .asm_1d0e7
- call Func_1d2b8
- jr c, Func_1d078
-.asm_1d0e7
- ld a, [wd628]
- cp $0
- jr nz, .asm_1d0f3
- call Func_1d2dd
- jr c, Func_1d078
-.asm_1d0f3
+.start_menu
+ call CheckIfHasSaveData
+ call HandleStartMenu
+
+; new game
+ ld a, [wStartMenuChoice]
+ cp START_MENU_NEW_GAME
+ jr nz, .continue_from_diary
+ call DeleteSaveDataForNewGame
+ jr c, HandleTitleScreen
+ jr .card_pop
+.continue_from_diary
+ ld a, [wStartMenuChoice]
+ cp START_MENU_CONTINUE_FROM_DIARY
+ jr nz, .card_pop
+ call AskToContinueFromDiaryWithDuelData
+ jr c, HandleTitleScreen
+.card_pop
+ ld a, [wStartMenuChoice]
+ cp START_MENU_CARD_POP
+ jr nz, .continue_duel
+ call ShowCardPopCGBDisclaimer
+ jr c, HandleTitleScreen
+.continue_duel
call ResetDoFrameFunction
call Func_3ca0
ret
+; 0x1d0fa
+
+; updates wHasSaveData and wHasDuelSaveData
+; depending on whether the save data is valid or not
+CheckIfHasSaveData: ; 1d0fa (7:50fa)
+ farcall ValidateBackupGeneralSaveData
+ ld a, TRUE
+ jr c, .no_error
+ ld a, FALSE
+.no_error
+ ld [wHasSaveData], a
+ cp $00 ; or a
+ jr z, .write_has_duel_data
+ bank1call ValidateSavedNonLinkDuelData
+ ld a, TRUE
+ jr nc, .write_has_duel_data
+ ld a, FALSE
+.write_has_duel_data
+ ld [wHasDuelSaveData], a
+ farcall ValidateBackupGeneralSaveData
+ ret
+; 0x1d11c
-Func_1d0fa: ; 1d0fa (7:50fa)
- INCROM $1d0fa, $1d11c
-
-Func_1d11c: ; 1d11c (7:511c)
+; handles printing the Start Menu
+; and getting player input and choice
+HandleStartMenu: ; 1d11c (7:511c)
ld a, MUSIC_PC_MAIN_MENU
call PlaySong
call DisableLCD
@@ -1601,68 +2109,356 @@ Func_1d11c: ; 1d11c (7:511c)
call Func_3ca0
xor a
ld [wLineSeparation], a
- call Func_1d1e1
- call Func_1d17f
+ call .DrawPlayerPortrait
+ call .SetStartMenuParams
+
ld a, $ff
- ld [wd626], a
- ld a, [wd627]
+ ld [wTitleScreenIgnoreInputCounter], a
+ ld a, [wLastSelectedStartMenuItem]
cp $4
- jr c, .asm_1d14f
- ld a, [wd624]
+ jr c, .init_menu
+ ld a, [wHasSaveData]
or a
- jr z, .asm_1d14f
- ld a, $1
-.asm_1d14f
- ld hl, wd636
- farcall Func_111e9
- farcall Func_10031
-.asm_1d15a
+ jr z, .init_menu
+ ld a, 1 ; start at second menu option
+.init_menu
+ ld hl, wStartMenuParams
+ farcall InitAndPrintPauseMenu
+ farcall FlashWhiteScreen
+
+.wait_input
call DoFrameIfLCDEnabled
call UpdateRNGSources
call HandleMenuInput
push af
- call Func_1d1e9
+ call PrintStartMenuDescriptionText
pop af
- jr nc, .asm_1d15a
+ jr nc, .wait_input
ldh a, [hCurMenuItem]
cp e
- jr nz, .asm_1d15a
- ld [wd627], a
- ld a, [wd624]
+ jr nz, .wait_input
+
+ ld [wLastSelectedStartMenuItem], a
+ ld a, [wHasSaveData]
or a
- jr nz, .asm_1d17a
+ jr nz, .no_adjustment
+ ; New Game is 3rd option
+ ; but when there's no save data,
+ ; it's the 1st in menu list, so adjust it
inc e
inc e
-.asm_1d17a
+.no_adjustment
ld a, e
- ld [wd628], a
+ ld [wStartMenuChoice], a
+ ret
+
+.SetStartMenuParams
+ ld hl, .StartMenuParams
+ ld de, wStartMenuParams
+ ld bc, .StartMenuParamsEnd - .StartMenuParams
+ call CopyDataHLtoDE
+
+ ld e, 0
+ ld a, [wHasSaveData]
+ or a
+ jr z, .get_text_id ; New Game
+ inc e
+ ld a, 2
+ call .AddItems
+ ld a, [wHasDuelSaveData]
+ or a
+ jr z, .get_text_id ; Continue From Diary
+ inc e
+ ld a, 1
+ call .AddItems
+ ; Continue Duel
+
+.get_text_id
+ sla e
+ ld d, $00
+ ld hl, .StartMenuTextIDs
+ add hl, de
+ ; set text ID as Start Menu param
+ ld a, [hli]
+ ld [wStartMenuParams + 6], a
+ ld a, [hl]
+ ld [wStartMenuParams + 7], a
+ ret
+
+; adds c items to start menu list
+; this means adding 2 units per item to the text box height
+; and adding to the number of items
+.AddItems
+ push bc
+ ld c, a
+ ; number of items in menu
+ ld a, [wStartMenuParams + 12]
+ add c
+ ld [wStartMenuParams + 12], a
+ ; height of text box
+ sla c
+ ld a, [wStartMenuParams + 3]
+ add c
+ ld [wStartMenuParams + 3], a
+ pop bc
ret
-Func_1d17f: ; 1d17f (7:517f)
- INCROM $1d17f, $1d1e1
+.StartMenuParams
+ db 0, 0 ; start menu coords
+ db 14, 4 ; start menu text box dimensions
+
+ db 2, 2 ; text alignment for InitTextPrinting
+ tx NewGameText
+ db $ff
+
+ db 1, 2 ; cursor x, cursor y
+ db 2 ; y displacement between items
+ db 1 ; number of items
+ db SYM_CURSOR_R ; cursor tile number
+ db SYM_SPACE ; tile behind cursor
+ dw NULL ; function pointer if non-0
+.StartMenuParamsEnd
+
+.StartMenuTextIDs
+ tx NewGameText
+ tx CardPopContinueDiaryNewGameText
+ tx CardPopContinueDiaryNewGameContinueDuelText
+
+.DrawPlayerPortrait
+ lb bc, 14, 1
+ farcall $4, DrawPlayerPortrait
+ ret
+; 0x1d1e9
+
+; prints the description for the current selected item
+; in the Start Menu in the text box
+PrintStartMenuDescriptionText: ; 1d1e9 (7:51e9)
+ push hl
+ push bc
+ push de
+ ; don't print if it's already showing
+ ld a, [wCurMenuItem]
+ ld e, a
+ ld a, [wCurHighlightedStartMenuItem]
+ cp e
+ jr z, .skip
+ ld a, [wHasSaveData]
+ or a
+ jr nz, .has_data
+ ; New Game option is 3rd element
+ ; in function table, so add 2
+ inc e
+ inc e
+.has_data
-Func_1d1e1: ; 1d1e1 (7:51e1)
- INCROM $1d1e1, $1d1e9
+ ld a, e
+ push af
+ lb de, 0, 10
+ lb bc, 20, 8
+ call DrawRegularTextBox
+ pop af
+ ld hl, .StartMenuDescriptionFunctionTable
+ call JumpToFunctionInTable
+.skip
+ ld a, [wCurMenuItem]
+ ld [wCurHighlightedStartMenuItem], a
+ pop de
+ pop bc
+ pop hl
+ ret
-Func_1d1e9: ; 1d1e9 (7:51e9)
- INCROM $1d1e9, $1d289
+.StartMenuDescriptionFunctionTable
+ dw .CardPop
+ dw .ContinueFromDiary
+ dw .NewGame
+ dw .ContinueDuel
+
+.CardPop
+ lb de, 1, 12
+ call InitTextPrinting
+ ldtx hl, WhenYouCardPopWithFriendText
+ call PrintTextNoDelay
+ ret
-Func_1d289: ; 1d289 (7:5289)
- INCROM $1d289, $1d2b8
+.ContinueDuel
+ lb de, 1, 12
+ call InitTextPrinting
+ ldtx hl, TheGameWillContinueFromThePointInTheDuelText
+ call PrintTextNoDelay
+ ret
-Func_1d2b8: ; 1d2b8 (7:52b8)
- INCROM $1d2b8, $1d2dd
+.NewGame
+ lb de, 1, 12
+ call InitTextPrinting
+ ldtx hl, StartANewGameText
+ call PrintTextNoDelay
+ ret
-Func_1d2dd: ; 1d2dd (7:52dd)
- INCROM $1d2dd, $1d306
+.ContinueFromDiary
+ ; get OW map name
+ ld a, [wCurOverworldMap]
+ add a
+ ld c, a
+ ld b, $00
+ ld hl, OverworldMapNames
+ add hl, bc
+ ld a, [hli]
+ ld [wTxRam2 + 0], a
+ ld a, [hl]
+ ld [wTxRam2 + 1], a
-Func_1d306: ; 1d306 (7:5306)
- INCROM $1d306, $1d335
+ ; get medal count
+ ld a, [wMedalCount]
+ ld [wTxRam3 + 0], a
+ xor a
+ ld [wTxRam3 + 1], a
-Func_1d335: ; 1d335 (7:5335)
- INCROM $1d335, $1d386
+ ; print text
+ lb de, 1, 10
+ call InitTextPrinting
+ ldtx hl, ContinueFromDiarySummaryText
+ call PrintTextNoDelay
-Titlescreen_1d386: ; 1d386 (7:5386)
+ ld a, [wTotalNumCardsCollected]
+ ld d, a
+ ld a, [wTotalNumCardsToCollect]
+ ld e, a
+ ld bc, $90e
+ farcall Func_1024f
+ ld bc, $a10
+ farcall Func_101df
+ ret
+; 0x1d289
+
+; asks the player whether it's okay to delete
+; the save data in order to create a new one
+; if player answers "yes", delete it
+DeleteSaveDataForNewGame: ; 1d289 (7:5289)
+; exit if there no save data
+ ld a, [wHasSaveData]
+ or a
+ ret z
+
+ call DisableLCD
+ farcall Func_10000
+ call Func_3ca0
+ farcall FlashWhiteScreen
+ call DoFrameIfLCDEnabled
+ ldtx hl, SavedDataAlreadyExistsText
+ call PrintScrollableText_NoTextBoxLabel
+ ldtx hl, OKToDeleteTheDataText
+ call YesOrNoMenuWithText
+ ret c ; quit if chose "no"
+ farcall InvalidateSaveData
+ ldtx hl, AllDataWasDeletedText
+ call PrintScrollableText_NoTextBoxLabel
+ or a
+ ret
+; 0x1d2b8
+
+; asks the player if the game should resume
+; from diary even though there is Duel save data
+; returns carry if "no" was selected
+AskToContinueFromDiaryWithDuelData: ; 1d2b8 (7:52b8)
+; return if there's no duel save data
+ ld a, [wHasDuelSaveData]
+ or a
+ ret z
+
+ call DisableLCD
+ farcall Func_10000
+ call Func_3ca0
+ farcall FlashWhiteScreen
+ call DoFrameIfLCDEnabled
+ ldtx hl, DataExistsWhenPowerWasTurnedOFFDuringDuelText
+ call PrintScrollableText_NoTextBoxLabel
+ ldtx hl, ContinueFromDiaryText
+ call YesOrNoMenuWithText
+ ret c
+ or a
+ ret
+; 0x1d2dd
+
+; shows disclaimer for Card Pop!
+; in case player is not playing in CGB
+; return carry if disclaimer was shown
+ShowCardPopCGBDisclaimer: ; 1d2dd (7:52dd)
+; return if playing in CGB
+ ld a, [wConsole]
+ cp CONSOLE_CGB
+ ret z
+
+ lb de, 0, 10
+ lb bc, 20, 8
+ call DrawRegularTextBox
+ lb de, 1,12
+ call InitTextPrinting
+ ldtx hl, YouCanAccessCardPopOnlyWithGameBoyColorsText
+ call PrintTextNoDelay
+ lb bc, SYM_CURSOR_D, SYM_BOX_BOTTOM
+ lb de, 18, 17
+ call SetCursorParametersForTextBox
+ call WaitForButtonAorB
+ scf
+ ret
+; 0x1d306
+
+DrawPlayerPortraitAndPrintNewGameText: ; 1d306 (7:5306)
+ call DisableLCD
+ farcall Func_10a9b
+ farcall Func_10000
+ call Func_3ca0
+ ld hl, HandleAllSpriteAnimations
+ call SetDoFrameFunction
+ lb bc, 7, 3
+ farcall $4, DrawPlayerPortrait
+ farcall Func_10af9
+ call DoFrameIfLCDEnabled
+ ldtx hl, IsCrazyAboutPokemonAndPokemonCardCollectingText
+ call PrintScrollableText_NoTextBoxLabel
+ call ResetDoFrameFunction
+ call Func_3ca0
+ ret
+; 0x1d335
+
+PlayOpeningSequence: ; 1d335 (7:5335)
+ call DisableLCD
+ farcall Func_10a9b
+ farcall Func_10000
+ call Func_3ca0
+ ld hl, HandleAllSpriteAnimations
+ call SetDoFrameFunction
+ call LoadTitleScreenSprites
+
+ ld a, LOW(OpeningSequence)
+ ld [wSequenceCmdPtr + 0], a
+ ld a, HIGH(OpeningSequence)
+ ld [wSequenceCmdPtr + 1], a
+
+ xor a
+ ld [wd317], a
+ ld [wOpeningSequencePalsNeedUpdate], a
+ ld [wSequenceDelay], a
+ farcall FlashWhiteScreen
+
+.loop_cmds
+ call DoFrameIfLCDEnabled
+ call UpdateRNGSources
+ ldh a, [hKeysPressed]
+ and A_BUTTON | START
+ jr nz, .jump_to_title_screen
+ ld a, [wOpeningSequencePalsNeedUpdate]
+ or a
+ jr z, .no_pal_update
+ farcall Func_10d74
+.no_pal_update
+ call ExecuteOpeningSequenceCmd
+ ld a, [wSequenceDelay]
+ cp $ff
+ jr nz, .loop_cmds
+ jr .asm_1d39f
+
+.jump_to_title_screen
call AssertSongFinished
or a
jr nz, .asm_1d39f
@@ -1672,54 +2468,191 @@ Titlescreen_1d386: ; 1d386 (7:5386)
lb bc, 0, 0
ld a, SCENE_TITLE_SCREEN
call LoadScene
- call Func_1d59c
+ call OpeningSequenceEmptyFunc
.asm_1d39f
call Func_3ca0
- call Func_1d3a9
+ call .ShowPressStart
call EnableLCD
ret
-Func_1d3a9: ; 1d3a9 (7:53a9)
- INCROM $1d3a9, $1d3ce
-
-Func_1d3ce: ; 1d3ce (7:53ce)
- INCROM $1d3ce, $1d42e
+.ShowPressStart
+ ld a, SPRITE_PRESS_START
+ farcall CreateSpriteAndAnimBufferEntry
+ ld c, SPRITE_ANIM_COORD_X
+ call GetSpriteAnimBufferProperty
+ ld a, 48
+ ld [hli], a ; x
+ ld a, 112
+ ld [hl], a ; y
+ ld c, $be
+ ld a, [wConsole]
+ cp CONSOLE_CGB
+ jr nz, .asm_1d3c5
+ ld c, $bf
+.asm_1d3c5
+ ld a, c
+ ld bc, 60
+ farcall Func_12ac9
+ ret
+; 0x1d3ce
-Func_1d42e: ; 1d42e (7:542e)
- INCROM $1d42e, $1d519
+LoadTitleScreenSprites: ; 1d3ce (7:53ce)
+ xor a
+ ld [wd4ca], a
+ ld [wd4cb], a
+ ld a, PALETTE_30
+ farcall LoadPaletteData
-Titlescreen_1d519: ; 1d519 (7:5519)
- ld a, MUSIC_TITLESCREEN
- call PlaySong
- call Func_1d42e
- scf
+ ld bc, 0
+ ld de, wTitleScreenSprites
+.loop_load_sprites
+ push bc
+ push de
+ ld hl, .TitleScreenSpriteList
+ add hl, bc
+ ld a, [hl]
+ farcall CreateSpriteAndAnimBufferEntry
+ ld a, [wWhichSprite]
+ ld [de], a
+ call GetFirstSpriteAnimBufferProperty
+ inc hl
+ ld a, [hl] ; SPRITE_ANIM_ATTRIBUTES
+ or c
+ ld [hl], a
+ pop de
+ pop bc
+ inc de
+ inc c
+ ld a, c
+ cp $7
+ jr c, .loop_load_sprites
ret
-; 0x1d523
- INCROM $1d523, $1d59c
+.TitleScreenSpriteList
+ db SPRITE_GRASS
+ db SPRITE_FIRE
+ db SPRITE_WATER
+ db SPRITE_COLORLESS
+ db SPRITE_LIGHTNING
+ db SPRITE_PSYCHIC
+ db SPRITE_FIGHTING
+; 0x1d408
+
+; TODO place in main.asm when possible
+INCLUDE "engine/sequences/opening_sequence_commands.asm"
+INCLUDE "data/sequences/opening_sequence.asm"
+
+; once every 63 frames randomly choose an orb sprite
+; to animate, i.e. circle around the screen
+AnimateRandomTitleScreenOrb: ; 1d614 (7:5614)
+ ld a, [wConsole]
+ cp CONSOLE_CGB
+ call z, .UpdateSpriteAttributes
+ ld a, [wd635]
+ and 63
+ ret nz ; don't pick an orb now
+
+.pick_orb
+ ld a, $7
+ call Random
+ ld c, a
+ ld b, $00
+ ld hl, wTitleScreenSprites
+ add hl, bc
+ ld a, [hl]
+ ld [wWhichSprite], a
+ farcall GetSpriteAnimCounter
+ cp $ff
+ jr nz, .pick_orb
-Func_1d59c: ; 1d59c (7:559c)
- INCROM $1d59c, $1d614
+ ld c, SPRITE_ANIM_ATTRIBUTES
+ call GetSpriteAnimBufferProperty
+ ld a, [wConsole]
+ cp CONSOLE_CGB
+ jr nz, .set_coords
+ set SPRITE_ANIM_FLAG_UNSKIPPABLE, [hl]
-Func_1d614: ; 1d614 (7:5614)
- INCROM $1d614, $1d6ad
+.set_coords
+ inc hl
+ ld a, 248
+ ld [hli], a ; SPRITE_ANIM_COORD_X
+ ld a, 14
+ ld [hl], a ; SPRITE_ANIM_COORD_Y
+ ld a, [wConsole]
+ cp CONSOLE_CGB
+ ld a, $d7
+ jr nz, .start_anim
+ ld a, $d8
+.start_anim
+ farcall StartSpriteAnimation
+ ret
+
+.UpdateSpriteAttributes
+ ld c, $7
+ ld de, wTitleScreenSprites
+.loop_orbs
+ push bc
+ ld a, [de]
+ ld [wWhichSprite], a
+ ld c, SPRITE_ANIM_COORD_X
+ call GetSpriteAnimBufferProperty
+ ld a, [hld]
+ cp 152
+ jr nz, .skip
+ res SPRITE_ANIM_FLAG_UNSKIPPABLE, [hl]
+.skip
+ pop bc
+ inc de
+ dec c
+ jr nz, .loop_orbs
+ ret
+; 0x1d67b
+
+; unreferenced
+; shows Copyright information for 300 frames
+; or until Start button is pressed
+Func_1d67b: ; 1d67b (7:567b)
+ call DisableLCD
+ farcall Func_10a9b
+ farcall Func_10000
+ ld bc, $0
+ ld a, SCENE_COPYRIGHT
+ call LoadScene
+ farcall Func_10af9
+ ld bc, 300
+.loop_frame
+ push bc
+ call DoFrameIfLCDEnabled
+ call UpdateRNGSources
+ pop bc
+ ldh a, [hKeysPressed]
+ and START
+ jr nz, .exit
+ dec bc
+ ld a, b
+ or c
+ jr nz, .loop_frame
+.exit
+ farcall Func_10ab4
+ ret
+; 0x1d6ad
Credits_1d6ad: ; 1d6ad (7:56ad)
ld a, MUSIC_STOP
call PlaySong
call Func_1d705
- call Func_1c858
+ call AddAllMastersToMastersBeatenList
xor a
ld [wOWMapEvents + 1], a
ld a, MUSIC_CREDITS
call PlaySong
- farcall Func_10031
- call Func_1d7fc
+ farcall FlashWhiteScreen
+ call SetCreditsSequenceCmdPtr
.asm_1d6c8
call DoFrameIfLCDEnabled
call Func_1d765
- call Func_1d80b
- ld a, [wd633]
+ call ExecuteCreditsSequenceCmd
+ ld a, [wSequenceDelay]
cp $ff
jr nz, .asm_1d6c8
call WaitForSongToFinish
@@ -1740,16 +2673,160 @@ Credits_1d6ad: ; 1d6ad (7:56ad)
ret
Func_1d705: ; 1d705 (7:5705)
- INCROM $1d705, $1d758
+ call DisableLCD
+ farcall Func_10a9b
+ call Func_3ca0
+ farcall Func_10000
+ call Func_1d7ee
+ ld hl, Func_3e31
+ call SetDoFrameFunction
+ call .Func_1d720 ; can be fallthrough
+ ret
+
+.Func_1d720
+ ld a, $91
+ ld [wd647], a
+ ld [wd649], a
+ ld a, $01
+ ld [wd648], a
+ ld [wd64a], a
+ call Func_1d765
+ call Set_WD_on
+ call .Func_1d73a ; can bee fallthrough
+ ret
+
+.Func_1d73a
+ push hl
+ di
+ xor a
+ ld [wd657], a
+ ld hl, wLCDCFunctionTrampoline + 1
+ ld [hl], LOW(Func_3e44)
+ inc hl
+ ld [hl], HIGH(Func_3e44)
+ ei
+
+ ld hl, rSTAT
+ set STAT_LYC, [hl]
+ xor a
+ ldh [rLYC], a
+ ld hl, rIE
+ set INT_LCD_STAT, [hl]
+ pop hl
+ ret
+; 0x1d758
Func_1d758: ; 1d758 (7:5758)
- INCROM $1d758, $1d765
+ push hl
+ ld hl, rSTAT
+ res STAT_LYC, [hl]
+ ld hl, rIE
+ res INT_LCD_STAT, [hl]
+ pop hl
+ ret
+; 0x1d765
Func_1d765: ; 1d765 (7:5765)
- INCROM $1d765, $1d7fc
+ push hl
+ push bc
+ push de
+ xor a
+ ldh [hWY], a
+
+ ld hl, wd659
+ ld de, wd65f
+ ld a, [wd648]
+ or a
+ jr nz, .asm_1d785
+ ld a, $a7
+ ldh [hWX], a
+ ld [hli], a
+ push hl
+ ld hl, wLCDC
+ set 1, [hl]
+ pop hl
+ jr .asm_1d7e2
-Func_1d7fc: ; 1d7fc (7:57fc)
- INCROM $1d7fc, $1d80b
+.asm_1d785
+ ld a, [wd647]
+ or a
+ jr z, .asm_1d79e
+ dec a
+ ld [de], a
+ inc de
+ ld a, $a7
+ ldh [hWX], a
+ ld [hli], a
+ push hl
+ ld hl, wLCDC
+ set 1, [hl]
+ pop hl
+ ld a, $07
+ jr .asm_1d7a9
-Func_1d80b: ; 1d80b (7:580b)
- INCROM $1d80b, $1e1c4
+.asm_1d79e
+ ld a, $07
+ ldh [hWX], a
+ push hl
+ ld hl, wLCDC
+ res 1, [hl]
+ pop hl
+.asm_1d7a9
+ ld [hli], a
+ ld a, [wd647]
+ dec a
+ ld c, a
+ ld a, [wd648]
+ add c
+ ld c, a
+ ld a, [wd649]
+ dec a
+ cp c
+ jr c, .asm_1d7d4
+ jr z, .asm_1d7d4
+ ld a, c
+ ld [de], a
+ inc de
+ push af
+ ld a, $a7
+ ld [hli], a
+ pop bc
+ ld a, [wd64a]
+ or a
+ jr z, .asm_1d7e2
+ ld a, [wd649]
+ dec a
+ ld [de], a
+ inc de
+ ld a, $07
+ ld [hli], a
+
+.asm_1d7d4
+ ld a, [wd649]
+ dec a
+ ld c, a
+ ld a, [wd64a]
+ add c
+ ld [de], a
+ inc de
+ ld a, $a7
+ ld [hli], a
+.asm_1d7e2
+ ld a, $ff
+ ld [de], a
+ ld a, $01
+ ld [wd665], a
+ pop de
+ pop bc
+ pop hl
+ ret
+; 0x1d7ee
+
+Func_1d7ee: ; 1d7ee (7:57ee)
+ xor a
+ lb de, 0, 32
+ lb bc, 20, 18
+ lb hl, 0, 0
+ call FillRectangle
+ ret
+; 0x1d7fc
diff --git a/src/engine/bank20.asm b/src/engine/bank20.asm
index daf4004..5481d17 100644
--- a/src/engine/bank20.asm
+++ b/src/engine/bank20.asm
@@ -867,8 +867,7 @@ LoadPaletteDataToBuffer: ; 80456 (20:4456)
ret
; 0x8047b
-; unreferenced?
-Func_8047b: ; 8047b (20:447b)
+ClearNumLoadedFramesetSubgroups: ; 8047b (20:447b)
xor a
ld [wNumLoadedFramesetSubgroups], a
ret
@@ -1416,7 +1415,7 @@ Func_80cd7: ; 80cd7 (20:4cd7)
.loop
call DoFrameIfLCDEnabled
call .HandleInput
- call Func_3cb4
+ call HandleAllSpriteAnimations
ldh a, [hKeysPressed]
and SELECT ; if select is pressed, exit
jr z, .loop
diff --git a/src/engine/home.asm b/src/engine/home.asm
index 0b60609..6935e0b 100644
--- a/src/engine/home.asm
+++ b/src/engine/home.asm
@@ -10600,10 +10600,10 @@ OverworldDoFrameFunction: ; 380e (0:380e)
call BankswitchROM
call SetScreenScrollWram
call Func_c554
- ld a, BANK(Func_1c610)
+ ld a, BANK(HandleAllNPCMovement)
call BankswitchROM
- call Func_1c610
- call Func_3cb4
+ call HandleAllNPCMovement
+ call HandleAllSpriteAnimations
ld a, BANK(DoLoadedFramesetSubgroupsFrame)
call BankswitchROM
call DoLoadedFramesetSubgroupsFrame
@@ -10698,7 +10698,7 @@ GameEvent_Duel: ; 38c0 (0:38c0)
xor a
ld [sba44], a
call DisableSRAM
- call Func_3a3b
+ call SaveGeneralSaveData
bank1call StartDuel
scf
ret
@@ -10736,11 +10736,11 @@ GameEvent_Credits: ; 3911 (0:3911)
or a
ret
-Func_3917: ; 3917 (0:3917)
+GetReceivedLegendaryCards: ; 3917 (0:3917)
ld a, EVENT_RECEIVED_LEGENDARY_CARDS
farcall GetEventValue
call EnableSRAM
- ld [s0a00a], a
+ ld [sReceivedLegendaryCards], a
call DisableSRAM
ret
@@ -10948,9 +10948,11 @@ PlayDefaultSong: ; 39fc (0:39fc)
; returns [wDefaultSong] or MUSIC_RONALD in a
GetDefaultSong: ; 3a1f (0:3a1f)
- ld a, [wd3b8]
+ ld a, [wRonaldIsInMap]
or a
jr z, .default_song
+ ; only return Ronald's theme if it's
+ ; not in one of the following maps
ld a, [wOverworldMapSelection]
cp OWMAP_ISHIHARAS_HOUSE
jr z, .default_song
@@ -10964,16 +10966,16 @@ GetDefaultSong: ; 3a1f (0:3a1f)
ld a, [wDefaultSong]
ret
-Func_3a3b: ; 3a3b (0:3a3b)
- farcall Func_1124d
+SaveGeneralSaveData: ; 3a3b (0:3a3b)
+ farcall _SaveGeneralSaveData
ret
-Func_3a40: ; 3a40 (0:3a40)
- farcall Func_11430
+LoadGeneralSaveData: ; 3a40 (0:3a40)
+ farcall _LoadGeneralSaveData
ret
-Func_3a45: ; 3a45 (0:3a45)
- farcall Func_11343
+ValidateGeneralSaveData: ; 3a45 (0:3a45)
+ farcall _ValidateGeneralSaveData
ret
; adds card with card ID in register a to collection
@@ -11236,7 +11238,7 @@ Func_3ba2: ; 3ba2 (0:3ba2)
ld a, BANK(Func_1cac5)
call BankswitchROM
call Func_1cac5
- call Func_3cb4
+ call HandleAllSpriteAnimations
pop af
call BankswitchROM
ret
@@ -11248,7 +11250,7 @@ Func_3bb5: ; 3bb5 (0:3bb5)
push af
ld a, [wDuelAnimReturnBank]
call BankswitchROM
- call Func_3cb4
+ call HandleAllSpriteAnimations
call CallHL2
pop af
call BankswitchROM
@@ -11448,12 +11450,12 @@ Func_3ca4: ; 3ca4 (0:3ca4)
call BankswitchROM
ret
-Func_3cb4: ; 3cb4 (0:3cb4)
+HandleAllSpriteAnimations: ; 3cb4 (0:3cb4)
ldh a, [hBankROM]
push af
- ld a, BANK(HandleAllSpriteAnimations)
+ ld a, BANK(_HandleAllSpriteAnimations)
call BankswitchROM
- call HandleAllSpriteAnimations
+ call _HandleAllSpriteAnimations
pop af
call BankswitchROM
ret
@@ -11700,7 +11702,7 @@ LoadScene: ; 3df3 (0:3df3)
ret
; draws player's portrait at b,c
-Func_3e10: ; 3e10 (0:3e10)
+DrawPlayerPortrait: ; 3e10 (0:3e10)
ld a, $1
ld [wd61e], a
ld a, TILEMAP_PLAYER
@@ -11726,7 +11728,7 @@ Func_3e2a: ; 3e2a (0:3e2a)
Func_3e31: ; 3e31 (0:3e31)
ldh a, [hBankROM]
push af
- call Func_3cb4
+ call HandleAllSpriteAnimations
ld a, BANK(DoLoadedFramesetSubgroupsFrame)
call BankswitchROM
call DoLoadedFramesetSubgroupsFrame
diff --git a/src/engine/sequences/credits_sequence_commands.asm b/src/engine/sequences/credits_sequence_commands.asm
new file mode 100644
index 0000000..5a7d4eb
--- /dev/null
+++ b/src/engine/sequences/credits_sequence_commands.asm
@@ -0,0 +1,484 @@
+SetCreditsSequenceCmdPtr: ; 1d7fc (7:57fc)
+ ld a, LOW(CreditsSequence)
+ ld [wSequenceCmdPtr + 0], a
+ ld a, HIGH(CreditsSequence)
+ ld [wSequenceCmdPtr + 1], a
+ xor a
+ ld [wSequenceDelay], a
+ ret
+; 0x1d80b
+
+ExecuteCreditsSequenceCmd: ; 1d80b (7:580b)
+ ld a, [wSequenceDelay]
+ or a
+ jr z, .call_func
+ cp $ff
+ ret z ; sequence ended
+
+ dec a ; still waiting
+ ld [wSequenceDelay], a
+ ret
+
+.call_func
+ ld a, [wSequenceCmdPtr + 0]
+ ld l, a
+ ld a, [wSequenceCmdPtr + 1]
+ ld h, a
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ push de
+ ld a, [hli]
+ ld c, a
+ ld a, [hli]
+ ld b, a
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ pop hl
+ call CallHL2
+ jr ExecuteCreditsSequenceCmd
+; 0x1d834
+
+ ret ; stray ret
+
+AdvanceCreditsSequenceCmdPtrBy2: ; 1d835 (7:5835)
+ ld a, 2
+ jr AdvanceCreditsSequenceCmdPtr
+
+AdvanceCreditsSequenceCmdPtrBy3: ; 1d839 (7:5839)
+ ld a, 3
+ jr AdvanceCreditsSequenceCmdPtr
+
+AdvanceCreditsSequenceCmdPtrBy5: ; 1d83d (7:583d)
+ ld a, 5
+ jr AdvanceCreditsSequenceCmdPtr
+
+AdvanceCreditsSequenceCmdPtrBy6: ; 1d841 (7:5841)
+ ld a, 6
+ jr AdvanceCreditsSequenceCmdPtr
+
+AdvanceCreditsSequenceCmdPtrBy4: ; 1d845 (7:5845)
+ ld a, 4
+; fallthrough
+
+AdvanceCreditsSequenceCmdPtr: ; 1d847 (7:5847)
+ push hl
+ ld hl, wSequenceCmdPtr
+ add [hl]
+ ld [hli], a
+ ld a, [hl]
+ adc 0
+ ld [hl], a
+ pop hl
+ ret
+; 0x1d853
+
+CreditsSequenceCmd_Wait: ; 1d853 (7:5853)
+ ld a, c
+ ld [wSequenceDelay], a
+ jp AdvanceCreditsSequenceCmdPtrBy3
+; 0x1d85a
+
+CreditsSequenceCmd_LoadScene: ; 1d85a (7:585a)
+ push bc
+ push de
+ farcall ClearNumLoadedFramesetSubgroups
+ call EmptyScreen
+ xor a
+ ldh [hSCX], a
+ ldh [hSCY], a
+ farcall Func_1288c
+ pop de
+ pop bc
+ ld a, c
+ ld c, b
+ ld b, a
+ ld a, e
+ call LoadScene
+ jp AdvanceCreditsSequenceCmdPtrBy5
+; 0x1d878
+
+CreditsSequenceCmd_LoadBooster: ; 1d878 (7:5878)
+ push bc
+ push de
+ farcall ClearNumLoadedFramesetSubgroups
+ call EmptyScreen
+ xor a
+ ldh [hSCX], a
+ ldh [hSCY], a
+ farcall Func_1288c
+ pop de
+ pop bc
+ ld a, c
+ ld c, b
+ ld b, a
+ ld a, e
+ farcall LoadBoosterGfx
+ jp AdvanceCreditsSequenceCmdPtrBy5
+; 0x1d897
+
+CreditsSequenceCmd_LoadClubMap: ; 1d897 (7:5897)
+ ld b, $00
+ ld hl, wMastersBeatenList
+ add hl, bc
+ ld a, [hl]
+ or a
+ jr nz, .at_least_1
+ inc a
+.at_least_1
+ dec a
+ ld c, a
+ add a
+ add a
+ add c ; *5
+ ld c, a
+ ld hl, .CreditsOWClubMaps
+ add hl, bc
+ ld a, [hli] ; map x coord
+ ld c, a
+ ld a, [hli] ; map y coord
+ ld b, a
+ ld a, [hli] ; map ID
+ ld e, a
+ push hl
+ call LoadOWMapForCreditsSequence
+ pop hl
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ or h
+ jr z, .done
+
+.loop_npcs
+ ld a, [hli] ; NPC ID
+ or a
+ jr z, .done
+ ld d, a
+ ld a, [hli] ; NPC x coord
+ ld c, a
+ ld a, [hli] ; NPC y coord
+ ld b, a
+ ld a, [hli] ; NPC direction
+ ld e, a
+ push hl
+ call LoadNPCForCreditsSequence
+ pop hl
+ jr .loop_npcs
+
+.done
+ jp AdvanceCreditsSequenceCmdPtrBy3
+
+credits_club_map: MACRO
+ db \1 ; x
+ db \2 ; y
+ db \3 ; OW map
+ dw \4 ; list of NPCs to load
+ENDM
+
+.CreditsOWClubMaps
+ credits_club_map 16, 0, FIGHTING_CLUB, .CreditsNPCs_FightingClub
+ credits_club_map 32, 0, ROCK_CLUB, .CreditsNPCs_RockClub
+ credits_club_map 64, 0, WATER_CLUB, .CreditsNPCs_WaterClub
+ credits_club_map 32, 0, LIGHTNING_CLUB, .CreditsNPCs_LightningClub
+ credits_club_map 32, 0, GRASS_CLUB, .CreditsNPCs_GrassClub
+ credits_club_map 32, 16, PSYCHIC_CLUB, .CreditsNPCs_PsychicClub
+ credits_club_map 0, 0, SCIENCE_CLUB, .CreditsNPCs_ScienceClub
+ credits_club_map 32, 0, FIRE_CLUB, .CreditsNPCs_FireClub
+ credits_club_map 32, 0, CHALLENGE_HALL, .CreditsNPCs_ChallengeHall
+ credits_club_map 48, 0, POKEMON_DOME, .CreditsNPCs_PokemonDome
+
+.CreditsNPCs_FightingClub
+ ; NPC ID, x, y, direction
+ db NPC_CHRIS, 4, 8, SOUTH
+ db NPC_MICHAEL, 14, 10, SOUTH
+ db NPC_JESSICA, 18, 6, EAST
+ db NPC_MITCH, 10, 4, SOUTH
+ db NPC_PLAYER_CREDITS, 10, 6, NORTH
+ db $00
+
+.CreditsNPCs_RockClub
+ ; NPC ID, x, y, direction
+ db NPC_RYAN, 20, 14, EAST
+ db NPC_GENE, 12, 6, SOUTH
+ db NPC_PLAYER_CREDITS, 12, 8, NORTH
+ db $00
+
+.CreditsNPCs_WaterClub
+ ; NPC ID, x, y, direction
+ db NPC_JOSHUA, 22, 8, SOUTH
+ db NPC_AMY, 22, 4, NORTH
+ db NPC_PLAYER_CREDITS, 18, 10, NORTH
+ db $00
+
+.CreditsNPCs_LightningClub
+ ; NPC ID, x, y, direction
+ db NPC_NICHOLAS, 6, 10, SOUTH
+ db NPC_BRANDON, 22, 12, NORTH
+ db NPC_ISAAC, 12, 4, NORTH
+ db NPC_PLAYER_CREDITS, 12, 10, NORTH
+ db $00
+
+.CreditsNPCs_GrassClub
+ ; NPC ID, x, y, direction
+ db NPC_KRISTIN, 4, 10, EAST
+ db NPC_HEATHER, 14, 16, SOUTH
+ db NPC_NIKKI, 12, 4, SOUTH
+ db NPC_PLAYER_CREDITS, 12, 6, NORTH
+ db $00
+
+.CreditsNPCs_PsychicClub
+ ; NPC ID, x, y, direction
+ db NPC_DANIEL, 8, 8, NORTH
+ db NPC_STEPHANIE, 22, 12, EAST
+ db NPC_MURRAY1, 12, 6, SOUTH
+ db NPC_PLAYER_CREDITS, 12, 8, NORTH
+ db $00
+
+.CreditsNPCs_ScienceClub
+ ; NPC ID, x, y, direction
+ db NPC_JOSEPH, 10, 10, WEST
+ db NPC_RICK, 4, 4, SOUTH
+ db NPC_PLAYER_CREDITS, 4, 6, NORTH
+ db $00
+
+.CreditsNPCs_FireClub
+ ; NPC ID, x, y, direction
+ db NPC_ADAM, 8, 14, SOUTH
+ db NPC_JONATHAN, 18, 10, SOUTH
+ db NPC_KEN, 14, 4, SOUTH
+ db NPC_PLAYER_CREDITS, 14, 6, NORTH
+ db $00
+
+.CreditsNPCs_ChallengeHall
+ ; NPC ID, x, y, direction
+ db NPC_HOST, 14, 4, SOUTH
+ db NPC_RONALD1, 18, 8, WEST
+ db NPC_PLAYER_CREDITS, 12, 8, EAST
+ db $00
+
+.CreditsNPCs_PokemonDome
+ ; NPC ID, x, y, direction
+ db NPC_COURTNEY, 18, 4, SOUTH
+ db NPC_STEVE, 22, 4, SOUTH
+ db NPC_JACK, 8, 4, SOUTH
+ db NPC_ROD, 14, 6, SOUTH
+ db NPC_PLAYER_CREDITS, 14, 10, NORTH
+ db $00
+; 0x1d9a6
+
+; bc = coordinates
+; e = OW map
+LoadOWMapForCreditsSequence: ; 1d9a6 (7:59a6)
+ push bc
+ push de
+ call EmptyScreen
+ pop de
+ pop bc
+
+ ; set input coordinates and map
+ ld a, c
+ ldh [hSCX], a
+ ld a, b
+ ldh [hSCY], a
+ ld a, e
+ ld [wCurMap], a
+
+ farcall LoadMapTilesAndPals
+ farcall Func_c9c7
+ farcall SafelyCopyBGMapFromSRAMToVRAM
+ farcall DoMapOWFrame
+ xor a
+ ld [wd4ca], a
+ ld [wd4cb], a
+ ld a, PALETTE_29
+ farcall LoadPaletteData
+ ret
+; 0x1d9d5
+
+CreditsSequenceCmd_LoadOWMap: ; 1d9d5 (7:59d5)
+ call LoadOWMapForCreditsSequence
+ jp AdvanceCreditsSequenceCmdPtrBy5
+; 0x1d9db
+
+CreditsSequenceCmd_DisableLCD: ; 1d9db (7:59db)
+ call DisableLCD
+ jp AdvanceCreditsSequenceCmdPtrBy2
+; 0x1d9e1
+
+CreditsSequenceCmd_FadeIn: ; 1d9e1 (7:59e1)
+ call DisableLCD
+ call Set_WD_on
+ farcall Func_10af9
+ jp AdvanceCreditsSequenceCmdPtrBy2
+; 0x1d9ee
+
+CreditsSequenceCmd_FadeOut: ; 1d9ee (7:59ee)
+ farcall Func_10ab4
+ call Func_3ca4
+ call EnableLCD
+ call DoFrameIfLCDEnabled
+ call DisableLCD
+ call Set_WD_off
+ jp AdvanceCreditsSequenceCmdPtrBy2
+; 0x1da04
+
+CreditsSequenceCmd_DrawRectangle: ; 1da04 (7:5a04)
+ ld a, c
+ or $20
+ ld e, a
+ ld d, $00
+ ld c, b
+ ld b, 20
+ xor a
+ lb hl, 0, 0
+ call FillRectangle
+ jp AdvanceCreditsSequenceCmdPtrBy4
+; 0x1da17
+
+CreditsSequenceCmd_PrintText: ; 1da17 (7:5a17)
+ ld a, $01
+ ld [wLineSeparation], a
+ push de
+ ld d, c
+ ld a, b
+ or $20
+ ld e, a
+ call InitTextPrinting
+ pop hl
+ call PrintTextNoDelay
+ jp AdvanceCreditsSequenceCmdPtrBy6
+; 0x1da2c
+
+CreditsSequenceCmd_PrintTextBox: ; 1da2c (7:5a2c)
+ ld a, $01
+ ld [wLineSeparation], a
+ push de
+ ld d, c
+ ld e, b
+ call InitTextPrinting
+ pop hl
+ call PrintTextNoDelay
+ jp AdvanceCreditsSequenceCmdPtrBy6
+; 0x1da3e
+
+CreditsSequenceCmd_InitOverlay: ; 1da3e (7:5a3e)
+ ld a, c
+ ld [wd647], a
+ ld a, b
+ ld [wd648], a
+ ld a, e
+ ld [wd649], a
+ ld a, d
+ ld [wd64a], a
+ call Func_1d765
+ jp AdvanceCreditsSequenceCmdPtrBy6
+; 0x1da54
+
+CreditsSequenceCmd_LoadNPC: ; 1da54 (7:5a54)
+ call LoadNPCForCreditsSequence
+ jp AdvanceCreditsSequenceCmdPtrBy6
+; 0x1da5a
+
+; bc = coordinates
+; e = direction
+; d = NPC ID
+LoadNPCForCreditsSequence: ; 1da5a (7:5a5a)
+ ld a, c
+ ld [wLoadNPCXPos], a
+ ld a, b
+ ld [wLoadNPCYPos], a
+ ld a, e
+ ld [wLoadNPCDirection], a
+ ld a, d
+ farcall LoadNPCSpriteData
+ ld a, [wNPCSpriteID]
+ farcall CreateSpriteAndAnimBufferEntry
+
+ ld c, SPRITE_ANIM_COORD_X
+ call GetSpriteAnimBufferProperty
+ ldh a, [hSCX]
+ ld c, a
+ ld a, [wLoadNPCXPos]
+ add a
+ add a
+ add a ; *8
+ add 8
+ sub c
+ ld [hli], a ; x
+ ldh a, [hSCY]
+ ld c, a
+ ld a, [wLoadNPCYPos]
+ add a
+ add a
+ add a ; *8
+ add 16
+ sub c
+ ld [hli], a ; y
+
+ ld a, [wNPCAnim]
+ ld c, a
+ ld a, [wLoadNPCDirection]
+ add c
+ farcall StartNewSpriteAnimation
+ ret
+; 0x1da9e
+
+CreditsSequenceCmd_InitVolcanoSprite: ; 1da9e (7:5a9e)
+ farcall OverworldMap_InitVolcanoSprite
+ jp AdvanceCreditsSequenceCmdPtrBy2
+; 0x1daa5
+
+CreditsSequenceCmd_TransformOverlay: ; 1daa5 (7:5aa5)
+; either stretches or shrinks overlay
+; to the input configurations
+ ld l, 0
+ ld a, [wd647]
+ call .Func_1dade
+ ld [wd647], a
+ ld a, [wd648]
+ ld c, b
+ call .Func_1dade
+ ld [wd648], a
+ ld a, [wd649]
+ ld c, e
+ call .Func_1dade
+ ld [wd649], a
+ ld a, [wd64a]
+ ld c, d
+ call .Func_1dade
+ ld [wd64a], a
+ ld a, l
+ or a
+ jr z, .advance_sequence
+ ld a, 1
+ ld [wSequenceDelay], a
+ ret
+
+.advance_sequence
+ call Func_1d765
+ jp AdvanceCreditsSequenceCmdPtrBy6
+
+; compares a with c
+; if it's smaller: increase by 2 and increment l
+; if it's larger: decrease by 2 and increment l
+; if it's equal or $ff: do nothing
+.Func_1dade
+ cp $ff
+ jr z, .done
+ cp c
+ jr z, .done
+ inc l
+ jr c, .incr_a
+; decr a
+ dec a
+ dec a
+ jr .done
+.incr_a
+ inc a
+ inc a
+.done
+ ret
+; 0x1daef
diff --git a/src/engine/sequences/opening_sequence_commands.asm b/src/engine/sequences/opening_sequence_commands.asm
new file mode 100644
index 0000000..8846c88
--- /dev/null
+++ b/src/engine/sequences/opening_sequence_commands.asm
@@ -0,0 +1,350 @@
+ExecuteOpeningSequenceCmd: ; 1d408 (7:5408)
+ ld a, [wSequenceDelay]
+ or a
+ jr z, .call_function
+ cp $ff
+ ret z ; sequence ended
+
+ dec a ; still waiting
+ ld [wSequenceDelay], a
+ ret
+
+.call_function
+ ld a, [wSequenceCmdPtr + 0]
+ ld l, a
+ ld a, [wSequenceCmdPtr + 1]
+ ld h, a
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ ld a, [hli]
+ ld c, a
+ ld a, [hli]
+ ld b, a
+ ld l, e
+ ld h, d
+ call CallHL2
+ jr c, ExecuteOpeningSequenceCmd
+ ret
+; 0x1d42e
+
+AdvanceOpeningSequenceCmdPtrBy2: ; 1d42e (7:542e)
+ ld a, 2
+ jr AdvanceOpeningSequenceCmdPtr
+
+AdvanceOpeningSequenceCmdPtrBy3: ; 1d432 (7:5432)
+ ld a, 3
+ jr AdvanceOpeningSequenceCmdPtr
+
+AdvanceOpeningSequenceCmdPtrBy4: ; 1d436 (7:5436)
+ ld a, 4
+; fallthrough
+
+AdvanceOpeningSequenceCmdPtr: ; 1d438 (7:5438)
+ push hl
+ ld hl, wSequenceCmdPtr
+ add [hl]
+ ld [hli], a
+ ld a, [hl]
+ adc 0
+ ld [hl], a
+ pop hl
+ ret
+; 0x1d444
+
+OpeningSequenceCmd_WaitOrbsAnimation: ; 1d444 (7:5444)
+ ld c, $7
+ ld de, wTitleScreenSprites
+.loop
+ ld a, [de]
+ ld [wWhichSprite], a
+ farcall GetSpriteAnimCounter
+ cp $ff
+ jr nz, .no_carry
+ inc de
+ dec c
+ jr nz, .loop
+ call AdvanceOpeningSequenceCmdPtrBy2
+ scf
+ ret
+
+.no_carry
+ or a
+ ret
+; 0x1d460
+
+OpeningSequenceCmd_Wait: ; 1d460 (7:5460)
+ ld a, c
+ ld [wSequenceDelay], a
+ call AdvanceOpeningSequenceCmdPtrBy3
+ scf
+ ret
+; 0x1d469
+
+OpeningSequenceCmd_SetOrbsAnimations: ; 1d469 (7:5469)
+ ld l, c
+ ld h, b
+
+ ld c, $7
+ ld de, wTitleScreenSprites
+.loop
+ push bc
+ push de
+ ld a, [de]
+ ld [wWhichSprite], a
+ ld a, [hli]
+ farcall StartSpriteAnimation
+ pop de
+ pop bc
+ inc de
+ dec c
+ jr nz, .loop
+
+ call AdvanceOpeningSequenceCmdPtrBy4
+ scf
+ ret
+; 0x1d486
+
+OpeningSequenceCmd_SetOrbsCoordinates: ; 1d486 (7:5486)
+ ld l, c
+ ld h, b
+
+ ld c, $7
+ ld de, wTitleScreenSprites
+.loop
+ push bc
+ push de
+ ld a, [de]
+ ld [wWhichSprite], a
+ push hl
+ ld c, SPRITE_ANIM_COORD_X
+ call GetSpriteAnimBufferProperty
+ ld e, l
+ ld d, h
+ pop hl
+ ld a, [hli]
+ add 8
+ ld [de], a ; x
+ inc de
+ ld a, [hli]
+ add 16
+ ld [de], a ; y
+ pop de
+ pop bc
+ inc de
+ dec c
+ jr nz, .loop
+
+ call AdvanceOpeningSequenceCmdPtrBy4
+ scf
+ ret
+; 0x1d4b0
+
+OpeningOrbAnimations_CharizardScene: ; 1d4b0 (7:54b0)
+ db $c0 ; GRASS
+ db $c1 ; FIRE
+ db $c1 ; WATER
+ db $c0 ; COLORLESS
+ db $c1 ; LIGHTNING
+ db $c0 ; PSYCHIC
+ db $c1 ; FIGHTING
+; 0x1d4b7
+
+OpeningOrbCoordinates_CharizardScene: ; 1d4b7 (7:54b7)
+ ; x coord, y coord
+ db 240, 28 ; GRASS
+ db 160, 120 ; FIRE
+ db 160, 8 ; WATER
+ db 240, 64 ; COLORLESS
+ db 160, 84 ; LIGHTNING
+ db 240, 100 ; PSYCHIC
+ db 160, 44 ; FIGHTING
+; 0x1d4c5
+
+OpeningOrbAnimations_ScytherScene: ; 1d4c5 (7:54c5)
+ db $c1 ; GRASS
+ db $c0 ; FIRE
+ db $c0 ; WATER
+ db $c1 ; COLORLESS
+ db $c0 ; LIGHTNING
+ db $c1 ; PSYCHIC
+ db $c0 ; FIGHTING
+; 0x1d4cc
+
+OpeningOrbCoordinates_ScytherScene: ; 1d4cc (7:54cc)
+ ; x coord, y coord
+ db 160, 28 ; GRASS
+ db 240, 120 ; FIRE
+ db 240, 8 ; WATER
+ db 160, 64 ; COLORLESS
+ db 240, 84 ; LIGHTNING
+ db 160, 100 ; PSYCHIC
+ db 240, 44 ; FIGHTING
+; 0x1d4da
+
+OpeningOrbAnimations_AerodactylScene: ; 1d4da (7:54da)
+ db $c2 ; GRASS
+ db $c5 ; FIRE
+ db $c8 ; WATER
+ db $cb ; COLORLESS
+ db $ce ; LIGHTNING
+ db $d1 ; PSYCHIC
+ db $d4 ; FIGHTING
+; 0x1d4e1
+
+OpeningOrbCoordinates_AerodactylScene: ; 1d4e1 (7:54e1)
+ ; x coord, y coord
+ db 240, 32 ; GRASS
+ db 160, 112 ; FIRE
+ db $A0, 16 ; WATER
+ db 240, 64 ; COLORLESS
+ db 160, 80 ; LIGHTNING
+ db 240, 96 ; PSYCHIC
+ db 160, 48 ; FIGHTING
+; 0x1d4ef
+
+OpeningOrbAnimations_InitialTitleScreen: ; 1d4ef (7:54ef)
+ db $c3 ; GRASS
+ db $c6 ; FIRE
+ db $c9 ; WATER
+ db $cc ; COLORLESS
+ db $cf ; LIGHTNING
+ db $d2 ; PSYCHIC
+ db $d5 ; FIGHTING
+; 0x1d4f6
+
+OpeningOrbCoordinates_InitialTitleScreen: ; 1d4f6 (7:54f6)
+ ; x coord, y coord
+ db 112, 144 ; GRASS
+ db 12, 144 ; FIRE
+ db 32, 144 ; WATER
+ db 92, 144 ; COLORLESS
+ db 52, 144 ; LIGHTNING
+ db 132, 144 ; PSYCHIC
+ db 72, 144 ; FIGHTING
+; 0x1d504
+
+OpeningOrbAnimations_InTitleScreen: ; 1d504 (7:5504)
+ db $c4 ; GRASS
+ db $c7 ; FIRE
+ db $ca ; WATER
+ db $cd ; COLORLESS
+ db $d0 ; LIGHTNING
+ db $d3 ; PSYCHIC
+ db $d6 ; FIGHTING
+; 0x1d50b
+
+OpeningOrbCoordinates_InTitleScreen: ; 1d50b (7:550b)
+ ; x coord, y coord
+ db 112, 76 ; GRASS
+ db 0, 28 ; FIRE
+ db 32, 76 ; WATER
+ db 92, 252 ; COLORLESS
+ db 52, 252 ; LIGHTNING
+ db 144, 28 ; PSYCHIC
+ db 72, 76 ; FIGHTING
+; 0x1d519
+
+OpeningSequenceCmd_PlayTitleScreenMusic: ; 1d519 (7:5519)
+ ld a, MUSIC_TITLESCREEN
+ call PlaySong
+ call AdvanceOpeningSequenceCmdPtrBy2
+ scf
+ ret
+; 0x1d523
+
+OpeningSequenceCmd_WaitSFX: ; 1d523 (7:5523)
+ call AssertSFXFinished
+ or a
+ jr nz, .no_carry
+ call AdvanceOpeningSequenceCmdPtrBy2
+ scf
+ ret
+
+.no_carry
+ or a
+ ret
+; 0x1d530
+
+OpeningSequenceCmd_PlaySFX: ; 1d530 (7:5530)
+ ld a, c
+ call PlaySFX
+ call AdvanceOpeningSequenceCmdPtrBy3
+ scf
+ ret
+; 0x1d539
+
+OpeningSequenceCmd_FadeIn: ; 1d539 (7:5539)
+ ld a, TRUE
+ ld [wOpeningSequencePalsNeedUpdate], a
+ call AdvanceOpeningSequenceCmdPtrBy2
+ scf
+ ret
+; 0x1d543
+
+OpeningSequenceCmd_FadeOut: ; 1d543 (7:5543)
+ farcall Func_10d50
+ ld a, TRUE
+ ld [wOpeningSequencePalsNeedUpdate], a
+ call AdvanceOpeningSequenceCmdPtrBy2
+ scf
+ ret
+; 0x1d551
+
+OpeningSequenceCmd_LoadCharizardScene: ; 1d551 (7:5551)
+ lb bc, 6, 3
+ ld a, SCENE_CHARIZARD_INTRO
+ jr LoadOpeningSceneAndUpdateSGBBorder
+
+OpeningSequenceCmd_LoadScytherScene: ; 1d558 (7:5558)
+ lb bc, 6, 3
+ ld a, SCENE_SCYTHER_INTRO
+ jr LoadOpeningSceneAndUpdateSGBBorder
+
+OpeningSequenceCmd_LoadAerodactylScene: ; 1d55f (7:555f)
+ lb bc, 6, 3
+ ld a, SCENE_AERODACTYL_INTRO
+; fallthrough
+
+LoadOpeningSceneAndUpdateSGBBorder: ; 1d564 (7:5564)
+ call LoadOpeningScene
+ ld l, %001010
+ lb bc, 0, 0
+ lb de, 20, 18
+ farcall Func_70498
+ scf
+ ret
+; 0x1d575
+
+OpeningSequenceCmd_LoadTitleScreenScene: ; 1d575 (7:5575)
+ lb bc, 0, 0
+ ld a, SCENE_TITLE_SCREEN
+ call LoadOpeningScene
+ call OpeningSequenceEmptyFunc
+ scf
+ ret
+; 0x1d582
+
+; a = scene ID
+; bc = coordinates for scene
+LoadOpeningScene: ; 1d582 (7:5582)
+ push af
+ push bc
+ call DisableLCD
+ pop bc
+ pop af
+
+ farcall _LoadScene ; TODO change func name?
+ farcall Func_10d17
+
+ xor a
+ ld [wOpeningSequencePalsNeedUpdate], a
+ call AdvanceOpeningSequenceCmdPtrBy2
+ call EnableLCD
+ ret
+; 0x1d59c
+
+OpeningSequenceEmptyFunc: ; 1d59c (7:559c)
+ ret
+; 0x1d59d
diff --git a/src/hram.asm b/src/hram.asm
index 6877f9c..bee2cbc 100644
--- a/src/hram.asm
+++ b/src/hram.asm
@@ -180,3 +180,6 @@ hffb5:: ; ffb5
; used in DivideBCbyDE
hffb6:: ; ffb6
ds $1
+
+hffb7:: ; ffb7
+ ds $1
diff --git a/src/layout.link b/src/layout.link
index 8fc3f61..413f9b8 100644
--- a/src/layout.link
+++ b/src/layout.link
@@ -43,6 +43,7 @@ ROMX $06
"Bank 6"
ROMX $07
"Bank 7"
+ "Credits Sequence"
"Booster Packs"
ROMX $08
"Bank 8"
diff --git a/src/macros/credits_sequence.asm b/src/macros/credits_sequence.asm
new file mode 100644
index 0000000..defe92e
--- /dev/null
+++ b/src/macros/credits_sequence.asm
@@ -0,0 +1,99 @@
+credits_seq_disable_lcd: MACRO
+ dw CreditsSequenceCmd_DisableLCD
+ENDM
+
+; x coordinate
+; y coordinate
+; OVERWORLD_* constant
+credits_seq_load_ow_map: MACRO
+ dw CreditsSequenceCmd_LoadOWMap
+ db \1, \2, \3
+ENDM
+
+credits_seq_init_volcano_sprite: MACRO
+ dw CreditsSequenceCmd_InitVolcanoSprite
+ENDM
+
+credits_seq_init_overlay: MACRO
+ dw CreditsSequenceCmd_InitOverlay
+ db \1, \2, \3, \4
+ENDM
+
+credits_seq_transform_overlay: MACRO
+ dw CreditsSequenceCmd_TransformOverlay
+ db \1, \2, \3, \4
+ENDM
+
+; x coordinate
+; y coordinate
+; text ID
+credits_seq_print_text_box: MACRO
+ dw CreditsSequenceCmd_PrintTextBox
+ db \1, \2
+ tx \3
+ENDM
+
+; x coordinate
+; y coordinate
+; text ID
+credits_seq_print_text: MACRO
+ dw CreditsSequenceCmd_PrintText
+ db \1, \2
+ tx \3
+ENDM
+
+credits_seq_fade_in: MACRO
+ dw CreditsSequenceCmd_FadeIn
+ENDM
+
+credits_seq_fade_out: MACRO
+ dw CreditsSequenceCmd_FadeOut
+ENDM
+
+; frames to wait
+credits_seq_wait: MACRO
+ dw CreditsSequenceCmd_Wait
+ db \1
+ENDM
+
+; x coordinate
+; y coordinate
+; direction
+; NPC ID
+credits_seq_load_npc: MACRO
+ dw CreditsSequenceCmd_LoadNPC
+ db \1, \2, \3, \4
+ENDM
+
+; y offset
+; heigh
+credits_seq_draw_rectangle: MACRO
+ dw CreditsSequenceCmd_DrawRectangle
+ db \1, \2
+ENDM
+
+; x coordinate
+; y coordinate
+; scene ID
+credits_seq_load_scene: MACRO
+ dw CreditsSequenceCmd_LoadScene
+ db \1, \2, \3
+ENDM
+
+; x coordinate
+; y coordinate
+; booster scene ID
+credits_seq_load_booster: MACRO
+ dw CreditsSequenceCmd_LoadBooster
+ db \1, \2, \3
+ENDM
+
+; index of beaten Club Master
+credits_seq_load_club_map: MACRO
+ dw CreditsSequenceCmd_LoadClubMap
+ db \1
+ENDM
+
+credits_seq_end: MACRO
+ credits_seq_wait $ff
+ENDM
diff --git a/src/macros/opening_sequence.asm b/src/macros/opening_sequence.asm
new file mode 100644
index 0000000..a19fc6d
--- /dev/null
+++ b/src/macros/opening_sequence.asm
@@ -0,0 +1,63 @@
+opening_seq_wait_orbs_animation: MACRO
+ dw OpeningSequenceCmd_WaitOrbsAnimation
+ENDM
+
+; argument = frames to delay
+opening_seq_wait: MACRO
+ dw OpeningSequenceCmd_Wait
+ db \1
+ENDM
+
+; argument = list of animations to set
+opening_seq_set_orbs_animations: MACRO
+ dw OpeningSequenceCmd_SetOrbsAnimations
+ dw \1
+ENDM
+
+; argument = list of coordinates to set
+opening_seq_set_orbs_coordinates: MACRO
+ dw OpeningSequenceCmd_SetOrbsCoordinates
+ dw \1
+ENDM
+
+opening_seq_play_title_screen_music: MACRO
+ dw OpeningSequenceCmd_PlayTitleScreenMusic
+ENDM
+
+opening_seq_wait_sfx: MACRO
+ dw OpeningSequenceCmd_WaitSFX
+ENDM
+
+; argument = SFX to play
+opening_seq_play_sfx: MACRO
+ dw OpeningSequenceCmd_PlaySFX
+ db \1
+ENDM
+
+opening_seq_fade_in: MACRO
+ dw OpeningSequenceCmd_FadeIn
+ENDM
+
+opening_seq_fade_out: MACRO
+ dw OpeningSequenceCmd_FadeOut
+ENDM
+
+opening_seq_load_charizard_scene: MACRO
+ dw OpeningSequenceCmd_LoadCharizardScene
+ENDM
+
+opening_seq_load_scyther_scene: MACRO
+ dw OpeningSequenceCmd_LoadScytherScene
+ENDM
+
+opening_seq_load_aerodactyl_scene: MACRO
+ dw OpeningSequenceCmd_LoadAerodactylScene
+ENDM
+
+opening_seq_load_title_screen_scene: MACRO
+ dw OpeningSequenceCmd_LoadTitleScreenScene
+ENDM
+
+opening_seq_end: MACRO
+ opening_seq_wait $ff
+ENDM
diff --git a/src/macros/scripts.asm b/src/macros/scripts.asm
index 10336ef..b8976fe 100644
--- a/src/macros/scripts.asm
+++ b/src/macros/scripts.asm
@@ -334,9 +334,9 @@ ENDM
; Sets some NPC sprite attributes
set_sprite_attributes: MACRO
run_command ScriptCommand_SetSpriteAttributes
- db \1 ; Relates to LOADED_NPC_FIELD_06
- db \2 ; Relates to LOADED_NPC_FIELD_06
- db \3 ; Relates to LOADED_NPC_FIELD_05
+ db \1 ; Relates to LOADED_NPC_ANIM
+ db \2 ; Relates to LOADED_NPC_ANIM
+ db \3 ; Relates to LOADED_NPC_FLAGS
ENDM
; Sets the active NPC's coords
@@ -603,7 +603,7 @@ wait_for_song_to_finish: MACRO
ENDM
; Records when the player defeats a master (the 8 Club Masters or the Ronald Grand Master duel)
-; the order of wins is stored in wd3bb
+; the order of wins is stored in wMastersBeatenList
; the purpose of this is still unknown
record_master_win: MACRO
run_command ScriptCommand_RecordMasterWin
diff --git a/src/main.asm b/src/main.asm
index 407ea58..b331dc8 100644
--- a/src/main.asm
+++ b/src/main.asm
@@ -24,6 +24,10 @@ INCLUDE "engine/bank06.asm"
SECTION "Bank 7", ROMX
INCLUDE "engine/bank07.asm"
+SECTION "Credits Sequence", ROMX
+INCLUDE "engine/sequences/credits_sequence_commands.asm"
+INCLUDE "data/sequences/credits_sequence.asm"
+
SECTION "Booster Packs", ROMX
INCLUDE "engine/booster_packs.asm"
diff --git a/src/sram.asm b/src/sram.asm
index b64d8c3..5d01ef5 100644
--- a/src/sram.asm
+++ b/src/sram.asm
@@ -27,7 +27,7 @@ s0a008:: ; a008
ds $1
s0a009:: ; a009
ds $1
-s0a00a:: ; a00a
+sReceivedLegendaryCards:: ; a00a
ds $1
s0a00b:: ; a00b
ds $1
@@ -39,6 +39,8 @@ sPlayerName:: ; a010
ds $e0
+sCardAndDeckSaveData::
+
; for each card, how many (0-127) the player owns
; CARD_NOT_OWNED ($80) indicates that the player has not yet seen the card
sCardCollection:: ; a100
@@ -127,16 +129,27 @@ sUnnamedDeckCounter:: ; b701
; in the Card Album PC menu
sHasPromotionalCards:: ; b703
ds $4
+sCardAndDeckSaveDataEnd::
ds $f9
+sGeneralSaveData::
sb800:: ; b800
- ds $8
+ ds $2
+
+sGeneralSaveDataByteCount:: ; b802
+ ds $2
+
+sGeneralSaveDataCheckSum:: ; b804
+ ds $2
-sb808:: ; b808
+ ds $2
+sGeneralSaveDataHeaderEnd::
+
+sMedalCount:: ; b808
ds $1
-sb809:: ; b809
+sCurOverworldMap:: ; b809
ds $1
sPlayTimeCounter:: ; b80a
@@ -194,7 +207,7 @@ sPCPackSelection:: ; b82c
ds $1
sPCPacks:: ; b82d
- ds $f
+ ds NUM_PC_PACKS
sDefaultSong:: ; b83c
ds $1
@@ -202,10 +215,10 @@ sDefaultSong:: ; b83c
sb83d:: ; b83d
ds $1
-sb83e:: ; b83e
+sRonaldIsInMap:: ; b83e
ds $1
-sb83f:: ; b83f
+sMastersBeatenList:: ; b83f
ds $a
sb849:: ; b849
@@ -229,7 +242,10 @@ sb86b:: ; b86b
sEventVars:: ; b87b
ds $40
- ds $189
+ ds $45
+sGeneralSaveDataEnd::
+
+ ds $144
sba44:: ; ba44
ds $1
@@ -299,7 +315,12 @@ ENDU
SECTION "SRAM2", SRAM
- ds $18fe
+ ds $1800
+
+sBackupGeneralSaveData:: ; b800
+ ds $bb
+
+ ds $43
; byte 1 = total number of cards collected
; byte 2 = total number of cards to collect
diff --git a/src/text/text3.asm b/src/text/text3.asm
index ffe0f59..acc143b 100644
--- a/src/text/text3.asm
+++ b/src/text/text3.asm
@@ -1269,29 +1269,29 @@ Text036b: ; 3ec03 (f:6c03)
text "Mail 15"
done
-Text036c: ; 3ec0c (f:6c0c)
+NewGameText: ; 3ec0c (f:6c0c)
text "NEW GAME"
done
-Text036d: ; 3ec16 (f:6c16)
+CardPopContinueDiaryNewGameText: ; 3ec16 (f:6c16)
text "CARD POP!"
line "CONTINUE FROM DIARY"
line "NEW GAME"
done
-Text036e: ; 3ec3e (f:6c3e)
+CardPopContinueDiaryNewGameContinueDuelText: ; 3ec3e (f:6c3e)
text "CARD POP!"
line "CONTINUE FROM DIARY"
line "New Game"
line "CONTINUE DUEL"
done
-Text036f: ; 3ec74 (f:6c74)
+WhenYouCardPopWithFriendText: ; 3ec74 (f:6c74)
text "When you CARD POP! with a friend,"
line "you will each receive a new card!"
done
-Text0370: ; 3ecb9 (f:6cb9)
+ContinueFromDiarySummaryText: ; 3ecb9 (f:6cb9)
text " <RAMNAME> <RAMTEXT>"
line " Master Medals Won "
half2full
@@ -1307,32 +1307,32 @@ Text0370: ; 3ecb9 (f:6cb9)
text ""
done
-Text0371: ; 3ed14 (f:6d14)
+StartANewGameText: ; 3ed14 (f:6d14)
text "Start a New Game."
line ""
done
-Text0372: ; 3ed28 (f:6d28)
+TheGameWillContinueFromThePointInTheDuelText: ; 3ed28 (f:6d28)
text "The Game will continue from "
line "the point in the duel at"
line "which the power was turned OFF."
done
-Text0373: ; 3ed7f (f:6d7f)
+SavedDataAlreadyExistsText: ; 3ed7f (f:6d7f)
text "Saved data already exists."
line "If you continue, you will lose"
line "all the cards you have collected."
done
-Text0374: ; 3eddc (f:6ddc)
+OKToDeleteTheDataText: ; 3eddc (f:6ddc)
text "OK to delete the data?"
done
-Text0375: ; 3edf4 (f:6df4)
+AllDataWasDeletedText: ; 3edf4 (f:6df4)
text "All data was deleted."
done
-Text0376: ; 3ee0b (f:6e0b)
+DataExistsWhenPowerWasTurnedOFFDuringDuelText: ; 3ee0b (f:6e0b)
text "Data exists from when the power "
line "was turned OFF during a duel."
line "Choose CONTINUE DUEL on the"
@@ -1347,17 +1347,17 @@ Text0376: ; 3ee0b (f:6e0b)
line "from the point saved in"
done
-Text0377: ; 3ef50 (f:6f50)
+ContinueFromDiaryText: ; 3ef50 (f:6f50)
text "CONTINUE FROM DIARY?"
done
-Text0378: ; 3ef66 (f:6f66)
+YouCanAccessCardPopOnlyWithGameBoyColorsText: ; 3ef66 (f:6f66)
text "You can access Card Pop! only"
line "with two Game Boy Colors."
line "Please play using a Game Boy Color."
done
-Text0379: ; 3efc3 (f:6fc3)
+IsCrazyAboutPokemonAndPokemonCardCollectingText: ; 3efc3 (f:6fc3)
text "<RAMNAME> is crazy about Pokémon"
line "and Pokémon card collecting!"
line "One day,"
diff --git a/src/text/text9.asm b/src/text/text9.asm
index 9bd93af..036fbd5 100644
--- a/src/text/text9.asm
+++ b/src/text/text9.asm
@@ -719,13 +719,13 @@ Text07b0: ; 56478 (15:6478)
line "when we Duel again!"
done
-Text07b1: ; 564db (15:64db)
+PokemonTradingCardGameStaffText: ; 564db (15:64db)
text ""
line " Pokémon Trading Card Game "
line " Staff"
done
-Text07b2: ; 56518 (15:6518)
+ProducersText: ; 56518 (15:6518)
text ""
line " Producers"
line ""
@@ -735,7 +735,7 @@ Text07b2: ; 56518 (15:6518)
line " Takehiro Izushi"
done
-Text07b3: ; 5658f (15:658f)
+DirectorText: ; 5658f (15:658f)
text ""
line " Director"
line ""
@@ -743,7 +743,7 @@ Text07b3: ; 5658f (15:658f)
line " Koji Arai"
done
-Text07b4: ; 565c6 (15:65c6)
+ProgrammersText: ; 565c6 (15:65c6)
text ""
line " Programmers"
line ""
@@ -753,7 +753,7 @@ Text07b4: ; 565c6 (15:65c6)
line " Masaki Tsumori"
done
-Text07b5: ; 5663a (15:663a)
+GBGraphicDesigners1Text: ; 5663a (15:663a)
text ""
line " GB Graphic Designers"
line ""
@@ -763,19 +763,19 @@ Text07b5: ; 5663a (15:663a)
line " Tsuguyuki Yamamoto"
done
-Text07b6: ; 566b5 (15:66b5)
+GBGraphicDesigners2Text: ; 566b5 (15:66b5)
text " Yasuhiro Ichizawa"
line " Miwa Matsuda"
line " Norihiro Kanie"
done
-Text07b7: ; 5670b (15:670b)
+GBGraphicDesigners3Text: ; 5670b (15:670b)
text " Kazushi Kousaka"
line " Hiromi Sugiue"
line " Katsuhisa Nishikawa"
done
-Text07b8: ; 56764 (15:6764)
+MusicText: ; 56764 (15:6764)
text ""
line " Music"
line ""
@@ -783,7 +783,7 @@ Text07b8: ; 56764 (15:6764)
line " Ichiro Shimakura"
done
-Text07b9: ; 5679d (15:679d)
+SoundEffectsText: ; 5679d (15:679d)
text ""
line " Sound Effects"
line ""
@@ -791,7 +791,7 @@ Text07b9: ; 5679d (15:679d)
line " Masato Aihara"
done
-Text07ba: ; 567d9 (15:67d9)
+SoundDirectorText: ; 567d9 (15:67d9)
text ""
line " Sound Director"
line ""
@@ -799,7 +799,7 @@ Text07ba: ; 567d9 (15:67d9)
line " Toshiaki Takimoto"
done
-Text07bb: ; 56817 (15:6817)
+SoundSystemSupportText: ; 56817 (15:6817)
text ""
line " Sound System Support"
line ""
@@ -808,7 +808,7 @@ Text07bb: ; 56817 (15:6817)
line " Hideki Oka"
done
-Text07bc: ; 56873 (15:6873)
+CardGameCreator1Text: ; 56873 (15:6873)
text ""
line " Card Game Creator"
line ""
@@ -816,7 +816,7 @@ Text07bc: ; 56873 (15:6873)
line " Takumi Akabane"
done
-Text07bd: ; 568b1 (15:68b1)
+CardGameCreator2Text: ; 568b1 (15:68b1)
text ""
line " Card Game Creator"
line ""
@@ -824,7 +824,7 @@ Text07bd: ; 568b1 (15:68b1)
line " Kouichi Oyama"
done
-Text07be: ; 568ee (15:68ee)
+CardGameCreator3Text: ; 568ee (15:68ee)
text ""
line " Card Game Creator"
line ""
@@ -832,7 +832,7 @@ Text07be: ; 568ee (15:68ee)
line " Akihiko Miura"
done
-Text07bf: ; 5692c (15:692c)
+CardIllustrators1Text: ; 5692c (15:692c)
text ""
line " Card Illustrators"
line ""
@@ -843,14 +843,14 @@ Text07bf: ; 5692c (15:692c)
line " Kagemaru Himeno"
done
-Text07c0: ; 569c0 (15:69c0)
+CardIllustrators2Text: ; 569c0 (15:69c0)
text " Tomoaki Imakuni"
line " Miki Tanaka"
line " Toshinao Aoki"
line " Benimaru Ito"
done
-Text07c1: ; 56a30 (15:6a30)
+SpecialAppearances1Text: ; 56a30 (15:6a30)
text ""
line " Special Appearances by"
line ""
@@ -859,12 +859,12 @@ Text07c1: ; 56a30 (15:6a30)
line " Masako Uchiyama"
done
-Text07c2: ; 56a8c (15:6a8c)
+SpecialAppearances2Text: ; 56a8c (15:6a8c)
text " Kunimi Kawamura"
line " Imakuni?"
done
-Text07c3: ; 56ac3 (15:6ac3)
+USCoordination1Text: ; 56ac3 (15:6ac3)
text ""
line " US COORDINATION"
line " NINTENDO OF AMERICA"
@@ -874,12 +874,12 @@ Text07c3: ; 56ac3 (15:6ac3)
line " HIRO NAKAMURA"
done
-Text07c4: ; 56b3a (15:6b3a)
+USCoordination2Text: ; 56b3a (15:6b3a)
text " KENJI OKUBO"
line " WILLIAM TRINEN"
done
-Text07c5: ; 56b71 (15:6b71)
+USCoordination3Text: ; 56b71 (15:6b71)
text ""
line " US COORDINATION"
line " Wizards of the Coast"
@@ -890,13 +890,13 @@ Text07c5: ; 56b71 (15:6b71)
line " Jessica Beaven"
done
-Text07c6: ; 56c0d (15:6c0d)
+USCoordination4Text: ; 56c0d (15:6c0d)
text " Paul Peterson"
line " Michael G. Ryan"
line " Tom Wylie"
done
-Text07c7: ; 56c5e (15:6c5e)
+TranslationDraftText: ; 56c5e (15:6c5e)
text ""
line " TRANSLATION/DRAFT"
line ""
@@ -904,7 +904,7 @@ Text07c7: ; 56c5e (15:6c5e)
line " BILL RITCH"
done
-Text07c8: ; 56c9a (15:6c9a)
+MasteringText: ; 56c9a (15:6c9a)
text ""
line " Mastering"
line ""
@@ -912,7 +912,7 @@ Text07c8: ; 56c9a (15:6c9a)
line " Tetsuya Komatsu"
done
-Text07c9: ; 56cd5 (15:6cd5)
+ManualCreationText: ; 56cd5 (15:6cd5)
text ""
line " Manual Creation"
line ""
@@ -920,7 +920,7 @@ Text07c9: ; 56cd5 (15:6cd5)
line " Haruki Mitani"
done
-Text07ca: ; 56d12 (15:6d12)
+ManualIllustrationsText: ; 56d12 (15:6d12)
text ""
line " Manual Illustrations"
line ""
@@ -928,7 +928,7 @@ Text07ca: ; 56d12 (15:6d12)
line " Kagemaru Himeno"
done
-Text07cb: ; 56d53 (15:6d53)
+PokemonOriginalStoryText: ; 56d53 (15:6d53)
text ""
line " Pokémon Original Story"
line ""
@@ -937,7 +937,7 @@ Text07cb: ; 56d53 (15:6d53)
line ""
done
-Text07cc: ; 56d95 (15:6d95)
+CreatedInCooperationWithText: ; 56d95 (15:6d95)
text ""
line " Created In Cooperation With"
line ""
@@ -947,7 +947,7 @@ Text07cc: ; 56d95 (15:6d95)
line " Takahiro Harada"
done
-Text07cd: ; 56e11 (15:6e11)
+WithCooperation1Text: ; 56e11 (15:6e11)
text ""
line " With Cooperation from"
line ""
@@ -957,21 +957,21 @@ Text07cd: ; 56e11 (15:6e11)
line " Keigo Yasuda"
done
-Text07ce: ; 56e8a (15:6e8a)
+WithCooperation2Text: ; 56e8a (15:6e8a)
text " Yusuke Kurushima"
line " Nobuchika Takahashi"
line " Junko Igarashi"
line " Yukiko Tomita"
done
-Text07cf: ; 56eff (15:6eff)
+WithCooperation3Text: ; 56eff (15:6eff)
text " Mari Matsuda"
line " Moto Yamaguchi"
line " Shigeru Sato"
line " Chiaki Nishiki"
done
-Text07d0: ; 56f6e (15:6f6e)
+ProjectManagerText: ; 56f6e (15:6f6e)
text ""
line " Project Manager"
line ""
@@ -979,7 +979,7 @@ Text07d0: ; 56f6e (15:6f6e)
line " Yasutaka Kakiseko"
done
-Text07d1: ; 56fad (15:6fad)
+SupervisorText: ; 56fad (15:6fad)
text ""
line " Supervisor"
line ""
@@ -988,7 +988,7 @@ Text07d1: ; 56fad (15:6fad)
line " Hiroshi Kudo"
done
-Text07d2: ; 56fe7 (15:6fe7)
+ExecutiveProducerText: ; 56fe7 (15:6fe7)
text ""
line " Executive Producer"
line ""
@@ -997,7 +997,7 @@ Text07d2: ; 56fe7 (15:6fe7)
line " Hiroshi Yamauchi"
done
-Text07d3: ; 57027 (15:7027)
+CreatedByText: ; 57027 (15:7027)
text ""
line " Created by"
line ""
diff --git a/src/text/text_offsets.asm b/src/text/text_offsets.asm
index b9d2561..7040fc8 100644
--- a/src/text/text_offsets.asm
+++ b/src/text/text_offsets.asm
@@ -877,20 +877,20 @@ TextOffsets:: ; 34000 (d:4000)
textpointer Text0369 ; 0x0369
textpointer Text036a ; 0x036a
textpointer Text036b ; 0x036b
- textpointer Text036c ; 0x036c
- textpointer Text036d ; 0x036d
- textpointer Text036e ; 0x036e
- textpointer Text036f ; 0x036f
- textpointer Text0370 ; 0x0370
- textpointer Text0371 ; 0x0371
- textpointer Text0372 ; 0x0372
- textpointer Text0373 ; 0x0373
- textpointer Text0374 ; 0x0374
- textpointer Text0375 ; 0x0375
- textpointer Text0376 ; 0x0376
- textpointer Text0377 ; 0x0377
- textpointer Text0378 ; 0x0378
- textpointer Text0379 ; 0x0379
+ textpointer NewGameText ; 0x036c
+ textpointer CardPopContinueDiaryNewGameText ; 0x036d
+ textpointer CardPopContinueDiaryNewGameContinueDuelText ; 0x036e
+ textpointer WhenYouCardPopWithFriendText ; 0x036f
+ textpointer ContinueFromDiarySummaryText ; 0x0370
+ textpointer StartANewGameText ; 0x0371
+ textpointer TheGameWillContinueFromThePointInTheDuelText ; 0x0372
+ textpointer SavedDataAlreadyExistsText ; 0x0373
+ textpointer OKToDeleteTheDataText ; 0x0374
+ textpointer AllDataWasDeletedText ; 0x0375
+ textpointer DataExistsWhenPowerWasTurnedOFFDuringDuelText ; 0x0376
+ textpointer ContinueFromDiaryText ; 0x0377
+ textpointer YouCanAccessCardPopOnlyWithGameBoyColorsText ; 0x0378
+ textpointer IsCrazyAboutPokemonAndPokemonCardCollectingText ; 0x0379
textpointer Text037a ; 0x037a
textpointer Text037b ; 0x037b
textpointer Text037c ; 0x037c
@@ -1970,41 +1970,41 @@ TextOffsets:: ; 34000 (d:4000)
textpointer Text07ae ; 0x07ae
textpointer Text07af ; 0x07af
textpointer Text07b0 ; 0x07b0
- textpointer Text07b1 ; 0x07b1
- textpointer Text07b2 ; 0x07b2
- textpointer Text07b3 ; 0x07b3
- textpointer Text07b4 ; 0x07b4
- textpointer Text07b5 ; 0x07b5
- textpointer Text07b6 ; 0x07b6
- textpointer Text07b7 ; 0x07b7
- textpointer Text07b8 ; 0x07b8
- textpointer Text07b9 ; 0x07b9
- textpointer Text07ba ; 0x07ba
- textpointer Text07bb ; 0x07bb
- textpointer Text07bc ; 0x07bc
- textpointer Text07bd ; 0x07bd
- textpointer Text07be ; 0x07be
- textpointer Text07bf ; 0x07bf
- textpointer Text07c0 ; 0x07c0
- textpointer Text07c1 ; 0x07c1
- textpointer Text07c2 ; 0x07c2
- textpointer Text07c3 ; 0x07c3
- textpointer Text07c4 ; 0x07c4
- textpointer Text07c5 ; 0x07c5
- textpointer Text07c6 ; 0x07c6
- textpointer Text07c7 ; 0x07c7
- textpointer Text07c8 ; 0x07c8
- textpointer Text07c9 ; 0x07c9
- textpointer Text07ca ; 0x07ca
- textpointer Text07cb ; 0x07cb
- textpointer Text07cc ; 0x07cc
- textpointer Text07cd ; 0x07cd
- textpointer Text07ce ; 0x07ce
- textpointer Text07cf ; 0x07cf
- textpointer Text07d0 ; 0x07d0
- textpointer Text07d1 ; 0x07d1
- textpointer Text07d2 ; 0x07d2
- textpointer Text07d3 ; 0x07d3
+ textpointer PokemonTradingCardGameStaffText ; 0x07b1
+ textpointer ProducersText ; 0x07b2
+ textpointer DirectorText ; 0x07b3
+ textpointer ProgrammersText ; 0x07b4
+ textpointer GBGraphicDesigners1Text ; 0x07b5
+ textpointer GBGraphicDesigners2Text ; 0x07b6
+ textpointer GBGraphicDesigners3Text ; 0x07b7
+ textpointer MusicText ; 0x07b8
+ textpointer SoundEffectsText ; 0x07b9
+ textpointer SoundDirectorText ; 0x07ba
+ textpointer SoundSystemSupportText ; 0x07bb
+ textpointer CardGameCreator1Text ; 0x07bc
+ textpointer CardGameCreator2Text ; 0x07bd
+ textpointer CardGameCreator3Text ; 0x07be
+ textpointer CardIllustrators1Text ; 0x07bf
+ textpointer CardIllustrators2Text ; 0x07c0
+ textpointer SpecialAppearances1Text ; 0x07c1
+ textpointer SpecialAppearances2Text ; 0x07c2
+ textpointer USCoordination1Text ; 0x07c3
+ textpointer USCoordination2Text ; 0x07c4
+ textpointer USCoordination3Text ; 0x07c5
+ textpointer USCoordination4Text ; 0x07c6
+ textpointer TranslationDraftText ; 0x07c7
+ textpointer MasteringText ; 0x07c8
+ textpointer ManualCreationText ; 0x07c9
+ textpointer ManualIllustrationsText ; 0x07ca
+ textpointer PokemonOriginalStoryText ; 0x07cb
+ textpointer CreatedInCooperationWithText ; 0x07cc
+ textpointer WithCooperation1Text ; 0x07cd
+ textpointer WithCooperation2Text ; 0x07ce
+ textpointer WithCooperation3Text ; 0x07cf
+ textpointer ProjectManagerText ; 0x07d0
+ textpointer SupervisorText ; 0x07d1
+ textpointer ExecutiveProducerText ; 0x07d2
+ textpointer CreatedByText ; 0x07d3
textpointer Text07d4 ; 0x07d4
textpointer Text07d5 ; 0x07d5
textpointer Text07d6 ; 0x07d6
@@ -2124,7 +2124,7 @@ TextOffsets:: ; 34000 (d:4000)
textpointer CobraName ; 0x0848
textpointer ArbokDescription ; 0x0849
textpointer NidoranFName ; 0x084a
- textpointer FurySwipesName ; 0x084b
+ textpointer FurySwipesName ; 0x084b
textpointer TripleAttackX10Description ; 0x084c
textpointer CallForFamilyName ; 0x084d
textpointer NidoranFsCallForFamilyDescription ; 0x084e
diff --git a/src/wram.asm b/src/wram.asm
index 4bfbc8d..fd18f8a 100644
--- a/src/wram.asm
+++ b/src/wram.asm
@@ -2389,7 +2389,7 @@ wPCPackSelection:: ; d11d
; 7th bit of each pack corresponds to whether or not it's been read
wPCPacks:: ; d11e
- ds $f
+ ds NUM_PC_PACKS
wPCLastDirectionPressed:: ; d12d
ds $1
@@ -2497,14 +2497,30 @@ wd291:: ; d291
wWriteBGMapToSRAM:: ; d292
ds $1
- ds $4
+wd293:: ; d293
+ ds $1
+
+wd294:: ; d294
+ ds $1
+
+wd295:: ; d295
+ ds $1
+
+wd296:: ; d296
+ ds $1
; temporarily holds the palettes from
; wBackgroundPalettesCGB
wTempBackgroundPalettesCGB:: ; d297
- ds 8 palettes
+ ds NUM_BACKGROUND_PALETTES palettes
- ds $41
+; temporarily holds the palettes from
+; wObjectPalettesCGB
+wTempObjectPalettesCGB:: ; d2d7
+ ds NUM_OBJECT_PALETTES palettes
+
+wd317:: ; d317
+ ds $1
; pointer to the data of current map OW frameset
wCurMapOWFrameset:: ; d318
@@ -2620,7 +2636,8 @@ wOverworldMapPlayerHorizontalSubPixelPosition:: ; d347
wOverworldMapPlayerVerticalSubPixelPosition:: ; d348
ds $1
-wd349:: ; d349
+; total number of NPCs that are currently loaded
+wNumLoadedNPCs:: ; d349
ds $1
wLoadedNPCs:: ; d34a
@@ -2651,10 +2668,10 @@ wLoadNPCDirection:: ; d3ae
wLoadNPCFunction:: ; d3af
ds $2
-wd3b1:: ; d3b1
+wNPCAnim:: ; d3b1
ds $1
-wd3b2:: ; d3b2
+wNPCAnimFlags:: ; d3b2
ds $1
; sprite ID of the NPC to load
@@ -2667,24 +2684,39 @@ wNPCSpriteID:: ; d3b3
wScriptNPC:: ; d3b6
ds $1
-wc3b7:: ; d3b7
+; bit 6 will be set if an NPC is currently moving
+wIsAnNPCMoving:: ; d3b7
ds $1
-wd3b8:: ; d3b8
+; whether Ronald is in the current map
+; is used to load his theme whenever he is present
+wRonaldIsInMap:: ; d3b8
ds $1
wd3b9:: ; d3b9
ds $2
-wd3bb:: ; d3bb
+wMastersBeatenList:: ; d3bb
ds $a
- ds $6
+wGeneralSaveDataCheckSum:: ; d3c5
+ ds $2
-wd3cb:: ; d3cb
+wNumSRAMValidationErrors:: ; d3c7
ds $1
-wd3cc:: ; d3cc
+; play time hours and minutes
+; byte 0: minutes
+; byte 1: hours (lower byte)
+; byte 2: hours (higher byte)
+; unused?
+wPlayTimeHourMinutes:: ; d3c8
+ ds $3
+
+wCurOverworldMap:: ; d3cb
+ ds $1
+
+wMedalCount:: ; d3cc
ds $1
; total number of cards the player has collected
@@ -2727,7 +2759,16 @@ wd416:: ; d416
wd417:: ; d417
ds $1
- ds $5
+ ds $3
+
+; used in Func_1c890
+wd41b:: ; d41b
+ ds $1
+
+; used in Func_1c890
+; is read like a sprite index
+wd41c:: ; d41c
+ ds $1
wd41d:: ; d41d
ds $1
@@ -2865,6 +2906,9 @@ wCurSpriteTileSize:: ; d4c7
; stores number of tiles that current sprite/tileset has
wTotalNumTiles:: ; d4c8
+
+; checksum?
+wGeneralSaveDataByteCount:: ; d4c8
ds $2
; stores tile offset in VRAM
@@ -2978,34 +3022,71 @@ wSceneSGBPacketPtr:: ; d620
wSceneSGBRoutinePtr:: ; d622
ds $2
-wd624:: ; d624
+; whether there exists valid save data
+wHasSaveData:: ; d624
ds $1
+; whether has valid duel save data
+wHasDuelSaveData:: ; d625
ds $1
-wd626:: ; d626
+; keep track of which Start Menu item
+; is currently highlighted
+wCurHighlightedStartMenuItem:: ; d626
+
+; used to keep track of the time
+; in which the Title Screen ignores
+; the player's input
+wTitleScreenIgnoreInputCounter:: ; d626
ds $1
-wd627:: ; d627
+wLastSelectedStartMenuItem:: ; d627
ds $1
-wd628:: ; d628
+; START_MENU_* constant chosen
+; by the player in the Start Menu
+wStartMenuChoice:: ; d628
ds $1
- ds $a
+; list of sprites used in the Title Screen
+wTitleScreenSprites:: ; d629
+ ds $7
+
+ ds $1
+
+; pointer to commands used by opening and credits sequence
+; (see OpeningSequence and CreditsSequence)
+wSequenceCmdPtr:: ; d631
+ ds $2
-wd633:: ; d633
+; when non-zero, is decremented and only
+; executes the next sequence command when it's 0
+; when it's $ff, it is interpreted as end of sequence
+wSequenceDelay:: ; d633
ds $1
+wOpeningSequencePalsNeedUpdate:: ; d634
ds $1
wd635:: ; d635
ds $1
-wd636:: ; d635
+; has parameters used for the Start Menu
+; check SetStartMenuParams for what parameters are set
+wStartMenuParams:: ; d636
+ ds $11
+
+wd647:: ; d647
+ ds $1
+
+wd648:: ; d648
ds $1
- ds $14
+wd649:: ; d649
+ ds $1
+
+wd64a:: ; d64a
+ ds $1
; wd64b to wd665 used by Func_3e44
wd64b:: ; d64b