🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #1338

Re: Setting VGA palette

#1338
From: N7YVM
Date: Mon, 07 Sep 1992 21:44
50 lines
1892 bytes
Heres a few routines in Turbo C to set the VGA 256 color mode palette
This first one is the work horse. To set the palette you need a buffer
of chars 3*256 bytes in length. Each group of 3 bytes respresents
a color of r g and b, in order of increasing index. I.E...

r0 g0 b0 r1 g1 b1 r2 g2 b2 ....   <- colors
 0  1  2  3  4  5  6  7  8        <- indexes into buffer

A good way to do this is to make buffer an array[256 of
structs { unsigned char r,g,b; }
The range of r g and b is 0-63, which means you have 262144 colors
to form a 256 color palette from. 
The second routine uses the first on to set a grey scale palette (linear).


/*
**  Sets the current VGA palette (256 colors)
**  This function sets the entire palette with
**   Int 10h, function 10h, subfunction 12h. This
**   subfunction sets the entire palette with
**   one interrupt.
**
**     Make sure buffer is at least 256*3 (768) bytes long.
*/
int VGA256_setrgbpalette(void far *buffer) {
struct REGPACK regs;
  regs.r_ax=0x1012;
  regs.r_bx=0;
  regs.r_cx=256;
  regs.r_es=FP_SEG(buffer);
  regs.r_dx=FP_OFF(buffer);
  intr(0x10,&regs);
  return 1;
  }

/* This function sets a 256 grey-scale palette
**  i.e. color 0 is black, colors increase in grey intensity until
**  color 255 which is white
*/
int VGA256_setgreyscalepalette(void) {
char palette[3*256],*p;
int i;
  p=palette;
  for(i=0; i<256; i++) {
    *p++=i>>2;
    *p++=i>>2;
    *p++=i>>2;
    }
  VGA256_setrgbpalette(palette);
  }
Technical Details
Message-ID: <27588@life.ai.mit.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!mintaka.lcs.mit.edu!ai-lab!hal.gnu.ai.mit.edu!rwed
References: <18fpg7INN15c@usenet.INS.CWRU.Edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!mintaka.lcs.mit.edu!ai-lab!hal.gnu.ai.mit.edu!rwed
From: rwed@hal.gnu.ai.mit.edu (N7YVM)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Setting VGA palette
Message-ID: <27588@life.ai.mit.edu>
Date: 7 Sep 92 21:44:40 GMT
References: <18fpg7INN15c@usenet.INS.CWRU.Edu>
Sender: news@ai.mit.edu
Organization: /etc/organization
Lines: 50