home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / msdos / turbopas / bonus507.arc / TPSWITCH.ARC / TPSWITCH.PAS < prev   
Pascal/Delphi Source File  |  1989-06-16  |  5KB  |  164 lines

  1. {$S-,R-,V-,I-,B-,F+}
  2.  
  3. {$IFNDEF Ver40}
  4.   {$I OPLUS.INC}
  5. {$ENDIF}
  6.  
  7. {*********************************************************}
  8. {*                  TPSWITCH.PAS 1.01                    *}
  9. {*                by TurboPower Software                 *}
  10. {*********************************************************}
  11.  
  12. unit TpSwitch;
  13.   {-Routine for switching screens on dual-display systems}
  14.  
  15. interface
  16.  
  17. uses
  18.   TpCrt;
  19.  
  20. type
  21.   WhichScreen = (Screen1, Screen2);
  22. const
  23.   MonoMode : Word = Mono;
  24.   ColorMode : Word = CO80;
  25. var
  26.   CurrentScreen : WhichScreen;
  27.   HasDualDisplays : Boolean;
  28.  
  29. procedure SwitchScreens(SC : WhichScreen);
  30.   {-Switch from the current screen to the specified screen}
  31.  
  32.   {==================================================================}
  33.  
  34. implementation
  35.  
  36. type
  37.   VidDispDataType =
  38.     record
  39.       { $40:$49 } CrtMode : Byte;
  40.       { $40:$4A } CrtCols : Word;
  41.       { $40:$4C } CrtLen : Word;
  42.       { $40:$4E } CrtStart : Word;
  43.       { $40:$50 } CursorPosn : array[0..7] of Word;
  44.       { $40:$60 } CursorMode : Word;
  45.       { $40:$62 } ActivePage : Byte;
  46.       { $40:$63 } Addr6845 : Word;
  47.       { $40:$65 } CrtModeSet : Byte;
  48.       { $40:$66 } CrtPalette : Byte;
  49.     end;
  50.   EgaTableType = array[1..5] of Byte;
  51.   EgaPtrType = ^EgaSavePtrs;
  52.   EgaSavePtrs = array[1..4] of ^EgaSaveArea;
  53.   EgaSaveArea =
  54.     record
  55.       case Boolean of
  56.         True : (Table : array[0..255] of Byte);
  57.         False : (Pntr : EgaPtrType);
  58.     end;
  59. var
  60.   SaveVidDispTable : array[WhichScreen] of
  61.     record
  62.       Part1 : VidDispDataType;
  63.       Part2 : EgaTableType;
  64.       Part3 : EgaSaveArea;
  65.     end;
  66.   SaveEquipFlag : array[WhichScreen] of Word;
  67.   VidDispTable1 : VidDispDataType absolute $40 : $49;
  68.   VidDispTable2 : EgaTableType absolute $40 : $84;
  69.   VidDispTable3 : EgaPtrType absolute $40 : $A8;
  70.   SaveWindMin, SaveWindMax : array[WhichScreen] of Word;
  71.   EquipFlag : Word absolute $40 : $10;
  72. const
  73.   SwitchedOnce : Boolean = False;
  74.  
  75.   procedure SaveCrtTable(SC : WhichScreen);
  76.     {-Save all three parts of the EGA tables when switching screens.}
  77.   begin
  78.     with SaveVidDispTable[SC] do begin
  79.       Part1 := VidDispTable1; {needed for all adapters}
  80.       if (EnhancedDisplay >= EGA) and (EnhancedDisplay <= VGA) then begin
  81.         {needed only for EGA/VGA}
  82.         Part2 := VidDispTable2;
  83.         Part3.Pntr := VidDispTable3;
  84.       end;
  85.     end;
  86.     SaveWindMin[SC] := WindMin;
  87.     SaveWindMax[SC] := WindMax;
  88.   end;
  89.  
  90.   procedure RestoreCrtTable(SC : WhichScreen);
  91.     {-Restore all three parts of the EGA tables when switching screens}
  92.   begin
  93.     with SaveVidDispTable[SC] do begin
  94.       VidDispTable1 := Part1; {needed for all adapters}
  95.       if (EnhancedDisplay >= EGA) and (EnhancedDisplay <= VGA) then begin
  96.         {needed only for EGA/VGA}
  97.         VidDispTable2 := Part2;
  98.         VidDispTable3 := Part3.Pntr;
  99.       end;
  100.     end;
  101.     WindMin := SaveWindMin[SC];
  102.     WindMax := SaveWindMax[SC];
  103.   end;
  104.  
  105.   procedure SwitchScreens(SC : WhichScreen);
  106.     {-Switch from the current screen to the specified screen}
  107.   begin
  108.     {exit if dual displays not found or we're already on right screen}
  109.     if (SC = CurrentScreen) or (not HasDualDisplays) then
  110.       Exit;
  111.  
  112.     SaveCrtTable(CurrentScreen);
  113.     SaveEquipFlag[CurrentScreen] := EquipFlag;
  114.  
  115.     if SwitchedOnce then begin
  116.       EquipFlag := SaveEquipFlag[SC];
  117.       RestoreCrtTable(SC);
  118.     end
  119.     else begin
  120.       {we haven't switched before--we'll have to reset the video mode}
  121.       if CurrentMode = 7 then begin
  122.         EquipFlag := EquipFlag and $FFEF; {clear bit 4}
  123.         TextMode(ColorMode);
  124.       end
  125.       else begin
  126.         EquipFlag := EquipFlag or $0010; {set bit 4}
  127.         TextMode(MonoMode);
  128.       end;
  129.       SaveEquipFlag[SC] := EquipFlag;
  130.       SaveCrtTable(SC);
  131.       SwitchedOnce := True;
  132.     end;
  133.  
  134.     {we've made the switch}
  135.     CurrentScreen := SC;
  136.  
  137.     {reinitialize TPCRT}
  138.     if Font8x8Selected then
  139.       {this resets everything but WindMin, WindMax, and CheckSnow} ;
  140.   end;
  141.  
  142.   function HasDualDisplaysPrim : Boolean;
  143.     {-Return true if dual displays are installed}
  144.   var
  145.     SaveWord, VSeg : Word;
  146.   begin
  147.     if VideoSegment = $B000 then
  148.       VSeg := $B800
  149.     else
  150.       VSeg := $B000;
  151.     SaveWord := MemW[VSeg:0];
  152.     MemW[VSeg:0] := $5555;
  153.     HasDualDisplaysPrim := (MemW[VSeg:0] = $5555);
  154.     MemW[VSeg:0] := SaveWord;
  155.   end;
  156.  
  157. begin
  158.   {initialize variables}
  159.   HasDualDisplays := HasDualDisplaysPrim;
  160.   CurrentScreen := Screen1;
  161.   SaveEquipFlag[Screen1] := EquipFlag;
  162.   SaveCrtTable(Screen1);
  163. end.
  164.