Generate dmadata

This commit is contained in:
rozlette 2019-04-11 21:12:49 -05:00
parent 1f09af0e2e
commit bbaa5c05a3
3 changed files with 1644 additions and 1 deletions

View File

@ -37,7 +37,13 @@ build/src/boot_O2_g3/%: CC := python3 preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
build/src/code/%: CC := python3 preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
BASEROM_FILES := $(wildcard baserom/*)
BASEROM_O_FILES := $(BASEROM_FILES:baserom/%=build/baserom/%.o)
# Exclude dmadata, it will be generated right before packing the rom
BASEROM_FILES := $(subst baserom/dmadata ,,$(BASEROM_FILES))
BASEROM_BUILD_FILES := $(BASEROM_FILES:baserom/%=build/baserom/%)
DECOMP_FILES := $(wildcard decomp/*)
COMP_FILES := $(DECOMP_FILES:decomp/%=build/comp/%.yaz0)
S_FILES := $(wildcard asm/*)
S_O_FILES = $(S_FILES:asm/%.asm=build/asm/%.o)
C_FILES := $(wildcard src/libultra/*) \
@ -89,6 +95,9 @@ test.txt: build/src/test.o
clean:
rm $(ROM) code.elf code.bin boot.bin -r build
build/baserom/dmadata: $(COMP_FILES) $(BASEROM_BUILD_FILES)
python3 dmadata.py
# Recipes
build/baserom/%: baserom/%

64
dmadata.py Normal file
View File

@ -0,0 +1,64 @@
import os
import struct
import sys
OUT = 'build/baserom/dmadata'
from dmadata_table import *
def align_up(base, align_to):
return ((base + align_to - 1) // align_to) * align_to
if __name__ == "__main__":
with open(OUT, 'wb') as dmadata:
curr_vrom = 0
curr_phys = 0
for base_file, comp_file, alignment, size_if_missing in dmadata_table:
try:
uncompressed = comp_file == ''
missing = base_file == '' and comp_file == ''
blank = missing and size_if_missing == 0
is_dmadata = base_file == 'dmadata'
alignment = max(alignment, 0x10)
if missing:
vrom_size = size_if_missing
phys_size = 0
elif is_dmadata:
vrom_size = len(dmadata_table) * 0x10
phys_size = vrom_size
else:
vrom_size = os.path.getsize(base_file)
if uncompressed:
phys_size = vrom_size
else:
phys_size = os.path.getsize(comp_file)
if blank:
vrom_start = 0
vrom_end = 0
else:
vrom_start = align_up(curr_vrom, alignment)
vrom_end = vrom_start + vrom_size
if blank:
phys_start = 0
phys_end = 0
elif missing:
phys_start = 0xFFFFFFFF
phys_end = 0xFFFFFFFF
else:
phys_start = align_up(curr_phys, 0x10)
phys_end = 0 if uncompressed else phys_start + phys_size
curr_vrom = align_up(curr_vrom, alignment) + vrom_size
curr_phys = align_up(curr_phys, 0x10) + phys_size
dmadata.write(vrom_start.to_bytes(4, 'big'))
dmadata.write(vrom_end.to_bytes(4, 'big'))
dmadata.write(phys_start.to_bytes(4, 'big'))
dmadata.write(phys_end.to_bytes(4, 'big'))
except:
print('Error when processing entry ' + base_file)
sys.exit(1)

1570
dmadata_table.py Normal file

File diff suppressed because it is too large Load Diff