diff --git a/Makefile b/Makefile index cd3852adaa8..ed76db4b204 100644 --- a/Makefile +++ b/Makefile @@ -117,7 +117,7 @@ $(pokecrystal_debug_obj): RGBASMFLAGS += -D _DEBUG $(pokecrystal11_debug_obj): RGBASMFLAGS += -D _CRYSTAL11 -D _DEBUG $(pokecrystal11_vc_obj): RGBASMFLAGS += -D _CRYSTAL11 -D _CRYSTAL11_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 @@ -146,10 +146,6 @@ $(foreach obj, $(pokecrystal_debug_obj), $(eval $(call DEP,$(obj),$(obj:_debug.o $(foreach obj, $(pokecrystal11_debug_obj), $(eval $(call DEP,$(obj),$(obj:11_debug.o=.asm)))) $(foreach obj, $(pokecrystal11_vc_obj), $(eval $(call DEP,$(obj),$(obj:11_vc.o=.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/docs/vc_patch.md b/docs/vc_patch.md index cc0e916353c..0f6724d2a2f 100644 --- a/docs/vc_patch.md +++ b/docs/vc_patch.md @@ -28,7 +28,7 @@ The `.patch.template` file is the basis for the `.patch` file. Many numeric valu ### vc/pokecrystal11.constants.asm -The `.constants.asm` file is used to create a `.constants.sym` file. Typical `.sym` files only list the values of *labels* (ROM banks and addresses); this file is used to list *constants* that are needed by the `.patch.template`. Any constants that the `.patch.template` refers to must be explicitly printed here with the `vc_const` macro. +The `.constants.asm` file is used to export the values of *constants* that are needed by `.patch.template`. Any constants that the `.patch.template` refers to must be explicitly exported with the `EXPORT` rgbasm directive, so their values may appear in the `.sym`. ### tools/make_patch.c @@ -38,13 +38,13 @@ The program used to convert a `.patch.template` into a `.patch` file. To convert `vc.patch.template` into `vc.patch`: ```bash -tools/make_patch labels.sym constants.sym patched.gbc original.gbc vc.patch.template vc.patch +tools/make_patch labels.sym patched.gbc original.gbc vc.patch.template vc.patch ``` For example, this is what `make crystal11_vc` does: ```bash -tools/make_patch pokecrystal11_vc.sym vc/pokecrystal11.constants.sym pokecrystal11_vc.gbc pokecrystal11.gbc vc/pokecrystal11.patch.template pokecrystal11.patch +tools/make_patch pokecrystal11_vc.sym pokecrystal11_vc.gbc pokecrystal11.gbc vc/pokecrystal11.patch.template pokecrystal11.patch ``` diff --git a/includes.asm b/includes.asm index 5d4c1c38d8c..9a79361cc65 100644 --- a/includes.asm +++ b/includes.asm @@ -69,3 +69,5 @@ INCLUDE "constants/trainer_constants.asm" INCLUDE "constants/trainer_data_constants.asm" INCLUDE "constants/type_constants.asm" INCLUDE "constants/battle_tower_constants.asm" + +INCLUDE "vc/pokecrystal11.constants.asm" diff --git a/tools/make_patch.c b/tools/make_patch.c index 3a36accdd87..cbae5575b53 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 "labels.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/pokecrystal11.constants.asm b/vc/pokecrystal11.constants.asm index 8410f5f074c..f954e8b44e4 100644 --- a/vc/pokecrystal11.constants.asm +++ b/vc/pokecrystal11.constants.asm @@ -1,39 +1,34 @@ ; These are all the asm constants needed to make the crystal11_vc patch. -MACRO vc_const - DEF x = \1 - println "{02x:x} \1" ; same format as rgblink's .sym file -ENDM - ; [fight begin] - vc_const SCREEN_HEIGHT_PX +EXPORT SCREEN_HEIGHT_PX ; [print forbid 2] - vc_const A_BUTTON +EXPORT A_BUTTON ; [print forbid 3] - vc_const MAPGROUP_CIANWOOD - vc_const MAP_CIANWOOD_PHOTO_STUDIO +EXPORT MAPGROUP_CIANWOOD +EXPORT MAP_CIANWOOD_PHOTO_STUDIO ; [print forbid 5] - vc_const NO_INPUT - vc_const B_BUTTON - vc_const D_UP - vc_const D_DOWN +EXPORT NO_INPUT +EXPORT B_BUTTON +EXPORT D_UP +EXPORT D_DOWN ; [FPA 001 Begin] - vc_const FISSURE +EXPORT FISSURE ; [FPA 002 Begin] - vc_const SELFDESTRUCT +EXPORT SELFDESTRUCT ; [FPA 003 Begin] - vc_const THUNDER +EXPORT THUNDER ; [FPA 004 Begin] - vc_const FLASH +EXPORT FLASH ; [FPA 005 Begin] - vc_const EXPLOSION +EXPORT EXPLOSION ; [FPA 006 Begin] - vc_const HORN_DRILL +EXPORT HORN_DRILL ; [FPA 007 Begin] - vc_const HYPER_BEAM +EXPORT HYPER_BEAM ; [FPA 042801 Begin] - vc_const PRESENT - vc_const anim_1gfx_command +EXPORT PRESENT +EXPORT anim_1gfx_command