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

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