home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / flex1 / flxpt5.txt < prev    next >
Text File  |  2020-01-01  |  20KB  |  411 lines

  1.  
  2.  STTL  Send routine
  3.  
  4. *
  5. *       This routine reads a file from disk and sends packets
  6. *       of data to the remote kermit
  7. *
  8. *               Input  Filename returned from Comnd routines
  9. *
  10. *               Output File is sent over port
  11. *
  12. *               Registers destroyed    A,X,Y
  13. *
  14.  
  15. send equ *
  16. *get file name
  17.  ldx #filena
  18.  jsr pstr
  19.  ldx #fcb1
  20.  jsr inline
  21.  ldx #filenr
  22.  jsr pstr
  23.  ldx #fcb2
  24.  jsr inline
  25.  jsr sswt
  26.         jmp     kermit          * Go back to main routine
  27.  
  28. sswt   lda     #'S             * Set up state variable as
  29.         sta     state           *       Send-init
  30.         lda     #$00            * Clear
  31.         sta     n               *       Packet number
  32.         sta     numtry          *       Number of tries
  33.         sta     oldtry          *       Old number of tries
  34.         sta     eofinp          *       End of input flag
  35.         sta     errcod          *       Error indicator
  36.         sta     rtot            *       Total received characters
  37.         sta     rtot+1          *               ...
  38.         sta     stot            *       Total Sent characters
  39.         sta     stot+1          *               ...
  40.         sta     rchr            *       Received characters, current file
  41.         sta     rchr+1          *               ...
  42.         sta     schr            *       and a Sent characters, current file
  43.         sta     schr+1          *               ...
  44.  sta filend reset file end flag
  45.         ldx     #pdbuf         * Set up the address of the packet buffer
  46.         stx     saddr           *       so that we can clear it out
  47.         lda     #$00            * Clear AC
  48.         ldb     #$00            * Clear Y
  49.  ldy saddr
  50. clpbuf sta     b,y       * Step through buffer, clearing it out
  51.         inc b                     * Up the index
  52.         cmpb     #mxpack       * Done?
  53.         bne     clpbuf          * No, continue
  54. sswt1  lda     state           * Fetch state of the system
  55.         cmp a     #'D             * Do Send-data?
  56.         bne     sswt2           * No, try next one
  57.         jsr     sdat            * Yes, send a data packet
  58.         jmp     sswt1           * Go to the top of the loop
  59. sswt2  cmp a     #'F             * Do we want to send-file-header?
  60.         bne     sswt3           * No, continue
  61.         jsr     sfil            * Yes, send a file header packet
  62.         jmp     sswt1           * Return to top of loop
  63. sswt3  cmp a     #'Z             * Are we due for an Eof packet?
  64.         bne     sswt4           * Nope, try next state
  65.         jsr     seof            * Yes, do it
  66.         jmp     sswt1           * Return to top of loop
  67. sswt4  cmp a     #'S             * Must we send an init packet
  68.         bne     sswt5           * No, continue
  69.         jsr     sini            * Yes, go do it
  70.         jmp     sswt1           * And continue
  71. sswt5  cmp a     #'B             * Time to break the connection?
  72.         bne     sswt6           * No, try next state
  73.         jsr     sbrk            * Yes, go send a break packet
  74.         jmp     sswt1           * Continue from top of loop
  75. sswt6  cmp a     #'C             * Is the entire transfer complete?
  76.         bne     sswt7           * No, something is wrong, go abort
  77.         lda     #true           * Return true
  78.         rts                     *               ...
  79. sswt7  lda     #false          * Return false
  80.         rts                     *               ...
  81.  
  82. sdat   lda     numtry          * Fetch the number for tries for current packet
  83.         inc     numtry          * Add one to it
  84.         cmp a     maxtry          * Is it more than the maximum allowed?
  85.         bne     sdat1           * No, not yet
  86.         bra     sdat1a          * If it is, go abort
  87. sdat1  jmp     sdat1b          * Continue
  88. sdat1a lda     #'A             * Load the 'abort' code
  89.         sta     state           * Stuff that in as current state
  90.  lda #errmrc
  91.  sta errcod
  92.         lda     #false          * Enter false return code
  93.         rts                     *       and a return
  94. sdat1b lda     #'D             * Packet type will be 'Send-data'
  95.         sta     ptype           *               ...
  96.         lda     n               * Get packet sequence number
  97.         sta     pnum            * Store that parameter to Spak
  98.         lda     size            * This is the size of the data in the packet
  99.         sta     pdlen           * Store that where it belongs
  100.         jsr     spak            * Go send the packet
  101. sdat2  jsr     rpak            * Try to get an ack
  102.         sta     rstat           * First, save the return status
  103.         lda     ptype           * Now get the packet type received
  104.         cmp a     #'N             * Was it a NAK?
  105.         bne     sdat2a          * No, try for an ACK
  106.         jmp     sdatcn          * Go handle the nak case
  107. sdat2a cmp a     #'Y             * Did we get an ACK?
  108.         bne     sdat2x          * No, try checking the return status
  109.         jmp     sdatca          * Yes, handle the ack
  110. sdat2x cmp a #'E
  111.  bne sdat2b
  112.  jsr pemsg
  113.  bra sdat1a
  114. sdat2b lda     rstat           * Fetch the return status
  115.         cmp a     #false          * Failure return?
  116.         beq     sdat2c          * Yes, just return with current state
  117.         lda     #'A             * Stuff the abort code
  118.         sta     state           *       as the current system state
  119.         lda     #false          * Load failure return code
  120. sdat2c rts                     * Go back
  121.  
  122. sdatcn dec  pnum            * Decrement the packet sequence number
  123.         lda     n               * Get the expected packet sequence number
  124.         cmp a     pnum            * If n=pnum-1 then this is like an ack
  125.         bne     sdatn1          * No, continue handling the nak
  126.         jmp     sdata2          * Jump to ack bypassing sequence check
  127. sdata1
  128. sdatn1 lda     #false          * Failure return
  129.         rts                     *               ...
  130. sdatca lda     n               * First check packet number
  131.         cmp a     pnum            * Did he ack the correct packet?
  132.         bne     sdata1          * No, go give failure return
  133. sdata2 lda     #$00            * Zero out number of tries for current packet
  134.         sta     numtry          *               ...
  135.         jsr     incn            * Increment the packet sequence number
  136.         jsr     bufill          * Go fill the packet buffer with data
  137.         sta     size            * Save the data size returned
  138.         lda     eofinp          * Load end-of-file indicator
  139.         cmp a     #true           * Was this set by Bufill?
  140.         beq     sdatrz          * If so, return state 'Z' ('Send-eof')
  141.         jmp     sdatrd          * Otherwise, return state 'D' ('Send-data')
  142. sdatrz lda     #'Z             * Load the Eof code
  143.         sta     state           *       and a make it the current system state
  144.         lda     #true           * We did succeed, so give a true return
  145.         rts                     * Go back
  146. sdatrd lda     #'D             * Load the Data code
  147.         sta     state           * Set current system state to that
  148.         lda     #true           * Set up successful return
  149.         rts                     *       and a go back
  150.  
  151. sfil   lda     numtry          * Fetch the current number of tries
  152.         inc     numtry          * Up it by one
  153.         cmp a     maxtry          * See if we went up to too many
  154.         bne     sfil1           * Not yet
  155.         bra     sfil1a          * Yes, go abort
  156. sfil1  jmp     sfil1b          * If we are still ok, take this jump
  157. sfil1a lda     #'A             * Load code for abort
  158.         sta     state           *       and a drop that in as the current state
  159.  lda #errmrc
  160.  sta errcod
  161.         lda     #false          * Load false for a return code
  162.         rts                     *       and a return
  163. sfil1b ldb     #$00            * Clear B
  164. sfil1c ldy #fcb2
  165.  lda     b,y          * Get a byte from the filename
  166.         cmp a     #$00            * Is it a null?
  167.         beq     sfil1d          * No, continue
  168.  ldy #pdbuf
  169.         sta     b,y         * Move the byte to this buffer
  170.         incb                     * Up the index once
  171.         jmp     sfil1c          * Loop and a do it again
  172. sfil1d        stb     pdlen           * This is the length of the filename
  173.         lda     #'F             * Load type ('Send-file')
  174.         sta     ptype           * Stuff that in as the packet type
  175.         lda     n               * Get packet number
  176.         sta     pnum            * Store that in its common area
  177.         jsr     spak            * Go send the packet
  178. sfil2  jsr     rpak            * Go try to receive an ack
  179.         sta     rstat           * Save the return status
  180.         lda     ptype           * Get the returned packet type
  181.         cmp a     #'N             * Is it a NAK?
  182.         bne     sfil2a          * No, try the next packet type
  183.         jmp     sfilcn          * Handle the case of a nak
  184. sfil2a cmp a     #'Y             * Is it, perhaps, an ACK?
  185.         bne     sfil2x          * If not, go to next test
  186.         jmp     sfilca          * Go and a handle the ack case
  187. sfil2x cmpa #'E
  188.  bne sfil2b
  189.  jsr pemsg
  190.  bra sfil1a abort
  191. sfil2b lda     rstat           * Get the return status
  192.         cmp a     #false          * Is it a failure return?
  193.         bne     sfil2c          * No, just go abort the send
  194.         rts                     * Return failure with current state
  195. sfil2c bra sfil1a
  196. sfilcn dec     pnum            * Decrement the receive packet number once
  197.         lda     pnum            * Load it into the AC
  198.         cmp a     n               * Compare that with what we are looking for
  199.         bne     sfiln1          * If n=pnum-1 then this is like an ack, do it
  200.         jmp     sfila2          * This is like an ack
  201. sfila1
  202. sfiln1 lda     #false          * Load failure return code
  203.         rts                     *       and a return
  204. sfilca lda     n               * Get the packet number
  205.         cmp a     pnum            * Is that the one that was acked?
  206.         bne     sfila1          * They are not equal
  207. sfila2 lda     #$00            * Clear AC
  208.         sta     numtry          * Zero the number of tries for current packet
  209.         jsr     incn            * Up the packet sequence number
  210.         ldx     #fcb1          * Load the fcb address into the pointer
  211. * open the file (harris)
  212.  ldx #fcb1
  213. sfcn lda 0,x+
  214.  cmpa #$00
  215.  bne sfcn
  216.  lda #$20
  217.  leax -1,x
  218.  sta 0,x
  219.  ldx #fcb1
  220.  stx $cc14
  221.  ldx #fcb
  222.  jsr getfil
  223.  bcs sfer1
  224.  lda #1
  225.  sta 0,x open for read
  226.  jsr setext
  227.  jsr fms open file
  228.  bne sfer1
  229.  
  230.  clr linlen
  231.  clr lfnext
  232.         jsr     bufill          * Go get characters from the file
  233.         sta     size            * Save the returned buffer size
  234.         lda     #'D             * Set state to 'Send-data'
  235.         sta     state           *               ...
  236.         lda     #true           * Set up true return code
  237.         rts                     *       and a return
  238.  
  239. sfer1 jsr rpterr tell user
  240.  jsr fmscls
  241.  jmp main
  242.  
  243. seof   lda     numtry          * Get the number of attempts for this packet
  244.         inc     numtry          * Now up it once for next time around
  245.         cmp a     maxtry          * Are we over the allowed max?
  246.         bne     seof1           * Not quite yet
  247.         bra     seof1a          * Yes, go abort
  248. seof1  jmp     seof1b          * Continue sending packet
  249. seof1a lda     #'A             * Load 'abort' code
  250.         sta     state           * Make that the state of the system
  251.         lda     #errmrc         * Fetch the error index
  252.         sta     errcod          *       and a store it as the error code
  253.         lda     #false          * Return false
  254.         rts                     *               ...
  255. seof1b lda     #'Z             * Load the packet type 'Z' ('Send-eof')
  256.         sta     ptype           * Save that as a parm to Spak
  257.         lda     n               * Get the packet sequence number
  258.         sta     pnum            * Copy in that parm
  259.         lda     #$00            * This is our packet data length (0 for EOF)
  260.         sta     pdlen           * Copy it
  261.         jsr     spak            * Go send out the Eof
  262. seof2  jsr     rpak            * Try to receive an ack for it
  263.         sta     rstat           * Save the return status
  264.         lda     ptype           * Get the received packet type
  265.         cmp a     #'N             * Was it a nak?
  266.         bne     seof2a          * If not, try the next packet type
  267.         jmp     seofcn          * Go take care of case nak
  268. seof2a cmp a     #'Y             * Was it an ack
  269.         bne     seof2x          * If it wasn't that, try return status
  270.         jmp     seofca          * Take care of the ack
  271. seof2x cmpa #'E
  272.  bne seof2b
  273.  jsr pemsg
  274.  bra seof1a
  275. seof2b lda     rstat           * Fetch the return status
  276.         cmp a     #false          * Was it a failure?
  277.         beq     seof2c          * Yes, just fail return with current state
  278.  bra seof1a
  279. seof2c rts                     * Return
  280. seofcn dec     pnum            * Decrement the received packet sequence number
  281.         lda     n               * Get the expected sequence number
  282.         cmp a     pnum            * If it's the same as pnum-1, it is like an ack
  283.         bne     seofn1          * It isn't, continue handling the nak
  284.         jmp     seofa2          * Switch to an ack but bypass sequence check
  285. seofa1
  286. seofn1 lda     #false          * Load failure return status
  287.         rts                     *       and a return
  288. seofca lda     n               * Check sequence number expected against
  289.         cmp a     pnum            *       the number we got.
  290.         bne     seofa1          * If not identical, fail and a return curr. state
  291. seofa2 lda     #$00            * Clear the number of tries for current packet
  292.         sta     numtry          *               ...
  293.         jsr     incn            * Up the packet sequence number
  294. seofrb lda     #'B             * Load Eot state code
  295.         sta     state           * Store that as the current state
  296.         lda     #true           * Give a success on the return
  297.         rts                     *               ...
  298.  
  299. sini   ldy     #pdbuf         * Load the pointer to the
  300.         sty     kerbf1          *       packet buffer into its
  301.         jsr     spar            * Go fill in the send init parms
  302.         lda     numtry          * If numtry > maxtry
  303.         cmp a     maxtry          *               ...
  304.         bne     sini1           *               ...
  305.         bra     sini1a          *       then we are in bad shape, go fail
  306. sini1  jmp     sini1b          * Otherwise, we just continue
  307. sini1a lda     #'A             * Set state to 'abort'
  308.         sta     state           *               ...
  309.         lda     #errmrc         * Fetch the error index
  310.         sta     errcod          *       and a store it as the error code
  311.         lda     #$00            * Set return status (AC) to fail
  312.         rts                     * Return
  313. sini1b inc     numtry          * Increment the number of tries for this packet
  314.         lda     #'S             * Packet type is 'Send-init'
  315.         sta     ptype           * Store that
  316.         lda     #$06            * Else it is 6
  317. sini1d sta     pdlen           * Store that parameter
  318.         lda     n               * Get the packet number
  319.         sta     pnum            * Store that in its common area
  320.         jsr     spak            * Call the routine to ship the packet out
  321.         jsr     rpak            * Now go try to receive a packet
  322.         sta     rstat           * Hold the return status from that last routine
  323. sinics lda     ptype           * Case statement, get the packet type
  324.         cmp a     #'Y             * Was it an ACK?
  325.         bne     sinic1          * If not, try next type
  326.         jmp     sinicy          * Go handle the ack
  327. sinic1 cmp a     #'N             * Was it a NAK?
  328.         bne     sinicx          * If not, try next condition
  329.         jmp     sinicn          * Handle a nak
  330. sinicx cmpa #'E
  331.  bne sinic2
  332.  jsr pemsg
  333.  bra sini1a
  334. sinic2 lda     rstat           * Fetch the return status
  335.         cmp a     #false          * Was this, perhaps false?
  336.         bne     sinic3          * Nope, do the 'otherwise' stuff
  337.         jmp     sinicf          * Just go and a return
  338. sinic3 bra sini1a
  339. sinicn
  340. sinicf rts                     * Return
  341.  
  342. sinicy ldb     #$00            * Clear B
  343.         lda     n               * Get packet number
  344.         cmp a     pnum            * Was the ack for that packet number?
  345.         beq     siniy1          * Yes, continue
  346.         lda     #false          * No, set false return status
  347.         rts                     *       and a go back
  348. siniy1 jsr     rpar            * Get parms from the ack packet
  349. siniy3 lda     #'F             * Load code for 'Send-file' into AC
  350.         sta     state           * Make that the new state
  351.         lda     #$00            * Clear AC
  352.         sta     numtry          * Reset numtry to 0 for next send
  353.         jsr     incn            * Up the packet sequence number
  354.         lda     #true           * Return true
  355.         rts
  356.  
  357. sbrk   lda     numtry          * Get the number of tries for this packet
  358.         inc     numtry          * Incrment it for next time
  359.         cmp a     maxtry          * Have we exceeded the maximum
  360.         bne     sbrk1           * Not yet
  361.         bra     sbrk1a          * Yes, go abort the whole thing
  362. sbrk1  jmp     sbrk1b          * Continue send
  363. sbrk1a lda     #'A             * Load 'abort' code
  364.         sta     state           * Make that the system state
  365.         lda     #errmrc         * Fetch the error index
  366.         sta     errcod          *       and a store it as the error code
  367.         lda     #false          * Load the failure return status
  368.         rts                     *       and a return
  369. sbrk1b lda     #'B             * We are sending an Eot packet
  370.         sta     ptype           * Store that as the packet type
  371.         lda     n               * Get the current sequence number
  372.         sta     pnum            * Copy in that parameter
  373.         lda     #$00            * The packet data length will be 0
  374.         sta     pdlen           * Copy that in
  375.         jsr     spak            * Go send the packet
  376. sbrk2  jsr     rpak            * Try to get an ack
  377.         sta     rstat           * First, save the return status
  378.         lda     ptype           * Get the packet type received
  379.         cmp a     #'N             * Was it a NAK?
  380.         bne     sbrk2a          * If not, try for the ack
  381.         jmp     sbrkcn          * Go handle the nak case
  382. sbrk2a cmp a     #'Y             * An ACK?
  383.         bne     sbrk2b          * If not, look at the return status
  384.         jmp     sbrkca          * Go handle the case of an ack
  385. sbrk2b lda     rstat           * Fetch the return status from Rpak
  386.         cmp a     #false          * Was it a failure?
  387.         beq     sbrk2c          * Yes, just return with current state
  388.  bra sbrk1a
  389. sbrk2c rts                     *       and a return
  390. sbrkcn dec     pnum            * Decrement the received packet number once
  391.         lda     n               * Get the expected sequence number
  392.         cmp a     pnum            * If =pnum-1 then this nak is like an ack
  393.         bne     sbrkn1          * No, this was no the case
  394.         jmp     sbrka2          * Yes! Go do the ack, but skip sequence check
  395. sbrka1
  396. sbrkn1 lda     #false          * Load failure return code
  397.         rts                     *       and a go back
  398. sbrkca lda     n               * Get the expected packet sequence number
  399.         cmp a     pnum            * Did we get what we expected?
  400.         bne     sbrka1          * No, return failure with current state
  401. sbrka2 lda     #$00            * Yes, clear number of tries for this packet
  402.         sta     numtry          *               ...
  403.         jsr     incn            * Up the packet sequence number
  404.         lda     #'C             * The transfer is now complete, reflect this
  405.         sta     state           *       in the system state
  406.         lda     #true           * Return success!
  407.         rts                     *               ...
  408.  
  409.  
  410.  
  411.