home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / SAVESCR1.ZIP / SAVESCR1.PAS next >
Encoding:
Pascal/Delphi Source File  |  1988-01-28  |  4.8 KB  |  153 lines

  1. {$R-,S-,I-,F-,V-,B-}
  2.                                                                                (*
  3. *******************************************************************************
  4.  
  5. Screen Save Unit Version 1
  6.  
  7. Steve Trace
  8. CompuServe ID 70317,2124
  9.  
  10. This is a simple unit to allow a programmer the ability to save up to four
  11. screens to the heap and restore them.  Only monochrome and CGA monitors are
  12. supported.
  13.  
  14. These routines are useful when using windowing routines and you wish to
  15. return to the prior window with the cursor placed at it's original position.
  16. Prior to opening and writing to a window simply call the procedure saveScr.
  17. When your finished using the window simply call the restoreScr procedure.
  18.  
  19. In addition to providing these features to the programmer, the unit will
  20. automatically determine the type of monitor in use, and allocate space on
  21. the heap for the saved screens. (20,035 bytes of heap space is allocated.  No
  22. check of heap space is made to assure there is available memory.  Reduce
  23. const maxScrs if you crash.)  An exit procedure has been incorporated to
  24. automatically restore the screen and the video mode in use when the program
  25. was executed.
  26.  
  27. I encourage others to modify these procedures to accomodate other types of
  28. monitors.
  29.  
  30. *******************************************************************************)
  31.  
  32. unit SaveScr1;
  33.  
  34.                                  interface
  35.  
  36. uses crt, dos;
  37.  
  38. type
  39.    panel = array[1..4000] of byte;  { accomodates 80 x 25 text mode }
  40.    scrRec = record
  41.                x,y : byte;          { x, y coordinates }
  42.                atr : byte;          { text attribute in use }
  43.                up  : word;          { window coordinates}
  44.                low : word;
  45.                scr : panel;         { the screen that is saved }
  46.             end;
  47.  
  48. const
  49.    maxScrs = 4;
  50.  
  51. var
  52.    screen : array[0..maxScrs] of ^scrRec;  { pointers to saved screens }
  53.                                            { screen[0] points to screen at start up }
  54. procedure saveScr(page : byte);
  55.  
  56. procedure restoreScr(page : byte);
  57.  
  58.                               implementation
  59.  
  60. type
  61.    scrType = (mono,CGA);
  62.  
  63. var
  64.    monoScr  : panel absolute $B000:0000;  { pointers to 1st page of }
  65.    CGAscr   : panel absolute $B800:0000;  { video memory }
  66.    origMode : byte;
  67.    monitor  : scrType;
  68.    exitSave : pointer;
  69.  
  70. procedure saveScr;
  71.  
  72.    begin
  73.       with screen[page]^ do
  74.          begin
  75.             x := whereX;      { save cursor coordinates }
  76.             y := whereY;
  77.             up := windMin;
  78.             low := windMax;
  79.             atr := textAttr;  { save the text attribute in use }
  80.             case monitor of
  81.                mono : scr := monoScr;   { save the screen }
  82.                CGA  : scr := CGAscr;
  83.             end;
  84.          end;
  85.    end;
  86.  
  87. procedure restoreScr;
  88.  
  89.    begin
  90.       with screen[page]^ do
  91.          begin
  92.             case monitor of
  93.                mono : monoScr := scr;  { restore the screen }
  94.                CGA  : CGAscr := scr;
  95.             end;
  96.             textAttr := atr;           { restore the text attribute }
  97.             window(succ(lo(up)),succ(hi(up)),succ(lo(low)),succ(hi(low)));
  98.                    { restore the window }
  99.             gotoxy(x,y);   { put the cursor back }
  100.          end;
  101.    end;
  102.  
  103. function videoMode : byte;   { returns the video mode }
  104.  
  105.    var
  106.       reg : registers;
  107.  
  108.    begin
  109.       reg.ah := 15;        { Int 10H BIOS request for video mode }
  110.       intr($10,reg);
  111.       videoMode := reg.al;   { mode returned in al register }
  112.    end;
  113.  
  114. function typeOfMonitor : scrType;
  115.  
  116.    begin
  117.       if videoMode = 7 then       { if mono mode then }
  118.          typeOfMonitor := mono
  119.       else                        { else make it CGA }
  120.          typeOfMonitor := CGA;
  121.    end;
  122.  
  123. {$f+}
  124. procedure scrExit;         { exit procedure }
  125.  
  126.    begin
  127.       textMode(origMode);      { return to original mode of monitor }
  128.       restoreScr(0);           { restore the start up screen }
  129.       exitProc := exitSave;    { restore orig exit procedure pointer }
  130.    end;
  131. {$f-}
  132.  
  133. var
  134.    page : byte;
  135.  
  136. begin                          { initialize unit }
  137.    exitSave := exitProc;       { save last exit procedure from chain }
  138.    exitProc := @scrExit;       { install scrExit in exit procedure chain }
  139.    for page := 0 to maxScrs do
  140.       begin                    { allocate & initialize screens }
  141.          new(screen[page]);
  142.          with screen[page]^ do
  143.             begin
  144.                fillchar(screen[page]^,sizeOf(screen[page]^),0);
  145.                x := 1;
  146.                y := 1;
  147.                low := (25 shl 8) + 79;
  148.             end;
  149.       end;
  150.    monitor := typeOfMonitor;    { establish monitor type }
  151.    saveScr(0);                  { save the start up screen }
  152.    origMode := videoMode;       { save the original video mode }
  153. end.