home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / HTMIX20.ZIP / VGACOLS.ZIP / VGACOLS.DOC < prev    next >
Encoding:
Text File  |  1992-07-14  |  8.3 KB  |  241 lines

  1.  
  2.  
  3.                            ┌──────────────────┐
  4.                            │  VGA Colors 2.0  │
  5.                            └──────────────────┘
  6.  
  7.  
  8.          INTRODUCTION
  9.          ────────────
  10.  
  11.          The program VGACOLS and the unit COLORS are used to obtain
  12.          complete control over the EGA palette registers. With the
  13.          program VGACOLS you can design your own 16 color palettes,
  14.          and save them to file. With the procedures in COLORS you can
  15.          get access to those stored palettes, or define new ones in
  16.          your own program.
  17.  
  18.  
  19.          SOME TECHNICAL STUFF
  20.          ────────────────────
  21.  
  22.          There are 16 8-bit palette registers on the EGA displays, and
  23.          each if these 16 registers can take on 1 of 64 values, defined by:
  24.  
  25.                  Bit 7  Reserved
  26.                  Bit 6  Reserved
  27.                  Bit 5  Secondary Red
  28.                  Bit 4  Secondary Green
  29.                  Bit 3  Secondary Blue
  30.                  Bit 2  Primary Red
  31.                  Bit 1  Primary Green
  32.                  Bit 1  Primary Blue
  33.  
  34.          The primary colors have an intensity of 2/3, while the secondary
  35.          have an intensity of 1/3. For example, a register value of $02
  36.          will produce green, $10 will produce a dim green, and $12 will
  37.          produce a bright green.
  38.  
  39.          The default color value for the 16 palette registers are:
  40.  
  41.          Palette register     Color value     Color
  42.          ──────────────────────────────────────────────────
  43.               $00                $00          Black
  44.               $01                $01          Blue
  45.               $02                $02          Green
  46.               $03                $03          Cyan
  47.               $04                $04          Red
  48.               $05                $05          Magenta
  49.               $06                $14          Brown
  50.               $07                $07          White
  51.               $08                $38          Dark Gray
  52.               $09                $39          Light Blue
  53.               $0A                $3A          Light Green
  54.               $0B                $3B          Light Cyan
  55.               $0C                $3C          Light Red
  56.               $0D                $3D          Light Magenta
  57.               $0E                $3E          Yellow
  58.               $0F                $3F          Bright White
  59.          ──────────────────────────────────────────────────
  60.          Table 1.
  61.  
  62.  
  63.          Each of the colors can be defined by a red, green and blue
  64.          component, each in the range from 0 to 63.
  65.  
  66.          In the Turbo Pascal GRAPH unit there are some routines,
  67.          SetPalette and SetRGBPalette, which are used to change the
  68.          default Color values in the Palette registers, and to set the
  69.          red, green and blue components. in text mode, however, no
  70.          similar routines exist.
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.          ┌───────────────┐
  83.          │  UNIT Colors  │
  84.          └───────────────┘
  85.  
  86.          This unit defines the routines necessary to control the color
  87.          palettes.
  88.  
  89.  
  90.  
  91.          procedure GetTEXTPalette(PaletteReg: byte;  var ColorNum: byte);
  92.          procedure SetTEXTPalette(PaletteReg,ColorNum: byte);
  93.          ────────────────────────────────────────────────────────────────
  94.            These are equivalent to the TP routines GetPalette and
  95.            SetPalette.
  96.  
  97.            GetTEXTPalette makes an INT $10 call, with the register entry:
  98.  
  99.              AL = $07
  100.              BL = PaletteReg
  101.  
  102.            and will return the Color value currently in PaletteReg
  103.  
  104.              ColorNum = BH
  105.  
  106.            SetTEXTPalette also makes an INT $10 call, with the register
  107.            entry:
  108.  
  109.              AL = $00
  110.              BL = PaletteReg
  111.              BH = ColorNum
  112.  
  113.            which will set the Color value in PaletteReg.
  114.  
  115.  
  116.          procedure GetDACRegister(ColorNum: byte;
  117.                         var RedValue,GreenValue,BlueValue: byte);
  118.          procedure SetDACRegister(ColorNum,RedValue,GreenValue,
  119.                                   BlueValue: byte);
  120.          ────────────────────────────────────────────────────────
  121.            These are equivalent to the TP routines GetRGBPalette and
  122.            SetRGBPalette.
  123.  
  124.            GetDACRegister makes an INT $10 call, with the register entry:
  125.  
  126.              AL = $15
  127.              BX = ColorNum
  128.  
  129.            and returns
  130.  
  131.              RedValue  = DH
  132.              GreenValue= CH
  133.              BlueValue = CL
  134.  
  135.  
  136.            SetDACRegister makes an INT $10 call, with the register entry:
  137.  
  138.              AL = $15
  139.              BX = ColorNum
  140.              DH = RedValue
  141.              CH = GreenValue
  142.              CL = BlueValue
  143.  
  144.          Turbo Pascal defines the colors as:
  145.  
  146.            Black     = 0   DarkGray     =  8
  147.            Blue      = 1   LightBlue    =  9
  148.            Green     = 2   LightGreen   = 10
  149.            Cyan      = 3   LightCyan    = 11
  150.            Red       = 4   LightRed     = 12
  151.            Magenta   = 5   LightMagenta = 13
  152.            Brown     = 6   Yellow       = 14
  153.            LightGray = 7   White        = 15
  154.  
  155.          but as can be seen in table 1, these are the register values,
  156.          not the color values, which range from 0 to 63. So if you try
  157.          the command
  158.  
  159.          SetRGBRegister(LightBlue,10,10,50);
  160.  
  161.          this will not give the result you would expect, since LightBlue is
  162.          define to be $09, while the color value of light blue is $39.
  163.  
  164.          There are two ways to solve this:
  165.  
  166.          The first is to redefine the color value in the palette registers,
  167.          and then set the RGB value of that color:
  168.  
  169.          SetTEXTPalette(LightBlue,LightBlue);
  170.          SetRGBRegister(LightBlue,10,10,50);
  171.  
  172.          Another, (and in my opinion cleaner way) is to use the constant
  173.          array CList defined in the Colors unit. This array contains the
  174.          values in table 1. So in order to perform the task above, just
  175.          give the command
  176.  
  177.          SetRGBRegister(CList[LightBlue],10,10,50);
  178.  
  179.          procedure GetColorList;
  180.          procedure SetColorList;
  181.          ───────────────────────
  182.  
  183.          The Colors unit defines:
  184.  
  185.            type  TColor   = record
  186.                               R,G,B : byte;
  187.                             end;
  188.  
  189.  
  190.            var   ColorList: array[0..15] of TColor;
  191.  
  192.            GetColorList will read the DAC registers (using GetRGBRegister)
  193.            and store them in ColorList, while SetColorList will call
  194.            SetRGBRegister and set the DAC registers to the values stored
  195.            in ColorList.
  196.  
  197.  
  198.          function ReadDACFile(Filename: string): boolean;
  199.          procedure WriteDACFile(Filename: string);
  200.          ────────────────────────────────────────────────
  201.  
  202.            ReadDACFile will read a color palette from the file Filename,
  203.            and return true if the operation was successful. The values
  204.            read will be stored in ColorList, but will NOT automatically
  205.            be loaded. Call SetColorList to do that!
  206.  
  207.            WriteDACFile will write the color palette stored in ColorList
  208.            to the file Filename.
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.          ┌───────────────────┐
  216.          │  PROGRAM VGACols  │
  217.          └───────────────────┘
  218.  
  219.          This program lets you create and edit color palettes. The palettes
  220.          can be stored to file and used in your own programs.
  221.  
  222.          When the program starts, it will display the 16 colors, and the
  223.          RGB component values of the current color. You can switch between
  224.          selecting the color and editing the color with the Tab key.
  225.  
  226.          To select a color, use the arrow keys to move, and either Return
  227.          or Tab to select. This will bring you to bottom of the screen,
  228.          where you can change the individual Red, Green and Blue components
  229.          of the current color. Use the up and down arrow keys to select Red,
  230.          Green or Blue, and the left and right arrow keys to change the value.
  231.  
  232.          To save the palette to file, press F2. The program will prompt you
  233.          for a filename.
  234.  
  235.          To load a palette from file, press F3. The program will give you
  236.          a list of files to choose from. The default extension of the
  237.          palette files are .VGA, but by pressing F3 again, you can look
  238.          for other files.
  239.  
  240.          Press Escape to quit the program.
  241.