home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / os968ka / k6optf.asm < prev    next >
Assembly Source File  |  2020-01-01  |  32KB  |  564 lines

  1.           nam       Kermit68K
  2.           ttl       Protocol subroutines module
  3.  
  4. *         Kermit68K: source file K68PTF
  5. *
  6. * Author: Roberto Bagnara (Bagnara@Iboinfn.Bitnet),
  7. * Bologna University, Physics Department, July 1987.
  8. *
  9. * All rights reserved to Bologna University, Italy.
  10. *
  11. * Permission is granted to any individual or institution
  12. * to use, copy, or redistribute this software so long as
  13. * it  is not  sold for  profit, provided  this copyright
  14. * notice is retained.
  15. *
  16. * Modification History:
  17. *
  18. * Version  Date    Who              Comments
  19. *
  20. * 1.0.00   870701  Roberto Bagnara  First official release
  21.  
  22.           use       DefsFile
  23.  
  24. Edition   equ       0
  25.           psect     K68ProtoFuncs,0,0,Edition,0,0
  26.  
  27. ******************************** NextFil ******************************ok
  28. *                                                                     *
  29. *  Try to get the next file name copying it to FilName.               *
  30. *                                                                     *
  31. *         Entry conditions : none                                     *
  32. *                                                                     *
  33. *         Exit  conditions : D0.B completion code                     *
  34. *                            A0.L destroyed                           *
  35. *                                                                     *
  36. ***********************************************************************
  37. NextFil:  TST.B     CtlZSeen(A6)       Interrupt flag setted ?
  38.           BNE.S     NextFil2           Yes, return with bad completion code
  39. NextFil1  LEA       FilName(A6),A0     Points to file name target string
  40.           BSR       GetNxtF            Try to get the next file name
  41.           TST.B     D0                 Check the completion code
  42.           BEQ.S     NextFil2           No files, return with bad cc
  43.           BSR       ChkInpF            Check if file is readable
  44.           TST.B     D0                 Ok ?
  45.           BEQ.S     NextFil3           Yes, return this
  46.           MOVEQ     #FlSkippd,D0       No, notify that we are skipping it
  47.           BSR       Screen
  48.           BRA.S     NextFil1           Try another
  49. NextFil2  SF        D0                 Set a bad completion code
  50.           RTS
  51. NextFil3  ST        D0
  52.           RTS
  53.  
  54. ******************************** SndPack ******************************ok
  55. *                                                                     *
  56. *  Send a packet.                                                     *
  57. *                                                                     *
  58. *         Entry conditions : D1.B packet type                         *
  59. *                            D2.B packet number                       *
  60. *                            D3.B packet length                       *
  61. *                                                                     *
  62. *         Exit  conditions : D4.W destroyed                           *
  63. *                            D5.L destroyed                           *
  64. *                            A0.L destroyed                           *
  65. *                            A1.L destroyed                           *
  66. *                                                                     *
  67. ***********************************************************************
  68. SndPack:  LEA       SendBuf(A6),A1     Packet buffer start
  69.           MOVEQ     #32,D5             Load register for quick addition
  70.  
  71.           MOVE.B    OStPckCh(A6),(A1)+ Packet marker
  72.  
  73.           MOVE.B    D3,D0              Packet length
  74.           ADDQ.B    #2,D0              Add 2 + block_check_type to packet ...
  75.           ADD.B     BlChkUs(A6),D0     length to obtain the character count
  76.           ADD.B     D5,D0              and convert it into a printable character
  77.           MOVE.B    D0,(A1)+           Send the character count
  78.  
  79.           ADD.B     D5,D2              Make the packet number printable
  80.           MOVE.B    D2,(A1)+           Send the packet number
  81.  
  82.           MOVE.B    D1,(A1)+           Send the packet type
  83.           MOVE.B    D1,SendType(A6)    And save it for echos removal
  84.  
  85.           LEA       DataBuf(A6),A0     Pointer to data buffer
  86.           CLR.W     D0                 Clear the counter register
  87.           MOVE.B    D3,D0              Data length
  88.           BRA.S     SndPack2           Loop for all data characters
  89. SndPack1  MOVE.B    (A0)+,(A1)+        Get a character and put it in the packet
  90. SndPack2  DBF       D0,SndPack1        Repeat
  91.  
  92.           CLR.B     (A1)               Mark end for block check
  93.  
  94.           LEA       SendBuf+1(A6),A0   First char for checksum computation
  95.           MOVE.B    BlChkUs(A6),D0     Block check type in use
  96.           SUBQ.B    #1,D0              Type 1 block check ?
  97.           BNE.S     SndPack3           No, try another
  98.           BSR       Check1             Yes, compute it
  99.           ADD.B     D5,D0              Convert the checksum into printable
  100.           MOVE.B    D0,(A1)+           Send it
  101.           BRA.S     SndPack5           Join common part
  102.  
  103. SndPack3  SUBQ.B    #1,D0              Type 2 block check ?
  104.           BNE.S     SndPack4           No, type 3 block check
  105.           BSR       Check2             Yes, compute it
  106.           MOVE.B    D0,D4              Save the lower portion of the result
  107.           LSR.W     #6,D0              Process bits 6 --> 11, right adjusting
  108.           ANDI.B    #$3F,D0            Mask extra bits
  109.           ADD.B     D5,D0              Conversion into a printable character
  110.           MOVE.B    D0,(A1)+           Send the first character
  111.           MOVE.B    D4,D0              Reload the copy
  112.           ANDI.B    #$3F,D0            Now bits 0 --> 5
  113.           ADD.B     D5,D0              Conversion into a printable character
  114.           MOVE.B    D0,(A1)+           Send the second character
  115.           BRA.S     SndPack5           Join common part
  116.  
  117. SndPack4  BSR       Check3             Compute a type 3 block check
  118.           MOVE.W    D0,D4              Make a copy of the result
  119.           LSR.W     #8,D0              Process bits 12 --> 15, right adjusting
  120.           LSR.W     #4,D0              Right adjusting
  121.           ADD.B     D5,D0              Conversion into a printable character
  122.           MOVE.B    D0,(A1)+           Send the first character
  123.           MOVE.W    D4,D0              Reload the copy
  124.           LSR.W     #6,D0              Now process bits 6 --> 11, right adjust
  125.           ANDI.B    #$3F,D0            Mask extra bits
  126.           ADD.B     D5,D0              Conversion into a printable character
  127.           MOVE.B    D0,(A1)+           Send the second character
  128.           MOVE.B    D4,D0              Reload the lower portion of the result
  129.           ANDI.B    #$3F,D0            Now bits 0 --> 5
  130.           ADD.B     D5,D0              Conversion into a printable character
  131.           MOVE.B    D0,(A1)+           Send the third character
  132.  
  133. SndPack5  MOVE.B    OEOL(A6),(A1)+     Extra-packet line terminator
  134.           CLR.B     (A1)               End-Of-Buffer marker
  135.           BSR       TxPackt            Transmit the packet now prepared
  136.           MOVEQ     #PackType,D0       Display the packet type on the screen
  137.           BSR       Screen
  138.           RTS
  139.  
  140. ******************************** RdPack *******************************ok
  141. *                                                                     *
  142. *  Attempts to read a packet.                                         *
  143. *                                                                     *
  144. *         Entry conditions : none                                     *
  145. *                                                                     *
  146. *         Exit  conditions : D1.B packet type or pseudo-type          *
  147. *                            D2.B packet number                       *
  148. *                            D3.B packet length                       *
  149. *                            D5.L destroyed                           *
  150. *                            D6.L destroyed                           *
  151. *                            A0.L destroyed                           *
  152. *                            A1.L destroyed                           *
  153. *                            A2.L destroyed                           *
  154. *                                                                     *
  155. ***********************************************************************
  156. RdPack:   MOVE.L    D4,-(A7)           Save working register
  157.           SUBQ.L    #4,A7              Allocate some space on the stack
  158.           MOVEQ     #3-1,D6            Try 3 times to get a line that has
  159. RdPack1   BSR       InpLine            a start-of-packet char in it
  160.           TST.B     D1                 Check InpLine completion code
  161.           BEQ       RdPack16           Failed, return a timeout pseudo-packet
  162. *                                      Ok, search the start-of-packet char
  163. RdPack2   LEA       RecBuf(A6),A0      Pointer to receive buffer
  164.           CLR.W     D1                 Clear the character counter
  165. RdPack3   MOVE.B    (A0)+,D2           Get a character
  166.           CMP.B     IStPckCh(A6),D2    Start-of-packet char ?
  167.           BEQ.S     RdPack4            Yes, first goal satisfied !
  168.           ADDQ.W    #1,D1              Increment character counter
  169.           CMP.W     D0,D1              Last character ?
  170.           BNE.S     RdPack3            No, try the next
  171.           DBF       D6,RdPack1         Repeat max 3 times
  172.           MOVEQ     #'Q',D1            Failed, return a garbage pseudo-packet
  173.           BRA       RdPack19
  174.  
  175. RdPack4   MOVEQ     #32,D6             Load for quick addition/subtraction
  176. RdPack5   MOVEA.L   A0,A1              Remember where packet started
  177.  
  178.           MOVE.B    (A0)+,D0           Get character
  179.           BEQ       RdPack15           EOL, garbled packet
  180.           CMP.B     IStPckCh(A6),D0    Start-of-packet char ?
  181.           BEQ.S     RdPack5            Yes, resynchronize
  182.           MOVE.B    D0,D3              This is the packet length
  183.           SUB.B     D6,D3              Convert it to numeric
  184.  
  185.           MOVE.B    (A0)+,D0           Get character
  186.           BEQ       RdPack15           EOL, garbled packet
  187.           CMP.B     IStPckCh(A6),D0    Start-of-packet char ?
  188.           BEQ.S     RdPack5            Yes, resynchronize
  189.           MOVE.B    D0,D2              This is the packet number
  190.           SUB.B     D6,D2              Convert it to numeric
  191.  
  192.           MOVE.B    (A0)+,D0           Get character
  193.           BEQ       RdPack15           EOL, garbled packet
  194.           CMP.B     IStPckCh(A6),D0    Start-of-packet char ?
  195.           BEQ.S     RdPack5            Yes, resynchronize
  196.           MOVE.B    D0,D1              This is the packet type
  197.  
  198. *                                      Heuristics for syncing block check type
  199.  
  200.           MOVEQ     #1,D5              Type 1 block check by default
  201.           CMPI.B    #'S',D1            Send-Init packet ?
  202.           BEQ.S     RdPack7            Yes, type 1 block check
  203.           CMPI.B    #'I',D1            Initialize packet ?
  204.           BEQ.S     RdPack7            Yes, type 1 block check
  205.           CMPI.B    #'N',D1            NAK packet ?
  206.           BNE.S     RdPack6            No
  207.           MOVE.B    D3,D5              Yes, block check type is
  208.           SUBQ.B    #2,D5              bct = packet_length - 2
  209.           BRA.S     RdPack7
  210. RdPack6   MOVE.B    BlChkUs(A6),D5     Otherwise block check type in use
  211. RdPack7   SUB.B     D5,D3              Now compute data length by subtracting
  212.           SUBQ.B    #2,D3              (block_check_type + 2)
  213.  
  214.           LEA       DataBuf(A6),A2     Pointer to data buffer
  215.           CLR.W     D4                 Clear the counter register
  216.           MOVE.B    D3,D4              Data length
  217.           BRA.S     RdPack9            Read data, if any
  218. RdPack8   MOVE.B    (A0)+,D0           Get character
  219.           BEQ       RdPack15           EOL, garbled packet
  220.           CMP.B     IStPckCh(A6),D0    Start-of-packet char ?
  221.           BEQ.S     RdPack5            Yes, resynchronize
  222.           MOVE.B    D0,(A2)+           Write character to data buffer
  223. RdPack9   DBF       D4,RdPack8
  224.           CLR.B     (A2)+              Mark the end of buffer
  225.  
  226.           MOVEA.L   A7,A2              Point to temporary storage space
  227.           CLR.W     D4                 Clear the counter register
  228.           MOVE.B    D5,D4              Block check type
  229.           BRA.S     RdPack11           Get the block check
  230. RdPack10  MOVE.B    (A0),D0            Get character
  231.           BEQ       RdPack15           EOL, garbled packet
  232.           CMP.B     IStPckCh(A6),D0    Start-of-packet char ?
  233.           BEQ       RdPack5            Yes, resynchronize
  234.           MOVE.B    D0,(A2)+           Store the block check character
  235.           CLR.B     (A0)+              Nullify checksum characters in RecBuf
  236. RdPack11  DBF       D4,RdPack10        Repeat
  237.  
  238. *                                      Got packet, now check the block check
  239.  
  240.           MOVEA.L   A1,A0              Pointer to packet start
  241.           MOVEA.L   A7,A1              Point to received block check characters
  242.  
  243.           SUBQ.B    #1,D5              Type 1 block check ?
  244.           BEQ.S     RdPack13           Yes, compute it
  245.           SUBQ.B    #1,D5              Type 2 block check ?
  246.           BEQ.S     RdPack12           Yes, compute it
  247.           SUBQ.B    #1,D5              Type 3 block check ?
  248.           BNE.S     RdPack15           No, return garbage pseudo-packet
  249. *                                      Yes, compute it, (fall thru)
  250.  
  251.           BSR       Check3             Compute
  252.           MOVEQ     #$3F,D4            Process bits 0 --> 5
  253.           AND.B     D0,D4              Move and mask extra bits
  254.           ADD.B     D6,D4              Conversion into a printable character
  255.           CMP.B     2(A1),D4           Ok, now compare, third byte
  256.           BNE       RdPack15           Compare fails, garbled packet
  257.           LSR.W     #6,D0              Now process bits 6 --> 11, right adjust
  258.           MOVEQ     #$3F,D4            To mask extra bits
  259.           AND.B     D0,D4              Move and mask extra bits
  260.           ADD.B     D6,D4              Conversion into a printable character
  261.           CMP.B     1(A1),D4           Compare the second byte
  262.           BNE       RdPack15           Compare fails, garbled packet
  263.           LSR.W     #6,D0              Process bits 12 --> 15, right adjusting
  264.           ADD.B     D6,D0              Conversion into a printable character
  265.           CMP.B     (A1),D0            Compare the first byte
  266.           BRA.S     RdPack14           Join common part
  267.  
  268. RdPack12  BSR       Check2             Compute
  269.           MOVEQ     #$3F,D4            Process bits 0 --> 5
  270.           AND.B     D0,D4              Move and mask extra bits
  271.           ADD.B     D6,D4              Conversion into a printable character
  272.           CMP.B     1(A1),D4           Ok, now compare, second byte
  273.           BNE       RdPack15           Compare fails, garbled packet
  274.           LSR.W     #6,D0              Process bits 6 --> 11, right adjusting
  275.           ANDI.B    #$3F,D0            Mask extra bits
  276.           ADD.B     D6,D0              Conversion into a printable character
  277.           CMP.B     (A1),D0            Compare the first byte
  278.           BRA.S     RdPack14           Join common part
  279.  
  280. RdPack13  BSR       Check1             Compute
  281.           ADD.B     D6,D0              Convert it to a printable character
  282.           CMP.B     (A1),D0            Compare it with the received block check
  283. *                                      Join common part, (fall thru)
  284.  
  285. RdPack14  BEQ.S     RdPack17           If compare succeeds return packet type
  286. RdPack15  MOVEQ     #'Q',D1            Return a garbage pseudo-packet
  287.           BRA.S     RdPack18
  288. RdPack16  MOVEQ     #'T',D1            Return a timeout pseudo-packet
  289.           BRA.S     RdPack18
  290. RdPack17  ADDQ.L    #1,PcksRecd(A6)    Increment packets received this trans
  291.           ADDQ.L    #1,TPckRecd(A6)    Increment total packets received
  292. RdPack18  MOVEQ     #PackType,D0       We want display the packet type
  293.           BSR       Screen             Update the screen, if necessary
  294. RdPack19  ADDQ.L    #4,A7              Deallocate space on the stack
  295.           MOVE.L    (A7)+,D4           Restore working register
  296.           RTS
  297.  
  298. ******************************** InpPack ******************************ok
  299. *                                                                     *
  300. *  Loop until the expected packet arrives or the maximum tries number *
  301. *  exceeded. If a packet arrives with the same type of the last       *
  302. *  packet sent, it's treated as an echo and another one is expected.  *
  303. *  If the previous packet arrives again, the last packet is resent    *
  304. *  and a new one is expected to come in.                              *
  305. *                                                                     *
  306. *         Entry conditions : none                                     *
  307. *                                                                     *
  308. *         Exit  conditions : D1.B packet type or pseudo-type          *
  309. *                            D2.B packet number                       *
  310. *                            D3.B packet length                       *
  311. *                            D4.B destroyed                           *
  312. *                                                                     *
  313. ***********************************************************************
  314. InpPack:  CLR.B     D4                 Clear the retry counter
  315. InpPack1  BSR       ChekInt            Check for console interrupts
  316.           BSR       RdPack             Try to read a packet
  317.           CMP.B     SendType(A6),D1    It's the same just sent ?
  318.           BNE.S     InpPack2           No
  319.           BSR       RdPack             Yes, it's an echo, read another
  320.  
  321. InpPack2  CMP.B     PrevPckN(A6),D2    Previous packet ?
  322.           BEQ.S     InpPack4           Yes, keep trying
  323.           CMPI.B    #'T',D1            Timeout pseudo-packet ?
  324.           BEQ.S     InpPack4           Yes, keep trying
  325.           CMPI.B    #'Q',D1            Garbage pseudo-packet ?
  326.           BEQ.S     InpPack4           Yes, keep trying
  327.           CMPI.B    #'N',D1            NAK packet ?
  328.           BNE.S     InpPack3           No, return the received packet
  329.           ADDQ.L    #1,NAKsRecd(A6)    Yes, increment NAKs received counter
  330.           ADDQ.L    #1,TNAKRecd(A6)    Increment total NAKs received counter
  331.           CMP.B     NextPckN(A6),D2    It's a NAK for the next packet ?
  332.           BNE.S     InpPack4           No
  333.           MOVEQ     #'Y',D1            Yes, it's like an ACK ...
  334.           MOVE.B    PackNum(A6),D2     ... for current packet
  335. InpPack3  MOVE.B    D1,D4              Save this for parameter passing
  336.           MOVEQ     #ClrInpBf,D0       Clear the input buffer ...
  337.           MOVEQ     #HostLine,D1       ... of the host line
  338.           BSR       ChanCtrl           Call the channel control routine
  339.           MOVE.B    D4,D1              Restore the packet (pseudo) type
  340.           RTS
  341.  
  342. InpPack4  CMP.B     Retry(A6),D4       Too many tries ?
  343.           BCC.S     InpPack3           Yes, return
  344.           BSR       Resend             No, send last packet again
  345.           ADDQ.B    #1,D4              Increment the retry counter
  346.           BRA.S     InpPack1           Stay in loop
  347.  
  348. ********************************* GetPack *****************************ok
  349. *                                                                     *
  350. *  Gets characters from the current source, file or memory string.    *
  351. *  Encodes the data into the packet, filling the packet optimally.    *
  352. *  Returns TRUE on success with Size containing the number of         *
  353. *  characters in DataBuf, or FALSE if DataBuf is empty (Size = 0,     *
  354. *  EOF for file, end of string for memory string).                    *
  355. *                                                                     *
  356. *         Entry conditions : none                                     *
  357. *                                                                     *
  358. *         Exit  conditions : D0.B completion code                     *
  359. *                                                                     *
  360. ***********************************************************************
  361. GetPack:  MOVEM.L   A0/D1-D2,-(A7)     Save working registers
  362.           LEA       DataBuf(A6),A0     Pointer to data buffer
  363.           MOVEQ     #0,D2              Clear index register
  364.           TST.B     First(A6)          First time ?
  365.           BLT.S     GetPack1           No, EOF from last time
  366.           BEQ.S     GetPack2           No, input in progress
  367.           CLR.B     First(A6)          Yes, remember
  368.           BSR       GetChx             Get first character of file
  369.           MOVE.B    D0,Current(A6)     Save current character
  370.           TST.B     D1                 Null file ?
  371.           BNE.S     GetPack3           No
  372. GetPack1  MOVE.B    #1,First(A6)       Yes, setup for next time
  373.           SF        D0                 Return negative completion code
  374.           BRA.S     GetPack9
  375.  
  376. GetPack2  MOVE.B    LeftOver(A6,D2.W),(A0,D2.W) Do any left-overs
  377.           BEQ.S     GetPack3           Exit if null
  378.           ADDQ.W    #1,D2              Increment index
  379.           BRA.S     GetPack2           Repeat
  380.  
  381. GetPack3  CLR.B     LeftOver(A6)       Nullify the left-overs buffer
  382.           CLR.B     ReptCnt(A6)        Clear out any old repeat count
  383. GetPack4  TST.B     First(A6)          EOF reached ?
  384.           BLT.S     GetPack8           Yes, return partially (?) filled packet
  385.           BSR       GetChx             Get a character from file or memory
  386.           MOVE.B    D0,Next(A6)        Save next character for lookahead
  387.           TST.B     D1                 EOF ?
  388.           BNE.S     GetPack5           No
  389.           MOVE.B    #-1,First(A6)      Yes, flag it for next time
  390. GetPack5  MOVE.B    D2,OldSize(A6)     Remember current position
  391.           MOVE.B    Current(A6),D0     Get the current character
  392.           BSR       Encode             Encode the current character
  393.           MOVE.B    Next(A6),Current(A6) Next is now current
  394.           CMP.B     OMPckSiz(A6),D2    Check packet size
  395.           BLT.S     GetPack4           Keep filling
  396.           BEQ.S     GetPack8           Return exactly full packet
  397.           MOVEQ     #0,D0              Clear for indexing the left-overs buffer
  398.           MOVEQ     #0,D1              Clear for indexing the data buffer
  399.           MOVE.B    OldSize(A6),D1     Set up the data buffer index
  400. GetPack6  MOVE.B    (A0,D1.W),LeftOver(A6,D0.W) Save some for next time
  401.           BEQ.S     GetPack7           Exit if null
  402.           ADDQ.W    #1,D0              Increment the first index
  403.           ADDQ.W    #1,D1              Increment the second index
  404.           BRA.S     GetPack6           Repeat
  405. GetPack7  MOVE.B    OldSize(A6),D2     Size of the truncated packet
  406. GetPack8  ST        D0                 Provide positive completion code
  407. GetPack9  MOVE.B    D2,Size(A6)
  408.           CLR.B     (A0,D2.W)          Write buffer terminator
  409.           MOVEM.L   (A7)+,A0/D1-D2     Restore working registers
  410.           RTS
  411.  
  412. ********************************* EncStrng ****************************ok
  413. *                                                                     *
  414. *  Encode a string from memory.                                       *
  415. *                                                                     *
  416. *         Entry conditions : A0.L memory string start address         *
  417. *                                                                     *
  418. *         Exit  conditions : A0.L memory string start address         *
  419. *                                                                     *
  420. ***********************************************************************
  421. EncStrng: MOVE.B    MStrFlag(A6),-(A7) Save the old flag
  422.           MOVE.L    MStrgPnt(A6),-(A7) Save the old pointer
  423.           ST        MStrFlag(A6)       Say input from memory string
  424.           MOVE.L    A0,MStrgPnt(A6)    Point to the memory string
  425.           MOVE.B    #1,First(A6)       Initialize character lookahead
  426.           BSR       GetPack            Get a packet from the string
  427.           MOVE.L    (A7)+,MStrgPnt(A6) Restore the old pointer
  428.           MOVE.B    (A7)+,MStrFlag(A6) Restore the old flag
  429.           MOVE.B    #1,First(A6)       Re-initialize character lookahead
  430.           RTS
  431.  
  432. ********************************* GetChx ******************************ok
  433. *                                                                     *
  434. *  Try to get the next character from file or memory string.          *
  435. *  Returns TRUE on success with D0.B set to the character, or FALSE   *
  436. *  on failure (EOF for file, enf of string for memory string).        *
  437. *                                                                     *
  438. *         Entry conditions : none                                     *
  439. *                                                                     *
  440. *         Exit  conditions : D0.B character (if any)                  *
  441. *                            D1.B completion code                     *
  442. *                                                                     *
  443. ***********************************************************************
  444. GetChx    MOVE.L    A0,-(A7)           Save working register
  445.           TST.B     LFSave(A6)         Do we have a linefeed saved ?
  446.           BEQ.S     GetChx1            No
  447.           SF        LFSave(A6)         Yes, nullify the flag
  448.           MOVEQ     #Asc_LF,D0         Return the saved LF
  449.           ST        D1                 Also return a positive cc
  450.           BRA.S     GetChx4
  451. GetChx1   TST.B     MStrFlag(A6)       Try to get the next character, memory ?
  452.           BEQ.S     GetChx2            No, get it from current file
  453.           MOVEA.L   MStrgPnt(A6),A0    Load pointer to the memory string
  454.           MOVE.B    (A0)+,D0           Get a character
  455.           SNE       D1                 Set cc to false if end of string reached
  456.           MOVE.L    A0,MStrgPnt(A6)    Save pointer for next time
  457.           BRA.S     GetChx3            Join the common part
  458. GetChx2   MOVEQ     #IOFile,D1         Get a char from the the current file
  459.           BSR       InpChar
  460.           TST.B     D1                 Check the returned completion code
  461.           SEQ       D1                 Set completion code accordingly
  462. GetChx3   TST.B     D1                 Have we got a character ?
  463.           BEQ.S     GetChx4            No, return
  464.           ADDQ.L    #1,DChsSent(A6)    Yes, count it
  465.           ADDQ.L    #1,TDChSent(A6)
  466.           TST.B     Binary(A6)         Are we in binary mode ?
  467.           BNE.S     GetChx4            Yes, nl-CRLF mapping not needed
  468.           CMPI.B    #NewLinCh,D0       No, newline character ?
  469.           BNE.S     GetChx4            No
  470.           ST        LFSave(A6)         Yes, remember a linefeed
  471.           MOVEQ     #Asc_CR,D0         Return a carriage return
  472. GetChx4   MOVE.L    (A7)+,A0           Restore working register
  473.           RTS
  474.  
  475. ********************************* Resend ******************************ok
  476. *                                                                     *
  477. *  Resend the last packet sent (the one in SendBuf), if any, send     *
  478. *  a NAK otherwise.                                                   *
  479. *                                                                     *
  480. *         Entry conditions : none                                     *
  481. *                                                                     *
  482. *         Exit  conditions : D0.L destroyed                           *
  483. *                            D1.L destroyed                           *
  484. *                                                                     *
  485. ***********************************************************************
  486. Resend:   MOVEQ     #ClrInpBf,D0       Clear the input buffer
  487.           MOVEQ     #HostLine,D1       Host line channel
  488.           BSR       ChanCtrl           Call the channel control routine
  489.           TST.B     SendBuf(A6)        Send buffer empty ?
  490.           BNE.S     Resend1            No, send last packet again
  491.           BSR       SendNAK            Yes, send a NAK packet
  492.           RTS
  493. Resend1   BSR       TxPackt            Send the previous packet again
  494.           MOVEQ     #PackType,D0       Update the screen
  495.           MOVEQ     #'%',D1            This is the symbol for a resent packet
  496.           BSR       Screen
  497.           RTS
  498.  
  499. ******************************** SndEPack *****************************ok
  500. *                                                                     *
  501. *  Send an Error packet.                                              *
  502. *                                                                     *
  503. *         Entry conditions : A1.L point to the reason string          *
  504. *                                                                     *
  505. *         Exit  conditions : D0.L destroyed                           *
  506. *                            D1.L destroyed                           *
  507. *                            D2.B destroyed                           *
  508. *                            D3.B destroyed                           *
  509. *                            A0.L destroyed                           *
  510. *                                                                     *
  511. ***********************************************************************
  512. SndEPack: MOVEA.L   A1,A0              Point to the reason string
  513.           BSR       EncStrng           Encode it
  514.           MOVEQ     #'E',D1            Error packet
  515.           MOVE.B    PackNum(A6),D2     Packet number
  516.           MOVE.B    Size(A6),D3        Packet length
  517.           BSR       SndPack            OK, send now
  518.           BSR       ClsInpF            Close the input file, if open
  519.           ST        CtlZSeen(A6)       This is an interrupted file transfer
  520.           BSR       ClsOutF            Close (and maybe delete) the output file
  521.           MOVEQ     #TranCmpl,D0       Give transaction complete message
  522.           BSR       Screen
  523.           RTS
  524.  
  525. ********************************* SendACK *****************************ok
  526. *                                                                     *
  527. *  Send an empty ACK packet.                                          *
  528. *                                                                     *
  529. *         Entry conditions : none                                     *
  530. *                                                                     *
  531. *         Exit  conditions : D1.L destroyed                           *
  532. *                            D2.B destroyed                           *
  533. *                            D3.L destroyed                           *
  534. *                                                                     *
  535. ***********************************************************************
  536. SendACK:  MOVEQ     #'Y',D1            ACK
  537.           MOVE.B    PackNum(A6),D2     Packet number
  538.           MOVEQ     #0,D3              Packet length (0, empty packet)
  539.           BSR       SndPack            OK, send now
  540.           BSR       BumpPckN           Bump packet number, modulo 64
  541.           RTS
  542.  
  543. ********************************* SendNAK *****************************ok
  544. *                                                                     *
  545. *  Send a NAK packet (always empty).                                  *
  546. *                                                                     *
  547. *         Entry conditions : none                                     *
  548. *                                                                     *
  549. *         Exit  conditions : D1.L destroyed                           *
  550. *                            D2.B destroyed                           *
  551. *                            D3.L destroyed                           *
  552. *                                                                     *
  553. ***********************************************************************
  554. SendNAK   MOVEQ     #'N',D1            NAK
  555.           MOVE.B    PackNum(A6),D2     Packet number
  556.           MOVEQ     #0,D3              Packet length (0, empty packet)
  557.           BSR       SndPack            OK, send now
  558.           ADDQ.L    #1,NAKsSent(A6)    Increment NAKs sent this transaction
  559.           ADDQ.L    #1,TNAKSent(A6)    Increment total NAKs sent
  560.           RTS
  561.  
  562.           ends
  563.           END
  564.