[Reduction] #561-562: scantol

Also finally getting a macro for the recurring "pop cx if LDATA" case.
This commit is contained in:
nmlgc 2014-10-30 09:38:46 +01:00
parent 696d7f9476
commit 48088875ca
4 changed files with 308 additions and 319 deletions

View File

@ -4,6 +4,7 @@
locals
include libs/BorlandC/RULES.ASI
include libs/BorlandC/ctype.inc
include libs/BorlandC/dos.inc
include libs/BorlandC/doserror.inc
include libs/BorlandC/fcntl.inc
@ -34,3 +35,9 @@ if LDATA
push ss
endif
endm
popCX_ macro
if LDATA
pop cx
endif
endm

13
libs/BorlandC/ctype.inc Normal file
View File

@ -0,0 +1,13 @@
; character classes
_IS_SP equ 1 ; space
_IS_DIG equ 2 ; digit
_IS_UPP equ 4 ; upper case
_IS_LOW equ 8 ; lower case
_IS_HEX equ 16 ; [0..9] or [A-F] or [a-f]
_IS_CTL equ 32 ; control
_IS_PUN equ 64 ; punctuation
_IS_BLK equ 128 ; blank
_IS_ALPHA equ (_IS_UPP | _IS_LOW)
_IS_ALNUM equ (_IS_DIG | _IS_ALPHA)
_IS_GRAPH equ (_IS_ALNUM | _IS_HEX | _IS_PUN)

287
libs/BorlandC/scantol.asm Normal file
View File

