Compare commits

...

9 commits

Author SHA1 Message Date
acamilo
80104f0d98 docs: v0.7.4 status
Some checks are pending
ci / node 22 (test + typecheck) (push) Waiting to run
ci / rust stable (cargo test --workspace --release) (push) Waiting to run
ci / infra/tests/lint.sh (push) Waiting to run
ci / playwright apps/stage (allowed to fail) (push) Waiting to run
2026-10-01 14:47:23 +00:00
acamilo
15ab7ee002 Merge fix/loop-row71 (reviewed: APPROVE both): the bag and mart cursors count the list's scroll offset 2026-10-01 14:47:23 +00:00
acamilo
ecff9bcff4 docs: macros-traps row 71 trap hunt before/after 2026-10-01 13:49:20 +00:00
acamilo
2ca0853c9a docs: macros-traps row 71 2026-10-01 13:18:49 +00:00
acamilo
a6632b4acf macros: the mart's list cursor is the entry too; the catch test pins its first-window ball (row 71)
state::shop reports the buy and sell lists' cursor as row plus
wListScrollOffset, only while the list is on screen. MART_CURSOR_ROWS
stays. The catch ROM test now asserts its ball sits in the bag window's
first rows, so it covers the unscrolled throw beside row 71's scrolled
one.
2026-10-01 13:10:05 +00:00
acamilo
2dcce9452a docs: row 71, the battle bag's scroll offset (macros.md 12.34, macros-wram.md 16) 2026-10-01 12:57:03 +00:00
acamilo
85d2da363a macros: the battle bag's cursor is the entry, not the window's row (row 71)
The battle bag is a DisplayListMenuID list: the arrow walks rows 0..2 and
the window scrolls under it. state::battle reported wCurrentMenuItem alone
as the bag cursor, so THROW BALL and ITEM could never reach a bag entry
past the third. Live on rung 15 a wild Oddish sat at low HP with the
Poke Ball fifth in the bag; row 69 left THROW BALL alone on the pad and
every start blocked.

The cursor is now wCurrentMenuItem + wListScrollOffset, the sum the
cartridge makes on A. wListScrollOffset ($CC36) is pinned from the operand
of DisplayListMenuIDLoop's read and checked by a ROM test. The ROM test
from the live trap checkpoint (FLY_ROW71_CHECKPOINT) blocks on main and
throws and catches on this branch.
2026-10-01 12:57:03 +00:00
acamilo
390d118460 infra: fly-shadow-run check reads fly.env as KEY=VALUE lines, never sources it
fly.env is systemd EnvironmentFile syntax; GAME_TITLE=Pokemon Red is valid
there and a shell error when sourced. The v0.7.3 cutover's check died on it
(exit 127) after a passing verdict. Parse it as fly-runtime does; lint
refuses any infra/bin script that sources fly.env.
2026-10-01 09:54:11 +00:00
acamilo
16cb3b754b infra: the box set-up's ingest probe tolerates the usage exit
fly-shadow ingest without --root exits 2; piped into grep under pipefail the
probe failed even when the message matched, so the set-up refused every
release. Found on its first run as root on a real box.
2026-10-01 05:56:11 +00:00
12 changed files with 310 additions and 16 deletions

View file

