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[1] 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[1]),':',ofs(a[1]));
 writeln(seg(b[1]),':',ofs(b[1]));
 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[1],' ',a[2],' ',a[3],' ',a[4],' ',a[5],' ',a[6],' ',a[7],'
',a[8],' ',a[9],' ',a[10]);
 writeln(b[1],' ',b[2],' ',b[3],' ',b[4],' ',b[5],' ',b[6],' ',b[7],'
',b[8],' ',b[9],' ',b[10]);
 writeln;
 for v:=1 to 10 do begin
  b[10]:=a[1];
  a:=b;
  writeln(a[1],' ',a[2],' ',a[3],' ',a[4],' ',a[5],' ',a[6],' ',a[7],'
',a[8],' ',a[9],' ',a[10]);
 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[1]. 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  
 
 [ 2 post ] 

 Relevant Pages 

1. Help me with rotating my palette!!!

2. RGB and 256-color palette matching

3. RGB 256-color palette problem

4. 256 color palette

5. Please Help Me with 256 color Palette !!

6. 256 color palette in TP7

7. Windows Colors & palette help needed

8. Changing Palette in high color mode

9. - 256 Color Palette Blues

10. 256 color image on a 16 color screen?

11. Windows Pascal 1.5 - Text color & Background color

12. Problem printing color bitmap on color printer wih TPW 1.5

 

 
Powered by phpBB® Forum Software