Microsoft KB Archive/37421

= Two Basic Methods to Save & Restore Text Screens in DOS & OS/2 =

Article ID: 37421

Article Last Modified on 8/16/2005

-

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 Q37421



SUMMARY
This article explains two methods for saving and restoring text-mode screens (SCREEN 0). The first method uses BLOAD and BSAVE (supported under MS-DOS only, not under OS/2 protected mode). The second method uses the SCREEN function to save and restore the values of the screen characters to and from a numeric array (supported under both MS-DOS and OS/2 protected mode).



MORE INFORMATION
(The October 27, 1987, issue of &quot;PC Magazine&quot; has a separate example of an assembly-language routine that saves and restores text screens; however, the code needs to be modified for QuickBasic Versions 4.00, 4.00b, and 4.50, for the Basic compiler 6.00 and 6.00b, and for Basic PDS 7.00.)

First Method for Saving and Restoring Text-Mode Screens
The following steps save the screen with BLOAD and BSAVE statements (under MS-DOS but not under OS/2 protected mode):

  Place the text on the screen using the following: SCREEN 0 ' This is the default SCREEN mode. FOR i = 1 TO 400 PRINT i;  NEXT i                          Use the following DEF SEG command to assign the current segment to the correct video-memory location (not supported in OS/2 protected mode): DEF SEG=&HB000  'MONOCHROME CARD DEF SEG=&HB800  'CGA,EGA CARD   Use the BSAVE command below to save the screen (not supported in OS/2 protected mode). In 23-line (CGA) mode, you need 4000 bytes to save a complete text mode screen; (80 columns) times (25 lines) times (1 character byte plus 1 color attribute byte) equals 4000 bytes. In EGA 43-line mode, you need 6880 bytes to save a complete text mode screen (80 times 43 times 2). The BSAVE command is as follows: BSAVE &quot;filename&quot;,0,4000 ' For CGA 23-line mode in SCREEN 0 

Use the following steps to restore the screen:

  Use the following DEF SEG command to assign the current segment to the correct video-memory location: DEF SEG=&HB000  'MONOCHROME CARD DEF SEG=&HB800  'CGA,EGA CARD   Use the following BLOAD command to reload the text: BLOAD &quot;filename&quot;,0 </ol>

Second Method for Saving and Restoring Text-Only on a Screen
(Note: This method works both in MS-DOS and in OS/2 protected mode.)

The second method (below) calls a Basic routine to store the characters on a screen in an array, then restore them. This method uses the SCREEN function, which works both in MS-DOS and in OS/2 protected mode, and in text or graphics screen modes. The SCREEN function returns the ASCII value of the character at a specified row and column (but returns the ASCII value 32, a blank, for text characters that are overlaid with graphics).

Note: The following program is only a short sample. It doesn't include any error checking for coordinate validity. This and other possible enhancements are left up to you. DEFINT A-Z DECLARE SUB SaveScreen (StartCol, StartRow, ColLen, RowLen, arrar%) DECLARE SUB RestScreen (StartCol, StartRow, ColLen, RowLen, arrar%) COLOR 7, 1 CLS COLOR 4 FOR i = 1 TO 10 PRINT &quot;This is a test&quot; NEXT i COLOR 7 INPUT &quot;Enter the Save Starting Row : &quot;;StartRow INPUT &quot;Enter the Save Starting Column : &quot;;StartCol INPUT &quot;Enter the width (the number of columns) : &quot;; col INPUT &quot;Enter the height (the number of rows) : &quot;; row DIM array%(col, row, 2) CALL SaveScreen(StartCol,StartRow, col, row, array%) PRINT &quot;Hit any Key to continue....&quot; while inkey$=&quot;&quot; : wend COLOR 7,3 CLS INPUT &quot;Enter the Restore Starting Row : &quot;;StartRow INPUT &quot;Enter the Restore Starting Column : &quot;;StartCol CALL RestScreen(StartCol, StartRow, col, row, array%) COLOR 7,3 locate 25,10 : PRINT &quot;Hit any key to quit...&quot; WHILE INKEY$ = &quot;&quot;: WEND END

'============= Restore Screen ============= SUB RestScreen (StartCol, StartRow, ColLen, RowLen, array%) STATIC FOR i = 1 TO RowLen LOCATE StartRow + i, StartCol FOR j = 1 TO ColLen COLOR array%(j, i, 2) MOD 16, array%(j, i, 2) \ 16 PRINT CHR$(array%(j, i, 1)); NEXT j   NEXT i END SUB

'============= Save Screen =============== SUB SaveScreen (StartCol, StartRow, ColLen, RowLen, array%) STATIC FOR i = StartCol TO (StartCol + ColLen - 1) FOR j = StartRow TO (StartRow + RowLen - 1) RowIndex = i - StartRow + 1 ColIndex = j - StartCol + 1 array%(RowIndex, ColIndex, 1) = SCREEN(j, i)   'character array%(RowIndex, ColIndex, 2) = SCREEN(j, i, 1) 'color NEXT j   NEXT i END SUB

Additional query words: QuickBas BasicCom

Keywords: KB37421

-

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

© Microsoft Corporation. All rights reserved.