home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / msdos / programm / 9136 < prev    next >
Encoding:
Text File  |  1992-09-08  |  1.8 KB  |  62 lines

  1. Path: sparky!uunet!olivea!mintaka.lcs.mit.edu!ai-lab!hal.gnu.ai.mit.edu!rwed
  2. From: rwed@hal.gnu.ai.mit.edu (N7YVM)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: Re: Setting VGA palette
  5. Message-ID: <27588@life.ai.mit.edu>
  6. Date: 7 Sep 92 21:44:40 GMT
  7. References: <18fpg7INN15c@usenet.INS.CWRU.Edu>
  8. Sender: news@ai.mit.edu
  9. Organization: /etc/organization
  10. Lines: 50
  11.  
  12. Heres a few routines in Turbo C to set the VGA 256 color mode palette
  13. This first one is the work horse. To set the palette you need a buffer
  14. of chars 3*256 bytes in length. Each group of 3 bytes respresents
  15. a color of r g and b, in order of increasing index. I.E...
  16.  
  17. r0 g0 b0 r1 g1 b1 r2 g2 b2 ....   <- colors
  18.  0  1  2  3  4  5  6  7  8        <- indexes into buffer
  19.  
  20. A good way to do this is to make buffer an array[256 of
  21. structs { unsigned char r,g,b; }
  22. The range of r g and b is 0-63, which means you have 262144 colors
  23. to form a 256 color palette from. 
  24. The second routine uses the first on to set a grey scale palette (linear).
  25.  
  26.  
  27. /*
  28. **  Sets the current VGA palette (256 colors)
  29. **  This function sets the entire palette with
  30. **   Int 10h, function 10h, subfunction 12h. This
  31. **   subfunction sets the entire palette with
  32. **   one interrupt.
  33. **
  34. **     Make sure buffer is at least 256*3 (768) bytes long.
  35. */
  36. int VGA256_setrgbpalette(void far *buffer) {
  37. struct REGPACK regs;
  38.   regs.r_ax=0x1012;
  39.   regs.r_bx=0;
  40.   regs.r_cx=256;
  41.   regs.r_es=FP_SEG(buffer);
  42.   regs.r_dx=FP_OFF(buffer);
  43.   intr(0x10,®s);
  44.   return 1;
  45.   }
  46.  
  47. /* This function sets a 256 grey-scale palette
  48. **  i.e. color 0 is black, colors increase in grey intensity until
  49. **  color 255 which is white
  50. */
  51. int VGA256_setgreyscalepalette(void) {
  52. char palette[3*256],*p;
  53. int i;
  54.   p=palette;
  55.   for(i=0; i<256; i++) {
  56.     *p++=i>>2;
  57.     *p++=i>>2;
  58.     *p++=i>>2;
  59.     }
  60.   VGA256_setrgbpalette(palette);
  61.   }
  62.