Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-06

Cross Platform Save/Restore Screen

8 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Preslar

Back in the DOS Turbo Pascal days I could do the following

type
 screentype= array[1..4000] of byte;
 screenptr=^screentype;
var
 screen1: screenptr;
procedure savescreen(scr:byte);
var
 sc1: byte absolute $b000:0;
 sc2: byte absolute $b800:0;
begin;
 if screenaddress=$b000 then move(sc1,screens1^,4000);
 if screenaddress=$b800 then move(sc2,screens1^,4000);
end;
procedure restorescreen(scr:byte);
var
 sc1: byte absolute $b800:0;
 sc2: byte absolute $b000:0;
begin;
 if screenaddress=$b000 then move(screens1^, sc2,4000);
 if screenaddress=$b800 then move(screens1^, sc1,4000);
end;

Now I'm stuck. How can I do the same for Win32 Console apps, and *nix/*bsd console apps?

(For anyone wondering.. I'm the Legend of the Red Dragon developer [remember that old beast?], and after porting LORD to Win32, *nix [and mostly *bsd .. Just need to replace the dependance on the 'oldlinux' unit], and os2, I'm converting LordCfg to a native binary as well, and need the savescreen/restorescreen for the eyecandy part of the program)

Michael Preslar Landline: (402) 614-3551 Cell: (402) 990-8001
Michael Van Canneyt
to Michael Preslar
Michael Preslar wrote 28 lines
Back in the DOS Turbo Pascal days I could do the following type screentype= array[1..4000] of byte; screenptr=^screentype; var screen1: screenptr; procedure savescreen(scr:byte); var sc1: byte absolute $b000:0; sc2: byte absolute $b800:0; begin; if screenaddress=$b000 then move(sc1,screens1^,4000); if screenaddress=$b800 then move(sc2,screens1^,4000); end; procedure restorescreen(scr:byte); var sc1: byte absolute $b800:0; sc2: byte absolute $b000:0; begin; if screenaddress=$b000 then move(screens1^, sc2,4000); if screenaddress=$b800 then move(screens1^, sc1,4000); end; Now I'm stuck. How can I do the same for Win32 Console apps, and *nix/*bsd console apps?

The short answer: You simply can't...

You must use the 'video' unit to do this kind of tricks in a more or less cross-platform way, but you'll have to rewrite your code completely.

You may also want to have a look at the ncurses unit and the various descendents, ocrt, ncrt.

video is documented, and is part of the RTL.
The others are in the packages.

Michael.

Marco van de Voort
to Michael Preslar: Back in the DOS Turbo Pascal days I could do the following type screentype=…
Show quoted text 25 lines
Back in the DOS Turbo Pascal days I could do the following type screentype= array[1..4000] of byte; screenptr=^screentype; var screen1: screenptr; procedure savescreen(scr:byte); var sc1: byte absolute $b000:0; sc2: byte absolute $b800:0; begin; if screenaddress=$b000 then move(sc1,screens1^,4000); if screenaddress=$b800 then move(sc2,screens1^,4000); end; procedure restorescreen(scr:byte); var sc1: byte absolute $b800:0; sc2: byte absolute $b000:0; begin; if screenaddress=$b000 then move(screens1^, sc2,4000); if screenaddress=$b800 then move(screens1^, sc1,4000); end;

(this code would fail even on dos if I set a high resolution 132x60 is 16k)

Now I'm stuck. How can I do the same for Win32 Console apps, and *nix/*bsd console apps?

You can't. Most OSes don't even have a way to read the screen.

So what we do is make a virtual screen using unit "Video". For the OSes that can read the screen we preload the virtual screen with the screen contents, and then we update it with all screenwrites. However for this to work, all I/O must go through it,

Since the unit Video (which is documented btw) is a backend for our Turbo Vision equivalent, it is a bit sparse. To see how the video I/O works, see the demo "lister".

Jonas Maebe
to Michael Preslar: Back in the DOS Turbo Pascal days I could do the following type screentype=…
Michael Preslar wrote
Now I'm stuck. How can I do the same for Win32 Console apps, and *nix/*bsd console apps?

See the user screen unit of the IDE:
http://www.freepascal.org/cgi-bin/viewcvs.cgi/trunk/ide/fpusrscr.pas? rev=3297

