home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / bbs / turbobbs.ark / MACHDEP.TI < prev    next >
Encoding:
Text File  |  1986-12-21  |  7.8 KB  |  317 lines

  1. (* MACHDEP.TI - TIPC overlay for TurboBBS version 1.05 - by R. Maxwell *)
  2. (* TurboBBS Vancouver: (604) 738-7811 300/1200/2400 baud, online 24hrs *)
  3.  
  4. {This is a minimal overlay file the TI personal computer.
  5.  It uses the addresses of the 8530 on the Sync-Async Communications card.
  6.  The modem initialization is for a Hayes Smartmodem or clone thereof. - RHM}
  7.  
  8. {NOTE! This overlay contains a procedure "flush" which conflicts with
  9.        a procedure with the same name in IO.INC. The routine here is
  10.        preferred: delete or comment out the one occurring in IO.INC.}
  11.  
  12. const
  13.   iobase    = $E0; {Port 1 address}
  14.  
  15. procedure lineout(message: line); forward;
  16.  {lineout is in IO.INC - don't change this declaration!}
  17.  
  18. procedure clearstatus;
  19.  
  20. {Resets latching status flags on SIO chip -
  21.  replace with empty procedure if not needed}
  22.  
  23.   begin
  24.   end;
  25.  
  26. function outready: boolean;
  27.  
  28. {Returns true if serial output port is
  29.  ready to transmit a new character}
  30.  
  31.   begin
  32.     outready := ((port[iobase + 6] and 4) > 0);
  33.   end;
  34.  
  35. procedure xmitchar(ch: char);
  36.  
  37. {Transmits ch when serial output port is ready,
  38.    unless we're in the local mode.}
  39.  
  40.   begin
  41.     if not local then begin
  42.       repeat until outready;
  43.       port[iobase + 7] := ord(ch);
  44.     end;
  45.   end;
  46.  
  47. function cts: boolean;
  48.  
  49. {This function returns true if a carrier tone is present on the modem
  50.  and is frequently checked to see if the caller is still present.
  51.  It always returns "true" in the local mode.}
  52.  
  53.   const checkvalue = 32; {change to 8 to monitor DCD line instead of CTS}
  54.  
  55.   begin
  56.     cts := ((port[iobase + 6] and checkvalue) = checkvalue) or local;
  57.   end;
  58.  
  59. function inready: boolean;
  60.  
  61. {Returns true if we've got a character received
  62.  from the serial port or keyboard.}
  63.  
  64.   begin
  65.     inready := keypressed or ((port[iobase + 6] and 1) > 0);
  66.   end;
  67.  
  68. function recvchar: char;
  69.  
  70. {Returns character from serial input port,
  71.   REGARDLESS of the status of inready.}
  72.  
  73.   begin
  74.     recvchar := chr(port[iobase + 7]);
  75.   end;
  76.  
  77. procedure setbaud(speed: rate);
  78.  
  79. {For changing the hardware baud rate setting}
  80.  
  81.   begin
  82.     port[iobase + 6] := 13;
  83.     port[iobase + 6] := 0;
  84.     port[iobase + 6] := 12;
  85.     case speed of
  86.       slow: port[iobase + 6] := 254;
  87.       fast: port[iobase + 6] := 62;
  88.     end;
  89.     baud := speed;
  90.   end;
  91.  
  92. procedure clearSIO;
  93.  
  94. { Initializes serial I/O chip:
  95.   sets up for 8 bits, no parity and one stop bit on both
  96.   transmit and receive, and allows character transmission
  97.   with CTS low. Also sets RTS line high. }
  98.  
  99.   begin
  100.     port[iobase + 6] := 0;   {Port A initialization:}
  101.     port[iobase + 6] := 9;
  102.     port[iobase + 6] := 192; {Master Reset}
  103.     port[iobase + 6] := 11;
  104.     port[iobase + 6] := 82;  {Select Baud Rate Generator}
  105.     port[iobase + 6] := 14;
  106.     port[iobase + 6] := 3;   {Turn Baud Rate Generator ON}
  107.     setbaud(fast);
  108.     port[iobase + 6] := 15;
  109.     port[iobase + 6] := 0;   {Disable External/Status Int}
  110.     port[iobase + 6] := 1;
  111.     port[iobase + 6] := 0;   {Disable all other Interrupts}
  112.     port[iobase + 6] := 3;
  113.     port[iobase + 6] := 193; {8 bits/char, enable receive}
  114.     port[iobase + 6] := 4;
  115.     port[iobase + 6] := 68;  {x16 clock, 1 stop, no parity}
  116.     port[iobase + 6] := 5;
  117.     port[iobase + 6] := 234; {enable xmit, raise RTS & DTR}
  118.     port[iobase + 4] := 0;   {Port B initialization:}
  119.     port[iobase + 4] := 15;
  120.     port[iobase + 4] := 0;   {Disable External/Status Int}
  121.     port[iobase + 4] := 1;
  122.     port[iobase + 4] := 0;   {Disable all other Interrupts}
  123.   end;
  124.  
  125. procedure clearmodem;        (* Modem Dependent *)
  126.  
  127. {Sets modem for auto-answer, CTS line as carrier detect, no command echo}
  128.  
  129.   var buffer: line;
  130.       loop  : byte;
  131.       ch    : char;
  132.  
  133.   begin
  134.     buffer := 'ATS0=1 V0 Q1';
  135.     for loop := 1 to length(buffer) do begin
  136.       ch := buffer[loop];
  137.       xmitchar(ch);
  138.       delay(50);
  139.     end;
  140.     xmitchar(#13);
  141.     writeln;
  142.     write('Delaying...');
  143.     delay(1000); {Delays while modem digests initialization codes}
  144.     writeln;
  145.   end;
  146.  
  147. procedure setup;
  148.  
  149. {Hardware initializion for system to start BBS program}
  150.  
  151.   begin
  152.     clearSIO;
  153.     clearmodem;
  154.   end;
  155.  
  156. function badframe: boolean;
  157.  
  158. {Indicates Framing Error on serial I/O chip - return false if not available.}
  159.  
  160.   begin
  161.     port[iobase + 6] := 1;
  162.     badframe := (port[iobase + 6] and 64) = 64;
  163.   end;
  164.  
  165. procedure dropRTS;
  166.  
  167. { Lowers RS-232 RTS line - used to inhibit auto-answer
  168.    and to cause modem to hang up }
  169.  
  170.   begin
  171.     port[iobase + 6] := 5;
  172.     port[iobase + 6] := 232;
  173.   end;
  174.  
  175. procedure raiseRTS;
  176.  
  177. (* Raises RTS line to enable auto-answer *)
  178.  
  179.   begin
  180.     port[iobase + 6] := 5;
  181.     port[iobase + 6] := 234;
  182.   end;
  183.  
  184. procedure setlocal;
  185.  
  186. {Sets local flag true and inhibits modem auto-answer}
  187.  
  188.   begin
  189.     dropRTS; {Inhibits auto-answer}
  190.     local := true;
  191.   end;
  192.  
  193. procedure clearlocal;
  194.  
  195. {Clears local flag and allows modem auto-answer}
  196.  
  197.   begin
  198.     raiseRTS; {Enables Auto-answer}
  199.     local := false;
  200.   end;
  201.  
  202. procedure unload;
  203.  
  204. {Halts Kaypro disk drives - normally they run for about 15 secs.}
  205.  
  206.   begin
  207.   end;
  208.  
  209. procedure dispcaller;
  210.  
  211. {Displays caller's name on protected 25th line of host CRT;
  212.  Replace with empty procedure if not desired.}
  213.  
  214.   begin
  215.   end;
  216.  
  217. procedure hangup;
  218.  
  219. {Signals modem to hang up - in this case by dropping RTS until CTS drops}
  220.  
  221.   begin
  222.     if cts then lineout('--- Disconnected ---' + cr + lf);
  223.     dropRTS;
  224.     if local then clearlocal else repeat until not cts;
  225.     raiseRTS;
  226.   end;
  227.  
  228. procedure flush;
  229.  
  230.   var junk: char;
  231.       loop: byte;
  232.  
  233.   begin
  234.     for loop := 1 to 3 do junk := recvchar;
  235.   end;
  236.  
  237. {Real-time clock support begins here - this routine is called
  238.  even if there is NO clock, so leave it and set clockin accordingly}
  239.  
  240. procedure clock(var month,date,hour,min,sec: byte);
  241.  
  242. {Returns with month in range 1(Jan)..12(Dec),
  243.  date in 1..length of month, hour in 0..23 (24-hr clock),
  244.  minute and second in 0..59}
  245.  
  246.   var
  247.     temp: integer;
  248.     tempint: integer;
  249.     temp1: byte;
  250.  
  251.   const monthmask = $000F;
  252.         daymask = $001F;
  253.         minutemask = $003F;
  254.         secondmask = $001F;
  255.   type  dtstr = string[8];
  256.         Register        = Record
  257.                           AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer;
  258.                           End;
  259.   var  tstr : dtstr;
  260.  
  261.   function getdate : dtstr;
  262.  
  263.   var
  264.     allregs : register;
  265.     month, day,
  266.     year    : string[2];
  267.     i       : integer;
  268.     tstr    : dtstr;
  269.  
  270.   begin
  271.      allregs.ax := $2A * 256;
  272.      MsDos(allregs);
  273.      str((allregs.dx div 256):2,month);
  274.      str((allregs.dx mod 256):2,day);
  275.      str((allregs.cx - 1900):2,year);
  276.      tstr := month + '/' + day + '/' + year;
  277.      for i := 1 to 8 do
  278.        if tstr[i] = ' ' then
  279.          tstr[i] := '0';
  280.      getdate := tstr;
  281.   end;  {getdate}
  282.  
  283.   function gettime : dtstr;
  284.  
  285.   var
  286.    allregs : register;
  287.    hour, minute,
  288.    second  : string[2];
  289.    i       : integer;
  290.    tstr    : dtstr;
  291.  
  292.   begin
  293.      allregs.ax := $2C * 256;
  294.      MsDos(allregs);
  295.      str((allregs.cx div 256):2,hour);
  296.      str((allregs.cx mod 256):2,minute);
  297.      str((allregs.dx div 256):2,second);
  298.      tstr := hour + ':' + minute + ':' + second;
  299.      for i := 1 to 8 do
  300.        if tstr[i] = ' ' then
  301.          tstr[i] := '0';
  302.      gettime := tstr;
  303.   end;  {gettime}
  304.  
  305.   begin
  306.     val(copy(getdate,1,2),tempint,temp);
  307.     month := lo(tempint);
  308.     val(copy(getdate,4,2),tempint,temp);
  309.     date := lo(tempint);
  310.     val(copy(gettime,1,2),tempint,temp);
  311.     hour := lo(tempint);
  312.     val(copy(gettime,4,2),tempint,temp);
  313.     min := lo(tempint);
  314.     val(copy(gettime,7,2),tempint,temp);
  315.     sec := lo(tempint);
  316.   end;
  317.