home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / Pascal / 10TLST.ZIP / 10PEEK.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-09-17  |  9.2 KB  |  319 lines

  1. Program TenPeek;
  2. { This program uses the 10NET network function call $14 of the $6F interrupt
  3.   (GetRemoteMemory) provided by 10NET to access first the low memory of
  4.   another node, to find out what video mode it is currently in, and then
  5.   Video memory, to "peek" at their screen and duplicate it locally. It works
  6.   for monochrome, CGA in text or graphics mode, and EGA or VGA in all but
  7.   their highest resolution graphics.
  8.        The parameters that the program expects on startup are as illustrated:
  9.  
  10.        10Peek <Nodename> [<delay>]
  11.  
  12.   where <Nodename> must be currently on the network and available to NetStat,
  13.   and <delay> is an optional number of seconds to delay between refreshes of
  14.   the screen. Whether a delay is selected or not, a refresh can be forced by
  15.   pressing the spacebar.
  16.      This program takes advantage of TURBO Pascal 5.5 graph procedures to put
  17.   the local monitor into the proper mode.
  18.  
  19.    [In the case of high resolution VGA/EGA modes, apparently part of the
  20.   detail of their screen images is not available in their directly accessible
  21.   memory.]
  22.  
  23.   }
  24.  
  25.  
  26.   Uses CRT,DOS,Graph;
  27. TYPE
  28.     VGABuffer = Array[0..32767] of Byte;
  29.  
  30. CONST
  31.    VGARemScreen : Array[0..3] of Word = ($A000,$A800,$B000,$B800);
  32.    VRec : Array[0..3] of ^VGABuffer = (Ptr($A000,0000),Ptr($A800,0000),Ptr($B000,0000),Ptr($B800,0000));
  33. TYPE
  34.    RegRec= Registers;
  35.    Buffer = Byte;
  36.    VidRec = Record
  37.              VMode : Byte;
  38.              ColCount : Integer;
  39.              ScreenPagelength : Word;
  40.              ScreenLoc : Integer;
  41.              CursorPos : Array[1..8] of Array[1..2] of Byte;
  42.              CursorSize : Array[1..2] of Byte;
  43.              DisplayPage : Byte;
  44.              ControllerAddr : Integer;
  45.              CRTMode : Byte;
  46.              PalletteMask : Byte;
  47.           end;
  48.     ScreenBuffer = Array[0..65490] of Char;
  49.     String12 = String[12];
  50.     ScreenRec = Record
  51.                  RNode : String12;
  52.                  SBuffer : ScreenBuffer;
  53.                  VidBuffer : VidRec;
  54.                 end;
  55. VAR
  56.    VGAHi : Boolean;
  57.    CGAScreen : Array[0..4096] of Byte absolute $B800:0000;
  58.    EGAVGAScreen : Array[0..41360] of Byte absolute $A000:0000;
  59.    LocalScreenBuffer : Array[0..4096] of Byte;
  60.    PageOffset,ErrCode : Word;
  61.    VideoMode : Byte;
  62.    GDriver,GMode : Integer;
  63.    PauseCount : Word;
  64.    Test,I,IV,VLength : Integer;
  65.    VidBuffer : VidRec;
  66.    SRec : ^ScreenRec;
  67.    LocalScreen : ^ScreenBuffer;
  68.    RemScreen : Word;
  69.    OneKey : Char;
  70.    LocalVideo : VidRec absolute 0000:$0449;
  71.    Reps : Integer;
  72.    Regs : RegRec;
  73.  
  74. Procedure Save;
  75. Begin
  76.    Move(LocalVideo,VidBuffer,30);
  77.    Repeat until ((Port[$3DA] and 8)=8);
  78.    Move(LocalScreen^,LocalScreenBuffer,4096);
  79. End;
  80.  
  81. Procedure Restore;
  82. Begin
  83.    GDriver:=CGA;
  84.    GMode:=0;
  85.    Case VidBuffer.VMode of
  86.    0..3 : TextMode(VidBuffer.VMode);
  87.    4 : InitGraph(GDriver,GMode,'');
  88.    5 : InitGraph(GDriver,GMode,'');
  89.    6 : InitGraph(GDriver,GMode,'');
  90.    end;
  91.    LocalScreen:=@CGAScreen;
  92.    Repeat until ((Port[$3DA] and 8)=8);
  93.    Move(LocalScreenBuffer,LocalScreen^,4096);
  94.    Move(VidBuffer.CursorPos,LocalVideo.CursorPos,18);
  95. End;
  96.  
  97.  
  98. Procedure GetRemoteMemory(VAR Node : String12; RSeg,ROfs : Word; VAR RLength : Integer;VAR LBuffer);
  99. Begin
  100.    With Regs do
  101.     begin
  102.        AX:=$1400;
  103.        BX:=RSeg;
  104.        CX:=RLength;
  105.        SI:=ROfs;
  106.        DS:=Seg(Node);
  107.        DX:=Ofs(Node)+1;
  108.        While (Length(Node)<12) do Node:=Node+' ';
  109.        DI:=Ofs(LBuffer);
  110.        Intr($6F,Regs);
  111.        If (Flags and 1)>0
  112.        then
  113.         begin
  114.            Writeln(^G,'Error reading remote memory...Halting');
  115.            Halt;
  116.         end;
  117.        RLength:=CX;
  118.     end;
  119. End;
  120.  
  121. Procedure SetVideoMode;
  122. Begin
  123.    Case SRec^.VidBuffer.VMode of
  124.    0..3,7 : Begin
  125.                VGAHi:=False;
  126.                If ((SRec^.VidBuffer.VMode=3) and (SRec^.VidBuffer.ScreenPageLength>4096))
  127.                then
  128.                 begin
  129.                    TextMode(CO80+Font8X8);
  130.                    LocalScreen:=@CGAScreen;
  131.                    RemScreen:=$B800;
  132.                    Reps:=17;
  133.                 end
  134.                else if SRec^.VidBuffer.VMode=7 then TextMode(BW80)
  135.                else TextMode(SRec^.VidBuffer.VMode);
  136.                LocalScreen:=@CGAScreen;
  137.             End;
  138.    4 : Begin
  139.           VGAHi:=False;
  140.           GMode:=0;
  141.           GDriver:=CGA;
  142.           LocalScreen:=@CGAScreen;
  143.        End;
  144.    6 : Begin
  145.           VGAHi:=False;
  146.           GMode:=4;
  147.           GDriver:=CGA;
  148.           LocalScreen:=@CGAScreen;
  149.        End;
  150.    14 : Begin
  151.            VGAHi:=False;
  152.            GMode:=0;
  153.            GDriver:=EGA;
  154.            LocalScreen:=@EGAVGAScreen;
  155.         End;
  156.    16 : Begin
  157.            VGAHi:=True;
  158.            GMode:=1;
  159.            GDriver:=VGA;
  160.            LocalScreen:=@EGAVGAScreen;
  161.         End;
  162.    18,19 : Begin
  163.            VGAHi:=True;
  164.            GMode:=2;
  165.            GDriver:=VGA;
  166.            LocalScreen:=@EGAVGAScreen;
  167.         End;
  168.    End;
  169.    If SRec^.VidBuffer.VMode in [4,6,14,16,18,19]
  170.    then
  171.     begin
  172.        InitGraph(GDriver,GMode,'');
  173.        ErrCode:=GraphResult;
  174.        If ErrCode=0 then VideoMode:=SRec^.VidBuffer.VMode;
  175.     end
  176.    else VideoMode:=SRec^.VidBuffer.VMode;
  177. End;
  178.  
  179. Procedure VideoParms;
  180. Begin
  181.    VLength:=30;
  182.    GetRemoteMemory(SRec^.RNode,0,$449,VLength,SRec^.VidBuffer);
  183.    If VLength<>30 then Halt;
  184. {   ClrScr;
  185.    GotoXY(1,1);
  186.    Writeln('Mode: ',SRec^.VidBuffer.VMode);
  187.    Writeln('Columns: ',SRec^.VidBuffer.ColCount);
  188.    Writeln('Bytes/Page: ',SRec^.VidBuffer.ScreenPageLength);
  189.    Delay(300);
  190.  }  If VideoMode<>SRec^.VidBuffer.VMode
  191.    then SetVideoMode;
  192.    Case SRec^.VidBuffer.VMode of
  193.         0 : Begin
  194.                Reps:=4;
  195.                RemScreen:=$B800;
  196.             End;
  197.         1 : Begin
  198.                Reps:=4;
  199.                RemScreen:=$B800;
  200.             End;
  201.         2 : Begin
  202.                Reps:=8;
  203.                RemScreen:=$B800;
  204.             End;
  205.         3 : If not((SRec^.VidBuffer.VMode=3) and (SRec^.VidBuffer.ScreenPageLength>4096))
  206.             then
  207.              begin
  208.                Reps:=8;
  209.                RemScreen:=$B800;
  210.              End;
  211.         4 : Begin
  212.                Reps:=34;
  213.                RemScreen:=$B800;
  214.             End;
  215.         6 : Begin
  216.                Reps:=34;
  217.                RemScreen:=$B800;
  218.             End;
  219.         7 : Begin
  220.                Reps:=34;
  221.                RemScreen:=$B000;
  222.             End;
  223.         14 : Begin
  224.                Reps:=34;
  225.                RemScreen:=$A000;
  226.              End;
  227.         16 : Begin
  228.                 Reps:=69;
  229.                 RemScreen:=$A000;
  230.              end;
  231.         18,19 : Begin
  232.                 Reps:=69;
  233.                 RemScreen:=$A000;
  234.              End;
  235.  
  236.         else
  237.          begin
  238.         TextMode(CO80);
  239.             ClrScr;
  240.             Writeln('VideoMode= ',SRec^.VidBuffer.VMode);
  241.             Halt;
  242.          end;
  243.    end;
  244.   Move(SRec^.VidBuffer.CursorPos,LocalVideo.CursorPos,18);
  245. end;
  246.  
  247. {Main}
  248. Begin
  249.    If ParamCount=0
  250.    then
  251.     begin
  252.        Writeln(' Syntax : ');
  253.        Writeln('             10Peek <Nodename>');
  254.     end
  255.    else
  256.     begin
  257.        New(SRec);
  258.        VideoMode:=255;
  259.        VGAHi:=False;
  260.        LocalScreen:=@CGAScreen;
  261.        ErrCode:=0;
  262.        SRec^.RNode:=ParamStr(1);
  263.        For I:=1 to Length(SRec^.RNode) do SRec^.RNode[I]:=Upcase(SRec^.RNode[I]);
  264.        PauseCount:=0;
  265.        If Paramcount<2 then Test:=0 else VAL(ParamStr(2),PauseCount,Test);
  266.        If test<>0 then PauseCount:=0;
  267.        PauseCount:=PauseCount*10;
  268.        Save;
  269.        VideoParms;
  270.        Repeat
  271.           OneKey:=#0;
  272.           If (SRec^.VidBuffer.VMode in [0..3])
  273.           then PageOffset:=Integer(SRec^.VidBuffer.DisplayPage)*SRec^.VidBuffer.ScreenPageLength
  274.           else PageOffset:=0;
  275.           If not VGAHi
  276.           then
  277.            begin
  278.               for I:=0 to Reps do
  279.                begin
  280.                   VLength:=470;
  281.                   GetRemoteMemory(SRec^.RNode,RemScreen,I*470+PageOffset,VLength,SRec^.SBuffer[I*470]);
  282.                end;
  283.               Repeat until ((Port[$3DA] and 8)=8);
  284.               Move(SRec^.SBuffer[0],LocalScreen^,(Reps*470)+VLength);
  285.            end
  286.           else for IV:=0 to 3 do
  287.            begin
  288.               Delay(10);
  289.               for I:=0 to Reps do
  290.                begin
  291.                   VLength:=470;
  292.                   GetRemoteMemory(SRec^.RNode,RemScreen,I*470+PageOffset,VLength,SRec^.SBuffer[I*470]);
  293.                end;
  294.               Move(SRec^.SBuffer,VRec[IV]^,32767);
  295.            end;
  296.           Sound(6000);
  297.           Delay(50);
  298.           Nosound;
  299.           Repeat
  300.              If PauseCount<>0
  301.              then
  302.               begin
  303.                  OneKey:=#32;
  304.                  For I:=1 to PauseCount do if not keypressed
  305.                   then delay(100) else
  306.                    begin
  307.                       I:=PauseCount;
  308.                       OneKey:=Readkey;
  309.                    end;
  310.               end
  311.              else OneKey:=Readkey;
  312.              If not (Onekey in [#32,#27]) then Write(#7);
  313.           Until OneKey in [#32,#27];
  314.           If Onekey=#32 then Videoparms;
  315.        Until OneKey=#27;
  316.       Restore;
  317.    end;
  318. End.
  319.