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



The information in this article applies to:

  • Microsoft QuickBASIC 3.0
  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Basic Professional Development System for MS-DOS 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
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB36022