-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMILES.PAS
More file actions
725 lines (576 loc) · 15.8 KB
/
MILES.PAS
File metadata and controls
725 lines (576 loc) · 15.8 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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
{This Unit provides functions to collect driver information from Miles Design Audio Interface Library
Sound driver files.
v0.1 - 2018/07/09 by Jan Knipperts
Note: does not read the driver description}
Unit Miles;
interface
uses misc,dos;
const
maxdrv = 31; {maximum number of drivers}
type
milesdrvinfo = record
drvfile : string; {name of driver files}
option : array[0..9] of string[20]; {options}
numopt : byte; {number of options}
name : string; {name of soundcard / driver}
end;
var
digs : array[0..maxdrv] of milesdrvinfo; {List of digital drivers with options}
mids : array[0..maxdrv] of milesdrvinfo; {List of midi drivers with options}
numdig : byte; {number of digital sound drivers}
nummid : byte; {number of midi sound drivers}
Function LowerCase(up : string) : string;
{Converts a string to lowercase chars}
Function UpperCase(low : string) : string;
{Converts a string to uppercase chars}
Procedure FindDigitalAudoDrivers;
{find all digital audio driver files and reads the options for them from
AILDRVR.LST. All information are stored in "digs"}
Procedure FindMidiAudoDrivers;
{find all midi audio driver files and reads the options for them from
AILDRVR.LST. All information are stored in "mids"}
Function DetectHardware(device : milesdrvinfo) : Boolean;
Function Selectable(device : milesdrvinfo) : Boolean;
{Can driver be selected as default?}
Function Configureable(device : milesdrvinfo) : Boolean;
{Driver configuraeble by user?}
Function useBLASTER(device : milesdrvinfo) : Boolean;
{Use BLASTER variable to configure?}
Function highDMA(device : milesdrvinfo) : Boolean;
{Uses a second DMA address?}
Function PortOnly(device : milesdrvinfo) : Boolean;
{Uses only I/O address?}
function GetBLASTERSettings(var BaseIO, IRQ, DMA, DMA16: word): boolean;
{Get settings from BLASTER environment var}
implementation
const
title = 'Miles Design Audio Interface Library Sound driver information - by Jan Knipperts';
digid = 'AIL3DIG';
mdiid = 'AIL3MDI';
listfile = 'AILDRVR.LST';
DescBegin = '.SPECIAL_TEXT';
DescEnd = '.END_SPECIAL_TEXT';
var
a,list : text;
f : file;
info : milesdrvinfo;
dummy : string;
name : string;
dc,oc : byte;
Function LowerCase(up : string) : string;
{Converts a string to lowercase chars}
var low : string;
sz : byte;
begin
low := '';
for sz := 1 to length(up) do
begin
if up[sz] in ['A'..'Z'] then
begin
low := low + char( ( ord(up[sz]) + 32) );
end
else
begin
low := low + up[sz];
end;
end;
LowerCase := low;
end;
Function UpperCase(low : string) : string;
{Converts a string to uppercase chars}
var up : string;
sz : byte;
begin
up := '';
for sz := 1 to length(low) do
begin
up := up+upcase(low[sz]);
end;
UpperCase := up;
end;
function GetSetting(BLASTER: string; Letter: char; Hex: boolean; var Value: word): boolean;
var
EnvStr: string;
NumStr: string;
ErrorCode: integer;
begin
EnvStr := BLASTER + ' ';
Delete(EnvStr, 1, Pos(Letter, EnvStr));
NumStr := Copy(EnvStr, 1, Pos(' ', EnvStr)-1);
if Hex
then Val('$' + NumStr, Value, ErrorCode)
else Val(NumStr, Value, ErrorCode);
if ErrorCode <> 0
then GetSetting := false
else GetSetting := true;
end;
function GetBLASTERSettings(var BaseIO, IRQ, DMA, DMA16: word): boolean;
var
EnvStr: string;
i: byte;
begin
EnvStr := GetEnv('BLASTER');
for i := 1 to Length(EnvStr) do EnvStr[i] := UpCase(EnvStr[i]);
GetBLASTERSettings := true;
if EnvStr = ''
then
GetBLASTERSettings := false
else
begin
if not(GetSetting(EnvStr, 'A', true, BaseIO))
then GetBLASTERSettings := false;
if not(GetSetting(EnvStr, 'I', false, IRQ))
then GetBLASTERSettings := false;
if not(GetSetting(EnvStr, 'D', false, DMA))
then GetBLASTERSettings := false;
GetSetting(EnvStr, 'H', false, DMA16);
end;
end;
Function GetRealName(filename : string) : string;
{Reads the name directly from the driver file
(and checks the file by the way)}
var Idstring : array[1..7] of char;
c,c1 : byte;
name : string;
begin
name := '';
assign(f,filename);
reset(f,1);
blockread(f,idstring,sizeof(idstring));
if (idstring = DIGID) or (idstring = MDIID) then
begin
seek(f,186);
blockread(f,c,1);
blockread(f,c1,1);
if ( upcase(chr(c)) in ['A'..'Z']) and
( upcase(chr(c1)) in ['A'..'Z']) then
begin
name := name + chr(c);
name := name + chr(c1);
end
else
begin
seek(f,1888);
end;
while (c > 0) and (filepos(f) < filesize(f)) do
begin
blockread(f,c,1);
name := name + chr(c);
end;
end;
close(f);
GetRealName := name;
end;
Function FindA(search : string) : boolean;
var autoexec,s : string;
begin
autoexec := copy(GetEnv('COMSPEC'),1,3);
autoexec := autoexec + 'AUTOEXEC.BAT';
search := uppercase(search);
if fileexist(autoexec) then
begin
assign(a,autoexec);
reset(a);
while not eof(a) do
begin
readln(a,s);
if pos(search,uppercase(s)) > 0 then
begin
close(a);
FindA := true;
exit;
end;
end;
close(a);
end;
FindA := false;
end;
Function FindC(search : string) : boolean;
var config,s : string;
begin
config := copy(GetEnv('COMSPEC'),1,3);
config := config + 'CONFIG.SYS';
search := uppercase(search);
if fileexist(config) then
begin
assign(a,config);
reset(a);
while not eof(a) do
begin
readln(a,s);
if pos(search,uppercase(s)) > 0 then
begin
close(a);
FindC := true;
exit;
end;
end;
close(a);
end;
FindC := false;
end;
Procedure SkipCommentBlock;
{skips empty lines and comments in the AILDRVR.LST file}
begin
readln(list,dummy);
while (dummy[1] = ';') or
(dummy = '') or
(dummy[1] = ' ') do
readln(list,dummy);
end;
Procedure SkipDescriptionBlock;
{skips the driver description in the AILDRVR.LST file}
begin
readln(list,dummy);
while dummy <> DescEnd do
begin
readln(list,dummy);
end;
end;
Procedure ReadDriverBlock;
{Reads the information and options for the driver.
outputs them in "info"}
begin
info.drvfile := dummy;
readln(list,dummy);
SkipCommentBlock;
oc := 0;
while (dummy[1] = '.') and
(dummy <> '.NAME') and
(dummy <> DescBegin) do
begin
info.option[oc] := dummy;
readln(list,dummy);
if dummy = '' then readln(list,dummy);
inc(oc);
end;
info.numopt := oc;
if dummy = '.NAME' then
begin
readln(list,dummy);
info.name := dummy;
readln(list,dummy);
end;
if (dummy = '') or (dummy[1] = ';') then SkipCommentBlock;
if dummy = DescBegin then SkipDescriptionBlock;
end;
Procedure LookupInfo(search : string);
{looks for a specific driverinformation in the AILDRVR.LST and reads them}
begin
fillchar(info,sizeof(info),0);
assign(list,listfile);
reset(list);
while not eof(list) do
begin
readln(list,dummy);
if dummy = search then
begin
ReadDriverBlock;
break;
end;
end;
close(list);
end;
Function Selectable(device : milesdrvinfo) : Boolean;
{Can driver be selected as default?}
var option, param, s : string;
begin
if device.numopt > 0 then
begin
for oc := 0 to device.numopt-1 do
begin
if pos(' ',device.option[oc]) > 0 then
begin
option := copy(device.option[oc],1,pos(' ',device.option[oc])-1);
param := copy(device.option[oc],pos(' ',device.option[oc])+1,length(device.option[oc]));
end
else
begin
option := device.option[oc];
param := '';
end;
if option = '.ND' then
begin
Selectable := FALSE;
exit;
end;
end;
end;
end;
Function PortOnly(device : milesdrvinfo) : Boolean;
{Uses only I/O address?}
var option, param, s : string;
begin
if device.numopt > 0 then
begin
for oc := 0 to device.numopt-1 do
begin
if pos(' ',device.option[oc]) > 0 then
begin
option := copy(device.option[oc],1,pos(' ',device.option[oc])-1);
param := copy(device.option[oc],pos(' ',device.option[oc])+1,length(device.option[oc]));
end
else
begin
option := device.option[oc];
param := '';
end;
if option = '.IOA' then
begin
PortOnly := True;
exit;
end;
end;
end;
PortOnly := false;
end;
Function Configureable(device : milesdrvinfo) : Boolean;
{Driver configuraeble by user?}
var option, param, s : string;
begin
if device.numopt > 0 then
begin
for oc := 0 to device.numopt-1 do
begin
if pos(' ',device.option[oc]) > 0 then
begin
option := copy(device.option[oc],1,pos(' ',device.option[oc])-1);
param := copy(device.option[oc],pos(' ',device.option[oc])+1,length(device.option[oc]));
end
else
begin
option := device.option[oc];
param := '';
end;
if option = '.ION' then
begin
Configureable := FALSE;
exit;
end;
end;
end;
end;
Function highDMA(device : milesdrvinfo) : Boolean;
{Uses a second DMA address?}
var option, param, s : string;
begin
if device.numopt > 0 then
begin
for oc := 0 to device.numopt-1 do
begin
if pos(' ',device.option[oc]) > 0 then
begin
option := copy(device.option[oc],1,pos(' ',device.option[oc])-1);
param := copy(device.option[oc],pos(' ',device.option[oc])+1,length(device.option[oc]));
end
else
begin
option := device.option[oc];
param := '';
end;
if option = '.IOL' then
begin
highDMA := false;
exit;
end;
end;
end;
end;
Function useBLASTER(device : milesdrvinfo) : Boolean;
{Use BLASTER variable to configure?}
var option, param, s : string;
begin
if device.numopt > 0 then
begin
for oc := 0 to device.numopt-1 do
begin
if pos(' ',device.option[oc]) > 0 then
begin
option := copy(device.option[oc],1,pos(' ',device.option[oc])-1);
param := copy(device.option[oc],pos(' ',device.option[oc])+1,length(device.option[oc]));
end
else
begin
option := device.option[oc];
param := '';
end;
if option = '.IOB' then
begin
useBlaster := true;
exit;
end;
end;
end;
useBlaster := false;
end;
Procedure FindDigitalAudoDrivers;
{find all digital audio driver files and reads the options for them from
AILDRVR.LST. All information are stored in "digs"}
var fileinfo : SearchRec;
search : string;
name : string;
z : byte;
dignum : byte;
begin
if not fileexist(listfile) then
begin
nummid := 0;
exit;
end;
dignum := 0;
fillchar(digs,sizeof(digs),0);
FindFirst('*.DIG', Archive, FileInfo); { Same as DIR *.DIG }
while (DosError = 0) and (dignum <= maxdrv) do
begin
search := '['+LowerCase(FileInfo.Name)+']';
Lookupinfo(search);
name := GetRealName(FileInfo.Name);
if (info.drvfile <> '') and (name <> '') then
begin
digs[dignum] := info;
digs[dignum].name := name;
inc(dignum);
end;
FindNext(FileInfo);
end;
if dignum > 0 then numdig := dignum - 1;
end;
Procedure FindMidiAudoDrivers;
{same for the midi drivers...}
var fileinfo : SearchRec;
search : string;
name : string;
z : byte;
midnum : byte;
begin
if not fileexist(listfile) then
begin
nummid := 0;
exit;
end;
midnum := 0;
FindFirst('*.MDI', Archive, FileInfo); { Same as DIR *.MDI }
fillchar(mids,sizeof(mids),0);
while (DosError = 0) and (midnum <= maxdrv) do
begin
search := '['+LowerCase(FileInfo.Name)+']';
Lookupinfo(search);
name := GetRealName(FileInfo.Name);
if (info.drvfile <> '') and (name <> '') then
begin
mids[midnum] := info;
mids[midnum].name := name;
inc(midnum);
end;
FindNext(FileInfo);
end;
if midnum > 0 then nummid := midnum - 1;
end;
Function DetectHardware(device : milesdrvinfo) : Boolean;
var option, param, s : string;
begin
if device.numopt > 0 then
begin
for oc := 0 to device.numopt-1 do
begin
if pos(' ',device.option[oc]) > 0 then
begin
option := copy(device.option[oc],1,pos(' ',device.option[oc])-1);
param := copy(device.option[oc],pos(' ',device.option[oc])+1,length(device.option[oc]));
end
else
begin
option := device.option[oc];
param := '';
end;
if option = '.E' then
begin
if getenv(param) = '' then
begin
DetectHardware := FALSE;
exit;
end;
end;
if option = '.T1' then
begin
s := uppercase(getenv('BLASTER'));
if (pos(s,'T') > 0) then
begin
s := copy(s,pos(s,'T'),2);
if (s <> 'T1') or (s <> 'T3') then
begin
DetectHardware := FALSE;
exit;
end;
end;
end;
if option = '.T2' then
begin
s := uppercase(getenv('BLASTER'));
if (pos(s,'T') > 0) then
begin
s := copy(s,pos(s,'T'),2);
if (s <> 'T2') or (s <> 'T4') or (s <> 'T5') then
begin
DetectHardware := FALSE;
exit;
end;
end;
end;
if option = '.T3' then
begin
s := uppercase(getenv('BLASTER'));
if (pos(s,'T') > 0) then
begin
s := copy(s,pos(s,'T'),2);
if (s <> 'T6') or (s <> 'T7') then
begin
DetectHardware := FALSE;
exit;
end;
end;
end;
if option = '.NE' then
begin
if getenv(param) <> '' then
begin
DetectHardware := FALSE;
exit;
end;
end;
if option = '.A' then
begin
if FindA(param) = false then
begin
DetectHardware := FALSE;
exit;
end;
end;
if option = '.NA' then
begin
if FindA(param) = true then
begin
DetectHardware := FALSE;
exit;
end;
end;
if option = '.C' then
begin
if FindC(param) = false then
begin
DetectHardware := FALSE;
exit;
end;
end;
if option = '.NC' then
begin
if FindC(param) = true then
begin
DetectHardware := FALSE;
exit;
end;
end;
end;
end;
end;
end.