/* SPDX-License-Identifier: MIT */ /* First published under MIT by alewman in ym2612-python (validation/nuked_harness.c); the MIT permission is kept * (notices/MIT-emulator-family.txt). Built with Nuked-OPN2, LGPL-2.1-or-later, the binary is a * combined work under that licence; this repository is GPL-3.0-or-later. * Regrouped into tools/nuked on 2026-11-23 (README.md there). */ /* * Rung 6: drive Nuked-OPN2 as a closed box (docs/validation.md, restart.md rule 8). * * This file is the only code that touches the model. It includes the model's * public header and calls only the functions that header declares: * OPN2_SetChipType, OPN2_Reset, OPN2_Write, OPN2_Read, OPN2_ReadIRQPin and * OPN2_Clock. It names the header's chip type and nothing of the header's state * structure: the structure is allocated whole and never looked into. The model's * source file is compiled beside this one and was never opened. * * Commands on standard input, one per line: * t N set the chip type (the header's enum: 1 YM2612, 2 status on any * port) and reset * w P V write byte V to port P (0 to 3) * r P read port P; the value and the IRQ pin go to standard error as * "clock value irq" * c N advance N internal clocks (one is six master clocks) * * Standard output: two little-endian signed 16-bit numbers per clock, the left * and right outputs the model reports for that clock. */ #include #include #include #include "ym3438.h" int main(void) { ym3438_t *chip = calloc(1, sizeof(ym3438_t)); char line[64]; unsigned long clock = 0; Bit16s frame[2]; if (!chip) return 1; OPN2_SetChipType(0); OPN2_Reset(chip); while (fgets(line, sizeof line, stdin)) { unsigned a = 0, b = 0; char command = line[0]; sscanf(line + 1, "%u %u", &a, &b); if (command == 't') { OPN2_SetChipType(a); OPN2_Reset(chip); } else if (command == 'w') { OPN2_Write(chip, a, (Bit8u)b); } else if (command == 'r') { fprintf(stderr, "%lu %u %u\n", clock, (unsigned)OPN2_Read(chip, a), (unsigned)OPN2_ReadIRQPin(chip)); } else if (command == 'c') { for (; a; a--, clock++) { OPN2_Clock(chip, frame); fwrite(frame, sizeof frame[0], 2, stdout); } } } free(chip); return 0; }