From f33a04193092e3df8c9b1ac4f560018b95925f61 Mon Sep 17 00:00:00 2001 From: Rangi Date: Sat, 12 Mar 2022 22:38:29 -0500 Subject: [PATCH] Allow alternate labels for patch names --- Makefile | 43 ++++++++++++++------------- docs/vc_patch.md | 8 +++-- engine/battle_anims/anim_commands.asm | 10 ++----- engine/menus/save.asm | 2 +- tools/make_patch.c | 22 ++++++++++---- vc/pokecrystal11.patch.template | 18 +++++------ 6 files changed, 55 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index 6ee999c8f..e4ef0a41d 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,28 @@ -roms := pokecrystal.gbc \ - pokecrystal11.gbc \ - pokecrystal_au.gbc \ - pokecrystal_debug.gbc \ - pokecrystal11_debug.gbc +roms := \ + pokecrystal.gbc \ + pokecrystal11.gbc \ + pokecrystal_au.gbc \ + pokecrystal_debug.gbc \ + pokecrystal11_debug.gbc patches := pokecrystal11.patch rom_obj := \ -audio.o \ -home.o \ -main.o \ -wram.o \ -data/text/common.o \ -data/maps/map_data.o \ -data/pokemon/dex_entries.o \ -data/pokemon/egg_moves.o \ -data/pokemon/evos_attacks.o \ -engine/movie/credits.o \ -engine/overworld/events.o \ -gfx/misc.o \ -gfx/pics.o \ -gfx/sprites.o \ -gfx/tilesets.o \ -lib/mobile/main.o + audio.o \ + home.o \ + main.o \ + wram.o \ + data/text/common.o \ + data/maps/map_data.o \ + data/pokemon/dex_entries.o \ + data/pokemon/egg_moves.o \ + data/pokemon/evos_attacks.o \ + engine/movie/credits.o \ + engine/overworld/events.o \ + gfx/misc.o \ + gfx/pics.o \ + gfx/sprites.o \ + gfx/tilesets.o \ + lib/mobile/main.o pokecrystal_obj := $(rom_obj:.o=.o) pokecrystal11_obj := $(rom_obj:.o=11.o) diff --git a/docs/vc_patch.md b/docs/vc_patch.md index 55aa2f11d..dde8dd680 100644 --- a/docs/vc_patch.md +++ b/docs/vc_patch.md @@ -46,11 +46,11 @@ tools/make_patch pokecrystal11_vc.sym vc/pokecrystal11.constants.sym pokecrystal ## Patch types -**Hooks** do not directly modify the ROM; they just identify locations within the ROM code. When the emulated code execution reaches a hook, the emulator performs an emulation function. For example, the `BiographySave_ret` hook is located after the code to add a new Hall of Fame entry, and causes the emulator to edit the save file to enable the GS Ball event. +**Hooks** do not directly modify the ROM; they just identify locations within the ROM code. When the emulated code execution reaches a hook, the emulator performs an emulation function. For example, the `Enable_GS_Ball_mobile_event` hook is located after the code to add a new Hall of Fame entry, and causes the emulator to edit the save file to enable the GS Ball event. Hooks are defined with the `vc_hook` macro, which defines a label starting with "`.VC_`" for the patch template file to use. -**Patches** directly modify the contents of the ROM. This is done before emulation begins. For example, the `print forbid 1` patch modifies an "`and A_BUTTON`" instruction to "`and 0`", so pressing A will not print Unown on the Game Boy Printer. +**Patches** directly modify the contents of the ROM. This is done before emulation begins. For example, the `print_forbid_1` patch modifies an "`and A_BUTTON`" instruction to "`and 0`", so pressing A will not print Unown on the Game Boy Printer. Patches are defined with the `vc_patch` and `vc_patch_end` macros; `vc_patch` defines a label starting with "`.VC_`", `vc_patch_end` defines a corresponding label with "`_End`" appended. Between these two macros, the code or data is conditionally different depending on whether or not a patch file is being built. @@ -63,7 +63,9 @@ The sole purpose of creating `pokecrystal11_vc.gbc` and `pokecrystal11_vc.sym` i **Patch names** are contained in "`[`" brackets "`]`". They are output as-is, without interpreting commands. -Patch names also set the **current patch label**. This is the label starting with "`.VC_`" followed by the patch name, with any invalid characters (not letters "`A-Z`", digits "`0-9`", underscore "`_`", at sign "`@`", or hash "`#`") converted to underscores "`_`". These labels are conditionally defined only when building the patch file with the `vc_hook` and `vc_patch` macros. For example, the patch name "`[fight begin]`" corresponds to the patch label "`.VC_fight_begin`", generated by the "`vc_hook fight_begin`" macro. +Patch names also set the **current patch label**. This is the label starting with "`.VC_`" followed by the patch name, with any invalid characters (not letters "`A-Z`", digits "`0-9`", or underscore "`_`") converted to underscores "`_`". These labels are conditionally defined only when building the patch file with the `vc_hook` and `vc_patch` macros. For example, the patch name "`[fight begin]`" corresponds to the patch label "`.VC_fight_begin`", generated by the "`vc_hook fight_begin`" macro. + +Patch names may designate an alternate for the label with an at-sign "`@`". This allows the label in the assembly source to have a more descriptive name, while still reproducing the original `.patch` file. For example, the patch name "`[BiographySave_ret@Enable_GS_Ball_mobile_event]`" corresponds to the label "`.VC_Enable_GS_Ball_mobile_event`" but is output as "`[BiographySave_ret]`". **Commands** are contained in "`{`" braces "`}`". They are not output themselves, but may produce their own output when interpreted. diff --git a/engine/battle_anims/anim_commands.asm b/engine/battle_anims/anim_commands.asm index d6d874240..e67cea281 100644 --- a/engine/battle_anims/anim_commands.asm +++ b/engine/battle_anims/anim_commands.asm @@ -58,20 +58,14 @@ BattleAnimRunScript: farcall CheckBattleScene jr c, .disabled - vc_hook FPA_001_Begin - vc_hook FPA_002_Begin - vc_hook FPA_003_Begin - vc_hook FPA_004_Begin - vc_hook FPA_005_Begin - vc_hook FPA_006_Begin - vc_hook FPA_007_Begin + vc_hook Reduce_move_anim_flashing call BattleAnimClearHud call RunBattleAnimScript call BattleAnimAssignPals call BattleAnimRequestPals - vc_hook FPA_001_End + vc_hook Stop_reducing_move_anim_flashing xor a ldh [hSCX], a ldh [hSCY], a diff --git a/engine/menus/save.asm b/engine/menus/save.asm index 381e3cc7c..02a2541e8 100644 --- a/engine/menus/save.asm +++ b/engine/menus/save.asm @@ -165,7 +165,7 @@ AddHallOfFameEntry: ; to MOBILE_EVENT_OBJECT_GS_BALL ($b), which enables you to get the GS Ball, take it to Kurt, and ; encounter Celebi. It assumes that sMobileEventIndex and sMobileEventIndexBackup are at their ; original addresses. - vc_hook BiographySave_ret + vc_hook Enable_GS_Ball_mobile_event vc_assert BANK(sMobileEventIndex) == $1 && sMobileEventIndex == $be3c, \ "sMobileEventIndex is no longer located at 01:be3c." vc_assert BANK(sMobileEventIndexBackup) == $1 && sMobileEventIndexBackup == $be44, \ diff --git a/tools/make_patch.c b/tools/make_patch.c index 9546349da..a67a4a399 100644 --- a/tools/make_patch.c +++ b/tools/make_patch.c @@ -344,16 +344,26 @@ struct Buffer *process_template(const char *template_filename, const char *patch case '[': // "[...]" is a patch label; buffer its contents putc(c, output); + bool alternate = false; buffer->size = 0; for (c = getc(input); c != EOF; c = getc(input)) { - putc(c, output); - if (c == ']') { + if (!alternate && c == '@') { + // "@" designates an alternate name for the ".VC_" label + alternate = true; + buffer->size = 0; + } else if (c == ']') { + putc(c, output); break; - } else if (!isalnum(c) && c != '_' && c != '@' && c != '#') { - // Convert non-identifier characters to underscores - c = '_'; + } else { + if (!alternate) { + putc(c, output); + if (!isalnum(c) && c != '_') { + // Convert non-identifier characters to underscores + c = '_'; + } + } + buffer_append(buffer, &c); } - buffer_append(buffer, &c); } buffer_append(buffer, &(char []){'\0'}); // The current patch should have a corresponding ".VC_" label diff --git a/vc/pokecrystal11.patch.template b/vc/pokecrystal11.patch.template index ae5dd8db6..134a51520 100644 --- a/vc/pokecrystal11.patch.template +++ b/vc/pokecrystal11.patch.template @@ -235,7 +235,7 @@ Address = {HEx @} Fixcode={db SCREEN_HEIGHT_PX} ;12 1b 0b 79 b0 find next C9 -[BiographySave_ret] +[BiographySave_ret@Enable_GS_Ball_mobile_event] Mode = 2 Address = {HEX @} Type = 60 @@ -425,7 +425,7 @@ Type = 103 ;Dark0 = 10 ;0~10 (for Normal Mode) ;012532 ; -[FPA 001 Begin] +[FPA 001 Begin@Reduce_move_anim_flashing] Mode = 3 Type = 0 Address = {hex @} @@ -459,7 +459,7 @@ ConditionValueC = {dws_ FISSURE } ;s e l d e s c ; -[FPA 002 Begin] +[FPA 002 Begin@Reduce_move_anim_flashing] Mode = 3 Type = 0 Address = {hex @} @@ -475,7 +475,7 @@ ConditionValueC = {dws_ SELFDESTRUCT} ; lightening ; -------------- Mem Write: pc32 = 0x35d09 addr = 0xcfb6 value = 0x57 -[FPA 003 Begin] +[FPA 003 Begin@Reduce_move_anim_flashing] Mode = 3 Type = 0 Address = {hex @} @@ -493,7 +493,7 @@ ConditionValueC = {dws_ THUNDER } ;ji wa lei 011800 -[FPA 004 Begin] +[FPA 004 Begin@Reduce_move_anim_flashing] Mode = 3 Type = 0 Address = {hex @} @@ -516,7 +516,7 @@ ConditionValueC = {dws_ FLASH } ; include 2 pieces of animationl. ;ji ba lu 011607 -[FPA 005 Begin] +[FPA 005 Begin@Reduce_move_anim_flashing] Mode = 3 Type = 0 Address = {hex @} @@ -538,7 +538,7 @@ ConditionValueC = {dws_ EXPLOSION} ;skill name 6 : ..............Mem Write: pc32 = 0x30db addr = 0xcf8c value = 0xc2 ; da yi ba ha ku ci 011441 -[FPA 006 Begin] +[FPA 006 Begin@Reduce_move_anim_flashing] Mode = 3 Type = 0 Address = {hex @} @@ -561,7 +561,7 @@ ConditionValueC = {dws_ HORN_DRILL} ;skill name 6 : ..............Mem Write: pc32 = 0x30db addr = 0xcf8c value = 0x50 ; 011251 ; -[FPA 007 Begin] +[FPA 007 Begin@Reduce_move_anim_flashing] Mode = 3 Type = 0 Address = {hex @} @@ -618,7 +618,7 @@ ConditionValueC = {dws_ PRESENT anim_1gfx_command} ;exit point -[FPA 001 End] +[FPA 001 End@Stop_reducing_move_anim_flashing] Mode = 3 Type = 1 Address = {hex @}