#!/usr/bin/env python3 """Convert SingleStepTests JSON into a binary fixture. Format 2. Avoids a JSON parser in C. Run once; the C runner walks the output with fread(). One format covers both suites. The 65C02 has no bank registers and no emulation bit, so those fields carry the values a 65C816 in emulation mode would hold, and the cpu field says which core to reset into. Layout, all little-endian: magic 'X16P', u32 version = 2, u32 case count per case: u8 opcode u8 cpu 0 = 65C02, 1 = 65C816 initial state, then u16 ram count and [u32 addr, u8 value] each final state, then u16 ram count and [u32 addr, u8 value] each u16 cycle count, then [u32 addr, u8 value, u8 flags] each state: u16 pc, u16 s, u16 a, u16 x, u16 y, u8 p, u8 e, u8 dbr, u8 pbr, u16 d Cycle flags, from the 65C816 suite's eight-character signal string: 0x01 VDA 0x02 VPA 0x04 VPB 0x08 write 0x10 E 0x20 M 0x40 X 0x80 MLB The 65C02 suite reports only read or write, so its cycles carry VDA and VPA set and the rest from the read/write word alone. """ import struct MAGIC = b"X16P" VERSION = 2 CPU_65C02 = 0 CPU_65816 = 1 F_VDA, F_VPA, F_VPB, F_WRITE = 0x01, 0x02, 0x04, 0x08 F_E, F_M, F_X, F_MLB = 0x10, 0x20, 0x40, 0x80 def pack_state(st, emulation_defaults): e = st.get("e", 1 if emulation_defaults else 0) return struct.pack( "