-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUDISPLAY.PAS
153 lines (130 loc) · 3.79 KB
/
UDISPLAY.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
{
UDisplay Unit
Implements the program interface to the video adapter, allowing to get
video information, set video modes and access the display canvas
2022 LRT
}
unit
udisplay;
interface
uses
uexc, uclasses, types, locale, uobject, uviddrv, uvgadrv, ulog,
ucanvas, ubitmap, ubitmap8, upalette;
type
PDisplayAdapter = ^TDisplayAdapter;
TDisplayAdapter = object (TObject)
public
constructor init;
destructor done; virtual;
function detectAdapter: boolean;
procedure getVideoModes(var list:PVideoMode; var count: word);
procedure setVideoMode(index: word);
procedure setTextMode;
procedure setPalette(palette: PColorPalette);
function isPaletteSupported: boolean;
function getCurrentVideoMode: PVideoMode;
function getCanvas: PCanvas;
function getDriver: PVideoDriver;
function getVideoDriverName: string;
function getClassName: string; virtual;
function getClassId: word; virtual;
private
_driver: PVideoDriver;
_canvas: PCanvas;
end;
var
DisplayAdapter: PDisplayAdapter;
implementation
{ TDisplayAdapter }
constructor TDisplayAdapter.init;
begin
_driver := nil;
_canvas := nil;
inherited init;
end;
destructor TDisplayAdapter.done;
begin
if _canvas <> nil then _canvas^.release;
if _driver <> nil then _driver^.release;
inherited done;
end;
function TDisplayAdapter.detectAdapter: boolean;
var
res: boolean;
vgadrv: PVGADriver;
begin
res := false;
new(vgadrv, init);
if vgadrv^.isAvailable then
begin
_driver := vgadrv;
vgadrv^.retain;
res := true;
end;
vgadrv^.release;
detectAdapter := res;
end;
procedure TDisplayAdapter.getVideoModes(var list:PVideoMode; var count: word);
begin
iassert(_driver <> nil, @self, 0, S_ERR_DRIVER_NOT_READY);
_driver^.getVideoModes(list, count);
end;
procedure TDisplayAdapter.setVideoMode(index: word);
begin
iassert(_driver <> nil, @self, 0, S_ERR_DRIVER_NOT_READY);
_driver^.setVideoMode(index);
if _canvas <> nil then _canvas^.release;
_canvas := new(PCanvas, initWithBitmap(_driver^.getBitmap));
end;
procedure TDisplayAdapter.setTextMode;
begin
iassert(_driver <> nil, @self, 0, S_ERR_DRIVER_NOT_READY);
if _canvas <> nil then
begin
_canvas^.release;
_canvas := nil;
end;
_driver^.setTextMode;
end;
procedure TDisplayAdapter.setPalette(palette: PColorPalette);
begin
iassert(_driver <> nil, @self, 0, S_ERR_DRIVER_NOT_READY);
_driver^.setPalette(palette);
end;
function TDisplayAdapter.isPaletteSupported: boolean;
begin
iassert(_driver <> nil, @self, 0, S_ERR_DRIVER_NOT_READY);
isPaletteSupported := _driver^.supportsPalette;
end;
function TDisplayAdapter.getCurrentVideoMode: PVideoMode;
begin
iassert(_driver <> nil, @self, 0, S_ERR_DRIVER_NOT_READY);
getCurrentVideoMode := _driver^.getCurrentVideoMode;
end;
function TDisplayAdapter.getCanvas: PCanvas;
begin
getCanvas := _canvas;
end;
function TDisplayAdapter.getDriver: PVideoDriver;
begin
getDriver := _driver;
end;
function TDisplayAdapter.getVideoDriverName: string;
begin
iassert(_driver <> nil, @self, 0, S_ERR_DRIVER_NOT_READY);
getVideoDriverName := _driver^.GetDriverName;
end;
function TDisplayAdapter.getClassName: string;
begin
getClassName := 'TDisplayAdapter';
end;
function TDisplayAdapter.getClassId: word;
begin
getClassId := C_CLASS_ID_DisplayAdapter;
end;
{ private }
{ Other }
begin
DisplayAdapter := new(PDisplayAdapter, init);
DisplayAdapter^.detectAdapter;
end.