#!/usr/bin/env python3 """Generates the embedded game images of OpenBMH, so that the game runs from the asset files alone (no BMH.exe, no FLTD.EXE): src/formats/diamond_constants.inc (German, Diamond 3.7) and src/formats/fltd_constants.inc (English Football Limited). Both hold every non-zero byte of the data the engine reads - tables, rates, positions, prices and the game texts - as runs of bytes; zero runs are not stored. German (a Diamond 3.7 BMH.exe, read here and never copied into the repository): python generate.py german --exe BMH.exe --trace trace1.txt [--trace trace2.txt ...] --out ../../src/formats/diamond_constants.inc The file backed part of the data object, plus the few bytes of the code object that the program reads as numbers or tables (instruction immediates such as the calendar setup). The code bytes come from the read traces of OPENBMH_LE_TRACE (formats/le.hpp: run the data dependent tests and scenarios with the variable set to a file; the lines are " " in hex, flag 1 = number read, 2 = string read, 4 = start of a bulk read) and from a window at every layout constant that names a place in the code objects. English (the German layout image of FLTD.EXE, the cached "BMH.exe" of an English game that translate_fltd() made): python generate.py english --image BMH.exe --out ../../src/formats/fltd_constants.inc Every non-zero byte of the image. """ import argparse import re import struct from pathlib import Path DATA_LO, DATA_PAGES = 0xA0000, 12 # the initialised pages of the data object (file backed) DATA_HI = DATA_LO + DATA_PAGES * 4096 CODE = (0x10000, 0x10000 + 438272) PATCH = (0x80000, 0x81000) def load_le(path): """The loaded image of a DOS/4GW LE executable (objects at their link addresses, internal fixups applied).""" raw = Path(path).read_bytes() u16 = lambda o: struct.unpack_from(" len(data): continue if ftype == 0x07: put(pos, "