@ -1058,3 +1058,22 @@ one `$77`) from (10, 3). The run's length is the capacity (`PLAYER_NAME_LENGTH -
`NAME_LENGTH - 1`). The menu bytes outlive the screen, so both halves are needed, as for
`yes_no_prompt`. The player's and rival's names at the start of a game are this screen before
`wStatusFlags6`'s game-timer bit is set, and `scene::detect` answers `Title` for them first.
## 16. The list's scroll offset (2026-10-01, `docs/design/macros.md` 12.34)
Row 71. One byte the reviewed list does not carry. It is pinned the way `hJoyLast` is, and
`row71_the_list_scroll_offset_is_where_the_cartridge_reads_it` (FLY_ROM) reads it back from the
code that uses it. Section 7's "cannot be pinned" applied to the symbol table. The pin comes from
the cartridge instead.
| name | where | what reads it |
| --- | --- | --- |
| `wListScrollOffset` | `$CC36` | entries scrolled off the top of a `DisplayListMenuID` window; the operand of `DisplayListMenuIDLoop.buttonAPressed`'s `ld a, [wCurrentMenuItem] / ld c, a / ld a, [wListScrollOffset] / add c / ld c, a`, found once in the cartridge |
**`BattleMenu::Bag`'s `cursor`** is now `wCurrentMenuItem + wListScrollOffset`, the bag entry
under the arrow, which is the sum the cartridge makes on A. In the live trap the arrow was on row 1
with an offset of 3, so it was on entry 4, the Poké Ball. `state::shop`'s buy and sell lists
report their cursor (and its `max`) as the entry the same way. The offset is added only while a
list is on screen, because the byte outlives every list. Purchases still use only the first three
rows (`MART_CURSOR_ROWS`, section 7).

View file

@ -2114,6 +2114,47 @@ Tests: `the_shift_offers_party_list_is_the_flys_turn_and_its_way_out_is_back`, t
uses `FLY_ROW70_FORCED_CHECKPOINT`, the rung-12 archive carried forward by the stub to the same
Lass with a Zubat caught.
### 12.34 The battle bag's cursor is the entry, not the window's row (2026-10-01, row 71)
Live on v0.7.3, rung 15, Route 25 (map 36): a wild Oddish L13 at 8 of 36, Wartortle L35 out, the
bag open. Row 69's rule saw the HP low enough for the ball and left `THROW BALL` alone on the pad.
Every start was `blocked`, 131 of 131 in ten minutes and about two hours in all. A flysim restart
restored the same battle with the same bag open, so the trap came straight back.
- **Not a trainer.** `wIsInBattle` was 1 (wild), so the cartridge would have taken the ball.
There were two Poké Balls in the bag, the party had room, the Oddish was a new species, and
Wartortle's moves had PP left. `THROW BALL` was a correct button that its script could not
carry out.
- **The misread.** The battle bag is a `DisplayListMenuID` list. Its window shows three entries,
the arrow moves over rows `0, 1, 2` (`wCurrentMenuItem`), and the list scrolls under the arrow.
The entry under the arrow is the row plus `wListScrollOffset`. `state::battle` reported the row
as the bag cursor. `THROW BALL` aims at the ball's bag index, here 4 (TM34, HELIX FOSSIL, NUGGET
and TM45 come first), and no row can ever be 4. The cursor step walked between rows 1 and 2, ran out
of budget and blocked, even though the arrow was on the ball (offset 3, row 1).
- **The rule.** The bag cursor is `wCurrentMenuItem + wListScrollOffset`, the same sum
`DisplayListMenuIDLoop` makes when A selects. `wListScrollOffset` (`$CC36`) is pinned from the
operand of that read and checked against the cartridge, the same way as `hJoyLast` (12.27).
Every UP or DOWN press then moves the entry by one, either by moving the arrow or by scrolling
the window, so the existing cursor step reaches any entry. `ITEM`'s Potion had the same limit
(fourth entry or later) and is fixed by the same change.
- **Why row 69 turned it into a trap.** Before row 69, a ball fourth or later in the bag was a
dead `THROW BALL` next to the moves. That cost a hold but did not trap the fly. Row 69 withholds
the moves, `SWITCH`, `RUN` and the bag's `BACK` at low HP, so the dead button became the only
one.
Other lists, checked: the mart's buy and sell lists are `DisplayListMenuID` lists too, and
`state::shop` now reports their cursor as the entry in the same way. The battle menu, the move
list, the party list and the start menu do not scroll. No macro navigates the PC's lists.
`MART_CURSOR_ROWS` (row 55) still limits purchases to the first three rows, because lifting it puts
new buttons on the pad and needs its own survey on the cartridge.
Tests: `a_battle_frame_with_a_cursor_accepting_input_is_the_flys_turn` (state, a bag scrolled by
three), `a_mart_reports_which_of_its_screens_is_up` (a scrolled buy list, and a stale offset on the
counter menu), the catch test's check that its ball is in the window's first rows (it still
throws),
`row71_a_ball_past_the_bags_window_is_thrown` (`FLY_ROW71_CHECKPOINT`, the live trap) and
`row71_the_list_scroll_offset_is_where_the_cartridge_reads_it` (FLY_ROM).
## 13. Shops and Pokémon Centers (the operator, 2026-09-17: "refactor the shop macros. make it a
## priority to visit the shop at least once per area; make shop macros item purchases. same
## for the Pokécenter. heal should be a macro.")

