BBS: Inland Empire Archive
Date: 06-02-92 (06:49) Number: 173
From: RICH GELDREICH Refer#: NONE
To: MICAH SHERR Recvd: NO
Subj: Re:fading In Qb 4.5 Conf: (2) Quik_Bas
> Dear Experienced QuickBasic Programmer,
> I am at my wit's end trying to figure out a way to smoothly
> fade a mcga screen to black. I don't wish to just make every color
> black. I want to know how to do a "Sierra" quality fade. I have
> experimented with the palette commands, but to no avail. If ANYONE can
> help, PLEASE respond!
> By the way, I have tried the formula the way it is displayed
> in QuickBASIC's help screen for the palette statement. However, it
> doesn't seem to work. It always produces a number around 4,000,000.
> Please help!
Did you see my VGA fading routines? I posted two of them- one in QB,
and one in assembly. Fading the screen is very easy... here goes!
Lets say we have 4 colors to fade. The colors are:
The object is to go from brightest to darkest as smoothly as
possible. After each fade(or frame), we wait until the next one so that
the fade works at the same speed for each computer.
To do this fade, all we have to do is store the R G B values in 3
arrays, like this:
In order to fade these colors, we must have a quick way of changing
palettes. Since QB's PALETTE command calls BIOS to do it's dirty work,
it's rather slow. Instead, we're going to go directly to the hardware
To fade the colors, we go from 1 to 0 with a small step, say 1/64 or
so. There's one problem with that, though. It uses floating point
math(which is slow as hell). The alternate way is to use integer math-
something computers do best. Instead of representing .5 in floating
point form, we would represent .5 in fractional form(e.g. 32/64). This
allows us to manipulate floating point numbers as integers.
The port addresses on the VGA for changing attributes are &h3C7,
&h3c8, and &h3c9(these are hexidecimal, or base 16, numbers). To change
a color on the VGA, quickly, use this:
OUT &h3c7, colornumber:out &h3c8, colornumber
Out &h3c9, red:out &h3c9, green:out &h3c9, blue
This is the same thing as:
Palette colornumber, Red+Green*256&+Blue*65536&
To do our fade of the 4 colors, we just do a simple FOR/NEXT loop:
For A=63 to 0 step -1
For B=1 to 4
out &h3c7,B:out &h3c8,B
Rnew = (R(B) * A) \ 63
Rnew = R(B) * (A/63)
If you know your algebra, you'll understand what's going on.
Hope that helps! If you need a practical program(one that gets the
R,G,B values for you) then let me know.
(P.S. All of this was off the top of my head so I hope there's no
stupid bugs in the port numbers or something :-)
--- RBBSMAIL 17.2A
* Origin: Computer Co-Op RBBS HST, 609-784-9404 Voorhees
NJ (RBBS-PC 1:266/29)