Port librfu from firered

This commit is contained in:
PikalaxALT
2020-02-16 13:49:36 -05:00
parent ac1738e11d
commit 91dd7f5cc3
32 changed files with 7005 additions and 6967 deletions

1398
src/AgbRfu_LinkManager.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -280,9 +280,9 @@ void sub_8020C70(MainCallback callback)
if (!gReceivedRemoteLinkPlayers || gWirelessCommType == 0)
{
SetMainCallback2(callback);
gUnknown_03005000.unk_10 = 0;
gUnknown_03005000.unk_12 = 0;
gUnknown_03005000.unk_ee = 1;
Rfu.unk_10 = 0;
Rfu.unk_12 = 0;
Rfu.unk_ee = 1;
return;
}
@@ -291,9 +291,9 @@ void sub_8020C70(MainCallback callback)
if (playerCount < 2 || multiplayerId >= playerCount)
{
SetMainCallback2(callback);
gUnknown_03005000.unk_10 = 0;
gUnknown_03005000.unk_12 = 0;
gUnknown_03005000.unk_ee = 1;
Rfu.unk_10 = 0;
Rfu.unk_12 = 0;
Rfu.unk_ee = 1;
return;
}
@@ -301,9 +301,9 @@ void sub_8020C70(MainCallback callback)
if (!gUnknown_02022C90)
{
SetMainCallback2(callback);
gUnknown_03005000.unk_10 = 0;
gUnknown_03005000.unk_12 = 0;
gUnknown_03005000.unk_ee = 1;
Rfu.unk_10 = 0;
Rfu.unk_12 = 0;
Rfu.unk_ee = 1;
return;
}

View File

@@ -1,5 +1,402 @@
#include "global.h"
#include "main.h"
#include "librfu.h"
//TODO: decompile asm/librfu_intr.s to here
static void sio32intr_clock_master(void);
static void sio32intr_clock_slave(void);
static u16 handshake_wait(u16 slot);
static void STWI_set_timer_in_RAM(u8 count);
static void STWI_stop_timer_in_RAM(void);
static void STWI_init_slave(void);
static void Callback_Dummy_M(int reqCommandId, int error, void (*callbackM)());
static void Callback_Dummy_S(u16 reqCommandId, void (*callbackS)(u16));
static void Callback_Dummy_ID(void (*callbackId)(void));
void IntrSIO32(void)
{
if (gSTWIStatus->state == 10)
{
if (gSTWIStatus->callbackID != NULL)
Callback_Dummy_ID(gSTWIStatus->callbackID);
}
else
{
if (gSTWIStatus->msMode == AGB_CLK_MASTER)
sio32intr_clock_master();
else
sio32intr_clock_slave();
}
}
static void sio32intr_clock_master(void)
{
u32 regSIODATA32;
u32 ackLen;
STWI_set_timer_in_RAM(80);
regSIODATA32 = REG_SIODATA32;
if (gSTWIStatus->state == 0) // master send req
{
if (regSIODATA32 == 0x80000000)
{
if (gSTWIStatus->reqNext <= gSTWIStatus->reqLength)
{
REG_SIODATA32 = ((u32*)gSTWIStatus->txPacket->rfuPacket8.data)[gSTWIStatus->reqNext];
gSTWIStatus->reqNext++;
}
else
{
gSTWIStatus->state = 1; // master wait ack
REG_SIODATA32 = 0x80000000;
}
}
else
{
STWI_stop_timer_in_RAM();
STWI_set_timer_in_RAM(130);
return;
}
}
else if (gSTWIStatus->state == 1) // master wait ack
{
if ((regSIODATA32 & 0xFFFF0000) == 0x99660000)
{
gSTWIStatus->ackNext = 0;
((u32*)gSTWIStatus->rxPacket)[gSTWIStatus->ackNext] = regSIODATA32;
gSTWIStatus->ackNext++;
gSTWIStatus->ackActiveCommand = regSIODATA32;
gSTWIStatus->ackLength = ackLen = regSIODATA32 >> 8;
if ((ackLen = gSTWIStatus->ackLength) >= gSTWIStatus->ackNext)
{
gSTWIStatus->state = 2; // master receive ack
REG_SIODATA32 = 0x80000000;
}
else
{
gSTWIStatus->state = 3; // master done ack
}
}
else
{
STWI_stop_timer_in_RAM();
STWI_set_timer_in_RAM(130);
return;
}
}
else if (gSTWIStatus->state == 2) // master receive ack
{
((u32*)gSTWIStatus->rxPacket)[gSTWIStatus->ackNext] = regSIODATA32;
gSTWIStatus->ackNext++;
if (gSTWIStatus->ackLength < gSTWIStatus->ackNext)
gSTWIStatus->state = 3; // master done ack
else
REG_SIODATA32 = 0x80000000;
}
if (handshake_wait(1) == 1)
return;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS | SIO_MULTI_SD;
if (handshake_wait(0) == 1)
return;
STWI_stop_timer_in_RAM();
if (gSTWIStatus->state == 3) // master done ack
{
if (
gSTWIStatus->ackActiveCommand == (0x80 | ID_MS_CHANGE_REQ)
|| gSTWIStatus->ackActiveCommand == (0x80 | ID_DATA_TX_AND_CHANGE_REQ)
|| gSTWIStatus->ackActiveCommand == (0x80 | ID_UNK35_REQ)
|| gSTWIStatus->ackActiveCommand == (0x80 | ID_RESUME_RETRANSMIT_AND_CHANGE_REQ)
)
{
gSTWIStatus->msMode = AGB_CLK_SLAVE;
REG_SIODATA32 = 0x80000000;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS | SIO_ENABLE;
gSTWIStatus->state = 5; // slave receive req init
}
else
{
if (gSTWIStatus->ackActiveCommand == 0xEE)
{
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
gSTWIStatus->state = 4; // error
gSTWIStatus->error = ERR_REQ_CMD_ACK_REJECTION;
}
else
{
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
gSTWIStatus->state = 4; // error
}
}
gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL)
Callback_Dummy_M(gSTWIStatus->reqActiveCommand, gSTWIStatus->error, gSTWIStatus->callbackM);
}
else
{
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS | SIO_ENABLE;
}
}
static void sio32intr_clock_slave(void)
{
u32 regSIODATA32;
u32 r0;
register u32 reqLen asm("r2");
gSTWIStatus->timerActive = 0;
STWI_set_timer_in_RAM(100);
if (handshake_wait(0) == 1)
return;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS | SIO_MULTI_SD;
regSIODATA32 = REG_SIODATA32;
if (gSTWIStatus->state == 5) // slave receive req init
{
((u32*)gSTWIStatus->rxPacket)[0] = regSIODATA32;
gSTWIStatus->reqNext = 1;
r0 = 0x99660000;
if ((regSIODATA32 >> 16) == (r0 >> 16))
{
gSTWIStatus->reqLength = reqLen = regSIODATA32 >> 8;
gSTWIStatus->reqActiveCommand = regSIODATA32;
if (gSTWIStatus->reqLength == 0)
{
if (
gSTWIStatus->reqActiveCommand == ID_MS_CHANGE_REQ
|| gSTWIStatus->reqActiveCommand == ID_DATA_READY_AND_CHANGE_REQ
|| gSTWIStatus->reqActiveCommand == ID_DISCONNECTED_AND_CHANGE_REQ
|| gSTWIStatus->reqActiveCommand == ID_UNK36_REQ
)
{
gSTWIStatus->ackActiveCommand = gSTWIStatus->reqActiveCommand + 0x80;
((u32*)gSTWIStatus->txPacket)[0] = 0x99660000 + gSTWIStatus->ackActiveCommand;
gSTWIStatus->ackLength = 0;
}
else
{
((u32*)gSTWIStatus->txPacket)[0] = 0x996601EE;
if (gSTWIStatus->reqActiveCommand >= 0x10 && gSTWIStatus->reqActiveCommand <= 0x3D)
{
((u32*)gSTWIStatus->txPacket)[1] = 1;
}
else
{
((u32*)gSTWIStatus->txPacket)[1] = 2;
}
gSTWIStatus->ackLength = 1;
gSTWIStatus->error = ERR_REQ_CMD_ACK_REJECTION;
}
REG_SIODATA32 = ((u32*)gSTWIStatus->txPacket)[0];
gSTWIStatus->ackNext = 1;
gSTWIStatus->state = 7; // slave send ack
}
else
{
REG_SIODATA32 = 0x80000000;
gSTWIStatus->reqNext = 1;
gSTWIStatus->state = 6; // slave receive req
}
}
else
{
STWI_stop_timer_in_RAM();
STWI_set_timer_in_RAM(100);
return;
}
}
else if (gSTWIStatus->state == 6) // slave receive req
{
((u32*)gSTWIStatus->rxPacket)[gSTWIStatus->reqNext] = regSIODATA32;
gSTWIStatus->reqNext++;
if (gSTWIStatus->reqLength < gSTWIStatus->reqNext)
{
if (
gSTWIStatus->reqActiveCommand == ID_DATA_READY_AND_CHANGE_REQ
|| gSTWIStatus->reqActiveCommand == ID_DISCONNECTED_AND_CHANGE_REQ
|| gSTWIStatus->reqActiveCommand == ID_UNK36_REQ
)
{
gSTWIStatus->ackActiveCommand = gSTWIStatus->reqActiveCommand + 0x80;
((u32*)gSTWIStatus->txPacket)[0] = 0x99660000 | gSTWIStatus->ackActiveCommand;
gSTWIStatus->ackLength = 0;
}
else
{
((u32*)gSTWIStatus->txPacket)[0] = 0x996601EE;
if (gSTWIStatus->reqActiveCommand >= 0x10 && gSTWIStatus->reqActiveCommand <= 0x3D)
{
((u32*)gSTWIStatus->txPacket)[1] = 1;
}
else
{
((u32*)gSTWIStatus->txPacket)[1] = 2;
}
gSTWIStatus->ackLength = 1;
gSTWIStatus->error = ERR_REQ_CMD_ACK_REJECTION;
}
REG_SIODATA32 = ((u32*)gSTWIStatus->txPacket)[0];
gSTWIStatus->ackNext = 1;
gSTWIStatus->state = 7; // slave send ack
}
else
{
REG_SIODATA32 = 0x80000000;
}
}
else if (gSTWIStatus->state == 7) // slave send ack
{
if (regSIODATA32 == 0x80000000)
{
if (gSTWIStatus->ackLength < gSTWIStatus->ackNext)
{
gSTWIStatus->state = 8; // slave done ack
}
else
{
REG_SIODATA32 = ((u32*)gSTWIStatus->txPacket)[gSTWIStatus->ackNext];
gSTWIStatus->ackNext++;
}
}
else
{
STWI_stop_timer_in_RAM();
STWI_set_timer_in_RAM(100);
return;
}
}
if (handshake_wait(1) == 1)
return;
if (gSTWIStatus->state == 8) // slave done ack
{
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS;
STWI_stop_timer_in_RAM();
if (gSTWIStatus->error == ERR_REQ_CMD_ACK_REJECTION)
{
STWI_init_slave();
if (gSTWIStatus->callbackS != NULL)
{
Callback_Dummy_S(0x1EE, gSTWIStatus->callbackS);
}
}
else
{
REG_SIODATA32 = 0;
REG_SIOCNT = 0;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
gSTWIStatus->msMode = AGB_CLK_MASTER;
gSTWIStatus->state = 0; // master send req
if (gSTWIStatus->callbackS != NULL)
{
Callback_Dummy_S((gSTWIStatus->reqLength << 8) | (gSTWIStatus->reqActiveCommand), gSTWIStatus->callbackS);
}
}
}
else
{
REG_IME = 0;
if (REG_TM0CNT_H & TIMER_ENABLE)
{
if ((REG_TM0CNT_H & 0x03) == TIMER_1CLK)
{
while (REG_TM0CNT_L > 0xFF9B);
}
else
{
while (REG_TM0CNT_L > 0xFFFE);
}
}
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS | SIO_ENABLE;
REG_IME = 1;
}
}
static u16 handshake_wait(u16 slot)
{
do
{
if ((gSTWIStatus->timerActive & 0xFF) == 1)
{
gSTWIStatus->timerActive = 0;
return 1;
}
} while ((REG_SIOCNT & SIO_MULTI_SI) != (slot << SIO_MULTI_SI_SHIFT));
return 0;
}
static void STWI_set_timer_in_RAM(u8 count)
{
vu16* regTMCNTL = (vu16*)(REG_ADDR_TMCNT_L + gSTWIStatus->timerSelect * 4);
vu16* regTMCNTH = (vu16*)(REG_ADDR_TMCNT_H + gSTWIStatus->timerSelect * 4);
REG_IME = 0;
switch (count)
{
case 50:
*regTMCNTL = 0xFCCB;
gSTWIStatus->timerState = 1;
break;
case 80:
*regTMCNTL = 0xFAE0;
gSTWIStatus->timerState = 2;
break;
case 100:
*regTMCNTL = 0xF996;
gSTWIStatus->timerState = 3;
break;
case 130:
*regTMCNTL = 0xF7AD;
gSTWIStatus->timerState = 4;
break;
}
*regTMCNTH = TIMER_ENABLE | TIMER_64CLK | TIMER_256CLK | TIMER_INTR_ENABLE;
REG_IF = INTR_FLAG_TIMER0 << gSTWIStatus->timerSelect;
REG_IME = 1;
}
static void STWI_stop_timer_in_RAM(void)
{
gSTWIStatus->timerState = 0;
REG_TMCNT_L(gSTWIStatus->timerSelect) = 0;
REG_TMCNT_H(gSTWIStatus->timerSelect) = 0;
}
static void STWI_init_slave(void)
{
gSTWIStatus->state = 5; // slave receive req init
gSTWIStatus->msMode = AGB_CLK_SLAVE;
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
gSTWIStatus->reqActiveCommand = 0;
gSTWIStatus->ackLength = 0;
gSTWIStatus->ackNext = 0;
gSTWIStatus->ackActiveCommand = 0;
gSTWIStatus->timerState = 0;
gSTWIStatus->timerActive = 0;
gSTWIStatus->error = 0;
gSTWIStatus->recoveryCount = 0;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS | SIO_ENABLE;
}
NAKED
static void Callback_Dummy_M(int reqCommandId, int error, void (*callbackM)())
{
asm("bx r2");
}
NAKED
static void Callback_Dummy_S(u16 reqCommandId, void (*callbackS)(u16))
{
asm("bx r1");
}
NAKED
static void Callback_Dummy_ID(void (*callbackId)(void))
{
asm("bx r0");
}

