mirror of https://github.com/zeldaret/mm.git
makerom improvements. Faster and generate checksum
This commit is contained in:
parent
a88337a2fd
commit
33a45c2819
2
Makefile
2
Makefile
|
|
@ -78,7 +78,7 @@ check: $(ROM)
|
||||||
@md5sum -c checksum.md5
|
@md5sum -c checksum.md5
|
||||||
|
|
||||||
$(ROM): $(ROM_FILES)
|
$(ROM): $(ROM_FILES)
|
||||||
@python3 ./tools/makerom.py ./tables/makerom_files.txt $@
|
@python3 ./tools/makerom.py ./tables/dmadata_table.py $@
|
||||||
|
|
||||||
boot.bin: code.elf
|
boot.bin: code.elf
|
||||||
$(MIPS_BINUTILS)objcopy --dump-section boot=$@ $<
|
$(MIPS_BINUTILS)objcopy --dump-section boot=$@ $<
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
[
|
[
|
||||||
('build/baserom/makerom', '', 0x10, 0),
|
('build/baserom/makerom', '', 0x10, 0),
|
||||||
('build/baserom/boot', '', 0x10, 0),
|
('build/baserom/boot', '', 0x10, 0),
|
||||||
('dmadata', '', 0x10, 0),
|
('build/baserom/dmadata', '', 0x10, 0),
|
||||||
('build/baserom/Audiobank', '', 0x10, 0),
|
('build/baserom/Audiobank', '', 0x10, 0),
|
||||||
('build/baserom/Audioseq', '', 0x10, 0),
|
('build/baserom/Audioseq', '', 0x10, 0),
|
||||||
('build/baserom/Audiotable', '', 0x10, 0),
|
('build/baserom/Audiotable', '', 0x10, 0),
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ if __name__ == "__main__":
|
||||||
uncompressed = comp_file == ''
|
uncompressed = comp_file == ''
|
||||||
missing = base_file == '' and comp_file == ''
|
missing = base_file == '' and comp_file == ''
|
||||||
blank = missing and size_if_missing == 0
|
blank = missing and size_if_missing == 0
|
||||||
is_dmadata = base_file == 'dmadata'
|
is_dmadata = base_file.endswith('dmadata')
|
||||||
|
|
||||||
alignment = max(alignment, 0x10)
|
alignment = max(alignment, 0x10)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,37 @@
|
||||||
import os, struct, sys, ast, argparse
|
import os, struct, sys, ast, argparse
|
||||||
|
|
||||||
def read_uint32_be(offset):
|
def read_uint32_be(data, offset):
|
||||||
return struct.unpack('>I', fileData[offset:offset+4])[0]
|
return struct.unpack('>I', data[offset:offset+4])[0]
|
||||||
|
|
||||||
def read_uint16_be(offset):
|
def generate_checksum(data):
|
||||||
return struct.unpack('>H', fileData[offset:offset+2])[0]
|
seed = 0xDF26F436
|
||||||
|
|
||||||
|
t1 = t2 = t3 = t4 = t5 = t6 = seed
|
||||||
|
|
||||||
|
for i in range(0x1000, 0x1000 + 0x100000, 4):
|
||||||
|
d = read_uint32_be(data, i)
|
||||||
|
|
||||||
|
shift = d & 0x1F
|
||||||
|
r = ((d << shift) & 0xFFFFFFFF) | ((d >> (32 - shift)) & 0xFFFFFFFF)
|
||||||
|
|
||||||
|
if t6 + d > 0xFFFFFFFF:
|
||||||
|
t4 += 1
|
||||||
|
|
||||||
|
t6 = (t6 + d) & 0xFFFFFFFF
|
||||||
|
t3 ^= d
|
||||||
|
t5 = (t5 + r) & 0xFFFFFFFF
|
||||||
|
|
||||||
|
if t2 > d:
|
||||||
|
t2 ^= r
|
||||||
|
else:
|
||||||
|
t2 ^= t6 ^ d
|
||||||
|
|
||||||
|
t1 = (t1 + (read_uint32_be(data, 0x0750 + (i & 0xFF)) ^ d)) & 0xFFFFFFFF
|
||||||
|
|
||||||
|
chksum0 = t6 ^ t4 ^ t3
|
||||||
|
chksum1 = t5 ^ t2 ^ t1
|
||||||
|
|
||||||
|
return chksum0, chksum1
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
@ -13,22 +39,30 @@ if __name__ == "__main__":
|
||||||
parser.add_argument('out', help='output file')
|
parser.add_argument('out', help='output file')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
outputBuffer = bytearray()
|
||||||
|
|
||||||
with open(args.out, 'wb') as w, open(args.files, 'rt') as f:
|
with open(args.out, 'wb') as w, open(args.files, 'rt') as f:
|
||||||
file_name = f.readline().strip()
|
|
||||||
total_size = 0
|
total_size = 0
|
||||||
|
|
||||||
while file_name:
|
dmadata_table = ast.literal_eval(f.read())
|
||||||
try:
|
for base_file, comp_file, _, _ in dmadata_table:
|
||||||
with open(file_name, 'rb') as current_file:
|
file_name = base_file if comp_file == '' else comp_file
|
||||||
file_data = current_file.read()
|
if file_name != '':
|
||||||
w.write(file_data)
|
try:
|
||||||
total_size += len(file_data)
|
with open(file_name, 'rb') as current_file:
|
||||||
except:
|
file_data = current_file.read()
|
||||||
print('Could not open file ' + file_name)
|
outputBuffer += file_data
|
||||||
sys.exit(1)
|
total_size += len(file_data)
|
||||||
file_name = f.readline().strip()
|
except:
|
||||||
|
print('Could not open file ' + file_name)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
while total_size < 0x2000000:
|
while total_size < 0x2000000:
|
||||||
w.write((total_size % 256).to_bytes(1,"big"))
|
outputBuffer.append(total_size % 256)
|
||||||
total_size += 1
|
total_size += 1
|
||||||
|
|
||||||
|
chksum0, chksum1 = generate_checksum(outputBuffer)
|
||||||
|
outputBuffer[0x10:0x18] = chksum0.to_bytes(4, byteorder='big') + chksum1.to_bytes(4, byteorder='big')
|
||||||
|
|
||||||
|
w.write(outputBuffer)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue