home *** CD-ROM | disk | FTP | other *** search
/ World of Graphics / WOGRAPH.BIN / 440.TEST256.C < prev    next >
C/C++ Source or Header  |  1993-03-07  |  8KB  |  318 lines

  1. /****************************************************************************
  2. *
  3. *                           SuperVGA Test Library
  4. *
  5. *                   Copyright (C) 1993 Kendall Bennett.
  6. *                            All rights reserved.
  7. *
  8. * Filename:        $RCSfile: test256.c $
  9. * Version:        $Revision: 1.2 $
  10. *
  11. * Language:        ANSI C
  12. * Environment:    IBM PC (MSDOS)
  13. *
  14. * Description:    Simple program to test the operation of the SuperVGA
  15. *                bank switching code and page flipping code for the
  16. *                256 color SuperVGA video modes.
  17. *
  18. *                MUST be compiled in the large model.
  19. *
  20. * $Id: test256.c 1.2 1993/03/07 04:06:11 kjb Exp $
  21. *
  22. * Revision History:
  23. * -----------------
  24. *
  25. * $Log: test256.c $
  26. * Revision 1.2  1993/03/07  04:06:11  kjb
  27. * Bug fixes.
  28. *
  29. * Revision 1.1  1993/03/03  10:30:09  kjb
  30. * Initial revision
  31. *
  32. ****************************************************************************/
  33.  
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <dos.h>
  38. #include <conio.h>
  39. #include "svga256.h"
  40.  
  41. /*---------------------------- Global Variables ---------------------------*/
  42.  
  43. int        x,y,maxcolor = 255,defcolor = 15;
  44. int        driver = grDETECT,chipID,memory,dac,mode;
  45.  
  46. extern char *version;
  47.  
  48. /* External routines */
  49.  
  50. void _copyTest(void);
  51. void parseArguments(int argc,char *argv[]);
  52.  
  53. /*----------------------------- Implementation ----------------------------*/
  54.  
  55. void writeText(int x,int y,uchar *str)
  56. /****************************************************************************
  57. *
  58. * Function:        writeText
  59. * Parameters:    x,y        - Position to begin drawing string at
  60. *                str        - String to draw
  61. *
  62. * Description:    Draws a string using the BIOS 8x16 video font by plotting
  63. *                each pixel in the characters individually. This should
  64. *                work for all video modes.
  65. *
  66. ****************************************************************************/
  67. {
  68.     uchar            byte;
  69.     int                i,j,k,length,ch;
  70.     uchar            far *_font;
  71.     struct REGPACK    regs;
  72.  
  73.     regs.r_ax = 0x1130;
  74.     regs.r_bx = 0x0600;
  75.     intr(0x10,®s);
  76.     _font = FP(regs.r_es,regs.r_bp);
  77.  
  78.     length = strlen(str);
  79.     for (k = 0; k < length; k++) {
  80.         ch = str[k];
  81.         for (j = 0; j < 16; j++) {
  82.             byte = *(_font + ch * 16 + j);
  83.             for (i = 0; i < 8; i++) {
  84.                 if ((byte & 0x80) != 0)
  85.                     putPixel(x+i,y+j,defcolor);
  86.                 byte <<= 1;
  87.                 }
  88.             }
  89.         x += 8;
  90.         }
  91. }
  92.  
  93. void moireTest(void)
  94. /****************************************************************************
  95. *
  96. * Function:        moireTest
  97. *
  98. * Description:    Draws a simple Moire pattern on the display screen using
  99. *                lines, and waits for a key press.
  100. *
  101. ****************************************************************************/
  102. {
  103.     uchar    buf[80];
  104.     int        i;
  105.  
  106.     clear();
  107.     for (i = 0; i < maxx; i += 10) {
  108.         line(maxx/2,maxy/2,i,0,i % maxcolor);
  109.         line(maxx/2,maxy/2,i,maxy,(i+1) % maxcolor);
  110.         }
  111.     for (i = 0; i < maxy; i += 10) {
  112.         line(maxx/2,maxy/2,0,i,(i+2) % maxcolor);
  113.         line(maxx/2,maxy/2,maxx,i,(i+3) % maxcolor);
  114.         }
  115.  
  116.     if (maxx != 319) {
  117.         x = 80;
  118.         y = 80;
  119.         writeText(x,y,"Bank switching test");    y += 32;
  120.         sprintf(buf,"Video mode: %s",MGL_modeName(mode));
  121.         writeText(x,y,buf);    y += 16;
  122.         sprintf(buf,"Maximum x: %d, Maximum y: %d, BytesPerLine %d, Pages: %d",
  123.             maxx,maxy,bytesperline,maxpage+1);
  124.         writeText(x,y,buf);    y += 32;
  125.         writeText(x,y,"You should see a colorful Moire pattern on the screen");
  126.         y += 16;
  127.         }
  128.     else {
  129.         x = 40;
  130.         y = 40;
  131.         }
  132.     writeText(x,y,"Press any key to continue");
  133.     y += 32;
  134.     getch();
  135. }
  136.  
  137. void readWriteTest(void)
  138. /****************************************************************************
  139. *
  140. * Function:        readWriteTest
  141. *
  142. * Description:    Test the separate read/write bank routines if available.
  143. *                We do this by copying the top 100 scanlines of video memory
  144. *                to another location in video memory.
  145. *
  146. *                This test is desgined to work only in 640 wide video modes.
  147. *
  148. ****************************************************************************/
  149. {
  150.     if (twobanks && (maxx == 639)) {
  151.         _copyTest();
  152.         writeText(x,y,"To test the separate read/write banks, the top 100 scanlines of");
  153.         y += 16;
  154.         writeText(x,y,"this display page should be moved to start at scanline 205.");
  155.         y += 16;
  156.         writeText(x,y,"This ensures that a bank boundary will have been crossed");
  157.         y += 78;
  158.         writeText(x,y,"Press any key to continue");
  159.         getch();
  160.         }
  161. }
  162.  
  163. void pageFlipTest(void)
  164. /****************************************************************************
  165. *
  166. * Function:        pageFlipTest
  167. *
  168. * Description:    Animates a line on the display using page flipping if
  169. *                page flipping is active.
  170. *
  171. ****************************************************************************/
  172. {
  173.     int        i,j,istep,jstep,color,apage,vpage;
  174.     char    buf[80];
  175.  
  176.     if (maxpage != 0) {
  177.         vpage = 0;
  178.         apage = 1;
  179.         setActivePage(apage);
  180.         setVisualPage(vpage);
  181.         i = 0;
  182.         j = maxy;
  183.         istep = 2;
  184.         jstep = -2;
  185.         color = 15;
  186.         while (!kbhit()) {
  187.             setActivePage(apage);
  188.             clear();
  189.             sprintf(buf,"Page %d of %d", vpage+1, maxpage+1);
  190.             if (maxx == 319) {
  191.                 writeText(0,80,"Page flipping - should be no flicker");
  192.                 writeText(0,100,buf);
  193.                 }
  194.             else {
  195.                 writeText(80,80,"Page flipping - should be no flicker");
  196.                 writeText(80,100,buf);
  197.                 }
  198.             line(i,0,maxx-i,maxy,color);
  199.             line(0,maxy-j,maxx,j,color);
  200.             vpage = ++vpage % (maxpage+1);
  201.             setVisualPage(vpage);
  202.             apage = ++apage % (maxpage+1);
  203.             i += istep;
  204.             if (i > maxx) {
  205.                 i = maxx-2;
  206.                 istep = -2;
  207.                 }
  208.             if (i < 0)    i = istep = 2;
  209.             j += jstep;
  210.             if (j > maxy) {
  211.                 j = maxy-2;
  212.                 jstep = -2;
  213.                 }
  214.             if (j < 0)    j = jstep = 2;
  215.             }
  216.         getch();                /* Swallow keypress */
  217.         }
  218. }
  219.  
  220. void testingComplete(void)
  221. /****************************************************************************
  222. *
  223. * Function:        testingComplete
  224. *
  225. * Description:    Clears the first display page and puts up a message.
  226. *
  227. ****************************************************************************/
  228. {
  229.     setActivePage(0);
  230.     setVisualPage(0);
  231.     clear();
  232.  
  233.     if (maxx == 319) {
  234.         writeText(0,40,"Testing complete");
  235.         writeText(0,60,"press any key to return to text mode");
  236.         }
  237.     else
  238.         writeText(80,80,"Testing complete - press any key to return to text mode");
  239.     getch();
  240. }
  241.  
  242. void main(int argc,char *argv[])
  243. {
  244.     int        i,choice,maxmenu,result;
  245.     int        menu[20];
  246.     char    buf[80];
  247.  
  248.     parseArguments(argc,argv);
  249.     initSuperVGA(&driver,&chipID,&memory,&dac);
  250.  
  251.     while (true) {
  252.         clrscr();
  253.         printf("256 color SuperVGA Test Program (Version %s)\n\n",version);
  254.         printf("Video Card: %s ",MGL_driverName(driver));
  255.         if (driver > grSVGA && MGL_chipsetName(driver,chipID))
  256.             printf("(%s)",MGL_chipsetName(driver,chipID));
  257.         printf("\n");
  258.         printf("Memory:     %dk\n",memory);
  259.         printf("Video DAC:  %s\n",MGL_dacName(dac));
  260.         printf("\n");
  261.         printf("Separate read/write banks: %s\n", twobanks ? "Yes" : "No");
  262.         printf("Extended page flipping:    %s\n", extendedflipping ? "Yes" : "No");
  263.         printf("\n");
  264.         printf("Which video mode to test:\n\n");
  265.  
  266.         i = maxmenu = 0;
  267.         while (modeList[i] != -1) {
  268.             /* Filter out the 256 color video modes */
  269.  
  270.             switch (modeList[i]) {
  271.                 case grVGA_320x200x256:
  272.                 case grSVGA_640x350x256:
  273.                 case grSVGA_640x400x256:
  274.                 case grSVGA_640x480x256:
  275.                 case grSVGA_800x600x256:
  276.                 case grSVGA_1024x768x256:
  277.                 case grSVGA_1280x1024x256:
  278.                     printf("    [%2d] - %s (%d page)\n",maxmenu,
  279.                         MGL_modeName(modeList[i]),
  280.                         MGL_availablePages(driver,memory,modeList[i]));
  281.                     menu[maxmenu++] = modeList[i];
  282.                     break;
  283.                 }
  284.             i++;
  285.             }
  286.         printf("    [ Q] - Quit\n\n");
  287.         printf("Choice: ");
  288.  
  289.         gets(buf);
  290.         if (buf[0] == 'q' || buf[0] == 'Q')
  291.             break;
  292.  
  293.         choice = atoi(buf);
  294.         if (0 <= choice && choice < maxmenu) {
  295.             result = setSuperVGAMode(mode = menu[choice]);
  296.             if (result == -1) {
  297.                 printf("ERROR: Invalid video mode for driver!\n");
  298.                 printf("       Please report this discrepancy...\n");
  299.                 exit(1);
  300.                 }
  301.             if (!result) {
  302.                 printf("\n");
  303.                 printf("ERROR: Video mode did not set correctly!\n");
  304.                 printf("       Please report this discrepancy...\n");
  305.                 printf("\nPress any key to continue...\n");
  306.                 getch();
  307.                 }
  308.             else {
  309.                 moireTest();
  310.                 readWriteTest();
  311.                 pageFlipTest();
  312.                 testingComplete();
  313.                 restoreMode();
  314.                 }
  315.             }
  316.         }
  317. }
  318.