home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / TPOWER54.ZIP / DEMOSRC.ARC / PREF.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-10  |  21.1 KB  |  730 lines

  1. {$S-,R-,V-,I-,B-,F-}
  2. {$M 2048,0,1000}
  3.  
  4. {$I TPDEFINE.INC}
  5.  
  6. {*********************************************************}
  7. {*                   PREF.PAS 5.07                       *}
  8. {*          Programmer's Quick Reference Chart           *}
  9. {*     An example program for Turbo Professional 5.0     *}
  10. {*        Copyright (c) TurboPower Software 1987.        *}
  11. {* Portions copyright (c) Sunny Hill Software 1985, 1986 *}
  12. {*     and used under license to TurboPower Software     *}
  13. {*                 All rights reserved.                  *}
  14. {*********************************************************}
  15.  
  16. program PREF;
  17.   {-Displays a quick reference chart for PC programmers}
  18.  
  19. uses
  20.   Dos,                       {standard DOS/BIOS routines}
  21.   TpCrt,                     {Turbo Professional CRT unit}
  22.   {$IFDEF UseMouse}
  23.   TpMouse,                   {Turbo Professional mouse routines}
  24.   {$ENDIF}
  25.   TpInt,                     {Turbo Professional ISR management}
  26.   TpTsr,                     {Turbo Professional TSR management}
  27.   TpString;                  {Turbo Professional string handling routines}
  28.  
  29. const
  30.   {** keep the following together to allow easy patching **}
  31.   ModuleName : string[4] = 'PREF'; {module name for standard interface}
  32.  
  33.   OurHotKey : Word = $0513;  {Ctrl + RightShift, 'R'}
  34.  DisableScan : Char = #22;   {scan code for Alt-U, press twice in succession
  35.                             to disable the popup}
  36.   BlinkToggle : Char = #$30; {code for Alt-B, toggle blinking}
  37.   SuppressBlink : Boolean = True; {suppress blinking when displaying attributes?}
  38.   {******************* end of patch area ******************}
  39.  
  40. type
  41.   String3 = string[3];
  42.   String4 = string[4];
  43.   String6 = string[6];
  44.   String7 = string[7];
  45.   String8 = string[8];
  46.   String9 = string[9];
  47.   String10 = string[10];
  48.   String80 = string[80];
  49.   DigitString = string[8];
  50.   ScreenBuffer = array[0..1999] of Word;
  51.   StringPointer = ^String9;
  52.  
  53. const
  54.   {screen messages}
  55.   ProgName : string[45] = 'PREF: Programmer''s Quick Reference Chart 5.07';
  56.   Copyright : string[41] = 'Copyright (c) 1987 by TurboPower Software';
  57.   LoadError : string[22] = 'Unable to install PREF';
  58.  
  59.   {Window border characters}
  60.   LeftTee = #195;            {'├', left T}
  61.   RtTee = #180;              {'┤', right T}
  62.   CrossBar = #196;           {'─', horizontal bar}
  63.  
  64.   {Window coordinates}
  65.   LeftCol = 1;               {leftmost col on screen}
  66.   RtCol = 80;                {rightmost col on screen}
  67.   TopRow = 3;                {top row of window border}
  68.   BotRow = 25;               {bottom row of window border}
  69.  
  70.   {For displaying video attributes}
  71.   ColorBar : string[5] = '* * *'; {for samples of video attributes}
  72.   ColorWheel : array[Black..White] of String8 =
  73.   ('Black   ', 'Blue    ', 'Green   ', 'Cyan    ', 'Red     ', 'Magenta ',
  74.     'Brown   ', 'Lt Gray ', 'Dk Gray ', 'Lt Blue ', 'Lt Green', 'Lt Cyan ',
  75.     'Lt Red  ', 'Pink    ', 'Yellow  ', 'White   ');
  76.  
  77.   {For displaying keys}
  78.   Shift = 'Sh';
  79.   Ctrl = '^';
  80.   Alt : string[3] = 'Alt';
  81.   {For the main display}
  82.   ColumnLabels : string[74] =
  83.   {      1         2         3         4         5         6         7         8
  84.    45678901234567890123456789012345678901234567890123456789012345678901234567890
  85.    xxx  x  xxxxxxxx  xx  xxx  xxx xxxxxx    xxxxx  xxxxxxxx  xxxxxxx  xxxxxxx}
  86.   'Dec Chr  Binary  Hex Ascii Key Extended  Color  Foregrnd  Backgrnd    Mono';
  87.  
  88.   {For translating keystrokes}
  89.   Normal : String8 = ^Q^E^W^X^Z^R^C#27;
  90.   IbmNormal : String8 = #0'H'#0'P'#0'IQ'#0;
  91.   CtrlQs : String4 = ^S^D^R^C;
  92.   IbmCtrlQs : String4 = 'GO'#132'v';
  93.   Esc = #27;
  94.  
  95.   {initialized variables}
  96.   AttrAtTop : Byte = 0;      {value at top of browse window}
  97.   DisableOurselves : Boolean = False; {if true, disable the TSR}
  98. var
  99.   OurScreenBuffer : ScreenBuffer; {for saving the screen}
  100.  
  101.   Span : String80;           {for drawing boxes}
  102.   SpLen : Byte absolute Span; {its length}
  103.   Reverse,                   {reverse video attribute}
  104.   Bright,                    {bright video attribute}
  105.   Highlight,                 {highlight video attribute}
  106.   Dim,                       {dim video attribute}
  107.   FullPage : Byte;           {no. of rows in full page}
  108.   LastLine : Word;           {last attribute that can be displayed at top of screen}
  109.   CtrlQ : Boolean;           {true if ^Q pressed}
  110.   {$IFDEF UseMouse}
  111.   MSP : MouseStatePtr;
  112.   MSPsize : Word;
  113.   ScrollBarPos : Byte;
  114. const
  115.   {scroll bar coordinates}
  116.   ScrollBarUp = 1;           {relative location of the up arrow}
  117.   ScrollBarTop = 2;          {of the top of the bar}
  118.   ScrollBarBot = 20;         {of the bottom of the bar}
  119.   ScrollBarDn = 21;          {of the down arrow}
  120.   ScrollBarHt = 19;          {the height of bar, excluding the arrows}
  121.   {$ENDIF}
  122.  
  123.   {$L PREF.OBJ}
  124.  
  125.   {$F+}
  126.   function EscapeSequence(B : Byte) : StringPointer; external;
  127.   {-Return a pointer to a text string representing extended scan code B}
  128.   {$F-}
  129.  
  130.   procedure Beep;
  131.     {-Ring that obnoxious bell}
  132.   begin
  133.     Write(^G);
  134.   end;
  135.  
  136.   procedure SetAttributes;
  137.     {-Set video attribute variables based on the current video mode}
  138.   var
  139.     MonoColors : Boolean;
  140.   begin
  141.     {set video attributes}
  142.     case CurrentMode of
  143.       2, 7 :
  144.         MonoColors := WhichHerc <> HercInColor;
  145.       else
  146.         MonoColors := False;
  147.     end;
  148.  
  149.     if MonoColors then begin
  150.       Bright := $F;          {white on black}
  151.       Dim := $7;             {light gray on black}
  152.       Highlight := $F;       {white on black}
  153.       Reverse := $70;        {black on light gray}
  154.     end
  155.     else begin
  156.       Bright := $E;          {yellow on black}
  157.       Dim := $7;             {light gray on black}
  158.       Highlight := $F;       {white on black}
  159.       Reverse := $1E;        {yellow on blue}
  160.     end;
  161.  
  162.     TextAttr := Dim;
  163.   end;
  164.  
  165.   function DecimalByte(B : Byte) : DigitString;
  166.     {-Return B in decimal}
  167.   var
  168.     S : string[3];
  169.   begin
  170.     Str(B:3, S);
  171.     DecimalByte := S;
  172.   end;
  173.  
  174.   function Monochrome(A : Byte) : String10;
  175.     {-Return string representing a monochrome attribute}
  176.   const
  177.     MonoStrings : array[0..5] of String7 =
  178.     ('Invis  ', 'Reverse', 'Int Und', 'Intense', 'Dim Und', 'Dim    ');
  179.   var
  180.     AttrType : Byte;
  181.   begin
  182.     case A and 127 of
  183.       0, 8 : AttrType := 0;  {Invisible}
  184.       $70,
  185.       $78 : AttrType := 1;   {Reverse}
  186.     else
  187.       if A and 8 <> 0 then
  188.         if A and 7 = 1 then
  189.           AttrType := 2      {Intense Underline}
  190.         else
  191.           AttrType := 3      {Intense}
  192.       else
  193.         if A and 7 = 1 then
  194.           AttrType := 4      {Dim Underline}
  195.         else
  196.           AttrType := 5;     {Dim}
  197.     end;
  198.     Monochrome := MonoStrings[AttrType];
  199.   end;
  200.  
  201.   function Ascii(A : Byte) : String3;
  202.     {-Return a string representing an ASCII character code}
  203.   const
  204.     AsciiChars : array[0..32] of String3 =
  205.     ('NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS ', 'HT ',
  206.       'LF ', 'VT ', 'FF ', 'CR ', 'SO ', 'SI ', 'DLE', 'DC1', 'DC2', 'DC3',
  207.       'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM ', 'SUB', 'ESC', 'FS ', 'GS ',
  208.       'RS ', 'US ', 'SP ');
  209.   begin
  210.     Ascii := '   ';
  211.     case A of
  212.       0..32 : Ascii := AsciiChars[A];
  213.       33..126 : Ascii[1] := Chr(A);
  214.       127 : Ascii := 'DEL';
  215.     end;
  216.   end;
  217.  
  218.   function RegKey(K : Byte) : String3;
  219.     {-Return a string representing a regular keystroke}
  220.   begin
  221.     RegKey := '   ';
  222.     case K of
  223.       1..31 : begin
  224.                 RegKey[1] := '^';
  225.                 RegKey[2] := Chr(K+64);
  226.               end;
  227.       32 : RegKey := 'SP ';
  228.       33..126 : RegKey[1] := Chr(K);
  229.       127 : RegKey := '^BS';
  230.     end;
  231.   end;
  232.  
  233.   function AuxKey(K : Byte; var A : Byte) : String9;
  234.     {-Return a string representing an auxiliary keystroke}
  235.   const
  236.     Enhanced : array[0..165] of Byte = (
  237.       0, 1, 0, 0, 0, 0, 0, 0, 0, 0, {000-009}
  238.       0, 0, 0, 0, 1, 0, 0, 0, 0, 0, {010-019}
  239.       0, 0, 0, 0, 0, 0, 1, 1, 1, 0, {020-029}
  240.       0, 0, 0, 0, 0, 0, 0, 0, 0, 1, {030-039}
  241.       1, 1, 0, 1, 0, 0, 0, 0, 0, 0, {040-049}
  242.       0, 1, 1, 1, 0, 0, 0, 0, 0, 0, {050-059}
  243.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {060-069}
  244.       0, 0, 0, 0, 0, 0, 1, 0, 0, 0, {070-079}
  245.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {080-089}
  246.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {090-099}
  247.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {100-109}
  248.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {110-119}
  249.       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {120-129}
  250.       0, 0, 0, 1, 1, 1, 1, 1, 1, 1, {130-139}
  251.       1, 1, 1, 1, 1, 1, 1, 1, 1, 0, {140-149}
  252.       0, 1, 1, 1, 0, 1, 1, 1, 0, 1, {150-159}
  253.       1, 1, 1, 1, 0, 1);     {160-165}
  254.   var
  255.     S : String9;
  256.     SLen : Byte absolute S;
  257.   begin
  258.     {convert to a string}
  259.     S := EscapeSequence(K)^;
  260.  
  261.     {pad the end of the string}
  262.     if SLen < 9 then
  263.       FillChar(S[Succ(SLen)], 9-SLen, ' ');
  264.  
  265.     {force length to 9 and return the string}
  266.     SLen := 9;
  267.     AuxKey := S;
  268.  
  269.     {fix the attribute}
  270.     A := Dim;
  271.     case K of
  272.       0..165 : if Boolean(Enhanced[K]) then
  273.                  A := Highlight;
  274.       $E9..$EF : A := Bright;
  275.     end;
  276.   end;
  277.  
  278.   procedure DrawChartLine(Row, A : Byte);
  279.     {-Draw one line in the chart}
  280.   var
  281.     NameAttr, A2 : Byte;
  282.   begin
  283.     {show attribute names as Highlight if blink bit set}
  284.     if (A > 127) and SuppressBlink then
  285.       NameAttr := Highlight
  286.     else
  287.       NameAttr := Dim;
  288.  
  289.     {draw the individual parts of the line}
  290.     FastWrite(DecimalByte(A), Row, 04, Bright);
  291.     FastWrite(Chr(A), Row, 09, Dim);
  292.     FastWrite(BinaryB(A), Row, 12, Dim);
  293.     FastWrite(HexB(A), Row, 22, Bright);
  294.     FastWrite(Ascii(A), Row, 26, Dim);
  295.     FastWrite(RegKey(A), Row, 31, Dim);
  296.     FastWrite(AuxKey(A, A2), Row, 35, A2);
  297.     if SuppressBlink then
  298.       A2 := A and 127
  299.     else
  300.       A2 := A;
  301.     FastWrite(ColorBar, Row, 45, A2);
  302.     FastWrite(ColorWheel[A and $F], Row, 52, NameAttr);
  303.     A2 := A shr 4;
  304.     if SuppressBlink then
  305.       A2 := A2 and $07;
  306.     FastWrite(ColorWheel[A2], Row, 62, NameAttr);
  307.     FastWrite(Monochrome(A), Row, 71, NameAttr);
  308.   end;
  309.  
  310.   {$IFDEF UseMouse}
  311.  
  312.   procedure DrawScrollBar;
  313.     {-Draw the scroll bar used by the mouse}
  314.   const
  315.     ScrollBarPtr : string[1] = ' ';
  316.   var
  317.     S : string[50];
  318.     SLen : Byte absolute S;
  319.   begin
  320.     if not MouseInstalled then
  321.       Exit;
  322.  
  323.     {make raw scroll bar string and display it}
  324.     SLen := ScrollBarHt+2;
  325.     FillChar(S[ScrollBarTop], ScrollBarHt, #176);
  326.     S[ScrollBarUp] := #24;
  327.     S[ScrollBarDn] := #25;
  328.     FastVert(S, TopRow+1, LeftCol+1, Dim);
  329.  
  330.     {calculate ScrollBarPos}
  331.     ScrollBarPos := ScrollBarTop+(AttrAtTop div ((LastLine+1) div ScrollBarHt));
  332.     if ScrollBarPos > ScrollBarBot then
  333.       ScrollBarPos := ScrollBarBot;
  334.  
  335.     {display scroll bar pointer}
  336.     FastWrite(ScrollBarPtr, TopRow+ScrollBarPos, LeftCol+1, Reverse);
  337.     {                       ^- actually (TopRow+1)+(ScrollBarPos-1)}
  338.   end;
  339.  
  340.   {$ENDIF}
  341.  
  342.   procedure DrawFullChart;
  343.     {-Draw the color chart}
  344.   var
  345.     Row : Word;
  346.   begin
  347.     for Row := Succ(TopRow) to Pred(BotRow) do
  348.       DrawChartLine(Row, AttrAtTop+Row-Succ(TopRow));
  349.     {$IFDEF UseMouse}
  350.     DrawScrollBar;
  351.     {$ENDIF}
  352.   end;
  353.  
  354.   procedure DrawScreen;
  355.     {-Draw initial screen}
  356.   begin
  357.     {Draw main box, title, and column labels}
  358.     FrameWindow(LeftCol, 1, RtCol, BotRow, Bright, Reverse, ' '+ProgName+' ');
  359.     FastWrite(ColumnLabels, 2, 4, Bright);
  360.  
  361.     {draw cross bar}
  362.     SpLen := Succ(RtCol-LeftCol);
  363.     FillChar(Span[1], 80, CrossBar);
  364.     Span[1] := LeftTee;
  365.     Span[SpLen] := RtTee;
  366.     FastWrite(Span, TopRow, LeftCol, Bright);
  367.   end;
  368.  
  369.   {$IFDEF UseMouse}
  370.  
  371.   function ReadKeyWord : Word;
  372.     {-Special ReadKeyWord routine that accounts for mouse}
  373.   var
  374.     Key : Word;
  375.     Status : ButtonStatus;
  376.   begin
  377.     if not MouseInstalled then
  378.       ReadKeyWord := TpCrt.ReadKeyWord
  379.     else begin
  380.       Key := $FFFF;
  381.       repeat
  382.         {give priority to real keys}
  383.         if KeyPressed then
  384.           Key := TpCrt.ReadKeyWord
  385.         else if MousePressed then begin
  386.           Key := MouseKeyWord;
  387.           if Key = MouseRt then
  388.             Key := $001B     {ESC}
  389.           else if Key = MouseLft then begin
  390.             if MouseKeyWordY = 1 then
  391.               Key := $4800   {Up}
  392.             else if MouseKeyWordY = ScrollBarDn then
  393.               Key := $5000   {Down}
  394.             else if MouseKeyWordY <> ScrollBarPos then begin
  395.               {scroll display based on scroll bar}
  396.               Key := $FF00;  {special pseudokey}
  397.               if MouseKeyWordY = ScrollBarTop then
  398.                 AttrAtTop := 0
  399.               else if MouseKeyWordY = ScrollBarBot then
  400.                 AttrAtTop := LastLine
  401.               else
  402.                 AttrAtTop :=
  403.                 (MouseKeyWordY-ScrollBarTop)*((LastLine+1) div ScrollBarHt);
  404.             end;
  405.           end;
  406.         end
  407.         else
  408.           {give other TSR's a chance to pop up}
  409.           inline($cd/$28);
  410.       until Key <> $FFFF;
  411.       ReadKeyWord := Key;
  412.     end;
  413.   end;
  414.  
  415.   function ReadKey : Char;
  416.     {-Special ReadKey routine that accounts for mouse}
  417.   const
  418.     ScanCode : Char = #0;
  419.   var
  420.     Key : Word;
  421.   begin
  422.     if ScanCode <> #0 then begin
  423.       {return the scan code}
  424.       ReadKey := ScanCode;
  425.       ScanCode := #0;
  426.     end
  427.     else begin
  428.       {get the next keystroke}
  429.       Key := ReadKeyWord;
  430.  
  431.       {return the low byte}
  432.       ReadKey := Char(Lo(Key));
  433.  
  434.       {if it's 0, save the scan code for the next call}
  435.       if Lo(Key) = 0 then
  436.         ScanCode := Char(Hi(Key));
  437.     end;
  438.   end;
  439.  
  440.   {$ENDIF}
  441.  
  442.   function GetCursorCommand : Char;
  443.   {-Get a cursor command. Translate IBM keypad commands to WordStar
  444.     equivalents.}
  445.   var
  446.     C : Char;
  447.     Posn : Byte;
  448.     I : Word;
  449.   begin
  450.     repeat
  451.       CtrlQ := False;
  452.       C := ReadKey;
  453.       if C = #0 then begin
  454.         {translate IBM keypad into WordStar equivalents}
  455.         C := ReadKey;
  456.  
  457.         {see if we're going to disable the TSR}
  458.         if C = #$FF then
  459.           {special mouse command}
  460.           Posn := 1
  461.         else if C = DisableScan then begin
  462.           I := ReadKeyWord;
  463.           if Hi(I) = Ord(DisableScan) then begin
  464.             DisableOurselves := True;
  465.             C := Esc;
  466.             Posn := 1;
  467.           end
  468.           else
  469.             Posn := 0;
  470.         end
  471.         else if C = BlinkToggle then begin
  472.           SuppressBlink := not SuppressBlink;
  473.           SetBlink(SuppressBlink);
  474.           DrawFullChart;
  475.           Posn := 0;
  476.         end
  477.         else begin
  478.           Posn := Pos(C, IbmCtrlQs);
  479.           CtrlQ := Posn <> 0;
  480.           if CtrlQ then
  481.             C := CtrlQs[Posn]
  482.           else begin
  483.             Posn := Pos(C, IbmNormal);
  484.             C := Normal[Posn];
  485.           end;
  486.         end;
  487.       end
  488.       else
  489.         if C = ^Q then begin
  490.           CtrlQ := True;
  491.  
  492.           {read next character}
  493.           C := ReadKey;
  494.  
  495.           {convert 's' and 'S' to ^S, etc.}
  496.           C := Upcase(C);
  497.           if C = #0 then begin
  498.             Posn := 0;
  499.             C := ReadKey;
  500.           end
  501.           else begin
  502.             case C of
  503.               'A'..'Z' : C := Chr(Ord(C)-64);
  504.             end;
  505.             Posn := Pos(C, CtrlQs);
  506.           end;
  507.         end
  508.         else
  509.           Posn := Pos(C, Normal);
  510.     until Posn <> 0;         {wait for valid cursor command or ESC}
  511.     GetCursorCommand := C;
  512.   end;
  513.  
  514.   procedure BrowseThroughChart;
  515.     {-Browse through chart until Done}
  516.   var
  517.     Ch : Char;
  518.   begin
  519.     {initialize screen stuff}
  520.     FullPage := BotRow-TopRow-2;
  521.     LastLine := 255-FullPage;
  522.  
  523.     {draw initial screen}
  524.     Window(LeftCol, 1, RtCol, BotRow);
  525.     ClrScr;
  526.     DrawScreen;
  527.     DrawFullChart;
  528.  
  529.     {$IFDEF UseMouse}
  530.     if MouseInstalled then
  531.       {force the mouse to stay in the far left column of the chart}
  532.       MouseWindow(LeftCol+1, TopRow+1, LeftCol+1, BotRow-1);
  533.     {$ENDIF}
  534.  
  535.     repeat
  536.       Ch := GetCursorCommand;
  537.       if CtrlQ then
  538.         case Ch of
  539.           ^S,
  540.           ^R :               {Home, ^PgUp -- top of chart}
  541.             if AttrAtTop <> 0 then begin
  542.               AttrAtTop := 0;
  543.               DrawFullChart;
  544.             end;
  545.           ^D,
  546.           ^C :               {End, ^PgDn -- bottom of chart}
  547.             if AttrAtTop <> LastLine then begin
  548.               AttrAtTop := LastLine;
  549.               DrawFullChart;
  550.             end;
  551.         end
  552.       else
  553.         case Ch of
  554.           ^E,
  555.           ^W :               {Scroll up}
  556.             if AttrAtTop <> 0 then begin
  557.               Dec(AttrAtTop);
  558.               ScrollWindowDown(LeftCol+2, TopRow+1, RtCol-1, BotRow-1, 1);
  559.               DrawChartLine(Succ(TopRow), AttrAtTop);
  560.               {$IFDEF UseMouse}
  561.               DrawScrollBar;
  562.               {$ENDIF}
  563.             end;
  564.           ^Z,
  565.           ^X :               {Scroll down}
  566.             if AttrAtTop <> LastLine then begin
  567.               Inc(AttrAtTop);
  568.               ScrollWindowUp(LeftCol+2, TopRow+1, RtCol-1, BotRow-1, 1);
  569.               DrawChartLine(Pred(BotRow), AttrAtTop+FullPage);
  570.               {$IFDEF UseMouse}
  571.               DrawScrollBar;
  572.               {$ENDIF}
  573.             end;
  574.  
  575.           ^R :               {PgUp}
  576.             if AttrAtTop <> 0 then begin
  577.               if AttrAtTop < FullPage then
  578.                 AttrAtTop := 0
  579.               else
  580.                 AttrAtTop := AttrAtTop-FullPage;
  581.               DrawFullChart;
  582.             end;
  583.           ^C :               {PgDn}
  584.             if AttrAtTop <> LastLine then begin
  585.               AttrAtTop := AttrAtTop+FullPage;
  586.               if AttrAtTop > LastLine then
  587.                 AttrAtTop := LastLine;
  588.               DrawFullChart;
  589.             end;
  590.           {$IFDEF UseMouse}
  591.           #$FF :             {special mouse command}
  592.             DrawFullChart;
  593.           {$ENDIF}
  594.         end;
  595.     until Ch = Esc;          {Escape}
  596.  
  597.     {check to see if we're disabling the TSR}
  598.     if DisableOurselves then
  599.       if not DisableTSR then begin
  600.         {no go, exit but stay resident and active}
  601.         DisableOurselves := False;
  602.         Write(^G);
  603.       end;
  604.   end;
  605.  
  606.   {$F+}
  607.   procedure PopupEntryPoint(var Regs : Registers);
  608.     {-This is the entry point for the popup}
  609.   var
  610.     SaveXY, SaveSL : Word;   {for saving cursor position and shape}
  611.   begin
  612.     {reinitialize CRT}
  613.     ReInitCrt;
  614.  
  615.     {exit if not in 80-column text mode}
  616.     if InTextMode and (ScreenWidth = 80) then begin
  617.       {initialize screen stuff}
  618.       SetAttributes;
  619.       GetCursorState(SaveXY, SaveSL);
  620.       HiddenCursor;
  621.       MoveScreen(Mem[VideoSegment:0], OurScreenBuffer, 2000);
  622.  
  623.       {$IFDEF UseMouse}
  624.       if MouseInstalled then begin
  625.         {save the state of the mouse driver}
  626.         SaveMouseState(MSP, False);
  627.  
  628.         {reinitialize the mouse}
  629.         InitializeMouse;
  630.  
  631.         {install event handler so MousePressed and MouseKeyWord will work}
  632.         EnableEventHandling;
  633.  
  634.         {we don't want to wait for buttons to be released}
  635.         WaitForButtonRelease := False;
  636.  
  637.         {use the hardware cursor for the mouse}
  638.         BlockMouseCursor;
  639.  
  640.         {make it visible}
  641.         ShowMouse;
  642.       end;
  643.       {$ENDIF}
  644.  
  645.       {show the chart}
  646.       if not SuppressBlink then
  647.         SetBlink(SuppressBlink);
  648.       BrowseThroughChart;
  649.       if not SuppressBlink then
  650.         SetBlink(not SuppressBlink);
  651.  
  652.       {restore cursor and screen}
  653.       RestoreCursorState(SaveXY, SaveSL);
  654.       MoveScreen(OurScreenBuffer, Mem[VideoSegment:0], 2000);
  655.  
  656.       {$IFDEF UseMouse}
  657.       if MouseInstalled then begin
  658.         {disable our event handler}
  659.         DisableEventHandling;
  660.  
  661.         {restore the state of the mouse driver}
  662.         RestoreMouseState(MSP, False);
  663.       end;
  664.       {$ENDIF}
  665.     end
  666.     else
  667.       Beep;
  668.   end;
  669.   {$F-}
  670.  
  671.   procedure Abort(Message : string);
  672.     {-Display Message and Halt with error code}
  673.   begin
  674.     WriteLn(Message);
  675.     Halt(1);
  676.   end;
  677.  
  678. begin
  679.   {smooth scrolling on CGA's}
  680.   BiosScroll := False;
  681.  
  682.   {signon message}
  683.   HighVideo;
  684.   WriteLn(ProgName, ^M^J, Copyright, ^M^J);
  685.   LowVideo;
  686.  
  687.   {check to see if SideKick is loaded}
  688.   if SideKickLoaded then
  689.     Abort('Can''t be loaded after SideKick!');
  690.  
  691.   {check to see if we're already installed}
  692.   if ModuleInstalled(ModuleName) then
  693.     Abort('PREF is already loaded. Aborting...');
  694.  
  695.   {install the module}
  696.   InstallModule(ModuleName, nil);
  697.  
  698.   {$IFDEF UseMouse}
  699.   if MouseInstalled then begin
  700.     {allocate the buffer used to save the state of the mouse}
  701.     MSPsize := MouseStateBufferSize;
  702.  
  703.     {if the size is 0, assume that it's not safe to use the mouse}
  704.     if MSPsize = 0 then
  705.       MouseInstalled := False
  706.     else
  707.       GetMem(MSP, MSPsize);
  708.   end;
  709.   {$ENDIF}
  710.  
  711.   {go resident}
  712.   if DefinePop(OurHotKey, @PopupEntryPoint, Ptr(SSeg, SPtr), True) then begin
  713.     WriteLn('PREF loaded. Press Ctrl-RightShift-R to activate.');
  714.  
  715.     {Enable popups}
  716.     PopupsOn;
  717.  
  718.     {$IFDEF Ver40}
  719.     {restore INT $1B, captured by TPCRT}
  720.     SetIntVec($1B, SaveInt1B);
  721.     {$ENDIF}
  722.  
  723.     {terminate and stay resident}
  724.     if not TerminateAndStayResident(ParagraphsToKeep, 0) then {} ;
  725.   end;
  726.  
  727.   {if we get here we failed}
  728.   Abort(LoadError);
  729. end.
  730.