-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvgatest.cpp
More file actions
348 lines (301 loc) · 9.86 KB
/
Copy pathvgatest.cpp
File metadata and controls
348 lines (301 loc) · 9.86 KB
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
/*
VGATEST
Use at your own risk.
Copyright (C) 2019-2026 Marco Bortolin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <conio.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "vgatest.h"
#include "demotext.h"
#include "demogfx.h"
#include "bench.h"
#define VERSION "git"
GfxScreen gfx;
TextScreen text;
int getCharFromKeyb(const char* allowed, int promptrow, int promptcol)
{
int c = ' ';
size_t len = strlen(allowed);
while(NULL == memchr(allowed, c, len)) {
text.moveCursor(promptrow, promptcol);
c = getche();
if(c == k_ESC) {
c = 'q';
break;
}
c = tolower(c);
}
return c;
}
int getHexFromKeyb(int row, int col)
{
int hex1 = -1;
int hex2 = -1;
int hex = -1;
const char *hexch = "0123456789abcdef";
// first digit
hex1 = getCharFromKeyb(hexch, row, col);
if(hex1 == 'q') {
return 0xFFFF;
}
if(hex1 >= 'a') {
hex1 = (hex1-'a')+10;
} else {
hex1 -= '0';
}
// second digit
hex2 = getCharFromKeyb(hexch, row, col+1);
if(hex2 == 'q') {
return 0xFFFF;
}
if(hex2 >= 'a') {
hex2 = (hex2-'a')+10;
} else {
hex2 -= '0';
}
hex = hex1*16 + hex2;
return hex;
}
void putTitle(const char *title)
{
const int len = strlen(title) + 6;
const int col = text.cols() / 2 - len / 2;
text(1,col)("-", c_dgray)("-", c_lgray)("-", c_white)
(title, c_white)
("-", c_white)("-", c_lgray)("-", c_dgray);
#ifdef __386__
text(text.rows()-1, 0)("Version: " VERSION " 32-bit", c_dgray);
#else
text(text.rows()-1, 0)("Version: " VERSION " 16-bit", c_dgray);
#endif
}
int main(int argc, char *argv[])
{
if (gfx.error() != e_none) {
if(gfx.error() == e_notVgaDisplay) {
printf("This is not a VGA compatible display.\n");
} else {
printf("An error occurred.\n");
}
return 1;
}
uint8_t a;
int promptrow, promptcol;
int mode = 0, demo = 0, vmode = 0;
while(true) {
text.erasePage(DEFAULT_FG_COL, DEFAULT_BG_COL);
putTitle(" VGA modes test ");
text(3,33);
text("Text [t]\n", DEFAULT_FG_COL);
text("Graphics [g]\n");
text("Options [o]\n");
text("Quit [q]\n");
text(text.getRow()+1, 33);
text("Which Mode?");
text.getPos(promptrow, promptcol);
if(!mode) {
mode = getCharFromKeyb("tTgGoOq", promptrow, promptcol);
}
if(mode == 'q') {
break;
}
if(mode == 'o') {
text(promptrow+3,33)("Overscan color [o]\n");
text(text.getRow()+1, 33);
text("Which option?");
text.getPos(promptrow, promptcol);
int opt = getCharFromKeyb("oO", promptrow, promptcol);
if(opt == 'q') {
mode = 0;
continue;
}
switch(opt) {
case 'o': {
text(text.getRow()+1, 33);
text("Palette index (hex)?");
text.getPos(promptrow, promptcol);
int pal = getHexFromKeyb(promptrow, promptcol);
if(pal > 0xff) {
continue;
}
text.setOverscanColor(pal);
gfx.setOverscanColor(pal);
break;
}
default:
continue;
}
}
if(mode == 't') {
text.erasePage(DEFAULT_FG_COL, DEFAULT_BG_COL);
putTitle(" TEXT modes ");
text(3,33);
text("Font Maps [f]\n", DEFAULT_FG_COL);
text("Split & Pan [s]\n");
text("Benchmark [b]\n");
text(text.getRow()+1, 33);
text("Which Test?");
text.getPos(promptrow, promptcol);
if(!demo) {
demo = getCharFromKeyb("fFsSbB", promptrow, promptcol);
}
if(demo == 'q') {
demo = 0;
mode = 0;
continue;
}
int modesrow = text.setRow(text.getRow()+2);
int askrow = modesrow;
text(modesrow, 10)("BIOS modes\n");
text("0,1 40x25 8x8 320x200 [01]\n");
text("0*,1* 40x25 8x14 320x350 [a1]\n");
text("0m,1m 40x25 8x16 320x400 [b1]\n");
text("0+,1+ 40x25 9x16 360x400 [c1]\n");
text("2,3 80x25 8x8 640x200 [03]\n");
text("2*,3* 80x25 8x14 640x350 [a3]\n");
text("2m,3m 80x25 8x16 640x400 [b3]\n");
text("2+,3+ 80x25 9x16 720x400 [c3]\n");
text("7 80x25 9x14 720x350 [07]\n");
text("7+ 80x25 9x16 720x400 [a7]\n");
askrow = (text.getRow()>askrow)?text.getRow():askrow;
text(modesrow, 42)("Tweaked modes\n");
text(" 40x30 8x8 320x240 [11]\n");
text(" 80x43 8x8 640x350 [1a]\n");
text(" 80x50 9x8 720x400 [1b]\n");
text(" 80x28 9x14 720x400 [1c]\n");
text("° 80x30 8x16 640x480 [1d]\n");
text("° 80x34 8x14 640x480 [1e]\n");
text("° 80x60 8x8 640x480 [1f]\n");
askrow = (text.getRow()>askrow)?text.getRow():askrow;
text(askrow+1, 33);
text("Which Mode?");
text.getPos(promptrow, promptcol);
text(23,50)("° = multisync monitor req.");
do {
vmode = getHexFromKeyb(promptrow, promptcol);
if(vmode == 0xFFFF) {
demo = 0;
break;
}
text.setMode(vmode);
} while(text.error());
switch(demo) {
case 'f':
demoTextFontMaps();
break;
case 's':
demoTextSplitscreen();
break;
case 'b':
demoMemBench(false);
break;
}
if(demo) {
text.resetMode();
}
}
if(mode == 'g') {
text.erasePage(DEFAULT_FG_COL, DEFAULT_BG_COL);
putTitle(" GRAPHICS modes ");
text(3,33);
text("Test card [t]\n", DEFAULT_FG_COL);
text("Circles [c]\n");
text("Lines [l]\n");
text("Palette [p]\n");
text("Worms [w]\n");
text("Split & Pan [s]\n");
text("Scrolling [r]\n");
text("Benchmark [b]\n");
text(text.getRow()+1, 33);
text("Which Test?");
text.getPos(promptrow, promptcol);
if(!demo) {
demo = getCharFromKeyb("cClLpPwWsSrRbBtT", promptrow, promptcol);
}
if(demo == 'q') {
demo = 0;
mode = 0;
continue;
}
int modesrow = text.setRow(text.getRow()+2);
text(modesrow, 6)("BIOS modes\n");
text(" 4h 320x200 [04]\n");
text(" 6h 640x200 [06]\n");
text(" Dh 320x200 [0d]\n");
text(" Eh 640x200 [0e]\n");
text(" Fh 640x350 [0f]\n");
text("10h 640x350 [10]\n");
text("12h 640x480 [12]\n");
text("13h 320x200 [13]\n");
text(modesrow, 28)("Tweaked 256-color modes\n");
text("° 160x120 planar [14]\n");
text("Q 256x256 chain4 [15]\n");
text(" 296x220 planar [16]\n");
text("Y 320x200 planar [17]\n");
text("X 320x240 planar [18]\n");
text(" 320x400 planar [19]\n");
text(modesrow+1, 50);
text(" 360x270 planar [1a]\n");
text(" 360x360 planar [1b]\n");
text(" 360x480 planar [1c]\n");
text("° 400x300 planar [1d]\n");
text(text.getRow()+3, 33);
text("Which Mode?");
text.getPos(promptrow, promptcol);
text(23,50)("° = multisync monitor req.");
int mode1 = -1;
int mode2 = -1;
do {
int vmode = getHexFromKeyb(promptrow, promptcol);
if(vmode == 0xFFFF) {
demo = 0;
break;
}
gfx.setMode(vmode);
} while(gfx.error());
switch(demo) {
case 'w':
demoWorm();
break;
case 'c':
demoCircle();
break;
case 'l':
demoLine();
break;
case 'p':
demoPalette();
break;
case 's':
demoGfxSpitscreen();
break;
case 'r':
demoGfxHScrolling();
break;
case 't':
demoGfxTestCard();
break;
case 'b':
demoMemBench(true);
break;
}
if(demo) {
gfx.resetMode();
}
}
}
text.erasePage(c_lgray, c_black);
return 0;
}