]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/MAPPER/OPEN.ASM

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / MAPPER / OPEN.ASM
1 page 80,132
2 ;\ f\e0
3 title CP/DOS DosOpen mapper
4
5
6 FileAttributeSegment segment word public 'fat'
7
8 public FileAttributeTable
9
10 FileAttributeTable dw 100 dup(0)
11
12 FileAttributeSegment ends
13
14
15 dosxxx segment byte public 'dos'
16 assume cs:dosxxx,ds:nothing,es:nothing,ss:nothing
17 ;
18 ; ************************************************************************* *
19 ; *
20 ; * MODULE: DosOpen
21 ; *
22 ; * FILE NAME: DosOpen.ASM
23 ; *
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.
31 ; *
32 ; * CALLING SEQUENCE:
33 ; *
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)
42 ; * CALL DosOpen
43 ; *
44 ; * RETURN SEQUENCE:
45 ; *
46 ; * IF ERROR (AX not = 0)
47 ; *
48 ; * AX = Error Code:
49 ; *
50 ; * o Invalid parameter(s)
51 ; *
52 ; * o Insufficient disk space available
53 ; *
54 ; * o Insufficient resources (i.e., file handles)
55 ; *
56 ; *
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
62 ; *
63 ; *************************************************************************
64 ;
65 public DosOpen
66 .sall
67 .xlist
68 include macros.inc
69 .list
70
71 ACT_FileExisted equ 1
72 ACT_FileCreated equ 2
73
74
75 str struc
76 old_bp dw ?
77 return dd ?
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
86 str ends
87
88 ;\f
89 DosOpen proc far
90 Enter DosOpen ; save registers
91 sub sp,2 ; allocate space on the stack
92 SaveArea equ -2
93
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.
97
98 test [bp].OpenMode,08000h ; DASD open ?
99 jz FileOpenRequest ; branch if file open
100
101 lds si,[bp].FileNamePtr ; convert device name to upper case
102 mov al,ds:[si]
103 cmp al,'a'
104 jc NoFold
105 cmp al,'z'+1
106 jnc NoFold
107
108 add al,'A' - 'a'
109
110 NoFold:
111 sub al,'A'
112 jc BadDASDName ; jump if bad DASD name
113
114 cmp al,27
115 jnc BadDASDName
116
117 xor ah,ah ; drive number from 0 to 25
118 inc ax ; 1 to 26
119 inc ax ; 2 to 27
120 neg ax ; -2 to -27
121
122 lds si,[bp].FileHandlePtr
123 mov ds:[si],ax ; save dasd dummy device handle
124 jmp GoodExit ; in return data area and return
125
126 BadDASDName:
127 mov ax,3 ; set error code
128 jmp ErrorExit ; return
129
130
131 ; Query the file attribute to determine if file exists
132
133
134 FileOpenRequest:
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
139
140 cmp ax,00002h ; check if file does not exist error
141 je dne34 ; go here if does not exist
142
143 jmp erret34 ; error return
144
145 SaveAttribute:
146 mov [bp].SaveArea,cx
147
148 ; File exists - determine what to do
149
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
156
157 cmp ax,00001h ; check if file is to be opened
158 je opn34 ; file should be opened
159
160 cmp ax,00002h ; check if file should be replaced
161 je creat34 ; file should be replaced
162
163 nxt134:;
164 mov ax,0000ch ; report general
165 jmp erret34 ; failure
166
167 ;\f
168 opn34:;
169
170 ; set the file attribute ( *** commented to fix mapper problem Pylee 6/10
171 ;
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
178
179 nxto34:;
180
181 ; open the file
182
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
187
188 mov ah,03dh ; load opcode
189 int 21h ; open file
190 jc ErrorExit ; error return
191
192 FileWasThere:
193 lds si,dword ptr [bp].FileHandlePtr ; load file handle address
194 mov [si],ax ; save file handle
195 jmp PutAwayAttribute ; normal return
196
197 dne34:;
198
199 ; File does not exist - determine what to do
200
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
205
206 mov ax,0000ch ; report general failure
207 jmp erret34 ; if create not requested
208
209 creat34:;
210
211 ; file did not exist so it was created or replacement was requested
212
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
217
218 mov ah,03ch
219 int 21h ; create the file
220 jc erret34 ; error return
221
222 lds si,dword ptr [bp].FileHandlePtr ; load file handle address
223 mov [si],ax ; save file handle
224 ;
225 ; set file length
226 ;
227 les dx,[bp].FileSize
228 mov cx,es
229 mov bx,ax ; load file handle
230
231 mov ax,04202h ; load opcode
232 int 21h ; move file pointer
233 jc erret34 ; error return
234
235 len134:;
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
239 sub cx,cx
240
241 mov ah,040h
242 int 21h ; write 0 length record
243 jc erret34 ; error return
244
245 ;\f
246 len234:;
247 ;
248 ; close and reopen the file to make the length permanent
249 ;
250 lds si,dword ptr [bp].FileHandlePtr ; load file handle address
251 mov bx,[si] ; load file handle
252 mov ah,03eh
253 int 21h
254 jc erret34 ; error return
255
256 lds dx,dword ptr [bp].FileNamePtr ; load asciiz string address
257 mov ax,[bp].OpenMode ; load the file mode
258 mov ah,03dh ;
259 int 21h ; open the file
260 jc erret34 ; error return
261
262 lds si,dword ptr [bp].FileHandlePtr ; load file handle address
263 mov [si],ax ; save file handle
264
265 PutAwayAttribute: ; save file attribute for other mapper
266 mov bx,ax ; calls
267 add bx,bx
268
269 mov ax,seg FileAttributeSegment
270 mov ds,ax
271 assume ds:FileAttributeSegment
272
273 mov ax,[bp].SaveArea
274 mov FileAttributeTable[bx],ax ; save file attribute
275
276 GoodExit:
277 sub ax,ax ; set good return code
278
279 erret34:;
280 ErrorExit:
281 add sp,2 ; deallocate space
282 mexit ; restore registers
283 ret size str - 6 ; return
284
285 DosOpen endp
286
287 dosxxx ends
288
289 end