-
Notifications
You must be signed in to change notification settings - Fork 4
/
SETUP.PAS
3236 lines (2744 loc) · 83.5 KB
/
SETUP.PAS
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
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{*****************************************************************************
Setup for my OPTi 82C929 Soundcard low level driver
*****************************************************************************
Version: 1.3
Date : 23.02.2019
Author : Jan Knipperts
*****************************************************************************}
Program Opti929Setup;
uses opti929,mpu,oplfm,opl4,sbpro,ad1848,
dos,textmode,misc;
type
volumes = record
DACL,
DACR,
AUX1L,
AUX1R,
AUX2L,
AUX2R,
inp,
micgain,
gain : byte;
dmix : boolean;
end;
Freqconfig = record
freq,
bits,
chan : byte;
end;
freqdata = record
xtal : byte;
rate : string;
end;
SBAdress = record
Port,
IRQ,
DMA : byte;
end;
WSSAdress = record
Port,
IRQ,
DMA,
DMA2 : byte;
end;
CDAdress = record
Port,
IRQ,
DMA,
Typ : byte;
end;
MPUAdress = record
Port,
IRQ,
DMA,
Typ : byte;
end;
const
title : string = 'OPTi82C929 Configuration v1.3 (c) 2019 by Jan Knipperts';
cfgfile : string = 'SOUND.CFG';
autoexec : string = 'AUTOEXEC.BAT';
CFIX : array[0..1] of string = ('AD18xx','CS42xx');
FM_chip : array[3..4] of string = ('OPL3','OPL4');
FM_CLK : array[2..3] of string = ('OPL2','OPL3');
DSP : array[1..4] of string = ('1.5','2.1','3.2','4.4');
SB_Port : array[1..2] of string = ('220h','240h');
SB_IRQ : array[1..4] of string = ('5','7','10','Disable');
SB_DMA : array[1..4] of string = ('0','1','3','Disable');
WSS_Port : array[1..4] of string = ('530h','E80h','F40h','604h');
WSS_IRQ : array[1..5] of string = ('7','9','10','11','Auto');
WSS_DMA : array[1..4] of string = ('0','1','3','Disable');
WSS_DMA2 : array[1..3] of string = ('0','1','Disable');
CD_PORT : array[1..4] of string = ('320h','330h','340h','360h');
CD_DMA : array[1..4] of string = ('0','1','3','Disable');
CD_IRQ : array[1..6] of string = ('5','7','9','10','11','Disable');
CD_TYP : array[1..4] of string = ('Sony','Mitsumi','Panasonic','IDE');
MPU_PORT : array[1..4] of string = ('300h','310h','320h','330h');
MPU_IRQ : array[1..4] of string = ('5','7','9/2','10');
ONOFF : array[0..1] of string = ('Disable','Enable');
FMap : array[0..1] of string = ('16+24 MHz','16 MHz');
GPMode : array[0..1] of string = ('External','Internal');
OUTMX : array[0..1] of string = ('OUT0','OPL3SCN');
Frequency : array[0..13] of freqdata = (
(xtal : 2; rate : ' 5.5 kHz'),
(xtal : 2; rate : ' 6.6 kHz'),
(xtal : 1; rate : ' 8.0 kHz'),
(xtal : 1; rate : ' 9.6 kHz'),
(xtal : 2; rate : '11.0 kHz'),
(xtal : 1; rate : '16.0 kHz'),
(xtal : 2; rate : '18.9 kHz'),
(xtal : 2; rate : '22.0 kHz'),
(xtal : 1; rate : '27.4 kHz'),
(xtal : 1; rate : '32.0 kHz'),
(xtal : 2; rate : '33.0 kHz'),
(xtal : 2; rate : '37.8 kHz'),
(xtal : 2; rate : '44.1 kHz'),
(xtal : 1; rate : '48.0 kHz'));
Bits : array[0..1] of string = (' 8-bit','16-bit');
MS : array[0..1] of string = (' Mono ','Stereo');
var
cnt,
xp,
yp,
menu,
mselect,
aselect : byte;
quit,
mpuoff,
cdoff,
irqcalled : boolean;
p : pointer;
key : char;
WSStext : WSSAdress;
SBtext : SBAdress;
MPUtext : MPUAdress;
CDtext : CDAdress;
f : file;
cfg : OPTI929config;
SBFreq,
WSSFreq : Freqconfig;
filter : byte;
CodecVolumes : Volumes;
ocnt,size,bpos,cpos : word;
s,newblaster,dir,
initstr,backup : string;
found : boolean;
DirInfo : SearchRec;
Error : word;
keyboardmode,
setdefault,
skip,
noinit,
sb : boolean;
apage : byte;
Procedure DrawSelector(xp,yp : byte; s : string);
begin
if not keyboardmode then
begin
putchar(xp+9,yp,#24,0,7);
putchar(xp+10,yp,#25,0,7);
end;
fastwrite(xp,yp,14,1,' ');
fastwrite(xp+(4-(length(s) div 2)),yp,14,1,s);
end;
Procedure Mark(x,y,l : byte);
var c : byte;
begin
if keyboardmode then
begin
for c := x to x+(l-1) do
begin
changeattr(c,y,14,4);
end;
end;
end;
Procedure UnMark(x,y,l : byte);
var c : byte;
begin
if keyboardmode then
begin
for c := x to x+(l-1) do
begin
changeattr(c,y,14,1);
end;
end;
end;
Procedure UnSelectItem(sel : byte);
var x,y,l : byte;
begin
if keyboardmode then
begin
if menu = 1 then
begin
case sel of
1: begin y := 6; x := 21; l := 9; end;
2: begin y := 7; x := 21; l := 9; end;
3: begin y := 8; x := 21; l := 9; end;
4: begin y := 11; x := 28; l := 1; end;
5: begin y := 6; x := 58; l := 9; end;
6: begin y := 7; x := 58; l := 9; end;
7: begin y := 8; x := 58; l := 9; end;
8: begin y := 11; x := 64; l := 1; end;
9: begin y := 15; x := 24; l := 1; end;
10: begin y := 16; x := 21; l := 9; end;
11: begin y := 17; x := 21; l := 9; end;
12: begin y := 19; x := 26; l := 1; end;
13: begin y := 15; x := 67; l := 1; end;
14: begin y := 16; x := 56; l := 9; end;
15: begin y := 17; x := 56; l := 9; end;
16: begin y := 18; x := 56; l := 9; end;
17: begin y := 19; x := 56; l := 9; end;
18: begin y := 21; x := 13; l := 16; end;
19: begin y := 21; x := 34; l := 13; end;
20: begin y := 21; x := 52; l := 13; end;
end;
if y < 21 then unmark(x,y,l);
end;
if menu = 2 then
begin
if apage = 0 then
begin
case sel of
1: begin y := 7; x := 42; l := 9; end;
2: begin y := 8; x := 42; l := 9; end;
3: begin y := 8; x := 52; l := 9; end;
4: begin y := 8; x := 63; l := 9; end;
5: begin y := 9; x := 42; l := 9; end;
6: begin y := 9; x := 52; l := 9; end;
7: begin y := 9; x := 63; l := 9; end;
8: begin y := 10; x := 42; l := 9; end;
9: begin y := 11; x := 42; l := 9; end;
10: begin y := 12; x := 42; l := 9; end;
11: begin y := 13; x := 42; l := 9; end;
12: begin y := 14; x := 42; l := 9; end;
13: begin y := 15; x := 42; l := 9; end;
14: begin y := 16; x := 42; l := 9; end;
15: begin y := 17; x := 42; l := 9; end;
16: begin y := 18; x := 42; l := 9; end;
17: begin y := 19; x := 42; l := 9; end;
18: begin y := 22; x := 9; l := 6; end;
19: begin y := 22; x := 44; l := 11; end;
end;
if y < 22 then unmark(x,y,l);
end
else
begin
case sel of
1: begin y := 7; x := 42; l := 9; end;
2: begin y := 8; x := 42; l := 9; end;
3: begin y := 9; x := 42; l := 9; end;
4: begin y := 10; x := 42; l := 9; end;
5: begin y := 11; x := 42; l := 9; end;
6: begin y := 12; x := 42; l := 9; end;
7: begin y := 13; x := 42; l := 9; end;
8: begin y := 14; x := 42; l := 9; end;
9: begin y := 15; x := 42; l := 9; end;
10: begin y := 22; x := 9; l := 6; end;
11: begin y := 22; x := 44; l := 11; end;
end;
if y < 22 then unmark(x,y,l);
end;
end;
end;
end;
Procedure SelectItem(sel : byte);
var x,y,l : byte;
begin
if keyboardmode then
begin
if menu = 1 then
begin
case sel of
1: begin y := 6; x := 21; l := 9; end;
2: begin y := 7; x := 21; l := 9; end;
3: begin y := 8; x := 21; l := 9; end;
4: begin y := 11; x := 28; l := 1; end;
5: begin y := 6; x := 58; l := 9; end;
6: begin y := 7; x := 58; l := 9; end;
7: begin y := 8; x := 58; l := 9; end;
8: begin y := 11; x := 64; l := 1; end;
9: begin y := 15; x := 24; l := 1; end;
10: begin y := 16; x := 21; l := 9; end;
11: begin y := 17; x := 21; l := 9; end;
12: begin y := 19; x := 26; l := 1; end;
13: begin y := 15; x := 67; l := 1; end;
14: begin y := 16; x := 56; l := 9; end;
15: begin y := 17; x := 56; l := 9; end;
16: begin y := 18; x := 56; l := 9; end;
17: begin y := 19; x := 56; l := 9; end;
18: begin y := 21; x := 13; l := 16; end;
19: begin y := 21; x := 34; l := 13; end;
20: begin y := 21; x := 52; l := 13; end;
end;
end;
if menu = 2 then
begin
if apage = 0 then
begin
case sel of
1: begin y := 7; x := 42; l := 9; end;
2: begin y := 8; x := 42; l := 9; end;
3: begin y := 8; x := 52; l := 9; end;
4: begin y := 8; x := 63; l := 9; end;
5: begin y := 9; x := 42; l := 9; end;
6: begin y := 9; x := 52; l := 9; end;
7: begin y := 9; x := 63; l := 9; end;
8: begin y := 10; x := 42; l := 9; end;
9: begin y := 11; x := 42; l := 9; end;
10: begin y := 12; x := 42; l := 9; end;
11: begin y := 13; x := 42; l := 9; end;
12: begin y := 14; x := 42; l := 9; end;
13: begin y := 15; x := 42; l := 9; end;
14: begin y := 16; x := 42; l := 9; end;
15: begin y := 17; x := 42; l := 9; end;
16: begin y := 18; x := 42; l := 9; end;
17: begin y := 19; x := 42; l := 9; end;
18: begin y := 22; x := 9; l := 6; end;
19: begin y := 22; x := 44; l := 11; end;
end;
end
else
begin
case sel of
1: begin y := 7; x := 42; l := 9; end;
2: begin y := 8; x := 42; l := 9; end;
3: begin y := 9; x := 42; l := 9; end;
4: begin y := 10; x := 42; l := 9; end;
5: begin y := 11; x := 42; l := 9; end;
6: begin y := 12; x := 42; l := 9; end;
7: begin y := 13; x := 42; l := 9; end;
8: begin y := 14; x := 42; l := 9; end;
9: begin y := 15; x := 42; l := 9; end;
10: begin y := 22; x := 9; l := 6; end;
11: begin y := 22; x := 44; l := 11; end;
end;
end;
end;
mark(x,y,l);
end;
end;
Procedure HLine(y : byte);
begin
putchar(4,y,#199,15,1);
for cnt := 5 to 77 do
putchar(cnt,y,#196,15,1);
putchar(77,y,#182,15,1);
end;
Procedure Button(x,y : byte; name : string; pressed : boolean);
var col,c : byte;
begin
if pressed then col := 1 else col := 0;
fastwrite(x,y,0,7,name);
c := 1;
while (name[c] = ' ') and (c <= length(name)) do inc(c);
putchar(x+(c-1),y,name[c],4,7);
for c := x+1 to x+length(name) do fastwrite(c,y+1,col,1, 'ß');
fastwrite(x+length(name),y,col,1, 'Ü');
end;
Procedure Wait_for_Mousebutton;
begin
repeat
Mouse_Read;
while iskeypressed do getkey;
until mouse.b = 0;
key := #0;
case menu of
1: selectitem(mselect);
2: selectitem(aselect);
3: selectitem(aselect);
end;
end;
Procedure MapCFGtoText;
begin
if cfg.sbbase = $220 then sbtext.port := 1 else sbtext.port := 2;
case cfg.sbIRQ of
5: sbtext.irq := 1;
7: sbtext.irq := 2;
10: sbtext.irq := 3;
$FF: sbtext.irq := 4;
end;
case cfg.sbdma of
0: sbtext.dma := 1;
1: sbtext.dma := 2;
3: sbtext.dma := 3;
$FF: sbtext.dma := 4;
end;
case cfg.wssbase of
$530: wsstext.port := 1;
$E80: wsstext.port := 2;
$F40: wsstext.port := 3;
$604: wsstext.port := 4;
end;
case cfg.wssIRQ of
7: wsstext.irq := 1;
9: wsstext.irq := 2;
10: wsstext.irq := 3;
11: wsstext.irq := 4;
$FF: wsstext.irq := 5;
end;
case cfg.wssDMA of
0: wsstext.dma := 1;
1: wsstext.dma := 2;
3: wsstext.dma := 3;
$FF: wsstext.dma := 4;
end;
case cfg.mpubase of
$300: mputext.port := 1;
$310: mputext.port := 2;
$320: mputext.port := 3;
$330: mputext.port := 4;
end;
case cfg.mpuirq of
5: mputext.irq := 1;
7: mputext.irq := 2;
9: mputext.irq := 3;
10: mputext.irq := 4;
end;
cdtext.typ := cfg.cdtype;
case cfg.cdbase of
$320: cdtext.port := 1;
$330: cdtext.port := 2;
$340: cdtext.port := 3;
$360: cdtext.port := 4;
end;
case cfg.cddma of
0: cdtext.dma := 1;
1: cdtext.dma := 2;
3: cdtext.dma := 3;
$FF: cdtext.dma := 4;
end;
case cfg.cdirq of
5: cdtext.irq := 1;
7: cdtext.irq := 2;
9: cdtext.irq := 3;
10: cdtext.irq := 4;
11: cdtext.irq := 5;
$FF: cdtext.irq := 6;
end;
end;
Procedure SetDefaultcfg; {Sets the default configuration}
begin
with cfg do
begin
initmode := 0; {Enable Sound Blaster Mode}
powerdwn := 0; {Disable Powerdown mode}
silence := 0; {Mute is disabled}
Cfix := 1; {We assume a Crystal codec because the AD codec run aslo well with this setting but the CS does not with AD's}
shprotect := 1; {Shadow Register protection is enabled}
access := 0; {No access to codec in SB Mode}
wave := 1;
filter := 1;
CDTYPE := $FF; {Disable CD-ROM}
CDBASE := $340; {340h as dummy CD-ROM I/O Port}
CDIRQ := $FF; {No IRQ for disabled CD-ROM}
CDDMA := 3; {Seit DMA channel 3 as dummy for disbaled CD-ROM}
SBBASE := $220; {Set SB I/O Port to the default 220h}
SBIRQ := 5; {..IRQ 5}
SBDMA := 1; {..DMA 1}
SBVER := 3; {SB DSP Version is 3.1}
FMAP := 0; {Use both crystals for SB Frequencymapping}
FIFO := 1; {Enable command FiFo in SB Mode}
SBMIX := 1; {Enable Sound Blaser Mixer chip emulation}
AUTOVOL := 0; {Disable Automatic volume control}
ADPCM := 1; {Enable ADPCM}
TIMEOUT := 1; {Enable Timeout ackonwledge}
DMAWD := 0; {Disable DMA watch dog}
ATTN := 1; {Enable attunation}
WSSBase := $530; {WSS Port}
WSSDMA := 1; {WSS playback DMA 1}
WSSIRQ := $FF; {WSS Auto IRQ}
GPEN := 1; {GamePort enabled}
GPMODE := 1; {Use internal timer for Gameport}
OUTMX := 0; {Timing mode is OPL3SCn}
GPOUT := 0; {General purpose outputs are disabled}
if OPL4_detect then
begin
OPL := 4; {OPL 4 FM}
end
else
begin
OPL := 3;
end;
FMCLK := 3; {Use OPL 3 clock}
MPU401 := 1; {MPU-401 enabled}
MPUBASE := $330; {MPU401 Port}
MPUIRQ := 9; {MPU401 IRQ}
end;
fillchar(codecvolumes,sizeof(codecvolumes),15); {middle all volumes}
codecvolumes.dacl := 30;
codecvolumes.dacr := 30;
codecvolumes.inp := Postmx; {Post mix input}
codecvolumes.micgain := 0; {disable +20 db mic gain}
codecvolumes.gain := 0; {set gain to 0, mute input}
codecvolumes.dmix := true; {digital mix enabled}
SBFreq.freq := 7; {22050 Hz, 8 Bit, Stereo}
SBFreq.bits := 0;
SBFreq.chan := 1;
WSSFreq.freq := 12; {44100 Hz, 16 Bit, Stereo}
WSSFreq.bits := 1;
WSSFreq.chan := 1;
end;
Procedure LoadCfg;
begin
write('Loading configuration...');
assign(f,cfgfile);
reset(f,1);
if filesize(f) <>
(sizeof(cfg)+(2*sizeof(freqconfig))+sizeof(volumes)+1) then
begin
writeln('ERROR!');
writeln('');
writeln('Configuration file is damaged!');
writeln('Creating a new file with default settings.');
writeln('');
writeln('Press any key to continue....');
waitkey;
setDefaultcfg;
close(f);
end
else
begin
{$I-}
blockread(f,cfg,sizeof(cfg));
blockread(f,sbfreq,sizeof(freqconfig));
blockread(f,wssfreq,sizeof(freqconfig));
blockread(f,filter,sizeof(filter));
blockread(f,codecvolumes,sizeof(codecvolumes));
if IOResult <> 0 then
begin
writeln('ERROR!');
writeln('');
writeln('Settings could not be read!');
writeln('Using default settings.');
writeln('');
writeln('Press any key to continue....');
waitkey;
setDefaultcfg;
end;
close(f);
writeln('');
end;
MapCFGtoText;
end;
Procedure SaveCfg;
begin
assign(f,cfgfile);
{$I-}
rewrite(f,1);
{$I+}
if IOResult <> 0 then
begin
clrscr;
writeln('ERROR!');
writeln('');
writeln('Configuration file could not be written! ');
writeln('Settings were not saved!');
writeln('');
close(f);
cursor(true);
halt(1);
end;
{$I-}
blockwrite(f,cfg,sizeof(cfg));
blockwrite(f,sbfreq,sizeof(freqconfig));
blockwrite(f,wssfreq,sizeof(freqconfig));
blockwrite(f,filter,sizeof(filter));
blockwrite(f,codecvolumes,sizeof(codecvolumes));
{$I+}
if IOResult <> 0 then
begin
clrscr;
writeln('ERROR!');
writeln('');
writeln('Configuration file could not be written! ');
writeln('Settings were not saved!');
writeln('');
close(f);
cursor(true);
halt(1);
end;
close(f);
writeln('Settings have been saved.');
end;
Procedure CenteredText(y,c : byte; s : string);
begin
fastwrite(40-(length(s) div 2),y,c,1,s);
end;
Procedure DelChars(x,y,c : byte);
var cnt : byte;
begin
for cnt := x to x+c do
putchar(cnt,y,' ',15,1);
end;
Procedure Draw_Main_Menu;
var c : byte;
begin
MapCFGtoText;
fillchar(p^,4000,0);
writeto(p);
InitMenuScreen(title);
Window(4,3,77,23,15,1,true);
putchar(40,3,'Ñ',15,1);
for cnt := 4 to 19 do
putchar(40,cnt,'³',15,1);
fastwrite(9,4,14,1,'Sound Blaster configuration');
fastwrite(9,6,15,1,'Address:');
fastwrite(9,7,15,1,'Interrupt:');
fastwrite(9,8,15,1,'DMA:');
Drawselector(21,6,SB_Port[sbtext.port]);
Drawselector(21,7,SB_IRQ[sbtext.irq]);
Drawselector(21,8,SB_DMA[sbtext.dma]);
fastwrite(9,11,14,1,'Set SB as default [ ]');
fastwrite(44,4,14,1,'WSS configuration');
fastwrite(44,6,15,1,'Address:');
fastwrite(44,7,15,1,'Interrupt:');
fastwrite(44,8,15,1,'Playback DMA:');
fastwrite(44,11,14,1,'Set WSS as default [ ]');
Drawselector(58,6,WSS_Port[wsstext.port]);
Drawselector(58,7,WSS_IRQ[wsstext.irq]);
Drawselector(58,8,WSS_DMA[wsstext.dma]);
HLine(12);
putchar(40,12,'Å',15,1);
fastwrite(9,13,14,1,'MPU401 configuration');
fastwrite(9,15,15,1,'Enable MPU401 [ ]');
if cfg.mpu401 = 1 then
begin
fastwrite(9,16,15,1,'Address:');
fastwrite(9,17,15,1,'Interrupt:');
Drawselector(21,16,MPU_Port[mputext.port]);
Drawselector(21,17,MPU_IRQ[mputext.irq]);
end;
fastwrite(9,19,15,1,'Enable gameport [ ]');
fastwrite(44,13,14,1,'CD-ROM configuration');
fastwrite(44,15,15,1,'Enable CD-ROM support [ ]');
if ((cfg.CDTYPE <> $FF) and (cfg.CDIRQ <> $FF)) then
begin
putchar(67,15,'x',15,1);
fastwrite(44,16,15,1,'Type:');
fastwrite(44,17,15,1,'Address:');
fastwrite(44,18,15,1,'Interrupt:');
fastwrite(44,19,15,1,'DMA:');
Drawselector(56,16,CD_TYP[cdtext.typ]);
Drawselector(56,17,CD_PORT[cdtext.port]);
Drawselector(56,18,CD_IRQ[cdtext.irq]);
Drawselector(56,19,CD_DMA[cdtext.dma]);
cdoff := false;
end
else
begin
cdoff := true;
end;
HLine(20);
putchar(40,20,'Å',15,1);
putchar(40,20,'Á',15,1);
Button(13,21,'Advanced Options',false);
Button(34,21,'Test Settings',false);
Button(52,21,'Save and quit',false);
if cfg.gpen = 1 then putchar(26,19,'x',14,1);
if cfg.mpu401 = 1 then putchar(24,15,'x',14,1);
if cfg.initmode = 0 then
putchar(28,11,'x',15,1)
else
putchar(64,11,'x',15,1);
ViewBuffer(p);
writeto(ptr(segB800,0));
SelectItem(mselect);
end;
Procedure Draw_Advanced_Menu;
begin
fillchar(p^,4000,0);
writeto(p);
InitMenuScreen(title);
Window(4,3,77,24,15,1,true);
centeredtext(4,14,'Advanced Options');
HLine(5);
if apage = 0 then
begin
fastwrite(7,7,15,1,'Codec selection:');
fastwrite(7,8,15,1,'Frequency for WSS mode:');
fastwrite(7,9,15,1,'Frequency for SB mode:');
fastwrite(7,10,15,1,'Crystals used for SB frequencies:');
fastwrite(7,11,15,1,'Writeprotect shadow registers:');
fastwrite(7,12,15,1,'Yamaha Synthesis Chip selection: ');
fastwrite(7,13,15,1,'Timing mode for FM Chip: ');
fastwrite(7,14,15,1,'Sound Blaster DSP Version:');
fastwrite(7,15,15,1,'Automatic Volume Control:');
fastwrite(7,16,15,1,'Sound Blaster ADPCM support:');
fastwrite(7,17,15,1,'Command FIFO in Sound Blaster mode: ');
fastwrite(7,18,15,1,'SB mixer voice volume emulation:');
fastwrite(7,19,15,1,'Allow access to codec in SB mode: ');
Drawselector(42,7,CFIX[cfg.cfix]);
Drawselector(42,8,Frequency[WSSFreq.freq].rate);
Drawselector(53,8,Bits[WSSFreq.bits]);
Drawselector(64,8,MS[WSSFreq.chan]);
if (cfg.fmap = 1) and (Frequency[SBFreq.freq].xtal = 1) then
begin
repeat;
if SBfreq.freq = 0 then SBfreq.freq := 13 else dec(SBfreq.freq);
until Frequency[SBFreq.freq].xtal = 2;
end;
Drawselector(42,9,Frequency[SBFreq.freq].rate);
Drawselector(53,9,Bits[SBFreq.bits]);
Drawselector(64,9,MS[SBFreq.chan]);
Drawselector(42,10,FMAP[cfg.fmap]);
Drawselector(42,11,ONOFF[cfg.shprotect]);
Drawselector(42,12,FM_chip[cfg.opl]);
Drawselector(42,13,FM_CLK[cfg.fmclk]);
Drawselector(42,14,DSP[cfg.sbver]);
Drawselector(42,15,ONOFF[cfg.autovol]);
Drawselector(42,16,ONOFF[cfg.adpcm]);
Drawselector(42,17,ONOFF[cfg.fifo]);
Drawselector(42,18,ONOFF[cfg.sbmix]);
Drawselector(42,19,ONOFF[cfg.access]);
end
else
begin
fastwrite(7,7,15,1,'MC6:1 (reserved bit):');
fastwrite(7,8,15,1,'Disable access to FM and SB/WSS: ');
fastwrite(7,9,15,1,'Game Port Timer Mode:');
fastwrite(7,10,15,1,'Internal GP Timer Mode:');
fastwrite(7,11,15,1,'General Purpose Outputs:');
fastwrite(7,12,15,1,'Acknowledge chip timeout: ');
fastwrite(7,13,15,1,'MC6:0 (ATTN):');
fastwrite(7,14,15,1,'MC6:2 (DMA watch dog): ');
fastwrite(7,15,15,1,'Filter SB output: ');
Drawselector(42,7,ONOFF[cfg.wave]);
Drawselector(42,8,ONOFF[cfg.silence]);
Drawselector(42,9,GPMODE[cfg.gpmode]);
Drawselector(42,10,OUTMX[cfg.outmx]);
Drawselector(42,11,ONOFF[cfg.gpout]);
Drawselector(42,12,ONOFF[cfg.timeout]);
Drawselector(42,13,ONOFF[cfg.attn]);
Drawselector(42,14,ONOFF[cfg.dmawd]);
Drawselector(42,15,ONOFF[filter]);
end;
HLine(21);
if apage > 0 then
Button(9,22,' Back ',false)
else
Button(9,22,' Next ',false);
Button(44,22,' Main menu ',false);
ViewBuffer(p);
writeto(ptr(segB800,0));
SelectItem(aselect);
end;
Procedure Prepare_AD1848_for_SB;
{Configure the codec to a propper format and frequency for Sound Blaster compatibility}
var dummy : byte;
begin
asm
cli
end;
WaitForCodec; {Just to be sure the codec is ready}
case sbfreq.bits of
0: dummy := PCM_U_8BIT;
1: dummy := PCM_COMPL_16BIT;
end;
AD1848_SetOutputFormat(codec_rates[SBFreq.freq+1].freq,
dummy,boolean(sbfreq.chan)); {Set format and frequency}
Calibrate_AD1848; {Recalibrate codec o new samplerate}
WaitForCodec; {Wait for the codec to be ready again}
asm
sti
end;
end;
Procedure Prepare_AD1848_for_WSS;
{Sets the codec to a propper format and frequency for WSS output and
performs a full autocalibration of the codec}
var dummy : byte;
begin
asm
cli
end;
WaitForCodec; {Just to be sure the codec is ready}
case wssfreq.bits of {8 or 16 bit sound?}
0: dummy := PCM_U_8BIT;
1: dummy := PCM_COMPL_16BIT;
end;
AD1848_SetOutputFormat(codec_rates[SBFreq.freq+1].freq,
dummy,boolean(wssfreq.chan)); {Set format and frequency}
Calibrate_AD1848; {Recalibrate codec o new samplerate}
WaitForCodec; {Wait for the codec to be ready again}
asm
sti
end;
end;
Function TestSBDMA : Boolean;
{Lets the Sound Blaster DSP request a DMA transfer and checks if the right channel is requested}
var
Before, After : Byte;
Count : Word;
begin
DSP_Reset(cfg.sbbase);
SB_ResetMixer;
SB_SetDataformat(PCM_8Bit);
DSP_Write($D1); {DSP-command D1h - Enable speaker, required
on older SB's}
DSP_Write($40); {DSP-command 40h - Set sample frequency}
DSP_Write(165); {Write time constant for 11025Hz}
DSP_Write($14); {DSP-command 14h - 8bit playback}
DSP_Write($03); {Set the block length to 3 = 1 DWORD}
Count := 0;
{Disable interrupts}
asm
cli
end;
{Look at the current state of the DMA requests}
Before := Port [8] and $E0;
{Start playback}
DSP_Write($00);
repeat
{Check them again until there is a change or it takes too long}
After := Port [8] and $E0;
inc (Count);
until (Before <> After) or (Count > 60000);
{Reenable interrupts}
asm
sti
end;
SB_HaltDMA;
{Is there a change?}
if Before <> After then
begin
Count := 0;
After := After xor Before;
{If yes, which bit is set?}
while (After > 0) do
begin
inc (Count);
After := After shr 1;
end;
if (Count - 5) = cfg.sbdma then TestSBDMA := true;
DSP_reset(cfg.sbbase);
exit;
end;
{No DMA transfer occured?}
TestSBDMA := false;
DSP_reset(cfg.sbbase);
end;
Function TestWSSDMA : Boolean;
{Lets the codec request a DMA transfer and checks if the right channel is requested}
var
Before, After : Byte;
Count : Word;
begin
asm
cli
end;
MuteDAC(LeftANDRight,true);
Port[$0A] := $4 + cfg.WSSDMA;
Port[$0C] := 0; {Clear the internal DMA flip-flop}
port[$20] := 20;
Port[$0A] := cfg.wssDMA;
WriteCODECReg($0E,3); {Set the block length to 3}
WriteCODECReg($0F,0);
Count := 0;
{Look at the current state of the DMA requests}
Before := Port [8] and $E0;
writeCODECreg($0A,$02); {enable interrupt and pin control}
Playback(true); {start playback}
repeat
{Check them again until there is a change or it takes too long}