diff --git a/tools/maple_build_image.py b/tools/maple_build_image.py new file mode 100644 index 0000000..481bb78 --- /dev/null +++ b/tools/maple_build_image.py @@ -0,0 +1,151 @@ +from os import path +import struct +import sys +from itertools import chain +from dataclasses import dataclass +from binascii import unhexlify + +storage_size = 128 * 1024 +buf = bytearray(storage_size) + +storage_blocks_count = storage_size // 512 +system_block = 0xff +fat_block = 0xfe +fat_blocks = 1 +file_information_block = 0xfd +file_information_blocks = 0xd +block_size = 512 + +def round_up(n): + rem = n % block_size + if rem != 0: + rem = block_size - rem + return n + rem + +def build_chain(length): + total_blocks = length // block_size + print("total blocks", length, total_blocks) + unused_blocks = storage_blocks_count - total_blocks + #print(total_blocks, unused_blocks) + for i in range(total_blocks - 1): + yield i + 1 + yield 0xfffa + + for i in range(unused_blocks): + yield 0xfffc + +def write_chain(start_entry, chain): + offset = fat_block * block_size + start_entry * 2 + for entry in chain: + assert offset < (fat_block + fat_blocks) * block_size + packed = struct.pack(" 0: + file_name += b'\x00' * append + + info = FileInformation( + status = 0xcc, + copy = 0x0, + start_fat = 0x0, + file_name = file_name, + date = 0, + block_size = image_size // block_size, + header = 1, + ) + + write_file_information_chain() + write_file_information(info) + + offset = fat_block * 512 + (254 * 2) + struct.pack_into("