Skip to content

Commit

Permalink
Use exported constants for VC patch (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
vulcandth authored Dec 27, 2024
1 parent f8a7ac3 commit 5336950
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 73 deletions.
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ endif
$(pokeyellow_debug_obj): RGBASMFLAGS += -D _DEBUG
$(pokeyellow_vc_obj): RGBASMFLAGS += -D _YELLOW_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 All @@ -116,10 +116,6 @@ $(foreach obj, $(pokeyellow_obj), $(eval $(call DEP,$(obj),$(obj:.o=.asm))))
$(foreach obj, $(pokeyellow_debug_obj), $(eval $(call DEP,$(obj),$(obj:_debug.o=.asm))))
$(foreach obj, $(pokeyellow_vc_obj), $(eval $(call DEP,$(obj),$(obj:_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


Expand Down
4 changes: 4 additions & 0 deletions includes.asm
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ INCLUDE "constants/text_constants.asm"
INCLUDE "constants/menu_constants.asm"
INCLUDE "constants/sprite_anim_constants.asm"
INCLUDE "constants/pikachu_emotion_constants.asm"

IF DEF(_YELLOW_VC)
INCLUDE "vc/pokeyellow.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 @@ -443,20 +445,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
66 changes: 30 additions & 36 deletions vc/pokeyellow.constants.asm
Original file line number Diff line number Diff line change
@@ -1,59 +1,53 @@
; These are all the asm constants needed to make the yellow_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 "M"
vc_const "E"
vc_const "G"
vc_const "A"
vc_const "P"
vc_const "X"
vc_const "L"
vc_const "S"
vc_const "F"
vc_const MEGA_PUNCH
EXPORT DEF M_CHAR EQU "M"
EXPORT DEF E_CHAR EQU "E"
EXPORT DEF G_CHAR EQU "G"
EXPORT DEF A_CHAR EQU "A"
EXPORT DEF P_CHAR EQU "P"
EXPORT DEF X_CHAR EQU "X"
EXPORT DEF L_CHAR EQU "L"
EXPORT DEF S_CHAR EQU "S"
EXPORT DEF F_CHAR EQU "F"
EXPORT MEGA_PUNCH

; [FPA 002 Begin]
vc_const "U"
vc_const "I"
vc_const GUILLOTINE
EXPORT DEF U_CHAR EQU "U"
EXPORT DEF I_CHAR EQU "I"
EXPORT GUILLOTINE

; [FPA 003 Begin]
vc_const "K"
vc_const MEGA_KICK
EXPORT DEF K_CHAR EQU "K"
EXPORT MEGA_KICK

; [FPA 004 Begin]
vc_const "B"
vc_const "Z"
vc_const BLIZZARD
EXPORT DEF B_CHAR EQU "B"
EXPORT DEF Z_CHAR EQU "Z"
EXPORT BLIZZARD

; [FPA 005 Begin]
vc_const BUBBLEBEAM
EXPORT BUBBLEBEAM

; [FPA 006 Begin]
vc_const "H"
vc_const "Y"
vc_const HYPER_BEAM
EXPORT DEF H_CHAR EQU "H"
EXPORT DEF Y_CHAR EQU "Y"
EXPORT HYPER_BEAM

; [FPA 007 Begin]
vc_const "T"
vc_const "N"
vc_const THUNDERBOLT
EXPORT DEF T_CHAR EQU "T"
EXPORT DEF N_CHAR EQU "N"
EXPORT THUNDERBOLT

; [FPA 008 Begin]
vc_const HAZE
EXPORT HAZE

; [FPA 009 Begin]
vc_const "R"
vc_const "F"
vc_const REFLECT
EXPORT DEF R_CHAR EQU "R"
EXPORT REFLECT

; [FPA 010 Begin]
vc_const SELFDESTRUCT
EXPORT SELFDESTRUCT

; [FPA 011 Begin]
vc_const EXPLOSION
EXPORT EXPLOSION
42 changes: 21 additions & 21 deletions vc/pokeyellow.patch.template
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ MotionBlur0 = 11
ConditionType = 11
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wStringBuffer+5 wAnimationID 00 wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID 00 wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == == || == == == == == || == == == == == }
ConditionValueC = {dws_ "M" "E" "G" "A" "P" MEGA_PUNCH 00 "E" "X" "P" "L" MEGA_PUNCH 00 "S" "E" "L" "F" MEGA_PUNCH }
ConditionValueC = {dws_ M_CHAR E_CHAR G_CHAR A_CHAR P_CHAR MEGA_PUNCH 00 E_CHAR X_CHAR P_CHAR L_CHAR MEGA_PUNCH 00 S_CHAR E_CHAR L_CHAR F_CHAR MEGA_PUNCH }

[FPA 001 End@Stop_reducing_move_anim_flashing_Mega_Punch]
Mode = 3
Expand All @@ -311,7 +311,7 @@ Address = {hex @}
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wStringBuffer+5 wAnimationID}
ConditionValueB = {dws_ == == == == == == }
ConditionValueC = {dws_ "M" "E" "G" "A" "P" MEGA_PUNCH }
ConditionValueC = {dws_ M_CHAR E_CHAR G_CHAR A_CHAR P_CHAR MEGA_PUNCH }

;rsm103725
;Mem Write: pc32 = 0x781c5 addr = 0xd086 value = 0x3
Expand All @@ -325,7 +325,7 @@ MotionBlur0 = 7
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == }
ConditionValueC = {dws_ "G" "U" "I" "L" GUILLOTINE }
ConditionValueC = {dws_ G_CHAR U_CHAR I_CHAR L_CHAR GUILLOTINE }

[FPA 002 End@Stop_reducing_move_anim_flashing_Guillotine]
Mode = 3
Expand All @@ -334,7 +334,7 @@ Address = {hex @}
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == }
ConditionValueC = {dws_ "G" "U" "I" "L" GUILLOTINE }
ConditionValueC = {dws_ G_CHAR U_CHAR I_CHAR L_CHAR GUILLOTINE }


;rsm142438
Expand All @@ -349,7 +349,7 @@ MotionBlur0 = 10
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wStringBuffer+5 wAnimationID}
ConditionValueB = {dws_ == == == == == == }
ConditionValueC = {dws_ "M" "E" "G" "A" "K" MEGA_KICK }
ConditionValueC = {dws_ M_CHAR E_CHAR G_CHAR A_CHAR K_CHAR MEGA_KICK }

