home *** CD-ROM | disk | FTP | other *** search
- {$R-,S-,I-,F-,V-,B-}
- (*
- *******************************************************************************
-
- Screen Save Unit Version 1
-
- Steve Trace
- CompuServe ID 70317,2124
-
- This is a simple unit to allow a programmer the ability to save up to four
- screens to the heap and restore them. Only monochrome and CGA monitors are
- supported.
-
- These routines are useful when using windowing routines and you wish to
- return to the prior window with the cursor placed at it's original position.
- Prior to opening and writing to a window simply call the procedure saveScr.
- When your finished using the window simply call the restoreScr procedure.
-
- In addition to providing these features to the programmer, the unit will
- automatically determine the type of monitor in use, and allocate space on
- the heap for the saved screens. (20,035 bytes of heap space is allocated. No
- check of heap space is made to assure there is available memory. Reduce
- const maxScrs if you crash.) An exit procedure has been incorporated to
- automatically restore the screen and the video mode in use when the program
- was executed.
-
- I encourage others to modify these procedures to accomodate other types of
- monitors.
-
- *******************************************************************************)
-
- unit SaveScr1;
-
- interface
-
- uses crt, dos;
-
- type
- panel = array[1..4000] of byte; { accomodates 80 x 25 text mode }
- scrRec = record
- x,y : byte; { x, y coordinates }
- atr : byte; { text attribute in use }
- up : word; { window coordinates}
- low : word;
- scr : panel; { the screen that is saved }
- end;
-
- const
- maxScrs = 4;
-
- var
- screen : array[0..maxScrs] of ^scrRec; { pointers to saved screens }
- { screen[0] points to screen at start up }
- procedure saveScr(page : byte);
-
- procedure restoreScr(page : byte);
-
- implementation
-
- type
- scrType = (mono,CGA);
-
- var
- monoScr : panel absolute $B000:0000; { pointers to 1st page of }
- CGAscr : panel absolute $B800:0000; { video memory }
- origMode : byte;
- monitor : scrType;
- exitSave : pointer;
-
- procedure saveScr;
-
- begin
- with screen[page]^ do
- begin
- x := whereX; { save cursor coordinates }
- y := whereY;
- up := windMin;
- low := windMax;
- atr := textAttr; { save the text attribute in use }
- case monitor of
- mono : scr := monoScr; { save the screen }
- CGA : scr := CGAscr;
- end;
- end;
- end;
-
- procedure restoreScr;
-
- begin
- with screen[page]^ do
- begin
- case monitor of
- mono : monoScr := scr; { restore the screen }
- CGA : CGAscr := scr;
- end;
- textAttr := atr; { restore the text attribute }
- window(succ(lo(up)),succ(hi(up)),succ(lo(low)),succ(hi(low)));
- { restore the window }
- gotoxy(x,y); { put the cursor back }
- end;
- end;
-
- function videoMode : byte; { returns the video mode }
-
- var
- reg : registers;
-
- begin
- reg.ah := 15; { Int 10H BIOS request for video mode }
- intr($10,reg);
- videoMode := reg.al; { mode returned in al register }
- end;
-
- function typeOfMonitor : scrType;
-
- begin
- if videoMode = 7 then { if mono mode then }
- typeOfMonitor := mono
- else { else make it CGA }
- typeOfMonitor := CGA;
- end;
-
- {$f+}
- procedure scrExit; { exit procedure }
-
- begin
- textMode(origMode); { return to original mode of monitor }
- restoreScr(0); { restore the start up screen }
- exitProc := exitSave; { restore orig exit procedure pointer }
- end;
- {$f-}
-
- var
- page : byte;
-
- begin { initialize unit }
- exitSave := exitProc; { save last exit procedure from chain }
- exitProc := @scrExit; { install scrExit in exit procedure chain }
- for page := 0 to maxScrs do
- begin { allocate & initialize screens }
- new(screen[page]);
- with screen[page]^ do
- begin
- fillchar(screen[page]^,sizeOf(screen[page]^),0);
- x := 1;
- y := 1;
- low := (25 shl 8) + 79;
- end;
- end;
- monitor := typeOfMonitor; { establish monitor type }
- saveScr(0); { save the start up screen }
- origMode := videoMode; { save the original video mode }
- end.