Correct screen colors not restored after exiting a pascal program

This is a discussion on Correct screen colors not restored after exiting a pascal program within the Pascal forums in Programming Languages category; Hi group After exiting a DOS program that manipulates the screen colors I sometimes (but not always) don't get the same colors back that existed before invoking the program. I have tried to save then restore TextAttr within the program but that seems to have no effect. I have observed this in both Turbo Pascal 7.0 and FreePascal. It seems to be a question of sheer luck if the original screen colors are restored or not at exit. Any suggestions? Jorgen...

Go Back   Application Development Forum > Programming Languages > Pascal

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-22-2008, 07:51 AM
Schjaer
Guest
 
Default Correct screen colors not restored after exiting a pascal program

Hi group

After exiting a DOS program that manipulates the screen colors I sometimes
(but not always) don't get the same colors back that existed before invoking
the program. I have tried to save then restore TextAttr within the program
but that seems to have no effect. I have observed this in both Turbo Pascal
7.0 and FreePascal. It seems to be a question of sheer luck if the original
screen colors are restored or not at exit. Any suggestions?

Jorgen


Reply With Quote
  #2  
Old 08-22-2008, 12:13 PM
Jim Leonard
Guest
 
Default Re: Correct screen colors not restored after exiting a pascal program

On Aug 22, 6:51 am, "Schjaer" <j...@nospambyg.dtu.dk> wrote:
> Hi group
>
> After exiting a DOS program that manipulates the screen colors I sometimes
> (but not always) don't get the same colors back that existed before invoking
> the program. I have tried to save then restore TextAttr within the program
> but that seems to have no effect. I have observed this in both Turbo Pascal
> 7.0 and FreePascal. It seems to be a question of sheer luck if the original
> screen colors are restored or not at exit. Any suggestions?


Incorrect colors are the result of MS-DOS painting just the characters
while leaving the color attributes alone. Your DOS program probably
recolors the entire screen, then dumps you at the prompt without
cleaning up.
Reply With Quote
  #3  
Old 08-22-2008, 01:39 PM
winston19842005
Guest
 
Default Re: Correct screen colors not restored after exiting a pascalprogram

On 8/22/08 7:51 AM, in article g8m988$h8h$1@news.net.uni-c.dk, "Schjaer"
<jsj@nospambyg.dtu.dk> wrote:

> Hi group
>
> After exiting a DOS program that manipulates the screen colors I sometimes
> (but not always) don't get the same colors back that existed before invoking
> the program. I have tried to save then restore TextAttr within the program
> but that seems to have no effect. I have observed this in both Turbo Pascal
> 7.0 and FreePascal. It seems to be a question of sheer luck if the original
> screen colors are restored or not at exit. Any suggestions?
>
> Jorgen
>
>

It might help to know the OS.
I've noticed programs that did not exhibit this behavior under Windows
versions prior to XP did not exhibit this behavior, whereas the same program
(same configuration) run under "DOS" under XP or Vista sometimes have
strange color changes.

Reply With Quote
  #4  
Old 08-24-2008, 05:08 AM
Bart
Guest
 
Default Re: Correct screen colors not restored after exiting a pascal program

Op Fri, 22 Aug 2008 13:51:35 +0200 schreef "Schjaer"
<jsj@nospambyg.dtu.dk>:

>Hi group
>
>After exiting a DOS program that manipulates the screen colors I sometimes
>(but not always) don't get the same colors back that existed before invoking
>the program. I have tried to save then restore TextAttr within the program
>but that seems to have no effect. I have observed this in both Turbo Pascal
>7.0 and FreePascal. It seems to be a question of sheer luck if the original
>screen colors are restored or not at exit. Any suggestions?
>
>Jorgen
>

Do you save and restore the current videomode?

In plain DOS...

var CurrentMode: Byte Absolute $0000:$0449;
SavedMode: Byte;

Somewhere at startup
...
SavedMode := CurrentMode;
...


Somewhre at cleanup in the end

...
if CurrentMode <> VMode then TextMode(SavedMode);
...

This has worked for me in the past.

Bart


--
Bart Broersma
broersma.juda_ANTISPAM_@tiscali.nl
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
Reply With Quote
  #5  
Old 08-28-2008, 07:23 AM
Schjaer
Guest
 
Default Re: Correct screen colors not restored after exiting a pascal program

