Skip to content

Commit 0d4562d

Browse files
authored
Use exported constants for VC patch (#483)
1 parent cd647df commit 0d4562d

File tree

7 files changed

+136
-144
lines changed

7 files changed

+136
-144
lines changed

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ $(pokeblue_debug_obj): RGBASMFLAGS += -D _BLUE -D _DEBUG
9797
$(pokered_vc_obj): RGBASMFLAGS += -D _RED -D _RED_VC
9898
$(pokeblue_vc_obj): RGBASMFLAGS += -D _BLUE -D _BLUE_VC
9999

100-
%.patch: vc/%.constants.sym %_vc.gbc %.gbc vc/%.patch.template
100+
%.patch: %_vc.gbc %.gbc vc/%.patch.template
101101
tools/make_patch $*_vc.sym $^ $@
102102

103103
rgbdscheck.o: rgbdscheck.asm
@@ -125,10 +125,6 @@ $(foreach obj, $(pokeblue_debug_obj), $(eval $(call DEP,$(obj),$(obj:_blue_debug
125125
$(foreach obj, $(pokered_vc_obj), $(eval $(call DEP,$(obj),$(obj:_red_vc.o=.asm))))
126126
$(foreach obj, $(pokeblue_vc_obj), $(eval $(call DEP,$(obj),$(obj:_blue_vc.o=.asm))))
127127

128-
# Dependencies for VC files that need to run scan_includes
129-
%.constants.sym: %.constants.asm $(shell tools/scan_includes %.constants.asm) $(preinclude_deps) | rgbdscheck.o
130-
$(RGBASM) $(RGBASMFLAGS) $< > $@
131-
132128
endif
133129

134130

includes.asm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ INCLUDE "constants/tileset_constants.asm"
5050
INCLUDE "constants/event_constants.asm"
5151
INCLUDE "constants/text_constants.asm"
5252
INCLUDE "constants/menu_constants.asm"
53+
54+
IF DEF(_RED_VC)
55+
INCLUDE "vc/pokered.constants.asm"
56+
ENDC
57+
IF DEF(_BLUE_VC)
58+
INCLUDE "vc/pokeblue.constants.asm"
59+
ENDC

tools/make_patch.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define PROGRAM_NAME "make_patch"
2-
#define USAGE_OPTS "labels.sym constants.sym patched.gbc original.gbc vc.patch.template vc.patch"
2+
#define USAGE_OPTS "values.sym patched.gbc original.gbc vc.patch.template vc.patch"
33

44
#include "common.h"
55

@@ -113,21 +113,22 @@ void parse_symbol_value(char *input, int *restrict bank, int *restrict address)
113113
}
114114
}
115115

116-
void parse_symbols(const char *filename, struct Symbol **symbols) {
116+
struct Symbol *parse_symbols(const char *filename) {
117117
FILE *file = xfopen(filename, 'r');
118118
struct Buffer *buffer = buffer_create(1);
119119

120120
enum { SYM_PRE, SYM_VALUE, SYM_SPACE, SYM_NAME } state = SYM_PRE;
121121
int bank = 0;
122122
int address = 0;
123+
struct Symbol *symbols = NULL;
123124

124125
for (;;) {
125126
int c = getc(file);
126127
if (c == EOF || c == '\n' || c == '\r' || c == ';' || (state == SYM_NAME && (c == ' ' || c == '\t'))) {
127128
if (state == SYM_NAME) {
128129
// The symbol name has ended; append the buffered symbol
129130
buffer_append(buffer, &(char []){'\0'});
130-
symbol_append(symbols, buffer->data, bank, address);
131+
symbol_append(&symbols, buffer->data, bank, address);
131132
}
132133
// Skip to the next line, ignoring anything after the symbol value and name
133134
state = SYM_PRE;
@@ -156,6 +157,7 @@ void parse_symbols(const char *filename, struct Symbol **symbols) {
156157

157158
fclose(file);
158159
buffer_free(buffer);
160+
return symbols;
159161
}
160162

161163
int strfind(const char *s, const char *list[], int count) {
@@ -443,20 +445,18 @@ bool verify_completeness(FILE *restrict orig_rom, FILE *restrict new_rom, struct
443445
}
444446

445447
int main(int argc, char *argv[]) {
446-
if (argc != 7) {
448+
if (argc != 6) {
447449
usage_exit(1);
448450
}
449451

450-
struct Symbol *symbols = NULL;
451-
parse_symbols(argv[1], &symbols);
452-
parse_symbols(argv[2], &symbols);
452+
struct Symbol *symbols = parse_symbols(argv[1]);
453453

454-
FILE *new_rom = xfopen(argv[3], 'r');
455-
FILE *orig_rom = xfopen(argv[4], 'r');
456-
struct Buffer *patches = process_template(argv[5], argv[6], new_rom, orig_rom, symbols);
454+
FILE *new_rom = xfopen(argv[2], 'r');
455+
FILE *orig_rom = xfopen(argv[3], 'r');
456+
struct Buffer *patches = process_template(argv[4], argv[5], new_rom, orig_rom, symbols);
457457

458458
if (!verify_completeness(orig_rom, new_rom, patches)) {
459-
fprintf(stderr, PROGRAM_NAME ": Warning: Not all ROM differences are defined by \"%s\"\n", argv[6]);
459+
fprintf(stderr, PROGRAM_NAME ": Warning: Not all ROM differences are defined by \"%s\"\n", argv[5]);
460460
}
461461

462462
symbol_free(symbols);

vc/pokeblue.constants.asm

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,64 @@
11
; These are all the asm constants needed to make the blue_vc patch.
22

3-
MACRO vc_const
4-
DEF x = \1
5-
PRINTLN "{02x:x} \1" ; same format as rgblink's .sym file
6-
ENDM
7-
83
; [FPA 001 Begin]
9-
vc_const "M"
10-
vc_const "E"
11-
vc_const "G"
12-
vc_const "A"
13-
vc_const "P"
14-
vc_const "S"
15-
vc_const "L"
16-
vc_const "F"
17-
vc_const "X"
18-
vc_const MEGA_PUNCH
4+
EXPORT DEF M_CHAR EQU "M"
5+
EXPORT DEF E_CHAR EQU "E"
6+
EXPORT DEF G_CHAR EQU "G"
7+
EXPORT DEF A_CHAR EQU "A"
8+
EXPORT DEF P_CHAR EQU "P"
9+
EXPORT DEF S_CHAR EQU "S"
10+
EXPORT DEF L_CHAR EQU "L"
11+
EXPORT DEF F_CHAR EQU "F"
12+
EXPORT DEF X_CHAR EQU "X"
13+
EXPORT MEGA_PUNCH
1914

2015
; [FPA 001 End]
21-
vc_const EXPLOSION
16+
EXPORT EXPLOSION
2217

2318
; [FPA 002 Begin]
24-
vc_const "U"
25-
vc_const "I"
26-
vc_const GUILLOTINE
19+
EXPORT DEF U_CHAR EQU "U"
20+
EXPORT DEF I_CHAR EQU "I"
21+
EXPORT GUILLOTINE
2722

2823
; [FPA 002 End]
29-
vc_const "K"
30-
vc_const MEGA_KICK
24+
EXPORT DEF K_CHAR EQU "K"
25+
EXPORT MEGA_KICK
3126

3227
; [FPA 004 Begin]
33-
vc_const "B"
34-
vc_const "Z"
35-
vc_const BLIZZARD
28+
EXPORT DEF B_CHAR EQU "B"
29+
EXPORT DEF Z_CHAR EQU "Z"
30+
EXPORT BLIZZARD
3631

3732
; [FPA 005 Begin]
38-
vc_const BUBBLEBEAM
33+
EXPORT BUBBLEBEAM
3934

4035
; [FPA 005 End]
41-
vc_const HYPER_BEAM
36+
EXPORT HYPER_BEAM
4237

4338
; [FPA 006 Begin]
44-
vc_const "H"
45-
vc_const "Y"
39+
EXPORT DEF H_CHAR EQU "H"
40+
EXPORT DEF Y_CHAR EQU "Y"
4641

4742
; [FPA 007 Begin]
48-
vc_const "T"
49-
vc_const "N"
50-
vc_const THUNDERBOLT
43+
EXPORT DEF T_CHAR EQU "T"
44+
EXPORT DEF N_CHAR EQU "N"
45+
EXPORT THUNDERBOLT
5146

5247
; [FPA 008 Begin]
53-
vc_const "R"
54-
vc_const REFLECT
48+
EXPORT DEF R_CHAR EQU "R"
49+
EXPORT REFLECT
5550

5651
; [FPA 009 Begin]
57-
vc_const SELFDESTRUCT
52+
EXPORT SELFDESTRUCT
5853

5954
; [FPA 010 Begin]
60-
vc_const "D"
61-
vc_const DREAM_EATER
55+
EXPORT DEF D_CHAR EQU "D"
56+
EXPORT DREAM_EATER
6257

6358
; [FPA 011 Begin]
64-
vc_const "O"
65-
vc_const SPORE
59+
EXPORT DEF O_CHAR EQU "O"
60+
EXPORT SPORE
6661

6762
; [FPA 012 Begin]
68-
vc_const "C"
69-
vc_const ROCK_SLIDE
63+
EXPORT DEF C_CHAR EQU "C"
64+
EXPORT ROCK_SLIDE

0 commit comments

Comments
 (0)