From 77f79d068a1f62c5d0cbbe1bf9781b19d554a0aa Mon Sep 17 00:00:00 2001 From: rozlette Date: Tue, 12 Nov 2019 22:08:56 -0600 Subject: [PATCH] Makerom: compress rom only if dmadata contains compressed files, pad to smallest power of 2 --- tools/makerom.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/makerom.py b/tools/makerom.py index 130566d861..1c3703c2f6 100644 --- a/tools/makerom.py +++ b/tools/makerom.py @@ -46,7 +46,22 @@ if __name__ == "__main__": dmadata_table = ast.literal_eval(f.read()) for base_file, comp_file, _, _ in dmadata_table: - file_name = base_file if comp_file == '' else comp_file + if base_file.endswith('dmadata'): + dma_file_name = base_file + else: + print('Could not find dmadata') + sys.exit(1) + + has_compressed_files = False + with open(dma_file_name, 'rb') as dma_file: + dma_data = dma_file.read() + for i in range(0xC, len(dma_data), 0x10) + if read_uint32_be(dma_data, i) != 0: + has_compressed_files = True + break + + for base_file, comp_file, _, _ in dmadata_table: + file_name = base_file if not has_compressed_files or comp_file == '' else comp_file if file_name != '': try: with open(file_name, 'rb') as current_file: @@ -57,7 +72,9 @@ if __name__ == "__main__": print('Could not open file ' + file_name) sys.exit(1) - while total_size < 0x2000000: + required_rom_size = 1 << (len(outputBuffer) - 1).bit_length() + + while total_size < required_rom_size: outputBuffer.append(total_size % 256) total_size += 1