home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / DOORPROC.ZIP / DOORPROC.PAS
Encoding:
Pascal/Delphi Source File  |  1986-11-07  |  5.8 KB  |  204 lines

  1. type
  2.   CPUregs = record
  3.               AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer;
  4.             end;
  5.   MaxString = string [80];
  6.  
  7.  
  8.  
  9. procedure Print (output:MaxString); forward;
  10. procedure Println (output:MaxString); forward;
  11. procedure Exit; forward;
  12.  
  13.  
  14. function Carrier : boolean;  {This function looks for a carrier and returns
  15.                               TRUE if one exists, FALSE if one doesn't}
  16. var
  17.   regs : CPUregs;
  18.  
  19. begin
  20.   regs.AX:=$0300;
  21.   regs.DX:=$0000;           {Change to regs.DX:=$0001; for COM2:)
  22.   Intr ($14,regs);
  23.   if (Lo(regs.AX)>=128) then Carrier:=true else Carrier:=false;
  24. end;
  25.  
  26.  
  27.  
  28.  
  29. function SerialChar : boolean;  {This function checks to see if a character
  30.                                  is available from the COM1: port.  TRUE if
  31.                                  one is, FALSE if one isn't}
  32. var
  33.   regs : CPUregs;
  34.  
  35. begin
  36.   regs.AX:=$0300;
  37.   regs.DX:=$0000;               {Change to regs.DX:=$0001; for COM2:)
  38.   Intr ($14,regs);
  39.   if (Odd(Hi(regs.AX)) and (OrgCarr=true)) then SerialChar:=true
  40.     else SerialChar:=false;
  41. end;
  42.  
  43. function KeyChar : boolean;    {This function checks to see if a character is
  44.                                 available from the keyboard.  TRUE if one is,
  45.                                 FALSE if one isn't.}
  46. var
  47.   regs : CPUregs;
  48.  
  49. begin
  50.   regs.AX:=$0B00;
  51.   MsDos(regs);
  52.   if (Lo(regs.AX)=0) then KeyChar:=false
  53.     else KeyChar:=true;
  54. end;
  55.  
  56. Function Inkey:char;            {This functions like the BASIC INKEY$, only
  57.                                  it returns the first character from the
  58.                                  keyboard OR the modem.  All input is done
  59.                                  through this function}
  60. var
  61.  tc : char;
  62.  AL :  Integer;
  63.  finished : boolean;
  64.  
  65. Begin
  66.   finished:=false;
  67.   tc:='Q';
  68.   if ((OrgCarr=true) and (Carrier=false)) then Exit;
  69.   repeat
  70.     if SerialChar then
  71.     begin
  72.       param.AX:=$0200;
  73.       param.DX:=$0000;
  74.       Intr($14,param);
  75.       AL:=Lo(param.AX);
  76.       tc:=chr(AL);
  77.       finished:=true;
  78.     end else
  79.     if KeyChar then
  80.     begin
  81.       param.AX:=$0700;
  82.       MsDos(param);
  83.       AL:=Lo(param.AX);
  84.       tc:=chr(AL);
  85.       finished:=true;
  86.     end
  87.   until Finished;
  88.   InKey:=tc;
  89. End;
  90.  
  91.  
  92. function Input(num:integer):MaxString;      {This function returns a string
  93.                                              of length num.  It uses the Inkey
  94.                                              function, and will not allow the
  95.                                              user to enter more than num
  96.                                              characters.}
  97. var
  98.   ts : MaxString;
  99.   tc : char;
  100.  
  101. begin
  102.   cnt:=0;
  103.   ts:='';
  104.   repeat
  105.     tc:=Inkey;
  106.     if (tc=chr(8)) then
  107.     begin
  108.       if (cnt>0) then
  109.       begin
  110.         ts:=Copy (ts,1,(Length(ts)-1));
  111.         Print (tc+' '+tc);
  112.         cnt:=cnt-1;
  113.       end;
  114.     end else
  115.      if (tc<>chr(13)) and (cnt<num) then
  116.      begin
  117.        ts:=ts+tc;
  118.        Print (tc);
  119.        cnt:=cnt+1;
  120.      end;
  121.   until (tc=chr(13));
  122.   Println ('');
  123.   Input:=ts;
  124. end;
  125.  
  126.  
  127.  
  128. procedure Println;                          {This procedure mimics Writeln,
  129.                                              only it also sends to the modem
  130.                                              if there is a carrier, and to the
  131.                                              printer if the boolean variable
  132.                                              printer is TRUE}
  133. begin
  134.   Writeln (output);
  135.   if Carrier then Writeln (aux,output);
  136.   if Printer then Writeln (lst,output);
  137. end;
  138.  
  139. procedure Print;                           {Same as above, only without a
  140.                                             CR/LF at the end, to enable you
  141.                                             to continue writing on the same
  142.                                             line}
  143. begin
  144.   Write (output);
  145.   if Carrier then Write (aux,output);
  146.   if Printer then Write (lst,output);
  147. end;
  148.  
  149. procedure cls;                            {Clears both the local screen and
  150.                                            the screen of the modem user}
  151. begin
  152.   print (chr(12));
  153.   ClrScr;
  154. end;
  155.  
  156. procedure Exit;                           {Sends the user back to RBBS.  I
  157.                                            exit this "non-standard" way in
  158.                                            to enable a return to RBBS if the
  159.                                            Carrier is lost (i.e. User hangs
  160.                                            up on the program)}
  161. begin
  162.   Println ('Now returning to RBBS.  Please stand by...');
  163.   Port[$3FC]:=Port[$3FC] Or 1;
  164.   if ((OrgCarr=true) and (Carrier=false)) then Intr ($20,param);
  165. end;
  166.  
  167.  
  168.  
  169. procedure Init;                       {This is used to initialize the modem
  170.                                        and generally set everything up.  Call
  171.                                        this procedure before you do any screen
  172.                                        I/O, or even call cls.  If you don't,
  173.                                        the PC refuses to recognize input from
  174.                                        the modem.}
  175. var
  176.   messages : file of string[128];
  177.   r : string [128];
  178.   bps : integer;
  179.   Code : integer;
  180.  
  181. begin
  182.   Printer:=false;
  183.   OrgCarr:=Carrier;
  184.   if OrgCarr then
  185.   begin
  186.     Assign (messages,'B:MESSAGES');   {Sysops, make sure this is the drive
  187.                                        that your MESSAGES file is on!}
  188.     Reset (messages);
  189.     Seek (messages,2);
  190.     Read (messages,r);
  191.     Val((Copy(r,44,2)),bps,Code);
  192.     if (bps=-3) then param.AX:=$0043
  193.       else param.AX:=$0083;
  194.     Intr($14,param);
  195.     Close (messages);
  196.   end;
  197. end;
  198.  
  199. {Well, that's about it.  I hope these procedures help all you aspiring Doors
  200. programmers out, and I really hope we see a whole lot more useful Doors for
  201. RBBS out there.  Good Luck!
  202.      -JV-
  203. }
  204.