View file

@ -994,3 +994,11 @@ median; a two-fly transition near 10 to 12 ms at the median in every execution m
after the last loss. The guard and `check` stay on the container. The on-box shadow (v0.7.0)
slowed the live fly; the relay costs about 0.5% of a core. Reviews: BLOCK, BLOCK,
APPROVE-WITH-NOTES, APPROVE.
- 2026-10-01 (v0.7.4, loop review hotfix): row 71. On Route 24 (rung 15) the fly met a wild
Oddish at low HP with two Poké Balls in a bag that had grown to five items (TMs, HELIX FOSSIL,
NUGGET), so the ball was the fifth entry and the list scrolled. The macro state read the bag
cursor as the window row only, so THROW BALL could never reach the ball and was blocked every
time; row 69's low-HP rule left it the only card. A restart restores the open bag, so the ladder
could not clear it. The cursor is now the row plus the list's scroll offset, as the cartridge
computes it; the mart's lists the same. ROM test from the live checkpoint: 10 blocked before,
Oddish caught after. Review: APPROVE.

View file

@ -549,11 +549,20 @@ PY
exit 1
fi
[ -x "$BIN" ] || die "$BIN is missing"
# The live service's configuration, for its compatibility string.
set -a
# shellcheck disable=SC1090,SC1091
. "${FLY_ENV_FILE:-/etc/fly/fly.env}"
set +a
# The live service's configuration, for its compatibility string. fly.env is systemd's
# EnvironmentFile syntax (GAME_TITLE=Pokemon Red is valid there), so it is read as KEY=VALUE
# lines, as fly-runtime does, never sourced as shell.
local line key value env_file="${FLY_ENV_FILE:-/etc/fly/fly.env}"
if [ -f "$env_file" ]; then
while IFS= read -r line || [ -n "$line" ]; do
[[ "$line" =~ ^[A-Za-z_][A-Za-z0-9_]*= ]] || continue
key="${line%%=*}"
value="${line#*=}"
value="${value%\"}"
value="${value#\"}"
export "${key}=${value}"
done <"$env_file"
fi
# The release CUT-01 switches into and the binary it switches to: SERVE-01's service there.
"$BIN" check --verdict "$SHADOW_DIR/verdict.json" --current "${FLY_CURRENT_DIR:-/opt/fly/current}" \
--binary flysim-session "$@"

View file

@ -76,7 +76,9 @@ else
fi
(cd "$release" && sha256sum -c MANIFEST --quiet) || die "MANIFEST verification failed for $release"
[ -x "$release/fly-shadow" ] || die "$release has no fly-shadow: this release predates SHADOW-01"
"$release/fly-shadow" ingest 2>&1 | grep -q 'needs --root' \
# The bare subcommand exits 2 (usage); under pipefail a pipe into grep would fail on that, so capture.
probe="$("$release/fly-shadow" ingest 2>&1 || true)"
printf '%s' "$probe" | grep -q 'needs --root' \
|| die "$release/fly-shadow has no ingest: this release predates SHADOW-02"
ln -sfn "$release" /opt/fly/current.tmp && mv -T /opt/fly/current.tmp /opt/fly/current
log "/opt/fly/current -> $release"

