From 9a15a3a038cc1d34e81b8c617974b5990b9267ee Mon Sep 17 00:00:00 2001 From: WhenGryphonsFly <84215159+WhenGryphonsFly@users.noreply.github.com> Date: Sun, 4 Aug 2024 20:44:45 -0500 Subject: [PATCH 1/5] Split rom_9BC Split rom_9BC.s/.c into its known components gbplayer.c/.s and link.s, as well as its unknown component rom_2414.s/.c --- asm/gbplayer.s | 585 +++++++++++++++++++++++++++++ asm/{rom_9BC.s => link.s} | 683 ---------------------------------- asm/rom_2414.s | 106 ++++++ ld_script.txt | 6 +- src/{rom_9BC.c => rom_2414.c} | 0 5 files changed, 695 insertions(+), 685 deletions(-) create mode 100644 asm/gbplayer.s rename asm/{rom_9BC.s => link.s} (69%) create mode 100644 asm/rom_2414.s rename src/{rom_9BC.c => rom_2414.c} (100%) diff --git a/asm/gbplayer.s b/asm/gbplayer.s new file mode 100644 index 0000000..a3442f2 --- /dev/null +++ b/asm/gbplayer.s @@ -0,0 +1,585 @@ + .include "asm/macros.inc" + + .syntax unified + + .text + + thumb_func_start sub_13FC +sub_13FC: @ 0x080013FC + push {r4, r5, r6, r7, lr} + mov r7, sb + mov r6, r8 + push {r6, r7} + sub sp, #0xc + ldr r1, _08001434 @ =gUnknown_02002818 + ldr r0, _08001438 @ =0x04000120 + ldr r0, [r0] + str r0, [r1] + ldr r1, _0800143C @ =0x0400010E + movs r0, #0 + strh r0, [r1] + subs r1, #2 + movs r2, #0x80 + lsls r2, r2, #8 + adds r0, r2, #0 + strh r0, [r1] + ldr r0, _08001440 @ =gUnknown_02019C10 + ldrb r1, [r0] + mov sb, r0 + cmp r1, #5 + bls _0800142A + b _0800161C +_0800142A: + lsls r0, r1, #2 + ldr r1, _08001444 @ =_08001448 + adds r0, r0, r1 + ldr r0, [r0] + mov pc, r0 + .align 2, 0 +_08001434: .4byte gUnknown_02002818 +_08001438: .4byte 0x04000120 +_0800143C: .4byte 0x0400010E +_08001440: .4byte gUnknown_02019C10 +_08001444: .4byte _08001448 +_08001448: @ jump table + .4byte _08001460 @ case 0 + .4byte _08001520 @ case 1 + .4byte _08001574 @ case 2 + .4byte _080015C8 @ case 3 + .4byte _0800161C @ case 4 + .4byte _0800161C @ case 5 +_08001460: + ldr r0, _080014B0 @ =0x04000120 + mov r8, r0 + ldr r6, [r0] + ldr r3, _080014B4 @ =gUnknown_02002808 + ldrb r1, [r3] + lsls r2, r1, #4 + adds r0, r6, #0 + lsls r0, r2 + lsrs r0, r0, #0x10 + movs r7, #1 + subs r1, r7, r1 + lsls r1, r1, #4 + lsls r6, r1 + adds r1, r6, #0 + lsrs r6, r1, #0x10 + ldrh r5, [r3, #0xa] + adds r4, r3, #0 + cmp r5, #0 + bne _080014E4 + ldrh r2, [r4, #6] + adds r1, r0, #0 + cmp r1, r2 + bne _080014E2 + ldrh r3, [r4, #2] + cmp r3, #3 + bhi _080014B8 + ldrh r0, [r4, #4] + mvns r0, r0 + lsls r0, r0, #0x10 + lsrs r0, r0, #0x10 + cmp r1, r0 + bne _080014E4 + mvns r0, r2 + lsls r0, r0, #0x10 + lsrs r0, r0, #0x10 + cmp r6, r0 + bne _080014E4 + adds r0, r3, #1 + strh r0, [r4, #2] + b _080014E4 + .align 2, 0 +_080014B0: .4byte 0x04000120 +_080014B4: .4byte gUnknown_02002808 +_080014B8: + strh r6, [r4, #0xa] + ldr r0, _080014D8 @ =0x00008002 + cmp r6, r0 + bne _080014E0 + mov r1, sb + strb r7, [r1] + movs r0, #1 + bl sub_1748 + ldr r1, _080014DC @ =gUnknown_02002814 + str r0, [r1] + mov r2, r8 + str r0, [r2] + strh r5, [r4, #2] + b _08001640 + .align 2, 0 +_080014D8: .4byte 0x00008002 +_080014DC: .4byte gUnknown_02002814 +_080014E0: + strh r5, [r4, #0xa] +_080014E2: + strh r5, [r4, #2] +_080014E4: + ldrh r0, [r4, #2] + cmp r0, #3 + bhi _080014F8 + lsls r0, r0, #1 + ldr r1, _080014F4 @ =gUnknown_0805C748 + adds r0, r0, r1 + ldrh r0, [r0] + b _080014FC + .align 2, 0 +_080014F4: .4byte gUnknown_0805C748 +_080014F8: + movs r0, #0x80 + lsls r0, r0, #8 +_080014FC: + strh r0, [r4, #4] + mvns r0, r6 + strh r0, [r4, #6] + ldr r3, _0800151C @ =0x04000120 + ldrh r2, [r4, #4] + ldrb r1, [r4] + movs r0, #1 + subs r0, r0, r1 + lsls r0, r0, #4 + lsls r2, r0 + ldrh r0, [r4, #6] + lsls r1, r1, #4 + lsls r0, r1 + adds r2, r2, r0 + str r2, [r3] + b _08001640 + .align 2, 0 +_0800151C: .4byte 0x04000120 +_08001520: + ldr r5, _08001544 @ =gUnknown_02019C10 + ldrb r0, [r5] + bl sub_16A0 + cmp r0, #0 + beq _08001550 + ldr r1, _08001548 @ =gUnknown_02002808 + movs r4, #0 + movs r0, #0 + strh r0, [r1, #2] + str r0, [sp] + ldr r2, _0800154C @ =0x05000003 + mov r0, sp + bl CpuSet + strb r4, [r5] + b _08001554 + .align 2, 0 +_08001544: .4byte gUnknown_02019C10 +_08001548: .4byte gUnknown_02002808 +_0800154C: .4byte 0x05000003 +_08001550: + movs r0, #2 + strb r0, [r5] +_08001554: + ldr r0, _0800156C @ =gUnknown_02019BF4 + ldr r0, [r0] + ldr r1, _08001570 @ =gUnknown_02019C10 + mov sb, r1 + cmp r0, #0 + bne _08001564 + movs r0, #4 + strb r0, [r1] +_08001564: + mov r2, sb + ldrb r0, [r2] + b _080015F8 + .align 2, 0 +_0800156C: .4byte gUnknown_02019BF4 +_08001570: .4byte gUnknown_02019C10 +_08001574: + ldr r5, _08001598 @ =gUnknown_02019C10 + ldrb r0, [r5] + bl sub_16A0 + cmp r0, #0 + beq _080015A4 + ldr r1, _0800159C @ =gUnknown_02002808 + movs r4, #0 + movs r0, #0 + strh r0, [r1, #2] + str r0, [sp, #4] + add r0, sp, #4 + ldr r2, _080015A0 @ =0x05000003 + bl CpuSet + strb r4, [r5] + b _080015A8 + .align 2, 0 +_08001598: .4byte gUnknown_02019C10 +_0800159C: .4byte gUnknown_02002808 +_080015A0: .4byte 0x05000003 +_080015A4: + movs r0, #3 + strb r0, [r5] +_080015A8: + ldr r0, _080015C0 @ =gUnknown_02019BF4 + ldr r0, [r0] + ldr r1, _080015C4 @ =gUnknown_02019C10 + mov sb, r1 + cmp r0, #0 + bne _080015B8 + movs r0, #4 + strb r0, [r1] +_080015B8: + mov r2, sb + ldrb r0, [r2] + b _080015F8 + .align 2, 0 +_080015C0: .4byte gUnknown_02019BF4 +_080015C4: .4byte gUnknown_02019C10 +_080015C8: + mov r5, sb + ldrb r0, [r5] + bl sub_16A0 + cmp r0, #0 + beq _080015E8 + ldr r1, _08001608 @ =gUnknown_02002808 + movs r4, #0 + movs r0, #0 + strh r0, [r1, #2] + str r0, [sp, #8] + add r0, sp, #8 + ldr r2, _0800160C @ =0x05000003 + bl CpuSet + strb r4, [r5] +_080015E8: + ldr r0, _08001610 @ =gUnknown_02019BF4 + ldr r0, [r0] + cmp r0, #0 + bne _080015F4 + movs r0, #4 + strb r0, [r5] +_080015F4: + mov r1, sb + ldrb r0, [r1] +_080015F8: + bl sub_1748 + ldr r1, _08001614 @ =gUnknown_02002814 + str r0, [r1] + ldr r1, _08001618 @ =0x04000120 + str r0, [r1] + b _08001640 + .align 2, 0 +_08001608: .4byte gUnknown_02002808 +_0800160C: .4byte 0x05000003 +_08001610: .4byte gUnknown_02019BF4 +_08001614: .4byte gUnknown_02002814 +_08001618: .4byte 0x04000120 +_0800161C: + ldr r3, _08001634 @ =0x04000208 + movs r0, #0 + strh r0, [r3] + ldr r2, _08001638 @ =0x04000200 + ldrh r1, [r2] + ldr r0, _0800163C @ =0x0000FF7F + ands r0, r1 + strh r0, [r2] + movs r0, #1 + strh r0, [r3] + b _08001650 + .align 2, 0 +_08001634: .4byte 0x04000208 +_08001638: .4byte 0x04000200 +_0800163C: .4byte 0x0000FF7F +_08001640: + ldr r2, _08001660 @ =0x04000128 + ldrh r0, [r2] + movs r1, #0x80 + orrs r0, r1 + strh r0, [r2] + ldr r1, _08001664 @ =0x0400010E + movs r0, #0xc1 + strh r0, [r1] +_08001650: + add sp, #0xc + pop {r3, r4} + mov r8, r3 + mov sb, r4 + pop {r4, r5, r6, r7} + pop {r0} + bx r0 + .align 2, 0 +_08001660: .4byte 0x04000128 +_08001664: .4byte 0x0400010E + + thumb_func_start sub_1668 +sub_1668: @ 0x08001668 + push {r4, r5, lr} + ldr r2, _0800169C @ =0x00FFFFFF + ands r2, r0 + lsls r4, r2, #4 + lsls r1, r1, #0x1c + orrs r4, r1 + lsrs r3, r4, #0x1c + movs r2, #6 + movs r5, #0xf +_0800167A: + lsls r0, r2, #2 + adds r1, r4, #0 + lsrs r1, r0 + ands r1, r5 + eors r3, r1 + subs r0, r2, #1 + lsls r0, r0, #0x18 + lsrs r2, r0, #0x18 + cmp r2, #0 + bne _0800167A + movs r0, #0xf + ands r3, r0 + orrs r4, r3 + adds r0, r4, #0 + pop {r4, r5} + pop {r1} + bx r1 + .align 2, 0 +_0800169C: .4byte 0x00FFFFFF + + thumb_func_start sub_16A0 +sub_16A0: @ 0x080016A0 + push {r4, r5, r6, lr} + lsls r0, r0, #0x18 + lsrs r4, r0, #0x18 + ldr r6, _080016C4 @ =gUnknown_02002818 + ldr r0, [r6] + lsrs r5, r0, #0x1c + bl sub_170C + lsls r0, r0, #0x18 + cmp r0, #0 + bne _080016DE + cmp r4, #2 + beq _080016E8 + cmp r4, #2 + bgt _080016C8 + cmp r4, #1 + beq _080016CE + b _080016DE + .align 2, 0 +_080016C4: .4byte gUnknown_02002818 +_080016C8: + cmp r4, #3 + beq _08001700 + b _080016DE +_080016CE: + ldr r1, _080016E4 @ =gUnknown_0200281C + ldr r0, [r6] + lsls r0, r0, #4 + lsrs r0, r0, #8 + ands r0, r4 + str r0, [r1] + cmp r5, #1 + beq _08001704 +_080016DE: + movs r0, #1 + b _08001706 + .align 2, 0 +_080016E4: .4byte gUnknown_0200281C +_080016E8: + cmp r5, #2 + bne _080016DE + ldr r0, _080016FC @ =gUnknown_0200281C + ldr r1, [r6] + lsls r1, r1, #4 + lsrs r1, r1, #8 + ldr r0, [r0] + cmp r0, r1 + beq _08001704 + b _080016DE + .align 2, 0 +_080016FC: .4byte gUnknown_0200281C +_08001700: + cmp r5, #3 + bne _080016DE +_08001704: + movs r0, #0 +_08001706: + pop {r4, r5, r6} + pop {r1} + bx r1 + + thumb_func_start sub_170C +sub_170C: @ 0x0800170C + push {r4, r5, r6, lr} + ldr r0, _0800173C @ =gUnknown_02002818 + ldr r0, [r0] + lsrs r4, r0, #4 + movs r5, #0xf + ands r5, r0 + lsrs r3, r4, #0x18 + movs r0, #6 + movs r6, #0xf +_0800171E: + subs r0, #1 + lsls r2, r0, #2 + adds r1, r4, #0 + lsrs r1, r2 + ands r1, r6 + eors r3, r1 + lsls r0, r0, #0x18 + lsrs r0, r0, #0x18 + cmp r0, #0 + bne _0800171E + cmp r3, r5 + beq _08001740 + movs r0, #1 + b _08001742 + .align 2, 0 +_0800173C: .4byte gUnknown_02002818 +_08001740: + movs r0, #0 +_08001742: + pop {r4, r5, r6} + pop {r1} + bx r1 + + thumb_func_start sub_1748 +sub_1748: @ 0x08001748 + push {r4, lr} + lsls r0, r0, #0x18 + lsrs r0, r0, #0x18 + subs r0, #1 + cmp r0, #4 + bhi _080017CE + lsls r0, r0, #2 + ldr r1, _08001760 @ =_08001764 + adds r0, r0, r1 + ldr r0, [r0] + mov pc, r0 + .align 2, 0 +_08001760: .4byte _08001764 +_08001764: @ jump table + .4byte _080017C4 @ case 0 + .4byte _08001778 @ case 1 + .4byte _08001784 @ case 2 + .4byte _080017C4 @ case 3 + .4byte _080017C4 @ case 4 +_08001778: + ldr r0, _08001780 @ =gUnknown_0200281C + ldr r0, [r0] + movs r1, #2 + b _080017C8 + .align 2, 0 +_08001780: .4byte gUnknown_0200281C +_08001784: + ldr r4, _080017C0 @ =gUnknown_02019C00 + ldr r0, [r4] + cmp r0, #0 + bne _0800179A + movs r0, #0 + bl sub_17D8 + movs r1, #4 + bl sub_1668 + adds r2, r0, #0 +_0800179A: + ldr r0, [r4] + cmp r0, #1 + bne _080017AE + movs r0, #1 + bl sub_17D8 + movs r1, #4 + bl sub_1668 + adds r2, r0, #0 +_080017AE: + ldr r0, [r4] + cmp r0, #2 + bne _080017CE + movs r0, #2 + bl sub_17D8 + movs r1, #4 + b _080017C8 + .align 2, 0 +_080017C0: .4byte gUnknown_02019C00 +_080017C4: + movs r0, #1 + movs r1, #1 +_080017C8: + bl sub_1668 + adds r2, r0, #0 +_080017CE: + adds r0, r2, #0 + pop {r4} + pop {r1} + bx r1 + + thumb_func_start sub_17D8 +sub_17D8: @ 0x080017D8 + adds r2, r0, #0 + ldr r0, _080017EC @ =gUnknown_02019BEC + ldr r0, [r0] + cmp r0, #4 + bhi _08001824 + lsls r0, r0, #2 + ldr r1, _080017F0 @ =_080017F4 + adds r0, r0, r1 + ldr r0, [r0] + mov pc, r0 + .align 2, 0 +_080017EC: .4byte gUnknown_02019BEC +_080017F0: .4byte _080017F4 +_080017F4: @ jump table + .4byte _08001808 @ case 0 + .4byte _0800180C @ case 1 + .4byte _08001810 @ case 2 + .4byte _08001814 @ case 3 + .4byte _08001818 @ case 4 +_08001808: + adds r1, r2, #0 + b _08001824 +_0800180C: + lsls r1, r2, #2 + b _08001824 +_08001810: + lsls r1, r2, #4 + b _08001824 +_08001814: + lsls r1, r2, #6 + b _08001824 +_08001818: + lsls r1, r2, #2 + orrs r1, r2 + lsls r0, r2, #4 + orrs r1, r0 + lsls r0, r2, #6 + orrs r1, r0 +_08001824: + adds r0, r1, #0 + bx lr + + thumb_func_start sub_1828 +sub_1828: @ 0x08001828 + push {r4, r5, lr} + ldr r3, _08001868 @ =0x04000208 + movs r4, #0 + strh r4, [r3] + ldr r2, _0800186C @ =0x04000200 + ldrh r1, [r2] + ldr r0, _08001870 @ =0x0000FFBF + ands r0, r1 + strh r0, [r2] + movs r5, #1 + strh r5, [r3] + strh r4, [r3] + subs r2, #0xd8 + ldrh r1, [r2] + ldr r0, _08001874 @ =0x0000FF7F + ands r0, r1 + strh r0, [r2] + strh r5, [r3] + ldr r0, _08001878 @ =0x0400010E + strh r4, [r0] + ldr r1, _0800187C @ =0x0400010C + movs r2, #0x80 + lsls r2, r2, #8 + adds r0, r2, #0 + strh r0, [r1] + ldr r1, _08001880 @ =gUnknown_02019C10 + movs r0, #5 + strb r0, [r1] + pop {r4, r5} + pop {r0} + bx r0 + .align 2, 0 +_08001868: .4byte 0x04000208 +_0800186C: .4byte 0x04000200 +_08001870: .4byte 0x0000FFBF +_08001874: .4byte 0x0000FF7F +_08001878: .4byte 0x0400010E +_0800187C: .4byte 0x0400010C +_08001880: .4byte gUnknown_02019C10 diff --git a/asm/rom_9BC.s b/asm/link.s similarity index 69% rename from asm/rom_9BC.s rename to asm/link.s index b6abe6b..d253f01 100644 --- a/asm/rom_9BC.s +++ b/asm/link.s @@ -4,588 +4,6 @@ .text - thumb_func_start sub_13FC -sub_13FC: @ 0x080013FC - push {r4, r5, r6, r7, lr} - mov r7, sb - mov r6, r8 - push {r6, r7} - sub sp, #0xc - ldr r1, _08001434 @ =gUnknown_02002818 - ldr r0, _08001438 @ =0x04000120 - ldr r0, [r0] - str r0, [r1] - ldr r1, _0800143C @ =0x0400010E - movs r0, #0 - strh r0, [r1] - subs r1, #2 - movs r2, #0x80 - lsls r2, r2, #8 - adds r0, r2, #0 - strh r0, [r1] - ldr r0, _08001440 @ =gUnknown_02019C10 - ldrb r1, [r0] - mov sb, r0 - cmp r1, #5 - bls _0800142A - b _0800161C -_0800142A: - lsls r0, r1, #2 - ldr r1, _08001444 @ =_08001448 - adds r0, r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_08001434: .4byte gUnknown_02002818 -_08001438: .4byte 0x04000120 -_0800143C: .4byte 0x0400010E -_08001440: .4byte gUnknown_02019C10 -_08001444: .4byte _08001448 -_08001448: @ jump table - .4byte _08001460 @ case 0 - .4byte _08001520 @ case 1 - .4byte _08001574 @ case 2 - .4byte _080015C8 @ case 3 - .4byte _0800161C @ case 4 - .4byte _0800161C @ case 5 -_08001460: - ldr r0, _080014B0 @ =0x04000120 - mov r8, r0 - ldr r6, [r0] - ldr r3, _080014B4 @ =gUnknown_02002808 - ldrb r1, [r3] - lsls r2, r1, #4 - adds r0, r6, #0 - lsls r0, r2 - lsrs r0, r0, #0x10 - movs r7, #1 - subs r1, r7, r1 - lsls r1, r1, #4 - lsls r6, r1 - adds r1, r6, #0 - lsrs r6, r1, #0x10 - ldrh r5, [r3, #0xa] - adds r4, r3, #0 - cmp r5, #0 - bne _080014E4 - ldrh r2, [r4, #6] - adds r1, r0, #0 - cmp r1, r2 - bne _080014E2 - ldrh r3, [r4, #2] - cmp r3, #3 - bhi _080014B8 - ldrh r0, [r4, #4] - mvns r0, r0 - lsls r0, r0, #0x10 - lsrs r0, r0, #0x10 - cmp r1, r0 - bne _080014E4 - mvns r0, r2 - lsls r0, r0, #0x10 - lsrs r0, r0, #0x10 - cmp r6, r0 - bne _080014E4 - adds r0, r3, #1 - strh r0, [r4, #2] - b _080014E4 - .align 2, 0 -_080014B0: .4byte 0x04000120 -_080014B4: .4byte gUnknown_02002808 -_080014B8: - strh r6, [r4, #0xa] - ldr r0, _080014D8 @ =0x00008002 - cmp r6, r0 - bne _080014E0 - mov r1, sb - strb r7, [r1] - movs r0, #1 - bl sub_1748 - ldr r1, _080014DC @ =gUnknown_02002814 - str r0, [r1] - mov r2, r8 - str r0, [r2] - strh r5, [r4, #2] - b _08001640 - .align 2, 0 -_080014D8: .4byte 0x00008002 -_080014DC: .4byte gUnknown_02002814 -_080014E0: - strh r5, [r4, #0xa] -_080014E2: - strh r5, [r4, #2] -_080014E4: - ldrh r0, [r4, #2] - cmp r0, #3 - bhi _080014F8 - lsls r0, r0, #1 - ldr r1, _080014F4 @ =gUnknown_0805C748 - adds r0, r0, r1 - ldrh r0, [r0] - b _080014FC - .align 2, 0 -_080014F4: .4byte gUnknown_0805C748 -_080014F8: - movs r0, #0x80 - lsls r0, r0, #8 -_080014FC: - strh r0, [r4, #4] - mvns r0, r6 - strh r0, [r4, #6] - ldr r3, _0800151C @ =0x04000120 - ldrh r2, [r4, #4] - ldrb r1, [r4] - movs r0, #1 - subs r0, r0, r1 - lsls r0, r0, #4 - lsls r2, r0 - ldrh r0, [r4, #6] - lsls r1, r1, #4 - lsls r0, r1 - adds r2, r2, r0 - str r2, [r3] - b _08001640 - .align 2, 0 -_0800151C: .4byte 0x04000120 -_08001520: - ldr r5, _08001544 @ =gUnknown_02019C10 - ldrb r0, [r5] - bl sub_16A0 - cmp r0, #0 - beq _08001550 - ldr r1, _08001548 @ =gUnknown_02002808 - movs r4, #0 - movs r0, #0 - strh r0, [r1, #2] - str r0, [sp] - ldr r2, _0800154C @ =0x05000003 - mov r0, sp - bl CpuSet - strb r4, [r5] - b _08001554 - .align 2, 0 -_08001544: .4byte gUnknown_02019C10 -_08001548: .4byte gUnknown_02002808 -_0800154C: .4byte 0x05000003 -_08001550: - movs r0, #2 - strb r0, [r5] -_08001554: - ldr r0, _0800156C @ =gUnknown_02019BF4 - ldr r0, [r0] - ldr r1, _08001570 @ =gUnknown_02019C10 - mov sb, r1 - cmp r0, #0 - bne _08001564 - movs r0, #4 - strb r0, [r1] -_08001564: - mov r2, sb - ldrb r0, [r2] - b _080015F8 - .align 2, 0 -_0800156C: .4byte gUnknown_02019BF4 -_08001570: .4byte gUnknown_02019C10 -_08001574: - ldr r5, _08001598 @ =gUnknown_02019C10 - ldrb r0, [r5] - bl sub_16A0 - cmp r0, #0 - beq _080015A4 - ldr r1, _0800159C @ =gUnknown_02002808 - movs r4, #0 - movs r0, #0 - strh r0, [r1, #2] - str r0, [sp, #4] - add r0, sp, #4 - ldr r2, _080015A0 @ =0x05000003 - bl CpuSet - strb r4, [r5] - b _080015A8 - .align 2, 0 -_08001598: .4byte gUnknown_02019C10 -_0800159C: .4byte gUnknown_02002808 -_080015A0: .4byte 0x05000003 -_080015A4: - movs r0, #3 - strb r0, [r5] -_080015A8: - ldr r0, _080015C0 @ =gUnknown_02019BF4 - ldr r0, [r0] - ldr r1, _080015C4 @ =gUnknown_02019C10 - mov sb, r1 - cmp r0, #0 - bne _080015B8 - movs r0, #4 - strb r0, [r1] -_080015B8: - mov r2, sb - ldrb r0, [r2] - b _080015F8 - .align 2, 0 -_080015C0: .4byte gUnknown_02019BF4 -_080015C4: .4byte gUnknown_02019C10 -_080015C8: - mov r5, sb - ldrb r0, [r5] - bl sub_16A0 - cmp r0, #0 - beq _080015E8 - ldr r1, _08001608 @ =gUnknown_02002808 - movs r4, #0 - movs r0, #0 - strh r0, [r1, #2] - str r0, [sp, #8] - add r0, sp, #8 - ldr r2, _0800160C @ =0x05000003 - bl CpuSet - strb r4, [r5] -_080015E8: - ldr r0, _08001610 @ =gUnknown_02019BF4 - ldr r0, [r0] - cmp r0, #0 - bne _080015F4 - movs r0, #4 - strb r0, [r5] -_080015F4: - mov r1, sb - ldrb r0, [r1] -_080015F8: - bl sub_1748 - ldr r1, _08001614 @ =gUnknown_02002814 - str r0, [r1] - ldr r1, _08001618 @ =0x04000120 - str r0, [r1] - b _08001640 - .align 2, 0 -_08001608: .4byte gUnknown_02002808 -_0800160C: .4byte 0x05000003 -_08001610: .4byte gUnknown_02019BF4 -_08001614: .4byte gUnknown_02002814 -_08001618: .4byte 0x04000120 -_0800161C: - ldr r3, _08001634 @ =0x04000208 - movs r0, #0 - strh r0, [r3] - ldr r2, _08001638 @ =0x04000200 - ldrh r1, [r2] - ldr r0, _0800163C @ =0x0000FF7F - ands r0, r1 - strh r0, [r2] - movs r0, #1 - strh r0, [r3] - b _08001650 - .align 2, 0 -_08001634: .4byte 0x04000208 -_08001638: .4byte 0x04000200 -_0800163C: .4byte 0x0000FF7F -_08001640: - ldr r2, _08001660 @ =0x04000128 - ldrh r0, [r2] - movs r1, #0x80 - orrs r0, r1 - strh r0, [r2] - ldr r1, _08001664 @ =0x0400010E - movs r0, #0xc1 - strh r0, [r1] -_08001650: - add sp, #0xc - pop {r3, r4} - mov r8, r3 - mov sb, r4 - pop {r4, r5, r6, r7} - pop {r0} - bx r0 - .align 2, 0 -_08001660: .4byte 0x04000128 -_08001664: .4byte 0x0400010E - - thumb_func_start sub_1668 -sub_1668: @ 0x08001668 - push {r4, r5, lr} - ldr r2, _0800169C @ =0x00FFFFFF - ands r2, r0 - lsls r4, r2, #4 - lsls r1, r1, #0x1c - orrs r4, r1 - lsrs r3, r4, #0x1c - movs r2, #6 - movs r5, #0xf -_0800167A: - lsls r0, r2, #2 - adds r1, r4, #0 - lsrs r1, r0 - ands r1, r5 - eors r3, r1 - subs r0, r2, #1 - lsls r0, r0, #0x18 - lsrs r2, r0, #0x18 - cmp r2, #0 - bne _0800167A - movs r0, #0xf - ands r3, r0 - orrs r4, r3 - adds r0, r4, #0 - pop {r4, r5} - pop {r1} - bx r1 - .align 2, 0 -_0800169C: .4byte 0x00FFFFFF - - thumb_func_start sub_16A0 -sub_16A0: @ 0x080016A0 - push {r4, r5, r6, lr} - lsls r0, r0, #0x18 - lsrs r4, r0, #0x18 - ldr r6, _080016C4 @ =gUnknown_02002818 - ldr r0, [r6] - lsrs r5, r0, #0x1c - bl sub_170C - lsls r0, r0, #0x18 - cmp r0, #0 - bne _080016DE - cmp r4, #2 - beq _080016E8 - cmp r4, #2 - bgt _080016C8 - cmp r4, #1 - beq _080016CE - b _080016DE - .align 2, 0 -_080016C4: .4byte gUnknown_02002818 -_080016C8: - cmp r4, #3 - beq _08001700 - b _080016DE -_080016CE: - ldr r1, _080016E4 @ =gUnknown_0200281C - ldr r0, [r6] - lsls r0, r0, #4 - lsrs r0, r0, #8 - ands r0, r4 - str r0, [r1] - cmp r5, #1 - beq _08001704 -_080016DE: - movs r0, #1 - b _08001706 - .align 2, 0 -_080016E4: .4byte gUnknown_0200281C -_080016E8: - cmp r5, #2 - bne _080016DE - ldr r0, _080016FC @ =gUnknown_0200281C - ldr r1, [r6] - lsls r1, r1, #4 - lsrs r1, r1, #8 - ldr r0, [r0] - cmp r0, r1 - beq _08001704 - b _080016DE - .align 2, 0 -_080016FC: .4byte gUnknown_0200281C -_08001700: - cmp r5, #3 - bne _080016DE -_08001704: - movs r0, #0 -_08001706: - pop {r4, r5, r6} - pop {r1} - bx r1 - - thumb_func_start sub_170C -sub_170C: @ 0x0800170C - push {r4, r5, r6, lr} - ldr r0, _0800173C @ =gUnknown_02002818 - ldr r0, [r0] - lsrs r4, r0, #4 - movs r5, #0xf - ands r5, r0 - lsrs r3, r4, #0x18 - movs r0, #6 - movs r6, #0xf -_0800171E: - subs r0, #1 - lsls r2, r0, #2 - adds r1, r4, #0 - lsrs r1, r2 - ands r1, r6 - eors r3, r1 - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #0 - bne _0800171E - cmp r3, r5 - beq _08001740 - movs r0, #1 - b _08001742 - .align 2, 0 -_0800173C: .4byte gUnknown_02002818 -_08001740: - movs r0, #0 -_08001742: - pop {r4, r5, r6} - pop {r1} - bx r1 - - thumb_func_start sub_1748 -sub_1748: @ 0x08001748 - push {r4, lr} - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - subs r0, #1 - cmp r0, #4 - bhi _080017CE - lsls r0, r0, #2 - ldr r1, _08001760 @ =_08001764 - adds r0, r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_08001760: .4byte _08001764 -_08001764: @ jump table - .4byte _080017C4 @ case 0 - .4byte _08001778 @ case 1 - .4byte _08001784 @ case 2 - .4byte _080017C4 @ case 3 - .4byte _080017C4 @ case 4 -_08001778: - ldr r0, _08001780 @ =gUnknown_0200281C - ldr r0, [r0] - movs r1, #2 - b _080017C8 - .align 2, 0 -_08001780: .4byte gUnknown_0200281C -_08001784: - ldr r4, _080017C0 @ =gUnknown_02019C00 - ldr r0, [r4] - cmp r0, #0 - bne _0800179A - movs r0, #0 - bl sub_17D8 - movs r1, #4 - bl sub_1668 - adds r2, r0, #0 -_0800179A: - ldr r0, [r4] - cmp r0, #1 - bne _080017AE - movs r0, #1 - bl sub_17D8 - movs r1, #4 - bl sub_1668 - adds r2, r0, #0 -_080017AE: - ldr r0, [r4] - cmp r0, #2 - bne _080017CE - movs r0, #2 - bl sub_17D8 - movs r1, #4 - b _080017C8 - .align 2, 0 -_080017C0: .4byte gUnknown_02019C00 -_080017C4: - movs r0, #1 - movs r1, #1 -_080017C8: - bl sub_1668 - adds r2, r0, #0 -_080017CE: - adds r0, r2, #0 - pop {r4} - pop {r1} - bx r1 - - thumb_func_start sub_17D8 -sub_17D8: @ 0x080017D8 - adds r2, r0, #0 - ldr r0, _080017EC @ =gUnknown_02019BEC - ldr r0, [r0] - cmp r0, #4 - bhi _08001824 - lsls r0, r0, #2 - ldr r1, _080017F0 @ =_080017F4 - adds r0, r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_080017EC: .4byte gUnknown_02019BEC -_080017F0: .4byte _080017F4 -_080017F4: @ jump table - .4byte _08001808 @ case 0 - .4byte _0800180C @ case 1 - .4byte _08001810 @ case 2 - .4byte _08001814 @ case 3 - .4byte _08001818 @ case 4 -_08001808: - adds r1, r2, #0 - b _08001824 -_0800180C: - lsls r1, r2, #2 - b _08001824 -_08001810: - lsls r1, r2, #4 - b _08001824 -_08001814: - lsls r1, r2, #6 - b _08001824 -_08001818: - lsls r1, r2, #2 - orrs r1, r2 - lsls r0, r2, #4 - orrs r1, r0 - lsls r0, r2, #6 - orrs r1, r0 -_08001824: - adds r0, r1, #0 - bx lr - - thumb_func_start sub_1828 -sub_1828: @ 0x08001828 - push {r4, r5, lr} - ldr r3, _08001868 @ =0x04000208 - movs r4, #0 - strh r4, [r3] - ldr r2, _0800186C @ =0x04000200 - ldrh r1, [r2] - ldr r0, _08001870 @ =0x0000FFBF - ands r0, r1 - strh r0, [r2] - movs r5, #1 - strh r5, [r3] - strh r4, [r3] - subs r2, #0xd8 - ldrh r1, [r2] - ldr r0, _08001874 @ =0x0000FF7F - ands r0, r1 - strh r0, [r2] - strh r5, [r3] - ldr r0, _08001878 @ =0x0400010E - strh r4, [r0] - ldr r1, _0800187C @ =0x0400010C - movs r2, #0x80 - lsls r2, r2, #8 - adds r0, r2, #0 - strh r0, [r1] - ldr r1, _08001880 @ =gUnknown_02019C10 - movs r0, #5 - strb r0, [r1] - pop {r4, r5} - pop {r0} - bx r0 - .align 2, 0 -_08001868: .4byte 0x04000208 -_0800186C: .4byte 0x04000200 -_08001870: .4byte 0x0000FFBF -_08001874: .4byte 0x0000FF7F -_08001878: .4byte 0x0400010E -_0800187C: .4byte 0x0400010C -_08001880: .4byte gUnknown_02019C10 - -@ file boundary? - thumb_func_start sub_1884 sub_1884: @ 0x08001884 push {r4, r5, r6, lr} @@ -2069,104 +1487,3 @@ _080023DC: _08002408: .4byte gUnknown_0202BF20 _0800240C: .4byte 0x00000621 _08002410: .4byte 0x0000EFFF - - thumb_func_start sub_2414 -sub_2414: @ 0x08002414 - push {r4, r5, r6, r7, lr} - mov r7, sl - mov r6, sb - mov r5, r8 - push {r5, r6, r7} - sub sp, #0xc - str r0, [sp] - str r2, [sp, #8] - lsls r1, r1, #0x10 - lsrs r1, r1, #0x10 - str r1, [sp, #4] - ldr r4, _080024CC @ =gOamBuffer - movs r7, #0 - ldr r0, _080024D0 @ =gEmptyOamData - movs r2, #0x80 - lsls r2, r2, #2 - adds r1, r4, #0 - bl CpuSet - movs r1, #0 - ldr r0, [sp, #4] - cmp r7, r0 - bhs _080024B8 -_08002442: - movs r0, #0xb8 - muls r0, r1, r0 - ldr r2, [sp, #8] - adds r6, r2, r0 - ldrh r0, [r6] - adds r2, r1, #1 - mov sl, r2 - cmp r0, #0 - beq _080024AC - lsls r0, r1, #2 - ldr r1, [sp] - adds r0, r0, r1 - ldr r0, [r0] - ldrh r5, [r0] - adds r0, #2 - lsls r1, r7, #3 - ldr r4, _080024CC @ =gOamBuffer - adds r1, r1, r4 - lsls r2, r5, #2 - bl CpuSet - movs r3, #0 - cmp r3, r5 - bhs _080024AC - mov r8, r4 - ldr r2, _080024D4 @ =0x000001FF - mov sb, r2 - movs r0, #0xff - mov ip, r0 -_0800247C: - adds r2, r7, #0 - lsls r0, r2, #3 - mov r1, r8 - adds r4, r0, r1 - lsls r1, r3, #3 - adds r1, #8 - adds r1, r6, r1 - adds r0, r2, #1 - lsls r0, r0, #0x10 - lsrs r7, r0, #0x10 - strh r2, [r1] - ldrh r2, [r4, #2] - mov r0, sb - ands r0, r2 - strh r0, [r1, #2] - ldrh r2, [r4] - mov r0, ip - ands r0, r2 - strh r0, [r1, #4] - adds r0, r3, #1 - lsls r0, r0, #0x10 - lsrs r3, r0, #0x10 - cmp r3, r5 - blo _0800247C -_080024AC: - mov r2, sl - lsls r0, r2, #0x10 - lsrs r1, r0, #0x10 - ldr r0, [sp, #4] - cmp r1, r0 - blo _08002442 -_080024B8: - lsls r0, r7, #0x10 - asrs r0, r0, #0x10 - add sp, #0xc - pop {r3, r4, r5} - mov r8, r3 - mov sb, r4 - mov sl, r5 - pop {r4, r5, r6, r7} - pop {r1} - bx r1 - .align 2, 0 -_080024CC: .4byte gOamBuffer -_080024D0: .4byte gEmptyOamData -_080024D4: .4byte 0x000001FF diff --git a/asm/rom_2414.s b/asm/rom_2414.s new file mode 100644 index 0000000..6546b24 --- /dev/null +++ b/asm/rom_2414.s @@ -0,0 +1,106 @@ + .include "asm/macros.inc" + + .syntax unified + + .text + + thumb_func_start sub_2414 +sub_2414: @ 0x08002414 + push {r4, r5, r6, r7, lr} + mov r7, sl + mov r6, sb + mov r5, r8 + push {r5, r6, r7} + sub sp, #0xc + str r0, [sp] + str r2, [sp, #8] + lsls r1, r1, #0x10 + lsrs r1, r1, #0x10 + str r1, [sp, #4] + ldr r4, _080024CC @ =gOamBuffer + movs r7, #0 + ldr r0, _080024D0 @ =gEmptyOamData + movs r2, #0x80 + lsls r2, r2, #2 + adds r1, r4, #0 + bl CpuSet + movs r1, #0 + ldr r0, [sp, #4] + cmp r7, r0 + bhs _080024B8 +_08002442: + movs r0, #0xb8 + muls r0, r1, r0 + ldr r2, [sp, #8] + adds r6, r2, r0 + ldrh r0, [r6] + adds r2, r1, #1 + mov sl, r2 + cmp r0, #0 + beq _080024AC + lsls r0, r1, #2 + ldr r1, [sp] + adds r0, r0, r1 + ldr r0, [r0] + ldrh r5, [r0] + adds r0, #2 + lsls r1, r7, #3 + ldr r4, _080024CC @ =gOamBuffer + adds r1, r1, r4 + lsls r2, r5, #2 + bl CpuSet + movs r3, #0 + cmp r3, r5 + bhs _080024AC + mov r8, r4 + ldr r2, _080024D4 @ =0x000001FF + mov sb, r2 + movs r0, #0xff + mov ip, r0 +_0800247C: + adds r2, r7, #0 + lsls r0, r2, #3 + mov r1, r8 + adds r4, r0, r1 + lsls r1, r3, #3 + adds r1, #8 + adds r1, r6, r1 + adds r0, r2, #1 + lsls r0, r0, #0x10 + lsrs r7, r0, #0x10 + strh r2, [r1] + ldrh r2, [r4, #2] + mov r0, sb + ands r0, r2 + strh r0, [r1, #2] + ldrh r2, [r4] + mov r0, ip + ands r0, r2 + strh r0, [r1, #4] + adds r0, r3, #1 + lsls r0, r0, #0x10 + lsrs r3, r0, #0x10 + cmp r3, r5 + blo _0800247C +_080024AC: + mov r2, sl + lsls r0, r2, #0x10 + lsrs r1, r0, #0x10 + ldr r0, [sp, #4] + cmp r1, r0 + blo _08002442 +_080024B8: + lsls r0, r7, #0x10 + asrs r0, r0, #0x10 + add sp, #0xc + pop {r3, r4, r5} + mov r8, r3 + mov sb, r4 + mov sl, r5 + pop {r4, r5, r6, r7} + pop {r1} + bx r1 + .align 2, 0 +_080024CC: .4byte gOamBuffer +_080024D0: .4byte gEmptyOamData +_080024D4: .4byte 0x000001FF diff --git a/ld_script.txt b/ld_script.txt index dae6249..2e2752d 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -33,8 +33,10 @@ SECTIONS src/rom_850.o(.text); src/main.o(.text); src/gbplayer.o(.text); - asm/rom_9BC.o(.text); - src/rom_9BC.o(.text); + asm/gbplayer.o(.text); + asm/link.o(.text); + asm/rom_2414.o(.text); + src/rom_2414.o(.text); src/bonus_field_select.o(.text); src/ereader.o(.text); src/pokedex.o(.text); diff --git a/src/rom_9BC.c b/src/rom_2414.c similarity index 100% rename from src/rom_9BC.c rename to src/rom_2414.c From 2629168ec62a54940a8662648cad2b28b7d7e747 Mon Sep 17 00:00:00 2001 From: WhenGryphonsFly <84215159+WhenGryphonsFly@users.noreply.github.com> Date: Sun, 11 Aug 2024 15:35:13 -0500 Subject: [PATCH 2/5] [TEMPLATE] Add link.c and link.h --- include/link.h | 19 +++++++++++++++++++ src/link.c | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 include/link.h create mode 100644 src/link.c diff --git a/include/link.h b/include/link.h new file mode 100644 index 0000000..e6b4250 --- /dev/null +++ b/include/link.h @@ -0,0 +1,19 @@ +// include guard + +// include macros + +// "extern" define macros + +// "extern" enums + +// "extern" struct definitions + +// extern function declarations + +// extern IWRAM variable declarations + +// extern EWRAM variable declarations + +// extern const definitions + +// end include guard diff --git a/src/link.c b/src/link.c new file mode 100644 index 0000000..0453925 --- /dev/null +++ b/src/link.c @@ -0,0 +1,17 @@ +// include macros + +// "static" define macros + +// "static" enums + +// "static" struct definitions + +// static function declarations + +// static IWRAM variable declarations + +// static EWRAM variable declarations + +// static const definitions + +// function definitions From d17810564899a93ba72f859aa1f2c1b0757d8a98 Mon Sep 17 00:00:00 2001 From: WhenGryphonsFly <84215159+WhenGryphonsFly@users.noreply.github.com> Date: Sun, 11 Aug 2024 15:35:39 -0500 Subject: [PATCH 3/5] Decompile link.s --- asm/link.s | 1489 ------------------------------------------- include/functions.h | 2 +- include/variables.h | 2 +- ld_script.txt | 2 +- src/ereader.c | 3 - src/link.c | 783 +++++++++++++++++++++++ sym_ewram.txt | 4 +- 7 files changed, 787 insertions(+), 1498 deletions(-) delete mode 100644 asm/link.s diff --git a/asm/link.s b/asm/link.s deleted file mode 100644 index d253f01..0000000 --- a/asm/link.s +++ /dev/null @@ -1,1489 +0,0 @@ - .include "asm/macros.inc" - - .syntax unified - - .text - - thumb_func_start sub_1884 -sub_1884: @ 0x08001884 - push {r4, r5, r6, lr} - mov r6, r8 - push {r6} - sub sp, #4 - ldr r0, _08001944 @ =gUnknown_02002822 - mov r8, r0 - ldr r5, _08001948 @ =0x04000208 - ldrh r2, [r5] - movs r4, #0 - strh r4, [r5] - ldr r6, _0800194C @ =0x04000200 - ldrh r1, [r6] - ldr r0, _08001950 @ =0x0000FF3F - ands r0, r1 - strh r0, [r6] - strh r2, [r5] - ldr r0, _08001954 @ =0x04000134 - strh r4, [r0] - ldr r2, _08001958 @ =0x04000128 - movs r1, #0x80 - lsls r1, r1, #6 - adds r0, r1, #0 - strh r0, [r2] - ldrh r0, [r2] - ldr r3, _0800195C @ =0x00004003 - adds r1, r3, #0 - orrs r0, r1 - strh r0, [r2] - ldrh r0, [r5] - mov r1, r8 - strh r0, [r1] - ldr r0, _08001960 @ =sub_19CC + 1 - bl SetMainCallback - ldr r0, _08001964 @ =sub_1A78 + 1 - bl SetVBlankIntrFunc - strh r4, [r5] - ldrh r0, [r6] - movs r1, #0x80 - orrs r0, r1 - strh r0, [r6] - mov r3, r8 - ldrh r0, [r3] - strh r0, [r5] - ldr r0, _08001968 @ =0x0400012A - strh r4, [r0] - ldr r2, _0800196C @ =0x04000120 - movs r0, #0 - movs r1, #0 - str r0, [r2] - str r1, [r2, #4] - movs r5, #0 - str r5, [sp] - ldr r1, _08001970 @ =gUnknown_0202BF20 - ldr r2, _08001974 @ =0x05000189 - mov r0, sp - bl CpuSet - ldr r0, _08001978 @ =gUnknown_02002824 - strb r4, [r0] - ldr r0, _0800197C @ =gUnknown_02002825 - strb r4, [r0] - ldr r0, _08001980 @ =gUnknown_02002827 - strb r4, [r0] - ldr r0, _08001984 @ =gUnknown_02019C2C - strb r4, [r0] - ldr r0, _08001988 @ =gUnknown_0202A554 - strb r4, [r0] - ldr r0, _0800198C @ =gUnknown_0202C5E0 - strb r4, [r0] - ldr r0, _08001990 @ =gUnknown_0202ADD0 - str r5, [r0] - ldr r0, _08001994 @ =gUnknown_0201A444 - strh r5, [r0] - ldr r0, _08001998 @ =gUnknown_0202BDF0 - str r5, [r0] - ldr r0, _0800199C @ =gUnknown_0201C1AC - strb r4, [r0] - ldr r0, _080019A0 @ =gUnknown_0202ADDC - strb r4, [r0] - ldr r0, _080019A4 @ =gUnknown_0202BEC8 - strb r4, [r0] - ldr r0, _080019A8 @ =gUnknown_02002820 - strb r4, [r0] - ldr r0, _080019AC @ =gUnknown_02002828 - strh r5, [r0] - ldr r0, _080019B0 @ =gUnknown_0200282A - strh r5, [r0] - add sp, #4 - pop {r3} - mov r8, r3 - pop {r4, r5, r6} - pop {r0} - bx r0 - .align 2, 0 -_08001944: .4byte gUnknown_02002822 -_08001948: .4byte 0x04000208 -_0800194C: .4byte 0x04000200 -_08001950: .4byte 0x0000FF3F -_08001954: .4byte 0x04000134 -_08001958: .4byte 0x04000128 -_0800195C: .4byte 0x00004003 -_08001960: .4byte sub_19CC + 1 -_08001964: .4byte sub_1A78 + 1 -_08001968: .4byte 0x0400012A -_0800196C: .4byte 0x04000120 -_08001970: .4byte gUnknown_0202BF20 -_08001974: .4byte 0x05000189 -_08001978: .4byte gUnknown_02002824 -_0800197C: .4byte gUnknown_02002825 -_08001980: .4byte gUnknown_02002827 -_08001984: .4byte gUnknown_02019C2C -_08001988: .4byte gUnknown_0202A554 -_0800198C: .4byte gUnknown_0202C5E0 -_08001990: .4byte gUnknown_0202ADD0 -_08001994: .4byte gUnknown_0201A444 -_08001998: .4byte gUnknown_0202BDF0 -_0800199C: .4byte gUnknown_0201C1AC -_080019A0: .4byte gUnknown_0202ADDC -_080019A4: .4byte gUnknown_0202BEC8 -_080019A8: .4byte gUnknown_02002820 -_080019AC: .4byte gUnknown_02002828 -_080019B0: .4byte gUnknown_0200282A - - thumb_func_start sub_19B4 -sub_19B4: @ 0x080019B4 - push {lr} - bl sub_24DC - bl sub_250C - bl sub_1884 - bl sub_1AA4 - pop {r0} - bx r0 - - thumb_func_start sub_19CC -sub_19CC: @ 0x080019CC - push {lr} - ldr r0, _08001A6C @ =0x04000004 - ldrh r1, [r0] - movs r0, #8 - ands r0, r1 - cmp r0, #0 - beq _08001A64 - ldr r0, _08001A70 @ =gOamBuffer - movs r1, #0xe0 - lsls r1, r1, #0x13 - movs r2, #0x80 - lsls r2, r2, #2 - bl CpuSet - movs r1, #0x80 - lsls r1, r1, #0x13 - ldr r2, _08001A74 @ =gMain - ldrh r0, [r2, #0x16] - strh r0, [r1] - adds r1, #0x10 - movs r3, #0xba - lsls r3, r3, #2 - adds r0, r2, r3 - ldrh r0, [r0] - strh r0, [r1] - adds r1, #2 - adds r3, #2 - adds r0, r2, r3 - ldrh r0, [r0] - strh r0, [r1] - adds r1, #2 - adds r3, #2 - adds r0, r2, r3 - ldrh r0, [r0] - strh r0, [r1] - adds r1, #2 - adds r3, #2 - adds r0, r2, r3 - ldrh r0, [r0] - strh r0, [r1] - adds r1, #2 - adds r3, #2 - adds r0, r2, r3 - ldrh r0, [r0] - strh r0, [r1] - adds r1, #2 - adds r3, #2 - adds r0, r2, r3 - ldrh r0, [r0] - strh r0, [r1] - adds r1, #2 - adds r3, #2 - adds r0, r2, r3 - ldrh r0, [r0] - strh r0, [r1] - adds r1, #2 - adds r3, #2 - adds r0, r2, r3 - ldrh r0, [r0] - strh r0, [r1] - adds r0, r2, #0 - adds r0, #0x36 - ldrb r0, [r0] - cmp r0, #0 - beq _08001A60 - adds r1, #0x32 - ldrh r0, [r2, #0x38] - strh r0, [r1] - adds r1, #2 - ldrh r0, [r2, #0x3a] - strh r0, [r1] - adds r1, #2 - ldrh r0, [r2, #0x3c] - strh r0, [r1] -_08001A60: - bl VBlankIntrWait -_08001A64: - bl m4aSoundMain - pop {r0} - bx r0 - .align 2, 0 -_08001A6C: .4byte 0x04000004 -_08001A70: .4byte gOamBuffer -_08001A74: .4byte gMain - - thumb_func_start sub_1A78 -sub_1A78: @ 0x08001A78 - push {lr} - bl sub_1EC0 - bl m4aSoundVSync - ldr r3, _08001A98 @ =0x04000208 - movs r0, #0 - strh r0, [r3] - ldr r2, _08001A9C @ =INTR_CHECK - ldrh r0, [r2] - movs r1, #1 - orrs r0, r1 - strh r0, [r2] - strh r1, [r3] - pop {r0} - bx r0 - .align 2, 0 -_08001A98: .4byte 0x04000208 -_08001A9C: .4byte 0x03007FF8 @ INTR_CHECK - - thumb_func_start nullsub_15 -nullsub_15: @ 0x08001AA0 - bx lr - - thumb_func_start sub_1AA4 -sub_1AA4: @ 0x08001AA4 - push {r4, r5, lr} - sub sp, #4 - ldr r0, _08001AE4 @ =gUnknown_02002822 - ldr r2, _08001AE8 @ =0x04000208 - ldrh r5, [r2] - strh r5, [r0] - movs r4, #0 - strh r4, [r2] - ldr r3, _08001AEC @ =0x04000200 - ldrh r1, [r3] - ldr r0, _08001AF0 @ =0x0000FF3F - ands r0, r1 - strh r0, [r3] - strh r5, [r2] - ldr r0, _08001AF4 @ =0x04000128 - strh r4, [r0] - subs r0, #0x1a - strh r4, [r0] - ldr r1, _08001AF8 @ =0x04000202 - movs r0, #0xc0 - strh r0, [r1] - movs r0, #0 - str r0, [sp] - ldr r1, _08001AFC @ =gUnknown_0202BF20 - ldr r2, _08001B00 @ =0x05000189 - mov r0, sp - bl CpuSet - add sp, #4 - pop {r4, r5} - pop {r0} - bx r0 - .align 2, 0 -_08001AE4: .4byte gUnknown_02002822 -_08001AE8: .4byte 0x04000208 -_08001AEC: .4byte 0x04000200 -_08001AF0: .4byte 0x0000FF3F -_08001AF4: .4byte 0x04000128 -_08001AF8: .4byte 0x04000202 -_08001AFC: .4byte gUnknown_0202BF20 -_08001B00: .4byte 0x05000189 - - thumb_func_start sub_1B04 -sub_1B04: @ 0x08001B04 - push {r4, r5, r6, r7, lr} - adds r6, r0, #0 - adds r4, r1, #0 - adds r5, r2, #0 - ldr r0, _08001B20 @ =gUnknown_0202BF20 - ldrb r0, [r0, #1] - cmp r0, #4 - bhi _08001BEE - lsls r0, r0, #2 - ldr r1, _08001B24 @ =_08001B28 - adds r0, r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_08001B20: .4byte gUnknown_0202BF20 -_08001B24: .4byte _08001B28 -_08001B28: @ jump table - .4byte _08001B3C @ case 0 - .4byte _08001B4C @ case 1 - .4byte _08001B5C @ case 2 - .4byte _08001BD0 @ case 3 - .4byte _08001BDA @ case 4 -_08001B3C: - bl sub_1AA4 - ldr r1, _08001B48 @ =gUnknown_0202BF20 - movs r0, #1 - strb r0, [r1, #1] - b _08001BEE - .align 2, 0 -_08001B48: .4byte gUnknown_0202BF20 -_08001B4C: - bl sub_1884 - ldr r1, _08001B58 @ =gUnknown_0202BF20 - movs r0, #2 - strb r0, [r1, #1] - b _08001BEE - .align 2, 0 -_08001B58: .4byte gUnknown_0202BF20 -_08001B5C: - ldrb r1, [r6] - cmp r1, #1 - beq _08001B98 - cmp r1, #2 - beq _08001BBC - bl sub_1C5C - ldr r2, _08001B90 @ =gUnknown_0202C5E0 - movs r0, #0 - ldrsb r0, [r2, r0] - cmp r0, #0 - bne _08001BEE - ldr r1, _08001B94 @ =gUnknown_0202BF20 - ldrb r0, [r1] - cmp r0, #0 - beq _08001BEE - ldrb r0, [r1, #3] - cmp r0, #2 - bne _08001BEE - movs r0, #1 - strb r0, [r1, #0x10] - movs r1, #1 - rsbs r1, r1, #0 - adds r0, r1, #0 - strb r0, [r2] - b _08001BEE - .align 2, 0 -_08001B90: .4byte gUnknown_0202C5E0 -_08001B94: .4byte gUnknown_0202BF20 -_08001B98: - ldr r2, _08001BB4 @ =gUnknown_0202BF20 - ldrb r0, [r2] - cmp r0, #0 - beq _08001BA8 - ldrb r0, [r2, #3] - cmp r0, #2 - bne _08001BA8 - strb r1, [r2, #0x10] -_08001BA8: - ldr r1, _08001BB8 @ =gUnknown_0202C5E0 - movs r2, #1 - rsbs r2, r2, #0 - adds r0, r2, #0 - strb r0, [r1] - b _08001BEE - .align 2, 0 -_08001BB4: .4byte gUnknown_0202BF20 -_08001BB8: .4byte gUnknown_0202C5E0 -_08001BBC: - ldr r0, _08001BC8 @ =gUnknown_0202BF20 - movs r1, #0 - strb r1, [r0, #1] - ldr r0, _08001BCC @ =0x0400012A - strh r1, [r0] - b _08001BEE - .align 2, 0 -_08001BC8: .4byte gUnknown_0202BF20 -_08001BCC: .4byte 0x0400012A -_08001BD0: - bl sub_1C84 - ldr r1, _08001C30 @ =gUnknown_0202BF20 - movs r0, #4 - strb r0, [r1, #1] -_08001BDA: - ldr r0, _08001C30 @ =gUnknown_0202BF20 - ldrb r0, [r0, #0xe] - cmp r0, #0 - bne _08001BE8 - adds r0, r4, #0 - bl sub_1CD4 -_08001BE8: - adds r0, r5, #0 - bl sub_1DB8 -_08001BEE: - movs r0, #0 - strb r0, [r6] - ldr r1, _08001C30 @ =gUnknown_0202BF20 - ldrb r2, [r1, #2] - ldrb r0, [r1, #3] - lsls r0, r0, #2 - orrs r2, r0 - ldrb r0, [r1] - cmp r0, #8 - bne _08001C06 - movs r0, #0x20 - orrs r2, r0 -_08001C06: - ldrb r0, [r1, #0xc] - lsls r3, r0, #8 - ldrb r0, [r1, #0x11] - lsls r4, r0, #9 - ldrb r0, [r1, #0x12] - lsls r5, r0, #0x10 - ldrb r0, [r1, #0x13] - lsls r6, r0, #0x11 - ldrb r0, [r1, #0x14] - lsls r7, r0, #0x12 - ldrb r0, [r1, #0x15] - lsls r0, r0, #0x14 - mov ip, r0 - ldrb r0, [r1, #1] - cmp r0, #4 - bne _08001C34 - movs r0, #0x40 - orrs r0, r3 - orrs r0, r2 - b _08001C38 - .align 2, 0 -_08001C30: .4byte gUnknown_0202BF20 -_08001C34: - adds r0, r2, #0 - orrs r0, r3 -_08001C38: - orrs r0, r4 - orrs r0, r5 - orrs r0, r6 - orrs r0, r7 - mov r2, ip - orrs r0, r2 - adds r2, r0, #0 - ldrb r0, [r1, #2] - cmp r0, #1 - bls _08001C52 - movs r0, #0x80 - lsls r0, r0, #0xf - orrs r2, r0 -_08001C52: - adds r0, r2, #0 - pop {r4, r5, r6, r7} - pop {r1} - bx r1 - - thumb_func_start sub_1C5C -sub_1C5C: @ 0x08001C5C - ldr r0, _08001C74 @ =0x04000128 - ldr r1, [r0] - movs r0, #0xc - ands r1, r0 - ldr r2, _08001C78 @ =gUnknown_0202BF20 - cmp r1, #8 - bne _08001C7C - ldrb r0, [r2, #2] - cmp r0, #0 - bne _08001C7C - strb r1, [r2] - b _08001C80 - .align 2, 0 -_08001C74: .4byte 0x04000128 -_08001C78: .4byte gUnknown_0202BF20 -_08001C7C: - movs r0, #0 - strb r0, [r2] -_08001C80: - bx lr - - thumb_func_start sub_1C84 -sub_1C84: @ 0x08001C84 - push {r4, lr} - ldr r0, _08001CBC @ =gUnknown_0202BF20 - ldrb r0, [r0] - cmp r0, #0 - beq _08001CB4 - ldr r1, _08001CC0 @ =0x0400010C - ldr r2, _08001CC4 @ =0x0000FF3B - adds r0, r2, #0 - strh r0, [r1] - adds r1, #2 - movs r0, #0x41 - strh r0, [r1] - ldr r0, _08001CC8 @ =gUnknown_02002822 - ldr r2, _08001CCC @ =0x04000208 - ldrh r4, [r2] - strh r4, [r0] - movs r0, #0 - strh r0, [r2] - ldr r3, _08001CD0 @ =0x04000200 - ldrh r0, [r3] - movs r1, #0x40 - orrs r0, r1 - strh r0, [r3] - strh r4, [r2] -_08001CB4: - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_08001CBC: .4byte gUnknown_0202BF20 -_08001CC0: .4byte 0x0400010C -_08001CC4: .4byte 0x0000FF3B -_08001CC8: .4byte gUnknown_02002822 -_08001CCC: .4byte 0x04000208 -_08001CD0: .4byte 0x04000200 - - thumb_func_start sub_1CD4 -sub_1CD4: @ 0x08001CD4 - push {r4, r5, r6, r7, lr} - mov r7, sl - mov r6, sb - mov r5, r8 - push {r5, r6, r7} - adds r3, r0, #0 - ldr r2, _08001D48 @ =gUnknown_02002822 - ldr r1, _08001D4C @ =0x04000208 - ldrh r0, [r1] - strh r0, [r2] - movs r0, #0 - strh r0, [r1] - ldr r1, _08001D50 @ =gUnknown_0202BF20 - ldr r4, _08001D54 @ =0x0000021D - adds r0, r1, r4 - ldrb r4, [r0] - mov sl, r2 - adds r6, r1, #0 - cmp r4, #0x1f - bhi _08001D60 - movs r1, #0x87 - lsls r1, r1, #2 - adds r0, r6, r1 - ldrb r0, [r0] - adds r0, r4, r0 - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #0x1f - bls _08001D14 - subs r0, #0x20 - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 -_08001D14: - movs r2, #0 - ldr r4, _08001D58 @ =gUnknown_02002828 - mov r8, r4 - ldr r1, _08001D5C @ =gUnknown_02019C2C - mov sb, r1 - lsls r5, r0, #1 - movs r0, #0x1c - adds r0, r0, r6 - mov ip, r0 - movs r7, #0 -_08001D28: - ldrh r0, [r4] - ldrh r1, [r3] - orrs r0, r1 - strh r0, [r4] - lsls r0, r2, #6 - adds r0, r5, r0 - add r0, ip - strh r1, [r0] - strh r7, [r3] - adds r3, #2 - adds r0, r2, #1 - lsls r0, r0, #0x18 - lsrs r2, r0, #0x18 - cmp r2, #7 - bls _08001D28 - b _08001D70 - .align 2, 0 -_08001D48: .4byte gUnknown_02002822 -_08001D4C: .4byte 0x04000208 -_08001D50: .4byte gUnknown_0202BF20 -_08001D54: .4byte 0x0000021D -_08001D58: .4byte gUnknown_02002828 -_08001D5C: .4byte gUnknown_02019C2C -_08001D60: - ldrb r1, [r6, #0x14] - movs r0, #1 - orrs r0, r1 - strb r0, [r6, #0x14] - ldr r1, _08001DA8 @ =gUnknown_02002828 - mov r8, r1 - ldr r2, _08001DAC @ =gUnknown_02019C2C - mov sb, r2 -_08001D70: - mov r4, r8 - ldrh r0, [r4] - cmp r0, #0 - beq _08001D86 - ldr r1, _08001DB0 @ =0x0000021D - adds r0, r6, r1 - ldrb r1, [r0] - adds r1, #1 - movs r2, #0 - strb r1, [r0] - strh r2, [r4] -_08001D86: - ldr r1, _08001DB4 @ =0x04000208 - mov r2, sl - ldrh r0, [r2] - strh r0, [r1] - ldr r4, _08001DB0 @ =0x0000021D - adds r0, r6, r4 - ldrb r0, [r0] - mov r1, sb - strb r0, [r1] - pop {r3, r4, r5} - mov r8, r3 - mov sb, r4 - mov sl, r5 - pop {r4, r5, r6, r7} - pop {r0} - bx r0 - .align 2, 0 -_08001DA8: .4byte gUnknown_02002828 -_08001DAC: .4byte gUnknown_02019C2C -_08001DB0: .4byte 0x0000021D -_08001DB4: .4byte 0x04000208 - - thumb_func_start sub_1DB8 -sub_1DB8: @ 0x08001DB8 - push {r4, r5, r6, r7, lr} - mov r7, sl - mov r6, sb - mov r5, r8 - push {r5, r6, r7} - mov ip, r0 - ldr r2, _08001E18 @ =gUnknown_02002822 - ldr r1, _08001E1C @ =0x04000208 - ldrh r0, [r1] - strh r0, [r2] - movs r0, #0 - strh r0, [r1] - ldr r1, _08001E20 @ =gUnknown_0202BF20 - ldr r3, _08001E24 @ =0x00000621 - adds r0, r1, r3 - ldrb r0, [r0] - adds r7, r1, #0 - cmp r0, #0 - bne _08001E28 - movs r1, #0 - mov r8, r7 - ldrb r6, [r7, #3] -_08001DE4: - movs r2, #0 - adds r5, r1, #1 - cmp r2, r6 - bhs _08001E08 - lsls r0, r1, #2 - mov r3, ip - adds r1, r0, r3 - movs r4, #0 - mov r0, r8 - ldrb r3, [r0, #3] -_08001DF8: - lsls r0, r2, #1 - adds r0, r0, r1 - strh r4, [r0] - adds r0, r2, #1 - lsls r0, r0, #0x18 - lsrs r2, r0, #0x18 - cmp r2, r3 - blo _08001DF8 -_08001E08: - lsls r0, r5, #0x18 - lsrs r1, r0, #0x18 - cmp r1, #7 - bls _08001DE4 - movs r0, #1 - strb r0, [r7, #0xc] - b _08001E9A - .align 2, 0 -_08001E18: .4byte gUnknown_02002822 -_08001E1C: .4byte 0x04000208 -_08001E20: .4byte gUnknown_0202BF20 -_08001E24: .4byte 0x00000621 -_08001E28: - movs r1, #0 - ldrb r2, [r7, #3] - mov sb, r2 - movs r3, #0x88 - lsls r3, r3, #2 - adds r3, r3, r7 - mov r8, r3 - mov sl, r7 -_08001E38: - movs r2, #0 - adds r5, r1, #1 - cmp r2, sb - bhs _08001E6C - lsls r0, r1, #2 - mov r3, ip - adds r6, r0, r3 - ldr r0, _08001EB0 @ =gUnknown_0202C540 - ldrb r0, [r0] - lsls r0, r0, #1 - lsls r1, r1, #6 - adds r4, r0, r1 - mov r0, sl - ldrb r3, [r0, #3] -_08001E54: - lsls r1, r2, #1 - adds r1, r1, r6 - lsls r0, r2, #9 - adds r0, r4, r0 - add r0, r8 - ldrh r0, [r0] - strh r0, [r1] - adds r0, r2, #1 - lsls r0, r0, #0x18 - lsrs r2, r0, #0x18 - cmp r2, r3 - blo _08001E54 -_08001E6C: - lsls r0, r5, #0x18 - lsrs r1, r0, #0x18 - cmp r1, #7 - bls _08001E38 - adds r2, r7, #0 - ldr r3, _08001EB4 @ =0x00000621 - adds r1, r2, r3 - ldrb r0, [r1] - subs r0, #1 - movs r3, #0 - strb r0, [r1] - movs r0, #0xc4 - lsls r0, r0, #3 - adds r2, r2, r0 - ldrb r0, [r2] - adds r0, #1 - strb r0, [r2] - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #0x1f - bls _08001E98 - strb r3, [r2] -_08001E98: - strb r3, [r7, #0xc] -_08001E9A: - ldr r1, _08001EB8 @ =0x04000208 - ldr r2, _08001EBC @ =gUnknown_02002822 - ldrh r0, [r2] - strh r0, [r1] - pop {r3, r4, r5} - mov r8, r3 - mov sb, r4 - mov sl, r5 - pop {r4, r5, r6, r7} - pop {r0} - bx r0 - .align 2, 0 -_08001EB0: .4byte gUnknown_0202C540 -_08001EB4: .4byte 0x00000621 -_08001EB8: .4byte 0x04000208 -_08001EBC: .4byte gUnknown_02002822 - - thumb_func_start sub_1EC0 -sub_1EC0: @ 0x08001EC0 - push {r4, lr} - ldr r4, _08001F00 @ =gUnknown_0202BF20 - ldrb r0, [r4, #0xe] - cmp r0, #0 - beq _08001EDC - ldr r1, _08001F04 @ =gUnknown_02002826 - ldrb r0, [r1] - subs r0, #1 - strb r0, [r1] - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #0 - bne _08001F42 - strb r0, [r4, #0xe] -_08001EDC: - ldrb r3, [r4] - cmp r3, #0 - beq _08001F16 - ldrb r0, [r4, #1] - cmp r0, #2 - beq _08001F10 - cmp r0, #4 - bne _08001F42 - ldrb r0, [r4, #0xd] - cmp r0, #8 - bhi _08001F08 - ldrb r0, [r4, #0x12] - cmp r0, #0 - bne _08001F10 - movs r0, #1 - strb r0, [r4, #0x15] - b _08001F42 - .align 2, 0 -_08001F00: .4byte gUnknown_0202BF20 -_08001F04: .4byte gUnknown_02002826 -_08001F08: - ldrb r0, [r4, #0x15] - cmp r0, #0 - bne _08001F42 - strb r0, [r4, #0xd] -_08001F10: - bl sub_1FEC - b _08001F42 -_08001F16: - ldrb r2, [r4, #1] - cmp r2, #4 - beq _08001F20 - cmp r2, #2 - bne _08001F42 -_08001F20: - ldr r1, _08001F48 @ =gUnknown_02002824 - ldrb r0, [r1] - adds r0, #1 - strb r0, [r1] - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #6 - bls _08001F42 - cmp r2, #4 - bne _08001F38 - movs r0, #2 - strb r0, [r4, #0x15] -_08001F38: - cmp r2, #2 - bne _08001F42 - strb r3, [r4, #2] - strb r3, [r4, #3] - strb r3, [r4, #0x11] -_08001F42: - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_08001F48: .4byte gUnknown_02002824 - - thumb_func_start sub_1F4C -sub_1F4C: @ 0x08001F4C - push {lr} - bl sub_2308 - bl sub_1FEC - pop {r0} - bx r0 - - thumb_func_start sub_1F5C -sub_1F5C: @ 0x08001F5C - push {r4, lr} - ldr r0, _08001F90 @ =0x04000128 - ldr r1, [r0] - ldr r4, _08001F94 @ =gUnknown_0202BF20 - lsls r0, r1, #0x1a - lsrs r0, r0, #0x1e - strb r0, [r4, #2] - ldrb r0, [r4, #1] - cmp r0, #2 - beq _08001F98 - cmp r0, #4 - bne _08001FB6 - movs r0, #0x40 - ands r1, r0 - cmp r1, #0 - beq _08001F80 - movs r0, #1 - strb r0, [r4, #0x12] -_08001F80: - bl sub_20FC - bl sub_223C - bl sub_2338 - b _08001FB6 - .align 2, 0 -_08001F90: .4byte 0x04000128 -_08001F94: .4byte gUnknown_0202BF20 -_08001F98: - bl sub_1FFC - lsls r0, r0, #0x18 - cmp r0, #0 - beq _08001FB6 - ldrb r0, [r4] - cmp r0, #0 - beq _08001FB2 - movs r0, #3 - strb r0, [r4, #1] - movs r0, #8 - strb r0, [r4, #0xd] - b _08001FB6 -_08001FB2: - movs r0, #4 - strb r0, [r4, #1] -_08001FB6: - ldr r3, _08001FDC @ =gUnknown_0202BF20 - ldrb r0, [r3, #0xd] - adds r0, #1 - movs r2, #0 - strb r0, [r3, #0xd] - ldr r1, _08001FE0 @ =gUnknown_02002824 - strb r2, [r1] - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #8 - bne _08001FD6 - ldr r0, _08001FE4 @ =gUnknown_0202A554 - ldr r2, _08001FE8 @ =0x00000621 - adds r1, r3, r2 - ldrb r1, [r1] - strb r1, [r0] -_08001FD6: - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_08001FDC: .4byte gUnknown_0202BF20 -_08001FE0: .4byte gUnknown_02002824 -_08001FE4: .4byte gUnknown_0202A554 -_08001FE8: .4byte 0x00000621 - - thumb_func_start sub_1FEC -sub_1FEC: @ 0x08001FEC - ldr r0, _08001FF8 @ =0x04000128 - ldrh r1, [r0] - movs r2, #0x80 - orrs r1, r2 - strh r1, [r0] - bx lr - .align 2, 0 -_08001FF8: .4byte 0x04000128 - - thumb_func_start sub_1FFC -sub_1FFC: @ 0x08001FFC - push {r4, r5, r6, r7, lr} - mov r7, sb - mov r6, r8 - push {r6, r7} - movs r7, #0 - ldr r5, _08002018 @ =0x0000FFFF - ldr r0, _0800201C @ =gUnknown_0202BF20 - ldrb r1, [r0, #0x10] - adds r4, r0, #0 - cmp r1, #1 - bne _0800202C - ldr r1, _08002020 @ =0x0400012A - ldr r2, _08002024 @ =0x00008FFF - b _08002030 - .align 2, 0 -_08002018: .4byte 0x0000FFFF -_0800201C: .4byte gUnknown_0202BF20 -_08002020: .4byte 0x0400012A -_08002024: .4byte 0x00008FFF -_08002028: - movs r7, #0 - b _080020B2 -_0800202C: - ldr r1, _08002080 @ =0x0400012A - ldr r2, _08002084 @ =0x0000D13B -_08002030: - adds r0, r2, #0 - strh r0, [r1] - movs r0, #0 - strb r0, [r4, #0x10] - ldr r0, _08002088 @ =0x04000120 - ldr r1, [r0, #4] - ldr r0, [r0] - str r0, [r4, #4] - str r1, [r4, #8] - movs r3, #0 - ldr r0, _0800208C @ =gUnknown_02002827 - mov sb, r0 - adds r6, r4, #0 - ldr r1, _08002090 @ =0x00008FFF - mov r8, r1 - ldr r2, _08002094 @ =0x0000FFFF - mov ip, r2 -_08002052: - lsls r0, r3, #1 - adds r1, r6, #4 - adds r0, r0, r1 - ldrh r2, [r0] - movs r0, #4 - rsbs r0, r0, #0 - ands r0, r2 - ldr r1, _08002098 @ =0x0000D138 - cmp r0, r1 - beq _0800206C - adds r0, r2, #0 - cmp r0, r8 - bne _0800209C -_0800206C: - adds r0, r7, #1 - lsls r0, r0, #0x18 - lsrs r7, r0, #0x18 - adds r0, r2, #0 - cmp r5, r0 - bls _080020A8 - cmp r0, #0 - beq _080020A8 - adds r5, r2, #0 - b _080020A8 - .align 2, 0 -_08002080: .4byte 0x0400012A -_08002084: .4byte 0x0000D13B -_08002088: .4byte 0x04000120 -_0800208C: .4byte gUnknown_02002827 -_08002090: .4byte 0x00008FFF -_08002094: .4byte 0x0000FFFF -_08002098: .4byte 0x0000D138 -_0800209C: - cmp r0, ip - bne _08002028 - ldrb r0, [r6, #2] - cmp r3, r0 - bne _080020A8 - movs r7, #0 -_080020A8: - adds r0, r3, #1 - lsls r0, r0, #0x18 - lsrs r3, r0, #0x18 - cmp r3, #1 - bls _08002052 -_080020B2: - strb r7, [r4, #3] - adds r0, r7, #0 - cmp r0, #2 - bne _080020E2 - mov r1, sb - ldrb r1, [r1] - cmp r0, r1 - bne _080020D4 - ldrh r1, [r4, #4] - ldr r0, _080020D0 @ =0x00008FFF - cmp r1, r0 - bne _080020D4 - movs r0, #1 - b _080020EE - .align 2, 0 -_080020D0: .4byte 0x00008FFF -_080020D4: - ldrb r0, [r4, #3] - cmp r0, #2 - bne _080020E2 - movs r0, #3 - ands r5, r0 - adds r0, r5, #1 - b _080020E4 -_080020E2: - movs r0, #0 -_080020E4: - strb r0, [r4, #0x11] - ldrb r0, [r4, #3] - mov r2, sb - strb r0, [r2] - movs r0, #0 -_080020EE: - pop {r3, r4} - mov r8, r3 - mov sb, r4 - pop {r4, r5, r6, r7} - pop {r1} - bx r1 - - thumb_func_start sub_20FC -sub_20FC: @ 0x080020FC - push {r4, r5, r6, r7, lr} - mov r7, sb - mov r6, r8 - push {r6, r7} - sub sp, #8 - ldr r0, _08002158 @ =0x04000120 - ldr r1, [r0, #4] - ldr r0, [r0] - str r0, [sp] - str r1, [sp, #4] - ldr r0, _0800215C @ =gUnknown_0202BF20 - ldrb r1, [r0, #0x18] - adds r6, r0, #0 - cmp r1, #0 - bne _08002164 - movs r3, #0 - ldr r7, _08002160 @ =gUnknown_02002820 - ldrb r0, [r6, #3] - cmp r3, r0 - bhs _0800214C - adds r5, r6, #0 - ldrh r1, [r6, #0x16] - adds r4, r7, #0 - adds r2, r6, #0 -_0800212C: - lsls r0, r3, #1 - add r0, sp - ldrh r0, [r0] - cmp r1, r0 - beq _08002140 - ldrb r0, [r4] - cmp r0, #0 - beq _08002140 - movs r0, #1 - strb r0, [r5, #0x13] -_08002140: - adds r0, r3, #1 - lsls r0, r0, #0x18 - lsrs r3, r0, #0x18 - ldrb r0, [r2, #3] - cmp r3, r0 - blo _0800212C -_0800214C: - movs r0, #0 - strh r0, [r6, #0x16] - movs r0, #1 - strb r0, [r7] - b _08002224 - .align 2, 0 -_08002158: .4byte 0x04000120 -_0800215C: .4byte gUnknown_0202BF20 -_08002160: .4byte gUnknown_02002820 -_08002164: - movs r2, #0xc4 - lsls r2, r2, #3 - adds r1, r6, r2 - adds r2, #1 - adds r0, r6, r2 - ldrb r2, [r0] - ldrb r1, [r1] - adds r0, r2, r1 - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #0x1f - bls _08002182 - subs r0, #0x20 - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 -_08002182: - cmp r2, #0x1f - bhi _080021F8 - movs r3, #0 - ldrb r1, [r6, #3] - cmp r3, r1 - bhs _08002200 - adds r5, r6, #0 - ldr r7, _080021F0 @ =gUnknown_0200282A - lsls r0, r0, #1 - mov ip, r0 - movs r2, #0x88 - lsls r2, r2, #2 - adds r2, r2, r6 - mov sb, r2 - ldr r0, _080021F4 @ =gUnknown_02002826 - mov r8, r0 -_080021A2: - lsls r0, r3, #1 - mov r1, sp - adds r4, r1, r0 - ldrh r2, [r4] - ldrh r1, [r5, #0x16] - adds r0, r2, r1 - strh r0, [r5, #0x16] - ldrh r0, [r7] - orrs r0, r2 - strh r0, [r7] - ldrb r0, [r5, #0x19] - lsls r0, r0, #6 - add r0, ip - lsls r1, r3, #9 - adds r0, r0, r1 - add r0, sb - strh r2, [r0] - ldrb r0, [r5, #0x18] - cmp r0, #1 - bne _080021E2 - ldrb r0, [r6, #0xe] - cmp r0, #0 - bne _080021E2 - ldrh r0, [r4] - movs r1, #0xf - ands r1, r0 - cmp r1, #1 - bne _080021E2 - strb r1, [r5, #0xe] - movs r0, #5 - mov r2, r8 - strb r0, [r2] -_080021E2: - adds r0, r3, #1 - lsls r0, r0, #0x18 - lsrs r3, r0, #0x18 - ldrb r0, [r5, #3] - cmp r3, r0 - blo _080021A2 - b _08002200 - .align 2, 0 -_080021F0: .4byte gUnknown_0200282A -_080021F4: .4byte gUnknown_02002826 -_080021F8: - ldrb r1, [r6, #0x14] - movs r0, #2 - orrs r0, r1 - strb r0, [r6, #0x14] -_08002200: - ldrb r0, [r6, #0x19] - adds r0, #1 - strb r0, [r6, #0x19] - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #8 - bne _08002224 - ldr r2, _08002234 @ =gUnknown_0200282A - ldrh r0, [r2] - cmp r0, #0 - beq _08002224 - ldr r1, _08002238 @ =0x00000621 - adds r0, r6, r1 - ldrb r1, [r0] - adds r1, #1 - strb r1, [r0] - movs r0, #0 - strh r0, [r2] -_08002224: - add sp, #8 - pop {r3, r4} - mov r8, r3 - mov sb, r4 - pop {r4, r5, r6, r7} - pop {r0} - bx r0 - .align 2, 0 -_08002234: .4byte gUnknown_0200282A -_08002238: .4byte 0x00000621 - - thumb_func_start sub_223C -sub_223C: @ 0x0800223C - ldr r0, _08002278 @ =gUnknown_0202BF20 - ldrb r2, [r0, #0x18] - adds r3, r0, #0 - cmp r2, #8 - bne _0800228E - ldr r1, _0800227C @ =0x0400012A - ldrh r0, [r3, #0x16] - strh r0, [r1] - ldr r1, _08002280 @ =gUnknown_02002825 - ldrb r2, [r1] - cmp r2, #0 - bne _08002288 - ldr r0, _08002284 @ =0x0000021D - adds r1, r3, r0 - ldrb r0, [r1] - subs r0, #1 - strb r0, [r1] - movs r0, #0x87 - lsls r0, r0, #2 - adds r1, r3, r0 - ldrb r0, [r1] - adds r0, #1 - strb r0, [r1] - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #0x1f - bls _080022FE - strb r2, [r1] - b _080022FE - .align 2, 0 -_08002278: .4byte gUnknown_0202BF20 -_0800227C: .4byte 0x0400012A -_08002280: .4byte gUnknown_02002825 -_08002284: .4byte 0x0000021D -_08002288: - movs r0, #0 - strb r0, [r1] - b _080022FE -_0800228E: - ldr r1, _080022B0 @ =gUnknown_02002825 - cmp r2, #0 - bne _080022A2 - ldr r2, _080022B4 @ =0x0000021D - adds r0, r3, r2 - ldrb r0, [r0] - cmp r0, #0 - bne _080022A2 - movs r0, #1 - strb r0, [r1] -_080022A2: - ldrb r0, [r1] - cmp r0, #0 - beq _080022BC - ldr r1, _080022B8 @ =0x0400012A - movs r0, #0 - strh r0, [r1] - b _080022D8 - .align 2, 0 -_080022B0: .4byte gUnknown_02002825 -_080022B4: .4byte 0x0000021D -_080022B8: .4byte 0x0400012A -_080022BC: - ldr r2, _08002300 @ =0x0400012A - movs r1, #0x87 - lsls r1, r1, #2 - adds r0, r3, r1 - ldrb r1, [r0] - lsls r1, r1, #1 - ldrb r0, [r3, #0x18] - lsls r0, r0, #6 - adds r1, r1, r0 - adds r0, r3, #0 - adds r0, #0x1c - adds r1, r1, r0 - ldrh r0, [r1] - strh r0, [r2] -_080022D8: - ldrb r0, [r3, #0xe] - cmp r0, #0 - bne _080022F8 - ldrb r0, [r3, #0x18] - cmp r0, #0 - bne _080022F8 - ldr r2, _08002304 @ =0x00000621 - adds r0, r3, r2 - ldrb r0, [r0] - cmp r0, #3 - bls _080022F8 - ldr r0, _08002300 @ =0x0400012A - ldrh r1, [r0] - movs r2, #1 - orrs r1, r2 - strh r1, [r0] -_080022F8: - ldrb r0, [r3, #0x18] - adds r0, #1 - strb r0, [r3, #0x18] -_080022FE: - bx lr - .align 2, 0 -_08002300: .4byte 0x0400012A -_08002304: .4byte 0x00000621 - - thumb_func_start sub_2308 -sub_2308: @ 0x08002308 - ldr r0, _08002324 @ =gUnknown_0202BF20 - ldrb r0, [r0] - cmp r0, #0 - beq _08002322 - ldr r2, _08002328 @ =0x0400010E - ldrh r1, [r2] - ldr r0, _0800232C @ =0x0000FF7F - ands r0, r1 - strh r0, [r2] - ldr r1, _08002330 @ =0x0400010C - ldr r2, _08002334 @ =0x0000FF3B - adds r0, r2, #0 - strh r0, [r1] -_08002322: - bx lr - .align 2, 0 -_08002324: .4byte gUnknown_0202BF20 -_08002328: .4byte 0x0400010E -_0800232C: .4byte 0x0000FF7F -_08002330: .4byte 0x0400010C -_08002334: .4byte 0x0000FF3B - - thumb_func_start sub_2338 -sub_2338: @ 0x08002338 - ldr r1, _08002348 @ =gUnknown_0202BF20 - ldrb r0, [r1, #0x19] - cmp r0, #8 - bne _0800234C - movs r0, #0 - strb r0, [r1, #0x18] - strb r0, [r1, #0x19] - b _0800235C - .align 2, 0 -_08002348: .4byte gUnknown_0202BF20 -_0800234C: - ldrb r0, [r1] - cmp r0, #0 - beq _0800235C - ldr r0, _08002360 @ =0x0400010E - ldrh r1, [r0] - movs r2, #0x80 - orrs r1, r2 - strh r1, [r0] -_0800235C: - bx lr - .align 2, 0 -_08002360: .4byte 0x0400010E - - thumb_func_start sub_2364 -sub_2364: @ 0x08002364 - push {r4, r5, lr} - ldr r1, _080023A8 @ =gUnknown_0202BF20 - ldr r2, _080023AC @ =0x0000021D - adds r0, r1, r2 - movs r2, #0 - strb r2, [r0] - movs r3, #0x87 - lsls r3, r3, #2 - adds r0, r1, r3 - strb r2, [r0] - movs r0, #0 - adds r5, r1, #0 - adds r5, #0x1c - ldr r4, _080023B0 @ =0x0000EFFF -_08002380: - movs r2, #0 - adds r1, r0, #1 - lsls r3, r0, #6 -_08002386: - lsls r0, r2, #1 - adds r0, r0, r3 - adds r0, r0, r5 - strh r4, [r0] - adds r0, r2, #1 - lsls r0, r0, #0x18 - lsrs r2, r0, #0x18 - cmp r2, #0x1f - bls _08002386 - lsls r0, r1, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #7 - bls _08002380 - pop {r4, r5} - pop {r0} - bx r0 - .align 2, 0 -_080023A8: .4byte gUnknown_0202BF20 -_080023AC: .4byte 0x0000021D -_080023B0: .4byte 0x0000EFFF - - thumb_func_start sub_23B4 -sub_23B4: @ 0x080023B4 - push {r4, r5, r6, r7, lr} - ldr r1, _08002408 @ =gUnknown_0202BF20 - ldr r2, _0800240C @ =0x00000621 - adds r0, r1, r2 - movs r2, #0 - strb r2, [r0] - movs r3, #0xc4 - lsls r3, r3, #3 - adds r0, r1, r3 - strb r2, [r0] - movs r0, #0x88 - lsls r0, r0, #2 - adds r7, r1, r0 - ldr r6, _08002410 @ =0x0000EFFF -_080023D0: - movs r0, #0 - adds r5, r2, #1 - lsls r4, r2, #9 -_080023D6: - movs r2, #0 - adds r1, r0, #1 - lsls r3, r0, #6 -_080023DC: - lsls r0, r2, #1 - adds r0, r0, r3 - adds r0, r0, r4 - adds r0, r0, r7 - strh r6, [r0] - adds r0, r2, #1 - lsls r0, r0, #0x18 - lsrs r2, r0, #0x18 - cmp r2, #0x1f - bls _080023DC - lsls r0, r1, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #7 - bls _080023D6 - lsls r0, r5, #0x18 - lsrs r2, r0, #0x18 - cmp r2, #1 - bls _080023D0 - pop {r4, r5, r6, r7} - pop {r0} - bx r0 - .align 2, 0 -_08002408: .4byte gUnknown_0202BF20 -_0800240C: .4byte 0x00000621 -_08002410: .4byte 0x0000EFFF diff --git a/include/functions.h b/include/functions.h index 4f13dab..c02c119 100644 --- a/include/functions.h +++ b/include/functions.h @@ -794,7 +794,7 @@ extern void sub_19B4(void); //extern ? sub_1A78(); //extern ? nullsub_15(); extern void sub_1AA4(void); -extern s32 sub_1B04(u32 *, s16[], u16[][]); +extern s32 sub_1B04(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[]); //extern ? sub_1C5C(); //extern ? sub_1C84(); //extern ? sub_1CD4(); diff --git a/include/variables.h b/include/variables.h index c8033a5..c79a495 100644 --- a/include/variables.h +++ b/include/variables.h @@ -263,7 +263,7 @@ extern struct PokemonSpecies gUnknown_086A3700[]; extern const struct SpriteSet * const gUnknown_086A54D8[13]; extern u32 gUnknown_0202ADD0; -extern u32 gUnknown_0202BEC8; +extern u8 gUnknown_0202BEC8; extern s16 gUnknown_0202C5F0[]; extern u16 gUnknown_0201A4D0[][2]; extern u32 gUnknown_0202BDF0; diff --git a/ld_script.txt b/ld_script.txt index 2e2752d..f254b30 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -34,7 +34,7 @@ SECTIONS src/main.o(.text); src/gbplayer.o(.text); asm/gbplayer.o(.text); - asm/link.o(.text); + src/link.o(.text); asm/rom_2414.o(.text); src/rom_2414.o(.text); src/bonus_field_select.o(.text); diff --git a/src/ereader.c b/src/ereader.c index 781e638..47d4c37 100644 --- a/src/ereader.c +++ b/src/ereader.c @@ -24,7 +24,6 @@ extern u8 gUnknown_0200282D; extern s8 gUnknown_0202BEF8; extern u8 gUnknown_0201B124; extern u32 gUnknown_0202ADD0; -extern u32 gUnknown_0202BEC8; extern s16 gUnknown_0202C5F0[]; extern u16 gUnknown_0201A4D0[][2]; extern u32 gUnknown_0202BDF0; @@ -48,8 +47,6 @@ extern u8 gUnknown_080897E0[]; extern u8 gUnknown_0807FD00[]; extern s16 gUnknown_086A550C[]; -s32 sub_1B04(u32 *, s16[], u16[][]); - void EReaderMain(void) { gEReaderStateFuncs[gMain.subState](); diff --git a/src/link.c b/src/link.c index 0453925..9c2fb95 100644 --- a/src/link.c +++ b/src/link.c @@ -1,4 +1,7 @@ // include macros +#include "global.h" +#include "m4a.h" +#include "main.h" // "static" define macros @@ -15,3 +18,783 @@ // static const definitions // function definitions + +// TODO Unsorted + +#define MAX_LINK_PLAYERS 2 + +void sub_1884(void); +void sub_19B4(void); +void sub_19CC(void); +void sub_1A78(void); +void nullsub_15(void); +void sub_1AA4(void); +s32 sub_1B04(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[MAX_LINK_PLAYERS]); +void sub_1C5C(void); + +void sub_1C84(void); +void sub_1CD4(u16 *); +void sub_1DB8(u16 (*recvCmds)[MAX_LINK_PLAYERS]); +void sub_1EC0(void); +void sub_1F4C(void); +void sub_1F5C(void); +void sub_1FEC(void); + +bool8 sub_1FFC(void); +void sub_20FC(void); +void sub_223C(void); +void sub_2308(void); +void sub_2338(void); +void sub_2364(void); +void sub_23B4(void); + +#define CMD_LENGTH 8 +#define QUEUE_CAPACITY 0x20 + + +void sub_1DB8(u16 (*recvCmds)[MAX_LINK_PLAYERS]); + +#define LINKCMD_NONE 0xEFFF + +#define LINK_SLAVE 0 +#define LINK_MASTER 8 + +// TODO quite different from pokeemerald, redo constants +#define LINK_STAT_LOCAL_ID 0x00000003 +#define LINK_STAT_PLAYER_COUNT 0x0000001C +#define LINK_STAT_PLAYER_COUNT_SHIFT 2 +#define LINK_STAT_MASTER 0x00000020 +#define LINK_STAT_MASTER_SHIFT 5 +#define LINK_STAT_CONN_ESTABLISHED 0x00000040 +#define LINK_STAT_CONN_ESTABLISHED_SHIFT 6 +#define LINK_STAT_RECEIVED_NOTHING 0x00000100 +#define LINK_STAT_RECEIVED_NOTHING_SHIFT 8 +#define LINK_STAT_UNK_FLAG_9 0x00000200 +#define LINK_STAT_UNK_FLAG_9_SHIFT 9 +#define LINK_STAT_ERRORS 0x0007F000 +#define LINK_STAT_ERRORS_SHIFT 12 + +#define LINK_STAT_ERROR_HARDWARE 0x00001000 +#define LINK_STAT_ERROR_HARDWARE_SHIFT 12 +#define LINK_STAT_ERROR_CHECKSUM 0x00002000 +#define LINK_STAT_ERROR_CHECKSUM_SHIFT 13 +#define LINK_STAT_ERROR_QUEUE_FULL 0x00004000 +#define LINK_STAT_ERROR_QUEUE_FULL_SHIFT 14 +#define LINK_STAT_ERROR_LAG_MASTER 0x00010000 +#define LINK_STAT_ERROR_LAG_MASTER_SHIFT 16 +#define LINK_STAT_ERROR_INVALID_ID 0x00020000 +#define LINK_STAT_ERROR_INVALID_ID_SHIFT 17 +#define LINK_STAT_ERROR_LAG_SLAVE 0x00040000 +#define LINK_STAT_ERROR_LAG_SLAVE_SHIFT 18 + +enum +{ + QUEUE_FULL_NONE, + QUEUE_FULL_SEND, + QUEUE_FULL_RECV, +}; + +enum +{ + LINK_STATE_START0, + LINK_STATE_START1, + LINK_STATE_HANDSHAKE, + LINK_STATE_INIT_TIMER, + LINK_STATE_CONN_ESTABLISHED, +}; + +enum +{ + LAG_NONE, + LAG_MASTER, + LAG_SLAVE, +}; + +struct SendQueue +{ + u16 data[CMD_LENGTH][QUEUE_CAPACITY]; + u8 pos; + u8 count; +}; + +struct RecvQueue +{ + u16 data[MAX_LINK_PLAYERS][CMD_LENGTH][QUEUE_CAPACITY]; + u8 pos; + u8 count; // 0x621 +}; + +struct Link { // struct Link + u8 isMaster; // 0x0 + u8 state; // 0x1 + u8 localId; // 0x2 + u8 playerCount; // 0x3 + u16 handshakeBuffer[4]; // 0x4 + bool8 receivedNothing; // 0xC + u8 serialIntrCounter; // 0xD + u8 unkE; // 0xE + u8 fillerF; // 0xF + bool8 handshakeAsMaster; // 0x10 + u8 unk11; + u8 hardwareError; + u8 unk13; + u8 queueFull; // 0x14 + u8 unk15; + u16 checksum; // 0x16 + u8 sendCmdIndex; // 0x18 + u8 recvCmdIndex; // 0x19 + u8 filler1A[0x1C-0x1A]; // 0x1A + + struct SendQueue sendQueue; + struct RecvQueue recvQueue; +}; +extern struct Link gUnknown_0202BF20; // gLink + +extern u8 gUnknown_02002820; // sChecksumAvailable +extern u16 gUnknown_02002822; // gLinkSavedIme +extern u8 gUnknown_02002824; // sNumVBlanksWithoutSerialIntr +extern u8 gUnknown_02002826; +extern u16 gUnknown_02002828; // sSendNonzeroCheck +extern u16 gUnknown_0200282A; +extern u8 gUnknown_02019C2C; // gLastSendQueueCount +extern s8 gUnknown_0202C5E0; +extern u8 gUnknown_02002825; // sSendBufferEmpty +extern u8 gUnknown_02002827; // sHandshakePlayerCount ? +extern u8 gUnknown_0202A554; // ??? +extern u8 gUnknown_0202BEC8; + + +#define MASTER_HANDSHAKE 0x8FFF +#define SLAVE_HANDSHAKE 0xD13B +//#define EREADER_HANDSHAKE 0xCCD0 + +#define SIO_MULTI_CNT ((struct SioMultiCnt *)REG_ADDR_SIOCNT) + +#define EnableInterrupts(interrupts) \ +{ \ + gUnknown_02002822 = REG_IME; \ + REG_IME = 0; \ + REG_IE |= (interrupts); \ + REG_IME = gUnknown_02002822; \ +} + +#define DisableInterrupts(interrupts) \ +{ \ + gUnknown_02002822 = REG_IME; \ + REG_IME = 0; \ + REG_IE &= ~(interrupts); \ + REG_IME = gUnknown_02002822; \ +} + +void sub_1884(void) // EnableSerial +{ + DisableInterrupts(INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL); + REG_RCNT = 0; + REG_SIOCNT = SIO_MULTI_MODE; + REG_SIOCNT |= SIO_115200_BPS | SIO_INTR_ENABLE; + + gUnknown_02002822 = REG_IME; + SetMainCallback(sub_19CC+1); + SetVBlankIntrFunc(sub_1A78+1); + REG_IME = 0; + REG_IE |= INTR_FLAG_SERIAL; + REG_IME = gUnknown_02002822; + + REG_SIOMLT_SEND = 0; // TODO correct register name? + *((u64 *) REG_ADDR_SIOMULTI0) = 0; + CpuFill32(0, &gUnknown_0202BF20, sizeof(gUnknown_0202BF20)); + + gUnknown_02002824 = 0; + gUnknown_02002825 = 0; + gUnknown_02002827 = 0; + gUnknown_02019C2C = 0; + gUnknown_0202A554 = 0; + gUnknown_0202C5E0 = 0; + gUnknown_0202ADD0 = 0; + gUnknown_0201A444 = 0; + gUnknown_0202BDF0 = 0; + gUnknown_0201C1AC = 0; + gUnknown_0202ADDC = 0; + gUnknown_0202BEC8 = 0; + gUnknown_02002820 = 0; + gUnknown_02002828 = 0; + gUnknown_0200282A = 0; +} + +void sub_19B4(void) // TODO +{ + sub_24DC(); + sub_250C(); + sub_1884(); + sub_1AA4(); +} + +void sub_19CC(void) // TODO +{ + if ((REG_DISPSTAT & 0x8) != 0) + { + CpuSet(gOamBuffer, (void *) 0x7000000, 0x200); + REG_DISPCNT = gMain.unk16; + + REG_BG0HOFS = gMain.unk2E8[0].unk0; + REG_BG0VOFS = gMain.unk2E8[0].unk2; + REG_BG1HOFS = gMain.unk2E8[1].unk0; + REG_BG1VOFS = gMain.unk2E8[1].unk2; + REG_BG2HOFS = gMain.unk2E8[2].unk0; + REG_BG2VOFS = gMain.unk2E8[2].unk2; + REG_BG3HOFS = gMain.unk2E8[3].unk0; + REG_BG3VOFS = gMain.unk2E8[3].unk2; + + if (gMain.unk36) + { + REG_BLDCNT = gMain.blendControl; + REG_BLDALPHA = gMain.blendAlpha; + REG_BLDY = gMain.blendBrightness; + } + + VBlankIntrWait(); + } + + m4aSoundMain(); +} + +void sub_1A78(void) // VBlankIntr +{ + sub_1EC0(); + m4aSoundVSync(); + REG_IME = 0; + INTR_CHECK |= INTR_FLAG_VBLANK; + REG_IME = 1; +} + +void nullsub_15(void) +{ +} + +void sub_1AA4(void) // TODO DisableSerial? +{ + DisableInterrupts(INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL); + + REG_SIOCNT = 0; + REG_TM3CNT_H = 0; + REG_IF = 0xC0; + + CpuFill32(0, &gUnknown_0202BF20, sizeof(gUnknown_0202BF20)); // TODO off by 4 error? +} + +s32 sub_1B04(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[MAX_LINK_PLAYERS]) // LinkMain1 +{ + u32 retVal; + + switch (gUnknown_0202BF20.state) + { + case LINK_STATE_START0: + sub_1AA4(); + gUnknown_0202BF20.state = 1; + break; + case LINK_STATE_START1: + sub_1884(); + gUnknown_0202BF20.state = 2; + break; + case LINK_STATE_HANDSHAKE: + switch (*shouldAdvanceLinkState) + { + default: + sub_1C5C(); + if (gUnknown_0202C5E0 == 0 && gUnknown_0202BF20.isMaster && gUnknown_0202BF20.playerCount == 2) + { + gUnknown_0202BF20.handshakeAsMaster = TRUE; + gUnknown_0202C5E0 = -1; + } + break; + case 1: + if (gUnknown_0202BF20.isMaster != LINK_SLAVE && gUnknown_0202BF20.playerCount == 2) + gUnknown_0202BF20.handshakeAsMaster = TRUE; + gUnknown_0202C5E0 = -1; + break; + case 2: + gUnknown_0202BF20.state = LINK_STATE_START0; + REG_SIOMLT_SEND = 0; + break; + } + break; + case LINK_STATE_INIT_TIMER: + sub_1C84(); + gUnknown_0202BF20.state = LINK_STATE_CONN_ESTABLISHED; + // fallthrough + case LINK_STATE_CONN_ESTABLISHED: + if (gUnknown_0202BF20.unkE == 0) + { + sub_1CD4(sendCmd); + } + sub_1DB8(recvCmds); + break; + } + *shouldAdvanceLinkState = 0; + retVal = gUnknown_0202BF20.localId; + retVal |= (gUnknown_0202BF20.playerCount << LINK_STAT_PLAYER_COUNT_SHIFT); + if (gUnknown_0202BF20.isMaster == LINK_MASTER) + { + retVal |= LINK_STAT_MASTER; + } + + { + u32 receivedNothing = gUnknown_0202BF20.receivedNothing << 8; + u32 unk11 = gUnknown_0202BF20.unk11 << 9; + u32 hardwareError = gUnknown_0202BF20.hardwareError << 0x10; + u32 unk13 = gUnknown_0202BF20.unk13 << 0x11; + u32 queueFull = gUnknown_0202BF20.queueFull << 0x12; + u32 unk15 = gUnknown_0202BF20.unk15 << 0x14; + u32 val; + + if (gUnknown_0202BF20.state == LINK_STATE_CONN_ESTABLISHED) + { + val = LINK_STAT_CONN_ESTABLISHED; + val |= receivedNothing; + val |= retVal; + val |= unk11; + val |= hardwareError; + val |= unk13; + val |= queueFull; + val |= unk15; + } + else + { + val = retVal; + val |= receivedNothing; + val |= unk11; + val |= hardwareError; + val |= unk13; + val |= queueFull; + val |= unk15; + } + + retVal = val; + } + + if (gUnknown_0202BF20.localId >= MAX_LINK_PLAYERS) + retVal |= 0x80 << 0xF; + + + return retVal; +} + +void sub_1C5C(void) // CheckMasterOrSlave +{ + u32 terminals; + terminals = *(vu32 *)REG_ADDR_SIOCNT & (SIO_MULTI_SD | SIO_MULTI_SI); + + if (terminals == SIO_MULTI_SD && gUnknown_0202BF20.localId == 0) + { + gUnknown_0202BF20.isMaster = 8; + } + else + { + gUnknown_0202BF20.isMaster = 0; + } +} + +void sub_1C84(void) // InitTimer +{ + if (gUnknown_0202BF20.isMaster) + { + REG_TM3CNT_L = -197; + REG_TM3CNT_H = TIMER_64CLK | TIMER_INTR_ENABLE; + + EnableInterrupts(INTR_FLAG_TIMER3); + } +} + +void sub_1CD4(u16 *sendCmd) // EnqueueSendCmd +{ + u8 i; + u8 offset; + + gUnknown_02002822 = REG_IME; + REG_IME = 0; + + if (gUnknown_0202BF20.sendQueue.count < QUEUE_CAPACITY) + { + offset = gUnknown_0202BF20.sendQueue.pos + gUnknown_0202BF20.sendQueue.count; + if (offset >= QUEUE_CAPACITY) + { + offset -= QUEUE_CAPACITY; + } + for (i = 0; i < CMD_LENGTH; i++) + { + gUnknown_02002828 |= *sendCmd; + gUnknown_0202BF20.sendQueue.data[i][offset] = *sendCmd; + *sendCmd = 0; + sendCmd++; + } + } + else + { + gUnknown_0202BF20.queueFull |= QUEUE_FULL_SEND; + } + + if (gUnknown_02002828) + { + gUnknown_0202BF20.sendQueue.count++; + gUnknown_02002828 = 0; + } + + REG_IME = gUnknown_02002822; + gUnknown_02019C2C = gUnknown_0202BF20.sendQueue.count; +} + +void sub_1DB8(u16 (*recvCmds)[MAX_LINK_PLAYERS]) // DequeueRecvCmds +{ + u8 i; + u8 j; + + gUnknown_02002822 = REG_IME; + REG_IME = 0; + + if (gUnknown_0202BF20.recvQueue.count == 0) + { + for (i = 0; i < CMD_LENGTH; i++) + { + for (j = 0; j < gUnknown_0202BF20.playerCount; j++) + { + recvCmds[i][j] = 0; + } + } + + gUnknown_0202BF20.receivedNothing = TRUE; + } + else + { + for (i = 0; i < CMD_LENGTH; i++) + { + for (j = 0; j < gUnknown_0202BF20.playerCount; j++) + { + recvCmds[i][j] = gUnknown_0202BF20.recvQueue.data[j][i][gUnknown_0202BF20.recvQueue.pos]; + } + } + gUnknown_0202BF20.recvQueue.count--; + gUnknown_0202BF20.recvQueue.pos++; + if (gUnknown_0202BF20.recvQueue.pos >= QUEUE_CAPACITY) + { + gUnknown_0202BF20.recvQueue.pos = 0; + } + gUnknown_0202BF20.receivedNothing = FALSE; + } + + REG_IME = gUnknown_02002822; +} + +void sub_1EC0(void) // LinkVSync +{ + if (gUnknown_0202BF20.unkE) + { + if (--gUnknown_02002826 != 0) + { + return; + } + gUnknown_0202BF20.unkE = 0; + } + + if (gUnknown_0202BF20.isMaster) + { + switch (gUnknown_0202BF20.state) + { + case LINK_STATE_CONN_ESTABLISHED: + if (gUnknown_0202BF20.serialIntrCounter < 9) + { + if (!gUnknown_0202BF20.hardwareError) + { + gUnknown_0202BF20.unk15 = LAG_MASTER; + } + else + { + sub_1FEC(); + } + } + else if (gUnknown_0202BF20.unk15 == LAG_NONE) + { + gUnknown_0202BF20.serialIntrCounter = 0; + sub_1FEC(); + } + break; + case LINK_STATE_HANDSHAKE: + sub_1FEC(); + break; + } + } + else if (gUnknown_0202BF20.state == LINK_STATE_CONN_ESTABLISHED || gUnknown_0202BF20.state == LINK_STATE_HANDSHAKE) + { + if (++gUnknown_02002824 > 6) + { + if (gUnknown_0202BF20.state == LINK_STATE_CONN_ESTABLISHED) + { + gUnknown_0202BF20.unk15 = LAG_SLAVE; + } + if (gUnknown_0202BF20.state == LINK_STATE_HANDSHAKE) + { + gUnknown_0202BF20.localId = 0; + gUnknown_0202BF20.playerCount = 0; + gUnknown_0202BF20.unk11 = FALSE; + } + } + } +} + +void sub_1F4C(void) // Timer3Init +{ + sub_2308(); + sub_1FEC(); +} + +void sub_1F5C(void) // SerialCB +{ + u32 temp; + temp = *((u32*) REG_ADDR_SIOCNT); + gUnknown_0202BF20.localId = (temp << 0x1A) >> 0x1E; // TODO fakenatch? + switch (gUnknown_0202BF20.state) + { + case LINK_STATE_CONN_ESTABLISHED: + if (temp & 0x40) + { + gUnknown_0202BF20.hardwareError = 1; + } + sub_20FC(); + sub_223C(); + sub_2338(); + break; + case LINK_STATE_HANDSHAKE: + if (sub_1FFC()) + { + if (gUnknown_0202BF20.isMaster) + { + gUnknown_0202BF20.state = LINK_STATE_INIT_TIMER; + gUnknown_0202BF20.serialIntrCounter = 8; + } + else + { + gUnknown_0202BF20.state = LINK_STATE_CONN_ESTABLISHED; + } + } + break; + } + gUnknown_0202BF20.serialIntrCounter++; + gUnknown_02002824 = 0; + if (gUnknown_0202BF20.serialIntrCounter == 8) + { + gUnknown_0202A554 = gUnknown_0202BF20.recvQueue.count; + } +} + +void sub_1FEC(void) // StartTransfer +{ + REG_SIOCNT |= SIO_START; +} + +bool8 sub_1FFC(void) // DoHandshake +{ + u8 i; + u8 playerCount; + u16 minRecv; + + playerCount = 0; + minRecv = 0xFFFF; + if (gUnknown_0202BF20.handshakeAsMaster == TRUE) + { + REG_SIOMLT_SEND = MASTER_HANDSHAKE; + } + else + { + REG_SIOMLT_SEND = SLAVE_HANDSHAKE; + } + gUnknown_0202BF20.handshakeAsMaster = FALSE; + *(u64 *)gUnknown_0202BF20.handshakeBuffer = REG_SIOMLT_RECV; + //REG_SIOMLT_RECV = 0; + + for (i = 0; i < MAX_LINK_PLAYERS; i++) + { + if ((gUnknown_0202BF20.handshakeBuffer[i] & ~0x3) == (SLAVE_HANDSHAKE & ~3) || gUnknown_0202BF20.handshakeBuffer[i] == MASTER_HANDSHAKE) + { + playerCount++; + if (minRecv > gUnknown_0202BF20.handshakeBuffer[i] && gUnknown_0202BF20.handshakeBuffer[i] != 0) + minRecv = gUnknown_0202BF20.handshakeBuffer[i]; + } + else + { + if (gUnknown_0202BF20.handshakeBuffer[i] != 0xFFFF) + { + playerCount = 0; + break; + } + if (i == gUnknown_0202BF20.localId) // TODO check order + { + playerCount = 0; + } + } + } + gUnknown_0202BF20.playerCount = playerCount; + if (gUnknown_0202BF20.playerCount == 2 && gUnknown_0202BF20.playerCount == gUnknown_02002827 && gUnknown_0202BF20.handshakeBuffer[0] == MASTER_HANDSHAKE) + { + return TRUE; + } + if (gUnknown_0202BF20.playerCount == 2) // ??? + { + gUnknown_0202BF20.unk11 = (minRecv & 3) + 1; + } + else + { + gUnknown_0202BF20.unk11 = 0; + } + gUnknown_02002827 = gUnknown_0202BF20.playerCount; + return FALSE; +} + +void sub_20FC(void) // DoRecv +{ + u16 recv[4]; + u8 i; + u8 index; + + *(u64 *)recv = REG_SIOMLT_RECV; + if (gUnknown_0202BF20.sendCmdIndex == 0) + { + for (i = 0; i < gUnknown_0202BF20.playerCount; i++) + { + if (gUnknown_0202BF20.checksum != recv[i] && gUnknown_02002820) + { + gUnknown_0202BF20.unk13 = TRUE; + } + } + gUnknown_0202BF20.checksum = 0; + gUnknown_02002820 = TRUE; + } + else + { + index = gUnknown_0202BF20.recvQueue.pos + gUnknown_0202BF20.recvQueue.count; + if (index >= QUEUE_CAPACITY) + { + index -= QUEUE_CAPACITY; + } + if (gUnknown_0202BF20.recvQueue.count < QUEUE_CAPACITY) + { + for (i = 0; i < gUnknown_0202BF20.playerCount; i++) + { + gUnknown_0202BF20.checksum += recv[i]; + gUnknown_0200282A |= recv[i]; + gUnknown_0202BF20.recvQueue.data[i][gUnknown_0202BF20.recvCmdIndex][index] = recv[i]; + if ((gUnknown_0202BF20.sendCmdIndex == 1) && (gUnknown_0202BF20.unkE == 0) && ((recv[i] & 0xF) == 1)) + { + gUnknown_0202BF20.unkE = 1; + gUnknown_02002826 = 5; + } + } + } + else + { + gUnknown_0202BF20.queueFull |= QUEUE_FULL_RECV; + } + gUnknown_0202BF20.recvCmdIndex++; + if (gUnknown_0202BF20.recvCmdIndex == CMD_LENGTH && gUnknown_0200282A) + { + gUnknown_0202BF20.recvQueue.count++; + gUnknown_0200282A = 0; + } + } +} + +void sub_223C(void) // DoSend +{ + if (gUnknown_0202BF20.sendCmdIndex == CMD_LENGTH) + { + REG_SIOMLT_SEND = gUnknown_0202BF20.checksum; + if (!gUnknown_02002825) + { + gUnknown_0202BF20.sendQueue.count--; + gUnknown_0202BF20.sendQueue.pos++; + if (gUnknown_0202BF20.sendQueue.pos >= QUEUE_CAPACITY) + { + gUnknown_0202BF20.sendQueue.pos = 0; + } + } + else + { + gUnknown_02002825 = FALSE; + } + } + else + { + if (gUnknown_0202BF20.sendCmdIndex == 0 && gUnknown_0202BF20.sendQueue.count == 0) + { + gUnknown_02002825 = TRUE; + } + if (gUnknown_02002825) + { + REG_SIOMLT_SEND = 0; + } + else + { + REG_SIOMLT_SEND = gUnknown_0202BF20.sendQueue.data[gUnknown_0202BF20.sendCmdIndex][gUnknown_0202BF20.sendQueue.pos]; + } + if ((gUnknown_0202BF20.unkE == 0) && (gUnknown_0202BF20.sendCmdIndex == 0) && (3 < gUnknown_0202BF20.recvQueue.count)) { + REG_SIOMLT_SEND |= 1; // TODO + } + gUnknown_0202BF20.sendCmdIndex++; + } +} + +void sub_2308(void) // StopTimer +{ + if (gUnknown_0202BF20.isMaster) + { + REG_TM3CNT_H &= ~TIMER_ENABLE; + REG_TM3CNT_L = -197; + } +} + +void sub_2338(void) // SendRecvDone +{ + if (gUnknown_0202BF20.recvCmdIndex == CMD_LENGTH) + { + gUnknown_0202BF20.sendCmdIndex = 0; + gUnknown_0202BF20.recvCmdIndex = 0; + } + else if (gUnknown_0202BF20.isMaster) + { + REG_TM3CNT_H |= TIMER_ENABLE; + } +} + +void sub_2364(void) // ResetSendBuffer +{ + u8 i; + u8 j; + + gUnknown_0202BF20.sendQueue.count = 0; + gUnknown_0202BF20.sendQueue.pos = 0; + for (i = 0; i < CMD_LENGTH; i++) + { + for (j = 0; j < QUEUE_CAPACITY; j++) + { + gUnknown_0202BF20.sendQueue.data[i][j] = LINKCMD_NONE; + } + } +} + +void sub_23B4(void) // ResetRecvBuffer +{ + u8 i; + u8 j; + u8 k; + + gUnknown_0202BF20.recvQueue.count = 0; + gUnknown_0202BF20.recvQueue.pos = 0; + for (i = 0; i < MAX_LINK_PLAYERS; i++) + { + for (j = 0; j < CMD_LENGTH; j++) + { + for (k = 0; k < QUEUE_CAPACITY; k++) + { + gUnknown_0202BF20.recvQueue.data[i][j][k] = LINKCMD_NONE; + } + } + } +} diff --git a/sym_ewram.txt b/sym_ewram.txt index 5a97d4b..59aad98 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -475,9 +475,7 @@ gUnknown_0202BF10: @ 0x0202BF10 gUnknown_0202BF14: @ 0x0202BF14 .space 0xC gUnknown_0202BF20: @ 0x0202BF20 - .space 0x620 -gUnknown_0202C540: @ 0x0202C540 - .space 0x4 + .space 0x624 gUnknown_0202C544: @ 0x0202C544 .space 0x4 gUnknown_0202C548: @ 0x0202C548 From 1c909c1b7e8cf73b09fb63f604a6f5dbf2a894a7 Mon Sep 17 00:00:00 2001 From: WhenGryphonsFly <84215159+WhenGryphonsFly@users.noreply.github.com> Date: Sun, 11 Aug 2024 19:56:40 -0500 Subject: [PATCH 4/5] Rearrange link.c --- include/functions.h | 22 ----- include/link.h | 51 +++++++++++ include/variables.h | 1 - src/ereader.c | 1 + src/high_scores.c | 7 +- src/link.c | 213 ++++++++++++++++---------------------------- src/main.c | 1 + src/pokedex.c | 1 + 8 files changed, 132 insertions(+), 165 deletions(-) diff --git a/include/functions.h b/include/functions.h index c02c119..6ac45c2 100644 --- a/include/functions.h +++ b/include/functions.h @@ -788,28 +788,6 @@ extern void sub_13FC(void); //extern ? sub_1748(); //extern ? sub_17D8(); extern void sub_1828(void); -//extern ? sub_1884(); -extern void sub_19B4(void); -//extern ? sub_19CC(); -//extern ? sub_1A78(); -//extern ? nullsub_15(); -extern void sub_1AA4(void); -extern s32 sub_1B04(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[]); -//extern ? sub_1C5C(); -//extern ? sub_1C84(); -//extern ? sub_1CD4(); -//extern ? sub_1DB8(); -//extern ? sub_1EC0(); -extern void sub_1F4C(void); -extern void sub_1F5C(void); -//extern ? sub_1FEC(); -//extern ? sub_1FFC(); -//extern ? sub_20FC(); -//extern ? sub_223C(); -//extern ? sub_2308(); -//extern ? sub_2338(); -//extern ? sub_2364(); -//extern ? sub_23B4(); extern s16 sub_2414(const struct SpriteSet *const *spriteSets, u16 numSpriteSets, struct SpriteGroup *spriteGroups); //extern ? nullsub_16(); extern void sub_24DC(void); diff --git a/include/link.h b/include/link.h index e6b4250..34a71ce 100644 --- a/include/link.h +++ b/include/link.h @@ -1,19 +1,70 @@ // include guard +#ifndef GUARD_LINK_H +#define GUARD_LINK_H // include macros // "extern" define macros +#define CMD_LENGTH 8 +#define QUEUE_CAPACITY 0x20 +#define MAX_LINK_PLAYERS 2 // "extern" enums // "extern" struct definitions +struct SendQueue +{ + u16 data[CMD_LENGTH][QUEUE_CAPACITY]; + u8 pos; + u8 count; +}; + +struct RecvQueue +{ + u16 data[MAX_LINK_PLAYERS][CMD_LENGTH][QUEUE_CAPACITY]; + u8 pos; + u8 count; // 0x621 +}; + +struct Link { + u8 isMaster; // 0x0 + u8 state; // 0x1 + u8 localId; // 0x2 + u8 playerCount; // 0x3 + u16 handshakeBuffer[4]; // 0x4 + bool8 receivedNothing; // 0xC + u8 serialIntrCounter; // 0xD + u8 unkE; // 0xE + u8 fillerF; // 0xF + bool8 handshakeAsMaster; // 0x10 + u8 unk11; + u8 hardwareError; + u8 unk13; + u8 queueFull; // 0x14 + u8 unk15; + u16 checksum; // 0x16 + u8 sendCmdIndex; // 0x18 + u8 recvCmdIndex; // 0x19 + u8 filler1A[0x1C-0x1A]; // 0x1A + + struct SendQueue sendQueue; + struct RecvQueue recvQueue; +}; // extern function declarations +extern void sub_19B4(void); +extern void sub_1AA4(void); +extern s32 sub_1B04(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[MAX_LINK_PLAYERS]); +extern void sub_1F4C(void); +extern void sub_1F5C(void); // extern IWRAM variable declarations // extern EWRAM variable declarations +extern u8 gUnknown_0202BEC8; +extern struct Link gUnknown_0202BF20; // gLink // extern const definitions // end include guard +#endif//GUARD_LINK_H diff --git a/include/variables.h b/include/variables.h index c79a495..db22fe0 100644 --- a/include/variables.h +++ b/include/variables.h @@ -263,7 +263,6 @@ extern struct PokemonSpecies gUnknown_086A3700[]; extern const struct SpriteSet * const gUnknown_086A54D8[13]; extern u32 gUnknown_0202ADD0; -extern u8 gUnknown_0202BEC8; extern s16 gUnknown_0202C5F0[]; extern u16 gUnknown_0201A4D0[][2]; extern u32 gUnknown_0202BDF0; diff --git a/src/ereader.c b/src/ereader.c index 47d4c37..8554d8e 100644 --- a/src/ereader.c +++ b/src/ereader.c @@ -2,6 +2,7 @@ #include "constants/bg_music.h" #include "constants/ereader.h" #include "functions.h" +#include "link.h" #include "main.h" #include "m4a.h" #include "titlescreen.h" diff --git a/src/high_scores.c b/src/high_scores.c index b8a7131..393ac7d 100644 --- a/src/high_scores.c +++ b/src/high_scores.c @@ -1,6 +1,7 @@ #include "global.h" #include "constants/bg_music.h" #include "functions.h" +#include "link.h" #include "main.h" #include "m4a.h" #include "variables.h" @@ -1791,12 +1792,10 @@ void sub_E908(void) gUnknown_0202C54C = 0; } -extern u8 gUnknown_0202BF20; - s16 sub_E94C(void) { s16 result; - if (gUnknown_0202BF20 != 0) + if (gUnknown_0202BF20.isMaster) result = sub_EBEC(); else result = sub_ED28(); @@ -1807,7 +1806,7 @@ s16 sub_E94C(void) s16 sub_E970(void) { s16 result; - if (gUnknown_0202BF20 != 0) + if (gUnknown_0202BF20.isMaster) result = sub_E994(); else result = sub_EAC0(); diff --git a/src/link.c b/src/link.c index 9c2fb95..b603014 100644 --- a/src/link.c +++ b/src/link.c @@ -1,60 +1,14 @@ // include macros #include "global.h" +#include "link.h" #include "m4a.h" #include "main.h" // "static" define macros - -// "static" enums - -// "static" struct definitions - -// static function declarations - -// static IWRAM variable declarations - -// static EWRAM variable declarations - -// static const definitions - -// function definitions - -// TODO Unsorted - -#define MAX_LINK_PLAYERS 2 - -void sub_1884(void); -void sub_19B4(void); -void sub_19CC(void); -void sub_1A78(void); -void nullsub_15(void); -void sub_1AA4(void); -s32 sub_1B04(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[MAX_LINK_PLAYERS]); -void sub_1C5C(void); - -void sub_1C84(void); -void sub_1CD4(u16 *); -void sub_1DB8(u16 (*recvCmds)[MAX_LINK_PLAYERS]); -void sub_1EC0(void); -void sub_1F4C(void); -void sub_1F5C(void); -void sub_1FEC(void); - -bool8 sub_1FFC(void); -void sub_20FC(void); -void sub_223C(void); -void sub_2308(void); -void sub_2338(void); -void sub_2364(void); -void sub_23B4(void); - -#define CMD_LENGTH 8 -#define QUEUE_CAPACITY 0x20 - - -void sub_1DB8(u16 (*recvCmds)[MAX_LINK_PLAYERS]); - #define LINKCMD_NONE 0xEFFF +#define MASTER_HANDSHAKE 0x8FFF +#define SLAVE_HANDSHAKE 0xD13B +//#define EREADER_HANDSHAKE 0xCCD0 #define LINK_SLAVE 0 #define LINK_MASTER 8 @@ -87,6 +41,25 @@ void sub_1DB8(u16 (*recvCmds)[MAX_LINK_PLAYERS]); #define LINK_STAT_ERROR_LAG_SLAVE 0x00040000 #define LINK_STAT_ERROR_LAG_SLAVE_SHIFT 18 +#define SIO_MULTI_CNT ((struct SioMultiCnt *)REG_ADDR_SIOCNT) + +#define EnableInterrupts(interrupts) \ +{ \ + gUnknown_02002822 = REG_IME; \ + REG_IME = 0; \ + REG_IE |= (interrupts); \ + REG_IME = gUnknown_02002822; \ +} + +#define DisableInterrupts(interrupts) \ +{ \ + gUnknown_02002822 = REG_IME; \ + REG_IME = 0; \ + REG_IE &= ~(interrupts); \ + REG_IME = gUnknown_02002822; \ +} + +// "static" enums enum { QUEUE_FULL_NONE, @@ -110,83 +83,47 @@ enum LAG_SLAVE, }; -struct SendQueue -{ - u16 data[CMD_LENGTH][QUEUE_CAPACITY]; - u8 pos; - u8 count; -}; +// "static" struct definitions -struct RecvQueue -{ - u16 data[MAX_LINK_PLAYERS][CMD_LENGTH][QUEUE_CAPACITY]; - u8 pos; - u8 count; // 0x621 -}; +// static function declarations +static void sub_1884(void); +static void sub_19CC(void); +static void sub_1A78(void); +static void nullsub_15(void); +static void sub_1C5C(void); +static void sub_1C84(void); +static void sub_1CD4(u16 *); +static void sub_1DB8(u16 (*recvCmds)[MAX_LINK_PLAYERS]); +static void sub_1EC0(void); +static void sub_1FEC(void); +static bool8 sub_1FFC(void); +static void sub_20FC(void); +static void sub_223C(void); +static void sub_2308(void); +static void sub_2338(void); +static void sub_2364(void); +static void sub_23B4(void); -struct Link { // struct Link - u8 isMaster; // 0x0 - u8 state; // 0x1 - u8 localId; // 0x2 - u8 playerCount; // 0x3 - u16 handshakeBuffer[4]; // 0x4 - bool8 receivedNothing; // 0xC - u8 serialIntrCounter; // 0xD - u8 unkE; // 0xE - u8 fillerF; // 0xF - bool8 handshakeAsMaster; // 0x10 - u8 unk11; - u8 hardwareError; - u8 unk13; - u8 queueFull; // 0x14 - u8 unk15; - u16 checksum; // 0x16 - u8 sendCmdIndex; // 0x18 - u8 recvCmdIndex; // 0x19 - u8 filler1A[0x1C-0x1A]; // 0x1A - - struct SendQueue sendQueue; - struct RecvQueue recvQueue; -}; -extern struct Link gUnknown_0202BF20; // gLink +// static IWRAM variable declarations +// static EWRAM variable declarations +// TODO fix bss discard nonsense extern u8 gUnknown_02002820; // sChecksumAvailable extern u16 gUnknown_02002822; // gLinkSavedIme extern u8 gUnknown_02002824; // sNumVBlanksWithoutSerialIntr +extern u8 gUnknown_02002825; // sSendBufferEmpty extern u8 gUnknown_02002826; +extern u8 gUnknown_02002827; // sHandshakePlayerCount ? extern u16 gUnknown_02002828; // sSendNonzeroCheck extern u16 gUnknown_0200282A; -extern u8 gUnknown_02019C2C; // gLastSendQueueCount -extern s8 gUnknown_0202C5E0; -extern u8 gUnknown_02002825; // sSendBufferEmpty -extern u8 gUnknown_02002827; // sHandshakePlayerCount ? +extern u8 gUnknown_02019C2C; // gLastSendQueueCount extern u8 gUnknown_0202A554; // ??? -extern u8 gUnknown_0202BEC8; - - -#define MASTER_HANDSHAKE 0x8FFF -#define SLAVE_HANDSHAKE 0xD13B -//#define EREADER_HANDSHAKE 0xCCD0 - -#define SIO_MULTI_CNT ((struct SioMultiCnt *)REG_ADDR_SIOCNT) - -#define EnableInterrupts(interrupts) \ -{ \ - gUnknown_02002822 = REG_IME; \ - REG_IME = 0; \ - REG_IE |= (interrupts); \ - REG_IME = gUnknown_02002822; \ -} +extern s8 gUnknown_0202C5E0; -#define DisableInterrupts(interrupts) \ -{ \ - gUnknown_02002822 = REG_IME; \ - REG_IME = 0; \ - REG_IE &= ~(interrupts); \ - REG_IME = gUnknown_02002822; \ -} +// static const definitions -void sub_1884(void) // EnableSerial +// function definitions +static void sub_1884(void) // EnableSerial { DisableInterrupts(INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL); REG_RCNT = 0; @@ -194,8 +131,8 @@ void sub_1884(void) // EnableSerial REG_SIOCNT |= SIO_115200_BPS | SIO_INTR_ENABLE; gUnknown_02002822 = REG_IME; - SetMainCallback(sub_19CC+1); - SetVBlankIntrFunc(sub_1A78+1); + SetMainCallback(sub_19CC); + SetVBlankIntrFunc(sub_1A78); REG_IME = 0; REG_IE |= INTR_FLAG_SERIAL; REG_IME = gUnknown_02002822; @@ -221,7 +158,7 @@ void sub_1884(void) // EnableSerial gUnknown_0200282A = 0; } -void sub_19B4(void) // TODO +extern void sub_19B4(void) // TODO { sub_24DC(); sub_250C(); @@ -229,7 +166,7 @@ void sub_19B4(void) // TODO sub_1AA4(); } -void sub_19CC(void) // TODO +static void sub_19CC(void) // TODO { if ((REG_DISPSTAT & 0x8) != 0) { @@ -258,7 +195,7 @@ void sub_19CC(void) // TODO m4aSoundMain(); } -void sub_1A78(void) // VBlankIntr +static void sub_1A78(void) // VBlankIntr { sub_1EC0(); m4aSoundVSync(); @@ -267,11 +204,11 @@ void sub_1A78(void) // VBlankIntr REG_IME = 1; } -void nullsub_15(void) +static void nullsub_15(void) { } -void sub_1AA4(void) // TODO DisableSerial? +extern void sub_1AA4(void) // TODO DisableSerial? { DisableInterrupts(INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL); @@ -282,7 +219,7 @@ void sub_1AA4(void) // TODO DisableSerial? CpuFill32(0, &gUnknown_0202BF20, sizeof(gUnknown_0202BF20)); // TODO off by 4 error? } -s32 sub_1B04(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[MAX_LINK_PLAYERS]) // LinkMain1 +extern s32 sub_1B04(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[MAX_LINK_PLAYERS]) // LinkMain1 { u32 retVal; @@ -379,7 +316,7 @@ s32 sub_1B04(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[MAX_LINK_ return retVal; } -void sub_1C5C(void) // CheckMasterOrSlave +static void sub_1C5C(void) // CheckMasterOrSlave { u32 terminals; terminals = *(vu32 *)REG_ADDR_SIOCNT & (SIO_MULTI_SD | SIO_MULTI_SI); @@ -394,7 +331,7 @@ void sub_1C5C(void) // CheckMasterOrSlave } } -void sub_1C84(void) // InitTimer +static void sub_1C84(void) // InitTimer { if (gUnknown_0202BF20.isMaster) { @@ -405,7 +342,7 @@ void sub_1C84(void) // InitTimer } } -void sub_1CD4(u16 *sendCmd) // EnqueueSendCmd +static void sub_1CD4(u16 *sendCmd) // EnqueueSendCmd { u8 i; u8 offset; @@ -443,7 +380,7 @@ void sub_1CD4(u16 *sendCmd) // EnqueueSendCmd gUnknown_02019C2C = gUnknown_0202BF20.sendQueue.count; } -void sub_1DB8(u16 (*recvCmds)[MAX_LINK_PLAYERS]) // DequeueRecvCmds +static void sub_1DB8(u16 (*recvCmds)[MAX_LINK_PLAYERS]) // DequeueRecvCmds { u8 i; u8 j; @@ -484,7 +421,7 @@ void sub_1DB8(u16 (*recvCmds)[MAX_LINK_PLAYERS]) // DequeueRecvCmds REG_IME = gUnknown_02002822; } -void sub_1EC0(void) // LinkVSync +static void sub_1EC0(void) // LinkVSync { if (gUnknown_0202BF20.unkE) { @@ -540,13 +477,13 @@ void sub_1EC0(void) // LinkVSync } } -void sub_1F4C(void) // Timer3Init +extern void sub_1F4C(void) // Timer3Init { sub_2308(); sub_1FEC(); } -void sub_1F5C(void) // SerialCB +extern void sub_1F5C(void) // SerialCB { u32 temp; temp = *((u32*) REG_ADDR_SIOCNT); @@ -585,12 +522,12 @@ void sub_1F5C(void) // SerialCB } } -void sub_1FEC(void) // StartTransfer +static void sub_1FEC(void) // StartTransfer { REG_SIOCNT |= SIO_START; } -bool8 sub_1FFC(void) // DoHandshake +static bool8 sub_1FFC(void) // DoHandshake { u8 i; u8 playerCount; @@ -648,7 +585,7 @@ bool8 sub_1FFC(void) // DoHandshake return FALSE; } -void sub_20FC(void) // DoRecv +static void sub_20FC(void) // DoRecv { u16 recv[4]; u8 i; @@ -701,7 +638,7 @@ void sub_20FC(void) // DoRecv } } -void sub_223C(void) // DoSend +static void sub_223C(void) // DoSend { if (gUnknown_0202BF20.sendCmdIndex == CMD_LENGTH) { @@ -741,7 +678,7 @@ void sub_223C(void) // DoSend } } -void sub_2308(void) // StopTimer +static void sub_2308(void) // StopTimer { if (gUnknown_0202BF20.isMaster) { @@ -750,7 +687,7 @@ void sub_2308(void) // StopTimer } } -void sub_2338(void) // SendRecvDone +static void sub_2338(void) // SendRecvDone { if (gUnknown_0202BF20.recvCmdIndex == CMD_LENGTH) { @@ -763,7 +700,7 @@ void sub_2338(void) // SendRecvDone } } -void sub_2364(void) // ResetSendBuffer +static void sub_2364(void) // ResetSendBuffer { u8 i; u8 j; @@ -779,7 +716,7 @@ void sub_2364(void) // ResetSendBuffer } } -void sub_23B4(void) // ResetRecvBuffer +static void sub_23B4(void) // ResetRecvBuffer { u8 i; u8 j; diff --git a/src/main.c b/src/main.c index bb07c01..7cc25ad 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include "global.h" #include "main.h" #include "gbplayer.h" +#include "link.h" #include "m4a.h" static void InitGame(void); diff --git a/src/pokedex.c b/src/pokedex.c index 004ff4a..ee7bc7f 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -1,6 +1,7 @@ #include "global.h" #include "constants/bg_music.h" #include "functions.h" +#include "link.h" #include "m4a.h" #include "main.h" #include "types.h" From 9d49aa66a3db4fb01d215006d0890c295a248b09 Mon Sep 17 00:00:00 2001 From: WhenGryphonsFly <84215159+WhenGryphonsFly@users.noreply.github.com> Date: Sun, 11 Aug 2024 20:42:35 -0500 Subject: [PATCH 5/5] Document functions and variables --- asm/pokedex.s | 8 +- include/link.h | 10 +- src/ereader.c | 8 +- src/high_scores.c | 10 +- src/link.c | 410 +++++++++++++++++++++++----------------------- src/main.c | 4 +- src/pokedex.c | 6 +- sym_ewram.txt | 14 +- 8 files changed, 236 insertions(+), 234 deletions(-) diff --git a/asm/pokedex.s b/asm/pokedex.s index ae6dedd..7ffec80 100644 --- a/asm/pokedex.s +++ b/asm/pokedex.s @@ -2039,14 +2039,14 @@ _08005EA0: .4byte gUnknown_0202BECC thumb_func_start sub_5EA4 sub_5EA4: @ 0x08005EA4 push {lr} - ldr r0, _08005EB4 @ =gUnknown_0202BF20 + ldr r0, _08005EB4 @ =gLink ldrb r0, [r0] cmp r0, #0 beq _08005EB8 bl sub_639C b _08005EBC .align 2, 0 -_08005EB4: .4byte gUnknown_0202BF20 +_08005EB4: .4byte gLink _08005EB8: bl sub_65DC _08005EBC: @@ -2060,14 +2060,14 @@ _08005EBC: thumb_func_start sub_5EC8 sub_5EC8: @ 0x08005EC8 push {lr} - ldr r0, _08005ED8 @ =gUnknown_0202BF20 + ldr r0, _08005ED8 @ =gLink ldrb r0, [r0] cmp r0, #0 beq _08005EDC bl sub_5EEC b _08005EE0 .align 2, 0 -_08005ED8: .4byte gUnknown_0202BF20 +_08005ED8: .4byte gLink _08005EDC: bl sub_6144 _08005EE0: diff --git a/include/link.h b/include/link.h index 34a71ce..862a0e0 100644 --- a/include/link.h +++ b/include/link.h @@ -53,16 +53,16 @@ struct Link { // extern function declarations extern void sub_19B4(void); -extern void sub_1AA4(void); -extern s32 sub_1B04(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[MAX_LINK_PLAYERS]); -extern void sub_1F4C(void); -extern void sub_1F5C(void); +extern void DisableSerial(void); +extern s32 LinkMain1(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[MAX_LINK_PLAYERS]); +extern void Timer3Init(void); +extern void SerialCB(void); // extern IWRAM variable declarations // extern EWRAM variable declarations extern u8 gUnknown_0202BEC8; -extern struct Link gUnknown_0202BF20; // gLink +extern struct Link gLink; // extern const definitions diff --git a/src/ereader.c b/src/ereader.c index 8554d8e..b99033e 100644 --- a/src/ereader.c +++ b/src/ereader.c @@ -179,13 +179,13 @@ void sub_304C(void) sub_3AB4(); if (gMain.newKeys & B_BUTTON) { sub_2568(); - sub_1AA4(); + DisableSerial(); sub_02B4(); m4aMPlayAllStop(); sub_0D10(); gMain.subState = 0; } - gUnknown_0202ADD0 = sub_1B04(&gUnknown_0202BEC8, gUnknown_0202C5F0, gUnknown_0201A4D0); + gUnknown_0202ADD0 = LinkMain1(&gUnknown_0202BEC8, gUnknown_0202C5F0, gUnknown_0201A4D0); gUnknown_0202BDF0 = gUnknown_0202ADD0 & 3; gUnknown_0201C1AC = ((gUnknown_0202ADD0 & 0x1c) >> 2); gUnknown_0202ADDC = ((gUnknown_0202ADD0 & 0xe00) >> 9); @@ -271,7 +271,7 @@ void sub_3208(void) } else if (gUnknown_086A5528[gUnknown_0202AD90] == 0) { sub_2568(); - sub_1AA4(); + DisableSerial(); sub_02B4(); m4aMPlayAllStop(); sub_0D10(); @@ -298,7 +298,7 @@ void sub_33A0(void) { case 4: sub_2568(); - sub_1AA4(); + DisableSerial(); break; case 0x96: gUnknown_0202A58C = 3; diff --git a/src/high_scores.c b/src/high_scores.c index 393ac7d..e6b7828 100644 --- a/src/high_scores.c +++ b/src/high_scores.c @@ -742,7 +742,7 @@ void sub_DA20(void) } else { - gUnknown_0202ADD0 = sub_1B04(&gUnknown_0202BEC8, gUnknown_0202C5F0, gUnknown_0201A4D0); + gUnknown_0202ADD0 = LinkMain1(&gUnknown_0202BEC8, gUnknown_0202C5F0, gUnknown_0201A4D0); gUnknown_0202BDF0 = gUnknown_0202ADD0 & 3; gUnknown_0201C1AC = (gUnknown_0202ADD0 & 0x1c) >> 2; gUnknown_0202ADDC = (gUnknown_0202ADD0 & 0xe00) >> 9; @@ -795,7 +795,7 @@ void sub_DB70(void) gUnknown_0201B178 = 0; gUnknown_0202BEBC = 0; sub_2568(); - sub_1AA4(); + DisableSerial(); for (i = 0; i < 2; i++) { for (j = 0; j < 6; j++) @@ -819,7 +819,7 @@ void sub_DBF4(void) { case 4: sub_2568(); - sub_1AA4(); + DisableSerial(); break; case 130: gUnknown_0202BEBC = 3; @@ -1795,7 +1795,7 @@ void sub_E908(void) s16 sub_E94C(void) { s16 result; - if (gUnknown_0202BF20.isMaster) + if (gLink.isMaster) result = sub_EBEC(); else result = sub_ED28(); @@ -1806,7 +1806,7 @@ s16 sub_E94C(void) s16 sub_E970(void) { s16 result; - if (gUnknown_0202BF20.isMaster) + if (gLink.isMaster) result = sub_E994(); else result = sub_EAC0(); diff --git a/src/link.c b/src/link.c index b603014..f3c2ef5 100644 --- a/src/link.c +++ b/src/link.c @@ -45,18 +45,18 @@ #define EnableInterrupts(interrupts) \ { \ - gUnknown_02002822 = REG_IME; \ + gLinkSavedIme = REG_IME; \ REG_IME = 0; \ REG_IE |= (interrupts); \ - REG_IME = gUnknown_02002822; \ + REG_IME = gLinkSavedIme; \ } #define DisableInterrupts(interrupts) \ { \ - gUnknown_02002822 = REG_IME; \ + gLinkSavedIme = REG_IME; \ REG_IME = 0; \ REG_IE &= ~(interrupts); \ - REG_IME = gUnknown_02002822; \ + REG_IME = gLinkSavedIme; \ } // "static" enums @@ -86,65 +86,65 @@ enum // "static" struct definitions // static function declarations -static void sub_1884(void); +static void EnableSerial(void); static void sub_19CC(void); -static void sub_1A78(void); +static void LinkVBlankIntr(void); static void nullsub_15(void); -static void sub_1C5C(void); -static void sub_1C84(void); -static void sub_1CD4(u16 *); -static void sub_1DB8(u16 (*recvCmds)[MAX_LINK_PLAYERS]); -static void sub_1EC0(void); -static void sub_1FEC(void); -static bool8 sub_1FFC(void); -static void sub_20FC(void); -static void sub_223C(void); -static void sub_2308(void); -static void sub_2338(void); -static void sub_2364(void); -static void sub_23B4(void); +static void CheckMasterOrSlave(void); +static void InitTimer(void); +static void EnqueueSendCmd(u16 *); +static void DequeueRecvCmds(u16 (*recvCmds)[MAX_LINK_PLAYERS]); +static void LinkVSync(void); +static void StartTransfer(void); +static bool8 DoHandshake(void); +static void DoRecv(void); +static void DoSend(void); +static void StopTimer(void); +static void SendRecvDone(void); +static void ResetSendBuffer(void); +static void ResetRecvBuffer(void); // static IWRAM variable declarations // static EWRAM variable declarations // TODO fix bss discard nonsense -extern u8 gUnknown_02002820; // sChecksumAvailable -extern u16 gUnknown_02002822; // gLinkSavedIme -extern u8 gUnknown_02002824; // sNumVBlanksWithoutSerialIntr -extern u8 gUnknown_02002825; // sSendBufferEmpty +extern u8 sChecksumAvailable; +extern u16 gLinkSavedIme; +extern u8 sNumVBlanksWithoutSerialIntr; +extern u8 sSendBufferEmpty; extern u8 gUnknown_02002826; extern u8 gUnknown_02002827; // sHandshakePlayerCount ? -extern u16 gUnknown_02002828; // sSendNonzeroCheck +extern u16 sSendNonzeroCheck; extern u16 gUnknown_0200282A; -extern u8 gUnknown_02019C2C; // gLastSendQueueCount +extern u8 gLastSendQueueCount; extern u8 gUnknown_0202A554; // ??? extern s8 gUnknown_0202C5E0; // static const definitions // function definitions -static void sub_1884(void) // EnableSerial +static void EnableSerial(void) { DisableInterrupts(INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL); REG_RCNT = 0; REG_SIOCNT = SIO_MULTI_MODE; REG_SIOCNT |= SIO_115200_BPS | SIO_INTR_ENABLE; - gUnknown_02002822 = REG_IME; + gLinkSavedIme = REG_IME; SetMainCallback(sub_19CC); - SetVBlankIntrFunc(sub_1A78); + SetVBlankIntrFunc(LinkVBlankIntr); REG_IME = 0; REG_IE |= INTR_FLAG_SERIAL; - REG_IME = gUnknown_02002822; + REG_IME = gLinkSavedIme; REG_SIOMLT_SEND = 0; // TODO correct register name? *((u64 *) REG_ADDR_SIOMULTI0) = 0; - CpuFill32(0, &gUnknown_0202BF20, sizeof(gUnknown_0202BF20)); + CpuFill32(0, &gLink, sizeof(gLink)); - gUnknown_02002824 = 0; - gUnknown_02002825 = 0; + sNumVBlanksWithoutSerialIntr = 0; + sSendBufferEmpty = 0; gUnknown_02002827 = 0; - gUnknown_02019C2C = 0; + gLastSendQueueCount = 0; gUnknown_0202A554 = 0; gUnknown_0202C5E0 = 0; gUnknown_0202ADD0 = 0; @@ -153,8 +153,8 @@ static void sub_1884(void) // EnableSerial gUnknown_0201C1AC = 0; gUnknown_0202ADDC = 0; gUnknown_0202BEC8 = 0; - gUnknown_02002820 = 0; - gUnknown_02002828 = 0; + sChecksumAvailable = 0; + sSendNonzeroCheck = 0; gUnknown_0200282A = 0; } @@ -162,8 +162,8 @@ extern void sub_19B4(void) // TODO { sub_24DC(); sub_250C(); - sub_1884(); - sub_1AA4(); + EnableSerial(); + DisableSerial(); } static void sub_19CC(void) // TODO @@ -195,9 +195,9 @@ static void sub_19CC(void) // TODO m4aSoundMain(); } -static void sub_1A78(void) // VBlankIntr +static void LinkVBlankIntr(void) { - sub_1EC0(); + LinkVSync(); m4aSoundVSync(); REG_IME = 0; INTR_CHECK |= INTR_FLAG_VBLANK; @@ -208,7 +208,7 @@ static void nullsub_15(void) { } -extern void sub_1AA4(void) // TODO DisableSerial? +extern void DisableSerial(void) { DisableInterrupts(INTR_FLAG_TIMER3 | INTR_FLAG_SERIAL); @@ -216,75 +216,75 @@ extern void sub_1AA4(void) // TODO DisableSerial? REG_TM3CNT_H = 0; REG_IF = 0xC0; - CpuFill32(0, &gUnknown_0202BF20, sizeof(gUnknown_0202BF20)); // TODO off by 4 error? + CpuFill32(0, &gLink, sizeof(gLink)); } -extern s32 sub_1B04(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[MAX_LINK_PLAYERS]) // LinkMain1 +extern s32 LinkMain1(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[MAX_LINK_PLAYERS]) { u32 retVal; - switch (gUnknown_0202BF20.state) + switch (gLink.state) { case LINK_STATE_START0: - sub_1AA4(); - gUnknown_0202BF20.state = 1; + DisableSerial(); + gLink.state = 1; break; case LINK_STATE_START1: - sub_1884(); - gUnknown_0202BF20.state = 2; + EnableSerial(); + gLink.state = 2; break; case LINK_STATE_HANDSHAKE: switch (*shouldAdvanceLinkState) { default: - sub_1C5C(); - if (gUnknown_0202C5E0 == 0 && gUnknown_0202BF20.isMaster && gUnknown_0202BF20.playerCount == 2) + CheckMasterOrSlave(); + if (gUnknown_0202C5E0 == 0 && gLink.isMaster && gLink.playerCount == 2) { - gUnknown_0202BF20.handshakeAsMaster = TRUE; + gLink.handshakeAsMaster = TRUE; gUnknown_0202C5E0 = -1; } break; case 1: - if (gUnknown_0202BF20.isMaster != LINK_SLAVE && gUnknown_0202BF20.playerCount == 2) - gUnknown_0202BF20.handshakeAsMaster = TRUE; + if (gLink.isMaster != LINK_SLAVE && gLink.playerCount == 2) + gLink.handshakeAsMaster = TRUE; gUnknown_0202C5E0 = -1; break; case 2: - gUnknown_0202BF20.state = LINK_STATE_START0; + gLink.state = LINK_STATE_START0; REG_SIOMLT_SEND = 0; break; } break; case LINK_STATE_INIT_TIMER: - sub_1C84(); - gUnknown_0202BF20.state = LINK_STATE_CONN_ESTABLISHED; + InitTimer(); + gLink.state = LINK_STATE_CONN_ESTABLISHED; // fallthrough case LINK_STATE_CONN_ESTABLISHED: - if (gUnknown_0202BF20.unkE == 0) + if (gLink.unkE == 0) { - sub_1CD4(sendCmd); + EnqueueSendCmd(sendCmd); } - sub_1DB8(recvCmds); + DequeueRecvCmds(recvCmds); break; } *shouldAdvanceLinkState = 0; - retVal = gUnknown_0202BF20.localId; - retVal |= (gUnknown_0202BF20.playerCount << LINK_STAT_PLAYER_COUNT_SHIFT); - if (gUnknown_0202BF20.isMaster == LINK_MASTER) + retVal = gLink.localId; + retVal |= (gLink.playerCount << LINK_STAT_PLAYER_COUNT_SHIFT); + if (gLink.isMaster == LINK_MASTER) { retVal |= LINK_STAT_MASTER; } { - u32 receivedNothing = gUnknown_0202BF20.receivedNothing << 8; - u32 unk11 = gUnknown_0202BF20.unk11 << 9; - u32 hardwareError = gUnknown_0202BF20.hardwareError << 0x10; - u32 unk13 = gUnknown_0202BF20.unk13 << 0x11; - u32 queueFull = gUnknown_0202BF20.queueFull << 0x12; - u32 unk15 = gUnknown_0202BF20.unk15 << 0x14; + u32 receivedNothing = gLink.receivedNothing << 8; + u32 unk11 = gLink.unk11 << 9; + u32 hardwareError = gLink.hardwareError << 0x10; + u32 unk13 = gLink.unk13 << 0x11; + u32 queueFull = gLink.queueFull << 0x12; + u32 unk15 = gLink.unk15 << 0x14; u32 val; - if (gUnknown_0202BF20.state == LINK_STATE_CONN_ESTABLISHED) + if (gLink.state == LINK_STATE_CONN_ESTABLISHED) { val = LINK_STAT_CONN_ESTABLISHED; val |= receivedNothing; @@ -309,31 +309,31 @@ extern s32 sub_1B04(u8 *shouldAdvanceLinkState, s16 *sendCmd, u16 (*recvCmds)[MA retVal = val; } - if (gUnknown_0202BF20.localId >= MAX_LINK_PLAYERS) + if (gLink.localId >= MAX_LINK_PLAYERS) retVal |= 0x80 << 0xF; return retVal; } -static void sub_1C5C(void) // CheckMasterOrSlave +static void CheckMasterOrSlave(void) { u32 terminals; terminals = *(vu32 *)REG_ADDR_SIOCNT & (SIO_MULTI_SD | SIO_MULTI_SI); - if (terminals == SIO_MULTI_SD && gUnknown_0202BF20.localId == 0) + if (terminals == SIO_MULTI_SD && gLink.localId == 0) { - gUnknown_0202BF20.isMaster = 8; + gLink.isMaster = 8; } else { - gUnknown_0202BF20.isMaster = 0; + gLink.isMaster = 0; } } -static void sub_1C84(void) // InitTimer +static void InitTimer(void) { - if (gUnknown_0202BF20.isMaster) + if (gLink.isMaster) { REG_TM3CNT_L = -197; REG_TM3CNT_H = TIMER_64CLK | TIMER_INTR_ENABLE; @@ -342,192 +342,192 @@ static void sub_1C84(void) // InitTimer } } -static void sub_1CD4(u16 *sendCmd) // EnqueueSendCmd +static void EnqueueSendCmd(u16 *sendCmd) { u8 i; u8 offset; - gUnknown_02002822 = REG_IME; + gLinkSavedIme = REG_IME; REG_IME = 0; - if (gUnknown_0202BF20.sendQueue.count < QUEUE_CAPACITY) + if (gLink.sendQueue.count < QUEUE_CAPACITY) { - offset = gUnknown_0202BF20.sendQueue.pos + gUnknown_0202BF20.sendQueue.count; + offset = gLink.sendQueue.pos + gLink.sendQueue.count; if (offset >= QUEUE_CAPACITY) { offset -= QUEUE_CAPACITY; } for (i = 0; i < CMD_LENGTH; i++) { - gUnknown_02002828 |= *sendCmd; - gUnknown_0202BF20.sendQueue.data[i][offset] = *sendCmd; + sSendNonzeroCheck |= *sendCmd; + gLink.sendQueue.data[i][offset] = *sendCmd; *sendCmd = 0; sendCmd++; } } else { - gUnknown_0202BF20.queueFull |= QUEUE_FULL_SEND; + gLink.queueFull |= QUEUE_FULL_SEND; } - if (gUnknown_02002828) + if (sSendNonzeroCheck) { - gUnknown_0202BF20.sendQueue.count++; - gUnknown_02002828 = 0; + gLink.sendQueue.count++; + sSendNonzeroCheck = 0; } - REG_IME = gUnknown_02002822; - gUnknown_02019C2C = gUnknown_0202BF20.sendQueue.count; + REG_IME = gLinkSavedIme; + gLastSendQueueCount = gLink.sendQueue.count; } -static void sub_1DB8(u16 (*recvCmds)[MAX_LINK_PLAYERS]) // DequeueRecvCmds +static void DequeueRecvCmds(u16 (*recvCmds)[MAX_LINK_PLAYERS]) { u8 i; u8 j; - gUnknown_02002822 = REG_IME; + gLinkSavedIme = REG_IME; REG_IME = 0; - if (gUnknown_0202BF20.recvQueue.count == 0) + if (gLink.recvQueue.count == 0) { for (i = 0; i < CMD_LENGTH; i++) { - for (j = 0; j < gUnknown_0202BF20.playerCount; j++) + for (j = 0; j < gLink.playerCount; j++) { recvCmds[i][j] = 0; } } - gUnknown_0202BF20.receivedNothing = TRUE; + gLink.receivedNothing = TRUE; } else { for (i = 0; i < CMD_LENGTH; i++) { - for (j = 0; j < gUnknown_0202BF20.playerCount; j++) + for (j = 0; j < gLink.playerCount; j++) { - recvCmds[i][j] = gUnknown_0202BF20.recvQueue.data[j][i][gUnknown_0202BF20.recvQueue.pos]; + recvCmds[i][j] = gLink.recvQueue.data[j][i][gLink.recvQueue.pos]; } } - gUnknown_0202BF20.recvQueue.count--; - gUnknown_0202BF20.recvQueue.pos++; - if (gUnknown_0202BF20.recvQueue.pos >= QUEUE_CAPACITY) + gLink.recvQueue.count--; + gLink.recvQueue.pos++; + if (gLink.recvQueue.pos >= QUEUE_CAPACITY) { - gUnknown_0202BF20.recvQueue.pos = 0; + gLink.recvQueue.pos = 0; } - gUnknown_0202BF20.receivedNothing = FALSE; + gLink.receivedNothing = FALSE; } - REG_IME = gUnknown_02002822; + REG_IME = gLinkSavedIme; } -static void sub_1EC0(void) // LinkVSync +static void LinkVSync(void) { - if (gUnknown_0202BF20.unkE) + if (gLink.unkE) { if (--gUnknown_02002826 != 0) { return; } - gUnknown_0202BF20.unkE = 0; + gLink.unkE = 0; } - if (gUnknown_0202BF20.isMaster) + if (gLink.isMaster) { - switch (gUnknown_0202BF20.state) + switch (gLink.state) { case LINK_STATE_CONN_ESTABLISHED: - if (gUnknown_0202BF20.serialIntrCounter < 9) + if (gLink.serialIntrCounter < 9) { - if (!gUnknown_0202BF20.hardwareError) + if (!gLink.hardwareError) { - gUnknown_0202BF20.unk15 = LAG_MASTER; + gLink.unk15 = LAG_MASTER; } else { - sub_1FEC(); + StartTransfer(); } } - else if (gUnknown_0202BF20.unk15 == LAG_NONE) + else if (gLink.unk15 == LAG_NONE) { - gUnknown_0202BF20.serialIntrCounter = 0; - sub_1FEC(); + gLink.serialIntrCounter = 0; + StartTransfer(); } break; case LINK_STATE_HANDSHAKE: - sub_1FEC(); + StartTransfer(); break; } } - else if (gUnknown_0202BF20.state == LINK_STATE_CONN_ESTABLISHED || gUnknown_0202BF20.state == LINK_STATE_HANDSHAKE) + else if (gLink.state == LINK_STATE_CONN_ESTABLISHED || gLink.state == LINK_STATE_HANDSHAKE) { - if (++gUnknown_02002824 > 6) + if (++sNumVBlanksWithoutSerialIntr > 6) { - if (gUnknown_0202BF20.state == LINK_STATE_CONN_ESTABLISHED) + if (gLink.state == LINK_STATE_CONN_ESTABLISHED) { - gUnknown_0202BF20.unk15 = LAG_SLAVE; + gLink.unk15 = LAG_SLAVE; } - if (gUnknown_0202BF20.state == LINK_STATE_HANDSHAKE) + if (gLink.state == LINK_STATE_HANDSHAKE) { - gUnknown_0202BF20.localId = 0; - gUnknown_0202BF20.playerCount = 0; - gUnknown_0202BF20.unk11 = FALSE; + gLink.localId = 0; + gLink.playerCount = 0; + gLink.unk11 = FALSE; } } } } -extern void sub_1F4C(void) // Timer3Init +extern void Timer3Init(void) { - sub_2308(); - sub_1FEC(); + StopTimer(); + StartTransfer(); } -extern void sub_1F5C(void) // SerialCB +extern void SerialCB(void) { u32 temp; temp = *((u32*) REG_ADDR_SIOCNT); - gUnknown_0202BF20.localId = (temp << 0x1A) >> 0x1E; // TODO fakenatch? - switch (gUnknown_0202BF20.state) + gLink.localId = (temp << 0x1A) >> 0x1E; // TODO fakenatch? + switch (gLink.state) { case LINK_STATE_CONN_ESTABLISHED: if (temp & 0x40) { - gUnknown_0202BF20.hardwareError = 1; + gLink.hardwareError = 1; } - sub_20FC(); - sub_223C(); - sub_2338(); + DoRecv(); + DoSend(); + SendRecvDone(); break; case LINK_STATE_HANDSHAKE: - if (sub_1FFC()) + if (DoHandshake()) { - if (gUnknown_0202BF20.isMaster) + if (gLink.isMaster) { - gUnknown_0202BF20.state = LINK_STATE_INIT_TIMER; - gUnknown_0202BF20.serialIntrCounter = 8; + gLink.state = LINK_STATE_INIT_TIMER; + gLink.serialIntrCounter = 8; } else { - gUnknown_0202BF20.state = LINK_STATE_CONN_ESTABLISHED; + gLink.state = LINK_STATE_CONN_ESTABLISHED; } } break; } - gUnknown_0202BF20.serialIntrCounter++; - gUnknown_02002824 = 0; - if (gUnknown_0202BF20.serialIntrCounter == 8) + gLink.serialIntrCounter++; + sNumVBlanksWithoutSerialIntr = 0; + if (gLink.serialIntrCounter == 8) { - gUnknown_0202A554 = gUnknown_0202BF20.recvQueue.count; + gUnknown_0202A554 = gLink.recvQueue.count; } } -static void sub_1FEC(void) // StartTransfer +static void StartTransfer(void) { REG_SIOCNT |= SIO_START; } -static bool8 sub_1FFC(void) // DoHandshake +static bool8 DoHandshake(void) { u8 i; u8 playerCount; @@ -535,7 +535,7 @@ static bool8 sub_1FFC(void) // DoHandshake playerCount = 0; minRecv = 0xFFFF; - if (gUnknown_0202BF20.handshakeAsMaster == TRUE) + if (gLink.handshakeAsMaster == TRUE) { REG_SIOMLT_SEND = MASTER_HANDSHAKE; } @@ -543,194 +543,196 @@ static bool8 sub_1FFC(void) // DoHandshake { REG_SIOMLT_SEND = SLAVE_HANDSHAKE; } - gUnknown_0202BF20.handshakeAsMaster = FALSE; - *(u64 *)gUnknown_0202BF20.handshakeBuffer = REG_SIOMLT_RECV; + gLink.handshakeAsMaster = FALSE; + *(u64 *)gLink.handshakeBuffer = REG_SIOMLT_RECV; //REG_SIOMLT_RECV = 0; for (i = 0; i < MAX_LINK_PLAYERS; i++) { - if ((gUnknown_0202BF20.handshakeBuffer[i] & ~0x3) == (SLAVE_HANDSHAKE & ~3) || gUnknown_0202BF20.handshakeBuffer[i] == MASTER_HANDSHAKE) + if ((gLink.handshakeBuffer[i] & ~0x3) == (SLAVE_HANDSHAKE & ~3) || gLink.handshakeBuffer[i] == MASTER_HANDSHAKE) { playerCount++; - if (minRecv > gUnknown_0202BF20.handshakeBuffer[i] && gUnknown_0202BF20.handshakeBuffer[i] != 0) - minRecv = gUnknown_0202BF20.handshakeBuffer[i]; + if (minRecv > gLink.handshakeBuffer[i] && gLink.handshakeBuffer[i] != 0) + minRecv = gLink.handshakeBuffer[i]; } else { - if (gUnknown_0202BF20.handshakeBuffer[i] != 0xFFFF) + if (gLink.handshakeBuffer[i] != 0xFFFF) { playerCount = 0; break; } - if (i == gUnknown_0202BF20.localId) // TODO check order + if (i == gLink.localId) // TODO check order { playerCount = 0; } } } - gUnknown_0202BF20.playerCount = playerCount; - if (gUnknown_0202BF20.playerCount == 2 && gUnknown_0202BF20.playerCount == gUnknown_02002827 && gUnknown_0202BF20.handshakeBuffer[0] == MASTER_HANDSHAKE) + gLink.playerCount = playerCount; + if (gLink.playerCount == 2 && gLink.playerCount == gUnknown_02002827 && gLink.handshakeBuffer[0] == MASTER_HANDSHAKE) { return TRUE; } - if (gUnknown_0202BF20.playerCount == 2) // ??? + if (gLink.playerCount == 2) // ??? { - gUnknown_0202BF20.unk11 = (minRecv & 3) + 1; + gLink.unk11 = (minRecv & 3) + 1; } else { - gUnknown_0202BF20.unk11 = 0; + gLink.unk11 = 0; } - gUnknown_02002827 = gUnknown_0202BF20.playerCount; + gUnknown_02002827 = gLink.playerCount; return FALSE; } -static void sub_20FC(void) // DoRecv +static void DoRecv(void) { u16 recv[4]; u8 i; u8 index; *(u64 *)recv = REG_SIOMLT_RECV; - if (gUnknown_0202BF20.sendCmdIndex == 0) + if (gLink.sendCmdIndex == 0) { - for (i = 0; i < gUnknown_0202BF20.playerCount; i++) + for (i = 0; i < gLink.playerCount; i++) { - if (gUnknown_0202BF20.checksum != recv[i] && gUnknown_02002820) + if (gLink.checksum != recv[i] && sChecksumAvailable) { - gUnknown_0202BF20.unk13 = TRUE; + gLink.unk13 = TRUE; } } - gUnknown_0202BF20.checksum = 0; - gUnknown_02002820 = TRUE; + gLink.checksum = 0; + sChecksumAvailable = TRUE; } else { - index = gUnknown_0202BF20.recvQueue.pos + gUnknown_0202BF20.recvQueue.count; + index = gLink.recvQueue.pos + gLink.recvQueue.count; if (index >= QUEUE_CAPACITY) { index -= QUEUE_CAPACITY; } - if (gUnknown_0202BF20.recvQueue.count < QUEUE_CAPACITY) + if (gLink.recvQueue.count < QUEUE_CAPACITY) { - for (i = 0; i < gUnknown_0202BF20.playerCount; i++) + for (i = 0; i < gLink.playerCount; i++) { - gUnknown_0202BF20.checksum += recv[i]; + gLink.checksum += recv[i]; gUnknown_0200282A |= recv[i]; - gUnknown_0202BF20.recvQueue.data[i][gUnknown_0202BF20.recvCmdIndex][index] = recv[i]; - if ((gUnknown_0202BF20.sendCmdIndex == 1) && (gUnknown_0202BF20.unkE == 0) && ((recv[i] & 0xF) == 1)) + gLink.recvQueue.data[i][gLink.recvCmdIndex][index] = recv[i]; + if ((gLink.sendCmdIndex == 1) && (gLink.unkE == 0) && ((recv[i] & 0xF) == 1)) { - gUnknown_0202BF20.unkE = 1; + gLink.unkE = 1; gUnknown_02002826 = 5; } } } else { - gUnknown_0202BF20.queueFull |= QUEUE_FULL_RECV; + gLink.queueFull |= QUEUE_FULL_RECV; } - gUnknown_0202BF20.recvCmdIndex++; - if (gUnknown_0202BF20.recvCmdIndex == CMD_LENGTH && gUnknown_0200282A) + gLink.recvCmdIndex++; + if (gLink.recvCmdIndex == CMD_LENGTH && gUnknown_0200282A) { - gUnknown_0202BF20.recvQueue.count++; + gLink.recvQueue.count++; gUnknown_0200282A = 0; } } } -static void sub_223C(void) // DoSend +static void DoSend(void) { - if (gUnknown_0202BF20.sendCmdIndex == CMD_LENGTH) + if (gLink.sendCmdIndex == CMD_LENGTH) { - REG_SIOMLT_SEND = gUnknown_0202BF20.checksum; - if (!gUnknown_02002825) + REG_SIOMLT_SEND = gLink.checksum; + if (!sSendBufferEmpty) { - gUnknown_0202BF20.sendQueue.count--; - gUnknown_0202BF20.sendQueue.pos++; - if (gUnknown_0202BF20.sendQueue.pos >= QUEUE_CAPACITY) + gLink.sendQueue.count--; + gLink.sendQueue.pos++; + if (gLink.sendQueue.pos >= QUEUE_CAPACITY) { - gUnknown_0202BF20.sendQueue.pos = 0; + gLink.sendQueue.pos = 0; } } else { - gUnknown_02002825 = FALSE; + sSendBufferEmpty = FALSE; } } else { - if (gUnknown_0202BF20.sendCmdIndex == 0 && gUnknown_0202BF20.sendQueue.count == 0) + if (gLink.sendCmdIndex == 0 && gLink.sendQueue.count == 0) { - gUnknown_02002825 = TRUE; + sSendBufferEmpty = TRUE; } - if (gUnknown_02002825) + if (sSendBufferEmpty) { REG_SIOMLT_SEND = 0; } else { - REG_SIOMLT_SEND = gUnknown_0202BF20.sendQueue.data[gUnknown_0202BF20.sendCmdIndex][gUnknown_0202BF20.sendQueue.pos]; + REG_SIOMLT_SEND = gLink.sendQueue.data[gLink.sendCmdIndex][gLink.sendQueue.pos]; } - if ((gUnknown_0202BF20.unkE == 0) && (gUnknown_0202BF20.sendCmdIndex == 0) && (3 < gUnknown_0202BF20.recvQueue.count)) { + if ((gLink.unkE == 0) && (gLink.sendCmdIndex == 0) && (3 < gLink.recvQueue.count)) { REG_SIOMLT_SEND |= 1; // TODO } - gUnknown_0202BF20.sendCmdIndex++; + gLink.sendCmdIndex++; } } -static void sub_2308(void) // StopTimer +static void StopTimer(void) { - if (gUnknown_0202BF20.isMaster) + if (gLink.isMaster) { REG_TM3CNT_H &= ~TIMER_ENABLE; REG_TM3CNT_L = -197; } } -static void sub_2338(void) // SendRecvDone +static void SendRecvDone(void) { - if (gUnknown_0202BF20.recvCmdIndex == CMD_LENGTH) + if (gLink.recvCmdIndex == CMD_LENGTH) { - gUnknown_0202BF20.sendCmdIndex = 0; - gUnknown_0202BF20.recvCmdIndex = 0; + gLink.sendCmdIndex = 0; + gLink.recvCmdIndex = 0; } - else if (gUnknown_0202BF20.isMaster) + else if (gLink.isMaster) { REG_TM3CNT_H |= TIMER_ENABLE; } } -static void sub_2364(void) // ResetSendBuffer +// TODO Unused? +static void ResetSendBuffer(void) { u8 i; u8 j; - gUnknown_0202BF20.sendQueue.count = 0; - gUnknown_0202BF20.sendQueue.pos = 0; + gLink.sendQueue.count = 0; + gLink.sendQueue.pos = 0; for (i = 0; i < CMD_LENGTH; i++) { for (j = 0; j < QUEUE_CAPACITY; j++) { - gUnknown_0202BF20.sendQueue.data[i][j] = LINKCMD_NONE; + gLink.sendQueue.data[i][j] = LINKCMD_NONE; } } } -static void sub_23B4(void) // ResetRecvBuffer +// TODO Unused? +static void ResetRecvBuffer(void) { u8 i; u8 j; u8 k; - gUnknown_0202BF20.recvQueue.count = 0; - gUnknown_0202BF20.recvQueue.pos = 0; + gLink.recvQueue.count = 0; + gLink.recvQueue.pos = 0; for (i = 0; i < MAX_LINK_PLAYERS; i++) { for (j = 0; j < CMD_LENGTH; j++) { for (k = 0; k < QUEUE_CAPACITY; k++) { - gUnknown_0202BF20.recvQueue.data[i][j][k] = LINKCMD_NONE; + gLink.recvQueue.data[i][j][k] = LINKCMD_NONE; } } } diff --git a/src/main.c b/src/main.c index 7cc25ad..df4d9d2 100644 --- a/src/main.c +++ b/src/main.c @@ -111,12 +111,12 @@ void VCountIntr(void) void SerialIntr(void) { - sub_1F5C(); + SerialCB(); } void Timer3Intr(void) { - sub_1F4C(); + Timer3Init(); } void IntrDummy(void) diff --git a/src/pokedex.c b/src/pokedex.c index ee7bc7f..afe0c6b 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -542,7 +542,7 @@ void sub_49D0(void) } else { - gUnknown_0202ADD0 = sub_1B04(&gUnknown_0202BEC8, gUnknown_0202C5F0, gUnknown_0201A4D0); + gUnknown_0202ADD0 = LinkMain1(&gUnknown_0202BEC8, gUnknown_0202C5F0, gUnknown_0201A4D0); gUnknown_0202BDF0 = gUnknown_0202ADD0 & 3; gUnknown_0201C1AC = (gUnknown_0202ADD0 & 0x1C) >> 2; gUnknown_0202ADDC = (gUnknown_0202ADD0 & 0xe00) >> 9; @@ -608,7 +608,7 @@ void sub_4B34(void) gUnknown_0202A588 = 1; sub_2568(); - sub_1AA4(); + DisableSerial(); for(iVar1 = 0; iVar1 < 0xE1; iVar1++) { @@ -631,7 +631,7 @@ void sub_4BB4(void) { case 0x4: sub_2568(); - sub_1AA4(); + DisableSerial(); break; case 0x82: gUnknown_0202BEFC = 3; diff --git a/sym_ewram.txt b/sym_ewram.txt index 59aad98..70c1b09 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -14,19 +14,19 @@ gUnknown_02002818: @ 0x02002818 .space 0x4 gUnknown_0200281C: @ 0x0200281C .space 0x4 -gUnknown_02002820: @ 0x02002820 +sChecksumAvailable: @ 0x02002820 .space 0x2 -gUnknown_02002822: @ 0x02002822 +gLinkSavedIme: @ 0x02002822 .space 0x2 -gUnknown_02002824: @ 0x02002824 +sNumVBlanksWithoutSerialIntr: @ 0x02002824 .space 0x1 -gUnknown_02002825: @ 0x02002825 +sSendBufferEmpty: @ 0x02002825 .space 0x1 gUnknown_02002826: @ 0x02002826 .space 0x1 gUnknown_02002827: @ 0x02002827 .space 0x1 -gUnknown_02002828: @ 0x02002828 +sSendNonzeroCheck: @ 0x02002828 .space 0x2 gUnknown_0200282A: @ 0x0200282A .space 0x2 @@ -274,7 +274,7 @@ gUnknown_02019C24: @ 0x02019C24 .space 0x4 gUnknown_02019C28: @ 0x02019C28 .space 0x4 -gUnknown_02019C2C: @ 0x02019C2C +gLastSendQueueCount: @ 0x02019C2C .space 0x4 gUnknown_02019C30: @ 0x02019C30 .space 0x10 @@ -474,7 +474,7 @@ gUnknown_0202BF10: @ 0x0202BF10 .space 0x4 gUnknown_0202BF14: @ 0x0202BF14 .space 0xC -gUnknown_0202BF20: @ 0x0202BF20 +gLink: @ 0x0202BF20 .space 0x624 gUnknown_0202C544: @ 0x0202C544 .space 0x4