home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / PARADIS1 / COMSTUFF.PAS < prev    next >
Pascal/Delphi Source File  |  1992-02-26  |  12KB  |  490 lines

  1. (7448)  Fri 21 Feb 92 19:18
  2. By: Steve Sparks
  3. To: Ed Briggs
  4. Re: A unit
  5. St:
  6. ---------------------------------------------------------------------------
  7. @EID:9d72 18559a40
  8. unit modemio;  {(c) Copyright Steven S. Sparks 1992.}
  9.  
  10. { If you would like Xmodem and Timer routines NETMAIL Steve Sparks at 382/104
  11.  
  12. This unit was developed for anyone needing simple communications.
  13. You can use this to develop communications programs from bulletin boards
  14. to terminal programs.
  15.  
  16. Hopefully this is one of the least complicated MODEMIO units you will ever
  17. use. The reason behind this is that all the complicated IO - buffering,
  18. IRQ,INT and other problems are left to a Fossil driver.
  19.  
  20. This UNIT REQUIRES X00.SYS to operate properly. When you compile this UNIT you
  21. must have from the X00_???.ZIP a copy of BYPASS.OBJ. This will allow the
  22. extended communications of X00.SYS to be used.
  23.  
  24. If you do not have BYPASS.OBJ then you can delete the include of
  25. BYPASS.OBJ, delete the BYPASS function and change all the BYPASS refrences to
  26. INTER($14,regs).
  27.  
  28. HOWEVER THE USE OF BYPASS WILL ALLOW COM3,COM4 AND IRQ2 AND IRQ5 support!
  29.  
  30. If you use BYPASS you may notice some after effects of the fossil in memory
  31. once the communications program is executed. This can be resolved by re-booting
  32. your machine. The effect is only there onec the fossil has been active.
  33.  
  34. I have yet to figure out this problem/bug..is it my routines or the fossil.
  35.  
  36. These routines are COPYRIGHT Steven S. Sparks 1992. However anyone can use then
  37. for anything. If you sell a product that contains any part of this unit you
  38. must include a notation to the effect. No money or fee is required.
  39.  
  40.  
  41. }
  42.  
  43. interface
  44.  
  45. uses crt;
  46.  
  47. var
  48.  local:boolean;
  49.  
  50. { Local is a variable used to help determine if there is a carrier. You are
  51. required to pass this variable to the CD routine.
  52.  
  53. if cd(local,comport) then writeln('Connected!');
  54.  
  55. If you set local:=true then CD is true, else if local:=false then CD is the
  56. actual value of the CD bit. This is very helpful when testing a routine.
  57.  
  58. You should program your routines to prevent output
  59. to the serial port but to the screen if local is true. This is helpful
  60. when testing your program
  61.  
  62. }
  63.  
  64. procedure flowcontrol(comport:integer); {Xon/Xoff Turn off for file xfers}
  65. procedure flowoff(comport:integer);
  66. procedure watchdogon(comport:integer);  {Reboot PC if lost CD}
  67. procedure watchdogoff(comport:integer);
  68. procedure purgeinput(comport:integer);  {Purge buffers}
  69. procedure purgeoutput(comport:integer);
  70. procedure hangup(comport:integer);      {Lower then raise DTR}
  71. procedure initmodem(com:integer; baud:char); {Set baud...examine reoutine}
  72. procedure sendc(com: integer; c:char);
  73. procedure sendxc(com:integer; c:char);
  74. procedure getc(com:integer; var c:char);
  75. procedure getxc(com:integer; var c:integer);
  76. procedure startcom(com:integer);             {RUN THIS FIRST TO START FOSSIL}
  77. procedure stopcom(com:integer);              {THIS TURNS THE FOSSIL OFF!!!}
  78.  
  79. {procedure bypass; far; external;  - This is not needed outside of modemio }
  80.  
  81. function cd(var local:boolean; port:integer) : boolean;
  82. function ring(comport:integer) : boolean;
  83.  
  84. implementation
  85.  
  86. {$L bypass.obj}
  87.  
  88. procedure bypass; far; external;
  89.  
  90. procedure flowcontrol(comport:integer);
  91.  
  92.           begin
  93.             comport:=comport-1;
  94.            asm
  95.              mov dx,comport
  96.              mov al,$ff
  97.              mov ah,$0f
  98.            end;
  99.               bypass;
  100.          end;
  101.  
  102. procedure flowoff(comport:integer);
  103.           begin
  104.            comport:=comport-1;
  105.            asm
  106.             mov dx,comport
  107.             mov ah,$0f
  108.             mov al,$00
  109.           end;
  110.            bypass;
  111.          end;
  112.  
  113. procedure watchdogon(comport:integer);
  114.  
  115.           begin
  116.             comport:=comport-1;
  117.            asm
  118.              mov dx,comport
  119.              mov al,$01
  120.              mov ah,$14
  121.            end;
  122.               bypass;
  123.          end;
  124.  
  125. procedure watchdogoff(comport:integer);
  126.  
  127.           begin
  128.             comport:=comport-1;
  129.            asm
  130.              mov dx,comport
  131.              mov al,$00
  132.              mov ah,$14
  133.            end;
  134.               bypass;
  135.          end;
  136.  
  137.  
  138. procedure flush(comport:integer);
  139.  
  140.           begin
  141.             comport:=comport-1;
  142.             asm
  143.              mov dx,comport
  144.              mov ah,$08
  145.             end;
  146.             bypass;
  147.          end;
  148.  
  149. procedure purgeoutput(comport:integer);
  150.           begin
  151.             comport:=comport-1;
  152.             asm
  153.              mov dx,comport
  154.              mov ah,09
  155.            end;
  156.            bypass;
  157.           end;
  158.  
  159. procedure purgeinput(comport:integer);
  160.           begin
  161.            comport:=comport-1;
  162.            asm
  163.             mov dx,comport
  164.             mov ah,$0A
  165.            end;
  166.            bypass;
  167.           end;
  168.  
  169.  
  170.  
  171.  
  172. { Initlize com comport.  }
  173. procedure initmodem(com:integer; baud:char);
  174.           var
  175.            b    : integer;
  176.            rate : byte;
  177.  
  178.           begin
  179.  
  180.           case baud of
  181.                '1': b:=$43; {300n}
  182.                '2': b:=$83; {1200n}
  183.                '3': b:=$a3; {2400n}
  184.                '4': b:=$e3; {9600n}
  185.  
  186.               else begin
  187.                      writeln('     BAUD SET NOT VALID 300N - DEFALT');
  188.                      b:=$43;
  189.                    end;
  190.               end; {case}
  191.  
  192.           case baud of
  193.               '1': writeln('  Baud: 300,N,8,1');
  194.               '2': writeln('  Baud: 1200,N,8,1');
  195.               '3': writeln('  Baud: 2400,N,8,1');
  196.               '4': writeln('  Baud: 9600,N,8,1');
  197.  
  198.               else begin
  199.                      writeln('     BAUD SET NOT VALID 300N - DEFALT');
  200.                    end;
  201.               end; {case}
  202.  
  203.                  com:=com-1;
  204.                  rate:=b;
  205.                 asm
  206.                   mov dx,com
  207.                   mov ah,$00
  208.                   mov al,rate
  209.                 end;
  210.                 bypass;
  211.           end;
  212.  
  213.  
  214.  
  215. FUNCTION cd(var local:boolean; port:integer) : BOOLEAN;
  216.           var
  217.            temp   : boolean;
  218.            result : byte;
  219.  
  220.           begin
  221.  
  222.             temp:=false;
  223.  
  224.             port := port-1;
  225.                asm
  226.                  mov dx,port
  227.                  mov ah,$03;
  228.                  mov al,$00
  229.                end;
  230.              bypass;
  231.                asm
  232.                 mov result,al
  233.                end;
  234.  
  235.              IF result AND $80 = 128 THEN temp:=TRUE
  236.                                      ELSE temp:=FALSE;
  237.  
  238.              if local=true then temp:=true;
  239.  
  240.              cd:=temp;
  241.  
  242.          end;
  243.  
  244. procedure hangup(comport:integer);
  245.           var
  246.            count:integer;
  247.  
  248.  
  249.     procedure lower(comport:integer);
  250.           begin
  251.             comport:=comport-1;
  252.             asm
  253.              mov dx,comport
  254.              mov ah,$06
  255.              mov al,$00
  256.             end;
  257.             bypass;
  258.           end;
  259.  
  260.     procedure higher(comport:integer);
  261.           begin
  262.             comport:=comport-1;
  263.             asm
  264.              mov dx,comport
  265.              mov ah,$06
  266.              mov al,$01
  267.             end;
  268.             bypass;
  269.           end;
  270.  
  271.         begin
  272.         count:=0;
  273.         repeat
  274.           count:=count+1;
  275.           flowoff(comport);
  276.           flush(comport);
  277.           lower(comport);
  278.           delay(1000);
  279.           higher(comport);
  280.           local:=false;
  281.           if count>1 then writeln(' Error: CAN NOT DROP CARRIER!');
  282.          until not cd(local,comport) or (count>=255);
  283.          if count>=255 then halt(0);
  284.  
  285.         end;
  286.  
  287.  
  288. function ring(comport:integer) : boolean;
  289.  
  290.           var
  291.            result : byte;
  292.  
  293.           begin
  294.              comport:=comport-1;
  295.             asm
  296.              mov dx,comport
  297.              mov ah,$03
  298.              mov al,$00
  299.             end;
  300.             bypass;
  301.             asm
  302.              mov result,al
  303.             end;
  304.  
  305.              IF result AND 64 = 64 THEN ring:=TRUE
  306.                                     ELSE ring:=FALSE;
  307.  
  308.          end;
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315. {Sends a character to the modem }
  316. procedure sendc(com: integer; c:char);
  317.           var
  318.            x : byte;
  319.            sx,sy : integer;
  320.            loop  : integer;
  321.  
  322.           begin
  323.  
  324.             com:=com-1;
  325.             x:=ord(c);
  326.  
  327.             asm
  328.              mov dx,com
  329.              mov ah,$01
  330.              mov al,x;
  331.             end;
  332.             bypass;
  333.  
  334.  
  335.           end;
  336.  
  337.  
  338. procedure sendxc(com:integer; c:char);
  339.  
  340.           var
  341.            sx,sy : integer;
  342.            x     : byte;
  343.           begin
  344.  
  345.             com:=com-1;
  346.             x:=ord(c);
  347.  
  348.             asm
  349.              mov dx,com
  350.              mov ah,$01
  351.              mov al,x
  352.             end;
  353.             bypass;
  354.  
  355.           end;
  356.  
  357.  
  358. procedure getc(com:integer; var c:char);
  359.  
  360.           var
  361.            result : byte;
  362.            sx,sy : integer;
  363.  
  364.           begin
  365.  
  366.             c:=chr(0);
  367.             com:=com-1;
  368.             asm
  369.              mov dx,com
  370.              mov ah,$03
  371.              mov al,$00
  372.             end;
  373.             bypass;
  374.             asm
  375.              mov result,ah
  376.            end;
  377.  
  378.            if result and 1 = 1
  379.               then begin
  380.  
  381.  
  382.                      asm
  383.                       mov dx,com
  384.                       mov ah,$02
  385.                       mov al,$00
  386.                      end;
  387.                      bypass;
  388.                      asm
  389.                       mov result,al
  390.                      end;
  391.  
  392.                      c:=chr(result);
  393.  
  394.                    end;
  395.  
  396.             if c=chr(7) then c:=chr(0);
  397.             if c='+' then c:=chr(0);
  398.             if c=chr(26) then c:=chr(0);
  399.  
  400.           end;
  401.  
  402.  
  403.  
  404. procedure getxc(com:integer; var c:integer);
  405.  
  406.           var
  407.            result : byte;
  408.            sx,sy : integer;
  409.  
  410.           begin
  411.  
  412.             c:=-1;
  413.             com:=com-1;
  414.             result:=00;
  415.  
  416.             asm
  417.              mov dx,com
  418.              mov ah,$03
  419.              mov al,$00
  420.             end;
  421.             bypass;
  422.             asm
  423.              mov result,ah
  424.             end;
  425.  
  426.            if result and 1 = 1
  427.               then begin
  428.                      asm
  429.                        mov dx,com
  430.                        mov ah,$02
  431.                        mov al,$00
  432.                      end;
  433.                      bypass;
  434.                      asm
  435.                       mov result,al
  436.                      end;
  437.  
  438.                      c:=result;
  439.                    end;
  440.  
  441.           end;
  442.  
  443.  
  444. procedure startcom(com:integer);
  445.           var
  446.            result : integer;
  447.  
  448.           begin
  449.              com:=com-1;
  450.             asm
  451.               mov ax,$0000
  452.               mov dx,com
  453.               mov ah,$04
  454.             end;
  455.              bypass;
  456.             asm
  457.              mov result,ax
  458.             end;
  459.  
  460.  
  461.           if result <> $1954 then
  462.                         begin
  463.                           writeln;
  464.                           writeln('  Fossil not supporting Com',com+1,' or
  465. Fossil not installed.');
  466.                           halt(0);
  467.                        end;
  468.  
  469.           end;
  470.  
  471. procedure stopcom(com:integer);
  472.           begin
  473.             asm
  474.              mov dx,com
  475.              mov ah,$05
  476.             end;
  477.             bypass;
  478.           end;
  479.  
  480. END.
  481.  
  482. local:=true;
  483.  
  484.  
  485.  
  486. --- msged 2.05
  487.  * Origin: Quick_Mail  (1:382/104)
  488.  
  489. @PATH: 382/104 3 1 147/46 13/13 396/1 170/400 512/0 1007 
  490.