/* EDCLK, /HSYNC, the V and H counters and the RGB pins of Nuked-MD, logged per change * (docs/worklog.md, Session 9). This file is sega32x-python's own (MIT); Nuked-MD * (nukeykt, ogamespec, andkorzh; GPL-2.0) is read and run as a die-derived referee for * the Mega Drive side of the slot, never copied here. * * Build, against megadrive-python's pinned Nuked-MD (reference/src/Nuked-MD @ 594ca2a) * and its headless driver (validation/nuked_md_headless.c, nuked_md_sdl.h @ 44ab15d), * in a scratch copy of the Nuked-MD tree whose md.c gains one line after * `FC1004_Clock(&ym, mcycles & 1, mcycles);`: * * { extern void probe_tick(void); probe_tick(); } * * then megadrive-python's validation/build_nuked_md.sh link line with this file added. * Run (half-MCLK times, as Nuked-MD's `mcycles`): * * NMD_STOP=21700000 PROBE_FILE=out.txt PROBE_FROM=19800000 PROBE_TO=21600000 \ * ./nmd vscroll-latch-planeA-h40.bin * * Records, one per change: `E t` EDCLK (the FC1004's o_edclk, the slot's pin) rising; * `H t level rs0 rs1` /HSYNC; `C t rrggbb` the RGB pins; `V t v h=` the V counter; `K t h` * the H counter. scripts/nmd_edclk_report.py reads them. */ #include #include #include #include "md.h" static FILE *pf; static uint64_t from, to; static int inited, oe = -1, oh = -1, orgb = -1, ov = -1, ohc = -1; void probe_tick(void) { if (!inited) { const char *f = getenv("PROBE_FILE"); inited = 1; if (f) pf = fopen(f, "w"); from = getenv("PROBE_FROM") ? strtoull(getenv("PROBE_FROM"), 0, 10) : 0; to = getenv("PROBE_TO") ? strtoull(getenv("PROBE_TO"), 0, 10) : 0; } if (!pf || mcycles < from || mcycles >= to) return; int e = ym.o_edclk == state_z ? 2 : (ym.o_edclk != 0); int h = ym.vdp.o_hsync == state_z ? 1 : 0; int rgb = (ym.vdp.rgb_out[0] << 16) | (ym.vdp.rgb_out[1] << 8) | ym.vdp.rgb_out[2]; if (e != oe && e == 1) fprintf(pf, "E %llu\n", (unsigned long long)mcycles); if (h != oh) fprintf(pf, "H %llu %d rs0=%d rs1=%d\n", (unsigned long long)mcycles, h, ym.vdp.reg_rs0, ym.vdp.reg_rs1); if (rgb != orgb) fprintf(pf, "C %llu %06x\n", (unsigned long long)mcycles, rgb); if (ym.vdp.l105[1] != ov) fprintf(pf, "V %llu %d h=%d\n", (unsigned long long)mcycles, ym.vdp.l105[1], ym.vdp.l106[1]); if (ym.vdp.l106[1] != ohc) fprintf(pf, "K %llu %d\n", (unsigned long long)mcycles, ym.vdp.l106[1]); ov = ym.vdp.l105[1]; ohc = ym.vdp.l106[1]; oe = e; oh = h; orgb = rgb; }