home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / grap / util / 020 / testpat.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-21  |  4.0 KB  |  173 lines

  1. /*
  2.     TestPat.CPP version 1.0
  3.     by Robert Schmidt of Ztiff Zox Softwear 1993
  4.  
  5.     Defines the member functions of the TestPatterns class declared in
  6.         TestPat.HPP.
  7. */
  8.  
  9. #include <dos.h>
  10. #include <mem.h>
  11. #include <conio.h>
  12. #include <iostream.h>
  13. #include "Screen.HPP"
  14. #include "TestPat.HPP"
  15.  
  16. extern char *graphScr;
  17. extern unsigned *textScr;
  18. extern unsigned editHeight;
  19.  
  20. // These are the text strings identifying each test to the user.
  21.  
  22. char *TestPatterns::string[TestPatterns::tests] =
  23.     {
  24.     "Text screen, 16 point",
  25.     "Text screen, 8 point",
  26.     "4 planes, 16 colors",
  27.     "1 plane, 256 colors",
  28.     "4 planes, 256 colors"
  29.     };
  30.  
  31.  
  32. // TestPatterns::run() puts the given test onto the screen.
  33.  
  34. void TestPatterns::run()
  35.     {
  36.     unsigned a,c;
  37.     unsigned long offset;
  38.  
  39.     outportb(0x3c4,0x02);                //get write plane enable
  40.     unsigned plane=inportb(0x3c5);
  41.  
  42.     outportb(0x3d4,0x13);                //get screen width in words
  43.     unsigned width=inportb(0x3d5)*2;    //convert to bytes
  44.  
  45.     // Now select the correct initialization method:
  46.  
  47.     switch (testNo)
  48.         {
  49.         case test1x256:
  50.         case test4x16:
  51.         case test4x256:
  52.             // All graphics modes: clear the screen, but take care of
  53.             //    write enabling all planes.
  54.             outport(0x3c4,0x0f02);
  55.             memset(graphScr, 0, 0xffff);
  56.             outportb(0x3c4,0x02);
  57.             outportb(0x3c5,plane);
  58.             break;
  59.  
  60.         case testText16:                // set 8x16 font
  61.             _AX = 0x1104;
  62.             _BL = 0;
  63.             geninterrupt(0x10);
  64.             goto commonText;
  65.         case testText8:                    // set 8x8 font
  66.             _AX = 0x1102;
  67.             _BL = 0;
  68.             geninterrupt(0x10);
  69. commonText:
  70.             // Just blank the text screen.
  71.             memset(textScr, 0, 8000);
  72.         }
  73.  
  74.     // Now for the selected pattern.  None of them are very impressive,
  75.     //    but it kinda gives you an idea of the mode.  If you have ideas
  76.     //    for more informative tests, please let me know!
  77.  
  78.     switch (testNo)
  79.         {
  80.         case testText16:
  81.         case testText8:
  82.  
  83.             // Fill top line with the sequence "0123456789" lt grey/black:
  84.             a = 0;
  85.             for (c=0; c<width; c++)
  86.                 textScr[a++] = ('0'+(c+1)%10) | 0x0700;
  87.  
  88.             // Then fill 4 lines with the ASCII set in white on blue:
  89.             for (c=0; c<5*width; c++)
  90.                 textScr[a++] = c | 0x1f00;
  91.  
  92.             // Now fill the rest with the sequence "ABCDEFGHIJ" in all color
  93.             //    combinations (except blinking!):
  94.             c = 0;
  95.             while (a < 0x4800)
  96.                 textScr[a++] = ('A'+c%('K'-'A')) | ((c&0x7f)<<8), c++;
  97.             break;
  98.  
  99.         case test1x256:
  100.  
  101.             // Fill the first 32 lines with 1 pixel wide colored vertical
  102.             //    lines.
  103.             for (c=0; c<width*4; c++)
  104.                 for (a=0; a<32; a++)
  105.                     graphScr[a*width*4+c]=c;
  106.  
  107.             // Fill the rest with 1 pixel high horizontal lines.
  108.             c=0;
  109.             offset=32*4*width;
  110.             do    {
  111.                 memset(graphScr+offset, c++, width*4);
  112.                                     //horizontal lines, 1 color each
  113.                 offset+=width<<2;
  114.                 }
  115.             while (offset < (0xffff-width<<2));
  116.             break;
  117.  
  118.         case test4x256:
  119.  
  120.             // This test is affected by the Write Plane Enable register.
  121.             // First put up 32 horizontal lines in the 32 first colors.
  122.             for (c=0; c<(width<<5); c++)
  123.                 graphScr[c]=c/width;
  124.  
  125.             // Then fill the rest with vertical lines.  This is too slow!
  126.             offset=c;
  127.             c=0;
  128.             a=1;
  129.             do    {
  130.                 outportb(0x3c5,a);    //Set write plane enable
  131.                 graphScr[offset]=c;
  132.  
  133.                 if ((a<<=1)>8)
  134.                     {
  135.                     a=1;
  136.                     ++offset;
  137.                     }
  138.                 if ((++c)==width<<2)
  139.                     c=0;
  140.                 }
  141.             while (offset <= 0xffff);
  142.             break;
  143.         case test4x16:
  144.  
  145.             // Fill first 32 lines with thick vertical stripes alternating
  146.             //    between black and the color selected by Write Plane Enable.
  147.             for (c=0; c<(width<<5); c++)
  148.                 graphScr[c]=0x0f;
  149.  
  150.             // Fill the rest with various bit patterns, in all colors.
  151.             for (a=0; a<256; a++)
  152.                 {
  153.                 outportb(0x3c5,a);
  154.                 memset(graphScr+4000+a*width, a, width);
  155.                 }
  156.             break;
  157.         }
  158.     }
  159.  
  160.  
  161. // tellTest() puts the name of the current test at the correct position on
  162. //    the edit screen.
  163.  
  164. void TestPatterns::tellTest()
  165.     {
  166.     gotoxy(42,editHeight);
  167.     textattr(TESTHEADER_COLOR);
  168.     cprintf("Current test: ");
  169.     textattr(TESTSTRING_COLOR);
  170.     cprintf(string[testNo]);
  171.     clreol();
  172.     }
  173.