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

  1.  
  2.  
  3.  STTL  Packet routines - SPAK - send packet
  4.  
  5. *
  6. *       This routine forms and a sends out a complete packet in the
  7. *       following format
  8. *
  9. *       <SOH><char(pdlen)><char(pnum)><ptype><data><char(chksum)><eol>
  10. *
  11. *               Input  kerbf1- Pointer to packet buffer
  12. *                       pdlen-  Length of data
  13. *                       pnum-   Packet number
  14. *                       ptype-  Packet type
  15. *
  16. *               Output A-      True or False return code
  17. *
  18.  
  19. spak equ *
  20.  lda #'s
  21.  jsr couts tell console we are sending packet
  22.  jsr qures flush que
  23. * PRINT PACKET NUMBER TO CONSOLE
  24. spaknd lda     spadch          * Get the padding character
  25.         ldb     #$00            * Init counter
  26. spakpd cmpb     spad            * Are we done padding?
  27.         beq     spakst          * Yes, start sending packet
  28.         inc b                     * No, up the index and a count by one
  29.         jsr     telppc          * Output a padding character
  30.         jmp     spakpd          * Go around again
  31. spakst lda     #soh            * Get the start-of-header char into AC
  32.         jsr     telppc          * Send it
  33.         lda     pdlen           * Get the data length
  34.         add a     #$03            * Adjust it
  35.         pshs a                     * Save this to be added into stot
  36.         add a     #sp             * Make the thing a character
  37.         sta     chksum          * First item,  start off chksum with it
  38.         jsr     telppc          * Send the character
  39.         puls a                     * Fetch the pdlen and a add it into the
  40.         add a     stot            *               ...
  41.         sta     stot            *               ...
  42.         lda     stot+1          *               ...
  43.         add a     #$00            *               ...
  44.         sta     stot+1          *               ...
  45.         lda     pnum            * Get the packet number
  46.         clc                     *               ...
  47.         add a     #sp             * Char it
  48.         pshs a                     * Save it in this condition
  49.         add a     chksum          * Add this to the checksum
  50.         sta     chksum          *               ...
  51.         puls a                     * Restore character
  52.         jsr     telppc          * Send it
  53.         lda     ptype           * Fetch the packet type
  54.         and a     #$7f            * Make sure H.O. bit is off for chksum
  55.         pshs a                     * Save it on stack
  56.         add a     chksum          *               ...
  57.         sta     chksum          *               ...
  58.         puls a                     * Get the original character off stack
  59.         jsr     telppc          * Send packet type
  60.         ldb     #$00            * Initialize data count
  61.         stb     datind          * Hold it here
  62. spaklp ldb     datind          * Get the current index into the data
  63.         cmpb     pdlen           * Check against packet data length, done?
  64.         blo     spakdc          * Not yet, process another character
  65.         jmp     spakch          * Go do chksum calculations
  66. spakdc ldy kerbf1
  67.  lda b,y
  68.         add a     chksum          *               ...
  69.         sta     chksum          *               ...
  70.         lda     b,y      * Refetch data from packet buffer
  71.         jsr     telppc          * Send it
  72.         inc     datind          * Up the counter and a index
  73.         jmp     spaklp          * Loop to do next character
  74. spakch lda     chksum          * Now, adjust the chksum to fit in 6 bits
  75.         and a     #$c0            * First, take bits 6 and 7
  76.         lsr     a               *       and a shift them to the extreme right
  77.         lsr     a               *       side of the AC
  78.         lsr     a               *               ...
  79.         lsr     a               *               ...
  80.         lsr     a               *               ...
  81.         lsr     a               *               ...
  82.         add a     chksum          *               ...
  83.         and a     #$3f            * All this should be mod decimal 64
  84.         add a     #sp             * Put it in printable range
  85.         jsr     telppc          *       and a send it
  86.         lda     seol            * Fetch the eol character
  87.         jsr     telppc          * Send that as the last byte of the packet
  88. spakcr rts                     *       and a return
  89.  
  90.  
  91.  STTL  Packet routines - RPAK - receive a packet
  92.  
  93. *
  94. *       This routine receives a standard Kermit packet and a then breaks
  95. *       it apart returning the individuals components in their respective
  96. *       memory locations.
  97. *
  98. *               Input
  99. *
  100. *               Output kerbf1- Pointer to data from packet
  101. *                       pdlen-  Length of data
  102. *                       pnum-   Packet number
  103. *                       ptype-  Packet type
  104. *
  105.  
  106. rpak equ *
  107. * update user console with packet number
  108.  lda #'r
  109.  jsr couts tell console we are receiving packet
  110. rpaknd lda     #$00            * Clear the
  111.         sta     chksum          *       chksum
  112.         sta     datind          *       index into packet buffer
  113.         sta     kerchr          *       and the current character input
  114. rpakfs jsr     getplc          * Get a char, find SOH
  115.         sta     kerchr          * Save it
  116.         cmp a     #soh            * Is it an SOH character?
  117.         bne     rpakfs          * Nope, try again
  118.         lda     #$01            * Set up the switch for receive packet
  119.         sta     fld             *               ...
  120. rpklp1 lda     fld             * Get switch
  121.         cmp a     #$06            * Compare for <= 5
  122.         blo     rpklp2          * If it still is, continue
  123.         jmp     rpkchk          * Otherwise, do the chksum calcs
  124. rpklp2 cmp a     #$05            * Check fld
  125.         bne     rpkif1          * If it is not 5, go check for SOH
  126.         lda     datind          * Fetch the data index
  127.         cmp a     #$00            * If the data index is not null
  128.         bne     rpkif1          *       do the same thing
  129.         jmp     rpkif2          * Go process the character
  130. rpkif1 jsr     getplc          * Get a char, find SOH
  131.         sta     kerchr          * Save that here
  132.         cmp a     #soh            * Was it another SOH?
  133.         bne     rpkif2          * If not, we don't have to resynch
  134.         lda     #$00            * Yes, resynch
  135.         sta     fld             * Reset the switch
  136. rpkif2 lda     fld             * Get the field switch
  137.         cmp a     #$04            * Is it <= 3?
  138.         bhs     rpkswt          * No, go check the different cases now
  139.         lda     kerchr          * Yes, it was, get the character
  140.         add a     chksum          *               ...
  141.         sta     chksum          *               ...
  142. rpkswt lda     fld             * Now check the different cases of fld
  143.         cmp a     #$00            * Case 0?
  144.         bne     rpkc1           * Nope, try next one
  145.         lda     #$00            * Yes, zero the chksum
  146.         sta     chksum          *               ...
  147.         jmp     rpkef           *       and restart the loop
  148. rpkc1  cmp a     #$01            * Is it case 1?
  149.         bne     rpkc2           * No, continue checking
  150.         lda     kerchr          * Yes, get the length of packet
  151.         sec                     *               ...
  152.         sub a     #sp             * Unchar it
  153.         sec                     *               ...
  154.         sub a     #$03            * Adjust it down to data length
  155.         sta     pdlen           * That is the packet data length, put it there
  156.         jmp     rpkef           * Continue on to next item
  157. rpkc2  cmp a     #$02            * Case 2 (packet number)?
  158.         bne     rpkc3           * If not, try case 3
  159.         lda     kerchr          * Fetch the character
  160.         sec                     *               ...
  161.         sub a     #sp             * Take it down to what it really is
  162.         sta     pnum            * That is the packet number, save it
  163.         jmp     rpkef           * On to the next packet item
  164. rpkc3  cmp a     #$03            * Is it case 3 (packet type)?
  165.         bne     rpkc4           * If not, try next one
  166.         lda     kerchr          * Get the character and
  167.         sta     ptype           *       stuff it as is into the packet type
  168.         jmp     rpkef           * Go on to next item
  169. rpkc4  cmp a     #$04            * Is it case 4???
  170.         bne     rpkc5           * No, try last case
  171.         ldb     #$00            * Set up the data index
  172.         stb     datind          *               ...
  173. rpkchl ldb     datind          * Make sure datind is in Y
  174.         cmpb     pdlen           * Compare to the packet data length, done?
  175.         blo     rpkif3          * Not yet, process the character as data
  176.         jmp     rpkef           * Yes, go on to last field (chksum)
  177. rpkif3 cmpb     #$00            * Is this the first time through the data loop?
  178.         beq     rpkacc          * If so, SOH has been checked, skip it
  179.         jsr     getplc          * Get a char, find SOH
  180.         sta     kerchr          * Store it here
  181.         cmp a     #soh            * Is it an SOH again?
  182.         bne     rpkacc          * No, go accumulate chksum
  183.         lda     #$ff            * Yup, SOH, go resynch packet input once again
  184.         sta     fld             *               ...
  185.         jmp     rpkef           *               ...
  186. rpkacc lda     kerchr          * Get the character
  187.         clc                     *               ...
  188.         add a     chksum          * Add it to the chksum
  189.         sta     chksum          *       and save new chksum
  190.         lda     kerchr          * Get the character again
  191.  ldy kerbf1
  192.         ldb     datind          * Get our current data index
  193.         sta     b,y      * Stuff the current character into the buffer
  194.         inc     datind          * Up the index once
  195.         jmp     rpkchl          * Go back and check if we have to do this again
  196. rpkc5  cmp a     #$05            * Last chance, is it case 5?
  197.         beq     rpkc51          * Ok, continue
  198.         jmp     rpkpe           * Warn user about program error
  199. rpkc51 lda     chksum          * Do chksum calculations
  200.         and a     #$c0            * Grab bits 6 and 7
  201.         lsr     a               * Shift them to the right (6 times)
  202.         lsr     a               *               ...
  203.         lsr     a               *               ...
  204.         lsr     a               *               ...
  205.         lsr     a               *               ...
  206.         lsr     a               *               ...
  207.         clc                     * Clear carry for addition
  208.         add a     chksum          * Add this into original chksum
  209.         and a     #$3f            * Make all of this mod decimal 64
  210.         sta     chksum          *       and resave it
  211. rpkef  inc     fld             * Now increment the field switch
  212.         jmp     rpklp1          * And go check the next item
  213. rpkchk lda     kerchr          * Get chksum from packet
  214.         sub a     #sp             * Unchar it
  215.         cmp a     chksum          * Compare it to the one this Kermit generated
  216.         beq     rpkret          * We were successful, tell the caller that
  217.         lda     #$06            * Store the error code
  218.         sta     errcod          *               ...
  219. *print to console the
  220. * error message,packet checksum,expected checksum,crlf
  221.  
  222.  ldx #err6
  223.  jsr pstr
  224. rpkfls equ *
  225.         sta     rtot            *               ...
  226.         lda     rtot+1          *               ...
  227.         add a     #$00            *               ...
  228.         sta     rtot+1          *               ...
  229.  lda #'T
  230.  sta ptype error packet type
  231.         lda     #false          * Set up failure return
  232.         rts                     *       and go back
  233. rpkret equ *
  234. rpkrnd lda     pdlen           * Get the packet data length
  235.         add a     rtot            *       'total characters received' counter
  236.         sta     rtot            *               ...
  237.         lda     rtot+1          *               ...
  238.         add a     #$00            *               ...
  239.         sta     rtot+1          *               ...
  240.         lda     #true           * Show a successful return
  241.         rts                     *       and return
  242. rpkpe equ *
  243. * send error message to console
  244.         lda     #$07            * Load error code and store in errcod
  245.         sta     errcod          *               ...
  246.         jmp     rpkfls          * Go give a false return
  247.  
  248.  
  249.         
  250.  
  251. *
  252. *       Bufill - takes characters from the file, does any neccesary quoting,
  253. *       and then puts them in the packet data buffer. It returns the size
  254. *       of the data in the AC. If the size is zero and it hit end-of-file,
  255. *       it turns on eofinp.
  256. *
  257.  
  258. bufill lda     #$00            * Zero
  259.         sta     datind          *       the buffer index
  260.  tst filend
  261.  bne bendit
  262. bufil1 
  263.  tst lfnext
  264.  bne flfs
  265.  ldx #fcb
  266.  jsr fms read char from file
  267.  bne frder
  268. fcrchk cmpa #cr cr from file ?
  269.  bne nchck
  270.  clr linlen
  271.  sta lfnext
  272. nchck bra notend
  273. bendit jmp bffchk eof detect
  274.  
  275. crsubs
  276.  lda #cr
  277.  bra fcrchk
  278.  
  279. flfs clr lfnext
  280.  lda #lf
  281.  bra notend and send it
  282.  
  283. frder lda 1,x get error state
  284.  cmpa #8
  285.  bne frder1 error
  286.  bra bffchk eof
  287. frder1 jsr rpterr
  288.  jsr fmscls
  289.  jmp main
  290.  
  291. notend tst monito
  292.  beq notenm
  293.  jsr couts data to console
  294. notenm        sta     kerchr          * Got a character, save it
  295. bffqc0 cmp a     #sp             * Is the character less than a space?
  296.         bhs     bffqc1          * If not, try next possibility
  297.         jmp     bffctl          * This has to be controlified
  298. bffqc1 cmp a     #del            * Is the character a del?
  299.         bne     bffqc2          * If not, try something else
  300.         jmp     bffctl          * Controlify it
  301. bffqc2 cmp a     squote          * Is it the quote character?
  302.         bne     bffqc3          * If not, continue trying
  303.         jmp     bffstq          * It was, go stuff a quote in buffer
  304. bffqc3
  305.         bra     bffstf          * Nope, just stuff the character itself
  306. bffctl lda     kerchr          *[2] Get original character back
  307.         eor a     #$40            * Ctl(AC)
  308.         sta     kerchr          * Save the character again
  309. bffstq lda     squote          * Get the quote character
  310.  ldy kerbf1
  311.         ldb     datind          *       and the index into the buffer
  312.         sta     b,y      * Store it in the next location
  313.         inc b                     * Up the data index once
  314.         stb     datind          * Save the index again
  315. bffstf inc     schr            * Increment the data character count
  316.         bne     bffsdc          *               ...
  317.         inc     schr+1          *               ...
  318. bffsdc ldy     kerbf1          * Get the saved character
  319.  lda kerchr
  320.         ldb     datind          *       and the data index
  321.         sta    b,y     * This is the actual char we must store
  322.         incb                     * Increment the index
  323.         stb     datind          * And resave it
  324.         pshs b                  * Take this index, put it in AC
  325.         puls a
  326.         add a     #$06            * Adjust it so we can see if it
  327.         cmp a     spsiz           *       is >= spsiz-6
  328.         bhs     bffret          * If it is, go return
  329.         jmp     bufil1          * Otherwise, go get more characters
  330. bffret lda     datind          * Get the index, that will be the size
  331.         rts                     * Return with the buffer size in AC
  332. bffchk lda     datind          * Get the data index
  333.         cmp a     #$00            * Is it zero?
  334.         bne     bffnes          * Nope, just return
  335.         pshs a                  * Yes, this means the entire file has
  336.         lda     #true           *       been transmitted so turn on
  337.         sta     eofinp          *       the eofinp flag
  338.         puls a
  339. bffnes sta filend
  340. bffne  rts                     * Return
  341.  
  342. *
  343. *       Bufemp - takes a full data buffer, handles all quoting transforms
  344. *       and writes the reconstructed data out to the file using calls to
  345. *       FPUTC.
  346. *
  347.  
  348. bufemp lda     #$00            * Zero
  349.         sta     datind          *       the data index
  350. bfetol lda     datind          * Get the data index
  351.         cmp a     pdlen           * Is it >= the packet data length?
  352.         blo     bfemor          * No, there is more to come
  353.         rts                     * Yes, we emptied the buffer, return
  354. bfemor ldy kerbf1
  355.         ldb     datind          * Get the current buffer index
  356.         lda     b,y      * Fetch the character in that position
  357.         sta     kerchr          * Save it for the moment
  358. bfeqc  cmp a     rquote          * Is it the normal quote character
  359.         bne     bfeout          * No, pass this stuff up
  360.         inc     datind          * Increment the data index
  361.         ldb     datind          *       and fetch it in the Y-reg
  362.         lda     b,y      * Get the next character from buffer
  363.         sta     kerchr          * Save it
  364.         cmp a     rquote          * Were we quoting a quote?
  365.         beq     bfeout          * Yes, nothing has to be done
  366.         lda     kerchr          *[2] Fetch back the original character
  367.         eor a     #$40            * No, so controlify this again
  368.         sta     kerchr          * Resave it
  369. bfeout lda     kerchr          * Get the character
  370.  tst monito
  371.  beq bfeoum
  372.  jsr couts in monitor send to screen
  373. bfeoum
  374.  ldx #fcb
  375.  jsr fms write char
  376.  bne wder1
  377.         inc     rchr            * Increment the 'data characters receive' count
  378.         bne     bfeou1          *               ...
  379.         inc     rchr+1          *               ...
  380. bfeou1 inc     datind          * Up the buffer index once
  381.         jmp     bfetol          * Return to the top of the loop
  382.  
  383. wder1 jsr rpterr
  384.  jsr fmscls
  385.  jmp main
  386.  
  387.  
  388. pemsg equ * write packet contents to screen
  389.  ldx kerbf1
  390.  lda #eom
  391.  ldb pdlen
  392.  sta b,x set eof
  393.  jsr pstr string to console
  394.  rts
  395. *       Incn - increment the packet sequence number expected by this
  396. *       Kermit. Then take that number Mod $3f.
  397. *
  398.  
  399. incn   psh a                     * Save AC
  400.         lda     n               * Get the packet number
  401.         add a     #$01            * Up the number by one
  402.         and a     #$3f            * Do this Mod $3f!
  403.         sta     n               * Stuff the number where it belongs
  404.         puls a                     * Restore the AC
  405.         rts                     *       and return
  406.  
  407.  
  408. *
  409. *       Spar - This routine loads the data buffer with the init parameters
  410. *       requested for this Kermit.
  411. *
  412. *               Input  NONE
  413. *
  414. *               Output @Kerbf1 - Operational parameters
  415. *
  416. *               Registers destroyed    A,Y
  417. *
  418.  
  419. spar   clr b                 * Clear B
  420.  ldy kerbf1
  421.  stb datind *clear datind
  422.         lda     rpsiz           * Fetch receive packet size
  423.         add a     #$20            * Characterize it
  424.         sta     b,y      * Stuff it in the packet buffer
  425.         inc b                     * Increment the buffer index
  426.  lda rtime * get the timeout interval
  427.         add a     #$20            * Make that a printable character
  428.         sta     b,y      *       and stuff it in the buffer
  429.         inc b                    * Advance the index
  430.         lda     rpad            * Get the amount of padding required
  431.         add a     #$20            * Make that printable
  432.         sta     b,y      * Put it in the buffer
  433.         inc b                    * Advance index
  434.         lda     rpadch          * Get the padding character expected
  435.         eor  a     #$40            * Controlify it
  436.         sta     b,y      * And stuff it
  437.         inc b                    * Up the packet buffer index
  438.         lda     reol            * Get the end-of-line expected
  439.         add a     #$20            * Characterize it
  440.         sta     b,y      * Place that next in the buffer
  441.         inc b                    * Advance the index
  442.         lda     rquote          * Get the quote character expected
  443.         sta     b,y      * Store it as-is last in the buffer
  444.         inc b                    * Advance index
  445.         lda     rebq            * Get eight-bit-quote character
  446.         sta     b,y      * Stuff it into the data area
  447.         rts
  448.  
  449. *
  450. *       Rpar - This routine sets operational parameters for the other kermit
  451. *       from the init packet data buffer.
  452. *
  453. *               Input  @Kerbf1 - Operational parameters
  454. *
  455. *               Output Operational parameters set
  456. *
  457. *               Registers destroyed    A,Y
  458. *
  459.  
  460. rpar   ldy     kerbf1            * Start the data index at 0!
  461.  clr b
  462.         lda     b,y      * Start grabbing data from packet buffer
  463.         sub a     #$20            *               ...
  464.         sta     spsiz           * That must be the packet size of other Kermit
  465.         inc b                    * Increment the buffer index
  466.         lda     b,y      * Get the next item
  467.         sub a     #$20            * Uncharacterize that
  468.         sta     stime           * Other Kermit's timeout interval
  469.         inc b                    * Up the index once again
  470.         lda     b,y      * Get next char
  471.         sub a     #$20            * Restore to original value
  472.         sta     spad            * This is the amount of padding he wants
  473.         inc b                    * Advnace index
  474.         lda     b,y      * Next item
  475.         eor a     #$40            * Uncontrolify this one
  476.         sta     spadch          * That is padding character for other Kermit
  477.         inc b                    * Advance index
  478.         lda     b,y      * Get next item of data
  479.         cmp a     #$00            * If it is equal to zero
  480.         beq     rpar2           * Use <cr> as a default
  481.         jmp     rpar3           *               ...
  482. rpar2  lda     #cr             * Get value of <cr>
  483.         sta     seol            * That will be the eol character
  484.         jmp     rpar4           * Continue
  485. rpar3  sec                     *               ...
  486.         sub a     #$20            * unchar the character
  487.         sta     seol            * That is the eol character other Kermit wants
  488. rpar4  inc b                    * Advance the buffer index
  489.         lda     b,y      * Get quoting character
  490.         cmp a     #$00            * If that is zero
  491.         beq     rpar5           * Use # sign as the qoute character
  492.         jmp     rpar6           * Otherwise, give him what he wants
  493. rpar5  lda     #'#             * Load # sign
  494. rpar6  sta     squote          * Make that the other Kermit's quote character
  495.         inc b                    * Advance the index
  496.         lda     b,y      * Get 8-bit-quoting character
  497.         sta     sebq            * Store it - a higher level routine will work
  498. *       out how to use it
  499.         rts                     * Return
  500.  
  501. *
  502. *       Nakit - sends a standard NAK packet out to the other Kermit.
  503. *
  504. *               Input  NONE
  505. *
  506. *               Output NONE
  507. *
  508.  
  509. nakit  lda     #$00            * Zero the packet data length
  510.         sta     pdlen           *               ...
  511.         lda     #'N             * Set up a nak packet type
  512.         sta     ptype           *               ...
  513.         jsr     spak            * Now, send it
  514.         rts                     * Return
  515.  
  516.  
  517.  
  518.  STTL  End of Kermit-65 Source
  519.  
  520.         end  start
  521.