Skip to content

Commit

Permalink
Use exported constants for VC patch
Browse files Browse the repository at this point in the history
  • Loading branch information
vulcandth committed Dec 26, 2024
1 parent cd1065b commit 410e13f
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 144 deletions.
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ $(pokeblue_debug_obj): RGBASMFLAGS += -D _BLUE -D _DEBUG
$(pokered_vc_obj): RGBASMFLAGS += -D _RED -D _RED_VC
$(pokeblue_vc_obj): RGBASMFLAGS += -D _BLUE -D _BLUE_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 @@ -125,10 +125,6 @@ $(foreach obj, $(pokeblue_debug_obj), $(eval $(call DEP,$(obj),$(obj:_blue_debug
$(foreach obj, $(pokered_vc_obj), $(eval $(call DEP,$(obj),$(obj:_red_vc.o=.asm))))
$(foreach obj, $(pokeblue_vc_obj), $(eval $(call DEP,$(obj),$(obj:_blue_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
7 changes: 7 additions & 0 deletions includes.asm
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ INCLUDE "constants/tileset_constants.asm"
INCLUDE "constants/event_constants.asm"
INCLUDE "constants/text_constants.asm"
INCLUDE "constants/menu_constants.asm"

IF DEF(_RED_VC)
INCLUDE "vc/pokered.constants.asm"
ENDC
IF DEF(_BLUE_VC)
INCLUDE "vc/pokeblue.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 "labels.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
75 changes: 35 additions & 40 deletions vc/pokeblue.constants.asm
Original file line number Diff line number Diff line change
@@ -1,69 +1,64 @@
; These are all the asm constants needed to make the blue_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 "S"
vc_const "L"
vc_const "F"
vc_const "X"
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 S_CHAR EQU "S"
EXPORT DEF L_CHAR EQU "L"
EXPORT DEF F_CHAR EQU "F"
EXPORT DEF X_CHAR EQU "X"
EXPORT MEGA_PUNCH

; [FPA 001 End]
vc_const EXPLOSION
EXPORT EXPLOSION

; [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 002 End]
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 005 End]
vc_const HYPER_BEAM
EXPORT HYPER_BEAM

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

; [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 "R"
vc_const REFLECT
EXPORT DEF R_CHAR EQU "R"
EXPORT REFLECT

; [FPA 009 Begin]
vc_const SELFDESTRUCT
EXPORT SELFDESTRUCT

; [FPA 010 Begin]
vc_const "D"
vc_const DREAM_EATER
EXPORT DEF D_CHAR EQU "D"
EXPORT DREAM_EATER

; [FPA 011 Begin]
vc_const "O"
vc_const SPORE
EXPORT DEF O_CHAR EQU "O"
EXPORT SPORE

; [FPA 012 Begin]
vc_const "C"
vc_const ROCK_SLIDE
EXPORT DEF C_CHAR EQU "C"
EXPORT ROCK_SLIDE
Loading

0 comments on commit 410e13f

Please sign in to comment.