Skip to Content
The Alchemy Project

src/battle/battle_link.c

Link battles: the parties and Djinn exchanged, and the turn handshake. More…

Included by battle.c.

Macros

NameDescription
#defineNAME_LIMIT WHEN(SPACED_ENEMY_NAME_PREFIX, 7, 4)The longest "Enemy" label the opponent's names take before them; the European editions also put a space after it.
#defineAPPEND_NAME_SPACE WHEN(SPACED_ENEMY_NAME_PREFIX, 1, 0)
#defineOPPONENT_SLOT_NONE 255BATTLE_STATE.opponentSlots for a party unit the opponent was not sent.

Enumerations

NameDescription
enumLINK_PARTY_PACKET_SIZE { LINK_PARTY_UNIT_BYTES, LINK_PARTY_OFFER_BYTES }What a link battle sends of each party member, and of the Djinn recovery list, in bytes.

Functions

NameDescription
Sint32btLinkBattleReceiveParty (void)Unused: receives the opponent's party into the enemy units, "Enemy" before each name, then its Djinn recovery list.
UNREAD_RESULTbtLinkBattleSendParty (void)Unused: sends the party, then the Djinn recovery list, each unit under the id the opponent knows it by.
Uint8 *btTextCopyFourCharsUnderscored (Uint32 unusedA, Uint32 unusedB, Uint16 *src)Copies a name's first four characters, an underscore for each zero, and returns a pointer to the end.
Sint32btLinkBattleWaitSync (void)In a link battle, shows the "EXEC" signature and waits up to 30 ticks for the other console to show it too.
Sint32btLinkBattleSyncTurn (void)In a link battle, after each action and each turn, steps both consoles through the same handshake of signatures.
UNREAD_RESULTbtPartyAssignOpponentSlots (void)Records the unit id the link opponent knows each party member by.
Sint32btClearSerialTransferPayload (void)Clears the first 16 bytes of the link transfer's payload, the eight signature halfwords btLinkBattleWaitSync and btLinkBattleSyncTurn write.

Description

Link battles: the parties and Djinn exchanged, and the turn handshake. Part of battle.c.

Macros in detail

NAME_LIMIT

#define NAME_LIMIT WHEN(SPACED_ENEMY_NAME_PREFIX, 7, 4)

The longest "Enemy" label the opponent's names take before them; the European editions also put a space after it.

Referenced by btLinkBattleReceiveParty().

Definition at line 8 of file battle_link.c.

APPEND_NAME_SPACE

#define APPEND_NAME_SPACE WHEN(SPACED_ENEMY_NAME_PREFIX, 1, 0)

Definition at line 9 of file battle_link.c.

OPPONENT_SLOT_NONE

#define OPPONENT_SLOT_NONE 255

BATTLE_STATE.opponentSlots for a party unit the opponent was not sent.

Referenced by btLinkBattleSendParty().

Definition at line 90 of file battle_link.c.

Enumerations in detail

enum LINK_PARTY_PACKET_SIZE

What a link battle sends of each party member, and of the Djinn recovery list, in bytes.

EnumeratorValueDescription
LINK_PARTY_UNIT_BYTES340A UNIT (BATTLE_UNIT_SIZE, 332 bytes) and the 8 after it.
LINK_PARTY_OFFER_BYTES320A DJINN_RECOVERY_TABLE (268 bytes) and the 52 after it.

Definition at line 13 of file battle_link.c.

Functions in detail

btLinkBattleReceiveParty

Sint32 btLinkBattleReceiveParty(void)

Unused: receives the opponent's party into the enemy units, "Enemy" before each name, then its Djinn recovery list. Returns how many party members came.

References gmDjinnGetRecoveryTableStub(), gmUnitGetStub(), mnMessageDecodeRawUnboundedStub(), Sint32, syHeapAllocateEWRAM(), syHeapRelease(), sySerialStartReceive(), sySerialWaitForReceive() and sySynch().

Definition at line 23 of file battle_link.c.

btLinkBattleSendParty

UNREAD_RESULT btLinkBattleSendParty(void)

Unused: sends the party, then the Djinn recovery list, each unit under the id the opponent knows it by.

References btPartyPrepareMembers(), gmDjinnGetRecoveryTableStub(), gmUnitGetStub(), Sint32, syHeapAllocateEWRAM(), syHeapRelease(), sySerialStartSend(), sySerialWaitForSend(), sySynch() and syWordsCopy().

Definition at line 94 of file battle_link.c.

btTextCopyFourCharsUnderscored

Uint8 * btTextCopyFourCharsUnderscored(Uint32 unusedA, Uint32 unusedB, Uint16 *src)

Copies a name's first four characters, an underscore for each zero, and returns a pointer to the end. UB: the copy is on the stack; UBFIX keeps it.

References Sint32.

Definition at line 159 of file battle_link.c.

btLinkBattleWaitSync

Sint32 btLinkBattleWaitSync(void)

In a link battle, shows the "EXEC" signature and waits up to 30 ticks for the other console to show it too. Returns -1 when the link fails, else 0.

References LinkStatusWork, SerialPeerPayloads, SerialTransfer, Sint32 and sySynch().

Referenced by btGatherActions().

Definition at line 193 of file battle_link.c.

btLinkBattleSyncTurn

Sint32 btLinkBattleSyncTurn(void)

In a link battle, after each action and each turn, steps both consoles through the same handshake of signatures. Returns -1 when the link fails or the steps disagree, else 0.

References LinkStatusWork, SerialPeerPayloads, SerialTransfer, Sint32 and sySynch().

Referenced by btRun().

Definition at line 243 of file battle_link.c.

btPartyAssignOpponentSlots

UNREAD_RESULT btPartyAssignOpponentSlots(void)

Records the unit id the link opponent knows each party member by.

References btPartyPrepareMembers() and Sint32.

Referenced by btRun().

Definition at line 375 of file battle_link.c.

btClearSerialTransferPayload

Sint32 btClearSerialTransferPayload(void)

Clears the first 16 bytes of the link transfer's payload, the eight signature halfwords btLinkBattleWaitSync and btLinkBattleSyncTurn write.

References SerialTransfer, Sint32 and syWordsClear().

Referenced by btRun().

Definition at line 392 of file battle_link.c.