program dial;

{This program is written using Turbo Pascal.  It accepts user input to
dial the Hayes SmartModem 1200.  MS-DOS interrupts are used for RS232
communications, so even though this was written on a Tandy 2k, it shoul
work in the IBM and the host of compatables.  If you have trouble
communicating with the serial port, check and change as needed the
value assigned to DL in talk.  It selects the COM port which runs the modem}

{initialize for MS DOS interrupt call}
type
     regipak = record ax,bx,cx,dx,bp,di,ds,es,flags:integer;
     end;

var
    dm:byte;
    mypak: regipak;
    ah,al,bh,bl,ch,cl,dh,dl,bph,bpl,dih,dil,dsh,dsl: byte;
    cx,len,ct:integer;
    ir:byte;
    dialit,LAST,NUMBER,personal,prefix:string[40];
    dummy,digit:char;

procedure talk;
{Send characters to the modem}
begin
  textcolor(14); textbackground(1);
     with mypak do
     begin
     ax := ah shl 8 + al;
     dx := dh shl 8 + dl;
     intr($14,mypak);
     end;
end;

procedure send_line;
{Break the number apart and TALK to the modem}
begin
    NUMBER:=CONCAT(prefix,DIALIt,chr(13));
    len:=length(number);
    ct:=1;
      while ct<=len do
          begin
          digit:=copy(number,ct,1);
          al:=ord(digit);
          ah:=1;
          dl:=0;
          talk;
          ct:=ct+1;
       end;
end;

procedure setup;
{set communications parameters}
begin
     ah:=0;
     dl:=0;
     al:=131;
     talk;
     ah:=4;
     dl:=0;
     talk;
end;

procedure hangup;
{What else, but hang up the modem}
begin
    textbackground(7); textcolor(1);
    gotoxy(26,20);
    writeln(' Hit [ENTER] to hang up modem ');
    read(dummy);
    dialit:='h0';
    send_line;
end;


PROCEDURE MAIN;
{Get the number to dial or special commands}
begin
  textcolor(14); textbackground(1);
     setup;
           writeln(''); gotoxy(10,05);
           write('Number to Dial ( . = quit  [ENTER] = last number): ');
           readln(dialit);
              if dialit='' then
              begin
              dialit:=last;
              end;
           LAST:=DIALIT;
     if last<>'.' then
     begin
gotoxy(37,12);
write ('Dialing ');
gotoxy(37,14); textbackground(4); textcolor(15);
writeln(dialit);
     send_line;
     hangup;
     clrscr
     end;
clrscr
end;

BEGIN
textcolor(14); textbackground(1);
 {Get and store the prefix code and get down to business}
 clrscr;
 gotoxy(07,08);
 writeln(' Enter personal dialing code  (MCI access etc) or [enter] for none ');
 gotoxy(11,10);
 writeln(' This code remains active for the complete dialing session ');
 gotoxy(30,12);
 readln(personal);
 prefix:=concat('ATDT',personal);
 clrscr;
     WHILE LAST<>'.' do
     begin
     main;
     end;
last:='ddd';
end.
                                                                                                                             