Merge branch 'librfu-decomp'

This commit is contained in:
Diegoisawesome 2017-10-21 20:11:31 -05:00
commit 667914075b
11 changed files with 1635 additions and 2256 deletions

View File

@ -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

File diff suppressed because it is too large Load Diff

696
asm/librfu_intr.s Normal file
View File

@ -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

View File

@ -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)

View File

@ -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

108
include/librfu.h Normal file
View File

@ -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);

View File

@ -291,6 +291,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);

4
src/librfu_intr.c Normal file
View File

@ -0,0 +1,4 @@
#include "global.h"
#include "main.h"
//TODO: decompile asm/librfu_intr.s to here

109
src/librfu_rfu.c Normal file
View File

@ -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;
}*/

687
src/librfu_stwi.c Normal file
View File

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

View File

@ -432,7 +432,7 @@ gUnknown_03006370: @ 3006370
.include "agb_flash.o"
gUnknown_03007868: @ 3007868
gRfuState: @ 3007868
.space 0x8
gUnknown_03007870: @ 3007870