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
|
{
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 for DOS
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 Video;
interface
{$i videoh.inc}
var
VideoSeg : word;
implementation
uses
mouse,
go32;
{$i video.inc}
{$ASMMODE ATT}
{ used to know if LastCursorType is valid }
const
LastCursorType : word = crUnderline;
{ allways set blink state again }
procedure SetHighBitBlink;
var
regs : trealregs;
begin
regs.ax:=$1003;
regs.bx:=$0001;
realintr($10,regs);
end;
function BIOSGetScreenMode(var Cols,Rows: word; var Color: boolean): boolean;
var r: trealregs;
L: longint;
LSel,LSeg: word;
B: array[0..63] of byte;
type
TWord = word;
PWord = ^TWord;
var
OK: boolean;
begin
L:=global_dos_alloc(64);
LSeg:=(L shr 16);
LSel:=(L and $ffff);
r.ah:=$1b; r.bx:=0;
r.es:=LSeg; r.di:=0;
realintr($10,r);
OK:=(r.al=$1b);
if OK then
begin
dpmi_dosmemget(LSeg,0,B,64);
Cols:=PWord(@B[5])^; Rows:=B[$22];
Color:=PWord(@B[$27])^<>0;
end;
global_dos_free(LSel);
BIOSGetScreenMode:=OK;
end;
procedure SysInitVideo;
var
regs : trealregs;
begin
VideoSeg:=$b800;
if (ScreenWidth=$ffff) or (ScreenHeight=$ffff) or
(ScreenWidth=0) or (ScreenHeight=0) then
begin
ScreenColor:=true;
regs.ah:=$0f;
realintr($10,regs);
if (regs.al and 1)=0 then
ScreenColor:=false;
if regs.al=7 then
begin
ScreenColor:=false;
VideoSeg:=$b000;
end
else
VideoSeg:=$b800;
ScreenWidth:=regs.ah;
regs.ax:=$1130;
regs.bx:=0;
realintr($10,regs);
ScreenHeight:=regs.dl+1;
BIOSGetScreenMode(ScreenWidth,ScreenHeight,ScreenColor);
end;
regs.ah:=$03;
regs.bh:=0;
realintr($10,regs);
CursorLines:=regs.cl;
CursorX:=regs.dl;
CursorY:=regs.dh;
SetHighBitBlink;
SetCursorType(LastCursorType);
end;
procedure SysDoneVideo;
begin
LastCursorType:=GetCursorType;
ClearScreen;
SetCursorType(crUnderLine);
SetCursorPos(0,0);
end;
function SysGetCapabilities: Word;
begin
SysGetCapabilities := $3F;
end;
procedure SysSetCursorPos(NewCursorX, NewCursorY: Word);
var
regs : trealregs;
begin
regs.ah:=$02;
regs.bh:=0;
regs.dh:=NewCursorY;
regs.dl:=NewCursorX;
realintr($10,regs);
CursorY:=regs.dh;
CursorX:=regs.dl;
end;
{ I don't know the maximum value for the scan line
probably 7 or 15 depending on resolution !!
}
function SysGetCursorType: Word;
var
regs : trealregs;
begin
regs.ah:=$03;
regs.bh:=0;
realintr($10,regs);
SysGetCursorType:=crHidden;
if (regs.ch and $60)=0 then
begin
SysGetCursorType:=crBlock;
if (regs.ch and $1f)<>0 then
begin
SysGetCursorType:=crHalfBlock;
if regs.cl-1=(regs.ch and $1F) then
SysGetCursorType:=crUnderline;
end;
end;
end;
procedure SysSetCursorType(NewType: Word);
var
regs : trealregs;
const
MaxCursorLines = 7;
begin
regs.ah:=$01;
regs.bx:=NewType;
case NewType of
crHidden : regs.cx:=$2000;
crHalfBlock : begin
regs.ch:=MaxCursorLines shr 1;
regs.cl:=MaxCursorLines;
end;
crBlock : begin
regs.ch:=0;
regs.cl:=MaxCursorLines;
end;
else begin
regs.ch:=MaxCursorLines-1;
regs.cl:=MaxCursorLines;
end;
end;
realintr($10,regs);
end;
procedure SysUpdateScreen(Force: Boolean);
var
Is_Mouse_Vis: boolean;
begin
Is_Mouse_Vis := MouseIsVisible; {MouseIsVisible is from Mouse unit}
if Is_Mouse_Vis then
HideMouse;
if not force then
begin
asm
pushl %esi
pushl %edi
movl VideoBuf,%esi
movl OldVideoBuf,%edi
movl VideoBufSize,%ecx
shrl $2,%ecx
repe
cmpsl
setne force
popl %edi
popl %esi
end;
end;
if Force then
begin
dosmemput(videoseg,0,videobuf^,VideoBufSize);
move(videobuf^,oldvideobuf^,VideoBufSize);
end;
if Is_Mouse_Vis then
ShowMouse;
end;
Procedure DoSetVideoMode(Params: Longint);
type
wordrec=packed record
lo,hi : word;
end;
var
regs : trealregs;
begin
regs.ax:=wordrec(Params).lo;
regs.bx:=wordrec(Params).hi;
realintr($10,regs);
end;
Procedure SetVideo8x8;
type
wordrec=packed record
lo,hi : word;
end;
var
regs : trealregs;
begin
regs.ax:=3;
regs.bx:=0;
realintr($10,regs);
regs.ax:=$1112;
regs.bx:=$0;
realintr($10,regs);
end;
Const
SysVideoModeCount = 5;
SysVMD : Array[0..SysVideoModeCount-1] of TVideoMode = (
(Col: 40; Row : 25; Color : False),
(Col: 40; Row : 25; Color : True),
(Col: 80; Row : 25; Color : False),
(Col: 80; Row : 25; Color : True),
(Col: 80; Row : 50; Color : True)
);
Function SysSetVideoMode (Const Mode : TVideoMode) : Boolean;
Var
I : Integer;
begin
I:=SysVideoModeCount-1;
SysSetVideoMode:=False;
While (I>=0) and Not SysSetVideoMode do
If (Mode.col=SysVMD[i].col) and
(Mode.Row=SysVMD[i].Row) and
(Mode.Color=SysVMD[i].Color) then
SysSetVideoMode:=True
else
Dec(I);
If SysSetVideoMode then
begin
If (I<SysVideoModeCount-1) then
DoSetVideoMode(I)
else
SetVideo8x8;
ScreenWidth:=SysVMD[I].Col;
ScreenHeight:=SysVMD[I].Row;
ScreenColor:=SysVMD[I].Color;
DoCustomMouse(false);
end;
end;
Function SysGetVideoModeData (Index : Word; Var Data : TVideoMode) : boolean;
begin
SysGetVideoModeData:=(Index<=SysVideoModeCount);
If SysGetVideoModeData then
Data:=SysVMD[Index];
end;
Function SysGetVideoModeCount : Word;
begin
SysGetVideoModeCount:=SysVideoModeCount;
end;
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
SetVideoDriver(SysVideoDriver);
end.
|