home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / sampler / 01 / counter / counter3.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1988-09-09  |  25.3 KB  |  974 lines

  1. {
  2.                        F i l e    I n f o r m a t i o n
  3.  
  4. * DESCRIPTION
  5. Include source code file for COUNTER.PAS.
  6.  
  7. * ASSOCIATED FILES
  8. COUNTER.PAS
  9. COUNTER1.PAS
  10. COUNTER2.PAS
  11. COUNTER3.PAS
  12. COUNTER.EXE
  13.  
  14. }
  15.  
  16.  
  17. {-------------------------------------------------- procedure OpeningScreen }
  18.  
  19. {
  20. purpose: to display the opening screen.
  21. }
  22.  
  23. procedure OpeningScreen;
  24.  
  25. var
  26.  ch:char;
  27.  
  28. begin {procedure OpeningScreen}
  29.  
  30.  clrscr;
  31.  SetTextType(Rev);
  32.  gotoxy(23,1);
  33.  write(' COUNTER version 2.0 (2/15/1988) ');
  34.  SetTextType(High);
  35.  gotoxy(5,3);
  36.  write('This program allows you to define up to 20 keys on your keyboard as');
  37.  gotoxy(5,4);
  38.  write('counters.');
  39.  gotoxy(5,6);
  40.  write('First, you will enter the keys you wish to define.  Note that upper-');
  41.  gotoxy(5,7);
  42.  write('case and lower-case letters are considered DIFFERENT characters.  It');
  43.  gotoxy(5,8);
  44.  write('is not possible to modify the defined keys once the program starts');
  45.  gotoxy(5,9);
  46.  write('running.  If no keys are defined the program terminates execution.');
  47.  gotoxy(5,11);
  48.  write('Second, you will enter a label for each key.  This label may be up');
  49.  gotoxy(5,12);
  50.  write('to 20 characters long.  Once the label(s) are entered they cannot be');
  51.  gotoxy(5,13);
  52.  write('edited.');
  53.  gotoxy(5,15);
  54.  write('Finally, COUNTER is ready to start counting the number of times you');
  55.  gotoxy(5,16);
  56.  write('hit the defined key(s).  You may choose between addition and sub-');
  57.  gotoxy(5,17);
  58.  write('traction mode.  The program is set to start all counters at zero');
  59.  gotoxy(5,18);
  60.  write('and to operate within the range of 0 to 32767.  However, you may');
  61.  gotoxy(5,19);
  62.  write('modify these parameters by setting the appropriate constant values');
  63.  gotoxy(5,20);
  64.  write('in the file ''COUNTER1.PAS'' and recompiling the program with Turbo');
  65.  gotoxy(5,21);
  66.  write('Pascal version 4.0 (or later).');
  67.  gotoxy(5,23);
  68.  write('Only the menu options in ');  SetTextType(Rev);
  69.  write('reverse video');              SetTextType(High);
  70.  write(' are available.  ');          SetTextType(HighUndBlink);
  71.  write('Good Luck!!');
  72.  SetTextType(Rev);
  73.  gotoxy(18,25);
  74.  write(' Hit any key to start COUNTER or <ESC> to quit. ');
  75.  SetTextType(Norm);
  76.  ch:=ReadKey;
  77.  if ch=#27 then halt;
  78.  
  79. end; {procedure OpeningScreen}
  80.  
  81. {------------------------------------------------ procedure DefineKeys }
  82.  
  83. {
  84. purpose: to get the keys that the user wishes to define as counters.
  85. }
  86.  
  87. procedure DefineKeys;
  88.  
  89. var
  90.  ok,InvalidChar:boolean;
  91.  ch,cht:char;
  92.  i,j:byte;
  93.  
  94.  
  95. begin {procedure DefineKeys}
  96.  ok:=false;
  97.  
  98.  clrscr;
  99.  SetTextType(Rev);
  100.  gotoxy(8,3);
  101.  write ('  Type the characters in sequence, with no spaces in between.   ');
  102.  gotoxy(8,4);
  103.  write (' Upper-case and lower-case are considered DIFFERENT characters. ');
  104.  gotoxy(8,5);
  105.  write ('            Terminate input by hitting <ENTER>.                 ');
  106.  SetTextType(Norm);
  107.  
  108.  repeat
  109.   {prompt the user for the keys to be defined}
  110.   gotoxy(1,10); write (' Enter the keys to be used as counters ->');
  111.   InvalidChar:=false;
  112.   {get the string of characters}
  113.   gotoxy(42,10); clreol;
  114.   InputStr(S,20,42,10);
  115.   DefinedKeys:=S;
  116.   if (length(DefinedKeys)<1) then
  117.   begin
  118.    clrscr;
  119.    SetTextType(Rev);
  120.    gotoxy(1,18); write (' COUNTER cannot run without defined keys ');
  121.    gotoxy(1,19); write (' Program execution terminated            ');
  122.    gotoxy(1,20); write (' Strike any key to continue              ');
  123.    ch:=ReadKey;
  124.    SetTextType(Norm);
  125.    CursorOn;
  126.    clrscr;
  127.    Halt;
  128.   end; {if length(DefinedKeys)..}
  129.  
  130.   {check for invalid characters}
  131.   for i:=1 to (length(DefinedKeys)) do
  132.   begin
  133.    ch:=DefinedKeys[i];
  134.    if not (((ch) IN [#65..#90]) or ((ch) IN [#97..#122])
  135.     or ((ch) IN [#48..#57])) then
  136.     InvalidChar:=true;
  137.    CharArray[i]:=ord(ch);
  138.   end; {for i:=1 to...}
  139.  
  140.   {check for repeated characters}
  141.   {sequentialy load the characters into a temporary variable and
  142.    check the following characters for identity}
  143.  
  144.   for i:=1 to (length(DefinedKeys)) do
  145.   begin
  146.    cht:=DefinedKeys[i];
  147.    for j:=i+1 to (length(DefinedKeys)) do
  148.    begin
  149.     ch:=DefinedKeys[j];
  150.     if ch=cht then InvalidChar:=true;
  151.    end; {for j:=i+1 to...}
  152.   end; {for i:=1 to...}
  153.  
  154.   if InvalidChar then
  155.   begin
  156.    InvalidKey;
  157.    SetTextType(RevBlink);
  158.    gotoxy(1,20); write (' Invalid or duplicate characters. ');
  159.    SetTextType(Rev);
  160.    gotoxy(1,21); write (' Strike any key to try again.     ');
  161.    SetTextType(Norm);
  162.    ch:=ReadKey;
  163.    EraseWarning;
  164.   end; {if IvalidChar}
  165.  
  166.   if not InvalidChar then ok:=true;
  167.  until ok;
  168.  
  169.  clrscr;
  170.  ypos:=3;
  171.  
  172.  {get the labels for the defined keys}
  173.  for i:=1 to (length(DefinedKeys)) do
  174.  begin
  175.   ch:=DefinedKeys[i];
  176.   gotoxy(1,ypos); write ('Enter label for ',ch,' :');
  177.   InputStr(S,20,21,ypos);
  178.   LabelArray[i]:=S;
  179.   ypos:=ypos+1;
  180.  end; {for ...}
  181.  
  182. end; {procedure DefineKeys}
  183.  
  184. {------------------------------------------------ procedure ScreenDisplay }
  185.  
  186. {
  187. purpose: to set up the screen display.
  188. }
  189.  
  190. procedure ScreenDisplay;
  191.  
  192. const
  193.  ScreenHeader='              LABEL        KEY   COUNT';
  194.  
  195. var
  196.  i:byte;
  197.  
  198. begin {procedure ScreenDisplay}
  199.  clrscr;
  200.  
  201.  {display the output path and the mode}
  202.  gotoxy(1,1); write ('Active file : ');
  203.  SetTextType(High); write (ActiveFile); SetTextType(Norm);
  204.  gotoxy(1,2); write ('Active path : ');
  205.  SetTextType(High); write (ActivePath); SetTextType(Norm);
  206.  gotoxy(1,3); write ('Mode        : ');
  207.  
  208.  SetTextType(High);
  209.  if Add then
  210.  begin
  211.   gotoxy(15,3); write ('ADDITION');
  212.  end
  213.  else
  214.  begin
  215.   gotoxy(15,3); write ('SUBTRACTION');
  216.  end; {if Add}
  217.  
  218.  {display the headers}
  219.  gotoxy(1,5); write (ScreenHeader);
  220.  if (length(DefinedKeys))>10 then
  221.  begin
  222.   gotoxy(40,5); write (ScreenHeader);
  223.  end; {if length...}
  224.  
  225.  ypos:=7;
  226.  xpos:=1;
  227.  
  228.  {display the labels and the initial values}
  229.  for i:=1 to (length(DefinedKeys)) do
  230.  begin
  231.   gotoxy(xpos,ypos);
  232.   write (LabelArray[i]:20,'  :    ',chr(CharArray[i]):1,'    ',CharCounterArray[i]:5);
  233.   ypos:=ypos+1;
  234.   if ypos>16 then
  235.   begin
  236.    xpos:=40;
  237.    ypos:=7;
  238.   end; {if ypos}
  239.  end; {for ... to (length(DefinedKeys))}
  240.  SetTextType(Norm);
  241.  
  242. end; {procedure ScreenDisplay}
  243.  
  244. {------------------------------------------------ procedure UpDateMenu }
  245.  
  246. {
  247. purpose: to keep the menu up to date.
  248. }
  249.  
  250. procedure UpDateMenu;
  251.  
  252. var
  253.  TempF1,TempF2,TempF3,TempF4,TempF5,TempF6,TempF7,TempF8,Tempf10:boolean;
  254.  i:byte;
  255.  
  256. begin {procedure UpDateMenu}
  257.  
  258.  {check each of the status functions and update those that have changed}
  259.  {F1 and F10 are always on}
  260.  TempF1:=true;
  261.  TempF10:=true;
  262.  
  263.  {F2 and F3 are on only if an element in CharCounterArray is different}
  264.  {from StartCount}
  265.  TempF2:=false;
  266.  TempF3:=false;
  267.  for i:=1 to (length(DefinedKeys)) do
  268.  begin
  269.   if CharCounterArray[i]<>StartCount then
  270.   begin
  271.    TempF2:=true;
  272.    TempF3:=true;
  273.   end; {if CharCounterArray}
  274.  end; {for i:=1 to ...}
  275.  
  276.  {F4 is on if no active file is open}
  277.  if OutPutFileOpen then TempF4:=false else TempF4:=true;
  278.  
  279.  {F5 and F6 are on if an active file is open}
  280.  if OutPutFileOpen then
  281.  begin
  282.   TempF5:=true;
  283.   TempF6:=true;
  284.  end
  285.  else
  286.  begin
  287.   TempF5:=false;
  288.   TempF6:=false;
  289.  end; {if OutPutFileOpen}
  290.  
  291.  {F7 is on if printer is on-line}
  292.  if PrinterOK then TempF7:=true else TempF7:=false;
  293.  
  294.  {F8 is on if no active file is open}
  295.  if OutPutFileOpen then TempF8:=false else TempF8:=true;
  296.  
  297.  
  298.  {update the those whose status has changed}
  299.  
  300.  if TempF1<>F1_On then
  301.  begin
  302.   case TempF1 of
  303.    true:begin {display in reverse video}
  304.          SetTextType(Rev);
  305.          gotoxy(1,24); write ('<F1> MODE;');
  306.          SetTextType(Norm);
  307.          F1_On:=TempF1;
  308.         end;
  309.    false:begin {display in normal video}
  310.           gotoxy(1,24); write ('<F1> MODE;');
  311.           F1_On:=TempF1;
  312.          end;
  313.   end; {case TempF1}
  314.  end; {if TempF1}
  315.  
  316.  if TempF2<>F2_On then
  317.  begin
  318.   case TempF2 of
  319.     true:begin {display in reverse video}
  320.           SetTextType(Rev);
  321.           gotoxy(13,24); write ('<F2> RESET ALL;');
  322.           SetTextType(Norm);
  323.           F2_On:=TempF2;
  324.          end;
  325.     false:begin {display in normal video}
  326.            gotoxy(13,24); write ('<F2> RESET ALL;');
  327.            F2_On:=TempF2;
  328.           end;
  329.   end; {case TempF2}
  330.  end; {if TempF2}
  331.  
  332.  if TempF3<>F3_On then
  333.  begin
  334.   case TempF3 of
  335.     true:begin {display in reverse video}
  336.           SetTextType(Rev);
  337.           gotoxy(30,24); write ('<F3> RESET ONE;');
  338.           SetTextType(Norm);
  339.           F3_On:=TempF3;
  340.          end;
  341.     false:begin {display in normal video}
  342.            gotoxy(30,24); write ('<F3> RESET ONE;');
  343.            F3_On:=TempF3;
  344.           end;
  345.   end; {case TempF3}
  346.  end; {if TempF3}
  347.  
  348.  if TempF4<>F4_On then
  349.  begin
  350.   case TempF4 of
  351.     true:begin {display in reverse video}
  352.           SetTextType(Rev);
  353.           gotoxy(47,24); write ('<F4> OPEN FILE;');
  354.           SetTextType(Norm);
  355.           F4_On:=TempF4;
  356.          end;
  357.     false:begin {display in normal video}
  358.            gotoxy(47,24); write ('<F4> OPEN FILE;');
  359.            F4_On:=TempF4;
  360.           end;
  361.   end; {case TempF4}
  362.  end; {if TempF4}
  363.  
  364.  if TempF5<>F5_On then
  365.  begin
  366.   case TempF5 of
  367.     true:begin {display in reverse video}
  368.           SetTextType(Rev);
  369.           gotoxy(64,24); write ('<F5> CLOSE FILE;');
  370.           SetTextType(Norm);
  371.           F5_On:=TempF5;
  372.          end;
  373.     false:begin {display in normal video}
  374.            gotoxy(64,24); write ('<F5> CLOSE FILE;');
  375.            F5_On:=TempF5;
  376.           end;
  377.   end; {case TempF5}
  378.  end; {if TempF5}
  379.  
  380.  if TempF6<>F6_On then
  381.  begin
  382.   case TempF6 of
  383.     true:begin {display in reverse video}
  384.           SetTextType(Rev);
  385.           gotoxy(1,25); write ('<F6> PRINT TO FILE;');
  386.           SetTextType(Norm);
  387.           F6_On:=TempF6;
  388.          end;
  389.     false:begin {display in normal video}
  390.            gotoxy(1,25); write ('<F6> PRINT TO FILE;');
  391.            F6_On:=TempF6;
  392.           end;
  393.   end; {case TempF6}
  394.  end; {if TempF6}
  395.  
  396.  if TempF7<>F7_On then
  397.  begin
  398.   case TempF7 of
  399.     true:begin {display in reverse video}
  400.           SetTextType(Rev);
  401.           gotoxy(22,25); write ('<F7> PRINT TO PRINTER;');
  402.           SetTextType(Norm);
  403.           F7_On:=TempF7;
  404.          end;
  405.     false:begin {display in normal video}
  406.            gotoxy(22,25); write ('<F7> PRINT TO PRINTER;');
  407.            F7_On:=TempF7;
  408.           end;
  409.   end; {case TempF7}
  410.  end; {if TempF7}
  411.  
  412.  if TempF8<>F8_On then
  413.  begin
  414.   case TempF8 of
  415.     true:begin {display in reverse video}
  416.           SetTextType(Rev);
  417.           gotoxy(45,25); write ('<F8> SET PATH;');
  418.           SetTextType(Norm);
  419.           F8_On:=TempF8;
  420.          end;
  421.     false:begin {display in normal video}
  422.            gotoxy(45,25); write ('<F8> SET PATH;');
  423.            F8_On:=TempF8;
  424.           end;
  425.   end; {case TempF8}
  426.  end; {if TempF8}
  427.  
  428.  if TempF10<>F10_On then
  429.  begin
  430.   case TempF10 of
  431.     true:begin {display in reverse video}
  432.           SetTextType(Rev);
  433.           gotoxy(61,25); write ('<F10> EXIT PROGRAM;');
  434.           SetTextType(Norm);
  435.           F10_On:=TempF10;
  436.          end;
  437.     false:begin {display in normal video}
  438.            gotoxy(61,25); write ('<F10> EXIT PROGRAM;');
  439.            F10_On:=TempF10;
  440.           end;
  441.   end; {case TempF10}
  442.  end; {if TempF10}
  443.  
  444. end; {procedure UpDateMenu}
  445.  
  446. {---------------------------------------------- procedure UpDateStatusKeys }
  447.  
  448. {
  449. purpose: to indicate whether the status keys are engaged or not.  This
  450.          procedure is based on the Statkeys.pas program written by Don
  451.          Taylor and published in TUG-Lines issue #22.
  452. }
  453.  
  454. procedure UpDateStatusKeys;
  455.  
  456. var
  457.  CapsLock,NumLock,ScrollLock:boolean;
  458.  TheStatus:byte;
  459.  StatusByte:byte absolute $0000:$0417;
  460.  
  461. begin {procedure UpDateStatusKeys}
  462.  
  463.  if TheStatus<>StatusByte shr 4 then
  464.  begin
  465.   TheStatus:=StatusByte shr 4;
  466.  end;
  467.  
  468.  CapsLock:=(TheStatus and $04)<>0;
  469.  NumLock:=(TheStatus and $02)<>0;
  470.  ScrollLock:=(TheStatus and $01)<>0;
  471.  
  472.  if NumLock then
  473.  begin
  474.   SetTextType(Rev);
  475.   gotoxy(53,1); write ('Num Lock');
  476.  end
  477.  else
  478.  begin
  479.   SetTextType(Norm);
  480.   gotoxy(53,1); write ('        ');
  481.  end;
  482.  
  483.  if ScrollLock then
  484.  begin
  485.   SetTextType(Rev);
  486.   gotoxy(62,1); write ('Scroll Lock');
  487.  end
  488.  else
  489.  begin
  490.   SetTextType(Norm);
  491.   gotoxy(62,1); write ('           ');
  492.  end;
  493.  
  494.  if CapsLock then
  495.  begin
  496.   SetTextType(Rev);
  497.   gotoxy(43,1); write ('Caps Lock');
  498.  end
  499.  else
  500.  begin
  501.   SetTextType(Norm);
  502.   gotoxy(43,1); write ('         ');
  503.  end;
  504.  
  505.  SetTextType(Norm);
  506.  
  507. end; {procedure UpDateStatusKeys}
  508.  
  509. {------------------------------------------------ procedure ProcessUserInput }
  510.  
  511. {
  512. purpose: to process all input from the user via the keyboard.
  513. }
  514.  
  515. procedure ProcessUserInput;
  516.  
  517. var
  518.  Key1,Key2,ch:char;
  519.  i:byte;
  520.  BL:Str80;
  521.  TempStr:Str5;
  522.  TempHeader:Str12;
  523.  TempLabel:Str20;
  524.  
  525. begin {procedure ProcessUserInput}
  526.  
  527.  {process user input}
  528.    HitKey('',Key1,Key2);
  529.    case Key1 of
  530.        #0:begin
  531.           case Key2 of
  532.             #59:begin {F1}
  533.  
  534.                  if not F1_On then
  535.                  begin
  536.                   InvalidKey;
  537.                   exit;
  538.                  end; {if not F1_On}
  539.  
  540.                  SetTextType(High);
  541.                  if add then
  542.                  begin
  543.                   add:=false;
  544.                   gotoxy(15,3); clreol; write ('SUBTRACTION');
  545.                  end
  546.                  else
  547.                  begin
  548.                   add:=true;
  549.                   gotoxy(15,3); clreol; write ('ADDITION');
  550.                  end; {if add}
  551.                  SetTextType(Norm);
  552.                 end;
  553.             #60:begin {F2}
  554.  
  555.                  if not F2_On then
  556.                  begin
  557.                   InvalidKey;
  558.                   exit;
  559.                  end; {if not F2_On}
  560.  
  561.                  {make sure the user wants to reset all the counters}
  562.                  SetTextType(Rev);
  563.                  gotoxy(1,18); write (' Are you sure? (Y/N) ');
  564.                  SetTextType(Norm);
  565.                  ch:=ReadKey;
  566.                  if ((ch) IN ['Y','y']) then
  567.                  begin
  568.                   {reset all the counters}
  569.                   for i:=1 to length(DefinedKeys) do
  570.                   begin
  571.                    CharCounterArray[i]:=StartCount;
  572.                    UpDateScreen(i);
  573.                   end; {for i:=1 to}
  574.                  end; {if ch}
  575.                  EraseWarning;
  576.                 end;
  577.             #61:begin {F3}
  578.  
  579.                  if not F3_On then
  580.                  begin
  581.                   InvalidKey;
  582.                   exit;
  583.                  end; {if not F3_On}
  584.  
  585.                  {prompt the user for the counter to reset}
  586.                  SetTextType(Rev);
  587.                  gotoxy(1,18); write (' Hit the key to reset or <ESC> ');
  588.                  ch:=ReadKey;
  589.                  SetTextType(Norm);
  590.                  EraseWarning;
  591.                  i:=Pos(ch,DefinedKeys);
  592.                  if i=0 then InvalidKey
  593.                  else
  594.                  begin
  595.                   CharCounterArray[i]:=StartCount;
  596.                   UpDateScreen(i);
  597.                  end; {if i=0}
  598.                 end;
  599.             #62:begin {F4}
  600.  
  601.                  if not F4_On then
  602.                  begin
  603.                   InvalidKey;
  604.                   exit;
  605.                  end; {if not F4_On}
  606.  
  607.                  OpenOutPutFile;
  608.                 end;
  609.             #63:begin {F5}
  610.  
  611.                  if not F5_On then
  612.                  begin
  613.                   InvalidKey;
  614.                   exit;
  615.                  end; {if not F5_On}
  616.  
  617.                  {close the file}
  618.                  Close(OutPutFile);
  619.                  CheckIOError;
  620.  
  621.                  {update the screen}
  622.                  ActiveFile:='';
  623.                  gotoxy(15,1);
  624.                  write ('             ');
  625.                  {update the global variable}
  626.                  OutPutFileOpen:=false;
  627.                 end;
  628.             #64:begin {F6}
  629.  
  630.                  if not F6_On then
  631.                  begin
  632.                   InvalidKey;
  633.                   exit;
  634.                  end; {if not F6_On}
  635.  
  636.                  BL:='';
  637.  
  638.                  {send message to the screen}
  639.                  SetTextType(Rev);
  640.                  gotoxy(1,18); write (' Printing to file...');
  641.                  delay(300);
  642.                  SetTextType(Norm);
  643.  
  644.                  {send output to file}
  645.                  S:='COUNTER output on '+date+' at '+time;
  646.                  writeln (OutPutFile,S);
  647.                  writeln (OutPutFile,BL);
  648.  
  649.                  S:='LABEL                     KEY    COUNT';
  650.                  writeln (OutPutFile,S);
  651.                  writeln (OutPutFile,BL);
  652.  
  653.                  for i:=1 to length(DefinedKeys) do
  654.                  begin
  655.                   TempLabel:=LabelArray[i];
  656.                   while (length(TempLabel)<20) do TempLabel:=TempLabel+' ';
  657.                   S:=TempLabel+'  :    ';
  658.                   ch:=DefinedKeys[i];
  659.                   S:=S+ch+'    ';
  660.                   Str(CharCounterArray[i]:5,TempStr);
  661.                   S:=S+TempStr;
  662.                   writeln (OutPutFile,S);
  663.                  end; {for ... to length(DefinedKeys)}
  664.  
  665.                  for i:=1 to 2 do writeln (OutPutFile,BL);
  666.  
  667.                  EraseWarning;
  668.  
  669.                 end;
  670.             #65:begin {F7}
  671.  
  672.                  if not F7_On then
  673.                  begin
  674.                   InvalidKey;
  675.                   exit;
  676.                  end; {if not F7_On}
  677.  
  678.                  BL:='';
  679.                  EjectPrinterPage:=true;
  680.  
  681.                  {send message to the screen}
  682.                  SetTextType(Rev);
  683.                  gotoxy(1,18); write (' Printing...');
  684.                  SetTextType(Norm);
  685.  
  686.                  {send output to printer}
  687.                  PrinterDump(BL);
  688.                  S:='COUNTER output on '+date+' at '+time;
  689.                  PrinterDump(S);
  690.                  PrinterDump(BL);
  691.  
  692.                  S:='LABEL                     KEY    COUNT';
  693.                  PrinterDump(S);
  694.                  PrinterDump(BL);
  695.  
  696.                  for i:=1 to length(DefinedKeys) do
  697.                  begin
  698.                   TempLabel:=LabelArray[i];
  699.                   while (length(TempLabel)<20) do TempLabel:=TempLabel+' ';
  700.                   S:=TempLabel+'  :    ';
  701.                   ch:=DefinedKeys[i];
  702.                   S:=S+ch+'    ';
  703.                   Str(CharCounterArray[i]:5,TempStr);
  704.                   S:=S+TempStr;
  705.                   PrinterDump(S);
  706.                  end; {for ... to length(DefinedKeys)}
  707.  
  708.                  for i:=1 to 2 do PrinterDump(BL);
  709.  
  710.                  {wait for printer to finish printing}
  711.                  repeat until PrinterOK;
  712.                  EraseWarning;
  713.  
  714.                 end;
  715.             #66:begin {F8}
  716.  
  717.                  if not F8_On then
  718.                  begin
  719.                   InvalidKey;
  720.                   exit;
  721.                  end; {if not F8_On}
  722.  
  723.                  ChangePath(ActivePath);
  724.                  EraseWarning;
  725.                 end;
  726.             #68:begin {F10}
  727.  
  728.                  if not F10_On then
  729.                  begin
  730.                   InvalidKey;
  731.                   exit;
  732.                  end; {if not F10_On}
  733.  
  734.                  if OutPutFileOpen then
  735.                  begin
  736.                   {close the file}
  737.                   Close(OutPutFile);
  738.                   CheckIOError;
  739.  
  740.                   {update the screen}
  741.                   ActiveFile:='';
  742.                   gotoxy(1,1); clreol; write ('Active File : ',ActiveFile);
  743.                   {update the global variable}
  744.                   OutPutFileOpen:=false;
  745.                  end; {if OutPutFileOpen}
  746.                  quit:=true;
  747.                 end;
  748.             else InvalidKey
  749.           end; {case Key2}
  750.          end;
  751.      #48..#122:begin
  752.                 {check for defined keys}
  753.                 {if key is not defined InvalidKey else click and process}
  754.                 i:=Pos(Key1,DefinedKeys);
  755.                 if i=0 then InvalidKey else
  756.                 begin
  757.                  {based on status of add, add or subtract one from the
  758.                  corresponding value in the CharCounterArray}
  759.                  if add then
  760.                  begin
  761.                   if CharCounterArray[i]<MaxCount then
  762.                   begin
  763.                    CharCounterArray[i]:=CharCounterArray[i]+1;
  764.                    click;
  765.                   end
  766.                   else
  767.                   begin
  768.                    SetTextType(Rev);
  769.                    gotoxy(1,18); write (' Out of range ');
  770.                    sound(300); delay(50);
  771.                    sound(600); delay(50);
  772.                    sound(1500); delay(50);
  773.                    NoSound; delay(50);
  774.                    SetTextType(Norm);
  775.                    EraseWarning;
  776.                   end;
  777.                  end
  778.                  else
  779.                  begin
  780.                   if CharCounterArray[i]>MinCount then
  781.                   begin
  782.                    CharCounterArray[i]:=CharCounterArray[i]-1;
  783.                    click;
  784.                   end
  785.                   else
  786.                   begin
  787.                    SetTextType(Rev);
  788.                    gotoxy(1,18); write (' Out of range ');
  789.                    sound(300); delay(50);
  790.                    sound(600); delay(50);
  791.                    sound(1500); delay(50);
  792.                    NoSound; delay(50);
  793.                    SetTextType(Norm);
  794.                    EraseWarning;
  795.                   end;
  796.                  end; {if add}
  797.                  UpDateScreen(i);
  798.                 end; {if i=0}
  799.                end;
  800.      else InvalidKey
  801.    end; {case Key1}
  802.  
  803. end; {procedure ProcessUserInput}
  804.  
  805. {------------------------------------------------ procedure Initialize }
  806.  
  807. {
  808. purpose: to install exit and critical error procedures, to initialize
  809.          global variables, and to set up opening screens.
  810. }
  811.  
  812. procedure Initialize;
  813.  
  814. var
  815.  i:byte;
  816.  ch:char;
  817.  
  818. begin {procedure Initialize}
  819.  
  820.  {install the termination procedure}
  821.  ExitSave:=ExitProc;
  822.  ExitProc:=@Terminate;
  823.  
  824.  {install the critical error handling prodecure}
  825.  SetIntVec($24,@CEHandler);
  826.  CriticalErrorOccurred:=false;
  827.  CriticalErrorCode:=0;
  828.  CriticalErrorDrive:=$FF;
  829.  
  830.  {turn the cursor off}
  831.  CursorOff;
  832.  
  833.  {set the global status variables}
  834.  Quit:=false;
  835.  Add:=true;
  836.  FileName:='';
  837.  ActiveFile:='';
  838.  OutPutFileOpen:=false;
  839.  GetDir(0,OriginalPath);
  840.  ActivePath:=OriginalPath;
  841.  if length(ActivePath)>3 then ActivePath:=ActivePath+'\';
  842.  DefinedKeys:='';
  843.  F1_On:=false;
  844.  F2_On:=true;
  845.  F3_On:=true;
  846.  F4_On:=false;
  847.  F5_On:=true;
  848.  F6_On:=true;
  849.  if PrinterOK then F7_On:=false else F7_On:=true;
  850.  F8_On:=false;
  851.  F10_On:=false;
  852.  PrinterLine:=1;
  853.  EjectPrinterPage:=false;
  854.  
  855.  {initialize the arrays}
  856.  for i:=1 to 20 do
  857.  begin
  858.   CharCounterArray[i]:=StartCount;
  859.   CharArray[i]:=0;
  860.   LabelArray[i]:='';
  861.  end; {for ... to 20}
  862.  
  863.  {show the opening screen}
  864.  OpeningScreen;
  865.  
  866.  {get key definitions and labels}
  867.  DefineKeys;
  868.  
  869.  {set up display}
  870.  ScreenDisplay;
  871.  
  872. end; {procedure Initialize}
  873.  
  874. {------------------------------------------------ procedure Execute }
  875.  
  876. {
  877. purpose: to process user input or, if none, to update the clock and the
  878.          menu.
  879. }
  880. procedure Execute;
  881.  
  882. begin {procedure Execute}
  883.  
  884.  repeat
  885.    repeat
  886.     UpDateClock;
  887.     UpDateMenu;
  888.     UpDateStatusKeys;
  889.    until KeyPressed;
  890.    ProcessUserInput;
  891.  until quit;
  892.  
  893. end; {procedure Execute}
  894.  
  895. {-------------------------------------------------- procedure Terminate }
  896.  
  897. {
  898. purpose: to shut down program execution and to report run time errors.
  899. }
  900.  
  901. procedure Terminate;
  902.  
  903. var
  904.  Msg:Str40;
  905.  Segment,Offset:word;
  906.  
  907. begin {procedure Terminate}
  908.  
  909.  {close OutPutFile if open}
  910.  if OutPutFileOpen then
  911.  begin
  912.   Close(OutPutFile);
  913.   OutPutFileOpen:=false;
  914.  end; {if OutPutFileOpen}
  915.  
  916. {if output was sent to the printer, eject the page}
  917.  if EjectPrinterPage and PrinterOK then writeln (lst,#12);
  918.  
  919.  {clear the screen}
  920.  clrscr;
  921.  
  922.  SetTextType(High);
  923.  
  924.  if ((ExitCode>=200) and (ExitCode<=255)) then
  925.  begin
  926.   if ErrorAddr<>nil then               {run-time error occurred}
  927.   begin
  928.    case ExitCode of
  929.     200:Msg:=' Division by zero';
  930.     201:Msg:=' Range check error';
  931.     202:Msg:=' Stack overflow error';
  932.     203:Msg:=' Heap overflow error';
  933.     204:Msg:=' Invalid pointer operation';
  934.     205:Msg:=' Floating point overflow';
  935.     206:Msg:=' Floating point underflow';
  936.     207:Msg:=' Invalid floating point operation';
  937.    else Msg:=' Unknown error';
  938.    end; {case ExitCode}
  939.    Segment:=Seg(ErrorAddr);
  940.    Offset:=Ofs(ErrorAddr);
  941.    writeln (' Fatal run-time error # ',ExitCode,' at ',Segment:5,':',Offset:5);
  942.    writeln (Msg);
  943.    writeln (' Program execution aborted.');
  944.    ErrorAddr:=nil;
  945.   end
  946.   else
  947.   begin
  948.    writeln (' Program execution halted.');
  949.   end; {if ErrorAddr<>nil}
  950.  end; {if ExitCode<>0}
  951.  
  952.  clrscr;
  953.  SetTextType(Rev);
  954.  gotoxy(17,11); write (' COUNTER is a ');
  955.  SetTextType(RevBlink); write ('PUBLIC DOMAIN');
  956.  SetTextType(Rev); write (' program created by:   ');
  957.  gotoxy(29,13); write (' Rafael J Del Vecchio   ');
  958.  gotoxy(29,14); write (' PO Box 1243            ');
  959.  gotoxy(29,15); write (' Davis,  CA  95617-1243 ');
  960.  gotoxy(29,16); write (' U.S.A.                 ');
  961.  gotoxy(17,18); write (' You may copy and distribute this program freely. ');
  962.  gotoxy(17,19); write ('      Send comments to the above address.         ');
  963.  
  964.  SetTextType(Norm);
  965.  CursorOn;
  966.  gotoxy(1,24);
  967.  
  968.  ChDir(OriginalPath);
  969.  
  970.  {restore Turbo's built-in exit procedure}
  971.  ExitProc:=ExitSave;
  972.  
  973. end; {procedure Terminate}
  974.