Skip to content

Commit 87eadfd

Browse files
committed
Use exported constants for VC patch
1 parent cd1065b commit 87eadfd

File tree

7 files changed

+143
-145
lines changed

7 files changed

+143
-145
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@ 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+
INCLUDE "vc/pokeblue.constants.asm"
55+
INCLUDE "vc/pokered.constants.asm"

tools/make_patch.c

Lines changed: 18 additions & 12 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 "labels.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) {
@@ -342,6 +344,12 @@ struct Buffer *process_template(const char *template_filename, const char *patch
342344

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

346354
// Fill in the template
347355
const struct Symbol *current_hook = NULL;
@@ -411,7 +419,7 @@ struct Buffer *process_template(const char *template_filename, const char *patch
411419
int compare_patch(const void *patch1, const void *patch2) {
412420
unsigned int offset1 = ((const struct Patch *)patch1)->offset;
413421
unsigned int offset2 = ((const struct Patch *)patch2)->offset;
414-
return offset1 > offset2 ? 1 : offset1 < offset2 ? -1 : 0;
422+
return (offset1 > offset2) - (offset1 < offset2);
415423
}
416424

417425
bool verify_completeness(FILE *restrict orig_rom, FILE *restrict new_rom, struct Buffer *patches) {
@@ -443,20 +451,18 @@ bool verify_completeness(FILE *restrict orig_rom, FILE *restrict new_rom, struct
443451
}
444452

445453
int main(int argc, char *argv[]) {
446-
if (argc != 7) {
454+
if (argc != 6) {
447455
usage_exit(1);
448456
}
449457

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

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);
460+
FILE *new_rom = xfopen(argv[2], 'r');
461+
FILE *orig_rom = xfopen(argv[3], 'r');
462+
struct Buffer *patches = process_template(argv[4], argv[5], new_rom, orig_rom, symbols);
457463

458464
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]);
465+
fprintf(stderr, PROGRAM_NAME ": Warning: Not all ROM differences are defined by \"%s\"\n", argv[5]);
460466
}
461467

462468
symbol_free(symbols);

vc/pokeblue.constants.asm

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,66 @@
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-
3+
IF DEF(_BLUE)
84
; [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
5+
EXPORT DEF M_CHAR EQU "M"
6+
EXPORT DEF E_CHAR EQU "E"
7+
EXPORT DEF G_CHAR EQU "G"
8+
EXPORT DEF A_CHAR EQU "A"
9+
EXPORT DEF P_CHAR EQU "P"
10+
EXPORT DEF S_CHAR EQU "S"
11+
EXPORT DEF L_CHAR EQU "L"
12+
EXPORT DEF F_CHAR EQU "F"
13+
EXPORT DEF X_CHAR EQU "X"
14+
EXPORT MEGA_PUNCH
1915

2016
; [FPA 001 End]
21-
vc_const EXPLOSION
17+
EXPORT EXPLOSION
2218

2319
; [FPA 002 Begin]
24-
vc_const "U"
25-
vc_const "I"
26-
vc_const GUILLOTINE
20+
EXPORT DEF U_CHAR EQU "U"
21+
EXPORT DEF I_CHAR EQU "I"
22+
EXPORT GUILLOTINE
2723

2824
; [FPA 002 End]
29-
vc_const "K"
30-
vc_const MEGA_KICK
25+
EXPORT DEF K_CHAR EQU "K"
26+
EXPORT MEGA_KICK
3127

3228
; [FPA 004 Begin]
33-
vc_const "B"
34-
vc_const "Z"
35-
vc_const BLIZZARD
29+
EXPORT DEF B_CHAR EQU "B"
30+
EXPORT DEF Z_CHAR EQU "Z"
31+
EXPORT BLIZZARD
3632

3733
; [FPA 005 Begin]
38-
vc_const BUBBLEBEAM
34+
EXPORT BUBBLEBEAM
3935

4036
; [FPA 005 End]
41-
vc_const HYPER_BEAM
37+
EXPORT HYPER_BEAM
4238

4339
; [FPA 006 Begin]
44-
vc_const "H"
45-
vc_const "Y"
40+
EXPORT DEF H_CHAR EQU "H"
41+
EXPORT DEF Y_CHAR EQU "Y"
4642

4743
; [FPA 007 Begin]
48-
vc_const "T"
49-
vc_const "N"
50-
vc_const THUNDERBOLT
44+
EXPORT DEF T_CHAR EQU "T"
45+
EXPORT DEF N_CHAR EQU "N"
46+
EXPORT THUNDERBOLT
5147

5248
; [FPA 008 Begin]
53-
vc_const "R"
54-
vc_const REFLECT
49+
EXPORT DEF R_CHAR EQU "R"
50+
EXPORT REFLECT
5551

5652
; [FPA 009 Begin]
57-
vc_const SELFDESTRUCT
53+
EXPORT SELFDESTRUCT
5854

5955
; [FPA 010 Begin]
60-
vc_const "D"
61-
vc_const DREAM_EATER
56+
EXPORT DEF D_CHAR EQU "D"
57+
EXPORT DREAM_EATER
6258

6359
; [FPA 011 Begin]
64-
vc_const "O"
65-
vc_const SPORE
60+
EXPORT DEF O_CHAR EQU "O"
61+
EXPORT SPORE
6662

6763
; [FPA 012 Begin]
68-
vc_const "C"
69-
vc_const ROCK_SLIDE
64+
EXPORT DEF C_CHAR EQU "C"
65+
EXPORT ROCK_SLIDE
66+
ENDC

0 commit comments

Comments
 (0)