TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: ALL
from: BRIAN MCLAUGHLIN
date: 1998-03-14 19:39:00
subject: Code to restore colors in

From: Brian McLaughlin 
Subject: Code to restore colors in text mode
 
$IF 0
Under DOS, in text mode, you can use ANSI.SYS to force screen colors
other than B&W. I find very few text-mode programs restore the colors
I am using when they exit. Instead, they revert the screen to B&W.
The following code illustrates how to save the colors being used under
DOS, and restore them. I'm releasing this code into the public domain.
It requires PB3C or higher.
$ENDIF
 
$LIB ALL OFF
DECLARE SUB InitialScreenColors (Flag%)
 
%SAVECOLORS    = 0
%RESTORECOLORS = 1
 
InitialScreenColors %SAVECOLORS
CLS
PRINT "Initial colors have been saved."
DELAY 1
InitialScreenColors %RESTORECOLORS
 
'=============================================================================
 SUB InitialScreenColors (Flag%)   PUBLIC
'=============================================================================
' If you want to save the original screen colors, call this
' SUB before you print ANYTHING to the screen, or do a CLS.
'
' Flag% indicates whether to save or restore the screen colors:
'   %SAVECOLORS = 0
'   %RESTORECOLORS = 1
 
 DIM InitColorAttr AS STATIC BYTE
 
 IF Flag% = 0 THEN       'save the current screen colors.
   CursorRow% = CSRLIN
   CursorCol% = POS
   IF CursorCol% > 1 THEN DECR CursorCol%
   IF CursorRow% > 1 THEN DECR CursorRow%
   Attribute% = SCREEN(CursorRow%, CursorCol%, 1)
   InitColorAttr = CBYT(Attribute%)
 
 ELSEIF Flag% = 1 THEN   'restore the current screen colors.
   InitAttr? = InitColorAttr
   ASM  Les DI, pbvScrnBuff
   ASM  Inc DI             ; point at attribute byte, not char byte
   ASM  Mov AL, InitAttr?
   ASM  Mov CX, 2000
 VidLoop:
   ASM  Stosb              ; increments DI automatically
   ASM  Inc DI             ; but we need to increment DI once more
   ASM  Loop VidLoop
 END IF
 
END SUB
 
*** QwkNews (tm) v2.1
 * [TN71] Toast House Import
--- GEcho 1.20/Pro
---------------
* Origin: Toast House Remote (1:100/561)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.