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 path0043.pas
More file actions
360 lines (315 loc) · 7.79 KB
/
Copy path0043.pas
File metadata and controls
360 lines (315 loc) · 7.79 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
{
Also, please note, this unit has not been completely tested. It may
(and most probably does) have bugs in it. If (and when) any are
discovered, please contact me, so I can update my routines also.
**************************
* SHARE.PAS v1.0 *
* *
* General purpose file *
* sharing routines *
**************************
1992-93 HyperDrive Software
Released into the public domain.
}
{$S-,R-,D-}
{$IFOPT O+}
{$F+}
{$ENDIF}
unit Share;
interface
const
MaxLockRetries : Byte = 10;
NormalMode = $02; { ---- 0010 }
ReadOnly = $00; { ---- 0000 }
WriteOnly = $01; { ---- 0001 }
ReadWrite = $02; { ---- 0010 }
DenyAll = $10; { 0001 ---- }
DenyWrite = $20; { 0010 ---- }
DenyRead = $30; { 0011 ---- }
DenyNone = $40; { 0100 ---- }
NoInherit = $70; { 1000 ---- }
type
Taskers = (NoTasker, DesqView, DoubleDOS, Windows, OS2, NetWare);
var
MultiTasking : Boolean;
MultiTasker : Taskers;
VideoSeg : Word;
VideoOfs : Word;
procedure SetFileMode(Mode : Word);
{- Set filemode for typed/untyped files }
procedure ResetFileMode;
{- Reset filemode to ReadWrite (02h) }
procedure LockFile(var F);
{- Lock file F }
procedure UnLockFile(var F);
{- Unlock file F }
procedure LockBytes(var F; Start, Bytes : LongInt);
{- Lock Bytes bytes of file F, starting with Start }
procedure UnLockBytes(var F; Start, Bytes : LongInt);
{- Unlock Bytes bytes of file F, starting with Start }
procedure LockRecords(var F; Start, Records : LongInt);
{- Lock Records records of file F, starting with Start }
procedure UnLockRecords(var F; Start, Records : LongInt);
{- Unlock Records records of file F, starting with Start }
function TimeOut : Boolean;
{- Check for LockRetry timeout }
procedure TimeOutReset;
{- Reset internal LockRetry counter }
function InDos: Boolean;
{- Is DOS busy? }
procedure GiveTimeSlice;
{- Give up remaining CPU time slice }
procedure BeginCrit;
{- Enter critical region }
procedure EndCrit;
{- End critical region }
implementation
uses
Dos;
var
InDosFlag : ^Word;
LockRetry : Byte;
procedure FLock(Handle : Word; Pos, Len : LongInt);
Inline(
$B8/$00/$5C/ { mov AX,$5C00 ;DOS FLOCK, Lock subfunction}
$8B/$5E/$04/ { mov BX,[BP + 04] ;Place file handle in Bx register}
$C4/$56/$06/ { les DX,[BP + 06] ;Load position in ES:DX}
$8C/$C1/ { mov CX,ES ;Move ES pointer to CX register}
$C4/$7E/$08/ { les DI,[BP + 08] ;Load length in ES:DI}
$8C/$C6/ { mov SI,ES ;Move ES pointer to SI register}
$CD/$21); { int $21 ;Call DOS}
procedure FUnlock(Handle : Word; Pos, Len : LongInt);
Inline(
$B8/$01/$5C/ { mov AX,$5C01 ;DOS FLOCK, Unlock subfunction}
$8B/$5E/$04/ { mov BX,[BP + 04] ;Place file handle in Bx register}
$C4/$56/$06/ { les DX,[BP + 06] ;Load position in ES:DX}
$8C/$C1/ { mov CX,ES ;Move ES pointer to CX register}
$C4/$7E/$08/ { les DI,[BP + 08] ;Load length in ES:DI}
$8C/$C6/ { mov SI,ES ;Move ES pointer to SI register}
$CD/$21); { int $21 ;Call DOS}
procedure SetFileMode(Mode : Word);
begin
FileMode := Mode;
end;
procedure ResetFileMode;
begin
FileMode := NormalMode;
end;
procedure LockFile(var F);
begin
If not MultiTasking then
Exit;
While InDos do
GiveTimeSlice;
FLock(FileRec(F).Handle, 0, FileSize(File(F)));
end;
procedure UnLockFile(var F);
begin
If not MultiTasking then
Exit;
While InDos do
GiveTimeSlice;
FLock(FileRec(F).Handle, 0, FileSize(File(F)));
end;
procedure LockBytes(var F; Start, Bytes : LongInt);
begin
If not MultiTasking then
Exit;
While InDos do
GiveTimeSlice;
FLock(FileRec(F).Handle, Start, Bytes);
end;
procedure UnLockBytes(var F; Start, Bytes : LongInt);
begin
If not MultiTasking then
Exit;
While InDos do
GiveTimeSlice;
FLock(FileRec(F).Handle, Start, Bytes);
end;
procedure LockRecords(var F; Start, Records : LongInt);
begin
If not MultiTasking then
Exit;
While InDos do
GiveTimeSlice;
FLock(FileRec(F).Handle, Start * FileRec(F).RecSize, Records * FileRec(F).RecSize);
end;
procedure UnLockRecords(var F; Start, Records : LongInt);
begin
If not MultiTasking then
Exit;
While InDos do
GiveTimeSlice;
FLock(FileRec(F).Handle, Start * FileRec(F).RecSize, Records * FileRec(F).RecSize);
end;
function TimeOut : Boolean;
begin
GiveTimeSlice;
TimeOut := True;
If MultiTasking and (LockRetry < MaxLockRetries) then
begin
TimeOut := False;
Inc(LockRetry);
end;
end;
procedure TimeOutReset;
begin
LockRetry := 0;
end;
function InDos : Boolean;
begin
InDos := InDosFlag^ > 0;
end;
procedure GiveTimeSlice; ASSEMBLER;
asm
cmp MultiTasker, DesqView
je @DVwait
cmp MultiTasker, DoubleDOS
je @DoubleDOSwait
cmp MultiTasker, Windows
je @WinOS2wait
cmp MultiTasker, OS2
je @WinOS2wait
cmp MultiTasker, NetWare
je @Netwarewait
@Doswait:
int $28
jmp @WaitDone
@DVwait:
mov AX,$1000
int $15
jmp @WaitDone
@DoubleDOSwait:
mov AX,$EE01
int $21
jmp @WaitDone
@WinOS2wait:
mov AX,$1680
int $2F
jmp @WaitDone
@Netwarewait:
mov BX,$000A
int $7A
jmp @WaitDone
@WaitDone:
end;
procedure BeginCrit; ASSEMBLER;
asm
cmp MultiTasker, DesqView
je @DVCrit
cmp MultiTasker, DoubleDOS
je @DoubleDOSCrit
cmp MultiTasker, Windows
je @WinCrit
jmp @EndCrit
@DVCrit:
mov AX,$101B
int $15
jmp @EndCrit
@DoubleDOSCrit:
mov AX,$EA00
int $21
jmp @EndCrit
@WinCrit:
mov AX,$1681
int $2F
jmp @EndCrit
@EndCrit:
end;
procedure EndCrit; ASSEMBLER;
asm
cmp MultiTasker, DesqView
je @DVCrit
cmp MultiTasker, DoubleDOS
je @DoubleDOSCrit
cmp MultiTasker, Windows
je @WinCrit
jmp @EndCrit
@DVCrit:
mov AX,$101C
int $15
jmp @EndCrit
@DoubleDOSCrit:
mov AX,$EB00
int $21
jmp @EndCrit
@WinCrit:
mov AX,$1682
int $2F
jmp @EndCrit
@EndCrit:
end;
begin
{- Init }
LockRetry:= 0;
asm
@CheckDV:
mov AX, $2B01
mov CX, $4445
mov DX, $5351
int $21
cmp AL, $FF
je @CheckDoubleDOS
mov MultiTasker, DesqView
jmp @CheckDone
@CheckDoubleDOS:
mov AX, $E400
int $21
cmp AL, $00
je @CheckWindows
mov MultiTasker, DoubleDOS
jmp @CheckDone
@CheckWindows:
mov AX, $1600
int $2F
cmp AL, $00
je @CheckOS2
cmp AL, $80
je @CheckOS2
mov MultiTasker, Windows
jmp @CheckDone
@CheckOS2:
mov AX, $3001
int $21
cmp AL, $0A
je @InOS2
cmp AL, $14
jne @CheckNetware
@InOS2:
mov MultiTasker, OS2
jmp @CheckDone
@CheckNetware:
mov AX,$7A00
int $2F
cmp AL,$FF
jne @NoTasker
mov MultiTasker, NetWare
jmp @CheckDone
@NoTasker:
mov MultiTasker, NoTasker
@CheckDone:
{-Set MultiTasking }
cmp MultiTasker, NoTasker
mov VideoSeg, $B800
mov VideoOfs, $0000
je @NoMultiTasker
mov MultiTasking, $01
{-Get video address }
mov AH, $FE
les DI, [$B8000000]
int $10
mov VideoSeg, ES
mov VideoOfs, DI
jmp @Done
@NoMultiTasker:
mov MultiTasking, $00
@Done:
{-Get InDos flag }
mov AH, $34
int $21
mov WORD PTR InDosFlag, BX
mov WORD PTR InDosFlag + 2, ES
end;
end.