home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / bbs / turbobbs / io.inc < prev    next >
Encoding:
Text File  |  1985-08-24  |  10.6 KB  |  440 lines

  1. const
  2.   iodata    = 4;
  3.   iocontrol = 6;
  4.   iorate    = 0;
  5.  
  6. var
  7.   cancelled : boolean;
  8.   inbuffer  : line;
  9.  
  10. function inready:boolean; forward;
  11.  
  12. function charin(withecho: boolean):char; forward;
  13.  
  14. function outready: boolean;                    (* Machine Dependent *)
  15.  
  16. {Indicates that serial output port is
  17.  ready to transmit a new character}
  18.  
  19.   begin
  20.     port[iocontrol] := 16;
  21.     outready := (port[iocontrol] and 4) > 0;
  22.   end;
  23.  
  24. procedure xmitchar(ch: char);                  (* Machine Dependent *)
  25.  
  26. {Transmits character out serial port, unless we're in the local mode.}
  27.  
  28.   begin
  29.     if not local then begin
  30.       repeat until outready;
  31.       port[iodata] := ord(ch);
  32.     end;
  33.   end;
  34.  
  35.  
  36. procedure sendout(ch: char);
  37.  
  38. {Character output - bypasses word-wrap; also performs
  39.  "pause" and "abort" input character checks.}
  40.  
  41. var temp: char;
  42.  
  43.   begin
  44.     if not cancelled then begin
  45.       if inready then begin
  46.         temp := charin(noecho);
  47.         if (temp = pause) or (upcase(temp) = 'S') then temp := charin(noecho);
  48.         if (temp = abort) or (upcase(temp) = 'C') then cancelled := true;
  49.       end;
  50.       xmitchar(ch);
  51.       write(ch);
  52.       if printon then write(lst, ch);
  53.       if (ch = cr) and (lf = null) then writeln;
  54.     end;
  55.   end;
  56.  
  57. procedure flushbuff;
  58.  
  59.   var
  60.     outpointer: byte;
  61.  
  62.   begin
  63.     if length(buffer) > lastspace then
  64.       for outpointer := lastspace + 1 to length(buffer) do
  65.         sendout(buffer[outpointer]);
  66.     lastspace := length(buffer);
  67.   end;
  68.  
  69. procedure resetbuff;
  70.  
  71.   begin
  72.     bufpointer := 0;
  73.     lastspace := 0;
  74.     charcount := 0;
  75.     buffer := '';
  76.   end;
  77.  
  78. procedure charout(ch:char);
  79.  
  80. {Character output using word-wrap}
  81.  
  82.   var
  83.     buffull   : boolean;
  84.     temp      : long;
  85.  
  86.   begin
  87.     if caps then ch := upcase(ch);
  88.     if not (ch in [null..#31]) then charcount := succ(charcount);
  89.     if (ch = bs) and (charcount > 0) then charcount := charcount - 1;
  90.     buffer := buffer + ch;
  91.     bufpointer := length(buffer);
  92.     buffull := (charcount + 2 > width);
  93.     if buffull then begin
  94.       if (lastspace > 0)
  95.         then begin
  96.           buffer := copy(buffer, lastspace + 1, bufpointer - lastspace);
  97.           charcount := length(buffer);
  98.           lastspace := 0;
  99.           end {then}
  100.         else begin
  101.           flushbuff;
  102.           resetbuff;
  103.         end; {else}
  104.       sendout(cr);
  105.       sendout(lf);
  106.     end; {if}
  107.     if ch in [null..space] then flushbuff;
  108.     if (ch=cr) then resetbuff;
  109.   end;
  110.  
  111. procedure stringout(message:line);
  112.  
  113.   var
  114.     charpos: integer;
  115.  
  116.   begin
  117.     for charpos := 1 to length(message) do charout(message[charpos]);
  118.   end;
  119.  
  120. procedure lineout(message:line);
  121.  
  122.   begin
  123.     stringout(message);
  124.     charout(cr);
  125.     charout(lf);
  126.   end;
  127.  
  128. function cts: boolean;                            (* Machine Dependent *)
  129.  
  130. {This function indicates the presence of a carrier tone on the modem
  131.  and is frequently checked to see if the caller is still present.
  132.  It always returns "true" in the local mode".}
  133.  
  134.   begin
  135.     port[iocontrol] := 16;  {Z80 SIO status reset - gets current CTS level}
  136.     cts := ((port[iocontrol] and 32) = 32) or local;
  137.   end;
  138.  
  139. function inready;                                 (* Machine Dependent *)
  140.  
  141. {Returns true if we've got a character received
  142.  from the serial port or keyboard.}
  143.  
  144.   begin
  145.     inready := keypressed or ((port[iocontrol] and 1) > 0);
  146.   end;
  147.  
  148. function recvchar: char;                          (* Machine Dependent *)
  149.  
  150. {Reads character from serial I/O input}
  151.  
  152.   begin
  153.     recvchar := chr(port[iodata]);
  154.   end;
  155.  
  156. function charin;
  157.  
  158.   var
  159.     ch: char;
  160.  
  161.   begin
  162.     ch := null;
  163.     repeat
  164.       if inready then ch := recvchar;
  165.       if keypressed then read(kbd, ch);
  166.       if not cts then ch := cr;
  167.       if (ch <> bs) and not controls then ch := chr(ord(ch) and 127);
  168.     until (ch in [abort, pause, bs, tab, cr, space..#127])
  169.       or (controls and (ch <> null));
  170.     if (ch = #127) and not controls then ch := bs;
  171.     if ch = #$8D then ch := cr;
  172.     if withecho then begin
  173.         sendout(ch);
  174.         if ch = bs then begin sendout(' '); sendout(bs); end;
  175.       end
  176.       else write(ch);
  177.     charin := ch;
  178.   end;
  179.  
  180. procedure flush;                                      (* Machine Dependent *)
  181.  
  182.   var
  183.     junk: char;
  184.  
  185.   begin
  186.     while inready do junk := charin(noecho);
  187.     port[iocontrol] := 16;      {Reset Z80 SIO status lines}
  188.   end;
  189.  
  190. function inputstring(withecho: boolean): line;
  191.  
  192.   var
  193.     pointer: integer;
  194.     temp:    line;
  195.     ch:      char;
  196.  
  197.   begin
  198.     temp := '';
  199.     flush;
  200.     repeat
  201.       ch := charin(withecho);
  202.       if ((ch <> pause) and (ch <> abort)) or controls then begin
  203.         if ch = tab then
  204.           repeat
  205.             temp := temp + space;
  206.             pointer := length(temp);
  207.           until (pointer mod 8) = 0
  208.         else begin
  209.           temp := temp + ch;
  210.           pointer := length(temp);
  211.           if (ch = bs) then begin
  212.             if pointer > 1 then temp := copy(temp, 1, pointer - 2)
  213.                            else begin
  214.                              temp := '';
  215.                              sendout(' ');
  216.                            end;
  217.           end; {else}
  218.         end;   {if ch = tab}
  219.       end;     {if (ch <>...}
  220.     until (ch = cr) or (pointer = 80);
  221.     if ch = cr then temp := copy(temp,1,pointer-1)
  222.                else charout(cr);
  223.     if (ch = cr) and not withecho then charout(cr);
  224.     resetbuff;
  225.     charout(lf);
  226.     inputstring := temp;
  227.   end;
  228.  
  229. function getinput(prompt:line; maxlength:integer; withecho:boolean):line;
  230.  
  231.   var posn: integer;
  232.       temp: char;
  233.  
  234.   begin
  235.     if cancelled then begin
  236.       cancelled := false;
  237.       lineout(space);
  238.     end;
  239.     if inbuffer = '' then begin
  240.       repeat
  241.         cancelled := false;
  242.         stringout(prompt);
  243.         if bl = bell then stringout(bl);
  244.       until cancelled = false;
  245.       inbuffer := inputstring(withecho);
  246.     end;
  247.     if maxlength = 1 then begin
  248.       repeat
  249.         if inbuffer = '' then temp := cr else begin
  250.           temp := inbuffer[1];
  251.           inbuffer := copy(inbuffer, 2, length(inbuffer)-1);
  252.         end;
  253.       until temp <> ';';
  254.       getinput := temp;
  255.     end
  256.     else begin
  257.       posn := pos(';', inbuffer);
  258.       if posn = 0 then posn := length(inbuffer) + 1;
  259.       if posn > maxlength then posn := maxlength + 1;
  260.       getinput := copy(inbuffer, 1, posn - 1);
  261.       if posn >= length(inbuffer)
  262.         then inbuffer := ''
  263.         else inbuffer := copy(inbuffer, posn + 1, length(inbuffer) - posn);
  264.     end;
  265.   end;
  266.  
  267. function allcaps(letters: person): person;
  268.  
  269.   var
  270.     loop: byte;
  271.     temp: person;
  272.  
  273.   begin
  274.     temp := '';
  275.     for loop := 1 to length(letters) do
  276.       temp := temp + upcase(letters[loop]);
  277.     allcaps := temp;
  278.   end;
  279.  
  280. procedure setbaud(speed: rate);                       (* Machine Dependent *)
  281.  
  282.   begin
  283.     case speed of
  284.       slow: port[iorate] := 5;     { 300 baud}
  285.       fast: port[iorate] := 7;     {1200 baud}
  286.     end;
  287.     baud := speed;
  288.   end;
  289.  
  290. procedure clearSIO;                                   (* Machine Dependent *)
  291.  
  292. {Initializes serial I/O chip - a Z80 SIO in this case}
  293.  
  294.   begin
  295.     port[iocontrol] := $18;
  296.     port[iocontrol] := 4;
  297.     port[iocontrol] := $44;
  298.     port[iocontrol] := 3;
  299.     port[iocontrol] := $C1;
  300.     port[iocontrol] := 5;
  301.     port[iocontrol] := $EA;
  302.   end;
  303.  
  304. procedure clearmodem;                                 (* Modem Dependent *)
  305.  
  306. {Sets modem for auto-answer, CTS line as carrier detect, no command echo}
  307.  
  308.   begin
  309.     buffer := cr + cr + '<O3N4N5N0Q>';
  310.     flushbuff;
  311.     resetbuff;
  312.     writeln;
  313.     write('Delaying...');
  314.     delay(5000);
  315.     writeln;
  316.   end;
  317.  
  318. procedure setup;                                      (* Machine Dependent *)
  319.  
  320.   begin
  321.     port[8] := 12;  {sets Kaypro 2-84 serial printer port to 4800 baud}
  322.     write(esc + 'B7'); {sets 25th line protection on Kaypro 2-84.}
  323.     setbaud(fast);
  324.     clearSIO;
  325.     clearmodem;
  326.   end;
  327.  
  328. function badframe: boolean;                           (* Machine Dependent *)
  329.  
  330. {Indicates Framing Error on serial I/O chip - return false if not available.}
  331.  
  332.   begin
  333.     port[iocontrol] := 1;
  334.     badframe := (port[iocontrol] and 64) = 64;
  335.   end;
  336.  
  337. procedure dropRTS;                                   (* Machine Dependent *)
  338.  
  339.   begin
  340.     port[iocontrol] := 5;
  341.     port[iocontrol] := $68;
  342.   end;
  343.  
  344. procedure setlocal;
  345.  
  346.   begin
  347.     dropRTS;
  348.     local := true;
  349.     write('Local control.');
  350.   end;
  351.  
  352. procedure raiseRTS;                                   (* Machine Dependent *)
  353.  
  354.   begin
  355.     port[iocontrol] := 5;
  356.     port[iocontrol] := $EA;
  357.   end;
  358.  
  359. procedure clearlocal;
  360.  
  361.   begin
  362.     raiseRTS;
  363.     local := false;
  364.   end;
  365.  
  366. procedure awaitcall;                                  (* Machine Dependent *)
  367.  
  368.   var
  369.     junk: char;
  370.  
  371.   begin
  372.     setbaud(fast);
  373.     writeln(cr + lf + 'Waiting for call...');
  374.     flush;
  375.     repeat
  376.       if keypressed then begin
  377.         read(kbd, junk);
  378.         local := junk = esc;
  379.         if local then setlocal else exitchar := junk;
  380.       end;
  381.     until cts or (exitchar = abort);
  382.     if exitchar <> abort then begin
  383.       writeln('On line...');
  384.       delay(500);
  385.       flush;
  386.       junk := charin(noecho);
  387.       if badframe or (junk <> cr) then setbaud(slow);
  388.       port[iocontrol] := $30;   {Resets Z80 SIO error flags - this is the}
  389.     end;                        {only machine dependent line in procedure}
  390.   end;
  391.  
  392. procedure unload;                                     (* Machine Dependent *)
  393.  
  394. {Halts Kaypro disk drives - normally they run for about 15 secs.}
  395.  
  396.   begin
  397.     port[20] := (port[20] and $EF);
  398.   end;
  399.  
  400. procedure hangup;                                     (* Machine Dependent *)
  401.  
  402. {Signals modem to hang up by lowering RTS line for 400 msec.}
  403.  
  404.   begin
  405.     lineout('--- Disconnected ---' + cr + lf);
  406.     dropRTS;
  407.     delay(400);
  408.     raiseRTS;
  409.     if not local then repeat until not cts else clearlocal;
  410.   end;
  411.  
  412. procedure dispcaller;                                 (* Machine Dependent *)
  413.  
  414. {Displays caller's name on protected 25th line of host CRT;
  415.  Replace with empty procedure if not desired.}
  416.  
  417.   begin
  418.     write(esc + 'B6' + esc + '=' + chr(56) + ' ');
  419.     write(caller);
  420.     if clockin then write(' called at ' + timeon);
  421.     write(#24 + esc + 'C6');    {#24 = clear to end of line}
  422.   end;
  423.  
  424. procedure clearsc;
  425.  
  426.   begin
  427.     stringout(cs);
  428.     delay(500);   {allows time for slow terminal screen clears}
  429.   end;
  430.  
  431. function getcap(prompt: line): char;
  432.  
  433.   var
  434.     temp : char;
  435.  
  436.   begin
  437.     temp := upcase(getinput(prompt, 1, echo));
  438.     getcap := temp;
  439.   end;
  440. əəəəəəəəəəəəəəəəəəəəəəəəəə