Microsoft KB Archive/36022

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Knowledge Base


How to BSAVE/BLOAD EGA SCREENs 7, 8, 9, 10 in QB 2.x, 3.0

Article ID: 36022

Article Last Modified on 11/21/2006



APPLIES TO

  • Microsoft QuickBasic 3.0
  • 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
  • Microsoft BASIC Professional Development System 7.1



This article was previously published under Q36022

SUMMARY

Below is a code example that uses BSAVE and BLOAD to store and retrieve a screen image in EGA SCREEN modes 7, 8, 9, and 10 to and from disk. This BSAVE and BLOAD technique required for EGA screens is not as straightforward as for CGA or Hercules SCREEN modes, because EGA memory is stored in discontinuous color planes.

Note: A BETTER BLOAD/BSAVE article is available. For an example of BLOAD and BSAVE of VGA screen modes 11, 12, and 13 (supported in QuickBasic 4.x, in Basic compiler 6.0 and 6.0b, and in Basic PDS 7.0 and 7.1), in addition to the EGA modes shown below, query on the following word for a separate, more complete, current article in this Knowledge Base:

BSAVEVGA


The code example further below works in the following products: Microsoft QuickBasic versions 3.0, 4.0, 4.0b, and 4.5; Microsoft Basic Compiler versions 6.0 and 6.0b for MS-DOS; and Microsoft Basic Professional Development System (PDS) versions 7.0 and 7.1 for MS-DOS. (Note that EGA SCREENs are not supported in the protected mode of OS/2.)

QuickBasic versions 2.0 and 2.1 do not support SELECT CASE, and the program below needs to be modified to use IF statements instead.

QuickBasic versions 1.0, 1.01, and 1.02 do not support the EGA SCREEN modes (7, 8, 9, and 10), and cannot use this program.

This program can also be found in the May 12, 1987 issue of "PC Magazine" on pages 403-404.

MORE INFORMATION

The EGA memory is broken into color planes. The program below is designed to save a given EGA screen into separate disk files; one file for each EGA color plane.

For more technical information about EGA memory, please refer to the following book, which is available at book stores or from Microsoft Press at (800) 638-3030 or (206) 882-8080:

"Programmer's Guide to PC and PS/2 Video Systems," Richard Wilton, Microsoft Press, 1987


Code Example

' HOW TO BLOAD AND BSAVE EGA SCREENS 7, 8, 9, and 10.
SCREEN 9  ' Invokes EGA 640 x 350 16-color mode.
FOR i = i TO 200  '  Draw some random lines in random colors:
x1 = INT(640 * RND)
y1 = INT(350 * RND)
x2 = INT(640 * RND)
y2 = INT(350 * RND)
co = INT(15 * RND)
LINE (x1, y1)-(x2, y2), co
NEXT i

' Save EGA video memory from video memory to disk:
filename$ = "TEST"
mode = 9
RW = 0
CALL EGA(filename$, mode, RW)
CLS
INPUT "Hit <ENTER> to restore screen:", a$

'Load EGA video memory from disk to video memory:
RW = 1
CALL EGA(filename$, mode, RW)
END

SUB EGA (filename$, mode, RW) STATIC
' filename$=filename
' mode=video mode (EGA SCREEN number)
' RW=read/write EGA from/to disk R=T, W=F

'Determine amount of video memory for display mode:
SELECT CASE mode
CASE 7
  Total = 8000
CASE 8
  Total = 16000
CASE 9 TO 10
  Total = 28000
CASE ELSE
  PRINT "ERROR: NonEGA Graphics Mode!"
  GOTO NOEGA
END SELECT

'Cycle through each video plane of EGA
IF mode = 10 THEN cycle = 1 ELSE cycle = 3
DEF SEG = &HA000    ' Segment of EGA video memory
FOR i = 0 TO cycle
  IF RW = 1 THEN
    ' Set EGA register for write to each plane:
    OUT &H3C4, 2
    OUT &H3C5, 2 ^ i

    F$ = filename$ + CHR$(i + 48) + ".EGA"
    BLOAD F$, 0
  ELSE
    ' Set EGA register for read from each plane:
    OUT &H3CE, 4
    OUT &H3CF, i
    F$ = filename$ + CHR$(i + 48) + ".EGA"
    BSAVE F$, 0, Total
  END IF
NEXT i
DEF SEG
NOEGA:
END SUB
                


Additional query words: QuickBas BasicCom 2.00 2.10 3.00 4.00 4.00b 4.50 6.00 6.00b 7.00 7.10

Keywords: KB36022