# Plan 6 Task 1, the gate: Emerald's own link multi battle between two cores. The host (core A, the co-op test save: COOP, TORCHIC
# first) is the link master, the partner (core B, the partner save: NED, MUDKIP first) its link partner; two route trainers (ALLEN 333,
# CALVIN 318) are the AI side, run by the master. Every block either game sends goes through the bridge to the other
# (pk_coop_link_take / _give, moved by mgba_dump's `pair` pump after each frame), no serial line anywhere.
# Needs EMERALD_PARTNER_SAVE (`$PARTNER_SAVE`; scripts/coop_headless_check.sh).
#
# The tower's link multi sets the foes to level 50 (a Frontier rule a later task undoes), so the two Lv 5 leads get 999 HP here: a
# first turn that faints nobody leaves both players at the next action prompt without a replacement menu in between.
#
# What it checks, in order: both bridges reach PK_COOP_LINK_BATTLE (link state 2); the host's battler 0 and the partner's battler 2
# are each the game's own player controller at its action prompt (gBattlerControllerFuncs = HandleInputChooseAction | 1, 0x08057589,
# COOP_EM_HandleInputChooseAction); the teams: the game lays gPlayerParty out as the host's three then the partner's three on both
# cores (slot 0 TORCHIC on both, slot 3 MUDKIP on both: the partner core's own Pokémon sits at slot 3, not 0); each core picks FIGHT,
# a move and the target with its own keys; the prompt leaves and comes back (a whole turn ran over the bridge); and after that turn the
# 12 HP halfwords of gPlayerParty and gEnemyParty are the same on both cores (the partner core's gBattleMons is not filled in: only
# the master runs the engine, the partner's game works on the party structs).
#
# want: PASS linkwait 2
# want: expectsame php0 php0b: PASS
# want: expectsame ehp5 ehp5b: PASS
pair $PARTNER_SAVE
on b
@boot
poke16 0x02024542 999
poke16 0x02024544 999
on a
poke16 0x02024542 999
poke16 0x02024544 999
coopbegin 1 2 333 318
on b
coopbegin 0 2 333 318
linkwait 2 1500
on a
waitmem32 0x03005D60 0x08057589 3000
expectmonin 0x020244EC 280
expectmonin 0x02024618 283
on b
waitmem32 0x03005D68 0x08057589 3000
expect32 0x03005D68 0x08057589
expectmonin 0x020244EC 280
expectmonin 0x02024618 283
on a
hold A 4
linkrun 40
hold A 4
linkrun 40
hold A 4
linkrun 40
on b
hold A 4
linkrun 40
hold A 4
linkrun 40
hold A 4
linkrun 40
on a
waitmem8 0x03005D23 1 3000
waitmem32 0x03005D60 0x08057589 3000
expect32 0x03005D60 0x08057589
on b
waitmem32 0x03005D68 0x08057589 3000
expect32 0x03005D68 0x08057589
on a
rangehash php0 0x02024542 2
rangehash ehp0 0x0202479A 2
rangehash php1 0x020245A6 2
rangehash ehp1 0x020247FE 2
rangehash php2 0x0202460A 2
rangehash ehp2 0x02024862 2
rangehash php3 0x0202466E 2
rangehash ehp3 0x020248C6 2
rangehash php4 0x020246D2 2
rangehash ehp4 0x0202492A 2
rangehash php5 0x02024736 2
rangehash ehp5 0x0202498E 2
on b
rangehash php0b 0x02024542 2
rangehash ehp0b 0x0202479A 2
rangehash php1b 0x020245A6 2
rangehash ehp1b 0x020247FE 2
rangehash php2b 0x0202460A 2
rangehash ehp2b 0x02024862 2
rangehash php3b 0x0202466E 2
rangehash ehp3b 0x020248C6 2
rangehash php4b 0x020246D2 2
rangehash ehp4b 0x0202492A 2
rangehash php5b 0x02024736 2
rangehash ehp5b 0x0202498E 2
expectsame php0 php0b
expectsame ehp0 ehp0b
expectsame php1 php1b
expectsame ehp1 ehp1b
expectsame php2 php2b
expectsame ehp2 ehp2b
expectsame php3 php3b
expectsame ehp3 ehp3b
expectsame php4 php4b
expectsame ehp4 ehp4b
expectsame php5 php5b
expectsame ehp5 ehp5b
linkinfo
linkstate
