home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / SVGALIB / SVGALIB1.TAR / svgalib / demos / vgatest.c < prev   
Encoding:
C/C++ Source or Header  |  1994-12-22  |  5.3 KB  |  239 lines

  1. /* From VGAlib, changed for svgalib */
  2. /* partially copyrighted (C) 1993 by Hartmut Schirmer */
  3.  
  4.  
  5. #include <stdio.h>
  6. #include <unistd.h>        /* for usleep( long ) */
  7. #include <string.h>
  8. #include "vga.h"
  9.  
  10. static unsigned char line[2048 * 3];
  11.  
  12. static void testmode(int mode)
  13. {
  14.     int xmax, ymax, i, x, y, yw, ys, c;
  15.     vga_modeinfo *modeinfo;
  16.  
  17.     vga_setmode(mode);
  18.  
  19.     modeinfo = vga_getmodeinfo(mode);
  20.  
  21.     printf("Width: %d  Height: %d  Colors: %d\n",
  22.            modeinfo->width,
  23.            modeinfo->height,
  24.            modeinfo->colors);
  25.     printf("DisplayStartRange: %xh  Maxpixels: %d  Blit: %s\n",
  26.            modeinfo->startaddressrange,
  27.            modeinfo->maxpixels,
  28.            modeinfo->haveblit ? "YES" : "NO");
  29.  
  30. #ifdef TEST_MODEX
  31.     if (modeinfo->colors==256)
  32.       printf("Switching to ModeX ... %s\n", 
  33.         (vga_setmodeX()?"done":"failed"));
  34. #endif
  35.  
  36.     vga_screenoff();
  37.  
  38.     xmax = vga_getxdim() - 1;
  39.     ymax = vga_getydim() - 1;
  40.  
  41.     vga_setcolor(vga_white());
  42.     vga_drawline(0, 0, xmax, 0);
  43.     vga_drawline(xmax, 0, xmax, ymax);
  44.     vga_drawline(xmax, ymax, 0, ymax);
  45.     vga_drawline(0, ymax, 0, 0);
  46.  
  47.     for (i = 0; i <= 15; i++) {
  48.         vga_setegacolor(i);
  49.         vga_drawline(10 + i * 5, 10, 90 + i * 5, 90);
  50.     }
  51.     for (i = 0; i <= 15; i++) {
  52.         vga_setegacolor(i);
  53.         vga_drawline(90 + i * 5, 10, 10 + i * 5, 90);
  54.     }
  55.  
  56.     vga_screenon();
  57.  
  58.     ys = 100;
  59.     yw = (ymax - 100) / 4;
  60.     switch (vga_getcolors()) {
  61.     case 256:
  62.         for (i = 0; i < 60; ++i) {
  63.             c = (i * 64) / 60;
  64.             vga_setpalette(i + 16, c, c, c);
  65.             vga_setpalette(i + 16 + 60, c, 0, 0);
  66.             vga_setpalette(i + 16 + (2 * 60), 0, c, 0);
  67.             vga_setpalette(i + 16 + (3 * 60), 0, 0, c);
  68.         }
  69.         line[0] = line[xmax] = 15;
  70.         line[1] = line[xmax - 1] = 0;
  71.         for (x = 2; x < xmax - 1; ++x)
  72.             line[x] = (((x - 2) * 60) / (xmax - 3)) + 16;
  73.         for (y = ys; y < ys + yw; ++y)    /* gray */
  74.             vga_drawscanline(y, line);
  75.         for (x = 2; x < xmax - 1; ++x)
  76.             line[x] += 60;
  77.         ys += yw;
  78.         for (y = ys; y < ys + yw; ++y)    /* red */
  79.             vga_drawscanline(y, line);
  80.         for (x = 2; x < xmax - 1; ++x)
  81.             line[x] += 60;
  82.         ys += yw;
  83.         for (y = ys; y < ys + yw; ++y)    /* green */
  84.             vga_drawscanline(y, line);
  85.         for (x = 2; x < xmax - 1; ++x)
  86.             line[x] += 60;
  87.         ys += yw;
  88.         for (y = ys; y < ys + yw; ++y)    /* blue */
  89.             vga_drawscanline(y, line);
  90.         break;
  91.  
  92.     case 1 << 15:
  93.     case 1 << 16:
  94.     case 1 << 24:
  95.         for (x = 2; x < xmax - 1; ++x) {
  96.             c = ((x - 2) * 256) / (xmax - 3);
  97.             y = ys;
  98.             vga_setrgbcolor(c, c, c);
  99.             vga_drawline(x, y, x, y + yw - 1);
  100.             y += yw;
  101.             vga_setrgbcolor(c, 0, 0);
  102.             vga_drawline(x, y, x, y + yw - 1);
  103.             y += yw;
  104.             vga_setrgbcolor(0, c, 0);
  105.             vga_drawline(x, y, x, y + yw - 1);
  106.             y += yw;
  107.             vga_setrgbcolor(0, 0, c);
  108.             vga_drawline(x, y, x, y + yw - 1);
  109.         }
  110.         break;
  111.     default:
  112.         if (vga_getcolors() == 16) {
  113.             for (i = 0; i < xmax - 1; i++)
  114.                 line[i] = (i + 2) % 16;
  115.             line[0] = line[xmax] = 15;
  116.             line[1] = line[xmax - 1] = 0;
  117.         }
  118.         if (vga_getcolors() == 2) {
  119.             for (i = 0; i <= xmax; i++)
  120.                 line[i] = 0x11;
  121.             line[0] = 0x91;
  122.         }
  123.         for (i = 100; i < ymax - 1; i++)
  124.             vga_drawscanline(i, line);
  125.         break;
  126.  
  127.     }
  128.  
  129.     if (getchar() == 'd')
  130.         vga_dumpregs();
  131.  
  132.     vga_setmode(TEXT);
  133. }
  134.  
  135. void main(void)
  136. {
  137.     int mode;
  138.     int i, high;
  139.  
  140.     vga_init();    /* Initialize. */
  141.  
  142.     mode = -1;
  143. #if 0    /* Prompt is more useful. */
  144.     mode = vga_getdefaultmode();
  145. #endif
  146.  
  147.     if (mode == -1) {
  148.         printf("Choose one of the following video modes: \n");
  149.  
  150.         high = 0;
  151.         for (i = 1; i <= GLASTMODE; i++)
  152.             if (vga_hasmode(i)) {
  153.                 vga_modeinfo *info;
  154.                 char expl[100];
  155.                 char *cols = NULL;
  156.  
  157.                 *expl = '\0';
  158.                 info = vga_getmodeinfo(i);
  159.                 switch (info->colors) {
  160.                 case 2:
  161.                     cols = "2";
  162.                     strcpy(expl, "1 bitplane, monochrome");
  163.                     break;
  164.                 case 16:
  165.                     cols = "16";
  166.                     strcpy(expl, "4 bitplanes");
  167.                     break;
  168.                 case 256:
  169.                     if (i == G320x200x256)
  170.                         strcpy(expl, "packed-pixel");
  171.                     else
  172.                         if (i == G320x240x256
  173.                         || i == G320x400x256
  174.                         || i == G360x480x256)
  175.                             strcpy(expl, "Mode X");
  176.                         else
  177.                             strcpy(expl,
  178.                             "packed-pixel, banked");
  179.                     break;
  180.                 case 1 << 15:
  181.                     cols = "32K";
  182.                     strcpy(expl, "5-5-5 RGB, blue at LSB, banked");
  183.                     break;
  184.                 case 1 << 16:
  185.                     cols = "64K";
  186.                     strcpy(expl, "5-6-5 RGB, blue at LSB, banked");
  187.                     break;
  188.                 case 1 << 24:
  189.                     cols = "16M";
  190.                     if (info->bytesperpixel==3)
  191.                         strcpy(expl, "8-8-8 RGB, blue byte first, banked");
  192.                     else if(info->flags&RGB_MISORDERED)
  193.                         strcpy(expl, "8-8-8 RGBX, 32-bit pixels, X byte first, banked");
  194.                     else
  195.                         strcpy(expl, "8-8-8 XRGB, 32-bit pixels, blue byte first, banked");
  196.                     break;
  197.                 }
  198.                 if (info->flags&IS_INTERLACED) {
  199.                     if (*expl != '\0')
  200.                         strcat(expl, ", ");
  201.                     strcat(expl, "interlaced");
  202.                 }
  203.                 if (info->flags&IS_DYNAMICMODE) {
  204.                     if (*expl != '\0')
  205.                         strcat(expl, ", ");
  206.                     strcat(expl, "dynamically loaded");
  207.                 }
  208.                 high = i;
  209.                 printf("%5d: %dx%d, ",
  210.                     i, info->width, info->height);
  211.                 if (cols == NULL)
  212.                     printf("%d", info->colors);
  213.                 else
  214.                     printf("%s", cols);
  215.                 printf(" colors ");
  216.                 if (*expl != '\0')
  217.                     printf("(%s)", expl);
  218.                 printf("\n");
  219.             }
  220.  
  221.         printf("Enter mode number (1-%d): ", high);
  222.         scanf("%d", &mode);
  223.         getchar();
  224.         printf("\n");
  225.  
  226.         if (mode < 1 || mode > GLASTMODE) {
  227.             printf("Error: Mode number out of range \n");
  228.             exit(-1);
  229.         }
  230.     }
  231.  
  232.     if (vga_hasmode(mode))
  233.         testmode(mode);
  234.     else {
  235.         printf("Error: Video mode not supported by driver\n");
  236.         exit(-1);
  237.     }
  238. }
  239.