start porting mevent_server from firered

This commit is contained in:
PikalaxALT 2019-04-02 08:43:16 -04:00 committed by huderlem
parent 438521bf21
commit a455d98385
9 changed files with 150 additions and 125 deletions

View file

@ -5,115 +5,6 @@
.text
thumb_func_start mevent_srv_init_wnews
mevent_srv_init_wnews: @ 801D07C
push {r4,lr}
ldr r4, =gUnknown_02022C7C
movs r0, 0x60
bl AllocZeroed
str r0, [r4]
ldr r1, =gUnknown_082F298C
movs r2, 0
movs r3, 0x1
bl mevent_srv_init_common
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end mevent_srv_init_wnews
thumb_func_start mevent_srv_new_wcard
mevent_srv_new_wcard: @ 801D0A0
push {r4,lr}
ldr r4, =gUnknown_02022C7C
movs r0, 0x60
bl AllocZeroed
str r0, [r4]
ldr r1, =gUnknown_082F29EC
movs r2, 0
movs r3, 0x1
bl mevent_srv_init_common
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end mevent_srv_new_wcard
thumb_func_start mevent_srv_common_do_exec
mevent_srv_common_do_exec: @ 801D0C4
push {r4-r6,lr}
adds r6, r0, 0
ldr r4, =gUnknown_02022C7C
ldr r0, [r4]
cmp r0, 0
bne _0801D0D8
movs r0, 0x3
b _0801D0F8
.pool
_0801D0D8:
bl mevent_dispatch_08145600
adds r5, r0, 0
cmp r5, 0x3
bne _0801D0F6
ldr r0, [r4]
ldr r1, [r0, 0x4]
strh r1, [r6]
bl mevent_srv_free_resources
ldr r0, [r4]
bl Free
movs r0, 0
str r0, [r4]
_0801D0F6:
adds r0, r5, 0
_0801D0F8:
pop {r4-r6}
pop {r1}
bx r1
thumb_func_end mevent_srv_common_do_exec
thumb_func_start mevent_srv_init_common
mevent_srv_init_common: @ 801D100
push {r4-r6,lr}
mov r6, r9
mov r5, r8
push {r5,r6}
adds r4, r0, 0
adds r6, r1, 0
mov r8, r2
mov r9, r3
movs r5, 0
str r5, [r4]
str r5, [r4, 0x8]
movs r0, 0xA6
lsls r0, 1
bl AllocZeroed
str r0, [r4, 0x18]
movs r0, 0xDE
lsls r0, 1
bl AllocZeroed
str r0, [r4, 0x1C]
movs r0, 0x80
lsls r0, 3
bl AllocZeroed
str r0, [r4, 0x14]
movs r0, 0x64
bl AllocZeroed
str r0, [r4, 0x20]
str r6, [r4, 0x10]
str r5, [r4, 0xC]
adds r4, 0x38
adds r0, r4, 0
mov r1, r8
mov r2, r9
bl sub_801D8D8
pop {r3,r4}
mov r8, r3
mov r9, r4
pop {r4-r6}
pop {r0}
bx r0
thumb_func_end mevent_srv_init_common
thumb_func_start mevent_srv_free_resources
mevent_srv_free_resources: @ 801D158
push {r4,lr}
@ -517,8 +408,8 @@ _0801D464:
bx r1
thumb_func_end sub_801D1F0
thumb_func_start mevent_dispatch_08145600
mevent_dispatch_08145600: @ 801D46C
thumb_func_start mevent_srv_exec_common
mevent_srv_exec_common: @ 801D46C
push {lr}
ldr r2, =gUnknown_082F2548
ldr r1, [r0, 0x8]
@ -529,6 +420,6 @@ mevent_dispatch_08145600: @ 801D46C
pop {r1}
bx r1
.pool
thumb_func_end mevent_dispatch_08145600
thumb_func_end mevent_srv_exec_common
.align 2, 0 @ don't pad with nop

View file

@ -23,8 +23,8 @@ sub_801D8CC: @ 801D8CC
bx r1
thumb_func_end sub_801D8CC
thumb_func_start sub_801D8D8
sub_801D8D8: @ 801D8D8
thumb_func_start mevent_srv_sub_init
mevent_srv_sub_init: @ 801D8D8
movs r3, 0
strb r1, [r0, 0x4]
strb r2, [r0, 0x5]
@ -43,7 +43,7 @@ sub_801D8D8: @ 801D8D8
str r1, [r0, 0x20]
bx lr
.pool
thumb_func_end sub_801D8D8
thumb_func_end mevent_srv_sub_init
thumb_func_start sub_801D904
sub_801D904: @ 801D904

View file

@ -115,7 +115,7 @@ mevent_srv_ish_init: @ 801D50C
adds r0, r4, 0
adds r1, r6, 0
mov r2, r8
bl sub_801D8D8
bl mevent_srv_sub_init
pop {r3}
mov r8, r3
pop {r4-r6}

View file

@ -242,7 +242,7 @@ gUnknown_082F292C:: @ 82F292C
.byte 0x00, 0x00, 0x00, 0x00
.align 2
gUnknown_082F298C:: @ 82F298C
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
@ -262,7 +262,7 @@ gUnknown_082F298C:: @ 82F298C
.4byte gUnknown_082F2800
.align 2
gUnknown_082F29EC:: @ 82F29EC
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

View file

