docs: macros.md 12.27 and the row 63 audit, an A the cartridge has not let go of

This commit is contained in:
acamilo 2026-09-24 05:17:13 +00:00
parent e170812e7c
commit 1acd20eb23
3 changed files with 130 additions and 0 deletions

View file

@ -995,3 +995,32 @@ power, from `engine/battle/effects.asm` and `MoveHitTest`:
Confuse Ray and Supersonic on a confused target, Leech Seed on a seeded or Grass target, Focus
Energy, Mist, Reflect and Light Screen already up, Disable on a disabled target, and a damaging
move the type chart makes "doesn't affect" (the chart is another ROM table).
## 14. What an item will do, and the joypad the cartridge last read (2026-09-24, `docs/design/macros.md` 12.27)
Row 63. Two addresses, both pinned and read back from the code that uses them by
`row63_the_joypad_latch_and_the_item_table_are_where_the_cartridge_says` (FLY_ROM).
| name | where | what reads it |
| --- | --- | --- |
| `ItemUsePtrTable` | `$03:$55E1` | one little-endian routine pointer per item id, `MASTER_BALL` (1) to `MAX_ELIXER` (`$53`); the operand of `UseItem_`'s `ld hl` |
| `hJoyLast` | `$FFB1` (HRAM) | the buttons `_Joypad` saw down last time the game asked; the operand of `_Joypad`'s `ldh a, [hJoyLast]` at `$03:$4000` |
**`state::item_routine`** reads an item's pointer and refuses a table where the five balls or the
potions and status heals do not share one routine. **`state::battle_item_use`** classes an item by
its routine, never by its id: the routine of `POKE_BALL`, `POTION`, `POKE_DOLL`, `ETHER`, or one of
`X_ACCURACY`, `GUARD_SPEC`, `DIRE_HIT`, `X_ATTACK`, `POKE_FLUTE`, and answers each one's check before
it acts (`engine/items/item_effects.asm`): a ball in a wild battle (a full party is `None`, the box
count unread; a trainer is `false`); medicine with somebody it would change, `ItemUseMedicine`'s
own id order (Revive: fainted; Full Heal and the status heals: that status; Full Restore: hurt or
statused; the HP items: neither fainted nor full), the Pokémon that is out read from the battle's
copy; a Poké Doll in a wild battle; the X items and the flute in any battle; a PP restore with a
move below its PP (PP Ups counted). Every other routine refuses in a battle. A TM or an HM goes to
`ItemUseTMHM` before the table and is `None`.
**`state::a_latched`** is `hJoyLast` bit 0 (`PAD_A`). `hJoyPressed` is `hJoyInput & ~hJoyLast`,
and the game only calls `_Joypad` while something reads input, so after the A that confirms a list
the latch keeps that A until the next list first asks. Measured on the Potion's party list: the
list reads open on the frame after the pulse, an A in the next 22 frames is lost, and across 120
rollback delays `hJoyLast`, `hJoyPressed`, `hJoyHeld` and `hJoy5` are the only bytes of WRAM and
HRAM whose values never overlap between lost and answered frames.

View file

