[Reduction] #685: ldtrunc

This commit is contained in:
nmlgc 2014-11-09 14:49:18 +01:00
parent 03139534f7
commit 84180b9cd9
4 changed files with 154 additions and 179 deletions

View File

@ -7,6 +7,7 @@ include libs/BorlandC/RULES.ASI
include libs/BorlandC/ctype.inc
include libs/BorlandC/dos.inc
include libs/BorlandC/doserror.inc
include libs/BorlandC/errno.inc
include libs/BorlandC/fcntl.inc
include libs/BorlandC/stdio.inc
include libs/BorlandC/_printf.inc

53
libs/BorlandC/errno.inc Normal file
View File

@ -0,0 +1,53 @@
; Dos Error Codes
EZERO equ 0 ; Error 0
EINVFNC equ 1 ; Invalid function number
ENOFILE equ 2 ; File not found
ENOPATH equ 3 ; Path not found
ECONTR equ 7 ; Memory blocks destroyed
EINVMEM equ 9 ; Invalid memory block address
EINVENV equ 10 ; Invalid environment
EINVFMT equ 11 ; Invalid format
EINVACC equ 12 ; Invalid access code
EINVDAT equ 13 ; Invalid data
EINVDRV equ 15 ; Invalid drive specified
ECURDIR equ 16 ; Attempt to remove CurDir
ENOTSAM equ 17 ; Not same device
ENMFILE equ 18 ; No more files
ENOENT equ 2 ; No such file or directory
EMFILE equ 4 ; Too many open files
EACCES equ 5 ; Permission denied
EBADF equ 6 ; Bad file number
ENOMEM equ 8 ; Not enough core
EFAULT equ 14 ; Unknown error
ENODEV equ 15 ; No such device
EINVAL equ 19 ; Invalid argument
E2BIG equ 20 ; Arg list too long
ENOEXEC equ 21 ; Exec format error
EXDEV equ 22 ; Cross-device link
ENFILE equ 23 ; UNIX - not MSDOS
ECHILD equ 24 ; Unix/DOS
ENOTTY equ 25 ; UNIX - not MSDOS
ETXTBSY equ 26 ; UNIX - not MSDOS
EFBIG equ 27 ; UNIX - not MSDOS
ENOSPC equ 28 ; UNIX - not MSDOS
ESPIPE equ 29 ; UNIX - not MSDOS
EROFS equ 30 ; UNIX - not MSDOS
EMLINK equ 31 ; UNIX - not MSDOS
EPIPE equ 32 ; UNIX - not MSDOS
EDOM equ 33 ; Math argument
ERANGE equ 34 ; Result too large
EEXIST equ 35 ; File already exists
EDEADLOCK equ 36 ; Locking violation
EPERM equ 37 ; UNIX - not MSDOS
ESRCH equ 38 ; UNIX - not MSDOS
EINTR equ 39 ; UNIX - not MSDOS
EIO equ 40 ; UNIX - not MSDOS
ENXIO equ 41 ; UNIX - not MSDOS
EAGAIN equ 42 ; UNIX - not MSDOS
ENOTBLK equ 43 ; UNIX - not MSDOS
EBUSY equ 44 ; UNIX - not MSDOS
ENOTDIR equ 45 ; UNIX - not MSDOS
EISDIR equ 46 ; UNIX - not MSDOS
EUCLEAN equ 47 ; UNIX - not MSDOS

View File

@ -0,0 +1,97 @@
; double __pascal __near _ldtrunc(int flag, long double x, double xhuge)
__ldtrunc proc near
@@xfloat = qword ptr -0Ch
@@cword2 = word ptr -4
@@cword = word ptr -2
@@xhuge = qword ptr 4
@@x = tbyte ptr 0Ch
@@flag = word ptr 16h
push bp
mov bp, sp
sub sp, 0Ch
xor cx, cx
mov ax, 43FEh
mov bx, 3BCDh
cmp [bp+@@flag], 0
jnz short @@start
mov ax, 407Eh
mov bx, 3F6Ah
@@start:
mov dx, word ptr [bp+@@x+8]
shl dx, 1
rcl cx, 1
shr dx, 1
cmp dx, 7FFFh
jz short @@ret
cmp dx, ax
jz short @@hugex
jle short @@notinf
fld [bp+@@xhuge]
jmp short @@ret1
@@hugex:
fstcw [bp+@@cword]
mov ax, 0C00h
fwait
or ax, [bp+@@cword]
mov [bp+@@cword2], ax
fldcw [bp+@@cword2]
fld [bp+@@x]
cmp [bp+@@flag], 0
jnz short @@s1
fstp dword ptr [bp+@@xhuge]
fld dword ptr [bp+@@xhuge]
jmp short @@s2
@@s1:
fstp [bp+@@xhuge]
fld [bp+@@xhuge]
@@s2:
fldcw [bp+@@cword]
mov sp, bp
pop bp
ret 14h
@@notinf:
mov ax, dx
or ax, word ptr [bp+@@x+6]
or ax, word ptr [bp+@@x+4]
or ax, word ptr [bp+@@x+2]
or ax, word ptr [bp+@@x]
jz short @@ret
cmp dx, bx
jge short @@ret
fldz
@@ret1:
or cx, cx
jz short @@ret0
fchs
@@ret0:
mov _errno, ERANGE
mov sp, bp
pop bp
ret 14h
@@ret:
cmp [bp+@@flag], 0
jz short @@single
fld [bp+@@x]
fstp [bp+@@xfloat]
fld [bp+@@xfloat]
jmp short @@end
@@single:
fld [bp+@@x]
fstp dword ptr [bp+@@xfloat]
fld dword ptr [bp+@@xfloat]
@@end:
mov sp, bp
pop bp
ret 14h
__ldtrunc endp

