The link cable: payload exchange, block transfers and the link test. More...
Go to the source code of this file.
Data Structures | |
| struct | OneCell |
Macros | |
| #define | SERIAL_DEFINE_WAIT(name, pending) |
| Each waits a frame at a time until pending is 0, giving up after 600000 frames: the send, then the receive. | |
Enumerations | |
| enum | { SERIAL_PACKET_HALFWORDS = 14 , SERIAL_PAYLOAD_BYTES = 24 , SERIAL_BLOCK_BYTES = 20 , SERIAL_TRANSFER_TIMEOUT_FRAMES = 600000 , SERIAL_IDLE_HALFWORD = 0xfefe , SERIAL_TIMER_RELOAD = 0xc963 } |
Functions | |
| void | SerialRuntime_Initialize (void) |
| Resets the serial port into multiplayer mode, installs the serial and timer 3 interrupt handlers, clears gSerialRuntime and points its packet buffers into its storage, clears the bulk transfer state and sets gSerialExchangeActive, which starts the per-frame exchange. | |
| void | SerialRuntime_EnableTransferTimer (void) |
| Lets the timer start transfers again once a link mode is set, by setting gSerialRuntime.transferEnabled. | |
| void | SerialRuntime_DisableTransfer (void) |
| Disables the serial and timer 3 interrupts, stops the transfer timer and clears gSerialRuntime.transferEnabled. | |
| s32 | SerialRuntime_PollAndTransfer (void *send, void *receive) |
| Looks for the link partner and, once connected, does one exchange (as SerialRuntime_ExchangePayloads). | |
| s32 | SerialRuntime_PollStatus (void) |
| As SerialRuntime_PollAndTransfer, without exchanging data: WaitFrames calls it once a frame while gSerialExchangeActive is set, and the VBlank handler does the exchange. | |
| s32 | SerialRuntime_ExchangePayloads (void *send, void *receive) |
| Once connected (phase 1), gathers the received payloads into receive and builds the next packet from send. | |
| void | SerialRuntime_PrepareSendPacket (void *payload) |
| Builds the packet to send in sendBuffer[0]: [0] the sequence number, [1] the consoles not yet heard from, [2] the checksum and [4] the 24-byte payload. | |
| u8 | SerialRuntime_CollectReceivedPayloads (void *payload) |
| Swaps in the packets the interrupt handler finished, then copies the payload of each one whose checksum is good to payload (24 bytes per console), and records the consoles heard from in currentMask and receivedMask. | |
| void | SerialRuntime_HandleTransferInterrupt (void) |
| The serial and timer 3 interrupt, installed by SerialRuntime_Initialize: each one moves a halfword. | |
| void | SerialRuntime_RemoveIrqHandlers (void) |
| Clears gSerialExchangeActive, which stops the per-frame exchange, and removes the link interrupt handlers. | |
| u32 | SerialRuntime_WaitForStatusMask (s32 mask) |
| Waits a frame at a time until every status bit in mask is set in gLinkStatus, then returns this console's multiplayer id. | |
| s32 | SerialRuntime_BeginSend (void *source, s32 size) |
| Starts sending size bytes from source to the partner in 20-byte blocks: sets the send source, size and block sequence that SerialRuntime_StepBlockTransfer works from. | |
| s32 | SerialRuntime_BeginReceive (void *destination) |
| Starts receiving the partner's blocks into destination: sets the receive destination and clears the received size. | |
| void | SerialRuntime_WaitForSend (void) |
| void | SerialRuntime_WaitForReceive (void) |
| void | SerialRuntime_WaitForTransfers (void) |
| Waits until both the send and the receive have finished, giving up after 600000 frames. | |
| s32 | SerialRuntime_GetActiveTransfers (void) |
| Returns bit 0 while a send runs and bit 1 while a receive runs. | |
| void | BattleLink_ResetTransferState (void) |
| void | SerialRuntime_StepBlockTransfer (void) |
| Runs each VBlank after the exchange, called by System_VBlankHandler: moves the bulk transfer on by one 20-byte block each way. | |
| void | SerialTest_Delay (void) |
| An empty routine the link test calls to waste time. | |
| void | SerialTest_Run (void) |
| A link cable test left in the game: it shows a row of tiles, receives blocks into the map cell buffer and shows them as tiles, and sends a part of the ROM when A or B is held. | |
Variables | |
| const u8 | Rom_Start [] |
The link cable: payload exchange, block transfers and the link test.
Part of runtime.c, the runtime object, compiled only through it.
Definition in file serial.c.
| #define SERIAL_DEFINE_WAIT | ( | name, | |
| pending ) |
Each waits a frame at a time until pending is 0, giving up after 600000 frames: the send, then the receive.
Definition at line 492 of file serial.c.
Referenced by SerialRuntime_WaitForReceive(), and SerialRuntime_WaitForSend().
| anonymous enum |
| void SerialRuntime_Initialize | ( | void | ) |
Resets the serial port into multiplayer mode, installs the serial and timer 3 interrupt handlers, clears gSerialRuntime and points its packet buffers into its storage, clears the bulk transfer state and sets gSerialExchangeActive, which starts the per-frame exchange.
Called by the link lobby, the save menu's link transfer and the link test, and through the far-call table.
Definition at line 28 of file serial.c.
Referenced by LinkLobby_InitializeSerial(), LinkLobby_RunRoundResult(), memcpy(), SaveMenu_Run(), SerialRuntime_Initialize(), and SerialTest_Run().
| void SerialRuntime_EnableTransferTimer | ( | void | ) |
Lets the timer start transfers again once a link mode is set, by setting gSerialRuntime.transferEnabled.
Nothing in ☀️ calls it; WaitFrames does the same inline.
Definition at line 85 of file serial.c.
Referenced by memcpy(), and SerialRuntime_EnableTransferTimer().
| void SerialRuntime_DisableTransfer | ( | void | ) |
Disables the serial and timer 3 interrupts, stops the transfer timer and clears gSerialRuntime.transferEnabled.
Nothing in ☀️ calls it.
Definition at line 94 of file serial.c.
Referenced by memcpy(), and SerialRuntime_DisableTransfer().
| s32 SerialRuntime_PollAndTransfer | ( | void * | send, |
| void * | receive ) |
Looks for the link partner and, once connected, does one exchange (as SerialRuntime_ExchangePayloads).
When this console is the parent (SIOCNT reports multiplayer mode with no error) it arms timer 3 to clock the transfers. Called by the Tret tree branch scene for its own exchange. Returns the link status (see SerialRuntime_ExchangePayloads).
Definition at line 113 of file serial.c.
Referenced by memcpy(), SerialRuntime_PollAndTransfer(), and TretTreeBranch_ExchangeInputPacket().
| s32 SerialRuntime_PollStatus | ( | void | ) |
As SerialRuntime_PollAndTransfer, without exchanging data: WaitFrames calls it once a frame while gSerialExchangeActive is set, and the VBlank handler does the exchange.
Definition at line 168 of file serial.c.
Referenced by memcpy(), SerialRuntime_PollStatus(), and WaitFrames().
| s32 SerialRuntime_ExchangePayloads | ( | void * | send, |
| void * | receive ) |
Once connected (phase 1), gathers the received payloads into receive and builds the next packet from send.
Called by the VBlank handler while gSerialExchangeActive is set, which stores the result in gLinkStatus. Returns the link status: bits 0 to 7 : the consoles heard from this frame (bit 7 also when parent) bits 8 to 15 : the consoles heard from since the link began 0x1000 : this console is the parent 0x2000 : SIOCNT's multiplayer id is 2 or more
Definition at line 218 of file serial.c.
Referenced by memcpy(), SerialRuntime_ExchangePayloads(), and System_VBlankHandler().
| void SerialRuntime_PrepareSendPacket | ( | void * | payload | ) |
Builds the packet to send in sendBuffer[0]: [0] the sequence number, [1] the consoles not yet heard from, [2] the checksum and [4] the 24-byte payload.
The checksum is the complement of the sum of the first 28 bytes as halfwords. Then restarts the send position and the timer. Called by both exchanges.
Definition at line 246 of file serial.c.
Referenced by memcpy(), SerialRuntime_ExchangePayloads(), SerialRuntime_PollAndTransfer(), and SerialRuntime_PrepareSendPacket().
| u8 SerialRuntime_CollectReceivedPayloads | ( | void * | payload | ) |
Swaps in the packets the interrupt handler finished, then copies the payload of each one whose checksum is good to payload (24 bytes per console), and records the consoles heard from in currentMask and receivedMask.
Called by both exchanges. Returns the mask of consoles heard from this frame.
Definition at line 302 of file serial.c.
Referenced by memcpy(), SerialRuntime_CollectReceivedPayloads(), SerialRuntime_ExchangePayloads(), and SerialRuntime_PollAndTransfer().
| void SerialRuntime_HandleTransferInterrupt | ( | void | ) |
The serial and timer 3 interrupt, installed by SerialRuntime_Initialize: each one moves a halfword.
It sends the next halfword of the outgoing packet (0xfefe between packets) and stores the halfword received from each console; a console's fourteenth halfword completes its packet.
Definition at line 344 of file serial.c.
Referenced by memcpy(), SerialRuntime_HandleTransferInterrupt(), and SerialRuntime_Initialize().
| void SerialRuntime_RemoveIrqHandlers | ( | void | ) |
Clears gSerialExchangeActive, which stops the per-frame exchange, and removes the link interrupt handlers.
Called when the link lobby, the save menu's transfer or a link battle ends.
Definition at line 431 of file serial.c.
Referenced by BattlePresentation_AppendLinkedActions(), LinkLobby_InitializeSerial(), LinkLobby_LeaveArena(), memcpy(), SaveMenu_Run(), and SerialRuntime_RemoveIrqHandlers().
Waits a frame at a time until every status bit in mask is set in gLinkStatus, then returns this console's multiplayer id.
Called by the link test and through the far-call table.
Definition at line 440 of file serial.c.
Referenced by memcpy(), SerialRuntime_WaitForStatusMask(), and SerialTest_Run().
Starts sending size bytes from source to the partner in 20-byte blocks: sets the send source, size and block sequence that SerialRuntime_StepBlockTransfer works from.
Called by the link battle, the link lobby and the save menu's transfer. Returns -1 when a send is already running, 0 otherwise.
Definition at line 454 of file serial.c.
Referenced by BattlePresentation_AppendLinkedActions(), LinkBattle_SendParty(), LinkLobby_SendPartyRecords(), memcpy(), SaveMenu_Run(), SerialRuntime_BeginSend(), and SerialTest_Run().
| s32 SerialRuntime_BeginReceive | ( | void * | destination | ) |
Starts receiving the partner's blocks into destination: sets the receive destination and clears the received size.
Called by the same code as SerialRuntime_BeginSend. Returns -1 when a receive is already running, 0 otherwise.
Definition at line 474 of file serial.c.
Referenced by BattlePresentation_AppendLinkedActions(), LinkBattle_ReceiveParty(), LinkLobby_ReceivePartyRecords(), memcpy(), SerialRuntime_BeginReceive(), and SerialTest_Run().
| void SerialRuntime_WaitForSend | ( | void | ) |
Definition at line 504 of file serial.c.
Referenced by LinkBattle_SendParty(), SerialRuntime_WaitForSend(), and System_GetLanguage().
| void SerialRuntime_WaitForReceive | ( | void | ) |
Definition at line 505 of file serial.c.
Referenced by LinkBattle_ReceiveParty(), SerialRuntime_WaitForReceive(), and System_GetLanguage().
| void SerialRuntime_WaitForTransfers | ( | void | ) |
Waits until both the send and the receive have finished, giving up after 600000 frames.
Reached through the far-call table.
Definition at line 509 of file serial.c.
Referenced by memcpy(), and SerialRuntime_WaitForTransfers().
| s32 SerialRuntime_GetActiveTransfers | ( | void | ) |
Returns bit 0 while a send runs and bit 1 while a receive runs.
The link battle and lobby poll it between frames.
Definition at line 523 of file serial.c.
Referenced by BattlePresentation_AppendLinkedActions(), LinkLobby_ReceivePartyRecords(), LinkLobby_SendPartyRecords(), memcpy(), and SerialRuntime_GetActiveTransfers().
| void BattleLink_ResetTransferState | ( | void | ) |
Definition at line 536 of file serial.c.
Referenced by BattleLink_ResetTransferState(), BattlePresentation_AppendLinkedActions(), memcpy(), and SerialRuntime_Initialize().
| void SerialRuntime_StepBlockTransfer | ( | void | ) |
Runs each VBlank after the exchange, called by System_VBlankHandler: moves the bulk transfer on by one 20-byte block each way.
The receiver acknowledges each block's sequence number; when the sender sees an acknowledgement behind its own count it rewinds and sends the missed blocks again. A finished send or receive clears gSerialSendSource or gSerialReceiveDest.
Definition at line 548 of file serial.c.
Referenced by memcpy(), SerialRuntime_StepBlockTransfer(), and System_VBlankHandler().
| void SerialTest_Delay | ( | void | ) |
An empty routine the link test calls to waste time.
Definition at line 668 of file serial.c.
Referenced by memcpy(), SerialTest_Delay(), and SerialTest_Run().
| void SerialTest_Run | ( | void | ) |
A link cable test left in the game: it shows a row of tiles, receives blocks into the map cell buffer and shows them as tiles, and sends a part of the ROM when A or B is held.
It never returns. Nothing in ☀️ reaches it.
Definition at line 673 of file serial.c.
Referenced by memcpy(), and SerialTest_Run().
|
extern |
Referenced by SerialTest_Run().