-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vgatest.cpp
320 lines (273 loc) · 8.87 KB
/
vgatest.cpp
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
/*
VGATEST
Use at your own risk.
Copyright (C) 2019 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()
{
text(2,28)("-", c_dgray)("-", c_lgray)("-", c_white)
(" VGA modes test ", c_white)
("-", c_white)("-", c_lgray)("-", c_dgray);
text(text.rows()-1, 0)("Version: " VERSION, c_dgray);
}
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;
}
char demo = 0;
uint8_t a;
int promptrow, promptcol;
while(true) {
text.erasePage(DEFAULT_FG_COL, DEFAULT_BG_COL);
putTitle();
text(4,33);
text("Text [t]\n", DEFAULT_FG_COL);
text("Graphics [g]\n");
text("Options [o]\n");
text(text.getRow()+1, 33);
text("Which Mode?");
text.getPos(promptrow, promptcol);
int mode = getCharFromKeyb("tTgGoO", 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') {
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(4,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);
int demo = getCharFromKeyb("fFsSbB", promptrow, promptcol);
if(demo == 'q') {
continue;
}
int modesrow = text.setRow(text.getRow()+2);
int askrow = modesrow;
text(modesrow, 16)("BIOS modes\n");
text("0,1 40x25 8x8 [01]\n");
text("0*,1* 40x25 8x14 [a1]\n");
text("0+,1+ 40x25 9x16 [c1]\n");
text("2,3 80x25 8x8 [03]\n");
text("2*,3* 80x25 8x14 [a3]\n");
text("2+,3+ 80x25 9x16 [c3]\n");
text("7 80x25 9x14 [07]\n");
text("7+ 80x25 9x16 [a7]\n");
askrow = (text.getRow()>askrow)?text.getRow():askrow;
text(modesrow, 42)("Tweaked modes\n");
text(" 80x43 8x8 [1a]\n");
text(" 80x50 9x8 [1b]\n");
text(" 80x28 9x14 [1c]\n");
text("° 80x30 8x16 [1d]\n");
text("° 80x34 8x14 [1e]\n");
text("° 80x60 8x8 [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 {
int mode = getHexFromKeyb(promptrow, promptcol);
if(mode == 0xFFFF) {
demo = 'q';
break;
}
text.setMode(mode);
} while(text.error());
switch(demo) {
case 'f':
demoTextFontMaps();
break;
case 's':
demoTextSplitscreen();
break;
case 'b':
demoMemBench(false);
break;
}
text.resetMode();
}
if(mode == 'g') {
text.erasePage(DEFAULT_FG_COL, DEFAULT_BG_COL);
putTitle();
text(4,33);
text("Circles [c]\n", DEFAULT_FG_COL);
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);
int demo = getCharFromKeyb("cClLpPwWsSrRbB", promptrow, promptcol);
if(demo == 'q') {
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;
int mode = -1;
do {
int mode = getHexFromKeyb(promptrow, promptcol);
if(mode == 0xFFFF) {
demo = 'q';
break;
}
gfx.setMode(mode);
} 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 'b':
demoMemBench(true);
break;
}
gfx.resetMode();
}
}
text.erasePage(c_lgray, c_black);
return 0;
}