home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / vg-2.03 / video / vesa.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  4.9 KB  |  249 lines

  1. /*
  2.  * Copyright (C) 1992 by Michael Davidson.
  3.  * All rights reserved.
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software
  6.  * and its documentation for any purpose and without fee is hereby
  7.  * granted, provided that the above copyright notice appear in all
  8.  * copies and that both that copyright notice and this permission
  9.  * notice appear in supporting documentation.
  10.  *
  11.  * This software is provided "as is" without express or implied warranty.
  12.  */
  13.  
  14. /*
  15.  * vesa.c    - support routines for VESA compatible cards
  16.  */
  17.  
  18. #include    "vdev.h"
  19. #include    "video.h"
  20. #include    "svga.h"
  21. #include    "vesabios.h"
  22.  
  23. #define    GRAPHICS    (SVGA_MODE_SUPPORTED | SVGA_GRAPHICS_MODE)
  24. #define    TEXT        (SVGA_MODE_SUPPORTED | SVGA_TEXT_MODE)
  25.  
  26. #if 0
  27. static struct svga_mode_info vesa_standard_modes[] =
  28. {
  29.     {    1024,    768,    8,    0x105,    GRAPHICS },
  30.     {    800,    600,    8,    0x103,    GRAPHICS },
  31.     {    640,    480,    8,    0x101,    GRAPHICS },
  32.     {    0,    0,    0,    0x00,     0        }
  33. };
  34. #endif
  35.  
  36. static struct svga_mode_info vga_standard_modes[] =
  37. {
  38.     {    320,    200,    8,    0x13,    GRAPHICS },
  39.     {    80,    25,    0,    0x03,    TEXT     },
  40.     {    0,    0,    0,    0x00,     0        }
  41. };
  42.  
  43. #define    MAX_VESA_MODES    40
  44.  
  45. static struct svga_mode_info    vesa_modes[MAX_VESA_MODES];
  46.  
  47. /*
  48.  * special initialisation for specific cards
  49.  */
  50. struct vendor_init
  51. {
  52.     char    *vendor;
  53.     int        (*init)();
  54. };
  55.  
  56. #if 0
  57. struct vendor_init vendor_init_tab[] =
  58. {
  59.     { "Orchid Technology Fahrenheit 1280",    f1280_init    },
  60.     { 0,                    0        }
  61. };
  62. #endif
  63.  
  64. int    vesa_current_bank    = -1;
  65. int    vesa_version;
  66.  
  67. static int    vesa_setmode();
  68. static void    vesa_bank_switch();
  69.  
  70. /*ARGSUSED*/
  71. int
  72. vesa_init(
  73.     char    *name,
  74.     struct vdev    *v
  75.     )
  76. {
  77.     char    *vendor;
  78.  
  79.     s3_io_enable();
  80.     ati_io_enable();
  81.     /*
  82.      * check whether we have a VESA bios and what version it is
  83.      */
  84.  
  85.     if ((vesa_version = VESAVersion()) < 0)
  86.     return -1;
  87.  
  88.     vendor    = VESAVendorData();
  89.  
  90.     vesa_build_mode_table();
  91.  
  92.  
  93.     svga_setup(v, vesa_modes, vesa_bank_switch);
  94.  
  95.     v->v_name        = vendor;
  96.     v->v_setmode    = vesa_setmode;
  97.  
  98.     return 0;
  99. }
  100.  
  101. #define    COLOR_GRAPHICS    (VESA_MODE_SUPPORTED|VESA_MODE_COLOR|VESA_MODE_GRAPHICS)
  102.  
  103. /*
  104.  * vesa_build_mode_table() - build a table of VESA supported modes
  105.  */
  106. vesa_build_mode_table()
  107. {
  108.     int                i;
  109.     unsigned short         *modes;
  110.     unsigned short        bios_mode;
  111.     VESAModeInfo        *mode_info;
  112.     struct svga_mode_info    *s;
  113.  
  114.     modes    = VESAModeTable();
  115.     s        = vesa_modes;
  116.  
  117.     while ((bios_mode = *modes++) != 0xffff)
  118.     {
  119.     if (bios_mode < 0x100)
  120.         continue;
  121.  
  122.     if ((mode_info = VESABiosGetModeInfo(bios_mode)) == 0)
  123.         continue;
  124.  
  125.     if ( (mode_info->attributes & COLOR_GRAPHICS) != COLOR_GRAPHICS )
  126.         continue;
  127.  
  128.     if ( ! (mode_info->attributes & VESA_MODE_OPT_INFO) )
  129.     {
  130.         /* check to see if it's a standard mode */
  131.         continue;
  132.     }
  133.     else
  134.     {
  135.         if (mode_info->bits_per_pixel < 8)
  136.         continue;
  137.  
  138.         s->width        = mode_info->x_resolution;
  139.         s->height        = mode_info->y_resolution;
  140.         s->depth        = mode_info->bits_per_pixel;
  141.         s->bios_mode    = bios_mode;
  142.         s->attributes    = GRAPHICS;
  143.         s->scanline_length    = mode_info->scanline_size;
  144.         s->window_address    = (unsigned char *)
  145.                     (mode_info->window_seg[0] << 4);
  146.         s->window_size    = mode_info->window_size * 1024;
  147.         s->window_granularity = mode_info->window_granularity * 1024;
  148.  
  149.         if (s->depth > 8 && vesa_version >= 0x102)
  150.         {
  151.         s->red_bits    = mode_info->red_bits;
  152.         s->green_bits    = mode_info->green_bits;
  153.         s->blue_bits    = mode_info->blue_bits;
  154.         s->red_shift    = mode_info->red_shift;
  155.         s->green_shift    = mode_info->green_shift;
  156.         s->blue_shift    = mode_info->blue_shift;
  157.         }
  158.         s++;
  159.     }
  160.     }
  161.     /*
  162.      * now add the standard VGA modes to the table
  163.      */
  164.     for (i = 0; vga_standard_modes[i].attributes != 0; i++)
  165.     *s++ = vga_standard_modes[i];
  166. }
  167.  
  168. int
  169. vesa_probe()
  170. {
  171.     int        version;
  172.  
  173.     ati_io_enable();
  174.     if ((version = VESAVersion()) < 0)
  175.     return 0;
  176.  
  177.     return 1;
  178. }
  179.  
  180. /*
  181.  * vesa_setmode()
  182.  */
  183. static int
  184. vesa_setmode(
  185.     int        i
  186.     )
  187. {
  188.     struct svga_mode_info    *s;
  189.  
  190.     vesa_current_bank =    -1;
  191.     s    = &vesa_modes[i];
  192.  
  193.     if (s->bios_mode < 0x100)
  194.     {
  195.     VBiosSetMode(s->bios_mode | 0x80);
  196.     if ((VBiosGetMode() & 0x7f) != s->bios_mode)
  197.         return -1;
  198.     }
  199.     else 
  200.     {
  201.     if (VESABiosSetMode(s->bios_mode) != 0)
  202.         return -1;
  203.     }
  204.  
  205.     if (s->attributes & SVGA_TEXT_MODE)        /* text mode */
  206.     {
  207.         VBiosDisableBlink();
  208.         VBiosSetCursorPosition(s->width, s->height);
  209.     }
  210.  
  211.     /*
  212.      * make sure start address is 0
  213.      */
  214.     outw(0x3d4, 0x000c);
  215.     outw(0x3d4, 0x000d);
  216.  
  217.     if (s->attributes & SVGA_GRAPHICS_MODE)
  218.     {
  219.     switch (s->depth)
  220.     {
  221.         case 15:
  222.         case 16:
  223.         case 24:
  224.         RGB32Shift[0]    = s->red_shift;
  225.         RGB32Shift[1]    = s->green_shift;
  226.         RGB32Shift[2]    = s->blue_shift;
  227.         RGB32Bits[0]    = s->red_bits;
  228.         RGB32Bits[1]    = s->green_bits;
  229.         RGB32Bits[2]    = s->blue_bits;
  230.         break;
  231.  
  232.         default:
  233.         break;
  234.     }
  235.     }
  236.     SVGAModeInfo    = s;
  237.     return 0;
  238. }
  239.  
  240. static void
  241. vesa_bank_switch(
  242.     int        bank
  243.     )
  244. {
  245.     if (bank != vesa_current_bank)
  246.     VESABiosBankSwitch(bank);
  247.     vesa_current_bank = bank;
  248. }
  249.