From f6f8be20d337b1f9fc61506df9d0440a4c662eb5 Mon Sep 17 00:00:00 2001 From: Forest Belton Date: Wed, 29 Sep 2021 16:05:58 -0400 Subject: [PATCH] Fix conversion of C globals --- .vscode/c_cpp_properties.json | 5 +++-- gbsdk/rules.mk | 2 +- gbsdk/tools/asmconvert.py | 12 ++++++++++-- scripts/generate_map.py | 6 ++++-- src/level.c | 3 ++- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 5b726ee..0a6448a 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -6,8 +6,9 @@ "includePath": [ "${default}", "${workspaceFolder}/gbsdk/inc", - "${workspaceFolder}/include" + "${workspaceFolder}/include", + "${workspaceFolder}/_build/level" ] } ] -} \ No newline at end of file +} diff --git a/gbsdk/rules.mk b/gbsdk/rules.mk index a04ec36..edbc4e0 100644 --- a/gbsdk/rules.mk +++ b/gbsdk/rules.mk @@ -126,7 +126,7 @@ $(BUILD)/%.asm.o: %.asm $(BUILD)/%.asm.d # Rule to build the final rom $(PROJECT_NAME).$(ROM_EXTENSION) $(PROJECT_NAME).map $(PROJECT_NAME).sym: $(OBJS) @echo Linking $@ - $(Q)rgblink $(LDFLAGS) $^ -o $@ -m $(basename $@).map -n $(basename $@).sym + rgblink $(LDFLAGS) $^ -o $@ -m $(basename $@).map -n $(basename $@).sym $(Q)rgbfix $(FIXFLAGS) $@ @python3 $(TOOLS)/romspace.py $(basename $@).map diff --git a/gbsdk/tools/asmconvert.py b/gbsdk/tools/asmconvert.py index 4c3d332..663b3db 100644 --- a/gbsdk/tools/asmconvert.py +++ b/gbsdk/tools/asmconvert.py @@ -82,6 +82,7 @@ class Tokenizer: tok = Tokenizer(sys.stdin.read()) +global_names = set() def processExpression(): @@ -177,9 +178,13 @@ while tok: elif start.isA("COMMENT"): print(start.value) elif start.isA("DIRECTIVE"): - if start.value in {".module", ".optsdcc", ".globl"}: + if start.value in {".module", ".optsdcc"}: while not tok.pop().isA("NEWLINE"): pass + elif start.value == ".globl": + global_name = tok.pop().value + global_names.add(global_name) + assert tok.pop().isA("NEWLINE") elif start.value == ".area": area_name = tok.pop().value if area_name == "_DATA": @@ -251,7 +256,10 @@ while tok: processExpression() sys.stdout.write("\n") elif tok.peek().isA("LABEL"): - print("%s%s" % (start.value, tok.pop().value)) + label_suffix = tok.pop().value + if label_suffix == ":" and start.value in global_names: + label_suffix = "::" + print("%s%s" % (start.value, label_suffix)) elif start.isA("ID", "ldhl"): tok.expect("ID", "sp") tok.expect("OP", ",") diff --git a/scripts/generate_map.py b/scripts/generate_map.py index 799edb3..242eed2 100644 --- a/scripts/generate_map.py +++ b/scripts/generate_map.py @@ -131,6 +131,8 @@ def generate_map(pngfile: str, compress: bool = False) -> None: #ifndef IS_MAP_{section}_H_ #define IS_MAP_{section}_H_ +#include "map.h" + extern map_t map_{section}; #endif @@ -146,7 +148,7 @@ MAP_ASSET({section}_tiles, "{section}.tiles"); MAP_ASSET({section}_map, "{section}.tilemap"); MAP_ASSET({section}_collision, "{section}.collision"); -const map_t map_{section} = {{ +extern const map_t map_{section} = {{ (uint16_t)&{section}_tiles[0], {tiles_size} / 16, (uint16_t)&{section}_map[0], @@ -158,7 +160,7 @@ const map_t map_{section} = {{ {camera[0]}, {camera[1]} }}; -""" +""".strip() ) diff --git a/src/level.c b/src/level.c index ba34b2e..4e47901 100644 --- a/src/level.c +++ b/src/level.c @@ -1,4 +1,5 @@ #include "game.h" +#include "intro.h" #include "map.h" #include "sdk/hardware.h" #include "sdk/joypad.h" @@ -7,7 +8,7 @@ void level(void) { lcd_off(); - // map_load(); + map_load(&map_intro); rLCDC |= LCDC_ON;