Decompile to STWI_init

This commit is contained in:
shinyquagsire23 2017-09-11 17:04:13 -06:00
parent ce08f34ed5
commit 3c51ecded9
2 changed files with 128 additions and 292 deletions

View File

@ -4,283 +4,6 @@
.text
thumb_func_start STWI_intr_timer
STWI_intr_timer: @ 82E3214
push {r4,lr}
ldr r4, _082E322C
ldr r1, [r4]
ldr r0, [r1, 0xC]
cmp r0, 0x2
beq _082E323A
cmp r0, 0x2
bgt _082E3230
cmp r0, 0x1
beq _082E3248
b _082E3270
.align 2, 0
_082E322C: .4byte gRfuState
_082E3230:
cmp r0, 0x3
beq _082E3252
cmp r0, 0x4
beq _082E3248
b _082E3270
_082E323A:
ldrb r0, [r1, 0x10]
movs r0, 0x1
strb r0, [r1, 0x10]
movs r0, 0x32
bl STWI_set_timer
b _082E3270
_082E3248:
bl STWI_stop_timer
bl STWI_restart_Command
b _082E3270
_082E3252:
ldrb r0, [r1, 0x10]
movs r0, 0x1
strb r0, [r1, 0x10]
bl STWI_stop_timer
bl STWI_reset_ClockCounter
ldr r0, [r4]
ldr r2, [r0, 0x18]
cmp r2, 0
beq _082E3270
movs r0, 0xFF
movs r1, 0
bl _call_via_r2
_082E3270:
pop {r4}
pop {r0}
bx r0
thumb_func_end STWI_intr_timer
thumb_func_start STWI_set_timer
STWI_set_timer: @ 82E3278
push {r4-r7,lr}
lsls r0, 24
lsrs r3, r0, 24
adds r5, r3, 0
ldr r2, _082E32A8
ldr r0, [r2]
ldrb r0, [r0, 0xA]
lsls r0, 2
ldr r1, _082E32AC
adds r4, r0, r1
adds r1, 0x2
adds r7, r0, r1
ldr r1, _082E32B0
movs r0, 0
strh r0, [r1]
adds r6, r2, 0
cmp r3, 0x50
beq _082E32D0
cmp r3, 0x50
bgt _082E32B4
cmp r3, 0x32
beq _082E32BE
b _082E32FC
.align 2, 0
_082E32A8: .4byte gRfuState
_082E32AC: .4byte 0x04000100
_082E32B0: .4byte 0x04000208
_082E32B4:
cmp r5, 0x64
beq _082E32E0
cmp r5, 0x82
beq _082E32F0
b _082E32FC
_082E32BE:
ldr r1, _082E32CC
adds r0, r1, 0
strh r0, [r4]
ldr r1, [r6]
movs r0, 0x1
b _082E32FA
.align 2, 0
_082E32CC: .4byte 0x0000fccb
_082E32D0:
ldr r1, _082E32DC
adds r0, r1, 0
strh r0, [r4]
ldr r1, [r6]
movs r0, 0x2
b _082E32FA
.align 2, 0
_082E32DC: .4byte 0x0000fae0
_082E32E0:
ldr r1, _082E32EC
adds r0, r1, 0
strh r0, [r4]
ldr r1, [r6]
movs r0, 0x3
b _082E32FA
.align 2, 0
_082E32EC: .4byte 0x0000f996
_082E32F0:
ldr r1, _082E3318
adds r0, r1, 0
strh r0, [r4]
ldr r1, [r6]
movs r0, 0x4
_082E32FA:
str r0, [r1, 0xC]
_082E32FC:
movs r0, 0xC3
strh r0, [r7]
ldr r2, _082E331C
ldr r1, [r6]
movs r0, 0x8
ldrb r1, [r1, 0xA]
lsls r0, r1
strh r0, [r2]
ldr r1, _082E3320
movs r0, 0x1
strh r0, [r1]
pop {r4-r7}
pop {r0}
bx r0
.align 2, 0
_082E3318: .4byte 0x0000f7ad
_082E331C: .4byte 0x04000202
_082E3320: .4byte 0x04000208
thumb_func_end STWI_set_timer
thumb_func_start STWI_stop_timer
STWI_stop_timer: @ 82E3324
ldr r2, _082E3344
ldr r0, [r2]
movs r1, 0
str r1, [r0, 0xC]
ldrb r0, [r0, 0xA]
lsls r0, 2
ldr r3, _082E3348
adds r0, r3
strh r1, [r0]
ldr r0, [r2]
ldrb r0, [r0, 0xA]
lsls r0, 2
ldr r2, _082E334C
adds r0, r2
strh r1, [r0]
bx lr
.align 2, 0
_082E3344: .4byte gRfuState
_082E3348: .4byte 0x04000100
_082E334C: .4byte 0x04000102
thumb_func_end STWI_stop_timer
thumb_func_start STWI_init
STWI_init: @ 82E3350
push {r4-r6,lr}
lsls r0, 24
lsrs r5, r0, 24
adds r6, r5, 0
ldr r0, _082E337C
ldrh r0, [r0]
cmp r0, 0
bne _082E3384
ldr r0, _082E3380
ldr r1, [r0]
ldrh r0, [r1, 0x12]
movs r0, 0x6
strh r0, [r1, 0x12]
ldr r2, [r1, 0x18]
cmp r2, 0
beq _082E33CE
ldrh r1, [r1, 0x12]
adds r0, r5, 0
bl _call_via_r2
b _082E33CE
.align 2, 0
_082E337C: .4byte 0x04000208
_082E3380: .4byte gRfuState
_082E3384:
ldr r4, _082E33B0
ldr r2, [r4]
adds r3, r2, 0
adds r3, 0x2C
ldrb r0, [r3]
cmp r0, 0x1
bne _082E33B4
ldrh r0, [r2, 0x12]
movs r1, 0
movs r0, 0x2
strh r0, [r2, 0x12]
ldrb r0, [r3]
strb r1, [r3]
ldr r0, [r4]
ldr r2, [r0, 0x18]
cmp r2, 0
beq _082E33CE
ldrh r1, [r0, 0x12]
adds r0, r5, 0
bl _call_via_r2
b _082E33CE
.align 2, 0
_082E33B0: .4byte gRfuState
_082E33B4:
ldrb r0, [r2, 0x14]
cmp r0, 0
bne _082E33D2
ldrh r0, [r2, 0x12]
movs r0, 0x4
strh r0, [r2, 0x12]
ldr r3, [r2, 0x18]
cmp r3, 0
beq _082E33CE
ldrh r1, [r2, 0x12]
adds r0, r5, 0
bl _call_via_r3
_082E33CE:
movs r0, 0x1
b _082E341A
_082E33D2:
ldrb r0, [r3]
movs r1, 0
movs r0, 0x1
strb r0, [r3]
ldr r0, [r4]
strb r6, [r0, 0x6]
ldr r0, [r4]
str r1, [r0]
strb r1, [r0, 0x4]
ldr r0, [r4]
strb r1, [r0, 0x5]
ldr r0, [r4]
strb r1, [r0, 0x7]
ldr r0, [r4]
strb r1, [r0, 0x8]
ldr r0, [r4]
strb r1, [r0, 0x9]
ldr r0, [r4]
str r1, [r0, 0xC]
ldrb r2, [r0, 0x10]
strb r1, [r0, 0x10]
ldr r0, [r4]
ldrh r2, [r0, 0x12]
movs r2, 0
strh r1, [r0, 0x12]
strb r2, [r0, 0x15]
ldr r1, _082E3420
movs r2, 0x80
lsls r2, 1
adds r0, r2, 0
strh r0, [r1]
subs r1, 0xC
ldr r2, _082E3424
adds r0, r2, 0
strh r0, [r1]
movs r0, 0
_082E341A:
pop {r4-r6}
pop {r1}
bx r1
.align 2, 0
_082E3420: .4byte 0x04000134
_082E3424: .4byte 0x00005003
thumb_func_end STWI_init
thumb_func_start STWI_start_Command
STWI_start_Command: @ 82E3428
push {r4,r5,lr}

View File

@ -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 = &REG_TMCNT_L(gRfuState->timerSelect);
timerH = &REG_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;
}
}