1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
page 80,132
;0
title CP/DOS DosOpen mapper
FileAttributeSegment segment word public 'fat'
public FileAttributeTable
FileAttributeTable dw 100 dup(0)
FileAttributeSegment ends
dosxxx segment byte public 'dos'
assume cs:dosxxx,ds:nothing,es:nothing,ss:nothing
;
; ************************************************************************* *
; *
; * MODULE: DosOpen
; *
; * FILE NAME: DosOpen.ASM
; *
; * FUNCTION: This module creates the specified file (if necessary),
; * and opens it. If the file name is a device then the
; * handle returned will be a device handle. The high order
; * byte of the open flag is ignored because PC/DOS does not
; * support a word long open mode. Invalid parameters are
; * reported as general failures because there are no error
; * codes defined at this time.
; *
; * CALLING SEQUENCE:
; *
; * PUSH@ ASCIIZ FileName ; File path name
; * PUSH@ WORD FileHandle ; New file's handle
; * PUSH@ WORD ActionTaken ; Action taken
; * PUSH DWORD FileSize ; File primary allocation
; * PUSH WORD FileAttribute ; File attribute
; * PUSH WORD OpenFlag ; Open function type
; * PUSH WORD OpenMode ; Open mode of the file
; * PUSH@ DWORD 0 ; Reserved (must be zero)
; * CALL DosOpen
; *
; * RETURN SEQUENCE:
; *
; * IF ERROR (AX not = 0)
; *
; * AX = Error Code:
; *
; * o Invalid parameter(s)
; *
; * o Insufficient disk space available
; *
; * o Insufficient resources (i.e., file handles)
; *
; *
; * MODULES CALLED: DOS int 21H function 3DH
; * DOS int 21H function 3EH
; * DOS int 21H function 40H
; * DOS int 21H function 42H
; * DOS int 21H function 43H
; *
; *************************************************************************
;
public DosOpen
.sall
.xlist
include macros.inc
.list
ACT_FileExisted equ 1
ACT_FileCreated equ 2
str struc
old_bp dw ?
return dd ?
resrv34 dd ? ; reserved
OpenMode dw ? ; open mode
OpenFlag dw ? ; open function type (1=Open only if already exist)
OpenFileAttr dw ? ; file attribute
FileSize dd ? ; file allocation size
acttak34 dd ? ; action taken
FileHandlePtr dd ? ; New file handler
FileNamePtr dd ? ; file name pointer
str ends
;
DosOpen proc far
Enter DosOpen ; save registers
sub sp,2 ; allocate space on the stack
SaveArea equ -2
; Check to see if we are trying to open a DASD device. If so, we must do
; something unique as PC-DOS does not support this behavior.
; Return a dummy DASD file handle. This used by IOCTL category 8 option.
test [bp].OpenMode,08000h ; DASD open ?
jz FileOpenRequest ; branch if file open
lds si,[bp].FileNamePtr ; convert device name to upper case
mov al,ds:[si]
cmp al,'a'
jc NoFold
cmp al,'z'+1
jnc NoFold
add al,'A' - 'a'
NoFold:
sub al,'A'
jc BadDASDName ; jump if bad DASD name
cmp al,27
jnc BadDASDName
xor ah,ah ; drive number from 0 to 25
inc ax ; 1 to 26
inc ax ; 2 to 27
neg ax ; -2 to -27
lds si,[bp].FileHandlePtr
mov ds:[si],ax ; save dasd dummy device handle
jmp GoodExit ; in return data area and return
BadDASDName:
mov ax,3 ; set error code
jmp ErrorExit ; return
; Query the file attribute to determine if file exists
FileOpenRequest:
lds dx,dword ptr [bp].FileNamePtr ; load asciiz string address
mov ax,04300h ; query file mode
int 21h ; get file mode
jnc SaveAttribute ; file does exist
cmp ax,00002h ; check if file does not exist error
je dne34 ; go here if does not exist
jmp erret34 ; error return
SaveAttribute:
mov [bp].SaveArea,cx
; File exists - determine what to do
lds si,dword ptr [bp].acttak34 ; Load action taken pointer
mov word ptr[si],ACT_FileExisted ; Indicate that file existed
mov ax,[bp].OpenFlag ; load open flag
and ax,00003h ; mask off the replace and open flags
cmp ax,00003h ; check if both are requested
je nxt134 ; error - invalid parm
cmp ax,00001h ; check if file is to be opened
je opn34 ; file should be opened
cmp ax,00002h ; check if file should be replaced
je creat34 ; file should be replaced
nxt134:;
mov ax,0000ch ; report general
jmp erret34 ; failure
;
opn34:;
; set the file attribute ( *** commented to fix mapper problem Pylee 6/10
;
; lds dx,dword ptr [bp].FileNamePtr ; load asciiz string address
; mov cx,[bp].OpenFileAttr ; load the file attribute
; mov ax,04301h ; change file mode
; int 21h ; get file mode
; jnc nxto34 ; continue good return
; jmp erret34 ; error retrun
nxto34:;
; open the file
lds si,dword ptr [bp].acttak34 ; load action taken pointer
mov word ptr [si],00h ; clear action reported flag
lds dx,dword ptr [bp].FileNamePtr ; load asciiz string address
mov ax,[bp].OpenMode ; load the file mode
mov ah,03dh ; load opcode
int 21h ; open file
jc ErrorExit ; error return
FileWasThere:
lds si,dword ptr [bp].FileHandlePtr ; load file handle address
mov [si],ax ; save file handle
jmp PutAwayAttribute ; normal return
dne34:;
; File does not exist - determine what to do
mov ax,[bp].OpenFlag ; load open flag
and ax,00010h ; check create
cmp ax,00010h ; and open file flag
je creat34 ; go create the file
mov ax,0000ch ; report general failure
jmp erret34 ; if create not requested
creat34:;
; file did not exist so it was created or replacement was requested
lds si,dword ptr [bp].acttak34 ; load action taken pointer
mov word ptr [si],ACT_FileCreated ; file created - action reported
lds dx,dword ptr [bp].FileNamePtr ; load asciiz string address
mov cx,[bp].OpenFileAttr ; set file attribute
mov ah,03ch
int 21h ; create the file
jc erret34 ; error return
lds si,dword ptr [bp].FileHandlePtr ; load file handle address
mov [si],ax ; save file handle
;
; set file length
;
les dx,[bp].FileSize
mov cx,es
mov bx,ax ; load file handle
mov ax,04202h ; load opcode
int 21h ; move file pointer
jc erret34 ; error return
len134:;
lds si,dword ptr [bp].FileHandlePtr ; load file handle address
mov bx,[si] ; load file handle
lds dx,dword ptr [bp].acttak34
sub cx,cx
mov ah,040h
int 21h ; write 0 length record
jc erret34 ; error return
;
len234:;
;
; close and reopen the file to make the length permanent
;
lds si,dword ptr [bp].FileHandlePtr ; load file handle address
mov bx,[si] ; load file handle
mov ah,03eh
int 21h
jc erret34 ; error return
lds dx,dword ptr [bp].FileNamePtr ; load asciiz string address
mov ax,[bp].OpenMode ; load the file mode
mov ah,03dh ;
int 21h ; open the file
jc erret34 ; error return
lds si,dword ptr [bp].FileHandlePtr ; load file handle address
mov [si],ax ; save file handle
PutAwayAttribute: ; save file attribute for other mapper
mov bx,ax ; calls
add bx,bx
mov ax,seg FileAttributeSegment
mov ds,ax
assume ds:FileAttributeSegment
mov ax,[bp].SaveArea
mov FileAttributeTable[bx],ax ; save file attribute
GoodExit:
sub ax,ax ; set good return code
erret34:;
ErrorExit:
add sp,2 ; deallocate space
mexit ; restore registers
ret size str - 6 ; return
DosOpen endp
dosxxx ends
end
|