shithub: pokecrystal

Download patch

ref: f33a04193092e3df8c9b1ac4f560018b95925f61
parent: 31c3c94d64e1ac1e40c95acfda7de8b99b4f302b
author: Rangi <[email protected]>
date: Sat Mar 12 17:38:29 EST 2022

Allow alternate labels for patch names

--- 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)
--- a/docs/vc_patch.md
+++ b/docs/vc_patch.md
@@ -46,11 +46,11 @@
 
 ## 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 @@
 
 **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.
 
--- a/engine/battle_anims/anim_commands.asm
+++ b/engine/battle_anims/anim_commands.asm
@@ -58,13 +58,7 @@
 	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
 
@@ -71,7 +65,7 @@
 	call BattleAnimAssignPals
 	call BattleAnimRequestPals
 
-	vc_hook FPA_001_End
+	vc_hook Stop_reducing_move_anim_flashing
 	xor a
 	ldh [hSCX], a
 	ldh [hSCY], a
--- a/engine/menus/save.asm
+++ b/engine/menus/save.asm
@@ -165,7 +165,7 @@
 ; 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, \
--- a/tools/make_patch.c
+++ b/tools/make_patch.c
@@ -344,16 +344,26 @@
 		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
--- a/vc/pokecrystal11.patch.template
+++ b/vc/pokecrystal11.patch.template
@@ -235,7 +235,7 @@
 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 @@
 ;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 @@
 ;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 @@
 
 ; 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 @@
 
 ;ji wa lei  011800
 
-[FPA 004 Begin]                                                   
+[FPA 004 Begin@Reduce_move_anim_flashing]                                                   
 Mode = 3                                                          
 Type = 0                                                          
 Address = {hex @} 
@@ -516,7 +516,7 @@
 ; 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 @@
 ;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 @@
 ;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 @@
 
 ;exit point
 
-[FPA 001 End]                                                     
+[FPA 001 End@Stop_reducing_move_anim_flashing]                                                     
 Mode = 3                                                          
 Type = 1                                                          
 Address = {hex @}