Help me with rotating my palette!!! 
Author Message
 Help me with rotating my palette!!!

Hi!

I wonder if somebody can help me out with my problem?
I enclose my sourcecode in Pascal but I doubt it will be
any difficulties for any C/C++ programemr to understand
it.

My problem is that when I try to rotate my palette it also
changes the background color. I thought that the background-
color was color number 0. As I understand it from my program's
behaviour the background color is number 1. Crazy?

As I have written my source it does't change color 0
because I don't want the background to change color
when I am rotating my palette.

Do I have any kind of bugs in my source code?
(well obviously there is some kind of problem!)

I have tried to solve this s#it for 4 hours now and I can't
understand what the bug really is.

Please somebody help me.


type  ColorType = record
             R : BYTE;
             G : BYTE;
             B : BYTE;
      end;
      PaletteType = array[0..255] of ColorType;

{**********************
** Rotate palette    **
***********************}
procedure RotatePalette (var pal : PaletteType);
var i : INTEGER;
    r, g, b : BYTE;
begin
     r := pal[1].R;
     g := pal[1].G;
     b := pal[1].B;

     for i:=1 to 254 do begin
         pal[i].R := pal[i+1].R;
         pal[i].G := pal[i+1].G;
         pal[i].B := pal[i+1].B;
     end;

     {don't forget the last color}
         pal[255].R := r;
         pal[255].G := g;
         pal[255].B := b;
end; {RotatePalette}



Wed, 18 Jun 1902 08:00:00 GMT  
 Help me with rotating my palette!!!

Quote:

> Hi!

> I wonder if somebody can help me out with my problem?
> I enclose my sourcecode in Pascal but I doubt it will be
> any difficulties for any C/C++ programemr to understand
> it.

> My problem is that when I try to rotate my palette it also
> changes the background color. I thought that the background-
> color was color number 0. As I understand it from my program's
> behaviour the background color is number 1. Crazy?

> As I have written my source it does't change color 0
> because I don't want the background to change color
> when I am rotating my palette.

> Do I have any kind of bugs in my source code?
> (well obviously there is some kind of problem!)

> I have tried to solve this s#it for 4 hours now and I can't
> understand what the bug really is.

> Please somebody help me.


> type  ColorType = record
>              R : BYTE;
>              G : BYTE;
>              B : BYTE;
>       end;
>       PaletteType = array[0..255] of ColorType;

> {**********************
> ** Rotate palette    **
> ***********************}
> procedure RotatePalette (var pal : PaletteType);
> var i : INTEGER;
>     r, g, b : BYTE;
> begin
>      r := pal[1].R;
>      g := pal[1].G;
>      b := pal[1].B;

>      for i:=1 to 254 do begin
>          pal[i].R := pal[i+1].R;
>          pal[i].G := pal[i+1].G;
>          pal[i].B := pal[i+1].B;
>      end;

>      {don't forget the last color}
>          pal[255].R := r;
>          pal[255].G := g;
>          pal[255].B := b;
> end; {RotatePalette}Are you using a textmode when scrolling the palette.  Because if you use

a different background in text it is not 0.  From what i can tell your
code works.  Here is some that i wrote that tests your procedure.
uses crt;
type  ColorType = record
         R : BYTE;
         G : BYTE;
         B : BYTE;
         end;
PaletteType = array[0..255] of ColorType;
var pal1,pal2:palettetype;
Procedure setrgb(n,r,g,b:byte);
begin
  port[$3c8]:=n;
  port[$3c9]:=r;
  port[$3c9]:=g;
  port[$3c9]:=b;
end;
Procedure setpal(pal:palettetype);
var i:byte;
begin
  port[$3c8]:=0;
  for i:=0 to 255 do
   with pal[i] do begin
     port[$3c9]:=r;
     port[$3c9]:=g;
     port[$3c9]:=b;
   end;
end;
Procedure getpal(var pal:palettetype);
var i:byte;
begin
  for i:=0 to 255 do
   with pal[i] do begin
     port[$3c7]:=i;
     r:=port[$3c9];
     g:=port[$3c9];
     b:=port[$3c9];
   end;
end;

{********************** ** Rotate palette    **    
***********************}
procedure RotatePalette (var pal : PaletteType);
var i : INTEGER;
r, g, b : BYTE;
 begin
 r := pal[1].R;
 g := pal[1].G;
 b := pal[1].B;

 for i:=1 to 254 do begin
 pal[i].R := pal[i+1].R;
 pal[i].G := pal[i+1].G;
 pal[i].B := pal[i+1].B;
 end;

 pal[255].R := r;
 pal[255].G := g;
 pal[255].B := b;
 end; {RotatePalette}
 var p:byte;
begin
  asm
    mov ax,13h
    int 10h;
    push ds;
    mov ax,0A000h;
    mov ds,ax;
    xor bx,bx;
    mov dx,200;


    mov byte ptr[bx],al;
    inc bx;

    inc al;
    dec dx;

    pop ds;
  end;

  getpal(pal1);
  pal2:=pal1;
  for p:=1 to 16 do
   begin
    textcolor(p);
    textbackground(p);
    write('p');
   end;
  repeat
    rotatepalette(pal1);
    setpal(pal1);
    delay(10);
  until keypressed;
  setrgb(0,63,63,63);{this will now change the background}
  readkey;
  readkey;

  setpal(pal2);
  asm
     mov ax,3;
     int 10h;
  end;
end.



Wed, 18 Jun 1902 08:00:00 GMT  
 Help me with rotating my palette!!!

Quote:

>Hi!
>I wonder if somebody can help me out with my problem?
>I enclose my sourcecode in Pascal but I doubt it will be
>any difficulties for any C/C++ programemr to understand
>it.
>My problem is that when I try to rotate my palette it also
>changes the background color. I thought that the background-
>color was color number 0. As I understand it from my program's
>behaviour the background color is number 1. Crazy?

Exactly what do you mean by background color?  If it's the actual screen,
then it could be whatever you've drawn.  In mode 13h, there's also a border
around the screen (called overscan) which is always color 0 -- in text mode
this border's color can be changed, though.

Quote:
>As I have written my source it does't change color 0
>because I don't want the background to change color
>when I am rotating my palette.
>Do I have any kind of bugs in my source code?
>(well obviously there is some kind of problem!)

Not that I see, except for the fact that it's rather inefficient.  Some
changes are made below.

Quote:
>I have tried to solve this s#it for 4 hours now and I can't
>understand what the bug really is.

AFAIK, the only country I know of that disallows people to say "shit" is the
good ol' USless of A.  :-)

Quote:
>Please somebody help me.


Here's a patch-up for better speed (and overall code size):

type  ColorType = record
             R : BYTE;
             G : BYTE;
             B : BYTE;
      end;
      PaletteType = array[0..255] of ColorType;

{**********************
** Rotate palette    **
***********************}
procedure RotatePalette (var pal : PaletteType);
var tmp : ColorType;
begin
     move (tmp,pal[1],sizeof(ColorType));

     move (pal[1],pal[2],sizeof(ColorType)*254);

     {don't forget the last color}
     move (tmp,pal[254],sizeof(ColorType));
end; {RotatePalette}

Off the top of my head, not error-checked but it should work right.  Same
thing, faster and more compact.  I'm doubt this solves the original
problem.  Perhaps you could give a little more information and/or source?

--
Scott F. Earnest           | We now return you to our regularly scheduled



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Rotating color palette.

2. Lousy Palette - help, help, help, help, help...

3. 3d rotating, Please help

4. Help! rotated chars (TPW)

5. Help with palette in VGA

6. Please Help Me with 256 color Palette !!

7. HELP Palette Animation

8. Please help with palette animation.

9. Windows Colors & palette help needed

10. HELP! - Palettes in TPW1.5

11. Help with Palette [RGB]

12. Qreport, rotating text, label.caption

 

 
Powered by phpBB® Forum Software