(For anyone wondering.. I'm the Legend of the Red Dragon developer [remember that old beast?]

BBS doors! Phone costs were way too high to spend time on things like that, so I've never actually played it. I do remember reading about it in the FidoNet Pascal echo though :)

Jonas

Tomas Hajny
to Michael Preslar: Back in the DOS Turbo Pascal days I could do the following type screentype=…
Michael Preslar wrote
Back in the DOS Turbo Pascal days I could do the following

.
.

Show quoted text 8 lines
Now I'm stuck. How can I do the same for Win32 Console apps, and *nix/*bsd console apps? (For anyone wondering.. I'm the Legend of the Red Dragon developer [remember that old beast?], and after porting LORD to Win32, *nix [and mostly *bsd .. Just need to replace the dependance on the 'oldlinux' unit], and os2, I'm converting LordCfg to a native binary as well, and need the savescreen/restorescreen for the eyecandy part of the program)

Whereas the comments from other people in this thread still apply, the next version of unit Video should provide you with the possibility to save and restore the current screen - still under the condition that the platform and terminal/console allow it (which might require all output to be done via unit Video as well - however, that should include e.g. output done using Crt unit as well). Regarding availability - well, I'm afraid that this might not be before August now (another FPC activity which will take some time from FPC core team members is planned for July - stay tuned :/ ).

Regards

Tomas

Michael Preslar
to Jonas Maebe: See the user screen unit of the IDE: http://www.freepascal.org/cgi-bin/viewcvs.cgi/trunk/i…

Thanks to all for the pointers. The FPC IDE source is definitly useful. Will have to play with that and see what I can come up with..

Thanks again!

Michael Preslar Landline: (402) 614-3551 Cell: (402) 990-8001
Earlier message 28 lines
-----Original Message----- From: On Behalf Of Jonas Maebe Sent: Tuesday, June 20, 2006 10:01 AM To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] Cross Platform Save/Restore Screen On 20 jun 2006, at 16:45, Michael Preslar wrote: > Now I'm stuck. How can I do the same for Win32 Console apps, and > *nix/*bsd console apps? See the user screen unit of the IDE: http://www.freepascal.org/cgi-bin/viewcvs.cgi/trunk/ide/fpusrscr.pas? rev=3297 > (For anyone wondering.. I'm the Legend of the Red Dragon developer > [remember that old beast?] BBS doors! Phone costs were way too high to spend time on things like that, so I've never actually played it. I do remember reading about it in the FidoNet Pascal echo though :) Jonas
Marco van de Voort
to Michael Preslar
Thanks to all for the pointers. The FPC IDE source is definitly useful. Will have to play with that and see what I can come up with..

(note that the IDE is based on FV which is based in turn on units keyboard,video,mouse)

Luiz Americo Pereira Camara
to Michael Preslar: Back in the DOS Turbo Pascal days I could do the following type screentype=…
Michael Preslar wrote 36 lines
Back in the DOS Turbo Pascal days I could do the following type screentype= array[1..4000] of byte; screenptr=^screentype; var screen1: screenptr; procedure savescreen(scr:byte); var sc1: byte absolute $b000:0; sc2: byte absolute $b800:0; begin; if screenaddress=$b000 then move(sc1,screens1^,4000); if screenaddress=$b800 then move(sc2,screens1^,4000); end; procedure restorescreen(scr:byte); var sc1: byte absolute $b800:0; sc2: byte absolute $b000:0; begin; if screenaddress=$b000 then move(screens1^, sc2,4000); if screenaddress=$b800 then move(screens1^, sc1,4000); end; Now I'm stuck. How can I do the same for Win32 Console apps, and *nix/*bsd console apps? (For anyone wondering.. I'm the Legend of the Red Dragon developer [remember that old beast?], and after porting LORD to Win32, *nix [and mostly *bsd .. Just need to replace the dependance on the 'oldlinux' unit], and os2, I'm converting LordCfg to a native binary as well, and need the savescreen/restorescreen for the eyecandy part of the program)

I'm sending a unit that has such functions for win32. I've used this unit in a homebrew console ui "toolkit", but be aware that the last time i compiled it was in fpc106 days so maybe is not compiling in today fpc. Anyway, you can have a idea how implement it. The functions you must look are: SalvarTela(SaveScreen) and RestaurarTela(RestoreScreen).

Luiz