#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-or-later """Author an empty 90 MiB OS-9 RBF filesystem header; no third-party bytes. The remaining partition bytes must be zero. BASIC volumes begin at LSN 0x5a000. Layout follows https://sourceforge.net/p/nitros9/wiki/Random_Block_File_Manager/ Run from any directory; --check verifies the committed deterministic template. """ from pathlib import Path import sys def header(): b = bytearray(32 * 256) def put(offset, value, size=1): b[offset:offset+size] = value.to_bytes(size, 'big') put(0, 0x5a000, 3); put(3, 64); put(4, 5760, 2); put(6, 8, 2) put(8, 24, 3); put(13, 0xff); put(14, 0x5643, 2); put(16, 3); put(17, 64, 2) date = bytes([126, 11, 2, 0, 0]) b[26:31] = date name = bytearray(b'VCC Shared Data'); name[-1] |= 0x80; b[31:31+len(name)] = name # RBF path options: 2880 cylinders, two sides, 64 sectors/track. put(63, 1); put(66, 0x80); put(67, 1); put(68, 2880, 2); put(70, 2) put(71, 1); put(72, 64, 2); put(74, 64, 2); put(76, 1); put(77, 8) b[256] = 0xf0 # Four allocated clusters: LSN 0..31. # Mark padding beyond the bitmap's declared length as unavailable. b[256+5760:24*256] = bytes([255]) * (24*256-256-5760) fd = 24*256 put(fd, 0xbf); b[fd+3:fd+8] = date; put(fd+8, 2); put(fd+9, 64, 4) b[fd+13:fd+16] = date[:3]; put(fd+16, 25, 3); put(fd+19, 7, 2) for offset, name in [(25*256,b'..'), (25*256+32,b'.')]: n=bytearray(name); n[-1]|=128; b[offset:offset+len(n)]=n; put(offset+29,24,3) return bytes(b) if __name__ == '__main__': path = Path(__file__).resolve().parents[1]/'Resources/StarterMedia/Blank OS9 Header.bin' if '--check' in sys.argv: assert path.read_bytes() == header(), 'OS-9 header differs from its generator' else: path.write_bytes(header())