Discussion:
Correct screen colors not restored after exiting a pascal program
(too old to reply)
Schjaer
2008-08-22 11:51:35 UTC
Permalink
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
Jim Leonard
2008-08-22 16:13:21 UTC
Permalink
Post by Schjaer
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.
Schjaer
2008-08-28 11:23:15 UTC
Permalink
Post by Jim Leonard
Post by Schjaer
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?
Post by Jim Leonard
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.
Marco van de Voort
2008-08-28 14:57:05 UTC
Permalink
Post by Schjaer
Post by Jim Leonard
Post by Schjaer
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.
Post by Schjaer
Post by Jim Leonard
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.
Jim Leonard
2008-08-28 17:42:10 UTC
Permalink
Post by Schjaer
Post by Jim Leonard
Post by Schjaer
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.
Post by Schjaer
Post by Jim Leonard
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).
Schjaer
2008-09-01 12:07:27 UTC
Permalink
Post by Schjaer
Post by Jim Leonard
Post by Schjaer
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.
Post by Schjaer
Post by Jim Leonard
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
Dr J R Stockton
2008-09-01 17:35:14 UTC
Permalink
Post by Jim Leonard
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?
<URL:http://www.merlyn.demon.co.uk/programs/shower.pas> does that.
--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
Marco van de Voort
2008-09-01 12:16:44 UTC
Permalink
Post by Jim Leonard
Post by Schjaer
Post by Jim Leonard
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.
IIRC it does partially. In general you are right, but (either dos or bios)
has some color to fill newly inserted lines with.
winston19842005
2008-08-22 17:39:09 UTC
Permalink
Post by Schjaer
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.
Schjaer
2008-08-28 11:26:56 UTC
Permalink
Post by winston19842005
Post by Schjaer
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.
Post by winston19842005
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.
Bart
2008-08-24 09:08:07 UTC
Permalink
Op Fri, 22 Aug 2008 13:51:35 +0200 schreef "Schjaer"
Post by Schjaer
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
***@tiscali.nl
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
Schjaer
2008-08-28 11:35:35 UTC
Permalink
Post by Bart
Op Fri, 22 Aug 2008 13:51:35 +0200 schreef "Schjaer"
Post by Schjaer
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?
e***@gmail.com
2008-09-11 20:09:44 UTC
Permalink
Post by Schjaer
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 TurboPascal
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
See www.trsek.com/pas/trsek procedure put_window, get_window. It's
solve your problem.
TrSek

Loading...