Document remaining local variables in librfu_rfu

This commit is contained in:
PikalaxALT
2020-02-01 16:25:00 -05:00
parent 08aafe093c
commit 16cc1ee922
+273 -276
View File
@@ -180,12 +180,12 @@ u16 rfu_initializeAPI(u32 *APIBuffer, u16 buffByteSize, IntrFunc *sioIntrTable_p
static void rfu_STC_clearAPIVariables(void) static void rfu_STC_clearAPIVariables(void)
{ {
u16 IMEBackup = REG_IME; u16 IMEBackup = REG_IME;
u8 i, r4; u8 i, flags;
REG_IME = 0; REG_IME = 0;
r4 = gRfuStatic->flags; flags = gRfuStatic->flags;
CpuFill16(0, gRfuStatic, sizeof(struct RfuStatic)); CpuFill16(0, gRfuStatic, sizeof(struct RfuStatic));
gRfuStatic->flags = r4 & 8; gRfuStatic->flags = flags & 8;
CpuFill16(0, gRfuLinkStatus, sizeof(struct RfuLinkStatus)); CpuFill16(0, gRfuLinkStatus, sizeof(struct RfuLinkStatus));
gRfuLinkStatus->watchInterval = 4; gRfuLinkStatus->watchInterval = 4;
gRfuStatic->nowWatchInterval = 0; gRfuStatic->nowWatchInterval = 0;
@@ -562,7 +562,7 @@ static void rfu_CB_pollAndEndSearchChild(u8 reqCommand, u16 reqResult)
static void rfu_STC_readChildList(void) static void rfu_STC_readChildList(void)
{ {
u32 r5; u32 stwiParam;
u8 numSlots = gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[1]; u8 numSlots = gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[1];
u8 *data_p; u8 *data_p;
u8 i; u8 i;
@@ -571,7 +571,7 @@ static void rfu_STC_readChildList(void)
if (numSlots != 0) if (numSlots != 0)
{ {
r5 = gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket32.data[0]; stwiParam = gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket32.data[0];
STWI_set_Callback_M(rfu_CB_defaultCallback); STWI_set_Callback_M(rfu_CB_defaultCallback);
STWI_send_LinkStatusREQ(); STWI_send_LinkStatusREQ();
if (STWI_poll_CommandEnd() == 0) if (STWI_poll_CommandEnd() == 0)
@@ -580,7 +580,7 @@ static void rfu_STC_readChildList(void)
for (i = 0; i < RFU_CHILD_MAX; ++i) for (i = 0; i < RFU_CHILD_MAX; ++i)
true_slots[i] = *data_p++; true_slots[i] = *data_p++;
} }
gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket32.data[0] = r5; gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket32.data[0] = stwiParam;
} }
for (data_p = &gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[4]; for (data_p = &gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[4];
numSlots != 0; numSlots != 0;
@@ -651,7 +651,7 @@ static void rfu_STC_readParentCandidateList(void)
numSlots = packet_p[1]; numSlots = packet_p[1];
packet_p += 4; packet_p += 4;
gRfuLinkStatus->findParentCount = 0; gRfuLinkStatus->findParentCount = 0;
for (i = 0; i < 4 && numSlots != 0; ++i) for (i = 0; i < RFU_CHILD_MAX && numSlots != 0; ++i)
{ {
numSlots -= 7; numSlots -= 7;
uname_p = packet_p + 6; uname_p = packet_p + 6;
@@ -792,28 +792,28 @@ void rfu_REQ_endConnectParent(void)
u16 rfu_syncVBlank(void) u16 rfu_syncVBlank(void)
{ {
u8 r3, r4; u8 masterSlave, i;
s32 r5; s32 bmSlotFlag;
rfu_NI_checkCommFailCounter(); rfu_NI_checkCommFailCounter();
if (gRfuLinkStatus->parentChild == MODE_NEUTRAL) if (gRfuLinkStatus->parentChild == MODE_NEUTRAL)
return 0; return 0;
if (gRfuStatic->nowWatchInterval != 0) if (gRfuStatic->nowWatchInterval != 0)
--gRfuStatic->nowWatchInterval; --gRfuStatic->nowWatchInterval;
r3 = rfu_getMasterSlave(); masterSlave = rfu_getMasterSlave();
if (!(gRfuStatic->flags & 2)) if (!(gRfuStatic->flags & 2))
{ {
if (r3 == 0) if (masterSlave == AGB_CLK_SLAVE)
{ {
gRfuStatic->flags |= 4; gRfuStatic->flags |= 4;
gRfuStatic->watchdogTimer = 360; gRfuStatic->watchdogTimer = 360;
} }
} }
else if (r3 != 0) else if (masterSlave != AGB_CLK_SLAVE)
{ {
gRfuStatic->flags &= 0xFB; gRfuStatic->flags &= 0xFB;
} }
if (r3 != 0) if (masterSlave != AGB_CLK_SLAVE)
gRfuStatic->flags &= 0xFD; gRfuStatic->flags &= 0xFD;
else else
gRfuStatic->flags |= 2; gRfuStatic->flags |= 2;
@@ -822,10 +822,10 @@ u16 rfu_syncVBlank(void)
if (gRfuStatic->watchdogTimer == 0) if (gRfuStatic->watchdogTimer == 0)
{ {
gRfuStatic->flags &= 0xFB; gRfuStatic->flags &= 0xFB;
r5 = gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag; bmSlotFlag = gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag;
for (r4 = 0; r4 < RFU_CHILD_MAX; ++r4) for (i = 0; i < RFU_CHILD_MAX; ++i)
if ((r5 >> r4) & 1) if ((bmSlotFlag >> i) & 1)
rfu_STC_removeLinkData(r4, 1); rfu_STC_removeLinkData(i, 1);
gRfuLinkStatus->parentChild = MODE_NEUTRAL; gRfuLinkStatus->parentChild = MODE_NEUTRAL;
return 1; return 1;
} }
@@ -1109,7 +1109,7 @@ void rfu_REQ_CHILD_pollConnectRecovery(void)
static void rfu_CB_CHILD_pollConnectRecovery(u8 reqCommand, u16 reqResult) static void rfu_CB_CHILD_pollConnectRecovery(u8 reqCommand, u16 reqResult)
{ {
u8 bm_slot_flag, i; u8 bm_slot_flag, i;
struct RfuLinkStatus *r2; struct RfuLinkStatus *rfuLinkStatus;
if (reqResult == 0 && gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[4] == 0 && gRfuStatic->recoveryBmSlot) if (reqResult == 0 && gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[4] == 0 && gRfuStatic->recoveryBmSlot)
{ {
@@ -1117,8 +1117,8 @@ static void rfu_CB_CHILD_pollConnectRecovery(u8 reqCommand, u16 reqResult)
for (i = 0; i < RFU_CHILD_MAX; ++i) for (i = 0; i < RFU_CHILD_MAX; ++i)
{ {
bm_slot_flag = 1 << i; bm_slot_flag = 1 << i;
r2 = gRfuLinkStatus; // ??? rfuLinkStatus = gRfuLinkStatus; // ???
if (gRfuStatic->recoveryBmSlot & bm_slot_flag & r2->linkLossSlotFlag) if (gRfuStatic->recoveryBmSlot & bm_slot_flag & rfuLinkStatus->linkLossSlotFlag)
{ {
gRfuLinkStatus->connSlotFlag |= bm_slot_flag; gRfuLinkStatus->connSlotFlag |= bm_slot_flag;
gRfuLinkStatus->linkLossSlotFlag &= ~bm_slot_flag; gRfuLinkStatus->linkLossSlotFlag &= ~bm_slot_flag;
@@ -1133,11 +1133,8 @@ static void rfu_CB_CHILD_pollConnectRecovery(u8 reqCommand, u16 reqResult)
u16 rfu_CHILD_getConnectRecoveryStatus(u8 *status) u16 rfu_CHILD_getConnectRecoveryStatus(u8 *status)
{ {
u8 r0;
*status = 0xFF; *status = 0xFF;
r0 = gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[0] + 77; if (gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[0] == 0xB3 || gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[0] == 0xB4)
if (r0 <= 1)
{ {
*status = gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[4]; *status = gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[4];
return 0; return 0;
@@ -1213,87 +1210,87 @@ void rfu_clearAllSlot(void)
REG_IME = IMEBackup; REG_IME = IMEBackup;
} }
static void rfu_STC_releaseFrame(u8 r5, u8 r3, struct NIComm *r4) static void rfu_STC_releaseFrame(u8 bm_slot_id, u8 send_recv, struct NIComm *NI_comm)
{ {
if (!(gRfuStatic->flags & 0x80)) if (!(gRfuStatic->flags & 0x80))
{ {
if (r3 == 0) if (send_recv == 0)
gRfuLinkStatus->remainLLFrameSizeParent += r4->payloadSize; gRfuLinkStatus->remainLLFrameSizeParent += NI_comm->payloadSize;
gRfuLinkStatus->remainLLFrameSizeParent += 3; gRfuLinkStatus->remainLLFrameSizeParent += 3;
} }
else else
{ {
if (r3 == 0) if (send_recv == 0)
gRfuLinkStatus->remainLLFrameSizeChild[r5] += r4->payloadSize; gRfuLinkStatus->remainLLFrameSizeChild[bm_slot_id] += NI_comm->payloadSize;
gRfuLinkStatus->remainLLFrameSizeChild[r5] += 2; gRfuLinkStatus->remainLLFrameSizeChild[bm_slot_id] += 2;
} }
} }
u16 rfu_clearSlot(u8 connTypeFlag, u8 slotStatusIndex) u16 rfu_clearSlot(u8 connTypeFlag, u8 slotStatusIndex)
{ {
u16 r10, r3, r1; u16 imeBak, send_recv, i;
struct NIComm *r4; struct NIComm *NI_comm;
if (slotStatusIndex >= RFU_CHILD_MAX) if (slotStatusIndex >= RFU_CHILD_MAX)
return ERR_SLOT_NO; return ERR_SLOT_NO;
if (!(connTypeFlag & (TYPE_UNI_SEND | TYPE_UNI_RECV | TYPE_NI_SEND | TYPE_NI_RECV))) if (!(connTypeFlag & (TYPE_UNI_SEND | TYPE_UNI_RECV | TYPE_NI_SEND | TYPE_NI_RECV)))
return ERR_COMM_TYPE; return ERR_COMM_TYPE;
r10 = REG_IME; imeBak = REG_IME;
REG_IME = 0; REG_IME = 0;
if (connTypeFlag & (TYPE_NI_SEND | TYPE_NI_RECV)) if (connTypeFlag & (TYPE_NI_SEND | TYPE_NI_RECV))
{ {
for (r3 = 0; r3 < 2; ++r3) for (send_recv = 0; send_recv < 2; ++send_recv)
{ {
r4 = NULL; NI_comm = NULL;
if (r3 == 0) if (send_recv == 0)
{ {
if (connTypeFlag & TYPE_NI_SEND) if (connTypeFlag & TYPE_NI_SEND)
{ {
r4 = &gRfuSlotStatusNI[slotStatusIndex]->send; NI_comm = &gRfuSlotStatusNI[slotStatusIndex]->send;
gRfuLinkStatus->sendSlotNIFlag &= ~r4->bmSlotOrg; gRfuLinkStatus->sendSlotNIFlag &= ~NI_comm->bmSlotOrg;
} }
} }
else else
{ {
if (connTypeFlag & TYPE_NI_RECV) if (connTypeFlag & TYPE_NI_RECV)
{ {
r4 = &gRfuSlotStatusNI[slotStatusIndex]->recv; NI_comm = &gRfuSlotStatusNI[slotStatusIndex]->recv;
gRfuLinkStatus->recvSlotNIFlag &= ~(1 << slotStatusIndex); gRfuLinkStatus->recvSlotNIFlag &= ~(1 << slotStatusIndex);
} }
} }
if (r4 != NULL) if (NI_comm != NULL)
{ {
if (r4->state & SLOT_BUSY_FLAG) if (NI_comm->state & SLOT_BUSY_FLAG)
{ {
rfu_STC_releaseFrame(slotStatusIndex, r3, r4); rfu_STC_releaseFrame(slotStatusIndex, send_recv, NI_comm);
for (r1 = 0; r1 < RFU_CHILD_MAX; ++r1) for (i = 0; i < RFU_CHILD_MAX; ++i)
if ((r4->bmSlotOrg >> r1) & 1) if ((NI_comm->bmSlotOrg >> i) & 1)
r4->failCounter = 0; NI_comm->failCounter = 0;
} }
CpuFill16(0, r4, sizeof(struct NIComm)); CpuFill16(0, NI_comm, sizeof(struct NIComm));
} }
} }
} }
if (connTypeFlag & TYPE_UNI_SEND) if (connTypeFlag & TYPE_UNI_SEND)
{ {
struct RfuSlotStatusUNI *r3 = gRfuSlotStatusUNI[slotStatusIndex]; struct RfuSlotStatusUNI *slotStatusUNI = gRfuSlotStatusUNI[slotStatusIndex];
if (r3->send.state & SLOT_BUSY_FLAG) if (slotStatusUNI->send.state & SLOT_BUSY_FLAG)
{ {
if (!(gRfuStatic->flags & 0x80)) if (!(gRfuStatic->flags & 0x80))
gRfuLinkStatus->remainLLFrameSizeParent += 3 + (u8)r3->send.payloadSize; gRfuLinkStatus->remainLLFrameSizeParent += 3 + (u8)slotStatusUNI->send.payloadSize;
else else
gRfuLinkStatus->remainLLFrameSizeChild[slotStatusIndex] += 2 + (u8)r3->send.payloadSize; gRfuLinkStatus->remainLLFrameSizeChild[slotStatusIndex] += 2 + (u8)slotStatusUNI->send.payloadSize;
gRfuLinkStatus->sendSlotUNIFlag &= ~r3->send.bmSlot; gRfuLinkStatus->sendSlotUNIFlag &= ~slotStatusUNI->send.bmSlot;
} }
CpuFill16(0, &r3->send, sizeof(struct UNISend)); CpuFill16(0, &slotStatusUNI->send, sizeof(struct UNISend));
} }
if (connTypeFlag & TYPE_UNI_RECV) if (connTypeFlag & TYPE_UNI_RECV)
{ {
CpuFill16(0, &gRfuSlotStatusUNI[slotStatusIndex]->recv, sizeof(struct UNIRecv)); CpuFill16(0, &gRfuSlotStatusUNI[slotStatusIndex]->recv, sizeof(struct UNIRecv));
} }
REG_IME = r10; REG_IME = imeBak;
return 0; return 0;
} }
@@ -1339,16 +1336,16 @@ u16 rfu_NI_CHILD_setSendGameName(u8 slotNo, u8 subFrameSize)
return rfu_STC_setSendData_org(64, 1 << slotNo, subFrameSize, &gRfuLinkStatus->my.serialNo, 26); return rfu_STC_setSendData_org(64, 1 << slotNo, subFrameSize, &gRfuLinkStatus->my.serialNo, 26);
} }
static u16 rfu_STC_setSendData_org(u8 r6, u8 bmSendSlot, u8 subFrameSize, const void *src, u32 sp28) static u16 rfu_STC_setSendData_org(u8 ni_or_uni, u8 bmSendSlot, u8 subFrameSize, const void *src, u32 dataSize)
{ {
u8 r2, r0; u8 bm_slot_id, sendSlotFlag;
u8 r4; u8 frameSize;
u8 *llFrameSize_p; u8 *llFrameSize_p;
u8 r5; u8 sending;
u8 i; u8 i;
u16 sp04; u16 imeBak;
struct RfuSlotStatusUNI *r1; struct RfuSlotStatusUNI *slotStatus_UNI;
struct RfuSlotStatusNI *r12; struct RfuSlotStatusNI *slotStatus_NI;
if (gRfuLinkStatus->parentChild == MODE_NEUTRAL) if (gRfuLinkStatus->parentChild == MODE_NEUTRAL)
return ERR_MODE_NOT_CONNECTED; return ERR_MODE_NOT_CONNECTED;
@@ -1356,108 +1353,108 @@ static u16 rfu_STC_setSendData_org(u8 r6, u8 bmSendSlot, u8 subFrameSize, const
return ERR_SLOT_NO; return ERR_SLOT_NO;
if (((gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag) & bmSendSlot) != bmSendSlot) if (((gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag) & bmSendSlot) != bmSendSlot)
return ERR_SLOT_NOT_CONNECTED; return ERR_SLOT_NOT_CONNECTED;
if (r6 & 0x10) if (ni_or_uni & 0x10)
r0 = gRfuLinkStatus->sendSlotUNIFlag; sendSlotFlag = gRfuLinkStatus->sendSlotUNIFlag;
else else
r0 = gRfuLinkStatus->sendSlotNIFlag; sendSlotFlag = gRfuLinkStatus->sendSlotNIFlag;
if (r0 & bmSendSlot) if (sendSlotFlag & bmSendSlot)
return ERR_SLOT_BUSY; return ERR_SLOT_BUSY;
for (r2 = 0; r2 < RFU_CHILD_MAX && !((bmSendSlot >> r2) & 1); ++r2) for (bm_slot_id = 0; bm_slot_id < RFU_CHILD_MAX && !((bmSendSlot >> bm_slot_id) & 1); ++bm_slot_id)
; ;
if (gRfuLinkStatus->parentChild == MODE_PARENT) if (gRfuLinkStatus->parentChild == MODE_PARENT)
llFrameSize_p = &gRfuLinkStatus->remainLLFrameSizeParent; llFrameSize_p = &gRfuLinkStatus->remainLLFrameSizeParent;
else if (gRfuLinkStatus->parentChild == MODE_CHILD) else if (gRfuLinkStatus->parentChild == MODE_CHILD)
llFrameSize_p = &gRfuLinkStatus->remainLLFrameSizeChild[r2]; llFrameSize_p = &gRfuLinkStatus->remainLLFrameSizeChild[bm_slot_id];
r4 = llsf_struct[gRfuLinkStatus->parentChild].frameSize; frameSize = llsf_struct[gRfuLinkStatus->parentChild].frameSize;
if (subFrameSize > *llFrameSize_p || subFrameSize <= r4) if (subFrameSize > *llFrameSize_p || subFrameSize <= frameSize)
return ERR_SUBFRAME_SIZE; return ERR_SUBFRAME_SIZE;
sp04 = REG_IME; imeBak = REG_IME;
REG_IME = 0; REG_IME = 0;
r5 = r6 & 0x20; sending = ni_or_uni & 0x20;
if (r5 || r6 == 0x40) if (sending || ni_or_uni == 0x40)
{ {
u8 *r1; // a hack to swap instructions u8 *dataType_p; // a hack to swap instructions
r12 = gRfuSlotStatusNI[r2]; slotStatus_NI = gRfuSlotStatusNI[bm_slot_id];
r1 = NULL; slotStatus_UNI = NULL;
r12->send.errorCode = 0; slotStatus_NI->send.errorCode = 0;
*r12->send.now_p = r1 = &r12->send.dataType; *slotStatus_NI->send.now_p = dataType_p = &slotStatus_NI->send.dataType;
r12->send.remainSize = 7; slotStatus_NI->send.remainSize = 7;
r12->send.bmSlotOrg = bmSendSlot; slotStatus_NI->send.bmSlotOrg = bmSendSlot;
r12->send.bmSlot = bmSendSlot; slotStatus_NI->send.bmSlot = bmSendSlot;
r12->send.payloadSize = subFrameSize - r4; slotStatus_NI->send.payloadSize = subFrameSize - frameSize;
if (r5 != 0) if (sending != 0)
*r1 = 0; *dataType_p = 0;
else else
*r1 = 1; *dataType_p = 1;
r12->send.dataSize = sp28; slotStatus_NI->send.dataSize = dataSize;
r12->send.src = src; slotStatus_NI->send.src = src;
r12->send.ack = 0; slotStatus_NI->send.ack = 0;
r12->send.phase = 0; slotStatus_NI->send.phase = 0;
#ifndef NONMATCHING // to fix r2, r3, r4, r5 register roulette #ifndef NONMATCHING // to fix bm_slot_id, r3, frameSize, sending register roulette
asm("":::"r2"); asm("":::"r2");
#endif #endif
for (i = 0; i < WINDOW_COUNT; ++i) for (i = 0; i < WINDOW_COUNT; ++i)
{ {
r12->send.recvAckFlag[i] = 0; slotStatus_NI->send.recvAckFlag[i] = 0;
r12->send.n[i] = 1; slotStatus_NI->send.n[i] = 1;
} }
for (r2 = 0; r2 < RFU_CHILD_MAX; ++r2) for (bm_slot_id = 0; bm_slot_id < RFU_CHILD_MAX; ++bm_slot_id)
if ((bmSendSlot >> r2) & 1) if ((bmSendSlot >> bm_slot_id) & 1)
gRfuSlotStatusNI[r2]->send.failCounter = 0; gRfuSlotStatusNI[bm_slot_id]->send.failCounter = 0;
gRfuLinkStatus->sendSlotNIFlag |= bmSendSlot; gRfuLinkStatus->sendSlotNIFlag |= bmSendSlot;
*llFrameSize_p -= subFrameSize; *llFrameSize_p -= subFrameSize;
r12->send.state = SLOT_STATE_SEND_START; slotStatus_NI->send.state = SLOT_STATE_SEND_START;
} }
else if (r6 & 0x10) else if (ni_or_uni & 0x10)
{ {
r1 = gRfuSlotStatusUNI[r2]; slotStatus_UNI = gRfuSlotStatusUNI[bm_slot_id];
r1->send.bmSlot = bmSendSlot; slotStatus_UNI->send.bmSlot = bmSendSlot;
r1->send.src = src; slotStatus_UNI->send.src = src;
r1->send.payloadSize = subFrameSize - r4; slotStatus_UNI->send.payloadSize = subFrameSize - frameSize;
*llFrameSize_p -= subFrameSize; *llFrameSize_p -= subFrameSize;
r1->send.state = SLOT_STATE_SEND_UNI; slotStatus_UNI->send.state = SLOT_STATE_SEND_UNI;
gRfuLinkStatus->sendSlotUNIFlag |= bmSendSlot; gRfuLinkStatus->sendSlotUNIFlag |= bmSendSlot;
} }
REG_IME = sp04; REG_IME = imeBak;
return 0; return 0;
} }
u16 rfu_changeSendTarget(u8 connType, u8 slotStatusIndex, u8 bmNewTgtSlot) u16 rfu_changeSendTarget(u8 connType, u8 slotStatusIndex, u8 bmNewTgtSlot)
{ {
struct RfuSlotStatusNI *r5; struct RfuSlotStatusNI *slotStatusNI;
u16 r8; u16 imeBak;
u8 r2; u8 i;
if (slotStatusIndex >= RFU_CHILD_MAX) if (slotStatusIndex >= RFU_CHILD_MAX)
return ERR_SLOT_NO; return ERR_SLOT_NO;
if (connType == 0x20) if (connType == 0x20)
{ {
r5 = gRfuSlotStatusNI[slotStatusIndex]; slotStatusNI = gRfuSlotStatusNI[slotStatusIndex];
if ((r5->send.state & SLOT_BUSY_FLAG) if ((slotStatusNI->send.state & SLOT_BUSY_FLAG)
&& (r5->send.state & SLOT_SEND_FLAG)) && (slotStatusNI->send.state & SLOT_SEND_FLAG))
{ {
connType = bmNewTgtSlot ^ r5->send.bmSlot; connType = bmNewTgtSlot ^ slotStatusNI->send.bmSlot;
if (!(connType & bmNewTgtSlot)) if (!(connType & bmNewTgtSlot))
{ {
if (connType) if (connType)
{ {
r8 = REG_IME; imeBak = REG_IME;
REG_IME = 0; REG_IME = 0;
for (r2 = 0; r2 < RFU_CHILD_MAX; ++r2) for (i = 0; i < RFU_CHILD_MAX; ++i)
{ {
if ((connType >> r2) & 1) if ((connType >> i) & 1)
gRfuSlotStatusNI[r2]->send.failCounter = 0; gRfuSlotStatusNI[i]->send.failCounter = 0;
} }
gRfuLinkStatus->sendSlotNIFlag &= ~connType; gRfuLinkStatus->sendSlotNIFlag &= ~connType;
r5->send.bmSlot = bmNewTgtSlot; slotStatusNI->send.bmSlot = bmNewTgtSlot;
if (r5->send.bmSlot == 0) if (slotStatusNI->send.bmSlot == 0)
{ {
rfu_STC_releaseFrame(slotStatusIndex, 0, &r5->send); rfu_STC_releaseFrame(slotStatusIndex, 0, &slotStatusNI->send);
r5->send.state = SLOT_STATE_SEND_FAILED; slotStatusNI->send.state = SLOT_STATE_SEND_FAILED;
} }
REG_IME = r8; REG_IME = imeBak;
} }
} }
else else
@@ -1474,21 +1471,21 @@ u16 rfu_changeSendTarget(u8 connType, u8 slotStatusIndex, u8 bmNewTgtSlot)
{ {
if (connType == 16) if (connType == 16)
{ {
s32 r3; s32 bmSlot;
if (gRfuSlotStatusUNI[slotStatusIndex]->send.state != SLOT_STATE_SEND_UNI) if (gRfuSlotStatusUNI[slotStatusIndex]->send.state != SLOT_STATE_SEND_UNI)
return ERR_SLOT_NOT_SENDING; return ERR_SLOT_NOT_SENDING;
for (r3 = 0, r2 = 0; r2 < RFU_CHILD_MAX; ++r2) for (bmSlot = 0, i = 0; i < RFU_CHILD_MAX; ++i)
if (r2 != slotStatusIndex) if (i != slotStatusIndex)
r3 |= gRfuSlotStatusUNI[r2]->send.bmSlot; bmSlot |= gRfuSlotStatusUNI[i]->send.bmSlot;
if (bmNewTgtSlot & r3) if (bmNewTgtSlot & bmSlot)
return ERR_SLOT_TARGET; return ERR_SLOT_TARGET;
r8 = REG_IME; imeBak = REG_IME;
REG_IME = 0; REG_IME = 0;
gRfuLinkStatus->sendSlotUNIFlag &= ~gRfuSlotStatusUNI[slotStatusIndex]->send.bmSlot; gRfuLinkStatus->sendSlotUNIFlag &= ~gRfuSlotStatusUNI[slotStatusIndex]->send.bmSlot;
gRfuLinkStatus->sendSlotUNIFlag |= bmNewTgtSlot; gRfuLinkStatus->sendSlotUNIFlag |= bmNewTgtSlot;
gRfuSlotStatusUNI[slotStatusIndex]->send.bmSlot = bmNewTgtSlot; gRfuSlotStatusUNI[slotStatusIndex]->send.bmSlot = bmNewTgtSlot;
REG_IME = r8; REG_IME = imeBak;
} }
else else
{ {
@@ -1500,14 +1497,14 @@ u16 rfu_changeSendTarget(u8 connType, u8 slotStatusIndex, u8 bmNewTgtSlot)
u16 rfu_NI_stopReceivingData(u8 slotStatusIndex) u16 rfu_NI_stopReceivingData(u8 slotStatusIndex)
{ {
struct NIComm *r5; struct NIComm *NI_comm;
u16 r4, r1; u16 imeBak;
if (slotStatusIndex >= RFU_CHILD_MAX) if (slotStatusIndex >= RFU_CHILD_MAX)
return ERR_SLOT_NO; return ERR_SLOT_NO;
r5 = &gRfuSlotStatusNI[slotStatusIndex]->recv; NI_comm = &gRfuSlotStatusNI[slotStatusIndex]->recv;
r4 = REG_IME; imeBak = REG_IME;
++r4; --r4; // fix r4, r5 register swap ++imeBak; --imeBak; // fix imeBak, NI_comm register swap
REG_IME = 0; REG_IME = 0;
if (gRfuSlotStatusNI[slotStatusIndex]->recv.state & SLOT_BUSY_FLAG) if (gRfuSlotStatusNI[slotStatusIndex]->recv.state & SLOT_BUSY_FLAG)
{ {
@@ -1516,43 +1513,43 @@ u16 rfu_NI_stopReceivingData(u8 slotStatusIndex)
else else
gRfuSlotStatusNI[slotStatusIndex]->recv.state = SLOT_STATE_RECV_FAILED; gRfuSlotStatusNI[slotStatusIndex]->recv.state = SLOT_STATE_RECV_FAILED;
gRfuLinkStatus->recvSlotNIFlag &= ~(1 << slotStatusIndex); gRfuLinkStatus->recvSlotNIFlag &= ~(1 << slotStatusIndex);
rfu_STC_releaseFrame(slotStatusIndex, 1, r5); rfu_STC_releaseFrame(slotStatusIndex, 1, NI_comm);
} }
REG_IME = r4; REG_IME = imeBak;
return 0; return 0;
} }
u16 rfu_UNI_changeAndReadySendData(u8 slotStatusIndex, const void *src, u8 size) u16 rfu_UNI_changeAndReadySendData(u8 slotStatusIndex, const void *src, u8 size)
{ {
struct UNISend *r4; struct UNISend *UNI_send;
u8 *r6; u8 *frame_p;
u16 r1; u16 imeBak;
u8 r3_; u8 frameEnd;
if (slotStatusIndex >= RFU_CHILD_MAX) if (slotStatusIndex >= RFU_CHILD_MAX)
return ERR_SLOT_NO; return ERR_SLOT_NO;
r4 = &gRfuSlotStatusUNI[slotStatusIndex]->send; UNI_send = &gRfuSlotStatusUNI[slotStatusIndex]->send;
if (r4->state != SLOT_STATE_SEND_UNI) if (UNI_send->state != SLOT_STATE_SEND_UNI)
return ERR_SLOT_NOT_SENDING; return ERR_SLOT_NOT_SENDING;
if (gRfuLinkStatus->parentChild == MODE_PARENT) if (gRfuLinkStatus->parentChild == MODE_PARENT)
{ {
r6 = &gRfuLinkStatus->remainLLFrameSizeParent; frame_p = &gRfuLinkStatus->remainLLFrameSizeParent;
r3_ = gRfuLinkStatus->remainLLFrameSizeParent + (u8)r4->payloadSize; frameEnd = gRfuLinkStatus->remainLLFrameSizeParent + (u8)UNI_send->payloadSize;
} }
else else
{ {
r6 = &gRfuLinkStatus->remainLLFrameSizeChild[slotStatusIndex]; frame_p = &gRfuLinkStatus->remainLLFrameSizeChild[slotStatusIndex];
r3_ = gRfuLinkStatus->remainLLFrameSizeChild[slotStatusIndex] + (u8)r4->payloadSize; frameEnd = gRfuLinkStatus->remainLLFrameSizeChild[slotStatusIndex] + (u8)UNI_send->payloadSize;
} }
if (r3_ < size) if (frameEnd < size)
return ERR_SUBFRAME_SIZE; return ERR_SUBFRAME_SIZE;
r1 = REG_IME; imeBak = REG_IME;
REG_IME = 0; REG_IME = 0;
r4->src = src; UNI_send->src = src;
*r6 = r3_ - size; *frame_p = frameEnd - size;
r4->payloadSize = size; UNI_send->payloadSize = size;
r4->dataReadyFlag = 1; UNI_send->dataReadyFlag = 1;
REG_IME = r1; REG_IME = imeBak;
return 0; return 0;
} }
@@ -1633,23 +1630,23 @@ void rfu_REQ_sendData(bool8 clockChangeFlag)
static void rfu_CB_sendData(UNUSED u8 reqCommand, u16 reqResult) static void rfu_CB_sendData(UNUSED u8 reqCommand, u16 reqResult)
{ {
u8 r6; u8 i;
struct NIComm *r4; struct NIComm *NI_comm;
if (reqResult == 0) if (reqResult == 0)
{ {
for (r6 = 0; r6 < RFU_CHILD_MAX; ++r6) for (i = 0; i < RFU_CHILD_MAX; ++i)
{ {
if (gRfuSlotStatusUNI[r6]->send.dataReadyFlag) if (gRfuSlotStatusUNI[i]->send.dataReadyFlag)
gRfuSlotStatusUNI[r6]->send.dataReadyFlag = 0; gRfuSlotStatusUNI[i]->send.dataReadyFlag = 0;
r4 = &gRfuSlotStatusNI[r6]->send; NI_comm = &gRfuSlotStatusNI[i]->send;
if (r4->state == SLOT_STATE_SEND_NULL) if (NI_comm->state == SLOT_STATE_SEND_NULL)
{ {
rfu_STC_releaseFrame(r6, 0, r4); rfu_STC_releaseFrame(i, 0, NI_comm);
gRfuLinkStatus->sendSlotNIFlag &= ~r4->bmSlot; gRfuLinkStatus->sendSlotNIFlag &= ~NI_comm->bmSlot;
if (r4->dataType == 1) if (NI_comm->dataType == 1)
gRfuLinkStatus->getNameFlag |= 1 << r6; gRfuLinkStatus->getNameFlag |= 1 << i;
r4->state = SLOT_STATE_SEND_SUCCESS; NI_comm->state = SLOT_STATE_SEND_SUCCESS;
} }
} }
} }
@@ -1672,143 +1669,143 @@ static void rfu_CB_sendData3(u8 reqCommand, u16 reqResult)
static void rfu_constructSendLLFrame(void) static void rfu_constructSendLLFrame(void)
{ {
u32 r8, r5; u32 pakcketSize, currSize;
u8 r6; u8 i;
u8 *sp00; u8 *llf_p;
struct RfuSlotStatusNI *r2; struct RfuSlotStatusNI *slotStatusNI;
if (gRfuLinkStatus->parentChild != MODE_NEUTRAL if (gRfuLinkStatus->parentChild != MODE_NEUTRAL
&& gRfuLinkStatus->sendSlotNIFlag | gRfuLinkStatus->recvSlotNIFlag | gRfuLinkStatus->sendSlotUNIFlag) && gRfuLinkStatus->sendSlotNIFlag | gRfuLinkStatus->recvSlotNIFlag | gRfuLinkStatus->sendSlotUNIFlag)
{ {
gRfuLinkStatus->LLFReadyFlag = 0; gRfuLinkStatus->LLFReadyFlag = 0;
r8 = 0; pakcketSize = 0;
sp00 = (u8 *)&gRfuFixed->LLFBuffer[1]; llf_p = (u8 *)&gRfuFixed->LLFBuffer[1];
for (r6 = 0; r6 < RFU_CHILD_MAX; ++r6) for (i = 0; i < RFU_CHILD_MAX; ++i)
{ {
r5 = 0; currSize = 0;
if (gRfuSlotStatusNI[r6]->send.state & SLOT_BUSY_FLAG) if (gRfuSlotStatusNI[i]->send.state & SLOT_BUSY_FLAG)
r5 = rfu_STC_NI_constructLLSF(r6, &sp00, &gRfuSlotStatusNI[r6]->send); currSize = rfu_STC_NI_constructLLSF(i, &llf_p, &gRfuSlotStatusNI[i]->send);
if (gRfuSlotStatusNI[r6]->recv.state & SLOT_BUSY_FLAG) if (gRfuSlotStatusNI[i]->recv.state & SLOT_BUSY_FLAG)
r5 += rfu_STC_NI_constructLLSF(r6, &sp00, &gRfuSlotStatusNI[r6]->recv); currSize += rfu_STC_NI_constructLLSF(i, &llf_p, &gRfuSlotStatusNI[i]->recv);
if (gRfuSlotStatusUNI[r6]->send.state == SLOT_STATE_SEND_UNI) if (gRfuSlotStatusUNI[i]->send.state == SLOT_STATE_SEND_UNI)
r5 += rfu_STC_UNI_constructLLSF(r6, &sp00); currSize += rfu_STC_UNI_constructLLSF(i, &llf_p);
if (r5 != 0) if (currSize != 0)
{ {
if (gRfuLinkStatus->parentChild == MODE_PARENT) if (gRfuLinkStatus->parentChild == MODE_PARENT)
r8 += r5; pakcketSize += currSize;
else else
r8 |= r5 << (5 * r6 + 8); pakcketSize |= currSize << (5 * i + 8);
} }
} }
if (r8 != 0) if (pakcketSize != 0)
{ {
while ((u32)sp00 & 3) while ((u32)llf_p & 3)
*sp00++ = 0; *llf_p++ = 0;
gRfuFixed->LLFBuffer[0] = r8; gRfuFixed->LLFBuffer[0] = pakcketSize;
if (gRfuLinkStatus->parentChild == MODE_CHILD) if (gRfuLinkStatus->parentChild == MODE_CHILD)
{ {
u8 *r0 = sp00 - offsetof(struct RfuFixed, LLFBuffer[1]); u8 *maxSize = llf_p - offsetof(struct RfuFixed, LLFBuffer[1]);
// Does the volatile qualifier make sense? // Does the volatile qualifier make sense?
// It's the same as: // It's the same as:
// asm("":::"memory"); // asm("":::"memory");
r8 = r0 - *(u8 *volatile *)&gRfuFixed; pakcketSize = maxSize - *(u8 *volatile *)&gRfuFixed;
} }
} }
gRfuStatic->totalPacketSize = r8; gRfuStatic->totalPacketSize = pakcketSize;
} }
} }
static u16 rfu_STC_NI_constructLLSF(u8 r10, u8 **r12, struct NIComm *r4) static u16 rfu_STC_NI_constructLLSF(u8 bm_slot_id, u8 **dest_pp, struct NIComm *NI_comm)
{ {
u16 r5; u16 size;
u32 sp00; u32 frame;
u8 i; u8 i;
u8 *r2; u8 *frame8_p;
const struct LLSFStruct *r8 = &llsf_struct[gRfuLinkStatus->parentChild]; const struct LLSFStruct *llsf = &llsf_struct[gRfuLinkStatus->parentChild];
if (r4->state == SLOT_STATE_SENDING) if (NI_comm->state == SLOT_STATE_SENDING)
{ {
while (r4->now_p[r4->phase] >= (const u8 *)r4->src + r4->dataSize) while (NI_comm->now_p[NI_comm->phase] >= (const u8 *)NI_comm->src + NI_comm->dataSize)
{ {
++r4->phase; ++NI_comm->phase;
if (r4->phase == 4) if (NI_comm->phase == 4)
r4->phase = 0; NI_comm->phase = 0;
} }
} }
if (r4->state & SLOT_RECV_FLAG) if (NI_comm->state & SLOT_RECV_FLAG)
{ {
r5 = 0; size = 0;
} }
else if (r4->state == SLOT_STATE_SENDING) else if (NI_comm->state == SLOT_STATE_SENDING)
{ {
if (r4->now_p[r4->phase] + r4->payloadSize > (const u8 *)r4->src + r4->dataSize) if (NI_comm->now_p[NI_comm->phase] + NI_comm->payloadSize > (const u8 *)NI_comm->src + NI_comm->dataSize)
r5 = (const u8 *)r4->src + r4->dataSize - r4->now_p[r4->phase]; size = (const u8 *)NI_comm->src + NI_comm->dataSize - NI_comm->now_p[NI_comm->phase];
else else
r5 = r4->payloadSize; size = NI_comm->payloadSize;
} }
else else
{ {
if ((u32)r4->remainSize >= r4->payloadSize) if ((u32)NI_comm->remainSize >= NI_comm->payloadSize)
r5 = r4->payloadSize; size = NI_comm->payloadSize;
else else
r5 = r4->remainSize; size = NI_comm->remainSize;
} }
sp00 = (r4->state & 0xF) << r8->slotStateShift frame = (NI_comm->state & 0xF) << llsf->slotStateShift
| r4->ack << r8->ackShift | NI_comm->ack << llsf->ackShift
| r4->phase << r8->phaseShit | NI_comm->phase << llsf->phaseShit
| r4->n[r4->phase] << r8->nShift | NI_comm->n[NI_comm->phase] << llsf->nShift
| r5; | size;
if (gRfuLinkStatus->parentChild == MODE_PARENT) if (gRfuLinkStatus->parentChild == MODE_PARENT)
sp00 |= r4->bmSlot << 18; frame |= NI_comm->bmSlot << 18;
r2 = (u8 *)&sp00; frame8_p = (u8 *)&frame;
for (i = 0; i < r8->frameSize; ++i) for (i = 0; i < llsf->frameSize; ++i)
*(*r12)++ = *r2++; *(*dest_pp)++ = *frame8_p++;
if (r5 != 0) if (size != 0)
{ {
const u8 *sp04 = r4->now_p[r4->phase]; const u8 *src = NI_comm->now_p[NI_comm->phase];
gRfuFixed->fastCopyPtr(&sp04, r12, r5); gRfuFixed->fastCopyPtr(&src, dest_pp, size);
} }
if (r4->state == SLOT_STATE_SENDING) if (NI_comm->state == SLOT_STATE_SENDING)
{ {
++r4->phase; ++NI_comm->phase;
if (r4->phase == 4) if (NI_comm->phase == 4)
r4->phase = 0; NI_comm->phase = 0;
} }
if (gRfuLinkStatus->parentChild == MODE_PARENT) if (gRfuLinkStatus->parentChild == MODE_PARENT)
gRfuLinkStatus->LLFReadyFlag = 1; gRfuLinkStatus->LLFReadyFlag = 1;
else else
gRfuLinkStatus->LLFReadyFlag |= 1 << r10; gRfuLinkStatus->LLFReadyFlag |= 1 << bm_slot_id;
return r5 + r8->frameSize; return size + llsf->frameSize;
} }
static u16 rfu_STC_UNI_constructLLSF(u8 r8, u8 **r6) static u16 rfu_STC_UNI_constructLLSF(u8 bm_slot_id, u8 **dest_p)
{ {
const struct LLSFStruct *r5; const struct LLSFStruct *llsf;
const u8 *sp04; const u8 *src_p;
u32 sp00; u32 frame;
u8 *r2; u8 *frame8_p;
u8 i; u8 i;
struct UNISend *r4 = &gRfuSlotStatusUNI[r8]->send; struct UNISend *UNI_send = &gRfuSlotStatusUNI[bm_slot_id]->send;
if (!r4->dataReadyFlag || !r4->bmSlot) if (!UNI_send->dataReadyFlag || !UNI_send->bmSlot)
return 0; return 0;
r5 = &llsf_struct[gRfuLinkStatus->parentChild]; llsf = &llsf_struct[gRfuLinkStatus->parentChild];
sp00 = (r4->state & 0xF) << r5->slotStateShift frame = (UNI_send->state & 0xF) << llsf->slotStateShift
| r4->payloadSize; | UNI_send->payloadSize;
if (gRfuLinkStatus->parentChild == MODE_PARENT) if (gRfuLinkStatus->parentChild == MODE_PARENT)
sp00 |= r4->bmSlot << 18; frame |= UNI_send->bmSlot << 18;
r2 = (u8 *)&sp00; frame8_p = (u8 *)&frame;
for (i = 0; i < r5->frameSize; ++i) for (i = 0; i < llsf->frameSize; ++i)
*(*r6)++ = *r2++; *(*dest_p)++ = *frame8_p++;
sp04 = r4->src; src_p = UNI_send->src;
gRfuFixed->fastCopyPtr(&sp04, r6, r4->payloadSize); gRfuFixed->fastCopyPtr(&src_p, dest_p, UNI_send->payloadSize);
if (gRfuLinkStatus->parentChild == MODE_PARENT) if (gRfuLinkStatus->parentChild == MODE_PARENT)
gRfuLinkStatus->LLFReadyFlag = 16; gRfuLinkStatus->LLFReadyFlag = 16;
else else
gRfuLinkStatus->LLFReadyFlag |= 16 << r8; gRfuLinkStatus->LLFReadyFlag |= 16 << bm_slot_id;
return r5->frameSize + r4->payloadSize; return llsf->frameSize + UNI_send->payloadSize;
} }
void rfu_REQ_recvData(void) void rfu_REQ_recvData(void)
@@ -1824,9 +1821,9 @@ void rfu_REQ_recvData(void)
static void rfu_CB_recvData(u8 reqCommand, u16 reqResult) static void rfu_CB_recvData(u8 reqCommand, u16 reqResult)
{ {
u8 r6; u8 i;
struct RfuSlotStatusNI *r4; struct RfuSlotStatusNI *slotStatusNI;
struct NIComm *r5; struct NIComm *NI_comm;
if (reqResult == 0 && gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[1]) if (reqResult == 0 && gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[1])
{ {
@@ -1835,17 +1832,17 @@ static void rfu_CB_recvData(u8 reqCommand, u16 reqResult)
rfu_STC_PARENT_analyzeRecvPacket(); rfu_STC_PARENT_analyzeRecvPacket();
else else
rfu_STC_CHILD_analyzeRecvPacket(); rfu_STC_CHILD_analyzeRecvPacket();
for (r6 = 0; r6 < RFU_CHILD_MAX; ++r6) for (i = 0; i < RFU_CHILD_MAX; ++i)
{ {
r4 = gRfuSlotStatusNI[r6]; slotStatusNI = gRfuSlotStatusNI[i];
if (r4->recv.state == SLOT_STATE_RECV_LAST && !((gRfuStatic->NIEndRecvFlag >> r6) & 1)) if (slotStatusNI->recv.state == SLOT_STATE_RECV_LAST && !((gRfuStatic->NIEndRecvFlag >> i) & 1))
{ {
r5 = &r4->recv; NI_comm = &slotStatusNI->recv;
if (r5->dataType == 1) if (NI_comm->dataType == 1)
gRfuLinkStatus->getNameFlag |= 1 << r6; gRfuLinkStatus->getNameFlag |= 1 << i;
rfu_STC_releaseFrame(r6, 1, r5); rfu_STC_releaseFrame(i, 1, NI_comm);
gRfuLinkStatus->recvSlotNIFlag &= ~r5->bmSlot; gRfuLinkStatus->recvSlotNIFlag &= ~NI_comm->bmSlot;
r4->recv.state = SLOT_STATE_RECV_SUCCESS; slotStatusNI->recv.state = SLOT_STATE_RECV_SUCCESS;
} }
} }
if (gRfuStatic->recvErrorFlag) if (gRfuStatic->recvErrorFlag)
@@ -1935,7 +1932,7 @@ static u16 rfu_STC_analyzeLLSF(u8 bm_slot_id, const u8 *src, u16 last_frame)
{ {
if ((gRfuLinkStatus->connSlotFlag >> bm_slot_id) & 1) if ((gRfuLinkStatus->connSlotFlag >> bm_slot_id) & 1)
{ {
if (llsf_NI.slotState == 4) if (llsf_NI.slotState == LCOM_UNI)
{ {
rfu_STC_UNI_receive(bm_slot_id, &llsf_NI, src); rfu_STC_UNI_receive(bm_slot_id, &llsf_NI, src);
} }
@@ -1949,7 +1946,7 @@ static u16 rfu_STC_analyzeLLSF(u8 bm_slot_id, const u8 *src, u16 last_frame)
if (((gRfuSlotStatusNI[i]->send.bmSlot >> bm_slot_id) & 1) if (((gRfuSlotStatusNI[i]->send.bmSlot >> bm_slot_id) & 1)
&& ((gRfuLinkStatus->sendSlotNIFlag >> bm_slot_id) & 1)) && ((gRfuLinkStatus->sendSlotNIFlag >> bm_slot_id) & 1))
break; break;
if (i <= 3) if (i < RFU_CHILD_MAX)
rfu_STC_NI_receive_Sender(i, bm_slot_id, &llsf_NI, src); rfu_STC_NI_receive_Sender(i, bm_slot_id, &llsf_NI, src);
} }
} }
@@ -1964,7 +1961,7 @@ static u16 rfu_STC_analyzeLLSF(u8 bm_slot_id, const u8 *src, u16 last_frame)
{ {
if ((conSlots >> i) & 1) if ((conSlots >> i) & 1)
{ {
if (llsf_NI.slotState == 4) if (llsf_NI.slotState == LCOM_UNI)
rfu_STC_UNI_receive(i, &llsf_NI, src); rfu_STC_UNI_receive(i, &llsf_NI, src);
else if (llsf_NI.ack == 0) else if (llsf_NI.ack == 0)
rfu_STC_NI_receive_Receiver(i, &llsf_NI, src); rfu_STC_NI_receive_Receiver(i, &llsf_NI, src);
@@ -1978,44 +1975,44 @@ static u16 rfu_STC_analyzeLLSF(u8 bm_slot_id, const u8 *src, u16 last_frame)
return retVal; return retVal;
} }
static void rfu_STC_UNI_receive(u8 r7, const struct RfuLocalStruct *r6, const u8 *sp00) static void rfu_STC_UNI_receive(u8 bm_slot_id, const struct RfuLocalStruct *llsf_NI, const u8 *src)
{ {
u8 *sp04; u8 *dest;
u32 r2; u32 size;
struct RfuSlotStatusUNI *r3 = gRfuSlotStatusUNI[r7]; struct RfuSlotStatusUNI *slotStatusUNI = gRfuSlotStatusUNI[bm_slot_id];
struct UNIRecv *r5 = &r3->recv; struct UNIRecv *UNI_recv = &slotStatusUNI->recv;
r5->errorCode = 0; UNI_recv->errorCode = 0;
if (gRfuSlotStatusUNI[r7]->recvBufferSize < r6->unk6) if (gRfuSlotStatusUNI[bm_slot_id]->recvBufferSize < llsf_NI->unk6)
{ {
r3->recv.state = SLOT_STATE_RECV_IGNORE; slotStatusUNI->recv.state = SLOT_STATE_RECV_IGNORE;
r5->errorCode = ERR_RECV_BUFF_OVER; UNI_recv->errorCode = ERR_RECV_BUFF_OVER;
} }
else else
{ {
if (r5->dataBlockFlag) if (UNI_recv->dataBlockFlag)
{ {
if (r5->newDataFlag) if (UNI_recv->newDataFlag)
{ {
r5->errorCode = ERR_RECV_UNK; UNI_recv->errorCode = ERR_RECV_UNK;
goto _081E2F0E; goto _081E2F0E;
} }
} }
else else
{ {
if (r5->newDataFlag) if (UNI_recv->newDataFlag)
r5->errorCode = ERR_RECV_DATA_OVERWRITED; UNI_recv->errorCode = ERR_RECV_DATA_OVERWRITED;
} }
r5->state = SLOT_STATE_RECEIVING; UNI_recv->state = SLOT_STATE_RECEIVING;
r2 = r5->dataSize = r6->unk6; size = UNI_recv->dataSize = llsf_NI->unk6;
sp04 = gRfuSlotStatusUNI[r7]->recvBuffer; dest = gRfuSlotStatusUNI[bm_slot_id]->recvBuffer;
gRfuFixed->fastCopyPtr(&sp00, &sp04, r2); gRfuFixed->fastCopyPtr(&src, &dest, size);
r5->newDataFlag = 1; UNI_recv->newDataFlag = 1;
r5->state = 0; UNI_recv->state = 0;
} }
_081E2F0E: _081E2F0E:
if (r5->errorCode) if (UNI_recv->errorCode)
gRfuStatic->recvErrorFlag |= 16 << r7; gRfuStatic->recvErrorFlag |= 16 << bm_slot_id;
} }
static void rfu_STC_NI_receive_Sender(u8 NI_slot, u8 bm_flag, const struct RfuLocalStruct *llsf_NI, const u8 *data_p) static void rfu_STC_NI_receive_Sender(u8 NI_slot, u8 bm_flag, const struct RfuLocalStruct *llsf_NI, const u8 *data_p)