[comp.lang.c] cont...256 colors in C...

TTH102@psuvm.psu.edu (tom hand) (08/31/90)

Sorry about this continuation, I accidentally posted the original
artical before it was finished...

The program is actually rather simple, atleast from where dos
interupt calls are concerned. It starts out by initiallizing
mode 13h using int 10h.
Then I have a function which will put a display a pixel in
whatever color I want using mode 0C. Well here is the function...

dot(int x,int y)
{
        union REGS a,b;
        a.h.ah = 0x0C;
        a.h.al = color;    (global var.)
        a.h.bh = 0;
        a.h.cl = x;
        a.h.dl = y;
        int86(0x10, &a, &b);
}

What the program does is display the "Rose Function" aka "Clover Funcion"
repeatedly on the screen in different colors (256 of them).
Here is Where I ran into trouble.

I compiled and ran the program, and it worked wonderfully only as long as
stayed outside turboc's integrated environment. But as soon as I tried
running it from inside the editor, the function would skip whole sections
of the screen, leaving them blank, and then countinue to draw on the
other side of the blank spot. I got even more interesting results when I
took that same program and ran it on a different machine. The function
would not come out smoothly, but would be scrambled on the screen. As if
somehow it would randomly pick a place to start drawing.

So I compiled the same program on that machine (IBM ps/2 mod 50), ran it
and got the same results (scramble).

What am I doing wrong? Since Dos is suposed to keep track of Graphics as
well as everything else, why isn't my program portable?
-------------------------------------------------------------------
       Thomas Hand (TTH102@psuvm)...
-------------------------------------------------------------------
  Note: The opinions expressed here are those of the author,
        and may not be shared by faculty or students of PSU...
-------------------------------------------------------------------

mfinegan@uceng.UC.EDU (michael k finegan) (09/01/90)

The 256 color mode uses a look up table (palette) to get 256 colors out of 2^6
possible colors. The turboC 'environment' probably changes the palette, maybe
making a range of LUT entries 0. Try saving the palette on entering your
program, setting default or desired palette, then restoring palette on exit.
That should be pretty portable :-).
						- Mike
						  mfinegan@uceng.uc.edu