diff --git a/asm/clear_save_data_screen.s b/asm/clear_save_data_screen.s deleted file mode 100644 index 5efff250c9..0000000000 --- a/asm/clear_save_data_screen.s +++ /dev/null @@ -1,399 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start c2_clear_save_data_screen_2 -c2_clear_save_data_screen_2: @ 817ACC8 - push {lr} - bl sub_817AE00 - lsls r0, 24 - cmp r0, 0 - beq _0817ACDC - ldr r0, =sub_817ACE4 - movs r1, 0 - bl CreateTask -_0817ACDC: - pop {r0} - bx r0 - .pool - thumb_func_end c2_clear_save_data_screen_2 - - thumb_func_start sub_817ACE4 -sub_817ACE4: @ 817ACE4 - push {r4,lr} - sub sp, 0xC - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - movs r0, 0 - movs r1, 0 - movs r2, 0x2 - movs r3, 0xE - bl SetWindowBorderStyle - ldr r2, =gText_ClearAllSaveData - movs r0, 0x1 - str r0, [sp] - movs r0, 0 - str r0, [sp, 0x4] - str r0, [sp, 0x8] - movs r1, 0x1 - movs r3, 0 - bl PrintTextOnWindow - ldr r0, =gUnknown_085F06D8 - movs r1, 0x2 - movs r2, 0xE - movs r3, 0x1 - bl CreateYesNoMenu - ldr r1, =gTasks - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - adds r0, r1 - ldr r1, =sub_817AD40 - str r1, [r0] - add sp, 0xC - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_817ACE4 - - thumb_func_start sub_817AD40 -sub_817AD40: @ 817AD40 - push {r4,r5,lr} - sub sp, 0xC - lsls r0, 24 - lsrs r5, r0, 24 - bl sub_8198C58 - lsls r0, 24 - asrs r4, r0, 24 - cmp r4, 0 - beq _0817AD68 - cmp r4, 0 - bgt _0817AD62 - movs r0, 0x1 - negs r0, r0 - cmp r4, r0 - beq _0817ADA0 - b _0817ADB2 -_0817AD62: - cmp r4, 0x1 - beq _0817ADA0 - b _0817ADB2 -_0817AD68: - movs r0, 0 - movs r1, 0x11 - bl FillWindowPixelBuffer - ldr r2, =gText_ClearingData - movs r0, 0x1 - str r0, [sp] - str r4, [sp, 0x4] - str r4, [sp, 0x8] - movs r0, 0 - movs r1, 0x1 - movs r3, 0 - bl PrintTextOnWindow - ldr r1, =gTasks - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - adds r0, r1 - ldr r1, =sub_817ADC0 - str r1, [r0] - b _0817ADB2 - .pool -_0817ADA0: - movs r0, 0x5 - bl PlaySE - adds r0, r5, 0 - bl DestroyTask - ldr r0, =sub_817AFD4 - bl SetMainCallback2 -_0817ADB2: - add sp, 0xC - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_817AD40 - - thumb_func_start sub_817ADC0 -sub_817ADC0: @ 817ADC0 - push {r4,lr} - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - bl ClearSaveData - adds r0, r4, 0 - bl DestroyTask - ldr r0, =sub_817AFD4 - bl SetMainCallback2 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_817ADC0 - - thumb_func_start sub_817ADE4 -sub_817ADE4: @ 817ADE4 - push {lr} - bl RunTasks - bl UpdatePaletteFade - pop {r0} - bx r0 - thumb_func_end sub_817ADE4 - - thumb_func_start sub_817ADF4 -sub_817ADF4: @ 817ADF4 - push {lr} - bl TransferPlttBuffer - pop {r0} - bx r0 - thumb_func_end sub_817ADF4 - - thumb_func_start sub_817AE00 -sub_817AE00: @ 817AE00 - push {r4,lr} - sub sp, 0xC - ldr r0, =gMain - movs r1, 0x87 - lsls r1, 3 - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0 - beq _0817AE18 - cmp r0, 0x1 - bne _0817AE18 - b _0817AFA4 -_0817AE18: - movs r0, 0 - bl SetVBlankCallback - movs r0, 0 - movs r1, 0 - bl SetGpuReg - movs r0, 0x10 - movs r1, 0 - bl SetGpuReg - movs r0, 0x12 - movs r1, 0 - bl SetGpuReg - movs r0, 0x1C - movs r1, 0 - bl SetGpuReg - movs r0, 0x1E - movs r1, 0 - bl SetGpuReg - movs r0, 0x40 - movs r1, 0 - bl SetGpuReg - movs r0, 0x44 - movs r1, 0 - bl SetGpuReg - movs r0, 0x48 - movs r1, 0 - bl SetGpuReg - movs r0, 0x4A - movs r1, 0 - bl SetGpuReg - movs r0, 0x50 - movs r1, 0 - bl SetGpuReg - movs r0, 0x52 - movs r1, 0 - bl SetGpuReg - movs r0, 0x54 - movs r1, 0 - bl SetGpuReg - add r0, sp, 0x4 - movs r4, 0 - strh r4, [r0] - ldr r1, =0x040000d4 - str r0, [r1] - movs r0, 0xC0 - lsls r0, 19 - str r0, [r1, 0x4] - ldr r0, =0x8100c000 - str r0, [r1, 0x8] - ldr r0, [r1, 0x8] - movs r2, 0 - str r2, [sp, 0x8] - add r0, sp, 0x8 - str r0, [r1] - movs r0, 0xE0 - lsls r0, 19 - str r0, [r1, 0x4] - ldr r0, =0x85000100 - str r0, [r1, 0x8] - ldr r0, [r1, 0x8] - add r0, sp, 0x4 - strh r2, [r0] - str r0, [r1] - ldr r0, =0x05000002 - str r0, [r1, 0x4] - ldr r0, =0x810001ff - str r0, [r1, 0x8] - ldr r0, [r1, 0x8] - bl ResetPaletteFade - ldr r2, =gPlttBufferUnfaded - ldr r0, =0x00007fff - strh r0, [r2] - ldr r1, =gPlttBufferFaded - strh r0, [r1] - ldr r0, =0x00003945 - strh r0, [r2, 0x2] - strh r0, [r1, 0x2] - movs r1, 0 - ldr r3, =0x06000020 - ldr r0, =0x00001111 - adds r2, r0, 0 -_0817AED4: - lsls r0, r1, 1 - adds r0, r3 - strh r2, [r0] - adds r0, r1, 0x1 - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0xF - bls _0817AED4 - movs r1, 0 - ldr r4, =0x0600f000 - movs r3, 0x1 - ldr r2, =0x000003ff -_0817AEEC: - lsls r0, r1, 1 - adds r0, r4 - strh r3, [r0] - adds r0, r1, 0x1 - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, r2 - bls _0817AEEC - bl ResetTasks - bl ResetSpriteData - movs r0, 0 - bl ResetBgsAndClearDma3BusyFlags - ldr r1, =gUnknown_085F06C0 - movs r0, 0 - movs r2, 0x2 - bl InitBgsFromTemplates - movs r1, 0x82 - lsls r1, 5 - movs r0, 0 - bl SetGpuReg - movs r0, 0 - bl ShowBg - movs r0, 0x3 - bl ShowBg - movs r0, 0x50 - movs r1, 0 - bl SetGpuReg - bl sub_817B02C - ldr r0, =0x0000ffff - str r0, [sp] - movs r1, 0 - movs r2, 0x10 - movs r3, 0 - bl BeginNormalPaletteFade - movs r0, 0x1 - bl EnableInterrupts - ldr r0, =sub_817ADF4 - bl SetVBlankCallback - ldr r0, =gMain - movs r1, 0x87 - lsls r1, 3 - adds r0, r1 - movs r1, 0x1 - strb r1, [r0] - b _0817AFC8 - .pool -_0817AFA4: - bl UpdatePaletteFade - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - bne _0817AFC8 - ldr r0, =sub_817ADE4 - bl SetMainCallback2 - movs r0, 0x1 - b _0817AFCA - .pool -_0817AFC8: - movs r0, 0 -_0817AFCA: - add sp, 0xC - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_817AE00 - - thumb_func_start sub_817AFD4 -sub_817AFD4: @ 817AFD4 - push {r4,lr} - sub sp, 0x4 - ldr r0, =gMain - movs r1, 0x87 - lsls r1, 3 - adds r4, r0, r1 - ldrb r0, [r4] - cmp r0, 0 - beq _0817AFEA - cmp r0, 0x1 - beq _0817B008 -_0817AFEA: - ldr r0, =0x0000ffff - str r0, [sp] - movs r1, 0 - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade - movs r0, 0x1 - strb r0, [r4] - b _0817B020 - .pool -_0817B008: - bl UpdatePaletteFade - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - bne _0817B020 - bl FreeAllWindowBuffers - bl DoSoftReset -_0817B020: - add sp, 0x4 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_817AFD4 - - thumb_func_start sub_817B02C -sub_817B02C: @ 817B02C - push {lr} - ldr r0, =gUnknown_085F06C8 - bl InitWindows - bl DeactivateAllTextPrinters - movs r0, 0 - movs r1, 0 - bl FillWindowPixelBuffer - movs r0, 0 - movs r1, 0 - movs r2, 0x2 - movs r3, 0xE0 - bl sub_80987D4 - ldr r0, =gUnknown_0860F074 - movs r1, 0xF0 - movs r2, 0x20 - bl LoadPalette - pop {r0} - bx r0 - .pool - thumb_func_end sub_817B02C - - .align 2, 0 @ Don't pad with nop. diff --git a/asm/crt0.s b/asm/crt0.s index 3ece5c7d01..0b14a14699 100644 --- a/asm/crt0.s +++ b/asm/crt0.s @@ -163,7 +163,7 @@ IntrMain: @ 8000248 IntrMain_FoundIntr: strh r0, [r3, OFFSET_REG_IF - 0x200] bic r2, r2, r0 - ldr r0, =gUnknown_03007868 + ldr r0, =gRfuState ldr r0, [r0] ldrb r0, [r0, 0xA] mov r1, 0x8 diff --git a/asm/librfu.s b/asm/librfu.s index 129e0f34aa..5fc1b0d6fa 100644 --- a/asm/librfu.s +++ b/asm/librfu.s @@ -4,2251 +4,6 @@ .text - thumb_func_start STWI_init_all -STWI_init_all: @ 82E2A18 - push {r4,lr} - adds r3, r0, 0 - lsls r2, 24 - lsrs r2, 24 - cmp r2, 0x1 - bne _082E2A54 - adds r2, r3, 0 - adds r2, 0xE8 - str r2, [r1] - ldr r1, _082E2A40 - ldr r0, _082E2A44 - str r0, [r1] - str r2, [r1, 0x4] - ldr r0, _082E2A48 - str r0, [r1, 0x8] - ldr r0, [r1, 0x8] - ldr r1, _082E2A4C - ldr r2, _082E2A50 - adds r0, r3, r2 - b _082E2A5E - .align 2, 0 -_082E2A40: .4byte 0x040000d4 -_082E2A44: .4byte IntrSIO32 -_082E2A48: .4byte 0x800004b0 -_082E2A4C: .4byte gUnknown_03007868 -_082E2A50: .4byte 0x00000a48 -_082E2A54: - ldr r0, _082E2AD8 - str r0, [r1] - ldr r1, _082E2ADC - adds r0, r3, 0 - adds r0, 0xE8 -_082E2A5E: - str r0, [r1] - adds r2, r1, 0 - ldr r1, [r2] - str r3, [r1, 0x28] - adds r0, r3, 0 - adds r0, 0x74 - str r0, [r1, 0x24] - ldrb r0, [r1, 0x14] - movs r4, 0 - movs r0, 0x1 - strb r0, [r1, 0x14] - ldr r0, [r2] - str r4, [r0] - strb r4, [r0, 0x4] - ldr r0, [r2] - strb r4, [r0, 0x5] - ldr r0, [r2] - strb r4, [r0, 0x7] - ldr r0, [r2] - strb r4, [r0, 0x8] - ldr r0, [r2] - strb r4, [r0, 0x9] - ldr r0, [r2] - str r4, [r0, 0xC] - ldrb r1, [r0, 0x10] - strb r4, [r0, 0x10] - ldr r0, [r2] - ldrh r1, [r0, 0x12] - movs r1, 0 - strh r4, [r0, 0x12] - strb r1, [r0, 0x15] - ldr r0, [r2] - adds r0, 0x2C - ldrb r2, [r0] - strb r1, [r0] - ldr r1, _082E2AE0 - movs r2, 0x80 - lsls r2, 1 - adds r0, r2, 0 - strh r0, [r1] - subs r1, 0xC - ldr r2, _082E2AE4 - adds r0, r2, 0 - strh r0, [r1] - bl STWI_init_Callback_M - bl STWI_init_Callback_S - ldr r3, _082E2AE8 - ldrh r2, [r3] - strh r4, [r3] - ldr r4, _082E2AEC - ldrh r0, [r4] - movs r1, 0x80 - orrs r0, r1 - strh r0, [r4] - strh r2, [r3] - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_082E2AD8: .4byte IntrSIO32 -_082E2ADC: .4byte gUnknown_03007868 -_082E2AE0: .4byte 0x04000134 -_082E2AE4: .4byte 0x00005003 -_082E2AE8: .4byte 0x04000208 -_082E2AEC: .4byte 0x04000200 - thumb_func_end STWI_init_all - - thumb_func_start STWI_init_timer -STWI_init_timer: @ 82E2AF0 - push {r4,r5,lr} - ldr r2, _082E2B1C - str r2, [r0] - ldr r5, _082E2B20 - ldr r0, [r5] - movs r4, 0 - strb r1, [r0, 0xA] - ldr r3, _082E2B24 - ldrh r2, [r3] - strh r4, [r3] - ldr r4, _082E2B28 - ldr r1, [r5] - movs r0, 0x8 - ldrb r1, [r1, 0xA] - lsls r0, r1 - ldrh r1, [r4] - orrs r0, r1 - strh r0, [r4] - strh r2, [r3] - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_082E2B1C: .4byte STWI_intr_timer -_082E2B20: .4byte gUnknown_03007868 -_082E2B24: .4byte 0x04000208 -_082E2B28: .4byte 0x04000200 - thumb_func_end STWI_init_timer - - thumb_func_start AgbRFU_SoftReset -AgbRFU_SoftReset: @ 82E2B2C - push {r4,r5,lr} - ldr r5, _082E2BC4 - movs r1, 0x80 - lsls r1, 8 - adds r0, r1, 0 - strh r0, [r5] - ldr r2, _082E2BC8 - adds r0, r2, 0 - strh r0, [r5] - ldr r1, _082E2BCC - ldr r0, [r1] - ldrb r0, [r0, 0xA] - lsls r0, 2 - ldr r3, _082E2BD0 - adds r2, r0, r3 - ldr r4, _082E2BD4 - adds r3, r0, r4 - movs r0, 0 - strh r0, [r3] - strh r0, [r2] - movs r0, 0x83 - strh r0, [r3] - ldrh r0, [r2] - adds r4, r1, 0 - cmp r0, 0x11 - bhi _082E2B6C - ldr r0, _082E2BD8 - adds r1, r0, 0 -_082E2B64: - strh r1, [r5] - ldrh r0, [r2] - cmp r0, 0x11 - bls _082E2B64 -_082E2B6C: - movs r0, 0x3 - strh r0, [r3] - ldr r1, _082E2BC4 - ldr r2, _082E2BC8 - adds r0, r2, 0 - strh r0, [r1] - subs r1, 0xC - ldr r3, _082E2BDC - adds r0, r3, 0 - strh r0, [r1] - ldr r0, [r4] - movs r2, 0 - str r2, [r0] - strb r2, [r0, 0x4] - ldr r0, [r4] - strb r2, [r0, 0x5] - ldr r0, [r4] - strb r2, [r0, 0x6] - ldr r0, [r4] - strb r2, [r0, 0x7] - ldr r0, [r4] - strb r2, [r0, 0x8] - ldr r0, [r4] - strb r2, [r0, 0x9] - ldr r0, [r4] - str r2, [r0, 0xC] - ldrb r1, [r0, 0x10] - strb r2, [r0, 0x10] - ldr r1, [r4] - ldrh r0, [r1, 0x12] - movs r3, 0 - strh r2, [r1, 0x12] - ldrb r0, [r1, 0x14] - movs r0, 0x1 - strb r0, [r1, 0x14] - ldr r0, [r4] - strb r3, [r0, 0x15] - ldr r0, [r4] - adds r0, 0x2C - ldrb r1, [r0] - strb r3, [r0] - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_082E2BC4: .4byte 0x04000134 -_082E2BC8: .4byte 0x000080a0 -_082E2BCC: .4byte gUnknown_03007868 -_082E2BD0: .4byte 0x04000100 -_082E2BD4: .4byte 0x04000102 -_082E2BD8: .4byte 0x000080a2 -_082E2BDC: .4byte 0x00005003 - thumb_func_end AgbRFU_SoftReset - - thumb_func_start STWI_set_MS_mode -STWI_set_MS_mode: @ 82E2BE0 - lsls r0, 24 - lsrs r0, 24 - ldr r1, _082E2BF0 - ldr r1, [r1] - ldrb r2, [r1, 0x14] - strb r0, [r1, 0x14] - bx lr - .align 2, 0 -_082E2BF0: .4byte gUnknown_03007868 - thumb_func_end STWI_set_MS_mode - - thumb_func_start STWI_read_status -STWI_read_status: @ 82E2BF4 - push {lr} - lsls r0, 24 - lsrs r0, 24 - adds r1, r0, 0 - cmp r0, 0x1 - beq _082E2C20 - cmp r0, 0x1 - bgt _082E2C0A - cmp r0, 0 - beq _082E2C14 - b _082E2C48 -_082E2C0A: - cmp r1, 0x2 - beq _082E2C2C - cmp r1, 0x3 - beq _082E2C3C - b _082E2C48 -_082E2C14: - ldr r0, _082E2C1C - ldr r0, [r0] - ldrh r0, [r0, 0x12] - b _082E2C4A - .align 2, 0 -_082E2C1C: .4byte gUnknown_03007868 -_082E2C20: - ldr r0, _082E2C28 - ldr r0, [r0] - ldrb r0, [r0, 0x14] - b _082E2C4A - .align 2, 0 -_082E2C28: .4byte gUnknown_03007868 -_082E2C2C: - ldr r0, _082E2C38 - ldr r0, [r0] - ldr r0, [r0] - lsls r0, 16 - lsrs r0, 16 - b _082E2C4A - .align 2, 0 -_082E2C38: .4byte gUnknown_03007868 -_082E2C3C: - ldr r0, _082E2C44 - ldr r0, [r0] - ldrb r0, [r0, 0x6] - b _082E2C4A - .align 2, 0 -_082E2C44: .4byte gUnknown_03007868 -_082E2C48: - ldr r0, _082E2C50 -_082E2C4A: - pop {r1} - bx r1 - .align 2, 0 -_082E2C50: .4byte 0x0000ffff - thumb_func_end STWI_read_status - - thumb_func_start STWI_init_Callback_M -STWI_init_Callback_M: @ 82E2C54 - push {lr} - movs r0, 0 - bl STWI_set_Callback_M - pop {r0} - bx r0 - thumb_func_end STWI_init_Callback_M - - thumb_func_start STWI_init_Callback_S -STWI_init_Callback_S: @ 82E2C60 - push {lr} - movs r0, 0 - bl STWI_set_Callback_S - pop {r0} - bx r0 - thumb_func_end STWI_init_Callback_S - - thumb_func_start STWI_set_Callback_M -STWI_set_Callback_M: @ 82E2C6C - ldr r1, _082E2C74 - ldr r1, [r1] - str r0, [r1, 0x18] - bx lr - .align 2, 0 -_082E2C74: .4byte gUnknown_03007868 - thumb_func_end STWI_set_Callback_M - - thumb_func_start STWI_set_Callback_S -STWI_set_Callback_S: @ 82E2C78 - ldr r1, _082E2C80 - ldr r1, [r1] - str r0, [r1, 0x1C] - bx lr - .align 2, 0 -_082E2C80: .4byte gUnknown_03007868 - thumb_func_end STWI_set_Callback_S - - thumb_func_start STWI_set_Callback_ID -STWI_set_Callback_ID: @ 82E2C84 - ldr r1, _082E2C8C - ldr r1, [r1] - str r0, [r1, 0x20] - bx lr - .align 2, 0 -_082E2C8C: .4byte gUnknown_03007868 - thumb_func_end STWI_set_Callback_ID - - thumb_func_start STWI_poll_CommandEnd -STWI_poll_CommandEnd: @ 82E2C90 - push {lr} - ldr r0, _082E2CB4 - ldr r1, [r0] - adds r2, r1, 0 - adds r2, 0x2C - ldrb r1, [r2] - adds r3, r0, 0 - cmp r1, 0x1 - bne _082E2CAA - adds r1, r2, 0 -_082E2CA4: - ldrb r0, [r1] - cmp r0, 0x1 - beq _082E2CA4 -_082E2CAA: - ldr r0, [r3] - ldrh r0, [r0, 0x12] - pop {r1} - bx r1 - .align 2, 0 -_082E2CB4: .4byte gUnknown_03007868 - thumb_func_end STWI_poll_CommandEnd - - thumb_func_start STWI_send_ResetREQ -STWI_send_ResetREQ: @ 82E2CB8 - push {lr} - movs r0, 0x10 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2CD2 - ldr r0, _082E2CD8 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2CD2: - pop {r0} - bx r0 - .align 2, 0 -_082E2CD8: .4byte gUnknown_03007868 - thumb_func_end STWI_send_ResetREQ - - thumb_func_start STWI_send_LinkStatusREQ -STWI_send_LinkStatusREQ: @ 82E2CDC - push {lr} - movs r0, 0x11 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2CF6 - ldr r0, _082E2CFC - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2CF6: - pop {r0} - bx r0 - .align 2, 0 -_082E2CFC: .4byte gUnknown_03007868 - thumb_func_end STWI_send_LinkStatusREQ - - thumb_func_start STWI_send_VersionStatusREQ -STWI_send_VersionStatusREQ: @ 82E2D00 - push {lr} - movs r0, 0x12 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2D1A - ldr r0, _082E2D20 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2D1A: - pop {r0} - bx r0 - .align 2, 0 -_082E2D20: .4byte gUnknown_03007868 - thumb_func_end STWI_send_VersionStatusREQ - - thumb_func_start STWI_send_SystemStatusREQ -STWI_send_SystemStatusREQ: @ 82E2D24 - push {lr} - movs r0, 0x13 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2D3E - ldr r0, _082E2D44 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2D3E: - pop {r0} - bx r0 - .align 2, 0 -_082E2D44: .4byte gUnknown_03007868 - thumb_func_end STWI_send_SystemStatusREQ - - thumb_func_start STWI_send_SlotStatusREQ -STWI_send_SlotStatusREQ: @ 82E2D48 - push {lr} - movs r0, 0x14 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2D62 - ldr r0, _082E2D68 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2D62: - pop {r0} - bx r0 - .align 2, 0 -_082E2D68: .4byte gUnknown_03007868 - thumb_func_end STWI_send_SlotStatusREQ - - thumb_func_start STWI_send_ConfigStatusREQ -STWI_send_ConfigStatusREQ: @ 82E2D6C - push {lr} - movs r0, 0x15 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2D86 - ldr r0, _082E2D8C - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2D86: - pop {r0} - bx r0 - .align 2, 0 -_082E2D8C: .4byte gUnknown_03007868 - thumb_func_end STWI_send_ConfigStatusREQ - - thumb_func_start STWI_send_GameConfigREQ -STWI_send_GameConfigREQ: @ 82E2D90 - push {r4,r5,lr} - adds r4, r0, 0 - adds r5, r1, 0 - movs r0, 0x16 - bl STWI_init - lsls r0, 16 - cmp r0, 0 - bne _082E2DDC - ldr r2, _082E2DE4 - ldr r1, [r2] - movs r0, 0x6 - strb r0, [r1, 0x4] - ldr r0, [r2] - ldr r1, [r0, 0x24] - adds r1, 0x4 - ldrh r0, [r4] - strh r0, [r1] - adds r1, 0x2 - adds r4, 0x2 - movs r2, 0xD -_082E2DBA: - ldrb r0, [r4] - strb r0, [r1] - adds r1, 0x1 - adds r4, 0x1 - subs r2, 0x1 - cmp r2, 0 - bge _082E2DBA - movs r2, 0x7 -_082E2DCA: - ldrb r0, [r5] - strb r0, [r1] - adds r1, 0x1 - adds r5, 0x1 - subs r2, 0x1 - cmp r2, 0 - bge _082E2DCA - bl STWI_start_Command -_082E2DDC: - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_082E2DE4: .4byte gUnknown_03007868 - thumb_func_end STWI_send_GameConfigREQ - - thumb_func_start STWI_send_SystemConfigREQ -STWI_send_SystemConfigREQ: @ 82E2DE8 - push {r4-r6,lr} - lsls r0, 16 - lsrs r6, r0, 16 - lsls r1, 24 - lsrs r5, r1, 24 - lsls r2, 24 - lsrs r4, r2, 24 - movs r0, 0x17 - bl STWI_init - lsls r0, 16 - cmp r0, 0 - bne _082E2E1E - ldr r2, _082E2E24 - ldr r1, [r2] - movs r0, 0x1 - strb r0, [r1, 0x4] - ldr r0, [r2] - ldr r0, [r0, 0x24] - adds r0, 0x4 - strb r4, [r0] - adds r0, 0x1 - strb r5, [r0] - adds r0, 0x1 - strh r6, [r0] - bl STWI_start_Command -_082E2E1E: - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_082E2E24: .4byte gUnknown_03007868 - thumb_func_end STWI_send_SystemConfigREQ - - thumb_func_start STWI_send_SC_StartREQ -STWI_send_SC_StartREQ: @ 82E2E28 - push {lr} - movs r0, 0x19 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2E42 - ldr r0, _082E2E48 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2E42: - pop {r0} - bx r0 - .align 2, 0 -_082E2E48: .4byte gUnknown_03007868 - thumb_func_end STWI_send_SC_StartREQ - - thumb_func_start STWI_send_SC_PollingREQ -STWI_send_SC_PollingREQ: @ 82E2E4C - push {lr} - movs r0, 0x1A - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2E66 - ldr r0, _082E2E6C - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2E66: - pop {r0} - bx r0 - .align 2, 0 -_082E2E6C: .4byte gUnknown_03007868 - thumb_func_end STWI_send_SC_PollingREQ - - thumb_func_start STWI_send_SC_EndREQ -STWI_send_SC_EndREQ: @ 82E2E70 - push {lr} - movs r0, 0x1B - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2E8A - ldr r0, _082E2E90 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2E8A: - pop {r0} - bx r0 - .align 2, 0 -_082E2E90: .4byte gUnknown_03007868 - thumb_func_end STWI_send_SC_EndREQ - - thumb_func_start STWI_send_SP_StartREQ -STWI_send_SP_StartREQ: @ 82E2E94 - push {lr} - movs r0, 0x1C - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2EAE - ldr r0, _082E2EB4 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2EAE: - pop {r0} - bx r0 - .align 2, 0 -_082E2EB4: .4byte gUnknown_03007868 - thumb_func_end STWI_send_SP_StartREQ - - thumb_func_start STWI_send_SP_PollingREQ -STWI_send_SP_PollingREQ: @ 82E2EB8 - push {lr} - movs r0, 0x1D - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2ED2 - ldr r0, _082E2ED8 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2ED2: - pop {r0} - bx r0 - .align 2, 0 -_082E2ED8: .4byte gUnknown_03007868 - thumb_func_end STWI_send_SP_PollingREQ - - thumb_func_start STWI_send_SP_EndREQ -STWI_send_SP_EndREQ: @ 82E2EDC - push {lr} - movs r0, 0x1E - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2EF6 - ldr r0, _082E2EFC - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2EF6: - pop {r0} - bx r0 - .align 2, 0 -_082E2EFC: .4byte gUnknown_03007868 - thumb_func_end STWI_send_SP_EndREQ - - thumb_func_start STWI_send_CP_StartREQ -STWI_send_CP_StartREQ: @ 82E2F00 - push {r4,lr} - lsls r0, 16 - lsrs r4, r0, 16 - movs r0, 0x1F - bl STWI_init - lsls r0, 16 - cmp r0, 0 - bne _082E2F24 - ldr r2, _082E2F2C - ldr r1, [r2] - movs r0, 0x1 - strb r0, [r1, 0x4] - ldr r0, [r2] - ldr r0, [r0, 0x24] - str r4, [r0, 0x4] - bl STWI_start_Command -_082E2F24: - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_082E2F2C: .4byte gUnknown_03007868 - thumb_func_end STWI_send_CP_StartREQ - - thumb_func_start STWI_send_CP_PollingREQ -STWI_send_CP_PollingREQ: @ 82E2F30 - push {lr} - movs r0, 0x20 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2F4A - ldr r0, _082E2F50 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2F4A: - pop {r0} - bx r0 - .align 2, 0 -_082E2F50: .4byte gUnknown_03007868 - thumb_func_end STWI_send_CP_PollingREQ - - thumb_func_start STWI_send_CP_EndREQ -STWI_send_CP_EndREQ: @ 82E2F54 - push {lr} - movs r0, 0x21 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E2F6E - ldr r0, _082E2F74 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E2F6E: - pop {r0} - bx r0 - .align 2, 0 -_082E2F74: .4byte gUnknown_03007868 - thumb_func_end STWI_send_CP_EndREQ - - thumb_func_start STWI_send_DataTxREQ -STWI_send_DataTxREQ: @ 82E2F78 - push {r4-r6,lr} - adds r6, r0, 0 - lsls r4, r1, 24 - lsrs r5, r4, 24 - movs r0, 0x24 - bl STWI_init - lsls r0, 16 - cmp r0, 0 - bne _082E2FB6 - lsrs r2, r4, 26 - movs r0, 0x3 - ands r0, r5 - cmp r0, 0 - beq _082E2F98 - adds r2, 0x1 -_082E2F98: - ldr r1, _082E2FBC - ldr r0, [r1] - strb r2, [r0, 0x4] - ldr r0, [r1] - ldr r1, [r0, 0x24] - adds r1, 0x4 - ldrb r2, [r0, 0x4] - movs r0, 0x80 - lsls r0, 19 - orrs r2, r0 - adds r0, r6, 0 - bl CpuSet - bl STWI_start_Command -_082E2FB6: - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_082E2FBC: .4byte gUnknown_03007868 - thumb_func_end STWI_send_DataTxREQ - - thumb_func_start STWI_send_DataTxAndChangeREQ -STWI_send_DataTxAndChangeREQ: @ 82E2FC0 - push {r4-r6,lr} - adds r6, r0, 0 - lsls r4, r1, 24 - lsrs r5, r4, 24 - movs r0, 0x25 - bl STWI_init - lsls r0, 16 - cmp r0, 0 - bne _082E2FFE - lsrs r2, r4, 26 - movs r0, 0x3 - ands r0, r5 - cmp r0, 0 - beq _082E2FE0 - adds r2, 0x1 -_082E2FE0: - ldr r1, _082E3004 - ldr r0, [r1] - strb r2, [r0, 0x4] - ldr r0, [r1] - ldr r1, [r0, 0x24] - adds r1, 0x4 - ldrb r2, [r0, 0x4] - movs r0, 0x80 - lsls r0, 19 - orrs r2, r0 - adds r0, r6, 0 - bl CpuSet - bl STWI_start_Command -_082E2FFE: - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_082E3004: .4byte gUnknown_03007868 - thumb_func_end STWI_send_DataTxAndChangeREQ - - thumb_func_start STWI_send_DataRxREQ -STWI_send_DataRxREQ: @ 82E3008 - push {lr} - movs r0, 0x26 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E3022 - ldr r0, _082E3028 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E3022: - pop {r0} - bx r0 - .align 2, 0 -_082E3028: .4byte gUnknown_03007868 - thumb_func_end STWI_send_DataRxREQ - - thumb_func_start STWI_send_MS_ChangeREQ -STWI_send_MS_ChangeREQ: @ 82E302C - push {lr} - movs r0, 0x27 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E3046 - ldr r0, _082E304C - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E3046: - pop {r0} - bx r0 - .align 2, 0 -_082E304C: .4byte gUnknown_03007868 - thumb_func_end STWI_send_MS_ChangeREQ - - thumb_func_start STWI_send_DataReadyAndChangeREQ -STWI_send_DataReadyAndChangeREQ: @ 82E3050 - push {r4,r5,lr} - lsls r0, 24 - lsrs r4, r0, 24 - adds r5, r4, 0 - movs r0, 0x28 - bl STWI_init - lsls r0, 16 - lsrs r3, r0, 16 - cmp r3, 0 - bne _082E3096 - cmp r4, 0 - bne _082E3078 - ldr r0, _082E3074 - ldr r0, [r0] - strb r3, [r0, 0x4] - b _082E3092 - .align 2, 0 -_082E3074: .4byte gUnknown_03007868 -_082E3078: - ldr r2, _082E309C - ldr r1, [r2] - movs r0, 0x1 - strb r0, [r1, 0x4] - ldr r0, [r2] - ldr r0, [r0, 0x24] - adds r0, 0x4 - strb r5, [r0] - adds r0, 0x1 - strb r3, [r0] - adds r0, 0x1 - strb r3, [r0] - strb r3, [r0, 0x1] -_082E3092: - bl STWI_start_Command -_082E3096: - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_082E309C: .4byte gUnknown_03007868 - thumb_func_end STWI_send_DataReadyAndChangeREQ - - thumb_func_start STWI_send_DisconnectedAndChangeREQ -STWI_send_DisconnectedAndChangeREQ: @ 82E30A0 - push {r4,r5,lr} - lsls r0, 24 - lsrs r4, r0, 24 - lsls r1, 24 - lsrs r5, r1, 24 - movs r0, 0x29 - bl STWI_init - lsls r0, 16 - lsrs r3, r0, 16 - cmp r3, 0 - bne _082E30D6 - ldr r2, _082E30DC - ldr r1, [r2] - movs r0, 0x1 - strb r0, [r1, 0x4] - ldr r0, [r2] - ldr r0, [r0, 0x24] - adds r0, 0x4 - strb r4, [r0] - adds r0, 0x1 - strb r5, [r0] - adds r0, 0x1 - strb r3, [r0] - strb r3, [r0, 0x1] - bl STWI_start_Command -_082E30D6: - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_082E30DC: .4byte gUnknown_03007868 - thumb_func_end STWI_send_DisconnectedAndChangeREQ - - thumb_func_start STWI_send_ResumeRetransmitAndChangeREQ -STWI_send_ResumeRetransmitAndChangeREQ: @ 82E30E0 - push {lr} - movs r0, 0x37 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E30FA - ldr r0, _082E3100 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E30FA: - pop {r0} - bx r0 - .align 2, 0 -_082E3100: .4byte gUnknown_03007868 - thumb_func_end STWI_send_ResumeRetransmitAndChangeREQ - - thumb_func_start STWI_send_DisconnectREQ -STWI_send_DisconnectREQ: @ 82E3104 - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - movs r0, 0x30 - bl STWI_init - lsls r0, 16 - cmp r0, 0 - bne _082E3128 - ldr r2, _082E3130 - ldr r1, [r2] - movs r0, 0x1 - strb r0, [r1, 0x4] - ldr r0, [r2] - ldr r0, [r0, 0x24] - str r4, [r0, 0x4] - bl STWI_start_Command -_082E3128: - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_082E3130: .4byte gUnknown_03007868 - thumb_func_end STWI_send_DisconnectREQ - - thumb_func_start STWI_send_TestModeREQ -STWI_send_TestModeREQ: @ 82E3134 - push {r4,r5,lr} - lsls r0, 24 - lsrs r5, r0, 24 - lsls r1, 24 - lsrs r4, r1, 24 - movs r0, 0x31 - bl STWI_init - lsls r0, 16 - cmp r0, 0 - bne _082E3160 - ldr r2, _082E3168 - ldr r1, [r2] - movs r0, 0x1 - strb r0, [r1, 0x4] - ldr r0, [r2] - ldr r1, [r0, 0x24] - lsls r0, r4, 8 - orrs r0, r5 - str r0, [r1, 0x4] - bl STWI_start_Command -_082E3160: - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_082E3168: .4byte gUnknown_03007868 - thumb_func_end STWI_send_TestModeREQ - - thumb_func_start STWI_send_CPR_StartREQ -STWI_send_CPR_StartREQ: @ 82E316C - push {r4-r6,lr} - lsls r0, 16 - lsrs r5, r0, 16 - lsls r1, 16 - lsrs r4, r1, 16 - lsls r2, 24 - lsrs r6, r2, 24 - movs r0, 0x32 - bl STWI_init - lsls r0, 16 - cmp r0, 0 - bne _082E319E - ldr r2, _082E31A4 - ldr r1, [r2] - movs r0, 0x2 - strb r0, [r1, 0x4] - lsls r0, r5, 16 - orrs r0, r4 - ldr r1, [r2] - ldr r1, [r1, 0x24] - str r0, [r1, 0x4] - str r6, [r1, 0x8] - bl STWI_start_Command -_082E319E: - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_082E31A4: .4byte gUnknown_03007868 - thumb_func_end STWI_send_CPR_StartREQ - - thumb_func_start STWI_send_CPR_PollingREQ -STWI_send_CPR_PollingREQ: @ 82E31A8 - push {lr} - movs r0, 0x33 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E31C2 - ldr r0, _082E31C8 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E31C2: - pop {r0} - bx r0 - .align 2, 0 -_082E31C8: .4byte gUnknown_03007868 - thumb_func_end STWI_send_CPR_PollingREQ - - thumb_func_start STWI_send_CPR_EndREQ -STWI_send_CPR_EndREQ: @ 82E31CC - push {lr} - movs r0, 0x34 - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E31E6 - ldr r0, _082E31EC - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E31E6: - pop {r0} - bx r0 - .align 2, 0 -_082E31EC: .4byte gUnknown_03007868 - thumb_func_end STWI_send_CPR_EndREQ - - thumb_func_start STWI_send_StopModeREQ -STWI_send_StopModeREQ: @ 82E31F0 - push {lr} - movs r0, 0x3D - bl STWI_init - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _082E320A - ldr r0, _082E3210 - ldr r0, [r0] - strb r1, [r0, 0x4] - bl STWI_start_Command -_082E320A: - pop {r0} - bx r0 - .align 2, 0 -_082E3210: .4byte gUnknown_03007868 - thumb_func_end STWI_send_StopModeREQ - - 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 gUnknown_03007868 -_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 gUnknown_03007868 -_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 gUnknown_03007868 -_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 gUnknown_03007868 -_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 gUnknown_03007868 -_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} - ldr r5, _082E3480 - ldr r0, [r5] - ldr r3, [r0, 0x24] - ldrb r1, [r0, 0x4] - lsls r1, 8 - ldrb r0, [r0, 0x6] - ldr r2, _082E3484 - orrs r0, r2 - orrs r1, r0 - str r1, [r3] - ldr r2, _082E3488 - ldr r1, [r5] - ldr r0, [r1, 0x24] - ldr r0, [r0] - str r0, [r2] - movs r2, 0 - str r2, [r1] - movs r0, 0x1 - strb r0, [r1, 0x5] - ldr r4, _082E348C - ldrh r3, [r4] - strh r2, [r4] - ldr r2, _082E3490 - ldr r1, [r5] - movs r0, 0x8 - ldrb r1, [r1, 0xA] - lsls r0, r1 - ldrh r1, [r2] - orrs r0, r1 - strh r0, [r2] - ldrh r0, [r2] - movs r1, 0x80 - orrs r0, r1 - strh r0, [r2] - strh r3, [r4] - ldr r1, _082E3494 - ldr r2, _082E3498 - adds r0, r2, 0 - strh r0, [r1] - movs r0, 0 - pop {r4,r5} - pop {r1} - bx r1 - .align 2, 0 -_082E3480: .4byte gUnknown_03007868 -_082E3484: .4byte 0x99660000 -_082E3488: .4byte 0x04000120 -_082E348C: .4byte 0x04000208 -_082E3490: .4byte 0x04000200 -_082E3494: .4byte 0x04000128 -_082E3498: .4byte 0x00005083 - thumb_func_end STWI_start_Command - - thumb_func_start STWI_restart_Command -STWI_restart_Command: @ 82E349C - push {r4,lr} - ldr r4, _082E34B4 - ldr r2, [r4] - ldrb r0, [r2, 0x15] - adds r3, r4, 0 - cmp r0, 0x1 - bhi _082E34B8 - adds r0, 0x1 - strb r0, [r2, 0x15] - bl STWI_start_Command - b _082E3512 - .align 2, 0 -_082E34B4: .4byte gUnknown_03007868 -_082E34B8: - ldrb r0, [r2, 0x6] - cmp r0, 0x27 - beq _082E34CA - cmp r0, 0x25 - beq _082E34CA - cmp r0, 0x35 - beq _082E34CA - cmp r0, 0x37 - bne _082E34EC -_082E34CA: - ldr r0, [r3] - ldrh r1, [r0, 0x12] - movs r2, 0 - movs r1, 0x1 - strh r1, [r0, 0x12] - adds r0, 0x2C - ldrb r1, [r0] - strb r2, [r0] - ldr r1, [r3] - ldr r2, [r1, 0x18] - cmp r2, 0 - beq _082E3512 - ldrb r0, [r1, 0x6] - ldrh r1, [r1, 0x12] - bl _call_via_r2 - b _082E3512 -_082E34EC: - ldrh r0, [r2, 0x12] - movs r1, 0 - movs r0, 0x1 - strh r0, [r2, 0x12] - adds r0, r2, 0 - adds r0, 0x2C - ldrb r2, [r0] - strb r1, [r0] - ldr r1, [r4] - ldr r2, [r1, 0x18] - cmp r2, 0 - beq _082E350C - ldrb r0, [r1, 0x6] - ldrh r1, [r1, 0x12] - bl _call_via_r2 -_082E350C: - ldr r1, [r4] - movs r0, 0x4 - str r0, [r1] -_082E3512: - movs r0, 0 - pop {r4} - pop {r1} - bx r1 - thumb_func_end STWI_restart_Command - - thumb_func_start STWI_reset_ClockCounter -STWI_reset_ClockCounter: @ 82E351C - ldr r3, _082E3548 - ldr r1, [r3] - movs r0, 0x5 - str r0, [r1] - movs r2, 0 - strb r2, [r1, 0x4] - ldr r0, [r3] - strb r2, [r0, 0x5] - ldr r1, _082E354C - movs r0, 0x80 - lsls r0, 24 - str r0, [r1] - adds r1, 0x8 - strh r2, [r1] - ldr r2, _082E3550 - adds r0, r2, 0 - strh r0, [r1] - adds r2, 0x7F - adds r0, r2, 0 - strh r0, [r1] - movs r0, 0 - bx lr - .align 2, 0 -_082E3548: .4byte gUnknown_03007868 -_082E354C: .4byte 0x04000120 -_082E3550: .4byte 0x00005003 - thumb_func_end STWI_reset_ClockCounter - - arm_func_start IntrSIO32 -IntrSIO32: @ 82E3554 - mov r12, sp - stmdb sp!, {r11,r12,lr,pc} - ldr r3, _082E35B4 - ldr r0, [r3] - ldr r2, [r0] - sub r11, r12, 0x4 - cmp r2, 0xA - bne _082E3590 - ldr r0, [r0, 0x20] - cmp r0, 0 - ldmdbeq r11, {r11,sp,lr} - bxeq lr - bl sub_82E3EB0 - ldmdb r11, {r11,sp,lr} - bx lr -_082E3590: - ldrb r3, [r0, 0x14] - cmp r3, 0x1 - bne _082E35A8 - bl sio32intr_clock_master - ldmdb r11, {r11,sp,lr} - bx lr -_082E35A8: - bl sio32intr_clock_slave - ldmdb r11, {r11,sp,lr} - bx lr - .align 2, 0 -_082E35B4: .4byte gUnknown_03007868 - arm_func_end IntrSIO32 - - arm_func_start sio32intr_clock_master -sio32intr_clock_master: @ 82E35B8 - mov r12, sp - stmdb sp!, {r4-r6,r11,r12,lr,pc} - mov r0, 0x50 - sub r11, r12, 0x4 - bl STWI_set_timer_in_RAM - mov r4, 0x120 - ldr r2, _082E382C - add r4, r4, 0x4000000 - ldr lr, [r4] - ldr r12, [r2] - ldr r3, [r12] - mov r6, r2 - cmp r3, 0 - bne _082E3638 - cmp lr, 0x80000000 - bne _082E36B8 - ldrb r2, [r12, 0x5] - ldrb r3, [r12, 0x4] - cmp r2, r3 - bhi _082E3628 - ldr r3, [r12, 0x24] - mov r1, r2 - ldr r2, [r3, r1, lsl 2] - str r2, [r4] - ldrb r3, [r12, 0x5] - add r3, r3, 0x1 - strb r3, [r12, 0x5] - b _082E3714 -_082E3628: - mov r3, 0x1 - str r3, [r12] - str lr, [r4] - b _082E3714 -_082E3638: - ldr r3, [r12] - cmp r3, 0x1 - bne _082E36C8 - mov r3, 0x99000000 - add r3, r3, 0x660000 - mov r5, 0x80000000 - and r2, lr, r5, asr 15 - cmp r2, r3 - bne _082E36B8 - mov r3, 0 - strb r3, [r12, 0x8] - ldr r1, [r6] - ldrb r0, [r1, 0x8] - ldr r2, [r1, 0x28] - str lr, [r2, r0, lsl 2] - ldrb r3, [r1, 0x8] - add r3, r3, 0x1 - strb r3, [r1, 0x8] - ldr r2, [r6] - strb lr, [r2, 0x9] - ldr r3, [r6] - mov r2, lr, lsr 8 - strb r2, [r3, 0x7] - ldr r1, [r6] - ldrb r2, [r1, 0x7] - ldrb r3, [r1, 0x8] - cmp r2, r3 - bcc _082E3700 - mov r3, 0x2 - str r3, [r1] - str r5, [r4] - b _082E3714 -_082E36B8: - bl STWI_stop_timer_in_RAM - mov r0, 0x82 - bl STWI_set_timer_in_RAM - b _082E3840 -_082E36C8: - ldr r3, [r12] - cmp r3, 0x2 - bne _082E3714 - ldrb r1, [r12, 0x8] - ldr r2, [r12, 0x28] - str lr, [r2, r1, lsl 2] - ldrb r3, [r12, 0x8] - add r3, r3, 0x1 - strb r3, [r12, 0x8] - ldr r1, [r6] - ldrb r2, [r1, 0x7] - ldrb r3, [r1, 0x8] - cmp r2, r3 - bcs _082E370C -_082E3700: - mov r3, 0x3 - str r3, [r1] - b _082E3714 -_082E370C: - mov r3, 0x80000000 - str r3, [r4] -_082E3714: - mov r0, 0x1 - bl handshake_wait - mov r0, r0, lsl 16 - cmp r0, 0x10000 - beq _082E3840 - mov r4, 0x128 - add r4, r4, 0x4000000 - mov r5, 0x5000 - add r3, r5, 0xB - strh r3, [r4] - mov r0, 0 - bl handshake_wait - mov r0, r0, lsl 16 - cmp r0, 0x10000 - beq _082E3840 - bl STWI_stop_timer_in_RAM - ldr r1, [r6] - ldr r0, [r1] - cmp r0, 0x3 - bne _082E3830 - ldrb r3, [r1, 0x9] - cmp r3, 0xA5 - cmpne r3, 0xA7 - beq _082E3788 - and r3, r3, 0xFF - cmp r3, 0xB5 - beq _082E3788 - cmp r3, 0xB7 - bne _082E37D0 -_082E3788: - mov r1, 0x120 - add r1, r1, 0x4000000 - mov r12, 0x128 - add r12, r12, 0x4000000 - ldr r0, [r6] - mov r3, 0 - strb r3, [r0, 0x14] - mov r2, 0x80000000 - str r2, [r1] - add r3, r3, 0x5000 - add r2, r3, 0x2 - strh r2, [r12] - add r3, r3, 0x82 - strh r3, [r12] - ldr r2, [r6] - mov r3, 0x5 - str r3, [r2] - b _082E3800 -_082E37D0: - cmp r3, 0xEE - bne _082E37F0 - add r3, r5, 0x3 - strh r3, [r4] - mov r2, 0x4 - str r2, [r1] - strh r0, [r1, 0x12] - b _082E3800 -_082E37F0: - add r3, r5, 0x3 - strh r3, [r4] - mov r2, 0x4 - str r2, [r1] -_082E3800: - ldr r2, [r6] - mov r3, 0 - strb r3, [r2, 0x2C] - ldr r0, [r6] - ldr r2, [r0, 0x18] - cmp r2, r3 - beq _082E3840 - ldrh r1, [r0, 0x12] - ldrb r0, [r0, 0x6] - bl sub_82E3EA8 - b _082E3840 - .align 2, 0 -_082E382C: .4byte gUnknown_03007868 -_082E3830: - add r3, r5, 0x3 - strh r3, [r4] - add r2, r5, 0x83 - strh r2, [r4] -_082E3840: - ldmdb r11, {r4-r6,r11,sp,lr} - bx lr - arm_func_end sio32intr_clock_master - - arm_func_start sio32intr_clock_slave -sio32intr_clock_slave: @ 82E3848 - mov r12, sp - stmdb sp!, {r4-r6,r11,r12,lr,pc} - ldr r4, _082E3BF4 - mov r0, 0x64 - ldr r3, [r4] - mov r6, 0 - strb r6, [r3, 0x10] - sub r11, r12, 0x4 - bl STWI_set_timer_in_RAM - mov r0, r6 - bl handshake_wait - mov r0, r0, lsl 16 - cmp r0, 0x10000 - mov r5, r4 - beq _082E3C4C - mov r3, 0x128 - add r3, r3, 0x4000000 - mov r2, 0x5000 - add r2, r2, 0xA - strh r2, [r3] - mov lr, 0x120 - ldr r0, [r5] - add lr, lr, 0x4000000 - ldr r12, [lr] - ldr r3, [r0] - cmp r3, 0x5 - bne _082E3978 - ldr r3, [r0, 0x28] - mov r4, 0x1 - mov r0, 0x99000000 - str r12, [r3] - add r0, r0, 0x660000 - ldr r2, [r5] - mov r3, r0, lsr 16 - strb r4, [r2, 0x5] - cmp r3, r12, lsr 16 - bne _082E3AC4 - ldr r3, [r5] - mov r2, r12, lsr 8 - strb r2, [r3, 0x4] - ldr r2, [r5] - strb r12, [r2, 0x6] - ldr r1, [r5] - ldrb r3, [r1, 0x4] - cmp r3, r6 - bne _082E395C - ldrb r2, [r1, 0x6] - sub r3, r2, 0x27 - cmp r2, 0x36 - cmpne r3, 0x2 - bhi _082E3930 - add r3, r2, 0x80 - strb r3, [r1, 0x9] - ldr r2, [r5] - ldrb r3, [r2, 0x9] - ldr r1, [r2, 0x24] - add r3, r3, r0 - b _082E39E0 -_082E3930: - ldr r2, [r1, 0x24] - ldr r3, _082E3BF8 - str r3, [r2] - ldr r2, [r5] - ldrb r3, [r2, 0x6] - sub r3, r3, 0x10 - cmp r3, 0x2D - bhi _082E3A18 - ldr r3, [r2, 0x24] - str r4, [r3, 0x4] - b _082E3A24 -_082E395C: - mov r3, 0x80000000 - str r3, [lr] - strb r4, [r1, 0x5] - ldr r2, [r5] - add r3, r3, 0x80000006 - str r3, [r2] - b _082E3AD4 -_082E3978: - ldr r3, [r0] - cmp r3, 0x6 - bne _082E3A78 - ldrb r1, [r0, 0x5] - ldr r2, [r0, 0x28] - str r12, [r2, r1, lsl 2] - ldrb r3, [r0, 0x5] - add r3, r3, 0x1 - strb r3, [r0, 0x5] - ldr r1, [r5] - ldrb r2, [r1, 0x4] - ldrb r3, [r1, 0x5] - cmp r2, r3 - bcs _082E3A6C - ldrb r2, [r1, 0x6] - sub r3, r2, 0x28 - cmp r2, 0x36 - cmpne r3, 0x1 - bhi _082E39F0 - add r3, r2, 0x80 - strb r3, [r1, 0x9] - ldr r2, [r5] - ldrb r3, [r2, 0x9] - ldr r1, [r2, 0x24] - orr r3, r3, 0x99000000 - orr r3, r3, 0x660000 -_082E39E0: - str r3, [r1] - ldr r2, [r5] - strb r6, [r2, 0x7] - b _082E3A3C -_082E39F0: - ldr r2, [r1, 0x24] - ldr r3, _082E3BF8 - str r3, [r2] - ldr r2, [r5] - ldrb r3, [r2, 0x6] - sub r3, r3, 0x10 - cmp r3, 0x2D - ldrls r2, [r2, 0x24] - movls r3, 0x1 - bls _082E3A20 -_082E3A18: - ldr r2, [r2, 0x24] - mov r3, 0x2 -_082E3A20: - str r3, [r2, 0x4] -_082E3A24: - ldr r2, [r5] - mov r3, 0x1 - strb r3, [r2, 0x7] - ldr r1, [r5] - add r3, r3, 0x2 - strh r3, [r1, 0x12] -_082E3A3C: - ldr r0, [r5] - ldr r2, [r0, 0x24] - mov r3, 0x120 - ldr r1, [r2] - add r3, r3, 0x4000000 - str r1, [r3] - mov r2, 0x1 - strb r2, [r0, 0x8] - ldr r1, [r5] - mov r3, 0x7 - str r3, [r1] - b _082E3AD4 -_082E3A6C: - mov r3, 0x80000000 - str r3, [lr] - b _082E3AD4 -_082E3A78: - ldr r3, [r0] - cmp r3, 0x7 - bne _082E3AD4 - cmp r12, 0x80000000 - bne _082E3AC4 - ldrb r2, [r0, 0x7] - ldrb r3, [r0, 0x8] - cmp r2, r3 - movcc r3, 0x8 - strcc r3, [r0] - bcc _082E3AD4 - ldrb r1, [r0, 0x8] - ldr r3, [r0, 0x24] - ldr r2, [r3, r1, lsl 2] - str r2, [lr] - ldrb r3, [r0, 0x8] - add r3, r3, 0x1 - strb r3, [r0, 0x8] - b _082E3AD4 -_082E3AC4: - bl STWI_stop_timer_in_RAM - mov r0, 0x64 - bl STWI_set_timer_in_RAM - b _082E3C4C -_082E3AD4: - mov r0, 0x1 - bl handshake_wait - mov r0, r0, lsl 16 - cmp r0, 0x10000 - beq _082E3C4C - mov r6, r5 - ldr r3, [r6] - ldr r2, [r3] - cmp r2, 0x8 - bne _082E3B9C - mov r4, 0x128 - add r4, r4, 0x4000000 - mov r3, 0x5000 - add r3, r3, 0x2 - strh r3, [r4] - bl STWI_stop_timer_in_RAM - ldr r0, [r6] - ldrh r3, [r0, 0x12] - cmp r3, 0x3 - bne _082E3B48 - bl STWI_init_slave - ldr r3, [r6] - ldr r1, [r3, 0x1C] - cmp r1, 0 - beq _082E3C4C - mov r0, 0x1EC - add r0, r0, 0x2 - bl sub_82E3EAC - b _082E3C4C -_082E3B48: - mov r3, 0x120 - add r3, r3, 0x4000000 - mov r1, 0 - str r1, [r3] - mov r2, 0x5000 - strh r1, [r4] - add r2, r2, 0x3 - strh r2, [r4] - mov r3, 0x1 - strb r3, [r0, 0x14] - ldr r0, [r5] - ldr r2, [r0, 0x1C] - str r1, [r0] - cmp r2, r1 - beq _082E3C4C - ldrb r3, [r0, 0x4] - ldrb r0, [r0, 0x6] - mov r1, r2 - orr r0, r0, r3, lsl 8 - bl sub_82E3EAC - b _082E3C4C -_082E3B9C: - mov r3, 0x208 - add r3, r3, 0x4000000 - mov r2, 0 - strh r2, [r3] - mov r1, 0x100 - add r2, r1, 0x4000002 - ldrh r3, [r2] - tst r3, 0x80 - beq _082E3C20 - ldrh r3, [r2] - tst r3, 0x3 - bne _082E3BFC - mov r2, 0xFF00 - add r1, r1, 0x4000000 - ldrh r3, [r1] - add r2, r2, 0x9B - cmp r3, r2 - bls _082E3C20 -_082E3BE4: - ldrh r3, [r1] - cmp r3, r2 - bhi _082E3BE4 - b _082E3C20 - .align 2, 0 -_082E3BF4: .4byte gUnknown_03007868 -_082E3BF8: .4byte 0x996601ee -_082E3BFC: - mov r2, 0xFF00 - add r1, r1, 0x4000000 - ldrh r3, [r1] - add r2, r2, 0xFE - cmp r3, r2 - bls _082E3C20 -_082E3C14: - ldrh r3, [r1] - cmp r3, r2 - bhi _082E3C14 -_082E3C20: - mov r1, 0x128 - add r1, r1, 0x4000000 - mov r0, 0x208 - add r0, r0, 0x4000000 - mov r3, 0x5000 - add r2, r3, 0x2 - strh r2, [r1] - add r3, r3, 0x82 - strh r3, [r1] - mov r2, 0x1 - strh r2, [r0] -_082E3C4C: - ldmdb r11, {r4-r6,r11,sp,lr} - bx lr - arm_func_end sio32intr_clock_slave - - arm_func_start handshake_wait -handshake_wait: @ 82E3C54 - mov r12, sp - stmdb sp!, {r11,r12,lr,pc} - mov r1, 0x128 - add r1, r1, 0x4000000 - mov r0, r0, lsl 16 - ldr r2, _082E3CB8 - sub r11, r12, 0x4 - mov lr, r0, lsr 14 - ldr r12, [r2] -_082E3C78: - ldrb r3, [r12, 0x10] - and r0, r3, 0xFF - cmp r0, 0x1 - beq _082E3CA4 - ldrh r3, [r1] - and r3, r3, 0x4 - cmp r3, lr - bne _082E3C78 - mov r0, 0 - ldmdb r11, {r11,sp,lr} - bx lr -_082E3CA4: - ldr r2, [r2] - mov r3, 0 - strb r3, [r2, 0x10] - ldmdb r11, {r11,sp,lr} - bx lr - .align 2, 0 -_082E3CB8: .4byte gUnknown_03007868 - arm_func_end handshake_wait - - arm_func_start STWI_set_timer_in_RAM -STWI_set_timer_in_RAM: @ 82E3CBC - mov r12, sp - stmdb sp!, {r4,r5,r11,r12,lr,pc} - mov r1, 0x208 - add r1, r1, 0x4000000 - mov r3, 0 - sub r11, r12, 0x4 - ldr r12, _082E3D74 - and lr, r0, 0xFF - ldr r2, [r12] - cmp lr, 0x50 - ldrb r0, [r2, 0xA] - mov r4, r12 - mov r2, lr - strh r3, [r1] - mov r0, r0, lsl 2 - add r3, r3, 0x100 - add r1, r3, 0x4000000 - add r3, r3, 0x4000002 - add r5, r0, r3 - beq _082E3D44 - bgt _082E3D1C - cmp lr, 0x32 - beq _082E3D30 - b _082E3D90 -_082E3D1C: - cmp r2, 0x64 - beq _082E3D5C - cmp r2, 0x82 - beq _082E3D78 - b _082E3D90 -_082E3D30: - mvn r3, 0x334 - strh r3, [r0, r1] - ldr r2, [r4] - mov r3, 0x1 - b _082E3D8C -_082E3D44: - mov r3, 0xAE000000 - mov r3, r3, asr 20 - strh r3, [r0, r1] - ldr r2, [r4] - mov r3, 0x2 - b _082E3D8C -_082E3D5C: - mvn r3, 0x660 - sub r3, r3, 0x9 - strh r3, [r0, r1] - ldr r2, [r4] - mov r3, 0x3 - b _082E3D8C - .align 2, 0 -_082E3D74: .4byte gUnknown_03007868 -_082E3D78: - mvn r3, 0x850 - sub r3, r3, 0x2 - strh r3, [r0, r1] - ldr r2, [r4] - mov r3, 0x4 -_082E3D8C: - str r3, [r2, 0xC] -_082E3D90: - mov r12, 0x200 - add r12, r12, 0x4000002 - mov r3, 0xC3 - strh r3, [r5] - mov r1, 0x208 - ldr r2, [r4] - add r1, r1, 0x4000000 - ldrb r0, [r2, 0xA] - sub r3, r3, 0xBB - mov r3, r3, lsl r0 - strh r3, [r12] - mov r2, 0x1 - strh r2, [r1] - ldmdb r11, {r4,r5,r11,sp,lr} - bx lr - arm_func_end STWI_set_timer_in_RAM - - arm_func_start STWI_stop_timer_in_RAM -STWI_stop_timer_in_RAM: @ 82E3DCC - mov r12, sp - stmdb sp!, {r11,r12,lr,pc} - mov r1, 0x100 - ldr lr, _082E3E18 - add r0, r1, 0x4000000 - ldr r2, [lr] - sub r11, r12, 0x4 - ldrb r3, [r2, 0xA] - mov r12, 0 - str r12, [r2, 0xC] - mov r3, r3, lsl 2 - strh r12, [r3, r0] - ldr r2, [lr] - ldrb r3, [r2, 0xA] - add r1, r1, 0x4000002 - mov r3, r3, lsl 2 - strh r12, [r3, r1] - ldmdb r11, {r11,sp,lr} - bx lr - .align 2, 0 -_082E3E18: .4byte gUnknown_03007868 - arm_func_end STWI_stop_timer_in_RAM - - arm_func_start STWI_init_slave -STWI_init_slave: @ 82E3E1C - mov r12, sp - stmdb sp!, {r11,r12,lr,pc} - ldr r0, _082E3EA4 - ldr r2, [r0] - mov r3, 0x5 - str r3, [r2] - mov r1, 0 - strb r1, [r2, 0x14] - ldr r3, [r0] - strb r1, [r3, 0x4] - ldr r2, [r0] - strb r1, [r2, 0x5] - ldr r3, [r0] - strb r1, [r3, 0x6] - ldr r2, [r0] - strb r1, [r2, 0x7] - ldr r3, [r0] - strb r1, [r3, 0x8] - ldr r2, [r0] - strb r1, [r2, 0x9] - ldr r3, [r0] - str r1, [r3, 0xC] - sub r11, r12, 0x4 - strb r1, [r3, 0x10] - mov r2, 0x128 - ldr r12, [r0] - add r2, r2, 0x4000000 - strh r1, [r12, 0x12] - mov r3, 0x5000 - strb r1, [r12, 0x15] - add r3, r3, 0x82 - strh r3, [r2] - ldmdb r11, {r11,sp,lr} - bx lr - .align 2, 0 -_082E3EA4: .4byte gUnknown_03007868 - arm_func_end STWI_init_slave - - arm_func_start sub_82E3EA8 -sub_82E3EA8: @ 82E3EA8 - bx r2 - arm_func_end sub_82E3EA8 - - arm_func_start sub_82E3EAC -sub_82E3EAC: @ 82E3EAC - bx r1 - arm_func_end sub_82E3EAC - - arm_func_start sub_82E3EB0 -sub_82E3EB0: @ 82E3EB0 - bx r0 - arm_func_end sub_82E3EB0 - thumb_func_start rfu_initializeAPI rfu_initializeAPI: @ 82E3EB4 push {r4-r7,lr} @@ -2838,7 +593,7 @@ rfu_REQ_stopMode: @ 82E42C4 b _082E4362 .align 2, 0 _082E42E4: .4byte 0x04000208 -_082E42E8: .4byte gUnknown_03007868 +_082E42E8: .4byte gRfuState _082E42EC: bl AgbRFU_SoftReset bl rfu_STC_clearAPIVariables @@ -2878,7 +633,7 @@ _082E432A: b _082E4362 .align 2, 0 _082E433C: .4byte 0x00008001 -_082E4340: .4byte gUnknown_03007868 +_082E4340: .4byte gRfuState _082E4344: .4byte 0x04000100 _082E4348: .4byte 0x0105ffff _082E434C: .4byte rfu_CB_stopMode @@ -3156,7 +911,7 @@ rfu_CB_configGameData: @ 82E4500 movs r0, 0x1 b _082E4552 .align 2, 0 -_082E4544: .4byte gUnknown_03007868 +_082E4544: .4byte gRfuState _082E4548: .4byte gUnknown_03007890 _082E454C: adds r1, r6, 0 @@ -4225,7 +1980,7 @@ _082E4D18: b _082E4D88 .align 2, 0 _082E4D20: .4byte gUnknown_03007890 -_082E4D24: .4byte gUnknown_03007868 +_082E4D24: .4byte gRfuState _082E4D28: .4byte gUnknown_03007894 _082E4D2C: .4byte gUnknown_03007898 _082E4D30: @@ -5195,7 +2950,7 @@ _082E547E: pop {r1} bx r1 .align 2, 0 -_082E5484: .4byte gUnknown_03007868 +_082E5484: .4byte gRfuState thumb_func_end rfu_getMasterSlave thumb_func_start rfu_clearAllSlot @@ -6506,7 +4261,7 @@ _082E5E12: _082E5E34: .4byte gUnknown_03007898 _082E5E38: .4byte gUnknown_03007894 _082E5E3C: .4byte gUnknown_03007890 -_082E5E40: .4byte gUnknown_03007868 +_082E5E40: .4byte gRfuState _082E5E44: ldr r0, _082E5E54 bl STWI_set_Callback_M @@ -8564,7 +6319,7 @@ _082E6D88: b _082E6DD6 .align 2, 0 _082E6DB4: .4byte 0x04000200 -_082E6DB8: .4byte gUnknown_03007868 +_082E6DB8: .4byte gRfuState _082E6DBC: .4byte sub_82E6F88 _082E6DC0: .4byte 0x04000100 _082E6DC4: @@ -8612,7 +6367,7 @@ _082E6E08: .align 2, 0 _082E6E14: .4byte 0x04000208 _082E6E18: .4byte 0x04000200 -_082E6E1C: .4byte gUnknown_03007868 +_082E6E1C: .4byte gRfuState thumb_func_end sub_82E6D6C thumb_func_start sub_82E6E20 @@ -8663,7 +6418,7 @@ sub_82E6E20: @ 82E6E20 .align 2, 0 _082E6E78: .4byte 0x04000208 _082E6E7C: .4byte 0x04000200 -_082E6E80: .4byte gUnknown_03007868 +_082E6E80: .4byte gRfuState _082E6E84: .4byte 0x04000134 _082E6E88: .4byte gUnknown_030078A0 _082E6E8C: .4byte 0x05000003 diff --git a/asm/librfu_intr.s b/asm/librfu_intr.s new file mode 100644 index 0000000000..7f375e419e --- /dev/null +++ b/asm/librfu_intr.s @@ -0,0 +1,696 @@ + .include "asm/macros.inc" + + .syntax unified + + .text + + arm_func_start IntrSIO32 +IntrSIO32: @ 82E3554 + mov r12, sp + stmdb sp!, {r11,r12,lr,pc} + ldr r3, _082E35B4 + ldr r0, [r3] + ldr r2, [r0] + sub r11, r12, 0x4 + cmp r2, 0xA + bne _082E3590 + ldr r0, [r0, 0x20] + cmp r0, 0 + ldmdbeq r11, {r11,sp,lr} + bxeq lr + bl sub_82E3EB0 + ldmdb r11, {r11,sp,lr} + bx lr +_082E3590: + ldrb r3, [r0, 0x14] + cmp r3, 0x1 + bne _082E35A8 + bl sio32intr_clock_master + ldmdb r11, {r11,sp,lr} + bx lr +_082E35A8: + bl sio32intr_clock_slave + ldmdb r11, {r11,sp,lr} + bx lr + .align 2, 0 +_082E35B4: .4byte gRfuState + arm_func_end IntrSIO32 + + arm_func_start sio32intr_clock_master +sio32intr_clock_master: @ 82E35B8 + mov r12, sp + stmdb sp!, {r4-r6,r11,r12,lr,pc} + mov r0, 0x50 + sub r11, r12, 0x4 + bl STWI_set_timer_in_RAM + mov r4, 0x120 + ldr r2, _082E382C + add r4, r4, 0x4000000 + ldr lr, [r4] + ldr r12, [r2] + ldr r3, [r12] + mov r6, r2 + cmp r3, 0 + bne _082E3638 + cmp lr, 0x80000000 + bne _082E36B8 + ldrb r2, [r12, 0x5] + ldrb r3, [r12, 0x4] + cmp r2, r3 + bhi _082E3628 + ldr r3, [r12, 0x24] + mov r1, r2 + ldr r2, [r3, r1, lsl 2] + str r2, [r4] + ldrb r3, [r12, 0x5] + add r3, r3, 0x1 + strb r3, [r12, 0x5] + b _082E3714 +_082E3628: + mov r3, 0x1 + str r3, [r12] + str lr, [r4] + b _082E3714 +_082E3638: + ldr r3, [r12] + cmp r3, 0x1 + bne _082E36C8 + mov r3, 0x99000000 + add r3, r3, 0x660000 + mov r5, 0x80000000 + and r2, lr, r5, asr 15 + cmp r2, r3 + bne _082E36B8 + mov r3, 0 + strb r3, [r12, 0x8] + ldr r1, [r6] + ldrb r0, [r1, 0x8] + ldr r2, [r1, 0x28] + str lr, [r2, r0, lsl 2] + ldrb r3, [r1, 0x8] + add r3, r3, 0x1 + strb r3, [r1, 0x8] + ldr r2, [r6] + strb lr, [r2, 0x9] + ldr r3, [r6] + mov r2, lr, lsr 8 + strb r2, [r3, 0x7] + ldr r1, [r6] + ldrb r2, [r1, 0x7] + ldrb r3, [r1, 0x8] + cmp r2, r3 + bcc _082E3700 + mov r3, 0x2 + str r3, [r1] + str r5, [r4] + b _082E3714 +_082E36B8: + bl STWI_stop_timer_in_RAM + mov r0, 0x82 + bl STWI_set_timer_in_RAM + b _082E3840 +_082E36C8: + ldr r3, [r12] + cmp r3, 0x2 + bne _082E3714 + ldrb r1, [r12, 0x8] + ldr r2, [r12, 0x28] + str lr, [r2, r1, lsl 2] + ldrb r3, [r12, 0x8] + add r3, r3, 0x1 + strb r3, [r12, 0x8] + ldr r1, [r6] + ldrb r2, [r1, 0x7] + ldrb r3, [r1, 0x8] + cmp r2, r3 + bcs _082E370C +_082E3700: + mov r3, 0x3 + str r3, [r1] + b _082E3714 +_082E370C: + mov r3, 0x80000000 + str r3, [r4] +_082E3714: + mov r0, 0x1 + bl handshake_wait + mov r0, r0, lsl 16 + cmp r0, 0x10000 + beq _082E3840 + mov r4, 0x128 + add r4, r4, 0x4000000 + mov r5, 0x5000 + add r3, r5, 0xB + strh r3, [r4] + mov r0, 0 + bl handshake_wait + mov r0, r0, lsl 16 + cmp r0, 0x10000 + beq _082E3840 + bl STWI_stop_timer_in_RAM + ldr r1, [r6] + ldr r0, [r1] + cmp r0, 0x3 + bne _082E3830 + ldrb r3, [r1, 0x9] + cmp r3, 0xA5 + cmpne r3, 0xA7 + beq _082E3788 + and r3, r3, 0xFF + cmp r3, 0xB5 + beq _082E3788 + cmp r3, 0xB7 + bne _082E37D0 +_082E3788: + mov r1, 0x120 + add r1, r1, 0x4000000 + mov r12, 0x128 + add r12, r12, 0x4000000 + ldr r0, [r6] + mov r3, 0 + strb r3, [r0, 0x14] + mov r2, 0x80000000 + str r2, [r1] + add r3, r3, 0x5000 + add r2, r3, 0x2 + strh r2, [r12] + add r3, r3, 0x82 + strh r3, [r12] + ldr r2, [r6] + mov r3, 0x5 + str r3, [r2] + b _082E3800 +_082E37D0: + cmp r3, 0xEE + bne _082E37F0 + add r3, r5, 0x3 + strh r3, [r4] + mov r2, 0x4 + str r2, [r1] + strh r0, [r1, 0x12] + b _082E3800 +_082E37F0: + add r3, r5, 0x3 + strh r3, [r4] + mov r2, 0x4 + str r2, [r1] +_082E3800: + ldr r2, [r6] + mov r3, 0 + strb r3, [r2, 0x2C] + ldr r0, [r6] + ldr r2, [r0, 0x18] + cmp r2, r3 + beq _082E3840 + ldrh r1, [r0, 0x12] + ldrb r0, [r0, 0x6] + bl sub_82E3EA8 + b _082E3840 + .align 2, 0 +_082E382C: .4byte gRfuState +_082E3830: + add r3, r5, 0x3 + strh r3, [r4] + add r2, r5, 0x83 + strh r2, [r4] +_082E3840: + ldmdb r11, {r4-r6,r11,sp,lr} + bx lr + arm_func_end sio32intr_clock_master + + arm_func_start sio32intr_clock_slave +sio32intr_clock_slave: @ 82E3848 + mov r12, sp + stmdb sp!, {r4-r6,r11,r12,lr,pc} + ldr r4, _082E3BF4 + mov r0, 0x64 + ldr r3, [r4] + mov r6, 0 + strb r6, [r3, 0x10] + sub r11, r12, 0x4 + bl STWI_set_timer_in_RAM + mov r0, r6 + bl handshake_wait + mov r0, r0, lsl 16 + cmp r0, 0x10000 + mov r5, r4 + beq _082E3C4C + mov r3, 0x128 + add r3, r3, 0x4000000 + mov r2, 0x5000 + add r2, r2, 0xA + strh r2, [r3] + mov lr, 0x120 + ldr r0, [r5] + add lr, lr, 0x4000000 + ldr r12, [lr] + ldr r3, [r0] + cmp r3, 0x5 + bne _082E3978 + ldr r3, [r0, 0x28] + mov r4, 0x1 + mov r0, 0x99000000 + str r12, [r3] + add r0, r0, 0x660000 + ldr r2, [r5] + mov r3, r0, lsr 16 + strb r4, [r2, 0x5] + cmp r3, r12, lsr 16 + bne _082E3AC4 + ldr r3, [r5] + mov r2, r12, lsr 8 + strb r2, [r3, 0x4] + ldr r2, [r5] + strb r12, [r2, 0x6] + ldr r1, [r5] + ldrb r3, [r1, 0x4] + cmp r3, r6 + bne _082E395C + ldrb r2, [r1, 0x6] + sub r3, r2, 0x27 + cmp r2, 0x36 + cmpne r3, 0x2 + bhi _082E3930 + add r3, r2, 0x80 + strb r3, [r1, 0x9] + ldr r2, [r5] + ldrb r3, [r2, 0x9] + ldr r1, [r2, 0x24] + add r3, r3, r0 + b _082E39E0 +_082E3930: + ldr r2, [r1, 0x24] + ldr r3, _082E3BF8 + str r3, [r2] + ldr r2, [r5] + ldrb r3, [r2, 0x6] + sub r3, r3, 0x10 + cmp r3, 0x2D + bhi _082E3A18 + ldr r3, [r2, 0x24] + str r4, [r3, 0x4] + b _082E3A24 +_082E395C: + mov r3, 0x80000000 + str r3, [lr] + strb r4, [r1, 0x5] + ldr r2, [r5] + add r3, r3, 0x80000006 + str r3, [r2] + b _082E3AD4 +_082E3978: + ldr r3, [r0] + cmp r3, 0x6 + bne _082E3A78 + ldrb r1, [r0, 0x5] + ldr r2, [r0, 0x28] + str r12, [r2, r1, lsl 2] + ldrb r3, [r0, 0x5] + add r3, r3, 0x1 + strb r3, [r0, 0x5] + ldr r1, [r5] + ldrb r2, [r1, 0x4] + ldrb r3, [r1, 0x5] + cmp r2, r3 + bcs _082E3A6C + ldrb r2, [r1, 0x6] + sub r3, r2, 0x28 + cmp r2, 0x36 + cmpne r3, 0x1 + bhi _082E39F0 + add r3, r2, 0x80 + strb r3, [r1, 0x9] + ldr r2, [r5] + ldrb r3, [r2, 0x9] + ldr r1, [r2, 0x24] + orr r3, r3, 0x99000000 + orr r3, r3, 0x660000 +_082E39E0: + str r3, [r1] + ldr r2, [r5] + strb r6, [r2, 0x7] + b _082E3A3C +_082E39F0: + ldr r2, [r1, 0x24] + ldr r3, _082E3BF8 + str r3, [r2] + ldr r2, [r5] + ldrb r3, [r2, 0x6] + sub r3, r3, 0x10 + cmp r3, 0x2D + ldrls r2, [r2, 0x24] + movls r3, 0x1 + bls _082E3A20 +_082E3A18: + ldr r2, [r2, 0x24] + mov r3, 0x2 +_082E3A20: + str r3, [r2, 0x4] +_082E3A24: + ldr r2, [r5] + mov r3, 0x1 + strb r3, [r2, 0x7] + ldr r1, [r5] + add r3, r3, 0x2 + strh r3, [r1, 0x12] +_082E3A3C: + ldr r0, [r5] + ldr r2, [r0, 0x24] + mov r3, 0x120 + ldr r1, [r2] + add r3, r3, 0x4000000 + str r1, [r3] + mov r2, 0x1 + strb r2, [r0, 0x8] + ldr r1, [r5] + mov r3, 0x7 + str r3, [r1] + b _082E3AD4 +_082E3A6C: + mov r3, 0x80000000 + str r3, [lr] + b _082E3AD4 +_082E3A78: + ldr r3, [r0] + cmp r3, 0x7 + bne _082E3AD4 + cmp r12, 0x80000000 + bne _082E3AC4 + ldrb r2, [r0, 0x7] + ldrb r3, [r0, 0x8] + cmp r2, r3 + movcc r3, 0x8 + strcc r3, [r0] + bcc _082E3AD4 + ldrb r1, [r0, 0x8] + ldr r3, [r0, 0x24] + ldr r2, [r3, r1, lsl 2] + str r2, [lr] + ldrb r3, [r0, 0x8] + add r3, r3, 0x1 + strb r3, [r0, 0x8] + b _082E3AD4 +_082E3AC4: + bl STWI_stop_timer_in_RAM + mov r0, 0x64 + bl STWI_set_timer_in_RAM + b _082E3C4C +_082E3AD4: + mov r0, 0x1 + bl handshake_wait + mov r0, r0, lsl 16 + cmp r0, 0x10000 + beq _082E3C4C + mov r6, r5 + ldr r3, [r6] + ldr r2, [r3] + cmp r2, 0x8 + bne _082E3B9C + mov r4, 0x128 + add r4, r4, 0x4000000 + mov r3, 0x5000 + add r3, r3, 0x2 + strh r3, [r4] + bl STWI_stop_timer_in_RAM + ldr r0, [r6] + ldrh r3, [r0, 0x12] + cmp r3, 0x3 + bne _082E3B48 + bl STWI_init_slave + ldr r3, [r6] + ldr r1, [r3, 0x1C] + cmp r1, 0 + beq _082E3C4C + mov r0, 0x1EC + add r0, r0, 0x2 + bl sub_82E3EAC + b _082E3C4C +_082E3B48: + mov r3, 0x120 + add r3, r3, 0x4000000 + mov r1, 0 + str r1, [r3] + mov r2, 0x5000 + strh r1, [r4] + add r2, r2, 0x3 + strh r2, [r4] + mov r3, 0x1 + strb r3, [r0, 0x14] + ldr r0, [r5] + ldr r2, [r0, 0x1C] + str r1, [r0] + cmp r2, r1 + beq _082E3C4C + ldrb r3, [r0, 0x4] + ldrb r0, [r0, 0x6] + mov r1, r2 + orr r0, r0, r3, lsl 8 + bl sub_82E3EAC + b _082E3C4C +_082E3B9C: + mov r3, 0x208 + add r3, r3, 0x4000000 + mov r2, 0 + strh r2, [r3] + mov r1, 0x100 + add r2, r1, 0x4000002 + ldrh r3, [r2] + tst r3, 0x80 + beq _082E3C20 + ldrh r3, [r2] + tst r3, 0x3 + bne _082E3BFC + mov r2, 0xFF00 + add r1, r1, 0x4000000 + ldrh r3, [r1] + add r2, r2, 0x9B + cmp r3, r2 + bls _082E3C20 +_082E3BE4: + ldrh r3, [r1] + cmp r3, r2 + bhi _082E3BE4 + b _082E3C20 + .align 2, 0 +_082E3BF4: .4byte gRfuState +_082E3BF8: .4byte 0x996601ee +_082E3BFC: + mov r2, 0xFF00 + add r1, r1, 0x4000000 + ldrh r3, [r1] + add r2, r2, 0xFE + cmp r3, r2 + bls _082E3C20 +_082E3C14: + ldrh r3, [r1] + cmp r3, r2 + bhi _082E3C14 +_082E3C20: + mov r1, 0x128 + add r1, r1, 0x4000000 + mov r0, 0x208 + add r0, r0, 0x4000000 + mov r3, 0x5000 + add r2, r3, 0x2 + strh r2, [r1] + add r3, r3, 0x82 + strh r3, [r1] + mov r2, 0x1 + strh r2, [r0] +_082E3C4C: + ldmdb r11, {r4-r6,r11,sp,lr} + bx lr + arm_func_end sio32intr_clock_slave + + arm_func_start handshake_wait +handshake_wait: @ 82E3C54 + mov r12, sp + stmdb sp!, {r11,r12,lr,pc} + mov r1, 0x128 + add r1, r1, 0x4000000 + mov r0, r0, lsl 16 + ldr r2, _082E3CB8 + sub r11, r12, 0x4 + mov lr, r0, lsr 14 + ldr r12, [r2] +_082E3C78: + ldrb r3, [r12, 0x10] + and r0, r3, 0xFF + cmp r0, 0x1 + beq _082E3CA4 + ldrh r3, [r1] + and r3, r3, 0x4 + cmp r3, lr + bne _082E3C78 + mov r0, 0 + ldmdb r11, {r11,sp,lr} + bx lr +_082E3CA4: + ldr r2, [r2] + mov r3, 0 + strb r3, [r2, 0x10] + ldmdb r11, {r11,sp,lr} + bx lr + .align 2, 0 +_082E3CB8: .4byte gRfuState + arm_func_end handshake_wait + + arm_func_start STWI_set_timer_in_RAM +STWI_set_timer_in_RAM: @ 82E3CBC + mov r12, sp + stmdb sp!, {r4,r5,r11,r12,lr,pc} + mov r1, 0x208 + add r1, r1, 0x4000000 + mov r3, 0 + sub r11, r12, 0x4 + ldr r12, _082E3D74 + and lr, r0, 0xFF + ldr r2, [r12] + cmp lr, 0x50 + ldrb r0, [r2, 0xA] + mov r4, r12 + mov r2, lr + strh r3, [r1] + mov r0, r0, lsl 2 + add r3, r3, 0x100 + add r1, r3, 0x4000000 + add r3, r3, 0x4000002 + add r5, r0, r3 + beq _082E3D44 + bgt _082E3D1C + cmp lr, 0x32 + beq _082E3D30 + b _082E3D90 +_082E3D1C: + cmp r2, 0x64 + beq _082E3D5C + cmp r2, 0x82 + beq _082E3D78 + b _082E3D90 +_082E3D30: + mvn r3, 0x334 + strh r3, [r0, r1] + ldr r2, [r4] + mov r3, 0x1 + b _082E3D8C +_082E3D44: + mov r3, 0xAE000000 + mov r3, r3, asr 20 + strh r3, [r0, r1] + ldr r2, [r4] + mov r3, 0x2 + b _082E3D8C +_082E3D5C: + mvn r3, 0x660 + sub r3, r3, 0x9 + strh r3, [r0, r1] + ldr r2, [r4] + mov r3, 0x3 + b _082E3D8C + .align 2, 0 +_082E3D74: .4byte gRfuState +_082E3D78: + mvn r3, 0x850 + sub r3, r3, 0x2 + strh r3, [r0, r1] + ldr r2, [r4] + mov r3, 0x4 +_082E3D8C: + str r3, [r2, 0xC] +_082E3D90: + mov r12, 0x200 + add r12, r12, 0x4000002 + mov r3, 0xC3 + strh r3, [r5] + mov r1, 0x208 + ldr r2, [r4] + add r1, r1, 0x4000000 + ldrb r0, [r2, 0xA] + sub r3, r3, 0xBB + mov r3, r3, lsl r0 + strh r3, [r12] + mov r2, 0x1 + strh r2, [r1] + ldmdb r11, {r4,r5,r11,sp,lr} + bx lr + arm_func_end STWI_set_timer_in_RAM + + arm_func_start STWI_stop_timer_in_RAM +STWI_stop_timer_in_RAM: @ 82E3DCC + mov r12, sp + stmdb sp!, {r11,r12,lr,pc} + mov r1, 0x100 + ldr lr, _082E3E18 + add r0, r1, 0x4000000 + ldr r2, [lr] + sub r11, r12, 0x4 + ldrb r3, [r2, 0xA] + mov r12, 0 + str r12, [r2, 0xC] + mov r3, r3, lsl 2 + strh r12, [r3, r0] + ldr r2, [lr] + ldrb r3, [r2, 0xA] + add r1, r1, 0x4000002 + mov r3, r3, lsl 2 + strh r12, [r3, r1] + ldmdb r11, {r11,sp,lr} + bx lr + .align 2, 0 +_082E3E18: .4byte gRfuState + arm_func_end STWI_stop_timer_in_RAM + + arm_func_start STWI_init_slave +STWI_init_slave: @ 82E3E1C + mov r12, sp + stmdb sp!, {r11,r12,lr,pc} + ldr r0, _082E3EA4 + ldr r2, [r0] + mov r3, 0x5 + str r3, [r2] + mov r1, 0 + strb r1, [r2, 0x14] + ldr r3, [r0] + strb r1, [r3, 0x4] + ldr r2, [r0] + strb r1, [r2, 0x5] + ldr r3, [r0] + strb r1, [r3, 0x6] + ldr r2, [r0] + strb r1, [r2, 0x7] + ldr r3, [r0] + strb r1, [r3, 0x8] + ldr r2, [r0] + strb r1, [r2, 0x9] + ldr r3, [r0] + str r1, [r3, 0xC] + sub r11, r12, 0x4 + strb r1, [r3, 0x10] + mov r2, 0x128 + ldr r12, [r0] + add r2, r2, 0x4000000 + strh r1, [r12, 0x12] + mov r3, 0x5000 + strb r1, [r12, 0x15] + add r3, r3, 0x82 + strh r3, [r2] + ldmdb r11, {r11,sp,lr} + bx lr + .align 2, 0 +_082E3EA4: .4byte gRfuState + arm_func_end STWI_init_slave + + arm_func_start sub_82E3EA8 +sub_82E3EA8: @ 82E3EA8 + bx r2 + arm_func_end sub_82E3EA8 + + arm_func_start sub_82E3EAC +sub_82E3EAC: @ 82E3EAC + bx r1 + arm_func_end sub_82E3EAC + + arm_func_start sub_82E3EB0 +sub_82E3EB0: @ 82E3EB0 + bx r0 + arm_func_end sub_82E3EB0 diff --git a/asm/title_screen.s b/asm/title_screen.s index 961b142101..bc9401fb6a 100644 --- a/asm/title_screen.s +++ b/asm/title_screen.s @@ -1228,7 +1228,7 @@ c2_clear_save_data_screen_1: @ 80AAEF0 lsls r0, 24 cmp r0, 0 bne _080AAF02 - ldr r0, =c2_clear_save_data_screen_2 + ldr r0, =CB2_InitClearSaveDataScreen bl SetMainCallback2 _080AAF02: pop {r0} diff --git a/data/clear_save_data_screen.s b/data/clear_save_data_screen.s deleted file mode 100644 index 3abf9bf6d3..0000000000 --- a/data/clear_save_data_screen.s +++ /dev/null @@ -1,17 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - - .align 2 -gUnknown_085F06C0:: @ 85F06C0 - .4byte 0x000001f0, 0x000011e3 - - .align 2 -gUnknown_085F06C8:: @ 85F06C8 - window_template 0x00, 0x03, 0x0f, 0x1a, 0x04, 0x0f, 0x000b - window_template_terminator - - .align 2 -gUnknown_085F06D8:: @ 85F06D8 - window_template 0x00, 0x03, 0x02, 0x05, 0x04, 0x0f, 0x0073 diff --git a/include/gba/io_reg.h b/include/gba/io_reg.h index a2be31975d..f86f2434cb 100644 --- a/include/gba/io_reg.h +++ b/include/gba/io_reg.h @@ -137,6 +137,8 @@ #define REG_OFFSET_DMA3CNT_H 0xde #define REG_OFFSET_TMCNT 0x100 +#define REG_OFFSET_TMCNT_L 0x100 +#define REG_OFFSET_TMCNT_H 0x102 #define REG_OFFSET_TM0CNT 0x100 #define REG_OFFSET_TM0CNT_L 0x100 #define REG_OFFSET_TM0CNT_H 0x102 @@ -298,6 +300,8 @@ #define REG_ADDR_DMA3CNT_H (REG_BASE + REG_OFFSET_DMA3CNT_H) #define REG_ADDR_TMCNT (REG_BASE + REG_OFFSET_TMCNT) +#define REG_ADDR_TMCNT_L (REG_BASE + REG_OFFSET_TMCNT_L) +#define REG_ADDR_TMCNT_H (REG_BASE + REG_OFFSET_TMCNT_H) #define REG_ADDR_TM0CNT (REG_BASE + REG_OFFSET_TM0CNT) #define REG_ADDR_TM0CNT_L (REG_BASE + REG_OFFSET_TM0CNT_L) #define REG_ADDR_TM0CNT_H (REG_BASE + REG_OFFSET_TM0CNT_H) @@ -458,6 +462,8 @@ #define REG_DMA3CNT_H (*(vu16 *)REG_ADDR_DMA3CNT_H) #define REG_TMCNT(n) (*(vu16 *)(REG_ADDR_TMCNT + ((n) * 4))) +#define REG_TMCNT_L(n) (*(vu16 *)(REG_ADDR_TMCNT_L + ((n) * 4))) +#define REG_TMCNT_H(n) (*(vu16 *)(REG_ADDR_TMCNT_H + ((n) * 4))) #define REG_TM0CNT (*(vu32 *)REG_ADDR_TM0CNT) #define REG_TM0CNT_L (*(vu16 *)REG_ADDR_TM0CNT_L) #define REG_TM0CNT_H (*(vu16 *)REG_ADDR_TM0CNT_H) diff --git a/include/gba/macro.h b/include/gba/macro.h index 0217898e84..7b6b98c067 100644 --- a/include/gba/macro.h +++ b/include/gba/macro.h @@ -86,4 +86,14 @@ dmaRegs[5]; \ } +#define IntrEnable(flags) \ +{ \ + u16 imeTemp; \ + \ + imeTemp = REG_IME; \ + REG_IME = 0; \ + REG_IE |= flags; \ + REG_IME = imeTemp; \ +} \ + #endif // GUARD_GBA_MACRO_H diff --git a/include/librfu.h b/include/librfu.h new file mode 100644 index 0000000000..dbc8a41a62 --- /dev/null +++ b/include/librfu.h @@ -0,0 +1,108 @@ +#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 struct RfuStruct *gRfuState; + +void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam); diff --git a/include/menu.h b/include/menu.h index 480ffd1cef..ce653274ce 100644 --- a/include/menu.h +++ b/include/menu.h @@ -23,5 +23,7 @@ void reset_temp_tile_data_buffers(void); int decompress_and_copy_tile_data_to_vram(u8 bg_id, const void *src, int size, u16 offset, u8 mode); bool8 free_temp_tile_data_buffers_if_possible(void); u64 sub_8198A50(struct WindowTemplate*, u8, u8, u8, u8, u8, u8, u16); // returns something but it isn't used, fix when menu.s is decomp'd +void CreateYesNoMenu(const struct WindowTemplate *windowTemplate, u16 borderFirstTileNum, u8 borderPalette, u8 initialCursorPos); +s8 sub_8198C58(void); #endif // GUARD_MENU_H diff --git a/ld_script.txt b/ld_script.txt index 31d2fd7288..54ed8a7f88 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -226,7 +226,7 @@ SECTIONS { src/save_failed_screen.o(.text); src/braille_puzzles.o(.text); asm/pokeblock_feed.o(.text); - asm/clear_save_data_screen.o(.text); + src/clear_save_data_screen.o(.text); asm/intro_credits_graphics.o(.text); asm/evolution_graphics.o(.text); asm/bard_music.o(.text); @@ -295,6 +295,10 @@ SECTIONS { src/agb_flash_1m.o(.text); src/agb_flash_mx.o(.text); src/siirtc.o(.text); + src/librfu_stwi.o(.text); + src/librfu_intr.o(.text); + asm/librfu_intr.o(.text); + src/librfu_rfu.o(.text); asm/librfu.o(.text); asm/libagbsyscall.o(.text); tools/agbcc/lib/libgcc.a:_call_via_rX.o(.text); @@ -443,7 +447,7 @@ SECTIONS { src/save_failed_screen.o(.rodata); data/braille_puzzles.o(.rodata); data/pokeblock_feed.o(.rodata); - data/clear_save_data_screen.o(.rodata); + src/clear_save_data_screen.o(.rodata); data/intro_credits_graphics.o(.rodata); data/evolution_graphics.o(.rodata); data/bard_music.o(.rodata); diff --git a/src/clear_save_data_screen.c b/src/clear_save_data_screen.c new file mode 100755 index 0000000000..3192e0e116 --- /dev/null +++ b/src/clear_save_data_screen.c @@ -0,0 +1,209 @@ +#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 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, 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); + 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, 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); +} diff --git a/src/librfu_intr.c b/src/librfu_intr.c new file mode 100644 index 0000000000..bdf8b072a6 --- /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 0000000000..cf3fe12ad4 --- /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 0000000000..21d38bb38a --- /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; +} diff --git a/sym_common.txt b/sym_common.txt index 996463bb8c..a825b96866 100644 --- a/sym_common.txt +++ b/sym_common.txt @@ -432,7 +432,7 @@ gUnknown_03006370: @ 3006370 .include "agb_flash.o" -gUnknown_03007868: @ 3007868 +gRfuState: @ 3007868 .space 0x8 gUnknown_03007870: @ 3007870