-
Notifications
You must be signed in to change notification settings - Fork 2
/
DRIVERS.PAS
2898 lines (2611 loc) · 64.5 KB
/
DRIVERS.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
{/////////////////////////////////////////////////////////////////////////
//
// Dos Navigator Version 1.51 Copyright (C) 1991-99 RIT Research Labs
//
// This programs is free for commercial and non-commercial use as long as
// the following conditions are aheared to.
//
// Copyright remains RIT Research Labs, and as such any Copyright notices
// in the code are not to be removed. If this package is used in a
// product, RIT Research Labs should be given attribution as the RIT Research
// Labs of the parts of the library used. This can be in the form of a textual
// message at program startup or in documentation (online or textual)
// provided with the package.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// "Based on Dos Navigator by RIT Research Labs."
//
// THIS SOFTWARE IS PROVIDED BY RIT RESEARCH LABS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The licence and distribution terms for any publically available
// version or derivative of this code cannot be changed. i.e. this code
// cannot simply be copied and put under another distribution licence
// (including the GNU Public Licence).
//
//////////////////////////////////////////////////////////////////////////}
unit Drivers;
{-----------------------------------------------------}
{ This module is based on Turbo Vision Drivers Unit }
{ Copyright (c) 1990 by Borland International }
{-----------------------------------------------------}
interface
uses Objects, xTime;
{$I Version.INC}
var
LSliceTimer: TEventTimer;
LSliceCnt: LongInt;
procedure SliceAwake;
{ ******** EVENT MANAGER ******** }
const
{ Event codes }
evMouseDown = $0001;
evMouseUp = $0002;
evMouseMove = $0004;
evMouseAuto = $0008;
evKeyDown = $0010;
evCommand = $0100;
evBroadcast = $0200;
{ Event masks }
evNothing = $0000;
evMouse = $000F;
evKeyboard = $0010;
evMessage = $FF00;
AltSpaceChar: Char = #240;
AltCodes1: array[$10..$34] of Char =
'QWERTYUIOP'#0#0#0#0'ASDFGHJKL'#0#0#0#0#0'ZXCVBNM'#0#0;
{ Mouse button state masks }
mbLeftButton = $01;
mbRightButton = $02;
type
{ Event record }
PEvent = ^TEvent;
TEvent = record
What: Word;
case Word of
evNothing: ();
evMouse: (
Buttons: Byte;
Double: Boolean;
Where: TPoint);
evKeyDown: (
case Integer of
0: (KeyCode: Word);
1: (CharCode: Char;
ScanCode: Byte));
evMessage: (
Command: Word;
case Word of
0: (InfoPtr: Pointer);
1: (InfoLong: Longint);
2: (InfoWord: Word);
3: (InfoInt: Integer);
4: (InfoByte: Byte);
5: (InfoChar: Char));
end;
CharDef = Array [0..15] of Byte;
{ Initialized variables }
Const
ButtonCount: Byte = 0;
MouseEvents: Boolean = False;
MouseReverse: Boolean = False;
MouseButtons: Byte = 0;
DoubleDelay: Word = 8;
RepeatDelay: Word = 8;
UserScreen: Pointer = nil;
GraphMouse: Boolean = False;
MouseMouse: Boolean = True;
CharHeight: Byte = 16;
ScreenSaved: Boolean = False;
DESQDetected: Boolean = False;
NeedAbort: Boolean = False;
StdMouse: Boolean = False; { Is engine really using standard mouse }
XSens: Byte = 11;
YSens: Byte = 11;
CLSAct: Boolean = True;
CurrentBlink : Boolean = False;
var
{ Uninitialized variables }
OldBlink: Boolean;
MouseIntFlag: Byte;
MouseWhere: TPoint;
UserScreenSize: Word;
UserScreenWidth: Word;
MouseX, MouseY,
OldMouseX, OldMouseY: Word;
ShowMouseProc,
HideMouseProc: Pointer;
{ Event manager routines }
procedure InitDrivers;
procedure InitEvents;
{procedure InitMouse;}
procedure DoneEvents;
procedure ShowMouse;
procedure HideMouse;
procedure GetMouseEvent(var Event: TEvent);
procedure GetKeyEvent(var Event: TEvent);
procedure SetMouseSpeed(XS, YS: Byte);
{function GetShiftState: Byte;}
procedure GetCrtMode; { used to fixup screen before application starts }
{ ******** SCREEN MANAGER ******** }
type
vga_pal = array [1..3,0..15] of Byte ;
const
{ VGA palette }
VGA_palette : vga_pal = (
{ red } (0,0,0,0,42,42,42,42,21,21,21,21,63,63,63,63),
{ green } (0,0,42,42,0,0,21,42,21,21,63,63,21,21,63,63),
{ blue } (0,42,0,42,0,42,0,42,21,63,21,63,21,63,21,63)
) ;
{ default values }
VGA_Default : vga_pal = (
{ red } (0,0,0,0,42,42,42,42,21,21,21,21,63,63,63,63),
{ green } (0,0,42,42,0,0,21,42,21,21,63,63,21,21,63,63),
{ blue } (0,42,0,42,0,42,0,42,21,63,21,63,21,63,21,63)
) ;
{ palette slot }
SL : Array[0..15] of Byte =(0,1,2,3,4,5,20,7,56,57,58,59,60,61,62,63);
{ Screen modes }
smBW80 = $0002;
smCO80 = $0003;
smMono = $0007;
smFont8x8 = $0100;
smSVGALo: Word = $100; { - $109}
smSVGAHi: Word = $10A;
const
{ Initialized variables }
StartupMode: Word = $FFFF;
SkyEnabled: Integer = 0;
TottalExit: Boolean = False; { Set it only when leaving your program }
var
{ Uninitialized variables }
ScreenMode: Word;
ScreenWidth: Word;
ScreenHeight: Word;
HiResScreen: Boolean;
CheckSnow: Boolean;
ScreenBuffer: Pointer;
CursorLines: Word;
OldCursorShape: Word;
OldCursorPos: Word;
{ Screen manager routines }
procedure InitVideo;
procedure DoneVideo;
procedure SetVideoMode(Mode: Word);
procedure ClearScreen;
Procedure InitVGApalette ; { To be called at startup time !!!! }
Procedure ResetVGApalette( Update : Boolean ); { reset palette to default }
Procedure GetPalette(var Buf); { fill buff with palette 64 bytes }
Procedure SetPalette(var Buf); { set palette using buf 64 bytes }
Function VGASystem: Boolean;
Procedure Set_palette( slot:Word; sred,sgreen,sblue : Byte);
Procedure Get_palette( Var slot,gred,ggreen,gblue : Byte);
{ ******** SYSTEM ERROR HANDLER ******** }
type
{ System error handler function type }
TSysErrorFunc = function(ErrorCode: Integer; Drive: Byte): Integer;
{ Default system error handler routine }
function SystemError(ErrorCode: Integer; Drive: Byte): Integer;
const
{ Initialized variables }
SysErrorFunc: TSysErrorFunc = SystemError;
SysColorAttr: Word = $4E4F;
SysColorButtonAttr: Word = $0E0F;
SysMonoAttr: Word = $7070;
CtrlBreakHit: Boolean = False;
SaveCtrlBreak: Boolean = False;
SysErrActive: Boolean = False;
{ System error handler routines }
procedure InitSysError;
procedure DoneSysError;
{ ******** UTILITY ROUTINES ******** }
{ Keyboard support routines }
function GetAltChar(KeyCode: Word): Char;
function GetAltCode(Ch: Char): Word;
function GetCtrlChar(KeyCode: Word): Char;
function GetCtrlCode(Ch: Char): Word;
function CtrlToArrow(KeyCode: Word): Word;
{ String routines }
procedure FormatStr(var Result: String; const Format: String; var Params);
procedure PrintStr(const S: String);
{ Buffer move routines }
procedure MoveColor(var Buf; Num, Attr: Byte);
procedure MoveBuf(var Dest; var Source; Attr: Byte; Count: Word);
procedure MoveChar(var Dest; C: Char; Attr: Byte; Count: Word);
procedure MoveCStr(var Dest; const Str: String; Attrs: Word);
procedure MoveStr(var Dest; const Str: String; Attr: Byte);
function CStrLen(const S: String): Integer;
implementation
uses
Dos,
Advance,
Commands,
Views,
Startup,
DnApp,
FlPanelX;
const
MCurMP : CharDef=($00,$40,$60,$30,$18,$3C,$3E,$3E,$3E,$1F,$07,$06,$00,$00,$00,$00);
MCurSP : CharDef=($BF,$1F,$0F,$87,$C3,$80,$80,$80,$80,$C0,$E0,$F0,$F0,$FF,$FF,$FF);
MCurLP : CharDef=($00,$00,$38,$04,$36,$4E,$0E,$6E,$3E,$1F,$07,$06,$00,$00,$00,$00);
MCurLSP : CharDef=($FF,$C7,$83,$C1,$80,$00,$00,$00,$80,$C0,$E0,$F0,$F0,$FF,$FF,$FF);
MCurM0 : CharDef=($00,$40,$60,$70,$78,$7C,$7E,$78,$4C,$0E,$06,$00,$00,$00,$00,$00);
MCurS0 : CharDef=($1F,$0F,$07,$03,$01,$00,$00,$00,$01,$00,$F0,$F8,$F8,$FF,$FF,$FF);
MCurM1 : CharDef=($00,$18,$3C,$3C,$19,$7E,$BC,$3D,$7E,$98,$08,$04,$04,$08,$00,$00);
MCurS1 : CharDef=($FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF);
MCurM2 : CharDef=($00,$18,$3C,$3C,$98,$7E,$3D,$BC,$7E,$19,$10,$20,$20,$10,$00,$00);
MCurS2 : CharDef=($FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF);
StdMouseBlock : Array [0..5] of Byte = ($D6,$D7,$D0,$D2,$B7,$B8);
LastMouseMouse : Boolean = False;
EGAVGA : Boolean = False;
MouseVisible : Boolean = True;
{ ******** EVENT MANAGER ******** }
const
{ Event manager constants }
EventQSize = 16;
var
{ Event manager variables }
OldAttr: Byte;
OldSymbols: Array [0..5] of Byte;
SaveFont: Array [0..5] of CharDef;
LastButtons: Byte;
DownButtons: Byte;
LastDouble: Boolean;
LastWhere: TPoint;
DownWhere: TPoint;
DownTicks: Word;
AutoTicks: Word;
AutoDelay: Word;
EventCount: Word;
EventQHead: Word;
EventQTail: Word;
EventQueue: array[0..EventQSize - 1] of TEvent;
EventQLast: record end;
VESA_Found: ShortInt;
var
Ticks: Word absolute $40:$6C;
{ Detect mouse driver }
procedure DetectMouse; near; assembler;
asm
MOV AX,3533H
INT 21H
MOV AX,ES
OR AX,BX
JE @@1
MOV AX,21H
INT 33H
SUB AX,21H
JE @@2
@@3: PUSH BX
MOV AX,4
XOR CX,CX
XOR DX,DX
INT 33H
POP AX
jmp @@1
@@2: XOR AX,AX
INT 33H
OR AX, AX
JNE @@3
@@1: MOV ButtonCount,AL
end;
{procedure InitMouse;
begin
DetectMouse;
end;}
{ Store event in GetMouseEvent and GetKeyEvent }
procedure StoreEvent; near; assembler;
asm
MOV DI,SP
LES DI,SS:[DI+8]
CLD
STOSW
XCHG AX,BX
STOSW
XCHG AX,CX
STOSW
XCHG AX,DX
STOSW
end;
{ Get mouse state }
{ Out BL = Button mask }
{ CX = X coordinate }
{ DX = Y coordinate }
{ DI = Timer ticks }
procedure GetMouseState; near; assembler;
asm
CLI
CMP EventCount,0
JNE @@1
MOV BL,MouseButtons
MOV CX,MouseWhere.Word[0]
MOV DX,MouseWhere.Word[2]
MOV ES,Seg0040
MOV DI,ES:Ticks
JMP @@3
@@1: MOV SI,EventQHead
CLD
LODSW
XCHG AX,DI
LODSW
XCHG AX,BX
LODSW
XCHG AX,CX
LODSW
XCHG AX,DX
CMP SI,OFFSET EventQLast
JNE @@2
MOV SI,OFFSET EventQueue
@@2: MOV EventQHead,SI
DEC EventCount
@@3: STI
CMP MouseReverse,0
JE @@4
MOV BH,BL
AND BH,3
JE @@4
CMP BH,3
JE @@4
XOR BL,3
@@4:
end;
procedure ShowMouse; assembler;
asm
CMP ButtonCount,0
JE @@1
cmp StdMouse, 0
je @@@1
push AX
mov ax, 1
int 33h
pop AX
jmp @@1
@@@1:
CMP MouseVisible, 0
JNE @@1
PUSH AX
PUSH BX
PUSH DX
PUSH CX
PUSH DI
PUSH SI
PUSH ES
PUSH BP
MOV MouseVisible, 1
CALL ShowMouseProc
POP BP
POP ES
POP SI
POP DI
POP CX
POP DX
POP BX
POP AX
@@1:
end;
procedure HideMouse; assembler;
asm
CMP ButtonCount,0
JE @@1
cmp StdMouse, 0
je @@@1
push AX
mov ax, 2
int 33h
pop AX
jmp @@1
@@@1:
{CMP MouseVisible, 0
JE @@1}
PUSH AX
PUSH BX
PUSH DX
PUSH CX
PUSH DI
PUSH SI
PUSH ES
PUSH BP
CALL HideMouseProc
MOV MouseVisible, 0
MOV OldMouseX, $FFFF
MOV OldMouseY, $FFFF
POP BP
POP ES
POP SI
POP DI
POP CX
POP DX
POP BX
POP AX
@@1:
end;
procedure GetMouseEvent(var Event: TEvent); assembler;
asm
CMP MouseEvents,0
JE @@2
CALL GetMouseState
MOV BH,LastDouble
MOV AL,LastButtons
CMP AL,BL
JE @@1
OR AL,AL
JE @@3
OR BL,BL
JE @@5
MOV BL,AL
@@1: CMP CX,LastWhere.X
JNE @@6
CMP DX,LastWhere.Y
JNE @@6
CMP RepeatDelay, 0
JE @@6
OR BL,BL
JE @@2
MOV AX,DI
SUB AX,AutoTicks
CMP AX,AutoDelay
JAE @@7
@@2: XOR AX,AX
MOV BX,AX
MOV CX,AX
MOV DX,AX
JMP @@9
@@3: MOV BH,0
CMP BL,DownButtons
JNE @@4
CMP CX,DownWhere.X
JNE @@4
CMP DX,DownWhere.Y
JNE @@4
MOV AX,DI
SUB AX,DownTicks
CMP AX,DoubleDelay
JAE @@4
MOV BH,1
@@4: MOV DownButtons,BL
MOV DownWhere.X,CX
MOV DownWhere.Y,DX
MOV DownTicks,DI
MOV AutoTicks,DI
MOV AX,RepeatDelay
MOV AutoDelay,AX
MOV AX,evMouseDown
JMP @@8
@@5: MOV AX,evMouseUp
JMP @@8
@@6: MOV AX,evMouseMove
JMP @@8
@@7: MOV AutoTicks,DI
MOV AutoDelay,1
MOV AX,evMouseAuto
@@8: MOV LastButtons,BL
MOV LastDouble,BH
MOV LastWhere.X,CX
MOV LastWhere.Y,DX
@@9: CALL StoreEvent
end;
procedure _GetKeyEvent(var Event: TEvent); assembler;
asm
MOV AH,11h
INT 16H
MOV AX,0
MOV BX,AX
JE @@1
MOV AH,10h
INT 16H
cmp ah,$E0
jne @NotExt
cmp al,$0D
jne @NotEnter
mov bx,kbEnter
jmp @PUT
@NotEnter:
@NotExt:
XCHG AX,BX
@PUT: MOV AX,evKeyDown
@@1: XOR CX,CX
MOV DX,CX
CALL StoreEvent
end;
procedure GetKeyEvent;
begin
_GetKeyEvent(Event);
if Event.What = evNothing then Exit;
if (Event.KeyCode = kbCtrlTab) and (mem[$40:$17] and 3 <> 0) then Event.KeyCode := kbAltTab;
if (Event.CharCode = #$e0) and
(Event.ScanCode in [$52,$92,$A2,
$47,$77,$97,
$49,$84,$99,
$93,$53,$A3,
$4F,$75,$9F,
$51,$76,$A1,
$48,$8D,$98,
$4B,$73,$9B,
$50,$91,$A0,
$4D,$9D,$74])
then
Event.CharCode := #0
else
if Event.What = evKeyDown then
if (Event.CharCode >= '0') and (Event.CharCode <= '9') and
(ShiftState and 3 <> 0) then Event.CharCode := #0;
end;
{function GetShiftState: Byte; assembler;
asm
MOV ES,Seg0040
MOV AL,ES:ShiftState
end;}
{ ******** SCREEN MANAGER ******** }
var
Equipment: Word absolute $40:$10;
CrtRows: Byte absolute $40:$84;
CrtInfo: Byte absolute $40:$87;
{ Save registers and call video interrupt }
procedure VideoInt; near; assembler;
asm
PUSH BP
PUSH ES
INT 10H
POP ES
POP BP
end;
{ Return CRT mode in AX and dimensions in DX }
procedure GetCrtMode; assembler;
asm
MOV AH,0FH
CALL VideoInt
PUSH AX
MOV AX,1130H
MOV BH,0
MOV DL,0
CALL VideoInt
POP AX
MOV DH,AH
CMP AH, 2
JE @@1
CMP AH, 3
JE @@1
XOR AH, AH
JMP @@2
@@1:
CMP DL,25
SBB AH,AH
INC AH
@@2:
end;
procedure VGA30; assembler;
asm
cli
mov dx,3C4h
mov al,0
out dx,al
mov al,1
inc dx
out dx,al
dec dx
mov dx,3D4h
mov al,23
out dx,al
inc dx
in al,dx
and al,127
out dx,al
dec dx
mov al,17
out dx,al
inc dx
in al,dx
and al,127
out dx,al
mov dx,3CCh
in al,dx
or al,192
mov dx,3C2h
out dx,al
mov dx,3D4h
mov al,6
out dx,al
mov al,11
inc dx
out dx,al
dec dx
mov al,7
out dx,al
mov al,62
inc dx
out dx,al
dec dx
mov al,9
out dx,al
mov al,79
inc dx
out dx,al
dec dx
mov al,16
out dx,al
mov al,234
inc dx
out dx,al
dec dx
mov al,17
out dx,al
mov al,140
inc dx
out dx,al
dec dx
mov al,18
out dx,al
mov al,223
inc dx
out dx,al
dec dx
mov al,21
out dx,al
mov al,231
inc dx
out dx,al
dec dx
mov al,22
out dx,al
mov al,4
inc dx
out dx,al
dec dx
mov al,17
out dx,al
inc dx
in al,dx
or al,128
out dx,al
dec dx
mov al,23
out dx,al
inc dx
in al,dx
or al,128
out dx,al
mov dx,3C4h
mov al,0
out dx,al
mov al,3
inc dx
out dx,al
dec dx
sti
mov ax,40h
mov es,ax
mov byte ptr es:[84h],29
end;
{ Set CRT mode to value in AX }
procedure SetCrtMode; near; assembler;
asm
MOV ES,Seg0040
MOV BL,20H
CMP AL,smMono
JNE @@1
MOV BL,30H
@@1: AND ES:Equipment.Byte,0CFH
OR ES:Equipment.Byte,BL
AND ES:CrtInfo,0FEH
PUSH AX
OR AL, AL
JNZ @@@1
MOV AL, smCO80
@@@1:
MOV AH,0
CALL VideoInt
POP AX
OR AH,AH
JE @@2
OR AL, AL
JNZ @@@2
CALL VGA30
JMP @@2
@@@2:
MOV AX,1112H
MOV BL,0
CALL VideoInt
MOV AX,1130H
MOV BH,0
MOV DL,0
CALL VideoInt
CMP DL,42
JNE @@2
OR ES:CrtInfo,1
MOV AH,1
MOV CX,600H
CALL VideoInt
MOV AH,12H
MOV BL,20H
CALL VideoInt
@@2:
end;
{ Fix CRT mode in AX if required }
procedure FixXGAmode; near;
var R: Array [0..255] of Byte;
P: Pointer;
begin
P := @R;
asm
mov ax, $4E04
xor bx, bx
push bp
int 10h
pop bp
mov ax, $4E01
les di, P
mov cx, bx
xor dx, dx
push bp
int 10h
pop bp
end;
if R[$0C] <> 0 then
asm
mov AX, smCO80
call SetCRTmode;
end;
end;
procedure FixSVGAMode; near;
var R: Array [0..255] of Byte;
P: Pointer;
begin
P := @R;
asm
mov ax, $4F03
push bp
int 10h
pop bp
mov ax, $4F01
mov cx, bx
les di, P
push bp
int 10h
pop bp
end;
if R[0] and $10 <> 0 then
asm
mov AX, smCO80
call SetCRTmode
end;
end;
procedure FixCrtMode; near; assembler;
asm
CMP AL,smMono
JE @@1
CMP AL,smCO80
JE @@1
CMP AL,smBW80
JE @@1
CMP AL,byte ptr smSVGAHi
JE @@1
CMP AL,byte ptr smSVGALo
JE @@1
MOV AX,smCO80
@@1:
end;
{ Set CRT data areas and mouse range }
procedure SetCrtData; near; assembler;
asm
CALL GetCrtMode
MOV CL,1
OR DL,DL
JNE @@1
MOV CL,0
MOV DL,24
@@1: INC DL
MOV ScreenMode,AX
MOV byte ptr ScreenWidth,DH
MOV byte ptr ScreenWidth + 1, 0
MOV byte ptr ScreenHeight,DL
MOV byte ptr ScreenHeight + 1, 0
MOV HiResScreen,CL
XOR CL,1
MOV BX,SegB800
CMP AL,smMono
JNE @@2
MOV CL,0
MOV BX,SegB000
@@2: MOV CheckSnow,CL
XOR AX,AX
MOV ScreenBuffer.Word[0],AX
MOV ScreenBuffer.Word[2],BX
{$ifndef DPMI}
{ Check for DESQ View or compatible }
MOV AX, $1022
XOR BX, BX
INT 15H
OR BX, BX
JZ @@@1
MOV AH, 1
MOV DESQDetected, AH
MOV BX, ScreenBuffer.Word[2]
MOV ES, BX
XOR DI, DI
MOV AH, $FE
INT 10H
MOV ScreenBuffer.Word[0],DI
MOV BX, ES
MOV ScreenBuffer.Word[2],BX
{$endif}
@@@1:
{ end check }
MOV AH,3
MOV BH,0
CALL VideoInt
{MOV CX, $0607;}
MOV CursorLines,CX
MOV AH,1
MOV CX,2000H
CALL VideoInt
CMP ButtonCount,0
JE @@4
MOV AX,7
MOV DL,byte ptr ScreenWidth
CALL @@3
MOV AX,8
MOV DL,byte ptr ScreenHeight
@@3: XOR DH,DH
MOV CL,3
SHL DX,CL
DEC DX
XOR CX,CX