2017-09-30 15:56:08 +02:00
|
|
|
|
|
|
|
// Includes
|
|
|
|
#include "global.h"
|
2017-11-13 05:16:51 +01:00
|
|
|
#include "m4a.h"
|
2017-11-09 01:58:59 +01:00
|
|
|
#include "malloc.h"
|
2017-11-13 05:58:05 +01:00
|
|
|
#include "reset_save_heap.h"
|
2017-11-09 01:58:59 +01:00
|
|
|
#include "save.h"
|
2017-11-11 02:55:03 +01:00
|
|
|
#include "bg.h"
|
|
|
|
#include "window.h"
|
2017-11-08 02:25:24 +01:00
|
|
|
#include "librfu.h"
|
2017-12-16 17:27:10 +01:00
|
|
|
#include "random.h"
|
2017-11-10 03:14:43 +01:00
|
|
|
#include "decompress.h"
|
2017-11-08 04:26:00 +01:00
|
|
|
#include "string_util.h"
|
|
|
|
#include "event_data.h"
|
2017-11-10 03:48:27 +01:00
|
|
|
#include "item_menu.h"
|
|
|
|
#include "overworld.h"
|
2017-11-08 02:25:24 +01:00
|
|
|
#include "gpu_regs.h"
|
|
|
|
#include "palette.h"
|
|
|
|
#include "task.h"
|
2017-11-13 05:16:51 +01:00
|
|
|
#include "unknown_task.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "new_menu_helpers.h"
|
|
|
|
#include "text.h"
|
2017-11-13 05:33:03 +01:00
|
|
|
#include "strings.h"
|
2018-01-18 18:53:31 +01:00
|
|
|
#include "constants/songs.h"
|
2017-11-13 05:16:51 +01:00
|
|
|
#include "sound.h"
|
2017-11-11 01:06:06 +01:00
|
|
|
#include "trade.h"
|
2017-11-13 04:24:15 +01:00
|
|
|
#include "battle.h"
|
2017-11-08 02:25:24 +01:00
|
|
|
#include "link.h"
|
2018-01-20 23:28:10 +01:00
|
|
|
#include "link_rfu.h"
|
2017-09-30 15:56:08 +02:00
|
|
|
|
|
|
|
// Static type declarations
|
|
|
|
|
|
|
|
struct BlockTransfer
|
|
|
|
{
|
|
|
|
u16 pos;
|
|
|
|
u16 size;
|
2017-11-11 01:37:38 +01:00
|
|
|
const u8 *src;
|
2017-09-30 15:56:08 +02:00
|
|
|
bool8 active;
|
|
|
|
u8 multiplayerId;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LinkTestBGInfo
|
|
|
|
{
|
|
|
|
u32 screenBaseBlock;
|
|
|
|
u32 paletteNum;
|
|
|
|
u32 dummy_8;
|
|
|
|
u32 dummy_C;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Static RAM declarations
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
IWRAM_DATA struct BlockTransfer sBlockSend;
|
2017-09-30 15:56:08 +02:00
|
|
|
IWRAM_DATA u32 link_c_unused_03000d1c;
|
2017-11-11 06:05:44 +01:00
|
|
|
IWRAM_DATA struct BlockTransfer sBlockRecv[MAX_LINK_PLAYERS];
|
|
|
|
IWRAM_DATA u32 sBlockSendDelayCounter;
|
2017-09-30 15:56:08 +02:00
|
|
|
IWRAM_DATA u32 gUnknown_03000D54;
|
|
|
|
IWRAM_DATA u8 gUnknown_03000D58;
|
2017-11-11 06:05:44 +01:00
|
|
|
IWRAM_DATA u32 sPlayerDataExchangeStatus;
|
2017-09-30 15:56:08 +02:00
|
|
|
IWRAM_DATA u32 gUnknown_03000D60;
|
2017-11-11 06:05:44 +01:00
|
|
|
IWRAM_DATA u8 sLinkTestLastBlockSendPos;
|
|
|
|
ALIGNED() IWRAM_DATA u8 sLinkTestLastBlockRecvPos[MAX_LINK_PLAYERS];
|
2017-11-14 14:44:32 +01:00
|
|
|
IWRAM_DATA u8 sNumVBlanksWithoutSerialIntr;
|
2017-11-17 03:38:06 +01:00
|
|
|
IWRAM_DATA bool8 sSendBufferEmpty;
|
2017-11-14 14:31:37 +01:00
|
|
|
IWRAM_DATA u16 sSendNonzeroCheck;
|
2017-11-17 03:38:06 +01:00
|
|
|
IWRAM_DATA u16 sRecvNonzeroCheck;
|
|
|
|
IWRAM_DATA u8 sChecksumAvailable;
|
2017-11-15 14:44:11 +01:00
|
|
|
IWRAM_DATA u8 sHandshakePlayerCount;
|
2017-09-30 15:56:08 +02:00
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
u16 gLinkPartnersHeldKeys[6];
|
2017-11-11 06:25:05 +01:00
|
|
|
u32 gLinkDebugSeed;
|
2017-11-11 06:05:44 +01:00
|
|
|
struct LinkPlayerBlock gLocalLinkPlayerBlock;
|
|
|
|
bool8 gLinkErrorOccurred;
|
2017-11-11 06:25:05 +01:00
|
|
|
u32 gLinkDebugFlags;
|
2017-11-14 14:31:37 +01:00
|
|
|
u32 gFiller_03003074;
|
|
|
|
bool8 gRemoteLinkPlayersNotReceived[MAX_LINK_PLAYERS];
|
|
|
|
u8 gBlockReceivedStatus[MAX_LINK_PLAYERS];
|
2017-11-11 06:25:05 +01:00
|
|
|
u32 gFiller_03003080;
|
2017-11-11 06:05:44 +01:00
|
|
|
u16 gLinkHeldKeys;
|
2017-11-13 07:46:22 +01:00
|
|
|
u16 gRecvCmds[MAX_RFU_PLAYERS][CMD_LENGTH];
|
2017-11-11 06:05:44 +01:00
|
|
|
u32 gLinkStatus;
|
2017-11-13 04:44:20 +01:00
|
|
|
bool8 gUnknown_030030E4;
|
2017-11-09 01:29:37 +01:00
|
|
|
bool8 gUnknown_030030E8;
|
2017-11-13 04:44:20 +01:00
|
|
|
bool8 gUnknown_030030EC[MAX_LINK_PLAYERS];
|
|
|
|
bool8 gUnknown_030030F0[MAX_LINK_PLAYERS];
|
2017-11-09 01:29:37 +01:00
|
|
|
u16 gUnknown_030030F4;
|
2017-11-11 06:05:44 +01:00
|
|
|
u8 gSuppressLinkErrorMessage;
|
2017-11-13 05:58:05 +01:00
|
|
|
bool8 gWirelessCommType;
|
2017-11-13 02:57:21 +01:00
|
|
|
bool8 gSavedLinkPlayerCount;
|
2017-11-13 07:46:22 +01:00
|
|
|
u16 gSendCmd[CMD_LENGTH];
|
2017-11-13 03:31:08 +01:00
|
|
|
u8 gSavedMultiplayerId;
|
2017-11-09 01:29:37 +01:00
|
|
|
bool8 gReceivedRemoteLinkPlayers;
|
2017-11-11 06:05:44 +01:00
|
|
|
struct LinkTestBGInfo gLinkTestBGInfo;
|
|
|
|
void (*gLinkCallback)(void);
|
2017-11-13 07:46:22 +01:00
|
|
|
u8 gShouldAdvanceLinkState;
|
2017-11-11 06:05:44 +01:00
|
|
|
u16 gLinkTestBlockChecksums[MAX_LINK_PLAYERS];
|
|
|
|
u8 gBlockRequestType;
|
2017-11-11 06:25:05 +01:00
|
|
|
u32 gFiller_03003154;
|
|
|
|
u32 gFiller_03003158;
|
|
|
|
u32 gFiller_0300315c;
|
2017-11-13 05:16:51 +01:00
|
|
|
u8 gLastSendQueueCount;
|
2017-11-11 06:05:44 +01:00
|
|
|
struct Link gLink;
|
2017-11-13 05:16:51 +01:00
|
|
|
u8 gLastRecvQueueCount;
|
2017-11-14 14:31:37 +01:00
|
|
|
u16 gLinkSavedIme;
|
2017-11-11 06:25:05 +01:00
|
|
|
u32 gFiller_03004138;
|
|
|
|
u32 gFiller_0300413C;
|
2017-11-09 01:29:37 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
EWRAM_DATA u8 gLinkTestDebugValuesEnabled = 0;
|
2017-11-11 02:27:02 +01:00
|
|
|
EWRAM_DATA u8 gUnknown_020223BD = 0;
|
|
|
|
EWRAM_DATA u32 gUnknown_020223C0 = 0;
|
2017-11-11 04:34:23 +01:00
|
|
|
EWRAM_DATA u16 gBlockRecvBuffer[MAX_RFU_PLAYERS][BLOCK_BUFFER_SIZE / 2] = {};
|
2017-11-11 06:05:44 +01:00
|
|
|
EWRAM_DATA u8 gBlockSendBuffer[BLOCK_BUFFER_SIZE] = {};
|
|
|
|
EWRAM_DATA bool8 gLinkOpen = FALSE;
|
|
|
|
EWRAM_DATA u16 gLinkType = 0;
|
|
|
|
EWRAM_DATA u16 gLinkTimeOutCounter = 0;
|
|
|
|
EWRAM_DATA struct LinkPlayer gLocalLinkPlayer = {};
|
2017-11-11 04:34:23 +01:00
|
|
|
EWRAM_DATA struct LinkPlayer gLinkPlayers[MAX_RFU_PLAYERS] = {};
|
2017-11-13 02:57:21 +01:00
|
|
|
EWRAM_DATA struct LinkPlayer gSavedLinkPlayers[MAX_RFU_PLAYERS] = {};
|
2017-11-13 04:09:11 +01:00
|
|
|
EWRAM_DATA struct {
|
|
|
|
u32 status;
|
2017-11-13 05:16:51 +01:00
|
|
|
u8 lastRecvQueueCount;
|
|
|
|
u8 lastSendQueueCount;
|
|
|
|
u8 unk_06;
|
|
|
|
} sLinkErrorBuffer = {};
|
2017-11-13 04:09:11 +01:00
|
|
|
EWRAM_DATA u16 gUnknown_02022B08 = 0;
|
|
|
|
EWRAM_DATA void *gUnknown_02022B0C = NULL;
|
2017-11-08 04:14:40 +01:00
|
|
|
|
2017-09-30 15:56:08 +02:00
|
|
|
// Static ROM declarations
|
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
static void InitLocalLinkPlayer(void);
|
|
|
|
static void sub_80096BC(void);
|
2017-11-11 06:05:44 +01:00
|
|
|
static void CB2_LinkTest(void);
|
|
|
|
static void ProcessRecvCmds(u8 unused);
|
2017-11-11 01:25:46 +01:00
|
|
|
static void sub_8009F70(void);
|
2017-11-11 06:05:44 +01:00
|
|
|
static void ResetBlockSend(void);
|
|
|
|
static bool32 InitBlockSend(const void *src, size_t size);
|
|
|
|
static void LinkCB_BlockSendBegin(void);
|
|
|
|
static void LinkCB_BlockSend(void);
|
|
|
|
static void LinkCB_BlockSendEnd(void);
|
|
|
|
static void SetBlockReceivedFlag(u8 who);
|
|
|
|
static u16 LinkTestCalcBlockChecksum(const u16 *src, u16 size);
|
|
|
|
static void LinkTest_prnthex(u32 pos, u8 a0, u8 a1, u8 a2);
|
|
|
|
static void LinkCB_RequestPlayerDataExchange(void);
|
2017-11-11 06:25:05 +01:00
|
|
|
static void Task_PrintTestData(u8 taskId);
|
2017-11-17 05:37:09 +01:00
|
|
|
|
2017-11-13 04:24:15 +01:00
|
|
|
static void sub_800AC80(void);
|
|
|
|
static void sub_800ACAC(void);
|
2017-11-13 04:30:00 +01:00
|
|
|
static void sub_800AD5C(void);
|
|
|
|
static void sub_800AD88(void);
|
2017-11-13 04:44:20 +01:00
|
|
|
static void sub_800AE30(void);
|
|
|
|
static void sub_800AE5C(void);
|
2017-11-17 05:37:09 +01:00
|
|
|
|
2017-11-13 07:46:22 +01:00
|
|
|
static void CheckErrorStatus(void);
|
|
|
|
static void CB2_PrintErrorMessage(void);
|
|
|
|
static bool8 IsSioMultiMaster(void);
|
2017-11-13 07:04:31 +01:00
|
|
|
static void sub_800B4A4(void);
|
2017-11-14 14:31:37 +01:00
|
|
|
static void DisableSerial(void);
|
|
|
|
static void EnableSerial(void);
|
|
|
|
static void CheckMasterOrSlave(void);
|
|
|
|
static void InitTimer(void);
|
|
|
|
static void EnqueueSendCmd(u16 *sendCmd);
|
|
|
|
static void DequeueRecvCmds(u16 (*recvCmds)[CMD_LENGTH]);
|
2017-11-17 05:37:09 +01:00
|
|
|
|
2017-11-15 14:44:11 +01:00
|
|
|
static void StartTransfer(void);
|
|
|
|
static bool8 DoHandshake(void);
|
2017-11-17 03:38:06 +01:00
|
|
|
static void DoRecv(void);
|
|
|
|
static void DoSend(void);
|
|
|
|
static void StopTimer(void);
|
|
|
|
static void SendRecvDone(void);
|
2017-11-13 07:46:22 +01:00
|
|
|
|
2017-09-30 15:56:08 +02:00
|
|
|
// .rodata
|
|
|
|
|
2017-11-08 02:25:24 +01:00
|
|
|
ALIGNED(4) const u16 gWirelessLinkDisplayPal[] = INCBIN_U16("graphics/interface/wireless_link_display.gbapal");
|
|
|
|
const u8 gWirelessLinkDisplayGfx[] = INCBIN_U8("graphics/interface/wireless_link_display.4bpp.lz");
|
|
|
|
const u8 gWirelessLinkDisplayTilemap[] = INCBIN_U8("graphics/interface/wireless_link_display.bin.lz");
|
|
|
|
const u16 gLinkTestDigitsPal[] = INCBIN_U16("graphics/interface/link_test_digits.gbapal");
|
|
|
|
const u16 gLinkTestDigitsGfx[] = INCBIN_U16("graphics/interface/link_test_digits.4bpp");
|
2017-11-08 03:45:44 +01:00
|
|
|
const u8 unkstring_82ed160[] = _("{HIGHLIGHT TRANSPARENT}{COLOR WHITE}");
|
|
|
|
const u16 g2BlankTilesGfx[] = INCBIN_U16("graphics/interface/blank_1x2.4bpp");
|
2017-11-10 03:14:43 +01:00
|
|
|
const struct BlockRequest gUnknown_082ED1A8[] = {
|
2017-11-11 06:05:44 +01:00
|
|
|
{gBlockSendBuffer, 200},
|
|
|
|
{gBlockSendBuffer, 200},
|
|
|
|
{gBlockSendBuffer, 100},
|
|
|
|
{gBlockSendBuffer, 220},
|
|
|
|
{gBlockSendBuffer, 40}
|
2017-11-08 03:45:44 +01:00
|
|
|
};
|
2017-11-11 06:05:44 +01:00
|
|
|
const u8 gBGControlRegs[] = {
|
2017-11-08 03:45:44 +01:00
|
|
|
REG_OFFSET_BG0CNT,
|
|
|
|
REG_OFFSET_BG1CNT,
|
|
|
|
REG_OFFSET_BG2CNT,
|
|
|
|
REG_OFFSET_BG3CNT
|
|
|
|
};
|
2017-11-10 03:14:43 +01:00
|
|
|
const char gASCIIGameFreakInc[] = "GameFreak inc.";
|
|
|
|
const char gASCIITestPrint[] = "TEST PRINT\nP0\nP1\nP2\nP3";
|
2017-11-11 02:55:03 +01:00
|
|
|
const struct BgTemplate gUnknown_082ED1FC[] = {
|
|
|
|
{
|
|
|
|
.bg = 0,
|
|
|
|
.charBaseIndex = 2,
|
|
|
|
.mapBaseIndex = 31,
|
|
|
|
.priority = 0
|
|
|
|
}, {
|
|
|
|
.bg = 1,
|
|
|
|
.charBaseIndex = 0,
|
|
|
|
.mapBaseIndex = 8,
|
|
|
|
.priority = 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const struct WindowTemplate gUnknown_082ED204[] = {
|
|
|
|
{0x00, 0x00, 0x00, 0x1E, 0x05, 0x0F, 0x0002},
|
|
|
|
{0x00, 0x00, 0x06, 0x1E, 0x07, 0x0F, 0x0098},
|
|
|
|
{0x00, 0x00, 0x0D, 0x1E, 0x07, 0x0F, 0x016A},
|
|
|
|
DUMMY_WIN_TEMPLATE
|
|
|
|
};
|
|
|
|
const u8 gUnknown_082ED224[] = {
|
|
|
|
0x00, 0x01, 0x02, 0x00,
|
|
|
|
0xff, 0xfe, 0xff, 0x00
|
|
|
|
};
|
2017-11-08 02:25:24 +01:00
|
|
|
|
2017-09-30 15:56:08 +02:00
|
|
|
// .text
|
2017-11-08 02:25:24 +01:00
|
|
|
|
|
|
|
bool8 sub_80093CC(void)
|
|
|
|
{
|
|
|
|
sub_800B488();
|
|
|
|
sub_800E700();
|
|
|
|
if (sub_800BEC0() == 0x8001)
|
|
|
|
{
|
|
|
|
rfu_REQ_stopMode();
|
|
|
|
rfu_waitREQComplete();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
sub_800B4A4();
|
2017-11-11 06:05:44 +01:00
|
|
|
CloseLink();
|
2017-11-08 02:25:24 +01:00
|
|
|
RestoreSerialTimer3IntrHandlers();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
void Task_DestroySelf(u8 taskId)
|
2017-11-08 02:25:24 +01:00
|
|
|
{
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void InitLinkTestBG(u8 paletteNum, u8 bgNum, u8 screenBaseBlock, u8 charBaseBlock, u16 a4)
|
2017-11-08 02:25:24 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
LoadPalette(gLinkTestDigitsPal, paletteNum * 16, 0x20);
|
|
|
|
DmaCopy16(3, gLinkTestDigitsGfx, (u16 *)BG_CHAR_ADDR(charBaseBlock) + (16 * a4), sizeof gLinkTestDigitsGfx);
|
|
|
|
gLinkTestBGInfo.screenBaseBlock = screenBaseBlock;
|
|
|
|
gLinkTestBGInfo.paletteNum = paletteNum;
|
|
|
|
gLinkTestBGInfo.dummy_8 = a4;
|
|
|
|
switch (bgNum)
|
2017-11-08 02:25:24 +01:00
|
|
|
{
|
|
|
|
case 1:
|
2017-11-11 06:05:44 +01:00
|
|
|
SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_SCREENBASE(screenBaseBlock) | BGCNT_PRIORITY(1) | BGCNT_CHARBASE(charBaseBlock));
|
2017-11-08 02:25:24 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-11-11 06:05:44 +01:00
|
|
|
SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_SCREENBASE(screenBaseBlock) | BGCNT_PRIORITY(1) | BGCNT_CHARBASE(charBaseBlock));
|
2017-11-08 02:25:24 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2017-11-11 06:05:44 +01:00
|
|
|
SetGpuReg(REG_OFFSET_BG3CNT, BGCNT_SCREENBASE(screenBaseBlock) | BGCNT_PRIORITY(1) | BGCNT_CHARBASE(charBaseBlock));
|
2017-11-08 02:25:24 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
SetGpuReg(REG_OFFSET_BG0HOFS + bgNum * 4, 0);
|
|
|
|
SetGpuReg(REG_OFFSET_BG0VOFS + bgNum * 4, 0);
|
2017-11-08 02:25:24 +01:00
|
|
|
}
|
2017-11-08 03:45:44 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
void sub_80094EC(u8 paletteNum, u8 bgNum, u8 screenBaseBlock, u8 charBaseBlock)
|
2017-11-08 03:45:44 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
LoadPalette(gLinkTestDigitsPal, paletteNum * 16, 0x20);
|
|
|
|
DmaCopy16(3, gLinkTestDigitsGfx, (u16 *)BG_CHAR_ADDR(charBaseBlock), sizeof gLinkTestDigitsGfx);
|
|
|
|
gLinkTestBGInfo.screenBaseBlock = screenBaseBlock;
|
|
|
|
gLinkTestBGInfo.paletteNum = paletteNum;
|
|
|
|
gLinkTestBGInfo.dummy_8 = 0;
|
|
|
|
SetGpuReg(gBGControlRegs[bgNum], BGCNT_SCREENBASE(screenBaseBlock) | BGCNT_CHARBASE(charBaseBlock));
|
2017-11-08 03:45:44 +01:00
|
|
|
}
|
2017-11-08 04:14:40 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
void LinkTestScreen(void)
|
2017-11-08 04:14:40 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ResetSpriteData();
|
|
|
|
FreeAllSpritePalettes();
|
|
|
|
ResetTasks();
|
|
|
|
SetVBlankCallback(sub_80096BC);
|
2017-11-11 06:05:44 +01:00
|
|
|
ResetBlockSend();
|
|
|
|
gLinkType = 0x1111;
|
|
|
|
OpenLink();
|
2017-11-08 04:14:40 +01:00
|
|
|
SeedRng(gMain.vblankCounter2);
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < MAX_LINK_PLAYERS; i++)
|
2017-11-08 04:14:40 +01:00
|
|
|
{
|
|
|
|
gSaveBlock2Ptr->playerTrainerId[i] = Random() % 256;
|
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
InitLinkTestBG(0, 2, 4, 0, 0);
|
2017-11-08 04:14:40 +01:00
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG2_ON | DISPCNT_OBJ_ON);
|
2017-11-11 06:05:44 +01:00
|
|
|
CreateTask(Task_DestroySelf, 0);
|
2017-11-08 04:14:40 +01:00
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
gUnknown_03000D60 = 0;
|
2017-11-11 06:05:44 +01:00
|
|
|
InitLocalLinkPlayer();
|
2017-11-11 06:25:05 +01:00
|
|
|
CreateTask(Task_PrintTestData, 0);
|
2017-11-11 06:05:44 +01:00
|
|
|
SetMainCallback2(CB2_LinkTest);
|
2017-11-08 04:14:40 +01:00
|
|
|
}
|
2017-11-08 04:26:00 +01:00
|
|
|
|
|
|
|
void sub_8009628(u8 a0)
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gLocalLinkPlayer.lp_field_18 = a0;
|
2017-11-08 04:26:00 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
static void InitLocalLinkPlayer(void)
|
2017-11-08 04:26:00 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gLocalLinkPlayer.trainerId = gSaveBlock2Ptr->playerTrainerId[0] | (gSaveBlock2Ptr->playerTrainerId[1] << 8) | (gSaveBlock2Ptr->playerTrainerId[2] << 16) | (gSaveBlock2Ptr->playerTrainerId[3] << 24);
|
|
|
|
StringCopy(gLocalLinkPlayer.name, gSaveBlock2Ptr->playerName);
|
|
|
|
gLocalLinkPlayer.gender = gSaveBlock2Ptr->playerGender;
|
|
|
|
gLocalLinkPlayer.linkType = gLinkType;
|
|
|
|
gLocalLinkPlayer.language = gGameLanguage;
|
|
|
|
gLocalLinkPlayer.version = gGameVersion + 0x4000;
|
|
|
|
gLocalLinkPlayer.lp_field_2 = 0x8000;
|
|
|
|
gLocalLinkPlayer.name[8] = IsNationalPokedexEnabled();
|
2017-12-16 17:27:10 +01:00
|
|
|
if (FlagGet(FLAG_0x87F))
|
2017-11-08 04:26:00 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gLocalLinkPlayer.name[8] |= 0x10;
|
2017-11-08 04:26:00 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-08 04:52:10 +01:00
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
static void sub_80096BC(void)
|
2017-11-08 04:52:10 +01:00
|
|
|
{
|
|
|
|
LoadOam();
|
|
|
|
ProcessSpriteCopyRequests();
|
|
|
|
TransferPlttBuffer();
|
|
|
|
}
|
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
static void InitLink(void)
|
2017-11-08 04:52:10 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < 8; i++)
|
2017-11-08 04:52:10 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gSendCmd[i] = 0xefff;
|
2017-11-08 04:52:10 +01:00
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkOpen = TRUE;
|
|
|
|
EnableSerial();
|
2017-11-08 04:52:10 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
static void Task_TriggerHandshake(u8 taskId)
|
2017-11-08 04:52:10 +01:00
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
if (++gTasks[taskId].data[0] == 5)
|
2017-11-08 04:52:10 +01:00
|
|
|
{
|
2017-11-13 07:46:22 +01:00
|
|
|
gShouldAdvanceLinkState = 1;
|
2017-11-08 04:52:10 +01:00
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
void OpenLink(void)
|
2017-11-08 04:52:10 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-11-13 05:58:05 +01:00
|
|
|
if (!gWirelessCommType)
|
2017-11-08 04:52:10 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
ResetSerial();
|
|
|
|
InitLink();
|
|
|
|
gLinkCallback = LinkCB_RequestPlayerDataExchange;
|
|
|
|
gLinkVSyncDisabled = FALSE;
|
|
|
|
gLinkErrorOccurred = FALSE;
|
|
|
|
gSuppressLinkErrorMessage = FALSE;
|
2017-11-08 04:52:10 +01:00
|
|
|
ResetBlockReceivedFlags();
|
2017-11-11 06:05:44 +01:00
|
|
|
ResetBlockSend();
|
2017-11-08 04:52:10 +01:00
|
|
|
gUnknown_03000D54 = 0;
|
2017-11-13 04:44:20 +01:00
|
|
|
gUnknown_030030E8 = FALSE;
|
|
|
|
gUnknown_030030E4 = FALSE;
|
2017-11-08 04:52:10 +01:00
|
|
|
gUnknown_030030F4 = 0;
|
2017-11-11 06:05:44 +01:00
|
|
|
CreateTask(Task_TriggerHandshake, 2);
|
2017-11-08 04:52:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sub_800E700();
|
|
|
|
}
|
|
|
|
gReceivedRemoteLinkPlayers = 0;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < MAX_LINK_PLAYERS; i++)
|
2017-11-08 04:52:10 +01:00
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
gRemoteLinkPlayersNotReceived[i] = TRUE;
|
2017-11-13 04:44:20 +01:00
|
|
|
gUnknown_030030F0[i] = FALSE;
|
|
|
|
gUnknown_030030EC[i] = FALSE;
|
2017-11-08 04:52:10 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-09 01:29:37 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
void CloseLink(void)
|
2017-11-09 01:29:37 +01:00
|
|
|
{
|
|
|
|
gReceivedRemoteLinkPlayers = FALSE;
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType)
|
2017-11-09 01:29:37 +01:00
|
|
|
{
|
|
|
|
sub_800EDD4();
|
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkOpen = FALSE;
|
|
|
|
DisableSerial();
|
2017-11-09 01:29:37 +01:00
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void TestBlockTransfer(u8 nothing, u8 is, u8 used)
|
2017-11-09 01:29:37 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 status;
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
if (sLinkTestLastBlockSendPos != sBlockSend.pos)
|
2017-11-09 01:29:37 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
LinkTest_prnthex(sBlockSend.pos, 2, 3, 2);
|
|
|
|
sLinkTestLastBlockSendPos = sBlockSend.pos;
|
2017-11-09 01:29:37 +01:00
|
|
|
}
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < MAX_LINK_PLAYERS; i++)
|
2017-11-09 01:29:37 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
if (sLinkTestLastBlockRecvPos[i] != sBlockRecv[i].pos)
|
2017-11-09 01:29:37 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
LinkTest_prnthex(sBlockRecv[i].pos, 2, i + 4, 2);
|
|
|
|
sLinkTestLastBlockRecvPos[i] = sBlockRecv[i].pos;
|
2017-11-09 01:29:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
status = GetBlockReceivedStatus();
|
|
|
|
if (status == 0xF) // 0b1111
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < MAX_LINK_PLAYERS; i++)
|
2017-11-09 01:29:37 +01:00
|
|
|
{
|
|
|
|
if ((status >> i) & 1)
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkTestBlockChecksums[i] = LinkTestCalcBlockChecksum(gBlockRecvBuffer[i], sBlockRecv[i].size);
|
2017-11-09 01:29:37 +01:00
|
|
|
ResetBlockReceivedFlag(i);
|
2017-11-11 06:05:44 +01:00
|
|
|
if (gLinkTestBlockChecksums[i] != 0x0342)
|
2017-11-09 01:29:37 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkTestDebugValuesEnabled = FALSE;
|
|
|
|
gUnknown_020223BD = FALSE;
|
2017-11-09 01:29:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-09 01:58:59 +01:00
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
static void LinkTestProcessKeyInput(void)
|
2017-11-09 01:58:59 +01:00
|
|
|
{
|
|
|
|
if (gMain.newKeys & A_BUTTON)
|
|
|
|
{
|
2017-11-13 07:46:22 +01:00
|
|
|
gShouldAdvanceLinkState = 1;
|
2017-11-09 01:58:59 +01:00
|
|
|
}
|
|
|
|
if (gMain.heldKeys & B_BUTTON)
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
InitBlockSend(gHeap + 0x4000, 0x00002004);
|
2017-11-09 01:58:59 +01:00
|
|
|
}
|
|
|
|
if (gMain.newKeys & L_BUTTON)
|
|
|
|
{
|
|
|
|
BeginNormalPaletteFade(-1, 0, 16, 0, 2);
|
|
|
|
}
|
|
|
|
if (gMain.newKeys & START_BUTTON)
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
SetSuppressLinkErrorMessage(TRUE);
|
2017-11-09 01:58:59 +01:00
|
|
|
}
|
|
|
|
if (gMain.newKeys & R_BUTTON)
|
|
|
|
{
|
|
|
|
TrySavingData(1);
|
|
|
|
}
|
|
|
|
if (gMain.newKeys & SELECT_BUTTON)
|
|
|
|
{
|
|
|
|
sub_800AC34();
|
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
if (gLinkTestDebugValuesEnabled)
|
2017-11-09 01:58:59 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
SetLinkDebugValues(gMain.vblankCounter2, gLinkCallback ? gLinkVSyncDisabled : gLinkVSyncDisabled | 0x10);
|
2017-11-09 01:58:59 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-09 02:11:29 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void CB2_LinkTest(void)
|
2017-11-09 02:11:29 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
LinkTestProcessKeyInput();
|
|
|
|
TestBlockTransfer(1, 1, 0);
|
2017-11-09 02:11:29 +01:00
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
u16 LinkMain2(const u16 *heldKeys)
|
2017-11-09 02:11:29 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
if (!gLinkOpen)
|
2017-11-09 02:11:29 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < 8; i++)
|
2017-11-09 02:11:29 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gSendCmd[i] = 0;
|
2017-11-09 02:11:29 +01:00
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkHeldKeys = *heldKeys;
|
|
|
|
if (gLinkStatus & LINK_STAT_CONN_ESTABLISHED)
|
2017-11-09 02:11:29 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
ProcessRecvCmds(SIO_MULTI_CNT->id);
|
|
|
|
if (gLinkCallback != NULL)
|
2017-11-09 02:11:29 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkCallback();
|
2017-11-09 02:11:29 +01:00
|
|
|
}
|
2017-11-13 07:46:22 +01:00
|
|
|
CheckErrorStatus();
|
2017-11-09 02:11:29 +01:00
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
return gLinkStatus;
|
2017-11-09 02:11:29 +01:00
|
|
|
}
|
2017-11-09 02:48:26 +01:00
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
static void HandleReceiveRemoteLinkPlayer(u8 who)
|
2017-11-09 02:48:26 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count = 0;
|
2017-11-14 14:31:37 +01:00
|
|
|
gRemoteLinkPlayersNotReceived[who] = FALSE;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < GetLinkPlayerCount_2(); i++)
|
2017-11-09 02:48:26 +01:00
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
count += gRemoteLinkPlayersNotReceived[i];
|
2017-11-09 02:48:26 +01:00
|
|
|
}
|
|
|
|
if (count == 0 && gReceivedRemoteLinkPlayers == 0)
|
|
|
|
{
|
|
|
|
gReceivedRemoteLinkPlayers = 1;
|
|
|
|
}
|
|
|
|
}
|
2017-11-10 03:14:43 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void ProcessRecvCmds(u8 unused)
|
2017-11-10 03:14:43 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < MAX_LINK_PLAYERS; i++)
|
2017-11-10 03:14:43 +01:00
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
gLinkPartnersHeldKeys[i] = 0;
|
2017-11-11 06:05:44 +01:00
|
|
|
if (gRecvCmds[i][0] == 0)
|
2017-11-10 03:14:43 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
switch (gRecvCmds[i][0])
|
2017-11-10 03:14:43 +01:00
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_SEND_LINK_TYPE:
|
2017-11-10 03:14:43 +01:00
|
|
|
{
|
|
|
|
struct LinkPlayerBlock *block;
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
InitLocalLinkPlayer();
|
|
|
|
block = &gLocalLinkPlayerBlock;
|
|
|
|
block->linkPlayer = gLocalLinkPlayer;
|
2017-11-10 03:14:43 +01:00
|
|
|
memcpy(block->magic1, gASCIIGameFreakInc, sizeof(block->magic1) - 1);
|
|
|
|
memcpy(block->magic2, gASCIIGameFreakInc, sizeof(block->magic2) - 1);
|
2017-11-11 06:05:44 +01:00
|
|
|
InitBlockSend(block, sizeof(*block));
|
2017-11-10 03:14:43 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_SEND_HELD_KEYS:
|
|
|
|
gLinkPartnersHeldKeys[i] = gRecvCmds[i][1];
|
2017-11-10 03:14:43 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0x5555:
|
2017-11-13 04:44:20 +01:00
|
|
|
gUnknown_030030E8 = TRUE;
|
2017-11-10 03:14:43 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0x5566:
|
2017-11-13 04:44:20 +01:00
|
|
|
gUnknown_030030E8 = TRUE;
|
2017-11-10 03:14:43 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_INIT_BLOCK:
|
2017-11-10 03:14:43 +01:00
|
|
|
{
|
|
|
|
struct BlockTransfer *blockRecv;
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
blockRecv = &sBlockRecv[i];
|
2017-11-10 03:14:43 +01:00
|
|
|
blockRecv->pos = 0;
|
2017-11-11 06:05:44 +01:00
|
|
|
blockRecv->size = gRecvCmds[i][1];
|
|
|
|
blockRecv->multiplayerId = gRecvCmds[i][2];
|
2017-11-10 03:14:43 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_CONT_BLOCK:
|
2017-11-10 03:14:43 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
if (sBlockRecv[i].size > BLOCK_BUFFER_SIZE)
|
2017-11-10 03:14:43 +01:00
|
|
|
{
|
|
|
|
u16 *buffer;
|
|
|
|
u16 j;
|
|
|
|
|
|
|
|
buffer = (u16 *)gDecompressionBuffer;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (j = 0; j < CMD_LENGTH - 1; j++)
|
2017-11-10 03:14:43 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
buffer[(sBlockRecv[i].pos / 2) + j] = gRecvCmds[i][j + 1];
|
2017-11-10 03:14:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
u16 j;
|
|
|
|
|
2017-11-17 03:38:06 +01:00
|
|
|
for (j = 0; j < CMD_LENGTH - 1; j++)
|
2017-11-10 03:14:43 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gBlockRecvBuffer[i][(sBlockRecv[i].pos / 2) + j] = gRecvCmds[i][j + 1];
|
2017-11-10 03:14:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
sBlockRecv[i].pos += (CMD_LENGTH - 1) * 2;
|
2017-11-10 03:14:43 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
if (sBlockRecv[i].pos >= sBlockRecv[i].size)
|
2017-11-10 03:14:43 +01:00
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
if (gRemoteLinkPlayersNotReceived[i] == TRUE)
|
2017-11-10 03:14:43 +01:00
|
|
|
{
|
|
|
|
struct LinkPlayerBlock *block;
|
|
|
|
struct LinkPlayer *linkPlayer;
|
|
|
|
|
|
|
|
block = (struct LinkPlayerBlock *)&gBlockRecvBuffer[i];
|
|
|
|
linkPlayer = &gLinkPlayers[i];
|
|
|
|
*linkPlayer = block->linkPlayer;
|
|
|
|
if ((linkPlayer->version & 0xFF) == VERSION_RUBY || (linkPlayer->version & 0xFF) == VERSION_SAPPHIRE)
|
|
|
|
{
|
|
|
|
linkPlayer->name[10] = 0;
|
|
|
|
linkPlayer->name[9] = 0;
|
|
|
|
linkPlayer->name[8] = 0;
|
|
|
|
}
|
|
|
|
sub_800B524(linkPlayer);
|
|
|
|
if (strcmp(block->magic1, gASCIIGameFreakInc) != 0
|
|
|
|
|| strcmp(block->magic2, gASCIIGameFreakInc) != 0)
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
SetMainCallback2(CB2_LinkError);
|
2017-11-10 03:14:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
HandleReceiveRemoteLinkPlayer(i);
|
2017-11-10 03:14:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
SetBlockReceivedFlag(i);
|
2017-11-10 03:14:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0x5FFF:
|
2017-11-13 04:44:20 +01:00
|
|
|
gUnknown_030030F0[i] = TRUE;
|
2017-11-10 03:14:43 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0x2FFE:
|
2017-11-13 04:44:20 +01:00
|
|
|
gUnknown_030030EC[i] = TRUE;
|
2017-11-10 03:14:43 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0xAAAA:
|
2017-11-10 03:14:43 +01:00
|
|
|
sub_800A418();
|
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0xCCCC:
|
2017-11-11 06:05:44 +01:00
|
|
|
SendBlock(0, gUnknown_082ED1A8[gRecvCmds[i][1]].address, gUnknown_082ED1A8[gRecvCmds[i][1]].size);
|
2017-11-10 03:14:43 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_SEND_HELD_KEYS_2:
|
|
|
|
gLinkPartnersHeldKeys[i] = gRecvCmds[i][1];
|
2017-11-10 03:14:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-10 03:48:27 +01:00
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
static void BuildSendCmd(u16 command)
|
2017-11-10 03:48:27 +01:00
|
|
|
{
|
|
|
|
switch (command)
|
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_SEND_LINK_TYPE:
|
|
|
|
gSendCmd[0] = LINKCMD_SEND_LINK_TYPE;
|
2017-11-11 06:05:44 +01:00
|
|
|
gSendCmd[1] = gLinkType;
|
2017-11-10 03:48:27 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0x2FFE:
|
|
|
|
gSendCmd[0] = LINKCMD_0x2FFE;
|
2017-11-10 03:48:27 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_SEND_HELD_KEYS:
|
|
|
|
gSendCmd[0] = LINKCMD_SEND_HELD_KEYS;
|
2017-11-11 06:05:44 +01:00
|
|
|
gSendCmd[1] = gMain.heldKeys;
|
2017-11-10 03:48:27 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0x5555:
|
|
|
|
gSendCmd[0] = LINKCMD_0x5555;
|
2017-11-10 03:48:27 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0x6666:
|
|
|
|
gSendCmd[0] = LINKCMD_0x6666;
|
2017-11-11 06:05:44 +01:00
|
|
|
gSendCmd[1] = 0;
|
2017-11-10 03:48:27 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0x7777:
|
2017-11-10 03:48:27 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
gSendCmd[0] = LINKCMD_0x7777;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < 5; i++)
|
2017-11-10 03:48:27 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gSendCmd[i + 1] = 0xEE;
|
2017-11-10 03:48:27 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_INIT_BLOCK:
|
|
|
|
gSendCmd[0] = LINKCMD_INIT_BLOCK;
|
2017-11-11 06:05:44 +01:00
|
|
|
gSendCmd[1] = sBlockSend.size;
|
|
|
|
gSendCmd[2] = sBlockSend.multiplayerId + 0x80;
|
2017-11-10 03:48:27 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0xAAAA:
|
|
|
|
gSendCmd[0] = LINKCMD_0xAAAA;
|
2017-11-10 03:48:27 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0xAAAB:
|
|
|
|
gSendCmd[0] = LINKCMD_0xAAAB;
|
2017-11-16 14:36:51 +01:00
|
|
|
gSendCmd[1] = gSpecialVar_ItemId;
|
2017-11-10 03:48:27 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0xCCCC:
|
|
|
|
gSendCmd[0] = LINKCMD_0xCCCC;
|
2017-11-11 06:05:44 +01:00
|
|
|
gSendCmd[1] = gBlockRequestType;
|
2017-11-10 03:48:27 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0x5FFF:
|
|
|
|
gSendCmd[0] = LINKCMD_0x5FFF;
|
2017-11-11 06:05:44 +01:00
|
|
|
gSendCmd[1] = gUnknown_030030F4;
|
2017-11-10 03:48:27 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_0x5566:
|
|
|
|
gSendCmd[0] = LINKCMD_0x5566;
|
2017-11-10 03:48:27 +01:00
|
|
|
break;
|
2017-11-14 14:31:37 +01:00
|
|
|
case LINKCMD_SEND_HELD_KEYS_2:
|
2017-11-11 06:05:44 +01:00
|
|
|
if (gUnknown_03005DA8 == 0 || gLinkTransferringData)
|
2017-11-10 03:48:27 +01:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2017-11-14 14:31:37 +01:00
|
|
|
gSendCmd[0] = LINKCMD_SEND_HELD_KEYS_2;
|
2017-11-11 06:05:44 +01:00
|
|
|
gSendCmd[1] = gUnknown_03005DA8;
|
2017-11-10 03:48:27 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-11-10 03:56:47 +01:00
|
|
|
|
|
|
|
void sub_8009F18(void)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType)
|
2017-11-10 03:56:47 +01:00
|
|
|
{
|
|
|
|
sub_800F804();
|
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkCallback = sub_8009F70;
|
2017-11-10 03:56:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool32 sub_8009F3C(void)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType)
|
2017-11-10 03:56:47 +01:00
|
|
|
{
|
|
|
|
return sub_800F7E4();
|
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
if (gLinkCallback == sub_8009F70)
|
2017-11-10 03:56:47 +01:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-11-11 01:25:46 +01:00
|
|
|
static void sub_8009F70(void)
|
2017-11-10 03:56:47 +01:00
|
|
|
{
|
|
|
|
if (gReceivedRemoteLinkPlayers == TRUE)
|
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
BuildSendCmd(LINKCMD_SEND_HELD_KEYS_2);
|
2017-11-10 03:56:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
void ClearLinkCallback(void)
|
2017-11-10 03:56:47 +01:00
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType)
|
2017-11-10 03:56:47 +01:00
|
|
|
{
|
|
|
|
Rfu_set_zero();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkCallback = NULL;
|
2017-11-10 03:56:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
void ClearLinkCallback_2(void)
|
2017-11-10 03:56:47 +01:00
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType)
|
2017-11-10 03:56:47 +01:00
|
|
|
{
|
|
|
|
Rfu_set_zero();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkCallback = NULL;
|
2017-11-10 03:56:47 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-10 14:37:50 +01:00
|
|
|
|
|
|
|
u8 GetLinkPlayerCount(void)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType)
|
2017-11-10 14:37:50 +01:00
|
|
|
{
|
|
|
|
return sub_80104F4();
|
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
return EXTRACT_PLAYER_COUNT(gLinkStatus);
|
2017-11-10 14:37:50 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
static int sub_8009FF8(u32 version1, u32 version2)
|
2017-11-10 14:37:50 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u8 nPlayers;
|
|
|
|
|
|
|
|
nPlayers = GetLinkPlayerCount();
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < nPlayers; i++)
|
2017-11-10 14:37:50 +01:00
|
|
|
{
|
|
|
|
if ((gLinkPlayers[i].version & 0xFF) == version1 || (gLinkPlayers[i].version & 0xFF) == version2)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 sub_800A03C(void)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool32 sub_800A040(void)
|
|
|
|
{
|
|
|
|
if (GetLinkPlayerCount() != 4 || sub_8009FF8(VERSION_RUBY, VERSION_SAPPHIRE) < 0)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool32 sub_800A064(void)
|
|
|
|
{
|
|
|
|
if (sub_8009FF8(VERSION_RUBY, VERSION_SAPPHIRE) >= 0)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool32 sub_800A07C(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = sub_8009FF8(VERSION_FIRE_RED, VERSION_LEAF_GREEN);
|
|
|
|
if (i >= 0 && gLinkPlayers[i].language == LANGUAGE_JAPANESE)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
void OpenLinkTimed(void)
|
2017-11-10 14:37:50 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
sPlayerDataExchangeStatus = EXCHANGE_NOT_STARTED;
|
|
|
|
gLinkTimeOutCounter = 0;
|
|
|
|
OpenLink();
|
2017-11-10 14:37:50 +01:00
|
|
|
}
|
2017-11-11 01:06:06 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
u8 GetLinkPlayerDataExchangeStatusTimed(int lower, int upper)
|
2017-11-11 01:06:06 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int count;
|
|
|
|
u32 index;
|
|
|
|
u8 cmpVal;
|
|
|
|
u32 linkType1;
|
|
|
|
u32 linkType2;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
if (gReceivedRemoteLinkPlayers == TRUE)
|
|
|
|
{
|
2017-11-13 03:31:08 +01:00
|
|
|
cmpVal = GetLinkPlayerCount_2();
|
2017-11-11 01:06:06 +01:00
|
|
|
if (lower > cmpVal || cmpVal > upper)
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
sPlayerDataExchangeStatus = EXCHANGE_STAT_6;
|
2017-11-11 01:06:06 +01:00
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (GetLinkPlayerCount() == 0)
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkErrorOccurred = TRUE;
|
|
|
|
CloseLink();
|
2017-11-11 01:06:06 +01:00
|
|
|
}
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0, index = 0; i < GetLinkPlayerCount(); index++, i++)
|
2017-11-11 01:06:06 +01:00
|
|
|
{
|
|
|
|
if (gLinkPlayers[index].linkType == gLinkPlayers[0].linkType)
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
count++;
|
2017-11-11 01:06:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count == GetLinkPlayerCount())
|
|
|
|
{
|
|
|
|
if (gLinkPlayers[0].linkType == 0x1133)
|
|
|
|
{
|
|
|
|
switch (sub_807A728())
|
|
|
|
{
|
|
|
|
case 1:
|
2017-11-11 06:05:44 +01:00
|
|
|
sPlayerDataExchangeStatus = EXCHANGE_STAT_4;
|
2017-11-11 01:06:06 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-11-11 06:05:44 +01:00
|
|
|
sPlayerDataExchangeStatus = EXCHANGE_STAT_5;
|
2017-11-11 01:06:06 +01:00
|
|
|
break;
|
|
|
|
case 0:
|
2017-11-11 06:05:44 +01:00
|
|
|
sPlayerDataExchangeStatus = EXCHANGE_COMPLETE;
|
2017-11-11 01:06:06 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
sPlayerDataExchangeStatus = EXCHANGE_COMPLETE;
|
2017-11-11 01:06:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
sPlayerDataExchangeStatus = EXCHANGE_IN_PROGRESS;
|
2017-11-11 01:06:06 +01:00
|
|
|
linkType1 = gLinkPlayers[GetMultiplayerId()].linkType;
|
|
|
|
linkType2 = gLinkPlayers[GetMultiplayerId() ^ 1].linkType;
|
|
|
|
if ((linkType1 == 0x2266 && linkType2 == 0x2277) || (linkType1 == 0x2277 && linkType2 == 0x2266))
|
|
|
|
{
|
|
|
|
gSpecialVar_0x8005 = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-17 03:38:06 +01:00
|
|
|
else if (++gLinkTimeOutCounter > 600)
|
2017-11-11 01:06:06 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
sPlayerDataExchangeStatus = EXCHANGE_TIMED_OUT;
|
2017-11-11 01:06:06 +01:00
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
return sPlayerDataExchangeStatus;
|
2017-11-11 01:06:06 +01:00
|
|
|
}
|
2017-11-11 01:14:35 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
bool8 IsLinkPlayerDataExchangeComplete(void)
|
2017-11-11 01:14:35 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 count;
|
|
|
|
bool8 retval;
|
|
|
|
|
|
|
|
count = 0;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < GetLinkPlayerCount(); i++)
|
2017-11-11 01:14:35 +01:00
|
|
|
{
|
|
|
|
if (gLinkPlayers[i].linkType == gLinkPlayers[0].linkType)
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
count++;
|
2017-11-11 01:14:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count == GetLinkPlayerCount())
|
|
|
|
{
|
|
|
|
retval = TRUE;
|
2017-11-11 06:05:44 +01:00
|
|
|
sPlayerDataExchangeStatus = EXCHANGE_COMPLETE;
|
2017-11-11 01:14:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
retval = FALSE;
|
2017-11-11 06:05:44 +01:00
|
|
|
sPlayerDataExchangeStatus = EXCHANGE_IN_PROGRESS;
|
2017-11-11 01:14:35 +01:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GetLinkPlayerTrainerId(u8 who)
|
|
|
|
{
|
|
|
|
return gLinkPlayers[who].trainerId;
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
void ResetLinkPlayers(void)
|
2017-11-11 01:14:35 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i <= MAX_LINK_PLAYERS; i++)
|
2017-11-11 01:14:35 +01:00
|
|
|
{
|
|
|
|
gLinkPlayers[i] = (struct LinkPlayer){};
|
|
|
|
}
|
|
|
|
}
|
2017-11-11 01:25:46 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void ResetBlockSend(void)
|
2017-11-11 01:25:46 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
sBlockSend.active = FALSE;
|
|
|
|
sBlockSend.pos = 0;
|
|
|
|
sBlockSend.size = 0;
|
|
|
|
sBlockSend.src = NULL;
|
2017-11-11 01:25:46 +01:00
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static bool32 InitBlockSend(const void *src, size_t size)
|
2017-11-11 01:25:46 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
if (sBlockSend.active)
|
2017-11-11 01:25:46 +01:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
sBlockSend.multiplayerId = GetMultiplayerId();
|
|
|
|
sBlockSend.active = TRUE;
|
|
|
|
sBlockSend.size = size;
|
|
|
|
sBlockSend.pos = 0;
|
2017-11-11 01:25:46 +01:00
|
|
|
if (size > 0x100)
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
sBlockSend.src = src;
|
2017-11-11 01:25:46 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
if (src != gBlockSendBuffer)
|
2017-11-11 01:25:46 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
memcpy(gBlockSendBuffer, src, size);
|
2017-11-11 01:25:46 +01:00
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
sBlockSend.src = gBlockSendBuffer;
|
2017-11-11 01:25:46 +01:00
|
|
|
}
|
2017-11-14 14:31:37 +01:00
|
|
|
BuildSendCmd(LINKCMD_INIT_BLOCK);
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkCallback = LinkCB_BlockSendBegin;
|
|
|
|
sBlockSendDelayCounter = 0;
|
2017-11-11 01:25:46 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2017-11-11 01:37:38 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void LinkCB_BlockSendBegin(void)
|
2017-11-11 01:37:38 +01:00
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
if (++sBlockSendDelayCounter > 2)
|
2017-11-11 01:37:38 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkCallback = LinkCB_BlockSend;
|
2017-11-11 01:37:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void LinkCB_BlockSend(void)
|
2017-11-11 01:37:38 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const u8 *src;
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
src = sBlockSend.src;
|
2017-11-14 14:31:37 +01:00
|
|
|
gSendCmd[0] = LINKCMD_CONT_BLOCK;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < 7; i++)
|
2017-11-11 01:37:38 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gSendCmd[i + 1] = (src[sBlockSend.pos + i * 2 + 1] << 8) | src[sBlockSend.pos + i * 2];
|
2017-11-11 01:37:38 +01:00
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
sBlockSend.pos += 14;
|
|
|
|
if (sBlockSend.size <= sBlockSend.pos)
|
2017-11-11 01:37:38 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
sBlockSend.active = FALSE;
|
|
|
|
gLinkCallback = LinkCB_BlockSendEnd;
|
2017-11-11 01:37:38 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-11 02:27:02 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void LinkCB_BlockSendEnd(void)
|
2017-11-11 02:27:02 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkCallback = NULL;
|
2017-11-11 02:27:02 +01:00
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void sub_800A3F8(void)
|
2017-11-11 02:27:02 +01:00
|
|
|
{
|
|
|
|
GetMultiplayerId();
|
2017-11-14 14:31:37 +01:00
|
|
|
BuildSendCmd(LINKCMD_SEND_HELD_KEYS);
|
2017-11-17 03:38:06 +01:00
|
|
|
gUnknown_020223C0++;
|
2017-11-11 02:27:02 +01:00
|
|
|
}
|
2017-11-11 02:47:24 +01:00
|
|
|
|
|
|
|
void sub_800A418(void)
|
|
|
|
{
|
|
|
|
gUnknown_020223C0 = 0;
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType)
|
2017-11-11 02:47:24 +01:00
|
|
|
{
|
|
|
|
sub_800F850();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gLinkCallback = sub_800A3F8;
|
2017-11-11 02:47:24 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-11 04:08:17 +01:00
|
|
|
|
|
|
|
u32 sub_800A44C(void)
|
|
|
|
{
|
|
|
|
return gUnknown_020223C0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800A458(void)
|
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
BuildSendCmd(LINKCMD_0xAAAA);
|
2017-11-11 04:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u8 GetMultiplayerId(void)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType == TRUE)
|
2017-11-11 04:08:17 +01:00
|
|
|
{
|
|
|
|
return rfu_get_multiplayer_id();
|
|
|
|
}
|
|
|
|
return SIO_MULTI_CNT->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 bitmask_all_link_players_but_self(void)
|
|
|
|
{
|
|
|
|
u8 mpId;
|
|
|
|
|
|
|
|
mpId = GetMultiplayerId();
|
|
|
|
return ((1 << MAX_LINK_PLAYERS) - 1) ^ (1 << mpId);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 SendBlock(u8 unused, const void *src, u16 size)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType == TRUE)
|
2017-11-11 04:08:17 +01:00
|
|
|
{
|
|
|
|
return sub_800FE84(src, size);
|
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
return InitBlockSend(src, size);
|
2017-11-11 04:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool8 sub_800A4D8(u8 a0)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType == TRUE)
|
2017-11-11 04:08:17 +01:00
|
|
|
{
|
|
|
|
return sub_8010100(a0);
|
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
if (gLinkCallback == NULL)
|
2017-11-11 04:08:17 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
gBlockRequestType = a0;
|
2017-11-14 14:31:37 +01:00
|
|
|
BuildSendCmd(LINKCMD_0xCCCC);
|
2017-11-11 04:08:17 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 sub_800A520(void)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType == TRUE)
|
2017-11-11 04:08:17 +01:00
|
|
|
{
|
|
|
|
return sub_8010500();
|
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
return gLinkCallback == NULL;
|
2017-11-11 04:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u8 GetBlockReceivedStatus(void)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType == TRUE)
|
2017-11-11 04:08:17 +01:00
|
|
|
{
|
|
|
|
return sub_800FCD8();
|
|
|
|
}
|
2017-11-14 14:31:37 +01:00
|
|
|
return (gBlockReceivedStatus[3] << 3) | (gBlockReceivedStatus[2] << 2) | (gBlockReceivedStatus[1] << 1) | (gBlockReceivedStatus[0] << 0);
|
2017-11-11 04:08:17 +01:00
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void SetBlockReceivedFlag(u8 who)
|
2017-11-11 04:08:17 +01:00
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType == TRUE)
|
2017-11-11 04:08:17 +01:00
|
|
|
{
|
|
|
|
sub_800F6FC(who);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
gBlockReceivedStatus[who] = TRUE;
|
2017-11-11 04:08:17 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-11 04:34:23 +01:00
|
|
|
|
|
|
|
void ResetBlockReceivedFlags(void)
|
|
|
|
{
|
|
|
|
int i;
|
2018-01-18 18:53:31 +01:00
|
|
|
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType == TRUE)
|
2017-11-11 04:34:23 +01:00
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
2017-11-11 04:34:23 +01:00
|
|
|
{
|
|
|
|
sub_800F728(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < MAX_LINK_PLAYERS; i++)
|
2017-11-11 04:34:23 +01:00
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
gBlockReceivedStatus[i] = FALSE;
|
2017-11-11 04:34:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetBlockReceivedFlag(u8 who)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType == TRUE)
|
2017-11-11 04:34:23 +01:00
|
|
|
{
|
|
|
|
sub_800F728(who);
|
|
|
|
}
|
2017-11-14 14:31:37 +01:00
|
|
|
else if (gBlockReceivedStatus[who])
|
2017-11-11 04:34:23 +01:00
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
gBlockReceivedStatus[who] = FALSE;
|
2017-11-11 04:34:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800A620(void)
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
if ((gLinkStatus & LINK_STAT_MASTER) && EXTRACT_PLAYER_COUNT(gLinkStatus) > 1)
|
2017-11-11 04:34:23 +01:00
|
|
|
{
|
2017-11-13 07:46:22 +01:00
|
|
|
gShouldAdvanceLinkState = 1;
|
2017-11-11 04:34:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static u16 LinkTestCalcBlockChecksum(const u16 *src, u16 size)
|
2017-11-11 04:34:23 +01:00
|
|
|
{
|
|
|
|
u16 chksum;
|
|
|
|
u16 i;
|
|
|
|
|
|
|
|
chksum = 0;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < size / 2; i++)
|
2017-11-11 04:34:23 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
chksum += src[i];
|
2017-11-11 04:34:23 +01:00
|
|
|
}
|
|
|
|
return chksum;
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void LinkTest_prnthexchar(char a0, u8 a1, u8 a2)
|
2017-11-11 04:34:23 +01:00
|
|
|
{
|
|
|
|
u16 *vAddr;
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
vAddr = (u16 *)BG_SCREEN_ADDR(gLinkTestBGInfo.screenBaseBlock);
|
|
|
|
vAddr[a2 * 32 + a1] = (gLinkTestBGInfo.paletteNum << 12) | (a0 + 1 + gLinkTestBGInfo.dummy_8);
|
2017-11-11 04:34:23 +01:00
|
|
|
}
|
2017-11-11 04:44:35 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void LinkTest_prntchar(char a0, u8 a1, u8 a2)
|
2017-11-11 04:44:35 +01:00
|
|
|
{
|
|
|
|
u16 *vAddr;
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
vAddr = (u16 *)BG_SCREEN_ADDR(gLinkTestBGInfo.screenBaseBlock);
|
|
|
|
vAddr[a2 * 32 + a1] = (gLinkTestBGInfo.paletteNum << 12) | (a0 + gLinkTestBGInfo.dummy_8);
|
2017-11-11 04:44:35 +01:00
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void LinkTest_prnthex(u32 pos, u8 a0, u8 a1, u8 a2)
|
2017-11-11 04:44:35 +01:00
|
|
|
{
|
2017-11-11 05:12:21 +01:00
|
|
|
char sp[32 / 2];
|
2017-11-11 04:44:35 +01:00
|
|
|
int i;
|
|
|
|
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < a2; i++)
|
2017-11-11 04:44:35 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
sp[i] = pos & 0xf;
|
|
|
|
pos >>= 4;
|
2017-11-11 04:44:35 +01:00
|
|
|
}
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = a2 - 1; i >= 0; i--)
|
2017-11-11 04:44:35 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
LinkTest_prnthexchar(sp[i], a0, a1);
|
2017-11-17 03:38:06 +01:00
|
|
|
a0++;
|
2017-11-11 04:44:35 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-11 04:54:40 +01:00
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void LinkTest_prntint(int a0, u8 a1, u8 a2, u8 a3)
|
2017-11-11 04:54:40 +01:00
|
|
|
{
|
2017-11-11 05:12:21 +01:00
|
|
|
char sp[32 / 2];
|
2017-11-11 04:54:40 +01:00
|
|
|
int sp10;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sp10 = -1;
|
|
|
|
if (a0 < 0)
|
|
|
|
{
|
|
|
|
sp10 = a1;
|
|
|
|
a0 = -a0;
|
|
|
|
}
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < a3; i++)
|
2017-11-11 04:54:40 +01:00
|
|
|
{
|
|
|
|
sp[i] = a0 % 10;
|
|
|
|
a0 /= 10;
|
|
|
|
}
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = a3 - 1; i >= 0; i--)
|
2017-11-11 04:54:40 +01:00
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
LinkTest_prnthexchar(sp[i], a1, a2);
|
2017-11-17 03:38:06 +01:00
|
|
|
a1++;
|
2017-11-11 04:54:40 +01:00
|
|
|
}
|
|
|
|
if (sp10 != -1)
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
LinkTest_prnthexchar(*"\n", sp10, a2);
|
2017-11-11 05:12:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:05:44 +01:00
|
|
|
static void LinkTest_prntstr(const char *a0, u8 a1, u8 a2)
|
2017-11-11 05:12:21 +01:00
|
|
|
{
|
|
|
|
int r6;
|
|
|
|
int i;
|
|
|
|
int r5;
|
|
|
|
|
|
|
|
r5 = 0;
|
|
|
|
r6 = 0;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; a0[i] != 0; a0++)
|
2017-11-11 05:12:21 +01:00
|
|
|
{
|
|
|
|
if (a0[i] == *"\n")
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
r5++;
|
2017-11-11 05:12:21 +01:00
|
|
|
r6 = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-11 06:05:44 +01:00
|
|
|
LinkTest_prntchar(a0[i], a1 + r6, a2 + r5);
|
2017-11-17 03:38:06 +01:00
|
|
|
r6++;
|
2017-11-11 05:12:21 +01:00
|
|
|
}
|
2017-11-11 04:54:40 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-11 06:05:44 +01:00
|
|
|
|
|
|
|
static void LinkCB_RequestPlayerDataExchange(void)
|
|
|
|
{
|
|
|
|
if (gLinkStatus & LINK_STAT_MASTER)
|
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
BuildSendCmd(LINKCMD_SEND_LINK_TYPE);
|
2017-11-11 06:05:44 +01:00
|
|
|
}
|
|
|
|
gLinkCallback = NULL;
|
|
|
|
}
|
|
|
|
|
2017-11-11 06:25:05 +01:00
|
|
|
static void Task_PrintTestData(u8 taskId)
|
2017-11-11 06:05:44 +01:00
|
|
|
{
|
|
|
|
char sp[32];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
strcpy(sp, gASCIITestPrint);
|
|
|
|
LinkTest_prntstr(sp, 5, 2);
|
|
|
|
LinkTest_prnthex(gShouldAdvanceLinkState, 2, 1, 2);
|
|
|
|
LinkTest_prnthex(gLinkStatus, 15, 1, 8);
|
|
|
|
LinkTest_prnthex(gLink.state, 2, 10, 2);
|
|
|
|
LinkTest_prnthex(EXTRACT_PLAYER_COUNT(gLinkStatus), 15, 10, 2);
|
|
|
|
LinkTest_prnthex(GetMultiplayerId(), 15, 12, 2);
|
2017-11-13 05:16:51 +01:00
|
|
|
LinkTest_prnthex(gLastSendQueueCount, 25, 1, 2);
|
|
|
|
LinkTest_prnthex(gLastRecvQueueCount, 25, 2, 2);
|
2017-11-11 06:05:44 +01:00
|
|
|
LinkTest_prnthex(GetBlockReceivedStatus(), 15, 5, 2);
|
2017-11-11 06:25:05 +01:00
|
|
|
LinkTest_prnthex(gLinkDebugSeed, 2, 12, 8);
|
|
|
|
LinkTest_prnthex(gLinkDebugFlags, 2, 13, 8);
|
2017-11-13 07:46:22 +01:00
|
|
|
LinkTest_prnthex(GetSioMultiSI(), 25, 5, 1);
|
|
|
|
LinkTest_prnthex(IsSioMultiMaster(), 25, 6, 1);
|
|
|
|
LinkTest_prnthex(IsLinkConnectionEstablished(), 25, 7, 1);
|
|
|
|
LinkTest_prnthex(HasLinkErrorOccurred(), 25, 8, 1);
|
2017-11-11 06:05:44 +01:00
|
|
|
for (i = 0; i < MAX_LINK_PLAYERS; i++)
|
|
|
|
{
|
|
|
|
LinkTest_prnthex(gLinkTestBlockChecksums[i], 10, 4 + i, 4);
|
|
|
|
}
|
|
|
|
}
|
2017-11-11 06:25:05 +01:00
|
|
|
|
|
|
|
void SetLinkDebugValues(u32 seed, u32 flags)
|
|
|
|
{
|
|
|
|
gLinkDebugSeed = seed;
|
|
|
|
gLinkDebugFlags = flags;
|
|
|
|
}
|
2017-11-11 15:56:47 +01:00
|
|
|
|
|
|
|
u8 sub_800A9A8(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u8 flags;
|
|
|
|
|
|
|
|
flags = 0;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < gSavedLinkPlayerCount; i++)
|
2017-11-11 15:56:47 +01:00
|
|
|
{
|
|
|
|
flags |= (1 << i);
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 sub_800A9D8(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u8 flags;
|
|
|
|
|
|
|
|
flags = 0;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < GetLinkPlayerCount(); i++)
|
2017-11-11 15:56:47 +01:00
|
|
|
{
|
|
|
|
flags |= (1 << i);
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800AA04(u8 a0)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-11-13 02:57:21 +01:00
|
|
|
gSavedLinkPlayerCount = a0;
|
2017-11-13 03:31:08 +01:00
|
|
|
gSavedMultiplayerId = GetMultiplayerId();
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < MAX_RFU_PLAYERS; i++)
|
2017-11-11 15:56:47 +01:00
|
|
|
{
|
2017-11-13 02:57:21 +01:00
|
|
|
gSavedLinkPlayers[i] = gLinkPlayers[i];
|
2017-11-11 15:56:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 sub_800AA48(void)
|
|
|
|
{
|
2017-11-13 02:57:21 +01:00
|
|
|
return gSavedLinkPlayerCount;
|
2017-11-11 15:56:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u8 sub_800AA54(void)
|
|
|
|
{
|
2017-11-13 03:31:08 +01:00
|
|
|
return gSavedMultiplayerId;
|
2017-11-11 15:56:47 +01:00
|
|
|
}
|
2017-11-13 02:57:21 +01:00
|
|
|
|
|
|
|
bool8 sub_800AA60(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned count;
|
|
|
|
|
|
|
|
count = 0;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < gSavedLinkPlayerCount; i++)
|
2017-11-13 02:57:21 +01:00
|
|
|
{
|
|
|
|
if (gLinkPlayers[i].trainerId == gSavedLinkPlayers[i].trainerId)
|
|
|
|
{
|
|
|
|
if (gLinkType == 0x2288)
|
|
|
|
{
|
|
|
|
if (gLinkType == gLinkPlayers[i].linkType)
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
count++;
|
2017-11-13 02:57:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
count++;
|
2017-11-13 02:57:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count == gSavedLinkPlayerCount)
|
|
|
|
{
|
2017-11-13 03:31:08 +01:00
|
|
|
if (GetLinkPlayerCount_2() == gSavedLinkPlayerCount)
|
2017-11-13 02:57:21 +01:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-11-13 03:26:11 +01:00
|
|
|
|
|
|
|
void sub_800AAF4(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// Clearly not what was meant to be written, but here it is anyway.
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < 4; i++)
|
2017-11-13 03:26:11 +01:00
|
|
|
{
|
|
|
|
CpuSet(&gSavedLinkPlayers[i], NULL, sizeof(struct LinkPlayer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800AB18(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < gSavedLinkPlayerCount; i++)
|
2017-11-13 03:26:11 +01:00
|
|
|
{
|
|
|
|
if (gSavedLinkPlayers[i].trainerId != gLinkPlayers[i].trainerId || StringCompare(gSavedLinkPlayers[i].name, gLinkPlayers[i].name) != 0)
|
|
|
|
{
|
|
|
|
gLinkErrorOccurred = TRUE;
|
|
|
|
CloseLink();
|
|
|
|
SetMainCallback2(CB2_LinkError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-13 03:31:08 +01:00
|
|
|
|
|
|
|
void sub_800AB98(void)
|
|
|
|
{
|
|
|
|
gSavedLinkPlayerCount = 0;
|
|
|
|
gSavedMultiplayerId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 GetLinkPlayerCount_2(void)
|
|
|
|
{
|
|
|
|
return EXTRACT_PLAYER_COUNT(gLinkStatus);
|
|
|
|
}
|
2017-11-13 04:09:11 +01:00
|
|
|
|
|
|
|
bool8 IsLinkMaster(void)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType)
|
2017-11-13 04:09:11 +01:00
|
|
|
{
|
|
|
|
return Rfu_IsMaster();
|
|
|
|
}
|
|
|
|
return EXTRACT_MASTER(gLinkStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 sub_800ABE8(void)
|
|
|
|
{
|
|
|
|
return gUnknown_03000D58;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800ABF4(u16 a0)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType == TRUE)
|
2017-11-13 04:09:11 +01:00
|
|
|
{
|
|
|
|
task_add_05_task_del_08FA224_when_no_RfuFunc();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gLinkCallback == NULL)
|
|
|
|
{
|
|
|
|
gLinkCallback = sub_800AC80;
|
2017-11-13 04:44:20 +01:00
|
|
|
gUnknown_030030E4 = FALSE;
|
2017-11-13 04:09:11 +01:00
|
|
|
gUnknown_030030F4 = a0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800AC34(void)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType == TRUE)
|
2017-11-13 04:09:11 +01:00
|
|
|
{
|
|
|
|
task_add_05_task_del_08FA224_when_no_RfuFunc();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gLinkCallback != NULL)
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
gUnknown_02022B08++;
|
2017-11-13 04:09:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gLinkCallback = sub_800AC80;
|
2017-11-13 04:44:20 +01:00
|
|
|
gUnknown_030030E4 = FALSE;
|
2017-11-13 04:09:11 +01:00
|
|
|
gUnknown_030030F4 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-13 04:24:15 +01:00
|
|
|
|
|
|
|
static void sub_800AC80(void)
|
|
|
|
{
|
2017-11-13 05:16:51 +01:00
|
|
|
if (gLastRecvQueueCount == 0)
|
2017-11-13 04:24:15 +01:00
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
BuildSendCmd(LINKCMD_0x5FFF);
|
2017-11-13 04:24:15 +01:00
|
|
|
gLinkCallback = sub_800ACAC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_800ACAC(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned count;
|
|
|
|
u8 linkPlayerCount;
|
|
|
|
|
|
|
|
linkPlayerCount = GetLinkPlayerCount();
|
|
|
|
count = 0;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < linkPlayerCount; i++)
|
2017-11-13 04:24:15 +01:00
|
|
|
{
|
|
|
|
if (gUnknown_030030F0[i])
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
count++;
|
2017-11-13 04:24:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count == linkPlayerCount)
|
|
|
|
{
|
|
|
|
gBattleTypeFlags &= ~BATTLE_TYPE_20;
|
|
|
|
gLinkVSyncDisabled = TRUE;
|
|
|
|
CloseLink();
|
|
|
|
gLinkCallback = NULL;
|
2017-11-13 04:44:20 +01:00
|
|
|
gUnknown_030030E4 = TRUE;
|
2017-11-13 04:24:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800AD10(void)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType == TRUE)
|
2017-11-13 04:24:15 +01:00
|
|
|
{
|
|
|
|
task_add_05_task_del_08FA224_when_no_RfuFunc();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gLinkCallback != NULL)
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
gUnknown_02022B08++;
|
2017-11-13 04:24:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gLinkCallback = sub_800AD5C;
|
2017-11-13 04:44:20 +01:00
|
|
|
gUnknown_030030E4 = FALSE;
|
2017-11-13 04:24:15 +01:00
|
|
|
gUnknown_030030F4 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-13 04:30:00 +01:00
|
|
|
|
|
|
|
static void sub_800AD5C(void)
|
|
|
|
{
|
2017-11-13 05:16:51 +01:00
|
|
|
if (gLastRecvQueueCount == 0)
|
2017-11-13 04:30:00 +01:00
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
BuildSendCmd(LINKCMD_0x5FFF);
|
2017-11-13 04:30:00 +01:00
|
|
|
gLinkCallback = sub_800AD88;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_800AD88(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned count;
|
|
|
|
u8 linkPlayerCount;
|
|
|
|
|
|
|
|
linkPlayerCount = GetLinkPlayerCount();
|
|
|
|
count = 0;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < linkPlayerCount; i++)
|
2017-11-13 04:30:00 +01:00
|
|
|
{
|
|
|
|
if (gLinkPlayers[i].language == LANGUAGE_JAPANESE)
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
count++;
|
2017-11-13 04:30:00 +01:00
|
|
|
}
|
|
|
|
else if (gUnknown_030030F0[i])
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
count++;
|
2017-11-13 04:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count == linkPlayerCount)
|
|
|
|
{
|
|
|
|
gBattleTypeFlags &= ~BATTLE_TYPE_20;
|
|
|
|
gLinkVSyncDisabled = TRUE;
|
|
|
|
CloseLink();
|
|
|
|
gLinkCallback = NULL;
|
2017-11-13 04:44:20 +01:00
|
|
|
gUnknown_030030E4 = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800ADF8(void)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType == TRUE)
|
2017-11-13 04:44:20 +01:00
|
|
|
{
|
|
|
|
sub_8010434();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gLinkCallback == NULL)
|
|
|
|
{
|
|
|
|
gLinkCallback = sub_800AE30;
|
|
|
|
}
|
|
|
|
gUnknown_030030E4 = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_800AE30(void)
|
|
|
|
{
|
2017-11-13 05:16:51 +01:00
|
|
|
if (gLastRecvQueueCount == 0)
|
2017-11-13 04:44:20 +01:00
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
BuildSendCmd(LINKCMD_0x2FFE);
|
2017-11-13 04:44:20 +01:00
|
|
|
gLinkCallback = sub_800AE5C;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_800AE5C(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 linkPlayerCount;
|
|
|
|
|
|
|
|
linkPlayerCount = GetLinkPlayerCount();
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < linkPlayerCount; i++)
|
2017-11-13 04:44:20 +01:00
|
|
|
{
|
|
|
|
if (!gUnknown_030030EC[i])
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == linkPlayerCount)
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < MAX_LINK_PLAYERS; i++)
|
2017-11-13 04:44:20 +01:00
|
|
|
{
|
|
|
|
gUnknown_030030EC[i] = FALSE;
|
|
|
|
}
|
|
|
|
gLinkCallback = NULL;
|
2017-11-13 04:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-13 05:16:51 +01:00
|
|
|
|
2017-11-13 07:46:22 +01:00
|
|
|
static void CheckErrorStatus(void)
|
2017-11-13 05:16:51 +01:00
|
|
|
{
|
|
|
|
if (gLinkOpen && EXTRACT_LINK_ERRORS(gLinkStatus))
|
|
|
|
{
|
|
|
|
if (!gSuppressLinkErrorMessage)
|
|
|
|
{
|
|
|
|
sLinkErrorBuffer.status = gLinkStatus;
|
|
|
|
sLinkErrorBuffer.lastRecvQueueCount = gLastRecvQueueCount;
|
|
|
|
sLinkErrorBuffer.lastSendQueueCount = gLastSendQueueCount;
|
|
|
|
SetMainCallback2(CB2_LinkError);
|
|
|
|
}
|
|
|
|
gLinkErrorOccurred = TRUE;
|
|
|
|
CloseLink();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800AF18(u32 status, u8 lastSendQueueCount, u8 lastRecvQueueCount, u8 unk_06)
|
|
|
|
{
|
|
|
|
sLinkErrorBuffer.status = status;
|
|
|
|
sLinkErrorBuffer.lastSendQueueCount = lastSendQueueCount;
|
|
|
|
sLinkErrorBuffer.lastRecvQueueCount = lastRecvQueueCount;
|
|
|
|
sLinkErrorBuffer.unk_06 = unk_06;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CB2_LinkError(void)
|
|
|
|
{
|
|
|
|
u8 *tilemapBuffer;
|
|
|
|
|
|
|
|
SetGpuReg(REG_OFFSET_DISPCNT, 0);
|
2018-01-18 18:53:31 +01:00
|
|
|
m4aMPlayStop(&gMPlayInfo_SE1);
|
|
|
|
m4aMPlayStop(&gMPlayInfo_SE2);
|
|
|
|
m4aMPlayStop(&gMPlayInfo_SE3);
|
2017-11-13 05:16:51 +01:00
|
|
|
InitHeap(gHeap, HEAP_SIZE);
|
|
|
|
ResetSpriteData();
|
|
|
|
FreeAllSpritePalettes();
|
|
|
|
ResetPaletteFadeControl();
|
|
|
|
FillPalette(0, 0, 2);
|
|
|
|
ResetTasks();
|
2018-01-22 05:20:13 +01:00
|
|
|
ScanlineEffect_Stop();
|
2017-11-13 05:58:05 +01:00
|
|
|
if (gWirelessCommType)
|
2017-11-13 05:16:51 +01:00
|
|
|
{
|
|
|
|
if (!sLinkErrorBuffer.unk_06)
|
|
|
|
{
|
2017-11-13 05:58:05 +01:00
|
|
|
gWirelessCommType = 3;
|
2017-11-13 05:16:51 +01:00
|
|
|
}
|
|
|
|
sub_800E604();
|
|
|
|
}
|
|
|
|
SetVBlankCallback(sub_80096BC);
|
|
|
|
ResetBgsAndClearDma3BusyFlags(0);
|
|
|
|
InitBgsFromTemplates(0, gUnknown_082ED1FC, 2);
|
|
|
|
gUnknown_02022B0C = tilemapBuffer = malloc(0x800);
|
|
|
|
SetBgTilemapBuffer(1, tilemapBuffer);
|
|
|
|
if (InitWindows(gUnknown_082ED204))
|
|
|
|
{
|
|
|
|
DeactivateAllTextPrinters();
|
|
|
|
reset_temp_tile_data_buffers();
|
|
|
|
SetGpuReg(REG_OFFSET_BLDCNT, 0);
|
|
|
|
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
|
|
|
|
SetGpuReg(REG_OFFSET_BG0HOFS, 0);
|
|
|
|
SetGpuReg(REG_OFFSET_BG0VOFS, 0);
|
|
|
|
SetGpuReg(REG_OFFSET_BG1HOFS, 0);
|
|
|
|
SetGpuReg(REG_OFFSET_BG1VOFS, 0);
|
|
|
|
ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON | DISPCNT_WIN1_ON | DISPCNT_OBJWIN_ON);
|
|
|
|
LoadPalette(gUnknown_0860F074, 0xf0, 0x20);
|
|
|
|
gSoftResetDisabled = FALSE;
|
|
|
|
CreateTask(Task_DestroySelf, 0);
|
|
|
|
StopMapMusic();
|
|
|
|
gMain.callback1 = NULL;
|
|
|
|
RunTasks();
|
|
|
|
AnimateSprites();
|
|
|
|
BuildOamBuffer();
|
|
|
|
UpdatePaletteFade();
|
2017-11-13 07:46:22 +01:00
|
|
|
SetMainCallback2(CB2_PrintErrorMessage);
|
2017-11-13 05:16:51 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-13 05:33:03 +01:00
|
|
|
|
2017-11-13 06:15:31 +01:00
|
|
|
static void sub_800B080(void)
|
2017-11-13 05:33:03 +01:00
|
|
|
{
|
|
|
|
LoadBgTiles(0, g2BlankTilesGfx, 0x20, 0);
|
|
|
|
copy_decompressed_tile_data_to_vram_autofree(1, gWirelessLinkDisplayGfx, FALSE, 0, 0);
|
|
|
|
CopyToBgTilemapBuffer(1, gWirelessLinkDisplayTilemap, 0, 0);
|
|
|
|
CopyBgTilemapBufferToVram(1);
|
|
|
|
LoadPalette(gWirelessLinkDisplayPal, 0, 0x20);
|
|
|
|
FillWindowPixelBuffer(0, 0x00);
|
|
|
|
FillWindowPixelBuffer(2, 0x00);
|
|
|
|
box_print(0, 3, 2, 6, gUnknown_082ED224, 0, gText_CommErrorEllipsis);
|
|
|
|
box_print(2, 3, 2, 1, gUnknown_082ED224, 0, gText_MoveCloserToLinkPartner);
|
|
|
|
PutWindowTilemap(0);
|
|
|
|
PutWindowTilemap(2);
|
|
|
|
CopyWindowToVram(0, 0);
|
|
|
|
CopyWindowToVram(2, 3);
|
|
|
|
}
|
2017-11-13 05:58:05 +01:00
|
|
|
|
2017-11-13 06:15:31 +01:00
|
|
|
static void sub_800B138(void)
|
2017-11-13 05:58:05 +01:00
|
|
|
{
|
|
|
|
LoadBgTiles(0, g2BlankTilesGfx, 0x20, 0);
|
|
|
|
FillWindowPixelBuffer(1, 0x00);
|
|
|
|
FillWindowPixelBuffer(2, 0x00);
|
|
|
|
box_print(1, 3, 2, 0, gUnknown_082ED224, 0, gText_CommErrorCheckConnections);
|
|
|
|
PutWindowTilemap(1);
|
|
|
|
PutWindowTilemap(2);
|
|
|
|
CopyWindowToVram(1, 0);
|
|
|
|
CopyWindowToVram(2, 3);
|
|
|
|
}
|
|
|
|
|
2017-11-13 07:46:22 +01:00
|
|
|
static void CB2_PrintErrorMessage(void)
|
2017-11-13 05:58:05 +01:00
|
|
|
{
|
|
|
|
switch (gMain.state)
|
|
|
|
{
|
|
|
|
case 00:
|
|
|
|
if (sLinkErrorBuffer.unk_06)
|
|
|
|
{
|
|
|
|
sub_800B080();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sub_800B138();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 02:
|
|
|
|
ShowBg(0);
|
|
|
|
if (sLinkErrorBuffer.unk_06)
|
|
|
|
{
|
|
|
|
ShowBg(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 30:
|
|
|
|
PlaySE(SE_BOO);
|
|
|
|
break;
|
|
|
|
case 60:
|
|
|
|
PlaySE(SE_BOO);
|
|
|
|
break;
|
|
|
|
case 90:
|
|
|
|
PlaySE(SE_BOO);
|
|
|
|
break;
|
|
|
|
case 130:
|
|
|
|
if (gWirelessCommType == 2)
|
|
|
|
{
|
|
|
|
box_print(0, 3, 2, 20, gUnknown_082ED224, 0, gText_ABtnTitleScreen);
|
|
|
|
}
|
|
|
|
else if (gWirelessCommType == 1)
|
|
|
|
{
|
|
|
|
box_print(0, 3, 2, 20, gUnknown_082ED224, 0, gText_ABtnRegistrationCounter);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (gMain.state == 160)
|
|
|
|
{
|
|
|
|
if (gWirelessCommType == 1)
|
|
|
|
{
|
|
|
|
if (gMain.newKeys & A_BUTTON)
|
|
|
|
{
|
|
|
|
PlaySE(SE_PIN);
|
|
|
|
gWirelessCommType = 0;
|
|
|
|
sLinkErrorBuffer.unk_06 = 0;
|
|
|
|
sub_81700F8();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (gWirelessCommType == 2)
|
|
|
|
{
|
|
|
|
if (gMain.newKeys & A_BUTTON)
|
|
|
|
{
|
|
|
|
rfu_REQ_stopMode();
|
|
|
|
rfu_waitREQComplete();
|
|
|
|
DoSoftReset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gMain.state != 160)
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
gMain.state++;
|
2017-11-13 05:58:05 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-13 06:15:31 +01:00
|
|
|
|
2017-11-17 04:13:42 +01:00
|
|
|
// TODO: there might be a file boundary here, let's name it
|
|
|
|
|
2017-11-13 07:46:22 +01:00
|
|
|
bool8 GetSioMultiSI(void)
|
2017-11-13 06:15:31 +01:00
|
|
|
{
|
|
|
|
return (REG_SIOCNT & 0x04) != 0;
|
|
|
|
}
|
|
|
|
|
2017-11-13 07:46:22 +01:00
|
|
|
static bool8 IsSioMultiMaster(void)
|
2017-11-13 06:15:31 +01:00
|
|
|
{
|
|
|
|
return (REG_SIOCNT & 0x8) && !(REG_SIOCNT & 0x04);
|
|
|
|
}
|
|
|
|
|
2017-11-13 07:46:22 +01:00
|
|
|
bool8 IsLinkConnectionEstablished(void)
|
2017-11-13 06:15:31 +01:00
|
|
|
{
|
|
|
|
return EXTRACT_CONN_ESTABLISHED(gLinkStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetSuppressLinkErrorMessage(bool8 flag)
|
|
|
|
{
|
|
|
|
gSuppressLinkErrorMessage = flag;
|
|
|
|
}
|
|
|
|
|
2017-11-13 07:46:22 +01:00
|
|
|
bool8 HasLinkErrorOccurred(void)
|
2017-11-13 06:15:31 +01:00
|
|
|
{
|
|
|
|
return gLinkErrorOccurred;
|
|
|
|
}
|
2017-11-13 06:31:27 +01:00
|
|
|
|
|
|
|
void sub_800B348(void)
|
|
|
|
{
|
|
|
|
struct LinkPlayerBlock *block;
|
|
|
|
|
|
|
|
InitLocalLinkPlayer();
|
|
|
|
block = &gLocalLinkPlayerBlock;
|
|
|
|
block->linkPlayer = gLocalLinkPlayer;
|
|
|
|
memcpy(block->magic1, gASCIIGameFreakInc, sizeof(block->magic1) - 1);
|
|
|
|
memcpy(block->magic2, gASCIIGameFreakInc, sizeof(block->magic2) - 1);
|
|
|
|
memcpy(gBlockSendBuffer, block, sizeof(*block));
|
|
|
|
}
|
|
|
|
|
2018-01-20 22:38:44 +01:00
|
|
|
void sub_800B3A4(u32 who)
|
2017-11-13 06:31:27 +01:00
|
|
|
{
|
2018-01-20 22:38:44 +01:00
|
|
|
u8 who_ = who;
|
2017-11-13 06:31:27 +01:00
|
|
|
struct LinkPlayerBlock *block;
|
|
|
|
struct LinkPlayer *player;
|
|
|
|
|
2018-01-20 22:38:44 +01:00
|
|
|
block = (struct LinkPlayerBlock *)gBlockRecvBuffer[who_];
|
|
|
|
player = &gLinkPlayers[who_];
|
2017-11-13 06:31:27 +01:00
|
|
|
*player = block->linkPlayer;
|
|
|
|
sub_800B524(player);
|
|
|
|
if (strcmp(block->magic1, gASCIIGameFreakInc) != 0 || strcmp(block->magic2, gASCIIGameFreakInc) != 0)
|
|
|
|
{
|
|
|
|
SetMainCallback2(CB2_LinkError);
|
|
|
|
}
|
|
|
|
}
|
2017-11-13 07:01:27 +01:00
|
|
|
|
|
|
|
bool8 HandleLinkConnection(void)
|
|
|
|
{
|
|
|
|
bool32 r4;
|
|
|
|
bool32 r5;
|
|
|
|
|
|
|
|
if (gWirelessCommType == 0)
|
|
|
|
{
|
2017-11-13 07:46:22 +01:00
|
|
|
gLinkStatus = LinkMain1(&gShouldAdvanceLinkState, gSendCmd, gRecvCmds);
|
2017-11-13 07:01:27 +01:00
|
|
|
LinkMain2(&gMain.heldKeys);
|
|
|
|
if ((gLinkStatus & LINK_STAT_RECEIVED_NOTHING) && sub_808766C() == TRUE)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r4 = sub_8010EC0();
|
|
|
|
r5 = sub_8010F1C();
|
|
|
|
if (sub_808766C() == TRUE)
|
|
|
|
{
|
|
|
|
if (r4 == TRUE || sub_800F0B8() || r5)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-11-13 07:04:31 +01:00
|
|
|
|
|
|
|
void sub_800B488(void)
|
|
|
|
{
|
|
|
|
if (gReceivedRemoteLinkPlayers == 0)
|
|
|
|
{
|
|
|
|
gWirelessCommType = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_800B4A4(void)
|
|
|
|
{
|
|
|
|
if (gReceivedRemoteLinkPlayers == 0)
|
|
|
|
{
|
|
|
|
gWirelessCommType = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800B4C0(void)
|
|
|
|
{
|
|
|
|
if (gReceivedRemoteLinkPlayers == 0)
|
|
|
|
{
|
|
|
|
gWirelessCommType = 0;
|
|
|
|
}
|
|
|
|
}
|
2017-11-13 07:12:34 +01:00
|
|
|
|
|
|
|
u32 sub_800B4DC(void)
|
|
|
|
{
|
|
|
|
if (gWirelessCommType != 0)
|
|
|
|
{
|
|
|
|
return sub_80124D4();
|
|
|
|
}
|
|
|
|
return gLink.recvQueue.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 sub_800B504(void)
|
|
|
|
{
|
|
|
|
if (sub_800B4DC() > 2)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 sub_800B518(void)
|
|
|
|
{
|
|
|
|
return gWirelessCommType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_800B524(struct LinkPlayer *player)
|
|
|
|
{
|
|
|
|
player->name[10] = player->name[8];
|
|
|
|
ConvertInternationalString(player->name, player->language);
|
|
|
|
}
|
2017-11-13 07:20:38 +01:00
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
static void DisableSerial(void)
|
2017-11-13 07:20:38 +01:00
|
|
|
{
|
|
|
|
DisableInterrupts(INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL);
|
|
|
|
REG_SIOCNT = SIO_MULTI_MODE;
|
|
|
|
REG_TMCNT_H(3) = 0;
|
|
|
|
REG_IF = INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL;
|
|
|
|
REG_SIOMLT_SEND = 0;
|
|
|
|
REG_SIOMLT_RECV = 0;
|
|
|
|
CpuFill32(0, &gLink, sizeof(gLink));
|
|
|
|
}
|
2017-11-13 07:24:28 +01:00
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
static void EnableSerial(void)
|
2017-11-13 07:24:28 +01:00
|
|
|
{
|
|
|
|
DisableInterrupts(INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL);
|
|
|
|
REG_RCNT = 0;
|
|
|
|
REG_SIOCNT = SIO_MULTI_MODE;
|
|
|
|
REG_SIOCNT |= SIO_115200_BPS | SIO_INTR_ENABLE;
|
|
|
|
EnableInterrupts(INTR_FLAG_SERIAL);
|
|
|
|
REG_SIOMLT_SEND = 0;
|
|
|
|
CpuFill32(0, &gLink, sizeof(gLink));
|
2017-11-14 14:44:32 +01:00
|
|
|
sNumVBlanksWithoutSerialIntr = 0;
|
2017-11-14 14:31:37 +01:00
|
|
|
sSendNonzeroCheck = 0;
|
2017-11-17 03:38:06 +01:00
|
|
|
sRecvNonzeroCheck = 0;
|
|
|
|
sChecksumAvailable = 0;
|
2017-11-15 14:44:11 +01:00
|
|
|
sHandshakePlayerCount = 0;
|
2017-11-13 07:24:28 +01:00
|
|
|
gLastSendQueueCount = 0;
|
|
|
|
gLastRecvQueueCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetSerial(void)
|
|
|
|
{
|
|
|
|
EnableSerial();
|
|
|
|
DisableSerial();
|
|
|
|
}
|
2017-11-13 07:46:22 +01:00
|
|
|
|
2017-11-17 04:13:42 +01:00
|
|
|
// link_main1.c
|
|
|
|
|
2017-11-13 07:46:22 +01:00
|
|
|
u32 LinkMain1(u8 *shouldAdvanceLinkState, u16 *sendCmd, u16 (*recvCmds)[CMD_LENGTH])
|
|
|
|
{
|
|
|
|
u32 retVal;
|
|
|
|
u32 retVal2;
|
|
|
|
|
|
|
|
switch (gLink.state)
|
|
|
|
{
|
|
|
|
case LINK_STATE_START0:
|
|
|
|
DisableSerial();
|
|
|
|
gLink.state = 1;
|
|
|
|
break;
|
|
|
|
case LINK_STATE_START1:
|
|
|
|
if (*shouldAdvanceLinkState == 1)
|
|
|
|
{
|
|
|
|
EnableSerial();
|
|
|
|
gLink.state = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LINK_STATE_HANDSHAKE:
|
|
|
|
switch (*shouldAdvanceLinkState)
|
|
|
|
{
|
|
|
|
default:
|
2017-11-14 14:31:37 +01:00
|
|
|
CheckMasterOrSlave();
|
2017-11-13 07:46:22 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2017-11-14 14:31:37 +01:00
|
|
|
if (gLink.isMaster == LINK_MASTER && gLink.playerCount > 1)
|
2017-11-13 07:46:22 +01:00
|
|
|
{
|
|
|
|
gLink.handshakeAsMaster = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
gLink.state = LINK_STATE_START0;
|
|
|
|
REG_SIOMLT_SEND = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LINK_STATE_INIT_TIMER:
|
2017-11-14 14:31:37 +01:00
|
|
|
InitTimer();
|
2017-11-13 07:46:22 +01:00
|
|
|
gLink.state = LINK_STATE_CONN_ESTABLISHED;
|
|
|
|
// fallthrough
|
|
|
|
case LINK_STATE_CONN_ESTABLISHED:
|
2017-11-14 14:31:37 +01:00
|
|
|
EnqueueSendCmd(sendCmd);
|
|
|
|
DequeueRecvCmds(recvCmds);
|
2017-11-13 07:46:22 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
*shouldAdvanceLinkState = 0;
|
|
|
|
retVal = gLink.localId;
|
2017-11-14 14:31:37 +01:00
|
|
|
retVal |= (gLink.playerCount << LINK_STAT_PLAYER_COUNT_SHIFT);
|
|
|
|
if (gLink.isMaster == LINK_MASTER)
|
2017-11-13 07:46:22 +01:00
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
retVal |= LINK_STAT_MASTER;
|
2017-11-13 07:46:22 +01:00
|
|
|
}
|
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
u32 receivedNothing = gLink.receivedNothing << LINK_STAT_RECEIVED_NOTHING_SHIFT;
|
|
|
|
u32 link_field_F = gLink.link_field_F << LINK_STAT_UNK_FLAG_9_SHIFT;
|
|
|
|
u32 hardwareError = gLink.hardwareError << LINK_STAT_ERROR_HARDWARE_SHIFT;
|
|
|
|
u32 badChecksum = gLink.badChecksum << LINK_STAT_ERROR_CHECKSUM_SHIFT;
|
|
|
|
u32 queueFull = gLink.queueFull << LINK_STAT_ERROR_QUEUE_FULL_SHIFT;
|
2017-11-13 07:46:22 +01:00
|
|
|
u32 val;
|
|
|
|
|
|
|
|
if (gLink.state == LINK_STATE_CONN_ESTABLISHED)
|
|
|
|
{
|
2017-11-14 14:31:37 +01:00
|
|
|
val = LINK_STAT_CONN_ESTABLISHED;
|
2017-11-13 07:46:22 +01:00
|
|
|
val |= receivedNothing;
|
|
|
|
val |= retVal;
|
|
|
|
val |= link_field_F;
|
|
|
|
val |= hardwareError;
|
|
|
|
val |= badChecksum;
|
|
|
|
val |= queueFull;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val = retVal;
|
|
|
|
val |= receivedNothing;
|
|
|
|
val |= link_field_F;
|
|
|
|
val |= hardwareError;
|
|
|
|
val |= badChecksum;
|
|
|
|
val |= queueFull;
|
|
|
|
}
|
|
|
|
|
|
|
|
retVal = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gLink.lag == LAG_MASTER)
|
2017-11-14 14:31:37 +01:00
|
|
|
{
|
|
|
|
retVal |= LINK_STAT_ERROR_LAG_MASTER;
|
|
|
|
}
|
2017-11-13 07:46:22 +01:00
|
|
|
|
2017-11-14 14:31:37 +01:00
|
|
|
if (gLink.localId >= MAX_LINK_PLAYERS)
|
|
|
|
{
|
|
|
|
retVal |= LINK_STAT_ERROR_INVALID_ID;
|
|
|
|
}
|
2017-11-13 07:46:22 +01:00
|
|
|
|
|
|
|
retVal2 = retVal;
|
|
|
|
if (gLink.lag == LAG_SLAVE)
|
2017-11-14 14:31:37 +01:00
|
|
|
{
|
|
|
|
retVal2 |= LINK_STAT_ERROR_LAG_SLAVE;
|
|
|
|
}
|
2017-11-13 07:46:22 +01:00
|
|
|
|
|
|
|
return retVal2;
|
|
|
|
}
|
2017-11-14 14:31:37 +01:00
|
|
|
|
|
|
|
static void CheckMasterOrSlave(void)
|
|
|
|
{
|
|
|
|
u32 terminals;
|
|
|
|
|
|
|
|
terminals = *(vu32 *)REG_ADDR_SIOCNT & (SIO_MULTI_SD | SIO_MULTI_SI);
|
|
|
|
if (terminals == SIO_MULTI_SD && gLink.localId == 0)
|
|
|
|
{
|
|
|
|
gLink.isMaster = LINK_MASTER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gLink.isMaster = LINK_SLAVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void InitTimer(void)
|
|
|
|
{
|
|
|
|
if (gLink.isMaster)
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
REG_TM3CNT_L = -197;
|
2017-11-14 14:31:37 +01:00
|
|
|
REG_TM3CNT_H = TIMER_64CLK | TIMER_INTR_ENABLE;
|
|
|
|
EnableInterrupts(INTR_FLAG_TIMER3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void EnqueueSendCmd(u16 *sendCmd)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 offset;
|
|
|
|
|
|
|
|
gLinkSavedIme = REG_IME;
|
|
|
|
REG_IME = 0;
|
|
|
|
if (gLink.sendQueue.count < QUEUE_CAPACITY)
|
|
|
|
{
|
|
|
|
offset = gLink.sendQueue.pos + gLink.sendQueue.count;
|
|
|
|
if (offset >= QUEUE_CAPACITY)
|
|
|
|
{
|
|
|
|
offset -= QUEUE_CAPACITY;
|
|
|
|
}
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < CMD_LENGTH; i++)
|
2017-11-14 14:31:37 +01:00
|
|
|
{
|
|
|
|
sSendNonzeroCheck |= *sendCmd;
|
|
|
|
gLink.sendQueue.data[i][offset] = *sendCmd;
|
|
|
|
*sendCmd = 0;
|
|
|
|
sendCmd++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gLink.queueFull = QUEUE_FULL_SEND;
|
|
|
|
}
|
|
|
|
if (sSendNonzeroCheck)
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
gLink.sendQueue.count++;
|
2017-11-14 14:31:37 +01:00
|
|
|
sSendNonzeroCheck = 0;
|
|
|
|
}
|
|
|
|
REG_IME = gLinkSavedIme;
|
|
|
|
gLastSendQueueCount = gLink.sendQueue.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void DequeueRecvCmds(u16 (*recvCmds)[CMD_LENGTH])
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 j;
|
|
|
|
|
|
|
|
gLinkSavedIme = REG_IME;
|
|
|
|
REG_IME = 0;
|
|
|
|
if (gLink.recvQueue.count == 0)
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < gLink.playerCount; i++)
|
2017-11-14 14:31:37 +01:00
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
for (j = 0; j < CMD_LENGTH; j++)
|
2017-11-14 14:31:37 +01:00
|
|
|
{
|
|
|
|
recvCmds[i][j] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gLink.receivedNothing = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < gLink.playerCount; i++)
|
2017-11-14 14:31:37 +01:00
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
for (j = 0; j < CMD_LENGTH; j++)
|
2017-11-14 14:31:37 +01:00
|
|
|
{
|
|
|
|
recvCmds[i][j] = gLink.recvQueue.data[i][j][gLink.recvQueue.pos];
|
|
|
|
}
|
|
|
|
}
|
2017-11-17 03:38:06 +01:00
|
|
|
gLink.recvQueue.count--;
|
|
|
|
gLink.recvQueue.pos++;
|
2017-11-14 14:31:37 +01:00
|
|
|
if (gLink.recvQueue.pos >= QUEUE_CAPACITY)
|
|
|
|
{
|
|
|
|
gLink.recvQueue.pos = 0;
|
|
|
|
}
|
|
|
|
gLink.receivedNothing = FALSE;
|
|
|
|
}
|
|
|
|
REG_IME = gLinkSavedIme;
|
|
|
|
}
|
|
|
|
|
2017-11-17 03:38:06 +01:00
|
|
|
// link_intr.c
|
|
|
|
|
2017-11-14 14:44:32 +01:00
|
|
|
void LinkVSync(void)
|
|
|
|
{
|
|
|
|
if (gLink.isMaster)
|
|
|
|
{
|
|
|
|
switch (gLink.state)
|
|
|
|
{
|
|
|
|
case LINK_STATE_CONN_ESTABLISHED:
|
|
|
|
if (gLink.serialIntrCounter < 9)
|
|
|
|
{
|
|
|
|
if (gLink.hardwareError != TRUE)
|
|
|
|
{
|
|
|
|
gLink.lag = LAG_MASTER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StartTransfer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (gLink.lag != LAG_MASTER)
|
|
|
|
{
|
|
|
|
gLink.serialIntrCounter = 0;
|
|
|
|
StartTransfer();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LINK_STATE_HANDSHAKE:
|
|
|
|
StartTransfer();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (gLink.state == LINK_STATE_CONN_ESTABLISHED || gLink.state == LINK_STATE_HANDSHAKE)
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
if (++sNumVBlanksWithoutSerialIntr > 10)
|
2017-11-14 14:44:32 +01:00
|
|
|
{
|
|
|
|
if (gLink.state == LINK_STATE_CONN_ESTABLISHED)
|
|
|
|
{
|
|
|
|
gLink.lag = LAG_SLAVE;
|
|
|
|
}
|
|
|
|
if (gLink.state == LINK_STATE_HANDSHAKE)
|
|
|
|
{
|
|
|
|
gLink.playerCount = 0;
|
|
|
|
gLink.link_field_F = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 14:44:11 +01:00
|
|
|
void Timer3Intr(void)
|
|
|
|
{
|
|
|
|
StopTimer();
|
|
|
|
StartTransfer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SerialCB(void)
|
|
|
|
{
|
|
|
|
gLink.localId = SIO_MULTI_CNT->id;
|
|
|
|
switch (gLink.state)
|
|
|
|
{
|
|
|
|
case LINK_STATE_CONN_ESTABLISHED:
|
|
|
|
gLink.hardwareError = SIO_MULTI_CNT->error;
|
|
|
|
DoRecv();
|
|
|
|
DoSend();
|
|
|
|
SendRecvDone();
|
|
|
|
break;
|
|
|
|
case LINK_STATE_HANDSHAKE:
|
|
|
|
if (DoHandshake())
|
|
|
|
{
|
|
|
|
if (gLink.isMaster)
|
|
|
|
{
|
|
|
|
gLink.state = LINK_STATE_INIT_TIMER;
|
|
|
|
gLink.serialIntrCounter = 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gLink.state = LINK_STATE_CONN_ESTABLISHED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-11-17 03:38:06 +01:00
|
|
|
gLink.serialIntrCounter++;
|
2017-11-15 14:44:11 +01:00
|
|
|
sNumVBlanksWithoutSerialIntr = 0;
|
|
|
|
if (gLink.serialIntrCounter == 8)
|
|
|
|
{
|
|
|
|
gLastRecvQueueCount = gLink.recvQueue.count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void StartTransfer(void)
|
|
|
|
{
|
|
|
|
REG_SIOCNT |= SIO_START;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool8 DoHandshake(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 playerCount;
|
|
|
|
u16 minRecv;
|
|
|
|
|
|
|
|
playerCount = 0;
|
|
|
|
minRecv = 0xFFFF;
|
|
|
|
if (gLink.handshakeAsMaster == TRUE)
|
|
|
|
{
|
|
|
|
REG_SIOMLT_SEND = MASTER_HANDSHAKE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
REG_SIOMLT_SEND = SLAVE_HANDSHAKE;
|
|
|
|
}
|
|
|
|
*(u64 *)gLink.tempRecvBuffer = REG_SIOMLT_RECV;
|
|
|
|
REG_SIOMLT_RECV = 0;
|
|
|
|
gLink.handshakeAsMaster = FALSE;
|
2017-11-17 03:38:06 +01:00
|
|
|
for (i = 0; i < 4; i++)
|
2017-11-15 14:44:11 +01:00
|
|
|
{
|
|
|
|
if ((gLink.tempRecvBuffer[i] & ~0x3) == SLAVE_HANDSHAKE || gLink.tempRecvBuffer[i] == MASTER_HANDSHAKE)
|
|
|
|
{
|
2017-11-17 03:38:06 +01:00
|
|
|
playerCount++;
|
2017-11-15 14:44:11 +01:00
|
|
|
if (minRecv > gLink.tempRecvBuffer[i] && gLink.tempRecvBuffer[i] != 0)
|
|
|
|
{
|
|
|
|
minRecv = gLink.tempRecvBuffer[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gLink.tempRecvBuffer[i] != 0xFFFF)
|
|
|
|
{
|
|
|
|
playerCount = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gLink.playerCount = playerCount;
|
|
|
|
if (gLink.playerCount > 1 && gLink.playerCount == sHandshakePlayerCount && gLink.tempRecvBuffer[0] == MASTER_HANDSHAKE)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (gLink.playerCount > 1)
|
|
|
|
{
|
|
|
|
gLink.link_field_F = (minRecv & 3) + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gLink.link_field_F = 0;
|
|
|
|
}
|
|
|
|
sHandshakePlayerCount = gLink.playerCount;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-11-17 03:38:06 +01:00
|
|
|
|
|
|
|
static void DoRecv(void)
|
|
|
|
{
|
|
|
|
u16 recv[4];
|
|
|
|
u8 i;
|
|
|
|
u8 index;
|
|
|
|
|
|
|
|
*(u64 *)recv = REG_SIOMLT_RECV;
|
|
|
|
if (gLink.sendCmdIndex == 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < gLink.playerCount; i++)
|
|
|
|
{
|
|
|
|
if (gLink.checksum != recv[i] && sChecksumAvailable)
|
|
|
|
{
|
|
|
|
gLink.badChecksum = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gLink.checksum = 0;
|
|
|
|
sChecksumAvailable = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
index = gLink.recvQueue.pos + gLink.recvQueue.count;
|
|
|
|
if (index >= QUEUE_CAPACITY)
|
|
|
|
{
|
|
|
|
index -= QUEUE_CAPACITY;
|
|
|
|
}
|
|
|
|
if (gLink.recvQueue.count < QUEUE_CAPACITY)
|
|
|
|
{
|
|
|
|
for (i = 0; i < gLink.playerCount; i++)
|
|
|
|
{
|
|
|
|
gLink.checksum += recv[i];
|
|
|
|
sRecvNonzeroCheck |= recv[i];
|
|
|
|
gLink.recvQueue.data[i][gLink.recvCmdIndex][index] = recv[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gLink.queueFull = QUEUE_FULL_RECV;
|
|
|
|
}
|
|
|
|
gLink.recvCmdIndex++;
|
|
|
|
if (gLink.recvCmdIndex == CMD_LENGTH && sRecvNonzeroCheck)
|
|
|
|
{
|
|
|
|
gLink.recvQueue.count++;
|
|
|
|
sRecvNonzeroCheck = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DoSend(void)
|
|
|
|
{
|
|
|
|
if (gLink.sendCmdIndex == CMD_LENGTH)
|
|
|
|
{
|
|
|
|
REG_SIOMLT_SEND = gLink.checksum;
|
|
|
|
if (!sSendBufferEmpty)
|
|
|
|
{
|
|
|
|
gLink.sendQueue.count--;
|
|
|
|
gLink.sendQueue.pos++;
|
|
|
|
if (gLink.sendQueue.pos >= QUEUE_CAPACITY)
|
|
|
|
{
|
|
|
|
gLink.sendQueue.pos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sSendBufferEmpty = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!sSendBufferEmpty && gLink.sendQueue.count == 0)
|
|
|
|
{
|
|
|
|
sSendBufferEmpty = TRUE;
|
|
|
|
}
|
|
|
|
if (sSendBufferEmpty)
|
|
|
|
{
|
|
|
|
REG_SIOMLT_SEND = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
REG_SIOMLT_SEND = gLink.sendQueue.data[gLink.sendCmdIndex][gLink.sendQueue.pos];
|
|
|
|
}
|
|
|
|
gLink.sendCmdIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void StopTimer(void)
|
|
|
|
{
|
|
|
|
if (gLink.isMaster)
|
|
|
|
{
|
|
|
|
REG_TM3CNT_H &= ~TIMER_ENABLE;
|
|
|
|
REG_TM3CNT_L = -197;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SendRecvDone(void)
|
|
|
|
{
|
|
|
|
if (gLink.recvCmdIndex == CMD_LENGTH)
|
|
|
|
{
|
|
|
|
gLink.sendCmdIndex = 0;
|
|
|
|
gLink.recvCmdIndex = 0;
|
|
|
|
}
|
|
|
|
else if (gLink.isMaster)
|
|
|
|
{
|
|
|
|
REG_TM3CNT_H |= TIMER_ENABLE;
|
|
|
|
}
|
|
|
|
}
|
2017-11-17 04:13:42 +01:00
|
|
|
|
|
|
|
void ResetSendBuffer(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 j;
|
|
|
|
|
|
|
|
gLink.sendQueue.count = 0;
|
|
|
|
gLink.sendQueue.pos = 0;
|
|
|
|
for (i = 0; i < CMD_LENGTH; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < QUEUE_CAPACITY; j++)
|
|
|
|
{
|
|
|
|
gLink.sendQueue.data[i][j] = 0xEFFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetRecvBuffer(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 j;
|
|
|
|
u8 k;
|
|
|
|
|
|
|
|
gLink.recvQueue.count = 0;
|
|
|
|
gLink.recvQueue.pos = 0;
|
|
|
|
for (i = 0; i < MAX_LINK_PLAYERS; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < CMD_LENGTH; j++)
|
|
|
|
{
|
|
|
|
for (k = 0; k < QUEUE_CAPACITY; k++)
|
|
|
|
{
|
|
|
|
gLink.recvQueue.data[i][j][k] = 0xEFFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|