[FPA 003 End@Stop_reducing_move_anim_flashing_Mega_Kick]
Mode = 3
Expand All @@ -358,7 +358,7 @@ Address = {hex @}
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wStringBuffer+5 wAnimationID}
ConditionValueB = {dws_ == == == == == == }
ConditionValueC = {dws_ "M" "E" "G" "A" "K" MEGA_KICK }
ConditionValueC = {dws_ M_CHAR E_CHAR G_CHAR A_CHAR K_CHAR MEGA_KICK }

;rsm154217 blizzard
;No131
Expand All @@ -371,7 +371,7 @@ MotionBlur0 = 11
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == }
ConditionValueC = {dws_ "B" "L" "I" "Z" BLIZZARD }
ConditionValueC = {dws_ B_CHAR L_CHAR I_CHAR Z_CHAR BLIZZARD }

[FPA 004 End@Stop_reducing_move_anim_flashing_Blizzard]
Mode = 3
Expand All @@ -380,7 +380,7 @@ Address = {hex @}
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == }
ConditionValueC = {dws_ "B" "L" "I" "Z" BLIZZARD }
ConditionValueC = {dws_ B_CHAR L_CHAR I_CHAR Z_CHAR BLIZZARD }



Expand All @@ -395,7 +395,7 @@ MotionBlur0 = 15
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == }
ConditionValueC = {dws_ "B" "U" "B" "B" BUBBLEBEAM }
ConditionValueC = {dws_ B_CHAR U_CHAR B_CHAR B_CHAR BUBBLEBEAM }

[FPA 005 End@Stop_reducing_move_anim_flashing_Bubblebeam]
Mode = 3
Expand All @@ -404,7 +404,7 @@ Address = {hex @}
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == }
ConditionValueC = {dws_ "B" "U" "B" "B" BUBBLEBEAM }
ConditionValueC = {dws_ B_CHAR U_CHAR B_CHAR B_CHAR BUBBLEBEAM }

;Mem Write: pc32 = 0xc2 addr = 0xcfd1 value = 0x3f
;Pallte Write: pc32 =00078e79 00000048 e4
Expand All @@ -418,7 +418,7 @@ MotionBlur0 = 6
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wAnimationID}
ConditionValueB = {dws_ == == == == }
ConditionValueC = {dws_ "H" "Y" "P" HYPER_BEAM }
ConditionValueC = {dws_ H_CHAR Y_CHAR P_CHAR HYPER_BEAM }

