3 title CP
/DOS DosOpen mapper
6 FileAttributeSegment
segment word public 'fat'
8 public FileAttributeTable
10 FileAttributeTable dw 100 dup(0)
12 FileAttributeSegment ends
15 dosxxx
segment byte public 'dos'
16 assume
cs:dosxxx
,ds:nothing
,es:nothing
,ss:nothing
18 ; ************************************************************************* *
22 ; * FILE NAME: DosOpen.ASM
24 ; * FUNCTION: This module creates the specified file (if necessary),
25 ; * and opens it. If the file name is a device then the
26 ; * handle returned will be a device handle. The high order
27 ; * byte of the open flag is ignored because PC/DOS does not
28 ; * support a word long open mode. Invalid parameters are
29 ; * reported as general failures because there are no error
30 ; * codes defined at this time.
34 ; * PUSH@ ASCIIZ FileName ; File path name
35 ; * PUSH@ WORD FileHandle ; New file's handle
36 ; * PUSH@ WORD ActionTaken ; Action taken
37 ; * PUSH DWORD FileSize ; File primary allocation
38 ; * PUSH WORD FileAttribute ; File attribute
39 ; * PUSH WORD OpenFlag ; Open function type
40 ; * PUSH WORD OpenMode ; Open mode of the file
41 ; * PUSH@ DWORD 0 ; Reserved (must be zero)
46 ; * IF ERROR (AX not = 0)
50 ; * o Invalid parameter(s)
52 ; * o Insufficient disk space available
54 ; * o Insufficient resources (i.e., file handles)
57 ; * MODULES CALLED: DOS int 21H function 3DH
58 ; * DOS int 21H function 3EH
59 ; * DOS int 21H function 40H
60 ; * DOS int 21H function 42H
61 ; * DOS int 21H function 43H
63 ; *************************************************************************
78 resrv34 dd ?
; reserved
79 OpenMode dw ?
; open mode
80 OpenFlag dw ?
; open function type (1=Open only if already exist)
81 OpenFileAttr dw ?
; file attribute
82 FileSize dd ?
; file allocation size
83 acttak34 dd ?
; action taken
84 FileHandlePtr dd ?
; New file handler
85 FileNamePtr dd ?
; file name pointer
90 Enter DosOpen
; save registers
91 sub sp,2 ; allocate space on the stack
94 ; Check to see if we are trying to open a DASD device. If so, we must do
95 ; something unique as PC-DOS does not support this behavior.
96 ; Return a dummy DASD file handle. This used by IOCTL category 8 option.
98 test [bp].OpenMode
,08000h ; DASD open ?
99 jz FileOpenRequest
; branch if file open
101 lds si,[bp].FileNamePtr
; convert device name to upper case
112 jc BadDASDName
; jump if bad DASD name
117 xor ah,ah ; drive number from 0 to 25
122 lds si,[bp].FileHandlePtr
123 mov ds:[si],ax ; save dasd dummy device handle
124 jmp GoodExit
; in return data area and return
127 mov ax,3 ; set error code
128 jmp ErrorExit
; return
131 ; Query the file attribute to determine if file exists
135 lds dx,dword ptr [bp].FileNamePtr
; load asciiz string address
136 mov ax,04300h ; query file mode
137 int 21h
; get file mode
138 jnc SaveAttribute
; file does exist
140 cmp ax,00002h ; check if file does not exist error
141 je dne34
; go here if does not exist
143 jmp erret34
; error return
148 ; File exists - determine what to do
150 lds si,dword ptr [bp].acttak34
; Load action taken pointer
151 mov word ptr[si],ACT_FileExisted
; Indicate that file existed
152 mov ax,[bp].OpenFlag
; load open flag
153 and ax,00003h ; mask off the replace and open flags
154 cmp ax,00003h ; check if both are requested
155 je nxt134
; error - invalid parm
157 cmp ax,00001h ; check if file is to be opened
158 je opn34
; file should be opened
160 cmp ax,00002h ; check if file should be replaced
161 je creat34
; file should be replaced
164 mov ax,0000ch ; report general
165 jmp erret34
; failure
170 ; set the file attribute ( *** commented to fix mapper problem Pylee 6/10
172 ; lds dx,dword ptr [bp].FileNamePtr ; load asciiz string address
173 ; mov cx,[bp].OpenFileAttr ; load the file attribute
174 ; mov ax,04301h ; change file mode
175 ; int 21h ; get file mode
176 ; jnc nxto34 ; continue good return
177 ; jmp erret34 ; error retrun
183 lds si,dword ptr [bp].acttak34
; load action taken pointer
184 mov word ptr [si],00h ; clear action reported flag
185 lds dx,dword ptr [bp].FileNamePtr
; load asciiz string address
186 mov ax,[bp].OpenMode
; load the file mode
188 mov ah,03dh ; load opcode
190 jc ErrorExit
; error return
193 lds si,dword ptr [bp].FileHandlePtr
; load file handle address
194 mov [si],ax ; save file handle
195 jmp PutAwayAttribute
; normal return
199 ; File does not exist - determine what to do
201 mov ax,[bp].OpenFlag
; load open flag
202 and ax,00010h ; check create
203 cmp ax,00010h ; and open file flag
204 je creat34
; go create the file
206 mov ax,0000ch ; report general failure
207 jmp erret34
; if create not requested
211 ; file did not exist so it was created or replacement was requested
213 lds si,dword ptr [bp].acttak34
; load action taken pointer
214 mov word ptr [si],ACT_FileCreated
; file created - action reported
215 lds dx,dword ptr [bp].FileNamePtr
; load asciiz string address
216 mov cx,[bp].OpenFileAttr
; set file attribute
219 int 21h
; create the file
220 jc erret34
; error return
222 lds si,dword ptr [bp].FileHandlePtr
; load file handle address
223 mov [si],ax ; save file handle
229 mov bx,ax ; load file handle
231 mov ax,04202h ; load opcode
232 int 21h
; move file pointer
233 jc erret34
; error return
236 lds si,dword ptr [bp].FileHandlePtr
; load file handle address
237 mov bx,[si] ; load file handle
238 lds dx,dword ptr [bp].acttak34
242 int 21h
; write 0 length record
243 jc erret34
; error return
248 ; close and reopen the file to make the length permanent
250 lds si,dword ptr [bp].FileHandlePtr
; load file handle address
251 mov bx,[si] ; load file handle
254 jc erret34
; error return
256 lds dx,dword ptr [bp].FileNamePtr
; load asciiz string address
257 mov ax,[bp].OpenMode
; load the file mode
259 int 21h
; open the file
260 jc erret34
; error return
262 lds si,dword ptr [bp].FileHandlePtr
; load file handle address
263 mov [si],ax ; save file handle
265 PutAwayAttribute: ; save file attribute for other mapper
269 mov ax,seg FileAttributeSegment
271 assume
ds:FileAttributeSegment
274 mov FileAttributeTable
[bx],ax ; save file attribute
277 sub ax,ax ; set good return code
281 add sp,2 ; deallocate space
282 mexit
; restore registers
283 ret size
str - 6 ; return