@ -0,0 +1,287 @@
; void __near stl_Digit(void)
stl_Digit proc near
push si
push di
push bx
sub bl, '0'
jb short @@stld_badEnd
cmp bl, 9
jbe short @@stld_digitised
cmp bl, ('Z' - '0')
ja short @@stld_maybeLower
sub bl, ('A' - '0' - 10)
jmp short @@stld_extended
@@stld_maybeLower:
sub bl, ('a' - '0' - 10)
@@stld_extended:
cmp bl, 9
jbe short @@stld_badEnd
@@stld_digitised:
cmp bl, cl
jnb short @@stld_badEnd
inc sp
inc sp
clc
mov bh, 0
jmp short @@stld_end
@@stld_badEnd:
pop bx
stc
@@stld_end:
pop di
pop si
ret
stl_Digit endp
pushSrceP macro
if LDATA
push word ptr [bp+@@srceP+2]
endif
push word ptr [bp+@@srceP]
endm
; __int32 __cdecl __near _scantol(int (__cdecl __near *@@Get)(void *srceP, void (__cdecl __near *@@UnGet)(int ch, void *srceP), const void *@@srceP, int radix, int @@width, int *@@countP, int *@@statusP)
__scantol proc near
@@status = word ptr -6
@@ct = word ptr -4
@@sign = byte ptr -1
@@Get = word ptr 4
@@UnGet = word ptr 6
@@srceP = DPTR_ 8
@@radix = word ptr (8 + dPtrSize)
@@width = word ptr (8 + dPtrSize + 2)
@@countP = DPTR_ (8 + dPtrSize + 2 + 2)
@@statusP = DPTR_ (8 + dPtrSize + 2 + 2 + dPtrSize)
push bp
mov bp, sp
sub sp, 6
push si
push di
mov [bp+@@sign], 0
mov [bp+@@ct], 0
mov [bp+@@status], 1
@@stl_skipSpace:
inc [bp+@@ct]
pushSrceP
call [bp+@@Get]
pop cx
popCX_
or ax, ax
jl short @@stl_EOF
cbw
xchg ax, bx
test bl, 80h
jnz short @@stl_notSpace
mov di, (offset __ctype+1)
test BY0[bx+di], _IS_SP
jnz short @@stl_skipSpace
@@stl_notSpace:
xchg ax, bx
dec [bp+@@width]
jl short @@stl_noDigitSeen
cmp al, '+'
jz short @@stl_signSeen
cmp al, '-'
jnz short @@stl_signed
inc [bp+@@sign]
@@stl_signSeen:
dec [bp+@@width]
jl short @@stl_noDigitSeen
inc [bp+@@ct]
pushSrceP
call [bp+@@Get]
pop cx
popCX_
or ax, ax
jl short @@stl_EOF
@@stl_signed:
sub si, si
mov di, si
mov cx, [bp+@@radix]
jcxz short @@stl_autoRadix
cmp cx, 36
ja short @@stl_noDigitSeen
cmp cl, 2
jb short @@stl_noDigitSeen
@@stl_radixSet:
cmp al, '0'
jnz short @@stl_digitNeeded
cmp cl, 16
jnz short @@stl_nextWordDigitJmp
dec [bp+@@width]
jl short @@stl_resultJmp
inc [bp+@@ct]
pushSrceP
call [bp+@@Get]
pop cx
popCX_
cmp al, 'x'
jz short @@stl_nextWordDigitJmp
cmp al, 'X'
jz short @@stl_nextWordDigitJmp
jmp @@stl_inspectDigit
@@stl_EOF:
mov [bp+@@status], EOF
jmp short @@stl_backUp
@@stl_noDigitSeen:
mov [bp+@@status], 0
@@stl_backUp:
pushSrceP
push ax
call [bp+@@UnGet]
if LDATA
add sp, 6
else
pop cx
pop cx
endif
dec [bp+@@ct]
sub ax, ax
cwd
jmp @@stl_end
@@stl_resultJmp:
jmp @@stl_result
@@stl_autoRadix:
cmp al, '0'
mov [bp+@@radix], 10
jnz short @@stl_digitNeeded
dec [bp+@@width]
jl short @@stl_resultJmp
inc [bp+@@ct]
pushSrceP
call [bp+@@Get]
pop cx
popCX_
mov [bp+@@radix], 8
cmp al, 'x'
jz short @@stl_autoHex
cmp al, 'X'
jnz short @@stl_inspectDigit
@@stl_autoHex:
mov [bp+@@radix], 16
@@stl_nextWordDigitJmp:
jmp short @@stl_nextWordDigit
@@stl_digitNeeded:
mov cx, [bp+@@radix]
xchg ax, bx
call stl_Digit
xchg ax, bx
jb short @@stl_noDigitSeen
xchg ax, si
jmp short @@stl_nextWordDigit
@@stl_digitOnWord:
xchg ax, si
mul [bp+@@radix]
add si, ax
adc di, dx
jnz short @@stl_nextDigit
@@stl_nextWordDigit:
dec [bp+@@width]
jl short @@stl_result
inc [bp+@@ct]
pushSrceP
call [bp+@@Get]
pop cx
popCX_
@@stl_inspectDigit:
mov cx, [bp+@@radix]
xchg ax, bx
call stl_Digit
xchg ax, bx
jnb short @@stl_digitOnWord
jmp short @@stl_term
@@stl_digitOnLong:
xchg ax, si
mul cx
xchg ax, di
xchg cx, dx
mul dx
add si, di
adc ax, cx
xchg ax, di
adc dl, dh
jnz short @@stl_overflow
@@stl_nextDigit:
dec [bp+@@width]
jl short @@stl_result
inc [bp+@@ct]
pushSrceP
call [bp+@@Get]
pop cx
popCX_
mov cx, [bp+@@radix]
xchg ax, bx
call stl_Digit
xchg ax, bx
jnb short @@stl_digitOnLong
@@stl_term:
pushSrceP
push ax
call [bp+@@UnGet]
if LDATA
add sp, 6
else
pop cx
pop cx
endif
dec [bp+@@ct]
@@stl_result:
mov dx, di
xchg ax, si
cmp [bp+@@sign], 0
jz short @@stl_end
neg dx
neg ax
sbb dx, 0
@@stl_end:
LES_ di, [bp+@@countP]
mov bx, [bp+@@ct]
add ES_[di], bx
LES_ di, [bp+@@statusP]
mov bx, [bp+@@status]
mov ES_[di], bx
jmp short @@stl_ret
@@stl_overflow:
mov ax, 0FFFFh
mov dx, 7FFFh
add al, [bp+@@sign]
adc ah, 0
adc dx, 0
mov [bp+@@status], 2
jmp short @@stl_end
@@stl_ret:
pop di
pop si
mov sp, bp
pop bp
ret
__scantol endp

View File

@ -5356,325 +5356,7 @@ off_347C dw offset loc_33E1
dw offset loc_30B8
dw offset loc_30BE
; =============== S U B R O U T I N E =======================================
; Attributes: library function
sub_34A8 proc near
push si
push di
push bx
sub bl, 30h ; '0'
jb short loc_34D2
cmp bl, 9
jbe short loc_34C7
cmp bl, 2Ah ; '*'
ja short loc_34BF
sub bl, 7
jmp short loc_34C2
; ---------------------------------------------------------------------------
loc_34BF:
sub bl, 27h ; '''
loc_34C2:
cmp bl, 9
jbe short loc_34D2
loc_34C7:
cmp bl, cl
jnb short loc_34D2
inc sp
inc sp
clc
mov bh, 0
jmp short loc_34D4
; ---------------------------------------------------------------------------
loc_34D2:
pop bx
stc
loc_34D4:
pop di
pop si
retn
sub_34A8 endp
; =============== S U B R O U T I N E =======================================
; Attributes: library function bp-based frame
__scantol proc near
var_6 = word ptr -6
var_4 = word ptr -4
var_1 = byte ptr -1
arg_4 = word ptr 8
arg_6 = word ptr 0Ah
arg_8 = word ptr 0Ch
arg_A = word ptr 0Eh
arg_C = dword ptr 10h
arg_10 = dword ptr 14h
push bp
mov bp, sp
sub sp, 6
push si
push di
mov [bp+var_1], 0
mov [bp+var_4], 0
mov [bp+var_6], 1
loc_34ED:
inc [bp+var_4]
push [bp+arg_6]
push [bp+arg_4]
; Hack
db 0ffh
db 056h
db 004h
pop cx
pop cx
or ax, ax
jl short loc_3570
cbw
xchg ax, bx
test bl, 80h
jnz short loc_350E
mov di, (offset __ctype+1)
test byte ptr [bx+di], 1
jnz short loc_34ED
loc_350E:
xchg ax, bx
dec [bp+arg_A]
jl short loc_3577
cmp al, 2Bh ; '+'
jz short loc_351F
cmp al, 2Dh ; '-'
jnz short loc_3536
inc [bp+var_1]
loc_351F:
dec [bp+arg_A]
jl short loc_3577
inc [bp+var_4]
push [bp+arg_6]
push [bp+arg_4]
; Hack
db 0ffh
db 056h
db 004h
pop cx
pop cx
or ax, ax
jl short loc_3570
loc_3536:
sub si, si
mov di, si
mov cx, [bp+arg_8]
jcxz short loc_3595
cmp cx, 24h ; '$'
ja short loc_3577
cmp cl, 2
jb short loc_3577
cmp al, 30h ; '0'
jnz short loc_35C5
cmp cl, 10h
jnz short loc_35C3
dec [bp+arg_A]
jl short loc_3592
inc [bp+var_4]
push [bp+arg_6]
push [bp+arg_4]
; Hack
db 0ffh
db 056h
db 004h
pop cx
pop cx
cmp al, 78h ; 'x'
jz short loc_35C3
cmp al, 58h ; 'X'
jz short loc_35C3
jmp loc_35EF
; ---------------------------------------------------------------------------
loc_3570:
mov [bp+var_6], 0FFFFh
jmp short loc_357C
; ---------------------------------------------------------------------------
loc_3577:
mov [bp+var_6], 0
loc_357C:
push [bp+arg_6]
push [bp+arg_4]
push ax
; Hack
db 0ffh
db 056h
db 006h
add sp, 6
dec [bp+var_4]
sub ax, ax
cwd
jmp loc_3649
; ---------------------------------------------------------------------------
loc_3592:
jmp loc_3639
; ---------------------------------------------------------------------------
loc_3595:
cmp al, 30h ; '0'
mov [bp+arg_8], 0Ah
jnz short loc_35C5
dec [bp+arg_A]
jl short loc_3592
inc [bp+var_4]
push [bp+arg_6]
push [bp+arg_4]
; Hack
db 0ffh
db 056h
db 004h
pop cx
pop cx
mov [bp+arg_8], 8
cmp al, 78h ; 'x'
jz short loc_35BE
cmp al, 58h ; 'X'
jnz short loc_35EF
loc_35BE:
mov [bp+arg_8], 10h
loc_35C3:
jmp short loc_35DC
; ---------------------------------------------------------------------------
loc_35C5:
mov cx, [bp+arg_8]
xchg ax, bx
call sub_34A8
xchg ax, bx
jb short loc_3577
xchg ax, si
jmp short loc_35DC
; ---------------------------------------------------------------------------
loc_35D2:
xchg ax, si
mul [bp+arg_8]
add si, ax
adc di, dx
jnz short loc_360C
loc_35DC:
dec [bp+arg_A]
jl short loc_3639
inc [bp+var_4]
push [bp+arg_6]
push [bp+arg_4]
; Hack
db 0ffh
db 056h
db 004h
pop cx
pop cx
loc_35EF:
mov cx, [bp+arg_8]
xchg ax, bx
call sub_34A8
xchg ax, bx
jnb short loc_35D2
jmp short loc_3629
; ---------------------------------------------------------------------------
loc_35FB:
xchg ax, si
mul cx
xchg ax, di
xchg cx, dx
mul dx
add si, di
adc ax, cx
xchg ax, di
adc dl, dh
jnz short loc_365D
loc_360C:
dec [bp+arg_A]
jl short loc_3639
inc [bp+var_4]
push [bp+arg_6]
push [bp+arg_4]
; Hack
db 0ffh
db 056h
db 004h
pop cx
pop cx
mov cx, [bp+arg_8]
xchg ax, bx
call sub_34A8
xchg ax, bx
jnb short loc_35FB
loc_3629:
push [bp+arg_6]
push [bp+arg_4]
push ax
; Hack
db 0ffh
db 056h
db 006h
add sp, 6
dec [bp+var_4]
loc_3639:
mov dx, di
xchg ax, si
cmp [bp+var_1], 0
jz short loc_3649
neg dx
neg ax
sbb dx, 0
loc_3649:
les di, [bp+arg_C]
mov bx, [bp+var_4]
add es:[di], bx
les di, [bp+arg_10]
mov bx, [bp+var_6]
mov es:[di], bx
jmp short loc_3673
; ---------------------------------------------------------------------------
loc_365D:
mov ax, 0FFFFh
mov dx, 7FFFh
add al, [bp+var_1]
adc ah, 0
adc dx, 0
mov [bp+var_6], 2
jmp short loc_3649
; ---------------------------------------------------------------------------
loc_3673:
pop di
pop si
mov sp, bp
pop bp
retn
__scantol endp
include libs/BorlandC/scantol.asm
include libs/BorlandC/segread.asm
include libs/BorlandC/setupio.asm
include libs/BorlandC/cconv.asm