Optimiz3.Txt This text file is the third in a guide for use by QB/QBASIC programmers to help optimize the program code for greater efficiency. If you have any quetions, contact VirtuaSoft at gump@gnt.net. Address to Danny. (Note: This is not for the beginning programmer. A strong background in QB/QBASIC programming is highly recommended.) 3. PALETTE a. PALETTE USING b. Hardware Output c. Hardware Input 3. PALETTE a. PALETTE USING PALETTE USING is a QB statement that writes all 256 colors to the PALETTE at once instead of one at a time. This increases the speed by several times. Simply place the color values in a 256 element LONG INTEGER array with each element having the RGB values of that color's PALETTE (65536*red+256*green+blue Values are 0-63). PALETTE USING is used like this: DIM PaletteVariable(255) AS LONG ... PALETTE USING PaletteVariable(0) ... But why use this when you can write to the hardware for a 60x speed increase!? ...Next section... b. Hardware Output This is the ultimate PALETTE initiation method. It can change the entire 256 color PALETTE in the blink of an eye. It's so fast that PALETTE rotation and plasma effects can easily be achieved! But the downside is that this is slightly more difficult to learn, but once it's understood, it's a snap! It is used as follows: OUT &H3C8, ColorNumber OUT &H3C9, RedValue OUT &H3C9, GreenValue OUT &H3C9, BlueValue The COLOR values, as with PALETTE USING, range from 0-63. When using this method, it's easiest to have a 256 element LONG INTEGER array as was used for PALETTE USING, above. Also, a little bit of PEEKing should be used to further increase the speed and efficiency of the program. Below is an example: DIM PalVar(255) AS LONG ... DEF SEG=VARSEG(PalVar(0)) BLOAD "Palette.pal", VARPTR(PalVar(0)) FOR Temp%=0 to 255 OUT &H3C8, Temp% OUT &H3C9, PEEK(VARPTR(PalVar(Temp%))) OUT &H3C9, PEEK(VARPTR(PalVar(Temp%))+1) OUT &H3C9, PEEK(VARPTR(PalVar(Temp%))+2) NEXT This example BLOADs a separate PALETTE file, but that is not necessary if you define all the colors in the program. If you are not rotating the PALETTE, this method isn't always necessary; the PALETTE USING method will do fine. c. Hardware Input This does just the opposite of part (b). By doing this, you can read the palette values from the hardware. It is used as follows: OUT &H3C7, ColorNumber RedValue = INP(&H3C9) GreenValue = INP(&H3C9) BlueValue = INP(&H3C9) This is very useful for fading the screen or adjusting a current palette. ... This concludes the lesson ...