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

  1.  
  2.  STTL  Receve routine
  3.  
  4. *
  5. *       This routine receives a file from the remote kermit and
  6. *       writes it to a disk file
  7. *
  8. *               Input  Filename returned from comnd, if any
  9. *
  10. *               Output If file transfer is good, file is output to disk
  11. *
  12. *               Registers destroyed    A,X,Y
  13. *
  14.  
  15. receve equ *
  16. *get filename
  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     rswt            * Perform send-switch routine
  26.         jmp     kermit          * Go back to main routine
  27.  
  28. rswt   lda     #'R             * The state is receive-init
  29.         sta     state           * Set that up
  30.         lda     #$00            * Zero the packet sequence number
  31.         sta     n               *               ..
  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 Sent characters, current file
  43.         sta     schr+1          *               ..
  44.  jsr qures
  45. rswt1  lda     state           * Fetch the current system state
  46.         cmp a     #'D             * Are we trying to receive data?
  47.         bne     rswt2           * If not, try the next one
  48.         jsr     rdat            * Go try for the data packet
  49.         jmp     rswt1           * Go back to the top of the loop
  50. rswt2  cmp a     #'F             * Do we need a file header packet?
  51.         bne     rswt3           * If not, continue checking
  52.         jsr     rfil            * Go get the file-header
  53.         jmp     rswt1           * Return to top of loop
  54. rswt3  cmp a     #'R             * Do we need the init?
  55.         bne     rswt41           * No, try next state
  56.         jsr     rini            * Yes, go get it
  57.         jmp     rswt1           * Go back to top
  58. rswt41 cmpa #'B
  59.  bne rswt4
  60.  jsr rrbrk1
  61.  jmp rswt1
  62. rswt4  cmp a     #'C             * Have we completed the transfer?
  63.         bne     rswt5           * No, we are out of states, fail
  64.         lda     #true           * Load AC for true return
  65.         rts                     * Return
  66. rswt5  lda     #false          * Set up AC for false return
  67.         rts                     * Return
  68.  
  69. rini   ldx     #pdbuf         * Point kerbf1 at the packet data buffer
  70.         stx     kerbf1          *               ..
  71.         lda     numtry          * Get current number of tries
  72.         inc     numtry          * Increment it for next time
  73.         cmp a     maxtry          * Have we tried this one enought times
  74.         bne     rini1           * Not yet, go on
  75.         bra     rini1a          * Yup, go abort this transfer
  76. rini1  jmp     rini2           * Continue
  77. rini1a lda     #'A             * Change state to 'abort'
  78.         sta     state           *               ..
  79.         lda     #errcri         * Fetch the error index
  80.         sta     errcod          *       and store it as the error code
  81.         lda     #false          * Load AC with false status
  82.         rts                     *       and return
  83. rini2 equ *
  84. *send r packet to request file
  85.  clr b
  86. rinif2 ldy #fcb2
  87.  lda b,y
  88.  cmpa #$00 move file header to packet
  89.  beq rinif1 fini
  90.  ldy #pdbuf
  91.  sta b,y
  92.  inc b
  93.  bra rinif2
  94. rinif1 stb pdlen
  95.  lda #'R
  96.  sta ptype
  97.  lda n
  98.  sta pnum
  99.  jsr spak send it
  100.   jsr     rpak            * Go try to receive a packet
  101.         sta     rstat           * Store the return status for later
  102.         lda     ptype           * Fetch the packet type we got
  103.         cmp a     #'S             * Was it an 'Init'?
  104.         bne     rini2a          * No, check the return status
  105.         jmp     rinici          * Go handle the init case
  106. rini2a lda     rstat           * Fetch the saved return status
  107.         cmp a     #false          * Is it false?
  108.         beq     rini2b          * Yes, just return with same state
  109.         lda     #'A             * No, abort this transfer
  110.         sta     state           * State is now 'abort'
  111.         lda     #errcri         * Fetch the error index
  112.         sta     errcod          *       and store it as the error code
  113.         lda     #false          * Set return status to 'false'
  114.         rts                     * Return
  115. rini2b lda     n               * Get packet sequence number expected
  116.         sta     pnum            * Stuff that parameter at the Nakit routine
  117.         jsr     nakit           * Go send the Nak
  118.         lda     #false          * Set up failure return status
  119.         rts                     *       and go back
  120.  
  121. rinici lda     pnum            * Get the packet number we received
  122.         sta     n               * Synchronize our packet numbers with this
  123.         jsr     rpar            * Load in the init stuff from packet buffer
  124.         jsr     spar            * Stuff our init info into the packet buffer
  125.         lda     #'Y             * Store the 'Ack' code into the packet type
  126.         sta     ptype           *               ..
  127.         lda     n               * Get sequence number
  128.         sta     pnum            * Stuff that parameter
  129.         lda     #off            * No, punt 8-bit quoting
  130.         sta     ebqmod          *               ..
  131.         lda     #$06            * BTW, the data length is now only 6
  132. rinic1 sta     pdlen           * Store packet data length
  133.         jsr     spak            * Send that packet
  134.         lda     numtry          * Move the number of tries for this packet
  135.         sta     oldtry          *       to prev packet try count
  136.         lda     #$00            * Zero
  137.         sta     numtry          *       the number of tries for current packet
  138.         jsr     incn            * Increment the packet number once
  139.         lda     #'F             * Advance to 'File-header' state
  140.         sta     state           *               ..
  141.         lda     #true           * Set up return code
  142.         rts                     * Return
  143.  
  144. rfil   lda     numtry          * Get number of tries for this packet
  145.         inc     numtry          * Increment it for next time around
  146.         cmp a     maxtry          * Have we tried too many times?
  147.         bne     rfil1           * Not yet
  148.         bra     rfil1a          * Yes, go abort the transfer
  149. rfil1  jmp     rfil2           * Continue transfer
  150. rfil1a bra rfilla
  151. rfil2 jsr rpak *try to receive a packet
  152.         sta     rstat           * Save the return status
  153.         lda     ptype           * Get the packet type we found
  154.         cmp a     #'S             * Was it an 'init' packet?
  155.         bne     rfil2a          * Nope, try next one
  156.         jmp     rfilci          * Handle the init case
  157. rfil2a cmp a     #'Z             * Is it an 'eof' packet??
  158.         bne     rfil2b          * No, try again
  159.         jmp     rfilce          * Yes, handle that case
  160. rfil2b cmp a     #'F             * Is it a 'file-header' packet???
  161.         bne     rfil2c          * Nope
  162.         jmp     rfilcf          * Handle file-header case
  163. rfil2c cmp a     #'B             * Break packet????
  164.         bne     rfil2x          * Wrong, go get the return status
  165.         jmp     rfilcb          * Handle a break packet
  166. rfil2x cmpa #'E
  167.  bne rfil2d
  168.  jsr pemsg send error packet info to console
  169.  jmp rfilla and abort
  170. rfil2d lda     rstat           * Fetch the return status from Rpak
  171.         cmp a     #false          * Was it a false return?
  172.         beq     rfil2e          * Yes, Nak it and return
  173. rfilla        lda     #'A             * No, abort this transfer, we don't know what
  174.         sta     state           *       this is
  175.         lda     #errcrf         * Fetch the error index
  176.         sta     errcod          *       and store it as the error code
  177.         lda     #false          * Set up failure return code
  178.         rts                     *       and return
  179. rfil2e lda     n               * Move the expected packet number
  180.         sta     pnum            *       into the spot for the parameter
  181.         jsr     nakit           * Nak the packet
  182.         lda     #false          * Do a false return but don't change state
  183.         rts                     * Return
  184. rfilci lda     oldtry          * Get number of tries for prev packet
  185.         inc     oldtry          * Increment it
  186.         cmp a     maxtry          * Have we tried this one too much?
  187.         bne     rfili1          * Not quite yet
  188.         bra     rfili2          * Yes, go abort this transfer
  189. rfili1 jmp     rfili3          * Continue
  190. rfili2
  191. rfili5 lda     #'A             * Move abort code
  192.         sta     state           *       to system state
  193.         lda     #errcrf         * Fetch the error index
  194.         sta     errcod          *       and store it as the error code
  195.         lda     #false          * Prepare failure return
  196.         rts                     *       and go back
  197. rfili3 lda     pnum            * See if pnum=n-1
  198.         clc                     *               ..
  199.         add a     #$01            *               ..
  200.         cmp a     n               *               ..
  201.         beq     rfili4          * If it does, than we are ok
  202.         jmp     rfili5          * Otherwise, abort
  203. rfili4 jsr     spar            * Set up the init parms in the packet buffer
  204.         lda     #'Y             * Set up the code for Ack
  205.         sta     ptype           * Stuff that parm
  206.         lda     #$06            * Packet length for init
  207.         sta     pdlen           * Stuff that also
  208.         jsr     spak            * Send the ack
  209.         lda     #$00            * Clear out
  210.         sta     numtry          *       the number of tries for current packet
  211.         lda     #true           * This is ok, return true with current state
  212.         rts                     * Return
  213. rfilce lda     oldtry          * Get number of tries for previous packet
  214.         inc     oldtry          * Up it for next time we have to do this
  215.         cmp a     maxtry          * Too many times for this packet?
  216.         bne     rfile1          * Not yet, continue
  217.         bra     rfile2          * Yes, go abort it
  218. rfile1 jmp     rfile3          *               ..
  219. rfile2
  220. rfile5 lda     #'A             * Load abort code
  221.         sta     state           *       into current system state
  222.         lda     #errcrf         * Fetch the error index
  223.         sta     errcod          *       and store it as the error code
  224.         lda     #false          * Prepare failure return
  225.         rts                     *       and return
  226. rfile3 lda     pnum            * First, see if pnum=n-1
  227.         clc                     *               ..
  228.         add a     #$01            *               ..
  229.         cmp a     n               *               ..
  230.         beq     rfile4          * If so, continue
  231.         jmp     rfile5          * Else, abort it
  232. rfile4 lda     #'Y             * Load 'ack' code
  233.         sta     ptype           * Stuff that in the packet type
  234.         lda     #$00            * This packet will have a packet data length
  235.         sta     pdlen           *       of zero
  236.         jsr     spak            * Send the packet out
  237.         lda     #$00            * Zero number of tries for current packet
  238.         sta     numtry          *               ..
  239.         lda     #true           * Set up successful return code
  240.         rts                     *       and return
  241. rfilcf lda     pnum            * Does pnum=n?
  242.         cmp a     n               *               ..
  243.         bne     rfilf1          * If not, abort
  244.         jmp     rfilf2          * Else, we can continue
  245. rfilf1 lda     #'A             * Load the abort code
  246.         sta     state           *       and stuff it as current system state
  247.         lda     #errcrf         * Fetch the error index
  248.         sta     errcod          *       and store it as the error code
  249.         lda     #false          * Prepare failure return
  250.         rts                     *       and go back
  251. rfilf2 equ *
  252. * open file for write (harris)
  253.  ldx #fcb1
  254. rfnc lda 0,x+
  255.  cmpa #$00
  256.  bne rfnc
  257.  lda #$20 change terminator to space
  258.  leax -1,x
  259.  sta 0,x
  260.  ldx #fcb1 setup i/p point
  261.  stx $cc14 to line i/p buff
  262.  ldx #fcb
  263.  jsr getfil parse file spec
  264.  bcs fer1 error in file name
  265.  lda #2 open for write
  266.  sta 0,x set to txt
  267.  jsr setext set to text
  268.  jsr fms open file for write
  269.  bne fer1 file open error
  270.         lda     #'Y             * Stuff code for 'ack'
  271.         sta     ptype           * Into packet type parm
  272.         lda     #$00            * Stuff a zero in as the packet data length
  273.         sta     pdlen           *               ..
  274.         jsr     spak            * Ack the packet
  275.         lda     numtry          * Move current tries to previous tries
  276.         sta     oldtry          *               ..
  277.         lda     #$00            * Clear the
  278.         sta     numtry          * Number of tries for current packet
  279.         jsr     incn            * Increment the packet sequence number once
  280.         lda     #'D             * Advance the system state to 'receive-data'
  281.         sta     state           *               ..
  282.         lda     #true           * Set up success return
  283.         rts                     *       and go back
  284.  
  285. fer1 jsr rpterr tell userof error
  286.  jsr fmscls
  287.  jmp main
  288.  
  289. rfilcb lda     pnum            * Does pnum=n?
  290.         cmp a     n               *               ..
  291.         bne     rfilb1          * If not, abort the transfer process
  292.         jmp     rfilb2          * Otherwise, we can continue
  293. rfilb1 lda     #'A             * Code for abort
  294.         sta     state           * Stuff that into system state
  295.         lda     #errcrf         * Fetch the error index
  296.         sta     errcod          *       and store it as the error code
  297.         lda     #false          * Load failure return status
  298.         rts                     *       and return
  299. rfilb2 lda     #'Y             * Set up 'ack' packet type
  300.         sta     ptype           *               ..
  301.         lda     #$00            * Zero out
  302.         sta     pdlen           *       the packet data length
  303.         jsr     spak            * Send out this packet
  304.         lda     #'C             * Advance state to 'complete'
  305.         sta     state           *       since we are now done with the transfer
  306.         lda     #true           * Return a true
  307.         rts                     *               ..
  308.  
  309. rdat   lda     numtry          * Get number of tries for current packet
  310.         inc     numtry          * Increment it for next time around
  311.         cmp a     maxtry          * Have we gone beyond number of tries allowed?
  312.         bne     rdat1           * Not yet, so continue
  313.         bra     rdat1a          * Yes, we have, so abort
  314. rdat1  jmp     rdat2           *               ..
  315. rdat1a lda     #'A             * Code for 'abort' state
  316.         sta     state           * Stuff that in system state
  317.         lda     #errcrd         * Fetch the error index
  318.         sta     errcod          *       and store it as the error code
  319.  jsr closef
  320.         lda     #false          * Set up failure return code
  321.         rts                     *       and go back
  322. rdat2  jsr     rpak            * Go try to receive a packet
  323.         sta     rstat           * Save the return status for later
  324.         lda     ptype           * Get the type of packet we just picked up
  325.         cmp a     #'D             * Was it a data packet?
  326.         bne     rdat2a          * If not, try next type
  327.         jmp     rdatcd          * Handle a data packet
  328. rdat2a cmp a     #'F             * Is it a file-header packet?
  329.         bne     rdat2b          * Nope, try again
  330.         jmp     rdatcf          * Go handle a file-header packet
  331. rdat2b cmp a     #'Z             * Is it an eof packet???
  332.         bne     rdat2x          * If not, go check the return status from rpak
  333.         jmp     rdatce          * It is, go handle eof processing
  334. rdat2x cmpa #'E
  335.  bne rdat2c
  336.  jsr pemsg
  337.  bra rdater
  338. rdat2c lda     rstat           * Fetch the return status
  339.         cmp a     #false          * Was it a failure return?
  340.         beq     rdat2d          * If it was, Nak it
  341. rdater        lda     #'A             * Otherwise, we give up the whole transfer
  342.         sta     state           * Set system state to 'false'
  343.         lda     #errcrd         * Fetch the error index
  344.         sta     errcod          *       and store it as the error code
  345.  jsr closef
  346.         lda     #false          * Set up a failure return
  347.         rts                     *       and go back
  348. rdat2d lda     n               * Get the expected packet number
  349.         sta     pnum            * Stuff that parameter for Nak routine
  350.         jsr     nakit           * Send a Nak packet
  351.         lda     #false          * Give failure return
  352.         rts                     * Go back
  353.  
  354. rdatcd lda     pnum            * Is pnum the right sequence number?
  355.         cmp a     n               *               ..
  356.         bne     rdatd1          * If not, try another approach
  357.         jmp     rdatd7          * Otherwise, everything is fine
  358. rdatd1 lda     oldtry          * Get number of tries for previous packet
  359.         inc     oldtry          * Increment it for next time we need it
  360.         cmp a     maxtry          * Have we exceeded that limit?
  361.         bne     rdatd2          * Not just yet, continue
  362.         bra     rdatd3          * Yes, go abort the whole thing
  363. rdatd2 jmp     rdatd4          * Just continue working on the thing
  364. rdatd3
  365. rdatd6 lda     #'A             * Load 'abort' code into the
  366.         sta     state           *       current system state
  367.         lda     #errcrd         * Fetch the error index
  368.         sta     errcod          *       and store it as the error code
  369.  jsr closef
  370.         lda     #false          * Make this a failure return
  371.         rts                     * Return
  372. rdatd4 lda     pnum            * Is pnum=n-1.. Is the received packet
  373.         clc                     *       the one previous to the currently
  374.         add a     #$01            *       expected packet?
  375.         cmp a     n               *               ..
  376.         beq     rdatd5          * Yes, continue transfer
  377.         jmp     rdatd6          * Nope, abort the whole thing
  378. rdatd5 jsr     spar            * Go set up init data
  379.         lda     #'Y             * ***************** an ack to **********t
  380.         sta     ptype           *               ..
  381.         lda     #$00            *               ..
  382.         sta     pdlen           *               ..
  383.         jsr     spak            * Go send the ack
  384.         lda     #$00            * Clear the
  385.         sta     numtry          *       number of tries for current packet
  386.         lda     #true           *               ..
  387.         rts                     * Return (successful!)
  388. rdatd7 jsr     bufemp          * Go empty the packet buffer
  389.         lda     #'Y             * Set up an ack packet
  390.         sta     ptype           *               ..
  391.         lda     n               *               ..
  392.         sta     pnum            *               ..
  393.         lda     #$00            * Don't forget, there is no data
  394.         sta     pdlen           *               ..
  395.         jsr     spak            * Send it!
  396.         lda     numtry          * Move tries for current packet count to
  397.         sta     oldtry          *       tries for previous packet count
  398.         lda     #$00            * Zero the
  399.         sta     numtry          *       number of tries for current packet
  400.         jsr     incn            * Increment the packet sequence number once
  401.         lda     #'D             * Advance the system state to 'receive-data'
  402.         sta     state           *               ..
  403.         lda     #true           *               ..
  404.         rts                     * Return (successful)
  405.  
  406. rdatcf lda     oldtry          * Fetch number of tries for previous packet
  407.         inc     oldtry          * Increment it for when we need it again
  408.         cmp a     maxtry          * Have we exceeded maximum tries allowed?
  409.         bne     rdatf1          * Not yet, go on
  410.         bra     rdatf2          * Yup, we have to abort this thing
  411. rdatf1 jmp     rdatf3          * Just continue the transfer
  412. rdatf2
  413. rdatf5 lda     #'A             * Move 'abort' code to current system state
  414.         sta     state           *               ..
  415.         lda     #errcrd         * Fetch the error index
  416.         sta     errcod          *       and store it as the error code
  417.  jsr closef
  418.         lda     #false          *               ..
  419.         rts                     *       and return false
  420. rdatf3 lda     pnum            * Is this packet the one before the expected
  421.         clc                     *       one?
  422.         add a     #$01            *               ..
  423.         cmp a     n               *               ..
  424.         beq     rdatf4          * If so, we can still ack it
  425.         jmp     rdatf5          * Otherwise, we should abort the transfer
  426. rdatf4 lda     #'Y             * Load 'ack' code
  427.         sta     ptype           * Stuff that parameter
  428.         lda     #$00            * Use zero as the packet data length
  429.         sta     pdlen           *               ..
  430.         jsr     spak            * Send it!
  431.         lda     #$00            * Zero the number of tries for current packet
  432.         sta     numtry          *               ..
  433.         lda     #true           *               ..
  434.         rts                     * Return (successful)
  435.  
  436. rdatce lda     pnum            * Is this the packet we are expecting?
  437.         cmp a     n               *               ..
  438.         bne     rdatf5          * No, we should go abort
  439.         jmp     rdate2          * Yup, go handle it
  440. rdate1 lda     #'A             * Load 'abort' code into
  441.         sta     state           *       current system state
  442.         lda     #errcrd         * Fetch the error index
  443.         sta     errcod          *       and store it as the error code
  444.         lda     #false          *               ..
  445.         rts                     * Return (failure)
  446. rdate2 lda     #'Y             * Get set up for the ack
  447.         sta     ptype           * Stuff the packet type
  448.         lda     n               *       packet number
  449.         sta     pnum            *               ..
  450.         lda     #$00            *       and packet data length
  451.         sta     pdlen           *       parameters
  452.         jsr     spak            * Go send it!
  453.  
  454.  jsr closef
  455.  lda #'B
  456.  sta state complete
  457.  lda numtry
  458.  sta oldtry
  459.  lda #$00
  460.  sta numtry
  461.  jsr incn
  462.  lda #true
  463.  rts exit
  464.  
  465.  
  466. closef jmp fmscls
  467.  
  468. rrbrk1 lda numtry
  469.  inc numtry
  470.  cmpa maxtry
  471.  bne rrbrk2 not excceded try count
  472.  jmp rdate1 too many tries
  473. rrbrk2 jsr rpak
  474.  sta rstat
  475.  lda ptype
  476.  cmpa #'Z
  477.  bne rrbrk3
  478.  jmp rreof reack last
  479. rrbrk3 cmpa #'B
  480.  bne rrbrk4
  481.  jmp rrbp ack the break packet
  482. rrbrk4 lda rstat
  483.  cmp a #false
  484.  lbeq rdat2d nak it
  485.  bra rdate1 wrong type ..abort
  486.  
  487. rreof lda oldtry
  488.  inc oldtry
  489.  cmpa maxtry
  490.  lbeq rdate1 error in packet #
  491.  lda pnum
  492.  adda #$01 prev
  493.  cmpa n
  494.  beq rdate4 ack it
  495.  lbra rdate1 error in packet #
  496.  
  497. rrbp lda pnum
  498.  cmpa n
  499.  lbne rdate1 abort wrong packet #
  500.  lbsr rdate4 ack B.. packet.
  501.  bra rrds
  502.  
  503.  
  504. rdate4 lda #'Y
  505.  sta ptype
  506.  lda n
  507.  sta pnum
  508.  lda #$00
  509.  sta pdlen
  510.  jsr spak send ack
  511.  rts
  512.  
  513. rrds lda #'C
  514.  sta state
  515.  lda #true complete 
  516.  rts
  517.  
  518.