View File

@ -106,183 +106,7 @@ include libs/master.lib/isqrt.asm
include libs/master.lib/random.asm
include libs/BorlandC/emu/nec_fpinit.asm
include libs/BorlandC/math/ctrl87.asm
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
; int __stdcall sub_19D8(double, long double, int)
sub_19D8 proc near
var_C = qword ptr -0Ch
var_4 = word ptr -4
var_2 = word ptr -2
arg_0 = qword ptr 4
arg_8 = tbyte ptr 0Ch
arg_12 = word ptr 16h
push bp
mov bp, sp
sub sp, 0Ch
xor cx, cx
mov ax, 43FEh
mov bx, 3BCDh
cmp [bp+arg_12], 0
jnz short loc_19F2
mov ax, 407Eh
mov bx, 3F6Ah
loc_19F2:
mov dx, word ptr [bp+arg_8+8]
shl dx, 1
rcl cx, 1
shr dx, 1
cmp dx, 7FFFh
jz short loc_1A70
cmp dx, ax
jz short loc_1A0D
jle short loc_1A46
; Hack (fld [bp+arg_0])
db 0cdh
db 039h
db 046h
db 004h
jmp short loc_1A5D
; ---------------------------------------------------------------------------
loc_1A0D:
; Hack (fnstcw [bp+var_2])
db 0cdh
db 035h
db 07eh
db 0feh
mov ax, 0C00h
; Hack (wait)
db 0cdh
db 03dh
or ax, [bp+var_2]
mov [bp+var_4], ax
; Hack (fldcw [bp+var_4])
db 0cdh
db 035h
db 06eh
db 0fch
; Hack (fld [bp+arg_8])
db 0cdh
db 037h
db 06eh
db 00ch
cmp [bp+arg_12], 0
jnz short loc_1A34
; Hack (fstp dword ptr [bp+arg_0])
db 0cdh
db 035h
db 05eh
db 004h
; Hack (fld dword ptr [bp+arg_0])
db 0cdh
db 035h
db 046h
db 004h
jmp short loc_1A3C
; ---------------------------------------------------------------------------
loc_1A34:
; Hack (fstp [bp+arg_0])
db 0cdh
db 039h
db 05eh
db 004h
; Hack (fld [bp+arg_0])
db 0cdh
db 039h
db 046h
db 004h
loc_1A3C:
; Hack (fldcw [bp+var_2])
db 0cdh
db 035h
db 06eh
db 0feh
mov sp, bp
pop bp
retn 14h
; ---------------------------------------------------------------------------
loc_1A46:
mov ax, dx
or ax, word ptr [bp+arg_8+6]
or ax, word ptr [bp+arg_8+4]
or ax, word ptr [bp+arg_8+2]
or ax, word ptr [bp+arg_8]
jz short loc_1A70
cmp dx, bx
jge short loc_1A70
; Hack (fldz)
db 0cdh
db 035h
db 0eeh
loc_1A5D:
or cx, cx
jz short loc_1A64
; Hack (fchs)
db 0cdh
db 035h
db 0e0h
loc_1A64:
mov _errno, 22h ; '"'
mov sp, bp
pop bp
retn 14h
; ---------------------------------------------------------------------------
loc_1A70:
cmp [bp+arg_12], 0
jz short loc_1A84
; Hack (fld [bp+arg_8])
db 0cdh
db 037h
db 06eh
db 00ch
; Hack (fstp [bp+var_C])
db 0cdh
db 039h
db 05eh
db 0f4h
; Hack (fld [bp+var_C])
db 0cdh
db 039h
db 046h
db 0f4h
jmp short loc_1A90
; ---------------------------------------------------------------------------
loc_1A84:
; Hack (fld [bp+arg_8])
db 0cdh
db 037h
db 06eh
db 00ch
; Hack (fstp dword ptr [bp+var_C])
db 0cdh
db 035h
db 05eh
db 0f4h
; Hack (fld dword ptr [bp+var_C])
db 0cdh
db 035h
db 046h
db 0f4h
loc_1A90:
mov sp, bp
pop bp
retn 14h
sub_19D8 endp
include libs/BorlandC/math/ldtrunc.asm
include libs/BorlandC/math/realcvt.asm
; =============== S U B R O U T I N E =======================================
@ -884,7 +708,7 @@ arg_4 = word ptr 8
; Hack (wait)
db 0cdh
db 03dh
call sub_19D8
call __ldtrunc
les bx, [bp+arg_0]
; Hack (fstp qword ptr es:[bx])
db 0cdh
@ -940,7 +764,7 @@ loc_1FD4:
; Hack (wait)
db 0cdh
db 03dh
call sub_19D8
call __ldtrunc
les bx, [bp+arg_0]
; Hack (fstp dword ptr es:[bx])
db 0cdh