Browse Source

Fix conversion of C globals

master
Forest Belton 3 years ago
parent
commit
f6f8be20d3
5 changed files with 20 additions and 8 deletions
  1. +3
    -2
      .vscode/c_cpp_properties.json
  2. +1
    -1
      gbsdk/rules.mk
  3. +10
    -2
      gbsdk/tools/asmconvert.py
  4. +4
    -2
      scripts/generate_map.py
  5. +2
    -1
      src/level.c

+ 3
- 2
.vscode/c_cpp_properties.json View File

@ -6,8 +6,9 @@
"includePath": [ "includePath": [
"${default}", "${default}",
"${workspaceFolder}/gbsdk/inc", "${workspaceFolder}/gbsdk/inc",
"${workspaceFolder}/include"
"${workspaceFolder}/include",
"${workspaceFolder}/_build/level"
] ]
} }
] ]
}
}

+ 1
- 1
gbsdk/rules.mk View File

@ -126,7 +126,7 @@ $(BUILD)/%.asm.o: %.asm $(BUILD)/%.asm.d
# Rule to build the final rom # Rule to build the final rom
$(PROJECT_NAME).$(ROM_EXTENSION) $(PROJECT_NAME).map $(PROJECT_NAME).sym: $(OBJS) $(PROJECT_NAME).$(ROM_EXTENSION) $(PROJECT_NAME).map $(PROJECT_NAME).sym: $(OBJS)
@echo Linking $@ @echo Linking $@
$(Q)rgblink $(LDFLAGS) $^ -o $@ -m $(basename $@).map -n $(basename $@).sym
rgblink $(LDFLAGS) $^ -o $@ -m $(basename $@).map -n $(basename $@).sym
$(Q)rgbfix $(FIXFLAGS) $@ $(Q)rgbfix $(FIXFLAGS) $@
@python3 $(TOOLS)/romspace.py $(basename $@).map @python3 $(TOOLS)/romspace.py $(basename $@).map

+ 10
- 2
gbsdk/tools/asmconvert.py View File

@ -82,6 +82,7 @@ class Tokenizer:
tok = Tokenizer(sys.stdin.read()) tok = Tokenizer(sys.stdin.read())
global_names = set()
def processExpression(): def processExpression():
@ -177,9 +178,13 @@ while tok:
elif start.isA("COMMENT"): elif start.isA("COMMENT"):
print(start.value) print(start.value)
elif start.isA("DIRECTIVE"): elif start.isA("DIRECTIVE"):
if start.value in {".module", ".optsdcc", ".globl"}:
if start.value in {".module", ".optsdcc"}:
while not tok.pop().isA("NEWLINE"): while not tok.pop().isA("NEWLINE"):
pass pass
elif start.value == ".globl":
global_name = tok.pop().value
global_names.add(global_name)
assert tok.pop().isA("NEWLINE")
elif start.value == ".area": elif start.value == ".area":
area_name = tok.pop().value area_name = tok.pop().value
if area_name == "_DATA": if area_name == "_DATA":
@ -251,7 +256,10 @@ while tok:
processExpression() processExpression()
sys.stdout.write("\n") sys.stdout.write("\n")
elif tok.peek().isA("LABEL"): 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"): elif start.isA("ID", "ldhl"):
tok.expect("ID", "sp") tok.expect("ID", "sp")
tok.expect("OP", ",") tok.expect("OP", ",")

+ 4
- 2
scripts/generate_map.py View File

@ -131,6 +131,8 @@ def generate_map(pngfile: str, compress: bool = False) -> None:
#ifndef IS_MAP_{section}_H_ #ifndef IS_MAP_{section}_H_
#define IS_MAP_{section}_H_ #define IS_MAP_{section}_H_
#include "map.h"
extern map_t map_{section}; extern map_t map_{section};
#endif #endif
@ -146,7 +148,7 @@ MAP_ASSET({section}_tiles, "{section}.tiles");
MAP_ASSET({section}_map, "{section}.tilemap"); MAP_ASSET({section}_map, "{section}.tilemap");
MAP_ASSET({section}_collision, "{section}.collision"); MAP_ASSET({section}_collision, "{section}.collision");
const map_t map_{section} = {{
extern const map_t map_{section} = {{
(uint16_t)&{section}_tiles[0], (uint16_t)&{section}_tiles[0],
{tiles_size} / 16, {tiles_size} / 16,
(uint16_t)&{section}_map[0], (uint16_t)&{section}_map[0],
@ -158,7 +160,7 @@ const map_t map_{section} = {{
{camera[0]}, {camera[0]},
{camera[1]} {camera[1]}
}}; }};
"""
""".strip()
) )

+ 2
- 1
src/level.c View File

@ -1,4 +1,5 @@
#include "game.h" #include "game.h"
#include "intro.h"
#include "map.h" #include "map.h"
#include "sdk/hardware.h" #include "sdk/hardware.h"
#include "sdk/joypad.h" #include "sdk/joypad.h"
@ -7,7 +8,7 @@
void level(void) { void level(void) {
lcd_off(); lcd_off();
// map_load();
map_load(&map_intro);
rLCDC |= LCDC_ON; rLCDC |= LCDC_ON;

Loading…
Cancel
Save