home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / maj / swag / savescrn.swg < prev    next >
Text File  |  1993-08-27  |  19KB  |  1 lines

  1. SWAGOLX.EXE (c) 1993 GDSOFT  ALL RIGHTS RESERVED 00010         SCREEN SAVING ROUTINES                                            1      05-28-9313:56ALL                      SWAG SUPPORT TEAM        SAVE1.PAS                IMPORT              12          { ----------------------------------- 1 -------------------------------- }π{π> Does anyone know of an easy way to remember the current screen andπ> then put back when a Program is finished?  What I mean is before theπ> Program clears the screen or Writes to it or whatever, to store theπ> current screen so that it can be restored to how it was before a Programπ> is run?ππ Well you could try directly reading from memory and saving it into some kindπof buffer like this...π}ππVar Buffer : Array[1..4000] of Byte;ππProcedure Save_Screen;πbeginπ  Move(Mem[$B800:0000],Buffer,4000);πend;ππProcedure Restore_Screen;πbeginπ  Move(Buffer,Mem[$B800:0000],4000);πend;ππ{πYou must save the screen in a 4K Array and then put it back whenπthe Program is done.π}ππππ{ ----------------------------------- 2 -------------------------------- }πTypeπ   AScreen = Array[1..4000] of Byte;πVarπ   P : ^AScreen;    {Pointer to the Array}π   Scr : AScreen;ππProcedure SaveScreen;πbeginπ  P := Ptr($B800,$0); {Point to video memory}π  Move(P^,Scr,4000);  {Move the screen into the Array}πend;  {Run this proc at the beginning of the Program}ππProcedure RestoreScreen;πbeginπ  Move(Scr,MEm[$B800 : 0], 4000); {Move the saved screen to video mem}πend; {Call this at the end of your Program}ππ{πThis should do the job of saving the original screen and then restoring it whenπyour Program is doneπ}π                                  2      05-28-9313:56ALL                      SWAG SUPPORT TEAM        SAVE2.PAS                IMPORT              17          {π> Does anyone know of an easy way to remember the currentπ> screen and then put it back when a Program is finished?ππHere's one way to do it:π}ππProgram SaveScr;ππUsesπ  Crt, Dos;ππConstπ  vidseg : Word = $B800;π  ismono : Boolean = False;ππTypeπ  Windowrec = Array [0..4003] ofπ  Byte;ππVarπ  NewWindow : Windowrec;π  c : Char;ππProcedure checkvidseg;πbeginπ  if (mem [$0000 : $0449] = 7) thenπ     vidseg := $B000π  elseπ     vidseg := $B800;π  ismono := (vidseg = $B000);πend;ππProcedure savescreen (Var wind : Windowrec;π  TLX, TLY, BRX, BRY : Integer);πVar x, y, i : Integer;πbeginπ  checkvidseg;π  wind [4000] := TLX;π  wind [4001] := TLY;π  wind [4002] := BRX;π  wind [4003] := BRY;π  i := 0;π  For y := TLY to BRY Doπ    For x := TLX to BRX Doπ    beginπ      InLine ($FA);π      wind [i] := mem [vidseg : (160 * (y - 1) + 2 * (x - 1) ) ];π      wind [i + 1] := mem [vidseg : (160 * (y - 1) + 2 * (x - 1) ) + 1];π      InLine ($FB);π      Inc (i, 2);π    end;πend;ππProcedure setWindow (Var wind : Windowrec; TLX, TLY, BRX, BRY : Integer);πVarπ  i : Integer;πbeginπ  savescreen (wind, TLX, TLY, BRX, BRY);π  Window (TLX, TLY, BRX, BRY);π  ClrScr;πend;ππProcedure removeWindow (wind : Windowrec);πVar TLX, TLY, BRX, BRY, x, y, i : Integer;πbeginπ  checkvidseg;π  Window (1, 1, 80, 25);π  TLX := wind [4000];π  TLY := wind [4001];π  BRX := wind [4002];π  BRY := wind [4003];π  i := 0;π  For y := TLY to BRY Doπ    For x := TLX to BRX Doπ    beginπ      InLine ($FA);π      mem [vidseg : (160 * (y - 1) + 2 * (x - 1) ) ] := wind [i];π      mem [vidseg : (160 * (y - 1) + 2 * (x - 1) ) + 1] := wind [i + 1];π      InLine ($FB);π      Inc (i, 2);π    end;πend;ππbeginπ  TextColor(Yellow);π  GotoXY(1,24);π  Write('Press A Key to Save and Clear Screen...');π  ReadKey;π  setWindow (NewWindow, 1, 1, 80, 25);π  GotoXY(1, 12);π  Write ('Press a key to restore original screen...');π  ReadKey;π  removeWindow (NewWindow);π  GotoXY (1, 24);π  Write('Restored!!!');π  ReadKey;πend.π                                                                   3      05-28-9313:56ALL                      SWAG SUPPORT TEAM        SAVE3.PAS                IMPORT              10          >---------< How to save/restore the whole screen >----------π{$X+}πUses Crt;ππType PScreenBuf = ^TScreenBuf;π     TScreenBuf = Array [1..2000] of Word;ππVar ScreenBuf: PScreenBuf;   { Pointer to actual video ram }π    Scr:       TScreenBuf;   { buffer For screen storage   }π    VideoPort: Word Absolute 0:$463;  { the video port adr }π    i:         Byte;         { :-) you'll always find it   }π                             { in Programs like this :-)   }πbeginπ  if VideoPort = $3D4 thenπ    ScreenBuf := Ptr ($B800,0)        { oh, it's color :-) }π  elseπ    ScreenBuf := Ptr ($B000,0);          { oh no, mono :-( }ππ  Scr := ScreenBuf^;                   {*** SAVE SCREEN ***}ππ  if ReadKey=#0 then ReadKey;           { wait For any key }π  For i:=1 to 60 doπ    Writeln ('Hello guys out there...');  { DESTROY SCREEN }π  if ReadKey=#0 then ReadKey;           { wait For any key }ππ  ScreenBuf^ := Scr;                {*** REStoRE SCREEN ***}ππ  if ReadKey=#0 then ReadKey;           { wait For any key }πend.π>-----------------< Yes! Even tested! >---------------------π                                                                            4      05-28-9313:56ALL                      SWAG SUPPORT TEAM        SAVE4.PAS                IMPORT              15          {πI couldn't find your original message, but you could use this code fragment toπsave and restore a Text-mode screen.π}ππ(* global Vars *)πVarπ   vidSeg : Word;π   oldScr : Array[0..3999] of Byte;ππFunction GetVidSeg : Word;πVarπ   mode : Byte;π   seg  : Word;πbeginπ     seg := 0;π     mode := Mem[0 : $449];π     if (mode = 7) then seg := $B000;π     if (mode <= 3) then seg := $B800;π     if (mode in [4..6]) or (mode > 7) then beginπ        (* the Program is not in the correct Text mode *)π        Halt(1);  (* return errorlevel of 1 *)π     end;π     GetVidSeg := seg;πend;ππ(* main Program *)πbeginπ     vidSeg := GetVidSeg;π     Move(Mem[vidSeg : 0], oldScr[0], SizeOf(oldScr));π     (* the above line copies 4000 Bytes starting at $B000 : 0 For mono.π        or $B800 For colour into the Array 'oldScr' *)π     ClrScr;π     WriteLn('Press ENTER to restore the screen...');π     Readln;π     Move(oldScr[0], Mem[vidSeg : 0], SizeOf(oldScr));π     (* the above line copies the Array to video memory to restore theπ        old screen *)πend.ππ{πAs you can see, video memory starts at offset 0 of either of two segments.  Ifπthe computer is colour, Text screen memory starts at $B800 : 0000 and if theπcomputer is mono/herc, it starts at $B000 : 0000.  It is 4000 Bytes long.  Why?π Because there are 2000 Characters on the screen (80 x 25), and each Characterπgets a colour attribute (foreground, background, (non)blinking).  The top-leftπCharacter, at row 1, column 1, is [vidSeg] : 0, and the next Byte,[vidSeg] : 1,πis the attribute For the Character, so the memory is laid out like this:ππ(offset 0) Char, attr, Char, attr, Char, attr.......Char, attr (offset 3999)π}                                                                                                                   5      05-28-9313:56ALL                      SWAG SUPPORT TEAM        SAVE5.PAS                IMPORT              17          {π>show some help Text or something, and then make it disappearπ>without erasing the Text that the Window overlapped.  In otherπ>Words, there will be a screen full of Text, the Window would openπ>up over some Text display whatever message, and disappear, leavingππThe Text you see displayed on the screen can be captured to a Variableπand subsequently restored through direct screen reads/Writes.  Videoπmemory is located (on most systems) at $B800 For color and $B000 onπmonochrome adapters.  Each screen location consists of two Bytes: 1) theπForeground/background color of the location, and 2) the Character at theπlocation.ππThe following Program Writes a screen full of 'Text', captures thisπscreen to a Variable (VidScreen), Writes over top of the current screen,πthen restores original screen stored in VidScreen.π}πProgram OverLap;πUses Crt;ππConstπ  VidSeg = $B800;     {..$B000 For monochrome}ππTypeπ  VidArray = Array[1..2000] of Word;ππVarπ  VidScreen : VidArray;π  x : Integer;πππProcedure SetScreenColor(back,Fore : Integer);πbeginπ  TextBackGround(back);π  TextColor(Fore);πend;πππbeginπ  SetScreenColor(4,2);                   {.. green on red }π  ClrScr;π  For x := 1 to 25 doπ    begin                                {..Write original screen }π    GotoXY(1,x);π    Write('Text Text Text Text Text Text Text Text Text Text Text '+π           'Text Text Text Text Text');π    end;π  readln;                                {..press enter to cont. }ππ  For x := 1 to 2000 do                  {..store current screen in }π    VidScreen[x] := MemW[VidSeg:x];      {  VidScreen Array }ππ  SetScreenColor(7,0);                   {..black on white }π  GotoXY(38,11);π  WriteLn('HELP');                       {..Write help Text, or }π  GotoXY(38,12);                         {  whatever... }π  WriteLn('HELP');π  GotoXY(38,13);π  WriteLn('HELP');π  readln;                                {..press enter to cont. }ππ  For x := 1 to 2000 do                  {..restore VidScreen Array }π    MemW[VidSeg:x] := VidScreen[x];π  readln;πend.π    6      05-28-9313:56ALL                      SWAG SUPPORT TEAM        SAVE6.PAS                IMPORT              11          {π> I need to be able to create a screen then load it into Video Memory.π> Then load it on to the screen... Does anyone have any routines to doπ> this??? Thanks...ππ      Try the following codesπ}πProgram VidRAMStuff;πUsesπ  Crt;πConstπ  ScreenHeight = 25;π  ScreenWidth = 80;πTypeπ  OneChar = Recordπ    Character : Char;π    Attribute : Byte;π    end;π  RAMBuffer = Array [1..ScreenHeight, 1..ScreenWidth] of OneChar;π  RAMBufPtr = ^RAMBuffer;πVarπ  RowLoop, ColLoop : Byte;π  DataFile : Text;π  VideoRAM : RAMBufPtr;ππbeginπ  If (LastMode = 7) { means that the system is monochrome }π    Thenπ      VideoRAM := Ptr ($B000, $0000) { Segment:Offset address }π    Elseπ      VideoRAM := Ptr ($B800, $0000);π  Assign (DataFile, 'TESTING.TXT');π  ReWrite (DataFile);π  For RowLoop := 1 to ScreenHeight Doπ    beginπ      For ColLoop := 1 to ScreenWidth Doπ        Write (DataFile, VideoRAM^ [RowLoop, ColLoop].Character);π      WriteLn (DataFile);π    end;π  Close (DataFile);π  {************************ File Saved *****************************}π  {* Just add your own code to read in the data File and loaded it *}π  {* back to the screen and you're all set!                        *}π  {*****************************************************************}πend.ππ                   7      05-28-9313:56ALL                      SWAG SUPPORT TEAM        SAVE7.PAS                IMPORT              5           {πwell.. if you don't mind it not being in assembly, i can help..πBTW: your 19?? Byte Array wouldn't store the whole screen.. barely half ofπit. the color Text screen is 4000 Bytes. 2000 Characters + 2000 attributesπof those Characters.π}πTypeπ  screen = Array[1..4000] of Byte;πVarπ  scr : screen Absolute $b800:0000; (* or $B000:0000 For Mono *)π  scrf : File of screen;πbeginπ  assign(scrf,paramstr(1)); (* or Whatever Filename *)π  reWrite(scrf);π  Write(scrf,scr);π  close(scrf);πend.ππ                     8      05-28-9313:56ALL                      SWAG SUPPORT TEAM        SAVE8.PAS                IMPORT              18          {> Basically all I'm asking For are SaveScreen andπ> RestoreScreen Procedures. Procedures capable of justπ> partial screen saves and restores would be even better,π> but anything will do!  :-)π}πProgram SaveScr;ππUsesπ  Crt,π  Dos;ππConstπ  vidseg : Word = $B800;π  ismono : Boolean = False;ππTypeπ  Windowrec = Array [0..4003] Ofπ  Byte;ππVarπ  NewWindow : Windowrec;π  c : Char;ππProcedure checkvidseg;πbeginπ  If (mem [$0000 : $0449] = 7) Thenπ     vidseg := $B000π  Elseπ     vidseg := $B800;π  ismono := (vidseg = $B000);πend;ππProcedure savescreen (Var wind : Windowrec;π  TLX, TLY, BRX, BRY : Integer);πVar x, y, i : Integer;πbeginπ  checkvidseg;π  wind [4000] := TLX;π  wind [4001] := TLY;π  wind [4002] := BRX;π  wind [4003] := BRY;π  i := 0;π  For y := TLY To BRY Doπ      For x := TLX To BRX Doπ          beginπ          InLine ($FA);π          wind [i] := mem [vidseg : (160 * (y - 1) + 2 * (x - 1) ) ];π          wind [i + 1] := mem [vidseg : (160 * (y - 1) + 2 * (x - 1) ) + 1];π          InLine ($FB);π          Inc (i, 2);π          end;πend;ππProcedure setWindow (Var wind : Windowrec;π  TLX, TLY, BRX, BRY : Integer);πVar i : Integer;πbeginπ  savescreen (wind, TLX, TLY, BRX, BRY);π  Window (TLX, TLY, BRX, BRY);π  ClrScr;πend;ππProcedure removeWindow (wind : Windowrec);πVar TLX, TLY, BRX, BRY, x, y, i : Integer;πbeginπ  checkvidseg;π  Window (1, 1, 80, 25);π  TLX := wind [4000];π  TLY := wind [4001];π  BRX := wind [4002];π  BRY := wind [4003];π  i := 0;π  For y := TLY To BRY Doπ      For x := TLX To BRX Doπ          beginπ          InLine ($FA);π          mem [vidseg : (160 * (y - 1) + 2 * (x - 1) ) ] := wind [i];π          mem [vidseg : (160 * (y - 1) + 2 * (x - 1) ) + 1] := wind [i + 1];π          InLine ($FB);π          Inc (i, 2);π          end;πend;ππbeginπ  setWindow (NewWindow, 1, 1, 80, 25);π  GotoXY(1, 12);π  Write ('Press a key to restore original screen...');π  Repeatπ  Until KeyPressed;π  c := ReadKey;π  removeWindow (NewWindow);π  GotoXY (1, 24);πend.ππ{πYou can set the size of the Window to whatever you want, and save/restore asπmany Windows as you have memory available.π}                                                      9      05-28-9313:56ALL                      SWAG SUPPORT TEAM        SAVE9.PAS                IMPORT              27          {π> Basically all I'm asking For are SaveScreen and RestoreScreen Procedures.π> Procedures capable of just partial screen saves and restores would beπ> even better, but anything will do!  :-)π}ππUnit ScrUnit;ππInterfaceππConstπ  MaxPages  = 20;πTypeπ  PageType  = Array [1..50,1..80] Of Word;π  PageArray = Array [1..MaxPages] Of ^PageType;πVarπ  Screen    : ^PageType;π  ScrPages  : PageArray;π  PageInMem : Array [1..MaxPages] Of Boolean;π  VideoMode : ^Byte;π  UseDisk   : Boolean;ππProcedure InitPages(Pages : Byte);πProcedure DeInitPages;πProcedure StoreScreen(Page : Byte);πProcedure RestoreScreen(Page : Byte);ππImplementationπ{$IFNDEF VER70}πConst Seg0040      = $0040;π      SegB000      = $B000;π      SegB800      = $B800;π{$endIF}ππVarπ  MPages       : Byte;π  SaveExitProc : Pointer;ππFunction FStr(Num : LongInt) : String;πVar Dummy : String;πbeginπ  Str(Num,Dummy);π  FStr := Dummy;πend;ππProcedure InitPages;πVarπ  Loop : Byte;πbeginπ  If Pages>MaxPages Thenπ    Pages := MaxPages;π  For Loop:=1 To Pages Doπ  If (MaxAvail>=SizeOf(PageType)) And (Not UseDisk) Thenπ  beginπ    PageInMem[Loop] := True;π    GetMem(ScrPages[Loop],SizeOf(PageType));π  endπ  Elseπ  beginπ    PageInMem[Loop] := False;π    ScrPages[Loop]  := NIL;π  end;π  MPages := Pages;πend;ππProcedure DeInitPages;πVar Loop : Byte;πbeginπ  If MPages>0 Thenπ    For Loop:=MPages DownTo 1 Doπ      If PageInMem[Loop] Thenπ      beginπ        Release(ScrPages[Loop]);π        PageInMem[Loop] := False;π      end;π  MPages := 0;πend;ππProcedure StoreScreen;πVarπ  F : File Of PageType;πbeginπ  If Page<=MPages Thenπ  beginπ    If PageInMem[Page] Thenπ      Move(Screen^,ScrPages[Page]^,SizeOf(PageType))π    Elseπ    beginπ      Assign(F,'SCR'+FStr(Page)+'.$$$');π      ReWrite(F);π      If IOResult=0 Thenπ      beginπ        Write(F,Screen^);π        Close(F);π      end;π    end;π  end;πend;ππProcedure RestoreScreen;πVarπ  F : File Of PageType;πbeginπ  If Page<=MPages Thenπ  beginπ    If PageInMem[Page] Thenπ      Move(ScrPages[Page]^,Screen^,SizeOf(PageType))π    Elseπ    beginπ      Assign(F,'SCR'+FStr(Page)+'.$$$');π      Reset(F);π      If IOResult=0 Thenπ      beginπ        Read(F,Screen^);π        Close(F);π      end;π    end;π  end;πend;ππ{$F+}πProcedure ScreenExitProc;πVarπ  Loop : Byte;π  F    : File;πbeginπ  ExitProc := SaveExitProc;π  If MPages>0 Thenπ    For Loop:=1 To MPages Doπ    beginπ      Assign(F,'SCR'+FStr(Loop)+'.$$$');π      Erase(F);π      If IOResult<>0 Then;π    end;πend;π{$F-}ππbeginπ  VideoMode := Ptr(Seg0040,$0049);π  If VideoMode^=7 Thenπ    Screen := Ptr(SegB000,$0000)π  Elseπ    Screen := Ptr(SegB800,$0000);π  MPages := 0;π  UseDisk := False;π  SaveExitProc := ExitProc;π  ExitProc := @ScreenExitProc;πend.ππ(*πThis simple Unit is able to store up to 20 screens. If there is enough freeπheap all screens are stored to heap which is Really fast. If there is notπenough free heap or UseDisk=True all screens are stored virtually to disk. Thisπmethod isn't very fast, of course, but it helps you to save heap.ππUse this Unit as follows:ππProgram ThisIsMyProgram;πUses Screen;πbeginπ  InitPages(5);        { initialize 5 pages }π  {...}                { this is on you }πend.π*)π                                                                                                                              10     08-27-9321:54ALL                      SEAN PALMER              Graphic Screen Capture   IMPORT              13     R   {π> Does anyone have any code that will go tsr and dump the pixel colors in aπ> 320.256. whatever that mode is into a Text File in the format 200,5,0,0,0,4,π> etc?  just list every pixel followed by a comma?ππThe TSR part would be the hard part, the writing the screen to a Fileπwould be easy.ππI wrote this little prog just now, not incredibly great but mightπactually work and probably will do the job...ππBe careful as it doesn't check For Dos reentrancy and you might hangπyour computer if you try to capture a screen While Dos is doingπsomething else...ππby Sean Palmer,πpublic domainπ}ππProgram capture;πUsesπ  Dos;ππProcedure WriteScrn2File;πVarπ  f    : Text;π  x, y : Word;πbeginπ  assign(f,'CAPTURE.SCR');π  reWrite(f);π  For y := 0 to 199 doπ    For x := 0 to 319 doπ    beginπ      Write(f, mem[$A000 : y * 320 + x], ',');π      if x mod 20 = 0 thenπ        Writeln(f);  {new line every 20 pixels}π    end;π  close(f);πend;ππVarπ  oldIntVec : Procedure;ππ{you need to put a Real check For Dos activity here}ππFunction DosActive : Boolean;πbeginπ  DosActive := False;πend; {assume no and keep fingers crossed! 8)}ππProcedure keyHandler; interrupt;πbeginπ  if port[$60] = 114 then     {if print-screen pressed}π    if not DosActive then {better not press While Dos is doing something}π      WriteScrn2File;π  oldIntVec;  {call old handler}πend;ππbeginπ  getIntVec(9, @oldIntVec);π  setIntVec(9, @newIntVec);π  keep(0);  {go TSR}πend.π