home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 3 / hamradioversion3.0examsandprograms1992.iso / mods / pk232src / sss_main.pas < prev    next >
Pascal/Delphi Source File  |  1986-09-10  |  11KB  |  241 lines

  1.     {----------------------------------------------------------------------}
  2.     {         Main Program Part of the Split-Screen Server (SSS)           }
  3.     {----------------------------------------------------------------------}
  4.     {                                                                      }
  5.     {  Author:  Peter H. Heinrich (HB9CVV)                                 }
  6.     {  Date:    July, 1986                                                 }
  7.     {  Version: 1.1                                                        }
  8.     {  Systems: For MS-DOS on IBM PCs and close compatibles only.          }
  9.     {           Note:  I have checked this program on a PC/AT with EGA     }
  10.     {                  and a PC/XT Clone with Hercules card, both          }
  11.     {                  running PC-DOS V3.1.                                }
  12.     {                                                                      }
  13.     {----------------------------------------------------------------------}
  14.  
  15.  
  16.     {-------------------- MAIN PROGRAM ------------------------------------------}
  17.  
  18.   VAR CRflag : Boolean;
  19.  
  20.   BEGIN
  21.     ClrScr;                             {Clear the screen}
  22.     WriteLn(logo);
  23.     WriteLn;
  24.     WriteLn('Use ALT/X to exit this program. To enter the TNC command-mode press ESC-key.');
  25.     WriteLn;
  26.     WriteLn('The Com-line will use 8 databits, 1 stopbit, no parity.');
  27.     WriteLn;
  28.     IF NOT(Send_ok) THEN BEGIN
  29.       Write('File-send feature is disabled. ');
  30.     END;
  31.     READPARAMFILE(parfilnam);
  32.     REPEAT
  33.       CPort := 0;
  34.       Write('Select Com-port 1 .. 6, default is ', DefPort, ': ');
  35.       ReadLn(CPort); IF CPort = 0 THEN CPort := DefPort;
  36.     UNTIL (CPort IN [1, 2, 3, 4, 5, 6]);
  37.     REPEAT
  38.       Cbaudrate := 0;
  39.       Write('Select Baudrate (300..9600), default is ', Defbaud, ': ');
  40.       ReadLn(Cbaudrate); IF CBaudrate = 0 THEN CBaudrate := DefBaud;
  41.     UNTIL (Cbaudrate DIV 100 IN [3, 6, 12, 24, 48, 96]);
  42.     InitHelpWindows;                    {Setup the text in the Help pop-ups}
  43.     HelpWindow3;                        {and  show help}
  44.     ClrScr;
  45.     WriteLn;
  46.     WriteLn('Initializing....');
  47.  
  48.     Async_Init;
  49.     IF NOT Async_Open(CPort, CBaudrate, 'N', 8, 1) THEN BEGIN {Open the COMMport to the TNC}
  50.       WriteLn('*** Com-port init failure ***');
  51.       Halt;
  52.     END;
  53.  
  54.     cha := space;                       {init variables}
  55.     Outbuffer[NORM] := '';
  56.     Outbuffer[DEV_CMD] := '';
  57.     Outbuffer[PGM_CAP] := '';
  58.     Outbuffer[PGM_SEN] := '';
  59.     mode := NORM;
  60.     pdate := '';
  61.     minute := '00';
  62.     CurWinNo := 0;
  63.     Capture_enabled := False;
  64.     Sendfile_enabled := False;
  65.     Bells_enabled := True;
  66.     Wordout_enabled := False;
  67.     CRflag := False;
  68.     Wtab[1, 5] := 1; Wtab[1, 6] := 1;
  69.     Wtab[2, 5] := 1; Wtab[2, 6] := 1;
  70.  
  71.     InitDevice;                         {Load TNC with Init Values}
  72.     ClrScr;                             {Clear the screen}
  73.     Frame(Screendiv);                   {Draw the screen divider line}
  74.  
  75.     {=========================================================================}
  76.     {=========================== THE BIG LOOP ================================}
  77.     {=========================================================================}
  78.  
  79.     REPEAT BEGIN
  80.  
  81.       {-----------------------------------------------------------------------}
  82.       { (1) Insert date and time at end of screen divider (if it has changed) }
  83.       {-----------------------------------------------------------------------}
  84.  
  85.       IF minute = '00' THEN BEGIN
  86.         IF pdate <> date THEN BEGIN
  87.           Selectwindow(3);
  88.           GoToXY(60, screendiv); Write(' ', date, ' ');
  89.           pdate := date;
  90.           SelectWindow(2);                {move cursor back to input window}
  91.         END;
  92.       END;
  93.       IF ptime <> time THEN BEGIN
  94.         Selectwindow(3);
  95.         GoToXY(72, screendiv); Write(' ',time);
  96.         ptime := time;
  97.         SelectWindow(2);                {move cursor back to input window}
  98.       END;
  99.  
  100.       {-----------------------------------------------------------------------}
  101.       { (2) Read the characterstring from the TNC and display it on the upper }
  102.       {     output window. We read all characters which are found in the      }
  103.       {     receice buffer                                                    }
  104.       {-----------------------------------------------------------------------}
  105.  
  106.  
  107.       WHILE (Async_Receive(rcha)) DO BEGIN
  108.         IF NOT Bells_enabled THEN IF rcha = ^G THEN rcha := '~';
  109.         IF CRFlag AND (rcha <> lf) THEN
  110.           Inbuffer := lf+rcha
  111.         ELSE
  112.           Inbuffer := rcha;
  113.         UpdateWindow(1, Inbuffer);
  114.         CRFlag := (rcha = cr);
  115.       END;
  116.  
  117.       {-----------------------------------------------------------------------}
  118.       { (3) Sending a file is done here. We use Slindex as control variable:  }
  119.       {     If Slindex=0 (which is the start value also) then we read the     }
  120.       {     next line and set Slindex=1. If 0<Slindex<Length(Sline) then we   }
  121.       {     send the character at position Slindex. Please note that this is  }
  122.       {     the programs main loop even if just one character is sent per     }
  123.       {     pass, the sending speed is by far sufficient                      }
  124.       {-----------------------------------------------------------------------}
  125.  
  126.       IF Sendfile_enabled THEN BEGIN
  127.         IF Slindex = 0 THEN BEGIN       { we must read another line from file }
  128.           IF EoF(Sendfile) THEN BEGIN   { its all over now }
  129.             Sendfile_enabled := False;
  130.             Close(Sendfile);
  131.             Delay(500);
  132.             Async_send(^Z);             { Append a ^Z, most BBS like it}
  133.             Async_send(cr);
  134.             TmpStr := '*** Finished: End Of File ***'+cr+lf;
  135.             UpdateWindow(2, Tmpstr);    {Write it to lower window}
  136.             Delay(2000);
  137.             IF TNC_echo_on THEN Async_Send_STring(^C'ECHO ON'^M'CONV'^M);
  138.           END ELSE BEGIN                { read the line }
  139.             {$I-} ReadLn(Sendfile, Sline); IOR := IOResult; {$I+}
  140.             IF IOR <> 0 THEN BEGIN
  141.               Sendfile_enabled := False;
  142.               Close(Sendfile);
  143.               Async_send(^Z);           { Append a ^Z, most BBS like it}
  144.               Async_send(cr);
  145.               TmpStr := '*** Terminated: I/O Error reading File ***'+cr+lf;
  146.               UpdateWindow(2, Tmpstr);  {Write it to lower window}
  147.               Delay(2000);
  148.               IF TNC_echo_on THEN Async_Send_STring(^C'ECHO ON'^M'CONV'^M);
  149.             END ELSE BEGIN
  150.               Slindex := 1;             { position the index on 1st char }
  151.               Sline := Sline+cr;        { append a CR }
  152.             END;
  153.           END;
  154.         END ELSE BEGIN                  { send ONE char }
  155.           IF Async_CTS_On THEN BEGIN
  156.             Tmpchr := Chr(Ord(Sline[Slindex]) AND $7F);
  157.             IF ((Ord(Tmpchr) > $1F) OR (Tmpchr = cr)) THEN async_send(Tmpchr);
  158.             Tmpstr := Tmpchr;
  159.             UpdateWindow(2, Tmpstr);    { Write it to lower window }
  160.             Slindex := Slindex+1;       { advance to next char }
  161.             IF Slindex > Length(Sline) THEN BEGIN { Done this line }
  162.               Slindex := 0;             { indicate it to read a new line next pass }
  163.               Tmpstr := lf;             { scroll the text in window }
  164.               UpdateWindow(2, Tmpstr);  { Write it to lower window }
  165.             END;
  166.           END;
  167.         END;
  168.       END;
  169.  
  170.       {-----------------------------------------------------------------------}
  171.       { (4) Read character input from the Operator, process it and display it }
  172.       {     on the lower input window. Watch out, if a file is sent it might  }
  173.       {     be better to only permit the ABORT-file send here...              }
  174.       {-----------------------------------------------------------------------}
  175.  
  176.       echa := Char(0);
  177.       IF KeyPressed THEN BEGIN          {If OP pressed a key ....}
  178.         ReadIchar(cha, echa);           {Get next keystroke}
  179.         IF (cha = #00) THEN BEGIN       {it is a command char input}
  180.  
  181.           {----------------- Special character processing ----------------------}
  182.  
  183.           CASE Ord(echa) OF
  184.  
  185.             104..113:SWITCH_DEV_MODE;   {ALT/F1...ALT/F10}
  186.             017     : PGMCMD_WORDOUT;       { ALT/W: Word output mode}
  187.             038     : PGMCMD_LINEOUT;       { ALT/L: Line output mode}
  188.             046     : PGMCMD_CAPTURE;       { ALT/C: Capture file }
  189.             031     : PGMCMD_SENDFILE;      { ALT/S: Sendfile }
  190.             048     : PGMCMD_BELLS;         { ALT/B: toggle bell recognition }
  191.             021     : PGMCMD_CLR_L_SCREEN;  { ALT/Y: Clear lower screen and flush input line }
  192.             030     : PGMCMD_ABORT_SEND;    { ALT/A: Abort sending a file }
  193.             045     : BEGIN END;            { ALT/X: Terminate - dont show window}
  194.             050     : SWITCH_DEV_MODE;      { ALT/M: Switch devive modes }
  195.  
  196.             { 1/End, 2/down, 3/PgDn, 0/Ins, ./Del  : Device special keys }
  197.             079..083 : DEV_SPC_FUN(Ord(echa));
  198.  
  199.             059..64:                    { F-Key 1 to 6}
  200.               BEGIN Transferstr(Fstr[Ord(echa)-59+1], NORM); END;
  201.             067     :                       { F-Key 9 : Helpwindow for TNC/setups }
  202.               HelpWindow1;
  203.             068     :                       { F-Key10 : Helpwindow for QSO }
  204.               BEGIN HelpWindow3; END;
  205.           ELSE BEGIN Helpwindow2; END;  { All other Special Keys}
  206.           END;
  207.  
  208.         END
  209.         ELSE                            { it is a normal char input}
  210.  
  211.           {------------- Dialogue character processing -------------------------}
  212.  
  213.           BEGIN
  214.             CASE cha OF
  215.               del     : PROCCHAR_DEL;
  216.               cr     : PROCCHAR_CR;
  217.               esc     : PROCCHAR_ESC;
  218.               space, '.', ',':
  219.                 IF wordout_enabled THEN PROCCHAR_SPACE ELSE PROCCHAR_REST;
  220.             ELSE                        {ALL other 'normal' chars: no special treatment}
  221.               PROCCHAR_REST;
  222.             END;
  223.           END;
  224.       END;
  225.       END;
  226.     UNTIL (Ord(echa) = 45);             { ALT/X terminates }
  227.  
  228.     { Terminating this lovely little program - sigh - }
  229.  
  230.     Window(1, 1, 80, 25);
  231.     ClrScr;
  232.     WriteLn('Clean-up...');
  233.     IF Capture_enabled THEN Close(Capturefile);
  234.     IF Sendfile_enabled THEN Close(Sendfile);
  235.     Shutdowndevice;
  236.     Async_Close;
  237.     ClrScr;
  238.  
  239.   END.
  240.  
  241.