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 61c9ba5 commit 9f5a3d8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 41 deletions.
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
9 changes: 2 additions & 7 deletions docs/vc_patch.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,20 @@ There are a few files involved with building the `.patch` file, in addition to t
The `.patch.template` file is the basis for the `.patch` file. Many numeric values in the `.patch` file are derived from the values of labels, constants, and ROM content; these values are abstracted into *commands* that get evaluated by `tools/make_patch` to output symbolic names as their actual values, formatted to match the original `.patch` file.


### vc/pokecrystal11.constants.asm

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.


### tools/make_patch.c

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
```

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"
13 changes: 6 additions & 7 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 @@ -449,20 +449,19 @@ 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);

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

0 comments on commit 9f5a3d8

Please sign in to comment.