home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / multtsk / cpm25d / glasstty.inc < prev    next >
Text File  |  1994-04-28  |  11KB  |  454 lines

  1. {--------------------------------------------------------------------------
  2.  
  3. GLASSTTY.INC  (GlassTTY include file; see GLASSTTY.PAS)
  4.  
  5. This program requires the CPMULTI Multitasking Toolkit and Turbo Pascal
  6. 5.0 or later.
  7.  
  8. January 1994
  9.  
  10. Copyright (C) 1994 (USA)        Copyright (C) 1989-1994
  11. Hypermetrics                    Christian Philipps Software-Technik
  12. PO Box 9700 Suite 363           Duesseldorfer Str. 316
  13. Austin, TX  78758-9700          D-47447 Moers
  14.                                 Germany
  15.  
  16. ---------------------------------------------------------------------------}
  17.  
  18. const MaxValues   = 9;   { Maximum number of possible selectable values. }
  19.       MaxFields   = 5;   { Maximum number of fields. }
  20.       MaxCommLen  = 20;  { Maximum length of a field identifier. }
  21.       MaxFieldLen = 30;  { Maximum length of data. }
  22.       Up          = #72;
  23.       Down        = #80;
  24.       Tab         = #9;
  25.       CR          = #13;
  26.       Esc         = #27;
  27.       BTab        = #15;
  28.       F1          = #59;
  29.       F2          = #60;
  30.       ExitChars   : set of Char = [Esc,F1,F2];  
  31.                     { Characters which terminate the selection routines. }
  32.  
  33.       Ports       : array[1..2] of ComType
  34.                   = (Com1,Com2);
  35.       BaudRate    : array[1..9] of BaudType
  36.                   = (b110,b150,b300,b600,b1200,b2400,b4800,b9600,b19200);
  37.       Parity      : array[1..5] of ParityType
  38.                   = (Space,Odd,Mark,Even,None);
  39.       DataBits    : array[1..4] of DataBitsType
  40.                   = (d5,d6,d7,d8);
  41.       StopBits    : array[1..2] of StopBitsType
  42.                   = (s1,s2);
  43.  
  44. type  CommentType = string[MaxCommLen];
  45.       ValueType   = string[MaxFieldLen];
  46.       Str80       = string[80];
  47.       FieldType   = record
  48.                       Row     : Byte;         { Screen row. }
  49.                       Column  : Byte;         { Start of field identifier. }
  50.                       Comment : CommentType;  { Field identifier. }
  51.                       BarLen  : Byte;         { Length of the color bar. }
  52.                       Value   : Byte;         { Count of selectable values. }
  53.                                               { or BufLen input fields. }
  54.                       Current : Byte;         { Index of actual value. }
  55.                       Inp     : Boolean;      { Marker for input fields. }
  56.                       Data    : array[1..MaxValues] of ValueType;
  57.                     end;
  58.  
  59. var   Selection   : Byte;                     { Number of actual choices. }
  60.       Selects     : array[1..MaxFields] of FieldType;
  61.       SpecialChar : Boolean;                  { Marker for DoReadKey. }
  62.  
  63. {--------------------------------------------------------------------------}
  64.  
  65. function DoReadKey:Char;
  66.  
  67. { Keyboard input without blocking multitasking. }
  68.  
  69. var  C : Char;
  70.  
  71. begin
  72.   repeat Sleep(1); until KeyPressed;
  73.   C := ReadKey;
  74.   if C = #0 then 
  75.   begin
  76.     C := ReadKey;
  77.     SpecialChar := True;
  78.   end
  79.   else
  80.     SpecialChar := False;
  81.   DoReadKey := C;
  82. end;
  83.  
  84. {-----------------------------------------------------------------------------}
  85.  
  86. function IsColor : Boolean;
  87.  
  88. { This function returns True, if a color graphics adapter is installed;
  89.   a register structure Regs is needed. }
  90.  
  91. begin
  92.   with Regs do
  93.   begin
  94.     AH := 15;
  95.     Intr($10,Regs);
  96.     IsColor := (AL <> 7);
  97.   end;
  98. end;
  99.  
  100. {-----------------------------------------------------------------------------}
  101.  
  102. procedure CursorOff;
  103.  
  104. { Turns the cursor off; needs the function IsColor. }
  105.  
  106. begin
  107.   with Regs do
  108.   begin
  109.     if IsColor then 
  110.     begin 
  111.       CH := 9;
  112.       CL := 10;
  113.     end
  114.     else 
  115.     begin 
  116.       CH := 31;
  117.       CL := 32;
  118.     end;
  119.     AH := 1;
  120.   end;
  121.   Intr($10,Regs);
  122. end;
  123.  
  124. {-----------------------------------------------------------------------------}
  125.  
  126. procedure CursorOn;
  127.  
  128. { Restores a normal cursor; needs the function IsColor. }
  129.  
  130. begin
  131.   with Regs do
  132.   begin 
  133.     if IsColor then 
  134.     begin 
  135.       CH := 6;
  136.       CL := 7;
  137.     end
  138.     else 
  139.     begin 
  140.       CH := 11;
  141.       CL := 12;
  142.     end;
  143.     AH := 1;
  144.   end;
  145.   Intr($10,Regs);
  146. end;
  147.  
  148. {-----------------------------------------------------------------------------}
  149.  
  150. procedure ReverseVideo;
  151.  
  152. { Enables reverse video. }
  153.  
  154. begin
  155.   TextColor(0);
  156.   TextBackground(7);
  157. end;
  158.  
  159. {-----------------------------------------------------------------------------}
  160.  
  161. procedure DrawBar(SelectNo : Byte);
  162.  
  163. { Generates a color bar according to field SelectNo. }
  164.  
  165. begin
  166.   with Selects[SelectNo] do
  167.   begin 
  168.     GotoXY(Column,Row);
  169.     ReverseVideo;
  170.     Write(Copy(Comment,1,BarLen));
  171.     LowVideo;
  172.   end;
  173. end;
  174.  
  175. {-----------------------------------------------------------------------------}
  176.  
  177. procedure HighVideo;
  178.  
  179. begin 
  180.   TextColor(15);
  181.   TextBackground(0);
  182. end;
  183.  
  184. {-----------------------------------------------------------------------------}
  185.  
  186. procedure LowVideo;
  187.  
  188. begin 
  189.   TextColor(7);
  190.   TextBackground(0);
  191. end;
  192.  
  193. {-----------------------------------------------------------------------------}
  194.  
  195. procedure RemoveBar(SelectNo : Byte);
  196.  
  197. { Removes the color bar again. }
  198.  
  199. begin
  200.   with Selects[SelectNo] do
  201.   begin 
  202.     GotoXY(Column,Row);
  203.     LowVideo;
  204.     Write(Copy(Comment,1,BarLen));
  205.   end;
  206. end;
  207.  
  208. {-----------------------------------------------------------------------------}
  209.  
  210. procedure PrintSelection(SelectNo : Byte);
  211.  
  212. { Output the actual values for the field SelectNo. }
  213.  
  214. begin
  215.   with Selects[SelectNo] do
  216.   begin 
  217.     GotoXY(Column+Byte(Comment[0]),Row);
  218.     HighVideo;
  219.     Write(Data[Current]);
  220.     LowVideo;
  221.   end;
  222. end;
  223.  
  224. {-----------------------------------------------------------------------------}
  225.  
  226. function Replicate(C:Char;Count:Byte):Str80;
  227.  
  228. { Needs a type declaration Str80:string[80]. }
  229.  
  230. var   N : Byte;
  231.       Z : Str80;
  232.  
  233. begin
  234.   Z[0] := Chr(Count);
  235.   FillChar(Z[1],Count,C);
  236.   Replicate := Z;
  237. end;
  238.  
  239. {-----------------------------------------------------------------------------}
  240.  
  241. procedure PadValueArea(SelectNo:Byte; C:Char);
  242.  
  243. { Fill the data area for the input field SelectNo. }
  244.  
  245. begin
  246.   with Selects[SelectNo] do
  247.   begin 
  248.     GotoXY(Column+Byte(Comment[0]),Row);
  249.     Write(Replicate(C,Value));
  250.   end;
  251. end;
  252.  
  253. {-----------------------------------------------------------------------------}
  254.  
  255. procedure DoInput(SelectNo : Byte);
  256.  
  257. var AuxField : ValueType;
  258.  
  259. begin
  260.   with Selects[SelectNo] do
  261.   begin 
  262.     HighVideo;
  263.     PadValueArea(SelectNo,'.');
  264.     Current := 1;              { Make sure. }
  265.     GotoXY(Column+Byte(Comment[0]),Row);
  266.     CursorOn;
  267.     Read(AuxField);
  268.     CursorOff;
  269.     if Byte(AuxField[0]) > 0 then 
  270.       Data [1] := AuxField;
  271.     PadValueArea(SelectNo,' ');
  272.     LowVideo;
  273.     PrintSelection(SelectNo);
  274.   end;
  275. end;
  276.  
  277. {-----------------------------------------------------------------------------}
  278.  
  279. procedure InitSelection;
  280.  
  281. { Initialize the field parameters. }
  282.  
  283. begin
  284.   with Selects[1] do
  285.   begin 
  286.     Row := 6;
  287.     Column := 10;
  288.     Comment := 'Com-Port........:  ';
  289.     BarLen := 17;
  290.     Value := 2;
  291.     Current := 1;
  292.     Inp := False;
  293.     Data [1] := 'Com1:';
  294.     Data [2] := 'Com2:';
  295.   end;
  296.  
  297.   with Selects[2] do
  298.   begin 
  299.     Row := 7;
  300.     Column := 10;
  301.     Comment := 'Transfer rate...:  ';
  302.     BarLen := 17;
  303.     Value := 9;
  304.     Current := 8;
  305.     Inp := False;
  306.     Data [1] := '110  ';
  307.     Data [2] := '150  ';
  308.     Data [3] := '300  ';
  309.     Data [4] := '600  ';
  310.     Data [5] := '1200 ';
  311.     Data [6] := '2400 ';
  312.     Data [7] := '4800 ';
  313.     Data [8] := '9600 ';
  314.     Data [9] := '19200';
  315.   end;
  316.  
  317.   with Selects[3] do
  318.   begin 
  319.     Row := 8;
  320.     Column := 10;
  321.     Comment := 'Parity..........:  ';
  322.     BarLen := 17;
  323.     Value := 5;
  324.     Current := 5;
  325.     Inp := False;
  326.     Data [1] := 'Space';
  327.     Data [2] := 'Odd  ';
  328.     Data [3] := 'Mark ';
  329.     Data [4] := 'Even ';
  330.     Data [5] := 'None ';
  331.   end;
  332.  
  333.   with Selects[4] do
  334.   begin 
  335.     Row := 9;
  336.     Column := 10;
  337.     Comment := 'Data bits.......:  ';
  338.     BarLen := 17;
  339.     Value := 4;
  340.     Current := 4;
  341.     Inp := False;
  342.     Data [1] := '5';
  343.     Data [2] := '6';
  344.     Data [3] := '7';
  345.     Data [4] := '8';
  346.   end;
  347.  
  348.   with Selects[5] do
  349.   begin 
  350.     Row := 10;
  351.     Column := 10;
  352.     Comment := 'Stop bits.......:  ';
  353.     BarLen := 17;
  354.     Value := 2;
  355.     Current := 1;
  356.     Inp := False;
  357.     Data [1] := '1';
  358.     Data [2] := '2';
  359.   end;
  360. end;
  361.  
  362. {-----------------------------------------------------------------------------}
  363.  
  364. procedure SetupScreen;
  365.  
  366. { Build the screen mask. }
  367.  
  368. begin
  369.   ClrScr;
  370.   GotoXY(15,1);
  371.   Writeln('GlassTTY V1.00 (c) C. Philipps, March 1989');
  372.   GotoXY(15,2);
  373.   Writeln('============================================');
  374.   for Selection := 1 to MaxFields do
  375.   begin 
  376.     RemoveBar(Selection);
  377.     PrintSelection(Selection);
  378.   end;
  379.   GotoXY(12,21);
  380.   Writeln('Select input fields by using tab and backtab;');
  381.   GotoXY(12,22);
  382.   Writeln('Choose from the possible parameters by using the cursor keys.');
  383.   GotoXY(20,24);
  384.   HighVideo;
  385.   Writeln('F1 = Terminal mode  /  Esc = Exit');
  386. end;
  387.  
  388. {-----------------------------------------------------------------------------}
  389.  
  390. function DoSelect(Start:Byte) : Char;
  391.  
  392. { Begins with the selection mask of the field Start and returns the end-key
  393.   (CR or Esc). }
  394.  
  395. var C : Char;
  396.  
  397. begin
  398.   if Start in [1..MaxFields] then 
  399.     Selection := Start
  400.   else 
  401.     Selection := 1;
  402.   CursorOff;
  403.   DrawBar(Selection);
  404.   repeat
  405.     C := DoReadKey;
  406.     if SpecialChar then 
  407.       case C of
  408.         BTab: begin 
  409.                 RemoveBar(Selection);
  410.                 Selection := Pred(Selection);
  411.                 if Selection < 1 then 
  412.                   Selection := MaxFields;
  413.                 DrawBar(Selection);
  414.               end;
  415.         Up:   with Selects[Selection] do
  416.                 if Inp then 
  417.                   DoInput(selection)
  418.                 else 
  419.                   with Selects[Selection] do
  420.                   begin 
  421.                     Current := Pred(Current);
  422.                     if not (Current in [1..Value]) then 
  423.                       Current := Value;
  424.                     if Value > 1 then 
  425.                       PrintSelection(Selection);
  426.                   end;
  427.         Down: with Selects[Selection] do
  428.                 if Inp then 
  429.                   DoInput(selection)
  430.                 else 
  431.                   with Selects[Selection] do
  432.                   begin 
  433.                     Current := Succ(Current);
  434.                     if not (Current in [1..Value]) then 
  435.                       Current := 1;
  436.                     if Value > 1 then 
  437.                       PrintSelection(Selection);
  438.                   end;
  439.       end
  440.     else
  441.       case C of 
  442.         Tab: begin 
  443.                RemoveBar(Selection);
  444.                Selection := Succ(Selection);
  445.                if Selection > MaxFields then 
  446.                  Selection := 1;
  447.                DrawBar(Selection);
  448.              end;
  449.       end;
  450.   until C in ExitChars;
  451.   CursorOn;
  452.   DoSelect := C;
  453. end;
  454.