How to Save Color Registers After BSAVE of (PICEM) Graphics

This article was previously published under Q78888
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
QuickBasic cannot use .PCX, .GIF, or .PIC graphics files directly. Theutility PICEM210.EXE can be used to display the graphics on the screenso that QuickBasic can BSAVE and later BLOAD the image. However, BSAVEsaves only the bit planes, not the color registers. If the graphicsimage changes the color registers, then these changes will be lost,resulting in a gray-scale image when loaded with the BLOAD statement.This is a limitation of the BSAVE statement, not PICEM210.EXE.

In order to retain the picture's original colors, use the CALLINTERRUPTX &H10 with function &H17 to place the color registers intoan array, then BSAVE the array. To restore the picture's colors, BLOADthe color register array that was saved with BSAVE and use CALLINTERRUPTX &H10 with function &H12.

Of the four sample programs provided below, examples 1 and 3 BSAVE thepicture and its color registers, and examples 2 and 4 BLOAD thepicture and its color registers. These programs apply to QuickBasicversions 4.0, 4.0b, and 4.5, to Microsoft Basic Compiler versions 6.0and 6.0b, and to Microsoft Basic Professional Development System (PDS)versions 7.0 and 7.1 for MS-DOS. Because Basic BSAVEs SCREENs 7, 8, 9,and 12 differently then SCREEN 13, Examples 1 and 2 (SAV7to12.BAS andLOD7to12.BAS) have been written specifically for SCREENs 7, 8, 9, or12, and examples 3 and 4 (SAV13.BAS and LOD13.BAS) have been writtenfor SCREEN 13.

PICEM210 is a freeware graphics file viewing utility that can display.GIF, .PCX, and .PIC file formats, and is required to make these programsrun. PICEM210 is available as a freeware product. For more information onPICEM, please read its README file PICEM210.DOC, or query on the followingword:
PICEM
MORE INFORMATION
You only need to use example program 1 or 3 once to convert thegraphics image. You will use example program 2 or 4 every time youwish to display the graphics image. All four programs use theINTERRUPTX routine in the QuickBasic QB.QLB Quick library (or QBX.QLBfor Microsoft Basic PDS) to retrieve or set the graphics image's colorregisters. To use this Quick library's procedures, you must load theQuick library with the environment by typing QB/L (or QBX/L forMicrosoft Basic PDS) at the command prompt.

The examples can be used independently. If you add them to an existingprogram, the DECLARE SUB ConvrtPic(), the TYPE colortype ... END TYPE,and 'INCLUDE: 'qb.bi' (or '$INCLUDE: 'qbx.bi' for Microsoft BasicPDS) statements must be moved to the existing program's main modulelevel code. The introduction on each example lists which variablesneed to be altered by the programmer. The programs themselves containsuggested values for the variables when necessary.

Example 1: (SAV7TO12.BAS)

'REQUIREMENT: must have PICEM210.EXE'This program uses PICEM210 to display a .PCX, .PIC, or .GIF'graphics image file onto the screen so that QuickBasic can'then BSAVE it. It BSAVEs the picture and the color'registers for SCREEN 7,8,9, or 12. The values of the'variables MODE%, Z, TOTAL!,and YOURFILE must be written'into the code. PICEM210.EXE should be in the default directory.DECLARE SUB ConvrtPic ()TYPE colortype        red AS STRING * 1        green AS STRING * 1        blue AS STRING * 1END TYPE'$INCLUDE: 'qb.bi'''$INCLUDE: 'qbx.bi' for Basic PDSCALL ConvrtPic()ENDSUB Convrt Pic()DIM inregsx AS RegTypeXDIM outregsx AS RegTypeXDIM colorbuf(15) AS colortypeSCREEN MODE%'where MODE% = 7  for screen 7'            = 8  for screen 8'            = 9  for screen 9'            = 12 for screen 12.SHELL "PICEM210 /e/v:Z YOURFILE.PCX"'where Z = j for screen 7'        = d for screen 8'        = g for screen 9(ega)'        = i for screen 9(vga)'        = m for screen 12  'if other options for PICEM210 are desired, refer to  'PICEM210.DOC for alternate choices'where YOURFILE.PCX is the .pcx,.pic,or.gif file to be 'convertedDEF SEG = &HA000FOR i% = 0 TO 3'BSAVing 4 files with .b_0,.b_1,.b_2,.b_3 extensions.'The 4 files contain the 4 bit planes        OUT &H3CE, 4         'makes the port at &H3CE enable the data register at &H3CF        OUT &H3CF, i%         'selects next bit plane        f$ = "YOURFILE" + ".b_" + CHR$(i% + 48)         'where YOURFILE is the filename to be used for the         'BSAVEd graphics image files after conversion.        BSAVE f$, 0, TOTAL!         'where TOTAL! = 8000   for screen 7         '             = 16000  for screen 8         '             = 28000  for screen 9         '             = 38400  for screen 12NEXT i%DEF SEG'BIOS interrupt to get palette registersinregsx.ax = &H1017inregsx.bx = 0inregsx.cx = 16inregsx.es = VARSEG(colorbuf(0))inregsx.dx = VARPTR(colorbuf(0))CALL INTERRUPTX(&H10, inregsx, outregsx)'BSAVE palette registersDEF SEG = VARSEG(colorbuf(0))BSAVE "YOURFILE.REG", VARPTR(colorbuf(0)), 48'where YOURFILE is the filename to be used for the BSAVEd'color registersDEF SEGEND SUB				

EXAMPLE 2: (LOD7TO12.BAS)

