// Headless PPU Player: Breaknes's own PPUPlayer board (BreaksCore CoreApi), no UI. // Replays a PPU regdump into the real PPUPlayerBoard and writes the RAW frames asked // for as raw little-endian uint16 (V 0-239 x H 0-340), for reproducing issue #196. // // ppuplayer_headless DUMP ROM.nes OUTDIR LASTFRAME [frame ...] #include "pch.h" #include "CoreApi.h" #include #include #include #include static std::vector read_file(const char *path) { std::ifstream f(path, std::ios::binary); return std::vector((std::istreambuf_iterator(f)), std::istreambuf_iterator()); } int main(int argc, char **argv) { if (argc < 5) { fprintf(stderr, "usage: %s DUMP ROM OUTDIR LASTFRAME [frame ...]\n", argv[0]); return 2; } auto dump = read_file(argv[1]); auto rom = read_file(argv[2]); std::string out = argv[3]; int last = atoi(argv[4]); std::set wanted; for (int i = 5; i < argc; i++) wanted.insert(atoi(argv[i])); SetNescartdbDir((char *)"Nescartdb"); CreateBoard((char *)"PPUPlayer", (char *)"RP2A03G", (char *)"RP2C02G", (char *)"Fami"); if (InsertCartridge(rom.data(), rom.size()) != 0) { fprintf(stderr, "InsertCartridge failed\n"); return 1; } if (!getenv("NO_RESET")) Reset(); // the PPU Player's "Reset PPU" setting SetRAWColorMode(true); LoadRegDump(dump.data(), dump.size()); std::vector frame(240 * 341); int field = 0; size_t last_v = 0; while (field <= last) { Step(); size_t v = GetVCounter(), h = GetHCounter(); if (v < last_v) { if (wanted.count(field)) { std::string name = out + "/player-" + std::to_string(field) + ".raw"; FILE *f = fopen(name.c_str(), "wb"); fwrite(frame.data(), 2, frame.size(), f); fclose(f); fprintf(stderr, "field %d written\n", field); } field++; } last_v = v; if (!InResetState() && v < 240 && h < 341) { PPUSim::VideoOutSignal sample; SampleVideoSignal(&sample); frame[v * 341 + h] = sample.RAW.raw; } } return 0; }