@ -1650,6 +1650,44 @@ Nothing is ranked or pressed for the fly: frames that were never the fly's deal
decoder, the reward catalog, the adapter version, the roles and the compatibility string are
untouched.
### 12.27 An A the cartridge has not let go of is not a press, and a menu it is acting on is not a pad (2026-09-24, row 63)
Live on v0.6.2, rung 12, Mt. Moon B2F (map 61), wild battles: per ten minutes `BACK` 62, `ITEM`
28, `RUN` 21, `MOVE 1` 10, no game event; the log ITEM, BACK, BACK, ITEM, BACK ... then RUN, and
MOVE 1, BACK. Reproduced from the live checkpoint (`scene_probe`, `FLY_PROBE_CATCH=bag`).
- **The bag was not the problem.** Wartortle out at 8/86 with an Antidote, a Potion and TM34. The
cartridge's own `ItemUsePtrTable` (`$03:$55E1`) and each routine's checks say: the Potion would
be taken, the Antidote has nobody poisoned, TM34 is never usable in a battle. `ITEM` was dealt
correctly and it never used the Potion.
- **`ITEM`'s last press was no press.** The A that chose the Potion opens the party list. Its
cursor bytes read open at once, and with one Pokémon the cursor is already on its target, so the
script confirmed on the first frame. But `_Joypad` makes a press out of an edge against
`hJoyLast`, and the game does not ask again until the list is drawn: the Potion's A is still
`hJoyLast`, and an A pressed into that window is down on both sides of the comparison. Measured
by rollback: an A in the first 22 frames after the pulse is lost every time, and `hJoyLast`
alone separates lost from answered frames (every other WRAM and HRAM byte overlaps). `ITEM`
reported done over a list still waiting; `BACK` left it (the item unused, back to the bag) and
`BACK` left the bag. The pair was `ITEM` and `BACK`, and `ITEM` never did anything.
- **A confirming A waits for the cartridge to let go of the last one** (`state::a_latched`, the
cursor step). A wait presses nothing and shares the cursor step's budget. It applies to every
confirm, so SWITCH, a move, a ball and a purchase get the same guarantee.
- **A battle menu the cartridge still holds an A on deals no pad.** The same latch after an
answer: RUN's A is taken and the menu's box stays up to sixteen frames while the game acts on
it. A macro dealt there pressed at a menu already gone and held the pad for its three-second
cursor wait over "Got away safely!". Empty for those frames, 12.13's reading.
- **`MOVE 1` over the menu is FIGHT's backstop only while nothing else is a move** (12.8, 12.23).
Slot one spent beside slot four with PP, it was dealt anyway; its script confirms FIGHT and
stops, which opens the list its `BACK` closes. That is 12.11's pair, and `MOVE 4` is on the same
menu. With nothing usable it is the backstop as before.
- `ITEM` also asks the cartridge about its Potion (`item_refused`). With `hurt` it always agrees.
It is the same kind of rule as 12.23, and it is there for the day `hurt`'s reading and the
cartridge's part.
Nothing is ranked, weighted or pressed for the fly: a press waits for the cartridge to read it,
and a menu nobody is reading has no pad. The decoder, the reward catalog, the adapter version, the
roles and the compatibility string are untouched.
## 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.")
@ -1733,6 +1771,7 @@ observe is not a precondition, it is a guess.
| Battle, own turn, main menu | MOVE 1..4, SWITCH, ITEM, THROW BALL, RUN (whose cursor indices are FIGHT 0, **ITEM 1, PKMN 2**, RUN 3 -- two columns, 12.11) | four move buttons for `ATTACK` (section 14); THROW BALL added, and gated on the species since 12.9; **RUN gated**, below. No `BACK`: the four entries are the answers to this menu. **`NEXT` removed by 12.10** — an A press here confirms FIGHT and reopens the list the move list's `BACK` just closed, and `MOVE 1` is the backstop instead, bound here whatever the battler reads as |
| Battle, own turn, move list (**the box on screen**, 12.18) | MOVE 1..4, BACK -- or **MOVE 1 alone** | as above, plus **12.11**: `BACK` is dealt here only while `wBattleMon*` reads, because a list that binds no `MOVE n` has a pad whose one button closes the list `MOVE 1` underneath had just opened. With nothing readable the pad is `MOVE 1` and its script confirms where the cursor stands |
| Battle, own turn, party list | SWITCH, BACK | unchanged |
| Battle, own turn, any menu the cartridge still holds an A on (**12.27**) | nothing | new: the answer is taken or the list is not yet asking; the pad is back on the first frame the game reads the joypad |
| Battle, own turn, the bag | ITEM, THROW BALL, **BACK** | the bag reports a *cursor* (`macros-wram.md` 7.1), and since **12.10** it is the own turn, because a cursor accepting input is one. Its pad is the list's own answers; `NEXT` and `CONFIRM` are both off it, being the same blind A press that *uses* whatever the cursor holds |
| Battle, forced switch | SWITCH, NEXT | unchanged (row 8). The one arm that keeps `NEXT` with a cursor up, because it cannot be cancelled and has no `BACK` to undo it |
| Battle, between turns | NEXT | since **12.18** this row is most of a battle, and correctly so: a frame whose move list is remembered rather than drawn lands here. `BACK` was added here for the bag and **taken back out by 12.9**: on a frame of battle text there is no list to leave, and a `BACK` that changes nothing is the trap of section 12.2. Since **12.10** the bag is not on this row at all, so `NEXT` here is only ever the A that advances text |
@ -1781,6 +1820,7 @@ measured where it cannot.
| the title screen, and raw mode | not an empty pad by contract: the readout's boot variant applies and no palette is dealt |
| a scene the detector cannot name | `Unknown` deals `NEXT` and `BACK`; a screen neither press leaves (the naming screen, row 14) is a genuine stall and still needs START, which is a contract change |
| an `Unknown` frame that is the **overworld with the cartridge driving** -- a warp in flight, a scripted push-back, a guide walking the fly through a door | **empty on purpose** (12.13). There is no box to advance and no screen to leave, so an A or a B press is a press into somebody else's script: it changes nothing and completes where the fly stands. This is the one empty pad that ends itself -- the cartridge gives the buttons back within a few frames -- and `game.padEmptyMs` reports it like any other |
| the fly's own turn while the cartridge holds the A it last took (`hJoyLast`) | **empty on purpose** (12.27): a menu the game is acting on or has not started reading. Ends itself on the game's next joypad read |
| the fly's own turn where the seam cannot read the battler, now that `NEXT` is off that row (12.10) | **fixed**: `MOVE 1` is bound over the top-level menu whatever `wBattleMon*` reads as, because FIGHT is one of that menu's four entries and always opens |
And because "closed where a macro can close it" is not "closed":

