From f1216076d7cb6a383682f423c9b5c14e152e484b Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Thu, 7 Sep 2017 00:51:59 -0600 Subject: Begin librfu decompilation --- src/librfu.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 src/librfu.c (limited to 'src') diff --git a/src/librfu.c b/src/librfu.c new file mode 100644 index 000000000..2cf5d6dad --- /dev/null +++ b/src/librfu.c @@ -0,0 +1,217 @@ +#include "global.h" + +#include "main.h" + +typedef struct RfuStruct +{ + s32 unk_0; + u8 unk_4; + u8 unk_5; + u8 unk_6; + u8 unk_7; + u8 unk_8; + u8 unk_9; + u8 timerSelect; + u8 unk_b; + u32 unk_c; + vu8 unk_10; + u8 unk_11; + vu16 unk_12; + vu8 msMode; + u8 unk_15; + u8 unk_16; + u8 unk_17; + void * callbackM; + void * callbackS; + u32 callbackID; + void * unk_24; + void * unk_28; + vu8 unk_2c; + u8 padding[3]; +} RfuStruct; + +typedef struct RfuIntrStruct +{ + u8 unk28Data[0x74]; + u8 unk24Data[0x74]; + u8 block1[0x960]; + u8 block2[0x30]; +} RfuIntrStruct; + +typedef struct RfuState +{ + RfuStruct *rfuStruct; +} RfuState; + +extern IntrFunc IntrSIO32(); +extern struct RfuState gRfuState; +void STWI_init_Callback_M(); +void STWI_init_Callback_S(); +void STWI_set_Callback_M(void * callback); +void STWI_set_Callback_S(void * callback); +extern void STWI_intr_timer(); + +void STWI_init_all(RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam) +{ + struct RfuStruct *rfuStructTemp; + struct RfuStruct **rfuStructPtr; + u16 ime_temp; + int ret; + + // If we're copying our interrupt into RAM, DMA it to block1 and use + // block2 for our RfuStruct, otherwise block1 holds the RfuStruct. + // interrupt usually is a pointer to gIntrTable[1] + if (copyInterruptToRam == TRUE) + { + *interrupt = (IntrFunc)(&interruptStruct->block1); + DmaCopy16(3, &IntrSIO32, (void*)(&interruptStruct->block1), 0x960); + + gRfuState.rfuStruct = (struct RfuStruct*)(&interruptStruct->block2); + } + else + { + *interrupt = (IntrFunc)&IntrSIO32; + gRfuState.rfuStruct = (struct RfuStruct*)(&interruptStruct->block1); + } + + rfuStructPtr = (struct RfuStruct**)&gRfuState.rfuStruct; + (*rfuStructPtr)->unk_28 = (void*)&interruptStruct->unk28Data; + (*rfuStructPtr)->unk_24 = (void*)(&interruptStruct->unk24Data); + (*rfuStructPtr)->msMode = 1; + + (*rfuStructPtr)->unk_0 = 0; + (*rfuStructPtr)->unk_4 = 0; + (*rfuStructPtr)->unk_5 = 0; + (*rfuStructPtr)->unk_7 = 0; + (*rfuStructPtr)->unk_8 = 0; + (*rfuStructPtr)->unk_9 = 0; + (*rfuStructPtr)->unk_c = 0; + (*rfuStructPtr)->unk_10 = 0; + + // Don't @ me + rfuStructTemp = *rfuStructPtr; + rfuStructTemp->unk_12 = 0; + rfuStructTemp->unk_15 = 0; + + (*rfuStructPtr)->unk_2c = 0; + + 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(); + + IntrEnable(INTR_FLAG_SERIAL); +} + +void STWI_init_timer(IntrFunc *interrupt, int timerSelect) +{ + *interrupt = &STWI_intr_timer; + gRfuState.rfuStruct->timerSelect = timerSelect; + + IntrEnable(INTR_FLAG_TIMER0 << gRfuState.rfuStruct->timerSelect); +} + +void AgbRFU_SoftReset() +{ + struct RfuStruct **rfuStructPtr; + struct RfuStruct *rfuStructTemp; + + REG_RCNT = 0x8000; + REG_RCNT = 0x80A0; // all these bits are undocumented + + { + vu16 *timerL = ®_TMCNT_L(gRfuState.rfuStruct->timerSelect); + vu16 *timerH = ®_TMCNT_H(gRfuState.rfuStruct->timerSelect); + + *timerH = 0; + *timerL = 0; + *timerH = 0x83; + + while (*timerL <= 0x11) + { + REG_RCNT = 0x80A2; + } + + *timerH = 3; + } + REG_RCNT = 0x80A0; + REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; + + rfuStructPtr = (struct RfuStruct**)&gRfuState.rfuStruct; + + (*rfuStructPtr)->unk_0 = 0; + (*rfuStructPtr)->unk_4 = 0; + (*rfuStructPtr)->unk_5 = 0; + (*rfuStructPtr)->unk_6 = 0; + (*rfuStructPtr)->unk_7 = 0; + (*rfuStructPtr)->unk_8 = 0; + (*rfuStructPtr)->unk_9 = 0; + (*rfuStructPtr)->unk_c = 0; + (*rfuStructPtr)->unk_10 = 0; + + // Yeah this is the second time, there's probably something in the struct that I'm missing + rfuStructTemp = *rfuStructPtr; + rfuStructTemp->unk_12 = 0; + rfuStructTemp->msMode = 1; + (*rfuStructPtr)->unk_15 = 0; + + (*rfuStructPtr)->unk_2c = 0; +} + +void STWI_set_MS_mode(u8 mode) +{ + gRfuState.rfuStruct->msMode = mode; +} + +u32 STWI_read_status(u8 index) +{ + int result; + switch(index) + { + case 0: + return gRfuState.rfuStruct->unk_12; + case 1: + return gRfuState.rfuStruct->msMode; + case 2: + // something got inlined here? + //TODO: figure this one out + result = (gRfuState.rfuStruct->unk_0); + __asm__("lsl r0, r0, #16"); + __asm__("lsr r0, r0, #16"); + break; + + case 3: + return gRfuState.rfuStruct->unk_6; + break; + default: + return 0xFFFF; + break; + } + return result; +} + +void STWI_init_Callback_M() +{ + STWI_set_Callback_M(0); +} + +void STWI_init_Callback_S() +{ + STWI_set_Callback_S(0); +} + +void STWI_set_Callback_M(void * callback) +{ + gRfuState.rfuStruct->callbackM = callback; +} + +void STWI_set_Callback_S(void * callback) +{ + gRfuState.rfuStruct->callbackS = callback; +} + +void STWI_set_Callback_ID(u32 id) +{ + gRfuState.rfuStruct->callbackID = id; +} + -- cgit v1.2.3 From b420fb39624e10b364e17b593b1bf0d6e347a3ae Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Thu, 7 Sep 2017 03:59:39 -0600 Subject: Decompiled librfu to STWI_send_CP_EndREQ --- src/librfu.c | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 228 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/librfu.c b/src/librfu.c index 2cf5d6dad..1b9846ece 100644 --- a/src/librfu.c +++ b/src/librfu.c @@ -2,6 +2,28 @@ #include "main.h" +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 +}; + typedef struct RfuStruct { s32 unk_0; @@ -24,7 +46,7 @@ typedef struct RfuStruct void * callbackM; void * callbackS; u32 callbackID; - void * unk_24; + u8 * unk_24; void * unk_28; vu8 unk_2c; u8 padding[3]; @@ -49,6 +71,8 @@ void STWI_init_Callback_M(); void STWI_init_Callback_S(); void STWI_set_Callback_M(void * callback); void STWI_set_Callback_S(void * callback); +u16 STWI_init(u8 request); +int STWI_start_Command(); extern void STWI_intr_timer(); void STWI_init_all(RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam) @@ -76,7 +100,7 @@ void STWI_init_all(RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 co rfuStructPtr = (struct RfuStruct**)&gRfuState.rfuStruct; (*rfuStructPtr)->unk_28 = (void*)&interruptStruct->unk28Data; - (*rfuStructPtr)->unk_24 = (void*)(&interruptStruct->unk24Data); + (*rfuStructPtr)->unk_24 = (u8*)(&interruptStruct->unk24Data); (*rfuStructPtr)->msMode = 1; (*rfuStructPtr)->unk_0 = 0; @@ -215,3 +239,205 @@ void STWI_set_Callback_ID(u32 id) gRfuState.rfuStruct->callbackID = id; } +u16 STWI_poll_CommandEnd() +{ + while ( gRfuState.rfuStruct->unk_2c == TRUE ); + + return gRfuState.rfuStruct->unk_12; +} + +void STWI_send_ResetREQ() +{ + if (!STWI_init(RFU_RESET)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + +void STWI_send_LinkStatusREQ() +{ + if (!STWI_init(RFU_LINK_STATUS)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + +void STWI_send_VersionStatusREQ() +{ + if (!STWI_init(RFU_VERSION_STATUS)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + +void STWI_send_SystemStatusREQ() +{ + if (!STWI_init(RFU_SYSTEM_STATUS)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + +void STWI_send_SlotStatusREQ() +{ + if (!STWI_init(RFU_SLOT_STATUS)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + +void STWI_send_ConfigStatusREQ() +{ + if (!STWI_init(RFU_CONFIG_STATUS)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + +void STWI_send_GameConfigREQ(u8 * unk1, u8 *data) +{ + u8 *v5; + int i; + + if (!STWI_init(RFU_GAME_CONFIG)) + { + gRfuState.rfuStruct->unk_4 = 6; //TODO: what is 6 + + //TODO: kinda gross but idk what's going on here + v5 = (u8*)gRfuState.rfuStruct->unk_24; + v5 += 4; + *(u16*)v5 = *(u16*)unk1; + + v5 += 2; + unk1 += 2; + i = 13; + do + { + *v5 = *unk1; + v5++; + unk1++; + i--; + } + while(i >= 0); + + i = 7; + do + { + *v5 = *data; + v5++; + data++; + i--; + } + while(i >= 0); + + STWI_start_Command(); + } +} + +void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3) +{ + u8 *v5; + + if (!STWI_init(RFU_SYSTEM_CONFIG)) + { + gRfuState.rfuStruct->unk_4 = 1; //TODO: what is 1 + + //TODO: kinda weird but idk what's going on here + v5 = (u8*)gRfuState.rfuStruct->unk_24; + v5 += 4; + + *v5++ = unk3; + *v5++ = unk2; + *(u16*)v5 = unk1; + STWI_start_Command(); + } +} + +void STWI_send_SC_StartREQ() +{ + if (!STWI_init(RFU_SC_START)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + +void STWI_send_SC_PollingREQ() +{ + if (!STWI_init(RFU_SC_POLLING)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + +void STWI_send_SC_EndREQ() +{ + if (!STWI_init(RFU_SC_END)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + +void STWI_send_SP_StartREQ() +{ + if (!STWI_init(RFU_SP_START)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + +void STWI_send_SP_PollingREQ() +{ + if (!STWI_init(RFU_SP_POLLING)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + +void STWI_send_SP_EndREQ() +{ + if (!STWI_init(RFU_SP_END)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + +void STWI_send_CP_StartREQ(u16 unk1) +{ + if (!STWI_init(RFU_CP_START)) + { + gRfuState.rfuStruct->unk_4 = 1; + *(u32*)(gRfuState.rfuStruct->unk_24 + 4) = unk1; + STWI_start_Command(); + } +} + +void STWI_send_CP_PollingREQ() +{ + if (!STWI_init(RFU_CP_POLLING)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + +void STWI_send_CP_EndREQ() +{ + if (!STWI_init(RFU_CP_END)) + { + gRfuState.rfuStruct->unk_4 = 0; + STWI_start_Command(); + } +} + -- cgit v1.2.3 From f4a21e5789eac049f6b9788123448b77fa9d7c06 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Sun, 10 Sep 2017 12:04:48 -0600 Subject: Cleanup and formatting fixes from camthesaxman --- src/librfu.c | 632 +++++++++++++++++++++++++++-------------------------------- 1 file changed, 292 insertions(+), 340 deletions(-) (limited to 'src') diff --git a/src/librfu.c b/src/librfu.c index 1b9846ece..8e450caa0 100644 --- a/src/librfu.c +++ b/src/librfu.c @@ -1,443 +1,395 @@ #include "global.h" - #include "main.h" 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_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 }; -typedef struct RfuStruct -{ - s32 unk_0; - u8 unk_4; - u8 unk_5; - u8 unk_6; - u8 unk_7; - u8 unk_8; - u8 unk_9; - u8 timerSelect; - u8 unk_b; - u32 unk_c; - vu8 unk_10; - u8 unk_11; - vu16 unk_12; - vu8 msMode; - u8 unk_15; - u8 unk_16; - u8 unk_17; - void * callbackM; - void * callbackS; - u32 callbackID; - u8 * unk_24; - void * unk_28; - vu8 unk_2c; - u8 padding[3]; -} RfuStruct; - -typedef struct RfuIntrStruct -{ - u8 unk28Data[0x74]; - u8 unk24Data[0x74]; - u8 block1[0x960]; - u8 block2[0x30]; -} RfuIntrStruct; +struct RfuStruct +{ + vs32 unk_0; + u8 unk_4; + u8 unk_5; + u8 unk_6; + u8 unk_7; + u8 unk_8; + u8 unk_9; + u8 timerSelect; + u8 unk_b; + u32 unk_c; + vu8 unk_10; + u8 unk_11; + vu16 unk_12; + vu8 msMode; + u8 unk_15; + u8 unk_16; + u8 unk_17; + void *callbackM; + void *callbackS; + u32 callbackID; + u8 *unk_24; + void *unk_28; + vu8 unk_2c; + u8 padding[3]; +}; -typedef struct RfuState +struct RfuIntrStruct { - RfuStruct *rfuStruct; -} RfuState; + u8 unk28Data[0x74]; + u8 unk24Data[0x74]; + u8 block1[0x960]; + u8 block2[0x30]; +}; -extern IntrFunc IntrSIO32(); -extern struct RfuState gRfuState; -void STWI_init_Callback_M(); -void STWI_init_Callback_S(); +extern IntrFunc IntrSIO32(void); +extern struct RfuStruct *gRfuState; +void STWI_init_Callback_M(void); +void STWI_init_Callback_S(void); void STWI_set_Callback_M(void * callback); void STWI_set_Callback_S(void * callback); u16 STWI_init(u8 request); -int STWI_start_Command(); -extern void STWI_intr_timer(); - -void STWI_init_all(RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam) -{ - struct RfuStruct *rfuStructTemp; - struct RfuStruct **rfuStructPtr; - u16 ime_temp; - int ret; - - // If we're copying our interrupt into RAM, DMA it to block1 and use - // block2 for our RfuStruct, otherwise block1 holds the RfuStruct. - // interrupt usually is a pointer to gIntrTable[1] - if (copyInterruptToRam == TRUE) - { - *interrupt = (IntrFunc)(&interruptStruct->block1); - DmaCopy16(3, &IntrSIO32, (void*)(&interruptStruct->block1), 0x960); - - gRfuState.rfuStruct = (struct RfuStruct*)(&interruptStruct->block2); - } - else - { - *interrupt = (IntrFunc)&IntrSIO32; - gRfuState.rfuStruct = (struct RfuStruct*)(&interruptStruct->block1); - } - - rfuStructPtr = (struct RfuStruct**)&gRfuState.rfuStruct; - (*rfuStructPtr)->unk_28 = (void*)&interruptStruct->unk28Data; - (*rfuStructPtr)->unk_24 = (u8*)(&interruptStruct->unk24Data); - (*rfuStructPtr)->msMode = 1; - - (*rfuStructPtr)->unk_0 = 0; - (*rfuStructPtr)->unk_4 = 0; - (*rfuStructPtr)->unk_5 = 0; - (*rfuStructPtr)->unk_7 = 0; - (*rfuStructPtr)->unk_8 = 0; - (*rfuStructPtr)->unk_9 = 0; - (*rfuStructPtr)->unk_c = 0; - (*rfuStructPtr)->unk_10 = 0; - - // Don't @ me - rfuStructTemp = *rfuStructPtr; - rfuStructTemp->unk_12 = 0; - rfuStructTemp->unk_15 = 0; - - (*rfuStructPtr)->unk_2c = 0; - - 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(); - - IntrEnable(INTR_FLAG_SERIAL); +int STWI_start_Command(void); +extern void STWI_intr_timer(void); + +void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam) +{ + // If we're copying our interrupt into RAM, DMA it to block1 and use + // block2 for our RfuStruct, otherwise block1 holds the RfuStruct. + // interrupt usually is a pointer to gIntrTable[1] + if (copyInterruptToRam == TRUE) + { + *interrupt = (IntrFunc)interruptStruct->block1; + DmaCopy16(3, &IntrSIO32, interruptStruct->block1, 0x960); + gRfuState = (struct RfuStruct*)interruptStruct->block2; + } + else + { + *interrupt = (IntrFunc)IntrSIO32; + gRfuState = (struct RfuStruct*)interruptStruct->block1; + } + + gRfuState->unk_28 = interruptStruct->unk28Data; + gRfuState->unk_24 = interruptStruct->unk24Data; + gRfuState->msMode = 1; + gRfuState->unk_0 = 0; + gRfuState->unk_4 = 0; + gRfuState->unk_5 = 0; + gRfuState->unk_7 = 0; + gRfuState->unk_8 = 0; + gRfuState->unk_9 = 0; + gRfuState->unk_c = 0; + gRfuState->unk_10 = 0; + gRfuState->unk_12 = 0; + gRfuState->unk_15 = 0; + gRfuState->unk_2c = 0; + + 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(); + + IntrEnable(INTR_FLAG_SERIAL); } void STWI_init_timer(IntrFunc *interrupt, int timerSelect) { - *interrupt = &STWI_intr_timer; - gRfuState.rfuStruct->timerSelect = timerSelect; - - IntrEnable(INTR_FLAG_TIMER0 << gRfuState.rfuStruct->timerSelect); + *interrupt = STWI_intr_timer; + gRfuState->timerSelect = timerSelect; + + IntrEnable(INTR_FLAG_TIMER0 << gRfuState->timerSelect); } -void AgbRFU_SoftReset() -{ - struct RfuStruct **rfuStructPtr; - struct RfuStruct *rfuStructTemp; - - REG_RCNT = 0x8000; - REG_RCNT = 0x80A0; // all these bits are undocumented - - { - vu16 *timerL = ®_TMCNT_L(gRfuState.rfuStruct->timerSelect); - vu16 *timerH = ®_TMCNT_H(gRfuState.rfuStruct->timerSelect); - - *timerH = 0; - *timerL = 0; - *timerH = 0x83; - - while (*timerL <= 0x11) - { - REG_RCNT = 0x80A2; - } - - *timerH = 3; - } - REG_RCNT = 0x80A0; - REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; - - rfuStructPtr = (struct RfuStruct**)&gRfuState.rfuStruct; - - (*rfuStructPtr)->unk_0 = 0; - (*rfuStructPtr)->unk_4 = 0; - (*rfuStructPtr)->unk_5 = 0; - (*rfuStructPtr)->unk_6 = 0; - (*rfuStructPtr)->unk_7 = 0; - (*rfuStructPtr)->unk_8 = 0; - (*rfuStructPtr)->unk_9 = 0; - (*rfuStructPtr)->unk_c = 0; - (*rfuStructPtr)->unk_10 = 0; - - // Yeah this is the second time, there's probably something in the struct that I'm missing - rfuStructTemp = *rfuStructPtr; - rfuStructTemp->unk_12 = 0; - rfuStructTemp->msMode = 1; - (*rfuStructPtr)->unk_15 = 0; - - (*rfuStructPtr)->unk_2c = 0; +void AgbRFU_SoftReset(void) +{ + vu16 *timerL; + vu16 *timerH; + + REG_RCNT = 0x8000; + REG_RCNT = 0x80A0; // all these bits are undocumented + timerL = ®_TMCNT_L(gRfuState->timerSelect); + timerH = ®_TMCNT_H(gRfuState->timerSelect); + *timerH = 0; + *timerL = 0; + *timerH = 0x83; + while (*timerL <= 0x11) + REG_RCNT = 0x80A2; + *timerH = 3; + REG_RCNT = 0x80A0; + REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; + + gRfuState->unk_0 = 0; + gRfuState->unk_4 = 0; + gRfuState->unk_5 = 0; + gRfuState->unk_6 = 0; + gRfuState->unk_7 = 0; + gRfuState->unk_8 = 0; + gRfuState->unk_9 = 0; + gRfuState->unk_c = 0; + gRfuState->unk_10 = 0; + gRfuState->unk_12 = 0; + gRfuState->msMode = 1; + gRfuState->unk_15 = 0; + gRfuState->unk_2c = 0; } void STWI_set_MS_mode(u8 mode) { - gRfuState.rfuStruct->msMode = mode; + gRfuState->msMode = mode; } -u32 STWI_read_status(u8 index) -{ - int result; - switch(index) - { - case 0: - return gRfuState.rfuStruct->unk_12; - case 1: - return gRfuState.rfuStruct->msMode; - case 2: - // something got inlined here? - //TODO: figure this one out - result = (gRfuState.rfuStruct->unk_0); - __asm__("lsl r0, r0, #16"); - __asm__("lsr r0, r0, #16"); - break; - - case 3: - return gRfuState.rfuStruct->unk_6; - break; - default: - return 0xFFFF; - break; - } - return result; +u16 STWI_read_status(u8 index) +{ + switch (index) + { + case 0: + return gRfuState->unk_12; + case 1: + return gRfuState->msMode; + case 2: + return gRfuState->unk_0; + case 3: + return gRfuState->unk_6; + default: + return 0xFFFF; + } } -void STWI_init_Callback_M() +void STWI_init_Callback_M(void) { - STWI_set_Callback_M(0); + STWI_set_Callback_M(0); } -void STWI_init_Callback_S() +void STWI_init_Callback_S(void) { - STWI_set_Callback_S(0); + STWI_set_Callback_S(0); } -void STWI_set_Callback_M(void * callback) +void STWI_set_Callback_M(void *callback) { - gRfuState.rfuStruct->callbackM = callback; + gRfuState->callbackM = callback; } -void STWI_set_Callback_S(void * callback) +void STWI_set_Callback_S(void *callback) { - gRfuState.rfuStruct->callbackS = callback; + gRfuState->callbackS = callback; } void STWI_set_Callback_ID(u32 id) { - gRfuState.rfuStruct->callbackID = id; + gRfuState->callbackID = id; } -u16 STWI_poll_CommandEnd() +u16 STWI_poll_CommandEnd(void) { - while ( gRfuState.rfuStruct->unk_2c == TRUE ); - - return gRfuState.rfuStruct->unk_12; + while (gRfuState->unk_2c == TRUE) + ; + return gRfuState->unk_12; } -void STWI_send_ResetREQ() +void STWI_send_ResetREQ(void) { - if (!STWI_init(RFU_RESET)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_RESET)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } -void STWI_send_LinkStatusREQ() +void STWI_send_LinkStatusREQ(void) { - if (!STWI_init(RFU_LINK_STATUS)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_LINK_STATUS)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } -void STWI_send_VersionStatusREQ() +void STWI_send_VersionStatusREQ(void) { - if (!STWI_init(RFU_VERSION_STATUS)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_VERSION_STATUS)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } -void STWI_send_SystemStatusREQ() +void STWI_send_SystemStatusREQ(void) { - if (!STWI_init(RFU_SYSTEM_STATUS)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_SYSTEM_STATUS)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } -void STWI_send_SlotStatusREQ() +void STWI_send_SlotStatusREQ(void) { - if (!STWI_init(RFU_SLOT_STATUS)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_SLOT_STATUS)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } -void STWI_send_ConfigStatusREQ() +void STWI_send_ConfigStatusREQ(void) { - if (!STWI_init(RFU_CONFIG_STATUS)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_CONFIG_STATUS)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } void STWI_send_GameConfigREQ(u8 * unk1, u8 *data) { - u8 *v5; - int i; - - if (!STWI_init(RFU_GAME_CONFIG)) - { - gRfuState.rfuStruct->unk_4 = 6; //TODO: what is 6 - - //TODO: kinda gross but idk what's going on here - v5 = (u8*)gRfuState.rfuStruct->unk_24; - v5 += 4; - *(u16*)v5 = *(u16*)unk1; - - v5 += 2; - unk1 += 2; - i = 13; - do - { - *v5 = *unk1; - v5++; - unk1++; - i--; - } - while(i >= 0); - - i = 7; - do - { - *v5 = *data; - v5++; - data++; - i--; - } - while(i >= 0); - - STWI_start_Command(); - } + u8 *v5; + int i; + + if (!STWI_init(RFU_GAME_CONFIG)) + { + gRfuState->unk_4 = 6; //TODO: what is 6 + + //TODO: kinda gross but idk what's going on here + v5 = (u8*)gRfuState->unk_24; + v5 += 4; + *(u16*)v5 = *(u16*)unk1; + + v5 += 2; + unk1 += 2; + + for (i = 0; i < 14; i++) + { + *v5 = *unk1; + v5++; + unk1++; + } + + for (i = 0; i < 8; i++) + { + *v5 = *data; + v5++; + data++; + } + + STWI_start_Command(); + } } void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3) { u8 *v5; - if (!STWI_init(RFU_SYSTEM_CONFIG)) - { - gRfuState.rfuStruct->unk_4 = 1; //TODO: what is 1 + if (!STWI_init(RFU_SYSTEM_CONFIG)) + { + gRfuState->unk_4 = 1; //TODO: what is 1 - //TODO: kinda weird but idk what's going on here - v5 = (u8*)gRfuState.rfuStruct->unk_24; - v5 += 4; + //TODO: kinda weird but idk what's going on here + v5 = (u8*)gRfuState->unk_24; + v5 += 4; - *v5++ = unk3; - *v5++ = unk2; - *(u16*)v5 = unk1; - STWI_start_Command(); - } + *v5++ = unk3; + *v5++ = unk2; + *(u16*)v5 = unk1; + STWI_start_Command(); + } } -void STWI_send_SC_StartREQ() +void STWI_send_SC_StartREQ(void) { - if (!STWI_init(RFU_SC_START)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_SC_START)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } -void STWI_send_SC_PollingREQ() +void STWI_send_SC_PollingREQ(void) { - if (!STWI_init(RFU_SC_POLLING)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_SC_POLLING)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } -void STWI_send_SC_EndREQ() +void STWI_send_SC_EndREQ(void) { - if (!STWI_init(RFU_SC_END)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_SC_END)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } -void STWI_send_SP_StartREQ() +void STWI_send_SP_StartREQ(void) { - if (!STWI_init(RFU_SP_START)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_SP_START)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } -void STWI_send_SP_PollingREQ() +void STWI_send_SP_PollingREQ(void) { - if (!STWI_init(RFU_SP_POLLING)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_SP_POLLING)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } -void STWI_send_SP_EndREQ() +void STWI_send_SP_EndREQ(void) { - if (!STWI_init(RFU_SP_END)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_SP_END)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } void STWI_send_CP_StartREQ(u16 unk1) { - if (!STWI_init(RFU_CP_START)) - { - gRfuState.rfuStruct->unk_4 = 1; - *(u32*)(gRfuState.rfuStruct->unk_24 + 4) = unk1; - STWI_start_Command(); - } + if (!STWI_init(RFU_CP_START)) + { + gRfuState->unk_4 = 1; + *(u32*)(gRfuState->unk_24 + 4) = unk1; + STWI_start_Command(); + } } -void STWI_send_CP_PollingREQ() +void STWI_send_CP_PollingREQ(void) { - if (!STWI_init(RFU_CP_POLLING)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_CP_POLLING)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } -void STWI_send_CP_EndREQ() +void STWI_send_CP_EndREQ(void) { - if (!STWI_init(RFU_CP_END)) - { - gRfuState.rfuStruct->unk_4 = 0; - STWI_start_Command(); - } + if (!STWI_init(RFU_CP_END)) + { + gRfuState->unk_4 = 0; + STWI_start_Command(); + } } - -- cgit v1.2.3 From dac306c5e91ad8309bb0246d61204f8670e15955 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Sun, 10 Sep 2017 21:41:56 -0600 Subject: Decompiled librfu to STWI_send_DisconnectREQ --- src/librfu.c | 213 +++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 177 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/librfu.c b/src/librfu.c index 8e450caa0..67b76b0d9 100644 --- a/src/librfu.c +++ b/src/librfu.c @@ -20,13 +20,41 @@ enum RFU_SP_END, RFU_CP_START, RFU_CP_POLLING, - RFU_CP_END + 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_UNK31, + RFU_UNK32, + RFU_UNK33, + RFU_UNK34, + RFU_UNK35, + RFU_UNK36, + RFU_RESUME_RETRANSMIT_AND_CHANGE +}; + +struct RfuPacket +{ + u32 unk_0; + u32 data[0x1C]; }; struct RfuStruct { vs32 unk_0; - u8 unk_4; + u8 txParams; u8 unk_5; u8 unk_6; u8 unk_7; @@ -45,16 +73,16 @@ struct RfuStruct void *callbackM; void *callbackS; u32 callbackID; - u8 *unk_24; - void *unk_28; + struct RfuPacket *txPacket; + struct RfuPacket *rxPacket; vu8 unk_2c; u8 padding[3]; }; struct RfuIntrStruct { - u8 unk28Data[0x74]; - u8 unk24Data[0x74]; + u8 rxPacketAlloc[0x74]; + u8 txPacketAlloc[0x74]; u8 block1[0x960]; u8 block2[0x30]; }; @@ -86,11 +114,11 @@ void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, b gRfuState = (struct RfuStruct*)interruptStruct->block1; } - gRfuState->unk_28 = interruptStruct->unk28Data; - gRfuState->unk_24 = interruptStruct->unk24Data; + gRfuState->rxPacket = (struct RfuPacket*)interruptStruct->rxPacketAlloc; + gRfuState->txPacket = (struct RfuPacket*)interruptStruct->txPacketAlloc; gRfuState->msMode = 1; gRfuState->unk_0 = 0; - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; gRfuState->unk_5 = 0; gRfuState->unk_7 = 0; gRfuState->unk_8 = 0; @@ -136,7 +164,7 @@ void AgbRFU_SoftReset(void) REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; gRfuState->unk_0 = 0; - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; gRfuState->unk_5 = 0; gRfuState->unk_6 = 0; gRfuState->unk_7 = 0; @@ -208,7 +236,7 @@ void STWI_send_ResetREQ(void) { if (!STWI_init(RFU_RESET)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; STWI_start_Command(); } } @@ -217,7 +245,7 @@ void STWI_send_LinkStatusREQ(void) { if (!STWI_init(RFU_LINK_STATUS)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; STWI_start_Command(); } } @@ -226,7 +254,7 @@ void STWI_send_VersionStatusREQ(void) { if (!STWI_init(RFU_VERSION_STATUS)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; STWI_start_Command(); } } @@ -235,7 +263,7 @@ void STWI_send_SystemStatusREQ(void) { if (!STWI_init(RFU_SYSTEM_STATUS)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; STWI_start_Command(); } } @@ -244,7 +272,7 @@ void STWI_send_SlotStatusREQ(void) { if (!STWI_init(RFU_SLOT_STATUS)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; STWI_start_Command(); } } @@ -253,7 +281,7 @@ void STWI_send_ConfigStatusREQ(void) { if (!STWI_init(RFU_CONFIG_STATUS)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; STWI_start_Command(); } } @@ -265,15 +293,15 @@ void STWI_send_GameConfigREQ(u8 * unk1, u8 *data) if (!STWI_init(RFU_GAME_CONFIG)) { - gRfuState->unk_4 = 6; //TODO: what is 6 + gRfuState->txParams = 6; - //TODO: kinda gross but idk what's going on here - v5 = (u8*)gRfuState->unk_24; - v5 += 4; + //TODO: kinda gross but it was probably written weird + v5 = (u8*)gRfuState->txPacket; + v5 += sizeof(u32); *(u16*)v5 = *(u16*)unk1; - v5 += 2; - unk1 += 2; + v5 += sizeof(u16); + unk1 += sizeof(u16); for (i = 0; i < 14; i++) { @@ -299,11 +327,11 @@ void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3) if (!STWI_init(RFU_SYSTEM_CONFIG)) { - gRfuState->unk_4 = 1; //TODO: what is 1 + gRfuState->txParams = 1; - //TODO: kinda weird but idk what's going on here - v5 = (u8*)gRfuState->unk_24; - v5 += 4; + //TODO: kinda weird but I think it was written weird + v5 = (u8*)gRfuState->txPacket; + v5 += sizeof(u32); *v5++ = unk3; *v5++ = unk2; @@ -316,7 +344,7 @@ void STWI_send_SC_StartREQ(void) { if (!STWI_init(RFU_SC_START)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; STWI_start_Command(); } } @@ -325,7 +353,7 @@ void STWI_send_SC_PollingREQ(void) { if (!STWI_init(RFU_SC_POLLING)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; STWI_start_Command(); } } @@ -334,7 +362,7 @@ void STWI_send_SC_EndREQ(void) { if (!STWI_init(RFU_SC_END)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; STWI_start_Command(); } } @@ -343,7 +371,7 @@ void STWI_send_SP_StartREQ(void) { if (!STWI_init(RFU_SP_START)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; STWI_start_Command(); } } @@ -352,7 +380,7 @@ void STWI_send_SP_PollingREQ(void) { if (!STWI_init(RFU_SP_POLLING)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; STWI_start_Command(); } } @@ -361,7 +389,7 @@ void STWI_send_SP_EndREQ(void) { if (!STWI_init(RFU_SP_END)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; STWI_start_Command(); } } @@ -370,8 +398,8 @@ void STWI_send_CP_StartREQ(u16 unk1) { if (!STWI_init(RFU_CP_START)) { - gRfuState->unk_4 = 1; - *(u32*)(gRfuState->unk_24 + 4) = unk1; + gRfuState->txParams = 1; + gRfuState->txPacket->data[0] = unk1; STWI_start_Command(); } } @@ -380,7 +408,7 @@ void STWI_send_CP_PollingREQ(void) { if (!STWI_init(RFU_CP_POLLING)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; STWI_start_Command(); } } @@ -389,7 +417,120 @@ void STWI_send_CP_EndREQ(void) { if (!STWI_init(RFU_CP_END)) { - gRfuState->unk_4 = 0; + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_DataTxREQ(void *in, u8 size) +{ + if (!STWI_init(RFU_DATA_TX)) + { + u8 txParams = (size / sizeof(u32)); + if (size & (sizeof(u32) - 1)) + txParams += 1; + + gRfuState->txParams = txParams; + CpuCopy32(in, gRfuState->txPacket->data, gRfuState->txParams * sizeof(u32)); + STWI_start_Command(); + } +} + +void STWI_send_DataTxAndChangeREQ(void *in, u8 size) +{ + if (!STWI_init(RFU_DATA_TX_AND_CHANGE)) + { + u8 txParams = (size / sizeof(u32)); + if (size & (sizeof(u32) - 1)) + txParams += 1; + + gRfuState->txParams = txParams; + CpuCopy32(in, gRfuState->txPacket->data, gRfuState->txParams * sizeof(u32)); + STWI_start_Command(); + } +} + +void STWI_send_DataRxREQ() +{ + if (!STWI_init(RFU_DATA_RX)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_MS_ChangeREQ() +{ + if (!STWI_init(RFU_MS_CHANGE)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_DataReadyAndChangeREQ(u8 unk) +{ + if (!STWI_init(RFU_DATA_READY_AND_CHANGE)) + { + if (!unk) + { + gRfuState->txParams = 0; + } + else + { + u8 *packetBytes; + + gRfuState->txParams = 1; + + packetBytes = (u8*)gRfuState->txPacket; + packetBytes += sizeof(u32); + + *packetBytes++ = unk; + *packetBytes++ = 0; + *packetBytes++ = 0; + *packetBytes = 0; + } + + STWI_start_Command(); + } +} + +void STWI_send_DisconnectedAndChangeREQ(u8 unk0, u8 unk1) +{ + if (!STWI_init(RFU_DISCONNECTED_AND_CHANGE)) + { + u8 *packetBytes; + + gRfuState->txParams = 1; + + packetBytes = (u8*)gRfuState->txPacket; + packetBytes += sizeof(u32); + + *packetBytes++ = unk0; + *packetBytes++ = unk1; + *packetBytes++ = 0; + *packetBytes = 0; + + STWI_start_Command(); + } +} + +void STWI_send_ResumeRetransmitAndChangeREQ() +{ + if (!STWI_init(RFU_RESUME_RETRANSMIT_AND_CHANGE)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_DisconnectREQ(u8 unk) +{ + if (!STWI_init(RFU_DISCONNECT)) + { + gRfuState->txParams = 1; + gRfuState->txPacket->data[0] = unk; + STWI_start_Command(); } } -- cgit v1.2.3 From 9218c2ce16777bba33fea2b606c5805553d190de Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Sun, 10 Sep 2017 21:46:26 -0600 Subject: Decompile to STWI_send_TestModeREQ --- src/librfu.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/librfu.c b/src/librfu.c index 67b76b0d9..00dde830b 100644 --- a/src/librfu.c +++ b/src/librfu.c @@ -36,7 +36,7 @@ enum RFU_UNK2E, RFU_UNK2F, RFU_DISCONNECT, - RFU_UNK31, + RFU_TEST_MODE, RFU_UNK32, RFU_UNK33, RFU_UNK34, @@ -534,3 +534,14 @@ void STWI_send_DisconnectREQ(u8 unk) STWI_start_Command(); } } + +void STWI_send_TestModeREQ(u8 unk0, u8 unk1) +{ + if (!STWI_init(RFU_TEST_MODE)) + { + gRfuState->txParams = 1; + gRfuState->txPacket->data[0] = unk0 | (unk1 << 8); + + STWI_start_Command(); + } +} -- cgit v1.2.3 From e26e1f1275a23e290322059bab1f80f89dac4f8a Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Sun, 10 Sep 2017 21:58:47 -0600 Subject: Use a union to differentiate between 8-bit and 32-bit operations on packets --- src/librfu.c | 72 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/librfu.c b/src/librfu.c index 00dde830b..5cbe9eb49 100644 --- a/src/librfu.c +++ b/src/librfu.c @@ -45,12 +45,23 @@ enum RFU_RESUME_RETRANSMIT_AND_CHANGE }; -struct RfuPacket +struct RfuPacket8 { - u32 unk_0; + u8 data[0x74]; +}; + +struct RfuPacket32 +{ + u32 command; u32 data[0x1C]; }; +union RfuPacket +{ + struct RfuPacket32 rfuPacket32; + struct RfuPacket8 rfuPacket8; +}; + struct RfuStruct { vs32 unk_0; @@ -73,8 +84,8 @@ struct RfuStruct void *callbackM; void *callbackS; u32 callbackID; - struct RfuPacket *txPacket; - struct RfuPacket *rxPacket; + union RfuPacket *txPacket; + union RfuPacket *rxPacket; vu8 unk_2c; u8 padding[3]; }; @@ -114,8 +125,8 @@ void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, b gRfuState = (struct RfuStruct*)interruptStruct->block1; } - gRfuState->rxPacket = (struct RfuPacket*)interruptStruct->rxPacketAlloc; - gRfuState->txPacket = (struct RfuPacket*)interruptStruct->txPacketAlloc; + gRfuState->rxPacket = (union RfuPacket*)interruptStruct->rxPacketAlloc; + gRfuState->txPacket = (union RfuPacket*)interruptStruct->txPacketAlloc; gRfuState->msMode = 1; gRfuState->unk_0 = 0; gRfuState->txParams = 0; @@ -288,32 +299,32 @@ void STWI_send_ConfigStatusREQ(void) void STWI_send_GameConfigREQ(u8 * unk1, u8 *data) { - u8 *v5; + u8 *packetBytes; int i; if (!STWI_init(RFU_GAME_CONFIG)) { gRfuState->txParams = 6; - //TODO: kinda gross but it was probably written weird - v5 = (u8*)gRfuState->txPacket; - v5 += sizeof(u32); - *(u16*)v5 = *(u16*)unk1; + //TODO: what is unk1 + packetBytes = gRfuState->txPacket->rfuPacket8.data; + packetBytes += sizeof(u32); + *(u16*)packetBytes = *(u16*)unk1; - v5 += sizeof(u16); + packetBytes += sizeof(u16); unk1 += sizeof(u16); for (i = 0; i < 14; i++) { - *v5 = *unk1; - v5++; + *packetBytes = *unk1; + packetBytes++; unk1++; } for (i = 0; i < 8; i++) { - *v5 = *data; - v5++; + *packetBytes = *data; + packetBytes++; data++; } @@ -323,19 +334,18 @@ void STWI_send_GameConfigREQ(u8 * unk1, u8 *data) void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3) { - u8 *v5; - if (!STWI_init(RFU_SYSTEM_CONFIG)) { + u8 *packetBytes; + gRfuState->txParams = 1; - //TODO: kinda weird but I think it was written weird - v5 = (u8*)gRfuState->txPacket; - v5 += sizeof(u32); + packetBytes = gRfuState->txPacket->rfuPacket8.data; + packetBytes += sizeof(u32); - *v5++ = unk3; - *v5++ = unk2; - *(u16*)v5 = unk1; + *packetBytes++ = unk3; + *packetBytes++ = unk2; + *(u16*)packetBytes = unk1; STWI_start_Command(); } } @@ -399,7 +409,7 @@ void STWI_send_CP_StartREQ(u16 unk1) if (!STWI_init(RFU_CP_START)) { gRfuState->txParams = 1; - gRfuState->txPacket->data[0] = unk1; + gRfuState->txPacket->rfuPacket32.data[0] = unk1; STWI_start_Command(); } } @@ -431,7 +441,7 @@ void STWI_send_DataTxREQ(void *in, u8 size) txParams += 1; gRfuState->txParams = txParams; - CpuCopy32(in, gRfuState->txPacket->data, gRfuState->txParams * sizeof(u32)); + CpuCopy32(in, gRfuState->txPacket->rfuPacket32.data, gRfuState->txParams * sizeof(u32)); STWI_start_Command(); } } @@ -445,7 +455,7 @@ void STWI_send_DataTxAndChangeREQ(void *in, u8 size) txParams += 1; gRfuState->txParams = txParams; - CpuCopy32(in, gRfuState->txPacket->data, gRfuState->txParams * sizeof(u32)); + CpuCopy32(in, gRfuState->txPacket->rfuPacket32.data, gRfuState->txParams * sizeof(u32)); STWI_start_Command(); } } @@ -482,7 +492,7 @@ void STWI_send_DataReadyAndChangeREQ(u8 unk) gRfuState->txParams = 1; - packetBytes = (u8*)gRfuState->txPacket; + packetBytes = gRfuState->txPacket->rfuPacket8.data; packetBytes += sizeof(u32); *packetBytes++ = unk; @@ -503,7 +513,7 @@ void STWI_send_DisconnectedAndChangeREQ(u8 unk0, u8 unk1) gRfuState->txParams = 1; - packetBytes = (u8*)gRfuState->txPacket; + packetBytes = gRfuState->txPacket->rfuPacket8.data; packetBytes += sizeof(u32); *packetBytes++ = unk0; @@ -529,7 +539,7 @@ void STWI_send_DisconnectREQ(u8 unk) if (!STWI_init(RFU_DISCONNECT)) { gRfuState->txParams = 1; - gRfuState->txPacket->data[0] = unk; + gRfuState->txPacket->rfuPacket32.data[0] = unk; STWI_start_Command(); } @@ -540,7 +550,7 @@ void STWI_send_TestModeREQ(u8 unk0, u8 unk1) if (!STWI_init(RFU_TEST_MODE)) { gRfuState->txParams = 1; - gRfuState->txPacket->data[0] = unk0 | (unk1 << 8); + gRfuState->txPacket->rfuPacket32.data[0] = unk0 | (unk1 << 8); STWI_start_Command(); } -- cgit v1.2.3 From ce08f34ed54b9e5af9a8d1d6cd780df7207c1dbb Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Sun, 10 Sep 2017 22:22:10 -0600 Subject: Finish with STWI_send_* --- src/librfu.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/librfu.c b/src/librfu.c index 5cbe9eb49..dfb2f7221 100644 --- a/src/librfu.c +++ b/src/librfu.c @@ -37,12 +37,18 @@ enum RFU_UNK2F, RFU_DISCONNECT, RFU_TEST_MODE, - RFU_UNK32, - RFU_UNK33, - RFU_UNK34, + RFU_CPR_START, + RFU_CPR_POLLING, + RFU_CPR_END, RFU_UNK35, RFU_UNK36, - RFU_RESUME_RETRANSMIT_AND_CHANGE + RFU_RESUME_RETRANSMIT_AND_CHANGE, + RFU_UNK38, + RFU_UNK39, + RFU_UNK3A, + RFU_UNK3B, + RFU_UNK3C, + RFU_STOP_MODE, //3D }; struct RfuPacket8 @@ -555,3 +561,48 @@ void STWI_send_TestModeREQ(u8 unk0, u8 unk1) STWI_start_Command(); } } + +void STWI_send_CPR_StartREQ(u16 unk0, u16 unk1, u8 unk2) +{ + u32 *packetData; + u32 arg1; + + if (!STWI_init(RFU_CPR_START)) + { + gRfuState->txParams = 2; + + arg1 = unk1 | (unk0 << 16); + packetData = gRfuState->txPacket->rfuPacket32.data; + packetData[0] = arg1; + packetData[1] = unk2; + + STWI_start_Command(); + } +} + +void STWI_send_CPR_PollingREQ() +{ + if (!STWI_init(RFU_CPR_POLLING)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_CPR_EndREQ() +{ + if (!STWI_init(RFU_CPR_END)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_StopModeREQ() +{ + if (!STWI_init(RFU_STOP_MODE)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} -- cgit v1.2.3 From 3c51ecded9dee7c8d85642709d2e93af34274f39 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Mon, 11 Sep 2017 17:04:13 -0600 Subject: Decompile to STWI_init --- src/librfu.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 128 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/librfu.c b/src/librfu.c index dfb2f7221..f1c35b1ec 100644 --- a/src/librfu.c +++ b/src/librfu.c @@ -79,16 +79,16 @@ struct RfuStruct u8 unk_9; u8 timerSelect; u8 unk_b; - u32 unk_c; - vu8 unk_10; + int timerState; + vu8 timerActive; u8 unk_11; vu16 unk_12; vu8 msMode; u8 unk_15; u8 unk_16; u8 unk_17; - void *callbackM; - void *callbackS; + void (*callbackM)(); + void (*callbackS)(); u32 callbackID; union RfuPacket *txPacket; union RfuPacket *rxPacket; @@ -112,7 +112,11 @@ void STWI_set_Callback_M(void * callback); void STWI_set_Callback_S(void * callback); u16 STWI_init(u8 request); int STWI_start_Command(void); -extern void STWI_intr_timer(void); +void STWI_intr_timer(void); +void STWI_set_timer(u8 unk); +extern void STWI_stop_timer(void); +extern void STWI_restart_Command(void); +extern void STWI_reset_ClockCounter(void); void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam) { @@ -140,8 +144,8 @@ void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, b gRfuState->unk_7 = 0; gRfuState->unk_8 = 0; gRfuState->unk_9 = 0; - gRfuState->unk_c = 0; - gRfuState->unk_10 = 0; + gRfuState->timerState = 0; + gRfuState->timerActive = 0; gRfuState->unk_12 = 0; gRfuState->unk_15 = 0; gRfuState->unk_2c = 0; @@ -187,8 +191,8 @@ void AgbRFU_SoftReset(void) gRfuState->unk_7 = 0; gRfuState->unk_8 = 0; gRfuState->unk_9 = 0; - gRfuState->unk_c = 0; - gRfuState->unk_10 = 0; + gRfuState->timerState = 0; + gRfuState->timerActive = 0; gRfuState->unk_12 = 0; gRfuState->msMode = 1; gRfuState->unk_15 = 0; @@ -466,7 +470,7 @@ void STWI_send_DataTxAndChangeREQ(void *in, u8 size) } } -void STWI_send_DataRxREQ() +void STWI_send_DataRxREQ(void) { if (!STWI_init(RFU_DATA_RX)) { @@ -475,7 +479,7 @@ void STWI_send_DataRxREQ() } } -void STWI_send_MS_ChangeREQ() +void STWI_send_MS_ChangeREQ(void) { if (!STWI_init(RFU_MS_CHANGE)) { @@ -531,7 +535,7 @@ void STWI_send_DisconnectedAndChangeREQ(u8 unk0, u8 unk1) } } -void STWI_send_ResumeRetransmitAndChangeREQ() +void STWI_send_ResumeRetransmitAndChangeREQ(void) { if (!STWI_init(RFU_RESUME_RETRANSMIT_AND_CHANGE)) { @@ -580,7 +584,7 @@ void STWI_send_CPR_StartREQ(u16 unk0, u16 unk1, u8 unk2) } } -void STWI_send_CPR_PollingREQ() +void STWI_send_CPR_PollingREQ(void) { if (!STWI_init(RFU_CPR_POLLING)) { @@ -589,7 +593,7 @@ void STWI_send_CPR_PollingREQ() } } -void STWI_send_CPR_EndREQ() +void STWI_send_CPR_EndREQ(void) { if (!STWI_init(RFU_CPR_END)) { @@ -598,7 +602,7 @@ void STWI_send_CPR_EndREQ() } } -void STWI_send_StopModeREQ() +void STWI_send_StopModeREQ(void) { if (!STWI_init(RFU_STOP_MODE)) { @@ -606,3 +610,112 @@ void STWI_send_StopModeREQ() STWI_start_Command(); } } + +void STWI_intr_timer(void) +{ + switch (gRfuState->timerState) + { + //TODO: Make an enum for these + case 2: + gRfuState->timerActive = 1; + STWI_set_timer(50); + break; + case 1: + case 4: + STWI_stop_timer(); + STWI_restart_Command(); + break; + case 3: + gRfuState->timerActive = 1; + STWI_stop_timer(); + STWI_reset_ClockCounter(); + if (gRfuState->callbackM) + gRfuState->callbackM(255, 0); + break; + } +} + +void STWI_set_timer(u8 unk) +{ + vu16 *timerL; + vu16 *timerH; + + timerL = ®_TMCNT_L(gRfuState->timerSelect); + timerH = ®_TMCNT_H(gRfuState->timerSelect); + REG_IME = 0; + switch (unk) + { + case 50: + *timerL = 0xFCCB; + gRfuState->timerState = 1; + break; + case 80: + *timerL = 0xFAE0; + gRfuState->timerState = 2; + break; + case 100: + *timerL = 0xF996; + gRfuState->timerState = 3; + break; + case 130: + *timerL = 0xF7AD; + gRfuState->timerState = 4; + break; + } + *timerH = TIMER_ENABLE | TIMER_INTR_ENABLE | TIMER_1024CLK; + REG_IF = INTR_FLAG_TIMER0 << gRfuState->timerSelect; + REG_IME = 1; +} + +void STWI_stop_timer(void) +{ + gRfuState->timerState = 0; + + REG_TMCNT_L(gRfuState->timerSelect) = 0; + REG_TMCNT_H(gRfuState->timerSelect) = 0; +} + +u16 STWI_init(u8 request) +{ + if (!REG_IME) + { + gRfuState->unk_12 = 6; + if (gRfuState->callbackM) + gRfuState->callbackM(request, gRfuState->unk_12); + return TRUE; + } + else if (gRfuState->unk_2c == TRUE) + { + gRfuState->unk_12 = 2; + gRfuState->unk_2c = FALSE; + if (gRfuState->callbackM) + gRfuState->callbackM(request, gRfuState->unk_12); + return TRUE; + } + else if(!gRfuState->msMode) + { + gRfuState->unk_12 = 4; + if (gRfuState->callbackM) + gRfuState->callbackM(request, gRfuState->unk_12, gRfuState); + return TRUE; + } + else + { + gRfuState->unk_2c = TRUE; + gRfuState->unk_6 = request; + gRfuState->unk_0 = 0; + gRfuState->txParams = 0; + gRfuState->unk_5 = 0; + gRfuState->unk_7 = 0; + gRfuState->unk_8 = 0; + gRfuState->unk_9 = 0; + gRfuState->timerState = 0; + gRfuState->timerActive = 0; + gRfuState->unk_12 = 0; + gRfuState->unk_15 = 0; + + REG_RCNT = 0x100; + REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; + return FALSE; + } +} -- cgit v1.2.3 From a8a6816f0e6e6c20aa1ae23bf8030153c147b075 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Mon, 11 Sep 2017 17:49:50 -0600 Subject: Decompile STWI_start_command --- src/librfu.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/librfu.c b/src/librfu.c index f1c35b1ec..37b76ec3e 100644 --- a/src/librfu.c +++ b/src/librfu.c @@ -73,7 +73,7 @@ struct RfuStruct vs32 unk_0; u8 txParams; u8 unk_5; - u8 unk_6; + u8 activeCommand; u8 unk_7; u8 unk_8; u8 unk_9; @@ -187,7 +187,7 @@ void AgbRFU_SoftReset(void) gRfuState->unk_0 = 0; gRfuState->txParams = 0; gRfuState->unk_5 = 0; - gRfuState->unk_6 = 0; + gRfuState->activeCommand = 0; gRfuState->unk_7 = 0; gRfuState->unk_8 = 0; gRfuState->unk_9 = 0; @@ -215,7 +215,7 @@ u16 STWI_read_status(u8 index) case 2: return gRfuState->unk_0; case 3: - return gRfuState->unk_6; + return gRfuState->activeCommand; default: return 0xFFFF; } @@ -702,7 +702,7 @@ u16 STWI_init(u8 request) else { gRfuState->unk_2c = TRUE; - gRfuState->unk_6 = request; + gRfuState->activeCommand = request; gRfuState->unk_0 = 0; gRfuState->txParams = 0; gRfuState->unk_5 = 0; @@ -719,3 +719,25 @@ u16 STWI_init(u8 request) return FALSE; } } + +int STWI_start_Command() +{ + u16 imeTemp; + + // Yes, it matters that it's casted to a u32... + *(u32*)gRfuState->txPacket->rfuPacket8.data = 0x99660000 | (gRfuState->txParams << 8) | gRfuState->activeCommand; + REG_SIODATA32 = gRfuState->txPacket->rfuPacket32.command; + + gRfuState->unk_0 = 0; + gRfuState->unk_5 = 1; + + imeTemp = REG_IME; + REG_IME = 0; + REG_IE |= (INTR_FLAG_TIMER0 << gRfuState->timerSelect); + REG_IE |= INTR_FLAG_SERIAL; + REG_IME = imeTemp; + + REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_MULTI_BUSY | SIO_115200_BPS; + + return 0; +} -- cgit v1.2.3 From dd316b28e017d24567a86e972d780a43d42cd140 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Tue, 12 Sep 2017 20:11:51 -0600 Subject: Decompile up to ARM functions in librfu, split ARM interrupt functions into their own .s --- src/librfu.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/librfu.c b/src/librfu.c index 37b76ec3e..e647b9178 100644 --- a/src/librfu.c +++ b/src/librfu.c @@ -115,8 +115,8 @@ int STWI_start_Command(void); void STWI_intr_timer(void); void STWI_set_timer(u8 unk); extern void STWI_stop_timer(void); -extern void STWI_restart_Command(void); -extern void STWI_reset_ClockCounter(void); +int STWI_restart_Command(void); +int STWI_reset_ClockCounter(void); void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam) { @@ -741,3 +741,48 @@ int STWI_start_Command() return 0; } + +int STWI_restart_Command(void) +{ + if (gRfuState->unk_15 <= 1) + { + gRfuState->unk_15++; + STWI_start_Command(); + } + else + { + if (gRfuState->activeCommand == RFU_MS_CHANGE || gRfuState->activeCommand == RFU_DATA_TX_AND_CHANGE || gRfuState->activeCommand == RFU_UNK35 || gRfuState->activeCommand == RFU_RESUME_RETRANSMIT_AND_CHANGE) + { + gRfuState->unk_12 = 1; + gRfuState->unk_2c = 0; + + if (gRfuState->callbackM) + gRfuState->callbackM(gRfuState->activeCommand, gRfuState->unk_12); + } + else + { + gRfuState->unk_12 = 1; + gRfuState->unk_2c = 0; + + if (gRfuState->callbackM) + gRfuState->callbackM(gRfuState->activeCommand, gRfuState->unk_12); + + gRfuState->unk_0 = 4; //TODO: what's 4 + } + } + + return 0; +} + +int STWI_reset_ClockCounter() +{ + gRfuState->unk_0 = 5; //TODO: what is 5 + gRfuState->txParams = 0; + gRfuState->unk_5 = 0; + REG_SIODATA32 = (1 << 31); + REG_SIOCNT = 0; + REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; + REG_SIOCNT = (SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS) + 0x7F; + + return 0; +} -- cgit v1.2.3 From ae53458622db5321f10092fe1585474813b0edcd Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 21 Oct 2017 00:44:17 -0400 Subject: decompile clear_save_data_screen. --- src/clear_save_data_screen.c | 212 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100755 src/clear_save_data_screen.c (limited to 'src') diff --git a/src/clear_save_data_screen.c b/src/clear_save_data_screen.c new file mode 100755 index 000000000..4e3b12992 --- /dev/null +++ b/src/clear_save_data_screen.c @@ -0,0 +1,212 @@ +#include "global.h" +#include "task.h" +#include "menu.h" +#include "text.h" +#include "sound.h" +#include "main.h" +#include "save.h" +#include "palette.h" +#include "gpu_regs.h" +#include "bg.h" +#include "text_window.h" +#include "songs.h" + +extern void CreateYesNoMenu(const struct WindowTemplate *windowTemplate, u16 borderFirstTileNum, u8 borderPalette, u8 initialCursorPos); // menu.s +extern s8 sub_8198C58(void); // menu.s + +extern u8 gText_ClearAllSaveData[]; +extern u8 gText_ClearingData[]; + +extern u16 gUnknown_0860F074[]; + +static void Task_DoClearSaveDataScreenYesNo(u8); +static void Task_ClearSaveDataScreenYesNoChoice(u8); +static void Task_ClearSaveData(u8); +static bool8 SetupClearSaveDataScreen(void); +static void CB2_FadeAndDoReset(void); +static void InitClearSaveDataScreenWindows(void); + +static const struct BgTemplate sClearSaveBgTemplates[2] = +{ + { + .bg = 0, + .charBaseIndex = 0, + .mapBaseIndex = 31, + .screenSize = 0, + .paletteMode = 0, + .priority = 0, + .baseTile = 0, + }, + { + .bg = 3, + .charBaseIndex = 0, + .mapBaseIndex = 30, + .screenSize = 0, + .paletteMode = 0, + .priority = 1, + .baseTile = 0, + }, +}; + +static const struct WindowTemplate sClearSaveTextWindow[] = +{ + { + .priority = 0, + .tilemapLeft = 3, + .tilemapTop = 15, + .width = 26, + .height = 4, + .paletteNum = 15, + .baseBlock = 11, + }, + DUMMY_WIN_TEMPLATE +}; + +static const struct WindowTemplate sClearSaveYesNo[] = +{ + { + .priority = 0, + .tilemapLeft = 3, + .tilemapTop = 2, + .width = 5, + .height = 4, + .paletteNum = 15, + .baseBlock = 115, + } +}; + +void CB2_InitClearSaveDataScreen(void) +{ + if(SetupClearSaveDataScreen()) + CreateTask(Task_DoClearSaveDataScreenYesNo, 0); +} + +static void Task_DoClearSaveDataScreenYesNo(u8 taskId) +{ + SetWindowBorderStyle(0, 0, 2, 14); + PrintTextOnWindow(0, 1, gText_ClearAllSaveData, 0, 1, 0, 0); + CreateYesNoMenu(sClearSaveYesNo, 2, 14, 1); + gTasks[taskId].func = Task_ClearSaveDataScreenYesNoChoice; +} + +static void Task_ClearSaveDataScreenYesNoChoice(u8 taskId) +{ + switch(sub_8198C58()) + { + case 0: + FillWindowPixelBuffer(0, 17); + PrintTextOnWindow(0, 1, gText_ClearingData, 0, 1, 0, 0); + gTasks[taskId].func = Task_ClearSaveData; + break; + case 1: + case -1: + PlaySE(SE_SELECT); + DestroyTask(taskId); + SetMainCallback2(CB2_FadeAndDoReset); + } +} + +static void Task_ClearSaveData(u8 taskId) +{ + ClearSaveData(); + DestroyTask(taskId); + SetMainCallback2(CB2_FadeAndDoReset); +} + +static void MainCB(void) +{ + RunTasks(); + UpdatePaletteFade(); +} + +static void VBlankCB(void) +{ + TransferPlttBuffer(); +} + +static bool8 SetupClearSaveDataScreen(void) +{ + u16 i; + + switch(gMain.state) + { + case 0: + default: + SetVBlankCallback(NULL); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG0HOFS, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG0VOFS, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG3HOFS, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG3VOFS, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_WIN0H, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_WIN0V, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_WININ, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_WINOUT, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BLDCNT, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BLDALPHA, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BLDY, DISPCNT_MODE_0); + DmaFill16(3, 0, (void *)VRAM, VRAM_SIZE); + DmaFill32(3, 0, (void *)OAM, OAM_SIZE); + DmaFill16(3, 0, (void *)(PLTT + 2), PLTT_SIZE - 2); + ResetPaletteFade(); + gPlttBufferUnfaded[0] = 0x7fff; + gPlttBufferFaded[0] = 0x7fff; + gPlttBufferUnfaded[1] = 0x3945; + gPlttBufferFaded[1] = 0x3945; + for (i = 0; i < 0x10; i++) + ((u16 *)(VRAM + 0x20))[i] = 0x1111; + + for (i = 0; i < 0x400; i++) + ((u16 *)(VRAM + 0xF000))[i] = 0x0001; + ResetTasks(); + ResetSpriteData(); + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, sClearSaveBgTemplates, ARRAY_COUNT(sClearSaveBgTemplates)); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); + ShowBg(0); + ShowBg(3); + SetGpuReg(REG_OFFSET_BLDCNT, DISPCNT_MODE_0); + InitClearSaveDataScreenWindows(); + BeginNormalPaletteFade(0x0000FFFF, 0, 0x10, 0, 0xFFFF); + EnableInterrupts(1); + SetVBlankCallback(VBlankCB); + gMain.state = 1; + break; + case 1: + UpdatePaletteFade(); + if(!gPaletteFade.active) + { + SetMainCallback2(MainCB); + return TRUE; + } + } + return FALSE; +} + +static void CB2_FadeAndDoReset(void) +{ + switch(gMain.state) + { + case 0: + default: + BeginNormalPaletteFade(0x0000FFFF, 0, 0, 0x10, 0xFFFF); + gMain.state = 1; + break; + case 1: + UpdatePaletteFade(); + if(!gPaletteFade.active) + { + FreeAllWindowBuffers(); + DoSoftReset(); + } + } +} + +static void InitClearSaveDataScreenWindows(void) +{ + InitWindows(sClearSaveTextWindow); + DeactivateAllTextPrinters(); + FillWindowPixelBuffer(0, 0); + sub_80987D4(0, 0, 2, 224); + LoadPalette(gUnknown_0860F074, 0xF0, 0x20); +} -- cgit v1.2.3 From 482b42a295a80952cea75a8176183692b8e8d120 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Sat, 21 Oct 2017 13:42:31 -0600 Subject: Split librfu into separate C files in its own directory, rfu_initializeAPI matching except for register differences --- src/librfu.c | 788 ------------------------------------------------------ src/librfu_intr.c | 4 + src/librfu_rfu.c | 109 ++++++++ src/librfu_stwi.c | 687 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 800 insertions(+), 788 deletions(-) delete mode 100644 src/librfu.c create mode 100644 src/librfu_intr.c create mode 100644 src/librfu_rfu.c create mode 100644 src/librfu_stwi.c (limited to 'src') diff --git a/src/librfu.c b/src/librfu.c deleted file mode 100644 index e647b9178..000000000 --- a/src/librfu.c +++ /dev/null @@ -1,788 +0,0 @@ -#include "global.h" -#include "main.h" - -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 -}; - -struct RfuPacket8 -{ - u8 data[0x74]; -}; - -struct RfuPacket32 -{ - u32 command; - u32 data[0x1C]; -}; - -union RfuPacket -{ - struct RfuPacket32 rfuPacket32; - struct RfuPacket8 rfuPacket8; -}; - -struct RfuStruct -{ - vs32 unk_0; - u8 txParams; - u8 unk_5; - u8 activeCommand; - u8 unk_7; - u8 unk_8; - u8 unk_9; - u8 timerSelect; - u8 unk_b; - int timerState; - vu8 timerActive; - u8 unk_11; - vu16 unk_12; - vu8 msMode; - u8 unk_15; - u8 unk_16; - u8 unk_17; - void (*callbackM)(); - void (*callbackS)(); - u32 callbackID; - union RfuPacket *txPacket; - union RfuPacket *rxPacket; - vu8 unk_2c; - u8 padding[3]; -}; - -struct RfuIntrStruct -{ - u8 rxPacketAlloc[0x74]; - u8 txPacketAlloc[0x74]; - u8 block1[0x960]; - u8 block2[0x30]; -}; - -extern IntrFunc IntrSIO32(void); -extern struct RfuStruct *gRfuState; -void STWI_init_Callback_M(void); -void STWI_init_Callback_S(void); -void STWI_set_Callback_M(void * callback); -void STWI_set_Callback_S(void * callback); -u16 STWI_init(u8 request); -int STWI_start_Command(void); -void STWI_intr_timer(void); -void STWI_set_timer(u8 unk); -extern void STWI_stop_timer(void); -int STWI_restart_Command(void); -int STWI_reset_ClockCounter(void); - -void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam) -{ - // If we're copying our interrupt into RAM, DMA it to block1 and use - // block2 for our RfuStruct, otherwise block1 holds the RfuStruct. - // interrupt usually is a pointer to gIntrTable[1] - if (copyInterruptToRam == TRUE) - { - *interrupt = (IntrFunc)interruptStruct->block1; - DmaCopy16(3, &IntrSIO32, interruptStruct->block1, 0x960); - gRfuState = (struct RfuStruct*)interruptStruct->block2; - } - else - { - *interrupt = (IntrFunc)IntrSIO32; - gRfuState = (struct RfuStruct*)interruptStruct->block1; - } - - gRfuState->rxPacket = (union RfuPacket*)interruptStruct->rxPacketAlloc; - gRfuState->txPacket = (union RfuPacket*)interruptStruct->txPacketAlloc; - gRfuState->msMode = 1; - gRfuState->unk_0 = 0; - gRfuState->txParams = 0; - gRfuState->unk_5 = 0; - gRfuState->unk_7 = 0; - gRfuState->unk_8 = 0; - gRfuState->unk_9 = 0; - gRfuState->timerState = 0; - gRfuState->timerActive = 0; - gRfuState->unk_12 = 0; - gRfuState->unk_15 = 0; - gRfuState->unk_2c = 0; - - 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(); - - IntrEnable(INTR_FLAG_SERIAL); -} - -void STWI_init_timer(IntrFunc *interrupt, int timerSelect) -{ - *interrupt = STWI_intr_timer; - gRfuState->timerSelect = timerSelect; - - IntrEnable(INTR_FLAG_TIMER0 << gRfuState->timerSelect); -} - -void AgbRFU_SoftReset(void) -{ - vu16 *timerL; - vu16 *timerH; - - REG_RCNT = 0x8000; - REG_RCNT = 0x80A0; // all these bits are undocumented - timerL = ®_TMCNT_L(gRfuState->timerSelect); - timerH = ®_TMCNT_H(gRfuState->timerSelect); - *timerH = 0; - *timerL = 0; - *timerH = 0x83; - while (*timerL <= 0x11) - REG_RCNT = 0x80A2; - *timerH = 3; - REG_RCNT = 0x80A0; - REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; - - gRfuState->unk_0 = 0; - gRfuState->txParams = 0; - gRfuState->unk_5 = 0; - gRfuState->activeCommand = 0; - gRfuState->unk_7 = 0; - gRfuState->unk_8 = 0; - gRfuState->unk_9 = 0; - gRfuState->timerState = 0; - gRfuState->timerActive = 0; - gRfuState->unk_12 = 0; - gRfuState->msMode = 1; - gRfuState->unk_15 = 0; - gRfuState->unk_2c = 0; -} - -void STWI_set_MS_mode(u8 mode) -{ - gRfuState->msMode = mode; -} - -u16 STWI_read_status(u8 index) -{ - switch (index) - { - case 0: - return gRfuState->unk_12; - case 1: - return gRfuState->msMode; - case 2: - return gRfuState->unk_0; - case 3: - return gRfuState->activeCommand; - default: - return 0xFFFF; - } -} - -void STWI_init_Callback_M(void) -{ - STWI_set_Callback_M(0); -} - -void STWI_init_Callback_S(void) -{ - STWI_set_Callback_S(0); -} - -void STWI_set_Callback_M(void *callback) -{ - gRfuState->callbackM = callback; -} - -void STWI_set_Callback_S(void *callback) -{ - gRfuState->callbackS = callback; -} - -void STWI_set_Callback_ID(u32 id) -{ - gRfuState->callbackID = id; -} - -u16 STWI_poll_CommandEnd(void) -{ - while (gRfuState->unk_2c == TRUE) - ; - return gRfuState->unk_12; -} - -void STWI_send_ResetREQ(void) -{ - if (!STWI_init(RFU_RESET)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_LinkStatusREQ(void) -{ - if (!STWI_init(RFU_LINK_STATUS)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_VersionStatusREQ(void) -{ - if (!STWI_init(RFU_VERSION_STATUS)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_SystemStatusREQ(void) -{ - if (!STWI_init(RFU_SYSTEM_STATUS)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_SlotStatusREQ(void) -{ - if (!STWI_init(RFU_SLOT_STATUS)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_ConfigStatusREQ(void) -{ - if (!STWI_init(RFU_CONFIG_STATUS)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_GameConfigREQ(u8 * unk1, u8 *data) -{ - u8 *packetBytes; - int i; - - if (!STWI_init(RFU_GAME_CONFIG)) - { - gRfuState->txParams = 6; - - //TODO: what is unk1 - packetBytes = gRfuState->txPacket->rfuPacket8.data; - packetBytes += sizeof(u32); - *(u16*)packetBytes = *(u16*)unk1; - - packetBytes += sizeof(u16); - unk1 += sizeof(u16); - - for (i = 0; i < 14; i++) - { - *packetBytes = *unk1; - packetBytes++; - unk1++; - } - - for (i = 0; i < 8; i++) - { - *packetBytes = *data; - packetBytes++; - data++; - } - - STWI_start_Command(); - } -} - -void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3) -{ - if (!STWI_init(RFU_SYSTEM_CONFIG)) - { - u8 *packetBytes; - - gRfuState->txParams = 1; - - packetBytes = gRfuState->txPacket->rfuPacket8.data; - packetBytes += sizeof(u32); - - *packetBytes++ = unk3; - *packetBytes++ = unk2; - *(u16*)packetBytes = unk1; - STWI_start_Command(); - } -} - -void STWI_send_SC_StartREQ(void) -{ - if (!STWI_init(RFU_SC_START)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_SC_PollingREQ(void) -{ - if (!STWI_init(RFU_SC_POLLING)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_SC_EndREQ(void) -{ - if (!STWI_init(RFU_SC_END)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_SP_StartREQ(void) -{ - if (!STWI_init(RFU_SP_START)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_SP_PollingREQ(void) -{ - if (!STWI_init(RFU_SP_POLLING)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_SP_EndREQ(void) -{ - if (!STWI_init(RFU_SP_END)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_CP_StartREQ(u16 unk1) -{ - if (!STWI_init(RFU_CP_START)) - { - gRfuState->txParams = 1; - gRfuState->txPacket->rfuPacket32.data[0] = unk1; - STWI_start_Command(); - } -} - -void STWI_send_CP_PollingREQ(void) -{ - if (!STWI_init(RFU_CP_POLLING)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_CP_EndREQ(void) -{ - if (!STWI_init(RFU_CP_END)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_DataTxREQ(void *in, u8 size) -{ - if (!STWI_init(RFU_DATA_TX)) - { - u8 txParams = (size / sizeof(u32)); - if (size & (sizeof(u32) - 1)) - txParams += 1; - - gRfuState->txParams = txParams; - CpuCopy32(in, gRfuState->txPacket->rfuPacket32.data, gRfuState->txParams * sizeof(u32)); - STWI_start_Command(); - } -} - -void STWI_send_DataTxAndChangeREQ(void *in, u8 size) -{ - if (!STWI_init(RFU_DATA_TX_AND_CHANGE)) - { - u8 txParams = (size / sizeof(u32)); - if (size & (sizeof(u32) - 1)) - txParams += 1; - - gRfuState->txParams = txParams; - CpuCopy32(in, gRfuState->txPacket->rfuPacket32.data, gRfuState->txParams * sizeof(u32)); - STWI_start_Command(); - } -} - -void STWI_send_DataRxREQ(void) -{ - if (!STWI_init(RFU_DATA_RX)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_MS_ChangeREQ(void) -{ - if (!STWI_init(RFU_MS_CHANGE)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_DataReadyAndChangeREQ(u8 unk) -{ - if (!STWI_init(RFU_DATA_READY_AND_CHANGE)) - { - if (!unk) - { - gRfuState->txParams = 0; - } - else - { - u8 *packetBytes; - - gRfuState->txParams = 1; - - packetBytes = gRfuState->txPacket->rfuPacket8.data; - packetBytes += sizeof(u32); - - *packetBytes++ = unk; - *packetBytes++ = 0; - *packetBytes++ = 0; - *packetBytes = 0; - } - - STWI_start_Command(); - } -} - -void STWI_send_DisconnectedAndChangeREQ(u8 unk0, u8 unk1) -{ - if (!STWI_init(RFU_DISCONNECTED_AND_CHANGE)) - { - u8 *packetBytes; - - gRfuState->txParams = 1; - - packetBytes = gRfuState->txPacket->rfuPacket8.data; - packetBytes += sizeof(u32); - - *packetBytes++ = unk0; - *packetBytes++ = unk1; - *packetBytes++ = 0; - *packetBytes = 0; - - STWI_start_Command(); - } -} - -void STWI_send_ResumeRetransmitAndChangeREQ(void) -{ - if (!STWI_init(RFU_RESUME_RETRANSMIT_AND_CHANGE)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_DisconnectREQ(u8 unk) -{ - if (!STWI_init(RFU_DISCONNECT)) - { - gRfuState->txParams = 1; - gRfuState->txPacket->rfuPacket32.data[0] = unk; - - STWI_start_Command(); - } -} - -void STWI_send_TestModeREQ(u8 unk0, u8 unk1) -{ - if (!STWI_init(RFU_TEST_MODE)) - { - gRfuState->txParams = 1; - gRfuState->txPacket->rfuPacket32.data[0] = unk0 | (unk1 << 8); - - STWI_start_Command(); - } -} - -void STWI_send_CPR_StartREQ(u16 unk0, u16 unk1, u8 unk2) -{ - u32 *packetData; - u32 arg1; - - if (!STWI_init(RFU_CPR_START)) - { - gRfuState->txParams = 2; - - arg1 = unk1 | (unk0 << 16); - packetData = gRfuState->txPacket->rfuPacket32.data; - packetData[0] = arg1; - packetData[1] = unk2; - - STWI_start_Command(); - } -} - -void STWI_send_CPR_PollingREQ(void) -{ - if (!STWI_init(RFU_CPR_POLLING)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_CPR_EndREQ(void) -{ - if (!STWI_init(RFU_CPR_END)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_send_StopModeREQ(void) -{ - if (!STWI_init(RFU_STOP_MODE)) - { - gRfuState->txParams = 0; - STWI_start_Command(); - } -} - -void STWI_intr_timer(void) -{ - switch (gRfuState->timerState) - { - //TODO: Make an enum for these - case 2: - gRfuState->timerActive = 1; - STWI_set_timer(50); - break; - case 1: - case 4: - STWI_stop_timer(); - STWI_restart_Command(); - break; - case 3: - gRfuState->timerActive = 1; - STWI_stop_timer(); - STWI_reset_ClockCounter(); - if (gRfuState->callbackM) - gRfuState->callbackM(255, 0); - break; - } -} - -void STWI_set_timer(u8 unk) -{ - vu16 *timerL; - vu16 *timerH; - - timerL = ®_TMCNT_L(gRfuState->timerSelect); - timerH = ®_TMCNT_H(gRfuState->timerSelect); - REG_IME = 0; - switch (unk) - { - case 50: - *timerL = 0xFCCB; - gRfuState->timerState = 1; - break; - case 80: - *timerL = 0xFAE0; - gRfuState->timerState = 2; - break; - case 100: - *timerL = 0xF996; - gRfuState->timerState = 3; - break; - case 130: - *timerL = 0xF7AD; - gRfuState->timerState = 4; - break; - } - *timerH = TIMER_ENABLE | TIMER_INTR_ENABLE | TIMER_1024CLK; - REG_IF = INTR_FLAG_TIMER0 << gRfuState->timerSelect; - REG_IME = 1; -} - -void STWI_stop_timer(void) -{ - gRfuState->timerState = 0; - - REG_TMCNT_L(gRfuState->timerSelect) = 0; - REG_TMCNT_H(gRfuState->timerSelect) = 0; -} - -u16 STWI_init(u8 request) -{ - if (!REG_IME) - { - gRfuState->unk_12 = 6; - if (gRfuState->callbackM) - gRfuState->callbackM(request, gRfuState->unk_12); - return TRUE; - } - else if (gRfuState->unk_2c == TRUE) - { - gRfuState->unk_12 = 2; - gRfuState->unk_2c = FALSE; - if (gRfuState->callbackM) - gRfuState->callbackM(request, gRfuState->unk_12); - return TRUE; - } - else if(!gRfuState->msMode) - { - gRfuState->unk_12 = 4; - if (gRfuState->callbackM) - gRfuState->callbackM(request, gRfuState->unk_12, gRfuState); - return TRUE; - } - else - { - gRfuState->unk_2c = TRUE; - gRfuState->activeCommand = request; - gRfuState->unk_0 = 0; - gRfuState->txParams = 0; - gRfuState->unk_5 = 0; - gRfuState->unk_7 = 0; - gRfuState->unk_8 = 0; - gRfuState->unk_9 = 0; - gRfuState->timerState = 0; - gRfuState->timerActive = 0; - gRfuState->unk_12 = 0; - gRfuState->unk_15 = 0; - - REG_RCNT = 0x100; - REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; - return FALSE; - } -} - -int STWI_start_Command() -{ - u16 imeTemp; - - // Yes, it matters that it's casted to a u32... - *(u32*)gRfuState->txPacket->rfuPacket8.data = 0x99660000 | (gRfuState->txParams << 8) | gRfuState->activeCommand; - REG_SIODATA32 = gRfuState->txPacket->rfuPacket32.command; - - gRfuState->unk_0 = 0; - gRfuState->unk_5 = 1; - - imeTemp = REG_IME; - REG_IME = 0; - REG_IE |= (INTR_FLAG_TIMER0 << gRfuState->timerSelect); - REG_IE |= INTR_FLAG_SERIAL; - REG_IME = imeTemp; - - REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_MULTI_BUSY | SIO_115200_BPS; - - return 0; -} - -int STWI_restart_Command(void) -{ - if (gRfuState->unk_15 <= 1) - { - gRfuState->unk_15++; - STWI_start_Command(); - } - else - { - if (gRfuState->activeCommand == RFU_MS_CHANGE || gRfuState->activeCommand == RFU_DATA_TX_AND_CHANGE || gRfuState->activeCommand == RFU_UNK35 || gRfuState->activeCommand == RFU_RESUME_RETRANSMIT_AND_CHANGE) - { - gRfuState->unk_12 = 1; - gRfuState->unk_2c = 0; - - if (gRfuState->callbackM) - gRfuState->callbackM(gRfuState->activeCommand, gRfuState->unk_12); - } - else - { - gRfuState->unk_12 = 1; - gRfuState->unk_2c = 0; - - if (gRfuState->callbackM) - gRfuState->callbackM(gRfuState->activeCommand, gRfuState->unk_12); - - gRfuState->unk_0 = 4; //TODO: what's 4 - } - } - - return 0; -} - -int STWI_reset_ClockCounter() -{ - gRfuState->unk_0 = 5; //TODO: what is 5 - gRfuState->txParams = 0; - gRfuState->unk_5 = 0; - REG_SIODATA32 = (1 << 31); - REG_SIOCNT = 0; - REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; - REG_SIOCNT = (SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS) + 0x7F; - - return 0; -} diff --git a/src/librfu_intr.c b/src/librfu_intr.c new file mode 100644 index 000000000..bdf8b072a --- /dev/null +++ b/src/librfu_intr.c @@ -0,0 +1,4 @@ +#include "global.h" +#include "main.h" + +//TODO: decompile asm/librfu_intr.s to here diff --git a/src/librfu_rfu.c b/src/librfu_rfu.c new file mode 100644 index 000000000..cf3fe12ad --- /dev/null +++ b/src/librfu_rfu.c @@ -0,0 +1,109 @@ +#include "global.h" +#include "main.h" + +#include "librfu.h" + +struct RfuUnk1 +{ + u8 unk_0[0x14]; + u32 unk_14; + u32 unk_18; + struct RfuIntrStruct unk_1c; +}; + +struct RfuUnk2 +{ + u8 unk_0[0x68]; + u32 unk_68; + u32 unk_6c; + u8 unk_70[0x70]; +}; + +struct RfuUnk3 +{ + u32 unk_0; + u32 unk_4; + u8 unk_8[0xD4]; + u32 unk_dc; +}; + +extern u32 *gUnknown_03007890; +extern u32 *gUnknown_03007894; +extern struct RfuUnk3* gUnknown_03007898; +extern struct RfuUnk2* gUnknown_03007880[4]; +extern struct RfuUnk1* gUnknown_03007870[4]; +extern void* sub_82E53F4; +extern void rfu_STC_clearAPIVariables(void); + +// Nonmatching, only register differences +/*u16 rfu_initializeAPI(u32 *unk0, u16 unk1, IntrFunc *interrupt, bool8 copyInterruptToRam) +{ + u16 i; + u16 *v13; + u16 *v12; + u16 num; + + if (((u32)unk0 & 0xF000000) == 0x2000000 && copyInterruptToRam) + { + return 2; + } + + if ((u32)unk0 & 3) + return 2; + + // Nintendo pls, just use a ternary for once + if (copyInterruptToRam) + { + // An assert/debug print may have existed before, ie + // printf("%s %u < %u", "somefile.c:12345", unk1, num) + // to push this into r3? + num = 0xe64; + if (unk1 < num) + return 1; + } + + if (copyInterruptToRam == FALSE) + { + num = 0x504; // same as above, this should be r3 not r0 + if (unk1 < num) + return 1; + } + gUnknown_03007890 = unk0; + gUnknown_03007894 = unk0 + (0xB4 / sizeof(u32)); + gUnknown_03007898 = (struct RfuUnk3*)(unk0 + (0xDC / sizeof(u32))); + gUnknown_03007880[0] = (struct RfuUnk2*)(unk0 + (0x1BC / sizeof(u32))); + gUnknown_03007870[0] = (struct RfuUnk1*)(unk0 + (0x37C / sizeof(u32))); + + for (i = 1; i < 4; i++, num) + { + gUnknown_03007880[i] = (struct RfuUnk2*)&gUnknown_03007880[i-1]->unk_70; + gUnknown_03007870[i] = (struct RfuUnk1*)&gUnknown_03007870[i-1]->unk_1c; + } + + gUnknown_03007898->unk_dc = (u32)&gUnknown_03007870[3]->unk_1c; + STWI_init_all(&gUnknown_03007870[3]->unk_1c, interrupt, copyInterruptToRam); + rfu_STC_clearAPIVariables(); + + for (i = 0; i < 4; i++) + { + gUnknown_03007880[i]->unk_68 = 0; + gUnknown_03007880[i]->unk_6c = 0; + gUnknown_03007870[i]->unk_14 = 0; + gUnknown_03007870[i]->unk_18 = 0; + } + + // Not matching, register differences + v12 = (u16*)((u32)&sub_82E53F4 & ~1); + v13 = (u16*)gUnknown_03007898->unk_8; + + for (i = 47; i != 0xFFFF; i--) + { + *v13 = *v12; + ++v12; + ++v13; + } + + gUnknown_03007898->unk_4 = (u32)(&gUnknown_03007898->unk_8[1]); + + return 0; +}*/ diff --git a/src/librfu_stwi.c b/src/librfu_stwi.c new file mode 100644 index 000000000..21d38bb38 --- /dev/null +++ b/src/librfu_stwi.c @@ -0,0 +1,687 @@ +#include "global.h" +#include "librfu.h" + +extern IntrFunc IntrSIO32(void); + +extern void STWI_stop_timer(void); + +void STWI_init_Callback_M(void); +void STWI_init_Callback_S(void); +void STWI_set_Callback_M(void * callback); +void STWI_set_Callback_S(void * callback); +u16 STWI_init(u8 request); +int STWI_start_Command(void); +void STWI_intr_timer(void); +void STWI_set_timer(u8 unk); + +int STWI_restart_Command(void); +int STWI_reset_ClockCounter(void); + +void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam) +{ + // If we're copying our interrupt into RAM, DMA it to block1 and use + // block2 for our RfuStruct, otherwise block1 holds the RfuStruct. + // interrupt usually is a pointer to gIntrTable[1] + if (copyInterruptToRam == TRUE) + { + *interrupt = (IntrFunc)interruptStruct->block1; + DmaCopy16(3, &IntrSIO32, interruptStruct->block1, 0x960); + gRfuState = (struct RfuStruct*)interruptStruct->block2; + } + else + { + *interrupt = (IntrFunc)IntrSIO32; + gRfuState = (struct RfuStruct*)interruptStruct->block1; + } + + gRfuState->rxPacket = (union RfuPacket*)interruptStruct->rxPacketAlloc; + gRfuState->txPacket = (union RfuPacket*)interruptStruct->txPacketAlloc; + gRfuState->msMode = 1; + gRfuState->unk_0 = 0; + gRfuState->txParams = 0; + gRfuState->unk_5 = 0; + gRfuState->unk_7 = 0; + gRfuState->unk_8 = 0; + gRfuState->unk_9 = 0; + gRfuState->timerState = 0; + gRfuState->timerActive = 0; + gRfuState->unk_12 = 0; + gRfuState->unk_15 = 0; + gRfuState->unk_2c = 0; + + 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(); + + IntrEnable(INTR_FLAG_SERIAL); +} + +void STWI_init_timer(IntrFunc *interrupt, int timerSelect) +{ + *interrupt = STWI_intr_timer; + gRfuState->timerSelect = timerSelect; + + IntrEnable(INTR_FLAG_TIMER0 << gRfuState->timerSelect); +} + +void AgbRFU_SoftReset(void) +{ + vu16 *timerL; + vu16 *timerH; + + REG_RCNT = 0x8000; + REG_RCNT = 0x80A0; // all these bits are undocumented + timerL = ®_TMCNT_L(gRfuState->timerSelect); + timerH = ®_TMCNT_H(gRfuState->timerSelect); + *timerH = 0; + *timerL = 0; + *timerH = 0x83; + while (*timerL <= 0x11) + REG_RCNT = 0x80A2; + *timerH = 3; + REG_RCNT = 0x80A0; + REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; + + gRfuState->unk_0 = 0; + gRfuState->txParams = 0; + gRfuState->unk_5 = 0; + gRfuState->activeCommand = 0; + gRfuState->unk_7 = 0; + gRfuState->unk_8 = 0; + gRfuState->unk_9 = 0; + gRfuState->timerState = 0; + gRfuState->timerActive = 0; + gRfuState->unk_12 = 0; + gRfuState->msMode = 1; + gRfuState->unk_15 = 0; + gRfuState->unk_2c = 0; +} + +void STWI_set_MS_mode(u8 mode) +{ + gRfuState->msMode = mode; +} + +u16 STWI_read_status(u8 index) +{ + switch (index) + { + case 0: + return gRfuState->unk_12; + case 1: + return gRfuState->msMode; + case 2: + return gRfuState->unk_0; + case 3: + return gRfuState->activeCommand; + default: + return 0xFFFF; + } +} + +void STWI_init_Callback_M(void) +{ + STWI_set_Callback_M(0); +} + +void STWI_init_Callback_S(void) +{ + STWI_set_Callback_S(0); +} + +void STWI_set_Callback_M(void *callback) +{ + gRfuState->callbackM = callback; +} + +void STWI_set_Callback_S(void *callback) +{ + gRfuState->callbackS = callback; +} + +void STWI_set_Callback_ID(u32 id) +{ + gRfuState->callbackID = id; +} + +u16 STWI_poll_CommandEnd(void) +{ + while (gRfuState->unk_2c == TRUE) + ; + return gRfuState->unk_12; +} + +void STWI_send_ResetREQ(void) +{ + if (!STWI_init(RFU_RESET)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_LinkStatusREQ(void) +{ + if (!STWI_init(RFU_LINK_STATUS)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_VersionStatusREQ(void) +{ + if (!STWI_init(RFU_VERSION_STATUS)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_SystemStatusREQ(void) +{ + if (!STWI_init(RFU_SYSTEM_STATUS)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_SlotStatusREQ(void) +{ + if (!STWI_init(RFU_SLOT_STATUS)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_ConfigStatusREQ(void) +{ + if (!STWI_init(RFU_CONFIG_STATUS)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_GameConfigREQ(u8 * unk1, u8 *data) +{ + u8 *packetBytes; + int i; + + if (!STWI_init(RFU_GAME_CONFIG)) + { + gRfuState->txParams = 6; + + //TODO: what is unk1 + packetBytes = gRfuState->txPacket->rfuPacket8.data; + packetBytes += sizeof(u32); + *(u16*)packetBytes = *(u16*)unk1; + + packetBytes += sizeof(u16); + unk1 += sizeof(u16); + + for (i = 0; i < 14; i++) + { + *packetBytes = *unk1; + packetBytes++; + unk1++; + } + + for (i = 0; i < 8; i++) + { + *packetBytes = *data; + packetBytes++; + data++; + } + + STWI_start_Command(); + } +} + +void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3) +{ + if (!STWI_init(RFU_SYSTEM_CONFIG)) + { + u8 *packetBytes; + + gRfuState->txParams = 1; + + packetBytes = gRfuState->txPacket->rfuPacket8.data; + packetBytes += sizeof(u32); + + *packetBytes++ = unk3; + *packetBytes++ = unk2; + *(u16*)packetBytes = unk1; + STWI_start_Command(); + } +} + +void STWI_send_SC_StartREQ(void) +{ + if (!STWI_init(RFU_SC_START)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_SC_PollingREQ(void) +{ + if (!STWI_init(RFU_SC_POLLING)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_SC_EndREQ(void) +{ + if (!STWI_init(RFU_SC_END)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_SP_StartREQ(void) +{ + if (!STWI_init(RFU_SP_START)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_SP_PollingREQ(void) +{ + if (!STWI_init(RFU_SP_POLLING)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_SP_EndREQ(void) +{ + if (!STWI_init(RFU_SP_END)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_CP_StartREQ(u16 unk1) +{ + if (!STWI_init(RFU_CP_START)) + { + gRfuState->txParams = 1; + gRfuState->txPacket->rfuPacket32.data[0] = unk1; + STWI_start_Command(); + } +} + +void STWI_send_CP_PollingREQ(void) +{ + if (!STWI_init(RFU_CP_POLLING)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_CP_EndREQ(void) +{ + if (!STWI_init(RFU_CP_END)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_DataTxREQ(void *in, u8 size) +{ + if (!STWI_init(RFU_DATA_TX)) + { + u8 txParams = (size / sizeof(u32)); + if (size & (sizeof(u32) - 1)) + txParams += 1; + + gRfuState->txParams = txParams; + CpuCopy32(in, gRfuState->txPacket->rfuPacket32.data, gRfuState->txParams * sizeof(u32)); + STWI_start_Command(); + } +} + +void STWI_send_DataTxAndChangeREQ(void *in, u8 size) +{ + if (!STWI_init(RFU_DATA_TX_AND_CHANGE)) + { + u8 txParams = (size / sizeof(u32)); + if (size & (sizeof(u32) - 1)) + txParams += 1; + + gRfuState->txParams = txParams; + CpuCopy32(in, gRfuState->txPacket->rfuPacket32.data, gRfuState->txParams * sizeof(u32)); + STWI_start_Command(); + } +} + +void STWI_send_DataRxREQ(void) +{ + if (!STWI_init(RFU_DATA_RX)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_MS_ChangeREQ(void) +{ + if (!STWI_init(RFU_MS_CHANGE)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_DataReadyAndChangeREQ(u8 unk) +{ + if (!STWI_init(RFU_DATA_READY_AND_CHANGE)) + { + if (!unk) + { + gRfuState->txParams = 0; + } + else + { + u8 *packetBytes; + + gRfuState->txParams = 1; + + packetBytes = gRfuState->txPacket->rfuPacket8.data; + packetBytes += sizeof(u32); + + *packetBytes++ = unk; + *packetBytes++ = 0; + *packetBytes++ = 0; + *packetBytes = 0; + } + + STWI_start_Command(); + } +} + +void STWI_send_DisconnectedAndChangeREQ(u8 unk0, u8 unk1) +{ + if (!STWI_init(RFU_DISCONNECTED_AND_CHANGE)) + { + u8 *packetBytes; + + gRfuState->txParams = 1; + + packetBytes = gRfuState->txPacket->rfuPacket8.data; + packetBytes += sizeof(u32); + + *packetBytes++ = unk0; + *packetBytes++ = unk1; + *packetBytes++ = 0; + *packetBytes = 0; + + STWI_start_Command(); + } +} + +void STWI_send_ResumeRetransmitAndChangeREQ(void) +{ + if (!STWI_init(RFU_RESUME_RETRANSMIT_AND_CHANGE)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_DisconnectREQ(u8 unk) +{ + if (!STWI_init(RFU_DISCONNECT)) + { + gRfuState->txParams = 1; + gRfuState->txPacket->rfuPacket32.data[0] = unk; + + STWI_start_Command(); + } +} + +void STWI_send_TestModeREQ(u8 unk0, u8 unk1) +{ + if (!STWI_init(RFU_TEST_MODE)) + { + gRfuState->txParams = 1; + gRfuState->txPacket->rfuPacket32.data[0] = unk0 | (unk1 << 8); + + STWI_start_Command(); + } +} + +void STWI_send_CPR_StartREQ(u16 unk0, u16 unk1, u8 unk2) +{ + u32 *packetData; + u32 arg1; + + if (!STWI_init(RFU_CPR_START)) + { + gRfuState->txParams = 2; + + arg1 = unk1 | (unk0 << 16); + packetData = gRfuState->txPacket->rfuPacket32.data; + packetData[0] = arg1; + packetData[1] = unk2; + + STWI_start_Command(); + } +} + +void STWI_send_CPR_PollingREQ(void) +{ + if (!STWI_init(RFU_CPR_POLLING)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_CPR_EndREQ(void) +{ + if (!STWI_init(RFU_CPR_END)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_send_StopModeREQ(void) +{ + if (!STWI_init(RFU_STOP_MODE)) + { + gRfuState->txParams = 0; + STWI_start_Command(); + } +} + +void STWI_intr_timer(void) +{ + switch (gRfuState->timerState) + { + //TODO: Make an enum for these + case 2: + gRfuState->timerActive = 1; + STWI_set_timer(50); + break; + case 1: + case 4: + STWI_stop_timer(); + STWI_restart_Command(); + break; + case 3: + gRfuState->timerActive = 1; + STWI_stop_timer(); + STWI_reset_ClockCounter(); + if (gRfuState->callbackM) + gRfuState->callbackM(255, 0); + break; + } +} + +void STWI_set_timer(u8 unk) +{ + vu16 *timerL; + vu16 *timerH; + + timerL = ®_TMCNT_L(gRfuState->timerSelect); + timerH = ®_TMCNT_H(gRfuState->timerSelect); + REG_IME = 0; + switch (unk) + { + case 50: + *timerL = 0xFCCB; + gRfuState->timerState = 1; + break; + case 80: + *timerL = 0xFAE0; + gRfuState->timerState = 2; + break; + case 100: + *timerL = 0xF996; + gRfuState->timerState = 3; + break; + case 130: + *timerL = 0xF7AD; + gRfuState->timerState = 4; + break; + } + *timerH = TIMER_ENABLE | TIMER_INTR_ENABLE | TIMER_1024CLK; + REG_IF = INTR_FLAG_TIMER0 << gRfuState->timerSelect; + REG_IME = 1; +} + +void STWI_stop_timer(void) +{ + gRfuState->timerState = 0; + + REG_TMCNT_L(gRfuState->timerSelect) = 0; + REG_TMCNT_H(gRfuState->timerSelect) = 0; +} + +u16 STWI_init(u8 request) +{ + if (!REG_IME) + { + gRfuState->unk_12 = 6; + if (gRfuState->callbackM) + gRfuState->callbackM(request, gRfuState->unk_12); + return TRUE; + } + else if (gRfuState->unk_2c == TRUE) + { + gRfuState->unk_12 = 2; + gRfuState->unk_2c = FALSE; + if (gRfuState->callbackM) + gRfuState->callbackM(request, gRfuState->unk_12); + return TRUE; + } + else if(!gRfuState->msMode) + { + gRfuState->unk_12 = 4; + if (gRfuState->callbackM) + gRfuState->callbackM(request, gRfuState->unk_12, gRfuState); + return TRUE; + } + else + { + gRfuState->unk_2c = TRUE; + gRfuState->activeCommand = request; + gRfuState->unk_0 = 0; + gRfuState->txParams = 0; + gRfuState->unk_5 = 0; + gRfuState->unk_7 = 0; + gRfuState->unk_8 = 0; + gRfuState->unk_9 = 0; + gRfuState->timerState = 0; + gRfuState->timerActive = 0; + gRfuState->unk_12 = 0; + gRfuState->unk_15 = 0; + + REG_RCNT = 0x100; + REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; + return FALSE; + } +} + +int STWI_start_Command() +{ + u16 imeTemp; + + // Yes, it matters that it's casted to a u32... + *(u32*)gRfuState->txPacket->rfuPacket8.data = 0x99660000 | (gRfuState->txParams << 8) | gRfuState->activeCommand; + REG_SIODATA32 = gRfuState->txPacket->rfuPacket32.command; + + gRfuState->unk_0 = 0; + gRfuState->unk_5 = 1; + + imeTemp = REG_IME; + REG_IME = 0; + REG_IE |= (INTR_FLAG_TIMER0 << gRfuState->timerSelect); + REG_IE |= INTR_FLAG_SERIAL; + REG_IME = imeTemp; + + REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_MULTI_BUSY | SIO_115200_BPS; + + return 0; +} + +int STWI_restart_Command(void) +{ + if (gRfuState->unk_15 <= 1) + { + gRfuState->unk_15++; + STWI_start_Command(); + } + else + { + if (gRfuState->activeCommand == RFU_MS_CHANGE || gRfuState->activeCommand == RFU_DATA_TX_AND_CHANGE || gRfuState->activeCommand == RFU_UNK35 || gRfuState->activeCommand == RFU_RESUME_RETRANSMIT_AND_CHANGE) + { + gRfuState->unk_12 = 1; + gRfuState->unk_2c = 0; + + if (gRfuState->callbackM) + gRfuState->callbackM(gRfuState->activeCommand, gRfuState->unk_12); + } + else + { + gRfuState->unk_12 = 1; + gRfuState->unk_2c = 0; + + if (gRfuState->callbackM) + gRfuState->callbackM(gRfuState->activeCommand, gRfuState->unk_12); + + gRfuState->unk_0 = 4; //TODO: what's 4 + } + } + + return 0; +} + +int STWI_reset_ClockCounter() +{ + gRfuState->unk_0 = 5; //TODO: what is 5 + gRfuState->txParams = 0; + gRfuState->unk_5 = 0; + REG_SIODATA32 = (1 << 31); + REG_SIOCNT = 0; + REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; + REG_SIOCNT = (SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS) + 0x7F; + + return 0; +} -- cgit v1.2.3 From a43d6d4a53717d26480872ed5e0c1e806170091a Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 21 Oct 2017 23:20:50 -0400 Subject: review changes --- src/clear_save_data_screen.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/clear_save_data_screen.c b/src/clear_save_data_screen.c index 4e3b12992..3192e0e11 100755 --- a/src/clear_save_data_screen.c +++ b/src/clear_save_data_screen.c @@ -11,9 +11,6 @@ #include "text_window.h" #include "songs.h" -extern void CreateYesNoMenu(const struct WindowTemplate *windowTemplate, u16 borderFirstTileNum, u8 borderPalette, u8 initialCursorPos); // menu.s -extern s8 sub_8198C58(void); // menu.s - extern u8 gText_ClearAllSaveData[]; extern u8 gText_ClearingData[]; @@ -134,17 +131,17 @@ static bool8 SetupClearSaveDataScreen(void) default: SetVBlankCallback(NULL); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0); - SetGpuReg(REG_OFFSET_BG0HOFS, DISPCNT_MODE_0); - SetGpuReg(REG_OFFSET_BG0VOFS, DISPCNT_MODE_0); - SetGpuReg(REG_OFFSET_BG3HOFS, DISPCNT_MODE_0); - SetGpuReg(REG_OFFSET_BG3VOFS, DISPCNT_MODE_0); - SetGpuReg(REG_OFFSET_WIN0H, DISPCNT_MODE_0); - SetGpuReg(REG_OFFSET_WIN0V, DISPCNT_MODE_0); - SetGpuReg(REG_OFFSET_WININ, DISPCNT_MODE_0); - SetGpuReg(REG_OFFSET_WINOUT, DISPCNT_MODE_0); - SetGpuReg(REG_OFFSET_BLDCNT, DISPCNT_MODE_0); - SetGpuReg(REG_OFFSET_BLDALPHA, DISPCNT_MODE_0); - SetGpuReg(REG_OFFSET_BLDY, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + SetGpuReg(REG_OFFSET_BG3HOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); + SetGpuReg(REG_OFFSET_WIN0H, 0); + SetGpuReg(REG_OFFSET_WIN0V, 0); + SetGpuReg(REG_OFFSET_WININ, 0); + SetGpuReg(REG_OFFSET_WINOUT, 0); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 0); DmaFill16(3, 0, (void *)VRAM, VRAM_SIZE); DmaFill32(3, 0, (void *)OAM, OAM_SIZE); DmaFill16(3, 0, (void *)(PLTT + 2), PLTT_SIZE - 2); @@ -165,7 +162,7 @@ static bool8 SetupClearSaveDataScreen(void) SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); ShowBg(0); ShowBg(3); - SetGpuReg(REG_OFFSET_BLDCNT, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BLDCNT, 0); InitClearSaveDataScreenWindows(); BeginNormalPaletteFade(0x0000FFFF, 0, 0x10, 0, 0xFFFF); EnableInterrupts(1); -- cgit v1.2.3