home *** CD-ROM | disk | FTP | other *** search
-
-
- ┌──────────────────┐
- │ VGA Colors 2.0 │
- └──────────────────┘
-
-
- INTRODUCTION
- ────────────
-
- The program VGACOLS and the unit COLORS are used to obtain
- complete control over the EGA palette registers. With the
- program VGACOLS you can design your own 16 color palettes,
- and save them to file. With the procedures in COLORS you can
- get access to those stored palettes, or define new ones in
- your own program.
-
-
- SOME TECHNICAL STUFF
- ────────────────────
-
- There are 16 8-bit palette registers on the EGA displays, and
- each if these 16 registers can take on 1 of 64 values, defined by:
-
- Bit 7 Reserved
- Bit 6 Reserved
- Bit 5 Secondary Red
- Bit 4 Secondary Green
- Bit 3 Secondary Blue
- Bit 2 Primary Red
- Bit 1 Primary Green
- Bit 1 Primary Blue
-
- The primary colors have an intensity of 2/3, while the secondary
- have an intensity of 1/3. For example, a register value of $02
- will produce green, $10 will produce a dim green, and $12 will
- produce a bright green.
-
- The default color value for the 16 palette registers are:
-
- Palette register Color value Color
- ──────────────────────────────────────────────────
- $00 $00 Black
- $01 $01 Blue
- $02 $02 Green
- $03 $03 Cyan
- $04 $04 Red
- $05 $05 Magenta
- $06 $14 Brown
- $07 $07 White
- $08 $38 Dark Gray
- $09 $39 Light Blue
- $0A $3A Light Green
- $0B $3B Light Cyan
- $0C $3C Light Red
- $0D $3D Light Magenta
- $0E $3E Yellow
- $0F $3F Bright White
- ──────────────────────────────────────────────────
- Table 1.
-
-
- Each of the colors can be defined by a red, green and blue
- component, each in the range from 0 to 63.
-
- In the Turbo Pascal GRAPH unit there are some routines,
- SetPalette and SetRGBPalette, which are used to change the
- default Color values in the Palette registers, and to set the
- red, green and blue components. in text mode, however, no
- similar routines exist.
-
-
-
-
-
-
-
-
-
-
-
- ┌───────────────┐
- │ UNIT Colors │
- └───────────────┘
-
- This unit defines the routines necessary to control the color
- palettes.
-
-
-
- procedure GetTEXTPalette(PaletteReg: byte; var ColorNum: byte);
- procedure SetTEXTPalette(PaletteReg,ColorNum: byte);
- ────────────────────────────────────────────────────────────────
- These are equivalent to the TP routines GetPalette and
- SetPalette.
-
- GetTEXTPalette makes an INT $10 call, with the register entry:
-
- AL = $07
- BL = PaletteReg
-
- and will return the Color value currently in PaletteReg
-
- ColorNum = BH
-
- SetTEXTPalette also makes an INT $10 call, with the register
- entry:
-
- AL = $00
- BL = PaletteReg
- BH = ColorNum
-
- which will set the Color value in PaletteReg.
-
-
- procedure GetDACRegister(ColorNum: byte;
- var RedValue,GreenValue,BlueValue: byte);
- procedure SetDACRegister(ColorNum,RedValue,GreenValue,
- BlueValue: byte);
- ────────────────────────────────────────────────────────
- These are equivalent to the TP routines GetRGBPalette and
- SetRGBPalette.
-
- GetDACRegister makes an INT $10 call, with the register entry:
-
- AL = $15
- BX = ColorNum
-
- and returns
-
- RedValue = DH
- GreenValue= CH
- BlueValue = CL
-
-
- SetDACRegister makes an INT $10 call, with the register entry:
-
- AL = $15
- BX = ColorNum
- DH = RedValue
- CH = GreenValue
- CL = BlueValue
-
- Turbo Pascal defines the colors as:
-
- Black = 0 DarkGray = 8
- Blue = 1 LightBlue = 9
- Green = 2 LightGreen = 10
- Cyan = 3 LightCyan = 11
- Red = 4 LightRed = 12
- Magenta = 5 LightMagenta = 13
- Brown = 6 Yellow = 14
- LightGray = 7 White = 15
-
- but as can be seen in table 1, these are the register values,
- not the color values, which range from 0 to 63. So if you try
- the command
-
- SetRGBRegister(LightBlue,10,10,50);
-
- this will not give the result you would expect, since LightBlue is
- define to be $09, while the color value of light blue is $39.
-
- There are two ways to solve this:
-
- The first is to redefine the color value in the palette registers,
- and then set the RGB value of that color:
-
- SetTEXTPalette(LightBlue,LightBlue);
- SetRGBRegister(LightBlue,10,10,50);
-
- Another, (and in my opinion cleaner way) is to use the constant
- array CList defined in the Colors unit. This array contains the
- values in table 1. So in order to perform the task above, just
- give the command
-
- SetRGBRegister(CList[LightBlue],10,10,50);
-
- procedure GetColorList;
- procedure SetColorList;
- ───────────────────────
-
- The Colors unit defines:
-
- type TColor = record
- R,G,B : byte;
- end;
-
-
- var ColorList: array[0..15] of TColor;
-
- GetColorList will read the DAC registers (using GetRGBRegister)
- and store them in ColorList, while SetColorList will call
- SetRGBRegister and set the DAC registers to the values stored
- in ColorList.
-
-
- function ReadDACFile(Filename: string): boolean;
- procedure WriteDACFile(Filename: string);
- ────────────────────────────────────────────────
-
- ReadDACFile will read a color palette from the file Filename,
- and return true if the operation was successful. The values
- read will be stored in ColorList, but will NOT automatically
- be loaded. Call SetColorList to do that!
-
- WriteDACFile will write the color palette stored in ColorList
- to the file Filename.
-
-
-
-
-
-
- ┌───────────────────┐
- │ PROGRAM VGACols │
- └───────────────────┘
-
- This program lets you create and edit color palettes. The palettes
- can be stored to file and used in your own programs.
-
- When the program starts, it will display the 16 colors, and the
- RGB component values of the current color. You can switch between
- selecting the color and editing the color with the Tab key.
-
- To select a color, use the arrow keys to move, and either Return
- or Tab to select. This will bring you to bottom of the screen,
- where you can change the individual Red, Green and Blue components
- of the current color. Use the up and down arrow keys to select Red,
- Green or Blue, and the left and right arrow keys to change the value.
-
- To save the palette to file, press F2. The program will prompt you
- for a filename.
-
- To load a palette from file, press F3. The program will give you
- a list of files to choose from. The default extension of the
- palette files are .VGA, but by pressing F3 again, you can look
- for other files.
-
- Press Escape to quit the program.
-