home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / SVGALIB / SVGALIB1.TAR / svgalib / src / vgapal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-29  |  4.2 KB  |  162 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. /* Converted to especially ugly code and seriously hacked for Mach32: */
  11. /* M. Weller in 1994                                                  */
  12. #include <stdlib.h>
  13.  
  14. #include "vga.h"
  15. #include "libvga.h"
  16. #include "driver.h"
  17.  
  18.  
  19. int vga_setpalette(int index, int red, int green, int blue)
  20. {
  21.     if ((__svgalib_chipset == MACH32) && SVGAMODE(CM))
  22.     {
  23.     /* Actually the same but we are in 8514 mode and the dac
  24.        does not respond to the VGA circuitry anymore... */
  25.     port_out(index, PEL8514_IW); 
  26.     __vga_delay();
  27.     port_out(red, PEL8514_D);
  28.     __vga_delay();
  29.     port_out(green, PEL8514_D);
  30.     /* Uh yes.. and I didn't find a way to wait for hsync, so... */
  31.     __vga_delay();
  32.     port_out(blue, PEL8514_D);
  33.     return 0;
  34.     }
  35.     /* select palette register */
  36.     port_out(index, PEL_IW); 
  37.  
  38.     /* write RGB components */
  39.     __vga_delay();
  40.     port_out(red, PEL_D);
  41.     __vga_delay();
  42.     port_out(green, PEL_D);
  43.     if (SCREENON) {         /* writing the `blue' register will   */
  44.       while (!(inb(0x3da) & 1)); /* load the dac. Waiting for vertical */
  45.       while (inb(0x3da) & 1);    /* or horizontal retrace will load    */
  46.     } else             /* the dac without disturbances       */    
  47.       __vga_delay();
  48.     port_out(blue, PEL_D);
  49.     return 0;
  50. }
  51.  
  52.  
  53. int vga_getpalette(int index, int *red, int *green, int *blue)
  54. {
  55.     if ((__svgalib_chipset == MACH32) && SVGAMODE(CM))
  56.     {
  57.     /* Actually the same but we are in 8514 mode and the dac
  58.        does not respond to the VGA circuitry anymore... */
  59.     port_out(index, PEL8514_IR); 
  60.         __vga_delay();
  61.         *red = (int) port_in(PEL8514_D);
  62.         __vga_delay();
  63.         *green = (int) port_in(PEL8514_D);
  64.         __vga_delay();
  65.         *blue = (int) port_in(PEL8514_D);
  66.     }
  67.     /* select palette register */
  68.     port_out(index, PEL_IR);
  69.  
  70.     /* read RGB components */
  71.     __vga_delay();
  72.     *red = (int) port_in(PEL_D);
  73.     __vga_delay();
  74.     *green = (int) port_in(PEL_D);
  75.     __vga_delay();
  76.     *blue = (int) port_in(PEL_D);
  77.  
  78.     return 0;  
  79. }
  80.  
  81.  
  82. int vga_setpalvec(int start, int num, int *pal)
  83. {
  84.     int j;
  85.  
  86.     /* select palette register */
  87.     /* See above.. */
  88.     if ((__svgalib_chipset == MACH32) && SVGAMODE(CM))
  89.     {
  90.     port_out(start, PEL8514_IW); 
  91.     for(j = 0; j < num; j++)
  92.         {
  93.         if ((__svgalib_chipset == MACH32) && SVGAMODE(CM))
  94.         {
  95.         __vga_delay();
  96.         port_out(*(pal++), PEL8514_D);
  97.         __vga_delay();
  98.         port_out(*(pal++), PEL8514_D);
  99.         /* Uh yes.. and I didn't find a way to wait for hsync, so... */
  100.         __vga_delay();
  101.         port_out(*(pal++), PEL8514_D);
  102.         }
  103.         }
  104.     return j;
  105.     }
  106.     port_out(start, PEL_IW);
  107.  
  108.     for(j = 0; j < num; j++) {
  109.         __vga_delay();
  110.         port_out(*(pal++), PEL_D);
  111.         __vga_delay();
  112.         port_out(*(pal++), PEL_D);
  113.     if (SCREENON) {             /* writing the `blue' register will   */
  114.       while (!(inb(0x3da) & 1)); /* load the dac. Waiting for vertical */
  115.       while (inb(0x3da) & 1);    /* or horizontal retrace will load    */
  116.      } else                 /* the dac without disturbances       */    
  117.       __vga_delay();
  118.         port_out(*(pal++), PEL_D);
  119.     }
  120.  
  121.     return j;
  122. }
  123.  
  124.  
  125. int vga_getpalvec(int start, int num, int *pal)
  126. {
  127.     int j;
  128.  
  129.     if ((__svgalib_chipset == MACH32) && SVGAMODE(CM))
  130.     {
  131.     /* Actually the same but we are in 8514 mode and the dac
  132.        does not respond to the VGA circuitry anymore... */
  133.     port_out(start, PEL8514_IR); 
  134.         for(j = 0; j < num; j++) {
  135.             __vga_delay();
  136.             *(pal++) = (int) port_in(PEL8514_D);
  137.             __vga_delay();
  138.             *(pal++) = (int) port_in(PEL8514_D);
  139.             __vga_delay();
  140.             *(pal++) = (int) port_in(PEL8514_D);
  141.         }
  142.     return j;
  143.     }
  144.  
  145.     /* select palette register */
  146.     port_out(start, PEL_IR);
  147.  
  148.     for(j = 0; j < num; j++) {
  149.         __vga_delay();
  150.         *(pal++) = (int) port_in(PEL_D);
  151.         __vga_delay();
  152.         *(pal++) = (int) port_in(PEL_D);
  153.         __vga_delay();
  154.         *(pal++) = (int) port_in(PEL_D);
  155.     }
  156.  
  157.     return j;
  158. }
  159.  
  160.  
  161.  
  162.