From fb03ce1ad31943fd48cb15439ee4dbd08d300727 Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Wed, 12 May 2021 21:58:02 +0800 Subject: move out mthread code --- asm/Makefile | 2 +- asm/rich4.asm | 239 ++++---------------------------------------- asm/rich4_crt_mthread.asm | 250 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 271 insertions(+), 220 deletions(-) create mode 100644 asm/rich4_crt_mthread.asm diff --git a/asm/Makefile b/asm/Makefile index b6c8c21..0a175e7 100644 --- a/asm/Makefile +++ b/asm/Makefile @@ -7,7 +7,7 @@ LIBS+=-lmsvcrt OBJS = rich4.obj rich4_time.obj card_strings.obj stocks_data.obj card_table.obj tool_strings.obj \ players.obj \ - rich4_clib.obj + rich4_crt_mthread.obj rich4_clib.obj rich4.exe: $(OBJS) $(LD) -o $@ $(OBJS) $(LDFLAGS) $(LIBS) diff --git a/asm/rich4.asm b/asm/rich4.asm index ba35f0c..f152319 100644 --- a/asm/rich4.asm +++ b/asm/rich4.asm @@ -176,6 +176,26 @@ extern clib_rand extern clib_srand global _GetThreadPtr +extern __AllocInitThreadData +extern __NTAddThread +extern __NTRemoveThread +extern __NTThreadFini +global clib_free +global fcn_0045c836 +global fcn_0045e8ca +global __GetThreadData +global __InitThreadData +global lib_calloc +global __ReallocThreadData +global ref_00488f78 +global ref_00488f7c +global ref_00499954 +global _RWD_osbuild +global _RWD_osmajor +global __ThreadDataSize +global __TlsIndex + + section .text db 0xcc db 0xeb @@ -121362,177 +121382,6 @@ fcn_0045a1f3: push ref_0049932c ; push 0x49932c jmp near loc_0045a155 ; jmp 0x45a155 -__MultipleThread: -push ebx -push esi -call dword [cs:__imp__GetLastError@0] ; ucall: call dword cs:[0x4623ac] -mov edx, dword [__TlsIndex] ; mov edx, dword [0x488f48] -push edx -mov esi, eax -call dword [cs:__imp__TlsGetValue@4] ; ucall: call dword cs:[0x46241c] -mov ebx, eax -test eax, eax -jne short loc_0045a223 ; jne 0x45a223 -call __GetThreadData ; call 0x45c6be -jmp short loc_0045a22e ; jmp 0x45a22e - -loc_0045a223: -cmp byte [eax + 0x53], 0 -je short loc_0045a230 ; je 0x45a230 -call __ReallocThreadData ; call 0x45c6f5 - -loc_0045a22e: -mov ebx, eax - -loc_0045a230: -push esi -call dword [cs:__imp__SetLastError@4] ; ucall: call dword cs:[0x462408] -mov eax, ebx -pop esi -pop ebx -ret - -__AllocInitThreadData: -push ebx -mov ebx, dword [esp + 8] -test ebx, ebx -jne short loc_0045a26d ; jne 0x45a26d -mov edx, dword [__ThreadDataSize] ; mov edx, dword [0x4894b0] -push edx -push 1 -call lib_calloc ; call 0x45c62e -add esp, 8 -mov ebx, eax -test eax, eax -je short loc_0045a26d ; je 0x45a26d -mov edx, dword [__ThreadDataSize] ; mov edx, dword [0x4894b0] -mov byte [eax + 0x52], 1 -mov dword [eax + 0xf0], edx - -loc_0045a26d: -push ebx -call __InitThreadData ; call 0x45c8d7 -add esp, 4 -mov eax, ebx -pop ebx -ret - -__NTThreadInit: -call dword [cs:__imp__TlsAlloc@0] ; ucall: call dword cs:[0x462414] -mov dx, word [_RWD_osbuild] ; mov dx, word [0x489355] -mov dword [__TlsIndex], eax ; mov dword [0x488f48], eax -cmp dx, 0x8000 -jb short loc_0045a2bb ; jb 0x45a2bb -cmp byte [_RWD_osmajor], 4 ; cmp byte [0x489353], 4 -jae short loc_0045a2bb ; jae 0x45a2bb - -loc_0045a29d: -mov edx, dword [__TlsIndex] ; mov edx, dword [0x488f48] -cmp edx, 0xffffffff -je short loc_0045a2bb ; je 0x45a2bb -cmp edx, 2 -ja short loc_0045a2bb ; ja 0x45a2bb -call dword [cs:__imp__TlsAlloc@0] ; ucall: call dword cs:[0x462414] -mov dword [__TlsIndex], eax ; mov dword [0x488f48], eax -jmp short loc_0045a29d ; jmp 0x45a29d - -loc_0045a2bb: -cmp dword [__TlsIndex], 0xffffffff ; cmp dword [0x488f48], 0xffffffff -setne al -and eax, 0xff -ret - -__NTAddThread: -push ebx -push esi -cmp dword [__TlsIndex], 0xffffffff ; cmp dword [0x488f48], 0xffffffff -jne short loc_0045a2db ; jne 0x45a2db - -loc_0045a2d6: -xor eax, eax -pop esi -pop ebx -ret - -loc_0045a2db: -mov ebx, dword [esp + 0xc] -push ebx -call __AllocInitThreadData ; call 0x45a23d -mov ebx, eax -add esp, 4 -test eax, eax -je short loc_0045a321 ; je 0x45a321 -push eax -mov ecx, dword [eax + 0xda] -push ecx -call __AddThreadData ; call 0x45c7ca -add esp, 8 -test eax, eax -jne short loc_0045a30d ; jne 0x45a30d -push ebx -call clib_free ; call 0x456e11 -add esp, 4 -jmp short loc_0045a2d6 ; jmp 0x45a2d6 - -loc_0045a30d: -push ebx -mov esi, dword [__TlsIndex] ; mov esi, dword [0x488f48] -push esi -call dword [cs:__imp__TlsSetValue@8] ; ucall: call dword cs:[0x462420] -mov eax, 1 - -loc_0045a321: -pop esi -pop ebx -ret - -__NTRemoveThread: -push ebx -push esi -mov edx, dword [__TlsIndex] ; mov edx, dword [0x488f48] -cmp edx, 0xffffffff -je short loc_0045a375 ; je 0x45a375 -push edx -call dword [cs:__imp__TlsGetValue@4] ; ucall: call dword cs:[0x46241c] -test eax, eax -je short loc_0045a375 ; je 0x45a375 -mov ecx, dword [eax + 0xda] -push ecx -mov ebx, dword [eax + 0xde] -call fcn_0045c836 ; call 0x45c836 -add esp, 4 -push 0 -mov esi, dword [__TlsIndex] ; mov esi, dword [0x488f48] -push esi -call dword [cs:__imp__TlsSetValue@8] ; ucall: call dword cs:[0x462420] -test ebx, ebx -je short loc_0045a375 ; je 0x45a375 -cmp dword [esp + 0xc], 0 -je short loc_0045a375 ; je 0x45a375 -push ebx -call dword [cs:__imp__CloseHandle@4] ; ucall: call dword cs:[0x462348] - -loc_0045a375: -pop esi -pop ebx -ret - -__ThreadExit: -push 1 -call __NTRemoveThread ; call 0x45a324 -add esp, 4 - -__NTThreadFini: -mov edx, dword [__TlsIndex] ; mov edx, dword [0x488f48] -cmp edx, 0xffffffff -je short loc_0045a39f ; je 0x45a39f -push edx -call dword [cs:__imp__TlsFree@4] ; ucall: call dword cs:[0x462418] -mov dword [__TlsIndex], 0xffffffff ; mov dword [0x488f48], 0xffffffff - -loc_0045a39f: -ret - fcn_0045a4c0: push ebx @@ -125667,54 +125516,6 @@ pop esi pop ebx ret -__AddThreadData: -push ebx -push esi -push edi -mov edi, dword [esp + 0x14] -call dword [ref_00488f78] ; ucall: call dword [0x488f78] -push 0x10 -mov esi, 1 -push esi -call lib_calloc ; call 0x45c62e -mov ebx, eax -add esp, 8 -test eax, eax -je short loc_0045c828 ; je 0x45c828 -push edi -call fcn_0045e8ca ; call 0x45e8ca -add esp, 4 -test eax, eax -je short loc_0045c807 ; je 0x45c807 -push ebx -call clib_free ; call 0x456e11 -xor esi, esi -add esp, 4 -jmp short loc_0045c82a ; jmp 0x45c82a - -loc_0045c807: -mov eax, dword [esp + 0x10] -mov dword [ebx + 8], edi -mov dword [ebx + 4], eax -xor eax, eax -mov al, byte [edi + 0x52] -mov dword [ebx + 0xc], eax -mov eax, dword [ref_00499954] ; mov eax, dword [0x499954] -mov dword [ref_00499954], ebx ; mov dword [0x499954], ebx -mov dword [ebx], eax -jmp short loc_0045c82a ; jmp 0x45c82a - -loc_0045c828: -xor esi, esi - -loc_0045c82a: -call dword [ref_00488f7c] ; ucall: call dword [0x488f7c] -mov eax, esi -pop edi -pop esi -pop ebx -ret - fcn_0045c836: push ebx push esi diff --git a/asm/rich4_crt_mthread.asm b/asm/rich4_crt_mthread.asm new file mode 100644 index 0000000..26e66b7 --- /dev/null +++ b/asm/rich4_crt_mthread.asm @@ -0,0 +1,250 @@ +global __AllocInitThreadData +global __NTAddThread +global __NTRemoveThread +global __NTThreadFini + +extern __imp__GetLastError@0 +extern __imp__CloseHandle@4 +extern __imp__SetLastError@4 +extern __imp__TlsAlloc@0 +extern __imp__TlsFree@4 +extern __imp__TlsGetValue@4 +extern __imp__TlsSetValue@8 +extern clib_free +extern fcn_0045c836 +extern fcn_0045e8ca +extern __GetThreadData +extern __InitThreadData +extern lib_calloc +extern __ReallocThreadData +extern ref_00488f78 +extern ref_00488f7c +extern ref_00499954 +extern _RWD_osbuild +extern _RWD_osmajor +extern __ThreadDataSize +extern __TlsIndex + + +section .text + +__MultipleThread: +push ebx +push esi +call dword [cs:__imp__GetLastError@0] ; ucall: call dword cs:[0x4623ac] +mov edx, dword [__TlsIndex] ; mov edx, dword [0x488f48] +push edx +mov esi, eax +call dword [cs:__imp__TlsGetValue@4] ; ucall: call dword cs:[0x46241c] +mov ebx, eax +test eax, eax +jne short loc_0045a223 ; jne 0x45a223 +call __GetThreadData ; call 0x45c6be +jmp short loc_0045a22e ; jmp 0x45a22e + +loc_0045a223: +cmp byte [eax + 0x53], 0 +je short loc_0045a230 ; je 0x45a230 +call __ReallocThreadData ; call 0x45c6f5 + +loc_0045a22e: +mov ebx, eax + +loc_0045a230: +push esi +call dword [cs:__imp__SetLastError@4] ; ucall: call dword cs:[0x462408] +mov eax, ebx +pop esi +pop ebx +ret + +__AllocInitThreadData: +push ebx +mov ebx, dword [esp + 8] +test ebx, ebx +jne short loc_0045a26d ; jne 0x45a26d +mov edx, dword [__ThreadDataSize] ; mov edx, dword [0x4894b0] +push edx +push 1 +call lib_calloc ; call 0x45c62e +add esp, 8 +mov ebx, eax +test eax, eax +je short loc_0045a26d ; je 0x45a26d +mov edx, dword [__ThreadDataSize] ; mov edx, dword [0x4894b0] +mov byte [eax + 0x52], 1 +mov dword [eax + 0xf0], edx + +loc_0045a26d: +push ebx +call __InitThreadData ; call 0x45c8d7 +add esp, 4 +mov eax, ebx +pop ebx +ret + +__NTThreadInit: +call dword [cs:__imp__TlsAlloc@0] ; ucall: call dword cs:[0x462414] +mov dx, word [_RWD_osbuild] ; mov dx, word [0x489355] +mov dword [__TlsIndex], eax ; mov dword [0x488f48], eax +cmp dx, 0x8000 +jb short loc_0045a2bb ; jb 0x45a2bb +cmp byte [_RWD_osmajor], 4 ; cmp byte [0x489353], 4 +jae short loc_0045a2bb ; jae 0x45a2bb + +loc_0045a29d: +mov edx, dword [__TlsIndex] ; mov edx, dword [0x488f48] +cmp edx, 0xffffffff +je short loc_0045a2bb ; je 0x45a2bb +cmp edx, 2 +ja short loc_0045a2bb ; ja 0x45a2bb +call dword [cs:__imp__TlsAlloc@0] ; ucall: call dword cs:[0x462414] +mov dword [__TlsIndex], eax ; mov dword [0x488f48], eax +jmp short loc_0045a29d ; jmp 0x45a29d + +loc_0045a2bb: +cmp dword [__TlsIndex], 0xffffffff ; cmp dword [0x488f48], 0xffffffff +setne al +and eax, 0xff +ret + +__NTAddThread: +push ebx +push esi +cmp dword [__TlsIndex], 0xffffffff ; cmp dword [0x488f48], 0xffffffff +jne short loc_0045a2db ; jne 0x45a2db + +loc_0045a2d6: +xor eax, eax +pop esi +pop ebx +ret + +loc_0045a2db: +mov ebx, dword [esp + 0xc] +push ebx +call __AllocInitThreadData ; call 0x45a23d +mov ebx, eax +add esp, 4 +test eax, eax +je short loc_0045a321 ; je 0x45a321 +push eax +mov ecx, dword [eax + 0xda] +push ecx +call __AddThreadData ; call 0x45c7ca +add esp, 8 +test eax, eax +jne short loc_0045a30d ; jne 0x45a30d +push ebx +call clib_free ; call 0x456e11 +add esp, 4 +jmp short loc_0045a2d6 ; jmp 0x45a2d6 + +loc_0045a30d: +push ebx +mov esi, dword [__TlsIndex] ; mov esi, dword [0x488f48] +push esi +call dword [cs:__imp__TlsSetValue@8] ; ucall: call dword cs:[0x462420] +mov eax, 1 + +loc_0045a321: +pop esi +pop ebx +ret + +__NTRemoveThread: +push ebx +push esi +mov edx, dword [__TlsIndex] ; mov edx, dword [0x488f48] +cmp edx, 0xffffffff +je short loc_0045a375 ; je 0x45a375 +push edx +call dword [cs:__imp__TlsGetValue@4] ; ucall: call dword cs:[0x46241c] +test eax, eax +je short loc_0045a375 ; je 0x45a375 +mov ecx, dword [eax + 0xda] +push ecx +mov ebx, dword [eax + 0xde] +call fcn_0045c836 ; call 0x45c836 +add esp, 4 +push 0 +mov esi, dword [__TlsIndex] ; mov esi, dword [0x488f48] +push esi +call dword [cs:__imp__TlsSetValue@8] ; ucall: call dword cs:[0x462420] +test ebx, ebx +je short loc_0045a375 ; je 0x45a375 +cmp dword [esp + 0xc], 0 +je short loc_0045a375 ; je 0x45a375 +push ebx +call dword [cs:__imp__CloseHandle@4] ; ucall: call dword cs:[0x462348] + +loc_0045a375: +pop esi +pop ebx +ret + +__ThreadExit: +push 1 +call __NTRemoveThread ; call 0x45a324 +add esp, 4 + +__NTThreadFini: +mov edx, dword [__TlsIndex] ; mov edx, dword [0x488f48] +cmp edx, 0xffffffff +je short loc_0045a39f ; je 0x45a39f +push edx +call dword [cs:__imp__TlsFree@4] ; ucall: call dword cs:[0x462418] +mov dword [__TlsIndex], 0xffffffff ; mov dword [0x488f48], 0xffffffff + +loc_0045a39f: +ret + + ;; trdlist.c + +__AddThreadData: +push ebx +push esi +push edi +mov edi, dword [esp + 0x14] +call dword [ref_00488f78] ; ucall: call dword [0x488f78] +push 0x10 +mov esi, 1 +push esi +call lib_calloc ; call 0x45c62e +mov ebx, eax +add esp, 8 +test eax, eax +je short loc_0045c828 ; je 0x45c828 +push edi +call fcn_0045e8ca ; call 0x45e8ca +add esp, 4 +test eax, eax +je short loc_0045c807 ; je 0x45c807 +push ebx +call clib_free ; call 0x456e11 +xor esi, esi +add esp, 4 +jmp short loc_0045c82a ; jmp 0x45c82a + +loc_0045c807: +mov eax, dword [esp + 0x10] +mov dword [ebx + 8], edi +mov dword [ebx + 4], eax +xor eax, eax +mov al, byte [edi + 0x52] +mov dword [ebx + 0xc], eax +mov eax, dword [ref_00499954] ; mov eax, dword [0x499954] +mov dword [ref_00499954], ebx ; mov dword [0x499954], ebx +mov dword [ebx], eax +jmp short loc_0045c82a ; jmp 0x45c82a + +loc_0045c828: +xor esi, esi + +loc_0045c82a: +call dword [ref_00488f7c] ; ucall: call dword [0x488f7c] +mov eax, esi +pop edi +pop esi +pop ebx +ret -- cgit v1.2.3