This repository was archived by the owner on Oct 11, 2022. It is now read-only.
forked from nickelsworth/swag
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0049.pas
More file actions
525 lines (482 loc) · 29.4 KB
/
Copy path0049.pas
File metadata and controls
525 lines (482 loc) · 29.4 KB
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
UNIT FILEIO; { Low Level File handling routines. Jan 18/94 }
{ Copyright (C) 1993,1994 Greg Estabrooks }
{ NOTE: Requires TP 6.0+ to compile. }
INTERFACE
{***********************************************************************}
USES DOS; { IMPORT FSearch. }
CONST { Handles PreDefined by DOS. }
fStdIn = $00; { STD Input Device, (Keyboard). }
fStdOut = $01; { STD Output Device,(CRT). }
fStdErr = $02; { STD Error Device, (CRT). }
fStdCom = $03; { STD Comm. }
fStdPrn = $04; { STD Printer. }
oRead = $00; { Opens a file for read only. }
oWrite = $01; { Opens a file for writing only. }
oReadWrite = $02; { Opens a file for reading and writing. }
oDenyAll = $10; { Deny access to other processes. }
oDenyWrite = $20; { Deny write access to other processes. }
oDenyRead = $30; { Deny read access to other processes. }
oDenyNone = $40; { Allow free access to other processes. }
{ Possible file attribs,can be combined.}
aNormal = $00; aSystem = $04; aArchive = $20;
aReadOnly = $01; aVolume = $08;
aHidden = $02; aDir = $10;
TYPE
LockType = (Lock,UnLock); { Ordinal Type for use with 'fLock'. }
VAR
fError :WORD; { Holds any error codes from routines. }
PROCEDURE ASCIIZ( VAR fName :STRING );
{ Routine to add a NULL to a string to make it }
{ ASCIIZ compatible. }
{ File routines automatically call this routine}
{ usage : }
{ ASCIIZ(fName); }
FUNCTION fCreate( fName :STRING; Attr :BYTE ) :WORD;
{ Routine to Create 'fName' with an attribute }
{ of 'Attr'. If the file already exists then it}
{ will be truncated to a zero length file. }
{ Returns a WORD value containing the handle. }
{ Uses Int 21h/AH=3Ch. }
{ usage : }
{ handle := fCreate('Temp.Dat',aNormal); }
FUNCTION fOpen( fName :STRING; Mode :BYTE ) :WORD;
{ Routine to open already existing file defined}
{ in 'fName' with an opening mode of 'Mode'. }
{ Returns a WORD value containing the handle. }
{ Uses Int 21h/AH=3Dh. }
{ usage : }
{ handle := fOpen('Temp.Dat',oRead); }
PROCEDURE fRead( fHandle :WORD; VAR Buff; NTRead:WORD; VAR ARead :WORD );
{ Reads 'NTRead' bytes of data from 'fHandle' }
{ and puts it in 'Buff'. The actually amount }
{ of bytes read is returned in 'ARead'. }
{ Uses Int 21h/AH=3Fh. }
{ usage : }
{ fRead(handle,Buffer,SizeOf(Buffer),ARead); }
PROCEDURE fWrite( fHandle :WORD; VAR Buff; NTWrite:WORD; VAR AWrite :WORD );
{ Writes 'NTWrite' bytes of info from 'Buff' }
{ to 'fHandle'. The actually amount written is }
{ returned in 'AWrite'. }
{ Uses Int 21h/AH=40h. }
{ usage : }
{ fWrite(handle,Buffer,SizeOf(Buffer),AWrite);}
PROCEDURE fClose( fHandle :WORD );
{ Routine to close file 'fHandle'. This updates}
{ the directory time and size enteries. }
{ Uses Int 21h/AH=3Eh. }
{ usage : }
{ fClose(handle); }
PROCEDURE fReset( fHandle :WORD );
{ Routine to reset file position pointer to the}
{ beginning of 'fHandle'. }
{ Uses Int 21h/AH=42h. }
{ usage : }
{ fReset(handle); }
PROCEDURE fAppend( fHandle :WORD );
{ Routine to move the File position pointer of }
{ 'fHandle' to the end of the file. Any further}
{ writing is added to the end of the file. }
{ Uses Int 21h/AH=42h. }
{ usage : }
{ fAppend(handle); }
PROCEDURE fSeek( fHandle :WORD; fOfs :LONGINT );
{ Routine to move the file position pointer for}
{ 'fHandle' to 'fOfs'. 'fOfs' is the actual }
{ byte position in the file to move to. }
{ Uses Int 21h/AH=42h. }
{ usage : }
{ fSeek(handle,1023); }
PROCEDURE fErase( fName :STRING );
{ Routine to erase 'fName'. }
{ Uses Int 21h/AH=41h. }
{ usage : }
{ fErase('Temp.Dat'); }
FUNCTION fPos( fHandle :WORD ) :LONGINT;
{ Routine to return the current position within}
{ 'fHandle'. }
{ Uses Int 21h/AH=42. }
{ usage : }
{ CurPos := fPos(handle); }
FUNCTION fEof( fHandle :WORD ) :BOOLEAN;
{ Routine to determine whether or not we're }
{ currently at the end of file 'fHandle'. }
{ usage : }
{ IsEnd := fEof(handle); }
FUNCTION fExist( fName :STRING ) :BOOLEAN;
{ Routine to determine whether or not 'fName' }
{ exists. }
{ usage : }
{ Exist := fExist('Temp.Dat'); }
FUNCTION fGetAttr( fName :STRING ) :BYTE;
{ Routine to return the current file attribute }
{ of 'fName'. }
{ Uses Int 21h/AH=43h,AL=00h. }
{ usage : }
{ CurAttr := fGetAttr('Temp.Dat'); }
PROCEDURE fSetAttr( fName :STRING; NAttr :BYTE );
{ Routine to set file attribute of 'fName' to }
{ 'NAttr'. }
{ Uses Int 21h/AH=43h,AL=01h. }
{ usage : }
{ fSetAttr('Temp.Dat',aArchive OR aReadOnly); }
PROCEDURE fSetVerify( On_Off :BOOLEAN );
{ Routine to set the DOS verify flag ON or OFF.}
{ depending on 'On_Off'. }
{ TRUE = ON, FALSE = OFF. }
{ Uses Int 21h/AH=2Eh. }
{ usage : }
{ fSetVerify( TRUE ); }
FUNCTION fGetVerify :BOOLEAN;
{ Routine to return the current state of the }
{ DOS verify flag. }
{ Uses Int 21h/AH=54h. }
{ usage : }
{ IsVerify := fGetVerify; }
FUNCTION fSize( fHandle :WORD ) :LONGINT;
{ Routine to determine the size in bytes of }
{ 'fHandle'. }
{ usage : }
{ CurSize := fSize(handle); }
PROCEDURE fFlush( fHandle :WORD );
{ Flushes any File buffers for 'fHandle' }
{ immediately and updates the directory entry. }
{ Uses Int 21h/AH=68h. }
{ usage : }
{ fFlush(handle); }
PROCEDURE fLock( fHandle :WORD; LockInf :LockType; StartOfs,Len :LONGINT );
{ Routine to lock/unlock parts of a open file. }
{ Locking or unlock is determined by 'LockInf'. }
{ Uses Int 21h/AH=5Ch. }
{ usage : }
{ fLock(handle,Lock,1000,500); }
{***********************************************************************}
IMPLEMENTATION
PROCEDURE ASCIIZ( VAR fName :STRING ); ASSEMBLER;
{ Routine to add a NULL to a string to make it }
{ ASCIIZ compatible. }
{ File routines automatically call this routine}
ASM
Push DS { Push DS onto the stack. }
LDS DI,fname { Point DS:DI ---> fName. }
Xor BX,BX { Clear BX. }
Mov BL,BYTE PTR DS:[DI] { Load length of string into BL. }
Inc BL { Point to char after last one in name. }
Mov BYTE PTR DS:[DI+BX],0 { Now make it a ASCIIZ string. }
Pop DS { Pop DS off the stack. }
END;{ASCIIZ}
FUNCTION fCreate( fName :STRING; Attr :BYTE ) :WORD;
{ Routine to Create 'fName' with an attribute }
{ of 'Attr'. If the file already exists then it}
{ will be truncated to a zero length file. }
{ Returns a WORD value containing the handle. }
{ Uses Int 21h/AH=3Ch. }
BEGIN
ASCIIZ(fName); { Convert fName to an ASCIIZ string. }
ASM
Push DS { Push DS Onto stack. }
Mov fError,0 { Clear Error Flag. }
Mov AX,SS { Load AX with SS. }
Mov DS,AX { Now load that value into DS. }
Lea DX,fName { Now load DX with the offset of DX. }
Inc DX { Move past length byte. }
Xor CH,CH { Clear High byte of CX. }
Mov CL,Attr { Load attribute to give new file. }
Mov AH,$3C { Function to create a file. }
Int $21 { Call dos to create file. }
Jnc @Exit { If no error exit. }
Mov fError,AX { If there was an error save it. }
@Exit:
Mov @Result,AX { Return proper result to user. }
Pop DS { Pop DS Off the Stack. }
END;
END;{fCreate}
FUNCTION fOpen( fName :STRING; Mode :BYTE ) :WORD;
{ Routine to open already existing file defined}
{ in 'fName' with an opening mode of 'Mode'. }
{ Returns a WORD value containing the handle. }
{ Uses Int 21h/AH=3Dh. }
BEGIN
ASCIIZ(fName); { Convert fName to an ASCIIZ string. }
ASM
Push DS { Push DS onto stack. }
Mov fError,0 { Clear Error Flag. }
Mov AX,SS { Load AX with SS. }
Mov DS,AX { Now load that value into DS. }
Lea DX,fName { Now load DX with the offset of DX. }
Inc DX { Move past length byte. }
Mov AL,Mode { File Opening mode. }
Mov AH,$3D { Function to open a file. }
Int $21 { Call dos to open file. }
Jnc @Exit { If no error exit. }
Mov fError,AX { If there was an error save it. }
@Exit:
Mov @Result,AX { Return proper result to user. }
Pop DS { Restore DS from stack. }
END;
END;{fOpen}
PROCEDURE fRead( fHandle :WORD; VAR Buff; NTRead:WORD; VAR ARead :WORD );
ASSEMBLER; { Reads 'NTRead' bytes of data from 'fHandle' }
{ and puts it in 'Buff'. The actually amount }
{ of bytes read is returned in 'ARead'. }
{ Uses Int 21h/AH=3Fh. }
ASM
Push DS { Push DS onto the stack. }
Mov fError,0 { Clear Error flag. }
Mov AH,$3F { Function to read from a file. }
Mov BX,fHandle { load handle of file to read. }
Mov CX,NTRead { # of bytes to read. }
LDS DX,Buff { Point DS:DX to buffer. }
Int $21 { Call Dos to read file. }
LDS DI,ARead { Point to amount read. }
Mov WORD PTR DS:[DI],AX { Save amount actually read. }
Jnc @Exit { if there was no error exit. }
Mov fError,AX { If there was Save error code. }
@Exit:
Pop DS { Pop DS off the stack. }
END;{fRead}
PROCEDURE fWrite( fHandle :WORD; VAR Buff; NTWrite:WORD; VAR AWrite :WORD );
ASSEMBLER; { Writes 'NTWrite' bytes of info from 'Buff' }
{ to 'fHandle'. The actually amount written is }
{ returned in 'AWrite'. }
{ Uses Int 21h/AH=40h. }
ASM
Push DS { Push DS onto the stack. }
Mov fError,0 { Clear Error flag. }
Mov AH,$40 { Function to write to file. }
Mov BX,fHandle { Handle of file to write to. }
Mov CX,NTWrite { # of bytes to read. }
LDS DX,Buff { Point DS:DX -> Buffer. }
Int $21 { Call Dos to write to file. }
LDS DI,AWrite { Point to amount write. }
Mov WORD PTR DS:[DI],AX { Save amount actually written. }
Jnc @Exit { If there was no error exit. }
Mov fError,AX { if there was save error code. }
@Exit:
Pop DS { Pop DS off the stack. }
END;{fWrite}
PROCEDURE fClose( fHandle :WORD ); ASSEMBLER;
{ Routine to close file 'fHandle'. This updates}
{ the directory time and size enteries. }
{ Uses Int 21h/AH=3Eh. }
ASM
Mov fError,0 { Clear Error flag }
Mov AH,$3E { Function to close file }
Mov BX,fHandle { load handle of file to close }
Int $21 { call Dos to close file }
Jnc @Exit { If there was no error exit }
Mov fError,AX { if there was save error code }
@Exit:
END;{fClose}
PROCEDURE fReset( fHandle :WORD ); ASSEMBLER;
{ Routine to reset file position pointer to the}
{ beginning of 'fHandle'. }
{ Uses Int 21h/AH=42h. }
ASM
Mov fError,0 { Clear error flag. }
Mov AH,$42 { Function to move file pointer. }
Mov BX,fHandle { Handle of file. }
Mov AL,0 { Offset relative to begining. }
Mov CX,0 { CX:DX = offset from begining of file }
Mov DX,0 { to move to. }
Int $21 { Call dos to change file pointer. }
Jnc @Exit { If there was no error exit. }
Mov fError,AX { If there was save error code. }
@Exit:
END;{fReset}
PROCEDURE fAppend( fHandle :WORD); ASSEMBLER;
{ Routine to move the File position pointer of }
{ 'fHandle' to the end of the file. Any further}
{ writing is added to the end of the file. }
{ Uses Int 21h/AH=42h. }
ASM
Mov fError,0 { Clear error flag. }
Mov AH,$42 { Function to change file ptr position. }
Mov BX,fHandle { handle of file to change. }
Mov AL,$02 { Change relative to end of file. }
Mov CX,0 { CX:DX = offset from end of file }
Mov DX,0 { to move to. }
Int $21 { Call dos to move file ptr. }
Jnc @Exit { If there was no error exit. }
Mov fError,AX { If there was save error code. }
@Exit:
END;{fAppend}
PROCEDURE fSeek( fHandle :WORD; fOfs :LONGINT ); ASSEMBLER;
{ Routine to move the file position pointer for}
{ 'fHandle' to 'fOfs'. 'fOfs' is the actual }
{ byte position in the file to move to. }
{ Uses Int 21h/AH=42h. }
ASM
Mov fError,0 { Clear error flag. }
Mov AH,$42 { Function to change file ptr position. }
Mov BX,fHandle { handle of file to change. }
Mov AL,$00 { Change relative to start of file. }
Mov CX,fOfs[2].WORD { CX:DX = offset from start of file }
Mov DX,fOfs.WORD { to move to. }
Int $21 { Call dos to move file ptr. }
Jnc @Exit { If there was no error exit. }
Mov fError,AX { If there was save error code. }
@Exit:
END;{fSeek}
PROCEDURE fErase( fName :STRING );
{ Routine to erase 'fName'. }
{ Uses Int 21h/AH=41h. }
BEGIN
ASCIIZ(fName); { Convert fName to an ASCIIZ string. }
ASM
Push DS { Push DS onto the stack. }
Mov fError,0 { Clear error flag. }
Mov AX,SS { Load AX with SS. }
Mov DS,AX { Now load that value into DS. }
Lea DX,fName { Now load DX with the offset of DX. }
Inc DX
Mov AH,$41 { Function to erase a file. }
Int $21 { Call dos to erase file. }
Jnc @Exit { If no error exit. }
Mov fError,AX { if there was error save error code. }
@Exit:
Pop DS { Pop DS off the stack. }
END;
END;{fErase}
FUNCTION fPos( fHandle :WORD ) :LONGINT; ASSEMBLER;
{ Routine to return the current position within}
{ 'fHandle'. }
{ Uses Int 21h/AH=42. }
ASM
Mov fError,0 { Clear error flag. }
Mov AH,$42 { Function to move file pointer. }
Mov BX,fHandle { Handle of file. }
Mov AL,1 { Offset relative to current pos. }
Mov CX,0 { CX:DX = offset from current position }
Mov DX,0 { to move to. }
Int $21 { Call dos to change file pointer. }
Jnc @Exit { If there was no error return result. }
Mov fError,AX { If there was save error code. }
@Exit: { Int already returns DX:AX as file pos.}
END;{fPos}
FUNCTION fEof( fHandle :WORD ) :BOOLEAN;
{ Routine to determine whether or not we're }
{ currently at the end of file 'fHandle'. }
VAR
CurOfs :LONGINT; { current file offset. }
BEGIN
CurOfs := fPos(fHandle); { Save Current Pos. }
fAppend(fHandle); { Move to the end of the file. }
fEof := (CurOfs = fPos(fHandle)); { was current pos = end pos?. }
fSeek(fHandle,CurOfs); { Restore to original file position. }
END;{fEof}
FUNCTION fExist( fName :STRING ) :BOOLEAN;
{ Routine to determine whether or not 'fName' }
{ exists. }
BEGIN
fExist := ( FSearch(fName,'') <> '');
END;{fExist}
FUNCTION fGetAttr( fName :STRING ) :BYTE;
{ Routine to return the current file attribute }
{ of 'fName'. }
{ Uses Int 21h/AH=43h,AL=00h. }
BEGIN
ASCIIZ(fName); { Convert fName to an ASCIIZ string. }
ASM
Push DS { Push DS onto the stack. }
Mov fError,0 { Clear error flag. }
Mov AX,SS { Load AX with SS. }
Mov DS,AX { Now load that value into DS. }
Lea DX,fName { Now load DX with the offset of DX. }
Inc DX
Mov AX,$4300 { Function to Get file Attrib. }
Int $21 { Call dos to get attr. }
Jnc @Success { If no error return proper info. }
Mov fError,AX { if there was error save error code. }
@Success:
Mov AX,CX
Mov @Result,AL { Return proper result to user. }
Pop DS { Pop DS off the stack. }
END;
END;{fGetAttr}
PROCEDURE fSetAttr( fName :STRING; NAttr :BYTE );
{ Routine to set file attribute of 'fName' to }
{ 'NAttr'. }
{ Uses Int 21h/AH=43h,AL=01h. }
BEGIN
ASCIIZ(fName); { Convert fName to an ASCIIZ string. }
ASM
Push DS { Push DS onto the stack. }
Mov fError,0 { Clear error flag. }
Mov AX,SS { Load AX with SS. }
Mov DS,AX { Now load that value into DS. }
Lea DX,fName { Now load DX with the offset of DX. }
Inc DX { Point to first char after length byte.}
Xor CX,CX { Clear CX. }
Mov CL,NAttr { Load New attribute byte. }
Mov AX,$4301 { Function to Set file Attrib. }
Int $21 { Call dos to set attrib. }
Jnc @Exit { If no error exit. }
Mov fError,AX { if there was error save error code. }
@Exit:
Pop DS { Pop DS off the stack. }
END;
END;{fSetAttr}
PROCEDURE fSetVerify( On_Off :BOOLEAN ); ASSEMBLER;
{ Routine to set the DOS verify flag ON or OFF.}
{ depending on 'On_Off'. }
{ TRUE = ON, FALSE = OFF. }
{ Uses Int 21h/AH=2Eh. }
ASM
Mov AH,$2E { Interrupt Subfunction. }
Mov DL,0 { Clear DL. }
Mov AL,On_Off { 0(FALSE) = off, 1(TRUE) = on. }
Int $21 { Call Dos. }
END;{fSetVerify}
FUNCTION fGetVerify :BOOLEAN; ASSEMBLER;
{ Routine to return the current state of the }
{ DOS verify flag. }
{ Uses Int 21h/AH=54h. }
ASM
Mov AH,$54 { Interrupt Subfunction }
Int $21 { Call Dos }
END;{fGetVerify}
FUNCTION fSize( fHandle :WORD ) :LONGINT;
{ Routine to determine the size in bytes of }
{ 'fHandle'. }
VAR
CurOfs :LONGINT; { Holds original file pointer. }
BEGIN
CurOfs := fPos(fHandle); { Save current file pointer. }
fAppend(fHandle); { Move to end of file. }
fSize := fPos(fHandle); { Save current pos which equals size. }
fSeek(fHandle,CurOfs); { Restore original file pos. }
END;{fSize}
PROCEDURE fFlush( fHandle :WORD ); ASSEMBLER;
{ Flushes any File buffers for 'fHandle' }
{ immediately and updates the directory entry. }
{ Uses Int 21h/AH=68h. }
ASM
Mov fError,0 { Clear error flag. }
Mov AH,$68 { Function to Commit file to disk. }
Mov BX,fHandle { Load handle of file to Commit. }
Int $21 { Call dos to flush file. }
Jnc @Exit { If no error exit. }
Mov fError,AX { if there was error save error code. }
@Exit:
END;{fSetAttr}
PROCEDURE fLock( fHandle :WORD; LockInf :LockType; StartOfs,Len :LONGINT );
{ Routine to lock/unlock parts of a open file. }
ASSEMBLER; { Locking or unlock is determined by 'LockInf'. }
{ Uses Int 21h/AH=5Ch. }
ASM
Mov fError,0 { Clear Error Flag. }
Mov AH,$5C { Function to lock/unlock part of a file.}
Mov AL,LockInf { Load whether to lock/unlock file area.}
Mov BX,fHandle { Handle of file to lock. }
Mov CX,StartOfs.WORD[0] { Load StartOfs Into CX:DX. }
Mov DX,StartOfs.WORD[2]
Mov SI,Len.WORD[0] { Load Len Into SI:DI. }
Mov DI,Len.WORD[2]
Int $21 { Call dos to lock area. }
Jnc @Exit { If no error exit. }
Mov fError,AX { If there was an error save it. }
@Exit:
END;{fLock}
BEGIN
END.{FileIO}