Skip to content

Commit 0124a1e

Browse files
authored
Use exported constants for VC patch (#1161)
1 parent 15187f5 commit 0124a1e

File tree

5 files changed

+36
-41
lines changed

5 files changed

+36
-41
lines changed

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ $(pokecrystal_debug_obj): RGBASMFLAGS += -D _DEBUG
117117
$(pokecrystal11_debug_obj): RGBASMFLAGS += -D _CRYSTAL11 -D _DEBUG
118118
$(pokecrystal11_vc_obj): RGBASMFLAGS += -D _CRYSTAL11 -D _CRYSTAL11_VC
119119

120-
%.patch: vc/%.constants.sym %_vc.gbc %.gbc vc/%.patch.template
120+
%.patch: %_vc.gbc %.gbc vc/%.patch.template
121121
tools/make_patch $*_vc.sym $^ $@
122122

123123
rgbdscheck.o: rgbdscheck.asm
@@ -146,10 +146,6 @@ $(foreach obj, $(pokecrystal_debug_obj), $(eval $(call DEP,$(obj),$(obj:_debug.o
146146
$(foreach obj, $(pokecrystal11_debug_obj), $(eval $(call DEP,$(obj),$(obj:11_debug.o=.asm))))
147147
$(foreach obj, $(pokecrystal11_vc_obj), $(eval $(call DEP,$(obj),$(obj:11_vc.o=.asm))))
148148

149-
# Dependencies for VC files that need to run scan_includes
150-
%.constants.sym: %.constants.asm $(shell tools/scan_includes %.constants.asm) $(preinclude_deps) | rgbdscheck.o
151-
$(RGBASM) $(RGBASMFLAGS) $< > $@
152-
153149
endif
154150

155151

docs/vc_patch.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The `.patch.template` file is the basis for the `.patch` file. Many numeric valu
2828

2929
### vc/pokecrystal11.constants.asm
3030

31-
The `.constants.asm` file is used to create a `.constants.sym` file. Typical `.sym` files only list the values of *labels* (ROM banks and addresses); this file is used to list *constants* that are needed by the `.patch.template`. Any constants that the `.patch.template` refers to must be explicitly printed here with the `vc_const` macro.
31+
The `.constants.asm` file is used to export the values of *constants* that are needed by `.patch.template`, so their values will appear in the `.sym` file along with *labels* (ROM banks and addresses).
3232

3333

3434
### tools/make_patch.c
@@ -38,13 +38,13 @@ The program used to convert a `.patch.template` into a `.patch` file.
3838
To convert `vc.patch.template` into `vc.patch`:
3939

4040
```bash
41-
tools/make_patch labels.sym constants.sym patched.gbc original.gbc vc.patch.template vc.patch
41+
tools/make_patch values.sym patched.gbc original.gbc vc.patch.template vc.patch
4242
```
4343

4444
For example, this is what `make crystal11_vc` does:
4545

4646
```bash
47-
tools/make_patch pokecrystal11_vc.sym vc/pokecrystal11.constants.sym pokecrystal11_vc.gbc pokecrystal11.gbc vc/pokecrystal11.patch.template pokecrystal11.patch
47+
tools/make_patch pokecrystal11_vc.sym pokecrystal11_vc.gbc pokecrystal11.gbc vc/pokecrystal11.patch.template pokecrystal11.patch
4848
```
4949

5050

includes.asm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ INCLUDE "constants/trainer_constants.asm"
6969
INCLUDE "constants/trainer_data_constants.asm"
7070
INCLUDE "constants/type_constants.asm"
7171
INCLUDE "constants/battle_tower_constants.asm"
72+
73+
if DEF(_CRYSTAL11_VC)
74+
INCLUDE "vc/pokecrystal11.constants.asm"
75+
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) {
@@ -449,20 +451,18 @@ bool verify_completeness(FILE *restrict orig_rom, FILE *restrict new_rom, struct
449451
}
450452

451453
int main(int argc, char *argv[]) {
452-
if (argc != 7) {
454+
if (argc != 6) {
453455
usage_exit(1);
454456
}
455457

456-
struct Symbol *symbols = NULL;
457-
parse_symbols(argv[1], &symbols);
458-
parse_symbols(argv[2], &symbols);
458+
struct Symbol *symbols = parse_symbols(argv[1]);
459459

460-
FILE *new_rom = xfopen(argv[3], 'r');
461-
FILE *orig_rom = xfopen(argv[4], 'r');
462-
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);
463463

464464
if (!verify_completeness(orig_rom, new_rom, patches)) {
465-
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]);
466466
}
467467

468468
symbol_free(symbols);

vc/pokecrystal11.constants.asm

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
11
; These are all the asm constants needed to make the crystal11_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
; [fight begin]
9-
vc_const SCREEN_HEIGHT_PX
4+
EXPORT SCREEN_HEIGHT_PX
105

116
; [print forbid 2]
12-
vc_const A_BUTTON
7+
EXPORT A_BUTTON
138
; [print forbid 3]
14-
vc_const MAPGROUP_CIANWOOD
15-
vc_const MAP_CIANWOOD_PHOTO_STUDIO
9+
EXPORT MAPGROUP_CIANWOOD
10+
EXPORT MAP_CIANWOOD_PHOTO_STUDIO
1611
; [print forbid 5]
17-
vc_const NO_INPUT
18-
vc_const B_BUTTON
19-
vc_const D_UP
20-
vc_const D_DOWN
12+
EXPORT NO_INPUT
13+
EXPORT B_BUTTON
14+
EXPORT D_UP
15+
EXPORT D_DOWN
2116

2217
; [FPA 001 Begin]
23-
vc_const FISSURE
18+
EXPORT FISSURE
2419
; [FPA 002 Begin]
25-
vc_const SELFDESTRUCT
20+
EXPORT SELFDESTRUCT
2621
; [FPA 003 Begin]
27-
vc_const THUNDER
22+
EXPORT THUNDER
2823
; [FPA 004 Begin]
29-
vc_const FLASH
24+
EXPORT FLASH
3025
; [FPA 005 Begin]
31-
vc_const EXPLOSION
26+
EXPORT EXPLOSION
3227
; [FPA 006 Begin]
33-
vc_const HORN_DRILL
28+
EXPORT HORN_DRILL
3429
; [FPA 007 Begin]
35-
vc_const HYPER_BEAM
30+
EXPORT HYPER_BEAM
3631

3732
; [FPA 042801 Begin]
38-
vc_const PRESENT
39-
vc_const anim_1gfx_command
33+
EXPORT PRESENT
34+
EXPORT anim_1gfx_command

0 commit comments

Comments
 (0)