home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / bbs / pibterm / pibt3sp3 / receivea.pas < prev    next >
Pascal/Delphi Source File  |  1985-09-11  |  6KB  |  159 lines

  1. (*----------------------------------------------------------------------*)
  2. (*                Receive_Ascii_File --- Download ASCII file            *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. OVERLAY PROCEDURE Receive_Ascii_File;
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Procedure:  Receive_Ascii_File                                   *)
  10. (*                                                                      *)
  11. (*     Purpose:    Downloads ASCII file to PC                           *)
  12. (*                                                                      *)
  13. (*     Calling Sequence:                                                *)
  14. (*                                                                      *)
  15. (*        Receive_Ascii_File;                                           *)
  16. (*                                                                      *)
  17. (*     Calls:   KeyPressed                                              *)
  18. (*              Async_Send                                              *)
  19. (*              Async_Receive                                           *)
  20. (*              Async_Percentage_Used                                   *)
  21. (*                                                                      *)
  22. (*     Remarks:                                                         *)
  23. (*                                                                      *)
  24. (*        XON/XOFF is assumed to be supported by the host.              *)
  25. (*                                                                      *)
  26. (*----------------------------------------------------------------------*)
  27.  
  28. VAR
  29.    Ch         : CHAR;
  30.    Fin        : BOOLEAN;
  31.    XOFF_Sent  : BOOLEAN             (* TRUE if XOFF sent to host *);
  32.    X          : INTEGER;
  33.    Y          : INTEGER;
  34.    N_Xoff     : INTEGER;
  35.    Line_Count : REAL;
  36.    Byte_Count : REAL;
  37.  
  38. (*----------------------------------------------------------------------*)
  39. (*  Update_Ascii_Receive_Display --- Update display of Xmodem reception *)
  40. (*----------------------------------------------------------------------*)
  41.  
  42. PROCEDURE  Update_Ascii_Receive_Display;
  43.  
  44. BEGIN (* Update_Ascii_Receive_Display *)
  45.  
  46.    GoToXY( 17 , 1 );
  47.    WRITE( Line_Count:8:0 );
  48.    GoToXY( 17 , 2 );
  49.    WRITE( Byte_Count:8:0 );
  50.  
  51. END   (* Update_Ascii_Receive_Display *);
  52.  
  53. (*----------------------------------------------------------------------*)
  54.  
  55. BEGIN (* Receive_Ascii_File *)
  56.  
  57.    Fin        := FALSE;
  58.    XOFF_Sent  := FALSE;
  59.    N_Xoff     := 0;
  60.    Line_Count := 0;
  61.    Byte_Count := 0;
  62.                                    (* Open display window for transfer  *)
  63.    Save_Screen( Saved_Screen );
  64.  
  65.    Draw_Menu_Frame( 15, 10, 78, 17, Menu_Frame_Color,
  66.                     Menu_Text_Color,
  67.                     'Receive file ' + FileName + ' using ASCII' );
  68.  
  69.                                    (* Headings for status information *)
  70.    Window( 16, 11, 77, 16 );
  71.  
  72.    WRITELN(' Lines received: ');
  73.    WRITELN(' Bytes received: ');
  74.    WRITELN(' ');
  75.                                    (* Open reception file *)
  76.    ASSIGN( Afile, FileName );
  77.    REWRITE( AFile );
  78.  
  79.    REPEAT
  80.  
  81.       IF Async_Percentage_Used > 0.75 THEN
  82.          BEGIN  (* Buffer too full -- send XOFF if we already haven't *)
  83.             IF ( NOT XOFF_Sent ) THEN
  84.                BEGIN
  85.                   Async_Send( CHR( XOFF ) );
  86.                   XOFF_Sent := TRUE;
  87.                   GoToXY( 1 , 4 );
  88.                   WRITE(' XOFF sent, percentage = ',Async_Percentage_Used:5:2 );
  89.                   ClrEol;
  90.                   N_Xoff := N_Xoff + 1;
  91.                END
  92.          END    (* Buffer too full *)
  93.       ELSE IF Async_Percentage_Used < 0.25 THEN
  94.          BEGIN  (* Buffer reasonably empty -- send XON if needed *)
  95.             IF XOFF_Sent THEN
  96.                BEGIN
  97.                   Async_Send( CHR( XON ) );
  98.                   XOFF_Sent := FALSE;
  99.                   GoToXY( 1 , 4 );
  100.                   WRITE(' XON  sent, percentage = ',Async_Percentage_Used:5:2 );
  101.                   ClrEol;
  102.                END;
  103.          END;
  104.                                    (* Check for Alt_R -- ends transfer *)
  105.       IF KeyPressed THEN
  106.          BEGIN
  107.             READ( Kbd , Ch );
  108.             IF ( Ch = CHR( ESC ) ) AND KeyPressed THEN
  109.                BEGIN
  110.                   READ( Kbd , Ch );
  111.                   IF ORD( Ch ) = Alt_R THEN
  112.                      Fin := TRUE;
  113.                END
  114.             ELSE
  115.                Async_Send( Ch );
  116.          END;
  117.  
  118.       IF Async_Receive( Ch ) THEN
  119.          BEGIN
  120.  
  121.             WRITE( AFile , Ch );
  122.  
  123.             Byte_Count := Byte_Count + 1;
  124.  
  125.             IF ( Ch = CHR( CR ) ) THEN
  126.                BEGIN
  127.                   Line_Count := Line_Count + 1;
  128.                   Update_Ascii_Receive_Display;
  129.                END;
  130.  
  131.          END;
  132.  
  133.       Fin := Fin OR Async_Carrier_Drop;
  134.  
  135.    UNTIL ( Fin );
  136.  
  137.    IF Async_Carrier_Drop THEN
  138.       BEGIN
  139.          GoToXY( 1 , 4 );
  140.          Writelne('Carrier dropped, transfer stopped.' , TRUE );
  141.       END
  142.    ELSE
  143.       BEGIN
  144.          GoToXY( 1 , 4 );
  145.          Writelne('Finished receiving ASCII file ' + FileName , TRUE );
  146.          GoToXY( 1 , 5 );
  147.          WRITELN('Number of XOFFs sent: ',N_Xoff);
  148.       END;
  149.  
  150.    DELAY( Two_Second_Delay );
  151.  
  152.    CLOSE( AFile );
  153.                                    (* Remove this window            *)
  154.    Restore_Screen( Saved_Screen );
  155.  
  156.    Reset_Global_Colors;
  157.  
  158. END   (* Receive_Ascii_File *);
  159. ə