Port librfu from firered

This commit is contained in:
PikalaxALT 2020-02-16 13:49:36 -05:00
parent ac1738e11d
commit 91dd7f5cc3
32 changed files with 7005 additions and 6967 deletions

View File

@ -231,6 +231,10 @@ $(C_BUILDDIR)/agb_flash_mx.o: CFLAGS := -O -mthumb-interwork
$(C_BUILDDIR)/m4a.o: CC1 := tools/agbcc/bin/old_agbcc
$(C_BUILDDIR)/record_mixing.o: CFLAGS += -ffreestanding
$(C_BUILDDIR)/librfu_intr.o: CC1 := tools/agbcc/bin/agbcc_arm
$(C_BUILDDIR)/librfu_intr.o: CFLAGS := -O2 -mthumb-interwork -quiet
else
$(C_BUILDDIR)/librfu_intr.o: CFLAGS := -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -fno-aggressive-loop-optimizations -Wno-pointer-to-int-cast
endif
ifeq ($(NODEP),1)

View File

@ -1,696 +0,0 @@
.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 Callback_Dummy_ID
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 gSTWIStatus
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 Callback_Dummy_M
b _082E3840
.align 2, 0
_082E382C: .4byte gSTWIStatus
_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 Callback_Dummy_S
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 Callback_Dummy_S
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 gSTWIStatus
_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 gSTWIStatus
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 gSTWIStatus
_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 gSTWIStatus
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 gSTWIStatus
arm_func_end STWI_init_slave
arm_func_start Callback_Dummy_M
Callback_Dummy_M: @ 82E3EA8
bx r2
arm_func_end Callback_Dummy_M
arm_func_start Callback_Dummy_S
Callback_Dummy_S: @ 82E3EAC
bx r1
arm_func_end Callback_Dummy_S
arm_func_start Callback_Dummy_ID
Callback_Dummy_ID: @ 82E3EB0
bx r0
arm_func_end Callback_Dummy_ID

View File

@ -0,0 +1 @@
lman

View File

@ -1,2 +0,0 @@
gUnknown_03004140
gUnknown_03005000

View File

@ -0,0 +1,2 @@
gf_rfu_REQ_api
Rfu

View File

@ -0,0 +1,202 @@
#ifndef GUARD_LINKMANAGER_H
#define GUARD_LINKMANAGER_H
//-----------------------------------------------------------------
// Constant definition
//-----------------------------------------------------------------
// Link Manager operation mode (specified by u8 parent_child argument of rfu_LMAN_establishConnection)
//#define MODE_CHILD 0 // Start Link Manager in CHILD mode
//#define MODE_PARENT 1 // Start Link Manager in PARENT mode
//Note: This value uses the item defined by AgbRFU_LL.h.
#define MODE_P_C_SWITCH 2 // Start Link Manager in parent-child switching mode.
// Value of lman.p_c_switch_flag
#define PCSWITCH_1ST_SC_START 0x01
#define PCSWITCH_1ST_SC 0x02
#define PCSWITCH_2ND_SP_START 0x03
#define PCSWITCH_2ND_SP 0x04
#define PCSWITCH_3RD_SC_START 0x05
#define PCSWITCH_3RD_SC 0x06
#define PCSWITCH_CP 0x07
#define PCSWITCH_SC_LOCK 0x08
#define PCSWITCH_FORCE_SP_START 0x09
// Period for which parent-child switching search specified
#define PCSWITCH_ALL_PERIOD 180 // Entire cycle 180 frames
#define PCSWITCH_SP_PERIOD 40 // Child period 40 frames
// Error code returned by Link Manager API (rfu_LMAN_...return value of function)
#define LMAN_ERROR_MANAGER_BUSY 1 // Link Manager is already running.
#define LMAN_ERROR_AGB_CLK_SLAVE 2 // AGB is clock slave so link manager cannot run.
#define LMAN_ERROR_PID_NOT_FOUND 3 // Parent device information of the specified PID does not exist in rfuLinkStatus->partner[0-3].
#define LMAN_ERROR_ILLEGAL_PARAMETER 4 // Specified argument is unusual.
#define LMAN_ERROR_NOW_LINK_RECOVERY 5 // New settings were ignored because link recovery was under way when current link recovery was ON and new settings turned link recovery OFF.
#define LMAN_ERROR_NOW_COMMUNICATION 6 // New settings were ignored because currently communicating with NI.
#define LMAN_ERROR_NOW_SEARCH_PARENT 7 // Parent search currently under way, so ignore new setting.
// Details of messages and the related parameters returned by the u8 msg, u8 param_count, and lman.param[0-1] arguments of the LMAN callback generated by the operation of the Link Manager.
// msg name msg No. param qty param[0] param[1] Description
#define LMAN_MSG_INITIALIZE_COMPLETED 0x00 // 0 - - Generated when RFU reset and initial settings are completed
#define LMAN_MSG_NEW_CHILD_CONNECT_DETECTED 0x10 // 1 Bit indicating slot - Generated when new child device connection was detected at RFU level.
// with detected connection
#define LMAN_MSG_NEW_CHILD_CONNECT_ACCEPTED 0x11 // 1 Bit indicating slot - Generated when game identification information from child device connected at RFU level is received and accepted (game serial numbers match).
// where connection was accepted
#define LMAN_MSG_NEW_CHILD_CONNECT_REJECTED 0x12 // 1 Bit indicating slot - Generated when the connection from the child device connected at RFU level is rejected (game identification information reception failed or game serial numbers do not match).
// where connection was rejected
#define LMAN_MSG_SEARCH_CHILD_PERIOD_EXPIRED 0x13 // 0 - - Generated when SearchChild operation time expires.
#define LMAN_MSG_END_WAIT_CHILD_NAME 0x14 // 0 - - Generated when reception of game identification information from all child devices completes after the SearchChild operation time expires.
#define LMAN_MSG_PARENT_FOUND 0x20 // 1 Bit indicating - Generated when valid (game serial numbers match) parent devices are found during SearchParent.
// rfuLinkStatus->partner[x] index number storing the valid parent devices (game serial number matches) from among the discovered parent devices.
#define LMAN_MSG_SEARCH_PARENT_PERIOD_EXPIRED 0x21 // 0 - - Generated when SearchParent time expires.
#define LMAN_MSG_CONNECT_PARENT_SUCCESSED 0x22 // 1 Connected slot number - Generated when connection with parent device at RFU level succeeds.
#define LMAN_MSG_CONNECT_PARENT_FAILED 0x23 // 1 Connection failure reason - Generated when connection with parent device at RFU level fails.
#define LMAN_MSG_CHILD_NAME_SEND_COMPLETED 0x24 // 0 - - Generated when transmission of the child's game identification information to the parent device succeeds after connection with parent device at RFU level succeeds.
#define LMAN_MSG_CHILD_NAME_SEND_FAILED_AND_DISCONNECTED 0x25 // 0 - - Generated when transmission of the child's game identification information to the parent device fails after connection with parent device at RFU level succeeds.
#define LMAN_MSG_LINK_LOSS_DETECTED_AND_DISCONNECTED 0x30 // 1 Bit indicating slot - Generated when a link cut is detected and that slot disconnects. (Generated only when link recovery is OFF.)
// that was disconnected and where link cut was detected but link recover not attempted
#define LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY 0x31 // 1 Bit indicating slot - Generated when a link cut is detected and the link recovery process starts. (Generated only when link recovery is ON.)
// where link cut was detected and link recovery was started
#define LMAN_MSG_LINK_RECOVERY_SUCCESSED 0x32 // 1 Bit indicating slot - Generated when link recovery succeeds. (Generated only when link recovery is ON.)
// where link recovery succeeded
#define LMAN_MSG_LINK_RECOVERY_FAILED_AND_DISCONNECTED 0x33 // 1 Bit indicating slot - Generated when link recovery fails and that slot disconnects. (Generated only when link recovery is ON.)
// where link recovery failed and that disconnected
#define LMAN_MSG_LINK_DISCONNECTED_BY_USER 0x40 // 1 Generated on disconnection by execution of rfu_REQ_disconnect by disconnected user.
// Slot indicated in bits *Note: If rfu_REQ_disconnect is used for disconnection during link recovery in the child device, the link recovery is also suspended, but the only message returned is DISCONNECTED_BY_USER.
#define LMAN_MSG_CHANGE_AGB_CLOCK_SLAVE 0x41 // 0 - - Generated when the AGB-RFU clock switches to AGB clock slave after a successful connection or link recovery in the child device. (This message is not generated when the AGB switches to a clock slave when an MSC callback completes.)
#define LMAN_MSG_CHANGE_AGB_CLOCK_MASTER 0x45 // 0 - - Generated when the AGB-RFU intercommunication clock is switched to the AGB clock master in the child device.
#define LMAN_MSG_RFU_POWER_DOWN 0x42 // 0 - - Generated when the RFU enters power conservation mode with rfu_LMAN_powerDownRFU.
#define LMAN_MSG_MANAGER_STOPPED 0x43 // 0 - - Generated when the Link Manager is halted by rfu_LMAN_stopLMAN(0). (This message is not generated during SearchChild, SearchParent, ConnectParent, and LinkRecovery. A message (-PERIOD_EXPIRED, -SUCCESSED, -FAILED) corresponding to the operation completion is returned.)
#define LMAN_MSG_MANAGER_FORCED_STOPPED_AND_RFU_RESET 0x44 // 0 - - Generates when the Link Manager is forcibly halted by rfu_LMAN_stopLMAN(1) and RFU is reset.
#define LMAN_MSG_RECV_DATA_REQ_COMPLETED 0x50 // 0 - - Generated when the execution of rfu_REQ_recvData completes. (This message is not notification of data reception from a RFU.)
#define LMAN_MSG_REQ_API_ERROR 0xf0 // 2 REQ_commandID REQ_result REQ-API resulted in error. This message is also generated by an REQ-API executed by either the link manager or the user.
#define LMAN_MSG_WATCH_DOG_TIMER_ERROR 0xf1 // 0 - - Generated when a MSC callback does not occur even after 6 seconds pass when the AGB is the clock slave.
#define LMAN_MSG_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA 0xf2 // 0 - - Generated when an automatic starting DMA, such as HDMA, is issued at the same time the RFU attempts to send notification and to return the AGB to the clock master while the AGB is the clock slave and the exchange of that information (REQ command) fails.
#define LMAN_MSG_LMAN_API_ERROR_RETURN 0xf3 // 1 Return error code - Generated when LMAN-API execution returns an error.
#define LMAN_MSG_RFU_FATAL_ERROR 0xff // 0 - - Generated when the Link Manager cannot recongize a RFU because of the execution of rfu_REQBN_softReset_and_checkID.
// Value of lman.childClockSlave_flag
#define RFU_CHILD_CLOCK_SLAVE_OFF 0 // The child device is not operating in AGB clock slave mode. (The child device is in this mode in cases such as when the child has not established a connection or during link recovery.)
#define RFU_CHILD_CLOCK_SLAVE_ON 1 // The child device is operating in AGB clock slave mode. (Child automatically enters this mode when a connection is established.)
#define RFU_CHILD_CLOCK_SLAVE_OFF_REQ 2 // The child device has requested that AGB clock slave mode be halted.
// State of Link Manager (values of lman.state, lman.next_state)
#define LMAN_STATE_READY 0x00 // Waiting
#define LMAN_STATE_SOFT_RESET_AND_CHECK_ID 0x01 // Requesting execution of rfu_REQBN_softResetAndCheckID (same as below)
#define LMAN_STATE_RESET 0x02 // rfu_REQ_reset
#define LMAN_STATE_CONFIG_SYSTEM 0x03 // rfu_REQ_configSystem
#define LMAN_STATE_CONFIG_GAME_DATA 0x04 // rfu_REQ_configGameData
#define LMAN_STATE_START_SEARCH_CHILD 0x05 // rfu_REQ_startSearchChild
#define LMAN_STATE_POLL_SEARCH_CHILD 0x06 // rfu_REQ_pollSearchChild
#define LMAN_STATE_END_SEARCH_CHILD 0x07 // rfu_REQ_endSearchChild
#define LMAN_STATE_WAIT_RECV_CHILD_NAME 0x08 // Awaiting reception of game name from connected child device.
#define LMAN_STATE_START_SEARCH_PARENT 0x09 // rfu_REQ_startSearchParent
#define LMAN_STATE_POLL_SEARCH_PARENT 0x0a // rfu_REQ_pollSearchParent
#define LMAN_STATE_END_SEARCH_PARENT 0x0b // rfu_REQ_endSearchParent
#define LMAN_STATE_START_CONNECT_PARENT 0x0c // rfu_REQ_startConnectParent
#define LMAN_STATE_POLL_CONNECT_PARENT 0x0d // rfu_REQ_pollConnectParent
#define LMAN_STATE_END_CONNECT_PARENT 0x0e // rfu_REQ_endConnectParent
#define LMAN_STATE_SEND_CHILD_NAME 0x0f // Sending child game name.
#define LMAN_STATE_START_LINK_RECOVERY 0x10 // rfu_REQ_CHILD_startConnectRecovery
#define LMAN_STATE_POLL_LINK_RECOVERY 0x11 // rfu_REQ_CHILD_pollConnectRecovery
#define LMAN_STATE_END_LINK_RECOVERY 0x12 // rfu_REQ_CHILD_endConnectRecovery
#define LMAN_STATE_MS_CHANGE 0x13 // rfu_REQ_changeMasterSlave
#define LMAN_STATE_WAIT_CLOCK_MASTER 0x14 // Waiting for AGB-RFU intercommunication clock to become AGB clock master.
#define LMAN_STATE_STOP_MODE 0x15 // rfu_REQ_stopMode
#define LMAN_STATE_BACK_STATE 0x16 // Following the completion of link-recovery processing, return the Link Manager state to the state present before link-recovery processing was initiated.
#define LMAN_FORCED_STOP_AND_RFU_RESET 0x17 // Attempt to forcibly stop Link Manager using rfu_LMAN_stopLMAN(1).
#define LMAN_STATE_WAIT_CHANGE_CLOCK_MASTER 0x18 // Attempt to return to AGB clock master after child fails in sending game name.
struct Padded_U8
{
u8 value;
};
// Parameter group used in initial setting run of the link manager (rfu_LMAN_initializeRFU)
typedef struct InitializeParametersTag {
// rfu_REQ_configSystem argument
u8 maxMFrame; // Maximum number of times to re-transmit of RFU level
u8 MC_TimerCount; // MC_Timer count (x16.7ms)
u16 availSlot_flag; // Use RFU-API constant "AVAIL_SLOT1-4" to specify the maximum number of child devices (1 - 4) that can be connected to a parent device.
// rfu_REQB_configGameData argument
u8 mboot_flag; // Multiplayer boot flag
u16 serialNo; // Game serial number
u8 *gameName; // Game name
u8 *userName; // User name
// ON/OFF flag for parent fast search operation by child.
u8 fastSearchParent_flag; // Flag indicating whether parent fast search operation to be performed by child.
// Link recovery settings
u8 linkRecovery_enable; // Determines whether or not to execute the link recovery process when a link cut occurs
u16 linkRecovery_period; // Time to spend on the link recovery process (x 16.7 ms) Note: Runs for unlimited time when specifying 0.
// Setting for NI-type data transmit/receive period
u16 NI_failCounter_limit; // Limit for failCounter during NI type data transmit/receive (x 16.7 ms) Note: Runs for unlimited time when specifying 0.
}INIT_PARAM;
// Timer that counts with the V-Blank cycle
typedef struct VblankTimerTag {
u8 active; // Timer ON/OFF (bits 0 - 3 indicate ON/OFF for each connected slot)
u16 count_max; // Maximum count value (x16.7ms)
u16 count[RFU_CHILD_MAX]; // Current count value (x 16.7 ms) for each connected slot
}VBL_TIMER;
typedef struct linkManagerTag
{
/* 0x000 */ u8 acceptSlot_flag;
/* 0x001 */ u8 acceptCount;
/* 0x002 */ vu8 childClockSlave_flag;
/* 0x003 */ vu8 parentAck_flag;
/* 0x004 */ u8 state;
/* 0x005 */ u8 next_state;
/* 0x006 */ u8 parent_child;
/* 0x007 */ u8 pcswitch_flag;
/* 0x008 */ u8 RFU_powerOn_flag;
/* 0x009 */ u8 linkRecovery_enable;
/* 0x00a */ u8 linkRecovery_start_flag;
/* 0x00b */ u8 fastSearchParent_flag;
/* 0x00c */ u8 connectSlot_flag_old;
/* 0x00d */ u8 reserveDisconnectSlot_flag;
/* 0x00e */ u8 active;
/* 0x00f */ u8 msc_exe_flag;
/* 0x010 */ u8 child_slot;
/* 0x011 */ u8 state_bak[2];
/* 0x014 */ u16 param[2];
/* 0x018 */ u16 NI_failCounter_limit;
/* 0x01a */ u16 connect_period;
/* 0x01c */ u16 pcswitch_period_bak;
/* 0x01e */ u16 work;
/* 0x020 */ u16 *acceptable_serialNo_list;
/* 0x024 */ VBL_TIMER nameAcceptTimer;
/* 0x030 */ VBL_TIMER linkRecoveryTimer;
/* 0x03c */ INIT_PARAM *init_param;
/* 0x040 */ void (*LMAN_callback)(u8, u8);
/* 0x044 */ void (*MSC_callback)(u16);
} LINK_MANAGER;
extern struct GFtgtGname gUnknown_02022B14;
extern u8 gUnknown_02022B22[];
extern struct linkManagerTag lman;
u32 rfu_LMAN_REQBN_softReset_and_checkID(void);
void rfu_LMAN_requestChangeAgbClockMaster(void);
void rfu_LMAN_initializeRFU(INIT_PARAM *init_params);
u8 rfu_LMAN_establishConnection(u8 parent_child, u16 connect_period, u16 name_accept_period, u16 *acceptable_serialNo_list);
void rfu_LMAN_stopManager(bool8 forced_stop_and_RFU_reset_flag);
void rfu_LMAN_setMSCCallback(void (*MSC_callback_p)(u16));
void rfu_LMAN_REQ_sendData(bool8 clockChangeFlag);
void rfu_LMAN_powerDownRFU(void);
u8 rfu_LMAN_CHILD_connectParent(u16 parentId, u16 connect_period);
u8 rfu_LMAN_setLinkRecovery(u8 enable_flag, u16 recovery_period);
void rfu_LMAN_manager_entity(u32 rand);
void rfu_LMAN_syncVBlank(void);
u8 rfu_LMAN_initializeManager(void (*LMAN_callback_p)(u8, u8), void (*MSC_callback_p)(u16));
void rfu_LMAN_forceChangeSP(void);
#endif //GUARD_LINKMANAGER_H

