Move more tools into tools folder

This commit is contained in:
rozlette 2019-09-22 03:11:22 -05:00
parent ec35f43925
commit b88d1d0bf6
9 changed files with 105 additions and 59 deletions

View File

@ -33,8 +33,8 @@ test.txt: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
CC := $(QEMU_IRIX) -L $(IRIX_71_ROOT) $(IRIX_71_ROOT)/usr/bin/cc
test.txt: CC := python3 preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
build/src/boot_O2_g3/%: CC := python3 preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
build/src/code/%: CC := python3 preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
build/src/boot_O2_g3/%: CC := python3 ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
build/src/code/%: CC := python3 ./tools/preprocess.py $(CC) -- $(AS) $(ASFLAGS) --
BASEROM_FILES := $(wildcard baserom/*)
# Exclude dmadata, it will be generated right before packing the rom
@ -55,7 +55,7 @@ C_FILES := $(wildcard src/libultra/*) \
$(wildcard src/boot_O2_g3/*) \
$(wildcard src/boot_O1/*)
C_O_FILES = $(C_FILES:src/%.c=build/src/%.o)
ROM_FILES := $(shell cat makerom_files.txt)
ROM_FILES := $(shell cat ./tables/makerom_files.txt)
ROM := rom.z64
@ -78,7 +78,7 @@ check: $(ROM)
@md5sum -c checksum.md5
$(ROM): $(ROM_FILES)
@python3 makerom.py
@python3 ./tools/makerom.py ./tables/makerom_files.txt $@
boot.bin: code.elf
$(MIPS_BINUTILS)objcopy --dump-section boot=$@ $<
@ -102,7 +102,7 @@ build/baserom/boot: boot.bin
cp $< $@
build/comp/code.yaz0: code.bin
python3 yaz0.py -i $< -o $@
python3 ./tools/yaz0.py $< $@
disasm:
@python3 ./tools/disasm.py -d ./asm -e ./include -u . -l ./tables/files.py -f ./tables/functions.py -o ./tables/objects.py -v ./tables/variables.py
@ -122,5 +122,5 @@ build/src/%.o: src/%.c include/*
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTIMIZATION) -Iinclude -o $@ $<
build/comp/%.yaz0: decomp/%
python3 yaz0.py -i $< -o $@
python3 ./tools/yaz0.py $< $@

View File

@ -1,32 +0,0 @@
import os
import struct
import sys
FILENAME = 'makerom_files.txt'
OUT = 'rom.z64'
def read_uint32_be(offset):
return struct.unpack('>I', fileData[offset:offset+4])[0]
def read_uint16_be(offset):
return struct.unpack('>H', fileData[offset:offset+2])[0]
with open(OUT, 'wb') as w, open(FILENAME, 'rt') as f:
file_name = f.readline().strip()
total_size = 0
while file_name:
try:
with open(file_name, 'rb') as current_file:
file_data = current_file.read()
w.write(file_data)
total_size += len(file_data)
except:
print('Could not open file ' + file_name)
sys.exit(1)
file_name = f.readline().strip()
while total_size < 0x2000000:
w.write((total_size % 256).to_bytes(1,"big"))
total_size += 1

34
tools/makerom.py Normal file
View File

@ -0,0 +1,34 @@
import os, struct, sys, ast, argparse
def read_uint32_be(offset):
return struct.unpack('>I', fileData[offset:offset+4])[0]
def read_uint16_be(offset):
return struct.unpack('>H', fileData[offset:offset+2])[0]
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('files', help='file list')
parser.add_argument('out', help='output file')
args = parser.parse_args()
with open(args.out, 'wb') as w, open(args.files, 'rt') as f:
file_name = f.readline().strip()
total_size = 0
while file_name:
try:
with open(file_name, 'rb') as current_file:
file_data = current_file.read()
w.write(file_data)
total_size += len(file_data)
except:
print('Could not open file ' + file_name)
sys.exit(1)
file_name = f.readline().strip()
while total_size < 0x2000000:
w.write((total_size % 256).to_bytes(1,"big"))
total_size += 1

56
tools/parse_actor_init.py Normal file
View File

@ -0,0 +1,56 @@
# TODO generalize
data = [
0xC8580005,
0xB874FE0C,
0x801F0002,
0x30540FA0
]
last_continue = True
for entry in data:
if not last_continue:
print('Error: entries after entry without continue bit')
value = entry & 0xFFFF
offset = (entry >> 16) & 0x7FF
type = (entry >> 27) & 0xF
_continue = (entry >> 31) & 0x1
# convert to signed short
if value >= 0x8000:
value -= 0x10000
# TODO which ones are signed?
print('0x{:X}: '.format(offset), end='')
if type == 0:
print('char {}'.format(value))
elif type == 1:
print('char {}'.format(value))
elif type == 2:
print('short {}'.format(value))
elif type == 3:
print('short {}'.format(value))
elif type == 4:
print('int {}'.format(value))
elif type == 5:
print('int {}'.format(value))
elif type == 6:
print('float {:f}'.format(value))
elif type == 7:
print('float {:f}'.format(value / 1000))
elif type == 8:
print('Vector3f ({0:f}, {0:f}, {0:f})'.format(value))
elif type == 9:
value /= 1000
print('Vector3f ({0:f}, {0:f}, {0:f})'.format(value))
elif type == 10:
print('Vector3f ({0}, {0}, {0})'.format(value))
else:
print('Error: invalid type ' + str(value))
if not _continue:
print('END')
last_continue = _continue

View File

@ -1,6 +1,4 @@
import os
import sys
import getopt
import os, sys, argparse
def read_file(name):
file_data=[]
@ -162,30 +160,20 @@ def yaz0_compress(input):
def main(argv):
inputfile = ''
outputfile = ''
decompress = False
try:
opts, args = getopt.getopt(argv, 'i:o:d')
except getopt.GetoptError:
print('getopt Error') # todo errors
sys.exit(2)
for opt, arg in opts:
if opt == '-i':
inputfile = arg
elif opt == '-o':
outputfile = arg
elif opt == '-d':
decompress = True
parser = argparse.ArgumentParser()
parser.add_argument('input', help='input file')
parser.add_argument('output', help='output file')
parser.add_argument('-d', '--decompress', help='decompress file, otherwise compress it', action='store_true', default=False)
args = parser.parse_args()
input_data = read_file(inputfile)
input_data = read_file(args.input)
if decompress:
if args.decompress:
output_data = yaz0_decompress(input_data)
else:
output_data = yaz0_compress(input_data)
write_file(outputfile, output_data)
write_file(args.output, output_data)
if __name__ == "__main__":