File diff suppressed because it is too large Load Diff

View File

@@ -4,44 +4,56 @@ static void Sio32IDIntr(void);
static void Sio32IDInit(void);
static s32 Sio32IDMain(void);
struct RfuSIO32Id
{
u8 MS_mode;
u8 state;
u16 count;
u16 send_id;
u16 recv_id;
u16 unk8; // unused
u16 lastId;
};
struct RfuSIO32Id gRfuSIO32Id;
static const u16 Sio32ConnectionData[] = { 0x494e, 0x544e, 0x4e45, 0x4f44 }; // NINTENDO
static const char Sio32IDLib_Var[] = "Sio32ID_030820";
s32 AgbRFU_checkID(u8 r5)
s32 AgbRFU_checkID(u8 maxTries)
{
u16 r8;
vu16 *r4;
s32 r6;
u16 ieBak;
vu16 *regTMCNTL;
s32 id;
// Interrupts must be enabled
if (REG_IME == 0)
return -1;
r8 = REG_IE;
ieBak = REG_IE;
gSTWIStatus->state = 10;
STWI_set_Callback_ID(Sio32IDIntr);
Sio32IDInit();
r4 = &REG_TMCNT_L(gSTWIStatus->timerSelect);
r5 *= 8;
while (--r5 != 0xFF)
regTMCNTL = &REG_TMCNT_L(gSTWIStatus->timerSelect);
maxTries *= 8;
while (--maxTries != 0xFF)
{
r6 = Sio32IDMain();
if (r6 != 0)
id = Sio32IDMain();
if (id != 0)
break;
r4[1] = 0;
r4[0] = 0;
r4[1] = TIMER_1024CLK | TIMER_ENABLE;
while (r4[0] < 32)
regTMCNTL[1] = 0;
regTMCNTL[0] = 0;
regTMCNTL[1] = TIMER_1024CLK | TIMER_ENABLE;
while (regTMCNTL[0] < 32)
;
r4[1] = 0;
r4[0] = 0;
regTMCNTL[1] = 0;
regTMCNTL[0] = 0;
}
REG_IME = 0;
REG_IE = r8;
REG_IE = ieBak;
REG_IME = 1;
gSTWIStatus->state = 0;
STWI_set_Callback_ID(NULL);
return r6;
return id;
}
static void Sio32IDInit(void)
@@ -58,107 +70,105 @@ static void Sio32IDInit(void)
static s32 Sio32IDMain(void)
{
u8 r12;
switch (r12 = gRfuSIO32Id.unk1)
switch (gRfuSIO32Id.state)
{
case 0:
gRfuSIO32Id.unk0 = 1;
gRfuSIO32Id.MS_mode = AGB_CLK_MASTER;
REG_SIOCNT |= SIO_38400_BPS;
REG_IME = r12;
REG_IME = 0;
REG_IE |= INTR_FLAG_SERIAL;
REG_IME = 1;
gRfuSIO32Id.unk1 = 1;
gRfuSIO32Id.state = 1;
*(vu8 *)&REG_SIOCNT |= SIO_ENABLE;
break;
case 1:
if (gRfuSIO32Id.unkA == 0)
if (gRfuSIO32Id.lastId == 0)
{
if (gRfuSIO32Id.unk0 == 1)
if (gRfuSIO32Id.MS_mode == AGB_CLK_MASTER)
{
if (gRfuSIO32Id.unk2 == 0)
if (gRfuSIO32Id.count == 0)
{
REG_IME = gRfuSIO32Id.unk2;
REG_IME = 0;
REG_SIOCNT |= SIO_ENABLE;
REG_IME = r12;
REG_IME = 1;
}
}
else if (gRfuSIO32Id.unk4 != 0x8001 && !gRfuSIO32Id.unk2)
else if (gRfuSIO32Id.send_id != RFU_ID && !gRfuSIO32Id.count)
{
REG_IME = gRfuSIO32Id.unk2;
REG_IME = 0;
REG_IE &= ~INTR_FLAG_SERIAL;
REG_IME = r12;
REG_SIOCNT = gRfuSIO32Id.unk2;
REG_IME = 1;
REG_SIOCNT = 0;
REG_SIOCNT = SIO_32BIT_MODE;
REG_IF = INTR_FLAG_SERIAL;
REG_SIOCNT |= SIO_INTR_ENABLE | SIO_ENABLE;
REG_IME = gRfuSIO32Id.unk2;
REG_IME = 0;
REG_IE |= INTR_FLAG_SERIAL;
REG_IME = r12;
REG_IME = 1;
}
break;
}
else
{
gRfuSIO32Id.unk1 = 2;
gRfuSIO32Id.state = 2;
// fallthrough
}
default:
return gRfuSIO32Id.unkA;
return gRfuSIO32Id.lastId;
}
return 0;
}
static void Sio32IDIntr(void)
{
u32 r5;
u16 r0;
u32 regSIODATA32;
u16 delay;
#ifndef NONMATCHING
register u32 r1 asm("r1");
register u16 r0_ asm("r0");
register u32 rfuSIO32IdUnk0_times_16 asm("r1");
register u16 negRfuSIO32IdUnk6 asm("r0");
#else
u32 r1;
u16 r0_;
u32 rfuSIO32IdUnk0_times_16;
u16 negRfuSIO32IdUnk6;
#endif
r5 = REG_SIODATA32;
if (gRfuSIO32Id.unk0 != 1)
regSIODATA32 = REG_SIODATA32;
if (gRfuSIO32Id.MS_mode != AGB_CLK_MASTER)
REG_SIOCNT |= SIO_ENABLE;
r1 = 16 * gRfuSIO32Id.unk0; // to handle side effect of inline asm
r1 = (r5 << r1) >> 16;
r5 = (r5 << 16 * (1 - gRfuSIO32Id.unk0)) >> 16;
if (gRfuSIO32Id.unkA == 0)
rfuSIO32IdUnk0_times_16 = 16 * gRfuSIO32Id.MS_mode; // to handle side effect of inline asm
rfuSIO32IdUnk0_times_16 = (regSIODATA32 << rfuSIO32IdUnk0_times_16) >> 16;
regSIODATA32 = (regSIODATA32 << 16 * (1 - gRfuSIO32Id.MS_mode)) >> 16;
if (gRfuSIO32Id.lastId == 0)
{
if (r1 == gRfuSIO32Id.unk6)
if (rfuSIO32IdUnk0_times_16 == gRfuSIO32Id.recv_id)
{
if (gRfuSIO32Id.unk2 > 3)
if (gRfuSIO32Id.count > 3)
{
gRfuSIO32Id.unkA = r5;
gRfuSIO32Id.lastId = regSIODATA32;
}
else if (r1 == (u16)~gRfuSIO32Id.unk4)
else if (rfuSIO32IdUnk0_times_16 == (u16)~gRfuSIO32Id.send_id)
{
r0_ = ~gRfuSIO32Id.unk6;
if (r5 == r0_)
++gRfuSIO32Id.unk2;
negRfuSIO32IdUnk6 = ~gRfuSIO32Id.recv_id;
if (regSIODATA32 == negRfuSIO32IdUnk6)
++gRfuSIO32Id.count;
}
}
else
{
gRfuSIO32Id.unk2 = gRfuSIO32Id.unkA;
gRfuSIO32Id.count = 0;
}
}
if (gRfuSIO32Id.unk2 < 4)
gRfuSIO32Id.unk4 = *(gRfuSIO32Id.unk2 + Sio32ConnectionData);
if (gRfuSIO32Id.count < 4)
gRfuSIO32Id.send_id = *(gRfuSIO32Id.count + Sio32ConnectionData);
else
gRfuSIO32Id.unk4 = 0x8001;
gRfuSIO32Id.unk6 = ~r5;
REG_SIODATA32 = (gRfuSIO32Id.unk4 << 16 * (1 - gRfuSIO32Id.unk0))
+ (gRfuSIO32Id.unk6 << 16 * gRfuSIO32Id.unk0);
if (gRfuSIO32Id.unk0 == 1 && (gRfuSIO32Id.unk2 || r5 == 0x494E))
gRfuSIO32Id.send_id = RFU_ID;
gRfuSIO32Id.recv_id = ~regSIODATA32;
REG_SIODATA32 = (gRfuSIO32Id.send_id << 16 * (1 - gRfuSIO32Id.MS_mode))
+ (gRfuSIO32Id.recv_id << 16 * gRfuSIO32Id.MS_mode);
if (gRfuSIO32Id.MS_mode == AGB_CLK_MASTER && (gRfuSIO32Id.count != 0 || regSIODATA32 == 0x494e))
{
for (r0 = 0; r0 < 600; ++r0)
for (delay = 0; delay < 600; ++delay)
;
if (gRfuSIO32Id.unkA == 0)
if (gRfuSIO32Id.lastId == 0)
REG_SIOCNT |= SIO_ENABLE;
}
}