"Jim Leonard" <MobyGamer@gmail.com> wrote in message
news:a186b1b0-ec00-4eab-8b0f-22d2c39ce821@56g2000hsm.googlegroups.com...
> On Aug 22, 6:51 am, "Schjaer" <j...@nospambyg.dtu.dk> wrote:
>> Hi group
>>
>> After exiting a DOS program that manipulates the screen colors I
>> sometimes
>> (but not always) don't get the same colors back that existed before
>> invoking
>> the program. I have tried to save then restore TextAttr within the
>> program
>> but that seems to have no effect. I have observed this in both Turbo
>> Pascal
>> 7.0 and FreePascal. It seems to be a question of sheer luck if the
>> original
>> screen colors are restored or not at exit. Any suggestions?

>
> Incorrect colors are the result of MS-DOS painting just the characters
> while leaving the color attributes alone.


But what colors does MS-DOS use to paint the characters?

>Your DOS program probably
> recolors the entire screen, then dumps you at the prompt without
> cleaning up.


No, I save TextAttr upon entry then restore it just before exit.


Reply With Quote
  #6  
Old 08-28-2008, 07:26 AM
Schjaer
Guest
 
Default Re: Correct screen colors not restored after exiting a pascal program

"winston19842005" <bjjlyates@NOSPAMbellsouth.net> wrote in message
news:C4D471FD.81D8%bjjlyates@NOSPAMbellsouth.net.. .
> On 8/22/08 7:51 AM, in article g8m988$h8h$1@news.net.uni-c.dk, "Schjaer"
> <jsj@nospambyg.dtu.dk> wrote:
>
>> Hi group
>>
>> After exiting a DOS program that manipulates the screen colors I
>> sometimes
>> (but not always) don't get the same colors back that existed before
>> invoking
>> the program. I have tried to save then restore TextAttr within the
>> program
>> but that seems to have no effect. I have observed this in both Turbo
>> Pascal
>> 7.0 and FreePascal. It seems to be a question of sheer luck if the
>> original
>> screen colors are restored or not at exit. Any suggestions?
>>
>> Jorgen
>>
>>

> It might help to know the OS.


It seems to be a problem only under genuine DOS (6.22), not under Windows
DOS-prompt.

> I've noticed programs that did not exhibit this behavior under Windows
> versions prior to XP did not exhibit this behavior, whereas the same
> program
> (same configuration) run under "DOS" under XP or Vista sometimes have
> strange color changes.


So far I have noticed it only under real DOS.


Reply With Quote
  #7  
Old 08-28-2008, 07:35 AM
Schjaer
Guest
 
Default Re: Correct screen colors not restored after exiting a pascal program

"Bart" <broersma.juda_ANTISPAM_@tiscali.nl> wrote in message
news:0192b45eiuafcrihmvs3aarrh956ebchg6@4ax.com...
> Op Fri, 22 Aug 2008 13:51:35 +0200 schreef "Schjaer"
> <jsj@nospambyg.dtu.dk>:
>
>>Hi group
>>
>>After exiting a DOS program that manipulates the screen colors I sometimes
>>(but not always) don't get the same colors back that existed before
>>invoking
>>the program. I have tried to save then restore TextAttr within the program
>>but that seems to have no effect. I have observed this in both Turbo
>>Pascal
>>7.0 and FreePascal. It seems to be a question of sheer luck if the
>>original
>>screen colors are restored or not at exit. Any suggestions?
>>
>>Jorgen
>>

> Do you save and restore the current videomode?
>
> In plain DOS...
>
> var CurrentMode: Byte Absolute $0000:$0449;
> SavedMode: Byte;
>
> Somewhere at startup
> ...
> SavedMode := CurrentMode;
> ...
>
>
> Somewhre at cleanup in the end
>
> ...
> if CurrentMode <> VMode then TextMode(SavedMode);


I can't use the TextMode procedure because it clears the screen. Besides,
according to the TP 7 manual it hasn't got anything to do with colors, only
with the number of screen lines, etc. Do you think it affects the colors
after exiting a Pascal program?


Reply With Quote
  #8  
Old 08-28-2008, 10:57 AM
Marco van de Voort
Guest
 
Default Re: Correct screen colors not restored after exiting a pascal program

On 2008-08-28, Schjaer <jsj@nospambyg.dtu.dk> wrote:
>>> screen colors are restored or not at exit. Any suggestions?

