unit specproc;
interface
type
  RGBRec = record
    RedVal, GreenVal, BlueVal, ColorNum: Integer;
  end;
const
MaxColors=15;
VGAColors : array[0..MaxColors] of RGBRec = (
 ( RedVal:0;GreenVal:0;BlueVal:0;{Name:'Black';}ColorNum: 0),
 ( RedVal:0;GreenVal:0;BlueVal:40;{Name:'Blue';}ColorNum: 1),
 ( RedVal:0;GreenVal:40;BlueVal:0;{Name:'Green';}ColorNum: 2),
 ( RedVal:0;GreenVal:40;BlueVal:40;{Name:'Cyan';}ColorNum: 3),
 ( RedVal:40;GreenVal:7;BlueVal:7;{Name:'Red';}ColorNum: 4),
 ( RedVal:40;GreenVal:0;BlueVal:40;{Name:'Magenta';}ColorNum: 5),
 ( RedVal:40;GreenVal:30; BlueVal:0;{Name:'Brown';}ColorNum: 20),
 ( RedVal:49;GreenVal:49;BlueVal:49;{Name:'Light Gray';}ColorNum: 7),
 ( RedVal:26;GreenVal:26;BlueVal:26;{Name:'Dark Gray';}ColorNum: 56),
 ( RedVal:0;GreenVal:0;BlueVal:63;{Name:'Light Blue';}ColorNum: 57),
 ( RedVal:9;GreenVal:63;BlueVal:9;{Name:'Light Green';}ColorNum: 58),
 ( RedVal:0;GreenVal:63;BlueVal:63;{Name:'Light Cyan';}ColorNum: 59),
 ( RedVal:63;GreenVal:10;BlueVal:10;{Name:'Light Red';}ColorNum: 60),
 ( RedVal:44;GreenVal:0;BlueVal:63;{Name:'Light Magenta';}ColorNum: 61),
 ( RedVal:63;GreenVal:63;BlueVal:18;{Name:'Yellow';}ColorNum: 62),
 ( RedVal:63; GreenVal:63; BlueVal:63;{Name: 'White'; }ColorNum: 63)
);
type PaletteType = record
  Size  :Byte;
  Colors:array[0..MaxColors] of Shortint;
    end;

const HX='0123456789ABCDEF';
var HXs:string;
procedure InitPalette;
procedure setBit(_bitNum:byte;var _bitDat:byte);
procedure resBit(_bitNum:byte;var _bitDat:byte);
function setsBit(_bitNum,_bitDat:byte):boolean;
function whw(_dt:word):string;
function whb(_dt:byte):string;
implementation
function whb(_dt:byte):string;
begin
whb:=HXs[(_dt shr 4)+1]+HXs[(_dt and $0F)+1];
end;
function whw(_dt:word):string;
begin
whw:=whb(hi(_dt))+whb(lo(_dt));
end;
procedure setBit(_bitNum:byte;var _bitDat:byte);
begin
_bitDat:=_bitDat or ($01 shl _bitNum);
end;
procedure resBit(_bitNum:byte;var _bitDat:byte);
begin
_bitDat:=_bitDat and ($FF-($01 shl _bitNum));
end;
function setsBit(_bitNum,_bitDat:byte):boolean;
begin
if (_bitDat and ($01 shl _bitNum))=0 then setsBit:=false else setsBit:=true;
end;

procedure InitPalette;
var _c:byte;
begin
for _c:=0 to MaxColors do
 begin
port[$3C8]:=_c{VGAColors[_c].ColorNum};
port[$3C9]:=VGAColors[_c].RedVal;
port[$3C9]:=VGAColors[_c].GreenVal;
port[$3C9]:=VGAColors[_c].BlueVal;
 end;
end;
begin
HXs:=HX;
end.