// Original-screens smoke tests against the user's ROM (TBG_ROM=path). Exit code = failure count. // Runs the ROM's scene flow headless: boot -> title -> 1P -> character select -> Battle World -> battle stop, // a won battle -> next opponent, and a frame of the title that must be drawn (not blank); the 2P select: the // original's hidden boss pick (hold L / R), the book-select takeover and its way back, the empty-book capture. #include #include #include #include #include #include #include "screens/flow.hpp" namespace { int g_failures = 0; #define CHECK(cond) \ do { \ if (!(cond)) { \ std::printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \ ++g_failures; \ } \ } while (0) using tbg::screens::SceneRunner; // Press A for 1 frame every 120 frames until the runner stops (or `limit` frames pass). SceneRunner::Stop run_to_stop(SceneRunner& r, int& frame, int limit) { for (int n = 0; n < limit; ++n, ++frame) { const auto st = r.step(frame % 120 == 0 ? tbg::screens::kPadA : 0, 0); if (st != SceneRunner::Stop::None) return st; } return SceneRunner::Stop::None; } // Boot to the 2P character select's input loop with scripted presses (title menu: Down, Start). void to_vs_select(SceneRunner& r, int& frame) { for (; frame <= 1500; ++frame) { std::uint16_t pad = 0; if (frame >= 300 && frame < 304) pad = tbg::screens::kPadStart; if (frame >= 1050 && frame < 1054) pad = tbg::screens::kPadDown; if (frame >= 1100 && frame < 1104) pad = tbg::screens::kPadStart; r.step(pad, 0); } } void test_vs_select(const std::vector& rom) { namespace s = tbg::screens; { // 83:8266: holding L (P1) / R (P2) while the select ends gives Dragon / Queen. SceneRunner r(rom); int frame = 1; to_vs_select(r, frame); SceneRunner::Stop st = SceneRunner::Stop::None; for (int n = 0; n < 2000 && st == SceneRunner::Stop::None; ++n, ++frame) { const std::uint16_t a = n >= 200 && n < 204 ? s::kPadA : 0; st = r.step(static_cast(a | s::kPadL), static_cast(a | s::kPadR)); if (n > 100 && n < 200) CHECK(r.in_vs_select()); } CHECK(st == SceneRunner::Stop::Battle); CHECK(r.mode() == 0); CHECK(r.player_character() == 8); CHECK(r.opponent() == 9); } { // Takeover: the runner parks in the open book; finish_vs_select() leaves to the title. SceneRunner r(rom); r.vs_takeover = true; int frame = 1; to_vs_select(r, frame); int n = 0; while (r.stopped() == SceneRunner::Stop::None && n++ < 1000) r.step(0, 0); CHECK(r.stopped() == SceneRunner::Stop::VsSelect); auto book = std::make_unique(), live = std::make_unique(); r.vs_select_backdrop(*book); r.render(*live); int differ = 0; for (std::size_t i = 0; i < book->size(); ++i) differ += (*book)[i] != (*live)[i]; CHECK(differ > 2000); // names, portraits, power lists gone CHECK(r.step(0, 0) == SceneRunner::Stop::VsSelect); // parked r.finish_vs_select(); bool title = false; r.snes().cpu.hooks[0x83ECE5] = [&title](tbg::audio::Cpu65816& c) { title = true; c.exec(); }; for (n = 0; n < 1500 && !title; ++n) CHECK(r.step(0, 0) == SceneRunner::Stop::None); CHECK(title); } { const auto book = tbg::screens::capture_vs_backdrop(rom); CHECK(book != nullptr); } } } // namespace int main() { const char* path = std::getenv("TBG_ROM"); if (!path) { std::printf("screens tests skipped (set TBG_ROM)\n"); return 0; } std::ifstream f(path, std::ios::binary); const std::vector rom{std::istreambuf_iterator(f), {}}; if (rom.size() < 0x80000) { std::printf("FAIL: can't read %s\n", path); return 1; } SceneRunner r(rom); int songs = 0; r.on_sound = [&songs](int cmd, int) { songs += cmd == 0x13; }; int frame = 1; // The title (mode 7 book) is on screen by frame 1000 without input. for (; frame <= 1000; ++frame) CHECK(r.step(0, 0) == SceneRunner::Stop::None); auto img = std::make_unique(); r.render(*img); int lit = 0; for (std::uint32_t px : *img) lit += (px & 0xFFFFFF) != 0; CHECK(lit > 256 * 224 / 2); CHECK(songs >= 2); // boot + title songs // 1P (first menu item) -> select Halloween -> map -> the battle vs Mirurun. CHECK(run_to_stop(r, frame, 6000) == SceneRunner::Stop::Battle); CHECK(r.mode() == 2); CHECK(r.player_character() == 0); CHECK(r.opponent() == 1); r.finish_battle(2, 0); // Win -> results -> Battle World -> next opponent (Shaman). CHECK(run_to_stop(r, frame, 6000) == SceneRunner::Stop::Battle); CHECK(r.opponent() == 2); CHECK((r.wram(0xE2) & 3) == 3); // beaten mask: P1's own bit + Mirurun if (r.stopped() == SceneRunner::Stop::Halted) std::printf("halted: %s\n", r.error().c_str()); test_vs_select(rom); if (g_failures == 0) std::printf("all screens tests passed\n"); return g_failures; }