View File

@@ -28,8 +28,8 @@ void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, b
}
gSTWIStatus->rxPacket = &interruptStruct->rxPacketAlloc;
gSTWIStatus->txPacket = &interruptStruct->txPacketAlloc;
gSTWIStatus->msMode = 1;
gSTWIStatus->state = 0;
gSTWIStatus->msMode = AGB_CLK_MASTER;
gSTWIStatus->state = 0; // master send req
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
gSTWIStatus->ackLength = 0;
@@ -39,7 +39,7 @@ void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, b
gSTWIStatus->timerActive = 0;
gSTWIStatus->error = 0;
gSTWIStatus->recoveryCount = 0;
gSTWIStatus->unk_2c = 0;
gSTWIStatus->sending = 0;
REG_RCNT = 0x100; // TODO: mystery bit?
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
STWI_init_Callback_M();
@@ -71,7 +71,7 @@ void AgbRFU_SoftReset(void)
*timerH = 3;
REG_RCNT = 0x80A0;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
gSTWIStatus->state = 0;
gSTWIStatus->state = 0; // master send req
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
gSTWIStatus->reqActiveCommand = 0;
@@ -81,9 +81,9 @@ void AgbRFU_SoftReset(void)
gSTWIStatus->timerState = 0;
gSTWIStatus->timerActive = 0;
gSTWIStatus->error = 0;
gSTWIStatus->msMode = 1;
gSTWIStatus->msMode = AGB_CLK_MASTER;
gSTWIStatus->recoveryCount = 0;
gSTWIStatus->unk_2c = 0;
gSTWIStatus->sending = 0;
}
void STWI_set_MS_mode(u8 mode)
@@ -131,12 +131,12 @@ void STWI_set_Callback_S(void (*callbackS)(u16))
void STWI_set_Callback_ID(void (*func)(void)) // name in SDK, but is actually setting a function pointer
{
gSTWIStatus->unk_20 = func;
gSTWIStatus->callbackID = func;
}
u16 STWI_poll_CommandEnd(void)
{
while (gSTWIStatus->unk_2c == TRUE)
while (gSTWIStatus->sending == 1)
;
return gSTWIStatus->error;
}
@@ -195,7 +195,7 @@ void STWI_send_ConfigStatusREQ(void)
}
}
void STWI_send_GameConfigREQ(const u8 *unk1, const u8 *data)
void STWI_send_GameConfigREQ(const u8 *serial_gname, const u8 *uname)
{
u8 *packetBytes;
s32 i;
@@ -203,29 +203,28 @@ void STWI_send_GameConfigREQ(const u8 *unk1, const u8 *data)
if (!STWI_init(ID_GAME_CONFIG_REQ))
{
gSTWIStatus->reqLength = 6;
// TODO: what is unk1
packetBytes = gSTWIStatus->txPacket->rfuPacket8.data;
packetBytes += sizeof(u32);
*(u16 *)packetBytes = *(u16 *)unk1;
*(u16 *)packetBytes = *(u16 *)serial_gname;
packetBytes += sizeof(u16);
unk1 += sizeof(u16);
serial_gname += sizeof(u16);
for (i = 0; i < 14; ++i)
{
*packetBytes = *unk1;
*packetBytes = *serial_gname;
++packetBytes;
++unk1;
++serial_gname;
}
for (i = 0; i < 8; ++i)
{
*packetBytes = *data;
*packetBytes = *uname;
++packetBytes;
++data;
++uname;
}
STWI_start_Command();
}
}
void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3)
void STWI_send_SystemConfigREQ(u16 availSlotFlag, u8 maxMFrame, u8 mcTimer)
{
if (!STWI_init(ID_SYSTEM_CONFIG_REQ))
{
@@ -234,9 +233,9 @@ void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3)
gSTWIStatus->reqLength = 1;
packetBytes = gSTWIStatus->txPacket->rfuPacket8.data;
packetBytes += sizeof(u32);
*packetBytes++ = unk3;
*packetBytes++ = unk2;
*(u16*)packetBytes = unk1;
*packetBytes++ = mcTimer;
*packetBytes++ = maxMFrame;
*(u16*)packetBytes = availSlotFlag;
STWI_start_Command();
}
}
@@ -499,20 +498,17 @@ static void STWI_intr_timer(void)
STWI_stop_timer();
STWI_reset_ClockCounter();
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(255, 0);
gSTWIStatus->callbackM(ID_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA_REQ, 0);
break;
}
}
static void STWI_set_timer(u8 unk)
static void STWI_set_timer(u8 count)
{
vu16 *timerL;
vu16 *timerH;
timerL = &REG_TMCNT_L(gSTWIStatus->timerSelect);
timerH = &REG_TMCNT_H(gSTWIStatus->timerSelect);
vu16 *timerL = &REG_TMCNT_L(gSTWIStatus->timerSelect);
vu16 *timerH = &REG_TMCNT_H(gSTWIStatus->timerSelect);
REG_IME = 0;
switch (unk)
switch (count)
{
case 50:
*timerL = 0xFCCB;
@@ -543,25 +539,31 @@ static void STWI_stop_timer(void)
REG_TMCNT_H(gSTWIStatus->timerSelect) = 0;
}
/*
* Set up STWI to send REQ. Returns 1 if error (see below).
*/
static u16 STWI_init(u8 request)
{
if (!REG_IME)
{
// Can't start sending if IME is disabled.
gSTWIStatus->error = ERR_REQ_CMD_IME_DISABLE;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(request, gSTWIStatus->error);
return TRUE;
}
else if (gSTWIStatus->unk_2c == TRUE)
else if (gSTWIStatus->sending == 1)
{
// Already sending something. Cancel and error.
gSTWIStatus->error = ERR_REQ_CMD_SENDING;
gSTWIStatus->unk_2c = FALSE;
gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(request, gSTWIStatus->error);
return TRUE;
}
else if(!gSTWIStatus->msMode)
else if (gSTWIStatus->msMode == AGB_CLK_SLAVE)
{
// Can't send if clock slave
gSTWIStatus->error = ERR_REQ_CMD_CLOCK_SLAVE;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(request, gSTWIStatus->error, gSTWIStatus);
@@ -569,9 +571,10 @@ static u16 STWI_init(u8 request)
}
else
{
gSTWIStatus->unk_2c = TRUE;
// Good to go, start sending
gSTWIStatus->sending = 1;
gSTWIStatus->reqActiveCommand = request;
gSTWIStatus->state = 0;
gSTWIStatus->state = 0; // master send req
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
gSTWIStatus->ackLength = 0;
@@ -595,7 +598,7 @@ static s32 STWI_start_Command(void)
// but the cast here is required to avoid register issue
*(u32 *)gSTWIStatus->txPacket->rfuPacket8.data = 0x99660000 | (gSTWIStatus->reqLength << 8) | gSTWIStatus->reqActiveCommand;
REG_SIODATA32 = gSTWIStatus->txPacket->rfuPacket32.command;
gSTWIStatus->state = 0;
gSTWIStatus->state = 0; // master send req
gSTWIStatus->reqNext = 1;
imeTemp = REG_IME;
REG_IME = 0;
@@ -608,7 +611,7 @@ static s32 STWI_start_Command(void)
static s32 STWI_restart_Command(void)
{
if (gSTWIStatus->recoveryCount <= 1)
if (gSTWIStatus->recoveryCount < 2)
{
++gSTWIStatus->recoveryCount;
STWI_start_Command();
@@ -618,17 +621,17 @@ static s32 STWI_restart_Command(void)
if (gSTWIStatus->reqActiveCommand == ID_MS_CHANGE_REQ || gSTWIStatus->reqActiveCommand == ID_DATA_TX_AND_CHANGE_REQ || gSTWIStatus->reqActiveCommand == ID_UNK35_REQ || gSTWIStatus->reqActiveCommand == ID_RESUME_RETRANSMIT_AND_CHANGE_REQ)
{
gSTWIStatus->error = ERR_REQ_CMD_CLOCK_DRIFT;
gSTWIStatus->unk_2c = 0;
gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(gSTWIStatus->reqActiveCommand, gSTWIStatus->error);
}
else
{
gSTWIStatus->error = ERR_REQ_CMD_CLOCK_DRIFT;
gSTWIStatus->unk_2c = 0;
gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(gSTWIStatus->reqActiveCommand, gSTWIStatus->error);
gSTWIStatus->state = 4; // TODO: what's 4
gSTWIStatus->state = 4; // error
}
}
return 0;
@@ -636,7 +639,7 @@ static s32 STWI_restart_Command(void)
static s32 STWI_reset_ClockCounter(void)
{
gSTWIStatus->state = 5; // TODO: what is 5
gSTWIStatus->state = 5; // slave receive req init
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
REG_SIODATA32 = (1 << 31);

View File

@@ -223,7 +223,7 @@ bool8 IsWirelessAdapterConnected(void)
{
sub_800B488();
sub_800E700();
if (sub_800BEC0() == 0x8001)
if (rfu_LMAN_REQBN_softReset_and_checkID() == 0x8001)
{
rfu_REQ_stopMode();
rfu_waitREQComplete();

File diff suppressed because it is too large Load Diff

2813
src/link_rfu_2.c Normal file

File diff suppressed because it is too large Load Diff

938
src/link_rfu_3.c Normal file
View File

@@ -0,0 +1,938 @@
#include "global.h"
#include "malloc.h"
#include "decompress.h"
#include "link_rfu.h"
#include "string_util.h"
#include "random.h"
#include "text.h"
#include "event_data.h"
EWRAM_DATA u8 gWirelessStatusIndicatorSpriteId = 0;
static u8 gUnknown_03000D74;
const u16 gWirelessLinkIconPalette[] = INCBIN_U16("graphics/interface/wireless_link_icon.gbapal");
const u32 gWirelessLinkIconPic[] = INCBIN_U32("graphics/interface/wireless_link_icon.4bpp.lz");
const u8 sWireless_ASCIItoRSETable[] = {
0xff, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
0x00, 0xab, 0xb5, 0xb6, 0xb1, 0x00, 0x00, 0x00,
0x00, 0x00, 0xb2, 0xf1, 0x00, 0xae, 0xad, 0xba,
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8,
0xa9, 0xaa, 0x00, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0x00, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1,
0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1,
0xd2, 0xd3, 0xd4, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6,
0x00, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb,
0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,
0xec, 0xed, 0xee, 0x2d, 0x2f, 0x30, 0x31, 0x32,
0x33, 0x34, 0x35, 0x36, 0x50, 0x00, 0x01, 0x02,
0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a,
0x1b, 0xad, 0xb3, 0xb4, 0x00, 0xaf, 0x7d, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0xa0,
0xae, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7e, 0xb0, 0xac,
0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
0x2c, 0x2e, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c,
0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94
};
const u8 sWireless_RSEtoASCIITable[] = {
0x20, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c,
0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94,
0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c,
0x9d, 0x9e, 0x9f, 0xa0, 0xe0, 0xe1, 0xe2, 0xe3,
0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,
0xec, 0xed, 0xee, 0xef, 0xf0, 0x7b, 0xf1, 0x7c,
0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x84, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xa6, 0xdd, 0xa7,
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xf2,
0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,
0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x01, 0x02, 0x03,
0x04, 0x05, 0x06, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0xaf, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
0x37, 0x38, 0x39, 0x21, 0xdf, 0xa1, 0xb0, 0xa5,
0xde, 0x24, 0x2a, 0xa2, 0xa3, 0x22, 0x23, 0x20,
0xa4, 0x20, 0x2f, 0x41, 0x42, 0x43, 0x44, 0x45,
0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63,
0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,
0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x20,
0x20, 0x2b, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00
};
const struct OamData sWirelessStatusIndicatorOamData =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(16x16),
.x = 0,
.size = SPRITE_SIZE(16x16),
.tileNum = 0,
.priority = 0,
.paletteNum = 0,
};
const union AnimCmd sWirelessStatusIndicatorAnim0[] = {
// 3 bars
ANIMCMD_FRAME( 4, 5),
ANIMCMD_FRAME( 8, 5),
ANIMCMD_FRAME(12, 5),
ANIMCMD_FRAME(16, 10),
ANIMCMD_FRAME(12, 5),
ANIMCMD_FRAME( 8, 5),
ANIMCMD_JUMP(0)
};
const union AnimCmd sWirelessStatusIndicatorAnim1[] = {
// 2 bars
ANIMCMD_FRAME( 4, 5),
ANIMCMD_FRAME( 8, 5),
ANIMCMD_FRAME(12, 10),
ANIMCMD_FRAME( 8, 5),
ANIMCMD_JUMP(0)
};
const union AnimCmd sWirelessStatusIndicatorAnim2[] = {
// 1 bar
ANIMCMD_FRAME(4, 5),
ANIMCMD_FRAME(8, 5),
ANIMCMD_JUMP(0)
};
const union AnimCmd sWirelessStatusIndicatorAnim3[] = {
// searching
ANIMCMD_FRAME( 4, 10),
ANIMCMD_FRAME(20, 10),
ANIMCMD_JUMP(0)
};
const union AnimCmd sWirelessStatusIndicatorAnim4[] = {
// error
ANIMCMD_FRAME(24, 10),
ANIMCMD_FRAME( 4, 10),
ANIMCMD_JUMP(0)
};
const union AnimCmd *const sWirelessStatusIndicatorAnims[] = {
sWirelessStatusIndicatorAnim0,
sWirelessStatusIndicatorAnim1,
sWirelessStatusIndicatorAnim2,
sWirelessStatusIndicatorAnim3,
sWirelessStatusIndicatorAnim4
};
const struct CompressedSpriteSheet sWirelessStatusIndicatorSpriteSheet = {
gWirelessLinkIconPic, 0x0380, 0xD431
};
const struct SpritePalette sWirelessStatusIndicatorSpritePalette = {
gWirelessLinkIconPalette, 0xD432
};
const struct SpriteTemplate sWirelessStatusIndicatorSpriteTemplate = {
0xD431,
0xD432,
&sWirelessStatusIndicatorOamData,
sWirelessStatusIndicatorAnims,
NULL,
gDummySpriteAffineAnimTable,
SpriteCallbackDummy
};
void sub_800D6C8(struct UnkRfuStruct_2_Sub_124 *ptr)
{
s32 i;
s32 j;
for (i = 0; i < 32; i++)
{
for (j = 0; j < 70; j++)
{
ptr->unk_00[i][j] = 0;
}
}
ptr->unk_8c1 = 0;
ptr->unk_8c0 = 0;
ptr->unk_8c2 = 0;
ptr->unk_8c3 = 0;
}
void sub_800D724(struct UnkRfuStruct_2_Sub_9e8 *ptr)
{
s32 i;
s32 j;
for (i = 0; i < 40; i++)
{
for (j = 0; j < 14; j++)
{
ptr->unk_00[i][j] = 0;
}
}
ptr->unk_231 = 0;
ptr->unk_230 = 0;
ptr->unk_232 = 0;
ptr->unk_233 = 0;
}
void sub_800D780(struct UnkRfuStruct_Sub_Unused *ptr)
{
s32 i;
s32 j;
for (i = 0; i < 2; i++)
{
for (j = 0; j < 256; j++)
{
ptr->unk_00[i][j] = 0;
}
}
ptr->unk_201 = 0;
ptr->unk_200 = 0;
ptr->unk_202 = 0;
ptr->unk_203 = 0;
}
void sub_800D7D8(struct UnkRfuStruct_2_Sub_124 *q1, u8 *q2)
{
s32 i;
u16 imeBak;
u8 count;
if (q1->unk_8c2 < 32)
{
imeBak = REG_IME;
REG_IME = 0;
count = 0;
for (i = 0; i < 70; i += 14)
{
if (q2[i] == 0 && q2[i + 1] == 0)
{
count++;
}
}
if (count != 5)
{
for (i = 0; i < 70; i++)
{
q1->unk_00[q1->unk_8c0][i] = q2[i];
}
q1->unk_8c0++;
q1->unk_8c0 %= 32;
q1->unk_8c2++;
for (i = 0; i < 70; i++)
{
q2[i] = 0;
}
}
REG_IME = imeBak;
}
else
{
q1->unk_8c3 = 1;
}
}
void sub_800D888(struct UnkRfuStruct_2_Sub_9e8 *q1, u8 *q2)
{
s32 i;
u16 imeBak;
if (q1->unk_232 < 40)
{
imeBak = REG_IME;
REG_IME = 0;
for (i = 0; i < 14; i++)
{
if (q2[i] != 0)
{
break;
}
}
if (i != 14)
{
for (i = 0; i < 14; i++)
{
q1->unk_00[q1->unk_230][i] = q2[i];
}
q1->unk_230++;
q1->unk_230 %= 40;
q1->unk_232++;
for (i = 0; i < 14; i++)
{
q2[i] = 0;
}
}
REG_IME = imeBak;
}
else
{
q1->unk_233 = 1;
}
}
bool8 sub_800D934(struct UnkRfuStruct_2_Sub_124 *q1, u8 *q2)
{
u16 imeBak;
s32 i;
imeBak = REG_IME;
REG_IME = 0;
if (q1->unk_8c0 == q1->unk_8c1 || q1->unk_8c3 != 0)
{
for (i = 0; i < 70; i++)
{
q2[i] = 0;
}
REG_IME = imeBak;
return FALSE;
}
for (i = 0; i < 70; i++)
{
q2[i] = q1->unk_00[q1->unk_8c1][i];
}
q1->unk_8c1++;
q1->unk_8c1 %= 32;
q1->unk_8c2--;
REG_IME = imeBak;
return TRUE;
}
bool8 sub_800D9DC(struct UnkRfuStruct_2_Sub_9e8 *q1, u8 *q2)
{
s32 i;
u16 imeBak;
if (q1->unk_230 == q1->unk_231 || q1->unk_233 != 0)
{
return FALSE;
}
imeBak = REG_IME;
REG_IME = 0;
for (i = 0; i < 14; i++)
{
q2[i] = q1->unk_00[q1->unk_231][i];
}
q1->unk_231++;
q1->unk_231 %= 40;
q1->unk_232--;
REG_IME = imeBak;
return TRUE;
}
void sub_800DA68(struct UnkRfuStruct_2_Sub_c1c *q1, const u8 *q2)
{
s32 i;
if (q2[1] == 0)
{
sub_800DAC8(q1, NULL);
}
else
{
for (i = 0; i < 14; i++)
{
q1->unk_00[q1->unk_1c][i] = q2[i];
}
q1->unk_1c++;
q1->unk_1c %= 2;
if (q1->unk_1e < 2)
{
q1->unk_1e++;
}
else
{
q1->unk_1d = q1->unk_1c;
}
}
}
bool8 sub_800DAC8(struct UnkRfuStruct_2_Sub_c1c *q1, u8 *q2)
{
s32 i;
if (q1->unk_1e == 0)
{
return FALSE;
}
if (q2 != NULL)
{
for (i = 0; i < 14; i++)
{
q2[i] = q1->unk_00[q1->unk_1d][i];
}
}
q1->unk_1d++;
q1->unk_1d %= 2;
q1->unk_1e--;
return TRUE;
}
void sub_800DB18(struct UnkRfuStruct_Sub_Unused *q1, u8 *q2)
{
s32 i;
if (q1->unk_202 < 2)
{
for (i = 0; i < 256; i++)
{
q1->unk_00[q1->unk_200][i] = q2[i];
}
q1->unk_200++;
q1->unk_200 %= 2;
q1->unk_202++;
}
else
{
q1->unk_203 = 1;
}
}
bool8 sub_800DB84(struct UnkRfuStruct_Sub_Unused *q1, u8 *q2)
{
s32 i;
if (q1->unk_200 == q1->unk_201 || q1->unk_203)
{
return FALSE;
}
for (i = 0; i < 256; i++)
{
q2[i] = q1->unk_00[q1->unk_201][i];
}
q1->unk_201++;
q1->unk_201 %= 2;
q1->unk_202--;
return TRUE;
}
void sub_800DBF8(u8 *q1, u8 mode)
{
s32 i;
u8 rval;
u16 r5 = 0;
switch (mode)
{
case 0:
for (i = 0; i < 200; i++)
{
q1[i] = i + 1;
r5 += i + 1;
}
*((u16 *)(q1 + i)) = r5;
break;
case 1:
for (i = 0; i < 100; i++)
{
q1[i] = i + 1;
r5 += i + 1;
}
*((u16 *)(q1 + 200)) = r5;
break;
case 2:
for (i = 0; i < 200; i++)
{
rval = Random();
q1[i] = rval;
r5 += rval;
}
*((u16 *)(q1 + i)) = r5;
break;
case 3:
for (i = 0; i < 200; i++)
{
q1[i] = i + 1 + gUnknown_03000D74;
r5 += (i + 1 + gUnknown_03000D74) & 0xFF;
}
*((u16 *)(q1 + i)) = r5;
gUnknown_03000D74++;
break;
}
}
// File boundary here maybe?
void PkmnStrToASCII(u8 *q1, const u8 *q2)
{
s32 i;
for (i = 0; q2[i] != EOS; i++)
{
q1[i] = sWireless_RSEtoASCIITable[q2[i]];
}
q1[i] = 0;
}
void ASCIIToPkmnStr(u8 *q1, const u8 *q2)
{
s32 i;
for (i = 0; q2[i] != 0; i++)
{
q1[i] = sWireless_ASCIItoRSETable[q2[i]];
}
q1[i] = EOS;
}
#ifdef NONMATCHING
u8 sub_800DD1C(u8 maxFlags)
{
u8 flagCount = 0;
u32 flags = gRfuLinkStatus->connSlotFlag;
u8 i;
if (gRfuLinkStatus->parentChild == 1)
{
for (i = 0; i < 4; flags >>= 1, i++)
{
if (flags & 1)
{
if (maxFlags == flagCount + 1)
return gRfuLinkStatus->strength[i];
flagCount++;
}
}
}
else
{
for (i = 0; i < 4; flags >>= 1, i++)
{
if (flags & 1)
return gRfuLinkStatus->strength[i];
}
}
return 0;
}
#else
NAKED u8 sub_800DD1C(u8 maxFlags)
{
asm_unified("\tpush {r4-r7,lr}\n"
"\tlsls r0, 24\n"
"\tlsrs r5, r0, 24\n"
"\tmovs r6, 0\n"
"\tldr r0, =gRfuLinkStatus\n"
"\tldr r4, [r0]\n"
"\tldrb r2, [r4, 0x2]\n"
"\tldrb r1, [r4]\n"
"\tadds r7, r0, 0\n"
"\tcmp r1, 0x1\n"
"\tbne _0800DD72\n"
"\tmovs r3, 0\n"
"\tands r1, r2\n"
"\tcmp r1, 0\n"
"\tbeq _0800DD4E\n"
"\tcmp r5, 0x1\n"
"\tbne _0800DD48\n"
"\tldrb r0, [r4, 0xA]\n"
"\tb _0800DD8C\n"
"\t.pool\n"
"_0800DD48:\n"
"\tadds r0, r6, 0x1\n"
"\tlsls r0, 24\n"
"\tlsrs r6, r0, 24\n"
"_0800DD4E:\n"
"\tlsrs r2, 1\n"
"\tadds r0, r3, 0x1\n"
"\tlsls r0, 24\n"
"\tlsrs r3, r0, 24\n"
"\tcmp r3, 0x3\n"
"\tbhi _0800DD8A\n"
"\tmovs r0, 0x1\n"
"\tands r0, r2\n"
"\tcmp r0, 0\n"
"\tbeq _0800DD4E\n"
"\tadds r0, r6, 0x1\n"
"\tcmp r5, r0\n"
"\tbne _0800DD48\n"
"_0800DD68:\n"
"\tldr r0, [r7]\n"
"\tadds r0, 0xA\n"
"\tadds r0, r3\n"
"\tldrb r0, [r0]\n"
"\tb _0800DD8C\n"
"_0800DD72:\n"
"\tmovs r3, 0\n"
"\tmovs r1, 0x1\n"
"_0800DD76:\n"
"\tadds r0, r2, 0\n"
"\tands r0, r1\n"
"\tcmp r0, 0\n"
"\tbne _0800DD68\n"
"\tlsrs r2, 1\n"
"\tadds r0, r3, 0x1\n"
"\tlsls r0, 24\n"
"\tlsrs r3, r0, 24\n"
"\tcmp r3, 0x3\n"
"\tbls _0800DD76\n"
"_0800DD8A:\n"
"\tmovs r0, 0\n"
"_0800DD8C:\n"
"\tpop {r4-r7}\n"
"\tpop {r1}\n"
"\tbx r1");
}
#endif
void sub_800DD94(struct GFtgtGname *data, u8 r9, bool32 r2, s32 r3)
{
s32 i;
for (i = 0; i < 2; i++)
{
data->unk_00.playerTrainerId[i] = gSaveBlock2Ptr->playerTrainerId[i];
}
for (i = 0; i < 4; i++)
{
data->child_sprite_gender[i] = r3;
r3 >>= 8;
}
data->playerGender = gSaveBlock2Ptr->playerGender;
data->activity = r9;
data->started = r2;
data->unk_00.language = GAME_LANGUAGE;
data->unk_00.version = GAME_VERSION;
data->unk_00.hasNews = 0;
data->unk_00.hasCard = 0;
data->unk_00.unk_00_6 = 0;
data->unk_00.isChampion = FlagGet(FLAG_IS_CHAMPION);
data->unk_00.hasNationalDex = IsNationalPokedexEnabled();
data->unk_00.gameClear = FlagGet(FLAG_SYS_GAME_CLEAR);
}
bool8 sub_800DE7C(struct GFtgtGname *buff1, u8 *buff2, u8 idx)
{
bool8 retVal;
if (lman.parent_child == 1)
{
retVal = TRUE;
if (sub_8010454(gRfuLinkStatus->partner[idx].serialNo) && ((gRfuLinkStatus->getNameFlag >> idx) & 1))
{
memcpy(buff1, gRfuLinkStatus->partner[idx].gname, 0xD);
memcpy(buff2, gRfuLinkStatus->partner[idx].uname, PLAYER_NAME_LENGTH + 1);
}
else
{
memset(buff1, 0, 0xD);
memset(buff2, 0, PLAYER_NAME_LENGTH + 1);
}
}
else
{
retVal = FALSE;
if (sub_8010454(gRfuLinkStatus->partner[idx].serialNo))
{
memcpy(buff1, gRfuLinkStatus->partner[idx].gname, 0xD);
memcpy(buff2, gRfuLinkStatus->partner[idx].uname, PLAYER_NAME_LENGTH + 1);
}
else
{
memset(buff1, 0, 0xD);
memset(buff2, 0, PLAYER_NAME_LENGTH + 1);
}
}
return retVal;
}
bool8 sub_800DF34(struct GFtgtGname *buff1, u8 *buff2, u8 idx)
{
bool8 retVal = FALSE;
if (gRfuLinkStatus->partner[idx].serialNo == 0x7F7D)
{
memcpy(buff1, gRfuLinkStatus->partner[idx].gname, 0xD);
memcpy(buff2, gRfuLinkStatus->partner[idx].uname, 8);
retVal = TRUE;
}
else
{
memset(buff1, 0, 0xD);
memset(buff2, 0, 8);
}
return retVal;
}
void sub_800DF90(struct GFtgtGname *buff1, u8 *buff2)
{
memcpy(buff1, &gUnknown_02022B14, 0xD);
memcpy(buff2, gUnknown_02022B22, 8);
}
void CreateWirelessStatusIndicatorSprite(u8 x, u8 y)
{
u8 sprId;
if (x == 0 && y == 0)
{
x = 0xE7;
y = 0x08;
}
if (gRfuLinkStatus->parentChild == 1)
{
sprId = CreateSprite(&sWirelessStatusIndicatorSpriteTemplate, x, y, 0);
gSprites[sprId].data[7] = 0x1234;
gSprites[sprId].data[6] = GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag);
gSprites[sprId].invisible = TRUE;
gWirelessStatusIndicatorSpriteId = sprId;
}
else
{
gWirelessStatusIndicatorSpriteId = CreateSprite(&sWirelessStatusIndicatorSpriteTemplate, x, y, 0);
gSprites[gWirelessStatusIndicatorSpriteId].data[7] = 0x1234;
gSprites[gWirelessStatusIndicatorSpriteId].data[6] = GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag);
gSprites[gWirelessStatusIndicatorSpriteId].invisible = TRUE;
}
}
void DestroyWirelessStatusIndicatorSprite(void)
{
if (gSprites[gWirelessStatusIndicatorSpriteId].data[7] == 0x1234)
{
gSprites[gWirelessStatusIndicatorSpriteId].data[7] = 0;
DestroySprite(&gSprites[gWirelessStatusIndicatorSpriteId]);
gMain.oamBuffer[125] = gDummyOamData;
CpuCopy16(&gDummyOamData, (struct OamData *)OAM + 125, sizeof(struct OamData));
}
}
void LoadWirelessStatusIndicatorSpriteGfx(void)
{
if (GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag) == 0xFFFF)
{
LoadCompressedSpriteSheet(&sWirelessStatusIndicatorSpriteSheet);
}
LoadSpritePalette(&sWirelessStatusIndicatorSpritePalette);
gWirelessStatusIndicatorSpriteId = 0xFF;
}
u8 sub_800E124(void)
{
u8 i;
u8 flags = gRfuLinkStatus->connSlotFlag;
for (i = 0; i < 4; i++)
{
if (flags & 1)
{
return gRfuLinkStatus->strength[i];
}
flags >>= 1;
}
return 0;
}
void sub_800E15C(struct Sprite *sprite, s32 signalStrengthAnimNum)
{
if (sprite->data[2] != signalStrengthAnimNum)
{
sprite->data[2] = signalStrengthAnimNum;
sprite->data[3] = 0;
sprite->data[4] = 0;
}
}
void sub_800E174(void)
{
if (gWirelessStatusIndicatorSpriteId != 0xFF && gSprites[gWirelessStatusIndicatorSpriteId].data[7] == 0x1234)
{
struct Sprite *sprite = &gSprites[gWirelessStatusIndicatorSpriteId];
u8 signalStrength = 255;
u8 i = 0;
if (gRfuLinkStatus->parentChild == 1)
{
for (i = 0; i < GetLinkPlayerCount() - 1; i++)
{
if (signalStrength >= sub_800DD1C(i + 1))
{
signalStrength = sub_800DD1C(i + 1);
}
}
}
else
{
signalStrength = sub_800E124();
}
if (sub_8012224() == TRUE)
{
sprite->data[0] = 4;
}
else if (signalStrength < 25)
{
sprite->data[0] = 3;
}
else if (signalStrength >= 25 && signalStrength < 127)
{
sprite->data[0] = 2;
}
else if (signalStrength >= 127 && signalStrength < 229)
{
sprite->data[0] = 1;
}
else if (signalStrength >= 229)
{
sprite->data[0] = 0;
}
if (sprite->data[0] != sprite->data[1])
{
sub_800E15C(sprite, sprite->data[0]);
sprite->data[1] = sprite->data[0];
}
if (sprite->anims[sprite->data[2]][sprite->data[4]].frame.duration < sprite->data[3])
{
sprite->data[4]++;
sprite->data[3] = 0;
if (sprite->anims[sprite->data[2]][sprite->data[4]].type == -2)
{
sprite->data[4] = 0;
}
}
else
{
sprite->data[3]++;
}
gMain.oamBuffer[125] = sWirelessStatusIndicatorOamData;
gMain.oamBuffer[125].x = sprite->pos1.x + sprite->centerToCornerVecX;
gMain.oamBuffer[125].y = sprite->pos1.y + sprite->centerToCornerVecY;
gMain.oamBuffer[125].paletteNum = sprite->oam.paletteNum;
gMain.oamBuffer[125].tileNum = sprite->data[6] + sprite->anims[sprite->data[2]][sprite->data[4]].frame.imageValue;
CpuCopy16(gMain.oamBuffer + 125, (struct OamData *)OAM + 125, sizeof(struct OamData));
if (sub_8011A74() == 1)
{
DestroyWirelessStatusIndicatorSprite();
}
}
}
void CopyTrainerRecord(struct TrainerNameRecord *dest, u32 trainerId, const u8 *name)
{
dest->trainerId = trainerId;
StringCopy(dest->trainerName, name);
}
bool32 NameIsNotEmpty(const u8 *name)
{
s32 i;
for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++)
{
if (name[i] != 0)
{
return TRUE;
}
}
return FALSE;
}
// Save the currently connected players into the trainer records, shifting all previous records down.
void RecordMixTrainerNames(void)
{
if (gWirelessCommType != 0)
{
s32 i;
s32 j;
s32 nextSpace;
s32 connectedTrainerRecordIndices[5];
struct TrainerNameRecord *newRecords = calloc(20, sizeof(struct TrainerNameRecord));
// Check if we already have a record saved for connected trainers.
for (i = 0; i < GetLinkPlayerCount(); i++)
{
connectedTrainerRecordIndices[i] = -1;
for (j = 0; j < 20; j++)
{
if ((u16)gLinkPlayers[i].trainerId == gSaveBlock1Ptr->trainerNameRecords[j].trainerId && StringCompare(gLinkPlayers[i].name, gSaveBlock1Ptr->trainerNameRecords[j].trainerName) == 0)
{
connectedTrainerRecordIndices[i] = j;
}
}
}
// Save the connected trainers first, at the top of the list.
nextSpace = 0;
for (i = 0; i < GetLinkPlayerCount(); i++)
{
if (i != GetMultiplayerId() && gLinkPlayers[i].language != LANGUAGE_JAPANESE)
{
CopyTrainerRecord(&newRecords[nextSpace], (u16)gLinkPlayers[i].trainerId, gLinkPlayers[i].name);
// If we already had a record for this trainer, wipe it so that the next step doesn't duplicate it.
if (connectedTrainerRecordIndices[i] >= 0)
{
memset(gSaveBlock1Ptr->trainerNameRecords[connectedTrainerRecordIndices[i]].trainerName, 0, 8);
}
nextSpace++;
}
}
// Copy all non-empty records to the new list, in the order they appear on the old list. If the list is full,
// the last (oldest) records will be dropped.
for (i = 0; i < 20; i++)
{
if (NameIsNotEmpty(gSaveBlock1Ptr->trainerNameRecords[i].trainerName))
{
CopyTrainerRecord(&newRecords[nextSpace], gSaveBlock1Ptr->trainerNameRecords[i].trainerId, gSaveBlock1Ptr->trainerNameRecords[i].trainerName);
if (++nextSpace >= 20)
{
break;
}
}
}
// Finalize the new list, and clean up.
memcpy(gSaveBlock1Ptr->trainerNameRecords, newRecords, 20 * sizeof(struct TrainerNameRecord));
free(newRecords);
}
}
bool32 sub_800E540(u16 id, u8 *name)
{
s32 i;
for (i = 0; i < 20; i++)
{
if (StringCompare(gSaveBlock1Ptr->trainerNameRecords[i].trainerName, name) == 0 && gSaveBlock1Ptr->trainerNameRecords[i].trainerId == id)
{
return TRUE;
}
if (!NameIsNotEmpty(gSaveBlock1Ptr->trainerNameRecords[i].trainerName))
{
return FALSE;
}
}
return FALSE;
}
void WipeTrainerNameRecords(void)
{
s32 i;
for (i = 0; i < 20; i++)
{
gSaveBlock1Ptr->trainerNameRecords[i].trainerId = 0;
CpuFill16(0, gSaveBlock1Ptr->trainerNameRecords[i].trainerName, 8);
}
}

View File

@@ -2913,7 +2913,7 @@ bool32 sub_808766C(void)
static u32 GetLinkSendQueueLength(void)
{
if (gWirelessCommType != 0)
return gUnknown_03005000.unk_9e8.unk_232;
return Rfu.unk_9e8.unk_232;
else
return gLink.sendQueue.count;
}

View File

@@ -3527,7 +3527,7 @@ static void CursorCb_Register(u8 taskId)
u16 species = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES);
u8 obedience = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_OBEDIENCE);
switch (CanRegisterMonForTradingBoard(*(struct UnkLinkRfuStruct_02022B14Substruct *)sub_800F7DC(), species2, species, obedience))
switch (CanRegisterMonForTradingBoard(*(struct GFtgtGnameSub *)sub_800F7DC(), species2, species, obedience))
{
case CANT_REGISTER_MON:
StringExpandPlaceholders(gStringVar4, gText_PkmnCantBeTradedNow);
@@ -3553,7 +3553,7 @@ static void CursorCb_Trade1(u8 taskId)
u16 species2 = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES2);
u16 species = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES);
u8 obedience = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_OBEDIENCE);
u32 stringId = GetUnionRoomTradeMessageId(*(struct UnkLinkRfuStruct_02022B14Substruct *)sub_800F7DC(), gUnknown_02022C38, species2, gUnionRoomOfferedSpecies, gUnionRoomRequestedMonType, species, obedience);
u32 stringId = GetUnionRoomTradeMessageId(*(struct GFtgtGnameSub *)sub_800F7DC(), gUnknown_02022C38, species2, gUnionRoomOfferedSpecies, gUnionRoomRequestedMonType, species, obedience);
if (stringId != UR_TRADE_MSG_NONE)
{

View File

@@ -2040,7 +2040,7 @@ static int sub_802C6B0(void)
static bool32 sub_802C70C(void)
{
return !gUnknown_03005000.unk_124.unk_8c2 && !gUnknown_03005000.unk_9e8.unk_232;
return !Rfu.unk_124.unk_8c2 && !Rfu.unk_9e8.unk_232;
}
static int sub_802C73C(u8 *arg0)

View File

@@ -236,7 +236,7 @@ static bool8 SendLinkData(const void *linkData, u32 size)
{
if (gUnknown_02022C2C == 29)
{
rfu_NI_setSendData(gUnknown_03004140.unk_00, 84, linkData, size);
rfu_NI_setSendData(lman.acceptSlot_flag, 84, linkData, size);
return TRUE;
}
else
@@ -254,7 +254,7 @@ static bool32 sub_80771BC(void)
{
if (gUnknown_02022C2C == 29)
{
if (gRfuSlotStatusNI[sub_800E87C(gUnknown_03004140.unk_00)]->send.state == 0)
if (gRfuSlotStatusNI[sub_800E87C(lman.acceptSlot_flag)]->send.state == 0)
return TRUE;
else
return FALSE;
@@ -273,7 +273,7 @@ static u32 _GetBlockReceivedStatus(void)
static void TradeResetReceivedFlags(void)
{
if (IsWirelessTrade())
rfu_clearSlot(12, gUnknown_03004140.unk_00);
rfu_clearSlot(12, lman.acceptSlot_flag);
else
ResetBlockReceivedFlags();
}
@@ -281,7 +281,7 @@ static void TradeResetReceivedFlags(void)
static void TradeResetReceivedFlag(u32 who)
{
if (IsWirelessTrade())
rfu_clearSlot(12, gUnknown_03004140.unk_00);
rfu_clearSlot(12, lman.acceptSlot_flag);
else
ResetBlockReceivedFlag(who);
}
@@ -2405,15 +2405,15 @@ static bool32 IsDeoxysOrMewUntradable(u16 species, bool8 isObedientBitSet)
return FALSE;
}
int GetUnionRoomTradeMessageId(struct UnkLinkRfuStruct_02022B14Substruct rfuPlayer, struct UnkLinkRfuStruct_02022B14Substruct rfuPartner, u16 playerSpecies2, u16 partnerSpecies, u8 requestedType, u16 playerSpecies, u8 isObedientBitSet)
int GetUnionRoomTradeMessageId(struct GFtgtGnameSub rfuPlayer, struct GFtgtGnameSub rfuPartner, u16 playerSpecies2, u16 partnerSpecies, u8 requestedType, u16 playerSpecies, u8 isObedientBitSet)
{
bool8 playerHasNationalDex = rfuPlayer.hasNationalDex;
bool8 playerIsChampion = rfuPlayer.isChampion;
bool8 partnerHasNationalDex = rfuPartner.hasNationalDex;
bool8 partnerIsChampion = rfuPartner.isChampion;
u8 r1 = rfuPartner.unk_01_2;
u8 r1 = rfuPartner.version;
if (r1 != 3)
if (r1 != VERSION_EMERALD)
{
if (!playerIsChampion)
{
@@ -2476,7 +2476,7 @@ int GetUnionRoomTradeMessageId(struct UnkLinkRfuStruct_02022B14Substruct rfuPlay
return UR_TRADE_MSG_NONE;
}
int CanRegisterMonForTradingBoard(struct UnkLinkRfuStruct_02022B14Substruct rfuPlayer, u16 species2, u16 species, u8 isObedientBitSet)
int CanRegisterMonForTradingBoard(struct GFtgtGnameSub rfuPlayer, u16 species2, u16 species, u8 isObedientBitSet)
{
bool8 hasNationalDex = rfuPlayer.hasNationalDex;

View File

@@ -59,7 +59,7 @@ EWRAM_DATA u8 gUnknown_02022C2C = 0;
EWRAM_DATA u8 gUnknown_02022C2D = 0;
EWRAM_DATA union UnkUnion_Main gUnknown_02022C30 = {};
EWRAM_DATA u32 gFiller_02022C34 = 0;
EWRAM_DATA struct UnkLinkRfuStruct_02022B14Substruct gUnknown_02022C38 = {};
EWRAM_DATA struct GFtgtGnameSub gUnknown_02022C38 = {};
EWRAM_DATA u16 gUnionRoomOfferedSpecies = 0;
EWRAM_DATA u8 gUnionRoomRequestedMonType = 0;
static EWRAM_DATA struct UnionRoomTrade sUnionRoomTrade = {};
@@ -106,7 +106,7 @@ void sub_801AC54(void);
void sub_80149D8(void);
void MG_DrawTextBorder(u8 windowId);
s8 mevent_message_print_and_prompt_yes_no(u8 *textState, u8 *arg1, u8 arg2, const u8 *str);
bool32 sub_8016F1C(struct UnkLinkRfuStruct_02022B14 *arg0, s16 arg1);
bool32 sub_8016F1C(struct GFtgtGname *arg0, s16 arg1);
u8 sub_8016DF0(struct UnkStruct_Main4 *arg0, struct UnkStruct_Main4 *arg1, u32 arg2);
void sub_8019F2C(void);
static bool32 RegisterTradeMonAndGetIsEgg(u32 monId, struct UnionRoomTrade *trade);
@@ -875,9 +875,9 @@ void sub_80134E8(u8 taskId)
{
// this unused variable along with the assignment is needed to match
u32 unusedVar;
unusedVar = data->field_0->arr[id].unk.field_0.unk_0a_0;
unusedVar = data->field_0->arr[id].unk.field_0.activity;
if (data->field_0->arr[id].field_1A_0 == 1 && !data->field_0->arr[id].unk.field_0.unk_0a_7)
if (data->field_0->arr[id].field_1A_0 == 1 && !data->field_0->arr[id].unk.field_0.started)
{
u32 var = sub_8013B8C(data, id);
if (var == 0)
@@ -919,7 +919,7 @@ void sub_80134E8(u8 taskId)
case 6:
if (gReceivedRemoteLinkPlayers != 0)
{
gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.unk_0a_0;
gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.activity;
sub_8011A64(0, 0);
switch (gUnknown_02022C2C)
{
@@ -1078,7 +1078,7 @@ u32 sub_8013B8C(struct UnkStruct_Group *arg0, s32 id)
{
struct UnkStruct_x20 *structPtr = &arg0->field_0->arr[id];
if (gUnknown_02022C2C == 4 && structPtr->unk.field_0.unk_00.unk_01_2 != 3)
if (gUnknown_02022C2C == 4 && structPtr->unk.field_0.unk_00.version != VERSION_EMERALD)
{
if (!(gSaveBlock2Ptr->specialSaveWarpFlags & CHAMPION_SAVEWARP))
return 1;
@@ -1187,7 +1187,7 @@ u8 sub_8013DBC(struct UnkStruct_Group *data, u32 id)
{
if (data->field_0->arr[id].field_1A_0 == 1)
{
if (data->field_0->arr[id].unk.field_0.unk_0a_7)
if (data->field_0->arr[id].unk.field_0.started)
return 3;
else if (data->field_0->arr[id].field_1A_1 != 0)
return 1;
@@ -1946,9 +1946,9 @@ void sub_8014F48(u8 taskId)
{
// this unused variable along with the assignment is needed to match
u32 unusedVar;
unusedVar = data->field_0->arr[id].unk.field_0.unk_0a_0;
unusedVar = data->field_0->arr[id].unk.field_0.activity;
if (data->field_0->arr[id].field_1A_0 == 1 && !data->field_0->arr[id].unk.field_0.unk_0a_7)
if (data->field_0->arr[id].field_1A_0 == 1 && !data->field_0->arr[id].unk.field_0.started)
{
data->field_F = id;
LoadWirelessStatusIndicatorSpriteGfx();
@@ -1979,7 +1979,7 @@ void sub_8014F48(u8 taskId)
case 5:
if (gReceivedRemoteLinkPlayers != 0)
{
gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.unk_0a_0;
gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.activity;
data->state = 10;
}
@@ -2108,7 +2108,7 @@ void sub_80152F4(u8 taskId)
id = ListMenu_ProcessInput(data->listTaskId);
if (data->field_14 > 120)
{
if (data->field_0->arr[0].field_1A_0 == 1 && !data->field_0->arr[0].unk.field_0.unk_0a_7)
if (data->field_0->arr[0].field_1A_0 == 1 && !data->field_0->arr[0].unk.field_0.started)
{
if (sub_8016F1C(&data->field_0->arr[0].unk.field_0, data->field_12 + 7))
{
@@ -2144,7 +2144,7 @@ void sub_80152F4(u8 taskId)
case 5:
if (gReceivedRemoteLinkPlayers != 0)
{
gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.unk_0a_0;
gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.activity;
data->state = 12;
}
@@ -3250,11 +3250,11 @@ void sub_8016CA0(u8 taskId)
for (i = 0; i < 4; i++)
{
r4 = sub_800DE7C(&sp0.field_0, sp0.playerName, i);
if (!sub_8013D88(sp0.field_0.unk_0a_0, gTasks[taskId].data[4]))
if (!sub_8013D88(sp0.field_0.activity, gTasks[taskId].data[4]))
{
sp0 = gUnknown_082F045C;
}
if (sp0.field_0.unk_00.unk_00_0 == 1)
if (sp0.field_0.unk_00.language == 1)
{
sp0 = gUnknown_082F045C;
}
@@ -3296,7 +3296,7 @@ void sub_8016E24(u8 taskId)
for (i = 0; i < 4; i++)
{
sub_800DE7C(&ptr[0]->arr[i].unk0.field_0, ptr[0]->arr[i].unk0.playerName, i);
if (!sub_8013D88(ptr[0]->arr[i].unk0.field_0.unk_0a_0, gTasks[taskId].data[2]))
if (!sub_8013D88(ptr[0]->arr[i].unk0.field_0.activity, gTasks[taskId].data[2]))
{
ptr[0]->arr[i].unk0 = gUnknown_082F045C;
}
@@ -3311,11 +3311,11 @@ void sub_8016E24(u8 taskId)
}
}
bool32 sub_8016F1C(struct UnkLinkRfuStruct_02022B14 *arg0, s16 arg1)
bool32 sub_8016F1C(struct GFtgtGname *arg0, s16 arg1)
{
if (arg1 == 7)
{
if (!arg0->unk_00.unk_00_5)
if (!arg0->unk_00.hasCard)
{
return FALSE;
}
@@ -3326,7 +3326,7 @@ bool32 sub_8016F1C(struct UnkLinkRfuStruct_02022B14 *arg0, s16 arg1)
}
else if (arg1 == 8)
{
if (!arg0->unk_00.unk_00_4)
if (!arg0->unk_00.hasNews)
{
return FALSE;
}
@@ -3703,19 +3703,19 @@ bool32 sub_8017678(struct UnkStruct_Shared *arg0, struct UnkStruct_Shared *arg1)
{
s32 i;
if (arg0->field_0.unk_0a_0 != arg1->field_0.unk_0a_0)
if (arg0->field_0.activity != arg1->field_0.activity)
{
return TRUE;
}
if (arg0->field_0.unk_0a_7 != arg1->field_0.unk_0a_7)
if (arg0->field_0.started != arg1->field_0.started)
{
return TRUE;
}
for (i = 0; i < 4; i++)
{
if (arg0->field_0.unk_04[i] != arg1->field_0.unk_04[i])
if (arg0->field_0.child_sprite_gender[i] != arg1->field_0.child_sprite_gender[i])
{
return TRUE;
}
@@ -3783,7 +3783,7 @@ void sub_80177B8(u8 arg0, u8 arg1, u8 arg2, struct UnkStruct_x20 *arg3, u8 arg4,
StringAppend(gStringVar4, sText_Colon);
sub_80173E0(arg0, 1, gStringVar4, arg1, arg2, 0);
arg1 += 18;
r2 = arg3->unk.field_0.unk_0a_0;
r2 = arg3->unk.field_0.activity;
if (arg3->field_1A_0 == 1 && !(r2 & 0x40))
{
sub_8018404(gStringVar4, arg3);
@@ -3859,11 +3859,11 @@ s32 sub_80179D4(struct UnkStruct_Main0 *arg0, u8 arg1, u8 arg2, u32 playerGender
struct UnkStruct_x20 * r5 = &arg0->arr[arg2];
if (!r5->unk.field_0.unk_0a_7 && arg1 == 0)
if (!r5->unk.field_0.started && arg1 == 0)
{
sub_8018404(gStringVar1, r5);
r2 = sub_800E540(ReadAsU16(r5->unk.field_0.unk_00.playerTrainerId), gStringVar1);
if (r5->unk.field_0.unk_0a_0 == 0x45)
if (r5->unk.field_0.activity == 0x45)
{
StringExpandPlaceholders(gStringVar4, sJoinChatTexts[r2][playerGender]);
return 2;
@@ -3881,7 +3881,7 @@ s32 sub_80179D4(struct UnkStruct_Main0 *arg0, u8 arg1, u8 arg2, u32 playerGender
{
playerGender = (r5->unk.field_0.unk_00.playerTrainerId[arg1 + 1] >> 3) & 1;
}
switch (r5->unk.field_0.unk_0a_0 & 0x3F)
switch (r5->unk.field_0.activity & 0x3F)
{
case 1:
StringExpandPlaceholders(gStringVar4, sBattleReactionTexts[playerGender][Random() % 4]);
@@ -3908,7 +3908,7 @@ void nullsub_14(u8 windowId, s32 itemId, u8 y)
}
void sub_8017B3C(u8 arg0, u8 arg1, struct UnkLinkRfuStruct_02022B14 * arg2, const u8 * str, u8 arg4)
void sub_8017B3C(u8 arg0, u8 arg1, struct GFtgtGname * arg2, const u8 * str, u8 arg4)
{
u8 sp8[4];
u16 r8 = arg2->species;
@@ -3932,7 +3932,7 @@ void sub_8017B3C(u8 arg0, u8 arg1, struct UnkLinkRfuStruct_02022B14 * arg2, cons
void sub_8017BE8(u8 windowId, s32 itemId, u8 y)
{
struct UnkStruct_Leader *leader = gUnknown_02022C30.leader;
struct UnkLinkRfuStruct_02022B14 *rfu;
struct GFtgtGname *rfu;
s32 i, j;
u8 sp4[11];
@@ -4340,5 +4340,5 @@ void sub_8018220(u8 *unused, struct UnkStruct_URoom *arg1, bool8 arg2)
void sub_8018404(u8 *dest, struct UnkStruct_x20 *arg1)
{
StringCopy7(dest, arg1->unk.playerName);
ConvertInternationalString(dest, arg1->unk.field_0.unk_00.unk_00_0);
ConvertInternationalString(dest, arg1->unk.field_0.unk_00.language);
}

View File

@@ -369,7 +369,7 @@ static void sub_801A8B0(u8 windowId, u8 fontId, const u8 * str, u8 x, u8 y, u8 m
u32 sub_801A960(struct UnkStruct_x20 * a0, u32 * a1)
{
s32 i, j, r2;
u32 result = a0->unk.field_0.unk_0a_0;
u32 result = a0->unk.field_0.activity;
for (i = 0; i < (unsigned)ARRAY_COUNT(gUnknown_082F0D70); i++)
{
@@ -386,7 +386,7 @@ u32 sub_801A960(struct UnkStruct_x20 * a0, u32 * a1)
r2 = 0;
for (j = 0; j < 4; j++)
{
if (a0->unk.field_0.unk_04[j] != 0)
if (a0->unk.field_0.child_sprite_gender[j] != 0)
{
r2++;
}

View File

@@ -418,13 +418,13 @@ void sub_8019F2C(void)
}
}
static u8 sub_8019F64(u32 r1, u32 unused, struct UnkLinkRfuStruct_02022B14 * r2)
static u8 sub_8019F64(u32 r1, u32 unused, struct GFtgtGname * r2)
{
if (r1 != 0)
{
return gUnknown_082F076F[r1];
}
else if (r2->unk_0a_0 == 0x45)
else if (r2->activity == 0x45)
{
return 1;
}
@@ -439,7 +439,7 @@ static u32 sub_8019F8C(u32 a0, u32 a1)
return sub_8097C8C(5 * a0 + a1 - 0x38);
}
static void sub_8019FA4(u32 r5, u32 r6, u8 r8, struct UnkLinkRfuStruct_02022B14 * r9)
static void sub_8019FA4(u32 r5, u32 r6, u8 r8, struct GFtgtGname * r9)
{
s32 x, y;
s32 r7 = 5 * r5 + r6;
@@ -462,7 +462,7 @@ static void sub_801A02C(u32 a0, u32 a1)
sub_8088B94(x, y, 0);
}
static void sub_801A064(u32 r7, struct UnkLinkRfuStruct_02022B14 * r8)
static void sub_801A064(u32 r7, struct GFtgtGname * r8)
{
s16 x, y, x2, y2;
s32 i;
@@ -479,21 +479,21 @@ static void sub_801A064(u32 r7, struct UnkLinkRfuStruct_02022B14 * r8)
}
for (i = 1; i < 5; i++)
{
if (r8->unk_04[i - 1] == 0)
if (r8->child_sprite_gender[i - 1] == 0)
{
sub_801A02C(r7, i);
}
else if (sub_80199E0(r7, i, x, y) == 0 && sub_80199E0(r7, i, x2, y2) == 0)
{
sub_8019FA4(r7, i, sub_8019978((r8->unk_04[i - 1] >> 3) & 1, r8->unk_04[i - 1] & 7), r8);
sub_8019FA4(r7, i, sub_8019978((r8->child_sprite_gender[i - 1] >> 3) & 1, r8->child_sprite_gender[i - 1] & 7), r8);
}
}
}
static void sub_801A16C(u32 r5, struct UnkLinkRfuStruct_02022B14 * r4)
static void sub_801A16C(u32 r5, struct GFtgtGname * r4)
{
u32 i;
switch (r4->unk_0a_0)
switch (r4->activity)
{
case 0x40:
case 0x54:
@@ -516,7 +516,7 @@ static void sub_801A16C(u32 r5, struct UnkLinkRfuStruct_02022B14 * r4)
}
}
static void sub_801A214(u32 r5, struct UnkLinkRfuStruct_02022B14 * unused)
static void sub_801A214(u32 r5, struct GFtgtGname * unused)
{
s32 i;
sub_8019D20(r5);