>>
>> Incorrect colors are the result of MS-DOS painting just the characters
>> while leaving the color attributes alone.

>
> But what colors does MS-DOS use to paint the characters?


As far as I can remember, it uses some attribute to fill new lines when the
screen scrolls up, and just prints characters without changing the attribute
otherwise.

One of the reasons that in BBS times people often had ansi.sys loaded, and
an ansi escape sequence setting the attribute in their (4dos) prompt.

>>Your DOS program probably
>> recolors the entire screen, then dumps you at the prompt without
>> cleaning up.

>
> No, I save TextAttr upon entry then restore it just before exit.


And what "textattr" is this? The Crt one is just a variable for internal
use. Afaik it doesn't correspond with some systemwide value.
Reply With Quote
  #9  
Old 08-28-2008, 01:42 PM
Jim Leonard
Guest
 
Default Re: Correct screen colors not restored after exiting a pascal program

On Aug 28, 6:23*am, "Schjaer" <j...@nospambyg.dtu.dk> wrote:
> "Jim Leonard" <MobyGa...@gmail.com> wrote in message
>
> news:a186b1b0-ec00-4eab-8b0f-22d2c39ce821@56g2000hsm.googlegroups.com...
>
>
>
> > On Aug 22, 6:51 am, "Schjaer" <j...@nospambyg.dtu.dk> wrote:
> >> Hi group

>
> >> After exiting a DOS program that manipulates the screen colors I
> >> sometimes
> >> (but not always) don't get the same colors back that existed before
> >> invoking
> >> the program. I have tried to save then restore TextAttr within the
> >> program
> >> but that seems to have no effect. I have observed this in both Turbo
> >> Pascal
> >> 7.0 and FreePascal. It seems to be a question of sheer luck if the
> >> original
> >> screen colors are restored or not at exit. Any suggestions?

>
> > Incorrect colors are the result of MS-DOS painting just the characters
> > while leaving the color attributes alone.

>
> But what colors does MS-DOS use to paint the characters?


It doesn't use color, it only prints characters. That's why, if the
screen was recolored, the characters will show up using the previous
coloring.

> >Your DOS program probably
> > recolors the entire screen, then dumps you at the prompt without
> > cleaning up.

>
> No, I save TextAttr upon entry then restore it just before exit.


That's internal to CRT only.

What you should be doing is saving the screen contents when starting,
then restoring them on exit (along with the correct screen mode and
cursor location).
Reply With Quote
  #10  
Old 09-01-2008, 08:07 AM
Schjaer
Guest
 
Default Re: Correct screen colors not restored after exiting a pascal program

"Jim Leonard" <MobyGamer@gmail.com> wrote in message
news:73c1404a-b9eb-4690-8e14-7d2c50b4705b@k37g2000hsf.googlegroups.com...
On Aug 28, 6:23 am, "Schjaer" <j...@nospambyg.dtu.dk> wrote:
> "Jim Leonard" <MobyGa...@gmail.com> wrote in message
>
> news:a186b1b0-ec00-4eab-8b0f-22d2c39ce821@56g2000hsm.googlegroups.com...
>
>
>
> > On Aug 22, 6:51 am, "Schjaer" <j...@nospambyg.dtu.dk> wrote:
> >> Hi group

>
> >> After exiting a DOS program that manipulates the screen colors I
> >> sometimes
> >> (but not always) don't get the same colors back that existed before
> >> invoking
> >> the program. I have tried to save then restore TextAttr within the
> >> program
> >> but that seems to have no effect. I have observed this in both Turbo
> >> Pascal
> >> 7.0 and FreePascal. It seems to be a question of sheer luck if the
> >> original
> >> screen colors are restored or not at exit. Any suggestions?

>
> > Incorrect colors are the result of MS-DOS painting just the characters
> > while leaving the color attributes alone.

>
> But what colors does MS-DOS use to paint the characters?


It doesn't use color, it only prints characters. That's why, if the
screen was recolored, the characters will show up using the previous
coloring.

> >Your DOS program probably
> > recolors the entire screen, then dumps you at the prompt without
> > cleaning up.

>
> No, I save TextAttr upon entry then restore it just before exit.


That's internal to CRT only.

What you should be doing is saving the screen contents when starting,
then restoring them on exit (along with the correct screen mode and
cursor location).

That sounds like the solution. How does one do that?

Jorgen


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 04:15 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.