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

  1. /*
  2.  * Copyright (C) 1990-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.  * vga.c    - support routines for generic IBM VGA
  16.  */
  17.  
  18. #include    "video.h"
  19. #include    "vdev.h"
  20. #include    "vga.h"
  21.  
  22. /*
  23.  * table of video modes supported for generic VGA
  24.  */
  25. static vmode_t vga_modes[] =
  26. {
  27.     {    320, 200,  8, V_MODE_SUPPORTED | V_GRAPHICS_MODE    },
  28.     {     80,  25,  0, V_MODE_SUPPORTED | V_TEXT_MODE        },
  29.     {      0,   0,  0, 0                        }
  30. };
  31.  
  32. static int vga_bios_mode[] =
  33. {
  34.     0x13,
  35.     0x03,
  36.     0x00
  37. };
  38.  
  39. static int        vga_bios_initial_mode    = -1;
  40. static vmode_t        *vga_mode;
  41. static unsigned char    *VGAGraphicsAddress;
  42. static unsigned char    *VGATextAddress;
  43.  
  44. /*
  45.  * vga_reset()
  46.  */
  47. static void
  48. vga_reset()
  49. {
  50.     if (vga_bios_initial_mode != -1)
  51.     VBiosSetMode(vga_bios_initial_mode);
  52. }
  53.  
  54. /*
  55.  * vga_setmode()
  56.  */
  57. static int
  58. vga_setmode(
  59.     int        i
  60.     )
  61. {
  62.     vmode_t    *m;
  63.  
  64.     m    = &vga_modes[i];
  65.  
  66.     VBiosSetMode(vga_bios_mode[i] | 0x80);
  67.     if ((VBiosGetMode() & 0x7f) != vga_bios_mode[i])
  68.     return -1;
  69.  
  70.     if (m->depth == 0)        /* text mode */
  71.     {
  72.     VBiosDisableBlink();
  73.     VBiosSetCursorPosition(m->width, m->height);
  74.     }
  75.     vga_mode = m;
  76.     return 0;
  77. }
  78.  
  79. /*
  80.  * vga_setpalette()
  81.  */
  82. static void
  83. vga_setpalette(
  84.     color_t    *colormap,
  85.     int        ncolors
  86.     )
  87. {
  88.     int     i;
  89.  
  90.     inb(0x3da);
  91.     for (i = 0; i < 16; i++)
  92.     {
  93.     outb(0x3c0, i);
  94.     outb(0x3c0, i);
  95.     }
  96.  
  97.     inb(0x3da);
  98.     outb(0x3c8, 0);
  99.     while (--ncolors >= 0)
  100.     {
  101.     outb(0x3c9, RGB8Lookup[0][colormap->red] >> 2);
  102.     outb(0x3c9, RGB8Lookup[1][colormap->green] >> 2);
  103.     outb(0x3c9, RGB8Lookup[2][colormap->blue] >> 2);
  104.     colormap++;
  105.     }
  106.     outb(0x3c0, 0x20);
  107. }
  108.  
  109. static void
  110. vga_putpixels8(
  111.     int        x,
  112.     int        y,
  113.     unsigned char    *pixels,
  114.     int        npixels
  115.     )
  116. {
  117.     unsigned    offset;
  118.  
  119.     offset = (long)y * vga_mode->width + x;
  120.  
  121.     memcpy(VGAGraphicsAddress + offset, pixels, npixels);
  122. }
  123.  
  124. static void
  125. vga_putpixels24(
  126.     int        x,
  127.     int        y,
  128.     unsigned char    *pixels,
  129.     int        npixels
  130.     )
  131. {
  132.     unsigned    offset;
  133.  
  134.     offset = (long)y * vga_mode->width + x;
  135.  
  136.     CopyPixels24to8(pixels, VGAGraphicsAddress + offset, npixels, VPixelLookup);
  137. }
  138.  
  139. /*
  140.  * vga_puttext()
  141.  */
  142. static void
  143. vga_puttext(
  144.     int            x,
  145.     int            y,
  146.     register char    *buf,
  147.     int            nbytes
  148.     )
  149. {
  150.     memcpy(VGATextAddress + ((y * vga_mode->width + x) * 2), buf, nbytes);
  151. }
  152.  
  153.  
  154. static void
  155. vga_clear(
  156.     int        bg
  157.     )
  158. {
  159.     int        n;
  160.  
  161.     n    = vga_mode->width * vga_mode->height;
  162.  
  163.     if (vga_mode->depth == 0)    /* text mode    */
  164.     memset(VGATextAddress, bg | (bg << 4), n * 2);
  165.     else
  166.     memset(VGAGraphicsAddress, bg, n);
  167. }
  168.  
  169. /*
  170.  * vga_init()    - one time initialisation
  171.  */
  172. /*ARGSUSED*/
  173. int
  174. vga_init(
  175.     char    *name,
  176.     struct vdev *v
  177.     )
  178. {
  179.     v->v_name        = "VGA";
  180.     v->v_modes        = vga_modes;
  181.     v->v_init        = vga_init;
  182.     v->v_reset        = vga_reset;
  183.     v->v_setmode    = vga_setmode;
  184.     v->v_setpalette    = vga_setpalette;
  185.     v->v_clear        = vga_clear;
  186.     v->v_putpixels8    = vga_putpixels8;
  187.     v->v_putpixels24    = vga_putpixels24;
  188.     v->v_puttext    = vga_puttext;
  189.  
  190.     VGAGraphicsAddress    = (unsigned char *) 0xA0000;
  191.     VGATextAddress    = (unsigned char *) 0xB8000;
  192.  
  193.     vga_bios_initial_mode    = VBiosGetMode();
  194.  
  195.     return 0;
  196. }
  197.  
  198. int
  199. vga_probe()
  200. {
  201.     return 0;
  202. }
  203.