home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TMOD.ZIP / TMOD.PAS
Encoding:
Pascal/Delphi Source File  |  1986-02-23  |  6.2 KB  |  291 lines

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