From d188a594958b2397089030af4cb7e6a412021992 Mon Sep 17 00:00:00 2001 From: acamilo Date: Thu, 24 Sep 2026 02:43:19 +0000 Subject: [PATCH] tests: row 62's ROM proofs, HEAL in the Mt. Moon centre and a ball bought in Pewter From the Mt. Moon centre with the party at 10/70 (FLY_ROW62_CENTER_CHECKPOINT): HEAL is dealt, heals, and wLastBlackoutMap becomes Route 4. From the rung-11 Pewter checkpoint with the errands paid, 1,606 and no ball (FLY_ROW62_MART_CHECKPOINT): GO SHOP is on the pad, walks into the mart, and BUY BALL reports done only with the ball in the bag and 200 paid. Both fail on main 862e343 (HEAL never dealt in 3,000 frames; GO SHOP not on Pewter's pad). --- .../crates/flysim/tests/rom_macros_mode.rs | 210 +++++++++++++++++- 1 file changed, 203 insertions(+), 7 deletions(-) diff --git a/services/flysim/crates/flysim/tests/rom_macros_mode.rs b/services/flysim/crates/flysim/tests/rom_macros_mode.rs index 38ba60e..67c9e0c 100644 --- a/services/flysim/crates/flysim/tests/rom_macros_mode.rs +++ b/services/flysim/crates/flysim/tests/rom_macros_mode.rs @@ -702,13 +702,8 @@ impl Run { flybrain_gb::pokemon_red::state::money(&mut self.gb) } - /// How many of `item` the bag holds, summed over its stacks. - /// - /// Kept unused for now: the purchase the section-13 test would have counted with it is - /// unit-proven rather than ROM-proven (see `go_shop_enters_the_mart_once_and_walks_to_its_counter` - /// and rows 35 and 36 of `infra/docs/macros-traps.md`), and deleting the reader would mean - /// writing it again with the fix. - #[allow(dead_code)] + /// How many of `item` the bag holds, summed over its stacks: what row 62's purchase is + /// measured by. fn bag_count(&mut self, item: u8) -> u32 { flybrain_gb::pokemon_red::state::bag(&mut self.gb) .iter() @@ -3806,3 +3801,204 @@ fn a_trainers_challenge_does_not_wall_the_road_to_the_forests_north_gate() { assert!(route_2_north.is_some(), "nor Route 2 through it: {arrivals:?}"); assert!(pewter.is_some(), "nor Pewter City: {arrivals:?}"); } + +/// `wLastBlackoutMap`, `$d719` at the pinned commit (`ram/wram.asm`, the byte after +/// `wBoulderSpriteIndex`): the map a whiteout returns the player to, written by the nurse's YES +/// (`SetLastBlackoutMap`) and by nothing else a walk can reach. Read by this test only; the macros +/// never read it. +const W_LAST_BLACKOUT_MAP: u16 = 0xd719; +const POKE_BALL: u8 = 0x04; + +/// The live checkpoint from inside the Mt. Moon Pokémon Center with a hurt party, or `None`. +fn row62_center_checkpoint() -> Option { + std::env::var_os("FLY_ROW62_CENTER_CHECKPOINT").map(|path| { + flysim::store::load(std::path::Path::new(&path)) + .expect("the checkpoint should be a FLYSIM01 envelope") + }) +} + +/// The rung-11 Pewter checkpoint, errands paid, money and no ball, or `None`. +fn row62_mart_checkpoint() -> Option { + std::env::var_os("FLY_ROW62_MART_CHECKPOINT").map(|path| { + flysim::store::load(std::path::Path::new(&path)) + .expect("the checkpoint should be a FLYSIM01 envelope") + }) +} + +/// Row 62: in Route 4's Pokémon Center with a hurt party, `HEAL` is on the pad and heals, and the +/// cartridge's whiteout map becomes Route 4. +/// +/// **What was live** (2026-09-24, v0.6.2, rung 12 MT. MOON, 3.5 hours on the rung): in eleven +/// hours of the fresh run no `HEAL`, no `GO HEAL` after the first visit, no nurse's YES, so +/// `wLastBlackoutMap` stayed Pallet Town and every whiteout in Mt. Moon walked the fly back from +/// Pallet. This centre was on no table: `HEAL` is dealt by the map id and the map id was not +/// there. The checkpoint is row 59's, taken with the fly in this centre at 10 of 70 HP. +/// +/// ```sh +/// FLY_ROM=/path/to/pokemon-red.gb \ +/// FLY_ROW62_CENTER_CHECKPOINT=.local/checkpoints/release-rank12-mtmoon-center.checkpoint \ +/// cargo test --release -p flysim --test rom_macros_mode -- --nocapture row62 +/// ``` +#[test] +fn row62_heal_is_dealt_in_the_mt_moon_center_and_moves_the_whiteout_map() { + let rom = skip_without_rom!(); + let Some(checkpoint) = row62_center_checkpoint() else { + eprintln!("skipped: no FLY_ROW62_CENTER_CHECKPOINT"); + return; + }; + let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint); + assert_eq!(run.map(), MT_MOON_POKECENTER, "the checkpoint is Route 4's centre"); + assert!(!run.party_rested(), "and the party is hurt"); + assert_eq!(run.gb.read_wram(W_LAST_BLACKOUT_MAP), 0x00, "whiteouts go to Pallet Town"); + + // `HEAL` on the pad inside the centre. On the base it is never there: the map id is on no + // table, so the rotation walks the fly back out. + run.force_hot = Some("macro_heal"); + let mut heal_dealt = false; + run.drive_until("HEAL on the centre's pad", 3_000, |run| { + heal_dealt |= run.map() == MT_MOON_POKECENTER + && run.layer.bound_channels().iter().any(|channel| channel == "macro_heal"); + heal_dealt + }); + run.drive_until("the party reads back full", 3_000, |run| run.party_rested()); + assert_eq!(run.map(), MT_MOON_POKECENTER, "healed where it stood"); + assert_eq!( + u32::from(run.gb.read_wram(W_LAST_BLACKOUT_MAP)), + ROUTE_4, + "the nurse's YES wrote Route 4 as the whiteout map" + ); + // Full now, so the button leaves the pad rather than being pressed again (12.12). + for _ in 0..120 { + run.frame(); + } + assert!( + !run.layer.bound_channels().iter().any(|channel| channel == "macro_heal"), + "a rested party is no reason to rest: {:?}", + run.layer.bound_channels() + ); +} + +/// Row 62: from Pewter City with both errands paid, 1,606 in the wallet and no ball, `GO SHOP` is +/// on the pad, and the counter it leads to sells the fly a ball. +/// +/// **What was live**: `GO SHOP` twice in eleven hours, both on the parcel; `BUY BALL` never; +/// `THROW BALL` never. Three things stood between the fly and a ball, all measured from this +/// checkpoint: the errand was paid by the first visit and never offered again; a clerk this +/// session had talked to was out of `TALK`'s reach; and `BUY BALL` pressed its last A while the +/// price line was still printing, so it reported `done` with nothing bought (55 of 55 on the +/// cartridge, the wallet unchanged). The drive here leans on one button at a time, in order; it +/// says nothing about which the fly would press. +/// +/// ```sh +/// FLY_ROM=/path/to/pokemon-red.gb \ +/// FLY_ROW62_MART_CHECKPOINT=.local/checkpoints/survey-rank11-pewter.checkpoint \ +/// cargo test --release -p flysim --test rom_macros_mode -- --nocapture row62 +/// ``` +#[test] +fn row62_go_shop_comes_back_with_no_ball_and_buy_ball_rings_up_a_ball() { + use flybrain_gb::pokemon_red::macros::PokemonPalette; + use flybrain_gb::{MacroPalette, Outcome, Started}; + let rom = skip_without_rom!(); + let Some(checkpoint) = row62_mart_checkpoint() else { + eprintln!("skipped: no FLY_ROW62_MART_CHECKPOINT"); + return; + }; + let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint); + assert_eq!(run.bag_count(POKE_BALL), 0, "no ball at the checkpoint"); + let money = run.money(); + assert!(money >= 200, "and the money for one: {money}"); + + // The palette driven directly, one choice per hold: the chain's buttons whenever they are + // dealt, in this order, and otherwise the first button on the pad. A survey's driver, never + // the fly's -- the claim is about what the pad deals and what the buttons do. + let order = ["BUY BALL", "CONFIRM", "TALK", "GO SHOP"]; + let hold_frames = 48u32; + let mut palette = PokemonPalette::new(SEED); + let mut running: Option<&'static str> = None; + let mut since_decision = hold_frames; + let mut ms = run.ms; + let mut go_shop_on_the_first_pad = None; + let mut entered_the_mart = None; + let mut buy_done_without_a_ball = 0u32; + let mut buy_done_with_a_ball = 0u32; + for frame in 0..30_000u32 { + palette.clock(ms); + let observed = { + let ledger = AdapterLedger(&run.adapter); + palette.observe(&mut run.gb, &ledger) + }; + if go_shop_on_the_first_pad.is_none() && !observed.bindings.is_empty() { + go_shop_on_the_first_pad = + Some(observed.bindings.iter().any(|binding| binding.name == "GO SHOP")); + } + let mut mask = 0u8; + { + let ledger = AdapterLedger(&run.adapter); + if running.is_some() { + match palette.step(&mut run.gb, &ledger) { + Some(held) => mask = held, + None => running = None, + } + } else if since_decision >= hold_frames && !observed.bindings.is_empty() { + since_decision = 0; + let binding = order + .iter() + .find_map(|want| observed.bindings.iter().find(|binding| binding.name == *want)) + .unwrap_or(&observed.bindings[0]); + if let Started::Running(name) = palette.start(binding.slot, &mut run.gb, &ledger) { + running = Some(name); + match palette.step(&mut run.gb, &ledger) { + Some(held) => mask = held, + None => running = None, + } + } + } + } + if let Some((name, outcome)) = palette.take_finished() + && name == "BUY BALL" + && outcome == Outcome::Done + { + if run.bag_count(POKE_BALL) == 0 { + buy_done_without_a_ball += 1; + } else { + buy_done_with_a_ball += 1; + } + } + since_decision += 1; + run.gb.set_buttons(mask); + run.gb.run_frame().expect("a frame should complete"); + ms += MS_PER_FRAME; + run.adapter.sample(&mut run.gb, ms); + if entered_the_mart.is_none() && run.map() == PEWTER_MART { + entered_the_mart = Some(frame); + } + if run.bag_count(POKE_BALL) > 0 && running.is_none() { + break; + } + } + eprintln!( + "GO SHOP on the first pad {go_shop_on_the_first_pad:?}, into the mart at \ + {entered_the_mart:?}, BUY BALL done with a ball {buy_done_with_a_ball} / without \ + {buy_done_without_a_ball}, balls {}, money {} -> {}", + run.bag_count(POKE_BALL), + money, + run.money() + ); + // The errand is paid (the adapter's map ledger has the mart), so on the base `GO SHOP` is on + // no pad in Pewter at all. + assert_eq!(go_shop_on_the_first_pad, Some(true), "`GO SHOP` with no ball and 1,606"); + assert!(entered_the_mart.is_some(), "`GO SHOP` walked into the Pewter mart"); + assert_eq!(buy_done_without_a_ball, 0, "a `BUY BALL` reported done with nothing bought"); + assert_eq!(run.bag_count(POKE_BALL), 1, "one ball, one press"); + assert_eq!(run.money(), money - 200, "and the wallet paid for it"); + // With a ball in the bag the mart has nothing to do for the fly. + let still = { + let ledger = AdapterLedger(&run.adapter); + palette.observe(&mut run.gb, &ledger) + }; + assert!( + !still.bindings.iter().any(|binding| binding.name == "GO SHOP"), + "a ball in the bag: {:?}", + still.bindings.iter().map(|binding| binding.name).collect::>() + ); +}