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
#defineLINK_SIGNATURE_BYTES (8 * sizeof(Uint16))The eight halfwords of a link signature, at the transfer payload's start.

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.
Sint32btLinkBattleSendParty (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)Unused: copies a name's first four characters, an underscore for each zero, and returns a pointer to the copy's 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: "ex" and "TU", "rn", "EXEC", "tu", "RN".
Sint32btPartyAssignOpponentSlots (void)Records the unit id the link opponent knows each party member by: an enemy's, FIRST_ENEMY_UNIT on from the first member, as memberSlot - FIRST_ENEMY_UNIT comes out in the byte it is stored in.
voidbtClearSerialTransferPayload (void)Clears the first LINK_SIGNATURE_BYTES of the link transfer's payload, the 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

#define LINK_SIGNATURE_BYTES (8 * sizeof(Uint16))

The eight halfwords of a link signature, at the transfer payload's start.

Referenced by btClearSerialTransferPayload().

Definition at line 15 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_BYTES340A DJINN_RECOVERY_TABLE and what follows it.

Definition at line 6 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(), gmUnitGet(), mnMessageDecodeRawUnboundedStub(), Sint32, syHeapAllocateEWRAM(), syHeapRelease(), sySerialStartReceive(), sySerialWaitForReceive() and sySynch().

Definition at line 19 of file battle_link.c.

btLinkBattleSendParty

Sint32 btLinkBattleSendParty(void)

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

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

Definition at line 89 of file battle_link.c.

btTextCopyFourCharsUnderscored

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

Unused: copies a name's first four characters, an underscore for each zero, and returns a pointer to the copy's end.

References Sint32.

Definition at line 153 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 187 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: "ex" and "TU", "rn", "EXEC", "tu", "RN". Returns -1 when the link fails, the steps disagree or no link is heard for more than LINK_MAX_MISSED_TICKS, else 0.

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

Referenced by btRun().

Definition at line 238 of file battle_link.c.

btPartyAssignOpponentSlots

Sint32 btPartyAssignOpponentSlots(void)

Records the unit id the link opponent knows each party member by: an enemy's, FIRST_ENEMY_UNIT on from the first member, as memberSlot - FIRST_ENEMY_UNIT comes out in the byte it is stored in.

References btPartyPrepareMembers() and Sint32.

Referenced by btRun().

Definition at line 372 of file battle_link.c.

btClearSerialTransferPayload

void btClearSerialTransferPayload(void)

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

References SerialTransfer.

Referenced by btRun().

Definition at line 389 of file battle_link.c.