home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / SVGALIB / SVGALIB1.TAR / svgalib / demos / testlinear.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-28  |  2.3 KB  |  102 lines

  1.  
  2. /* 
  3.     Simple test program for Cirrus linear addressing/color expansion.
  4.     vgagl can take advantage of it (linear addressing).
  5. */
  6.  
  7.  
  8. #include <stdlib.h>
  9. #include <vga.h>
  10. #include <time.h>
  11. #include "../src/libvga.h"
  12.  
  13.  
  14. #define USE_LINEAR_ADDRESSING
  15. /* #define USE_BY16_ADDRESSING */
  16.  
  17.  
  18. unsigned char *vbuf;
  19.  
  20.  
  21. /* This function is Cirrus specific and has nothing to do with linear
  22.  * addressing. */
  23. void by8test() {
  24.     int i;
  25.     int startclock, diffclock;
  26.  
  27.     /* Enable extended write modes and BY8/16 addressing. */
  28.     outb(0x3ce, 0x0b);
  29.  
  30. #ifdef USE_BY16_ADDRESSING
  31.     outb(0x3cf, inb(0x3cf) | 0x16);
  32. #else
  33.     outb(0x3cf, inb(0x3cf) | 0x06);
  34. #endif
  35.     /* Set extended write mode 4. */
  36.     outb(0x3ce, 0x05);
  37.     outb(0x3cf, (inb(0x3cf) & 0xf8) | 4);
  38.  
  39.     /* Set pixel mask register (coincides with VGA plane mask register). */
  40.     outw(0x3c4, 0xff02);
  41.  
  42.     startclock = clock();
  43.     for (i = 0; i < 248; i++) {
  44.         int j;
  45.         outw(0x3ce, 0x01 + (i << 8));    /* Set foreground color. */
  46. #ifdef USE_BY16_ADDRESSING
  47.         outw(0x3ce, 0x11 + (i << 8));    /* Set high byte. */
  48.         memset(vbuf, 0xff, 640 * 480 / 16);
  49. #else
  50.         memset(vbuf, 0xff, 640 * 480 / 8);
  51. #endif
  52.     }
  53.     diffclock = clock() - startclock;
  54.     printf("Color expansion framebuffer fill speed: %dK/s\n",
  55.         640 * 480 * 248 / diffclock / 10);
  56. }
  57.  
  58.  
  59. void main( int argc, char *argv[]) {
  60.     int i;
  61.  
  62.     if (!(argc == 2 && strcmp(argv[1], "--force") == 0))
  63.         if (!(vga_getmodeinfo(G640x480x256)->flags & CAPABLE_LINEAR)) {
  64.             printf("Linear addressing not supported for this chipset.\n");
  65.             if (vga_getcurrentchipset() == CIRRUS)
  66.                 printf("(Cirrus currently disabled; specify '--force' to try (with < 16Mb RAM)).\n");
  67.             exit(1);
  68.         }
  69.     vga_init();
  70.     vga_setmode(G640x480x256);
  71.     vga_setpage(0);
  72. #ifdef USE_LINEAR_ADDRESSING    
  73.     if (vga_setlinearaddressing()) {
  74.         vga_setmode(TEXT);
  75.         printf("Could not set linear addressing.\n");
  76.         exit(-1);
  77.     }
  78. #endif
  79.     
  80.     /* Should not mess with bank register after this. */
  81.  
  82.     vbuf = vga_getgraphmem();
  83.     printf("vbuf mapped at %08x.\n", vbuf);
  84.  
  85. #ifdef USE_LINEAR_ADDRESSING
  86.     memset(vbuf, 88, 640 * 480);
  87.     sleep(1);
  88.     
  89.     memset(vbuf, 0, 640 * 480);
  90.     for (i = 0; i < 100000; i++)
  91.         *(vbuf + (rand() & 0xfffff)) = rand();
  92. #endif
  93.  
  94.     if (vga_getcurrentchipset() == CIRRUS)
  95.         /* Show the bandwidth of the extended write modes of the */
  96.         /* Cirrus chip. */
  97.         by8test();
  98.  
  99.     getchar();
  100.     vga_setmode(TEXT);
  101. }
  102.