home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1992 by Michael Davidson.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for any purpose and without fee is hereby
- * granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission
- * notice appear in supporting documentation.
- *
- * This software is provided "as is" without express or implied warranty.
- */
-
- /*
- * vesa.c - support routines for VESA compatible cards
- */
-
- #include "vdev.h"
- #include "video.h"
- #include "svga.h"
- #include "vesabios.h"
-
- #define GRAPHICS (SVGA_MODE_SUPPORTED | SVGA_GRAPHICS_MODE)
- #define TEXT (SVGA_MODE_SUPPORTED | SVGA_TEXT_MODE)
-
- #if 0
- static struct svga_mode_info vesa_standard_modes[] =
- {
- { 1024, 768, 8, 0x105, GRAPHICS },
- { 800, 600, 8, 0x103, GRAPHICS },
- { 640, 480, 8, 0x101, GRAPHICS },
- { 0, 0, 0, 0x00, 0 }
- };
- #endif
-
- static struct svga_mode_info vga_standard_modes[] =
- {
- { 320, 200, 8, 0x13, GRAPHICS },
- { 80, 25, 0, 0x03, TEXT },
- { 0, 0, 0, 0x00, 0 }
- };
-
- #define MAX_VESA_MODES 40
-
- static struct svga_mode_info vesa_modes[MAX_VESA_MODES];
-
- /*
- * special initialisation for specific cards
- */
- struct vendor_init
- {
- char *vendor;
- int (*init)();
- };
-
- #if 0
- struct vendor_init vendor_init_tab[] =
- {
- { "Orchid Technology Fahrenheit 1280", f1280_init },
- { 0, 0 }
- };
- #endif
-
- int vesa_current_bank = -1;
- int vesa_version;
-
- static int vesa_setmode();
- static void vesa_bank_switch();
-
- /*ARGSUSED*/
- int
- vesa_init(
- char *name,
- struct vdev *v
- )
- {
- char *vendor;
-
- s3_io_enable();
- ati_io_enable();
- /*
- * check whether we have a VESA bios and what version it is
- */
-
- if ((vesa_version = VESAVersion()) < 0)
- return -1;
-
- vendor = VESAVendorData();
-
- vesa_build_mode_table();
-
-
- svga_setup(v, vesa_modes, vesa_bank_switch);
-
- v->v_name = vendor;
- v->v_setmode = vesa_setmode;
-
- return 0;
- }
-
- #define COLOR_GRAPHICS (VESA_MODE_SUPPORTED|VESA_MODE_COLOR|VESA_MODE_GRAPHICS)
-
- /*
- * vesa_build_mode_table() - build a table of VESA supported modes
- */
- vesa_build_mode_table()
- {
- int i;
- unsigned short *modes;
- unsigned short bios_mode;
- VESAModeInfo *mode_info;
- struct svga_mode_info *s;
-
- modes = VESAModeTable();
- s = vesa_modes;
-
- while ((bios_mode = *modes++) != 0xffff)
- {
- if (bios_mode < 0x100)
- continue;
-
- if ((mode_info = VESABiosGetModeInfo(bios_mode)) == 0)
- continue;
-
- if ( (mode_info->attributes & COLOR_GRAPHICS) != COLOR_GRAPHICS )
- continue;
-
- if ( ! (mode_info->attributes & VESA_MODE_OPT_INFO) )
- {
- /* check to see if it's a standard mode */
- continue;
- }
- else
- {
- if (mode_info->bits_per_pixel < 8)
- continue;
-
- s->width = mode_info->x_resolution;
- s->height = mode_info->y_resolution;
- s->depth = mode_info->bits_per_pixel;
- s->bios_mode = bios_mode;
- s->attributes = GRAPHICS;
- s->scanline_length = mode_info->scanline_size;
- s->window_address = (unsigned char *)
- (mode_info->window_seg[0] << 4);
- s->window_size = mode_info->window_size * 1024;
- s->window_granularity = mode_info->window_granularity * 1024;
-
- if (s->depth > 8 && vesa_version >= 0x102)
- {
- s->red_bits = mode_info->red_bits;
- s->green_bits = mode_info->green_bits;
- s->blue_bits = mode_info->blue_bits;
- s->red_shift = mode_info->red_shift;
- s->green_shift = mode_info->green_shift;
- s->blue_shift = mode_info->blue_shift;
- }
- s++;
- }
- }
- /*
- * now add the standard VGA modes to the table
- */
- for (i = 0; vga_standard_modes[i].attributes != 0; i++)
- *s++ = vga_standard_modes[i];
- }
-
- int
- vesa_probe()
- {
- int version;
-
- ati_io_enable();
- if ((version = VESAVersion()) < 0)
- return 0;
-
- return 1;
- }
-
- /*
- * vesa_setmode()
- */
- static int
- vesa_setmode(
- int i
- )
- {
- struct svga_mode_info *s;
-
- vesa_current_bank = -1;
- s = &vesa_modes[i];
-
- if (s->bios_mode < 0x100)
- {
- VBiosSetMode(s->bios_mode | 0x80);
- if ((VBiosGetMode() & 0x7f) != s->bios_mode)
- return -1;
- }
- else
- {
- if (VESABiosSetMode(s->bios_mode) != 0)
- return -1;
- }
-
- if (s->attributes & SVGA_TEXT_MODE) /* text mode */
- {
- VBiosDisableBlink();
- VBiosSetCursorPosition(s->width, s->height);
- }
-
- /*
- * make sure start address is 0
- */
- outw(0x3d4, 0x000c);
- outw(0x3d4, 0x000d);
-
- if (s->attributes & SVGA_GRAPHICS_MODE)
- {
- switch (s->depth)
- {
- case 15:
- case 16:
- case 24:
- RGB32Shift[0] = s->red_shift;
- RGB32Shift[1] = s->green_shift;
- RGB32Shift[2] = s->blue_shift;
- RGB32Bits[0] = s->red_bits;
- RGB32Bits[1] = s->green_bits;
- RGB32Bits[2] = s->blue_bits;
- break;
-
- default:
- break;
- }
- }
- SVGAModeInfo = s;
- return 0;
- }
-
- static void
- vesa_bank_switch(
- int bank
- )
- {
- if (bank != vesa_current_bank)
- VESABiosBankSwitch(bank);
- vesa_current_bank = bank;
- }
-