View File

@ -9,6 +9,7 @@
#define BSS_DATA __attribute__((section(".bss")))
#define IWRAM_DATA __attribute__((section("iwram_data")))
#define EWRAM_DATA __attribute__((section("ewram_data")))
#define UNUSED __attribute__((unused))
#if MODERN
#define NOINLINE __attribute__((noinline))

View File

@ -4,10 +4,10 @@
#include "global.h"
#include "main.h"
/* TODOs:
#define LIBRFU_VERSION 1026
/* TODOs:
* - documentation
* - decompile librfu_intr.s once arm support is back again
(for internal structs not documented in SDK)
* - check if any field needs to be volatile
* - check if field names make sense
*/
@ -70,6 +70,7 @@
#define ID_CPR_POLL_REQ 0x0033
#define ID_CPR_END_REQ 0x0034
#define ID_UNK35_REQ 0x0035 // not defined in SDK header
#define ID_UNK36_REQ 0x0036 // not defined in SDK header
#define ID_RESUME_RETRANSMIT_AND_CHANGE_REQ 0x0037
#define ID_STOP_MODE_REQ 0x003d
#define ID_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA_REQ 0x00ff // When the AGB is the clock slave, the RFU generates an informational notice, and an automatically started DMA, such as HDMA, is generated at the instant the AGB is being returned as the clock master. This ID is notified by a REQ callback when the exchange of this information (REQ command) fails.
@ -89,8 +90,13 @@
#define RFU_MBOOT_DOWNLOADER_SERIAL_NO 0x0000 // The game serial number of the multi-boot downloader (programs that boot without a Game Pak)
#if LIBRFU_VERSION >= 1028
#define RFU_API_BUFF_SIZE_RAM 0x0e8c // Necessary size for buffer specified by rfu_initializeAPI (fast communication version that operates the library SIO interrupt routines in RAM)
#define RFU_API_BUFF_SIZE_ROM 0x052c // Necessary size for buffer specified by rfu_initializeAPI (fast communication version that operates the library SIO interrupt routines in ROM)
#else
#define RFU_API_BUFF_SIZE_RAM 0x0e64 // Necessary size for buffer specified by rfu_initializeAPI (fast communication version that operates the library SIO interrupt routines in RAM)
#define RFU_API_BUFF_SIZE_ROM 0x0504 // Necessary size for buffer specified by rfu_initializeAPI (fast communication version that operates the library SIO interrupt routines in ROM)
#endif
#define RFU_CHILD_MAX 4 // Maximum number of slaves that can be connected to one parent device
@ -303,7 +309,11 @@ struct STWIStatus
u8 ackActiveCommand;
u8 timerSelect;
u8 unk_b;
s32 timerState; // this field is u32 in firered
#if LIBRFU_VERSION >= 1026
s32 timerState;
#else
u32 timerState;
#endif
vu8 timerActive;
u8 unk_11;
vu16 error;
@ -313,10 +323,10 @@ struct STWIStatus
u8 unk_17;
void (*callbackM)();
void (*callbackS)(u16);
void (*unk_20)(void);
void (*callbackID)(void);
union RfuPacket *txPacket;
union RfuPacket *rxPacket;
vu8 unk_2c;
vu8 sending;
};
// This struct is used as u8 array in SDK.
@ -451,54 +461,32 @@ struct RfuStatic
u8 nullFrameCount;
u8 emberCount;
u8 SCStartFlag;
u8 linkEmergencyFlag[4];
u8 lsFixedCount[4];
u16 cidBak[4];
u16 unk_1a;
u8 linkEmergencyFlag[RFU_CHILD_MAX];
u8 lsFixedCount[RFU_CHILD_MAX];
u16 cidBak[RFU_CHILD_MAX];
u16 linkEmergencyLimit;
u16 reqResult;
u16 tryPid;
u16 watchdogTimer;
u32 totalPacketSize;
};
struct RfuSIO32Id
{
u8 unk0;
u8 unk1;
u16 unk2;
u16 unk4;
u16 unk6;
u16 unk8; // unused
u16 unkA;
};
struct RfuAPIBuffer
{
struct RfuLinkStatus linkStatus;
struct RfuStatic static_;
struct RfuFixed fixed;
struct RfuSlotStatusNI NI[RFU_CHILD_MAX];
struct RfuSlotStatusUNI UNI[RFU_CHILD_MAX];
struct RfuIntrStruct intr;
};
extern struct STWIStatus *gSTWIStatus;
extern struct RfuLinkStatus *gRfuLinkStatus;
extern struct RfuStatic *gRfuStatic;
extern struct RfuFixed *gRfuFixed;
extern struct RfuSlotStatusNI *gRfuSlotStatusNI[RFU_CHILD_MAX];
extern struct RfuSlotStatusUNI *gRfuSlotStatusUNI[RFU_CHILD_MAX];
extern struct RfuSIO32Id gRfuSIO32Id;
// librfu_s32id
s32 AgbRFU_checkID(u8);
// librfu_sio32id
s32 AgbRFU_checkID(u8 maxTries);
// Arguments with "bm..." specify slots of the form (0x01 << slot number) that are the object of a function operation.
// librfu_rfu
// API Initialization and Initial Settings
// API Initialization
u16 rfu_initializeAPI(struct RfuAPIBuffer *APIBuffer, u16 buffByteSize, IntrFunc *sioIntrTable_p, bool8 copyInterruptToRam);
u16 rfu_initializeAPI(u32 *APIBuffer, u16 buffByteSize, IntrFunc *sioIntrTable_p, bool8 copyInterruptToRam);
// Set Timer Interrupt
void rfu_setTimerInterrupt(u8 timerNo, IntrFunc *timerIntrTable_p);
// Resident Function called from within a V-Blank Interrupt
@ -599,7 +587,7 @@ u16 rfu_MBOOT_CHILD_inheritanceLinkStatus(void);
// For Debug
// Obtain address of the SWTI-layer receive buffer
struct RfuIntrStruct *rfu_getSTWIRecvBuffer(void);
u8 *rfu_getSTWIRecvBuffer(void);
// Obtain RFU state
void rfu_REQ_RFUStatus(void);
u16 rfu_getRFUStatus(u8 *rfuState);
@ -625,14 +613,14 @@ void STWI_send_DataRxREQ(void);
void STWI_send_MS_ChangeREQ(void);
void STWI_send_StopModeREQ(void);
void STWI_send_SystemStatusREQ(void);
void STWI_send_GameConfigREQ(const u8 *unk1, const u8 *data);
void STWI_send_GameConfigREQ(const u8 *serial_uname, const u8 *gname);
void STWI_send_ResetREQ(void);
void STWI_send_LinkStatusREQ(void);
void STWI_send_VersionStatusREQ(void);
void STWI_send_SlotStatusREQ(void);
void STWI_send_ConfigStatusREQ(void);
void STWI_send_ResumeRetransmitAndChangeREQ(void);
void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3);
void STWI_send_SystemConfigREQ(u16 availSlotFlag, u8 maxMFrame, u8 mcTimer);
void STWI_send_SC_StartREQ(void);
void STWI_send_SC_PollingREQ(void);
void STWI_send_SC_EndREQ(void);

View File

