Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use exported constants for VC patch #125

Merged
merged 3 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
7 changes: 7 additions & 0 deletions includes.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 11 additions & 11 deletions tools/make_patch.c
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -113,21 +113,22 @@ 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);
if (c == EOF || c == '\n' || c == '\r' || c == ';' || (state == SYM_NAME && (c == ' ' || c == '\t'))) {
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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
61 changes: 27 additions & 34 deletions vc/pokegold.constants.asm
Original file line number Diff line number Diff line change
@@ -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"
; "<SPACE>" is necessary since spaces separate template command arguments
charmap "<SPACE>", " "
vc_const "<SPACE>"
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
16 changes: 8 additions & 8 deletions vc/pokegold.patch.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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" "<SPACE>" }
ConditionValueC = {dws_ H_CHAR Y_CHAR P_CHAR E_CHAR R_CHAR SPACE_CHAR }


;******0xcccccccccffffffff8***********--------------- Mem Write: pc32 = 0x3180 addr = 0xcf7e value = 0x87
Expand All @@ -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" "<SPACE>" "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
Expand All @@ -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
Expand All @@ -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 }



Expand Down Expand Up @@ -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 }



Expand Down
61 changes: 27 additions & 34 deletions vc/pokesilver.constants.asm
Original file line number Diff line number Diff line change
@@ -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"
; "<SPACE>" is necessary since spaces separate template command arguments
charmap "<SPACE>", " "
vc_const "<SPACE>"
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
Loading
Loading