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 aa777f3 commit dcfe829
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 74 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
2 changes: 2 additions & 0 deletions includes.asm
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ INCLUDE "constants/text_constants.asm"
INCLUDE "constants/menu_constants.asm"
INCLUDE "constants/sprite_anim_constants.asm"
INCLUDE "constants/pikachu_emotion_constants.asm"

INCLUDE "vc/pokeyellow.constants.asm"
30 changes: 18 additions & 12 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 @@ -342,6 +344,12 @@ struct Buffer *process_template(const char *template_filename, const char *patch

// The ROM checksum will always differ
buffer_append(patches, &(struct Patch){0x14e, 2});
// The Stadium data (see stadium.c) will always differ
unsigned int rom_size = (unsigned int)xfsize("", orig_rom);
if (rom_size == 128 * 0x4000) {
unsigned int stadium_size = 24 + 6 + 2 + 128 * 2 * 2;
buffer_append(patches, &(struct Patch){rom_size - stadium_size, stadium_size});
}

// Fill in the template
const struct Symbol *current_hook = NULL;
Expand Down Expand Up @@ -411,7 +419,7 @@ struct Buffer *process_template(const char *template_filename, const char *patch
int compare_patch(const void *patch1, const void *patch2) {
unsigned int offset1 = ((const struct Patch *)patch1)->offset;
unsigned int offset2 = ((const struct Patch *)patch2)->offset;
return offset1 > offset2 ? 1 : offset1 < offset2 ? -1 : 0;
return (offset1 > offset2) - (offset1 < offset2);
}

bool verify_completeness(FILE *restrict orig_rom, FILE *restrict new_rom, struct Buffer *patches) {
Expand Down Expand Up @@ -443,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
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
Loading

0 comments on commit dcfe829

Please sign in to comment.