update documentation & func types
This commit is contained in:
+313
-474
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,163 @@
|
||||
#include "librfu.h"
|
||||
|
||||
extern const u16 _Str_Sio32ID[];
|
||||
|
||||
static void Sio32IDIntr(void);
|
||||
static void Sio32IDInit(void);
|
||||
static s32 Sio32IDMain(void);
|
||||
|
||||
struct RfuS32Id gRfuS32Id;
|
||||
|
||||
s32 AgbRFU_checkID(u8 r5)
|
||||
{
|
||||
u16 r8;
|
||||
vu16 *r4;
|
||||
s32 r6;
|
||||
|
||||
if (REG_IME == 0)
|
||||
return -1;
|
||||
r8 = REG_IE;
|
||||
gRfuState->state = 10;
|
||||
STWI_set_Callback_ID(Sio32IDIntr);
|
||||
Sio32IDInit();
|
||||
r4 = ®_TMCNT_L(gRfuState->timerSelect);
|
||||
r5 *= 8;
|
||||
while (--r5 != 0xFF)
|
||||
{
|
||||
r6 = Sio32IDMain();
|
||||
if (r6 != 0)
|
||||
break;
|
||||
r4[1] = 0;
|
||||
r4[0] = 0;
|
||||
r4[1] = TIMER_1024CLK | TIMER_ENABLE;
|
||||
while (r4[0] < 32)
|
||||
;
|
||||
r4[1] = 0;
|
||||
r4[0] = 0;
|
||||
}
|
||||
REG_IME = 0;
|
||||
REG_IE = r8;
|
||||
REG_IME = 1;
|
||||
gRfuState->state = 0;
|
||||
STWI_set_Callback_ID(NULL);
|
||||
return r6;
|
||||
}
|
||||
|
||||
static void Sio32IDInit(void)
|
||||
{
|
||||
REG_IME = 0;
|
||||
REG_IE &= ~((8 << gRfuState->timerSelect) | INTR_FLAG_SERIAL);
|
||||
REG_IME = 1;
|
||||
REG_RCNT = 0;
|
||||
REG_SIOCNT = SIO_32BIT_MODE;
|
||||
REG_SIOCNT |= SIO_INTR_ENABLE | SIO_ENABLE;
|
||||
CpuFill32(0, &gRfuS32Id, sizeof(struct RfuS32Id));
|
||||
REG_IF = INTR_FLAG_SERIAL;
|
||||
}
|
||||
|
||||
static s32 Sio32IDMain(void)
|
||||
{
|
||||
u8 r12;
|
||||
|
||||
switch (r12 = gRfuS32Id.unk1)
|
||||
{
|
||||
case 0:
|
||||
gRfuS32Id.unk0 = 1;
|
||||
REG_SIOCNT |= SIO_38400_BPS;
|
||||
REG_IME = r12;
|
||||
REG_IE |= INTR_FLAG_SERIAL;
|
||||
REG_IME = 1;
|
||||
gRfuS32Id.unk1 = 1;
|
||||
*(vu8 *)®_SIOCNT |= SIO_ENABLE;
|
||||
break;
|
||||
case 1:
|
||||
if (gRfuS32Id.unkA == 0)
|
||||
{
|
||||
if (gRfuS32Id.unk0 == 1)
|
||||
{
|
||||
if (gRfuS32Id.unk2 == 0)
|
||||
{
|
||||
REG_IME = gRfuS32Id.unk2;
|
||||
REG_SIOCNT |= SIO_ENABLE;
|
||||
REG_IME = r12;
|
||||
}
|
||||
}
|
||||
else if (gRfuS32Id.unk4 != 0x8001 && !gRfuS32Id.unk2)
|
||||
{
|
||||
REG_IME = gRfuS32Id.unk2;
|
||||
REG_IE &= ~INTR_FLAG_SERIAL;
|
||||
REG_IME = r12;
|
||||
REG_SIOCNT = gRfuS32Id.unk2;
|
||||
REG_SIOCNT = SIO_32BIT_MODE;
|
||||
REG_IF = INTR_FLAG_SERIAL;
|
||||
REG_SIOCNT |= SIO_INTR_ENABLE | SIO_ENABLE;
|
||||
REG_IME = gRfuS32Id.unk2;
|
||||
REG_IE |= INTR_FLAG_SERIAL;
|
||||
REG_IME = r12;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
gRfuS32Id.unk1 = 2;
|
||||
// fallthrough
|
||||
}
|
||||
default:
|
||||
return gRfuS32Id.unkA;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void Sio32IDIntr(void)
|
||||
{
|
||||
u32 r5;
|
||||
u16 r0;
|
||||
#ifndef NONMATCHING
|
||||
register u32 r1 asm("r1");
|
||||
register u16 r0_ asm("r0");
|
||||
#else
|
||||
u32 r1;
|
||||
u16 r0_;
|
||||
#endif
|
||||
|
||||
r5 = REG_SIODATA32;
|
||||
if (gRfuS32Id.unk0 != 1)
|
||||
REG_SIOCNT |= SIO_ENABLE;
|
||||
r1 = 16 * gRfuS32Id.unk0; // to handle side effect of inline asm
|
||||
r1 = (r5 << r1) >> 16;
|
||||
r5 = (r5 << 16 * (1 - gRfuS32Id.unk0)) >> 16;
|
||||
if (gRfuS32Id.unkA == 0)
|
||||
{
|
||||
if (r1 == gRfuS32Id.unk6)
|
||||
{
|
||||
if (gRfuS32Id.unk2 > 3)
|
||||
{
|
||||
gRfuS32Id.unkA = r5;
|
||||
}
|
||||
else if (r1 == (u16)~gRfuS32Id.unk4)
|
||||
{
|
||||
r0_ = ~gRfuS32Id.unk6;
|
||||
if (r5 == r0_)
|
||||
++gRfuS32Id.unk2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gRfuS32Id.unk2 = gRfuS32Id.unkA;
|
||||
}
|
||||
}
|
||||
if (gRfuS32Id.unk2 < 4)
|
||||
gRfuS32Id.unk4 = *(gRfuS32Id.unk2 + _Str_Sio32ID);
|
||||
else
|
||||
gRfuS32Id.unk4 = 0x8001;
|
||||
gRfuS32Id.unk6 = ~r5;
|
||||
REG_SIODATA32 = (gRfuS32Id.unk4 << 16 * (1 - gRfuS32Id.unk0))
|
||||
+ (gRfuS32Id.unk6 << 16 * gRfuS32Id.unk0);
|
||||
if (gRfuS32Id.unk0 == 1 && (gRfuS32Id.unk2 || r5 == 0x494E))
|
||||
{
|
||||
for (r0 = 0; r0 < 600; ++r0)
|
||||
;
|
||||
if (gRfuS32Id.unkA == 0)
|
||||
REG_SIOCNT |= SIO_ENABLE;
|
||||
}
|
||||
}
|
||||
+33
-34
@@ -1,4 +1,3 @@
|
||||
#include "global.h"
|
||||
#include "librfu.h"
|
||||
|
||||
static void STWI_intr_timer(void);
|
||||
@@ -12,7 +11,7 @@ static s32 STWI_reset_ClockCounter(void);
|
||||
void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam)
|
||||
{
|
||||
// If we're copying our interrupt into RAM, DMA it to block1 and use
|
||||
// block2 for our RfuStruct, otherwise block1 holds the RfuStruct.
|
||||
// block2 for our STWIStatus, otherwise block1 holds the STWIStatus.
|
||||
// interrupt usually is a pointer to gIntrTable[1]
|
||||
if (copyInterruptToRam == TRUE)
|
||||
{
|
||||
@@ -23,7 +22,7 @@ void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, b
|
||||
else
|
||||
{
|
||||
*interrupt = IntrSIO32;
|
||||
gRfuState = (struct RfuStruct *)interruptStruct->block1;
|
||||
gRfuState = (struct STWIStatus *)interruptStruct->block1;
|
||||
}
|
||||
gRfuState->rxPacket = &interruptStruct->rxPacketAlloc;
|
||||
gRfuState->txPacket = &interruptStruct->txPacketAlloc;
|
||||
@@ -142,7 +141,7 @@ u16 STWI_poll_CommandEnd(void)
|
||||
|
||||
void STWI_send_ResetREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_RESET))
|
||||
if (!STWI_init(ID_RESET_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -151,7 +150,7 @@ void STWI_send_ResetREQ(void)
|
||||
|
||||
void STWI_send_LinkStatusREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_LINK_STATUS))
|
||||
if (!STWI_init(ID_LINK_STATUS_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -160,7 +159,7 @@ void STWI_send_LinkStatusREQ(void)
|
||||
|
||||
void STWI_send_VersionStatusREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_VERSION_STATUS))
|
||||
if (!STWI_init(ID_VERSION_STATUS_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -169,7 +168,7 @@ void STWI_send_VersionStatusREQ(void)
|
||||
|
||||
void STWI_send_SystemStatusREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_SYSTEM_STATUS))
|
||||
if (!STWI_init(ID_SYSTEM_STATUS_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -178,7 +177,7 @@ void STWI_send_SystemStatusREQ(void)
|
||||
|
||||
void STWI_send_SlotStatusREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_SLOT_STATUS))
|
||||
if (!STWI_init(ID_SLOT_STATUS_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -187,7 +186,7 @@ void STWI_send_SlotStatusREQ(void)
|
||||
|
||||
void STWI_send_ConfigStatusREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_CONFIG_STATUS))
|
||||
if (!STWI_init(ID_CONFIG_STATUS_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -199,7 +198,7 @@ void STWI_send_GameConfigREQ(const u8 *unk1, const u8 *data)
|
||||
u8 *packetBytes;
|
||||
s32 i;
|
||||
|
||||
if (!STWI_init(RFU_GAME_CONFIG))
|
||||
if (!STWI_init(ID_GAME_CONFIG_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 6;
|
||||
// TODO: what is unk1
|
||||
@@ -226,7 +225,7 @@ void STWI_send_GameConfigREQ(const u8 *unk1, const u8 *data)
|
||||
|
||||
void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3)
|
||||
{
|
||||
if (!STWI_init(RFU_SYSTEM_CONFIG))
|
||||
if (!STWI_init(ID_SYSTEM_CONFIG_REQ))
|
||||
{
|
||||
u8 *packetBytes;
|
||||
|
||||
@@ -242,7 +241,7 @@ void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3)
|
||||
|
||||
void STWI_send_SC_StartREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_SC_START))
|
||||
if (!STWI_init(ID_SC_START_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -251,7 +250,7 @@ void STWI_send_SC_StartREQ(void)
|
||||
|
||||
void STWI_send_SC_PollingREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_SC_POLLING))
|
||||
if (!STWI_init(ID_SC_POLL_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -260,7 +259,7 @@ void STWI_send_SC_PollingREQ(void)
|
||||
|
||||
void STWI_send_SC_EndREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_SC_END))
|
||||
if (!STWI_init(ID_SC_END_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -269,7 +268,7 @@ void STWI_send_SC_EndREQ(void)
|
||||
|
||||
void STWI_send_SP_StartREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_SP_START))
|
||||
if (!STWI_init(ID_SP_START_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -278,7 +277,7 @@ void STWI_send_SP_StartREQ(void)
|
||||
|
||||
void STWI_send_SP_PollingREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_SP_POLLING))
|
||||
if (!STWI_init(ID_SP_POLL_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -287,7 +286,7 @@ void STWI_send_SP_PollingREQ(void)
|
||||
|
||||
void STWI_send_SP_EndREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_SP_END))
|
||||
if (!STWI_init(ID_SP_END_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -296,7 +295,7 @@ void STWI_send_SP_EndREQ(void)
|
||||
|
||||
void STWI_send_CP_StartREQ(u16 unk1)
|
||||
{
|
||||
if (!STWI_init(RFU_CP_START))
|
||||
if (!STWI_init(ID_CP_START_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 1;
|
||||
gRfuState->txPacket->rfuPacket32.data[0] = unk1;
|
||||
@@ -306,7 +305,7 @@ void STWI_send_CP_StartREQ(u16 unk1)
|
||||
|
||||
void STWI_send_CP_PollingREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_CP_POLLING))
|
||||
if (!STWI_init(ID_CP_POLL_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -315,7 +314,7 @@ void STWI_send_CP_PollingREQ(void)
|
||||
|
||||
void STWI_send_CP_EndREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_CP_END))
|
||||
if (!STWI_init(ID_CP_END_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -324,7 +323,7 @@ void STWI_send_CP_EndREQ(void)
|
||||
|
||||
void STWI_send_DataTxREQ(const void *in, u8 size)
|
||||
{
|
||||
if (!STWI_init(RFU_DATA_TX))
|
||||
if (!STWI_init(ID_DATA_TX_REQ))
|
||||
{
|
||||
u8 reqLength = (size / sizeof(u32));
|
||||
if (size & (sizeof(u32) - 1))
|
||||
@@ -337,7 +336,7 @@ void STWI_send_DataTxREQ(const void *in, u8 size)
|
||||
|
||||
void STWI_send_DataTxAndChangeREQ(const void *in, u8 size)
|
||||
{
|
||||
if (!STWI_init(RFU_DATA_TX_AND_CHANGE))
|
||||
if (!STWI_init(ID_DATA_TX_AND_CHANGE_REQ))
|
||||
{
|
||||
u8 reqLength = (size / sizeof(u32));
|
||||
if (size & (sizeof(u32) - 1))
|
||||
@@ -350,7 +349,7 @@ void STWI_send_DataTxAndChangeREQ(const void *in, u8 size)
|
||||
|
||||
void STWI_send_DataRxREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_DATA_RX))
|
||||
if (!STWI_init(ID_DATA_RX_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -359,7 +358,7 @@ void STWI_send_DataRxREQ(void)
|
||||
|
||||
void STWI_send_MS_ChangeREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_MS_CHANGE))
|
||||
if (!STWI_init(ID_MS_CHANGE_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -368,7 +367,7 @@ void STWI_send_MS_ChangeREQ(void)
|
||||
|
||||
void STWI_send_DataReadyAndChangeREQ(u8 unk)
|
||||
{
|
||||
if (!STWI_init(RFU_DATA_READY_AND_CHANGE))
|
||||
if (!STWI_init(ID_DATA_READY_AND_CHANGE_REQ))
|
||||
{
|
||||
if (!unk)
|
||||
{
|
||||
@@ -392,7 +391,7 @@ void STWI_send_DataReadyAndChangeREQ(u8 unk)
|
||||
|
||||
void STWI_send_DisconnectedAndChangeREQ(u8 unk0, u8 unk1)
|
||||
{
|
||||
if (!STWI_init(RFU_DISCONNECTED_AND_CHANGE))
|
||||
if (!STWI_init(ID_DISCONNECTED_AND_CHANGE_REQ))
|
||||
{
|
||||
u8 *packetBytes;
|
||||
|
||||
@@ -409,7 +408,7 @@ void STWI_send_DisconnectedAndChangeREQ(u8 unk0, u8 unk1)
|
||||
|
||||
void STWI_send_ResumeRetransmitAndChangeREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_RESUME_RETRANSMIT_AND_CHANGE))
|
||||
if (!STWI_init(ID_RESUME_RETRANSMIT_AND_CHANGE_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -418,7 +417,7 @@ void STWI_send_ResumeRetransmitAndChangeREQ(void)
|
||||
|
||||
void STWI_send_DisconnectREQ(u8 unk)
|
||||
{
|
||||
if (!STWI_init(RFU_DISCONNECT))
|
||||
if (!STWI_init(ID_DISCONNECT_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 1;
|
||||
gRfuState->txPacket->rfuPacket32.data[0] = unk;
|
||||
@@ -428,7 +427,7 @@ void STWI_send_DisconnectREQ(u8 unk)
|
||||
|
||||
void STWI_send_TestModeREQ(u8 unk0, u8 unk1)
|
||||
{
|
||||
if (!STWI_init(RFU_TEST_MODE))
|
||||
if (!STWI_init(ID_TEST_MODE_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 1;
|
||||
gRfuState->txPacket->rfuPacket32.data[0] = unk0 | (unk1 << 8);
|
||||
@@ -441,7 +440,7 @@ void STWI_send_CPR_StartREQ(u16 unk0, u16 unk1, u8 unk2)
|
||||
u32 *packetData;
|
||||
u32 arg1;
|
||||
|
||||
if (!STWI_init(RFU_CPR_START))
|
||||
if (!STWI_init(ID_CPR_START_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 2;
|
||||
arg1 = unk1 | (unk0 << 16);
|
||||
@@ -454,7 +453,7 @@ void STWI_send_CPR_StartREQ(u16 unk0, u16 unk1, u8 unk2)
|
||||
|
||||
void STWI_send_CPR_PollingREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_CPR_POLLING))
|
||||
if (!STWI_init(ID_CPR_POLL_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -463,7 +462,7 @@ void STWI_send_CPR_PollingREQ(void)
|
||||
|
||||
void STWI_send_CPR_EndREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_CPR_END))
|
||||
if (!STWI_init(ID_CPR_END_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -472,7 +471,7 @@ void STWI_send_CPR_EndREQ(void)
|
||||
|
||||
void STWI_send_StopModeREQ(void)
|
||||
{
|
||||
if (!STWI_init(RFU_STOP_MODE))
|
||||
if (!STWI_init(ID_STOP_MODE_REQ))
|
||||
{
|
||||
gRfuState->reqLength = 0;
|
||||
STWI_start_Command();
|
||||
@@ -614,7 +613,7 @@ static s32 STWI_restart_Command(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gRfuState->reqActiveCommand == RFU_MS_CHANGE || gRfuState->reqActiveCommand == RFU_DATA_TX_AND_CHANGE || gRfuState->reqActiveCommand == RFU_UNK35 || gRfuState->reqActiveCommand == RFU_RESUME_RETRANSMIT_AND_CHANGE)
|
||||
if (gRfuState->reqActiveCommand == ID_MS_CHANGE_REQ || gRfuState->reqActiveCommand == ID_DATA_TX_AND_CHANGE_REQ || gRfuState->reqActiveCommand == ID_UNK35_REQ || gRfuState->reqActiveCommand == ID_RESUME_RETRANSMIT_AND_CHANGE_REQ)
|
||||
{
|
||||
gRfuState->error = 1;
|
||||
gRfuState->unk_2c = 0;
|
||||
|
||||
Reference in New Issue
Block a user