home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol072 / dcmodem.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1984-04-29  |  5.6 KB  |  233 lines

  1. { Donated by Warren Smith, Feb 1982 }
  2.  
  3. Module DC_Hayes_Modem;
  4.  
  5. { This set of routines was originally written in Pascal MT+ so there may }
  6. { be some discrepencies you will have to iron out.  In particular, there }
  7. { is use of some built in routines, TSTBIT, CLRBIT, SETBIT.  These       }
  8. { routines perform the following functions -                 }
  9. {            TSTBIT - returns TRUE if the bit is set         }
  10. {            CLRBIT - clears the bit number specified     }
  11. {            SETBIT - sets the bit number specified         }
  12. { All of these routines operate on variables of type BYTE = 0..255     }
  13.  
  14. { PortIn and PortOut are used here even though Pascal MT+ doesn't need   }
  15. { them.  I hope the syntax is correct for your compiler.         }
  16.  
  17. { Port assignments for D.C. Hayes S-100 Modem board }
  18. Const
  19.     Reg1Modem    = $11;
  20.     Reg2Modem    = $12;
  21.     Status_Reg_Modem= $11;
  22.     Modem_Rcv_Reg    = $10;
  23.     Modem_Xmit_Reg    = $10;
  24.  
  25.  
  26. Procedure Init_Modem;
  27.  
  28.   Const    Char_Length     = 3;    { 8 data bits    }
  29.     Stop_bits    = 0;    { 1 stop bits    }
  30.     Parity_Inhibit    = 1;    { no parity    }
  31.     Parity_Type    = 1;    { even parity    }
  32.  
  33.   begin { Init_Modem }
  34.     { This routine is intended for use as an initializing routine    }
  35.     { if your serial port needs it.  You should set up your port    }
  36.     { to match the comments above. }
  37.   PortOut (Reg1Modem, Parity_Inhibit*16 + Stop_Bits*8 + Char_Length*2 +
  38.             Parity_Type)
  39.   end;  { Init_Modem }
  40.  
  41. Procedure Set_Modem (Modebyte : byte);
  42.  
  43.   begin { Set_Modem }
  44.     { This routine lets you change the various modes of the modem.    }
  45.   PortOut (Reg2Modem, Modebyte)
  46.   end;  { Set_Modem }
  47.  
  48. Procedure Go_Onhook (Var Modem_Mode : byte);
  49.  
  50.   begin { Go_Onhook }
  51.   Clrbit (Modem_Mode, 7);
  52.   Set_Modem (Modem_Mode)
  53.   end;  { Go_Onhook }
  54.  
  55. Procedure Go_Offhook (Var Modem_Mode : byte);
  56.  
  57.   begin { Go_Offhook }
  58.   SetBit (Modem_Mode, 7);
  59.   Set_Modem (Modem_Mode)
  60.   end;  { Go_Offhook }
  61.  
  62. Procedure Set_Ans_Mode (Var Modem_Mode : byte);
  63.  
  64.   begin { Set_Ans_Mode }
  65.   Clrbit (Modem_Mode, 2);
  66.   Set_Modem (Modem_Mode)
  67.   end;  { Set_Modem_Mode }
  68.  
  69. Procedure Set_Org_Mode (Var Modem_Mode : byte);
  70.  
  71.   begin { Set_Org_Mode }
  72.   Setbit (Modem_Mode, 2);
  73.   Set_Modem (Modem_Mode)
  74.   end;  { Set_Org_Mode }
  75.  
  76. Procedure Set_110bps (Var Modem_Mode : byte);
  77.  
  78.   begin { Set_110bps }
  79.   Clrbit (Modem_Mode, 0);
  80.   Set_Modem (Modem_Mode)
  81.   end;  { Set_110bps }
  82.  
  83. Procedure Set_300bps (Var Modem_Mode : byte);
  84.  
  85.   begin { Set_300bps }
  86.   Setbit (Modem_Mode, 0);
  87.   Set_Modem (Modem_Mode)
  88.   end;  { Set_300bps }
  89.  
  90. Procedure Enable_Xmit (Var Modem_Mode : byte);
  91.  
  92.   begin { Enable_Xmit }
  93.   Setbit (Modem_Mode, 1);
  94.   Set_Modem (Modem_mode)
  95.   end;  { Enable_Xmit }
  96.  
  97. Procedure Disable_Xmit (Var Modem_Mode : byte);
  98.  
  99.   begin { Disable_Xmit }
  100.   Clrbit (Modem_Mode, 1);
  101.   Set_Modem (Modem_Mode)
  102.   end;  { Disable_Xmit }
  103.  
  104. Function Carrier_Present : boolean;
  105.  
  106.   Var
  107.     Status    : byte;
  108.  
  109.   begin { Carrier_Present }
  110.   PortIn (Status_Reg_Modem, Status);
  111.   Carrier_Present := Tstbit (Status, 6)
  112.   end;  { Carrier_Present }
  113.  
  114. Function Ringing : boolean;
  115.  
  116.   Var
  117.     Status    : byte;
  118.  
  119.   begin { Ringing }
  120.   PortIn (Status_Reg_Modem, Status);
  121.   Ringing := not Tstbit (Status, 7)
  122.   end;  { Ringing }
  123.  
  124. Function Modem_Char_Rdy : boolean;
  125.  
  126.   Var
  127.     Status    : byte;
  128.  
  129.   begin { Modem_Char_Rdy }
  130.     { Returns TRUE if data is available in the input port    }
  131.     { (does NOT read the data) }
  132.   PortIn (Status_Reg_Modem, Status);
  133.   Modem_Char_Rdy := Tstbit (Status, 0)
  134.   end;  { Modem_Char_Rdy }
  135.  
  136. Function Modem_In : char;
  137.  
  138.   Var
  139.     In_Char    : byte;
  140.  
  141.   begin { Modem_In }
  142.     { Reads the data port of the acoustic coupler.  May have to    }
  143.     { mask off bit 7 of the data if the sender is not treating it    }
  144.     { as part of the data byte sent. }
  145.   PortIn (Modem_Rcv_Reg, In_Char);
  146.   Modem_In := chr(In_Char & $7F)
  147.   end;  { Modem_In }
  148.  
  149. Function Modem_Out (OutChar : char) : boolean;
  150.  
  151.   Var
  152.     Status : byte;
  153.  
  154.   Function Modem_Busy : boolean;
  155.  
  156.     Var
  157.     Status    : byte;
  158.  
  159.     begin { Modem_Busy }
  160.     { Returns TRUE if the transmit buffer empty bit of status port    }
  161.     { indicates that the UART is still transmitting.        }
  162.     PortIn (Status_Reg_Modem, Status);
  163.     Modem_Busy := not Tstbit (Status, 1)
  164.     end;  { Modem_Busy }
  165.  
  166.   begin { Modem_Out }
  167.   While Modem_Busy do;
  168.   If Carrier_Present then
  169.     begin
  170.     PortOut (Modem_Xmit_Reg, ord(OutChar));
  171.     Modem_Out := TRUE
  172.     end
  173.   else
  174.     Modem_Out := FALSE
  175.   end;  { Modem_Out }
  176.  
  177. Procedure Delay;    { delay's for 10 millisecond }
  178.  
  179.   Const
  180.     Count = 477;
  181.   Var
  182.     I : integer;
  183.   begin { Delay }
  184.     { Very machine dependent.  I am using a 5 MHz 8085, running    }
  185.     { Pascal MT+ 5.5 if that helps. }
  186.   For I := 1 to Count do
  187.   end;  { Delay }
  188.  
  189. Procedure Dial_a_Number (Var Modem_Mode : byte; Number : string);
  190.  
  191.   Var
  192.     I, J, K, Pulse_Count : integer;
  193.  
  194.   Procedure Pulse_Line;
  195.  
  196.     Var
  197.     I : integer;
  198.     begin { Pulse_Line }
  199.     Go_Onhook (Modem_Mode);
  200.     For I := 1 to 5 do
  201.       Delay;            { leave on for 50 ms }
  202.     Go_Offhook (Modem_Mode);
  203.     For I := 1 to 5 do
  204.       Delay            { leave off for 50 ms }
  205.     end;  { Pulse_Line }
  206.  
  207.   begin { Dial_a_Number }
  208.   Go_Offhook (Modem_Mode);
  209.   For I := 1 to 100 do        { Wait for dial tone    }
  210.     Delay;
  211.   For I := 1 to Length(Number) do
  212.     If (Number[I] < '0') OR (Number[I] > '9') then
  213.       begin
  214.       Write (Number[I]);
  215.       For J := 1 to 300 do    { wait 3 seconds for non_digit }
  216.     Delay
  217.       end
  218.     else
  219.       begin
  220.       Pulse_Count := ord(Number[I]) - $30;
  221.       If Pulse_Count = 0 then
  222.     Pulse_Count := 10;
  223.       Write (Number[I]);
  224.       For J := 1 to Pulse_Count do
  225.     Pulse_Line;
  226.       For J := 1 to 60 do
  227.     Delay            { 600 ms delay between digits }
  228.       end;
  229.   Writeln
  230.   end;  { Dial_a_Number }
  231.  
  232. Modend.
  233.