home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / test / pdp11 / krtsen.mac < prev    next >
Text File  |  1996-10-17  |  27KB  |  837 lines

  1.     .title    KRTSEN    Send file processing
  2.     .ident    "V04.64"
  3.  
  4. ; /E64/    28-Apr-96  John Santos
  5. ;
  6. ;    Conditionalize for RSTS/E
  7. ;    Note: doesn't handle large files!!
  8. ;    If we resize the buffer and re-open the input file in sdat$$, close
  9. ;    it first.  Check for errors and abort if re-open fails.
  10.  
  11. ; /63/     8-Feb-96  Billy Youdelman
  12. ;
  13. ;    display file size and type in "sending file" messages
  14. ;    display contents of SEND FILE ACK packet, if any..
  15. ;    redo data packet at sdat$$ when resizing due to first one failing
  16. ;    so the next retry is actually done with the smaller sized packet
  17.  
  18. ; /62/    27-Jul-93  Billy Youdelman  V03.62
  19. ;
  20. ;    dump FILLOG, as PRINTM now does this
  21. ;    use log$packets for state logging
  22. ;    provide for logfile errors
  23. ;    add time to SEN.SW state logging
  24. ;    modified to wait thru bad ack packets, noise, etc..
  25. ;    recpkt buffer back to normal size, now passes same to rpack
  26.  
  27. ; /BBS/     1-Dec-91  Billy Youdelman  V03.61
  28. ;
  29. ;    increased size of recpkt buffer to $allsiz to avoid writing past
  30. ;    eob (causing trap to 4 in rpack$ which crashes the program) when
  31. ;    packets are out of sync and a long packet arrives where an ack
  32. ;    is expected, or line noise "extends" otherwise ok data..
  33. ;
  34. ;    kill debug to TT if not running as a local Kermit
  35. ;    modified to (w/KRTATR) send all attributes in a single packet
  36. ;    ensure directory search channel is closed on errors/aborts
  37. ;
  38. ;    display abort message when file skipped due to SET FILE PROTECT
  39. ;    (by an "X" or "Z" in the ACK packet) on the other Kermit
  40.  
  41. ;    13-Oct-84  14:04:37  Brian Nelson
  42. ;
  43. ;    Copyright 1983,1984 Change Software, Inc.
  44. ;
  45. ;    This software is furnished under a license and may
  46. ;    be  used  and  copied  only in accordance with the
  47. ;    terms of such license and with  the  inclusion  of
  48. ;    the  above copyright notice.  This software or any
  49. ;    other copies thereof may not be provided or other-
  50. ;    wise made available to any other person.  No title
  51. ;    to and ownership of the software is hereby  trans-
  52. ;    ferred.
  53. ;
  54. ;    The information in this  software  is  subject  to
  55. ;    change  without notice and should not be construed
  56. ;    as a commitment by the author.
  57.  
  58.  
  59.     .include "IN:KRTMAC.MAC"
  60.     .iif ndf  KRTINC  .error    <; .include for IN:KRTMAC.MAC failed>
  61.     .include "IN:KRTDEF.MAC"
  62.     .iif ndf  MSG$DA  .error    <; .include for IN:KRTDEF.MAC failed>
  63.  
  64. .if df    RT11                ; /E64/
  65.     .mcall    .PURGE            ; /62/ to hose dir search ch on err
  66. .endc    ;RT11                ; /E64/
  67.  
  68.  
  69.     .sbttl    Local data
  70.  
  71.     .psect    $pdata            ; /62/ consolidated this stuff here..
  72. fillst:    .word    10$    ,20$    ,30$    ; /63/
  73.  10$:    .asciz    "ASCII (7-bit)"        ; /63/
  74.  20$:    .asciz    "BINARY (8-bit)"    ; /63/
  75.  30$:    .asciz    "DEC-Multinational"    ; /63/
  76. adpmsg:    .asciz    "First data packet failed, PACKET-LENGTH reduced to "
  77. adptag:    .asciz    ". bytes"
  78. badpre:    .asciz    "Ignoring invalid "
  79. badack:    .asciz    "ACK/NAK serial number"
  80. badpak:    .asciz    "response"        ; /63/
  81. badtag:    .asciz    ", paknum: "
  82. sen.01:    .asciz    "SEN.SW"
  83. sen.02:    .asciz    "Warning: Parity found in SOH byte"
  84. sen.03:    .asciz    "Remote ACK: "        ; /63/
  85. sen.04:    .asciz    "ABORT$CURRENT-FILE"
  86. sen.05:    .asciz    "ABORT$ALL-FILES"
  87. sen.06:    .byte    eof$dis    ,0
  88. sen.07:    .asciz    "Sending file "
  89. sen.08:    .asciz    " as "            ; /63/
  90. sen.09:    .asciz    " file "
  91.     .even
  92.  
  93.     .psect    recpkt    ,rw,d,lcl,rel,con
  94. recpkt:    .blkb    maxpak+2        ; /62/ added passed length to rpack
  95.  
  96.  
  97.     .psect    $code
  98.     .sbttl    State controller for send file processing
  99.     .enabl    lsb
  100.  
  101. sensw::    movb    @r5    ,state        ; state at which caller wants to begin
  102.     clr    cccnt            ; /62/ no ^Cs typed yet
  103.     movb    #defchk    ,chktyp        ; setup the default checksum type
  104.     mov    #1    ,chksiz        ; size of default checksum
  105.     mov    $image    ,image        ; ensure correct default for mode
  106.     clr    paknum            ; packet_number := 0
  107.     clr    numtry            ; retry_count := 0
  108.     cmpb    conpar+p.chkt,#'1    ; did other system want CRC checks?
  109.     bne    10$            ; yep
  110.     cmpb    senpar+p.chkt,#'1    ; simple block checks today?
  111.     beq    20$            ; yes, assume caller's state is ok
  112. 10$:    movb    #sta.sin,state        ; no, must force a sinit exchange
  113. 20$:    clr    logini            ; /62/ force display stats header
  114.     call    inista            ; /63/ init packet count stats
  115.     clr    dpnumber        ; /43/ clear data packet count
  116.     movb    sentim    ,senpar+p.time    ; /62/ load send time-out value
  117.  
  118. 30$:    call    sendeb            ; do send debugging if enabled
  119.     call    senlog            ; /62/ update transfer stats display
  120.     cmp    incpar    ,#1        ; /62/ is it possible that parity
  121.     bne    40$            ; /62/ is messed up?
  122.     calls    printm    ,<#1,#sen.02>    ; /62/ warn, but only once
  123.     inc    incpar            ; /62/ be sure it is only once!
  124. 40$:    tst    remote            ; /43/ if remote,
  125.     bne    50$            ; /43/ ignore random noise
  126.     tst    cccnt            ; /36/ ^C abort?
  127.     beq    50$            ; /36/ no
  128.     movb    #sta.cca,state        ; /36/ ya, fake abort
  129. 50$:    scan    state    ,#70$        ; now dispatch
  130.     asl    r0            ; based on current
  131.     jsr    pc    ,@80$(r0)    ; state
  132.     movb    r1    ,state        ; set a new state
  133.     bcc    30$            ; ok
  134.  
  135.     movb    #defchk    ,chktyp        ; reset the checksum type
  136.     mov    #1    ,chksiz        ; size of the above checksum
  137.     save    <r0>            ; save the exit status code
  138.     tst    inopn            ; file open from a failure?
  139.     beq    60$            ; no
  140.     calls    close    ,<#lun.in>    ; ya, ensure that it's closed
  141.     clr    inopn            ; /BBS/ say so..
  142. 60$:
  143. .if df    RT11                ; /E64/
  144.     .purge    #lun.sr            ; /62/ close dir search channel
  145. .endc    ;RT11                ; /E64/
  146.     call    incsta            ; /43/ increment timer stats
  147.     unsave    <r0>            ; pop exit status code please
  148.     return
  149.  
  150.     .save
  151.     .psect    $pdata
  152. 70$:    .byte    sta.abo    ,sta.brk,sta.com,sta.dat,sta.fil,sta.atr,sta.sin
  153.     .byte    sta.eof    ,sta.cca
  154.     .byte    0
  155.     .even
  156. 80$:    .word    send.$
  157.     .word    send$$    ,sbreak    ,send.c    ,sdata    ,sfile    ,sattr    ,sinit    ; /62/
  158.     .word    seof    ,ccabort
  159.     .restore
  160.  
  161.     .dsabl    lsb
  162.  
  163.  
  164.     .sbttl    State routines for SENSW
  165.     .enabl    lsb            ; /62/
  166.  
  167. send.$:    call    bad$pak            ; /62/ report ignoring bad packet type
  168.     movb    state    ,r1        ; /62/ stay in same state
  169.     clc                ; keep sensw running
  170.     return
  171.  
  172. ccabort:spack    #msg$err,paknum        ; /36/ break up a deadlock perhaps
  173. send$$:    mov    sp    ,r0        ; flag there was an error
  174.     movb    #sta.abo,r1        ; return(abort)
  175.     br    10$
  176.  
  177. send.c:    clr    r0            ; complete
  178. 10$:    sec                ; exit sensw
  179.     return
  180.  
  181.     .dsabl    lsb            ; /62/
  182.  
  183.  
  184.     .sbttl    Received bad ACK/NAK and error handling
  185.     .enabl    lsb            ; /62/ all new..
  186.  
  187. sndx$$:    movb    state    ,r1        ; time-out, stay in current state
  188.     br    10$            ; kill re-read loop and retry packet
  189. sndx.$:    cmp    numtry    ,maxtry        ; bad data, been here too often?
  190.     blo    bad$pak            ; compare as if already bumped..
  191. s$retry:call    m$retry            ; too many retries error
  192.     br    sabort
  193. sndx.e:    calls    prerrp    ,<#recpkt>    ; print out received error packet
  194.     br    sabort
  195. s$sync:    call    m$sync            ; can't resync packets error
  196. sabort:    movb    #sta.abo,r1        ; exit please
  197. 10$:    clr    datauk            ; stop read_only loop
  198.     return
  199.  
  200. bad$pak:mov    #1    ,datauk        ; listen again, no matter what
  201.     mov    #badpak    ,r3        ; point to appropriate text
  202.     br    20$            ; common code..
  203. bad$ack:mov    #-1    ,datauk        ; listen again, but just once
  204.     mov    #badack    ,r3        ; point to appropriate text
  205. 20$:    inc    numtry            ; this is another retry
  206.     mov    #pcnt.s    ,r1        ; packet number
  207.     mov    #spare1    ,r0        ; where to write ascii output
  208.     clr    r2            ; kill leading zero and spaces
  209.     call    $cddmg            ; convert 32-bit # to ascii
  210.     clrb    @r0            ; make it .asciz
  211.     calls    printm    ,<#4,#badpre,r3,#badtag,#spare1> ; say what's up
  212.     return
  213.  
  214.     .dsabl    lsb
  215.  
  216.  
  217.     .sbttl    Send debugging and logging    ; /62/ major revision..
  218.  
  219. sendeb:    mov    trace    ,r0        ; copy of debug status word
  220.     bic    #^c<log$pa!log$de>,r0    ; need to do this?
  221.     beq    30$            ; nope
  222.     save    <r1,r2>
  223.     sub    #100.    ,sp        ; allocate a small buffer
  224.     mov    sp    ,r1        ; point to it
  225.     mov    #sen.01    ,r2        ; /62/ pointer to "SEN.SW"
  226.     call    paksta            ; get elapsed time of last packet
  227.     sub    sp    ,r1        ; get the record length
  228.     mov    sp    ,r2        ; and point back to the record
  229.     bit    #log$pa    ,trace        ; debugging for SEND.SW
  230.     beq    10$            ; if trace is on then
  231.     calls    putrec    ,<r2,r1,#lun.lo> ; dump it
  232.     tst    r0            ; did it work?
  233.     beq    10$            ; ya
  234.     call    logerr            ; no, handle the error
  235. 10$:    tst    remote            ; is there a TT to do this?
  236.     bne    20$            ; not right now..
  237.     bit    #log$de    ,trace        ; terminal debugging on?
  238.     beq    20$            ; no
  239.     wrtall    r2            ; ya, print it
  240.     .newline
  241. 20$:    add    #100.    ,sp        ; deallocate the buffer
  242.     unsave    <r2,r1>
  243. 30$:    return
  244.  
  245.  
  246.     .sbttl    Send attribute data for the current file
  247.     .enabl    lsb
  248.  
  249. ; /BBS/    Modified to (w/KRTATR.MAC) send all attributes in a single packet
  250. ; /E64/ Change this back to send multiple attributes packets if
  251. ; /E64/ more than 94 bytes of attributes.
  252.  
  253. sattr:    clr    datauk            ; /62/ init re-read only flag
  254.     inc    numtry            ; abort if it's been trying too much
  255.     cmp    numtry    ,maxtry        ; well?
  256.     blos    10$            ; no, keep it up
  257.     jmp    s$retry            ; /62/ handle the error please
  258.  
  259. 10$:    tst    doattr            ; really do this?
  260.     beq    30$            ; no
  261.     calls    w$attr    ,<#lun.in,#packet> ; build the attributes packet
  262.     tst    r0            ; any errors along the way?
  263.     bne    30$            ; yes
  264.     tst    r1            ; anything to send over?
  265.     beq    30$            ; no
  266.  
  267.     spack    #msg$atr,paknum,r1,#packet ; send file attributes to receiver
  268. 20$:    rpack    r2 ,r3    ,#recpkt,#maxpak ; /62/ get the reply please
  269.     scan    r1    ,#50$        ; and take action on the reply
  270.     asl    r0            ; dispatch based on the packet type
  271.     jsr    pc    ,@60$(r0)    ; simple
  272.     tst    datauk            ; /62/ need to re-read w/o re-sending?
  273.     bne    20$            ; /62/ ya
  274.     br    40$            ; /62/ no
  275.  
  276. 30$:    calls    buffil    ,<#0,#packet>    ; /63/ get the first buffer of data
  277.     mov    r1    ,size        ; and save it
  278.     movb    #sta.dat,r1        ; switch to data state
  279. 40$:    clc                ; /62/ keep sensw running
  280.     return
  281.  
  282.     .save
  283.     .psect    $pdata
  284. 50$:    .byte    msg$err    ,msg$nak,msg$ack,timout    ,badchk
  285.     .byte    0
  286.     .even
  287. 60$:    .word    sndx.$                    ; /62/
  288.     .word    sndx.e    ,satr.n    ,satr.y    ,sndx$$    ,sndx.$    ; /62/ badchk = noise
  289.     .restore
  290.  
  291.     .dsabl    lsb
  292.  
  293.  
  294.     .sbttl    Process response to SATTR
  295.     .enabl    lsb            ; /62/
  296.  
  297. satr$$:    jmp    sndx$$            ; /62/ common code
  298.  
  299. satr.n:    cmp    r3    ,paknum        ; /62/ is NAK for this packet?
  300.     beq    satr$$            ; /62/ ya, resend the data
  301.     dec    r3            ; NAK for next packet
  302.     bge    10$            ; is ACK for current packet
  303.     mov    #63.    ,r3        ; if --paknum<0, 63:paknum
  304. 10$:    cmp    r3    ,paknum        ; well?
  305.     beq    40$            ; /62/ it's an implicit ACK
  306.     br    20$            ; /62/ out of sync, try to fix things
  307.  
  308. satr.y:    cmp    r3    ,paknum        ; ensure ACK is for correct packet
  309.     beq    40$            ; it is
  310. 20$:    cmp    numtry    ,maxtry        ; /62/ it isn't, been here too often?
  311.     blos    30$            ; /62/ not yet
  312.     jmp    s$sync            ; /62/ ya, say so, send error packet
  313.  
  314. 30$:    tst    datauk            ; /62/ already tossed one bad ACK/NAK?
  315.     blt    satr$$            ; /62/ ya, re-send packet
  316.     jmp    bad$ack            ; /62/ listen again, but just once
  317.  
  318. 40$:    clr    datauk            ; /62/ stop read_only loop
  319.     clr    numtry            ; retrycount := 0
  320.     incm64    paknum            ; paknum := (paknum+1) mod 64
  321. .if df    RSTS                ; /E64/
  322.     mov    atrctx    ,atrsnt        ; /E64/ count attributes sent
  323.     calls    w$attr    ,<#lun.in,#packet> ; build the attributes packet
  324.     tst    r0            ; any errors along the way?
  325.     bne    50$            ; yes
  326.     tst    r1            ; anything to send over?
  327.     beq    50$            ; no
  328.     movb    #sta.atr,r1        ; stay in attribute state
  329.     return                ; send next attr packet
  330. .endc    ;RSTS                ; /E64/
  331. 50$:    calls    buffil    ,<#0,#packet>    ; /63/ get the first buffer of data
  332.     mov    r1    ,size        ; /BBS/ and save it
  333.     movb    #sta.dat,r1        ; /BBS/ switch to data state
  334.     return
  335.  
  336.     .dsabl    lsb            ; /62/
  337.  
  338.  
  339.     .sbttl    Send a break packet
  340.     .enabl    lsb
  341.  
  342. sbreak:    clr    datauk            ; /62/ init re-read only flag
  343.     inc    numtry            ; abort if retry count is too high
  344.     cmp    numtry    ,maxtry        ; well?
  345.     blos    10$            ; ok
  346.     jmp    s$retry            ; /62/ handle the error please
  347.  
  348. 10$:    spack    #msg$bre,paknum,#0,#packet ; send a break packet
  349. 20$:    rpack    r2 ,r3    ,#recpkt,#maxpak ; /62/ read the response
  350.     scan    r1    ,#30$        ; and dispatch based on it
  351.     asl    r0            ; word indexing
  352.     jsr    pc    ,@40$(r0)
  353.     tst    datauk            ; /62/ need to re-read w/o re-sending?
  354.     bne    20$            ; /62/ ya
  355.     return                ; /62/ no, carry cleared by above tst
  356.  
  357.     .save
  358.     .psect    $pdata
  359. 30$:    .byte    msg$err    ,msg$nak,msg$ack,timout    ,badchk
  360.     .byte    0
  361.     .even
  362. 40$:    .word    sndx.$                    ; /62/
  363.     .word    sndx.e    ,sbrk.n    ,sbrk.y    ,sndx$$    ,sndx.$    ; /62/ badchk = noise
  364.     .restore
  365.  
  366.     .dsabl    lsb
  367.  
  368.  
  369.     .sbttl    Process response to SBREAK
  370.     .enabl    lsb            ; /62/
  371.  
  372. sbrk$$:    jmp    sndx$$            ; /62/ common code
  373.  
  374. sbrk.n:    cmp    r3    ,paknum        ; /62/ is NAK for this packet?
  375.     beq    sbrk$$            ; /62/ ya, resend the data
  376.     dec    r3            ; NAK for next packet
  377.     bge    10$            ; is ACK for current packet
  378.     mov    #63.    ,r3        ; if --paknum<0, 63:paknum
  379. 10$:    cmp    r3    ,paknum        ; well?
  380.     beq    40$            ; /62/ it's an implicit ACK
  381.     br    20$            ; /62/ out of sync, try to fix things
  382.  
  383. sbrk.y:    cmp    r3    ,paknum        ; ensure ACK is for correct packet
  384.     beq    40$            ; it is
  385. 20$:    cmp    numtry    ,maxtry        ; /62/ it isn't, been here too often?
  386.     blos    30$            ; /62/ not yet
  387.     jmp    s$sync            ; /62/ ya, say so, send error packet
  388.  
  389. 30$:    tst    datauk            ; /62/ already tossed one bad ACK/NAK?
  390.     blt    sbrk$$            ; /62/ ya, re-send packet
  391.     jmp    bad$ack            ; /62/ listen again, but just once
  392.  
  393. 40$:    clr    datauk            ; /62/ stop read_only loop
  394.     clr    numtry            ; ACK for this packet
  395.     incm64    paknum            ; paknum := (paknum+1) mod 64
  396.     movb    #sta.com,r1        ; return(complete)
  397.     return
  398.  
  399.     .dsabl    lsb            ; /62/
  400.  
  401.  
  402.     .sbttl    Send file init
  403.     .enabl    lsb
  404.  
  405. sinit:    movb    #msg$snd,-(sp)        ; normal sinit operation
  406.     call    .sinit            ; for sending files
  407.     return
  408.  
  409. .sinit::clr    datauk            ; /62/ init re-read only flag
  410.     inc    numtry            ; /62/ moved this test here..
  411.     cmp    numtry    ,initry        ; abort if we've been trying too much
  412.     blos    10$            ; no, keep it up
  413.     call    s$retry            ; /62/ yes, return(abort)
  414.     br    30$            ; /62/ go pop init type off the stack
  415.  
  416. 10$:    mov    chktyp    ,-(sp)        ; save checksum type (not needed)
  417.     mov    chksiz    ,-(sp)        ; and size (also not needed)
  418.     movb    #defchk    ,chktyp        ; force type one please
  419.     mov    #1    ,chksiz        ; length of it
  420.     calls    spar    ,<#packet>    ; get our send parameters
  421.     call    cantyp            ; flush pending input please
  422.     movb    6(sp)    ,r5        ; packet type to do today
  423.     spack    r5,paknum,sparsz,#packet ; send our init info now
  424. 20$:    rpack    r2 ,r3    ,#recpkt,#maxpak ; /62/ and get the other's response
  425.     scan    r1    ,#40$        ; and dispatch to the correct
  426.     asl    r0            ; routine now
  427.     jsr    pc    ,@50$(r0)
  428.     tst    datauk            ; /62/ need to re-read w/o re-sending?
  429.     bne    20$            ; /62/ ya  note above tst clears carry
  430.     mov    (sp)+    ,chksiz        ; restore checksum size
  431.     mov    (sp)+    ,chktyp        ; restore checksum type
  432. 30$:    mov    (sp)+    ,@sp        ; dump passed packet type now
  433.     return
  434.  
  435.     .save
  436.     .psect    $pdata
  437. 40$:    .byte    msg$err    ,msg$nak,msg$ack,timout    ,badchk
  438.     .byte    0
  439.     .even
  440. 50$:    .word    sndx.$                    ; /62/
  441.     .word    sini.e    ,sini.n    ,sini.y    ,sndx$$    ,sndx.$    ; /62/ badchk = noise
  442.     .restore
  443.  
  444.     .dsabl    lsb
  445.  
  446.  
  447.     .sbttl    Process response to SINIT
  448.     .enabl    lsb            ; /62/
  449.  
  450. sini.$:    jmp    sndx.$            ; /62/ common
  451. sini$$:    jmp    sndx$$            ; /62/ code
  452.  
  453. sini.e:    calls    prerrp    ,<#recpkt>    ; /62/ print error message
  454.     cmpb    r5    ,#msg$ser    ; if called from sinfo..
  455.     beq    40$            ; /62/ ..ignore errors
  456.     jmp    sabort            ; /62/ return(abort)
  457.  
  458. sini.n:    cmp    r3    ,paknum        ; /62/ is NAK for this packet?
  459.     bne    sini.$            ; /62/ no, try just listening again
  460.     cmpb    r5    ,#msg$ser    ; server NAK for "I" (sinfo) packet?
  461.     bne    10$            ; /62/ no
  462.     cmp    numtry    ,#2        ; gotten at least one NAK for "I" ?
  463.     bhis    40$            ; /62/ ya, move to file state
  464. 10$:    br    sini$$            ; /62/ no, loop another time
  465.  
  466. sini.y:    cmp    r3    ,paknum        ; got an ACK for sinit
  467.     beq    30$            ; and the ACK is for correct packet
  468.     cmp    numtry    ,initry        ; /62/ it isn't, been here too often?
  469.     blos    20$            ; /62/ not yet
  470.     jmp    s$sync            ; /62/ ya, say so, send error packet
  471.  
  472. 20$:    tst    datauk            ; /62/ already tossed one bad ACK/NAK?
  473.     blt    sini$$            ; /62/ ya, re-send packet
  474.     jmp    bad$ack            ; /62/ listen again, but just once
  475.  
  476. 30$:    calls    rpar    ,<#recpkt,r2>    ; load the other's parameters now
  477. 40$:    clr    datauk            ; /62/ stop read_only loop
  478.     clr    numtry            ; number_of_tries := 0
  479.     incm64    paknum            ; pack_number := pack_number+1 mod 64
  480.     movb    #sta.fil,r1        ; return(file)
  481.     jmp    inirepeat        ; /62/ initialize repeat processing
  482.  
  483.     .dsabl    lsb            ; /62/
  484.  
  485.  
  486.     .sbttl    Send a file
  487.     .enabl    lsb
  488.  
  489. sfile:    clr    datauk            ; /62/ init re-read only flag
  490.     inc    numtry            ; /62/ moved this test here..
  491.     cmp    numtry    ,maxtry        ; abort if we've been trying too much
  492.     blos    10$            ; no, keep it up
  493.     jmp    s$retry            ; /62/ handle the error please
  494.  
  495. 10$:    movb    conpar+p.chkt,chktyp    ; switch to new checksum type
  496.     movb    chktyp    ,chksiz        ; compute the checksum size also
  497.     sub    #'0    ,chksiz        ; simple
  498.     mov    $image    ,image        ; ensure correct default for mode
  499.     mov    #filnam    ,r3        ; and point to it please
  500.     clr    skipfl            ; the user skipped the rest of a file
  501.     call    clratr            ; ensure attribute stuff is cleared
  502.     call    inirepeat        ; must reset ptrs for repeat counts
  503.     sub    #ln$max+2,sp        ; /63/ a converted file name buffer
  504.     mov    sp    ,r4        ; and point to it please
  505.     tst    inopn            ; open files hanging around?
  506.     beq    20$            ; no
  507.     calls    close    ,<#lun.in>    ; yes, clean up please
  508.     clr    inopn            ; it's closed now
  509. 20$:    tstb    filnam            ; /38/ a REAL file today?
  510.     bne    30$            ; /38/ ya..
  511.     jmp    70$            ; /38/ no, must be an extended reply
  512. 30$:    tst    doauto            ; see if we should check for binary
  513.     beq    40$            ; no, don't do it please
  514.     tst    image            ; /56/
  515.     bne    40$            ; /56/
  516.     calls    chkext    ,<#filnam>    ; should we force binary mode?
  517.     tst    r0            ; if gt, then yes
  518.     ble    40$            ; no
  519.     mov    #binary    ,image        ; yes, force binary file operations
  520. 40$:    calls    open    ,<#filnam,#lun.in,image> ; open the file for input
  521.     tst    r0            ; did it work?
  522.     beq    50$            ; yes
  523.     calls    syserr    ,<r0,#errtxt>    ; no
  524.     calls    error    ,<#3,#errtxt,#aspace,#filnam> ; /BBS/ add space here
  525.     movb    #sta.abo,r1        ; return(abort)
  526.     br    90$            ; go dump local buffer and exit
  527.  
  528. 50$:    mov    sp    ,inopn        ; file is open
  529.     tst    xmode            ; is this a server X-tended reply?
  530.     bne    70$            ; yes, send a simple "X" packet
  531.     calls    namcvt    ,<#filnam,r4>    ; convert to simple name (strip dev:)
  532.     tstb    asname            ; /36/ check for alternate name?
  533.     beq    60$            ; /36/ no
  534.     mov    #asname    ,r4        ; /36/ yes, point to that name
  535. 60$:    movb    #'[    ,errtxt        ; /63/ a leading bracket
  536.     mov    #lun.in    ,r0        ; /63/ the LUN in use here
  537.     asl    r0            ; /63/ word indexing
  538. ; /E64/    NOTE: this doesn't handle large files!!
  539.     mov    sizof(r0),r0        ; /63/ recover the file size
  540.     mov    #errtxt+1,r1        ; /63/ start writing size here
  541.     call    L10012            ; /63/ convert size to ascii
  542.     movb    #']    ,(r1)+        ; /63/ a terminating bracket
  543.     clrb    (r1)            ; /63/ terminate the size string
  544.     mov    image    ,r1        ; /63/ recover current file-type
  545.     asl    r1            ; /63/ word indexing
  546.     mov    fillst(r1),r1        ; /63/ point to its description
  547.     calls    printm    ,<#7,#sen.07,#filnam,#errtxt,#sen.08,r1,#sen.09,r4>
  548.     strlen    r4            ; and get the file name length
  549.     spack    #msg$fil,paknum,r0,r4    ; set the file name packet over
  550.     clrb    asname            ; /36/ ensure one shot only
  551.     br    80$
  552.  
  553. 70$:    spack    #msg$tex,paknum        ; server extended reply here, send "X"
  554. 80$:    rpack    r2 ,r3    ,#recpkt,#maxpak ; /62/ get response to the file name
  555.     scan    r1    ,#100$        ; and dispatch on the response
  556.     asl    r0            ; word indexing
  557.     jsr    pc    ,@110$(r0)    ; and call the appropriate response
  558.     tst    datauk            ; /62/ need to re-read w/o re-sending?
  559.     bne    80$            ; /62/ ya
  560. 90$:    add    #ln$max+2,sp        ; /63/ dump local buff, clears carry
  561.     return
  562.  
  563.     .save
  564.     .psect    $pdata
  565. 100$:    .byte    msg$err    ,msg$nak,msg$ack,timout    ,badchk
  566.     .byte    0
  567.     .even
  568. 110$:    .word    sndx.$                    ; /62/
  569.     .word    sndx.e    ,sfil.n    ,sfil.y    ,sndx$$    ,sndx.$    ; /62/ badchk = noise
  570.     .restore
  571.  
  572.     .dsabl    lsb
  573.  
  574.  
  575.     .sbttl    Process response to SFILE
  576.     .enabl    lsb            ; /62/
  577.  
  578. sfil$$:    jmp    sndx$$            ; /62/ common code
  579.  
  580. sfil.n:    cmp    r3    ,paknum        ; /62/ is NAK for this packet?
  581.     beq    sfil$$            ; /62/ ya, resend the data
  582.     dec    r3            ; NAK for next packet
  583.     bge    10$            ; is ACK for current packet
  584.     mov    #63.    ,r3        ; if --paknum<0, 63:paknum
  585. 10$:    cmp    r3    ,paknum        ; well?
  586.     beq    40$            ; /62/ it's an implicit ACK
  587.     br    20$            ; /62/ out of sync, try to fix things
  588.  
  589. sfil.y:    cmp    r3    ,paknum        ; ensure ACK is for correct packet
  590.     beq    40$            ; it is
  591. 20$:    cmp    numtry    ,maxtry        ; /62/ it isn't, been here too often?
  592.     blos    30$            ; /62/ not yet
  593.     jmp    s$sync            ; /62/ ya, say so, send error packet
  594.  
  595. 30$:    tst    datauk            ; /62/ already tossed one bad ACK/NAK?
  596.     blt    sfil$$            ; /62/ ya, re-send packet
  597.     jmp    bad$ack            ; /62/ listen again, but just once
  598.  
  599. 40$:    tstb    recpkt            ; /63/ anything in received packet?
  600.     beq    50$            ; /63/ no
  601.     calls    printm    ,<#2,#sen.03,#recpkt> ; /63/ ya, print the packet
  602. 50$:    clr    datauk            ; /62/ stop read_only loop
  603.     clr    numtry            ; number_of_tries := 0
  604.     incm64    paknum            ; packnumber := packnumber+1 mod 64
  605. .if df    RSTS                ; /E64/
  606.     clr    atrsnt            ; /E64/ we haven't sent any attrs yet
  607. .endc    ;RSTS                ; /E64/
  608.     movb    #sta.atr,r1        ; assume return(attribute)
  609.     tst    xmode            ; /38/ is this an extended reply?
  610.     beq    60$            ; /38/ no, attributes are next
  611.     calls    buffil    ,<#0,#packet>    ; /63/ ya, get first buffer of data
  612.     mov    r1    ,size        ; /38/ and save it
  613.     movb    #sta.dat,r1        ; /38/ skip attributes, return(data)
  614. 60$:    return
  615.  
  616.     .dsabl    lsb
  617.  
  618.  
  619.     .sbttl    Send file data
  620.     .enabl    lsb
  621.  
  622. sdata:    clr    datauk            ; /62/ init re-read only flag
  623.     inc    numtry            ; abort if we've been trying too much
  624.     cmp    numtry    ,maxtry        ; well?
  625.     blos    10$            ; no, keep it up
  626.     jmp    s$retry            ; /62/ flag the error type please
  627.  
  628. 10$:    spack    #msg$dat,paknum,size,#packet ; send the next record please
  629. 20$:    rpack    r2 ,r3    ,#recpkt,#maxpak ; /62/ get the reply
  630.     scan    r1    ,#30$        ; look for type in list of responses
  631.     asl    r0            ; word indexing
  632.     jsr    pc    ,@40$(r0)    ; dispatch based on the packet type
  633.     tst    datauk            ; /62/ need to re-read w/o re-sending?
  634.     bne    20$            ; /62/ ya
  635.     return                ; /62/ no, carry cleared by above tst
  636.  
  637.     .save
  638.     .psect    $pdata
  639. 30$:    .byte    msg$err    ,msg$nak,msg$ack,timout    ,badchk
  640.     .byte    0
  641.     .even
  642. 40$:    .word    sndx.$                    ; /62/
  643.     .word    sndx.e    ,sdat.n    ,sdat.y    ,sdat$$    ,sndx.$    ; /62/ badchk = noise
  644.     .restore
  645.  
  646.     .dsabl    lsb
  647.  
  648.  
  649.     .sbttl    Process response to SDATA
  650.  
  651. sdat$$:    tst    dpnumber        ; /43/ first data packet?
  652.     bne    10$            ; /43/ no
  653.     cmp    senlng    ,#maxpak    ; /43/ long packet gotten TOO small?
  654.     blos    10$            ; /43/ ya
  655.     asr    senlng            ; /43/ no, reduce packet size
  656.     mov    senlng    ,r0        ; /BBS/ pass new length to L10012
  657.     mov    #spare1    ,r1        ; /BBS/ where to write ascii digits
  658.     call    L10012            ; /BBS/ convert r0 to decimal number
  659.     clrb    @r1            ; /BBS/ null terminate the string
  660.     calls    printm    ,<#3,#adpmsg,#spare1,#adptag> ; /BBS/ inform the user
  661. ;/E64/    This next, commented-out section closes and re-opens the
  662. ;    input file to reset our send pointer.  We are going to try
  663. ;    rewinding it, instead.
  664. ;    calls    close    ,<#lun.in>    ; /E64/ clean up please
  665. ;    clr    inopn            ; /E64/ it's closed now
  666. ;    calls    open    ,<#filnam,#lun.in,image> ; /63/ back to top of file
  667. ;    tst    r0            ; /E64/ did it work?
  668. ;    beq    50$            ; /E64/ yes
  669. ;    calls    syserr    ,<r0,#errtxt>    ; /E64/ no
  670. ;    calls    error    ,<#3,#errtxt,#aspace,#filnam> ; /E64/ add space here
  671. ;    jmp    sabort            ; /E64/ whoops!!
  672. ;
  673. ;50$:    mov    sp    ,inopn        ; file is open
  674.     calls    rewind    ,<#lun.in>    ; /E64/ rewind please
  675.     clr    fileout+0        ; /63/ no chars sent yet
  676.     clr    fileout+2        ; /63/ this too just to be sure..
  677.     call    inirepeat        ; /E64/ must reset repeat count ptrs
  678.     calls    buffil    ,<#0,#packet>    ; /63/ redo the re-sized packet
  679.     mov    r1    ,size        ; /63/ and save it's new length here
  680. 10$:    jmp    sndx$$            ; /62/ keep current state, try again
  681.  
  682.  
  683.     .enabl    lsb
  684.  
  685. sdat.n:    cmp    r3    ,paknum        ; /62/ is NAK for this packet?
  686.     beq    sdat$$            ; /62/ ya, resend the data
  687.     dec    r3            ; NAK for next packet
  688.     bge    10$            ; is ACK for current packet
  689.     mov    #63.    ,r3        ; if --paknum<0, 63:paknum
  690. 10$:    cmp    r3    ,paknum        ; well?
  691.     beq    40$            ; /62/ it's an implicit ACK
  692.     br    20$            ; /62/ out of sync, try to fix things
  693.  
  694. sdat.y:    cmp    r3    ,paknum        ; ensure ACK is for correct packet
  695.     beq    40$            ; it is
  696. 20$:    cmp    numtry    ,maxtry        ; /62/ it isn't, been here too often?
  697.     blos    30$            ; /62/ not yet
  698.     jmp    s$sync            ; /62/ ya, say so, send error packet
  699.  
  700. 30$:    tst    datauk            ; /62/ already tossed one bad ACK/NAK?
  701.     blt    sdat$$            ; /62/ ya, re-send packet
  702.     jmp    bad$ack            ; /62/ listen again, but just once
  703.  
  704. 40$:    clr    datauk            ; /62/ stop read_only loop
  705.     add    #1    ,dpnumber    ; /43/ datapacket_number++
  706.     bcc    50$            ; /43/
  707.     mov    #1    ,dpnumber    ; /43/ avoid overflow
  708. 50$:    clr    numtry            ; retry_counter = 0
  709.     incm64    paknum            ; paknum = paknum++ mod 64
  710.     tst    remote            ; is this a remote system?
  711.     bne    90$            ; yes, forget about checking
  712.     tst    cccnt            ; ^C pending?
  713.     bne    80$            ; yes, always send an error packet
  714.     call    chkabo            ; now check for ^A, ^E, ^X or ^Z
  715.     cmpb    r0    ,#'A&37        ; /56/ ^A stats?
  716.     bne    60$            ; /56/ no
  717.     call    cs$out            ; /56/ yes, dump char counts
  718.     br    90$            ; /56/ and finish up
  719. 60$:    cmpb    r0    ,#abt$err&37    ; /56/ if ^E
  720.     beq    80$            ; /56/ then send error packet
  721.     cmpb    r0    ,#abt$cur&37    ; if ^X
  722.     beq    70$            ; then abort current file
  723.     cmpb    r0    ,#abt$all&37    ; if ^Z
  724.     bne    90$            ; then abort file group
  725.     mov    #-1    ,index        ; flag that we are all done
  726. 70$:    mov    #sta.eof,r1        ; force new state to EOF
  727.     mov    sp    ,skipfl        ; get seof to set discard
  728.     return
  729. 80$:    spack    #msg$err,paknum        ; send an error packet
  730.     clr    cccnt            ; /36/ clear ^C flag
  731.     jmp    sabort            ; /62/ force state to abort
  732.  
  733. 90$:    cmpb    recpkt    ,#abt$cur    ; ACK contain a "X" for skipfile?
  734.     bne    100$            ; /BBS/ no
  735.     calls    printm    ,<#2,#sen.03,#sen.04> ; /63/ ya, say so if not remote
  736.     br    110$            ; /BBS/ then fake EOF
  737. 100$:    cmpb    recpkt    ,#abt$all    ; ACK contain a "Z" for skip all?
  738.     bne    120$            ; no
  739.     calls    printm    ,<#2,#sen.03,#sen.05> ; /63/ ya, say so if not remote
  740.      mov    #-1    ,index        ; flag a fake no more files and
  741. 110$:     movb    #sta.eof,r1        ; fake EOF for either "X" or "Z" ACK
  742.      return
  743.  
  744. 120$:    add    size    ,charout+2    ; /43/ keep track of counts
  745.     adc    charout+0        ; /43/ 32. bits please
  746.     calls    buffil    ,<#0,#packet>    ; /63/ get next buffer of data to send
  747.     mov    r1    ,size        ; and save the size please
  748.     bne    130$            ; something was there
  749.      movb    #sta.eof,r1        ; set state to EOF
  750.      return
  751. 130$:    movb    #sta.dat,r1        ; not EOF, stay in data state
  752.     return
  753.  
  754.     .dsabl    lsb
  755.  
  756.  
  757.     .sbttl    Send end of file packet
  758.     .enabl    lsb
  759.  
  760. seof:    clr    datauk            ; /62/ init re-read only flag
  761.     inc    numtry            ; abort if we've been trying too much
  762.     cmp    numtry    ,maxtry        ; well?
  763.     blos    10$            ; no, keep it up
  764.     jmp    s$retry            ; /62/ handle the error please
  765.  
  766. 10$:    tst    skipfl            ; skipping the rest of a file?
  767.     beq    20$            ; no
  768.     spack    #msg$eof,paknum,#1,#sen.06 ; /62/ yes, send "D" in data field
  769.     br    30$
  770. 20$:    spack    #msg$eof,paknum        ; send an EOF packet out now
  771. 30$:    rpack    r2 ,r3    ,#recpkt,#maxpak ; /62/ get the reply please
  772.     scan    r1    ,#40$        ; and take action on the reply
  773.     asl    r0            ; word indexing
  774.     jsr    pc    ,@50$(r0)    ; dispatch based on the packet type
  775.     tst    datauk            ; /62/ need to re-read w/o re-sending?
  776.     bne    30$            ; /62/ ya
  777.     clr    skipfl            ; clear skipfile flg, also clear carry
  778.     return
  779.  
  780.     .save
  781.     .psect    $pdata
  782. 40$:    .byte    msg$err    ,msg$nak,msg$ack,timout    ,badchk
  783.     .byte    0
  784.     .even
  785. 50$:    .word    sndx.$                    ; /62/
  786.     .word    sndx.e    ,seof.n    ,seof.y    ,sndx$$    ,sndx.$    ; /62/ badchk = noise
  787.     .restore
  788.  
  789.     .dsabl    lsb
  790.  
  791.  
  792.     .sbttl    Process response to SEOF
  793.     .enabl    lsb            ; /62/
  794.  
  795. seof$$:    jmp    sndx$$            ; /62/ common code
  796.  
  797. seof.n:    cmp    r3    ,paknum        ; /62/ is NAK for this packet?
  798.     beq    seof$$            ; /62/ ya, resend the data
  799.     dec    r3            ; NAK for next packet
  800.     bge    10$            ; is ACK for current packet
  801.     mov    #63.    ,r3        ; if --paknum<0, 63:paknum
  802. 10$:    cmp    r3    ,paknum        ; well?
  803.     beq    40$            ; /62/ it's an implicit ACK
  804.     br    20$            ; /62/ out of sync, try to fix things
  805.  
  806. seof.y:    cmp    r3    ,paknum        ; ensure ACK is for correct packet
  807.     beq    40$            ; it is
  808. 20$:    cmp    numtry    ,maxtry        ; /62/ it isn't, been here too often?
  809.     blos    30$            ; /62/ not yet
  810.     jmp    s$sync            ; /62/ ya, say so, send error packet
  811.  
  812. 30$:    tst    datauk            ; /62/ already tossed one bad ACK/NAK?
  813.     blt    seof$$            ; /62/ ya, re-send packet
  814.     jmp    bad$ack            ; /62/ listen again, but just once
  815.  
  816. 40$:    clr    datauk            ; /62/ stop read_only loop
  817.     clr    numtry            ; clear the retry count
  818.     incm64    paknum            ; paknum := (paknum+1) mod 64
  819.     calls    close    ,<#lun.in>    ; close the input file
  820.     clr    inopn            ; input file is now closed
  821.     cmp    index    ,#-1        ; force a break here from user
  822.     beq    50$            ; yes
  823.     clr    r0            ; /38/ no errors
  824.     tst    xmode            ; /38/ extended response?
  825.     bne    50$            ; /38/ finish up the transaction
  826.     call    getnxt            ; get the next input file?
  827.     tst    r0            ; did it work?
  828.     bne    50$            ; no
  829.     movb    #sta.fil,r1        ; yes, set new state to file
  830.     return
  831. 50$:    movb    #sta.brk,r1        ; return(break)
  832.     return
  833.  
  834.     .dsabl    lsb            ; /62/
  835.  
  836.     .end
  837.