summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gflib/bg.c8
-rw-r--r--include/librfu.h8
-rw-r--r--src/librfu_rfu.c57
3 files changed, 31 insertions, 42 deletions
diff --git a/gflib/bg.c b/gflib/bg.c
index ab4e8b60d..66dd81a25 100644
--- a/gflib/bg.c
+++ b/gflib/bg.c
@@ -1,3 +1,4 @@
+#include <limits.h>
#include "global.h"
#include "bg.h"
#include "dma3.h"
@@ -1178,20 +1179,19 @@ void CopyTileMapEntry(const u16 *src, u16 *dest, s32 palette1, s32 tileOffset, s
{
u16 var;
- if (palette1 == 16)
- goto CASE_16;
switch (palette1)
{
- case 0 ... 16:
+ case 0 ... 15:
var = ((*src + tileOffset) & 0xFFF) + ((palette1 + palette2) << 12);
break;
- CASE_16:
+ case 16:
var = *dest;
var &= 0xFC00;
var += palette2 << 12;
var |= (*src + tileOffset) & 0x3FF;
break;
default:
+ case 17 ... INT_MAX:
var = *src + tileOffset + (palette2 << 12);
break;
}
diff --git a/include/librfu.h b/include/librfu.h
index 1baa4253e..69c696172 100644
--- a/include/librfu.h
+++ b/include/librfu.h
@@ -90,13 +90,8 @@
#define RFU_MBOOT_DOWNLOADER_SERIAL_NO 0x0000 // The game serial number of the multi-boot downloader (programs that boot without a Game Pak)
-#if LIBRFU_VERSION >= 1028
-#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)
-#else
#define RFU_API_BUFF_SIZE_RAM 0x0e64 // 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 0x0504 // Necessary size for buffer specified by rfu_initializeAPI (fast communication version that operates the library SIO interrupt routines in ROM)
-#endif
#define RFU_CHILD_MAX 4 // Maximum number of slaves that can be connected to one parent device
@@ -376,8 +371,7 @@ struct NIComm
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
+ u32 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)
diff --git a/src/librfu_rfu.c b/src/librfu_rfu.c
index 582060f78..3f5bd8b69 100644
--- a/src/librfu_rfu.c
+++ b/src/librfu_rfu.c
@@ -1,3 +1,4 @@
+#include <limits.h>
#include "librfu.h"
struct LLSFStruct
@@ -110,7 +111,7 @@ static const struct LLSFStruct llsf_struct[2] = {
#define xstr(s) str(s)
#define str(s) #s
-const char version_string[] = "RFU_V" xstr(LIBRFU_VERSION);
+static const char version_string[] = "RFU_V" xstr(LIBRFU_VERSION);
static const char str_checkMbootLL[] = "RFU-MBOOT";
@@ -154,16 +155,13 @@ u16 rfu_initializeAPI(u32 *APIBuffer, u16 buffByteSize, IntrFunc *sioIntrTable_p
gRfuStatic = (void *)APIBuffer + 0xb4; // + sizeof(*gRfuLinkStatus)
gRfuFixed = (void *)APIBuffer + 0xdc; // + sizeof(*gRfuStatic)
gRfuSlotStatusNI[0] = (void *)APIBuffer + 0x1bc; // + sizeof(*gRfuFixed)
- gRfuSlotStatusUNI[0] = (void *)APIBuffer + 0x37c; // + sizeof(*gRfuSlotStatusNI[0])
+ gRfuSlotStatusUNI[0] = (void *)APIBuffer + 0x37c; // + sizeof(*gRfuSlotStatusNI[0]) * RFU_CHILD_MAX
for (i = 1; i < RFU_CHILD_MAX; ++i)
{
gRfuSlotStatusNI[i] = &gRfuSlotStatusNI[i - 1][1];
gRfuSlotStatusUNI[i] = &gRfuSlotStatusUNI[i - 1][1];
}
- // TODO: Is it possible to fix the following 2 statements?
- // It's equivalent to:
- // gRfuFixed->STWIBuffer = &APIBuffer->intr;
- // STWI_init_all(&APIBuffer->intr, sioIntrTable_p, copyInterruptToRam);
+ // remaining space in API buffer is used for `struct RfuIntrStruct`.
gRfuFixed->STWIBuffer = (struct RfuIntrStruct *)&gRfuSlotStatusUNI[3][1];
STWI_init_all((struct RfuIntrStruct *)&gRfuSlotStatusUNI[3][1], sioIntrTable_p, copyInterruptToRam);
rfu_STC_clearAPIVariables();
@@ -1800,7 +1798,7 @@ static u16 rfu_STC_NI_constructLLSF(u8 bm_slot_id, u8 **dest_pp, struct NIComm *
}
else
{
- if ((u32)NI_comm->remainSize >= NI_comm->payloadSize)
+ if (NI_comm->remainSize >= NI_comm->payloadSize)
size = NI_comm->payloadSize;
else
size = NI_comm->remainSize;
@@ -2095,34 +2093,31 @@ static void rfu_STC_NI_receive_Sender(u8 NI_slot, u8 bm_flag, const struct RfuLo
else
NI_comm->now_p[llsf_NI->phase] += NI_comm->payloadSize << 2;
NI_comm->remainSize -= NI_comm->payloadSize;
- if (NI_comm->remainSize != 0)
- if (NI_comm->remainSize >= 0)
- goto _081E30AE;
- // Above is a hack to avoid optimization over comparison.
- // rfu_STC_NI_constructLLSF uses this field as u32.
- // It's equivalent to the following condition:
- // if (NI_comm->remainSize == 0 || NI_comm->remainSize < 0)
+ switch (NI_comm->remainSize)
+ {
+ default:
+ case 0:
+ NI_comm->phase = 0;
+ if (NI_comm->state == SLOT_STATE_SEND_START)
{
- NI_comm->phase = 0;
- if (NI_comm->state == SLOT_STATE_SEND_START)
+ for (i = 0; i < WINDOW_COUNT; ++i)
{
- for (i = 0; i < WINDOW_COUNT; ++i)
- {
- NI_comm->n[i] = 1;
- NI_comm->now_p[i] = NI_comm->src + NI_comm->payloadSize * i;
- }
- NI_comm->remainSize = NI_comm->dataSize;
- NI_comm->state = SLOT_STATE_SENDING;
- }
- else
- {
- NI_comm->n[0] = 0;
- NI_comm->remainSize = 0;
- NI_comm->state = SLOT_STATE_SEND_LAST;
+ NI_comm->n[i] = 1;
+ NI_comm->now_p[i] = NI_comm->src + NI_comm->payloadSize * i;
}
+ NI_comm->remainSize = NI_comm->dataSize;
+ NI_comm->state = SLOT_STATE_SENDING;
}
- _081E30AE:
- ;
+ else
+ {
+ NI_comm->n[0] = 0;
+ NI_comm->remainSize = 0;
+ NI_comm->state = SLOT_STATE_SEND_LAST;
+ }
+ break;
+ case 1 ... INT_MAX:
+ break;
+ }
}
else if (NI_comm->state == SLOT_STATE_SEND_LAST)
{