mirror of
https://github.com/YohannDR/mzm.git
synced 2024-10-06 18:13:20 +00:00
Add gen_data.pl as a temp data label mechanism
Temporary until proper extractor gets merged
This commit is contained in:
parent
4d46eb362e
commit
465795eba7
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,6 @@
|
||||
/src/**/*.s
|
||||
/data/*
|
||||
!/data/data.txt
|
||||
|
||||
*.gba
|
||||
*.elf
|
||||
|
10
Makefile
10
Makefile
@ -26,6 +26,7 @@ CC = agbcc
|
||||
|
||||
DIFF = diff -u
|
||||
HOSTCC = cc
|
||||
MKDIR = mkdir -p
|
||||
RM = rm -f
|
||||
SHA1SUM = sha1sum
|
||||
TAIL = tail
|
||||
@ -40,7 +41,8 @@ CPPFLAGS = -nostdinc -Isrc/
|
||||
# Objects
|
||||
CSRC = $(wildcard src/*.c) $(wildcard src/sram/*.c)
|
||||
.PRECIOUS: $(CSRC:.c=.s)
|
||||
ASMSRC = $(CSRC:.c=.s) $(wildcard asm/*.s)
|
||||
DATA = data/data_0x0808c71c.s
|
||||
ASMSRC = $(CSRC:.c=.s) $(wildcard asm/*.s) $(DATA)
|
||||
OBJ = $(ASMSRC:.s=.o)
|
||||
|
||||
# Enable verbose output
|
||||
@ -77,6 +79,8 @@ clean:
|
||||
$Q$(RM) $(DUMPS)
|
||||
$(MSG) RM \*.o
|
||||
$Q$(RM) $(OBJ)
|
||||
$(MSG) RM data/*.s
|
||||
$Q$(RM) $(DATA)
|
||||
$(MSG) RM src/\*\*/\*.s
|
||||
$Q$(RM) $(CSRC:.c=.s)
|
||||
$(MSG) RM $(GBAFIX)
|
||||
@ -118,6 +122,10 @@ $(ELF) $(MAP): $(OBJ) linker.ld
|
||||
$(MSG) CC $@
|
||||
$Q$(CPP) $(CPPFLAGS) $< | $(CC) -o $@ $(CFLAGS) && printf '\t.align 2, 0 @ dont insert nops\n' >> $@
|
||||
|
||||
data/data_0x0808c71c.s: data/data.txt
|
||||
$(MSG) EXTRACT $@
|
||||
$Q./tools/gen_data.pl 0x0808c71c 0x08800000 $(BASEROM) <$< >$@
|
||||
|
||||
src/sram/%.s: CFLAGS = -O1 -mthumb-interwork -fhex-asm
|
||||
src/sram/%.s: src/sram/%.c
|
||||
|
||||
|
@ -1,2 +0,0 @@
|
||||
.include "asm/macros.inc"
|
||||
baserom_blob 0x0008c71c, 0x00800000
|
@ -17,7 +17,3 @@
|
||||
.thumb
|
||||
.type \name, %function
|
||||
.endm
|
||||
|
||||
.macro baserom_blob start end
|
||||
.incbin "mzm_us_baserom.gba", \start, (\end - \start)
|
||||
.endm
|
||||
|
0
data/data.txt
Normal file
0
data/data.txt
Normal file
@ -70,7 +70,7 @@ SECTIONS {
|
||||
asm/disasm_0x08005368.o(.text);
|
||||
asm/libgcc.o(.text);
|
||||
asm/disasm_0x0808af18.o(.text);
|
||||
asm/data_0x0808c71c.o(.text);
|
||||
data/data_0x0808c71c.o(.text);
|
||||
} >rom
|
||||
|
||||
/DISCARD/ : {
|
||||
|
50
tools/gen_data.pl
Executable file
50
tools/gen_data.pl
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
use constant USAGE => "Usage: $0 START END ROM <data.txt\n";
|
||||
use constant OFFSET => 0x08000000;
|
||||
|
||||
my $start = shift or die(USAGE);
|
||||
my $end = shift or die(USAGE);
|
||||
my $rom = shift or die(USAGE);
|
||||
|
||||
hex($end) > hex($start)
|
||||
or die(USAGE);
|
||||
|
||||
-f $rom
|
||||
or die("Cannot find '$rom'\n");
|
||||
|
||||
my $first_addr = hex($start) - OFFSET;
|
||||
my %labels = ($first_addr => "");
|
||||
|
||||
while (<>) {
|
||||
s/^\s+//;
|
||||
s/\s+$//;
|
||||
s/\s*#.*$//;
|
||||
|
||||
next if /^$/;
|
||||
|
||||
/^(0x[\da-fA-F]{8})\s+(\w+)$/
|
||||
or die("failed to parse line '$_'\n");
|
||||
|
||||
my $addr = hex($1);
|
||||
my $label = $2;
|
||||
|
||||
$labels{$addr} = $label;
|
||||
}
|
||||
|
||||
my $last_addr = $first_addr;
|
||||
for my $addr (sort keys %labels) {
|
||||
my $label = $labels{$addr};
|
||||
next if $label eq "";
|
||||
|
||||
my $size = $addr - $last_addr;
|
||||
print(".incbin \"$rom\", $last_addr, $size\n") if $size;
|
||||
print("$label:\n");
|
||||
$last_addr = $addr;
|
||||
}
|
||||
|
||||
my $size = hex($end) - OFFSET - $last_addr;
|
||||
print(".incbin \"$rom\", $last_addr, $size\n");
|
Loading…
Reference in New Issue
Block a user