From 1d8a5338cff81416085e43ec490911d3f2ed19fa Mon Sep 17 00:00:00 2001 From: vulcandth Date: Fri, 27 Dec 2024 12:10:25 -0600 Subject: [PATCH] Use exported constants for VC patch (#125) --- Makefile | 6 +--- includes.asm | 7 +++++ tools/make_patch.c | 22 ++++++------- vc/pokegold.constants.asm | 61 ++++++++++++++++-------------------- vc/pokegold.patch.template | 16 +++++----- vc/pokesilver.constants.asm | 61 ++++++++++++++++-------------------- vc/pokesilver.patch.template | 16 +++++----- 7 files changed, 89 insertions(+), 100 deletions(-) diff --git a/Makefile b/Makefile index fc9ac0b78..a4e850f00 100644 --- a/Makefile +++ b/Makefile @@ -120,7 +120,7 @@ $(pokesilver_debug_obj): RGBASMFLAGS += -D _SILVER -D _DEBUG $(pokegold_vc_obj): RGBASMFLAGS += -D _GOLD -D _GOLD_VC $(pokesilver_vc_obj): RGBASMFLAGS += -D _SILVER -D _GOLD_VC -%.patch: vc/%.constants.sym %_vc.gbc %.gbc vc/%.patch.template +%.patch: %_vc.gbc %.gbc vc/%.patch.template tools/make_patch $*_vc.sym $^ $@ rgbdscheck.o: rgbdscheck.asm @@ -167,10 +167,6 @@ $(foreach obj, $(gold_vc_excl_obj), \ $(foreach obj, $(silver_vc_excl_obj), \ $(eval $(call DEP,$(obj),$(obj:_silver_vc.o=_silver.asm)))) -# Dependencies for VC files that need to run scan_includes -%.constants.sym: %.constants.asm $(shell tools/scan_includes %.constants.asm) $(preinclude_deps) | rgbdscheck.o - $(RGBASM) $(RGBASMFLAGS) $< > $@ - endif diff --git a/includes.asm b/includes.asm index e9698f2c3..7c2699587 100644 --- a/includes.asm +++ b/includes.asm @@ -66,3 +66,10 @@ INCLUDE "constants/tileset_constants.asm" INCLUDE "constants/trainer_constants.asm" INCLUDE "constants/trainer_data_constants.asm" INCLUDE "constants/type_constants.asm" + +IF DEF(_GOLD_VC) +INCLUDE "vc/pokegold.constants.asm" +ENDC +IF DEF(_SILVER_VC) +INCLUDE "vc/pokesilver.constants.asm" +ENDC diff --git a/tools/make_patch.c b/tools/make_patch.c index 20c725b33..a7b8be723 100644 --- a/tools/make_patch.c +++ b/tools/make_patch.c @@ -1,5 +1,5 @@ #define PROGRAM_NAME "make_patch" -#define USAGE_OPTS "labels.sym constants.sym patched.gbc original.gbc vc.patch.template vc.patch" +#define USAGE_OPTS "values.sym patched.gbc original.gbc vc.patch.template vc.patch" #include "common.h" @@ -113,13 +113,14 @@ void parse_symbol_value(char *input, int *restrict bank, int *restrict address) } } -void parse_symbols(const char *filename, struct Symbol **symbols) { +struct Symbol *parse_symbols(const char *filename) { FILE *file = xfopen(filename, 'r'); struct Buffer *buffer = buffer_create(1); enum { SYM_PRE, SYM_VALUE, SYM_SPACE, SYM_NAME } state = SYM_PRE; int bank = 0; int address = 0; + struct Symbol *symbols = NULL; for (;;) { int c = getc(file); @@ -127,7 +128,7 @@ void parse_symbols(const char *filename, struct Symbol **symbols) { if (state == SYM_NAME) { // The symbol name has ended; append the buffered symbol buffer_append(buffer, &(char []){'\0'}); - symbol_append(symbols, buffer->data, bank, address); + symbol_append(&symbols, buffer->data, bank, address); } // Skip to the next line, ignoring anything after the symbol value and name state = SYM_PRE; @@ -156,6 +157,7 @@ void parse_symbols(const char *filename, struct Symbol **symbols) { fclose(file); buffer_free(buffer); + return symbols; } int strfind(const char *s, const char *list[], int count) { @@ -449,20 +451,18 @@ bool verify_completeness(FILE *restrict orig_rom, FILE *restrict new_rom, struct } int main(int argc, char *argv[]) { - if (argc != 7) { + if (argc != 6) { usage_exit(1); } - struct Symbol *symbols = NULL; - parse_symbols(argv[1], &symbols); - parse_symbols(argv[2], &symbols); + struct Symbol *symbols = parse_symbols(argv[1]); - FILE *new_rom = xfopen(argv[3], 'r'); - FILE *orig_rom = xfopen(argv[4], 'r'); - struct Buffer *patches = process_template(argv[5], argv[6], new_rom, orig_rom, symbols); + FILE *new_rom = xfopen(argv[2], 'r'); + FILE *orig_rom = xfopen(argv[3], 'r'); + struct Buffer *patches = process_template(argv[4], argv[5], new_rom, orig_rom, symbols); if (!verify_completeness(orig_rom, new_rom, patches)) { - fprintf(stderr, PROGRAM_NAME ": Warning: Not all ROM differences are defined by \"%s\"\n", argv[6]); + fprintf(stderr, PROGRAM_NAME ": Warning: Not all ROM differences are defined by \"%s\"\n", argv[5]); } symbol_free(symbols); diff --git a/vc/pokegold.constants.asm b/vc/pokegold.constants.asm index 3e2278ab2..e1e3e2b0f 100644 --- a/vc/pokegold.constants.asm +++ b/vc/pokegold.constants.asm @@ -1,57 +1,50 @@ ; These are all the asm constants needed to make the gold_vc patch. -MACRO vc_const - DEF x = \1 - println "{02x:x} \1" ; same format as rgblink's .sym file -ENDM - ; [FPA 001 Begin] - vc_const "F" - vc_const "I" - vc_const "S" - vc_const "U" - vc_const "R" +EXPORT DEF F_CHAR EQU "F" +EXPORT DEF I_CHAR EQU "I" +EXPORT DEF S_CHAR EQU "S" +EXPORT DEF U_CHAR EQU "U" +EXPORT DEF R_CHAR EQU "R" ; [FPA 002 Begin] - vc_const "E" - vc_const "L" - vc_const "D" +EXPORT DEF E_CHAR EQU "E" +EXPORT DEF L_CHAR EQU "L" +EXPORT DEF D_CHAR EQU "D" ; [FPA 003 Begin] - vc_const "T" - vc_const "H" - vc_const "N" +EXPORT DEF T_CHAR EQU "T" +EXPORT DEF H_CHAR EQU "H" +EXPORT DEF N_CHAR EQU "N" ; [FPA 004 Begin] - vc_const "Y" - vc_const "P" - ; "" is necessary since spaces separate template command arguments - charmap "", " " - vc_const "" +EXPORT DEF Y_CHAR EQU "Y" +EXPORT DEF P_CHAR EQU "P" +EXPORT DEF SPACE_CHAR EQU " " ; [FPA 005 Begin] - vc_const "O" +EXPORT DEF O_CHAR EQU "O" ; [FPA 006 Begin] - vc_const "X" +EXPORT DEF X_CHAR EQU "X" ; [FPA 007 Begin] - vc_const "A" - vc_const "@" +EXPORT DEF A_CHAR EQU "A" +EXPORT DEF AT_CHAR EQU "@" ; [FPA 042801 Begin] - vc_const BATTLE_ANIM_GFX_BUBBLE +EXPORT BATTLE_ANIM_GFX_BUBBLE ; [fight begin] - vc_const SCREEN_HEIGHT_PX +EXPORT SCREEN_HEIGHT_PX ; [print forbid 2] - vc_const NO_INPUT - vc_const A_BUTTON - vc_const B_BUTTON - vc_const D_UP - vc_const D_DOWN +EXPORT NO_INPUT +EXPORT A_BUTTON +EXPORT B_BUTTON +EXPORT D_UP +EXPORT D_DOWN ; [print forbid 3] - vc_const MAPGROUP_CIANWOOD - vc_const MAP_CIANWOOD_PHOTO_STUDIO +EXPORT MAPGROUP_CIANWOOD +EXPORT MAP_CIANWOOD_PHOTO_STUDIO diff --git a/vc/pokegold.patch.template b/vc/pokegold.patch.template index 10dc84192..07cee2401 100644 --- a/vc/pokegold.patch.template +++ b/vc/pokegold.patch.template @@ -251,7 +251,7 @@ MotionBlur0 = 10 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "F" "I" "S" "S" "U" "R" } +ConditionValueC = {dws_ F_CHAR I_CHAR S_CHAR S_CHAR U_CHAR R_CHAR } ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7e value = 0x92 ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7f value = 0x84 @@ -274,7 +274,7 @@ MotionBlur0 = 10 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "S" "E" "L" "F" "D" "E" } +ConditionValueC = {dws_ S_CHAR E_CHAR L_CHAR F_CHAR D_CHAR E_CHAR } ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7e value = 0x93 ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7f value = 0x87 @@ -296,7 +296,7 @@ MotionBlur0 = 10 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "T" "H" "U" "N" "D" "E" } +ConditionValueC = {dws_ T_CHAR H_CHAR U_CHAR N_CHAR D_CHAR E_CHAR } ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7e value = 0x87 ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7f value = 0x98 @@ -320,7 +320,7 @@ MotionBlur0 = 16 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "H" "Y" "P" "E" "R" "" } +ConditionValueC = {dws_ H_CHAR Y_CHAR P_CHAR E_CHAR R_CHAR SPACE_CHAR } ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7e value = 0x87 @@ -344,7 +344,7 @@ MotionBlur0 = 11 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "H" "O" "R" "N" "" "D" } +ConditionValueC = {dws_ H_CHAR O_CHAR R_CHAR N_CHAR SPACE_CHAR D_CHAR } ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7e value = 0x84 ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7f value = 0x97 @@ -367,7 +367,7 @@ MotionBlur0 = 11 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "E" "X" "P" "L" "O" "S" } +ConditionValueC = {dws_ E_CHAR X_CHAR P_CHAR L_CHAR O_CHAR S_CHAR } ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7e value = 0x85 ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7f value = 0x8b @@ -387,7 +387,7 @@ MotionBlur0 = 11 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "F" "L" "A" "S" "H" "@" } +ConditionValueC = {dws_ F_CHAR L_CHAR A_CHAR S_CHAR H_CHAR AT_CHAR } @@ -420,7 +420,7 @@ MotionBlur0 = 11 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5 wBattleAnimTileDict+2} ConditionValueB = {dws_ == == == == == == == } -ConditionValueC = {dws_ "P" "R" "E" "S" "E" "N" BATTLE_ANIM_GFX_BUBBLE } +ConditionValueC = {dws_ P_CHAR R_CHAR E_CHAR S_CHAR E_CHAR N_CHAR BATTLE_ANIM_GFX_BUBBLE } diff --git a/vc/pokesilver.constants.asm b/vc/pokesilver.constants.asm index 86a7b2c99..cae2c7cb5 100644 --- a/vc/pokesilver.constants.asm +++ b/vc/pokesilver.constants.asm @@ -1,57 +1,50 @@ ; These are all the asm constants needed to make the silver_vc patch. -MACRO vc_const - DEF x = \1 - println "{02x:x} \1" ; same format as rgblink's .sym file -ENDM - ; [FPA 001 Begin] - vc_const "F" - vc_const "I" - vc_const "S" - vc_const "U" - vc_const "R" +EXPORT DEF F_CHAR EQU "F" +EXPORT DEF I_CHAR EQU "I" +EXPORT DEF S_CHAR EQU "S" +EXPORT DEF U_CHAR EQU "U" +EXPORT DEF R_CHAR EQU "R" ; [FPA 002 Begin] - vc_const "E" - vc_const "L" - vc_const "D" +EXPORT DEF E_CHAR EQU "E" +EXPORT DEF L_CHAR EQU "L" +EXPORT DEF D_CHAR EQU "D" ; [FPA 003 Begin] - vc_const "T" - vc_const "H" - vc_const "N" +EXPORT DEF T_CHAR EQU "T" +EXPORT DEF H_CHAR EQU "H" +EXPORT DEF N_CHAR EQU "N" ; [FPA 004 Begin] - vc_const "Y" - vc_const "P" - ; "" is necessary since spaces separate template command arguments - charmap "", " " - vc_const "" +EXPORT DEF Y_CHAR EQU "Y" +EXPORT DEF P_CHAR EQU "P" +EXPORT DEF SPACE_CHAR EQU " " ; [FPA 005 Begin] - vc_const "O" +EXPORT DEF O_CHAR EQU "O" ; [FPA 006 Begin] - vc_const "X" +EXPORT DEF X_CHAR EQU "X" ; [FPA 007 Begin] - vc_const "A" - vc_const "@" +EXPORT DEF A_CHAR EQU "A" +EXPORT DEF AT_CHAR EQU "@" ; [FPA 042801 Begin] - vc_const BATTLE_ANIM_GFX_BUBBLE +EXPORT BATTLE_ANIM_GFX_BUBBLE ; [fight begin] - vc_const SCREEN_HEIGHT_PX +EXPORT SCREEN_HEIGHT_PX ; [print forbid 2] - vc_const NO_INPUT - vc_const A_BUTTON - vc_const B_BUTTON - vc_const D_UP - vc_const D_DOWN +EXPORT NO_INPUT +EXPORT A_BUTTON +EXPORT B_BUTTON +EXPORT D_UP +EXPORT D_DOWN ; [print forbid 3] - vc_const MAPGROUP_CIANWOOD - vc_const MAP_CIANWOOD_PHOTO_STUDIO +EXPORT MAPGROUP_CIANWOOD +EXPORT MAP_CIANWOOD_PHOTO_STUDIO diff --git a/vc/pokesilver.patch.template b/vc/pokesilver.patch.template index e7dadf572..b9aa36b36 100644 --- a/vc/pokesilver.patch.template +++ b/vc/pokesilver.patch.template @@ -253,7 +253,7 @@ MotionBlur0 = 10 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "F" "I" "S" "S" "U" "R" } +ConditionValueC = {dws_ F_CHAR I_CHAR S_CHAR S_CHAR U_CHAR R_CHAR } ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7e value = 0x92 ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7f value = 0x84 @@ -276,7 +276,7 @@ MotionBlur0 = 10 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "S" "E" "L" "F" "D" "E" } +ConditionValueC = {dws_ S_CHAR E_CHAR L_CHAR F_CHAR D_CHAR E_CHAR } ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7e value = 0x93 ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7f value = 0x87 @@ -298,7 +298,7 @@ MotionBlur0 = 10 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "T" "H" "U" "N" "D" "E" } +ConditionValueC = {dws_ T_CHAR H_CHAR U_CHAR N_CHAR D_CHAR E_CHAR } ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7e value = 0x87 ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7f value = 0x98 @@ -322,7 +322,7 @@ MotionBlur0 = 16 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "H" "Y" "P" "E" "R" "" } +ConditionValueC = {dws_ H_CHAR Y_CHAR P_CHAR E_CHAR R_CHAR SPACE_CHAR } @@ -348,7 +348,7 @@ MotionBlur0 = 11 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "H" "O" "R" "N" "" "D" } +ConditionValueC = {dws_ H_CHAR O_CHAR R_CHAR N_CHAR SPACE_CHAR D_CHAR } ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7e value = 0x84 ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7f value = 0x97 @@ -371,7 +371,7 @@ MotionBlur0 = 11 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "E" "X" "P" "L" "O" "S" } +ConditionValueC = {dws_ E_CHAR X_CHAR P_CHAR L_CHAR O_CHAR S_CHAR } ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7e value = 0x85 ;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7f value = 0x8b @@ -391,7 +391,7 @@ MotionBlur0 = 11 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5} ConditionValueB = {dws_ == == == == == == } -ConditionValueC = {dws_ "F" "L" "A" "S" "H" "@" } +ConditionValueC = {dws_ F_CHAR L_CHAR A_CHAR S_CHAR H_CHAR AT_CHAR } @@ -425,7 +425,7 @@ MotionBlur0 = 11 ConditionType = 0 ConditionValueA = {dws_ wStringBuffer2 wStringBuffer2+1 wStringBuffer2+2 wStringBuffer2+3 wStringBuffer2+4 wStringBuffer2+5 wBattleAnimTileDict+2} ConditionValueB = {dws_ == == == == == == == } -ConditionValueC = {dws_ "P" "R" "E" "S" "E" "N" BATTLE_ANIM_GFX_BUBBLE } +ConditionValueC = {dws_ P_CHAR R_CHAR E_CHAR S_CHAR E_CHAR N_CHAR BATTLE_ANIM_GFX_BUBBLE }