diff --git a/Makefile b/Makefile index 3e96d07e7..b13f740f3 100644 --- a/Makefile +++ b/Makefile @@ -14,15 +14,16 @@ else $(error unknown version $(GAME_VERSION)) endif endif -REVISION ?= 0 -MAKER_CODE := 01 +MAKER_CODE := 01 +REVISION := 0 +KEEP_TEMPS ?= 0 # `File name`.gba FILE_NAME := poke$(BUILD_NAME) BUILD_DIR := build # Compares the ROM to a checksum of the original - only makes sense using when non-modern -COMPARE ?= 0 +COMPARE ?= 0 # Executes the Test Runner System that checks that all mechanics work as expected TEST ?= 0 # Enables -fanalyzer C flag to analyze in depth potential UBs @@ -333,6 +334,8 @@ include audio_rules.mk # NOTE: Tools must have been built prior (FIXME) # so you can't really call this rule directly generated: $(AUTO_GEN_TARGETS) + @: # Silence the "Nothing to be done for `generated'" message, which some people were confusing for an error. + %.s: ; %.png: ; diff --git a/include/gba/macro.h b/include/gba/macro.h index 9183de36d..6e7dd2b0a 100644 --- a/include/gba/macro.h +++ b/include/gba/macro.h @@ -1,7 +1,7 @@ #ifndef GUARD_GBA_MACRO_H #define GUARD_GBA_MACRO_H -#define CPU_FILL(value, dest, size, bit) \ +#define CPU_FILL_UNCHECKED(value, dest, size, bit) \ { \ vu##bit tmp = (vu##bit)(value); \ CpuSet((void *)&tmp, \ @@ -9,6 +9,17 @@ CPU_SET_##bit##BIT | CPU_SET_SRC_FIXED | ((size)/(bit/8) & 0x1FFFFF)); \ } +#if MODERN +#define CPU_FILL(value, dest, size, bit) \ + do \ + { \ + _Static_assert(_Alignof(dest) >= (bit / 8), "destination potentially unaligned"); \ + CPU_FILL_UNCHECKED(value, dest, size, bit); \ + } while (0) +#else +#define CPU_FILL(value, dest, size, bit) CPU_FILL_UNCHECKED(value, dest, size, bit) +#endif + #define CpuFill16(value, dest, size) CPU_FILL(value, dest, size, 16) #define CpuFill32(value, dest, size) CPU_FILL(value, dest, size, 32) diff --git a/include/global.h b/include/global.h index 961af3199..fb3b9c7fd 100644 --- a/include/global.h +++ b/include/global.h @@ -737,7 +737,7 @@ struct TrainerTower struct TrainerNameRecord { u32 trainerId; - u8 trainerName[PLAYER_NAME_LENGTH + 1]; + u8 ALIGNED(2) trainerName[PLAYER_NAME_LENGTH + 1]; }; // For external event data storage. The majority of these may have never been used. diff --git a/include/librfu.h b/include/librfu.h index 886db0561..6b0bd97c7 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -4,7 +4,7 @@ #include "global.h" #include "main.h" -#define LIBRFU_VERSION 1024 +#define LIBRFU_VERSION 1026 /* TODOs: * - documentation @@ -30,12 +30,12 @@ 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. - - 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, + + 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 @@ -137,7 +137,7 @@ // Definition Data Returned by Return Values for Library Functions // ******************************************************* -// The function doesn't have return value. +// 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 @@ -145,7 +145,7 @@ // #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. +// 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) @@ -329,7 +329,7 @@ struct RfuIntrStruct { union RfuPacket rxPacketAlloc; union RfuPacket txPacketAlloc; - u8 block1[0x960]; // size of librfu_intr.s binary + u8 ALIGNED(2) block1[0x960]; // size of librfu_intr.s binary struct STWIStatus block2; }; @@ -475,7 +475,7 @@ extern struct RfuSlotStatusUNI *gRfuSlotStatusUNI[RFU_CHILD_MAX]; // 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. +// Arguments with "bm..." specify slots of the form (0x01 << slot number) that are the object of a function operation. // librfu_rfu // API Initialization and Initial Settings diff --git a/include/link.h b/include/link.h index 99453bbd6..56bff96e0 100644 --- a/include/link.h +++ b/include/link.h @@ -229,7 +229,7 @@ struct BlockRequest extern const struct BlockRequest sBlockRequestLookupTable[5]; extern struct Link gLink; -extern u16 gRecvCmds[MAX_RFU_PLAYERS][CMD_LENGTH]; +extern u16 ALIGNED(4) gRecvCmds[MAX_RFU_PLAYERS][CMD_LENGTH]; extern u8 gBlockSendBuffer[BLOCK_BUFFER_SIZE]; extern u16 gLinkType; extern u32 gLinkStatus; diff --git a/include/mon_markings.h b/include/mon_markings.h index d52a1d745..b05d15ca2 100644 --- a/include/mon_markings.h +++ b/include/mon_markings.h @@ -18,7 +18,7 @@ struct MonMarkingsMenu /*0x0028*/ struct Sprite *textSprite; /*0x002C*/ const u8 *frameTiles; /*0x0030*/ const u16 *framePalette; - /*0x0034*/ u8 windowSpriteTiles[0x1000]; + /*0x0034*/ u8 ALIGNED(2) windowSpriteTiles[0x1000]; /*0x1034*/ u8 unused[0x80]; /*0x10B4*/ u8 tileLoadState; }; // 10b8 diff --git a/include/palette.h b/include/palette.h index eb40e0512..57131b1e6 100644 --- a/include/palette.h +++ b/include/palette.h @@ -76,8 +76,8 @@ extern const struct BlendSettings gTimeOfDayBlend[]; extern struct PaletteFadeControl gPaletteFade; extern u32 gPlttBufferTransferPending; -extern u16 gPlttBufferUnfaded[PLTT_BUFFER_SIZE]; -extern u16 gPlttBufferFaded[PLTT_BUFFER_SIZE]; +extern u16 ALIGNED(4) gPlttBufferUnfaded[PLTT_BUFFER_SIZE]; +extern u16 ALIGNED(4) gPlttBufferFaded[PLTT_BUFFER_SIZE]; void LoadCompressedPalette(const u32 *src, u32 offset, u32 size); void LoadPalette(const void *src, u32 offset, u32 size); diff --git a/include/pokemon_storage_system_internal.h b/include/pokemon_storage_system_internal.h index 95bc35c1b..188ade14d 100644 --- a/include/pokemon_storage_system_internal.h +++ b/include/pokemon_storage_system_internal.h @@ -435,11 +435,8 @@ struct PokemonStorageSystemData u16 *displayMonTilePtr; struct Sprite *displayMonSprite; u16 displayMonPalBuffer[0x20]; - u8 unusedBuffer1[0x40]; - u8 tileBuffer[0x800]; - u8 unusedBuffer2[0x1800]; - u8 itemIconBuffer[0x200]; - u8 unusedBuffer3[0x600]; + u8 ALIGNED(4) tileBuffer[MON_PIC_SIZE * MAX_MON_PIC_FRAMES]; + u8 ALIGNED(4) itemIconBuffer[0x200]; u8 wallpaperBgTilemapBuffer[0x1000]; u8 menuTilemapBuffer[0x800]; }; diff --git a/src/fieldmap.c b/src/fieldmap.c index d3aa18929..7faae5cdf 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -16,10 +16,10 @@ struct ConnectionFlags }; struct BackupMapLayout VMap; -EWRAM_DATA u16 sBackupMapData[VIRTUAL_MAP_SIZE] = {}; -EWRAM_DATA struct MapHeader gMapHeader = {}; -EWRAM_DATA struct Camera gCamera = {}; -static EWRAM_DATA struct ConnectionFlags gMapConnectionFlags = {}; +EWRAM_DATA u16 ALIGNED(4) sBackupMapData[VIRTUAL_MAP_SIZE] = {0}; +EWRAM_DATA struct MapHeader gMapHeader = {0}; +EWRAM_DATA struct Camera gCamera = {0}; +static EWRAM_DATA struct ConnectionFlags gMapConnectionFlags = {0}; EWRAM_DATA u8 gGlobalFieldTintMode = QL_TINT_NONE; static const struct ConnectionFlags sDummyConnectionFlags = {}; diff --git a/src/librfu_intr.c b/src/librfu_intr.c index c63ef5a94..ab4392e22 100644 --- a/src/librfu_intr.c +++ b/src/librfu_intr.c @@ -1,3 +1,4 @@ +#include "global.h" #include "librfu.h" static void sio32intr_clock_master(void); @@ -164,9 +165,9 @@ static void sio32intr_clock_slave(void) reqLen = (regSIODATA32 >> 16); if (reqLen == (r0 >> 16)) { - // only reqLen = regSIODATA32 >> 8 is required to match, but it looks a bit + // only reqLen = regSIODATA32 >> 8 is needed to match, but it looks a bit // more consistent when both lines update the variables. Might have been a macro? - gSTWIStatus->reqLength = reqLen = regSIODATA32 >> 8; + gSTWIStatus->reqLength = reqLen = (regSIODATA32 >> 8); gSTWIStatus->reqActiveCommand = reqLen = (regSIODATA32 >> 0); if (gSTWIStatus->reqLength == 0) { @@ -335,8 +336,8 @@ static u16 handshake_wait(u16 slot) static void STWI_set_timer_in_RAM(u8 count) { - vu16* regTMCNTL = (vu16*)(REG_ADDR_TMCNT_L + gSTWIStatus->timerSelect * 4); - vu16* regTMCNTH = (vu16*)(REG_ADDR_TMCNT_H + gSTWIStatus->timerSelect * 4); + vu16 *regTMCNTL = ®_TMCNT_L(gSTWIStatus->timerSelect); + vu16 *regTMCNTH = ®_TMCNT_H(gSTWIStatus->timerSelect); REG_IME = 0; switch (count) { diff --git a/src/librfu_rfu.c b/src/librfu_rfu.c index 26e14539e..0097ac349 100644 --- a/src/librfu_rfu.c +++ b/src/librfu_rfu.c @@ -1,6 +1,14 @@ #include #include "librfu.h" +// If expanding the length of the player name and wireless link functionality is +// desired, ensure that the name string is limited in size when it's copied from the +// saveblock to any Rfu-related fields (e.g. in SetHostRfuUsername). +// If wireless link functionality is not desired ignore or delete this warning. +#if RFU_USER_NAME_LENGTH < (PLAYER_NAME_LENGTH + 1) +#warning "The Wireless Adapter hardware expects a username of no more than 8 bytes." +#endif + struct LLSFStruct { u8 frameSize; @@ -8,7 +16,7 @@ struct LLSFStruct u8 connSlotFlagShift; u8 slotStateShift; u8 ackShift; - u8 phaseShit; + u8 phaseShift; u8 nShift; u8 recvFirstMask; u8 connSlotFlagMask; @@ -42,8 +50,8 @@ static void rfu_CB_pollConnectParent(u8 reqCommand, u16 reqResult); static void rfu_CB_pollConnectParent(u8 reqCommand, u16 reqResult); static void rfu_CB_disconnect(u8 reqCommand, u16 reqResult); static void rfu_CB_CHILD_pollConnectRecovery(u8 reqCommand, u16 reqResult); -static void rfu_CB_sendData(u8 reqCommand, u16 reqResult); -static void rfu_CB_sendData2(u8 reqCommand, u16 reqResult); +static void rfu_CB_sendData(UNUSED u8 reqCommand, u16 reqResult); +static void rfu_CB_sendData2(UNUSED u8 reqCommand, u16 reqResult); static void rfu_CB_sendData3(u8 reqCommand, u16 reqResult); static void rfu_CB_recvData(u8 reqCommand, u16 reqResult); static void rfu_enableREQCallback(bool8 enable); @@ -64,15 +72,15 @@ static void rfu_STC_CHILD_analyzeRecvPacket(void); static u16 rfu_STC_analyzeLLSF(u8, const u8 *, u16); static void rfu_STC_UNI_receive(u8, const struct RfuLocalStruct *, const u8 *); static void rfu_STC_NI_receive_Receiver(u8, const struct RfuLocalStruct *, const u8 *); -static void rfu_STC_NI_receive_Sender(u8, u8, const struct RfuLocalStruct *, const u8 *); +static void rfu_STC_NI_receive_Sender(u8, u8, const struct RfuLocalStruct *, UNUSED const u8 *); static void rfu_STC_NI_initSlot_asRecvDataEntity(u8, struct NIComm *); static void rfu_STC_NI_initSlot_asRecvControllData(u8, struct NIComm *); -struct RfuSlotStatusUNI *gRfuSlotStatusUNI[RFU_CHILD_MAX]; -struct RfuSlotStatusNI *gRfuSlotStatusNI[RFU_CHILD_MAX]; -struct RfuLinkStatus *gRfuLinkStatus; -struct RfuStatic *gRfuStatic; -struct RfuFixed *gRfuFixed; +COMMON_DATA struct RfuSlotStatusUNI *gRfuSlotStatusUNI[RFU_CHILD_MAX] = {0}; +COMMON_DATA struct RfuSlotStatusNI *gRfuSlotStatusNI[RFU_CHILD_MAX] = {0}; +COMMON_DATA struct RfuLinkStatus *gRfuLinkStatus = NULL; +COMMON_DATA struct RfuStatic *gRfuStatic = NULL; +COMMON_DATA struct RfuFixed *gRfuFixed = NULL; static const struct LLSFStruct llsf_struct[2] = { [MODE_CHILD] = { @@ -81,7 +89,7 @@ static const struct LLSFStruct llsf_struct[2] = { .connSlotFlagShift = 0, .slotStateShift = 10, .ackShift = 9, - .phaseShit = 5, + .phaseShift = 5, .nShift = 7, .recvFirstMask = 2, .connSlotFlagMask = 0, @@ -97,7 +105,7 @@ static const struct LLSFStruct llsf_struct[2] = { .connSlotFlagShift = 18, .slotStateShift = 14, .ackShift = 13, - .phaseShit = 9, + .phaseShift = 9, .nShift = 11, .recvFirstMask = 3, .connSlotFlagMask = 15, @@ -126,12 +134,10 @@ static const char str_checkMbootLL[] = "RFU-MBOOT"; u16 rfu_initializeAPI(u32 *APIBuffer, u16 buffByteSize, IntrFunc *sioIntrTable_p, bool8 copyInterruptToRam) { u16 i; - u16 *dst; - const u16 *src; u16 buffByteSizeMax; // is in EWRAM? - if (((uintptr_t)APIBuffer & 0xF000000) == 0x2000000 && copyInterruptToRam) + if (((uintptr_t)APIBuffer & 0xF000000) == EWRAM_START && copyInterruptToRam) return ERR_RFU_API_BUFF_ADR; // is not 4-byte aligned? if ((u32)APIBuffer & 3) @@ -161,7 +167,7 @@ u16 rfu_initializeAPI(u32 *APIBuffer, u16 buffByteSize, IntrFunc *sioIntrTable_p gRfuSlotStatusNI[i] = &gRfuSlotStatusNI[i - 1][1]; gRfuSlotStatusUNI[i] = &gRfuSlotStatusUNI[i - 1][1]; } - // remaining space in API buffer is used for `struct RfuIntrStruct`. + // 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(); @@ -174,11 +180,13 @@ u16 rfu_initializeAPI(u32 *APIBuffer, u16 buffByteSize, IntrFunc *sioIntrTable_p } // rfu_REQ_changeMasterSlave is the function next to rfu_STC_fastCopy #if LIBRFU_VERSION < 1026 - src = (const u16 *)((uintptr_t)&rfu_STC_fastCopy & ~1); - dst = gRfuFixed->fastCopyBuffer; +{ + const u16 *src = (const u16 *)((uintptr_t)&rfu_STC_fastCopy & ~1); + u16 *dst = gRfuFixed->fastCopyBuffer; buffByteSizeMax = ((void *)rfu_REQ_changeMasterSlave - (void *)rfu_STC_fastCopy) / sizeof(u16); while (buffByteSizeMax-- != 0) *dst++ = *src++; +} #else COPY( (uintptr_t)&rfu_STC_fastCopy & ~1, @@ -330,7 +338,7 @@ u16 rfu_getRFUStatus(u8 *rfuState) u16 rfu_MBOOT_CHILD_inheritanceLinkStatus(void) { const char *s1 = str_checkMbootLL; - char *s2 = (char *)0x30000F0; + char *s2 = (char *)(IWRAM_START + 0xF0); u16 checksum; u16 *mb_buff_iwram_p; u8 i; @@ -339,15 +347,15 @@ u16 rfu_MBOOT_CHILD_inheritanceLinkStatus(void) while (*s1 != '\0') if (*s1++ != *s2++) return 1; - mb_buff_iwram_p = (u16 *)0x3000000; + mb_buff_iwram_p = (u16 *)IWRAM_START; // The size of struct RfuLinkStatus is 180 checksum = 0; for (i = 0; i < 180/2; ++i) checksum += *mb_buff_iwram_p++; - if (checksum != *(u16 *)0x30000FA) + if (checksum != *(u16 *)(IWRAM_START + 0xFA)) return 1; - CpuCopy16((u16 *)0x3000000, gRfuLinkStatus, sizeof(struct RfuLinkStatus)); + CpuCopy16((u16 *)IWRAM_START, gRfuLinkStatus, sizeof(struct RfuLinkStatus)); gRfuStatic->flags |= 0x80; // mboot return 0; } @@ -488,7 +496,7 @@ static void rfu_CB_configGameData(u8 reqCommand, u16 reqResult) for (i = 0; i < RFU_GAME_NAME_LENGTH; ++i) gRfuLinkStatus->my.gname[i] = *gname_uname_p++; ++gname_uname_p; - for (i = 0; i < RFU_USER_NAME_LENGTH; ++i) + for (i = 0; i < PLAYER_NAME_LENGTH + 1; ++i) gRfuLinkStatus->my.uname[i] = *gname_uname_p++; } rfu_STC_REQ_callback(reqCommand, reqResult); @@ -583,19 +591,17 @@ static void rfu_CB_pollAndEndSearchChild(u8 reqCommand, u16 reqResult) static void rfu_STC_readChildList(void) { - u32 stwiParam; u8 numSlots = gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket8.data[1]; u8 *data_p; - u8 i; u8 bm_slot_id; -#if LIBRFU_VERSION < 1026 - u8 true_slots[RFU_CHILD_MAX]; -#endif #if LIBRFU_VERSION < 1026 + u8 true_slots[RFU_CHILD_MAX]; + if (numSlots != 0) { - stwiParam = gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket32.data[0]; + u8 i; + u32 stwiParam = gRfuFixed->STWIBuffer->rxPacketAlloc.rfuPacket32.data[0]; STWI_set_Callback_M(rfu_CB_defaultCallback); STWI_send_LinkStatusREQ(); if (STWI_poll_CommandEnd() == 0) @@ -718,7 +724,7 @@ static void rfu_STC_readParentCandidateList(void) for (j = 0; j < RFU_GAME_NAME_LENGTH; ++j) target->gname[j] = *packet_p++; ++packet_p; - for (j = 0; j < RFU_USER_NAME_LENGTH; ++j) + for (j = 0; j < PLAYER_NAME_LENGTH + 1; ++j) target->uname[j] = *packet_p++; ++gRfuLinkStatus->findParentCount; } @@ -1445,6 +1451,7 @@ static u16 rfu_STC_setSendData_org(u8 ni_or_uni, u8 bmSendSlot, u8 subFrameSize, slotStatus_NI->send.dataType = 0; else slotStatus_NI->send.dataType = 1; + slotStatus_NI->send.dataSize = dataSize; slotStatus_NI->send.src = src; slotStatus_NI->send.ack = 0; @@ -1563,21 +1570,20 @@ u16 rfu_changeSendTarget(u8 connType, u8 slotStatusIndex, u8 bmNewTgtSlot) u16 rfu_NI_stopReceivingData(u8 slotStatusIndex) { - struct NIComm *NI_comm; u16 imeBak; + struct NIComm *NI_comm; if (slotStatusIndex >= RFU_CHILD_MAX) return ERR_SLOT_NO; NI_comm = &gRfuSlotStatusNI[slotStatusIndex]->recv; imeBak = REG_IME; - ++imeBak; --imeBak; // fix imeBak, NI_comm register swap REG_IME = 0; - if (gRfuSlotStatusNI[slotStatusIndex]->recv.state & SLOT_BUSY_FLAG) + if (NI_comm->state & SLOT_BUSY_FLAG) { - if (gRfuSlotStatusNI[slotStatusIndex]->recv.state == SLOT_STATE_RECV_LAST) - gRfuSlotStatusNI[slotStatusIndex]->recv.state = SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN; + if (NI_comm->state == SLOT_STATE_RECV_LAST) + NI_comm->state = SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN; else - gRfuSlotStatusNI[slotStatusIndex]->recv.state = SLOT_STATE_RECV_FAILED; + NI_comm->state = SLOT_STATE_RECV_FAILED; gRfuLinkStatus->recvSlotNIFlag &= ~(1 << slotStatusIndex); rfu_STC_releaseFrame(slotStatusIndex, 1, NI_comm); } @@ -1694,7 +1700,7 @@ void rfu_REQ_sendData(bool8 clockChangeFlag) } } -static void rfu_CB_sendData(u8 reqCommand, u16 reqResult) +static void rfu_CB_sendData(UNUSED u8 reqCommand, u16 reqResult) { u8 i; struct NIComm *NI_comm; @@ -1720,7 +1726,7 @@ static void rfu_CB_sendData(u8 reqCommand, u16 reqResult) rfu_STC_REQ_callback(ID_DATA_TX_REQ, reqResult); } -static void rfu_CB_sendData2(u8 reqCommand, u16 reqResult) +static void rfu_CB_sendData2(UNUSED u8 reqCommand, u16 reqResult) { rfu_STC_REQ_callback(ID_DATA_TX_REQ, reqResult); } @@ -1815,7 +1821,7 @@ static u16 rfu_STC_NI_constructLLSF(u8 bm_slot_id, u8 **dest_pp, struct NIComm * } frame = (NI_comm->state & 0xF) << llsf->slotStateShift | NI_comm->ack << llsf->ackShift - | NI_comm->phase << llsf->phaseShit + | NI_comm->phase << llsf->phaseShift | NI_comm->n[NI_comm->phase] << llsf->nShift | size; if (gRfuLinkStatus->parentChild == MODE_PARENT) @@ -1984,7 +1990,7 @@ static u16 rfu_STC_analyzeLLSF(u8 slot_id, const u8 *src, u16 last_frame) llsf_NI.connSlotFlag = (frames >> llsf_p->connSlotFlagShift) & llsf_p->connSlotFlagMask; llsf_NI.slotState = (frames >> llsf_p->slotStateShift) & llsf_p->slotStateMask; llsf_NI.ack = (frames >> llsf_p->ackShift) & llsf_p->ackMask; - llsf_NI.phase = (frames >> llsf_p->phaseShit) & llsf_p->phaseMask; + llsf_NI.phase = (frames >> llsf_p->phaseShift) & llsf_p->phaseMask; llsf_NI.n = (frames >> llsf_p->nShift) & llsf_p->nMask; llsf_NI.frame = (frames & llsf_p->framesMask) & frames; retVal = llsf_NI.frame + llsf_p->frameSize; diff --git a/src/librfu_sio32id.c b/src/librfu_sio32id.c index 1c02840e8..45b1bc33d 100644 --- a/src/librfu_sio32id.c +++ b/src/librfu_sio32id.c @@ -15,7 +15,7 @@ struct RfuSIO32Id u16 lastId; }; -struct RfuSIO32Id gRfuSIO32Id; +COMMON_DATA struct RfuSIO32Id gRfuSIO32Id = {0}; static const u16 Sio32ConnectionData[] = { 0x494e, 0x544e, 0x4e45, 0x4f44 }; // NINTENDO static const char Sio32IDLib_Var[] = "Sio32ID_030820"; @@ -24,7 +24,7 @@ s32 AgbRFU_checkID(u8 maxTries) { u16 ieBak; vu16 *regTMCNTL; - s32 id; + s32 id = 0; // Interrupts must be enabled if (REG_IME == 0) @@ -145,7 +145,9 @@ static void Sio32IDIntr(void) } } else + { gRfuSIO32Id.lastId = regSIODATA32; + } } else { diff --git a/src/librfu_stwi.c b/src/librfu_stwi.c index fb90cb452..13a7e3408 100644 --- a/src/librfu_stwi.c +++ b/src/librfu_stwi.c @@ -8,7 +8,7 @@ static void STWI_stop_timer(void); static s32 STWI_restart_Command(void); static s32 STWI_reset_ClockCounter(void); -struct STWIStatus *gSTWIStatus; +COMMON_DATA struct STWIStatus *gSTWIStatus = NULL; void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam) { @@ -40,7 +40,7 @@ void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, b gSTWIStatus->error = 0; gSTWIStatus->recoveryCount = 0; gSTWIStatus->sending = 0; - REG_RCNT = 0x100; // TODO: mystery bit? + REG_RCNT = 0x100; // TODO: mystery bit? REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; STWI_init_Callback_M(); STWI_init_Callback_S(); @@ -594,7 +594,7 @@ static s32 STWI_start_Command(void) { u16 imeTemp; - // equivalent to gSTWIStatus->txPacket->rfuPacket32.command, + // equivalent to gSTWIStatus->txPacket->rfuPacket32.command, // but the cast here is required to avoid register issue *(u32 *)gSTWIStatus->txPacket->rfuPacket8.data = 0x99660000 | (gSTWIStatus->reqLength << 8) | gSTWIStatus->reqActiveCommand; REG_SIODATA32 = gSTWIStatus->txPacket->rfuPacket32.command; diff --git a/src/link.c b/src/link.c index e7da69d66..28dc60545 100644 --- a/src/link.c +++ b/src/link.c @@ -61,41 +61,41 @@ static u16 sRecvNonzeroCheck; static u8 sChecksumAvailable; static u8 sHandshakePlayerCount; -u16 gLinkPartnersHeldKeys[6]; -u32 gLinkDebugSeed; -struct LinkPlayerBlock gLocalLinkPlayerBlock; -bool8 gLinkErrorOccurred; -u32 gLinkDebugFlags; -u32 gLinkFiller1; -bool8 gRemoteLinkPlayersNotReceived[MAX_LINK_PLAYERS]; -u8 gBlockReceivedStatus[MAX_LINK_PLAYERS]; -u32 gLinkFiller2; -u16 gLinkHeldKeys; -u16 gRecvCmds[MAX_RFU_PLAYERS][CMD_LENGTH]; -u32 gLinkStatus; -bool8 gLinkDummy1; // Never read -bool8 gLinkDummy2; // Never read -bool8 gReadyToExitStandby[MAX_LINK_PLAYERS]; -bool8 gReadyToCloseLink[MAX_LINK_PLAYERS]; -u16 gReadyCloseLinkType; -u8 gSuppressLinkErrorMessage; -u8 gWirelessCommType; -u8 gSavedLinkPlayerCount; -u16 gSendCmd[CMD_LENGTH]; -u8 gSavedMultiplayerId; -bool8 gReceivedRemoteLinkPlayers; -struct LinkTestBGInfo gLinkTestBGInfo; -void (*gLinkCallback)(void); -u8 gShouldAdvanceLinkState; -u16 gLinkTestBlockChecksums[MAX_LINK_PLAYERS]; -u8 gBlockRequestType; -u32 gLinkFiller3; // file -u32 gLinkFiller4; // boundary -u32 gLinkFiller5; // here? -u8 gLastSendQueueCount; -struct Link gLink; -u8 gLastRecvQueueCount; -u16 gLinkSavedIme; +COMMON_DATA u16 gLinkPartnersHeldKeys[6]; +COMMON_DATA u32 gLinkDebugSeed; +COMMON_DATA struct LinkPlayerBlock gLocalLinkPlayerBlock; +COMMON_DATA bool8 gLinkErrorOccurred; +COMMON_DATA u32 gLinkDebugFlags; +COMMON_DATA u32 gLinkFiller1; +COMMON_DATA bool8 gRemoteLinkPlayersNotReceived[MAX_LINK_PLAYERS]; +COMMON_DATA u8 gBlockReceivedStatus[MAX_LINK_PLAYERS]; +COMMON_DATA u32 gLinkFiller2; +COMMON_DATA u16 gLinkHeldKeys; +COMMON_DATA u16 ALIGNED(4) gRecvCmds[MAX_RFU_PLAYERS][CMD_LENGTH] = {0}; +COMMON_DATA u32 gLinkStatus; +COMMON_DATA bool8 gLinkDummy1; // Never read +COMMON_DATA bool8 gLinkDummy2; // Never read +COMMON_DATA bool8 gReadyToExitStandby[MAX_LINK_PLAYERS]; +COMMON_DATA bool8 gReadyToCloseLink[MAX_LINK_PLAYERS]; +COMMON_DATA u16 gReadyCloseLinkType; +COMMON_DATA u8 gSuppressLinkErrorMessage; +COMMON_DATA u8 gWirelessCommType; +COMMON_DATA u8 gSavedLinkPlayerCount; +COMMON_DATA u16 gSendCmd[CMD_LENGTH]; +COMMON_DATA u8 gSavedMultiplayerId; +COMMON_DATA bool8 gReceivedRemoteLinkPlayers; +COMMON_DATA struct LinkTestBGInfo gLinkTestBGInfo; +COMMON_DATA void (*gLinkCallback)(void); +COMMON_DATA u8 gShouldAdvanceLinkState; +COMMON_DATA u16 gLinkTestBlockChecksums[MAX_LINK_PLAYERS]; +COMMON_DATA u8 gBlockRequestType; +COMMON_DATA u32 gLinkFiller3; // file +COMMON_DATA u32 gLinkFiller4; // boundary +COMMON_DATA u32 gLinkFiller5; // here? +COMMON_DATA u8 gLastSendQueueCount; +COMMON_DATA struct Link gLink; +COMMON_DATA u8 gLastRecvQueueCount; +COMMON_DATA u16 gLinkSavedIme; EWRAM_DATA u32 gBerryBlenderKeySendAttempts = 0; EWRAM_DATA u16 gBlockRecvBuffer[MAX_RFU_PLAYERS][BLOCK_BUFFER_SIZE / 2] = {}; diff --git a/src/util.c b/src/util.c index b32799584..71e92b92c 100644 --- a/src/util.c +++ b/src/util.c @@ -154,7 +154,7 @@ void CopySpriteTiles(u8 shape, u8 size, u8 *tiles, u16 *tilemap, u8 *output) { u8 x, y; s8 i, j; - u8 xflip[32]; + u8 ALIGNED(4) xflip[32]; u8 h = sSpriteDimensions[shape][size][1]; u8 w = sSpriteDimensions[shape][size][0];