Add first version of extractor

This commit is contained in:
YohannDR 2022-09-24 17:42:57 +02:00
parent a5593bb34c
commit 04396acc1c
4 changed files with 41 additions and 7 deletions

2
.gitignore vendored
View File

@ -1,6 +1,5 @@
/src/**/*.s
/data/*
!/data/data.txt
*.gba
*.elf
@ -14,7 +13,6 @@
*.deps.json
*.runtimeconfig.json
data/*.c
include/**/*.s
tools/*.txt
.vscode

View File

@ -32,6 +32,8 @@ SHA1SUM = sha1sum
TAIL = tail
GBAFIX = tools/gbafix/gbafix
PYTHON = python3
EXTRACTOR = tools/extractor.py
# Flags
ASFLAGS = -mcpu=arm7tdmi
@ -56,10 +58,6 @@ endif
.PHONY: all
all: $(TARGET)
.PHONY: extract
extract:
$(MSG) MZM-Extractor -a
.PHONY: check
check: all
$(MSG) SHA1SUM $(SHA1FILE)
@ -96,7 +94,6 @@ help:
@echo ' dump: dump the ROMs'
@echo ' diff: compare the ROM with the original'
@echo ' clean: remove the ROM and intermediate files'
@echo ' extract: extract data as files using the MZM-Extractor (https://github.com/YohannDR/MZM-Extractor)'
@echo ' help: show this message'
@echo ''
@echo 'Flags:'
@ -124,6 +121,9 @@ $(ELF) $(MAP): $(OBJ) linker.ld
$(MSG) CC $@
$Q$(CPP) $(CPPFLAGS) $< | $(CC) -o $@ $(CFLAGS) && printf '\t.align 2, 0 @ dont insert nops\n' >> $@
%.c:
$(MSG) Extractor $@
$Q$(PYTHON) $(EXTRACTOR)
src/sram/%.s: CFLAGS = -O1 -mthumb-interwork -fhex-asm
src/sram/%.s: src/sram/%.c

1
database.txt Normal file
View File

@ -0,0 +1 @@
Sprites/MorphBall.gfx;672;0x2b28a8

35
tools/extractor.py Normal file
View File

@ -0,0 +1,35 @@
from array import array
from io import BufferedReader
import os
import shutil
DATA_PATH = "../data/"
subDirs: array = [
"Sprites/"
]
shutil.rmtree(DATA_PATH, ignore_errors=False, onerror=None)
if not os.path.exists(DATA_PATH):
# Create directories
os.mkdir(DATA_PATH)
for dir in subDirs:
os.mkdir(DATA_PATH.__add__(dir))
rom: BufferedReader = open("../mzm_us_baserom.gba", "rb")
db: BufferedReader = open("../database.txt", "r")
line: str = db.readline()
while line != '':
# Formatted as follows : name;size;address
info: array = line.split(";")
rom.seek(int(info[2], 16))
data = rom.read(int(info[1]))
output: BufferedReader = open("../data/".__add__(info[0]), "wb")
output.write(bytearray(data))
output.close()
line = db.readline()
rom.close()