]> 4ch.mooo.com Git - 16.git/blob - 16/tweak16/TESTPAT.CPP
wwww
[16.git] / 16 / tweak16 / TESTPAT.CPP
1 /*\r
2         testpat.cpp version 1.6\r
3         by Robert Schmidt of Ztiff Zox Softwear 1993\r
4 \r
5         Defines the member functions of the TestPatterns class declared in\r
6                 testpat.hpp.\r
7 \r
8         1.1\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
12 \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
18 \r
19         1.6\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
23 */\r
24 \r
25 #include <dos.h>\r
26 #include <mem.h>\r
27 #include <conio.h>\r
28 #include <math.h>\r
29 #include <string.h>\r
30 #include <iostream.h>\r
31 #include <stdio.h>\r
32 \r
33 #include "misc.hpp"\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
39 \r
40 extern char *graphScr;\r
41 extern unsigned *textScr;\r
42 extern unsigned editHeight;\r
43 \r
44 // These are the text strings identifying each test to the user.\r
45 \r
46 char *TestPatterns::string[TestPatterns::tests] =\r
47         {\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
54         };\r
55 \r
56 \r
57 void color16(unsigned char color)                                       // Peter\r
58 {\r
59   // load set/reset register with color to be displayed\r
60   outport(0x3ce,color<<8);\r
61 }\r
62 \r
63 // following is a point routine for 16 color mode\r
64 void init16()                                                                           // Peter\r
65 {\r
66   // default drawing color is white\r
67   color16(15);\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
78 }\r
79 \r
80 \r
81 void point16(unsigned int x, unsigned int y)            // Peter\r
82 {\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
91 }\r
92 \r
93 \r
94 // TestPatterns::run() puts the selected test onto the screen.\r
95 \r
96 void TestPatterns::run(RegisterTable &regTab)\r
97         {\r
98         unsigned a,c;\r
99         unsigned long offset;\r
100 \r
101         regTab.out();\r
102 \r
103         outportb(0x3c4,0x02);                   //get write plane enable\r
104         unsigned plane=inportb(0x3c5);\r
105 \r
106         outportb(0x3d4,0x13);                           //get screen width in words\r
107         unsigned long width=inportb(0x3d5)*2;   //convert to bytes\r
108 \r
109         // Now select the correct initialization method:\r
110 \r
111         switch (testNo)\r
112                 {\r
113                 case test4x16:\r
114                 case test1x256:\r
115                 case test4x256:\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
123                         break;\r
124 \r
125                 case testText16:                                // set 8x16 font\r
126                         _AX = 0x1104;\r
127                         _BL = 0;\r
128                         geninterrupt(0x10);\r
129                         goto commonText;\r
130                 case testText8:                                 // set 8x8 font\r
131                         _AX = 0x1102;\r
132                         _BL = 0;\r
133                         geninterrupt(0x10);\r
134 commonText:\r
135                         // Just blank the text screen.\r
136                         memset(textScr, 0, 8000);\r
137                 }\r
138 \r
139         switch (testNo)\r
140                 {\r
141                 case autoDetect:\r
142                         ModeInfo minfo(regTab);\r
143                         GraphicsAPI *g = minfo.getGraphicsAPI();\r
144                         if (!g)\r
145                                 {\r
146                                 setBiosMode(3);\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
157                                 getch();\r
158                                 }\r
159                         else\r
160                                 {\r
161                                 g->setColor(0);\r
162                                 g->wipe();\r
163                                 int width = g->getVirtualWidth();\r
164                                 int height = g->getVirtualHeight();\r
165                                 int colors = g->getColors();\r
166                                 char txt1[40];\r
167                                 int i, j, maxTick = max(width, height);\r
168 \r
169                                 if (g->getColors() == 256)\r
170                                         setPalette256();\r
171                                 else\r
172                                         setPalette16();\r
173 \r
174                                 for (i = 2; i <= maxTick; i += 2)\r
175                                         {\r
176                                         int coord = i-1;\r
177                                         int color, length;\r
178                                         if (i % 10 == 0)\r
179                                                 if (i % 50 == 0)\r
180                                                         if (i % 100 == 0)\r
181                                                                 {\r
182                                                                 color = 15, length = 10;\r
183                                                                 itoa(i, txt1, 10);\r
184                                                                 }\r
185                                                         else\r
186                                                                 color = 14, length = 7;\r
187                                                 else\r
188                                                         color = 13, length = 5;\r
189                                         else\r
190                                                 color = 9, length = 2;\r
191                                         if (i <= width)\r
192                                                 {\r
193                                                 g->setColor(color);\r
194                                                 g->vLine(coord, 0, length);\r
195                                                 if (length == 10)\r
196                                                         {\r
197                                                         g->setTextJustify(GraphicsAPI::RIGHT,\r
198                                                                                           GraphicsAPI::TOP);\r
199                                                         g->putText(coord, length, txt1);\r
200                                                         }\r
201                                                 }\r
202                                         if (i <= height)\r
203                                                 {\r
204                                                 g->setColor(color);\r
205                                                 g->hLine(0, coord, length);\r
206                                                 if (length == 10)\r
207                                                         {\r
208                                                         g->setTextJustify(GraphicsAPI::LEFT,\r
209                                                                                           GraphicsAPI::BOTTOM);\r
210                                                         g->putText(length, coord, txt1);\r
211                                                         }\r
212                                                 }\r
213                                         }\r
214 \r
215                                 int middle = width/2;\r
216                                 int line = 30;\r
217                                 g->setTextJustify(GraphicsAPI::HCENTER, GraphicsAPI::TOP);\r
218                                 g->setColor(10);\r
219                                 g->putText(middle, line, g->getLibID());\r
220                                 g->setColor(12);\r
221                                 g->putText(middle, line+=12, "Physical resolution");\r
222                                 sprintf(txt1, "%d x %d", g->getWidth(), g->getHeight());\r
223                                 g->setColor(15);\r
224                                 g->putText(middle, line+=9, txt1);\r
225 \r
226                                 g->setColor(12);\r
227                                 g->putText(middle, line+=12, "Virtual resolution");\r
228                                 sprintf(txt1, "%d x %d", width, height);\r
229                                 g->setColor(15);\r
230                                 g->putText(middle, line+=9, txt1);\r
231 \r
232                                 g->setColor(12);\r
233                                 g->putText(middle, line+=12, "Page resolution");\r
234                                 sprintf(txt1, "%3.1f x %3.1f", minfo.xpages, minfo.ypages);\r
235                                 g->setColor(15);\r
236                                 g->putText(middle, line+=9, txt1);\r
237 \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
246                                         {\r
247                                         g->setColor(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
251                                         }\r
252 \r
253                                 int basex=0, basey=0, bdirx=0, bdiry=0, quit=0;\r
254                                 while (!quit)\r
255                                         {\r
256                                         if (kbhit())\r
257                                                 {\r
258                                                 int key = getch();\r
259                                                 if (!key && kbhit())\r
260                                                         key = getch() << 8;\r
261 \r
262                                                 switch (key)\r
263                                                         {\r
264                                                         case 0x4700:\r
265                                                                 basex = basey = bdirx = bdiry = 0;\r
266                                                                 break;\r
267                                                         case 0x4800:                    //UP\r
268                                                                 --bdiry;\r
269                                                                 break;\r
270                                                         case 0x4b00:\r
271                                                                 --bdirx;\r
272                                                                 break;\r
273                                                         case 0x4c00:\r
274                                                                 bdirx = bdiry = 0;\r
275                                                                 break;\r
276                                                         case 0x4d00:\r
277                                                                 ++bdirx;\r
278                                                                 break;\r
279                                                         case 0x5000:                    //DOWN\r
280                                                                 ++bdiry;\r
281                                                                 break;\r
282                                                         case 27:\r
283                                                         case 13:\r
284                                                                 quit = 1;\r
285                                                                 break;\r
286                                                         }\r
287                                                 }\r
288                                         basex += bdirx;\r
289                                         basey += bdiry;\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
294                                         if (basex < 0)\r
295                                                 basex = bdirx = 0;\r
296                                         if (basey < 0)\r
297                                                 basey = bdiry = 0;\r
298 \r
299                                         g->setBase(basex, basey);\r
300 //                                      bdirx = bdiry = 0;                      // for debugging\r
301                                         }\r
302                                 delete g;\r
303                                 }\r
304                         break;\r
305 \r
306                 case testText16:\r
307                 case testText8:\r
308 \r
309                         // Fill top line with the sequence "0123456789" lt grey/black:\r
310                         a = 0;\r
311                         for (c=0; c<width; c++)\r
312                                 textScr[a++] = ('0'+(c+1)%10) | 0x0700;\r
313 \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
317 \r
318                         // Now fill the rest with the sequence "ABCDEFGHIJ" in all color\r
319                         //      combinations (except blinking!):\r
320                         c = 0;\r
321                         while (a < 0x4000)      // fixed 0x4800 bug May 7. 1993\r
322                                 textScr[a++] = ('A'+c%('K'-'A')) | ((c&0x7f)<<8), c++;\r
323                         getch();\r
324                         break;\r
325 \r
326 \r
327                 case test1x256:\r
328                         width *= 4;\r
329 \r
330                         // Fill the first 32 lines with 1 pixel wide colored vertical\r
331                         //      lines.\r
332                         for (c=0; c<width; c++)\r
333                                 for (a=0; a<32; a++)\r
334                                         graphScr[a*width+c]=c;\r
335 \r
336                         // Fill the rest with 1 pixel high horizontal lines.\r
337                         c=0;\r
338                         offset=32*width;\r
339                         do      {\r
340                                 memset(graphScr+offset, c++, width);\r
341                                                         //horizontal lines, 1 color each\r
342                                 offset+=width;\r
343                                 }\r
344                         while (offset <= 0x10000-width);\r
345                         getch();\r
346                         break;\r
347 \r
348                 case test4x256:\r
349 \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
354 \r
355                         // Then fill the rest with vertical lines.  This is too slow!\r
356                         offset=c;\r
357                         c=0;\r
358                         a=1;\r
359                         do      {\r
360                                 outportb(0x3c5,a);      //Set write plane enable\r
361                                 graphScr[offset]=c;\r
362 \r
363                                 if ((a<<=1)>8)\r
364                                         {\r
365                                         a=1;\r
366                                         ++offset;\r
367                                         }\r
368                                 if ((++c)==width<<2)\r
369                                         c=0;\r
370                                 }\r
371                         while (offset <= 0xffff);\r
372                         getch();\r
373                         break;\r
374                 case test4x16:\r
375 \r
376 // This is Peter's 16-color test.  The original test is commented out below.\r
377 \r
378                         init16();\r
379                         color16(15);\r
380                         for (a=0; a<(width*8); a+=10) {\r
381                           if (! (a % 100)) {\r
382                                 color16(15);\r
383                                 point16(a,1);\r
384                                 point16(a,2);\r
385                                 point16(a,3); }\r
386                           else\r
387                                 color16(2);\r
388 \r
389                           point16(a,0); }\r
390 \r
391                         for (a=0; a<600; a+=10) {\r
392                           if (! (a % 100)) {\r
393                                 color16(15);\r
394                                 point16(1,a);\r
395                                 point16(2,a);\r
396                                 point16(3,a); }\r
397                           else\r
398                                 color16(2);\r
399 \r
400                           point16(0,a); }\r
401 \r
402                         // draw 16 color bars across the screen\r
403 \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
407                                 point16(x+8,y); }}\r
408 \r
409 /*\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
414                                 graphScr[c]=0x0f;\r
415 \r
416                         // Fill the rest with various bit patterns, in all colors.\r
417                         for (a=0; a<256; a++)\r
418                                 {\r
419                                 outportb(0x3c5,a);\r
420                                 memset(graphScr+(a+40)*width, a, width);\r
421                                 }\r
422 */\r
423                         getch();\r
424                         break;\r
425                 }\r
426         }\r
427 \r
428 \r
429 // tellTest() puts the name of the current test at the correct position on\r
430 //      the edit screen.\r
431 \r
432 void TestPatterns::tellTest()\r
433         {\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
439         clreol();\r
440         }\r