View file

@ -3051,3 +3051,64 @@ On `main` `510727c` (v0.6.1, row 59 merged):
- `npm test` 663 passed; `npm run typecheck` clean; `infra/tests/lint.sh` ALL CHECKS PASSED.
- `flysim --print-compatibility`, raw and macros: 648 bytes, sha256 `8ce67b97...a8f68`, the same
as `main`. Decoder, reward catalog, adapter version and roles untouched.
## 2026-09-24, row 63: Mt. Moon B2F, ITEM, BACK, BACK
### What was live
Map 61 (Mt. Moon B2F), rung 12, v0.6.2, wild battles, about 03:05 to 03:15 UTC: per ten minutes
`BACK` 62, `ITEM` 28, `RUN` 21, `MOVE 1` 10, no game event. The log: ITEM, BACK, BACK, ITEM, BACK
... RUN, and MOVE 1, BACK, RUN. The checkpoint is a wild Geodude L9 with the battle bag open:
Wartortle L28 at 8/86, BITE, TAIL WHIP and BUBBLE at 0 PP and WATER GUN at 25; the bag an
Antidote, a Potion, TM34.
### The survey
`scene_probe` `FLY_PROBE_CATCH=bag` (uniform pick among dealt buttons, trace per macro) and
`=potion` (the Potion pressed by hand, then A tried after every delay 0..120 in a rollback).
- The cartridge's `ItemUsePtrTable` says the Potion would be taken, the Antidote not (nobody
poisoned), TM34 never in a battle. `ITEM` is dealt correctly (hurt, a Potion).
- `ITEM` presses ITEM, the Potion, and the party list opens on the frame after the pulse with
the one Pokémon under the cursor; the script's confirm goes in at once and the list stays up.
`ITEM done`; `BACK` closes the list (`UseItem` fails, back to the bag); `BACK` closes the bag.
- By rollback: A lost for 22 frames after the pulse, answered from then on; `hJoyLast` (and the
three joypad bytes after it) the only bytes that separate the two.
- `MOVE 1` is dealt over the menu with slot one spent beside slot four; it opens the list, whose
`BACK` closes it.
- With the confirm fixed: RUN's A is taken, the menu's box stays for up to sixteen frames with
`hJoyLast` = A, and a macro dealt there (the survey: `MOVE 4` after every `RUN` from FIGHT's
column, 324 of 324) presses at a menu that is gone and blocks for 180 frames.
| # | trap | trigger | test | fix, or why it is left |
| --- | --- | --- | --- | --- |
| 63 | a cursor step's confirming A goes into a list that reads open before the cartridge has let go of the A that opened it; the press is no edge, the macro reports done over a waiting list, and `BACK` twice undoes it | any list opened by an A whose target is under the cursor at once; the Potion's party list with one Pokémon | `items_last_press_waits_for_the_cartridge_to_let_go_of_the_potions_a`, `row63_item_uses_the_potion_and_the_battle_menu_deals_no_list_it_only_opens` (ROM) | **fixed**: `state::a_latched` (`hJoyLast`, `$FFB1`); the confirm waits while it holds. `docs/design/macros.md` 12.27 |
| 63b | `MOVE 1` over the battle menu with slot one spent beside a usable move only opens the list its `BACK` closes | a spent first move | `move_one_is_not_fights_backstop_beside_a_usable_move`, the ROM test's second drive | **fixed**: the backstop only while no move is usable |
| 63c | a battle menu the cartridge has taken an A on stays on screen; a macro dealt on it presses at a menu already gone | RUN, and any answer whose box lingers | `a_battle_menu_the_cartridge_still_holds_an_a_on_deals_no_pad` | **fixed**: no own-turn pad while `hJoyLast` holds A |
| 63d | `ITEM` is dealt while the cartridge would refuse the Potion | none reached: `hurt` implies it is taken | `item_is_off_the_pad_while_the_cartridge_would_refuse_the_potion`, `the_row_63_bag_holds_one_item_the_cartridge_would_take` | **guarded**: `state::battle_item_use` from `ItemUsePtrTable` (`$03:$55E1`) |
| 63e | a party list opened by an item reads as the battle's party list: its pad is `SWITCH`, `BACK`, and `SWITCH` there would use the item on the healthiest other Pokémon | only if `ITEM` stops before its last press; not reached with 63 fixed | -- | **left**: `ITEM` now finishes; naming the item's list is a seam change for when it is reached |
### Before and after
Ten seeds per arm, 71,673 frames each (20 brain minutes), uniform pick among the dealt buttons,
from the row-63 checkpoint. Base: `main` plus the seam reader and the probe; branch: the fix.
`build/loop-row63/survey-summary.md` has the per-seed table.
| | base | branch |
| --- | ---: | ---: |
| `ITEM` starts | 244 | 10 (each one used the Potion) |
| `BACK` starts | 559 | 0 |
| `MOVE 1` starts | 173 | 0 |
| longest ITEM/BACK run | 6 | 0 |
| battle macros blocked | 0 | 0 |
| battles | 392 | 343 |
| battle frames | 448,282 | 366,049 |
| mean / longest battle | 1,144 / 2,006 | 1,067 / 1,651 |
| wins (enemy seen at 0 HP) | 185 | 166 |
| rewards: battle / exploration / boundary+item | 67 / 3 / 0 | 73 / 19 / 24 |
ROM-gated, `row63_item_uses_the_potion_and_the_battle_menu_deals_no_list_it_only_opens`: base,
pressing `ITEM` whenever dealt, 12,000 frames in the one battle, `ITEM` 119 and `BACK` 119, the
party list left waiting 119 times, the Potion never used, and pressing `BACK` then `MOVE 1`
whenever dealt, `MOVE 1` 125 and `BACK` 125, the battle never ends: **fails**. Branch: the Potion
used (8 to 28 HP) and the battle over in 555 frames; `MOVE 4` and the battle over in 773: passes.