/* SPDX-License-Identifier: MIT */ /* First published under MIT by alewman in sn76489-python (validation/nuked_harness.c); the MIT permission is kept * (notices/MIT-emulator-family.txt). Built with Nuked-PSG, GPL-2.0-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). */ /* * Closed-box harness for Nuked-PSG (docs/restart.md rule 8, docs/validation.md * rung 5). * * Nuked-PSG is GPL-2.0-or-later. This file is the only code in the repository * that touches it, and it was written from the model's public header, ympsg.h, * alone: the declarations of YMPSG_Init, YMPSG_Write, YMPSG_Clock, * YMPSG_GetOutput, YMPSG_Test and YMPSG_SetMute. The header also declares the * model's state structure; this harness allocates one and never looks inside it. * The model's ympsg.c is compiled and linked, and is not opened, searched or * quoted. Nothing built from it is committed or shipped (validation/build/ is * git-ignored). * * It reads commands, one per line, from standard input: * * w BYTE YMPSG_Write(chip, BYTE) * t VALUE YMPSG_Test(chip, VALUE) * m MASK YMPSG_SetMute(chip, MASK) * c COUNT call YMPSG_Clock COUNT times; after each call append * YMPSG_GetOutput as a 32-bit float to standard output * * Numbers are decimal or 0x-prefixed. What one YMPSG_Clock call is in input * clocks, and what the output's scale is, the header does not say: * validation/closed_box.py measures both from the output. */ #include #include #include #include "ympsg.h" int main(void) { static ympsg_t chip; char command; char number[64]; static float block[4096]; size_t held = 0; YMPSG_Init(&chip); while (scanf(" %c %63s", &command, number) == 2) { unsigned long value = strtoul(number, NULL, 0); switch (command) { case 'w': YMPSG_Write(&chip, (uint8_t)value); break; case 't': YMPSG_Test(&chip, (uint16_t)value); break; case 'm': YMPSG_SetMute(&chip, (uint8_t)value); break; case 'c': while (value--) { YMPSG_Clock(&chip); block[held++] = YMPSG_GetOutput(&chip); if (held == sizeof block / sizeof block[0]) { fwrite(block, sizeof block[0], held, stdout); held = 0; } } break; default: fprintf(stderr, "unknown command %c\n", command); return 2; } } fwrite(block, sizeof block[0], held, stdout); return 0; }