@ -3,35 +3,40 @@
#include "librfu.h"
#include "link.h"
#include "AgbRfu_LinkManager.h"
// Exported type declarations
struct UnkLinkRfuStruct_02022B14Substruct
// RfuTgtData.gname is read as these structs.
struct GFtgtGnameSub
{
u16 unk_00_0:4;
u16 unk_00_4:1;
u16 unk_00_5:1;
u16 language:4;
u16 hasNews:1;
u16 hasCard:1;
u16 unk_00_6:1;
u16 isChampion:1;
u16 hasNationalDex:1;
u16 gameClear:1; // never read, redundant with isChampion
u16 unk_01_2:4; // always 3?
u16 gameClear:1;
u16 version:4;
u16 unk_01_6:2;
u8 playerTrainerId[2];
};
struct __attribute__((packed, aligned(2))) UnkLinkRfuStruct_02022B14
struct __attribute__((packed, aligned(2))) GFtgtGname
{
struct UnkLinkRfuStruct_02022B14Substruct unk_00;
u8 unk_04[4];
struct GFtgtGnameSub unk_00;
u8 child_sprite_gender[RFU_CHILD_MAX]; // u8 sprite_idx:3;
// u8 gender:1;
// u8 unk_4:3
// u8 active:1
u16 species:10;
u16 type:6;
u8 unk_0a_0:7;
u8 unk_0a_7:1;
u8 activity:7;
u8 started:1;
u8 playerGender:1;
u8 level:7;
u8 unk_0c;
};
u8 padding;
}; // size: RFU_GNAME_SIZE
struct UnkLinkRfuStruct_02022B2C
{
@ -40,7 +45,7 @@ struct UnkLinkRfuStruct_02022B2C
u16 unk_02;
u8 unk_04;
u16 unk_06;
struct UnkLinkRfuStruct_02022B14 *unk_08;
struct GFtgtGname *unk_08;
u8 *unk_0c;
u8 unk_10;
u8 unk_11;
@ -62,50 +67,6 @@ struct UnkLinkRfuStruct_02022B44
u8 fill_84[0x58];
};
struct UnkRfuStruct_1
{
/* 0x000 */ u8 unk_00;
/* 0x001 */ u8 unk_01;
/* 0x002 */ vu8 unk_02;
/* 0x003 */ vu8 unk_03;
/* 0x004 */ u8 unk_04;
/* 0x005 */ u8 unk_05;
/* 0x006 */ u8 unk_06;
/* 0x007 */ u8 unk_07;
/* 0x008 */ u8 unk_08;
/* 0x009 */ u8 unk_09;
/* 0x00a */ u8 unk_0a;
/* 0x00b */ u8 unk_0b;
/* 0x00c */ u8 unk_0c;
/* 0x00d */ u8 unk_0d;
/* 0x00e */ u8 unk_0e;
/* 0x00f */ u8 unk_0f;
/* 0x010 */ u8 unk_10;
/* 0x011 */ u8 unk_11;
/* 0x012 */ u8 unk_12;
// aligned
/* 0x014 */ u16 unk_14;
/* 0x016 */ u16 unk_16;
/* 0x018 */ u16 unk_18;
/* 0x01a */ u16 unk_1a;
/* 0x01c */ u16 unk_1c;
/* 0x01e */ u16 unk_1e;
/* 0x020 */ const u16 *unk_20;
/* 0x024 */ u8 unk_24;
/* 0x026 */ u16 unk_26;
/* 0x028 */ u16 unk_28[4];
/* 0x030 */ u8 unk_30;
// aligned
/* 0x032 */ u16 unk_32;
/* 0x034 */ u16 unk_34[4];
/* 0x03c */ const struct UnkLinkRfuStruct_02022B2C *unk_3c;
/* 0x040 */ void (*unk_40)(u8, u8);
/* 0x044 */ void (*unk_44)(u16);
/* 0x048 */ u8 filler_48[8];
/* 0x050 */ u32 unk_50[0x399];
/* 0xeb4 */ u8 filler_e64[12];
};
struct UnkRfuStruct_2_Sub_6c
{
/* 0x00 */ u16 unk_00;
@ -187,7 +148,7 @@ struct UnkRfuStruct_2
/* 0x100 */ u16 unk_100;
/* 0x102 */ u8 unk_102;
/* 0x103 */ u8 filler_103[0x10A - 0x103];
/* 0x10A */ struct UnkLinkRfuStruct_02022B14 unk_10A;
/* 0x10A */ struct GFtgtGname unk_10A;
u8 filler_;
u8 playerName[PLAYER_NAME_LENGTH + 1];
/* 0x124 */ struct UnkRfuStruct_2_Sub_124 unk_124;
@ -235,13 +196,11 @@ struct UnkRfuStruct_8010A14
// Exported RAM declarations
extern struct UnkRfuStruct_1 gUnknown_03004140;
extern struct UnkRfuStruct_2 gUnknown_03005000;
extern struct UnkRfuStruct_2 Rfu;
extern u8 gWirelessStatusIndicatorSpriteId;
// Exported ROM declarations
void WipeTrainerNameRecords(void);
u32 sub_800BEC0(void);
void sub_800E700(void);
void sub_800EDD4(void);
void sub_800F6FC(u8 who);
@ -270,12 +229,12 @@ u32 GetRfuRecvQueueLength(void);
void RfuVSync(void);
void sub_80111B0(bool32 a0);
u8 sub_8011A74(void);
struct UnkLinkRfuStruct_02022B14 *sub_800F7DC(void);
struct GFtgtGname *sub_800F7DC(void);
void sub_8011068(u8 a0);
void sub_8011170(u32 a0);
void sub_8011A64(u8 a0, u16 a1);
u8 sub_801048C(bool32 a0);
void sub_800DF90(struct UnkLinkRfuStruct_02022B14 *buff1, u8 *buff2);
void sub_800DF90(struct GFtgtGname *buff1, u8 *buff2);
void sub_8010F84(u8 a0, u32 a1, u32 a2);
void sub_8011C10(u32 a0);
bool32 sub_8012240(void);
@ -300,15 +259,15 @@ void sub_8010FA0(bool32 a0, bool32 a1);
void sub_8010F60(void);
void sub_8010FCC(u32 a0, u32 a1, u32 a2);
void sub_8011C84(void);
void sub_8012188(const u8 *name, struct UnkLinkRfuStruct_02022B14 *structPtr, u8 a2);
void sub_8012188(const u8 *name, struct GFtgtGname *structPtr, u8 a2);
bool32 sub_8011B90(void);
void sub_800FE50(void *a0);
bool32 sub_800E540(u16 id, u8 *name);
void sub_8011DE0(u32 arg0);
u8 sub_801100C(s32 a0);
void sub_800EF7C(void);
bool8 sub_800DE7C(struct UnkLinkRfuStruct_02022B14 *buff1, u8 *buff2, u8 idx);
bool8 sub_800DF34(struct UnkLinkRfuStruct_02022B14 *buff1, u8 *buff2, u8 idx);
bool8 sub_800DE7C(struct GFtgtGname *buff1, u8 *buff2, u8 idx);
bool8 sub_800DF34(struct GFtgtGname *buff1, u8 *buff2, u8 idx);
s32 sub_800E87C(u8 idx);
void sub_8011BA4(void);
void sub_8010198(void);
@ -318,5 +277,65 @@ bool32 sub_8011A9C(void);
void sub_80104B0(void);
void sub_8011A50(void);
void sub_80110B8(u32 a0);
bool8 sub_800DAC8(struct UnkRfuStruct_2_Sub_c1c *q1, u8 *q2);
void sub_800EAB4(void);
void sub_800EAFC(void);
void sub_800ED34(u16 unused);
void sub_800EDBC(u16 unused);
void sub_800F048(void);
void sub_800F86C(u8 unused);
void sub_800FCC4(struct UnkRfuStruct_2_Sub_6c *data);
void sub_800FD14(u16 command);
void rfufunc_80F9F44(void);
void sub_800FFB0(void);
void rfufunc_80FA020(void);
bool32 sub_8010454(u32 a0);
void sub_8010528(void);
void sub_8010750(void);
s32 sub_80107A0(void);
void sub_801084C(u8 taskId);
void sub_80109E8(u16 a0);
void sub_8010A70(void *a0);
void sub_8010AAC(u8 taskId);
void sub_8010D0C(u8 taskId);
void sub_80115EC(s32 a0);
u8 sub_8011CE4(const u8 *a0, u16 a1);
void sub_8011D6C(u32 a0);
void sub_8011E94(u32 a0, u32 a1);
bool8 sub_8012224(void);
void sub_801227C(void);
void sub_801209C(u8 taskId);
void sub_8011BF8(void);
void sub_8011BA4(void);
void sub_800D6C8(struct UnkRfuStruct_2_Sub_124 *ptr);
void sub_800D724(struct UnkRfuStruct_2_Sub_9e8 *ptr);
void sub_800D780(struct UnkRfuStruct_Sub_Unused *ptr);
void sub_800D7D8(struct UnkRfuStruct_2_Sub_124 *q1, u8 *q2);
void sub_800D888(struct UnkRfuStruct_2_Sub_9e8 *q1, u8 *q2);
bool8 sub_800D934(struct UnkRfuStruct_2_Sub_124 *q1, u8 *q2);
bool8 sub_800D9DC(struct UnkRfuStruct_2_Sub_9e8 *q1, u8 *q2);
void sub_800DA68(struct UnkRfuStruct_2_Sub_c1c *q1, const u8 *q2);
bool8 sub_800DAC8(struct UnkRfuStruct_2_Sub_c1c *q1, u8 *q2);
void sub_800DB18(struct UnkRfuStruct_Sub_Unused *q1, u8 *q2);
bool8 sub_800DB84(struct UnkRfuStruct_Sub_Unused *q1, u8 *q2);
void sub_800DBF8(u8 *q1, u8 mode);
void PkmnStrToASCII(u8 *q1, const u8 *q2);
void ASCIIToPkmnStr(u8 *q1, const u8 *q2);
u8 sub_800DD1C(u8 maxFlags);
void sub_800DD94(struct GFtgtGname *data, u8 r9, bool32 r2, s32 r3);
bool8 sub_800DE7C(struct GFtgtGname *buff1, u8 *buff2, u8 idx);
bool8 sub_800DF34(struct GFtgtGname *buff1, u8 *buff2, u8 idx);
void sub_800DF90(struct GFtgtGname *buff1, u8 *buff2);
void CreateWirelessStatusIndicatorSprite(u8 x, u8 y);
void DestroyWirelessStatusIndicatorSprite(void);
void LoadWirelessStatusIndicatorSpriteGfx(void);
u8 sub_800E124(void);
void sub_800E15C(struct Sprite *sprite, s32 signalStrengthAnimNum);
void sub_800E174(void);
void CopyTrainerRecord(struct TrainerNameRecord *dest, u32 trainerId, const u8 *name);
bool32 NameIsNotEmpty(const u8 *name);
void RecordMixTrainerNames(void);
bool32 sub_800E540(u16 id, u8 *name);
void WipeTrainerNameRecords(void);
#endif //GUARD_LINK_RFU_H

View File

@ -16,8 +16,8 @@ extern const struct WindowTemplate gTradeEvolutionSceneYesNoWindowTemplate;
s32 GetGameProgressForLinkTrade(void);
void CB2_StartCreateTradeMenu(void);
void CB2_LinkTrade(void);
int CanRegisterMonForTradingBoard(struct UnkLinkRfuStruct_02022B14Substruct a0, u16, u16, u8);
int GetUnionRoomTradeMessageId(struct UnkLinkRfuStruct_02022B14Substruct a0, struct UnkLinkRfuStruct_02022B14Substruct a1, u16 a2, u16 a3, u8 a4, u16 a5, u8 a6);
int CanRegisterMonForTradingBoard(struct GFtgtGnameSub a0, u16, u16, u8);
int GetUnionRoomTradeMessageId(struct GFtgtGnameSub a0, struct GFtgtGnameSub a1, u16 a2, u16 a3, u8 a4, u16 a5, u8 a6);
int CanSpinTradeMon(struct Pokemon*, u16);
void InitTradeSequenceBgGpuRegs(void);
void LinkTradeDrawWindow(void);

View File

@ -7,7 +7,7 @@
struct UnkStruct_Shared
{
struct UnkLinkRfuStruct_02022B14 field_0;
struct GFtgtGname field_0;
u8 ALIGNED(4) playerName[PLAYER_NAME_LENGTH + 1];
};
@ -154,7 +154,7 @@ struct UnionRoomTrade
extern u8 gUnknown_02022C2C;
extern union UnkUnion_Main gUnknown_02022C30;
extern struct UnkLinkRfuStruct_02022B14Substruct gUnknown_02022C38;
extern struct GFtgtGnameSub gUnknown_02022C38;
extern u16 gUnionRoomOfferedSpecies;
extern u8 gUnionRoomRequestedMonType;

View File

@ -59,7 +59,9 @@ SECTIONS {
gflib/sprite.o(.text);
gflib/string_util.o(.text);
src/link.o(.text);
src/link_rfu.o(.text);
src/AgbRfu_LinkManager.o(.text);
src/link_rfu_3.o(.text);
src/link_rfu_2.o(.text);
src/union_room.o(.text);
src/mystery_gift.o(.text);
src/union_room_player_avatar.o(.text);
@ -356,7 +358,6 @@ SECTIONS {
src/siirtc.o(.text);
src/librfu_stwi.o(.text);
src/librfu_intr.o(.text);
asm/librfu_intr.o(.text);
src/librfu_rfu.o(.text);
src/librfu_sio32id.o(.text);
src/libisagbprn.o(.text);
@ -441,8 +442,10 @@ SECTIONS {
gflib/string_util.o(.rodata);
src/link.o(.rodata);
src/link.o(.rodata.str1.4);
src/link_rfu.o(.rodata);
src/link_rfu.o(.rodata.str1.4);
src/AgbRfu_LinkManager.o(.rodata);
src/link_rfu_3.o(.rodata);
src/link_rfu_2.o(.rodata);
src/link_rfu_2.o(.rodata.str1.4);
src/union_room.o(.rodata);
src/mystery_gift.o(.rodata);
src/union_room_player_avatar.o(.rodata);

1398
src/AgbRfu_LinkManager.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -280,9 +280,9 @@ void sub_8020C70(MainCallback callback)
if (!gReceivedRemoteLinkPlayers || gWirelessCommType == 0)
{
SetMainCallback2(callback);
gUnknown_03005000.unk_10 = 0;
gUnknown_03005000.unk_12 = 0;
gUnknown_03005000.unk_ee = 1;
Rfu.unk_10 = 0;
Rfu.unk_12 = 0;
Rfu.unk_ee = 1;
return;
}
@ -291,9 +291,9 @@ void sub_8020C70(MainCallback callback)
if (playerCount < 2 || multiplayerId >= playerCount)
{
SetMainCallback2(callback);
gUnknown_03005000.unk_10 = 0;
gUnknown_03005000.unk_12 = 0;
gUnknown_03005000.unk_ee = 1;
Rfu.unk_10 = 0;
Rfu.unk_12 = 0;
Rfu.unk_ee = 1;
return;
}
@ -301,9 +301,9 @@ void sub_8020C70(MainCallback callback)
if (!gUnknown_02022C90)
{
SetMainCallback2(callback);
gUnknown_03005000.unk_10 = 0;
gUnknown_03005000.unk_12 = 0;
gUnknown_03005000.unk_ee = 1;
Rfu.unk_10 = 0;
Rfu.unk_12 = 0;
Rfu.unk_ee = 1;
return;
}

View File

@ -1,5 +1,402 @@
#include "global.h"
#include "main.h"
#include "librfu.h"
//TODO: decompile asm/librfu_intr.s to here
static void sio32intr_clock_master(void);
static void sio32intr_clock_slave(void);
static u16 handshake_wait(u16 slot);
static void STWI_set_timer_in_RAM(u8 count);
static void STWI_stop_timer_in_RAM(void);
static void STWI_init_slave(void);
static void Callback_Dummy_M(int reqCommandId, int error, void (*callbackM)());
static void Callback_Dummy_S(u16 reqCommandId, void (*callbackS)(u16));
static void Callback_Dummy_ID(void (*callbackId)(void));
void IntrSIO32(void)
{
if (gSTWIStatus->state == 10)
{
if (gSTWIStatus->callbackID != NULL)
Callback_Dummy_ID(gSTWIStatus->callbackID);
}
else
{
if (gSTWIStatus->msMode == AGB_CLK_MASTER)
sio32intr_clock_master();
else
sio32intr_clock_slave();
}
}
static void sio32intr_clock_master(void)
{
u32 regSIODATA32;
u32 ackLen;
STWI_set_timer_in_RAM(80);
regSIODATA32 = REG_SIODATA32;
if (gSTWIStatus->state == 0) // master send req
{
if (regSIODATA32 == 0x80000000)
{
if (gSTWIStatus->reqNext <= gSTWIStatus->reqLength)
{
REG_SIODATA32 = ((u32*)gSTWIStatus->txPacket->rfuPacket8.data)[gSTWIStatus->reqNext];
gSTWIStatus->reqNext++;
}
else
{
gSTWIStatus->state = 1; // master wait ack
REG_SIODATA32 = 0x80000000;
}
}
else
{
STWI_stop_timer_in_RAM();
STWI_set_timer_in_RAM(130);
return;
}
}
else if (gSTWIStatus->state == 1) // master wait ack
{
if ((regSIODATA32 & 0xFFFF0000) == 0x99660000)
{
gSTWIStatus->ackNext = 0;
((u32*)gSTWIStatus->rxPacket)[gSTWIStatus->ackNext] = regSIODATA32;
gSTWIStatus->ackNext++;
gSTWIStatus->ackActiveCommand = regSIODATA32;
gSTWIStatus->ackLength = ackLen = regSIODATA32 >> 8;
if ((ackLen = gSTWIStatus->ackLength) >= gSTWIStatus->ackNext)
{
gSTWIStatus->state = 2; // master receive ack
REG_SIODATA32 = 0x80000000;
}
else
{
gSTWIStatus->state = 3; // master done ack
}
}
else
{
STWI_stop_timer_in_RAM();
STWI_set_timer_in_RAM(130);
return;
}
}
else if (gSTWIStatus->state == 2) // master receive ack
{
((u32*)gSTWIStatus->rxPacket)[gSTWIStatus->ackNext] = regSIODATA32;
gSTWIStatus->ackNext++;
if (gSTWIStatus->ackLength < gSTWIStatus->ackNext)
gSTWIStatus->state = 3; // master done ack
else
REG_SIODATA32 = 0x80000000;
}
if (handshake_wait(1) == 1)
return;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS | SIO_MULTI_SD;
if (handshake_wait(0) == 1)
return;
STWI_stop_timer_in_RAM();
if (gSTWIStatus->state == 3) // master done ack
{
if (
gSTWIStatus->ackActiveCommand == (0x80 | ID_MS_CHANGE_REQ)
|| gSTWIStatus->ackActiveCommand == (0x80 | ID_DATA_TX_AND_CHANGE_REQ)
|| gSTWIStatus->ackActiveCommand == (0x80 | ID_UNK35_REQ)
|| gSTWIStatus->ackActiveCommand == (0x80 | ID_RESUME_RETRANSMIT_AND_CHANGE_REQ)
)
{
gSTWIStatus->msMode = AGB_CLK_SLAVE;
REG_SIODATA32 = 0x80000000;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS | SIO_ENABLE;
gSTWIStatus->state = 5; // slave receive req init
}
else
{
if (gSTWIStatus->ackActiveCommand == 0xEE)
{
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
gSTWIStatus->state = 4; // error
gSTWIStatus->error = ERR_REQ_CMD_ACK_REJECTION;
}
else
{
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
gSTWIStatus->state = 4; // error
}
}
gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL)
Callback_Dummy_M(gSTWIStatus->reqActiveCommand, gSTWIStatus->error, gSTWIStatus->callbackM);
}
else
{
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS | SIO_ENABLE;
}
}
static void sio32intr_clock_slave(void)
{
u32 regSIODATA32;
u32 r0;
register u32 reqLen asm("r2");
gSTWIStatus->timerActive = 0;
STWI_set_timer_in_RAM(100);
if (handshake_wait(0) == 1)
return;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS | SIO_MULTI_SD;
regSIODATA32 = REG_SIODATA32;
if (gSTWIStatus->state == 5) // slave receive req init
{
((u32*)gSTWIStatus->rxPacket)[0] = regSIODATA32;
gSTWIStatus->reqNext = 1;
r0 = 0x99660000;
if ((regSIODATA32 >> 16) == (r0 >> 16))
{
gSTWIStatus->reqLength = reqLen = regSIODATA32 >> 8;
gSTWIStatus->reqActiveCommand = regSIODATA32;
if (gSTWIStatus->reqLength == 0)
{
if (
gSTWIStatus->reqActiveCommand == ID_MS_CHANGE_REQ
|| gSTWIStatus->reqActiveCommand == ID_DATA_READY_AND_CHANGE_REQ
|| gSTWIStatus->reqActiveCommand == ID_DISCONNECTED_AND_CHANGE_REQ
|| gSTWIStatus->reqActiveCommand == ID_UNK36_REQ
)
{
gSTWIStatus->ackActiveCommand = gSTWIStatus->reqActiveCommand + 0x80;
((u32*)gSTWIStatus->txPacket)[0] = 0x99660000 + gSTWIStatus->ackActiveCommand;
gSTWIStatus->ackLength = 0;
}
else
{
((u32*)gSTWIStatus->txPacket)[0] = 0x996601EE;
if (gSTWIStatus->reqActiveCommand >= 0x10 && gSTWIStatus->reqActiveCommand <= 0x3D)
{
((u32*)gSTWIStatus->txPacket)[1] = 1;
}
else
{
((u32*)gSTWIStatus->txPacket)[1] = 2;
}
gSTWIStatus->ackLength = 1;
gSTWIStatus->error = ERR_REQ_CMD_ACK_REJECTION;
}
REG_SIODATA32 = ((u32*)gSTWIStatus->txPacket)[0];
gSTWIStatus->ackNext = 1;
gSTWIStatus->state = 7; // slave send ack
}
else
{
REG_SIODATA32 = 0x80000000;
gSTWIStatus->reqNext = 1;
gSTWIStatus->state = 6; // slave receive req
}
}
else
{
STWI_stop_timer_in_RAM();
STWI_set_timer_in_RAM(100);
return;
}
}
else if (gSTWIStatus->state == 6) // slave receive req
{
((u32*)gSTWIStatus->rxPacket)[gSTWIStatus->reqNext] = regSIODATA32;
gSTWIStatus->reqNext++;
if (gSTWIStatus->reqLength < gSTWIStatus->reqNext)
{
if (
gSTWIStatus->reqActiveCommand == ID_DATA_READY_AND_CHANGE_REQ
|| gSTWIStatus->reqActiveCommand == ID_DISCONNECTED_AND_CHANGE_REQ
|| gSTWIStatus->reqActiveCommand == ID_UNK36_REQ
)
{
gSTWIStatus->ackActiveCommand = gSTWIStatus->reqActiveCommand + 0x80;
((u32*)gSTWIStatus->txPacket)[0] = 0x99660000 | gSTWIStatus->ackActiveCommand;
gSTWIStatus->ackLength = 0;
}
else
{
((u32*)gSTWIStatus->txPacket)[0] = 0x996601EE;
if (gSTWIStatus->reqActiveCommand >= 0x10 && gSTWIStatus->reqActiveCommand <= 0x3D)
{
((u32*)gSTWIStatus->txPacket)[1] = 1;
}
else
{
((u32*)gSTWIStatus->txPacket)[1] = 2;
}
gSTWIStatus->ackLength = 1;
gSTWIStatus->error = ERR_REQ_CMD_ACK_REJECTION;
}
REG_SIODATA32 = ((u32*)gSTWIStatus->txPacket)[0];
gSTWIStatus->ackNext = 1;
gSTWIStatus->state = 7; // slave send ack
}
else
{
REG_SIODATA32 = 0x80000000;
}
}
else if (gSTWIStatus->state == 7) // slave send ack
{
if (regSIODATA32 == 0x80000000)
{
if (gSTWIStatus->ackLength < gSTWIStatus->ackNext)
{
gSTWIStatus->state = 8; // slave done ack
}
else
{
REG_SIODATA32 = ((u32*)gSTWIStatus->txPacket)[gSTWIStatus->ackNext];
gSTWIStatus->ackNext++;
}
}
else
{
STWI_stop_timer_in_RAM();
STWI_set_timer_in_RAM(100);
return;
}
}
if (handshake_wait(1) == 1)
return;
if (gSTWIStatus->state == 8) // slave done ack
{
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS;
STWI_stop_timer_in_RAM();
if (gSTWIStatus->error == ERR_REQ_CMD_ACK_REJECTION)
{
STWI_init_slave();
if (gSTWIStatus->callbackS != NULL)
{
Callback_Dummy_S(0x1EE, gSTWIStatus->callbackS);
}
}
else
{
REG_SIODATA32 = 0;
REG_SIOCNT = 0;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
gSTWIStatus->msMode = AGB_CLK_MASTER;
gSTWIStatus->state = 0; // master send req
if (gSTWIStatus->callbackS != NULL)
{
Callback_Dummy_S((gSTWIStatus->reqLength << 8) | (gSTWIStatus->reqActiveCommand), gSTWIStatus->callbackS);
}
}
}
else
{
REG_IME = 0;
if (REG_TM0CNT_H & TIMER_ENABLE)
{
if ((REG_TM0CNT_H & 0x03) == TIMER_1CLK)
{
while (REG_TM0CNT_L > 0xFF9B);
}
else
{
while (REG_TM0CNT_L > 0xFFFE);
}
}
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS | SIO_ENABLE;
REG_IME = 1;
}
}
static u16 handshake_wait(u16 slot)
{
do
{
if ((gSTWIStatus->timerActive & 0xFF) == 1)
{
gSTWIStatus->timerActive = 0;
return 1;
}
} while ((REG_SIOCNT & SIO_MULTI_SI) != (slot << SIO_MULTI_SI_SHIFT));
return 0;
}
static void STWI_set_timer_in_RAM(u8 count)
{
vu16* regTMCNTL = (vu16*)(REG_ADDR_TMCNT_L + gSTWIStatus->timerSelect * 4);
vu16* regTMCNTH = (vu16*)(REG_ADDR_TMCNT_H + gSTWIStatus->timerSelect * 4);
REG_IME = 0;
switch (count)
{
case 50:
*regTMCNTL = 0xFCCB;
gSTWIStatus->timerState = 1;
break;
case 80:
*regTMCNTL = 0xFAE0;
gSTWIStatus->timerState = 2;
break;
case 100:
*regTMCNTL = 0xF996;
gSTWIStatus->timerState = 3;
break;
case 130:
*regTMCNTL = 0xF7AD;
gSTWIStatus->timerState = 4;
break;
}
*regTMCNTH = TIMER_ENABLE | TIMER_64CLK | TIMER_256CLK | TIMER_INTR_ENABLE;
REG_IF = INTR_FLAG_TIMER0 << gSTWIStatus->timerSelect;
REG_IME = 1;
}
static void STWI_stop_timer_in_RAM(void)
{
gSTWIStatus->timerState = 0;
REG_TMCNT_L(gSTWIStatus->timerSelect) = 0;
REG_TMCNT_H(gSTWIStatus->timerSelect) = 0;
}
static void STWI_init_slave(void)
{
gSTWIStatus->state = 5; // slave receive req init
gSTWIStatus->msMode = AGB_CLK_SLAVE;
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
gSTWIStatus->reqActiveCommand = 0;
gSTWIStatus->ackLength = 0;
gSTWIStatus->ackNext = 0;
gSTWIStatus->ackActiveCommand = 0;
gSTWIStatus->timerState = 0;
gSTWIStatus->timerActive = 0;
gSTWIStatus->error = 0;
gSTWIStatus->recoveryCount = 0;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_57600_BPS | SIO_ENABLE;
}
NAKED
static void Callback_Dummy_M(int reqCommandId, int error, void (*callbackM)())
{
asm("bx r2");
}
NAKED
static void Callback_Dummy_S(u16 reqCommandId, void (*callbackS)(u16))
{
asm("bx r1");
}
NAKED
static void Callback_Dummy_ID(void (*callbackId)(void))
{
asm("bx r0");
}

File diff suppressed because it is too large Load Diff

View File

@ -4,44 +4,56 @@ static void Sio32IDIntr(void);
static void Sio32IDInit(void);
static s32 Sio32IDMain(void);
struct RfuSIO32Id
{
u8 MS_mode;
u8 state;
u16 count;
u16 send_id;
u16 recv_id;
u16 unk8; // unused
u16 lastId;
};
struct RfuSIO32Id gRfuSIO32Id;
static const u16 Sio32ConnectionData[] = { 0x494e, 0x544e, 0x4e45, 0x4f44 }; // NINTENDO
static const char Sio32IDLib_Var[] = "Sio32ID_030820";
s32 AgbRFU_checkID(u8 r5)
s32 AgbRFU_checkID(u8 maxTries)
{
u16 r8;
vu16 *r4;
s32 r6;
u16 ieBak;
vu16 *regTMCNTL;
s32 id;
// Interrupts must be enabled
if (REG_IME == 0)
return -1;
r8 = REG_IE;
ieBak = REG_IE;
gSTWIStatus->state = 10;
STWI_set_Callback_ID(Sio32IDIntr);
Sio32IDInit();
r4 = &REG_TMCNT_L(gSTWIStatus->timerSelect);
r5 *= 8;
while (--r5 != 0xFF)
regTMCNTL = &REG_TMCNT_L(gSTWIStatus->timerSelect);
maxTries *= 8;
while (--maxTries != 0xFF)
{
r6 = Sio32IDMain();
if (r6 != 0)
id = Sio32IDMain();
if (id != 0)
break;
r4[1] = 0;
r4[0] = 0;
r4[1] = TIMER_1024CLK | TIMER_ENABLE;
while (r4[0] < 32)
regTMCNTL[1] = 0;
regTMCNTL[0] = 0;
regTMCNTL[1] = TIMER_1024CLK | TIMER_ENABLE;
while (regTMCNTL[0] < 32)
;
r4[1] = 0;
r4[0] = 0;
regTMCNTL[1] = 0;
regTMCNTL[0] = 0;
}
REG_IME = 0;
REG_IE = r8;
REG_IE = ieBak;
REG_IME = 1;
gSTWIStatus->state = 0;
STWI_set_Callback_ID(NULL);
return r6;
return id;
}
static void Sio32IDInit(void)
@ -58,107 +70,105 @@ static void Sio32IDInit(void)
static s32 Sio32IDMain(void)
{
u8 r12;
switch (r12 = gRfuSIO32Id.unk1)
switch (gRfuSIO32Id.state)
{
case 0:
gRfuSIO32Id.unk0 = 1;
gRfuSIO32Id.MS_mode = AGB_CLK_MASTER;
REG_SIOCNT |= SIO_38400_BPS;
REG_IME = r12;
REG_IME = 0;
REG_IE |= INTR_FLAG_SERIAL;
REG_IME = 1;
gRfuSIO32Id.unk1 = 1;
gRfuSIO32Id.state = 1;
*(vu8 *)&REG_SIOCNT |= SIO_ENABLE;
break;
case 1:
if (gRfuSIO32Id.unkA == 0)
if (gRfuSIO32Id.lastId == 0)
{
if (gRfuSIO32Id.unk0 == 1)
if (gRfuSIO32Id.MS_mode == AGB_CLK_MASTER)
{
if (gRfuSIO32Id.unk2 == 0)
if (gRfuSIO32Id.count == 0)
{
REG_IME = gRfuSIO32Id.unk2;
REG_IME = 0;
REG_SIOCNT |= SIO_ENABLE;
REG_IME = r12;
REG_IME = 1;
}
}
else if (gRfuSIO32Id.unk4 != 0x8001 && !gRfuSIO32Id.unk2)
else if (gRfuSIO32Id.send_id != RFU_ID && !gRfuSIO32Id.count)
{
REG_IME = gRfuSIO32Id.unk2;
REG_IME = 0;
REG_IE &= ~INTR_FLAG_SERIAL;
REG_IME = r12;
REG_SIOCNT = gRfuSIO32Id.unk2;
REG_IME = 1;
REG_SIOCNT = 0;
REG_SIOCNT = SIO_32BIT_MODE;
REG_IF = INTR_FLAG_SERIAL;
REG_SIOCNT |= SIO_INTR_ENABLE | SIO_ENABLE;
REG_IME = gRfuSIO32Id.unk2;
REG_IME = 0;
REG_IE |= INTR_FLAG_SERIAL;
REG_IME = r12;
REG_IME = 1;
}
break;
}
else
{
gRfuSIO32Id.unk1 = 2;
gRfuSIO32Id.state = 2;
// fallthrough
}
default:
return gRfuSIO32Id.unkA;
return gRfuSIO32Id.lastId;
}
return 0;
}
static void Sio32IDIntr(void)
{
u32 r5;
u16 r0;
u32 regSIODATA32;
u16 delay;
#ifndef NONMATCHING
register u32 r1 asm("r1");
register u16 r0_ asm("r0");
register u32 rfuSIO32IdUnk0_times_16 asm("r1");
register u16 negRfuSIO32IdUnk6 asm("r0");
#else
u32 r1;
u16 r0_;
u32 rfuSIO32IdUnk0_times_16;
u16 negRfuSIO32IdUnk6;
#endif
r5 = REG_SIODATA32;
if (gRfuSIO32Id.unk0 != 1)
regSIODATA32 = REG_SIODATA32;
if (gRfuSIO32Id.MS_mode != AGB_CLK_MASTER)
REG_SIOCNT |= SIO_ENABLE;
r1 = 16 * gRfuSIO32Id.unk0; // to handle side effect of inline asm
r1 = (r5 << r1) >> 16;
r5 = (r5 << 16 * (1 - gRfuSIO32Id.unk0)) >> 16;
if (gRfuSIO32Id.unkA == 0)
rfuSIO32IdUnk0_times_16 = 16 * gRfuSIO32Id.MS_mode; // to handle side effect of inline asm
rfuSIO32IdUnk0_times_16 = (regSIODATA32 << rfuSIO32IdUnk0_times_16) >> 16;
regSIODATA32 = (regSIODATA32 << 16 * (1 - gRfuSIO32Id.MS_mode)) >> 16;
if (gRfuSIO32Id.lastId == 0)
{
if (r1 == gRfuSIO32Id.unk6)
if (rfuSIO32IdUnk0_times_16 == gRfuSIO32Id.recv_id)
{
if (gRfuSIO32Id.unk2 > 3)
if (gRfuSIO32Id.count > 3)
{
gRfuSIO32Id.unkA = r5;
gRfuSIO32Id.lastId = regSIODATA32;
}
else if (r1 == (u16)~gRfuSIO32Id.unk4)
else if (rfuSIO32IdUnk0_times_16 == (u16)~gRfuSIO32Id.send_id)
{
r0_ = ~gRfuSIO32Id.unk6;
if (r5 == r0_)
++gRfuSIO32Id.unk2;
negRfuSIO32IdUnk6 = ~gRfuSIO32Id.recv_id;
if (regSIODATA32 == negRfuSIO32IdUnk6)
++gRfuSIO32Id.count;
}
}
else
{
gRfuSIO32Id.unk2 = gRfuSIO32Id.unkA;
gRfuSIO32Id.count = 0;
}
}
if (gRfuSIO32Id.unk2 < 4)
gRfuSIO32Id.unk4 = *(gRfuSIO32Id.unk2 + Sio32ConnectionData);
if (gRfuSIO32Id.count < 4)
gRfuSIO32Id.send_id = *(gRfuSIO32Id.count + Sio32ConnectionData);
else
gRfuSIO32Id.unk4 = 0x8001;
gRfuSIO32Id.unk6 = ~r5;
REG_SIODATA32 = (gRfuSIO32Id.unk4 << 16 * (1 - gRfuSIO32Id.unk0))
+ (gRfuSIO32Id.unk6 << 16 * gRfuSIO32Id.unk0);
if (gRfuSIO32Id.unk0 == 1 && (gRfuSIO32Id.unk2 || r5 == 0x494E))
gRfuSIO32Id.send_id = RFU_ID;
gRfuSIO32Id.recv_id = ~regSIODATA32;
REG_SIODATA32 = (gRfuSIO32Id.send_id << 16 * (1 - gRfuSIO32Id.MS_mode))
+ (gRfuSIO32Id.recv_id << 16 * gRfuSIO32Id.MS_mode);
if (gRfuSIO32Id.MS_mode == AGB_CLK_MASTER && (gRfuSIO32Id.count != 0 || regSIODATA32 == 0x494e))
{
for (r0 = 0; r0 < 600; ++r0)
for (delay = 0; delay < 600; ++delay)
;
if (gRfuSIO32Id.unkA == 0)
if (gRfuSIO32Id.lastId == 0)
REG_SIOCNT |= SIO_ENABLE;
}
}

View File

@ -28,8 +28,8 @@ void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, b
}
gSTWIStatus->rxPacket = &interruptStruct->rxPacketAlloc;
gSTWIStatus->txPacket = &interruptStruct->txPacketAlloc;
gSTWIStatus->msMode = 1;
gSTWIStatus->state = 0;
gSTWIStatus->msMode = AGB_CLK_MASTER;
gSTWIStatus->state = 0; // master send req
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
gSTWIStatus->ackLength = 0;
@ -39,7 +39,7 @@ void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, b
gSTWIStatus->timerActive = 0;
gSTWIStatus->error = 0;
gSTWIStatus->recoveryCount = 0;
gSTWIStatus->unk_2c = 0;
gSTWIStatus->sending = 0;
REG_RCNT = 0x100; // TODO: mystery bit?
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
STWI_init_Callback_M();
@ -71,7 +71,7 @@ void AgbRFU_SoftReset(void)
*timerH = 3;
REG_RCNT = 0x80A0;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
gSTWIStatus->state = 0;
gSTWIStatus->state = 0; // master send req
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
gSTWIStatus->reqActiveCommand = 0;
@ -81,9 +81,9 @@ void AgbRFU_SoftReset(void)
gSTWIStatus->timerState = 0;
gSTWIStatus->timerActive = 0;
gSTWIStatus->error = 0;
gSTWIStatus->msMode = 1;
gSTWIStatus->msMode = AGB_CLK_MASTER;
gSTWIStatus->recoveryCount = 0;
gSTWIStatus->unk_2c = 0;
gSTWIStatus->sending = 0;
}
void STWI_set_MS_mode(u8 mode)
@ -131,12 +131,12 @@ void STWI_set_Callback_S(void (*callbackS)(u16))
void STWI_set_Callback_ID(void (*func)(void)) // name in SDK, but is actually setting a function pointer
{
gSTWIStatus->unk_20 = func;
gSTWIStatus->callbackID = func;
}
u16 STWI_poll_CommandEnd(void)
{
while (gSTWIStatus->unk_2c == TRUE)
while (gSTWIStatus->sending == 1)
;
return gSTWIStatus->error;
}
@ -195,7 +195,7 @@ void STWI_send_ConfigStatusREQ(void)
}
}
void STWI_send_GameConfigREQ(const u8 *unk1, const u8 *data)
void STWI_send_GameConfigREQ(const u8 *serial_gname, const u8 *uname)
{
u8 *packetBytes;
s32 i;
@ -203,29 +203,28 @@ void STWI_send_GameConfigREQ(const u8 *unk1, const u8 *data)
if (!STWI_init(ID_GAME_CONFIG_REQ))
{
gSTWIStatus->reqLength = 6;
// TODO: what is unk1
packetBytes = gSTWIStatus->txPacket->rfuPacket8.data;
packetBytes += sizeof(u32);
*(u16 *)packetBytes = *(u16 *)unk1;
*(u16 *)packetBytes = *(u16 *)serial_gname;
packetBytes += sizeof(u16);
unk1 += sizeof(u16);
serial_gname += sizeof(u16);
for (i = 0; i < 14; ++i)
{
*packetBytes = *unk1;
*packetBytes = *serial_gname;
++packetBytes;
++unk1;
++serial_gname;
}
for (i = 0; i < 8; ++i)
{
*packetBytes = *data;
*packetBytes = *uname;
++packetBytes;
++data;
++uname;
}
STWI_start_Command();
}
}
void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3)
void STWI_send_SystemConfigREQ(u16 availSlotFlag, u8 maxMFrame, u8 mcTimer)
{
if (!STWI_init(ID_SYSTEM_CONFIG_REQ))
{
@ -234,9 +233,9 @@ void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3)
gSTWIStatus->reqLength = 1;
packetBytes = gSTWIStatus->txPacket->rfuPacket8.data;
packetBytes += sizeof(u32);
*packetBytes++ = unk3;
*packetBytes++ = unk2;
*(u16*)packetBytes = unk1;
*packetBytes++ = mcTimer;
*packetBytes++ = maxMFrame;
*(u16*)packetBytes = availSlotFlag;
STWI_start_Command();
}
}
@ -499,20 +498,17 @@ static void STWI_intr_timer(void)
STWI_stop_timer();
STWI_reset_ClockCounter();
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(255, 0);
gSTWIStatus->callbackM(ID_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA_REQ, 0);
break;
}
}
static void STWI_set_timer(u8 unk)
static void STWI_set_timer(u8 count)
{
vu16 *timerL;
vu16 *timerH;
timerL = &REG_TMCNT_L(gSTWIStatus->timerSelect);
timerH = &REG_TMCNT_H(gSTWIStatus->timerSelect);
vu16 *timerL = &REG_TMCNT_L(gSTWIStatus->timerSelect);
vu16 *timerH = &REG_TMCNT_H(gSTWIStatus->timerSelect);
REG_IME = 0;
switch (unk)
switch (count)
{
case 50:
*timerL = 0xFCCB;
@ -543,25 +539,31 @@ static void STWI_stop_timer(void)
REG_TMCNT_H(gSTWIStatus->timerSelect) = 0;
}
/*
* Set up STWI to send REQ. Returns 1 if error (see below).
*/
static u16 STWI_init(u8 request)
{
if (!REG_IME)
{
// Can't start sending if IME is disabled.
gSTWIStatus->error = ERR_REQ_CMD_IME_DISABLE;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(request, gSTWIStatus->error);
return TRUE;
}
else if (gSTWIStatus->unk_2c == TRUE)
else if (gSTWIStatus->sending == 1)
{
// Already sending something. Cancel and error.
gSTWIStatus->error = ERR_REQ_CMD_SENDING;
gSTWIStatus->unk_2c = FALSE;
gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(request, gSTWIStatus->error);
return TRUE;
}
else if(!gSTWIStatus->msMode)
else if (gSTWIStatus->msMode == AGB_CLK_SLAVE)
{
// Can't send if clock slave
gSTWIStatus->error = ERR_REQ_CMD_CLOCK_SLAVE;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(request, gSTWIStatus->error, gSTWIStatus);
@ -569,9 +571,10 @@ static u16 STWI_init(u8 request)
}
else
{
gSTWIStatus->unk_2c = TRUE;
// Good to go, start sending
gSTWIStatus->sending = 1;
gSTWIStatus->reqActiveCommand = request;
gSTWIStatus->state = 0;
gSTWIStatus->state = 0; // master send req
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
gSTWIStatus->ackLength = 0;
@ -595,7 +598,7 @@ static s32 STWI_start_Command(void)
// but the cast here is required to avoid register issue
*(u32 *)gSTWIStatus->txPacket->rfuPacket8.data = 0x99660000 | (gSTWIStatus->reqLength << 8) | gSTWIStatus->reqActiveCommand;
REG_SIODATA32 = gSTWIStatus->txPacket->rfuPacket32.command;
gSTWIStatus->state = 0;
gSTWIStatus->state = 0; // master send req
gSTWIStatus->reqNext = 1;
imeTemp = REG_IME;
REG_IME = 0;
@ -608,7 +611,7 @@ static s32 STWI_start_Command(void)
static s32 STWI_restart_Command(void)
{
if (gSTWIStatus->recoveryCount <= 1)
if (gSTWIStatus->recoveryCount < 2)
{
++gSTWIStatus->recoveryCount;
STWI_start_Command();
@ -618,17 +621,17 @@ static s32 STWI_restart_Command(void)
if (gSTWIStatus->reqActiveCommand == ID_MS_CHANGE_REQ || gSTWIStatus->reqActiveCommand == ID_DATA_TX_AND_CHANGE_REQ || gSTWIStatus->reqActiveCommand == ID_UNK35_REQ || gSTWIStatus->reqActiveCommand == ID_RESUME_RETRANSMIT_AND_CHANGE_REQ)
{
gSTWIStatus->error = ERR_REQ_CMD_CLOCK_DRIFT;
gSTWIStatus->unk_2c = 0;
gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(gSTWIStatus->reqActiveCommand, gSTWIStatus->error);
}
else
{
gSTWIStatus->error = ERR_REQ_CMD_CLOCK_DRIFT;
gSTWIStatus->unk_2c = 0;
gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(gSTWIStatus->reqActiveCommand, gSTWIStatus->error);
gSTWIStatus->state = 4; // TODO: what's 4
gSTWIStatus->state = 4; // error
}
}
return 0;
@ -636,7 +639,7 @@ static s32 STWI_restart_Command(void)
static s32 STWI_reset_ClockCounter(void)
{
gSTWIStatus->state = 5; // TODO: what is 5
gSTWIStatus->state = 5; // slave receive req init
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
REG_SIODATA32 = (1 << 31);

View File

@ -223,7 +223,7 @@ bool8 IsWirelessAdapterConnected(void)
{
sub_800B488();
sub_800E700();
if (sub_800BEC0() == 0x8001)
if (rfu_LMAN_REQBN_softReset_and_checkID() == 0x8001)
{
rfu_REQ_stopMode();
rfu_waitREQComplete();

File diff suppressed because it is too large Load Diff

2813
src/link_rfu_2.c Normal file

File diff suppressed because it is too large Load Diff

938
src/link_rfu_3.c Normal file
View File

@ -0,0 +1,938 @@
#include "global.h"
#include "malloc.h"
#include "decompress.h"
#include "link_rfu.h"
#include "string_util.h"
#include "random.h"
#include "text.h"
#include "event_data.h"
EWRAM_DATA u8 gWirelessStatusIndicatorSpriteId = 0;
static u8 gUnknown_03000D74;
const u16 gWirelessLinkIconPalette[] = INCBIN_U16("graphics/interface/wireless_link_icon.gbapal");
const u32 gWirelessLinkIconPic[] = INCBIN_U32("graphics/interface/wireless_link_icon.4bpp.lz");
const u8 sWireless_ASCIItoRSETable[] = {
0xff, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
0x00, 0xab, 0xb5, 0xb6, 0xb1, 0x00, 0x00, 0x00,
0x00, 0x00, 0xb2, 0xf1, 0x00, 0xae, 0xad, 0xba,
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8,
0xa9, 0xaa, 0x00, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0x00, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1,
0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1,
0xd2, 0xd3, 0xd4, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6,
0x00, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb,
0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,
0xec, 0xed, 0xee, 0x2d, 0x2f, 0x30, 0x31, 0x32,
0x33, 0x34, 0x35, 0x36, 0x50, 0x00, 0x01, 0x02,
0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a,
0x1b, 0xad, 0xb3, 0xb4, 0x00, 0xaf, 0x7d, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0xa0,
0xae, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7e, 0xb0, 0xac,
0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
0x2c, 0x2e, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c,
0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94
};
const u8 sWireless_RSEtoASCIITable[] = {
0x20, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c,
0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94,
0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c,
0x9d, 0x9e, 0x9f, 0xa0, 0xe0, 0xe1, 0xe2, 0xe3,
0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,
0xec, 0xed, 0xee, 0xef, 0xf0, 0x7b, 0xf1, 0x7c,
0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x84, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xa6, 0xdd, 0xa7,
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xf2,
0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,
0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x01, 0x02, 0x03,
0x04, 0x05, 0x06, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0xaf, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
0x37, 0x38, 0x39, 0x21, 0xdf, 0xa1, 0xb0, 0xa5,
0xde, 0x24, 0x2a, 0xa2, 0xa3, 0x22, 0x23, 0x20,
0xa4, 0x20, 0x2f, 0x41, 0x42, 0x43, 0x44, 0x45,
0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d,
0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63,
0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,
0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x20,
0x20, 0x2b, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00
};
const struct OamData sWirelessStatusIndicatorOamData =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(16x16),
.x = 0,
.size = SPRITE_SIZE(16x16),
.tileNum = 0,
.priority = 0,
.paletteNum = 0,
};
const union AnimCmd sWirelessStatusIndicatorAnim0[] = {
// 3 bars
ANIMCMD_FRAME( 4, 5),
ANIMCMD_FRAME( 8, 5),
ANIMCMD_FRAME(12, 5),
ANIMCMD_FRAME(16, 10),
ANIMCMD_FRAME(12, 5),
ANIMCMD_FRAME( 8, 5),
ANIMCMD_JUMP(0)
};
const union AnimCmd sWirelessStatusIndicatorAnim1[] = {
// 2 bars
ANIMCMD_FRAME( 4, 5),
ANIMCMD_FRAME( 8, 5),
ANIMCMD_FRAME(12, 10),
ANIMCMD_FRAME( 8, 5),
ANIMCMD_JUMP(0)
};
const union AnimCmd sWirelessStatusIndicatorAnim2[] = {
// 1 bar
ANIMCMD_FRAME(4, 5),
ANIMCMD_FRAME(8, 5),
ANIMCMD_JUMP(0)
};
const union AnimCmd sWirelessStatusIndicatorAnim3[] = {
// searching
ANIMCMD_FRAME( 4, 10),
ANIMCMD_FRAME(20, 10),
ANIMCMD_JUMP(0)
};
const union AnimCmd sWirelessStatusIndicatorAnim4[] = {
// error
ANIMCMD_FRAME(24, 10),
ANIMCMD_FRAME( 4, 10),
ANIMCMD_JUMP(0)
};
const union AnimCmd *const sWirelessStatusIndicatorAnims[] = {
sWirelessStatusIndicatorAnim0,
sWirelessStatusIndicatorAnim1,
sWirelessStatusIndicatorAnim2,
sWirelessStatusIndicatorAnim3,
sWirelessStatusIndicatorAnim4
};
const struct CompressedSpriteSheet sWirelessStatusIndicatorSpriteSheet = {
gWirelessLinkIconPic, 0x0380, 0xD431
};
const struct SpritePalette sWirelessStatusIndicatorSpritePalette = {
gWirelessLinkIconPalette, 0xD432
};
const struct SpriteTemplate sWirelessStatusIndicatorSpriteTemplate = {
0xD431,
0xD432,
&sWirelessStatusIndicatorOamData,
sWirelessStatusIndicatorAnims,
NULL,
gDummySpriteAffineAnimTable,
SpriteCallbackDummy
};
void sub_800D6C8(struct UnkRfuStruct_2_Sub_124 *ptr)
{
s32 i;
s32 j;
for (i = 0; i < 32; i++)
{
for (j = 0; j < 70; j++)
{
ptr->unk_00[i][j] = 0;
}
}
ptr->unk_8c1 = 0;
ptr->unk_8c0 = 0;
ptr->unk_8c2 = 0;
ptr->unk_8c3 = 0;
}
void sub_800D724(struct UnkRfuStruct_2_Sub_9e8 *ptr)
{
s32 i;
s32 j;
for (i = 0; i < 40; i++)
{
for (j = 0; j < 14; j++)
{
ptr->unk_00[i][j] = 0;
}
}
ptr->unk_231 = 0;
ptr->unk_230 = 0;
ptr->unk_232 = 0;
ptr->unk_233 = 0;
}
void sub_800D780(struct UnkRfuStruct_Sub_Unused *ptr)
{
s32 i;
s32 j;
for (i = 0; i < 2; i++)
{
for (j = 0; j < 256; j++)
{
ptr->unk_00[i][j] = 0;
}
}
ptr->unk_201 = 0;
ptr->unk_200 = 0;
ptr->unk_202 = 0;
ptr->unk_203 = 0;
}
void sub_800D7D8(struct UnkRfuStruct_2_Sub_124 *q1, u8 *q2)
{
s32 i;
u16 imeBak;
u8 count;
if (q1->unk_8c2 < 32)
{
imeBak = REG_IME;
REG_IME = 0;
count = 0;
for (i = 0; i < 70; i += 14)
{
if (q2[i] == 0 && q2[i + 1] == 0)
{
count++;
}
}
if (count != 5)
{
for (i = 0; i < 70; i++)
{
q1->unk_00[q1->unk_8c0][i] = q2[i];
}
q1->unk_8c0++;
q1->unk_8c0 %= 32;
q1->unk_8c2++;
for (i = 0; i < 70; i++)
{
q2[i] = 0;
}
}
REG_IME = imeBak;
}
else
{
q1->unk_8c3 = 1;
}
}
void sub_800D888(struct UnkRfuStruct_2_Sub_9e8 *q1, u8 *q2)
{
s32 i;
u16 imeBak;
if (q1->unk_232 < 40)
{
imeBak = REG_IME;
REG_IME = 0;
for (i = 0; i < 14; i++)
{
if (q2[i] != 0)
{
break;
}
}
if (i != 14)
{
for (i = 0; i < 14; i++)
{
q1->unk_00[q1->unk_230][i] = q2[i];
}
q1->unk_230++;
q1->unk_230 %= 40;
q1->unk_232++;
for (i = 0; i < 14; i++)
{
q2[i] = 0;
}
}
REG_IME = imeBak;
}
else
{
q1->unk_233 = 1;
}
}
bool8 sub_800D934(struct UnkRfuStruct_2_Sub_124 *q1, u8 *q2)
{
u16 imeBak;
s32 i;
imeBak = REG_IME;
REG_IME = 0;
if (q1->unk_8c0 == q1->unk_8c1 || q1->unk_8c3 != 0)
{
for (i = 0; i < 70; i++)
{
q2[i] = 0;
}
REG_IME = imeBak;
return FALSE;
}
for (i = 0; i < 70; i++)
{
q2[i] = q1->unk_00[q1->unk_8c1][i];
}
q1->unk_8c1++;
q1->unk_8c1 %= 32;
q1->unk_8c2--;
REG_IME = imeBak;
return TRUE;
}
bool8 sub_800D9DC(struct UnkRfuStruct_2_Sub_9e8 *q1, u8 *q2)
{
s32 i;
u16 imeBak;
if (q1->unk_230 == q1->unk_231 || q1->unk_233 != 0)
{
return FALSE;
}
imeBak = REG_IME;
REG_IME = 0;
for (i = 0; i < 14; i++)
{
q2[i] = q1->unk_00[q1->unk_231][i];
}
q1->unk_231++;
q1->unk_231 %= 40;
q1->unk_232--;
REG_IME = imeBak;
return TRUE;
}
void sub_800DA68(struct UnkRfuStruct_2_Sub_c1c *q1, const u8 *q2)
{
s32 i;
if (q2[1] == 0)
{
sub_800DAC8(q1, NULL);
}
else
{
for (i = 0; i < 14; i++)
{
q1->unk_00[q1->unk_1c][i] = q2[i];
}
q1->unk_1c++;
q1->unk_1c %= 2;
if (q1->unk_1e < 2)
{
q1->unk_1e++;
}
else
{
q1->unk_1d = q1->unk_1c;
}
}
}
bool8 sub_800DAC8(struct UnkRfuStruct_2_Sub_c1c *q1, u8 *q2)
{
s32 i;
if (q1->unk_1e == 0)
{
return FALSE;
}
if (q2 != NULL)
{
for (i = 0; i < 14; i++)
{
q2[i] = q1->unk_00[q1->unk_1d][i];
}
}
q1->unk_1d++;
q1->unk_1d %= 2;
q1->unk_1e--;
return TRUE;
}
void sub_800DB18(struct UnkRfuStruct_Sub_Unused *q1, u8 *q2)
{
s32 i;
if (q1->unk_202 < 2)
{
for (i = 0; i < 256; i++)
{
q1->unk_00[q1->unk_200][i] = q2[i];
}
q1->unk_200++;
q1->unk_200 %= 2;
q1->unk_202++;
}
else
{
q1->unk_203 = 1;
}
}
bool8 sub_800DB84(struct UnkRfuStruct_Sub_Unused *q1, u8 *q2)
{
s32 i;
if (q1->unk_200 == q1->unk_201 || q1->unk_203)
{
return FALSE;
}
for (i = 0; i < 256; i++)
{
q2[i] = q1->unk_00[q1->unk_201][i];
}
q1->unk_201++;
q1->unk_201 %= 2;
q1->unk_202--;
return TRUE;
}
void sub_800DBF8(u8 *q1, u8 mode)
{
s32 i;
u8 rval;
u16 r5 = 0;
switch (mode)
{
case 0:
for (i = 0; i < 200; i++)
{
q1[i] = i + 1;
r5 += i + 1;
}
*((u16 *)(q1 + i)) = r5;
break;
case 1:
for (i = 0; i < 100; i++)
{
q1[i] = i + 1;
r5 += i + 1;
}
*((u16 *)(q1 + 200)) = r5;
break;
case 2:
for (i = 0; i < 200; i++)
{
rval = Random();
q1[i] = rval;
r5 += rval;
}
*((u16 *)(q1 + i)) = r5;
break;
case 3:
for (i = 0; i < 200; i++)
{
q1[i] = i + 1 + gUnknown_03000D74;
r5 += (i + 1 + gUnknown_03000D74) & 0xFF;
}
*((u16 *)(q1 + i)) = r5;
gUnknown_03000D74++;
break;
}
}
// File boundary here maybe?
void PkmnStrToASCII(u8 *q1, const u8 *q2)
{
s32 i;
for (i = 0; q2[i] != EOS; i++)
{
q1[i] = sWireless_RSEtoASCIITable[q2[i]];
}
q1[i] = 0;
}
void ASCIIToPkmnStr(u8 *q1, const u8 *q2)
{
s32 i;
for (i = 0; q2[i] != 0; i++)
{
q1[i] = sWireless_ASCIItoRSETable[q2[i]];
}
q1[i] = EOS;
}
#ifdef NONMATCHING
u8 sub_800DD1C(u8 maxFlags)
{
u8 flagCount = 0;
u32 flags = gRfuLinkStatus->connSlotFlag;
u8 i;
if (gRfuLinkStatus->parentChild == 1)
{
for (i = 0; i < 4; flags >>= 1, i++)
{
if (flags & 1)
{
if (maxFlags == flagCount + 1)
return gRfuLinkStatus->strength[i];
flagCount++;
}
}
}
else
{
for (i = 0; i < 4; flags >>= 1, i++)
{
if (flags & 1)
return gRfuLinkStatus->strength[i];
}
}
return 0;
}
#else
NAKED u8 sub_800DD1C(u8 maxFlags)
{
asm_unified("\tpush {r4-r7,lr}\n"
"\tlsls r0, 24\n"
"\tlsrs r5, r0, 24\n"
"\tmovs r6, 0\n"
"\tldr r0, =gRfuLinkStatus\n"
"\tldr r4, [r0]\n"
"\tldrb r2, [r4, 0x2]\n"
"\tldrb r1, [r4]\n"
"\tadds r7, r0, 0\n"
"\tcmp r1, 0x1\n"
"\tbne _0800DD72\n"
"\tmovs r3, 0\n"
"\tands r1, r2\n"
"\tcmp r1, 0\n"
"\tbeq _0800DD4E\n"
"\tcmp r5, 0x1\n"
"\tbne _0800DD48\n"
"\tldrb r0, [r4, 0xA]\n"
"\tb _0800DD8C\n"
"\t.pool\n"
"_0800DD48:\n"
"\tadds r0, r6, 0x1\n"
"\tlsls r0, 24\n"
"\tlsrs r6, r0, 24\n"
"_0800DD4E:\n"
"\tlsrs r2, 1\n"
"\tadds r0, r3, 0x1\n"
"\tlsls r0, 24\n"
"\tlsrs r3, r0, 24\n"
"\tcmp r3, 0x3\n"
"\tbhi _0800DD8A\n"
"\tmovs r0, 0x1\n"
"\tands r0, r2\n"
"\tcmp r0, 0\n"
"\tbeq _0800DD4E\n"
"\tadds r0, r6, 0x1\n"
"\tcmp r5, r0\n"
"\tbne _0800DD48\n"
"_0800DD68:\n"
"\tldr r0, [r7]\n"
"\tadds r0, 0xA\n"
"\tadds r0, r3\n"
"\tldrb r0, [r0]\n"
"\tb _0800DD8C\n"
"_0800DD72:\n"
"\tmovs r3, 0\n"
"\tmovs r1, 0x1\n"
"_0800DD76:\n"
"\tadds r0, r2, 0\n"
"\tands r0, r1\n"
"\tcmp r0, 0\n"
"\tbne _0800DD68\n"
"\tlsrs r2, 1\n"
"\tadds r0, r3, 0x1\n"
"\tlsls r0, 24\n"
"\tlsrs r3, r0, 24\n"
"\tcmp r3, 0x3\n"
"\tbls _0800DD76\n"
"_0800DD8A:\n"
"\tmovs r0, 0\n"
"_0800DD8C:\n"
"\tpop {r4-r7}\n"
"\tpop {r1}\n"
"\tbx r1");
}
#endif
void sub_800DD94(struct GFtgtGname *data, u8 r9, bool32 r2, s32 r3)
{
s32 i;
for (i = 0; i < 2; i++)
{
data->unk_00.playerTrainerId[i] = gSaveBlock2Ptr->playerTrainerId[i];
}
for (i = 0; i < 4; i++)
{
data->child_sprite_gender[i] = r3;
r3 >>= 8;
}
data->playerGender = gSaveBlock2Ptr->playerGender;
data->activity = r9;
data->started = r2;
data->unk_00.language = GAME_LANGUAGE;
data->unk_00.version = GAME_VERSION;
data->unk_00.hasNews = 0;
data->unk_00.hasCard = 0;
data->unk_00.unk_00_6 = 0;
data->unk_00.isChampion = FlagGet(FLAG_IS_CHAMPION);
data->unk_00.hasNationalDex = IsNationalPokedexEnabled();
data->unk_00.gameClear = FlagGet(FLAG_SYS_GAME_CLEAR);
}
bool8 sub_800DE7C(struct GFtgtGname *buff1, u8 *buff2, u8 idx)
{
bool8 retVal;
if (lman.parent_child == 1)
{
retVal = TRUE;
if (sub_8010454(gRfuLinkStatus->partner[idx].serialNo) && ((gRfuLinkStatus->getNameFlag >> idx) & 1))
{
memcpy(buff1, gRfuLinkStatus->partner[idx].gname, 0xD);
memcpy(buff2, gRfuLinkStatus->partner[idx].uname, PLAYER_NAME_LENGTH + 1);
}
else
{
memset(buff1, 0, 0xD);
memset(buff2, 0, PLAYER_NAME_LENGTH + 1);
}
}
else
{
retVal = FALSE;
if (sub_8010454(gRfuLinkStatus->partner[idx].serialNo))
{
memcpy(buff1, gRfuLinkStatus->partner[idx].gname, 0xD);
memcpy(buff2, gRfuLinkStatus->partner[idx].uname, PLAYER_NAME_LENGTH + 1);
}
else
{
memset(buff1, 0, 0xD);
memset(buff2, 0, PLAYER_NAME_LENGTH + 1);
}
}
return retVal;
}
bool8 sub_800DF34(struct GFtgtGname *buff1, u8 *buff2, u8 idx)
{
bool8 retVal = FALSE;
if (gRfuLinkStatus->partner[idx].serialNo == 0x7F7D)
{
memcpy(buff1, gRfuLinkStatus->partner[idx].gname, 0xD);
memcpy(buff2, gRfuLinkStatus->partner[idx].uname, 8);
retVal = TRUE;
}
else
{
memset(buff1, 0, 0xD);
memset(buff2, 0, 8);
}
return retVal;
}
void sub_800DF90(struct GFtgtGname *buff1, u8 *buff2)
{
memcpy(buff1, &gUnknown_02022B14, 0xD);
memcpy(buff2, gUnknown_02022B22, 8);
}
void CreateWirelessStatusIndicatorSprite(u8 x, u8 y)
{
u8 sprId;
if (x == 0 && y == 0)
{
x = 0xE7;
y = 0x08;
}
if (gRfuLinkStatus->parentChild == 1)
{
sprId = CreateSprite(&sWirelessStatusIndicatorSpriteTemplate, x, y, 0);
gSprites[sprId].data[7] = 0x1234;
gSprites[sprId].data[6] = GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag);
gSprites[sprId].invisible = TRUE;
gWirelessStatusIndicatorSpriteId = sprId;
}
else
{
gWirelessStatusIndicatorSpriteId = CreateSprite(&sWirelessStatusIndicatorSpriteTemplate, x, y, 0);
gSprites[gWirelessStatusIndicatorSpriteId].data[7] = 0x1234;
gSprites[gWirelessStatusIndicatorSpriteId].data[6] = GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag);
gSprites[gWirelessStatusIndicatorSpriteId].invisible = TRUE;
}
}
void DestroyWirelessStatusIndicatorSprite(void)
{
if (gSprites[gWirelessStatusIndicatorSpriteId].data[7] == 0x1234)
{
gSprites[gWirelessStatusIndicatorSpriteId].data[7] = 0;
DestroySprite(&gSprites[gWirelessStatusIndicatorSpriteId]);
gMain.oamBuffer[125] = gDummyOamData;
CpuCopy16(&gDummyOamData, (struct OamData *)OAM + 125, sizeof(struct OamData));
}
}
void LoadWirelessStatusIndicatorSpriteGfx(void)
{
if (GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag) == 0xFFFF)
{
LoadCompressedSpriteSheet(&sWirelessStatusIndicatorSpriteSheet);
}
LoadSpritePalette(&sWirelessStatusIndicatorSpritePalette);
gWirelessStatusIndicatorSpriteId = 0xFF;
}
u8 sub_800E124(void)
{
u8 i;
u8 flags = gRfuLinkStatus->connSlotFlag;
for (i = 0; i < 4; i++)
{
if (flags & 1)
{
return gRfuLinkStatus->strength[i];
}
flags >>= 1;
}
return 0;
}
void sub_800E15C(struct Sprite *sprite, s32 signalStrengthAnimNum)
{
if (sprite->data[2] != signalStrengthAnimNum)
{
sprite->data[2] = signalStrengthAnimNum;
sprite->data[3] = 0;
sprite->data[4] = 0;
}
}
void sub_800E174(void)
{
if (gWirelessStatusIndicatorSpriteId != 0xFF && gSprites[gWirelessStatusIndicatorSpriteId].data[7] == 0x1234)
{
struct Sprite *sprite = &gSprites[gWirelessStatusIndicatorSpriteId];
u8 signalStrength = 255;
u8 i = 0;
if (gRfuLinkStatus->parentChild == 1)
{
for (i = 0; i < GetLinkPlayerCount() - 1; i++)
{
if (signalStrength >= sub_800DD1C(i + 1))
{
signalStrength = sub_800DD1C(i + 1);
}
}
}
else
{
signalStrength = sub_800E124();
}
if (sub_8012224() == TRUE)
{
sprite->data[0] = 4;
}
else if (signalStrength < 25)
{
sprite->data[0] = 3;
}
else if (signalStrength >= 25 && signalStrength < 127)
{
sprite->data[0] = 2;
}
else if (signalStrength >= 127 && signalStrength < 229)
{
sprite->data[0] = 1;
}
else if (signalStrength >= 229)
{
sprite->data[0] = 0;
}
if (sprite->data[0] != sprite->data[1])
{
sub_800E15C(sprite, sprite->data[0]);
sprite->data[1] = sprite->data[0];
}
if (sprite->anims[sprite->data[2]][sprite->data[4]].frame.duration < sprite->data[3])
{
sprite->data[4]++;
sprite->data[3] = 0;
if (sprite->anims[sprite->data[2]][sprite->data[4]].type == -2)
{
sprite->data[4] = 0;
}
}
else
{
sprite->data[3]++;
}
gMain.oamBuffer[125] = sWirelessStatusIndicatorOamData;
gMain.oamBuffer[125].x = sprite->pos1.x + sprite->centerToCornerVecX;
gMain.oamBuffer[125].y = sprite->pos1.y + sprite->centerToCornerVecY;
gMain.oamBuffer[125].paletteNum = sprite->oam.paletteNum;
gMain.oamBuffer[125].tileNum = sprite->data[6] + sprite->anims[sprite->data[2]][sprite->data[4]].frame.imageValue;
CpuCopy16(gMain.oamBuffer + 125, (struct OamData *)OAM + 125, sizeof(struct OamData));
if (sub_8011A74() == 1)
{
DestroyWirelessStatusIndicatorSprite();
}
}
}
void CopyTrainerRecord(struct TrainerNameRecord *dest, u32 trainerId, const u8 *name)
{
dest->trainerId = trainerId;
StringCopy(dest->trainerName, name);
}
bool32 NameIsNotEmpty(const u8 *name)
{
s32 i;
for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++)
{
if (name[i] != 0)
{
return TRUE;
}
}
return FALSE;
}
// Save the currently connected players into the trainer records, shifting all previous records down.
void RecordMixTrainerNames(void)
{
if (gWirelessCommType != 0)
{
s32 i;
s32 j;
s32 nextSpace;
s32 connectedTrainerRecordIndices[5];
struct TrainerNameRecord *newRecords = calloc(20, sizeof(struct TrainerNameRecord));
// Check if we already have a record saved for connected trainers.
for (i = 0; i < GetLinkPlayerCount(); i++)
{
connectedTrainerRecordIndices[i] = -1;
for (j = 0; j < 20; j++)
{
if ((u16)gLinkPlayers[i].trainerId == gSaveBlock1Ptr->trainerNameRecords[j].trainerId && StringCompare(gLinkPlayers[i].name, gSaveBlock1Ptr->trainerNameRecords[j].trainerName) == 0)
{
connectedTrainerRecordIndices[i] = j;
}
}
}
// Save the connected trainers first, at the top of the list.
nextSpace = 0;
for (i = 0; i < GetLinkPlayerCount(); i++)
{
if (i != GetMultiplayerId() && gLinkPlayers[i].language != LANGUAGE_JAPANESE)
{
CopyTrainerRecord(&newRecords[nextSpace], (u16)gLinkPlayers[i].trainerId, gLinkPlayers[i].name);
// If we already had a record for this trainer, wipe it so that the next step doesn't duplicate it.
if (connectedTrainerRecordIndices[i] >= 0)
{
memset(gSaveBlock1Ptr->trainerNameRecords[connectedTrainerRecordIndices[i]].trainerName, 0, 8);
}
nextSpace++;
}
}
// Copy all non-empty records to the new list, in the order they appear on the old list. If the list is full,
// the last (oldest) records will be dropped.
for (i = 0; i < 20; i++)
{
if (NameIsNotEmpty(gSaveBlock1Ptr->trainerNameRecords[i].trainerName))
{
CopyTrainerRecord(&newRecords[nextSpace], gSaveBlock1Ptr->trainerNameRecords[i].trainerId, gSaveBlock1Ptr->trainerNameRecords[i].trainerName);
if (++nextSpace >= 20)
{
break;
}
}
}
// Finalize the new list, and clean up.
memcpy(gSaveBlock1Ptr->trainerNameRecords, newRecords, 20 * sizeof(struct TrainerNameRecord));
free(newRecords);
}
}
bool32 sub_800E540(u16 id, u8 *name)
{
s32 i;
for (i = 0; i < 20; i++)
{
if (StringCompare(gSaveBlock1Ptr->trainerNameRecords[i].trainerName, name) == 0 && gSaveBlock1Ptr->trainerNameRecords[i].trainerId == id)
{
return TRUE;
}
if (!NameIsNotEmpty(gSaveBlock1Ptr->trainerNameRecords[i].trainerName))
{
return FALSE;
}
}
return FALSE;
}
void WipeTrainerNameRecords(void)
{
s32 i;
for (i = 0; i < 20; i++)
{
gSaveBlock1Ptr->trainerNameRecords[i].trainerId = 0;
CpuFill16(0, gSaveBlock1Ptr->trainerNameRecords[i].trainerName, 8);
}
}

View File

@ -2913,7 +2913,7 @@ bool32 sub_808766C(void)
static u32 GetLinkSendQueueLength(void)
{
if (gWirelessCommType != 0)
return gUnknown_03005000.unk_9e8.unk_232;
return Rfu.unk_9e8.unk_232;
else
return gLink.sendQueue.count;
}

View File

@ -3527,7 +3527,7 @@ static void CursorCb_Register(u8 taskId)
u16 species = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES);
u8 obedience = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_OBEDIENCE);
switch (CanRegisterMonForTradingBoard(*(struct UnkLinkRfuStruct_02022B14Substruct *)sub_800F7DC(), species2, species, obedience))
switch (CanRegisterMonForTradingBoard(*(struct GFtgtGnameSub *)sub_800F7DC(), species2, species, obedience))
{
case CANT_REGISTER_MON:
StringExpandPlaceholders(gStringVar4, gText_PkmnCantBeTradedNow);
@ -3553,7 +3553,7 @@ static void CursorCb_Trade1(u8 taskId)
u16 species2 = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES2);
u16 species = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES);
u8 obedience = GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_OBEDIENCE);
u32 stringId = GetUnionRoomTradeMessageId(*(struct UnkLinkRfuStruct_02022B14Substruct *)sub_800F7DC(), gUnknown_02022C38, species2, gUnionRoomOfferedSpecies, gUnionRoomRequestedMonType, species, obedience);
u32 stringId = GetUnionRoomTradeMessageId(*(struct GFtgtGnameSub *)sub_800F7DC(), gUnknown_02022C38, species2, gUnionRoomOfferedSpecies, gUnionRoomRequestedMonType, species, obedience);
if (stringId != UR_TRADE_MSG_NONE)
{

View File

@ -2040,7 +2040,7 @@ static int sub_802C6B0(void)
static bool32 sub_802C70C(void)
{
return !gUnknown_03005000.unk_124.unk_8c2 && !gUnknown_03005000.unk_9e8.unk_232;
return !Rfu.unk_124.unk_8c2 && !Rfu.unk_9e8.unk_232;
}
static int sub_802C73C(u8 *arg0)

View File

@ -236,7 +236,7 @@ static bool8 SendLinkData(const void *linkData, u32 size)
{
if (gUnknown_02022C2C == 29)
{
rfu_NI_setSendData(gUnknown_03004140.unk_00, 84, linkData, size);
rfu_NI_setSendData(lman.acceptSlot_flag, 84, linkData, size);
return TRUE;
}
else
@ -254,7 +254,7 @@ static bool32 sub_80771BC(void)
{
if (gUnknown_02022C2C == 29)
{
if (gRfuSlotStatusNI[sub_800E87C(gUnknown_03004140.unk_00)]->send.state == 0)
if (gRfuSlotStatusNI[sub_800E87C(lman.acceptSlot_flag)]->send.state == 0)
return TRUE;
else
return FALSE;
@ -273,7 +273,7 @@ static u32 _GetBlockReceivedStatus(void)
static void TradeResetReceivedFlags(void)
{
if (IsWirelessTrade())
rfu_clearSlot(12, gUnknown_03004140.unk_00);
rfu_clearSlot(12, lman.acceptSlot_flag);
else
ResetBlockReceivedFlags();
}
@ -281,7 +281,7 @@ static void TradeResetReceivedFlags(void)
static void TradeResetReceivedFlag(u32 who)
{
if (IsWirelessTrade())
rfu_clearSlot(12, gUnknown_03004140.unk_00);
rfu_clearSlot(12, lman.acceptSlot_flag);
else
ResetBlockReceivedFlag(who);
}
@ -2405,15 +2405,15 @@ static bool32 IsDeoxysOrMewUntradable(u16 species, bool8 isObedientBitSet)
return FALSE;
}
int GetUnionRoomTradeMessageId(struct UnkLinkRfuStruct_02022B14Substruct rfuPlayer, struct UnkLinkRfuStruct_02022B14Substruct rfuPartner, u16 playerSpecies2, u16 partnerSpecies, u8 requestedType, u16 playerSpecies, u8 isObedientBitSet)
int GetUnionRoomTradeMessageId(struct GFtgtGnameSub rfuPlayer, struct GFtgtGnameSub rfuPartner, u16 playerSpecies2, u16 partnerSpecies, u8 requestedType, u16 playerSpecies, u8 isObedientBitSet)
{
bool8 playerHasNationalDex = rfuPlayer.hasNationalDex;
bool8 playerIsChampion = rfuPlayer.isChampion;
bool8 partnerHasNationalDex = rfuPartner.hasNationalDex;
bool8 partnerIsChampion = rfuPartner.isChampion;
u8 r1 = rfuPartner.unk_01_2;
u8 r1 = rfuPartner.version;
if (r1 != 3)
if (r1 != VERSION_EMERALD)
{
if (!playerIsChampion)
{
@ -2476,7 +2476,7 @@ int GetUnionRoomTradeMessageId(struct UnkLinkRfuStruct_02022B14Substruct rfuPlay
return UR_TRADE_MSG_NONE;
}
int CanRegisterMonForTradingBoard(struct UnkLinkRfuStruct_02022B14Substruct rfuPlayer, u16 species2, u16 species, u8 isObedientBitSet)
int CanRegisterMonForTradingBoard(struct GFtgtGnameSub rfuPlayer, u16 species2, u16 species, u8 isObedientBitSet)
{
bool8 hasNationalDex = rfuPlayer.hasNationalDex;

View File

@ -59,7 +59,7 @@ EWRAM_DATA u8 gUnknown_02022C2C = 0;
EWRAM_DATA u8 gUnknown_02022C2D = 0;
EWRAM_DATA union UnkUnion_Main gUnknown_02022C30 = {};
EWRAM_DATA u32 gFiller_02022C34 = 0;
EWRAM_DATA struct UnkLinkRfuStruct_02022B14Substruct gUnknown_02022C38 = {};
EWRAM_DATA struct GFtgtGnameSub gUnknown_02022C38 = {};
EWRAM_DATA u16 gUnionRoomOfferedSpecies = 0;
EWRAM_DATA u8 gUnionRoomRequestedMonType = 0;
static EWRAM_DATA struct UnionRoomTrade sUnionRoomTrade = {};
@ -106,7 +106,7 @@ void sub_801AC54(void);
void sub_80149D8(void);
void MG_DrawTextBorder(u8 windowId);
s8 mevent_message_print_and_prompt_yes_no(u8 *textState, u8 *arg1, u8 arg2, const u8 *str);
bool32 sub_8016F1C(struct UnkLinkRfuStruct_02022B14 *arg0, s16 arg1);
bool32 sub_8016F1C(struct GFtgtGname *arg0, s16 arg1);
u8 sub_8016DF0(struct UnkStruct_Main4 *arg0, struct UnkStruct_Main4 *arg1, u32 arg2);
void sub_8019F2C(void);
static bool32 RegisterTradeMonAndGetIsEgg(u32 monId, struct UnionRoomTrade *trade);
@ -875,9 +875,9 @@ void sub_80134E8(u8 taskId)
{
// this unused variable along with the assignment is needed to match
u32 unusedVar;
unusedVar = data->field_0->arr[id].unk.field_0.unk_0a_0;
unusedVar = data->field_0->arr[id].unk.field_0.activity;
if (data->field_0->arr[id].field_1A_0 == 1 && !data->field_0->arr[id].unk.field_0.unk_0a_7)
if (data->field_0->arr[id].field_1A_0 == 1 && !data->field_0->arr[id].unk.field_0.started)
{
u32 var = sub_8013B8C(data, id);
if (var == 0)
@ -919,7 +919,7 @@ void sub_80134E8(u8 taskId)
case 6:
if (gReceivedRemoteLinkPlayers != 0)
{
gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.unk_0a_0;
gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.activity;
sub_8011A64(0, 0);
switch (gUnknown_02022C2C)
{
@ -1078,7 +1078,7 @@ u32 sub_8013B8C(struct UnkStruct_Group *arg0, s32 id)
{
struct UnkStruct_x20 *structPtr = &arg0->field_0->arr[id];
if (gUnknown_02022C2C == 4 && structPtr->unk.field_0.unk_00.unk_01_2 != 3)
if (gUnknown_02022C2C == 4 && structPtr->unk.field_0.unk_00.version != VERSION_EMERALD)
{
if (!(gSaveBlock2Ptr->specialSaveWarpFlags & CHAMPION_SAVEWARP))
return 1;
@ -1187,7 +1187,7 @@ u8 sub_8013DBC(struct UnkStruct_Group *data, u32 id)
{
if (data->field_0->arr[id].field_1A_0 == 1)
{
if (data->field_0->arr[id].unk.field_0.unk_0a_7)
if (data->field_0->arr[id].unk.field_0.started)
return 3;
else if (data->field_0->arr[id].field_1A_1 != 0)
return 1;
@ -1946,9 +1946,9 @@ void sub_8014F48(u8 taskId)
{
// this unused variable along with the assignment is needed to match
u32 unusedVar;
unusedVar = data->field_0->arr[id].unk.field_0.unk_0a_0;
unusedVar = data->field_0->arr[id].unk.field_0.activity;
if (data->field_0->arr[id].field_1A_0 == 1 && !data->field_0->arr[id].unk.field_0.unk_0a_7)
if (data->field_0->arr[id].field_1A_0 == 1 && !data->field_0->arr[id].unk.field_0.started)
{
data->field_F = id;
LoadWirelessStatusIndicatorSpriteGfx();
@ -1979,7 +1979,7 @@ void sub_8014F48(u8 taskId)
case 5:
if (gReceivedRemoteLinkPlayers != 0)
{
gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.unk_0a_0;
gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.activity;
data->state = 10;
}
@ -2108,7 +2108,7 @@ void sub_80152F4(u8 taskId)
id = ListMenu_ProcessInput(data->listTaskId);
if (data->field_14 > 120)
{
if (data->field_0->arr[0].field_1A_0 == 1 && !data->field_0->arr[0].unk.field_0.unk_0a_7)
if (data->field_0->arr[0].field_1A_0 == 1 && !data->field_0->arr[0].unk.field_0.started)
{
if (sub_8016F1C(&data->field_0->arr[0].unk.field_0, data->field_12 + 7))
{
@ -2144,7 +2144,7 @@ void sub_80152F4(u8 taskId)
case 5:
if (gReceivedRemoteLinkPlayers != 0)
{
gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.unk_0a_0;
gUnknown_02022C2C = data->field_0->arr[data->field_F].unk.field_0.activity;
data->state = 12;
}
@ -3250,11 +3250,11 @@ void sub_8016CA0(u8 taskId)
for (i = 0; i < 4; i++)
{
r4 = sub_800DE7C(&sp0.field_0, sp0.playerName, i);
if (!sub_8013D88(sp0.field_0.unk_0a_0, gTasks[taskId].data[4]))
if (!sub_8013D88(sp0.field_0.activity, gTasks[taskId].data[4]))
{
sp0 = gUnknown_082F045C;
}
if (sp0.field_0.unk_00.unk_00_0 == 1)
if (sp0.field_0.unk_00.language == 1)
{
sp0 = gUnknown_082F045C;
}
@ -3296,7 +3296,7 @@ void sub_8016E24(u8 taskId)
for (i = 0; i < 4; i++)
{
sub_800DE7C(&ptr[0]->arr[i].unk0.field_0, ptr[0]->arr[i].unk0.playerName, i);
if (!sub_8013D88(ptr[0]->arr[i].unk0.field_0.unk_0a_0, gTasks[taskId].data[2]))
if (!sub_8013D88(ptr[0]->arr[i].unk0.field_0.activity, gTasks[taskId].data[2]))
{
ptr[0]->arr[i].unk0 = gUnknown_082F045C;
}
@ -3311,11 +3311,11 @@ void sub_8016E24(u8 taskId)
}
}
bool32 sub_8016F1C(struct UnkLinkRfuStruct_02022B14 *arg0, s16 arg1)
bool32 sub_8016F1C(struct GFtgtGname *arg0, s16 arg1)
{
if (arg1 == 7)
{
if (!arg0->unk_00.unk_00_5)
if (!arg0->unk_00.hasCard)
{
return FALSE;
}
@ -3326,7 +3326,7 @@ bool32 sub_8016F1C(struct UnkLinkRfuStruct_02022B14 *arg0, s16 arg1)
}
else if (arg1 == 8)
{
if (!arg0->unk_00.unk_00_4)
if (!arg0->unk_00.hasNews)
{
return FALSE;
}
@ -3703,19 +3703,19 @@ bool32 sub_8017678(struct UnkStruct_Shared *arg0, struct UnkStruct_Shared *arg1)
{
s32 i;
if (arg0->field_0.unk_0a_0 != arg1->field_0.unk_0a_0)
if (arg0->field_0.activity != arg1->field_0.activity)
{
return TRUE;
}
if (arg0->field_0.unk_0a_7 != arg1->field_0.unk_0a_7)
if (arg0->field_0.started != arg1->field_0.started)
{
return TRUE;
}
for (i = 0; i < 4; i++)
{
if (arg0->field_0.unk_04[i] != arg1->field_0.unk_04[i])
if (arg0->field_0.child_sprite_gender[i] != arg1->field_0.child_sprite_gender[i])
{
return TRUE;
}
@ -3783,7 +3783,7 @@ void sub_80177B8(u8 arg0, u8 arg1, u8 arg2, struct UnkStruct_x20 *arg3, u8 arg4,
StringAppend(gStringVar4, sText_Colon);
sub_80173E0(arg0, 1, gStringVar4, arg1, arg2, 0);
arg1 += 18;
r2 = arg3->unk.field_0.unk_0a_0;
r2 = arg3->unk.field_0.activity;
if (arg3->field_1A_0 == 1 && !(r2 & 0x40))
{
sub_8018404(gStringVar4, arg3);
@ -3859,11 +3859,11 @@ s32 sub_80179D4(struct UnkStruct_Main0 *arg0, u8 arg1, u8 arg2, u32 playerGender
struct UnkStruct_x20 * r5 = &arg0->arr[arg2];
if (!r5->unk.field_0.unk_0a_7 && arg1 == 0)
if (!r5->unk.field_0.started && arg1 == 0)
{
sub_8018404(gStringVar1, r5);
r2 = sub_800E540(ReadAsU16(r5->unk.field_0.unk_00.playerTrainerId), gStringVar1);
if (r5->unk.field_0.unk_0a_0 == 0x45)
if (r5->unk.field_0.activity == 0x45)
{
StringExpandPlaceholders(gStringVar4, sJoinChatTexts[r2][playerGender]);
return 2;
@ -3881,7 +3881,7 @@ s32 sub_80179D4(struct UnkStruct_Main0 *arg0, u8 arg1, u8 arg2, u32 playerGender
{
playerGender = (r5->unk.field_0.unk_00.playerTrainerId[arg1 + 1] >> 3) & 1;
}
switch (r5->unk.field_0.unk_0a_0 & 0x3F)
switch (r5->unk.field_0.activity & 0x3F)
{
case 1:
StringExpandPlaceholders(gStringVar4, sBattleReactionTexts[playerGender][Random() % 4]);
@ -3908,7 +3908,7 @@ void nullsub_14(u8 windowId, s32 itemId, u8 y)
}
void sub_8017B3C(u8 arg0, u8 arg1, struct UnkLinkRfuStruct_02022B14 * arg2, const u8 * str, u8 arg4)
void sub_8017B3C(u8 arg0, u8 arg1, struct GFtgtGname * arg2, const u8 * str, u8 arg4)
{
u8 sp8[4];
u16 r8 = arg2->species;
@ -3932,7 +3932,7 @@ void sub_8017B3C(u8 arg0, u8 arg1, struct UnkLinkRfuStruct_02022B14 * arg2, cons
void sub_8017BE8(u8 windowId, s32 itemId, u8 y)
{
struct UnkStruct_Leader *leader = gUnknown_02022C30.leader;
struct UnkLinkRfuStruct_02022B14 *rfu;
struct GFtgtGname *rfu;
s32 i, j;
u8 sp4[11];
@ -4340,5 +4340,5 @@ void sub_8018220(u8 *unused, struct UnkStruct_URoom *arg1, bool8 arg2)
void sub_8018404(u8 *dest, struct UnkStruct_x20 *arg1)
{
StringCopy7(dest, arg1->unk.playerName);
ConvertInternationalString(dest, arg1->unk.field_0.unk_00.unk_00_0);
ConvertInternationalString(dest, arg1->unk.field_0.unk_00.language);
}

View File

@ -369,7 +369,7 @@ static void sub_801A8B0(u8 windowId, u8 fontId, const u8 * str, u8 x, u8 y, u8 m
u32 sub_801A960(struct UnkStruct_x20 * a0, u32 * a1)
{
s32 i, j, r2;
u32 result = a0->unk.field_0.unk_0a_0;
u32 result = a0->unk.field_0.activity;
for (i = 0; i < (unsigned)ARRAY_COUNT(gUnknown_082F0D70); i++)
{
@ -386,7 +386,7 @@ u32 sub_801A960(struct UnkStruct_x20 * a0, u32 * a1)
r2 = 0;
for (j = 0; j < 4; j++)
{
if (a0->unk.field_0.unk_04[j] != 0)
if (a0->unk.field_0.child_sprite_gender[j] != 0)
{
r2++;
}

View File

@ -418,13 +418,13 @@ void sub_8019F2C(void)
}
}
static u8 sub_8019F64(u32 r1, u32 unused, struct UnkLinkRfuStruct_02022B14 * r2)
static u8 sub_8019F64(u32 r1, u32 unused, struct GFtgtGname * r2)
{
if (r1 != 0)
{
return gUnknown_082F076F[r1];
}
else if (r2->unk_0a_0 == 0x45)
else if (r2->activity == 0x45)
{
return 1;
}
@ -439,7 +439,7 @@ static u32 sub_8019F8C(u32 a0, u32 a1)
return sub_8097C8C(5 * a0 + a1 - 0x38);
}
static void sub_8019FA4(u32 r5, u32 r6, u8 r8, struct UnkLinkRfuStruct_02022B14 * r9)
static void sub_8019FA4(u32 r5, u32 r6, u8 r8, struct GFtgtGname * r9)
{
s32 x, y;
s32 r7 = 5 * r5 + r6;
@ -462,7 +462,7 @@ static void sub_801A02C(u32 a0, u32 a1)
sub_8088B94(x, y, 0);
}
static void sub_801A064(u32 r7, struct UnkLinkRfuStruct_02022B14 * r8)
static void sub_801A064(u32 r7, struct GFtgtGname * r8)
{
s16 x, y, x2, y2;
s32 i;
@ -479,21 +479,21 @@ static void sub_801A064(u32 r7, struct UnkLinkRfuStruct_02022B14 * r8)
}
for (i = 1; i < 5; i++)
{
if (r8->unk_04[i - 1] == 0)
if (r8->child_sprite_gender[i - 1] == 0)
{
sub_801A02C(r7, i);
}
else if (sub_80199E0(r7, i, x, y) == 0 && sub_80199E0(r7, i, x2, y2) == 0)
{
sub_8019FA4(r7, i, sub_8019978((r8->unk_04[i - 1] >> 3) & 1, r8->unk_04[i - 1] & 7), r8);
sub_8019FA4(r7, i, sub_8019978((r8->child_sprite_gender[i - 1] >> 3) & 1, r8->child_sprite_gender[i - 1] & 7), r8);
}
}
}
static void sub_801A16C(u32 r5, struct UnkLinkRfuStruct_02022B14 * r4)
static void sub_801A16C(u32 r5, struct GFtgtGname * r4)
{
u32 i;
switch (r4->unk_0a_0)
switch (r4->activity)
{
case 0x40:
case 0x54:
@ -516,7 +516,7 @@ static void sub_801A16C(u32 r5, struct UnkLinkRfuStruct_02022B14 * r4)
}
}
static void sub_801A214(u32 r5, struct UnkLinkRfuStruct_02022B14 * unused)
static void sub_801A214(u32 r5, struct GFtgtGname * unused)
{
s32 i;
sub_8019D20(r5);

View File

@ -6,7 +6,9 @@
.include "gflib/text.o"
.include "gflib/sprite.o"
.include "src/link.o"
.include "src/link_rfu.o"
.include "src/AgbRfu_LinkManager.o"
.include "src/link_rfu_3.o"
.include "src/link_rfu_2.o"
.include "src/union_room.o"
.include "src/union_room_battle.o"
.include "src/dodrio_berry_picking.o"

View File

@ -33,7 +33,8 @@ gReservedSpritePaletteCount:
.space 1
.align 4
.include "link.o"
.include "link_rfu.o"
.include "AgbRfu_LinkManager.o"
.include "link_rfu_2.o"
.include "rtc.o"
.include "battle_main.o"
.include "random.o"

View File

@ -5,7 +5,9 @@
.include "gflib/sprite.o"
.include "gflib/string_util.o"
.include "src/link.o"
.include "src/link_rfu.o"
.include "src/AgbRfu_LinkManager.o"
.include "src/link_rfu_3.o"
.include "src/link_rfu_2.o"
.include "src/union_room.o"
.include "src/mystery_gift.o"
.include "src/union_room_player_avatar.o"