From 6c12d154e7a6a0bc60c988497b3daa4f8126a5b2 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Tue, 2 Apr 2019 12:22:39 -0400 Subject: [PATCH] Reformat mevent server and client scripts --- asm/mevent_server_helpers.s | 373 ------------------------------------ data/mevent_server.s | 318 ++++++++++++------------------ include/util.h | 4 +- ld_script.txt | 2 +- src/mevent_server_helpers.c | 210 ++++++++++++++++++++ src/mevent_server_ish.c | 4 +- src/util.c | 4 +- 7 files changed, 335 insertions(+), 580 deletions(-) delete mode 100755 asm/mevent_server_helpers.s diff --git a/asm/mevent_server_helpers.s b/asm/mevent_server_helpers.s deleted file mode 100755 index 9bb70ff63..000000000 --- a/asm/mevent_server_helpers.s +++ /dev/null @@ -1,373 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start mevent_srv_sub_recv -mevent_srv_sub_recv: @ 801D8C0 - push {lr} - ldr r1, [r0, 0x20] - bl _call_via_r1 - pop {r1} - bx r1 - thumb_func_end mevent_srv_sub_recv - - thumb_func_start mevent_srv_sub_send -mevent_srv_sub_send: @ 801D8CC - push {lr} - ldr r1, [r0, 0x24] - bl _call_via_r1 - pop {r1} - bx r1 - thumb_func_end mevent_srv_sub_send - - thumb_func_start mevent_srv_sub_init -mevent_srv_sub_init: @ 801D8D8 - movs r3, 0 - strb r1, [r0, 0x4] - strb r2, [r0, 0x5] - str r3, [r0] - strh r3, [r0, 0x12] - strh r3, [r0, 0x14] - strh r3, [r0, 0x10] - strh r3, [r0, 0xA] - strh r3, [r0, 0xC] - strh r3, [r0, 0x8] - str r3, [r0, 0x1C] - str r3, [r0, 0x18] - ldr r1, =sub_801DA5C - str r1, [r0, 0x24] - ldr r1, =sub_801D988 - str r1, [r0, 0x20] - bx lr - .pool - thumb_func_end mevent_srv_sub_init - - thumb_func_start mevent_srv_sub_init_send -mevent_srv_sub_init_send: @ 801D904 - push {r4,lr} - adds r4, r0, 0 - movs r0, 0 - str r0, [r4] - strh r1, [r4, 0xE] - strh r0, [r4, 0x10] - strh r0, [r4, 0x12] - cmp r3, 0 - beq _0801D91A - strh r3, [r4, 0x14] - b _0801D920 -_0801D91A: - movs r0, 0x80 - lsls r0, 3 - strh r0, [r4, 0x14] -_0801D920: - str r2, [r4, 0x1C] - pop {r4} - pop {r0} - bx r0 - thumb_func_end mevent_srv_sub_init_send - - thumb_func_start mevent_srv_sub_init_recv -mevent_srv_sub_init_recv: @ 801D928 - movs r3, 0 - str r3, [r0] - strh r1, [r0, 0x6] - strh r3, [r0, 0x8] - strh r3, [r0, 0xA] - strh r3, [r0, 0xC] - str r2, [r0, 0x18] - bx lr - thumb_func_end mevent_srv_sub_init_recv - - thumb_func_start sub_801D938 -sub_801D938: @ 801D938 - push {lr} - adds r3, r0, 0 - adds r0, r1, 0 - lsls r3, 8 - ldr r1, =gBlockRecvBuffer - adds r3, r1 - adds r1, r3, 0 - bl memcpy - pop {r0} - bx r0 - .pool - thumb_func_end sub_801D938 - - thumb_func_start sub_801D954 -sub_801D954: @ 801D954 - push {r4,lr} - adds r4, r0, 0 - bl GetBlockReceivedStatus - lsls r0, 24 - lsrs r0, 24 - asrs r0, r4 - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - bne _0801D96E - movs r0, 0 - b _0801D970 -_0801D96E: - movs r0, 0x1 -_0801D970: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_801D954 - - thumb_func_start sub_801D978 -sub_801D978: @ 801D978 - push {lr} - lsls r0, 24 - lsrs r0, 24 - bl ResetBlockReceivedFlag - pop {r0} - bx r0 - thumb_func_end sub_801D978 - - thumb_func_start sub_801D988 -sub_801D988: @ 801D988 - push {r4-r6,lr} - sub sp, 0x8 - adds r5, r0, 0 - ldr r6, [r5] - cmp r6, 0x1 - beq _0801D9EC - cmp r6, 0x1 - bgt _0801D99E - cmp r6, 0 - beq _0801D9A4 - b _0801DA52 -_0801D99E: - cmp r6, 0x2 - beq _0801DA38 - b _0801DA52 -_0801D9A4: - ldrb r0, [r5, 0x5] - bl sub_801D954 - cmp r0, 0 - beq _0801DA52 - ldrb r0, [r5, 0x5] - mov r4, sp - mov r1, sp - movs r2, 0x8 - bl sub_801D938 - ldrh r1, [r4, 0x4] - strh r1, [r5, 0xC] - ldrh r0, [r4, 0x2] - strh r0, [r5, 0xA] - lsls r1, 16 - movs r0, 0x80 - lsls r0, 19 - cmp r1, r0 - bls _0801D9D2 -_0801D9CC: - bl sub_8010198 - b _0801DA52 -_0801D9D2: - mov r1, sp - ldrh r0, [r5, 0x6] - ldrh r1, [r1] - cmp r0, r1 - bne _0801D9CC - strh r6, [r5, 0x8] - ldrb r0, [r5, 0x5] - bl sub_801D978 - ldr r0, [r5] - adds r0, 0x1 - str r0, [r5] - b _0801DA52 -_0801D9EC: - ldrb r0, [r5, 0x5] - bl sub_801D954 - cmp r0, 0 - beq _0801DA52 - ldrh r0, [r5, 0x8] - lsls r1, r0, 6 - subs r1, r0 - lsls r3, r1, 2 - ldrh r0, [r5, 0xC] - subs r2, r0, r3 - cmp r2, 0xFC - bhi _0801DA1E - ldrb r0, [r5, 0x5] - ldr r1, [r5, 0x18] - adds r1, r3 - bl sub_801D938 - ldrh r0, [r5, 0x8] - adds r0, 0x1 - strh r0, [r5, 0x8] - ldr r0, [r5] - adds r0, 0x1 - str r0, [r5] - b _0801DA30 -_0801DA1E: - ldrb r0, [r5, 0x5] - ldr r1, [r5, 0x18] - adds r1, r3 - movs r2, 0xFC - bl sub_801D938 - ldrh r0, [r5, 0x8] - adds r0, 0x1 - strh r0, [r5, 0x8] -_0801DA30: - ldrb r0, [r5, 0x5] - bl sub_801D978 - b _0801DA52 -_0801DA38: - ldr r0, [r5, 0x18] - ldrh r1, [r5, 0xC] - bl CalcCRC16WithTable - lsls r0, 16 - lsrs r0, 16 - ldrh r1, [r5, 0xA] - cmp r0, r1 - bne _0801D9CC - movs r0, 0 - str r0, [r5] - movs r0, 0x1 - b _0801DA54 -_0801DA52: - movs r0, 0 -_0801DA54: - add sp, 0x8 - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_801D988 - - thumb_func_start sub_801DA5C -sub_801DA5C: @ 801DA5C - push {r4,r5,lr} - sub sp, 0x8 - adds r4, r0, 0 - ldr r5, [r4] - cmp r5, 0x1 - beq _0801DAC8 - cmp r5, 0x1 - bgt _0801DA72 - cmp r5, 0 - beq _0801DA7C - b _0801DB5E -_0801DA72: - cmp r5, 0x2 - beq _0801DB1C - cmp r5, 0x3 - beq _0801DB46 - b _0801DB5E -_0801DA7C: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _0801DB5E - ldrh r1, [r4, 0xE] - ldr r2, =0xffff0000 - ldr r0, [sp] - ands r0, r2 - orrs r0, r1 - str r0, [sp] - ldrh r1, [r4, 0x14] - ldr r0, [sp, 0x4] - ands r0, r2 - orrs r0, r1 - str r0, [sp, 0x4] - ldr r0, [r4, 0x1C] - bl CalcCRC16WithTable - lsls r0, 16 - ldr r2, =0x0000ffff - ldr r1, [sp] - ands r1, r2 - orrs r1, r0 - str r1, [sp] - lsrs r1, 16 - strh r1, [r4, 0x12] - strh r5, [r4, 0x10] - movs r0, 0 - mov r1, sp - movs r2, 0x8 - bl SendBlock - b _0801DB3E - .pool -_0801DAC8: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _0801DB5E - ldrb r0, [r4, 0x4] - bl sub_801D954 - cmp r0, 0 - beq _0801DB5E - ldrb r0, [r4, 0x4] - bl sub_801D978 - ldrh r1, [r4, 0x10] - lsls r0, r1, 6 - subs r0, r1 - lsls r3, r0, 2 - ldrh r0, [r4, 0x14] - subs r0, r3 - cmp r0, 0xFC - bhi _0801DB08 - ldr r1, [r4, 0x1C] - adds r1, r3 - lsls r2, r0, 16 - lsrs r2, 16 - movs r0, 0 - bl SendBlock - ldrh r0, [r4, 0x10] - adds r0, 0x1 - strh r0, [r4, 0x10] - b _0801DB3E -_0801DB08: - ldr r1, [r4, 0x1C] - adds r1, r3 - movs r0, 0 - movs r2, 0xFC - bl SendBlock - ldrh r0, [r4, 0x10] - adds r0, 0x1 - strh r0, [r4, 0x10] - b _0801DB5E -_0801DB1C: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _0801DB5E - ldr r0, [r4, 0x1C] - ldrh r1, [r4, 0x14] - bl CalcCRC16WithTable - lsls r0, 16 - lsrs r0, 16 - ldrh r1, [r4, 0x12] - cmp r0, r1 - beq _0801DB3E - bl sub_8010198 - b _0801DB5E -_0801DB3E: - ldr r0, [r4] - adds r0, 0x1 - str r0, [r4] - b _0801DB5E -_0801DB46: - ldrb r0, [r4, 0x4] - bl sub_801D954 - cmp r0, 0 - beq _0801DB5E - ldrb r0, [r4, 0x4] - bl sub_801D978 - movs r0, 0 - str r0, [r4] - movs r0, 0x1 - b _0801DB60 -_0801DB5E: - movs r0, 0 -_0801DB60: - add sp, 0x8 - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_801DA5C - - .align 2, 0 @ don't pad with nop diff --git a/data/mevent_server.s b/data/mevent_server.s index b6d8b4e25..47e474e61 100755 --- a/data/mevent_server.s +++ b/data/mevent_server.s @@ -9,265 +9,185 @@ gText_CanceledReadingCard:: @ 82F257C .align 2 gUnknown_082F2598:: @ 82F2598 - .byte 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 - .byte 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + .4byte 2, 16 + .4byte 4, 0 .align 2 gUnknown_082F25A8:: @ 82F25A8 - .byte 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 - .byte 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + .4byte 8, 0 + .4byte 3, 0 + .4byte 2, 16 + .4byte 4, 0 .align 2 gUnknown_082F25C8:: @ 82F25C8 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 + .4byte 20, 0 + .4byte 1, 10 .align 2 gUnknown_082F25D8:: @ 82F25D8 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00 + .4byte 20, 0 + .4byte 1, 11 .align 2 gUnknown_082F25E8:: @ 82F25E8 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + .4byte 20, 0 + .4byte 1, 0 .align 2 gUnknown_082F25F8:: @ 82F25F8 - .byte 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00 - .byte 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x02, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00 - .byte 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 + .4byte 2, 22 + .4byte 10, 0 + .4byte 2, 25 + .4byte 17, 0 + .4byte 20, 0 + .4byte 1, 2 .align 2 gUnknown_082F2628:: @ 82F2628 - .byte 0x02, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00 - .byte 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 - .byte 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + .4byte 2, 23 + .4byte 9, 0 + .4byte 3, 0 + .4byte 2, 16 + .4byte 4, 0 .align 2 gUnknown_082F2650:: @ 82F2650 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00 + .4byte 20, 0 + .4byte 1, 7 .align 2 gUnknown_082F2660:: @ 82F2660 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 + .4byte 20, 0 + .4byte 1, 3 .align 2 gUnknown_082F2670:: @ 82F2670 - .byte 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 - .byte 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + .4byte 13, 0 + .4byte 14, 0 + .4byte 3, 0 + .4byte 2, 16 + .4byte 4, 0 .align 2 gUnknown_082F2698:: @ 82F2698 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00 + .4byte 20, 0 + .4byte 1, 9 .align 2 gUnknown_082F26A8:: @ 82F26A8 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00 + .4byte 20, 0 + .4byte 1, 5 .align 2 gUnknown_082F26B8:: @ 82F26B8 - .byte 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00 - .byte 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00 - .byte 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00 - .byte 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00 + .4byte 2, 21 + .4byte 12, 0 + .4byte 20, 0 + .4byte 1, 14 + .4byte 2, 21 + .4byte 12, 0 + .4byte 20, 0 + .4byte 1, 13 .align 2 gUnknown_082F26F8:: @ 82F26F8 - .byte 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F25C8 - .byte 0x01, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x02, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F25D8 - .byte 0x01, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x02, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F2698 - .byte 0x01, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x02, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + .4byte 18, 0x10, gUnknown_082F25C8 + .4byte 1, 0x00, NULL + .4byte 2, 0x14, NULL + .4byte 0, 0x0a, NULL + .4byte 18, 0x10, gUnknown_082F25D8 + .4byte 1, 0x00, NULL + .4byte 2, 0x14, NULL + .4byte 0, 0x0b, NULL + .4byte 18, 0x10, gUnknown_082F2698 + .4byte 1, 0x00, NULL + .4byte 2, 0x14, NULL + .4byte 0, 0x09, NULL .align 2 gUnknown_082F2788:: @ 82F2788 - .byte 0x12, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F26B8 - .byte 0x01, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x14, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00 - - .4byte gText_CanceledReadingCard - .byte 0x01, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x02, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + .4byte 18, 0x20, gUnknown_082F26B8 + .4byte 1, 0x00, NULL + .4byte 20, 0x1b, gText_CanceledReadingCard + .4byte 1, 0x00, NULL + .4byte 2, 0x14, NULL + .4byte 0, 0x09, NULL .align 2 gUnknown_082F27D0:: @ 82F27D0 - .byte 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F2650 - .byte 0x01, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x02, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + .4byte 18, 0x10, gUnknown_082F2650 + .4byte 1, 0x00, NULL + .4byte 2, 0x14, NULL + .4byte 0, 0x07, NULL .align 2 gUnknown_082F2800:: @ 82F2800 - .byte 0x12, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F2628 - .byte 0x01, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F27D0 - .byte 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F2660 - .byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00 + .4byte 18, 0x28, gUnknown_082F2628 + .4byte 1, 0x00, NULL + .4byte 14, 0x00, NULL + .4byte 1, 0x00, NULL + .4byte 2, 0x13, NULL + .4byte 8, 0x00, NULL + .4byte 4, 0x01, gUnknown_082F27D0 + .4byte 18, 0x10, gUnknown_082F2660 + .4byte 1, 0x00, NULL + .4byte 2, 0x14, NULL + .4byte 0, 0x03, NULL .align 2 gUnknown_082F2884:: @ 82F2884 - .byte 0x12, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F25F8 - .byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00 + .4byte 18, 0x30, gUnknown_082F25F8 + .4byte 1, 0x00, NULL + .4byte 13, 0x00, NULL + .4byte 1, 0x00, NULL + .4byte 15, 0x00, NULL + .4byte 1, 0x00, NULL + .4byte 2, 0x14, NULL + .4byte 0, 0x02, NULL .align 2 gUnknown_082F28E4:: @ 82F28E4 - .byte 0x12, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F2670 - .byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 - .byte 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F2884 - .byte 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F2788 + .4byte 18, 0x28, gUnknown_082F2670 + .4byte 1, 0x00, NULL + .4byte 2, 0x13, NULL + .4byte 8, 0x00, NULL + .4byte 4, 0x00, gUnknown_082F2884 + .4byte 3, 0x00, gUnknown_082F2788 .align 2 gUnknown_082F292C:: @ 82F292C - .byte 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F26A8 - .byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00 - .byte 0x10, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F25E8 - .byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 - .byte 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00 + .4byte 18, 0x10, gUnknown_082F26A8 + .4byte 1, 0x00, NULL + .4byte 2, 0x14, NULL + .4byte 0, 0x05, NULL + .4byte 18, 0x10, gUnknown_082F25E8 + .4byte 1, 0x00, NULL + .4byte 2, 0x14, NULL + .4byte 0, 0x00, NULL .align 2 s_mevent_wonder_news:: @ 82F298C - .byte 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00 - .byte 0x20, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F25A8 - .byte 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 - .byte 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F26F8 - .byte 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F2800 + .4byte 27, 0x00, NULL + .4byte 18, 0x20, gUnknown_082F25A8 + .4byte 1, 0x00, NULL + .4byte 2, 0x11, NULL + .4byte 5, 0x00, NULL + .4byte 30, 0x00, NULL + .4byte 4, 0x00, gUnknown_082F26F8 + .4byte 3, 0x00, gUnknown_082F2800 .align 2 s_mevent_wonder_card:: @ 82F29EC - .byte 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x12, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F25A8 - .byte 0x01, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x02, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F26F8 - .byte 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - .byte 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00 - .byte 0x02, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F28E4 - .byte 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F2884 - .byte 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - - .4byte gUnknown_082F292C + .4byte 26, 0x00, NULL + .4byte 28, 0x00, NULL + .4byte 18, 0x20, gUnknown_082F25A8 + .4byte 1, 0x00, NULL + .4byte 2, 0x11, NULL + .4byte 5, 0x00, NULL + .4byte 6, 0x00, NULL + .4byte 4, 0x00, gUnknown_082F26F8 + .4byte 7, 0x00, NULL + .4byte 4, 0x02, gUnknown_082F28E4 + .4byte 4, 0x00, gUnknown_082F2884 + .4byte 3, 0x00, gUnknown_082F292C diff --git a/include/util.h b/include/util.h index 56c89359a..77062de96 100644 --- a/include/util.h +++ b/include/util.h @@ -10,8 +10,8 @@ u8 CreateInvisibleSpriteWithCallback(void (*)(struct Sprite *)); void StoreWordInTwoHalfwords(u16 *, u32); void LoadWordFromTwoHalfwords(u16 *, u32 *); int CountTrailingZeroBits(u32 value); -u16 CalcCRC16(u8 *data, s32 length); -u16 CalcCRC16WithTable(u8 *data, u32 length); +u16 CalcCRC16(const u8 *data, s32 length); +u16 CalcCRC16WithTable(const u8 *data, u32 length); u32 CalcByteArraySum(const u8* data, u32 length); void BlendPalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor); void DoBgAffineSet(struct BgAffineDstData *dest, u32 texX, u32 texY, s16 scrX, s16 scrY, s16 sx, s16 sy, u16 alpha); diff --git a/ld_script.txt b/ld_script.txt index 0a7838883..65f171171 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -62,7 +62,7 @@ SECTIONS { src/mevent_801BAAC.o(.text); src/mevent_server.o(.text); src/mevent_server_ish.o(.text); - asm/mevent_server_helpers.o(.text); + src/mevent_server_helpers.o(.text); src/mevent_news.o(.text); src/union_room_chat.o(.text); src/berry_crush.o(.text); diff --git a/src/mevent_server_helpers.c b/src/mevent_server_helpers.c index dc4f98a6e..af14b514c 100644 --- a/src/mevent_server_helpers.c +++ b/src/mevent_server_helpers.c @@ -1 +1,211 @@ #include "global.h" +#include "alloc.h" +#include "decompress.h" +#include "util.h" +#include "link.h" +#include "link_rfu.h" +#include "overworld.h" +#include "script.h" +#include "battle_tower.h" +#include "mystery_event_script.h" +#include "mevent.h" +#include "mevent_server_helpers.h" + +static u32 mevent_receive_func(struct mevent_srv_sub *); +static u32 mevent_send_func(struct mevent_srv_sub *); + +u32 mevent_srv_sub_recv(struct mevent_srv_sub * svr) +{ + return svr->recvFunc(svr); +} + +u32 mevent_srv_sub_send(struct mevent_srv_sub * svr) +{ + return svr->sendFunc(svr); +} + +void mevent_srv_sub_init(struct mevent_srv_sub * svr, u32 sendPlayerNo, u32 recvPlayerNo) +{ + svr->sendPlayerNo = sendPlayerNo; + svr->recvPlayerNo = recvPlayerNo; + svr->seqno = 0; + svr->sendCRC = 0; + svr->sendSize = 0; + svr->sendCounter = 0; + svr->recvCRC = 0; + svr->recvSize = 0; + svr->recvCounter = 0; + svr->sendBfr = NULL; + svr->recvBfr = NULL; + svr->sendFunc = mevent_send_func; + svr->recvFunc = mevent_receive_func; +} + +void mevent_srv_sub_init_send(struct mevent_srv_sub * svr, u32 ident, const void * src, u32 size) +{ + svr->seqno = 0; + svr->sendIdent = ident; + svr->sendCounter = 0; + svr->sendCRC = 0; + if (size != 0) + svr->sendSize = size; + else + svr->sendSize = ME_SEND_BUF_SIZE; + svr->sendBfr = src; +} + +void mevent_srv_sub_init_recv(struct mevent_srv_sub * svr, u32 ident, void * dest) +{ + svr->seqno = 0; + svr->recvIdent = ident; + svr->recvCounter = 0; + svr->recvCRC = 0; + svr->recvSize = 0; + svr->recvBfr = dest; +} + +static void mevent_recv_block(u32 recv_idx, void * dest, size_t size) +{ + memcpy(dest, gBlockRecvBuffer[recv_idx], size); +} + +static bool32 mevent_has_received(u32 recv_idx) +{ + if ((GetBlockReceivedStatus() >> recv_idx) & 1) + return TRUE; + else + return FALSE; +} + +static void mevent_reset_recv(u32 recv_idx) +{ + ResetBlockReceivedFlag(recv_idx); +} + +static bool32 mevent_receive_func(struct mevent_srv_sub * svr) +{ + struct send_recv_header header; + + switch (svr->seqno) + { + case 0: + if (mevent_has_received(svr->recvPlayerNo)) + { + mevent_recv_block(svr->recvPlayerNo, &header, sizeof(header)); + svr->recvSize = header.size; + svr->recvCRC = header.crc; + if (svr->recvSize > ME_SEND_BUF_SIZE) + { + sub_8010198(); + return FALSE; + } + else if (svr->recvIdent != header.ident) + { + sub_8010198(); + return FALSE; + } + else + { + svr->recvCounter = 0; + mevent_reset_recv(svr->recvPlayerNo); + ++svr->seqno; + } + } + break; + case 1: + if (mevent_has_received(svr->recvPlayerNo)) + { + size_t blocksiz = svr->recvCounter * 252; + if (svr->recvSize - blocksiz <= 252) + { + mevent_recv_block(svr->recvPlayerNo, svr->recvBfr + blocksiz, svr->recvSize - blocksiz); + ++svr->recvCounter; + ++svr->seqno; + } + else + { + mevent_recv_block(svr->recvPlayerNo, svr->recvBfr + blocksiz, 252); + ++svr->recvCounter; + } + mevent_reset_recv(svr->recvPlayerNo); + } + break; + case 2: + if (CalcCRC16WithTable(svr->recvBfr, svr->recvSize) != svr->recvCRC) + { + sub_8010198(); + return FALSE; + } + else + { + svr->seqno = 0; + return TRUE; + } + break; + + } + + return FALSE; +} + +static bool32 mevent_send_func(struct mevent_srv_sub * svr) +{ + struct send_recv_header header; + + switch (svr->seqno) + { + case 0: + if (IsLinkTaskFinished()) + { + header.ident = svr->sendIdent; + header.size = svr->sendSize; + header.crc = CalcCRC16WithTable(svr->sendBfr, svr->sendSize); + svr->sendCRC = header.crc; + svr->sendCounter = 0; + SendBlock(0, &header, sizeof(header)); + ++svr->seqno; + } + break; + case 1: + if (IsLinkTaskFinished()) + { + if (mevent_has_received(svr->sendPlayerNo)) + { + size_t blocksiz; + mevent_reset_recv(svr->sendPlayerNo); + blocksiz = 252 * svr->sendCounter; + if (svr->sendSize - blocksiz <= 252) + { + SendBlock(0, svr->sendBfr + blocksiz, svr->sendSize - blocksiz); + ++svr->sendCounter; + ++svr->seqno; + } + else + { + SendBlock(0, svr->sendBfr + blocksiz, 252); + ++svr->sendCounter; + } + } + } + break; + case 2: + if (IsLinkTaskFinished()) + { + if (CalcCRC16WithTable(svr->sendBfr, svr->sendSize) != svr->sendCRC) + sub_8010198(); + else + ++svr->seqno; + } + break; + case 3: + if (mevent_has_received(svr->sendPlayerNo)) + { + mevent_reset_recv(svr->sendPlayerNo); + svr->seqno = 0; + return TRUE; + } + break; + } + + return FALSE; +} diff --git a/src/mevent_server_ish.c b/src/mevent_server_ish.c index 2b310c981..0303bfd9b 100644 --- a/src/mevent_server_ish.c +++ b/src/mevent_server_ish.c @@ -14,9 +14,7 @@ static void mevent_srv_ish_init(struct mevent_srv_ish *, u32, u32); static u32 mevent_srv_ish_exec(struct mevent_srv_ish *); static void mevent_srv_ish_free_resources(struct mevent_srv_ish *); -extern const u8 gUnknown_082F2598[]; -extern const struct mevent_cmd gUnknown_8468B6C[]; -extern const struct mevent_cmd gUnknown_8468BCC[]; +extern const struct mevent_cmd_ish gUnknown_082F2598[]; void mevent_srv_ish_do_init(u32 arg) { diff --git a/src/util.c b/src/util.c index 47112774a..8aa54857a 100644 --- a/src/util.c +++ b/src/util.c @@ -218,7 +218,7 @@ int CountTrailingZeroBits(u32 value) return 0; } -u16 CalcCRC16(u8 *data, s32 length) +u16 CalcCRC16(const u8 *data, s32 length) { u16 i, j; u16 crc = 0x1121; @@ -237,7 +237,7 @@ u16 CalcCRC16(u8 *data, s32 length) return ~crc; } -u16 CalcCRC16WithTable(u8 *data, u32 length) +u16 CalcCRC16WithTable(const u8 *data, u32 length) { u16 i; u16 crc = 0x1121;