Allow alternate labels for patch names

This commit is contained in:
Rangi 2022-03-12 22:38:29 -05:00
parent 31c3c94d64
commit f33a041930
6 changed files with 55 additions and 48 deletions

View File

@ -1,4 +1,5 @@
roms := pokecrystal.gbc \
roms := \
pokecrystal.gbc \
pokecrystal11.gbc \
pokecrystal_au.gbc \
pokecrystal_debug.gbc \

View File

@ -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.

View File

@ -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

View File

@ -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, \

View File

@ -344,17 +344,27 @@ 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)) {
if (!alternate && c == '@') {
// "@" designates an alternate name for the ".VC_" label
alternate = true;
buffer->size = 0;
} else if (c == ']') {
putc(c, output);
if (c == ']') {
break;
} else if (!isalnum(c) && c != '_' && c != '@' && 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, &(char []){'\0'});
// The current patch should have a corresponding ".VC_" label
current_hook = symbol_find_cat(symbols, ".VC_", buffer->data);

View File

@ -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 @}