home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cutting-Edge 3D Game Programming with C++
/
CE3DC++.ISO
/
BOOK
/
CHAP03
/
PALSHOW.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-15
|
2KB
|
85 lines
//
// File name: PalShow.CPP
//
// Description: A simple program designed to display the palette
//
//
// Author: John De Goes
//
// Project: Cutting Edge 3D Game Programming
//
// ------------------------------------------------------------
// | Global headers: |
// ------------------------------------------------------------
#include <Dos.H>
#include <Time.H>
#include <Math.H>
#include <Stdio.H>
#include <Assert.H>
#include <Conio.H>
#include <Stdlib.H>
#include <Iostream.H>
// ------------------------------------------------------------
// | Local headers: |
// ------------------------------------------------------------
#include "32bit.HPP"
void SetPalReg ( long Index, char Red, char Green, char Blue )
{
// Sets the palette index Index to the specified RGB value:
REGS Regs;
Regs.w.ax = 0x1010;
Regs.x.ebx = Index;
Regs.h.ch = Red;
Regs.h.cl = Green;
Regs.h.dh = Blue;
int386 ( 0x10, &Regs, &Regs );
}
// Sets the palette to shades of gray
void SetPalette ()
{
short unsigned int Color1, Color2, Color3;
for (short unsigned int Index = 0; Index < 256; Index++)
{
// Update three colors:
Color1 = ( unsigned short ) ( Index >> 2 );
Color2 = ( unsigned short ) ( Index >> 2 );
Color3 = ( unsigned short ) ( Index >> 2 );
SetPalReg ( Index, Color1, Color2, Color3 );
}
}
// Program entry:
void main ()
{
// Create a pointer to video memory:
unsigned char *ScreenPtr = VideoAddress ();
long X, Y, Color, Cy, YIndex;
// Set the video mode to 13h:
SetVideo ( 0x13 );
// Set the palette:
SetPalette ();
for ( Y = 0; Y < 200; Y++ )
{
YIndex = Y * 320;
Cy = long ( ( float ( Y ) / ( 200.0F / 16.0F ) ) ) * 16;
for ( X = 0; X < 320; X++ )
{
Color = Cy + long ( ( float ( X ) / ( 320.0F / 16.0F ) ) );
ScreenPtr [ YIndex + X ] = ( unsigned char ) Color;
}
}
getch ();
// Set the video mode to 03h:
SetVideo ( 0x03 );
}