home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / SVGALIB / SVGALIB1.TAR / svgalib / src / vgadrv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-11  |  7.7 KB  |  288 lines

  1. /* VGAlib version 1.2 - (c) 1993 Tommy Frandsen            */
  2. /*                                   */
  3. /* This library is free software; you can redistribute it and/or   */
  4. /* modify it without any restrictions. This library is distributed */
  5. /* in the hope that it will be useful, but without any warranty.   */
  6.  
  7. /* Multi-chipset support Copyright 1993 Harm Hanemaayer */
  8. /* partially copyrighted (C) 1993 by Hartmut Schirmer */
  9.  
  10.  
  11. #include <stdlib.h>    /* for NULL */
  12. #include "vga.h"
  13. #include "libvga.h"
  14. #include "driver.h"
  15.  
  16. /* BIOS mode 0Dh - 320x200x16 */
  17. static const unsigned char g320x200x16_regs[60] = {
  18.   0x2D,0x27,0x28,0x90,0x2B,0x80,0xBF,0x1F,0x00,0xC0,0x00,0x00, 
  19.   0x00,0x00,0x00,0x00,0x9C,0x8E,0x8F,0x14,0x00,0x96,0xB9,0xE3, 
  20.   0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B, 
  21.   0x0C,0x0D,0x0E,0x0F,0x01,0x00,0x0F,0x00,0x00, 
  22.   0x00,0x0F,0x00,0x20,0x00,0x00,0x05,0x0F,0xFF, 
  23.   0x03,0x09,0x0F,0x00,0x06, 
  24.   0x63
  25. };
  26.  
  27. /* BIOS mode 0Eh - 640x200x16 */
  28. static const unsigned char g640x200x16_regs[60] = {
  29.   0x5F,0x4F,0x50,0x82,0x54,0x80,0xBF,0x1F,0x00,0xC0,0x00,0x00, 
  30.   0x00,0x00,0x00,0x00,0x9C,0x8E,0x8F,0x28,0x00,0x96,0xB9,0xE3, 
  31.   0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B, 
  32.   0x0C,0x0D,0x0E,0x0F,0x01,0x00,0x0F,0x00,0x00, 
  33.   0x00,0x0F,0x00,0x20,0x00,0x00,0x05,0x0F,0xFF, 
  34.   0x03,0x01,0x0F,0x00,0x06, 
  35.   0x63
  36. };
  37.  
  38. /* BIOS mode 10h - 640x350x16 */
  39. static const unsigned char g640x350x16_regs[60] = {
  40.   0x5F,0x4F,0x50,0x82,0x54,0x80,0xBF,0x1F,0x00,0x40,0x00,0x00, 
  41.   0x00,0x00,0x00,0x00,0x83,0x85,0x5D,0x28,0x0F,0x63,0xBA,0xE3, 
  42.   0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B, 
  43.   0x0C,0x0D,0x0E,0x0F,0x01,0x00,0x0F,0x00,0x00, 
  44.   0x00,0x0F,0x00,0x20,0x00,0x00,0x05,0x0F,0xFF, 
  45.   0x03,0x01,0x0F,0x00,0x06, 
  46.   0xA3
  47. };
  48.  
  49. /* BIOS mode 12h - 640x480x16 */
  50. static const unsigned char g640x480x16_regs[60] = {
  51.   0x5F,0x4F,0x50,0x82,0x54,0x80,0x0B,0x3E,0x00,0x40,0x00,0x00,
  52.   0x00,0x00,0x00,0x00,0xEA,0x8C,0xDF,0x28,0x00,0xE7,0x04,0xE3,
  53.   0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,
  54.   0x0C,0x0D,0x0E,0x0F,0x01,0x00,0x0F,0x00,0x00,
  55.   0x00,0x0F,0x00,0x20,0x00,0x00,0x05,0x0F,0xFF,
  56.   0x03,0x01,0x0F,0x00,0x06,
  57.   0xE3
  58. };
  59.  
  60. /* BIOS mode 13h - 320x200x256 */
  61. static const unsigned char g320x200x256_regs[60] = {
  62.   0x5F,0x4F,0x50,0x82,0x54,0x80,0xBF,0x1F,0x00,0x41,0x00,0x00, 
  63.   0x00,0x00,0x00,0x00,0x9C,0x8E,0x8F,0x28,0x40,0x96,0xB9,0xA3, 
  64.   0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B, 
  65.   0x0C,0x0D,0x0E,0x0F,0x41,0x00,0x0F,0x00,0x00, 
  66.   0x00,0x00,0x00,0x00,0x00,0x40,0x05,0x0F,0xFF, 
  67.   0x03,0x01,0x0F,0x00,0x0E, 
  68.   0x63
  69. };
  70.  
  71. /* non-BIOS mode - 320x240x256 */
  72. static const unsigned char g320x240x256_regs[60] = {
  73.   0x5F,0x4F,0x50,0x82,0x54,0x80,0x0D,0x3E,0x00,0x41,0x00,0x00, 
  74.   0x00,0x00,0x00,0x00,0xEA,0xAC,0xDF,0x28,0x00,0xE7,0x06,0xE3, 
  75.   0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B, 
  76.   0x0C,0x0D,0x0E,0x0F,0x41,0x00,0x0F,0x00,0x00, 
  77.   0x00,0x00,0x00,0x00,0x00,0x40,0x05,0x0F,0xFF, 
  78.   0x03,0x01,0x0F,0x00,0x06, 
  79.   0xE3
  80. };
  81.  
  82. /* non-BIOS mode - 320x400x256 */
  83. static const unsigned char g320x400x256_regs[60] = {
  84.   0x5F,0x4F,0x50,0x82,0x54,0x80,0xBF,0x1F,0x00,0x40,0x00,0x00, 
  85.   0x00,0x00,0x00,0x00,0x9C,0x8E,0x8F,0x28,0x00,0x96,0xB9,0xE3, 
  86.   0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B, 
  87.   0x0C,0x0D,0x0E,0x0F,0x41,0x00,0x0F,0x00,0x00, 
  88.   0x00,0x00,0x00,0x00,0x00,0x40,0x05,0x0F,0xFF, 
  89.   0x03,0x01,0x0F,0x00,0x06, 
  90.   0x63
  91. };
  92.  
  93. /* non-BIOS mode - 360x480x256 */
  94. static const unsigned char g360x480x256_regs[60] = {
  95.   0x6B,0x59,0x5A,0x8E,0x5E,0x8A,0x0D,0x3E,0x00,0x40,0x00,0x00, 
  96.   0x00,0x00,0x00,0x00,0xEA,0xAC,0xDF,0x2D,0x00,0xE7,0x06,0xE3, 
  97.   0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B, 
  98.   0x0C,0x0D,0x0E,0x0F,0x41,0x00,0x0F,0x00,0x00, 
  99.   0x00,0x00,0x00,0x00,0x00,0x40,0x05,0x0F,0xFF, 
  100.   0x03,0x01,0x0F,0x00,0x06, 
  101.   0xE7
  102. };
  103.  
  104. /* monochrome mode based on BIOS mode 12h - 640x480x2 */
  105. #define g640x480x2_regs g640x480x16_regs
  106.  
  107. /* non BIOS mode - 720x348x2 based on mode 10h */
  108. static const unsigned char g720x348x2_regs[60] = {
  109.   0x6B,0x59,0x5A,0x8E,0x5E,0x8A,0xBF,0x1F,0x00,0x40,0x00,0x00,
  110.   0x00,0x00,0x00,0x00,0x83,0x85,0x5D,0x2D,0x0F,0x63,0xBA,0xE3,
  111.   0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,
  112.   0x0C,0x0D,0x0E,0x0F,0x01,0x00,0x0F,0x00,0x00,
  113.   0x00,0x0F,0x00,0x20,0x00,0x00,0x05,0x0F,0xFF,
  114.   0x03,0x01,0x0F,0x00,0x06,
  115.   0xA7
  116. };
  117.  
  118.  
  119. /* Mode table */
  120. static ModeTable vga_modes[] = {
  121.         OneModeEntry(640x480x2),
  122.     OneModeEntry(720x348x2),
  123.     OneModeEntry(320x200x16),
  124.     OneModeEntry(640x200x16),
  125.     OneModeEntry(640x350x16),
  126.         OneModeEntry(640x480x16),
  127.     OneModeEntry(320x200x256),
  128.     OneModeEntry(320x240x256),
  129.     OneModeEntry(320x400x256),
  130.     OneModeEntry(360x480x256),
  131. #ifdef G720x350x16
  132.     OneModeEntry(720x350x16).
  133. #endif
  134.     END_OF_MODE_TABLE
  135. };
  136.  
  137.  
  138. /* Fill in chipset-specific modeinfo */
  139.  
  140. static void getmodeinfo( int mode, vga_modeinfo *modeinfo ) {
  141.     if (modeinfo->bytesperpixel == 1) {    /* 320x200x256 linear mode */
  142.         modeinfo->maxpixels = 65536;
  143.         modeinfo->startaddressrange = 0xffff;
  144.     }
  145.     else
  146.         switch (modeinfo->colors) {
  147.         case 16 :    /* 4-plane 16 color mode */
  148.             modeinfo->maxpixels = 65536 * 8;
  149.             modeinfo->startaddressrange = 0x7ffff;
  150.             break;
  151.         case 256 :    /* 4-plane 256 color mode */
  152.             modeinfo->maxpixels = 65536 * 4;
  153.             modeinfo->startaddressrange = 0x3ffff;
  154.             break;
  155.         }
  156.     modeinfo->maxlogicalwidth = 2040;
  157.     modeinfo->haveblit = 0;
  158.     modeinfo->flags &= ~(IS_INTERLACED | HAVE_RWPAGE);
  159. }
  160.  
  161. static int nothing() { return 0; }
  162.  
  163.  
  164. /* Return nonzero if mode available */
  165.  
  166. static int modeavailable( int mode ) {
  167.     const unsigned char *regs;
  168.  
  169.     regs = LOOKUPMODE(vga_modes, mode);
  170.     if (regs != NULL && regs != DISABLE_MODE)
  171.       return STDVGADRV;
  172.     return 0;
  173. }
  174.  
  175.  
  176. /* Set a mode */
  177.  
  178. static int lastmode;
  179.  
  180. static int setmode( int mode, int prv_mode )   {
  181. /* standard VGA driver: setmode */
  182.     const unsigned char *regs;
  183.  
  184.     if (mode == TEXT)
  185.         return 0;    /* Do nothing. */
  186.  
  187.     regs = LOOKUPMODE(vga_modes, mode);
  188.     if (regs == NULL || regs == DISABLE_MODE)
  189.         return 1;
  190.     lastmode = mode;
  191.     __vga_setregs(regs);
  192.     return 0;
  193. }
  194.  
  195.  
  196. /* Set display start */
  197.  
  198. static int setdisplaystart( int address ) {
  199.     vga_modeinfo *modeinfo;
  200.     modeinfo = vga_getmodeinfo(lastmode);
  201.     if (modeinfo->bytesperpixel == 0)    /* not 320x200x256 linear */
  202.         switch (modeinfo->colors) {
  203.         case 16 :    /* planar 16-color mode */
  204.             inb(0x3da);
  205.             outb(0x3c0, 0x13 + 0x20);
  206.             outb(0x3c0, (inb(0x3c1) & 0xf0) | (address & 7));
  207.                 /* write sa0-2 to bits 0-2 */
  208.             address >>= 3;
  209.             break;
  210.         case 256 :    /* planar 256-color mode */
  211.             inb(0x3da);
  212.             outb(0x3c0, 0x13 + 0x20);
  213.             outb(0x3c0, (inb(0x3c1) & 0xf0) | ((address & 3) << 1));
  214.                 /* write sa0-1 to bits 1-2 */
  215.             address >>= 2;
  216.             break;
  217.         }
  218.     outw(0x3d4, 0x0d + (address & 0x00ff) * 256);        /* sa0-sa7 */
  219.     outw(0x3d4, 0x0c + (address & 0xff00));            /* sa8-sa15 */
  220.  
  221.     return 0;
  222. }
  223.  
  224. static int setlogicalwidth( int width ) {
  225.     outw(0x3d4, 0x13 + (width >> 3) * 256);    /* lw3-lw11 */
  226.  
  227.     return 0;
  228. }
  229.  
  230. static int vgadrv_init( int, int, int );
  231.  
  232. static int vga_test()
  233. {
  234.     unsigned char save, back;
  235.  
  236.     /* Check if a DAC is present */
  237.     save = inb(PEL_IW);
  238.     __vga_delay();
  239.     outb(PEL_IW, ~save);
  240.     __vga_delay();
  241.     back = inb(PEL_IW);
  242.     __vga_delay();
  243.     outb(PEL_IW, save);
  244.     save = ~save;
  245.     if (back == save) {
  246.         vgadrv_init(0,0,0);
  247.         return 1;
  248.     }
  249.     return 0;
  250. }
  251.  
  252.  
  253. DriverSpecs vga_driverspecs = {        /* standard VGA */
  254.     nothing,
  255.     nothing,
  256.     nothing, /* unlock */
  257.     nothing, /* lock */
  258.     vga_test,
  259.     vgadrv_init,
  260.     nothing, /* setpage */
  261.     nothing, /* setrdpage */
  262.     nothing, /* setwrpage */
  263.     setmode,
  264.     modeavailable,
  265.     setdisplaystart,
  266.     setlogicalwidth,
  267.     getmodeinfo,
  268.     0,    /* bitblt */
  269.     0,    /* imageblt */
  270.     0,    /* fillblt */
  271.     0,    /* hlinelistblt */
  272.     0,    /* bltwait */
  273.     0,    /* extset */
  274.     0,
  275.     0,    /* linear */
  276.     NULL    /* accelspecs */
  277. }; 
  278.  
  279. /* Initialize chipset (called after detection) */
  280.  
  281. static int vgadrv_init( int force, int par1, int par2) {
  282.     if (__svgalib_driver_report)
  283.         printf("Using VGA driver.\n");
  284.     driverspecs = &vga_driverspecs;
  285.  
  286.     return 0;
  287. }
  288.