2 testpat.cpp version 1.6
\r
3 by Robert Schmidt of Ztiff Zox Softwear 1993
\r
5 Defines the member functions of the TestPatterns class declared in
\r
9 Fixed a couple of bugs in the text mode test. On some computers
\r
10 it would overwrite data in the C000h segment, if RAM had been mapped
\r
11 there by QEMM or something similar.
\r
13 Modified June 13-14, 1993 by Peter McDermott
\r
14 The 16 color test pattern has been changed. Now it puts dots from the
\r
15 upper left hand corner to down the top and left of the screen to the
\r
16 edges. There is a longer, white dot every 100 pixels. Also, a color
\r
17 bar is displayed across the page.
\r
20 Added support for the mode autodetecting scheme, and for VGALIB,
\r
21 my mode independant VGA graphics library, to provide more
\r
22 intelligent test screens.
\r
30 #include <iostream.h>
\r
34 #include "screen.hpp"
\r
35 #include "vgalib.hpp"
\r
36 #include "testpat.hpp"
\r
37 #include "detect.hpp"
\r
38 #include "screen.hpp"
\r
40 extern char *graphScr;
\r
41 extern unsigned *textScr;
\r
42 extern unsigned editHeight;
\r
44 // These are the text strings identifying each test to the user.
\r
46 char *TestPatterns::string[TestPatterns::tests] =
\r
48 "Graphics autodetect",
\r
49 "Text screen, 16 point",
\r
50 "Text screen, 8 point",
\r
51 "4 planes, 16 colors",
\r
52 "1 plane, 256 colors",
\r
53 "4 planes, 256 colors"
\r
57 void color16(unsigned char color) // Peter
\r
59 // load set/reset register with color to be displayed
\r
60 outport(0x3ce,color<<8);
\r
63 // following is a point routine for 16 color mode
\r
64 void init16() // Peter
\r
66 // default drawing color is white
\r
68 // load set/reset enable for all display planes
\r
69 outport(0x3ce,0x0f01);
\r
70 // load map mask register for all display planes
\r
71 outport(0x3c4,0x0f02);
\r
72 // load function select correctly (logical OR)
\r
73 outport(0x3ce,0x2003);
\r
74 // set to read mode 0
\r
75 outportb(0x3ce,0x05);
\r
76 int ModeReg=inportb(0x3cf);
\r
77 outport(0x3ce,ModeReg && 0xf7); // make sure we're in read mode 0
\r
81 void point16(unsigned int x, unsigned int y) // Peter
\r
83 outportb(0x3d4,0x13); //get screen width in words
\r
84 unsigned width=inportb(0x3d5)*2; //convert to bytes
\r
85 // load bitmask register with correct value
\r
86 outport(0x3ce,(0x80 >> (x % 8) << 8) | 0x08);
\r
87 // load the latch register with the data already in display memory
\r
88 _AX=graphScr[y*width+x/8];
\r
89 // calculate the position in memory of the pixel to be written
\r
90 graphScr[y*width+x/8] = 0x00;
\r
94 // TestPatterns::run() puts the selected test onto the screen.
\r
96 void TestPatterns::run(RegisterTable ®Tab)
\r
99 unsigned long offset;
\r
103 outportb(0x3c4,0x02); //get write plane enable
\r
104 unsigned plane=inportb(0x3c5);
\r
106 outportb(0x3d4,0x13); //get screen width in words
\r
107 unsigned long width=inportb(0x3d5)*2; //convert to bytes
\r
109 // Now select the correct initialization method:
\r
116 // All graphics modes: clear the screen, but take care of
\r
117 // write enabling all planes.
\r
118 outport(0x3c4,0x0f02);
\r
119 memset(graphScr, 0, 0xffff);
\r
120 graphScr[0xffff] = 0;
\r
121 outportb(0x3c4,0x02);
\r
122 outportb(0x3c5,plane);
\r
125 case testText16: // set 8x16 font
\r
128 geninterrupt(0x10);
\r
130 case testText8: // set 8x8 font
\r
133 geninterrupt(0x10);
\r
135 // Just blank the text screen.
\r
136 memset(textScr, 0, 8000);
\r
142 ModeInfo minfo(regTab);
\r
143 GraphicsAPI *g = minfo.getGraphicsAPI();
\r
147 cout << "This is not a graphics mode. Either: -" << endl
\r
148 << " - Use TAB (->|) to select one of the two "
\r
149 "available text screens," << endl
\r
150 << " - Base your mode on one of the BIOS graphics "
\r
151 "modes, by pressing B and " << endl
\r
152 << " typing a graphics mode number, for example "
\r
153 "0x12 or 0x13, or" << endl
\r
154 << " - Load a graphics mode file by pressing L and "
\r
155 "typing the name of the file." << endl << endl
\r
156 << "Now press any key to return to the editor." << endl;
\r
163 int width = g->getVirtualWidth();
\r
164 int height = g->getVirtualHeight();
\r
165 int colors = g->getColors();
\r
167 int i, j, maxTick = max(width, height);
\r
169 if (g->getColors() == 256)
\r
174 for (i = 2; i <= maxTick; i += 2)
\r
182 color = 15, length = 10;
\r
186 color = 14, length = 7;
\r
188 color = 13, length = 5;
\r
190 color = 9, length = 2;
\r
193 g->setColor(color);
\r
194 g->vLine(coord, 0, length);
\r
197 g->setTextJustify(GraphicsAPI::RIGHT,
\r
199 g->putText(coord, length, txt1);
\r
204 g->setColor(color);
\r
205 g->hLine(0, coord, length);
\r
208 g->setTextJustify(GraphicsAPI::LEFT,
\r
209 GraphicsAPI::BOTTOM);
\r
210 g->putText(length, coord, txt1);
\r
215 int middle = width/2;
\r
217 g->setTextJustify(GraphicsAPI::HCENTER, GraphicsAPI::TOP);
\r
219 g->putText(middle, line, g->getLibID());
\r
221 g->putText(middle, line+=12, "Physical resolution");
\r
222 sprintf(txt1, "%d x %d", g->getWidth(), g->getHeight());
\r
224 g->putText(middle, line+=9, txt1);
\r
227 g->putText(middle, line+=12, "Virtual resolution");
\r
228 sprintf(txt1, "%d x %d", width, height);
\r
230 g->putText(middle, line+=9, txt1);
\r
233 g->putText(middle, line+=12, "Page resolution");
\r
234 sprintf(txt1, "%3.1f x %3.1f", minfo.xpages, minfo.ypages);
\r
236 g->putText(middle, line+=9, txt1);
\r
238 int hPalSize = width - 40;
\r
239 int vPalSize = height - (line+=22);
\r
240 int palSide = sqrt(colors);
\r
241 int hPalPix = hPalSize/palSide;
\r
242 int vPalPix = vPalSize/palSide;
\r
243 hPalSize = palSide * hPalPix + 1;
\r
244 vPalSize = palSide * vPalPix + 1;
\r
245 for (i = 0; i < colors; ++i)
\r
248 int x = width-hPalSize+(i/palSide)*hPalPix;
\r
249 int y = height-vPalSize+(i%palSide)*vPalPix;
\r
250 g->bar(x, y, x+hPalPix, y+vPalPix);
\r
253 int basex=0, basey=0, bdirx=0, bdiry=0, quit=0;
\r
259 if (!key && kbhit())
\r
260 key = getch() << 8;
\r
265 basex = basey = bdirx = bdiry = 0;
\r
279 case 0x5000: //DOWN
\r
290 if (basex > width-g->getWidth())
\r
291 basex = width-g->getWidth(), bdirx = 0;
\r
292 if (basey > height-g->getHeight())
\r
293 basey = height-g->getHeight(), bdiry = 0;
\r
299 g->setBase(basex, basey);
\r
300 // bdirx = bdiry = 0; // for debugging
\r
309 // Fill top line with the sequence "0123456789" lt grey/black:
\r
311 for (c=0; c<width; c++)
\r
312 textScr[a++] = ('0'+(c+1)%10) | 0x0700;
\r
314 // Then fill 4 lines with the ASCII set in white on blue:
\r
315 for (c=0; c<5*width; c++)
\r
316 textScr[a++] = c | 0x1f00;
\r
318 // Now fill the rest with the sequence "ABCDEFGHIJ" in all color
\r
319 // combinations (except blinking!):
\r
321 while (a < 0x4000) // fixed 0x4800 bug May 7. 1993
\r
322 textScr[a++] = ('A'+c%('K'-'A')) | ((c&0x7f)<<8), c++;
\r
330 // Fill the first 32 lines with 1 pixel wide colored vertical
\r
332 for (c=0; c<width; c++)
\r
333 for (a=0; a<32; a++)
\r
334 graphScr[a*width+c]=c;
\r
336 // Fill the rest with 1 pixel high horizontal lines.
\r
340 memset(graphScr+offset, c++, width);
\r
341 //horizontal lines, 1 color each
\r
344 while (offset <= 0x10000-width);
\r
350 // This test is affected by the Write Plane Enable register.
\r
351 // First put up 32 horizontal lines in the 32 first colors.
\r
352 for (c=0; c<(width<<5); c++)
\r
353 graphScr[c]=c/width;
\r
355 // Then fill the rest with vertical lines. This is too slow!
\r
360 outportb(0x3c5,a); //Set write plane enable
\r
361 graphScr[offset]=c;
\r
368 if ((++c)==width<<2)
\r
371 while (offset <= 0xffff);
\r
376 // This is Peter's 16-color test. The original test is commented out below.
\r
380 for (a=0; a<(width*8); a+=10) {
\r
391 for (a=0; a<600; a+=10) {
\r
402 // draw 16 color bars across the screen
\r
404 for (int x = 0; x < (width-2)*8; x++) {
\r
405 color16(x / ((width-2)*8/16));
\r
406 for (int y=10; y < 190; y++) {
\r
410 // Original 16-color test
\r
411 // Fill first 32 lines with thick vertical stripes alternating
\r
412 // between black and the color selected by Write Plane Enable.
\r
413 for (c=0; c<(width<<5); c++)
\r
416 // Fill the rest with various bit patterns, in all colors.
\r
417 for (a=0; a<256; a++)
\r
420 memset(graphScr+(a+40)*width, a, width);
\r
429 // tellTest() puts the name of the current test at the correct position on
\r
430 // the edit screen.
\r
432 void TestPatterns::tellTest()
\r
434 gotoxy(42,editHeight);
\r
435 textattr(TESTHEADER_COLOR);
\r
436 cprintf("Current test: ");
\r
437 textattr(TESTSTRING_COLOR);
\r
438 cprintf(string[testNo]);
\r