From a436d79177fc54927d14cc2114802dee74176a6b Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Tue, 24 Dec 2019 04:25:49 +0800 Subject: partially sync with knizz's documentation --- include/librfu.h | 214 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 136 insertions(+), 78 deletions(-) (limited to 'include') diff --git a/include/librfu.h b/include/librfu.h index 69f0bb695..5eb9fd7a0 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -76,9 +76,9 @@ struct UnkLinkRfuStruct_02022B14Substruct u16 unk_00_4:1; u16 unk_00_5:1; u16 unk_00_6:1; - u16 unk_00_7:1; - u16 unk_01_0:1; - u16 unk_01_1:1; + u16 isChampion:1; + u16 hasNationalDex:1; + u16 gameClear:1; u16 unk_01_2:4; u16 unk_01_6:2; u8 playerTrainerId[2]; @@ -93,36 +93,35 @@ struct __attribute__((packed, aligned(2))) UnkLinkRfuStruct_02022B14 u8 unk_0a_0:7; u8 unk_0a_7:1; u8 playerGender:1; - u8 unk_0b_1:7; + u8 level:7; u8 unk_0c; }; struct RfuStruct { - vs32 unk_0; - u8 txParams; - u8 unk_5; - u8 activeCommand; - u8 unk_7; - u8 unk_8; - u8 unk_9; + vs32 state; + u8 reqLength; + u8 reqNext; + u8 reqActiveCommand; + u8 ackLength; + u8 ackNext; + u8 ackActiveCommand; u8 timerSelect; u8 unk_b; - int timerState; + s32 timerState; vu8 timerActive; u8 unk_11; - vu16 unk_12; + vu16 error; vu8 msMode; - u8 unk_15; + u8 recoveryCount; u8 unk_16; u8 unk_17; void (*callbackM)(); void (*callbackS)(); - u32 callbackID; - union RfuPacket * txPacket; - union RfuPacket * rxPacket; + u32 callbackId; + union RfuPacket *txPacket; + union RfuPacket *rxPacket; vu8 unk_2c; - u8 padding[3]; }; struct RfuIntrStruct @@ -133,90 +132,149 @@ struct RfuIntrStruct u8 block2[0x30]; }; -struct RfuUnk1 +struct RfuSlotStatusUNI { - u16 unk_0; - u8 unk_2; - u8 unk_3; - u8 fill_4[14]; - u8 unk_12; - u32 unk_14; - u32 unk_18; - struct RfuIntrStruct unk_1c; + u16 sendState; + u8 dataReadyFlag; + u8 bmSlot; + u16 payloadSize; + void *src; // TODO: is it correct? + u16 recvState; + u16 errorCode; + u16 dataSize; + u8 newDataFlag; + u8 dataBlockFlag; + void *recvBuffer; + u32 recvBuffSize; }; -struct RfuUnk2 +struct NIComm { - u16 unk_0; - u16 unk_2; - u8 fill_4[0x16]; - u8 unk_1a; - u8 fill_1b[0x19]; - u16 unk_34; - u16 unk_36; - u8 fill_38[0x16]; - u8 unk_4e; - u8 fill_4f[0x12]; - u8 unk_61; - u8 fill_62[6]; - void *unk_68; - void *unk_6c; - u8 unk_70[0x70]; + u16 state; + u16 failCounter; + u32 nowP[4]; // ??? + u32 remainSize; + u16 errorCode; + u8 bmSlot; + u8 unk_1b; + u8 recvAckFlag[4]; + u8 ack; + u8 phase; + u8 n[4]; // ??? + void *src; + u8 bmSlotOrg; + u8 dataType; + u16 payloadSize; + u32 dataSize; }; -struct RfuUnk3 +struct RfuSlotStatusNI { - u32 unk_0; - u32 unk_4; - u8 unk_8[0xD4]; - u32 unk_dc; + struct NIComm send; + struct NIComm recv; + void *recvBuffer; + void *recvBufferSize; }; -struct RfuUnk5Sub +struct RfuFixed { - u16 unk_00; - u8 unk_02; - u16 unk_04; - struct UnkLinkRfuStruct_02022B14 unk_06; - u8 fill_13[1]; - u8 playerName[PLAYER_NAME_LENGTH + 1]; + void *reqCallback; + void *fastCopyPtr; + u16 fastCopyBuffer[24]; + u32 fastCopyBuffer2[12]; + u32 LLFBuffer[29]; + u8 *STWIBuffer; }; -struct RfuUnk5 +struct RfuStatic { - u8 unk_00; - u8 unk_01; - u8 unk_02; - u8 unk_03; - u8 unk_04; - u8 unk_05; - u8 unk_06; - u8 unk_07; - u8 unk_08; - u8 filler_09[1]; - u8 unk_0a[4]; - u8 filler_0e[6]; - struct RfuUnk5Sub unk_14[4]; + u8 flags; + u8 NIEndRecvFlag; + u8 RecvRenewalFlag; + u8 commExistFlag; + u8 recvErrorFlag; + u8 recoveryBmSlot; + u8 nowWatchInterval; + u8 nullFrameCount; + u8 emberCount; + u8 SCStartFlag; + u8 linkEmergencyFlag[4]; + u8 lsFixedCount[4]; + u16 cidBak[4]; + u16 unk_1a; + u16 reqResult; + u16 tryPid; + u32 watchdogTimer; + u32 totalPacketSize; }; -extern struct RfuStruct * gRfuState; +struct RfuTgtData +{ + u16 id; + u8 slot; + u8 multibootFlag; + u16 serialNum; + u8 gname[15]; + u8 uname[9]; +}; -extern struct RfuUnk5 * gUnknown_3007460; -extern u32 *gUnknown_3007464; -extern struct RfuUnk3 * gUnknown_3007468; -extern struct RfuUnk2 * gUnknown_3007450[4]; -extern struct RfuUnk1 * gUnknown_3007440[4]; -extern struct { +struct RfuLinkStatus +{ + u8 connMode; + u8 connCount; + u8 connSlotFlag; + u8 linkLossSlotFlag; + u8 sendSlotNIFlag; + u8 recvSlotNIFlag; + u8 sendSlotUNIFlag; + u8 getNameFlag; + u8 findParentCount; + u8 watchInterval; + u8 stength[4]; + u8 LLFReadyFlag; + u8 remainLLFrameSizeParent; + u8 remainLLFrameSizeChild[4]; + struct RfuTgtData partner[4]; + struct RfuTgtData my; +}; + +struct Unk_3007470 +{ u8 unk0; u8 unk1; u16 unk2; u16 unk4; u8 fill6[4]; u16 unkA; -} gUnknown_3007470; +}; + +struct STWIStruct +{ + // TODO: resolve the struct + u8 unk_0[232]; + u8 function[2400]; + struct RfuStruct STWIStatus; +}; + +struct Unk_3001190 +{ + struct RfuLinkStatus linkStatus; + struct RfuStatic static_; + struct RfuFixed fixed; + struct RfuSlotStatusNI NI[4]; + struct RfuSlotStatusUNI UNI[4]; + struct STWIStruct STWI; +}; -extern void rfu_STC_clearAPIVariables(void); +extern struct RfuStruct *gRfuState; +extern struct RfuLinkStatus *gRfuLinkStatus; +extern struct RfuStatic *gRfuStatic; +extern struct RfuFixed *gRfuFixed; +extern struct RfuSlotStatusNI *gRfuSlotStatusNI[4]; +extern struct RfuSlotStatusUNI *gRfuSlotStatusUNI[4]; +extern struct Unk_3007470 gUnknown_3007470; +void rfu_STC_clearAPIVariables(void); void STWI_init_all(struct RfuIntrStruct * interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam); void rfu_REQ_stopMode(void); void rfu_waitREQComplete(void); -- cgit v1.2.3 From 8f1a8972c19f5cd2522c9e7982bd330ac05305e9 Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Fri, 27 Dec 2019 05:17:41 +0800 Subject: librfu_stwi Co-authored-by: Max Thomas --- include/gba/io_reg.h | 6 +++++ include/gba/macro.h | 12 +++++++++- include/librfu.h | 67 ++++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 69 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/include/gba/io_reg.h b/include/gba/io_reg.h index 6d54bc5fb..8eacc8aa7 100644 --- a/include/gba/io_reg.h +++ b/include/gba/io_reg.h @@ -137,6 +137,8 @@ #define REG_OFFSET_DMA3CNT_H 0xde #define REG_OFFSET_TMCNT 0x100 +#define REG_OFFSET_TMCNT_L 0x100 +#define REG_OFFSET_TMCNT_H 0x102 #define REG_OFFSET_TM0CNT 0x100 #define REG_OFFSET_TM0CNT_L 0x100 #define REG_OFFSET_TM0CNT_H 0x102 @@ -298,6 +300,8 @@ #define REG_ADDR_DMA3CNT_H (REG_BASE + REG_OFFSET_DMA3CNT_H) #define REG_ADDR_TMCNT (REG_BASE + REG_OFFSET_TMCNT) +#define REG_ADDR_TMCNT_L (REG_BASE + REG_OFFSET_TMCNT_L) +#define REG_ADDR_TMCNT_H (REG_BASE + REG_OFFSET_TMCNT_H) #define REG_ADDR_TM0CNT (REG_BASE + REG_OFFSET_TM0CNT) #define REG_ADDR_TM0CNT_L (REG_BASE + REG_OFFSET_TM0CNT_L) #define REG_ADDR_TM0CNT_H (REG_BASE + REG_OFFSET_TM0CNT_H) @@ -458,6 +462,8 @@ #define REG_DMA3CNT_H (*(vu16 *)REG_ADDR_DMA3CNT_H) #define REG_TMCNT(n) (*(vu16 *)(REG_ADDR_TMCNT + ((n) * 4))) +#define REG_TMCNT_L(n) (*(vu16 *)(REG_ADDR_TMCNT_L + ((n) * 4))) +#define REG_TMCNT_H(n) (*(vu16 *)(REG_ADDR_TMCNT_H + ((n) * 4))) #define REG_TM0CNT (*(vu32 *)REG_ADDR_TM0CNT) #define REG_TM0CNT_L (*(vu16 *)REG_ADDR_TM0CNT_L) #define REG_TM0CNT_H (*(vu16 *)REG_ADDR_TM0CNT_H) diff --git a/include/gba/macro.h b/include/gba/macro.h index e416c3577..a3e870210 100644 --- a/include/gba/macro.h +++ b/include/gba/macro.h @@ -105,7 +105,7 @@ } \ } -#define DmaClearLarge(dmaNum, dest, size, block, bit) \ +#define DmaClearLarge(dmaNum, dest, size, block, bit) \ { \ u32 _size = size; \ while (1) \ @@ -170,4 +170,14 @@ #define DmaFill16Defvars(dmaNum, value, dest, size) DmaFillDefvars(dmaNum, value, dest, size, 16) #define DmaFill32Defvars(dmaNum, value, dest, size) DmaFillDefvars(dmaNum, value, dest, size, 32) +#define IntrEnable(flags) \ +{ \ + u16 imeTemp; \ + \ + imeTemp = REG_IME; \ + REG_IME = 0; \ + REG_IE |= flags; \ + REG_IME = imeTemp; \ +} + #endif // GUARD_GBA_MACRO_H diff --git a/include/librfu.h b/include/librfu.h index 5eb9fd7a0..709074f9c 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -108,7 +108,7 @@ struct RfuStruct u8 ackActiveCommand; u8 timerSelect; u8 unk_b; - s32 timerState; + u32 timerState; // this field is s32 in emerald vu8 timerActive; u8 unk_11; vu16 error; @@ -126,10 +126,10 @@ struct RfuStruct struct RfuIntrStruct { - u8 rxPacketAlloc[0x74]; - u8 txPacketAlloc[0x74]; - u8 block1[0x960]; - u8 block2[0x30]; + union RfuPacket rxPacketAlloc; + union RfuPacket txPacketAlloc; + u8 block1[0x960]; // size of librfu_intr.s binary + struct RfuStruct block2; }; struct RfuSlotStatusUNI @@ -248,14 +248,6 @@ struct Unk_3007470 u16 unkA; }; -struct STWIStruct -{ - // TODO: resolve the struct - u8 unk_0[232]; - u8 function[2400]; - struct RfuStruct STWIStatus; -}; - struct Unk_3001190 { struct RfuLinkStatus linkStatus; @@ -263,7 +255,7 @@ struct Unk_3001190 struct RfuFixed fixed; struct RfuSlotStatusNI NI[4]; struct RfuSlotStatusUNI UNI[4]; - struct STWIStruct STWI; + struct RfuIntrStruct intr; }; extern struct RfuStruct *gRfuState; @@ -275,7 +267,6 @@ extern struct RfuSlotStatusUNI *gRfuSlotStatusUNI[4]; extern struct Unk_3007470 gUnknown_3007470; void rfu_STC_clearAPIVariables(void); -void STWI_init_all(struct RfuIntrStruct * interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam); void rfu_REQ_stopMode(void); void rfu_waitREQComplete(void); u32 rfu_REQBN_softReset_and_checkID(void); @@ -323,4 +314,50 @@ void rfu_UNI_clearRecvNewDataFlag(u8 a0); void rfu_REQ_PARENT_resumeRetransmitAndChange(void); void rfu_NI_setSendData(u8, u8, const void *, u32); +// librfu_intr +void IntrSIO32(void); + +// librfu_stwi +void STWI_init_all(struct RfuIntrStruct * interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam); +void STWI_set_MS_mode(u8 mode); +void STWI_init_Callback_M(void); +void STWI_init_Callback_S(void); +void STWI_set_Callback_M(void (*callbackM)()); +void STWI_set_Callback_S(void (*callbackS)()); +void STWI_init_timer(IntrFunc *interrupt, s32 timerSelect); +void AgbRFU_SoftReset(void); +void STWI_set_Callback_ID(u32 id); +u16 STWI_read_status(u8 index); +u16 STWI_poll_CommandEnd(void); +void STWI_send_DataRxREQ(void); +void STWI_send_MS_ChangeREQ(void); +void STWI_send_StopModeREQ(void); +void STWI_send_SystemStatusREQ(void); +void STWI_send_GameConfigREQ(u8 *unk1, u8 *data); +void STWI_send_ResetREQ(void); +void STWI_send_LinkStatusREQ(void); +void STWI_send_VersionStatusREQ(void); +void STWI_send_SlotStatusREQ(void); +void STWI_send_ConfigStatusREQ(void); +void STWI_send_ResumeRetransmitAndChangeREQ(void); +void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3); +void STWI_send_SC_StartREQ(void); +void STWI_send_SC_PollingREQ(void); +void STWI_send_SC_EndREQ(void); +void STWI_send_SP_StartREQ(void); +void STWI_send_SP_PollingREQ(void); +void STWI_send_SP_EndREQ(void); +void STWI_send_CP_StartREQ(u16 unk1); +void STWI_send_CP_PollingREQ(void); +void STWI_send_CP_EndREQ(void); +void STWI_send_DataTxREQ(const void *in, u8 size); +void STWI_send_DataTxAndChangeREQ(const void *in, u8 size); +void STWI_send_DataReadyAndChangeREQ(u8 unk); +void STWI_send_DisconnectedAndChangeREQ(u8 unk0, u8 unk1); +void STWI_send_DisconnectREQ(u8 unk); +void STWI_send_TestModeREQ(u8 unk0, u8 unk1); +void STWI_send_CPR_StartREQ(u16 unk0, u16 unk1, u8 unk2); +void STWI_send_CPR_PollingREQ(void); +void STWI_send_CPR_EndREQ(void); + #endif // GUARD_LIBRFU_H -- cgit v1.2.3 From 973cb394b23002acde7d7ea19abc754019dd106c Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Sun, 29 Dec 2019 06:24:26 +0800 Subject: librfu through 0x81E13F0 --- include/constants/trade.h | 4 ++-- include/gba/io_reg.h | 2 +- include/gba/syscall.h | 2 ++ include/librfu.h | 37 +++++++++++++++++++------------------ 4 files changed, 24 insertions(+), 21 deletions(-) (limited to 'include') diff --git a/include/constants/trade.h b/include/constants/trade.h index b1371caab..b22cd26d2 100644 --- a/include/constants/trade.h +++ b/include/constants/trade.h @@ -1,4 +1,4 @@ - #ifndef GUARD_CONSTANTS_TRADE_H +#ifndef GUARD_CONSTANTS_TRADE_H #define GUARD_CONSTANTS_TRADE_H // TODO: document trade.c and trade_scene.c with corresponding macros @@ -115,4 +115,4 @@ #define CANT_REGISTER_MON 1 #define CANT_REGISTER_EGG 2 -#endif //GUARD_CONSTANTS_TRADE_H +#endif // GUARD_CONSTANTS_TRADE_H diff --git a/include/gba/io_reg.h b/include/gba/io_reg.h index 8eacc8aa7..548e27163 100644 --- a/include/gba/io_reg.h +++ b/include/gba/io_reg.h @@ -461,7 +461,7 @@ #define REG_DMA3CNT_L (*(vu16 *)REG_ADDR_DMA3CNT_L) #define REG_DMA3CNT_H (*(vu16 *)REG_ADDR_DMA3CNT_H) -#define REG_TMCNT(n) (*(vu16 *)(REG_ADDR_TMCNT + ((n) * 4))) +#define REG_TMCNT(n) (*(vu32 *)(REG_ADDR_TMCNT + ((n) * 4))) #define REG_TMCNT_L(n) (*(vu16 *)(REG_ADDR_TMCNT_L + ((n) * 4))) #define REG_TMCNT_H(n) (*(vu16 *)(REG_ADDR_TMCNT_H + ((n) * 4))) #define REG_TM0CNT (*(vu32 *)REG_ADDR_TM0CNT) diff --git a/include/gba/syscall.h b/include/gba/syscall.h index deddec5ba..22fdf09fa 100644 --- a/include/gba/syscall.h +++ b/include/gba/syscall.h @@ -45,4 +45,6 @@ void RLUnCompVram(const void *src, void *dest); int MultiBoot(struct MultiBootParam *mp); +s32 Div(s32 num, s32 denom); + #endif // GUARD_GBA_SYSCALL_H diff --git a/include/librfu.h b/include/librfu.h index 709074f9c..9482b94c4 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -117,7 +117,7 @@ struct RfuStruct u8 unk_16; u8 unk_17; void (*callbackM)(); - void (*callbackS)(); + void (*callbackS)(u16); u32 callbackId; union RfuPacket *txPacket; union RfuPacket *rxPacket; @@ -145,7 +145,7 @@ struct RfuSlotStatusUNI u8 newDataFlag; u8 dataBlockFlag; void *recvBuffer; - u32 recvBuffSize; + u32 recvBufferSize; }; struct NIComm @@ -178,12 +178,12 @@ struct RfuSlotStatusNI struct RfuFixed { - void *reqCallback; + void (*reqCallback)(u16, u16); void *fastCopyPtr; u16 fastCopyBuffer[24]; u32 fastCopyBuffer2[12]; u32 LLFBuffer[29]; - u8 *STWIBuffer; + struct RfuIntrStruct *STWIBuffer; }; struct RfuStatic @@ -204,7 +204,7 @@ struct RfuStatic u16 unk_1a; u16 reqResult; u16 tryPid; - u32 watchdogTimer; + u16 watchdogTimer; u32 totalPacketSize; }; @@ -230,7 +230,7 @@ struct RfuLinkStatus u8 getNameFlag; u8 findParentCount; u8 watchInterval; - u8 stength[4]; + u8 strength[4]; u8 LLFReadyFlag; u8 remainLLFrameSizeParent; u8 remainLLFrameSizeChild[4]; @@ -266,19 +266,20 @@ extern struct RfuSlotStatusNI *gRfuSlotStatusNI[4]; extern struct RfuSlotStatusUNI *gRfuSlotStatusUNI[4]; extern struct Unk_3007470 gUnknown_3007470; +// librfu_rfu void rfu_STC_clearAPIVariables(void); void rfu_REQ_stopMode(void); -void rfu_waitREQComplete(void); -u32 rfu_REQBN_softReset_and_checkID(void); +u16 rfu_waitREQComplete(void); +s32 rfu_REQBN_softReset_and_checkID(void); void rfu_REQ_sendData(u8); void rfu_setMSCCallback(void (*func)(u16)); void rfu_setREQCallback(void (*func)(u16, u16)); bool8 rfu_getMasterSlave(void); void rfu_REQBN_watchLink(u16 a0, u8 *a1, u8 *a2, u8 *a3); -bool16 rfu_syncVBlank(void); +u16 rfu_syncVBlank(void); void rfu_REQ_reset(void); void rfu_REQ_configSystem(u16, u8, u8); -void rfu_REQ_configGameData(u8, u16, struct UnkLinkRfuStruct_02022B14 *, u8 *); +void rfu_REQ_configGameData(u8 r6, u16 r2, const u8 *r4, const u8 *r7); void rfu_REQ_startSearchChild(void); void rfu_REQ_pollSearchChild(void); void rfu_REQ_endSearchChild(void); @@ -293,18 +294,18 @@ void rfu_REQ_CHILD_pollConnectRecovery(void); void rfu_REQ_CHILD_endConnectRecovery(void); void rfu_REQ_changeMasterSlave(void); void rfu_REQ_RFUStatus(void); -void rfu_getRFUStatus(u8 *status); -u8 *rfu_getSTWIRecvBuffer(void); +u32 rfu_getRFUStatus(u8 *status); +struct RfuIntrStruct *rfu_getSTWIRecvBuffer(void); u8 rfu_NI_CHILD_setSendGameName(u8 a0, u8 a1); void rfu_clearSlot(u8 a0, u8 a1); void rfu_clearAllSlot(void); bool16 rfu_CHILD_getConnectRecoveryStatus(u8 *status); -bool16 rfu_getConnectParentStatus(u8 *status, u8 *a1); +u16 rfu_getConnectParentStatus(u8 *status, u8 *a1); bool16 rfu_UNI_PARENT_getDRAC_ACK(u8 *a0); void rfu_REQ_disconnect(u8 who); void rfu_changeSendTarget(u8 a0, u8 who, u8 a2); void rfu_NI_stopReceivingData(u8 who); -u16 rfu_initializeAPI(u32 *unk0, u16 unk1, IntrFunc *interrupt, bool8 copyInterruptToRam); +u16 rfu_initializeAPI(struct Unk_3001190 *unk0, u16 unk1, IntrFunc *interrupt, bool8 copyInterruptToRam); void rfu_setTimerInterrupt(u8 which, IntrFunc *intr); void rfu_setRecvBuffer(u8 a0, u8 a1, void *a2, size_t a3); bool16 rfu_UNI_setSendData(u8 flag, void *ptr, u8 size); @@ -318,12 +319,12 @@ void rfu_NI_setSendData(u8, u8, const void *, u32); void IntrSIO32(void); // librfu_stwi -void STWI_init_all(struct RfuIntrStruct * interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam); +void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam); void STWI_set_MS_mode(u8 mode); void STWI_init_Callback_M(void); void STWI_init_Callback_S(void); -void STWI_set_Callback_M(void (*callbackM)()); -void STWI_set_Callback_S(void (*callbackS)()); +void STWI_set_Callback_M(void *callbackM); +void STWI_set_Callback_S(void (*callbackS)(u16)); void STWI_init_timer(IntrFunc *interrupt, s32 timerSelect); void AgbRFU_SoftReset(void); void STWI_set_Callback_ID(u32 id); @@ -333,7 +334,7 @@ void STWI_send_DataRxREQ(void); void STWI_send_MS_ChangeREQ(void); void STWI_send_StopModeREQ(void); void STWI_send_SystemStatusREQ(void); -void STWI_send_GameConfigREQ(u8 *unk1, u8 *data); +void STWI_send_GameConfigREQ(const u8 *unk1, const u8 *data); void STWI_send_ResetREQ(void); void STWI_send_LinkStatusREQ(void); void STWI_send_VersionStatusREQ(void); -- cgit v1.2.3 From 6cbce0b9668c0fd7e902397e96f9a488b1d6f5a8 Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Tue, 31 Dec 2019 06:42:18 +0800 Subject: librfu through 0x81E2C40 --- include/librfu.h | 75 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/include/librfu.h b/include/librfu.h index 9482b94c4..ff160e207 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -3,6 +3,12 @@ #include "main.h" +/* TODOs: + * - documentation + * - check if any field needs to be volatile + * - decompile librfu_intr.s once arm support is back again + */ + enum { RFU_RESET = 0x10, @@ -134,16 +140,25 @@ struct RfuIntrStruct struct RfuSlotStatusUNI { - u16 sendState; - u8 dataReadyFlag; - u8 bmSlot; - u16 payloadSize; - void *src; // TODO: is it correct? - u16 recvState; - u16 errorCode; - u16 dataSize; - u8 newDataFlag; - u8 dataBlockFlag; + struct + { + struct UNISend + { + u16 state; + u8 dataReadyFlag; + u8 bmSlot; + u16 payloadSize; + const void *src; + } send; + struct UNIRecv + { + u16 state; + u16 errorCode; + u16 dataSize; + u8 newDataFlag; + u8 dataBlockFlag; + } recv; + } sub; void *recvBuffer; u32 recvBufferSize; }; @@ -152,16 +167,15 @@ struct NIComm { u16 state; u16 failCounter; - u32 nowP[4]; // ??? + const u8 *nowP[4]; u32 remainSize; u16 errorCode; u8 bmSlot; - u8 unk_1b; u8 recvAckFlag[4]; u8 ack; u8 phase; - u8 n[4]; // ??? - void *src; + u8 n[4]; + const void *src; u8 bmSlotOrg; u8 dataType; u16 payloadSize; @@ -170,16 +184,19 @@ struct NIComm struct RfuSlotStatusNI { - struct NIComm send; - struct NIComm recv; + struct + { + struct NIComm send; + struct NIComm recv; + } sub; void *recvBuffer; - void *recvBufferSize; + u32 recvBufferSize; }; struct RfuFixed { void (*reqCallback)(u16, u16); - void *fastCopyPtr; + void (*fastCopyPtr)(const u8 **, u8 **, s32); u16 fastCopyBuffer[24]; u32 fastCopyBuffer2[12]; u32 LLFBuffer[29]; @@ -190,7 +207,7 @@ struct RfuStatic { u8 flags; u8 NIEndRecvFlag; - u8 RecvRenewalFlag; + u8 recvRenewalFlag; u8 commExistFlag; u8 recvErrorFlag; u8 recoveryBmSlot; @@ -231,7 +248,7 @@ struct RfuLinkStatus u8 findParentCount; u8 watchInterval; u8 strength[4]; - u8 LLFReadyFlag; + vu8 LLFReadyFlag; u8 remainLLFrameSizeParent; u8 remainLLFrameSizeChild[4]; struct RfuTgtData partner[4]; @@ -275,7 +292,7 @@ void rfu_REQ_sendData(u8); void rfu_setMSCCallback(void (*func)(u16)); void rfu_setREQCallback(void (*func)(u16, u16)); bool8 rfu_getMasterSlave(void); -void rfu_REQBN_watchLink(u16 a0, u8 *a1, u8 *a2, u8 *a3); +s32 rfu_REQBN_watchLink(u16 a0, u8 *a1, u8 *a2, u8 *a3); u16 rfu_syncVBlank(void); void rfu_REQ_reset(void); void rfu_REQ_configSystem(u16, u8, u8); @@ -296,24 +313,24 @@ void rfu_REQ_changeMasterSlave(void); void rfu_REQ_RFUStatus(void); u32 rfu_getRFUStatus(u8 *status); struct RfuIntrStruct *rfu_getSTWIRecvBuffer(void); -u8 rfu_NI_CHILD_setSendGameName(u8 a0, u8 a1); -void rfu_clearSlot(u8 a0, u8 a1); +s32 rfu_NI_CHILD_setSendGameName(u8 a0, u8 a1); +s32 rfu_clearSlot(u8 a0, u8 a1); void rfu_clearAllSlot(void); -bool16 rfu_CHILD_getConnectRecoveryStatus(u8 *status); +u16 rfu_CHILD_getConnectRecoveryStatus(u8 *status); u16 rfu_getConnectParentStatus(u8 *status, u8 *a1); bool16 rfu_UNI_PARENT_getDRAC_ACK(u8 *a0); void rfu_REQ_disconnect(u8 who); -void rfu_changeSendTarget(u8 a0, u8 who, u8 a2); -void rfu_NI_stopReceivingData(u8 who); +s32 rfu_changeSendTarget(u8 a0, u8 who, u8 a2); +s32 rfu_NI_stopReceivingData(u8 who); u16 rfu_initializeAPI(struct Unk_3001190 *unk0, u16 unk1, IntrFunc *interrupt, bool8 copyInterruptToRam); void rfu_setTimerInterrupt(u8 which, IntrFunc *intr); -void rfu_setRecvBuffer(u8 a0, u8 a1, void *a2, size_t a3); -bool16 rfu_UNI_setSendData(u8 flag, void *ptr, u8 size); +s32 rfu_setRecvBuffer(u8 a0, u8 a1, void *a2, size_t a3); +s32 rfu_UNI_setSendData(u8 flag, const void *ptr, u8 size); void rfu_REQ_recvData(void); void rfu_UNI_readySendData(u8 a0); void rfu_UNI_clearRecvNewDataFlag(u8 a0); void rfu_REQ_PARENT_resumeRetransmitAndChange(void); -void rfu_NI_setSendData(u8, u8, const void *, u32); +s32 rfu_NI_setSendData(u8, u8, const void *, u32); // librfu_intr void IntrSIO32(void); -- cgit v1.2.3 From 5bf8d1c62d6907b44d92f75f4402c4a0dee28a2c Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Wed, 1 Jan 2020 21:46:36 +0800 Subject: fix rfu_STC_analyzeLLSF Co-authored-by: Normmatt --- include/librfu.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/librfu.h b/include/librfu.h index ff160e207..e50f5cc89 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -284,7 +284,6 @@ extern struct RfuSlotStatusUNI *gRfuSlotStatusUNI[4]; extern struct Unk_3007470 gUnknown_3007470; // librfu_rfu -void rfu_STC_clearAPIVariables(void); void rfu_REQ_stopMode(void); u16 rfu_waitREQComplete(void); s32 rfu_REQBN_softReset_and_checkID(void); -- cgit v1.2.3 From 1fda78fd0a1b0235ec0ee2db85e5ebbfa9fc50b5 Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Thu, 2 Jan 2020 06:19:23 +0800 Subject: k.o. librfu_rfu --- include/librfu.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/librfu.h b/include/librfu.h index e50f5cc89..8bc1e636d 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -3,9 +3,11 @@ #include "main.h" -/* TODOs: +/* TODOs: + * - decide file boundaries * - documentation * - check if any field needs to be volatile + * - check if field names make sense * - decompile librfu_intr.s once arm support is back again */ @@ -124,7 +126,7 @@ struct RfuStruct u8 unk_17; void (*callbackM)(); void (*callbackS)(u16); - u32 callbackId; + void (*unk_20)(void); union RfuPacket *txPacket; union RfuPacket *rxPacket; vu8 unk_2c; @@ -168,7 +170,7 @@ struct NIComm u16 state; u16 failCounter; const u8 *nowP[4]; - u32 remainSize; + s32 remainSize; u16 errorCode; u8 bmSlot; u8 recvAckFlag[4]; @@ -261,7 +263,8 @@ struct Unk_3007470 u8 unk1; u16 unk2; u16 unk4; - u8 fill6[4]; + u16 unk6; + u16 unk8; // unused u16 unkA; }; @@ -330,6 +333,7 @@ void rfu_UNI_readySendData(u8 a0); void rfu_UNI_clearRecvNewDataFlag(u8 a0); void rfu_REQ_PARENT_resumeRetransmitAndChange(void); s32 rfu_NI_setSendData(u8, u8, const void *, u32); +void rfu_REQ_noise(void); // librfu_intr void IntrSIO32(void); @@ -343,7 +347,7 @@ void STWI_set_Callback_M(void *callbackM); void STWI_set_Callback_S(void (*callbackS)(u16)); void STWI_init_timer(IntrFunc *interrupt, s32 timerSelect); void AgbRFU_SoftReset(void); -void STWI_set_Callback_ID(u32 id); +void STWI_set_CallbackUnk(void (*func)(void)); u16 STWI_read_status(u8 index); u16 STWI_poll_CommandEnd(void); void STWI_send_DataRxREQ(void); -- cgit v1.2.3 From a7ec7175f1eadf79ab6cb4efbde1b9694535806f Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Tue, 7 Jan 2020 12:09:18 +0800 Subject: resolve a fake match --- include/librfu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/librfu.h b/include/librfu.h index 8bc1e636d..9440ffd7b 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -347,7 +347,7 @@ void STWI_set_Callback_M(void *callbackM); void STWI_set_Callback_S(void (*callbackS)(u16)); void STWI_init_timer(IntrFunc *interrupt, s32 timerSelect); void AgbRFU_SoftReset(void); -void STWI_set_CallbackUnk(void (*func)(void)); +void STWI_set_Callback_ID(void (*func)(void)); u16 STWI_read_status(u8 index); u16 STWI_poll_CommandEnd(void); void STWI_send_DataRxREQ(void); -- cgit v1.2.3 From f12c1edf3f626fd608b837c125514768f264dc2c Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Fri, 10 Jan 2020 02:13:35 +0800 Subject: update documentation & func types --- include/librfu.h | 649 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 472 insertions(+), 177 deletions(-) (limited to 'include') diff --git a/include/librfu.h b/include/librfu.h index 9440ffd7b..1e128d209 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -1,83 +1,276 @@ #ifndef GUARD_LIBRFU_H #define GUARD_LIBRFU_H +#include "global.h" #include "main.h" /* TODOs: - * - decide file boundaries + * - split files * - documentation + * - decompile librfu_intr.s once arm support is back again + (for internal structs not documented in SDK) * - check if any field needs to be volatile * - check if field names make sense - * - decompile librfu_intr.s once arm support is back again */ -enum -{ - RFU_RESET = 0x10, - RFU_LINK_STATUS, - RFU_VERSION_STATUS, - RFU_SYSTEM_STATUS, - RFU_SLOT_STATUS, - RFU_CONFIG_STATUS, - RFU_GAME_CONFIG, - RFU_SYSTEM_CONFIG, - RFU_UNK18, - RFU_SC_START, - RFU_SC_POLLING, - RFU_SC_END, - RFU_SP_START, - RFU_SP_POLLING, - RFU_SP_END, - RFU_CP_START, - RFU_CP_POLLING, - RFU_CP_END, - RFU_UNK22, - RFU_UNK23, - RFU_DATA_TX, - RFU_DATA_TX_AND_CHANGE, - RFU_DATA_RX, - RFU_MS_CHANGE, - RFU_DATA_READY_AND_CHANGE, - RFU_DISCONNECTED_AND_CHANGE, - RFU_UNK2A, - RFU_UNK2B, - RFU_UNK2C, - RFU_UNK2D, - RFU_UNK2E, - RFU_UNK2F, - RFU_DISCONNECT, - RFU_TEST_MODE, - RFU_CPR_START, - RFU_CPR_POLLING, - RFU_CPR_END, - RFU_UNK35, - RFU_UNK36, - RFU_RESUME_RETRANSMIT_AND_CHANGE, - RFU_UNK38, - RFU_UNK39, - RFU_UNK3A, - RFU_UNK3B, - RFU_UNK3C, - RFU_STOP_MODE, //3D -}; +// -------------------------------------------------------------------------- +// +// Restrictions When Using RFU +// +// -------------------------------------------------------------------------- +/* + The following restrictions apply when using RFU. -struct RfuPacket8 -{ - u8 data[0x74]; -}; + + (a) The timer for Sound DMA uses only 0 + (b) The prescaler for the timer count for the Sound DMA uses 59.5 ns. + (c) The sound sampling rate is Max36.314KHz. -struct RfuPacket32 -{ - u32 command; - u32 data[0x1C]; -}; + + These types of DMA can be operated on a maximum CPU cycle of 42 cycles. + Calculate the number of the transferable DMA count based on this 42 cycles and the access cycles of the destination and source. + For example, if both the CPU internal RAM --> VRAM have a one cycle access, then a 21 count DMA can occur. -union RfuPacket -{ - struct RfuPacket32 rfuPacket32; - struct RfuPacket8 rfuPacket8; -}; + + If RFU is used outside of these restrictions, problems, such as the loss of data caused by the failure of the AGB, as a clock slave, + to notify that data has been received from the RFU, will occur. + When this problem occurs, the REQ callback will send a REQ_commandID=ID_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA_REQ notification. + (When using Link Manager, the LMAN call back will send a LMAN_msg=LMAN_MSG_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA notification.) + +*/ + +// REQ-COMMAND (STWI) ID CODE LIST + +// REQ Command ID returned by the REQ callback +#define ID_RESET_REQ 0x0010 +#define ID_LINK_STATUS_REQ 0x0011 +#define ID_VERSION_STATUS_REQ 0x0012 // not defined in SDK header +#define ID_SYSTEM_STATUS_REQ 0x0013 +#define ID_SLOT_STATUS_REQ 0x0014 // not defined in SDK header +#define ID_CONFIG_STATUS_REQ 0x0015 // not defined in SDK header +#define ID_GAME_CONFIG_REQ 0x0016 +#define ID_SYSTEM_CONFIG_REQ 0x0017 +#define ID_SC_START_REQ 0x0019 +#define ID_SC_POLL_REQ 0x001a +#define ID_SC_END_REQ 0x001b +#define ID_SP_START_REQ 0x001c +#define ID_SP_POLL_REQ 0x001d +#define ID_SP_END_REQ 0x001e +#define ID_CP_START_REQ 0x001f +#define ID_CP_POLL_REQ 0x0020 +#define ID_CP_END_REQ 0x0021 +#define ID_DATA_TX_REQ 0x0024 +#define ID_DATA_TX_AND_CHANGE_REQ 0x0025 +#define ID_DATA_RX_REQ 0x0026 +#define ID_MS_CHANGE_REQ 0x0027 // When returned by the REQ callback, this ID indicates that execution of rfu_REQ_changeMasterSlave has finished. + // This ID is returned by both the REQ callback and the MSC callback. + // When returned by the MSC callback, this is notification that after the AGB has been made into the clock slave, the MC_Timer expired and the RFU returned the AGB to be the clock master. +#define ID_DISCONNECT_REQ 0x0030 +#define ID_TEST_MODE_REQ 0x0031 // not defined in SDK header +#define ID_CPR_START_REQ 0x0032 +#define ID_CPR_POLL_REQ 0x0033 +#define ID_CPR_END_REQ 0x0034 +#define ID_UNK35_REQ 0x0035 // not defined in SDK header +#define ID_RESUME_RETRANSMIT_AND_CHANGE_REQ 0x0037 +#define ID_STOP_MODE_REQ 0x003d +#define ID_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA_REQ 0x00ff // When the AGB is the clock slave, the RFU generates an informational notice, and an automatically started DMA, such as HDMA, is generated at the instant the AGB is being returned as the clock master. This ID is notified by a REQ callback when the exchange of this information (REQ command) fails. + +// REQ Command ID returned by the MSC callback +#define ID_DISCONNECTED_AND_CHANGE_REQ 0x0029 +#define ID_DATA_READY_AND_CHANGE_REQ 0x0028 +#define ID_DRAC_REQ_WITH_ACK_FLAG 0x0128 + +// -------------------------------------------------------------------------- +// +// Data Definitions +// +// -------------------------------------------------------------------------- + +#define RFU_ID 0x00008001 // ID number of AGB-RFU device: ID returned by execution of rfu_REQBN_softReset_and_checkID. + +#define RFU_MBOOT_DOWNLOADER_SERIAL_NO 0x0000 // The game serial number of the multi-boot downloader (programs that boot without a Game Pak) + +#define RFU_API_BUFF_SIZE_RAM 0x0e8c // Necessary size for buffer specified by rfu_initializeAPI (fast communication version that operates the library SIO interrupt routines in RAM) +#define RFU_API_BUFF_SIZE_ROM 0x052c // Necessary size for buffer specified by rfu_initializeAPI (fast communication version that operates the library SIO interrupt routines in ROM) + +#define RFU_CHILD_MAX 4 // Maximum number of slaves that can be connected to one parent device + +#define RFU_GAME_NAME_LENGTH 13 // Possible length of game name set by rfu_REQB_configGameData +#define RFU_USER_NAME_LENGTH 8 // Possible length of user name set by rfu_REQB_configGameData + +#define RFU_H_DMA_MAX_CPU_CYCLE 42 // Maximum number of CPU cycles for H-DMA or DMA that starts with V-Blank that can operate when using RFU + +// Value to determine the level of the icon that displays the link strength of the wireless status (value of rfuLinkStatus->strength[0-3]) +#define RFU_LINK_ICON_LEVEL4_MAX 255 // 90% -100% (If the value is betwen 229 and 255, the icon level is 4) +#define RFU_LINK_ICON_LEVEL4_MIN 229 +#define RFU_LINK_ICON_LEVEL3_MAX 228 // 50% - 89% (If the value is betwen 127 and 228, the icon level is 3) +#define RFU_LINK_ICON_LEVEL3_MIN 127 +#define RFU_LINK_ICON_LEVEL2_MAX 126 // 10% - 49% (If the value is betwen 25 and 126, the icon level is 2) +#define RFU_LINK_ICON_LEVEL2_MIN 25 +#define RFU_LINK_ICON_LEVEL1_MAX 24 // 0% - 9% (If the value is betwen 0 and 24, the icon level is 1) +#define RFU_LINK_ICON_LEVEL1_MIN 0 + + +// ******************************************************* +// Definition Data for Arguments Used in Library Functions +// ******************************************************* +// Specified by u16 mbootFlag in rfu_REQ_configGameData +#define RFU_MBOOT_FLAG 0x01 // Enabling this flag, allows connection to a multi-boot program. + +// AvailSlot (number of slots available for connection) used in u16 availSlotFlag in rfu_REQ_configSystem +#define AVAIL_SLOT4 0x0000 +#define AVAIL_SLOT3 0x0001 +#define AVAIL_SLOT2 0x0002 +#define AVAIL_SLOT1 0x0003 + +// u8 connTypeFlag specified by rfu_setRecvBuffer +#define TYPE_UNI 0x10 // UNI-type +#define TYPE_NI 0x20 // NI-type + +// u8 connTypeFlag specified by rfu_clearSlot +#define TYPE_UNI_SEND 0x01 // UNI-type send +#define TYPE_UNI_RECV 0x02 // UNI-type receive +#define TYPE_NI_SEND 0x04 // NI-type send +#define TYPE_NI_RECV 0x08 // NI-type receive + +// ******************************************************* +// Definition Data Returned by Return Values for Library Functions +// ******************************************************* + +// Value of u8 *status for rfu_REQ_pollConnectParent (Connection Trial Status) +#define CP_STATUS_DONE 0x00 // Connection successful +#define CP_STATUS_IN_PROCESS 0x01 // Connecting +#define CP_STATUS_SLOT_CLOSED 0x02 // Parent device is not in connection mode with child device +#define CP_STATUS_DISCONNECTED 0x03 // Disconnected by parent device while connecting +#define CP_STATUS_UNKNOWN 0xff // Cannot read status due to REQ-API execution error + +// Value of u8 *status argument for rfu_REQ_pollRecoveryConnect (Link Restore Status) +#define RC_STATUS_DONE 0x00 // Connection restore successful +#define RC_STATUS_FAILED 0x01 // Connection restore failure (meaningless to try anymore) +#define RC_STATUS_SEARCHING_PARENT 0x02 // Searching for parent device +#define RC_STATUS_UNKNOWN 0xff // Cannot read status due to REQ-API execution error + +// Value of u8 *linkLossReason argument for rfu_REQBN_watchLink (Reason for Link Loss) +#define REASON_DISCONNECTED 0x00 // State of complete disconnection with rfuLL_disconnect and no possibility of restoring the link (can detect only child device) +#define REASON_LINK_LOSS 0x01 // State of link loss that allows for the possibility for the link to be restored + + +// ******************************************************* +// Definition Data Returned with Return Values for Library Functions +// ******************************************************* + +// Value returned by rfu_getMasterSlave +#define AGB_CLK_SLAVE 0 // AGB clock slave +#define AGB_CLK_MASTER 1 // AGB clock master + +// ******************************************************* +// Error Code Group for Library Functions +// ******************************************************* + +// Error codes returned by u16 REQ_result with a REQ callback when a REQ-API function is executed +#define ERR_REQ_CMD 0x0000 +#define ERR_REQ_CMD_CLOCK_DRIFT (ERR_REQ_CMD | 0x0001) // Clock drift occurs when a REQ command is sent +#define ERR_REQ_CMD_SENDING (ERR_REQ_CMD | 0x0002) // The next command cannot be issued because a REQ command is being sent +#define ERR_REQ_CMD_ACK_REJECTION (ERR_REQ_CMD | 0x0003) // The REQ command was refused when issued +#define ERR_REQ_CMD_CLOCK_SLAVE (ERR_REQ_CMD | 0x0004) // Issuing the REQ command was attempted but failed because the AGB is the clock slave +#define ERR_REQ_CMD_IME_DISABLE (ERR_REQ_CMD | 0x0006) // Issuing the REQ command was attempted but failed because the IME register is 0 + +#define ERR_PID_NOT_FOUND 0x0100 // The specified PID does not exist in the gRfuLinkStatus->partner[0-3].id list + +// Error code returned by the return value of rfu_initializeAPI +#define ERR_RFU_API_BUFF_SIZE 0x0001 +#define ERR_RFU_API_BUFF_ADR 0x0002 + +// Error codes returned by return values for rfu_REQBN_softReset_and_checkID +#define ERR_ID_CHECK_IME_DISABLE 0xffffffff // ID check could not be executed because REG_IME=0 when executing rfu_REQBN_softReset_and_checkID + +// Error codes returned by rfu_getConnectParentStatus and rfu_CHILD_getConnectRecoveryStatus +#define ERR_REQ_CMD_ID (ERR_REQ_CMD | 0x0010) // A required REQ command was not executed within this function execution + +// Error codes returned by rfu_NI_setSendData, rfu_UNI_setSendData, and rfu_NI_CHILD_setSendGameName +#define ERR_MODE 0x0300 +#define ERR_MODE_NOT_CONNECTED (ERR_MODE | 0x0001) // RFU is not in connection mode (parent or child) + +#define ERR_SLOT 0x0400 +#define ERR_SLOT_NO (ERR_SLOT | 0x0000) // The specified slot number is not right +#define ERR_SLOT_NOT_CONNECTED (ERR_SLOT | 0x0001) // The specified slot is not connected +#define ERR_SLOT_BUSY (ERR_SLOT | 0x0002) // The specified slot is already communicating +#define ERR_SLOT_NOT_SENDING (ERR_SLOT | 0x0003) // The specified slot is not currently sending (Note: This is returned by rfu_UNI_re_setSendData) +#define ERR_SLOT_TARGET (ERR_SLOT | 0x0004) // The specified target slot is not right + +#define ERR_SUBFRAME_SIZE 0x0500 // The specified subframe size is either larger than the remaining communication frame size or smaller than the link layer subframe header size + +// Error code returned by rfu_clearSlot, rfu_setRecvBuffer, and rfu_changeSendTarget +#define ERR_COMM_TYPE 0x0600 // The specified communication format is not right + +// Error code returned by rfu_REQ_recvData (when receiving NI-type or UNI-type data) +#define ERR_DATA_RECV 0x0700 // Error notification is issued in the following format. + // "ERR_DATA_RECV | (slot number issuing error with 0x0010<recv.errorCode. + +// Error code during NI-type communication (code entered into gRfuSlotStatusNI[x]->recv.errorCode) +#define ERR_RECV_BUFF_OVER (ERR_DATA_RECV | 0x0001) // The receive data size is larger than the receive buffer (Note: This error is used for both NI and UNI) +#define ERR_RECV_REPLY_SUBFRAME_SIZE (ERR_DATA_RECV | 0x0002) // All frames are already in use by other communications, and a subframe for reception response could not be secured + +// Error code during UNI-type communication (code entered into gRfuSlotStatusUNI[x]->recv.errorCode) +#define ERR_RECV_DATA_OVERWRITED (ERR_DATA_RECV | 0x0008) // Received new data when gRfuSlotStatusUNI[x]->recv.newDataFlag=1 + + +// ******************************************************* +// Definition Data Used by Global Variables in the Library +// ******************************************************* + +// gRfuLinkStatus------------------------------------------- +// Connection status (refer to gRfuLinkStatus->parentChild) +#define MODE_NEUTRAL 0xff // Initialization +#define MODE_CHILD 0x00 // Child +#define MODE_PARENT 0x01 // Parent + + +// gRfuSlotStatusNI,UNI----------------------------------- +// Definition data for NI-(Numbered Information) and UNI-(Un-Numbered Information) type communication + +// Definition data common to NI- and UNI-type communication +#define LLF_P_SIZE 87 // Maximum link layer communication frame size for the Parent (Maximum number of bytes per transmission) +#define LLF_C_SIZE 16 // " " for the Child +#define LLSF_P_HEADER_SIZE 3 // Header size used by one link layer subframe (NI or UNI frame) for the Parent +#define LLSF_C_HEADER_SIZE 2 // " " for the Child + +// Link Layer Communication Code +#define LCOM_NULL 0x0000 +#define LCOM_NI_START 0x0001 +#define LCOM_NI 0x0002 +#define LCOM_NI_END 0x0003 +#define LCOM_UNI 0x0004 + +// Flag for Slot Status Data +#define SLOT_BUSY_FLAG 0x8000 // Slot in use +#define SLOT_SEND_FLAG 0x0020 // Send +#define SLOT_RECV_FLAG 0x0040 // Receive + +// NI- and UNI-type shared slot stand-by data (same state as gRfuSlotStatusNI[x]->send or ->recv.state or gRfuSlotStatusUNI) +#define SLOT_STATE_READY 0x0000 // Slot initialization + +// Status data for NI-type communication (gRfuSlotStatusNI[x]->send or ->recv.state) +#define SLOT_STATE_SEND_START (SLOT_BUSY_FLAG | SLOT_SEND_FLAG | LCOM_NI_START) // Start transmission +#define SLOT_STATE_SENDING (SLOT_BUSY_FLAG | SLOT_SEND_FLAG | LCOM_NI) // Transmitting +#define SLOT_STATE_SEND_LAST (SLOT_BUSY_FLAG | SLOT_SEND_FLAG | LCOM_NI_END) // Verify transmission end +#define SLOT_STATE_SEND_NULL (SLOT_BUSY_FLAG | SLOT_SEND_FLAG | LCOM_NULL) // Send NULL subframe to notify end of transmission +#define SLOT_STATE_SEND_SUCCESS ( SLOT_SEND_FLAG | 0x006) // Transmission successful +#define SLOT_STATE_SEND_FAILED ( SLOT_SEND_FLAG | 0x007) // Transmission failed + // Distinction of slot where transmission succeeded/failed compares gRfuSlotStatusNI[x]->send.bmSlot and same bmSlot_org +#define SLOT_STATE_RECV_START (SLOT_BUSY_FLAG | SLOT_RECV_FLAG | LCOM_NI_START) // Start reception +#define SLOT_STATE_RECEIVING (SLOT_BUSY_FLAG | SLOT_RECV_FLAG | LCOM_NI) // Receiving +#define SLOT_STATE_RECV_LAST (SLOT_BUSY_FLAG | SLOT_RECV_FLAG | LCOM_NI_END) // Verify reception end +#define SLOT_STATE_RECV_SUCCESS ( SLOT_RECV_FLAG | 0x006) // Reception successful +#define SLOT_STATE_RECV_FAILED ( SLOT_RECV_FLAG | 0x007) // Reception failed +#define SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN (SLOT_RECV_FLAG | 0x008) // The data was received successful, but because the end of the communication was incomplete, whether the transmission side status is successful or failed is unknown +#define SLOT_STATE_RECV_IGNORE ( SLOT_RECV_FLAG | 0x009) // Ignore reception (refer to gRfuSlotStatusNI[x]->recv.errorCode for reason for ignoring) + +// Status data for UNI-type communication (refer to gRfuSlotStatusUNI[x]->send.state) +#define SLOT_STATE_SEND_UNI (SLOT_BUSY_FLAG | SLOT_SEND_FLAG | LCOM_UNI) // Transmitting +// TODO: move the 2 structs to some other header as they're declared by GF struct UnkLinkRfuStruct_02022B14Substruct { u16 unk_00_0:4; @@ -105,7 +298,25 @@ struct __attribute__((packed, aligned(2))) UnkLinkRfuStruct_02022B14 u8 unk_0c; }; -struct RfuStruct +// the following structs are not documented in SDK +struct RfuPacket8 +{ + u8 data[0x74]; +}; + +struct RfuPacket32 +{ + u32 command; + u32 data[0x1C]; +}; + +union RfuPacket +{ + struct RfuPacket32 rfuPacket32; + struct RfuPacket8 rfuPacket8; +}; + +struct STWIStatus { vs32 state; u8 reqLength; @@ -132,69 +343,116 @@ struct RfuStruct vu8 unk_2c; }; +// This struct is used as u8 array in SDK. struct RfuIntrStruct { union RfuPacket rxPacketAlloc; union RfuPacket txPacketAlloc; u8 block1[0x960]; // size of librfu_intr.s binary - struct RfuStruct block2; + struct STWIStatus block2; }; +// Data Structure for Transmitting UNI-Type Data +struct UNISend +{ + u16 state; // Slot communication state (SLOT_STATE_READY, SLOT_STATE_SEND_UNI) + u8 dataReadyFlag; // Flag indicating transmission data is prepared (0: data sent; 1: transmission data ready) + // Set with rfu_UNI_re_setSendData or rfu_UNI_readySendData, cleared when data is sent with rfu_REQ_sendData. + u8 bmSlot; // Expresses transmission destination slot as bits + u16 payloadSize; // Payload size of 1 transmission. "size" specified by rfu_UNI_setSendData or rfu_UNI_re_setSendData is used. + const void *src; // Beginning address of transmission data +}; + +// Data Structure for Receiving UNI Data +struct UNIRecv +{ + u16 state; // Slot communication state (SLOT_STATE_READY, SLOT_STATE_RECEIVING, SLOT_STATE_RECV_IGNORE) + u16 errorCode; // Error code during reception + u16 dataSize; // Size of receive data + u8 newDataFlag; // Flag indicating whether receive data has newly arrived (0: no newly arrived data; 1: newly arrived data) + // The flag is cleared with rfu_UNI_clearRecvNewDataFlag; it is set when data is received with rfu_REQ_recvData. + u8 dataBlockFlag; // Flag for unreferenced receive data overwrite block (default is 0 Note: not used) +}; + +// Slot Status Data Structure for UNI-Type Communication struct RfuSlotStatusUNI { - struct - { - struct UNISend - { - u16 state; - u8 dataReadyFlag; - u8 bmSlot; - u16 payloadSize; - const void *src; - } send; - struct UNIRecv - { - u16 state; - u16 errorCode; - u16 dataSize; - u8 newDataFlag; - u8 dataBlockFlag; - } recv; - } sub; - void *recvBuffer; - u32 recvBufferSize; + struct UNISend send; // Transmission Status + struct UNIRecv recv; // Reception Status + void *recvBuffer; // Reception Buffer Address + u32 recvBufferSize; // Reception Buffer Size }; +#define WINDOW_COUNT 4 + struct NIComm { - u16 state; - u16 failCounter; - const u8 *nowP[4]; - s32 remainSize; - u16 errorCode; - u8 bmSlot; - u8 recvAckFlag[4]; + u16 state; // Communication state of slot + u16 failCounter; // Count of failed transmissions/receptions (Count is increased when transmission/reception of data does not succeed within 1PF=16.7 ms) + const u8 *now_p[WINDOW_COUNT]; // Address of current send/receive (The data is divided into WINDOW_COUNT blocks and sent in payloadSize units.) + // remainSize is u32 in SDK. This is a hack to match ASM + s32 remainSize; // Size of remaining communication data + u16 errorCode; // Error code + u8 bmSlot; // Expresses the current communication slot in bits + // (When sending from the Master, because multiple slaves can be specified with bmSlot, communications are terminated based on the failCounter for each child device) + // Parameters used inside the Library + u8 recvAckFlag[WINDOW_COUNT]; u8 ack; u8 phase; - u8 n[4]; - const void *src; - u8 bmSlotOrg; - u8 dataType; - u16 payloadSize; - u32 dataSize; + u8 n[WINDOW_COUNT]; + // Parameters indicating the current communication content + const void *src; // Start address transmission data (valid only for transmitting device) + u8 bmSlotOrg; // Expresses the communication source slot at the beginning of the transmission in bits (valid only for transmitting device) + u8 dataType; // Transmission/reception data type (0: User data; 1: Game identification information) + u16 payloadSize; // Payload size for one transmission + u32 dataSize; // Size of transmission/reception data + // Calculated by subtracting link layer header size from subFrameSize specified by the rfu_NI_setSendData function }; struct RfuSlotStatusNI { - struct - { - struct NIComm send; - struct NIComm recv; - } sub; - void *recvBuffer; - u32 recvBufferSize; + struct NIComm send; // Transmission Status + struct NIComm recv; // Reception Status + void *recvBuffer; // Reception Buffer Address + u32 recvBufferSize; // Reception Buffer Size +}; + +// Game Identification Information Data Structure +struct RfuTgtData +{ + u16 id; // ID of parent candidate ID of connection partner + u8 slot; // Slot number where parent candidate can enter Connection slot number + u8 mbootFlag; // Flag to indicate whether or not the parent candidate Flag to indicate whether or not the connection partner + // is multiboot program for download is multiboot program for download + u16 serialNo; // Game serial number of parent candidate Game serial number of connection partner + u8 gname[RFU_GAME_NAME_LENGTH + 2]; // Game name of parent candidate Game name of connection partner + u8 uname[RFU_USER_NAME_LENGTH + 1]; // User name for parent candidate User name for connection partner +}; + +struct RfuLinkStatus +{ + u8 parentChild; // Connection status (0x01:MODE_PARENT 0x00:MODE_CHILD 0xff:MODE_NEUTRAL) + u8 connCount; // Number of connections + u8 connSlotFlag; // Flag to indicate in bits the connection slot (0x01< Date: Fri, 10 Jan 2020 03:17:00 +0800 Subject: use constants --- include/librfu.h | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/librfu.h b/include/librfu.h index 1e128d209..f5a7b4d96 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -137,18 +137,20 @@ // Definition Data Returned by Return Values for Library Functions // ******************************************************* +// The function doesn't have return value. // Value of u8 *status for rfu_REQ_pollConnectParent (Connection Trial Status) -#define CP_STATUS_DONE 0x00 // Connection successful -#define CP_STATUS_IN_PROCESS 0x01 // Connecting -#define CP_STATUS_SLOT_CLOSED 0x02 // Parent device is not in connection mode with child device -#define CP_STATUS_DISCONNECTED 0x03 // Disconnected by parent device while connecting -#define CP_STATUS_UNKNOWN 0xff // Cannot read status due to REQ-API execution error +// #define CP_STATUS_DONE 0x00 // Connection successful +// #define CP_STATUS_IN_PROCESS 0x01 // Connecting +// #define CP_STATUS_SLOT_CLOSED 0x02 // Parent device is not in connection mode with child device +// #define CP_STATUS_DISCONNECTED 0x03 // Disconnected by parent device while connecting +// #define CP_STATUS_UNKNOWN 0xff // Cannot read status due to REQ-API execution error +// The function doesn't exist. // Value of u8 *status argument for rfu_REQ_pollRecoveryConnect (Link Restore Status) -#define RC_STATUS_DONE 0x00 // Connection restore successful -#define RC_STATUS_FAILED 0x01 // Connection restore failure (meaningless to try anymore) -#define RC_STATUS_SEARCHING_PARENT 0x02 // Searching for parent device -#define RC_STATUS_UNKNOWN 0xff // Cannot read status due to REQ-API execution error +// #define RC_STATUS_DONE 0x00 // Connection restore successful +// #define RC_STATUS_FAILED 0x01 // Connection restore failure (meaningless to try anymore) +// #define RC_STATUS_SEARCHING_PARENT 0x02 // Searching for parent device +// #define RC_STATUS_UNKNOWN 0xff // Cannot read status due to REQ-API execution error // Value of u8 *linkLossReason argument for rfu_REQBN_watchLink (Reason for Link Loss) #define REASON_DISCONNECTED 0x00 // State of complete disconnection with rfuLL_disconnect and no possibility of restoring the link (can detect only child device) @@ -189,6 +191,7 @@ // Error codes returned by rfu_NI_setSendData, rfu_UNI_setSendData, and rfu_NI_CHILD_setSendGameName #define ERR_MODE 0x0300 +#define ERR_MODE_NOT_PARENT (ERR_MODE | 0x0000) // not in SDK #define ERR_MODE_NOT_CONNECTED (ERR_MODE | 0x0001) // RFU is not in connection mode (parent or child) #define ERR_SLOT 0x0400 @@ -215,6 +218,8 @@ // Error code during UNI-type communication (code entered into gRfuSlotStatusUNI[x]->recv.errorCode) #define ERR_RECV_DATA_OVERWRITED (ERR_DATA_RECV | 0x0008) // Received new data when gRfuSlotStatusUNI[x]->recv.newDataFlag=1 +// not in SDK header +#define ERR_RECV_UNK (ERR_DATA_RECV | 0x0001 | 0x0008) // ******************************************************* // Definition Data Used by Global Variables in the Library @@ -496,7 +501,7 @@ struct RfuS32Id u16 unkA; }; -struct RfuStructsBuffer +struct RfuAPIBuffer { struct RfuLinkStatus linkStatus; struct RfuStatic static_; @@ -506,7 +511,7 @@ struct RfuStructsBuffer struct RfuIntrStruct intr; }; -extern struct STWIStatus *gRfuState; +extern struct STWIStatus *gSTWIStatus; extern struct RfuLinkStatus *gRfuLinkStatus; extern struct RfuStatic *gRfuStatic; extern struct RfuFixed *gRfuFixed; @@ -522,7 +527,7 @@ s32 AgbRFU_checkID(u8); // librfu_rfu // API Initialization and Initial Settings // API Initialization -u16 rfu_initializeAPI(struct RfuStructsBuffer *APIBuffer, u16 buffByteSize, IntrFunc *sioIntrTable_p, bool8 copyInterruptToRam); +u16 rfu_initializeAPI(struct RfuAPIBuffer *APIBuffer, u16 buffByteSize, IntrFunc *sioIntrTable_p, bool8 copyInterruptToRam); // Set Timer Interrupt void rfu_setTimerInterrupt(u8 timerNo, IntrFunc *timerIntrTable_p); // Resident Function called from within a V-Blank Interrupt -- cgit v1.2.3