@ -1,6 +1,80 @@
#ifndef GUARD_MEVENT_SERVER_H
#define GUARD_MEVENT_SERVER_H
#define ME_SEND_BUF_SIZE 0x400
struct mevent_srv_sub
{
s32 seqno;
u8 sendPlayerNo;
u8 recvPlayerNo;
u16 recvIdent;
u16 recvCounter;
u16 recvCRC;
u16 recvSize;
u16 sendIdent;
u16 sendCounter;
u16 sendCRC;
u16 sendSize;
void * recvBfr;
const void * sendBfr;
u32 (*recvFunc)(struct mevent_srv_sub *);
u32 (*sendFunc)(struct mevent_srv_sub *);
};
struct send_recv_header
{
u16 ident;
u16 crc;
u16 size;
};
struct mevent_cmd_ish
{
u32 instr;
u32 parameter;
};
struct mevent_srv_ish
{
u32 unk_00;
u32 param;
u32 mainseqno;
u32 flag;
u32 cmdidx;
void * sendBuffer;
void * recvBuffer;
struct mevent_cmd_ish * cmdBuffer;
void * buffer;
struct mevent_srv_sub manager;
};
struct mevent_cmd
{
u32 instr;
bool32 flag;
void * parameter;
};
struct mevent_srv_common
{
u32 unk_00;
u32 param;
u32 mainseqno;
u32 cmdidx;
const struct mevent_cmd * cmdBuffer;
void * recvBuffer;
struct MEventBuffer_32E0_Sub * mevent_32e0;
struct MEventBuffer_3120_Sub * mevent_3120;
struct MEventStruct_Unk1442CC * mevent_unk1442cc;
void * sendBuffer1;
u32 sendBuffer1Size;
void * sendBuffer2;
u32 sendBuffer2Size;
u32 sendWord;
struct mevent_srv_sub manager;
};
void mevent_srv_new_wcard();
void mevent_srv_init_wnews();
u32 mevent_srv_common_do_exec(u16 * a0);

View file

@ -0,0 +1,6 @@
#ifndef GUARD_MEVENT_SERVER_HELPERS_H
#define GUARD_MEVENT_SERVER_HELPERS_H
void mevent_srv_sub_init(struct mevent_srv_sub *, u32, u32);
#endif //GUARD_MEVENT_SERVER_HELPERS_H

View file

@ -60,6 +60,7 @@ SECTIONS {
src/union_room_battle.o(.text);
src/mevent2.o(.text);
src/mevent_801BAAC.o(.text);
src/mevent_server.o(.text);
asm/mevent_server.o(.text);
asm/mevent_server_ish.o(.text);
asm/mevent_server_helpers.o(.text);
@ -416,6 +417,7 @@ SECTIONS {
src/union_room_battle.o(.rodata);
src/mevent2.o(.rodata);
src/mevent_801BAAC.o(.rodata);
src/mevent_server.o(.rodata);
data/mevent_server.o(.rodata);
src/union_room_chat.o(.rodata);
data/union_room_chat.o(.rodata);

56
src/mevent_server.c Normal file
View file

@ -0,0 +1,56 @@
#include "global.h"
#include "alloc.h"
#include "mevent.h"
#include "mevent_server.h"
#include "mevent_server_helpers.h"
EWRAM_DATA struct mevent_srv_common * s_mevent_srv_common_ptr = NULL;
EWRAM_DATA struct mevent_srv_ish * s_mevent_srv_ish_ptr = NULL;
static void mevent_srv_init_common(struct mevent_srv_common *, const void *, u32, u32);
u32 mevent_srv_exec_common(struct mevent_srv_common *);
u32 mevent_srv_free_resources(struct mevent_srv_common *);
extern const struct mevent_cmd s_mevent_wonder_news[];
extern const struct mevent_cmd s_mevent_wonder_card[];
void mevent_srv_init_wnews(void)
{
s_mevent_srv_common_ptr = AllocZeroed(sizeof(struct mevent_srv_common));
mevent_srv_init_common(s_mevent_srv_common_ptr, s_mevent_wonder_news, 0, 1);
}
void mevent_srv_new_wcard(void)
{
s_mevent_srv_common_ptr = AllocZeroed(sizeof(struct mevent_srv_common));
mevent_srv_init_common(s_mevent_srv_common_ptr, s_mevent_wonder_card, 0, 1);
}
u32 mevent_srv_common_do_exec(u16 * a0)
{
u32 result;
if (s_mevent_srv_common_ptr == NULL)
return 3;
result = mevent_srv_exec_common(s_mevent_srv_common_ptr);
if (result == 3)
{
*a0 = s_mevent_srv_common_ptr->param;
mevent_srv_free_resources(s_mevent_srv_common_ptr);
Free(s_mevent_srv_common_ptr);
s_mevent_srv_common_ptr = NULL;
}
return result;
}
static void mevent_srv_init_common(struct mevent_srv_common * svr, const void * cmdBuffer, u32 sendPlayerNo, u32 recvPlayerNo)
{
svr->unk_00 = 0;
svr->mainseqno = 0;
svr->mevent_32e0 = AllocZeroed(sizeof(struct MEventBuffer_32E0_Sub));
svr->mevent_3120 = AllocZeroed(sizeof(struct MEventBuffer_3120_Sub));
svr->recvBuffer = AllocZeroed(ME_SEND_BUF_SIZE);
svr->mevent_unk1442cc = AllocZeroed(sizeof(struct MEventStruct_Unk1442CC));
svr->cmdBuffer = cmdBuffer;
svr->cmdidx = 0;
mevent_srv_sub_init(&svr->manager, sendPlayerNo, recvPlayerNo);
}

View file

@ -12,14 +12,10 @@
.include "src/union_room_battle.o"
.include "src/mevent2.o"
.include "src/mevent_801BAAC.o"
.include "src/mevent_server.o"
@ mevent_server
gUnknown_02022C7C: @ 2022C7C
.space 0x4
s_mevent_srv_ish_ptr: @ 2022C80
.space 0x4
@ union_room_chat
.align 2
gUnknown_02022C84: @ 2022C84
.space 0x4