'This program loads BSAVEd files from disk into video'memory and restores the graphics image's registers'for screen 7,8,9, or 12. It assumes the picture files'were BSAVEd using code from SAV7TO12.BAS. The values of'the variables MODE%, and YOURFILE must be written into'the code. The graphics image files should be in the default'directory.DECLARE SUB ConvrtPic ()TYPE colortype        red AS STRING * 1        green AS STRING * 1        blue AS STRING * 1END TYPE'$INCLUDE: 'qb.bi'''$INCLUDE: 'qbx.bi' for Basic PDSCALL ConvrtPic()ENDSUB Convrt Pic()DIM inregx AS RegTypeXDIM outregx AS RegTypeXDIM colorbuf(15) AS colortypeSCREEN MODE%'where MODE% = 7  for screen 7'            = 8  for screen 8'            = 9  for screen 9'            = 12 for screen 12CLS'if necessary, save the current color registers of the'existing screen using code from SAV7TO12.BAS before'changing colors to the graphics image's palette'BLOAD the graphics image's palette into arrayDEF SEG = VARSEG(colorbuf(0))BLOAD "YOURFILE.REG", VARPTR(colorbuf(0))'where YOURFILE.REG is the BSAVEd file created in'SAV7TO12.BAS which contains the color registersDEF SEG'call interrupt to restore graphics image's palette to registersinregx.ax = &H1012inregx.bx = 0inregx.cx = 16inregx.es = VARSEG(colorbuf(0))inregx.dx = VARPTR(colorbuf(0))CALL INTERRUPTX(&H10, inregx, outregx)'BLOAD 4 bit planes created in SAV7TO12.BASDEF SEG = &HA000FOR k = 0 TO 3        OUT &H3C4, 2         'makes the port at &H3C4 enable the data register at &H3C5        OUT &H3C5, 2 ^ k         'selects next bit plane        f$ = "YOURFILE.B_" + CHR$(k + 48)      'where YOURFILE.B_ is the filename of the converted graphics      'image        BLOAD f$, 0NEXT kDEF SEGEND SUB				

Example 3: (SAV13.BAS)

'REQUIREMENT: must have PICEM210.EXE'This program uses PICEM210 to display a .PCX, .PIC, or .GIF'file onto the screen so that QuickBasic can then BSAVE it.'It BSAVEs the picture and the color registers for SCREEN'13. The value of the variable YOURFILE must be written into'the code. PICEM210.EXE should be in the default directory.DECLARE SUB ConvrtPic ()TYPE colortype        red AS STRING * 1        green AS STRING * 1        blue AS STRING * 1END TYPE'$INCLUDE: 'qb.bi'''$INCLUDE: 'qbx.bi'  for Basic PDSCALL ConvrtPic()ENDSUB Convrt Pic()DIM inregsx AS RegTypeXDIM outregsx AS RegTypeXDIM colorbuf(255) AS colortypeSCREEN 13SHELL "PICEM210 /e/v:l YOURFILE.pcx"'where YOURFILE.pcx is the filename of the pcx,.pic, or .gif'graphics image to be converted'BSAVE graphics imageDEF SEG = &HA000BSAVE "YOURFILE.sav", 0, 64000'where YOURFILE is the filename for the converted graphic imageDEF SEG'BIOS interrupt to get palette registersinregsx.ax = &H1017inregsx.bx = 0inregsx.cx = 256inregsx.es = VARSEG(colorbuf(0))inregsx.dx = VARPTR(colorbuf(0))CALL INTERRUPTX(&H10, inregsx, outregsx)'BSAVE palette registersDEF SEG = VARSEG(colorbuf(0))BSAVE "YOURFILE.reg", VARPTR(colorbuf(0)), 3 * 256'where YOURFILE is the filename for the BSAVEd color registersDEF SEGEND SUB				

Example 4: (LOD13.BAS)

'This program loads BSAVEd files from disk into video'memory and restores the graphics image's registers'for screen 13. It assumes the picture files were BSAVEd'using code from SAV13.BAS. The value of the variable'YOURFILE must be written into the code. The graphics image'files should be in the default directory.DECLARE SUB ConvrtPic ()TYPE ColorType        red AS STRING * 1        green AS STRING * 1        blue AS STRING * 1END TYPE'$INCLUDE: 'qb.bi'    ' use for QuickBasic 4.0, 4.0b, or 4.5''$INCLUDE: 'qbx.bi   ' use for Basic PDS 7.0 or 7.1CALL ConvrtPic()ENDSUB Convrt Pic()DIM inregx AS RegTypeXDIM outregx AS RegTypeXDIM colorbuf(255) AS ColorTypeSCREEN 13CLS'if necessary, save the current color registers of the'existing screen using code from SAV13.BAS before changing'colors to the graphics image's palette'BLOAD the picture's paletteDEF SEG = VARSEG(colorbuf(0))BLOAD "YOURFILE.reg", VARPTR(colorbuf(0))'where YOURFILE is the filename containing the graphics'image's color registersDEF SEG'call interrupt to restore graphics image's paletteinregx.ax = &H1012inregx.bx = 0inregx.cx = 256inregx.es = VARSEG(colorbuf(0))inregx.dx = VARPTR(colorbuf(0))CALL INTERRUPTX(&H10, inregx, outregx)'BLOAD pictureDEF SEG = &HA000BLOAD "YOURFILE.sav", 0'where YOURFILE is the filename of the converted graphics'imageDEF SEGEND SUB				
QuickBas BasicCom 4.00 4.00b 4.50 6.00 6.00b 7.00 7.10
Properties

Article ID: 78888 - Last Review: 02/27/2014 18:30:40 - Revision: 1.2

  • kbnosurvey kbarchive KB78888
Feedback