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
|
{
This file is part of the Free Pascal run time library.
Copyright (c) 1999-2000 by Florian Klaempfl
member of the Free Pascal development team
Video unit extension for VESA Modes for go32v2
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
unit vesamode;
interface
implementation
uses
dos,go32,dpmiexcp,video,mouse;
type
twordarray = array[0..0] of word;
pwordarray = ^twordarray;
TVESAInfoBlock = record
VESASignature : ARRAY[0..3] OF CHAR;
VESAVersion : WORD;
OEMStringPtr : PChar;
Capabilities : LONGINT;
VideoModePtr : pwordarray;
TotalMemory : WORD;
Reserved : ARRAY[1..242] OF BYTE;
end;
TVesaVideoMode = record
{Col,Row : word;
Color : boolean;}
V : TVideoMode;
Mode : word;
end;
Const
VesaVideoModeCount = 5;
VesaVMD : Array[264..268] of TVesaVideoMode = (
(V : (Col: 80; Row : 60; Color : True); Mode : 264),
(V : (Col: 132; Row : 25; Color : True); Mode : 265),
(V : (Col: 132; Row : 43; Color : True); Mode : 266),
(V : (Col: 132; Row : 50; Color : True); Mode : 267),
(V : (Col: 132; Row : 60; Color : True); Mode : 268)
);
var
infoblock : TVESAInfoBLock;
SupportedVesaVMD : Array[0..VesaVideoModeCount-1] of TVesaVideoMode;
i : longint;
m : word;
Var
SysGetVideoModeCount : function : word;
SysSetVideoMode : function (Const VideoMode : TVideoMode) : boolean;
SysGetVideoModeData : Function (Index : Word; Var Data : TVideoMode) : boolean;
const
VesaRegisteredModes : word = 0;
function ReturnSuperVGAInfo(var ib : TVESAInfoBLock) : Word;
var
regs : registers;
begin
regs.ah:=$4f;
regs.al:=0;
regs.es:=tb_segment;
regs.di:=tb_offset;
intr($10,regs);
dosmemget(tb_segment,tb_offset,ib,sizeof(ib));
ReturnSuperVGAInfo:=regs.ax;
end;
function SetSuperVGAMode(m : word) : word;
var
regs : registers;
begin
regs.ah:=$4f;
regs.al:=2;
regs.bx:=m;
intr($10,regs);
SetSuperVGAMode:=regs.ax;
end;
function SetVESAMode(const VideoMode: TVideoMode): Boolean;
var
w : word;
begin
SetVESAMode:=false;
for w:=VesaRegisteredModes-1 downto 0 do
begin
if (VideoMode.col=SupportedVesaVMD[w].v.col) and
(VideoMode.row=SupportedVesaVMD[w].v.row) and
(VideoMode.color=SupportedVesaVMD[w].v.color) then
begin
if SetSuperVGAMode(SupportedVesaVMD[w].mode) <> $4f then
SetVESAMode:=false
else
begin
SetVESAMode:=true;
ScreenWidth:=VideoMode.Col;
ScreenHeight:=VideoMode.Row;
ScreenColor:=VideoMode.Color;
// cheat to get a correct mouse
{
mem[$40:$84]:=ScreenHeight-1;
mem[$40:$4a]:=ScreenWidth;
memw[$40:$4c]:=ScreenHeight*((ScreenWidth shl 1)-1);
}
DoCustomMouse(true);
end;
end;
if SetVESAMode then
exit;
end;
SetVESAMode:=SysSetVideoMode(VideoMode);
end;
procedure InitializeVesaModes;
begin
ReturnSuperVGAInfo(infoblock);
if not((infoblock.VESASignature[0]<>'V') or
(infoblock.VESASignature[1]<>'E') or
(infoblock.VESASignature[2]<>'S') or
(infoblock.VESASignature[3]<>'A')) then
begin
{$R-}
i:=0;
while true do
begin
dosmemget(hi(dword(infoblock.VideoModePtr)),lo(dword(infoblock.VideoModePtr))+i*2,m,2);
case m of
264:
Begin
{RegisterVideoMode(80,60,true,@SetVESAMode,264);}
SupportedVesaVMD[VesaRegisteredModes]:=VesaVMD[m];
Inc(VesaRegisteredModes);
End;
265:
Begin
{RegisterVideoMode(132,25,true,@SetVESAMode,265);}
SupportedVesaVMD[VesaRegisteredModes]:=VesaVMD[m];
Inc(VesaRegisteredModes);
End;
266:
Begin
{RegisterVideoMode(132,43,true,@SetVESAMode,266);}
SupportedVesaVMD[VesaRegisteredModes]:=VesaVMD[m];
Inc(VesaRegisteredModes);
End;
267:
Begin
{RegisterVideoMode(132,50,true,@SetVESAMode,267);}
SupportedVesaVMD[VesaRegisteredModes]:=VesaVMD[m];
Inc(VesaRegisteredModes);
End;
268:
Begin
{RegisterVideoMode(132,60,true,@SetVESAMode,268);}
SupportedVesaVMD[VesaRegisteredModes]:=VesaVMD[m];
Inc(VesaRegisteredModes);
End;
$ffff:
break;
end;
inc(i);
end;
end;
end;
Function VesaGetVideoModeData (Index : Word; Var Data : TVideoMode) : boolean;
Var
PrevCount : word;
begin
PrevCount:=SysGetVideoModeCount();
VesaGetVideoModeData:=(Index<=PrevCount);
If VesaGetVideoModeData then
begin
SysGetVideoModeData(Index,Data);
exit;
end;
VesaGetVideoModeData:=(Index-PrevCount)<=VesaRegisteredModes;
If VesaGetVideoModeData then
Data:=SupportedVesaVMD[Index-PrevCount-1].V;
end;
Function VesaGetVideoModeCount : Word;
begin
VesaGetVideoModeCount:=SysGetVideoModeCount()+VesaRegisteredModes;
end;
Var
Driver : TVideoDriver;
(*
Const
SysVideoDriver : TVideoDriver = (
InitDriver : @SysInitVideo;
DoneDriver : @SysDoneVideo;
UpdateScreen : @SysUpdateScreen;
ClearScreen : Nil;
SetVideoMode : @SysSetVideoMode;
GetVideoModeCount : @SysGetVideoModeCount;
GetVideoModeData : @SysGetVideoModedata;
SetCursorPos : @SysSetCursorPos;
GetCursorType : @SysGetCursorType;
SetCursorType : @SysSetCursorType;
GetCapabilities : @SysGetCapabilities
);
*)
initialization
{ Get the videodriver to be used }
GetVideoDriver (Driver);
InitializeVesaModes;
{ Change needed functions }
SysGetVideoModeCount:=Driver.GetVideoModeCount;
Driver.GetVideoModeCount:=@VesaGetVideoModeCount;
SysGetVideoModeData:=Driver.GetVideoModeData;
Driver.GetVideoModeData:=@VesaGetVideoModeData;
SysSetVideoMode:=Driver.SetVideoMode;
Driver.SetVideoMode:=@SetVESAMode;
SetVideoDriver (Driver);
end.
|