Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use exported constants for VC patch #1161

Merged
merged 5 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ $(pokecrystal_debug_obj): RGBASMFLAGS += -D _DEBUG
$(pokecrystal11_debug_obj): RGBASMFLAGS += -D _CRYSTAL11 -D _DEBUG
$(pokecrystal11_vc_obj): RGBASMFLAGS += -D _CRYSTAL11 -D _CRYSTAL11_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 @@ -146,10 +146,6 @@ $(foreach obj, $(pokecrystal_debug_obj), $(eval $(call DEP,$(obj),$(obj:_debug.o
$(foreach obj, $(pokecrystal11_debug_obj), $(eval $(call DEP,$(obj),$(obj:11_debug.o=.asm))))
$(foreach obj, $(pokecrystal11_vc_obj), $(eval $(call DEP,$(obj),$(obj:11_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
6 changes: 3 additions & 3 deletions docs/vc_patch.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The `.patch.template` file is the basis for the `.patch` file. Many numeric valu

### vc/pokecrystal11.constants.asm
vulcandth marked this conversation as resolved.
Show resolved Hide resolved

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.
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).


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

```bash
tools/make_patch labels.sym constants.sym patched.gbc original.gbc vc.patch.template vc.patch
tools/make_patch labels.sym patched.gbc original.gbc vc.patch.template vc.patch
Rangi42 marked this conversation as resolved.
Show resolved Hide resolved
```

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

```bash
tools/make_patch pokecrystal11_vc.sym vc/pokecrystal11.constants.sym pokecrystal11_vc.gbc pokecrystal11.gbc vc/pokecrystal11.patch.template pokecrystal11.patch
tools/make_patch pokecrystal11_vc.sym pokecrystal11_vc.gbc pokecrystal11.gbc vc/pokecrystal11.patch.template pokecrystal11.patch
```


Expand Down
2 changes: 2 additions & 0 deletions includes.asm
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ INCLUDE "constants/trainer_constants.asm"
INCLUDE "constants/trainer_data_constants.asm"
INCLUDE "constants/type_constants.asm"
INCLUDE "constants/battle_tower_constants.asm"

INCLUDE "vc/pokecrystal11.constants.asm"
Rangi42 marked this conversation as resolved.
Show resolved Hide resolved
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"
Rangi42 marked this conversation as resolved.
Show resolved Hide resolved

#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 @@ -449,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
39 changes: 17 additions & 22 deletions vc/pokecrystal11.constants.asm
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
; These are all the asm constants needed to make the crystal11_vc patch.

MACRO vc_const
DEF x = \1
println "{02x:x} \1" ; same format as rgblink's .sym file
ENDM

; [fight begin]
vc_const SCREEN_HEIGHT_PX
EXPORT SCREEN_HEIGHT_PX

; [print forbid 2]
vc_const A_BUTTON
EXPORT A_BUTTON
; [print forbid 3]
vc_const MAPGROUP_CIANWOOD
vc_const MAP_CIANWOOD_PHOTO_STUDIO
EXPORT MAPGROUP_CIANWOOD
EXPORT MAP_CIANWOOD_PHOTO_STUDIO
; [print forbid 5]
vc_const NO_INPUT
vc_const B_BUTTON
vc_const D_UP
vc_const D_DOWN
EXPORT NO_INPUT
EXPORT B_BUTTON
EXPORT D_UP
EXPORT D_DOWN

; [FPA 001 Begin]
vc_const FISSURE
EXPORT FISSURE
; [FPA 002 Begin]
vc_const SELFDESTRUCT
EXPORT SELFDESTRUCT
; [FPA 003 Begin]
vc_const THUNDER
EXPORT THUNDER
; [FPA 004 Begin]
vc_const FLASH
EXPORT FLASH
; [FPA 005 Begin]
vc_const EXPLOSION
EXPORT EXPLOSION
; [FPA 006 Begin]
vc_const HORN_DRILL
EXPORT HORN_DRILL
; [FPA 007 Begin]
vc_const HYPER_BEAM
EXPORT HYPER_BEAM

; [FPA 042801 Begin]
vc_const PRESENT
vc_const anim_1gfx_command
EXPORT PRESENT
EXPORT anim_1gfx_command
Loading