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

  1.           nam       Kermit68K
  2.           ttl       Protocol automaton subroutines module
  3.  
  4. *         Kermit68K: source file K68PRO
  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     K68Protocol,0,0,Edition,0,0
  26.  
  27. ******************************** KPSwtch ******************************ok
  28. *                                                                     *
  29. *  Kermit protocol state table switcher. It loops until either it     *
  30. *  finishes, or an error is encountered. D7.W contains the present    *
  31. *  state of the automaton. The routines called by KPSwtch are         *
  32. *  responsible for changing the state.                                *
  33. *                                                                     *
  34. *         Entry conditions : D7.W initial state of the automaton      *
  35. *                                                                     *
  36. *         Exit  conditions : D0.B completion code                     *
  37. *                                                                     *
  38. ***********************************************************************
  39. KPSwtch:  TST.B     Local(A6)          Are we running in local mode ?
  40.           BEQ.S     KPSwtch1           No, no mind about speed
  41.           TST.L     Speed(A6)          Is line speed setted ?
  42.           BLT.S     KPSwtch3           No, give error and return
  43. KPSwtch1  MOVEQ     #RawMode,D0        Put line in raw mode
  44.           MOVEQ     #HostLine,D1
  45.           BSR       ChanCtrl
  46.           CMPI.B    #AllOk,D0          All ok ?
  47.           BEQ.S     KPSwtch5           Yes, enter the protocol switcher
  48. KPSwtch2  LEA       CCndLStr(PC),A1    No, point to the error message
  49.           BRA.S     KPSwtch4           Display this on the screen
  50. KPSwtch3  LEA       StSpeStr(PC),A1    Point to the 'set speed' error message
  51. KPSwtch4  MOVEQ     #ErrMessg,D0       Error message display request code
  52.           BSR       Screen             Display on the screen
  53.           RTS
  54.  
  55. KPSwtch5  PEA       KPSwtch5(PC)       Provide return address
  56.           MOVE.W    D7,D0              Load the present state of the automaton
  57.           ADD.W     D0,D0              Scale it
  58.           MOVE.W    KPSwtch6(PC,D0.W),D0 Load index
  59.           JMP       KPSwtch6(PC,D0.W)  Jump to the appropriate address
  60.  
  61. KPSwtch6  DC.W      SndInit-KPSwtch6   Send-Init
  62.           DC.W      OpnFile-KPSwtch6   Open-File
  63.           DC.W      SndFile-KPSwtch6   Send-File
  64.           DC.W      SndData-KPSwtch6   Send-Data
  65.           DC.W      SendEOF-KPSwtch6   Send-End-Of-File
  66.           DC.W      SendEOT-KPSwtch6   Send-Break
  67.           DC.W      RecInit-KPSwtch6   Receive-Init
  68.           DC.W      RecFile-KPSwtch6   Receive-File
  69.           DC.W      RecData-KPSwtch6   Receive-Data
  70.           DC.W      SndSrvI-KPSwtch6   Send-Server-Init
  71.           DC.W      SndGCmd-KPSwtch6   Send-Generic-Command
  72.           DC.W      Complete-KPSwtch6  Complete
  73.           DC.W      Abort-KPSwtch6     Abort
  74.  
  75. ******************************** SndSrvI ******************************ok
  76. *                                                                     *
  77. *  Send Server Init, send this host's parameters and get other side's *
  78. *  back, then enter Send Generic Command state.                       *
  79. *                                                                     *
  80. *         Entry conditions : none                                     *
  81. *                                                                     *
  82. *         Exit  conditions : D0.L destroyed                           *
  83. *                            D1.L destroyed                           *
  84. *                            D2.L destroyed                           *
  85. *                            D3.B destroyed                           *
  86. *                            D7.L next state of the automaton         *
  87. *                                                                     *
  88. ***********************************************************************
  89. SndSrvI   MOVEQ     #ClrInpBf,D0       Clear the input buffer
  90.           MOVEQ     #HostLine,D1       Host line channel, of course
  91.           BSR       ChanCtrl           Call the channel control routine
  92.           BSR       SndParm            Fill up the init info packet
  93.           MOVEQ     #'I',D1            Send an I packet
  94.           MOVEQ     #0,D2              Packet number (always 0)
  95.           MOVE.B    D0,D3              Packet length as returned by SndParm
  96.           BSR       SndPack            Ok, send now
  97.  
  98.           BSR       InpPack            What was the reply ?
  99.           CMPI.B    #'Y',D1            ACK ?
  100.           BEQ.S     SndSrvI4           Yes
  101.           CMPI.B    #'E',D1            Error packet ?
  102.           BNE       BadPack            No, bad packet
  103.           CLR.B     DataBuf(A6)        Yes, ignore it, clear data buffer
  104. *                                      Fall thru, use default parameters
  105. SndSrvI4  BSR       RdParam            Get other side's init info
  106.           MOVE.B    BlChkRq(A6),BlChkUs(A6) Setup block check type
  107.           MOVEQ     #SndGCmdS,D7       OK, switch state to Send-Generic-Command
  108.           RTS
  109.  
  110. ******************************** SndGCmd ******************************ok
  111. *                                                                     *
  112. *  Send Generic Command.                                              *
  113. *                                                                     *
  114. *         Entry conditions : none                                     *
  115. *                                                                     *
  116. *         Exit  conditions : D0.L destroyed                           *
  117. *                            D1.L destroyed                           *
  118. *                            D2.L destroyed                           *
  119. *                            D3.B destroyed                           *
  120. *                            D7.L next state of the automaton         *
  121. *                            A0.L destroyed                           *
  122. *                                                                     *
  123. ***********************************************************************
  124. SndGCmd   LEA       CmdBuf(A6),A0      Point to command buffer
  125.           BSR       EncStrng           Fill up the data buffer
  126.           MOVE.B    ServrCmd(A6),D1    Send a packet of the appropriate type
  127.           MOVEQ     #0,D2              Packet number (always 0)
  128.           MOVE.B    Size(A6),D3        Packet size
  129.           BSR       SndPack            Ok, send now
  130.           BSR       InpPack            What was the reply ?
  131.  
  132.           CMPI.B    #'Y',D1            ACK ?
  133.           BEQ.S     SndGCmd2           Yes
  134.           CMPI.B    #'S',D1            Send-Init packet ?
  135.           BEQ.S     SndGCmd3           Yes
  136.           CMPI.B    #'X',D1            X packet ?
  137.           BNE       BadPack            No, unknown packet type, abort
  138.           ST        TermOut(A6)        Yes, set the terminal output flag
  139.           BSR       SendACK            Acknowledge
  140.           MOVEQ     #RecDataS,D7       Enter Receive-Data state
  141.           RTS
  142.  
  143. SndGCmd2  LEA       ConOut(PC),A0      ACK received
  144.           BSR       Decode             Decode packet and output it
  145.           BSR       NewLine            Start a new line on the screen
  146.           MOVEQ     #CompletS,D7       Ok, enter complete state
  147.           RTS
  148.  
  149. SndGCmd3  BSR       RdParam            Get the other side's init data
  150.           BSR       SndParm            Fill up packet with my init info
  151.           MOVEQ     #'Y',D1            ACK my parameters
  152.           MOVEQ     #0,D2              Packet number (0)
  153.           MOVE.B    D0,D3              Packet length as returned by SndParm
  154.           BSR       SndPack            OK, send now
  155.           BSR       BumpPckN           Bump packet number, modulo 64
  156.           MOVE.B    BlChkRq(A6),BlChkUs(A6) Setup block check type
  157.           MOVEQ     #RecFileS,D7       Enter Receive-File state
  158.           RTS
  159.  
  160. ******************************** Complete *****************************ok
  161. *                                                                     *
  162. *  Successful end of transaction.                                     *
  163. *                                                                     *
  164. *         Entry conditions : none                                     *
  165. *                                                                     *
  166. *         Exit  conditions : D0.B positive completion code            *
  167. *                                                                     *
  168. ***********************************************************************
  169. Complete  ADDQ.L    #4,A7              Drop return address
  170.           MOVEQ     #TranCmpl,D0       Say transaction complete
  171.           BSR       Screen
  172.           ST        D0                 Return a positive completion code
  173.           RTS
  174.  
  175. ********************************* Abort *******************************ok
  176. *                                                                     *
  177. *  Unsuccessful end of transaction.                                   *
  178. *                                                                     *
  179. *         Entry conditions : none                                     *
  180. *                                                                     *
  181. *         Exit  conditions : D0.B negative completion code            *
  182. *                            D4.B destroyed                           *
  183. *                            A0.L destroyed                           *
  184. *                                                                     *
  185. ***********************************************************************
  186. Abort     ADDQ.L    #4,A7              Drop return address
  187.  
  188.           CMPI.B    #'E',D1            Error packet received ?
  189.           BNE.S     Abort1             No, too many tries or invalid type
  190.  
  191.           BSR       NewLine
  192.           LEA       ErFRHStr(PC),A0    Yes, point to error string
  193.           BSR       ConWrite           Write it to terminal
  194.           LEA       DataBuf(A6),A0     Point to error packet contents
  195.           BSR       ConWrite           Write it to terminal
  196.           MOVE.B    Quiet(A6),D4       Save the quiet flag
  197.           ST        Quiet(A6)          Set the quiet flag on
  198.           BSR       ClsInpF            Close the input file silently
  199.           ST        CtlZSeen(A6)       Force discarding of the ouput file
  200.           BSR       ClsOutF            Close the output file silently
  201.           MOVE.B    D4,Quiet(A6)       Restore the quiet flag
  202.           BRA.S     Abort7
  203.  
  204. Abort1    CMPI.B    #'N',D1            NAK packet ?
  205.           BEQ.S     Abort2             Yes
  206.           CMPI.B    #'T',D1            Timeout pseudo-packet ?
  207.           BEQ.S     Abort3             Yes
  208.           CMPI.B    #'Q',D1            Garbage pseudo-packet ?
  209.           BEQ.S     Abort4             Yes
  210.           CMP.B     PackNum(A6),D2     Packet out of sequence ?
  211.           BNE.S     Abort5             Yes
  212.           BSR       NewLine
  213.           LEA       UkUxPStr(PC),A0    No, unknown or unexpected packet type
  214.           BSR       ConWrite
  215.           BRA.S     Abort7
  216.  
  217. Abort2    PEA       NAKRcStr(PC)       NAK received string
  218.           BRA.S     Abort6
  219. Abort3    PEA       TimLEStr(PC)       Timeout limit expired string
  220.           BRA.S     Abort6
  221. Abort4    PEA       GbPRcStr(PC)       Garbage packet received string
  222.           BRA.S     Abort6
  223. Abort5    PEA       POuOSStr(PC)       Packet out of sequence string
  224. Abort6    BSR       NewLine
  225.           LEA       TooMTStr(PC),A0    Point to the abort string
  226.           BSR       ConWrite           Write it to the terminal line
  227.           MOVEA.L   (A7)+,A0           Now write the last error string
  228.           BSR       ConWrite
  229. Abort7    BSR       NewLine            Start a new line
  230.           SF        D0                 Return a negative completion code
  231.           RTS
  232.  
  233. BadPack   MOVEQ     #AbortS,D7         This is for code reduction
  234.           RTS
  235.  
  236. ********************************* SndInit *****************************ok
  237. *                                                                     *
  238. *  Send Initiate, send this host's parameters and get other side's    *
  239. *  back.                                                              *
  240. *                                                                     *
  241. *         Entry conditions : none                                     *
  242. *                                                                     *
  243. *         Exit  conditions : D0.L destroyed                           *
  244. *                            D1.L destroyed                           *
  245. *                            D2.L destroyed                           *
  246. *                            D3.B destroyed                           *
  247. *                            D7.L next state of the automaton         *
  248. *                            A0.L destroyed                           *
  249. *                            A1.L destroyed                           *
  250. *                                                                     *
  251. ***********************************************************************
  252. SndInit   LEA       Argumnt1(A6),A0    Pointer to file name
  253.           BSR       ExpandFN           Expand it into a file names list
  254.           TST.L     D0                 Check the returned number
  255.           BLT.S     SndInit4           Too many files match
  256.           BNE.S     SndInit1           Some files match, get the first one
  257.           BSR       CRemTLoc           No files match, convert name to local
  258.           BSR       ExpandFN           Try again the file name expansion
  259.           TST.L     D0                 Check the returned number
  260.           BLE.S     SndInit3           If no or too many files match, error
  261.  
  262. SndInit1  BSR       NextFil            Get the first file name into FilName
  263.           TST.B     D0                 Check completion code
  264.           BEQ.S     SndInit5           Failed, exit protocol (don't enter it)
  265.  
  266.           MOVEQ     #ClrInpBf,D0       Clear the input buffer
  267.           MOVEQ     #HostLine,D1
  268.           BSR       ChanCtrl           Call the channel control routine
  269.           TST.B     Local(A6)          Are we running in local mode ?
  270.           BNE.S     SndInit2           Yes, no need for delay
  271.           MOVE.B    Delay(A6),D0       Load initial delay before sending
  272.           BSR       Sleep              Sleep the requested amount of time
  273. SndInit2  BSR       SndParm            Fill up init info packet
  274.           MOVEQ     #'S',D1            Send an S packet
  275.           MOVEQ     #0,D2              Packet number (always 0)
  276.           MOVE.B    D0,D3              Packet length as returned by SndParm
  277.           BSR       SndPack            Ok, send now
  278.  
  279.           BSR       InpPack            What was the reply ?
  280.           CMPI.B    #'Y',D1            ACK ?
  281.           BNE       BadPack            No, bad packet
  282.           BSR       RdParam            Yes, get other side's init info
  283.           BSR       BumpPckN           Bump packet count
  284.           MOVE.B    BlChkRq(A6),BlChkUs(A6) Setup block check type
  285.           MOVE.B    RtryPack(A6),Retry(A6) Setup retry limit for normal packets
  286.           MOVEQ     #OpnFileS,D7       OK, switch state to Open-File
  287.           RTS
  288.  
  289. SndInit3  LEA       FNFStr(PC),A1      Point to file not found error message
  290.           BRA.S     SndInit6           Join common part
  291. SndInit4  LEA       TMFStr(PC),A1      Point to too many files error message
  292.           BRA.S     SndInit6           Join common part
  293. SndInit5  LEA       NRFStr(PC),A1      Point to no readable files error message
  294. SndInit6  MOVEQ     #ErrMessg,D0       Give bad news
  295.           BSR       Screen
  296.           MOVEQ     #CompletS,D7       Enter complete state
  297.           RTS
  298.  
  299. ********************************* OpnFile *****************************ok
  300. *                                                                     *
  301. *  Open File or set up text to send.                                  *
  302. *                                                                     *
  303. *         Entry conditions : none                                     *
  304. *                                                                     *
  305. *         Exit  conditions : D0.L destroyed                           *
  306. *                            D7.L next state of the automaton         *
  307. *                            A0.L destroyed                           *
  308. *                            A1.L destroyed                           *
  309. *                                                                     *
  310. ***********************************************************************
  311. OpnFile   LEA       FilName(A6),A0     Point to file name
  312.           BSR       OpnInpF            Try to open the file
  313.           TST.B     D0                 Success ?
  314.           BEQ.S     OpnFile1           No
  315.           MOVEQ     #SndFileS,D7       Yes switch state to Send-File
  316.           RTS
  317.  
  318. OpnFile1  LEA       FlOErStr(PC),A1    Point to open failed error message
  319.           MOVEQ     #ErrMessg,D0       Give bad news
  320.           BSR       Screen             Screen return the pointer unchanged
  321.           BSR       SndEPack           Send an Error packet
  322.           MOVEQ     #AbortS,D7         Abort
  323.           RTS
  324.  
  325. ******************************** SndFile ******************************ok
  326. *                                                                     *
  327. *  Send File Header.                                                  *
  328. *                                                                     *
  329. *         Entry conditions : none                                     *
  330. *                                                                     *
  331. *         Exit  conditions : D0.L destroyed                           *
  332. *                            D1.L destroyed                           *
  333. *                            D2.B destroyed                           *
  334. *                            D3.B destroyed                           *
  335. *                            D7.L next state of the automaton         *
  336. *                            A0.L destroyed                           *
  337. *                            A1.L destroyed                           *
  338. *                                                                     *
  339. ***********************************************************************
  340. SndFile   LEA       FilName(A6),A1     Point to the local file name
  341.           MOVEQ     #SFilName,D0       Display it on the screen
  342.           BSR       Screen
  343.           LEA       Argumnt2(A6),A0    Point to the file send-as name
  344.           TST.B     (A0)               Has it been specified ?
  345.           BNE.S     SndFile1           Yes, send it in the packet data field
  346.           LEA       FilName(A6),A1     No, same as local file name
  347.           MOVEQ     #CmdBufLn,D0       Copy it to Argumnt2
  348.           BSR       CopyStr
  349.           TST.B     FNameCnv(A6)       Are we converting file names ?
  350.           BEQ.S     SndFile1           No
  351.           BSR       CLocTRem           Yes, so convert file name in Argumnt2
  352.  
  353. SndFile1  MOVEA.L   A0,A1              Display the file send-as name
  354.           MOVEQ     #FlAsName,D0
  355.           BSR       Screen
  356.           BSR       EncStrng           Encode the file name into the data field
  357.           CLR.B     (A0)               Finally nullify Argumnt2
  358.  
  359.           MOVEQ     #'F',D1            Send a F packet
  360.           MOVE.B    PackNum(A6),D2     Packet number
  361.           MOVE.B    Size(A6),D3        Packet length
  362.           BSR       SndPack            Ok, send now
  363.  
  364.           BSR       InpPack            What was the reply ?
  365.           CMPI.B    #'Y',D1            ACK ?
  366.           BNE       BadPack            No, bad packet
  367.           BSR       BumpPckN           Bump packet counters
  368.           MOVE.B    #1,First(A6)       Init file character lookahead
  369.           BSR       GetPack            Get the first buffer of data
  370.           TST.B     D0                 Null file ?
  371.           BNE.S     SndFile4           No, enter Send-Data state
  372.           MOVEQ     #SendEOFS,D7       Enter Send-EOF state
  373.           RTS
  374. SndFile4  MOVEQ     #SndDataS,D7       Switch state to Send-Data
  375.           RTS
  376.  
  377. ******************************** SndData ******************************ok
  378. *                                                                     *
  379. *  Send File Data.                                                    *
  380. *                                                                     *
  381. *         Entry conditions : none                                     *
  382. *                                                                     *
  383. *         Exit  conditions : D0.B destroyed                           *
  384. *                            D1.L destroyed                           *
  385. *                            D2.B destroyed                           *
  386. *                            D3.B destroyed                           *
  387. *                            D7.L next state of the automaton         *
  388. *                                                                     *
  389. ***********************************************************************
  390. SndData   MOVE.B    CtlXSeen(A6),D0    Current file or file group cancelled ?
  391.           OR.B      CtlZSeen(A6),D0
  392.           BNE.S     SndData4           Yes
  393.           MOVEQ     #'D',D1            No, send a D packet
  394.           MOVE.B    PackNum(A6),D2     Packet number
  395.           MOVE.B    Size(A6),D3        Packet length
  396.           BSR       SndPack            Ok, send now
  397.           BSR       InpPack            What was the reply ?
  398.  
  399. SndData2  CMPI.B    #'Y',D1            ACK ?
  400.           BNE       BadPack            No, bad packet
  401.           BSR       BumpPckN           Bump packet count
  402.           TST.B     D3                 Empty ACK packet ?
  403.           BEQ.S     SndData5           Yes, get next data buffer
  404.           MOVE.B    DataBuf(A6),D0     No, get first character of data buffer
  405.           CMPI.B    #'X',D0            File interrupt directive ?
  406.           SEQ       CtlXSeen(A6)       Yes, set the appropriate flag
  407.           BEQ.S     SndData4           And enter, Send-EOF state
  408.           CMPI.B    #'Z',D0            File group interrupt directive ?
  409.           SEQ       CtlZSeen(A6)       Yes, set the appropriate flag
  410.           BNE.S     SndData5           No, ignore ACK contents
  411. SndData4  MOVEQ     #SendEOFS,D7       Enter Send-EOF state
  412.           RTS
  413. SndData5  BSR       GetPack            Get next data buffer
  414.           TST.B     D0                 EOF or end of memory string ?
  415.           BEQ.S     SndData4           Yes, switch state to Send-EOF
  416.           RTS                          No, remain in this state
  417.  
  418. ******************************** SendEOF ******************************ok
  419. *                                                                     *
  420. *  Send End-Of-File.                                                  *
  421. *                                                                     *
  422. *         Entry conditions : none                                     *
  423. *                                                                     *
  424. *         Exit  conditions : D0.B destroyed                           *
  425. *                            D1.L destroyed                           *
  426. *                            D2.B destroyed                           *
  427. *                            D3.L destroyed                           *
  428. *                            D7.L next state of the automaton         *
  429. *                                                                     *
  430. ***********************************************************************
  431. SendEOF   BSR       ClsInpF            Close the input file
  432.           MOVEQ     #'Z',D1            Send a Z packet
  433.           MOVE.B    PackNum(A6),D2     Packet number
  434.           MOVE.B    CtlXSeen(A6),D0    Current file or file group cancelled ?
  435.           OR.B      CtlZSeen(A6),D0
  436.           BEQ.S     SendEOF1           No
  437.           MOVE.B    #'D',DataBuf(A6)   Yes, put discard directive in data space
  438.           MOVEQ     #1,D3              Packet length (1, Z/D packet)
  439.           BRA.S     SendEOF2
  440. SendEOF1  MOVEQ     #0,D3              Packet length (0, empty Z packet)
  441. SendEOF2  BSR       SndPack            OK, send now
  442.  
  443.           BSR       InpPack            What was the reply ?
  444.           CMPI.B    #'Y',D1            ACK ?
  445.           BNE       BadPack            No, bad packet
  446.           BSR       BumpPckN           Bump packet counters
  447.  
  448.           BSR       NextFil            Look for another file
  449.           TST.B     D0                 Is there ?
  450.           BEQ.S     SendEOF3           No, end of transaction
  451.           MOVEQ     #OpnFileS,D7       Yes, send it
  452.           RTS
  453. SendEOF3  MOVEQ     #SendEOTS,D7       Enter Send-EOT state
  454.           RTS
  455.  
  456. ******************************** SendEOT ******************************ok
  457. *                                                                     *
  458. *  Send Break (EOT).                                                  *
  459. *                                                                     *
  460. *         Entry conditions : none                                     *
  461. *                                                                     *
  462. *         Exit  conditions : D1.L destroyed                           *
  463. *                            D2.B destroyed                           *
  464. *                            D3.L destroyed                           *
  465. *                            D7.L next state of the automaton         *
  466. *                                                                     *
  467. ***********************************************************************
  468. SendEOT   MOVEQ     #'B',D1            Send a B packet
  469.           MOVE.B    PackNum(A6),D2     Packet number
  470.           MOVEQ     #0,D3              Packet length
  471.           BSR       SndPack            Ok, send now
  472.           CLR.B     NextPckN(A6)       If the expected ACK lost, the next
  473. *                                      packet from the receiver will be NAK(0)
  474.           BSR       InpPack            What was the reply ?
  475.           CMPI.B    #'Y',D1            ACK ?
  476.           BNE       BadPack            No, bad packet
  477.           MOVEQ     #CompletS,D7       Yes, enter Complete state
  478.           RTS
  479.  
  480. ********************************* RecInit *****************************ok
  481. *                                                                     *
  482. *  Receive Initialization.                                            *
  483. *                                                                     *
  484. *         Entry conditions : none                                     *
  485. *                                                                     *
  486. *         Exit  conditions : D1.L destroyed                           *
  487. *                            D2.L destroyed                           *
  488. *                            D3.B destroyed                           *
  489. *                            D7.L next state of the automaton         *
  490. *                                                                     *
  491. ***********************************************************************
  492. RecInit   BSR       InpPack            Try to get a packet
  493.           CMPI.B    #'S',D1            Send-Init packet received ?
  494.           BNE       BadPack            No, bad packet
  495.           BSR       RdParam            Get the other side's init data
  496.           BSR       SndParm            Fill up packet with my init info
  497.           MOVEQ     #'Y',D1            ACK my parameters
  498.           MOVEQ     #0,D2              Packet number (0)
  499.           MOVE.B    D0,D3              Packet length as returned by SndParm
  500.           BSR       SndPack            OK, send now
  501.           BSR       BumpPckN           Bump packet number, modulo 64
  502.           MOVE.B    BlChkRq(A6),BlChkUs(A6) Setup block check type
  503.           MOVE.B    RtryPack(A6),Retry(A6) Setup retry limit for normal packets
  504.           MOVEQ     #RecFileS,D7       Enter Receive-File state
  505.           RTS
  506.  
  507. ********************************* RecFile *****************************ok
  508. *                                                                     *
  509. *  Receive File Header.                                               *
  510. *                                                                     *
  511. *         Entry conditions : none                                     *
  512. *                                                                     *
  513. *         Exit  conditions : D0.L destroyed                           *
  514. *                            D1.L destroyed                           *
  515. *                            D2.B destroyed                           *
  516. *                            D3.B destroyed                           *
  517. *                            D7.L next state of the automaton         *
  518. *                            A0.L destroyed                           *
  519. *                            A1.L destroyed                           *
  520. *                                                                     *
  521. ***********************************************************************
  522. RecFile   BSR       InpPack            Try to get a packet
  523.  
  524.           CMPI.B    #'X',D1            Send-File packet received ?
  525.           BEQ       RecFile4           Yes
  526.           CMPI.B    #'B',D1            Break packet received ?
  527.           BEQ       RecFile5           Yes
  528.           CMPI.B    #'F',D1            Send-File packet received ?
  529.           BNE       BadPack            No, abort
  530.  
  531.           CLR.B     CmdBfPnt(A6)       Yes, prepare CmdBuf to receive file name
  532.           LEA       CmdBfOut(PC),A0    File name decoded to CmdBuf
  533.           BSR       Decode
  534.  
  535.           LEA       CmdBuf(A6),A0      Pointer to the file name just decoded
  536.           TST.B     (A0)               The F packet was null ?
  537.           BNE.S     RecFile1           No
  538.           LEA       NoNamStr(PC),A1    Yes, provide a default name
  539.           MOVEQ     #CmdBufLn,D0       Copy it to CmdBuf
  540.           BSR       CopyStr
  541. RecFile1  MOVEA.L   A0,A1              Display the file name on the screen
  542.           MOVEQ     #RFilName,D0       Load the appropriate request code
  543.           BSR       Screen             Call the screen handler
  544.           LEA       Argumnt2(A6),A1    Check for alternate file name
  545.           TST.B     (A1)               Has been specified ?
  546.           BEQ.S     RecFile2           No
  547.           MOVEQ     #CmdBufLn,D0       Yes, copy it to CmdBuf
  548.           BSR       CopyStr
  549.           CLR.B     (A1)               Nullify Argumnt2
  550. RecFile2  LEA       FilName(A6),A1     Return here the actual name
  551.           BSR       OpnOutF            Try to open (create) the file
  552.           TST.B     D0                 Check the completion code
  553.           BEQ.S     RecFile3           Open fails
  554.           MOVEA.L   A1,A0              Open succeeds, here is the actual name
  555.           MOVEQ     #FlAsName,D0       Display it on the screen
  556.           BSR       Screen
  557.           BSR       EncStrng           Encode the file name into the data field
  558.           MOVEQ     #'Y',D1            Send an ACK packet
  559.           MOVE.B    PackNum(A6),D2     Packet number
  560.           MOVE.B    Size(A6),D3        Packet length
  561.           BSR       SndPack            Ok, send now
  562.           BSR       BumpPckN           Bump packet counters
  563.           MOVEQ     #RecDataS,D7       Enter Receive-Data state
  564.           RTS
  565.  
  566. RecFile3  LEA       FlCrEStr(PC),A1    Point to open failed error message
  567.           MOVEQ     #ErrMessg,D0       Give bad news
  568.           BSR       Screen             Screen return the pointer unchanged
  569.           BSR       SndEPack           Send an Error packet
  570.           MOVEQ     #AbortS,D7         Abort
  571.           RTS
  572.  
  573. RecFile4  ST        TermOut(A6)        Set the terminal output flag
  574.           BSR       SendACK            Acknowledge
  575.           MOVEQ     #RecDataS,D7       Enter Receive-Data state
  576.           RTS
  577.  
  578. RecFile5  BSR       SendACK            Acknowledge
  579.           MOVEQ     #CompletS,D7       Enter Complete state
  580.           RTS
  581.  
  582. ********************************* RecData *****************************ok
  583. *                                                                     *
  584. *  Receive File Data.                                                 *
  585. *                                                                     *
  586. *         Entry conditions : none                                     *
  587. *                                                                     *
  588. *         Exit  conditions : D1.L destroyed                           *
  589. *                            D2.B destroyed                           *
  590. *                            D3.L destroyed                           *
  591. *                            D7.L next state of the automaton         *
  592. *                            A0.L destroyed                           *
  593. *                                                                     *
  594. ***********************************************************************
  595. RecData   BSR       InpPack            Try to get a packet
  596.  
  597.           CMPI.B    #'Z',D1            EOF packet received ?
  598.           BEQ.S     RecData6           Yes
  599.           CMPI.B    #'D',D1            Send-Data packet received ?
  600.           BNE       BadPack            No, bad packet
  601.  
  602.           TST.B     TermOut(A6)        Output to the terminal channel wanted ?
  603.           BEQ.S     RecData1           No, file output
  604.           LEA       ConOut(PC),A0      Yes
  605.           BRA.S     RecData2
  606. RecData1  LEA       FileOut(PC),A0     Address of the file output function
  607. RecData2  BSR       Decode             Decode packet and output it
  608.           LEA       DataBuf(A6),A0     Pointer to data buffer
  609.           TST.B     CtlXSeen(A6)       File transfer interrupt request ?
  610.           BEQ.S     RecData3           No, look for group transfer interrupt
  611.           MOVE.B    #'X',(A0)+         Put "X" in the ACK packet data space
  612.           BRA.S     RecData4
  613. RecData3  TST.B     CtlZSeen(A6)       File group transfer interrupt request ?
  614.           BEQ.S     RecData5           No, send a normal (empty) ACK packet
  615.           MOVE.B    #'Z',(A0)+         Put "Z" in the ACK packet data space
  616. RecData4  CLR.B     (A0)+              Mark end of data
  617.           MOVEQ     #'Y',D1            ACK packet type
  618.           MOVE.B    PackNum(A6),D2     Packet number
  619.           MOVEQ     #1,D3              Packet length (1, "X" or "Z")
  620.           BSR       SndPack            OK, send now
  621.           BSR       BumpPckN           Bump packet number, modulo 64
  622.           RTS                          Return, state unchanged
  623.  
  624. RecData5  BSR       SendACK            Acknowledge
  625.           RTS                          Return, state unchanged
  626.  
  627. RecData6  TST.B     CtlXSeen(A6)       File transfer interrupted ?
  628.           BNE.S     RecData7           Yes, close file
  629.           TST.B     D3                 Empty Z packet ?
  630.           BEQ.S     RecData7           Yes, close file
  631.           CMPI.B    #'D',DataBuf(A6)   Discard directive ?
  632.           SEQ       CtlXSeen(A6)       Set flag for ClsOutF
  633. RecData7  BSR       ClsOutF            Close the output file
  634.           SF        CtlXSeen(A6)       Reset flag, necessary for next file
  635.           BSR       SendACK            Acknowledge
  636.           MOVEQ     #RecFileS,D7       Enter Receive-File state
  637.           RTS
  638.  
  639.           ends
  640.           END
  641.