Rotating color palette.
Author Message Rotating color palette.

I've just discovered a cool way to shift values in an array to the left.
In other words, moving all values in array[n] to array[n-1] and moving
the value of array to
array[highest element]. Here is how I did it.

-----------------------------------------------------------------
program shift;
type line = array[1..10] of byte;
var a:line absolute 5499:82;
b:line absolute 5499:83;
i,v:byte;
begin
writeln(seg(a),':',ofs(a));
writeln(seg(b),':',ofs(b));
for i:=1 to 10 do begin
a[i]:=0;
b[i]:=0;
end;
for i:=1 to 10 do begin
a[i]:=i;
end;
writeln(a,' ',a,' ',a,' ',a,' ',a,' ',a,' ',a,'
',a,' ',a,' ',a);
writeln(b,' ',b,' ',b,' ',b,' ',b,' ',b,' ',b,'
',b,' ',b,' ',b);
writeln;
for v:=1 to 10 do begin
b:=a;
a:=b;
writeln(a,' ',a,' ',a,' ',a,' ',a,' ',a,' ',a,'
',a,' ',a,' ',a);
end;
end.

Array a starts out with values 1  2  3  4  5  6  7  8  9 10.
the next iteration gives it values of 2  3  4  5  6  7  8  9 10 1. Oh,
by the
way, I discovered that if I put in the statement b:=a, then EVERY
element of
a will be equal to a. Seems like a good way to initialize an array.

Now, here is a question. I wrote the following program to display 256
different colors on the screen. Once they are displayed, I know that I
can
change the palette with setrgb(i,r,g,b) where 0<i<255 and i stands for
the
numerical value of the colors on the screen. For example, if I display
all
256 colors and then issure the command setrgb(57,23,45,90) then every
part of
the screen which was colored by the setcolor(i) command when i was equal
to
57 will be changed to the color that results when red = 23, green = 45,
and
blue = 90.

program svga;
uses graph,crt;
var x,y,i,k,Driver, Mode: Integer;
p:palettetype;
begin
Driver := InstallUserDriver('SVGA256',nil);
if Driver = grError then
Halt(1);
mode:=127;
driver:=16;
InitGraph(driver,Mode,'');
getpalette(p);
for i:=0 to 511 do begin
k:=i div 2;
setcolor(k);
line(0,i,1024,i);
end;
x:=getmaxx;
y:=getmaxy;
repeat
until keypressed;
closegraph;
end.

So now my question is this. How can I rotate the palette. Can I use the
method in the first program to do this? I know that graphics memory
starts at
\$A000:0000, but if I'm right the values there just tell which pixels are
on
or off. It doesn't give color info. If I only knew where in memory the
screens color information was stored, I could use the absolute clause to
put
an array there and shift the palette in the same way that I can shift
the
values in an array. Any ideas?
-Patrick-

Wed, 18 Jun 1902 08:00:00 GMT  Rotating color palette.

Quote:
> So now my question is this. How can I rotate the palette. Can I use the
> method in the first program to do this? I know that graphics memory
> starts at
> \$A000:0000, but if I'm right the values there just tell which pixels are
> on
> or off. It doesn't give color info. If I only knew where in memory the
> screens color information was stored, I could use the absolute clause to
> put
> an array there and shift the palette in the same way that I can shift
> the
> values in an array. Any ideas?

It is not in the memory (just in case a mad program scribble all over them.
It is access thru IO ports. Here is the code.

Procedure SetRGBPalette(ColorNum, Red, Green, Blue : Byte);
Begin
Port[\$3C6] := \$FF;   { use all colors }
Port[\$3C8] := ColorNum;
Port[\$3C9] := Red;  Port[\$3C9] := Green;  Port[\$3C9] := Blue;
End;

Procedure GetRGBPalette(ColorNum : Byte; Var Red, Green, Blue : Byte);
Begin
Port[\$3C6] := \$FF;   { use all colors }
Port[\$3C7] := ColorNum;
Red := Port[\$3C9];  Green := Port[\$3C9];  Blue := Port[\$3C9];
End;

Note : Port[\$3C6] := \$FF needs to write only once. It allows all the 256
colors. Using \$0F allows only 16 colors.
Red, Green and Blue range from 00 to 63.

--
Vinson ABS.
"30% destiny, 70% hardwork"
"It's not a bug, it's a feature!"

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages