diff options
-rw-r--r-- | include/librfu.h | 10 | ||||
-rw-r--r-- | src/librfu_rfu.c | 60 |
2 files changed, 51 insertions, 19 deletions
diff --git a/include/librfu.h b/include/librfu.h index 50dd1c3db..3c9d776f1 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -4,6 +4,8 @@ #include "global.h" #include "main.h" +#define LIBRFU_VERSION 1024 + /* TODOs: * - documentation * - check if any field needs to be volatile @@ -307,7 +309,11 @@ struct STWIStatus u8 ackActiveCommand; u8 timerSelect; u8 unk_b; - u32 timerState; // this field is s32 in emerald +#if LIBRFU_VERSION >= 1026 + s32 timerState; +#else + u32 timerState; +#endif vu8 timerActive; u8 unk_11; vu16 error; @@ -472,7 +478,7 @@ extern struct RfuFixed *gRfuFixed; extern struct RfuSlotStatusNI *gRfuSlotStatusNI[RFU_CHILD_MAX]; extern struct RfuSlotStatusUNI *gRfuSlotStatusUNI[RFU_CHILD_MAX]; -// librfu_s32id +// librfu_sio32id s32 AgbRFU_checkID(u8 maxTries); // Arguments with "bm..." specify slots of the form (0x01 << slot number) that are the object of a function operation. diff --git a/src/librfu_rfu.c b/src/librfu_rfu.c index 420fb7c9a..9cd8fe13e 100644 --- a/src/librfu_rfu.c +++ b/src/librfu_rfu.c @@ -108,7 +108,7 @@ static const struct LLSFStruct llsf_struct[2] = { } }; -#ifdef EMERALD +#if LIBRFU_VERSION == 1026 static const char lib_ver[] = "RFU_V1026"; #else static const char lib_ver[] = "RFU_V1024"; @@ -116,12 +116,12 @@ static const char lib_ver[] = "RFU_V1024"; static const char str_checkMbootLL[] = "RFU-MBOOT"; -#define COPY(src, dst, size) do { \ - const u16 *_src = (const u16 *)(src); \ - u16 *_dst = (u16 *)(dst); \ - u16 _size = (size); \ - while (_size-- != 0) \ - *_dst++ = *_src++; \ +#define COPY(src, dst, iterator, size) do { \ + const u16 *_src = (const u16 *)(src); \ + u16 *_dst = (u16 *)(dst); \ + iterator = (size); \ + while (iterator-- != 0) \ + *_dst++ = *_src++; \ } while (0) u16 rfu_initializeAPI(u32 *APIBuffer, u16 buffByteSize, IntrFunc *sioIntrTable_p, bool8 copyInterruptToRam) @@ -177,17 +177,17 @@ u16 rfu_initializeAPI(u32 *APIBuffer, u16 buffByteSize, IntrFunc *sioIntrTable_p gRfuSlotStatusUNI[i]->recvBufferSize = 0; } // rfu_REQ_changeMasterSlave is the function next to rfu_STC_fastCopy -#if LIBRFU_VERSION < 1028 +#if LIBRFU_VERSION < 1026 src = (const u16 *)((uintptr_t)&rfu_STC_fastCopy & ~1); dst = gRfuFixed->fastCopyBuffer; buffByteSizeMax = ((void *)rfu_REQ_changeMasterSlave - (void *)rfu_STC_fastCopy) / sizeof(u16); while (buffByteSizeMax-- != 0) *dst++ = *src++; #else - // register swap dst <--> buffByteSizeMax COPY( - (const u16 *)((uintptr_t)&rfu_STC_fastCopy & ~1), + (uintptr_t)&rfu_STC_fastCopy & ~1, gRfuFixed->fastCopyBuffer, + buffByteSizeMax, 0x60 / sizeof(u16) ); #endif @@ -501,7 +501,7 @@ static void rfu_CB_configGameData(u8 reqCommand, u16 reqResult) void rfu_REQ_startSearchChild(void) { u16 result; -#if LIBRFU_VERSION >= 1028 +#if LIBRFU_VERSION >= 1026 u16 i; for (i = 0; i < RFU_CHILD_MAX; i++) { @@ -591,14 +591,12 @@ static void rfu_STC_readChildList(void) u8 numSlots = gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[1]; u8 *data_p; u8 i; - u8 true_slots[RFU_CHILD_MAX]; u8 bm_slot_id; - -#if LIBRFU_VERSION >= 1028 -//#if 1 - // TODO: decompile this +#if LIBRFU_VERSION < 1026 + u8 true_slots[RFU_CHILD_MAX]; #endif +#if LIBRFU_VERSION < 1026 if (numSlots != 0) { stwiParam = gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket32.data[0]; @@ -612,6 +610,7 @@ static void rfu_STC_readChildList(void) } gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket32.data[0] = stwiParam; } +#endif for (data_p = &gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[4]; numSlots != 0; data_p += 4) @@ -619,6 +618,7 @@ static void rfu_STC_readChildList(void) bm_slot_id = data_p[2]; if (bm_slot_id < RFU_CHILD_MAX && !((gRfuLinkStatus->connSlotFlag >> bm_slot_id) & 1) && !((gRfuLinkStatus->linkLossSlotFlag >> bm_slot_id) & 1)) { + #if LIBRFU_VERSION < 1026 if (true_slots[bm_slot_id] != 0) ++gRfuStatic->lsFixedCount[bm_slot_id]; if (gRfuStatic->lsFixedCount[bm_slot_id] >= 4) @@ -633,6 +633,17 @@ static void rfu_STC_readChildList(void) gRfuStatic->flags &= 0x7F; gRfuStatic->cidBak[bm_slot_id] = gRfuLinkStatus->partner[bm_slot_id].id; } + #else + gRfuStatic->lsFixedCount[bm_slot_id] = 0xF0; + gRfuLinkStatus->strength[bm_slot_id] = 16; + gRfuLinkStatus->connSlotFlag |= 1 << bm_slot_id; + ++gRfuLinkStatus->connCount; + gRfuLinkStatus->partner[bm_slot_id].id = *(u16 *)data_p; + gRfuLinkStatus->partner[bm_slot_id].slot = bm_slot_id; + gRfuLinkStatus->parentChild = MODE_PARENT; + gRfuStatic->flags &= 0x7F; + gRfuStatic->cidBak[bm_slot_id] = gRfuLinkStatus->partner[bm_slot_id].id; + #endif } --numSlots; } @@ -881,7 +892,11 @@ u16 rfu_REQBN_watchLink(u16 reqCommandId, u8 *bmLinkLossSlot, u8 *linkLossReason gRfuStatic->watchdogTimer = 360; if (gRfuStatic->nowWatchInterval == 0) { + #if LIBRFU_VERSION < 1026 gRfuStatic->nowWatchInterval = gRfuLinkStatus->watchInterval; + #else + gRfuStatic->nowWatchInterval = 4; + #endif reasonMaybe = 1; } if ((u8)reqCommandId == ID_DISCONNECTED_AND_CHANGE_REQ) @@ -934,6 +949,14 @@ u16 rfu_REQBN_watchLink(u16 reqCommandId, u8 *bmLinkLossSlot, u8 *linkLossReason } for (; i < RFU_CHILD_MAX; ++i) { + #if LIBRFU_VERSION >= 1026 + if (gRfuStatic->lsFixedCount[i] != 0) + { + gRfuStatic->lsFixedCount[i] -= 4; + if (gRfuLinkStatus->strength[i] <= 15) + gRfuLinkStatus->strength[i] = 16; + } + #endif newLinkLossFlag = 1 << i; if (reqResult == 0) { @@ -1041,6 +1064,9 @@ static void rfu_STC_removeLinkData(u8 bmConnectedPartnerId, u8 bmDisconnect) u8 bmLinkLossFlag = 1 << bmConnectedPartnerId; s32 bmLinkRetainedFlag; +#if LIBRFU_VERSION >= 1026 + gRfuStatic->lsFixedCount[bmConnectedPartnerId] = 0; +#endif if ((gRfuLinkStatus->connSlotFlag & bmLinkLossFlag) && gRfuLinkStatus->connCount != 0) --gRfuLinkStatus->connCount; gRfuLinkStatus->connSlotFlag &= bmLinkRetainedFlag = ~bmLinkLossFlag; @@ -1421,7 +1447,7 @@ static u16 rfu_STC_setSendData_org(u8 ni_or_uni, u8 bmSendSlot, u8 subFrameSize, slotStatus_NI->send.src = src; slotStatus_NI->send.ack = 0; slotStatus_NI->send.phase = 0; - #ifndef NONMATCHING // to fix bm_slot_id, r3, frameSize, sending register roulette + #ifndef NONMATCHING // to fix r2, r3, r4, r5 register roulette asm("":::"r2"); #endif for (i = 0; i < WINDOW_COUNT; ++i) |