;rsm112921 thunderbolt
;15 -- 13
Expand All @@ -432,7 +432,7 @@ MotionBlur0 = 13
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == }
ConditionValueC = {dws_ "T" "H" "U" "N" THUNDERBOLT }
ConditionValueC = {dws_ T_CHAR H_CHAR U_CHAR N_CHAR THUNDERBOLT }

[FPA 007 End@Stop_reducing_move_anim_flashing_Thunderbolt]
Mode = 3
Expand All @@ -441,7 +441,7 @@ Address = {hex @}
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == }
ConditionValueC = {dws_ "T" "H" "U" "N" THUNDERBOLT }
ConditionValueC = {dws_ T_CHAR H_CHAR U_CHAR N_CHAR THUNDERBOLT }
;
;rsm130806 haze
;No40 haze
Expand All @@ -454,7 +454,7 @@ MotionBlur0 = 28
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == }
ConditionValueC = {dws_ "H" "A" "Z" "E" HAZE }
ConditionValueC = {dws_ H_CHAR A_CHAR Z_CHAR E_CHAR HAZE }

[FPA 008 End@Stop_reducing_move_anim_flashing_Haze_Hyper_Beam]
Mode = 3
Expand All @@ -463,7 +463,7 @@ Address = {hex @}
ConditionType = 11
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID 00 wStringBuffer wStringBuffer+1 wStringBuffer+2 wAnimationID}
ConditionValueB = {dws_ == == == == == || == == == == }
ConditionValueC = {dws_ "H" "A" "Z" "E" HAZE 00 "H" "Y" "P" HYPER_BEAM }
ConditionValueC = {dws_ H_CHAR A_CHAR Z_CHAR E_CHAR HAZE 00 H_CHAR Y_CHAR P_CHAR HYPER_BEAM }


;rsm131656 reflect
Expand All @@ -477,7 +477,7 @@ MotionBlur0 = 6
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == }
ConditionValueC = {dws_ "R" "E" "F" "L" REFLECT }
ConditionValueC = {dws_ R_CHAR E_CHAR F_CHAR L_CHAR REFLECT }

[FPA 009 End@Stop_reducing_move_anim_flashing_Reflect]
Mode = 3
Expand All @@ -486,7 +486,7 @@ Address = {hex @}
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == }
ConditionValueC = {dws_ "R" "E" "F" "L" REFLECT }
ConditionValueC = {dws_ R_CHAR E_CHAR F_CHAR L_CHAR REFLECT }

;rsm132935 selfdestruct
;No56
Expand All @@ -499,7 +499,7 @@ MotionBlur0 = 11
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == }
ConditionValueC = {dws_ "S" "E" "L" "F" SELFDESTRUCT}
ConditionValueC = {dws_ S_CHAR E_CHAR L_CHAR F_CHAR SELFDESTRUCT}

[FPA 010 End@Stop_reducing_move_anim_flashing_Self_Destruct]
Mode = 3
Expand All @@ -508,7 +508,7 @@ Address = {hex @}
ConditionType = 11
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID 00 wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == || == == == == == }
ConditionValueC = {dws_ "S" "E" "L" "F" MEGA_PUNCH 00 "S" "E" "L" "F" SELFDESTRUCT}
ConditionValueC = {dws_ S_CHAR E_CHAR L_CHAR F_CHAR MEGA_PUNCH 00 S_CHAR E_CHAR L_CHAR F_CHAR SELFDESTRUCT}

;rsm013740 explosion
;No76
Expand All @@ -521,7 +521,7 @@ MotionBlur0 = 11
ConditionType = 0
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == }
ConditionValueC = {dws_ "E" "X" "P" "L" EXPLOSION }
ConditionValueC = {dws_ E_CHAR X_CHAR P_CHAR L_CHAR EXPLOSION }

[FPA 011 End@Stop_reducing_move_anim_flashing_Explosion]
Mode = 3
Expand All @@ -530,4 +530,4 @@ Address = {hex @}
ConditionType = 11
ConditionValueA = {dws_ wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID 00 wStringBuffer wStringBuffer+1 wStringBuffer+2 wStringBuffer+3 wAnimationID}
ConditionValueB = {dws_ == == == == == || == == == == == }
ConditionValueC = {dws_ "E" "X" "P" "L" MEGA_PUNCH 00 "E" "X" "P" "L" EXPLOSION }
ConditionValueC = {dws_ E_CHAR X_CHAR P_CHAR L_CHAR MEGA_PUNCH 00 E_CHAR X_CHAR P_CHAR L_CHAR EXPLOSION }

0 comments on commit 5336950

Please sign in to comment.