View file

@ -3687,3 +3687,52 @@ Ladder replay of the day (the same logs and the same start state, base against b
Zubat, 17:46) is new, so a restart at 18:04 and then the protection hold through 18:54, no reset.
The replay is open loop: the log after 16:50 is what the base's reset produced.
## 2026-10-01, row 71: Route 25, a ball past the bag's window
### What was live
v0.7.3 legacy, adapter v8, rung 15 (NUGGET BRIDGE), map 36 (Route 25), two badges. After the
Route 25 trainers, a wild battle began. The pad held `THROW BALL` alone and every start was
`blocked`: 131 of 131 in ten minutes, about two hours in all. A flysim restart restored a hot
generation from inside the same battle with the same bag open, so the trap came back at once. The
coordinator then reset the run to milestone 15.
### Reproduction (hot generation 263767, inside the trap)
- The state: `wIsInBattle` 1 (wild, not a trainer), a wild Oddish L13 at 8/36, Wartortle L35 at
21/105 with PP left (only GROWL at 0).
- The bag: TM34, HELIX FOSSIL, NUGGET, TM45, POKé BALL x2. Party of 2, Oddish not in it.
- The bag was open with `wListScrollOffset` 3, so the window showed TM45, POKé BALL and CANCEL,
with the arrow on row 1, the ball.
- Row 69's rule (enemy HP low for the ball) withheld everything but the ball.
- `THROW BALL` aims at bag index 4. The seam reported the window row (0..2) as the cursor, so the
cursor step walked between rows 1 and 2 until its budget ran out.
The hypotheses in the brief were all checked:
- **A trainer battle.** No, it is wild.
- **No balls in the bag.** No, there are two.
- **The ball counted wrong.** Its index was right; the cursor reading was wrong.
- **RUN, or PP.** Not involved.
| # | trap | trigger | test | fix, or why it is left |
| --- | --- | --- | --- | --- |
| 71 | the battle bag's cursor was read as the window's row, so a bag entry past the third could never be reached; with row 69's low-HP rule, `THROW BALL` alone on the pad and blocked for ever | any wild battle against a species not in the party at low HP, with the ball fourth or later in the bag (`ITEM`'s Potion likewise, without the trap) | `a_battle_frame_with_a_cursor_accepting_input_is_the_flys_turn`, `row71_a_ball_past_the_bags_window_is_thrown` (`FLY_ROW71_CHECKPOINT`), `row71_the_list_scroll_offset_is_where_the_cartridge_reads_it` | **fixed**: cursor = `wCurrentMenuItem + wListScrollOffset` (`$CC36`, pinned from the cartridge; `docs/design/macros.md` 12.34). The mart's lists read the same way; `MART_CURSOR_ROWS` stays |
| test | 390d118 | branch |
| --- | --- | --- |
| `row71_a_ball_past_the_bags_window_is_thrown` | 11 starts, 10 `blocked`, nothing thrown in 3,000 frames. **Fails** | thrown, Oddish caught (`wCapturedMonSpecies`) by f350, 0 `blocked`. Passes |
| `a_catch_on_the_cartridge_pays_the_catch_rule_once_with_the_species_in_its_label`, `row69_at_low_hp_a_wild_battles_pad_is_the_ball` | pass | pass (balls in the window's first rows, unscrolled) |
Trap hunt, 10 brain minutes with the real connectome from the trap checkpoint:
- **390d118:** 33 of 33 windows flagged, 1 tile, `THROW BALL` 131 starts and 131 `blocked`. That
matches the live count exactly.
- **Branch:** 1 of 33 flagged. That window is the opening battle text, with 71 tiles in it. The
ball is thrown on the first hold and the Oddish is caught at 0.10 min. The fly ends the keyboard
itself, and the run reaches 91 tiles.
The watchdog and the ladder flagged the trap correctly. The restart could not help, because the
trap is in the game state and the hot checkpoint is inside it (row 70's lesson again). Only a reset
or the fix ends it.

View file

@ -2355,6 +2355,16 @@ else
fail "loop recovery tests failed; run python3 -m unittest discover -s infra/tests -p test_loop_recover.py -v"
fi
echo "--- fly.env is read, never sourced ---"
# fly.env is systemd EnvironmentFile syntax: GAME_TITLE=Pokemon Red is valid there and a shell
# error when sourced (the v0.7.3 cutover's check died on it). Scripts parse KEY=VALUE lines.
sourced="$(grep -n -E '^[[:space:]]*(\.|source)[[:space:]]+.*(fly\.env|FLY_ENV_FILE)' "$REPO_ROOT"/infra/bin/* 2>/dev/null || true)"
if [ -z "$sourced" ]; then
pass "no infra/bin script sources fly.env"
else
fail "fly.env sourced as shell (parse KEY=VALUE lines instead): $sourced"
fi
echo "==="
if [ "$FAILED" -eq 0 ]; then
echo "lint.sh: ALL CHECKS PASSED"

View file

@ -118,6 +118,11 @@ pub const CHEAPEST_PURCHASE: u32 = {
/// can name, and a purchase aimed at one is a button whose script gives up before it presses
/// anything. [`super::palette::stock_index`] is where the rule is applied, once, for both the pad
/// and the plan.
///
/// Row 71 pinned `wListScrollOffset` from the cartridge, and `state::shop` now reports the buy
/// list's cursor as the entry (row plus offset), so the reading is right however the list is
/// scrolled. The limit stays until a purchase past the third row has been surveyed on the
/// cartridge: lifting it would put new buttons on the pad, which is its own change.
pub const MART_CURSOR_ROWS: usize = 3;
/// Cursor indices of the battle menu, as `state::BattleMenu::Main` documents them: "0 FIGHT,

View file

@ -239,6 +239,9 @@ pub enum BattleMenu {
/// `ITEM` and section 14's `THROW BALL` navigate by (2026-09-17). Then it needed to be the
/// fly's *turn*: a bag reading as nobody's turn landed on the between-turns row, whose `NEXT`
/// is the A that advances text and on an open bag is the A that uses an item (12.10).
///
/// `cursor` is the 0-based bag entry the arrow is on -- the window's row plus the list's
/// scroll offset, so the bag's `count`th entry is CANCEL (row 71).
Bag { cursor: u8, count: u8 },
}

View file

@ -50,6 +50,18 @@ pub mod poke {
/// reads it back from there (row 63, `docs/design/macros.md` 12.27).
pub const H_JOY_LAST: u16 = 0xffb1;
/// `wListScrollOffset`, `$CC36`: how many entries of a `DisplayListMenuID` list are scrolled
/// off the top of its window (row 71, `docs/design/macros.md` 12.34).
///
/// Not in the reviewed address list, so pinned the way [`H_JOY_LAST`] is: read from the
/// operands of the cartridge's own instructions and checked by the ROM-gated test.
/// `DisplayListMenuIDLoop.buttonAPressed` turns the cursor into the entry it selects with
/// `ld a, [wCurrentMenuItem] / ld c, a / ld a, [wListScrollOffset] / add c / ld c, a`
/// (`home/list_menu.asm`), whose second load is `$CC36`. The cursor walks the window's rows
/// `0, 1, 2` and the window scrolls under it, so the entry under the cursor is the row plus
/// this.
pub const LIST_SCROLL_OFFSET: u16 = 0xcc36;
/// `ram/hram.asm`: `hWhoseTurn`, "0 on player's turn, 1 on enemy's turn". Counted from the
/// `hJoyLast` anchor above through the declarations that follow it (each `UNION` at its
/// largest member) to `$FFF3`; the section's remaining nine bytes then end at `$FFFE`, the
@ -687,8 +699,18 @@ pub fn battle(memory: &mut dyn MemoryReader) -> Option<Battle> {
// Pokédex page, the nickname offer and the naming screen -- read as an open bag, the pad
// was `BACK` and `THROW BALL`, and the ball's A presses typed the nickname: 6,900 frames
// from the catch to the end of the battle, under a `THROW BALL` that threw nothing.
//
// **And the cursor is the bag entry, not the window's row** (row 71). `wCurrentMenuItem`
// is the row of the window the arrow is on, `0..=2`, and the window scrolls under it, so
// the entry is that row plus [`poke::LIST_SCROLL_OFFSET`] -- the sum the cartridge itself
// makes when A selects. Read as the row alone, a ball fourth or later in the bag was a
// target no cursor reading could ever equal: live on rung 15, a wild Oddish at 8 of 36,
// POKé BALL fifth in the bag, `THROW BALL` alone on the pad (row 69's throw at low
// HP) and every start `blocked` while the arrow sat on the ball itself, 131 of 131 in ten
// minutes.
let count = bag(memory).len().min(usize::from(poke::BAG_CAPACITY));
BattleMenu::Bag { cursor: cursor.current, count: u8::try_from(count).unwrap_or(0) }
let entry = cursor.current.saturating_add(read(memory, poke::LIST_SCROLL_OFFSET));
BattleMenu::Bag { cursor: entry, count: u8::try_from(count).unwrap_or(0) }
} else {
BattleMenu::None
};
@ -1348,19 +1370,33 @@ pub fn shop(memory: &mut dyn MemoryReader) -> Option<Shop> {
if text_box(memory).waiting {
return Some(Shop { screen: ShopScreen::Talking, cursor });
}
let screen = if mart_item_window_drawn(memory) {
ShopScreen::Buying
} else {
ShopScreen::BuySellQuit
};
return Some(Shop { screen, cursor });
if mart_item_window_drawn(memory) {
return Some(Shop { screen: ShopScreen::Buying, cursor: list_entry(memory, cursor) });
}
return Some(Shop { screen: ShopScreen::BuySellQuit, cursor });
}
if read(memory, ram::wTextBoxID) != poke::BUY_SELL_QUIT_MENU {
return None;
}
let screen =
if list == poke::ITEM_LIST_MENU { ShopScreen::Selling } else { ShopScreen::BuySellQuit };
Some(Shop { screen, cursor })
if list == poke::ITEM_LIST_MENU {
return Some(Shop { screen: ShopScreen::Selling, cursor: list_entry(memory, cursor) });
}
Some(Shop { screen: ShopScreen::BuySellQuit, cursor })
}
/// A `DisplayListMenuID` cursor as the entry it is on rather than the window's row (row 71).
///
/// The arrow walks the window's rows and the list scrolls under it, so the entry is the row plus
/// [`poke::LIST_SCROLL_OFFSET`], and the last entry the window can reach is its last row plus the
/// same. Only for a list that is on screen: the offset is one shared byte that outlives every list,
/// so a menu that is not a list menu keeps its own cursor.
fn list_entry(memory: &mut dyn MemoryReader, cursor: Cursor) -> Cursor {
let offset = read(memory, poke::LIST_SCROLL_OFFSET);
Cursor {
current: cursor.current.saturating_add(offset),
max: cursor.max.saturating_add(offset),
..cursor
}
}
/// Whether the mart's priced item window is the thing drawn over the counter menu.

View file

@ -420,6 +420,18 @@ fn a_battle_frame_with_a_cursor_accepting_input_is_the_flys_turn() {
assert_eq!(fight.menu, BattleMenu::Bag { cursor: 0, count: 1 });
assert!(fight.own_turn, "the battle bag is a cursor accepting input");
// Row 71: the window scrolls under the arrow, and the cursor is the entry, not the row. The
// live bag: TM34, HELIX FOSSIL, NUGGET and TM45 in front and the POKé BALL fifth, scrolled by
// three so the window shows TM45, the ball and CANCEL with the arrow on the ball.
use crate::pokemon_red::macros::cartridge::item;
wram.bag(&[(0xea, 1), (0x2a, 1), (0x31, 1), (0xf5, 1), (item::POKE_BALL, 2)])
.set(ram::wCurrentMenuItem, 1)
.set(poke::LIST_SCROLL_OFFSET, 3);
let fight = battle(&mut wram).unwrap();
assert_eq!(fight.menu, BattleMenu::Bag { cursor: 4, count: 5 }, "row 1 of a window scrolled by 3");
wram.set(poke::LIST_SCROLL_OFFSET, 0);
assert_eq!(battle(&mut wram).unwrap().menu, BattleMenu::Bag { cursor: 1, count: 5 });
// And the two frames that are not a choice. A move list whose cursor cannot be placed is a
// battle's opening frames (row 30b), and no menu at all is text, an animation or a turn
// resolving.
@ -574,6 +586,17 @@ fn a_mart_reports_which_of_its_screens_is_up() {
.screen_tile(poke::MART_NAME_COLUMN, poke::MART_NAME_ROW, poke::CHAR_UPPER_A);
assert_eq!(shop(&mut wram).map(|shop| shop.screen), Some(ShopScreen::Buying));
// Row 71: the buy list's cursor is the entry, the window's row plus the scroll offset, and so
// is the last entry the window reaches.
wram.cursor(4, 5, 1, 2, poke::pad::A | poke::pad::B).set(poke::LIST_SCROLL_OFFSET, 2);
let buying = shop(&mut wram).unwrap();
assert_eq!((buying.cursor.current, buying.cursor.max), (3, 4));
// The counter menu is not a list menu: a stale offset leaves its cursor alone.
wram.screen_tile(poke::MART_NAME_COLUMN, poke::MART_NAME_ROW, 0x7f);
let counter = shop(&mut wram).unwrap();
assert_eq!(counter.screen, ShopScreen::BuySellQuit);
assert_eq!((counter.cursor.current, counter.cursor.max), (1, 2));
// The bag list on its own is the start menu's, not a mart's.
let mut wram = Wram::overworld();
wram.set(ram::wFontLoaded, poke::BIT_FONT_LOADED)

View file

@ -210,6 +210,13 @@ fn a_catch_on_the_cartridge_pays_the_catch_rule_once_with_the_species_in_its_lab
return;
}
eprintln!("bag holds {balls} balls");
// Row 71's other half: this checkpoint's ball is in the bag window's first rows, unscrolled,
// so the catch below is the throw that worked before the scroll offset was read and must
// still work after it.
let ball_entry = state::bag(&mut Run::resume(&rom, &checkpoint).gb)
.iter()
.position(|item| (0x01..=0x04).contains(&item.id) && item.count > 0);
assert!(ball_entry.is_some_and(|entry| entry < 3), "ball at bag entry {ball_entry:?}");
// Five brain minutes per attempt is generous for a forest checkpoint: the live run threw 28
// balls in its first Viridian Forest session (`pokemon_red::macros::palette`). An attempt
@ -807,3 +814,85 @@ fn row69_the_naming_bytes_are_where_the_cartridge_stores_them() {
assert!(rom.windows(submit.len()).any(|window| window == submit), "wNamingScreenSubmitName");
assert_eq!(poke::NAMING_SUBMIT, poke::NAMING_LENGTH + 1, "consecutive in the UNION");
}
fn row71_checkpoint() -> Option<flysim::store::Checkpoint> {
let path = std::env::var_os("FLY_ROW71_CHECKPOINT")?;
Some(
flysim::store::load(std::path::Path::new(&path))
.expect("the checkpoint should be a FLYSIM01 envelope"),
)
}
/// Row 71: a ball past the bag's window is thrown.
///
/// The live trap (rung 15, Route 25): a wild Oddish at 8 of 36, the bag open and scrolled by
/// three, POKé BALL its fifth entry with the arrow on it. Row 69's low-HP rule leaves
/// `THROW BALL` alone on the pad, and on 390d118 its cursor step compared the bag index (4) with
/// the window's row (`wCurrentMenuItem`, `0..=2`), never met it, and every start was `blocked`:
/// 131 of 131 in ten minutes live. The stub leans on the one bound button, as the live fly could
/// only do. On the branch the first throw catches the Oddish.
#[test]
fn row71_a_ball_past_the_bags_window_is_thrown() {
let Some(rom) = rom() else {
eprintln!("skipped: FLY_ROM is not set");
return;
};
let Some(checkpoint) = row71_checkpoint() else {
eprintln!("skipped: no FLY_ROW71_CHECKPOINT");
return;
};
let mut run = Run::resume(&rom, &checkpoint);
assert_eq!(run.byte(ram::wIsInBattle), 1, "the trap is a wild battle, not a trainer's");
let balls = run.balls();
assert!(balls > 0, "the checkpoint's bag holds a ball");
let enemy = run.byte(ram::wEnemyMonSpecies);
assert_ne!(run.byte(ram::wCapturedMonSpecies), enemy, "nothing caught yet");
let mut pads: std::collections::BTreeSet<Vec<String>> = Default::default();
let mut thrown_at = None;
for frame in 0..3_000u32 {
let bound = run.layer.bound_channels();
if run.layer.running().is_none() {
pads.insert(bound.clone());
}
let hot = bound.first().cloned();
let active =
run.decoder.decode_bound(&rates(hot.as_deref()), run.ms, false, None, Some(&bound));
run.legacy.execute(Some(&mut run.layer), &active, 0, run.ms, &mut run.gb, &run.adapter);
run.ms += MS_PER_FRAME;
run.frame += 1;
let evaluated = run
.legacy
.stub_advance(Some(&mut run.layer), &mut run.gb, &mut run.adapter, run.ms)
.expect("a frame should complete");
run.payouts.extend(evaluated.rewards);
// The cartridge takes the ball out of the bag only once the catch's screens are over (the
// nickname is the fly's own buttons, which this stub does not press), so the ball keeping
// the Oddish (`wCapturedMonSpecies`) counts as the throw too.
if run.balls() < balls || run.byte(ram::wCapturedMonSpecies) == enemy {
thrown_at = Some(frame);
break;
}
}
let counts = run.layer.counts();
let caught = run.byte(ram::wCapturedMonSpecies) == enemy;
eprintln!("thrown at {thrown_at:?}; caught {caught}; {counts:?}; pads {pads:?}");
assert!(thrown_at.is_some(), "the ball was never thrown: {counts:?}");
assert_eq!(counts.blocked, 0, "a THROW BALL that blocked on the way: {counts:?}");
}
/// `wListScrollOffset` is where the cartridge reads it when a list entry is chosen (row 71):
/// `DisplayListMenuIDLoop.buttonAPressed`'s `ld a, [wCurrentMenuItem] / ld c, a /
/// ld a, [wListScrollOffset] / add c / ld c, a`, once in the cartridge.
#[test]
fn row71_the_list_scroll_offset_is_where_the_cartridge_reads_it() {
let Some(rom) = rom() else {
eprintln!("skipped: FLY_ROM is not set");
return;
};
use flybrain_gb::pokemon_red::state::poke;
let [lo, hi] = ram::wCurrentMenuItem.to_le_bytes();
let [slo, shi] = poke::LIST_SCROLL_OFFSET.to_le_bytes();
let selects = [0xfa, lo, hi, 0x4f, 0xfa, slo, shi, 0x81, 0x4f];
let found = rom.windows(selects.len()).filter(|window| *window == selects).count();
assert_eq!(found, 1, "wListScrollOffset's read in DisplayListMenuIDLoop");
}