Microsoft KB Archive/50000

= How to Save and Restore the VGA Palette Registers in Basic =

Article ID: 50000

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0

-



This article was previously published under Q50000



SUMMARY
In Microsoft QuickBasic, a program can save and restore the VGA PALETTE registers using the CALL INTERRUPT statement. This can be useful when SHELLing to other programs that might change the PALETTE registers.

This can also be used along with BSAVE and BLOAD to save graphic images. BLOAD and BSAVE save the binary image of the graphic image, but not the color PALETTE. The INTERRUPT can be used to read the PALETTE registers into an array, which can then be saved along with the graphic image.

This information applies to Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50 for MS-DOS, to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS, and Microsoft Basic PDS Version 7.00 for MS-DOS.



MORE INFORMATION
The Basic program below is SAVPAL.BAS, which displays a multicolored image and then restores the palette registers after setting all of the palette registers to black.

To demonstrate this program from an .EXE program, compile and link as follows: BC SAVEPAL.BAS; LINK SAVEPAL; If running the program from the QuickBasic editor environment, the Quick library QB.QLB must be loaded in. This can be done with the following command line: QB SAVPAL /L If running in the Basic Compiler 7.00 QuickBasic Extended environment, the Quick library QBX.LIB must be loaded in. This can be done with the following command line: QBX SAVEPAL /L

Code Example
TYPE colortype          ' structure to hold RGB color palette red AS STRING * 1 green AS STRING * 1 blue AS STRING * 1 END TYPE

REM $INCLUDE: 'qb.bi'   ' defines for CALL INTERRUPTX ' For QBX.EXE environment use the include file 'QBX.BI'

DIM inregsx AS RegTypeX DIM outregsx AS RegTypeX DIM colorbuf(255) AS colortype SCREEN 13

inregsx.ax = &H1017     ' BIOS interrupt to save palette registers inregsx.bx = 0 inregsx.cx = 256        ' save all 256 color registers inregsx.es = VARSEG(colorbuf(0)) ' address of array holding palette inregsx.dx = VARPTR(colorbuf(0))

CALL INTERRUPTX(&H10, inregsx, outregsx) ' save palette registers

FOR i% = 2 TO 255     ' display colorful pattern LINE (i%, 10)-(i%, 199), i% NEXT

LOCATE 1, 1 COLOR 1 PRINT &quot;press any key to blank palette&quot; WHILE INKEY$ = &quot;&quot;: WEND

FOR i% = 2 TO 255 ' set all but first palette register to black PALETTE i%, 0 NEXT

LOCATE 1, 1 PRINT &quot;press any key to restore palette&quot;

WHILE INKEY$ = &quot;&quot;: WEND

inregsx.ax = &H1012     ' BIOS interrupt to restore palette registers inregsx.bx = 0 inregsx.cx = 256        ' restore all 256 color registers inregsx.es = VARSEG(colorbuf(0)) ' address of array holding palette inregsx.dx = VARPTR(colorbuf(0))

CALL INTERRUPTX(&H10, inregsx, outregsx) ' restore palette registers

Additional query words: QuickBas BasicCom

Keywords: KB50000

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.