From dfc9361b33730dbd0c89e0151b80a6018afe59ed Mon Sep 17 00:00:00 2001 From: nmlgc Date: Mon, 10 Nov 2014 18:57:34 +0100 Subject: [PATCH] [Reduction] #690: farcalloc --- libs/BorlandC/fcalloc.asm | 112 ++++++++++++++++++++++++++++++++++++++ th01_reiiden.asm | 93 +------------------------------ 2 files changed, 113 insertions(+), 92 deletions(-) create mode 100644 libs/BorlandC/fcalloc.asm diff --git a/libs/BorlandC/fcalloc.asm b/libs/BorlandC/fcalloc.asm new file mode 100644 index 00000000..7ef1ca0d --- /dev/null +++ b/libs/BorlandC/fcalloc.asm @@ -0,0 +1,112 @@ +ife LDATA +; void __pascal __near _lsetmem(char far *p, unsigned int n, unsigned __int8 val) +_lsetmem proc +@@val = byte ptr (cPtrSize + 2) +@@n = word ptr (cPtrSize + 4) +@@p = dword ptr (cPtrSize + 6) + + push bp + mov bp, sp + push si + push di + cld + les di, [bp+@@p] + mov cx, [bp+@@n] + mov al, [bp+@@val] + rep stosb + pop di + pop si + pop bp + ret 8 +_lsetmem endp +endif + +; void far *__cdecl farcalloc(unsigned __int32 nunits, unsigned __int32 unitsz) +_farcalloc proc +@@sval = word ptr -0Ah +@@scp = dword ptr -8 +@@cp = dword ptr -4 +@@nunits = dword ptr (cPtrSize + 2) +@@unitsz = dword ptr (cPtrSize + 6) + + push bp + mov bp, sp + sub sp, 0Ah + push si + push di + mov cx, word ptr [bp+@@unitsz+2] + mov bx, word ptr [bp+@@unitsz] + mov dx, word ptr [bp+@@nunits+2] + mov ax, word ptr [bp+@@nunits] + call N_LXMUL@ + mov word ptr [bp+@@nunits+2], dx + mov word ptr [bp+@@nunits], ax + push dx + push ax + nopcall _farmalloc + pop cx + pop cx + mov word ptr [bp+@@cp+2], dx + mov word ptr [bp+@@cp], ax + or ax, dx + jz short @@ret + mov ax, word ptr [bp+@@cp] + mov word ptr [bp+@@scp+2], dx + mov word ptr [bp+@@scp], ax + jmp short @@nunitsLeft? + +@@loop: + cmp word ptr [bp+@@nunits+2], 0 + jb short @@nunitsTake + ja short @@nunitsClamp + cmp word ptr [bp+@@nunits], 64000 + jbe short @@nunitsTake + +@@nunitsClamp: + mov ax, 64000 + jmp short @@setmem + +@@nunitsTake: + mov ax, word ptr [bp+@@nunits] + +@@setmem: + mov [bp+@@sval], ax +ife LDATA + push word ptr [bp+@@scp+2] + push word ptr [bp+@@scp] + push ax +endif + mov al, 0 + push ax +if LDATA + push [bp+@@sval] + push word ptr [bp+@@scp+2] + push word ptr [bp+@@scp] + nopcall _setmem + add sp, 8 +else + call _lsetmem +endif + mov bx, [bp+@@sval] + xor cx, cx + mov dx, ss + lea ax, [bp+@@scp] + call N_PADA@ + mov ax, [bp+@@sval] + sub word ptr [bp+@@nunits], ax + sbb word ptr [bp+@@nunits+2], 0 + +@@nunitsLeft?: + mov ax, word ptr [bp+@@nunits] + or ax, word ptr [bp+@@nunits+2] + jnz short @@loop + +@@ret: + mov dx, word ptr [bp+@@cp+2] + mov ax, word ptr [bp+@@cp] + pop di + pop si + mov sp, bp + pop bp + ret +_farcalloc endp diff --git a/th01_reiiden.asm b/th01_reiiden.asm index ad81a26b..b21873fd 100644 --- a/th01_reiiden.asm +++ b/th01_reiiden.asm @@ -1022,98 +1022,7 @@ sub_4275 endp include libs/BorlandC/cputype.asm include libs/BorlandC/FARHEAP.ASM include libs/BorlandC/fbrk.asm - -; =============== S U B R O U T I N E ======================================= - -; Attributes: library function bp-based frame - -; void far *__cdecl farcalloc(unsigned __int32 nunits, unsigned __int32 unitsz) -_farcalloc proc far - -_length = word ptr -0Ah -dest = dword ptr -8 -var_4 = word ptr -4 -var_2 = word ptr -2 -nunits = word ptr 6 -arg_2 = word ptr 8 -unitsz = word ptr 0Ah -arg_6 = word ptr 0Ch - - push bp - mov bp, sp - sub sp, 0Ah - push si - push di - mov cx, [bp+arg_6] - mov bx, [bp+unitsz] - mov dx, [bp+arg_2] - mov ax, [bp+nunits] - call N_LXMUL@ - mov [bp+arg_2], dx - mov [bp+nunits], ax - push dx - push ax - nopcall _farmalloc - pop cx - pop cx - mov [bp+var_2], dx - mov [bp+var_4], ax - or ax, dx - jz short loc_491E - mov ax, [bp+var_4] - mov word ptr [bp+dest+2], dx - mov word ptr [bp+dest], ax - jmp short loc_4916 -; --------------------------------------------------------------------------- - -loc_48D1: - cmp [bp+arg_2], 0 - jb short loc_48E5 - ja short loc_48E0 - cmp [bp+nunits], 0FA00h - jbe short loc_48E5 - -loc_48E0: - mov ax, 0FA00h - jmp short loc_48E8 -; --------------------------------------------------------------------------- - -loc_48E5: - mov ax, [bp+nunits] - -loc_48E8: - mov [bp+_length], ax - mov al, 0 - push ax ; value - push [bp+_length] ; length - push word ptr [bp+dest+2] - push word ptr [bp+dest] ; dest - nopcall _setmem - add sp, 8 - mov bx, [bp+_length] - xor cx, cx - mov dx, ss - lea ax, [bp+dest] - call near ptr N_PADA@ - mov ax, [bp+_length] - sub [bp+nunits], ax - sbb [bp+arg_2], 0 - -loc_4916: - mov ax, [bp+nunits] - or ax, [bp+arg_2] - jnz short loc_48D1 - -loc_491E: - mov dx, [bp+var_2] - mov ax, [bp+var_4] - pop di - pop si - mov sp, bp - pop bp - retf -_farcalloc endp ; sp-analysis failed - +include libs/BorlandC/fcalloc.asm ; =============== S U B R O U T I N E =======================================