#!/usr/bin/env python3 """Author a small CONTENT-CLEAN synthetic PCSX2 .gs dump for Ch340 byte-exact parser tests. No copyrighted content — every byte is hand-authored here. Exercises the container header + each packet type + each GIF mode the parser must handle: PACKED A+D, PACKED PRE-prim, PACKED RGBAQ/XYZ2, an IMAGE upload, and a VSync frame boundary. Writes captures/gs/synthetic/mini.gs (whitelisted). """ import struct, os OUT = os.path.join(os.path.dirname(__file__), "..", "captures", "gs", "synthetic", "mini.gs") def giftag(nloop, eop, flg, nreg, regs, pre=0, prim=0): lo = (nloop & 0x7FFF) | ((eop & 1) << 15) | ((pre & 1) << 46) | ((prim & 0x7FF) << 47) \ | ((flg & 3) << 58) | ((nreg & 0xF) << 60) return (lo | ((regs & ((1 << 64) - 1)) << 64)).to_bytes(16, "little") def ad(addr, data): # PACKED A+D qword: data[63:0], addr[72:64] return ((addr & 0xFF) << 64 | (data & ((1 << 64) - 1))).to_bytes(16, "little") def packed_rgbaq(r, g, b, a): # R[7:0] G[39:32] B[71:64] A[103:96] return (r | (g << 32) | (b << 64) | (a << 96)).to_bytes(16, "little") def packed_xyz2(x, y, z, adc=0): # X[15:0] Y[47:32] Z[95:64] ADC[111] return ((x & 0xFFFF) | ((y & 0xFFFF) << 32) | ((z & 0xFFFFFFFF) << 64) | (adc << 111)).to_bytes(16, "little") def transfer(path, gifdata): return bytes([0]) + bytes([path]) + struct.pack("