0% found this document useful (0 votes)
14 views7 pages

Redir98.Asm

The document contains assembly language routines for file redirection in FORTRAN, authored by Kevin G. Rhoads, covering functions such as redir, unredir, nredir, xredir, handle, and sethnd. Each procedure is designed to manage file handles in DOS environments, providing functionality to redirect standard input/output and manipulate file handle tables. The code includes checks for DOS version compatibility and uses various DOS interrupts to perform its operations.

Uploaded by

kgrhoads
Copyright
© Attribution ShareAlike (BY-SA)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views7 pages

Redir98.Asm

The document contains assembly language routines for file redirection in FORTRAN, authored by Kevin G. Rhoads, covering functions such as redir, unredir, nredir, xredir, handle, and sethnd. Each procedure is designed to manage file handles in DOS environments, providing functionality to redirect standard input/output and manipulate file handle tables. The code includes checks for DOS version compatibility and uses various DOS interrupts to perform its operations.

Uploaded by

kgrhoads
Copyright
© Attribution ShareAlike (BY-SA)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

; FILE redirection routines for FORTRAN

;
; Copyright (c) 1986-1997 Kevin G. Rhoads. All rights reserved.
;
;
;
include forframe.mac
;
;
;DATA segment PUBLIC 'DATA' USE16
DATA segment PUBLIC 'DATA'
DATA ends
dgroup group DATA
;code segment 'CODE' PUBLIC USE16
code segment 'CODE' PUBLIC
assume cs:code,ds:dgroup,es:dgroup,ss:dgroup
;
; USE: integer*2 = redir() OR int*4 = redir()
; if int*4 the high word is the handle value now being used and the
; low word is the value of the handle being replaced
redir proc far
redir2 label far
redir4 label far
public redir,redir2,redir4
save
; push es
mov ah,30h ;? DOS version
int 21h
cmp al,02 ;DOS 3 or higher
ja dos3orhigher_redir
mov ah,51h ;get PSP - undoc DOS 2 version
int 21h ;PSP segment in BX
mov es,bx ;PSP:18h = process file handle table
for DOS 2
mov bx,18h
jmp havepointer_redir
dos3orhigher_redir:
mov ah,62h ;get PSP
int 21h ;PSP segment in BX
mov es,bx ;PSP segment to ES
mov bx,34h ;PSP:34h -> process file handle table
(typically PSP:18h)
les bx,es:[bx] ;get file handle table address
havepointer_redir:
mov al,es:[bx+1] ;get second handle in al (STDOUT)
mov dl,es:[bx+5] ;get sixth handle in dl (First file
opened by process)
mov es:[bx+1],dl ;stuff sixth handle in second
mov ah,0
mov dh,0
; pop es
restore
ret
db '(c) 1986-1994 Kevin G. Rhoads, all rights reserved.'
redir endp
;
; USE: integer*2 = unredir() OR int*4 = unredir()
; if int*4 the high word is the handle value now being used and the
; low word is the value of the handle being replaced
unredir proc far
unredir2 label far
unredir4 label far
public unredir,unredir2,unredir4
save
; push es
mov ah,30h ;? DOS version
int 21h
cmp al,02 ;DOS 3 or higher
ja dos3orhigher_unredir
mov ah,51h ;get PSP - undoc DOS 2 version
int 21h ;PSP segment in BX
mov es,bx ;PSP:18h = process file handle table
for DOS 2
mov bx,18h
jmp havepointer_unredir
dos3orhigher_unredir:
mov ah,62h ;get PSP
int 21h ;PSP segment in BX
mov es,bx ;PSP segment to ES
mov bx,34h ;PSP:34h -> process file handle table
(typically PSP:18h)
les bx,es:[bx] ;get file handle table address
havepointer_unredir:
mov al,es:[bx+1] ;get second handle in al (STDOUT)
mov dl,es:[bx+2] ;get third handle in dl (STDERR)
mov es:[bx+1],dl ;stuff third handle in second
mov ah,0
mov dh,0
; pop es
restore
ret
db '(c) 1986-1994 Kevin G. Rhoads, all rights reserved.'
unredir endp
;
;
; USE: int*2 = nredir(integer*2) OR int*4 = nredir(int*2)
; if int*4 the high word is the handle value now being used and the
; low word is the value of the handle being replaced
nredir proc far
nredir2 label far
nredir4 label far
public nredir,nredir2,nredir4
save
; push es
les si,dword ptr ss:[bp+argone1]
mov si,word ptr es:[si]
mov ah,30h ;? DOS version
int 21h
cmp al,02 ;DOS 3 or higher
ja dos3orhigher_nredir
mov ah,51h ;get PSP - undoc DOS 2 version
int 21h ;PSP segment in BX
mov es,bx ;PSP:18h = process file handle table
for DOS 2
mov bx,18h
jmp havepointer_nredir
dos3orhigher_nredir:
mov ah,62h ;get PSP
int 21h ;PSP segment in BX
mov es,bx ;PSP segment to ES
mov bx,34h ;PSP:34h -> process file handle table
(typically PSP:18h)
les bx,es:[bx] ;get file handle table address
havepointer_nredir:
mov al,es:[bx+1] ;get second handle in al (STDOUT)
mov dl,es:[bx+si] ;get si+1'th handle in dl
mov es:[bx+1],dl ;stuff si+1'th handle in second
mov ah,0
mov dh,0
; pop es
restore
ret 4
db '(c) 1986-1993 Kevin G. Rhoads, all rights reserved.'
nredir endp
;
; USE: call xredir(integer*2) OR int = xredir(integer*2)
xredir proc far
unrdir label far
public xredir,unrdir
save
; push es
les si,dword ptr ss:[bp+argone1]
mov si,word ptr es:[si]
mov ah,30h ;? DOS version
int 21h
cmp al,02 ;DOS 3 or higher
ja dos3orhigher_xredir
mov ah,51h ;get PSP - undoc DOS 2 version
int 21h ;PSP segment in BX
mov es,bx ;PSP:18h = process file handle table
for DOS 2
mov bx,18h
jmp havepointer_xredir
dos3orhigher_xredir:
mov ah,62h ;get PSP
int 21h ;PSP segment in BX
mov es,bx ;PSP segment to ES
mov bx,34h ;PSP:34h -> process file handle table
(typically PSP:18h)
les bx,es:[bx] ;get file handle table address
havepointer_xredir:

; ??????? mov es:[bx+1],cl


mov es:[bx+1],si
; pop es
mov ax,si
mov ah,0
restore
ret 4
db '(c) 1986-1993 Kevin G. Rhoads, all rights reserved.'
xredir endp
;
; USE: integer*2 = handle(integer*2) OR integer*4 = handle(integer*2)
;
handle proc far
gethnd label far
handl2 label far
handl4 label far
public handle,gethnd,handl2,handl4
save
; push es
les si,dword ptr ss:[bp+argone1]
mov si,word ptr es:[si]
mov ah,30h ;? DOS version
int 21h
cmp al,02 ;DOS 3 or higher
ja dos3orhigher_gethnd
mov ah,51h ;get PSP - undoc DOS 2 version
int 21h ;PSP segment in BX
mov es,bx ;PSP:18h = process file handle table
for DOS 2
mov bx,18h
jmp havepointer_gethnd
dos3orhigher_gethnd:
mov ah,62h ;get PSP
int 21h ;PSP segment in BX
mov es,bx ;PSP segment to ES
mov bx,34h ;PSP:34h -> process file handle table
(typically PSP:18h)
les bx,es:[bx] ;get file handle table address
havepointer_gethnd:
mov al,es:[bx+si]
mov ah,0
mov dx,0
; pop es
restore
ret 4
db '(c) 1986-1993 Kevin G. Rhoads, all rights reserved.'
handle endp
;
;
; USE: integer*2 = handles(integer*2) OR integer*4 = handles(integer*2)
;
handles proc far
allhnd label far
allhnd2 label far
allhnd4 label far
public handles,allhnd,allhnd2,allhnd4
save
; push es
les di,dword ptr ss:[bp+argone1]
push es
push di
mov ah,30h ;? DOS version
int 21h
cmp al,02 ;DOS 3 or higher
ja dos3orhigher_allhnd
mov ah,51h ;get PSP - undoc DOS 2 version
int 21h ;PSP segment in BX
push ds
mov ds,bx ;PSP:18h = process file handle table
for DOS 2
mov si,18h
mov cx,20
jmp havepointer_allhnd
dos3orhigher_allhnd:
mov ah,62h ;get PSP
int 21h ;PSP segment in BX
mov es,bx ;PSP segment to ES
mov bx,32h ;PSP:32h = Number of file handle table
entries
mov cx,es:[bx] ;get handle count into cx
mov bx,34h ;PSP:34h -> process file handle table
(typically PSP:18h)
push ds
lds si,es:[bx] ;get file handle table address
havepointer_allhnd:
pop ax ;saved ds into ax
pop di ;restore target address
pop es
push ax ;put saved ds back on stack
rep movsb ; es:[di],ds:[si] ;copy the file handle table
mov ax,si ;return the file handle address as INT4
mov dx,ds
pop ds ;restore ds
; pop es ; es
restore
ret 4
db '(c) 1986-1994 Kevin G. Rhoads, all rights reserved.'
handles endp
;
;
; USE: integer*2 = sethnd(integer*2 which,what)
;
sethnd proc far
sethn2 label far
sethn4 label far
public sethnd,sethn2,sethn4
save
; push es
les si,dword ptr ss:[bp+argone2]
mov si,word ptr es:[si]
les bx,dword ptr ss:[bp+argtwo2]
mov dx,word ptr es:[bx]
mov ah,30h ;? DOS version
int 21h
cmp al,02 ;DOS 3 or higher
ja dos3orhigher_sethnd
mov ah,51h ;get PSP - undoc DOS 2 version
int 21h ;PSP segment in BX
mov es,bx ;PSP:18h = process file handle table
for DOS 2
mov bx,18h
jmp havepointer_sethnd
dos3orhigher_sethnd:
mov ah,62h ;get PSP
int 21h ;PSP segment in BX
mov es,bx ;PSP segment to ES
mov bx,34h ;PSP:34h -> process file handle table
(typically PSP:18h)
les bx,es:[bx] ;get file handle table address
havepointer_sethnd:
mov al,es:[bx+si] ;get present value of si+1'th handle
mov es:[bx+si],dl ;set si+1'th handle to dl
mov ah,0
mov dx,0
; pop es
restore
ret 8
db '(c) 1986-1994 Kevin G. Rhoads, all rights reserved.'
sethnd endp
;
;
; USE: integer*4 = mvftab(integer*2 NewFileTable, integer*2 Length)
;
mvftab proc far
MoveFileTable label far
MoveFileTable4 label far
public mvftab,MoveFileTable,MoveFileTable4
save
; push es
les di,dword ptr ss:[bp+argtwo2]
mov cx,word ptr es:[di]
les di,dword ptr ss:[bp+argone2]
push es
push di
mov ah,30h ;? DOS version
int 21h
cmp al,02 ;DOS 3 or higher
ja dos3orhigher_MoveFileTable
mov ah,51h ;get PSP - undoc DOS 2 version
int 21h ;PSP segment in BX
push ds
mov ds,bx ;PSP:18h = process file handle table
for DOS 2
mov si,18h
mov cx,20
jmp havepointer_MoveFileTable
dos3orhigher_MoveFileTable:
mov ah,62h ;get PSP
int 21h ;PSP segment in BX
mov es,bx ;PSP segment to ES
cli
mov bx,32h ;PSP:32h = Number of file handle table
entries
xchg cx,es:[bx] ;get handle count into cx
mov bx,34h ;PSP:34h -> process file handle table
(typically PSP:18h)
push ds
lds si,es:[bx] ;get file handle table address
; sp = bp - 14
; mov es:[bx+2],ss:[sp-6]
; mov es:[bx],ss:[sp-4]
mov dx,word ptr ss:[bp+segone2]
mov word ptr es:[bx+2],dx
mov dx,word ptr ss:[bp+offone2]
mov word ptr es:[bx],dx
havepointer_MoveFileTable:
pop ax ;saved ds into ax
pop di ;restore target address
pop es
push ax ;put saved ds back on stack
rep movsb ; es:[di],ds:[si] ;copy the file handle table
sti
mov ax,si ;return the OLD file handle address as INT4
mov dx,ds
pop ds ;restore ds
; pop es ; es
restore
ret 8
db '(c) 1986-1994 Kevin G. Rhoads, all rights reserved.'
mvftab endp
;
;
code ends
end

You might also like