home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / b / krtrec.mac < prev    next >
Text File  |  2020-01-01  |  26KB  |  775 lines

  1.     .title    KRTREC    Receive file processing
  2.     .ident    "V03.63"
  3.  
  4. ; /63/    27-Sep-97  Billy Youdelman  V03.63
  5. ;
  6. ;    support gets to LP
  7. ;    display file size in "created file" messages
  8. ;    fix unpopped stack on error exit from bufemp
  9. ;    display file type in file create message
  10. ;    display file name sent back by remote Kermit
  11.  
  12. ; /62/    27-Jul-93  Billy Youdelman  V03.62
  13. ;
  14. ;    dump FILLOG, as PRINTM now does this
  15. ;    use log$packets for state logging
  16. ;    provide for logfile errors
  17. ;    modify to not NAK unknown packets (noise)
  18. ;    display any possible contents of "X" packet, for Unix and C-Kermit
  19.  
  20. ; /BBS/     1-Dec-91  Billy Youdelman  V03.61
  21. ;
  22. ;    rfil.x: put "Remote server response:" here so it displays even
  23. ;    when blo <>1.  also set image=binary here so typing 8-bit
  24. ;    files doesn't die on checksum error when clrpar hoses hi bits
  25. ;
  26. ;    rfil.f: check asname here (instead of rfil.d), also fixed so
  27. ;    VMS filespecs longer than 66. bytes don't write past end of the
  28. ;    scratch buffer.  also namcvt strips VMS node::dev:[dir] here..
  29. ;
  30. ;    kill debug to TT if not running as a local Kermit
  31. ;    add support for INCOMPLETE-FILE-DISPOSITION
  32.  
  33. ;    13-Oct-84  14:06:43  Brian Nelson
  34. ;
  35. ;    Copyright 1983,1984  Change Software, Inc.
  36. ;
  37. ;    This software is furnished under a license and may
  38. ;    be  used  and  copied  only in accordance with the
  39. ;    terms of such license and with  the  inclusion  of
  40. ;    the  above copyright notice.  This software or any
  41. ;    other copies thereof may not be provided or other-
  42. ;    wise made available to any other person.  No title
  43. ;    to and ownership of the software is hereby  trans-
  44. ;    ferred.
  45. ;
  46. ;    The information in this  software  is  subject  to
  47. ;    change  without notice and should not be construed
  48. ;    as a commitment by the author.
  49.  
  50.  
  51.     .include "IN:KRTMAC.MAC"
  52.     .iif ndf  KRTINC  .error    <; .include for IN:KRTMAC.MAC failed>
  53.     .include "IN:KRTDEF.MAC"
  54.     .iif ndf  MSG$DA  .error    <; .include for IN:KRTDEF.MAC failed>
  55.  
  56.     .mcall    .PURGE            ; /62/ hose dir search chan on error
  57.  
  58.  
  59.     .sbttl    Local data
  60.  
  61.     .psect    $pdata            ; /62/ consolidated this stuff here..
  62. fillst:    .word    10$    ,20$    ,30$    ; /63/
  63.  10$:    .asciz    "ASCII (7-bit text)"    ; /63/
  64.  20$:    .asciz    "BINARY (fixed 512)"    ; /63/
  65.  30$:    .asciz    "DEC-Multinational (8-bit text)" ; /63/
  66. dejavu:    .asciz    "Duplicate packet received" ; /63/
  67. dejatag:.asciz    ", paknum: "
  68. get2lp:    .asciz    "KRTGET.OUT"        ; /63/ need a name to output to LP
  69. nojavu:    .asciz    "Ignoring invalid response" ; /63/
  70. rec.01:    .asciz     "Remote server response:"<cr><lf><cr><lf> ; /63/
  71. rec.02:    .asciz    <bell>"Receive completed"
  72. rec.03:    .asciz    <bell>"Receive failed"
  73. rec.04:    .byte    abt$cur    ,0
  74. rec.05:    .byte    abt$all    ,0
  75. rec.06:    .asciz    "Created "
  76. rec.07:    .asciz    " file - "        ; /63/
  77. rec.08:    .asciz    "You have SET FILE PROTECT thus "
  78. rec.09:    .asciz    " can't be overwritten"
  79. rec.10:    .asciz    "Missing length attribute or "    ; /63/
  80. rec.11:    .asciz    " is empty"            ; /63/
  81. rec.12:    .asciz    "Received file name - "        ; /63/
  82. rec.13:    .asciz    "Warning: "            ; /63/
  83. rec.14:    .asciz    "REC.SW"
  84. rec.15:    .asciz    "Parity found in SOH byte"
  85. rec.16:    .asciz    " renamed to "
  86.     .even
  87.  
  88.  
  89.     .psect    $code
  90.     .sbttl    Receive file(s)        ; /62/ moved this here..
  91.  
  92. c$rec::    call    opentt            ; initialize the link device
  93.     tst    r0            ; /BBS/ did it work?
  94.     bne    20$            ; /BBS/ no
  95.     tst    outopn            ; is an output file already open?
  96.     beq    10$            ; no
  97.     calls    close    ,<#lun.ou>    ; yes, close it up please
  98. 10$:    mov    sp    ,inprogress    ; /BBS/ packets are being exchanged
  99.     calls    recsw    ,<#sta.rin>    ; get the file
  100.     tst    r0            ; did it work?
  101.     bne    20$            ; no
  102.     calls    printm    ,<#1,#rec.02>    ; /62/ yes, say so if we are local
  103.     br    30$
  104. 20$:    calls    printm    ,<#1,#rec.03>    ; /62/ it failed, say so if local
  105.     inc    status            ; /45/ flag for batch exit
  106. 30$:    call    clostt            ; release the terminal
  107.     jmp    clrcns            ; /62/ flush TT input, clear r0
  108.  
  109.  
  110.     .sbttl    State controller for receive file processing
  111.     .enabl    lsb
  112.  
  113. recsw::    clr    paknum            ; packet_number := 0
  114. rec.sw::movb    @r5    ,state        ; load passed state
  115.     clr    cccnt            ; no ^Cs typed yet
  116.     mov    $image    ,image        ; ensure correct default for mode
  117.     movb    #defchk    ,chktyp        ; reset checksum type to default
  118.     mov    #1    ,chksiz        ; size of default checksum
  119.     clr    numtry            ; number_trys := 0
  120.     clr    outopn            ; say nothing is open now
  121.     clr    logini            ; /62/ force display stats header
  122.     call    inista            ; /63/ init packet stats
  123.     movb    rectim    ,senpar+p.time    ; /62/ load RECEIVE time-out value
  124.  
  125. 10$:    call    recdeb            ; perhaps debugging should be done
  126.     call    reclog            ; /62/ update transfer stats display
  127.     cmp    incpar    ,#1        ; /56/ is it possible that parity
  128.     bne    20$            ; /56/ is messed up?
  129.     calls    printm,<#2,#rec.13,#rec.15> ; /63/ warn, but only once
  130.     inc    incpar            ; /BBS/ be sure it is only once!
  131. 20$:    tst    remote            ; /43/ running as a server?
  132.     bne    30$            ; /43/ yep, ignore random noise
  133.     tst    cccnt            ; /36/ ^C abort?
  134.     beq    30$            ; /36/ no
  135.     movb    #sta.cca,state        ; /36/ yes, enter abort state
  136. 30$:    scan    state    ,#50$        ; now dispatch
  137.     asl    r0            ; based on current
  138.     jsr    pc    ,@60$(r0)    ; state
  139.     bcc    10$            ; continue whilst carry remains clear
  140.  
  141.     movb    #defchk    ,chktyp        ; reset type of checksum to 1
  142.     mov    #1    ,chksiz        ; the above checksum uses 1 byte
  143.     save    <r0>            ; save exit status
  144.     tst    outopn            ; file open from a failure?
  145.     bpl    40$            ; no
  146.     calls    close    ,<#lun.ou>    ; ensure that it's closed
  147. 40$:    clr    outopn            ; clear this flag to say it is..
  148.     .purge    #lun.sr            ; /62/ close dir search channel
  149.     call    incsta            ; /43/ init timer stats
  150.     unsave    <r0>            ; pop exit status code please
  151.     return
  152.  
  153.     .save
  154.     .psect    $pdata
  155. 50$:    .byte    sta.abo    ,sta.com,sta.dat,sta.fil,sta.rin,sta.cca
  156.     .byte    0
  157.     .even
  158. 60$:    .word    recs.$
  159.     .word    recs$$    ,recs.c    ,recs.d    ,recs.f    ,recs.r    ,ccabort ; /62/
  160.     .restore
  161.  
  162.     .dsabl    lsb
  163.  
  164.  
  165.     .sbttl    State routines for RECSW
  166.     .enabl    lsb            ; /62/
  167.  
  168. ccabort:spack    #msg$err,paknum        ; /36/ break out the sender
  169. recs$$:    tst    outopn            ; /62/ is an output file open?
  170.     bge    10$            ; /BBS/ no..
  171.     mov    incfile    ,skipfile    ; /BBS/ ya, disposition to file closer
  172. 10$:    mov    sp    ,r0        ; abort
  173.     br    20$
  174.  
  175. recs.$:    call    recx.$            ; /62/ report invalid packet type
  176.     br    30$            ; /62/ then go back and try it again
  177.  
  178. recs.c:    clr    r0            ; complete
  179. 20$:    sec                ; force exit from recsw loop
  180.     return
  181.  
  182. recs.d:    call    rdata            ; receive_data
  183.     br    30$            ; /62/ pass state, keep recsw running
  184.  
  185. recs.f:    call    rfile            ; receive_file
  186.     br    30$            ; /62/ pass state, keep recsw running
  187.  
  188. recs.r:    call    rinit            ; receive_init
  189. 30$:    movb    r1    ,state        ; pass returned state
  190.     clc                ; keep recsw running
  191.     return
  192.  
  193.     .dsabl    lsb            ; /62/
  194.  
  195.  
  196.     .sbttl    Received bad ACK/NAK and error handling
  197.     .enabl    lsb            ; /62/ all new..
  198.  
  199. recx.e:    calls    prerrp    ,<#packet>    ; received error packet, display it
  200.     br    rabort
  201. r$sync:    call    m$sync            ; packets out of sync error
  202.     br    rabort
  203. r$retry:call    m$retry            ; too many retries error
  204. rabort:    movb    #sta.abo,r1        ; exit please
  205.     return
  206.  
  207. recx$$:    spack    #msg$nak,paknum        ; NAK a time-out or bad checksum
  208.     br    20$
  209. recx.$:    mov    #nojavu    ,r3        ; ignore an invalid packet type
  210.     br    10$
  211. deja$vu:spack    #msg$ack,r3        ; ACK the last packet again
  212. deja$$:    mov    #dejavu    ,r3        ; dupe packet received
  213. 10$:    mov    #pcnt.r    ,r1        ; packet number
  214.     mov    #spare1    ,r0        ; where to write ascii output
  215.     clr    r2            ; kill leading zero and spaces
  216.     call    $cddmg            ; convert 32-bit # to ascii
  217.     clrb    @r0            ; make it .asciz
  218.     calls    printm    ,<#3,r3,#dejatag,#spare1> ; say what's up
  219. 20$:    movb    state    ,r1        ; stay in the same state, try again
  220.     return
  221.  
  222.     .dsabl    lsb
  223.  
  224.  
  225.     .sbttl    Receive debugging and logging    ; /62/ major revision..
  226.  
  227. recdeb:    mov    trace    ,r0        ; copy of debug status word
  228.     bic    #^c<log$pa!log$de>,r0    ; need to do this?
  229.     beq    30$            ; nope
  230.     save    <r1,r2>
  231.     sub    #100.    ,sp        ; allocate a small buffer
  232.     mov    sp    ,r1        ; point to it
  233.     mov    #rec.14    ,r2        ; /62/ point to "REC.SW"
  234.     call    paksta            ; get elapsed time of last transaction
  235.     sub    sp    ,r1        ; get the record length
  236.     mov    sp    ,r2        ; and point back to the record
  237.     bit    #log$pa    ,trace        ; debugging for recsw?
  238.     beq    10$            ; not on
  239.     calls    putrec    ,<r2,r1,#lun.lo> ; it is on, dump it
  240.     tst    r0            ; did it work?
  241.     beq    10$            ; ya
  242.     call    logerr            ; no, handle the error
  243. 10$:    tst    remote            ; running locally? /BBS/ moved here
  244.     bne    20$            ; no
  245.     bit    #log$de    ,trace        ; ya, is terminal debugging on?
  246.     beq    20$            ; no
  247.     wrtall    r2            ; ya, print it
  248.     .newline
  249. 20$:    add    #100.    ,sp        ; pop local buffer
  250.     unsave    <r2,r1>
  251. 30$:    return
  252.  
  253.  
  254.     .sbttl    Receive file initialization
  255.     .enabl    lsb
  256.  
  257. rinit:    inc    numtry            ; check for retry count
  258.     cmp    numtry    ,initry        ; been here too often?
  259.     blos    10$            ; no
  260.      jmp    r$retry            ; /62/ log/send the reason for abort
  261.  
  262. 10$:    rpack    r2 ,r3    ,#packet,#maxlng ; /62/ get the next packet please
  263.     scan    r1    ,#20$        ; look for the packet type
  264.     asl    r0            ; word indexing
  265.     jmp    @30$(r0)        ; /62/ dispatch to it
  266.  
  267.     .save
  268.     .psect    $pdata
  269. 20$:    .byte    msg$err    ,msg$snd,timout    ,badchk
  270.     .byte    0
  271.     .even
  272. 30$:    .word    recx.$                ; /62/
  273.     .word    recx.e    ,rini.s    ,recx$$    ,recx$$    ; /62/
  274.     .restore
  275.  
  276.     .dsabl    lsb
  277.  
  278.  
  279.     .sbttl    Process response to RINIT
  280.  
  281. rini.s:    calls    rpar    ,<#packet,r2>    ; send_init  get other side's init
  282.     calls    spar    ,<#packet>    ; parameters, then fill with ours
  283.     spack    #msg$ack,paknum,sparsz,#packet ; and ship that back to sender
  284.     clr    numtry            ; retry_count := 0
  285.     incm64    paknum            ; paknum := (paknum+1) mod 64
  286.     movb    #sta.fil,r1        ; state := file_receive
  287.     jmp    inirepeat        ; /62/ initialize repeat processing
  288.  
  289.  
  290.     .sbttl    Receive file header
  291.     .enabl    lsb
  292.  
  293. rfile:    inc    numtry            ; check for retry count
  294.     cmp    numtry    ,maxtry        ; been here too often?
  295.     blos    10$            ; no
  296.      jmp    r$retry            ; /62/ log why we aborted please
  297.  
  298. 10$:    call    clratr            ; ensure attribute stuff is cleared
  299.     movb    conpar+p.chkt,chktyp    ; time to use new checksum
  300.     movb    chktyp    ,chksiz        ; compute the checksum size also
  301.     sub    #'0    ,chksiz        ; simple
  302.     mov    $image    ,image        ; ensure correct default for mode
  303.     tst    xgottn            ; already get the "X" packet?
  304.     beq    20$            ; no
  305.     movb    #sta.typ,r1        ; yes, fake that we already got it
  306.     br    30$
  307. 20$:    rpack    r2 ,r3    ,#packet,#maxlng ; /62/ get the next packet please
  308. 30$:    scan    r1    ,#40$        ; look for the packet type
  309.     asl    r0            ; word indexing
  310.     jmp    @50$(r0)        ; /62/ and dispatch to it
  311.  
  312.     .save
  313.     .psect    $pdata
  314. 40$:    .byte    msg$bre    ,msg$err,msg$fil,msg$snd,msg$tex,msg$eof
  315.     .byte    timout    ,badchk
  316.     .byte    0
  317.     .even
  318. 50$:    .word    recx.$                        ; /62/
  319.     .word    rfil.b    ,recx.e    ,rfil.f    ,rfil.s    ,rfil.x    ,rfil.z    ; /62/
  320.     .word    recx$$    ,recx$$                    ; /62/
  321.     .restore
  322.  
  323.     .dsabl    lsb
  324.  
  325.  
  326.     .sbttl    Process response to RFILE
  327.  
  328. rfil.b:    cmp    r3    ,paknum        ; break_transmission (EOT)
  329.     beq    10$            ; ensure break is for current packet
  330.      jmp    r$sync            ; /62/ it's not, we are out of sync
  331.  
  332. 10$:    spack    #msg$ack,paknum        ; ACK the break
  333.     movb    #sta.com,r1        ; and return state as complete
  334.     return
  335.  
  336.  
  337.     .sbttl    Receive file name    ; 18-Apr-84 10:24:45  Brian Nelson
  338.  
  339. ;    Move the actual file create to RDATA so we can create
  340. ;    the output file after all attribute packets have come.
  341. ;    Thus, when we get the first DATA packet is when we go
  342. ;    and create the file.
  343.  
  344. rfil.f:    cmp    r3    ,paknum        ; file name
  345.     beq    10$            ; ensure correct packet number
  346.      jmp    r$sync            ; /62/ log the reason for this abort
  347.  
  348. 10$:    calls    bufunp    ,<#packet,#spare1> ; /BBS/ use buff that's long enough
  349.     calls    printm    ,<#2,#rec.12,#spare1> ; /63/ display remote file name
  350.     calls    namcvt    ,<#spare1,#packet> ; /BBS/ maybe strip node::dev:[dir]
  351.     calls    fixfil    ,<#packet,#srcnam> ; fix invalid chars/trunc for RT-11
  352.     mov    #asname    ,r1        ; /62/ point to possible new name
  353.     tstb    (r1)            ; /62/ renaming this time?
  354.     bne    20$            ; /62/ ya, go say so..
  355.     mov    #srcnam    ,r1        ; /62/ no, point to old file name
  356.     tst    r0            ; was the old file name ok?
  357.     beq    40$            ; /62/ yes
  358.     br    30$            ; /63/ no, display change/truncation
  359.  
  360. 20$:    upcase    r1            ; /63/ leaves copy of ptr in r0
  361.     cmpb    #'L&137    ,(r0)+        ; /63/ is first byte an "L" ?
  362.     bne    30$            ; /63/ nope..
  363.     cmpb    #'P&137    ,(r0)+        ; /63/ is second byte a "P" ?
  364.     bne    30$            ; /63/ nope..
  365.     cmpb    #':    ,(r0)+        ; /63/ is "LP" followed by a colon?
  366.     bne    30$            ; /63/ no
  367.     tstb    (r0)            ; /63/ ya, but is it null terminated?
  368.     bne    30$            ; /63/ no, user supplied a file name
  369.     strcat    #asname    ,#get2lp    ; /63/ ya, a name is required here
  370. 30$:    calls    printm    ,<#3,#packet,#rec.16,r1> ; /63/ no, display the change
  371.  
  372. 40$:    upcase    r1            ; /BBS/ be sure it's ok for RT-11
  373.     calls    fparse    ,<r1,#filnam>    ; /BBS/ parse and fill in defaults
  374.     clrb    asname            ; /BBS/ one shot for alternate name
  375.     tst    r0            ; /42/ successful parse?
  376.     bne    60$            ; /42/ no
  377.     tst    outopn            ; output already open as if from
  378.     bpl    50$            ; a NAK or something?
  379.     calls    close    ,<#lun.ou>    ; yes, close it please
  380. 50$:    clr    outopn            ; flag it's closed
  381.     spack    #msg$ack,paknum        ; please ACK the file header packet
  382.     clr    numtry            ; and init the current retry count
  383.     incm64    paknum            ; paknum := (paknum+1) mod 64
  384.     movb    #sta.dat,r1        ; return data
  385.     return
  386.  
  387. 60$:    calls    syserr    ,<r0,#errtxt>    ; /42/ no, get the system error text
  388.     calls    error    ,<#3,#errtxt,#aspace,r1> ; /BBS/ include bad name
  389.     jmp    rabort            ; /62/ abort
  390.  
  391.  
  392. rfil.s:    inc    numtry            ; send_init, must have lost ours
  393.     cmp    numtry    ,maxtry        ; tried this too many times?
  394.     blos    10$            ; no
  395.      jmp    r$retry            ; /62/ log the reason for the abort
  396.  
  397. 10$:    mov    paknum    ,r1        ; does this packet=(paknum+63) mod 64?
  398.     dec    r1            ; /62/ if this packet was the one sent
  399.     bge    20$            ; /62/ the last time, we must reACK
  400.     mov    #63    ,r1        ; /62/ that packet and remain
  401. 20$:    cmp    r3    ,r1        ; /62/ in the current state
  402.     bne    30$            ; no
  403.      calls    spar    ,<#packet>    ; ya, reload parameters and
  404.      spack    #msg$ack,r3,sparsz,#packet ; resend our send_init stuff
  405.      jmp    deja$$            ; /62/ warn dupe packet occurred
  406.  
  407. 30$:     jmp    r$sync            ; /62/ log reason for this event
  408.  
  409.  
  410. rfil.x:    cmp    r3    ,paknum        ; "X" packets come here for processing
  411.     beq    10$            ; ensure correct packet number
  412.      jmp    rabort            ; /62/ it wasn't, abort
  413.  
  414. 10$:    mov    sp    ,xmode        ; flag this is an extended reply
  415.     wrtall    #rec.01            ; /63/ do here instead of rem.x
  416.     clr    outlun            ; /63/ not real file, output is to TT
  417.     clr    outopn            ; /63/ nothing is open for output
  418.     calls    open    ,<#0,#lun.kb,#text> ; /63/ init TT output buffer
  419.     mov    #binary    ,image        ; /63/ force 8-bit for remote type..
  420.     tst    r2            ; /62/ length of data in packet buffer
  421.     beq    20$            ; /62/ nothing there
  422.     calls    bufemp    ,<#packet,r2>    ; /63/ unpack repeat encoded chars
  423.     mov    #cr    ,r0        ; /63/ add in a return
  424.     call    putcr0            ; /63/
  425.     mov    #lf    ,r0        ; /63/ and a line feed
  426.     call    putcr0            ; /63/
  427.     calls    close    ,<#lun.kb>    ; /63/ this and the next line are
  428.     calls    open    ,<#0,#lun.kb,#text> ; /63/ for display pacing..
  429. 20$:    spack    #msg$ack,paknum        ; ACK the file name
  430.     clr    numtry            ; and init the current retry count
  431.     incm64    paknum            ; paknum := (paknum+1) mod 64
  432.     movb    #sta.dat,r1        ; return data
  433.     return
  434.  
  435.  
  436. rfil.z:    inc    numtry            ; end-of-file?
  437.     cmp    numtry    ,maxtry        ; tried this too many times?
  438.     blos    10$            ; no
  439.      jmp    r$retry            ; /62/ log the reason for this event
  440.  
  441. 10$:    mov    paknum    ,r1        ; does this packet=(paknum+63) mod 64?
  442.     dec    r1            ; /62/ if this packet was the one sent
  443.     bge    20$            ; /62/ the last time, we must reACK
  444.     mov    #63    ,r1        ; /62/ that packet and remain
  445. 20$:    cmp    r3    ,r1        ; /62/ in the current state
  446.     bne    30$            ; not the last one after all
  447.      jmp    deja$vu            ; /62/ reACK, warn dupe pkt occurred
  448.  
  449. 30$:     jmp    r$retry            ; /62/ log the reason for this please
  450.  
  451.  
  452.     .sbttl    Receive file data
  453.     .enabl    lsb
  454.  
  455. ;    R D A T A
  456. ;
  457. ;    output:    paknum    = packet number
  458. ;        packet    = data just received
  459. ;         r1    = returned state
  460.  
  461. rdata:    inc    numtry            ; abort of retry count is too large
  462.     cmp    numtry    ,maxtry        ; been here too many times?
  463.     blos    10$            ; no
  464.      jmp    r$retry            ; /62/ log/send error message about it
  465.  
  466. 10$:    rpack    r2 ,r3  ,#packet,#maxlng ; /62/ get the next incoming packet
  467.     scan    r1    ,#20$        ; look for the packet type & dispatch
  468.     asl    r0            ; to the correct routine, ie, a crude
  469.     jmp    @30$(r0)        ; /62/ case statement
  470.  
  471.     .save
  472.     .psect    $pdata
  473. 20$:    .byte    msg$atr    ,msg$dat,msg$err,msg$fil,msg$tex,msg$eof
  474.     .byte    timout    ,badchk
  475.     .byte    0
  476.     .even
  477. 30$:    .word    recx.$                        ; /62/
  478.     .word    rdat.a    ,rdat.d    ,recx.e    ,rdat.f    ,rdat.x    ,rdat.z    ; /62/
  479.     .word    recx$$    ,recx$$                    ; /62/
  480.     .restore
  481.  
  482.     .dsabl    lsb
  483.  
  484.  
  485.     .sbttl    Process response to RDATA
  486.  
  487. rdat.a:    cmp    r3    ,paknum        ; case "A"
  488.     beq    40$            ; correct packet number?
  489.     inc    numtry            ; no, see if retry limit expired
  490.     cmp    numtry    ,maxtry        ; if so, return abort
  491.     blos    10$            ; no
  492.      jmp    r$retry            ; /62/ yes, log/send the reason
  493.  
  494. 10$:    mov    paknum    ,r1        ; does this packet=(paknum+63) mod 64?
  495.     dec    r1            ; /62/ if this packet was the one sent
  496.     bge    20$            ; /62/ the last time, we must reACK
  497.     mov    #63    ,r1        ; /62/ that packet and remain
  498. 20$:    cmp    r3    ,r1        ; /62/ in the current state
  499.     bne    30$            ; not the last packet
  500.      jmp    deja$vu            ; /62/ reACK, warn dupe pkt occurred
  501.  
  502. 30$:     jmp    rabort            ; /62/ abort, must be way out of sync
  503.  
  504. 40$:    calls    r$attr    ,<#packet>    ; process the received attributes
  505.     tst    r0            ; was this successful?
  506.     bne    30$            ; /62/ no, bail out
  507.     spack    #msg$ack,paknum        ; ya, ACK it
  508.     clr    numtry            ; numtry := 0
  509.     incm64    paknum            ; increment packet number mod 64
  510.     tst    xmode            ; /63/ doing file I/O?
  511.     bne    50$            ; /63/ no
  512.     tst    at$len            ; /63/ ya, is file possibly empty?
  513.     bne    50$            ; /63/ no
  514.     calls    printm    ,<#4,#rec.13,#rec.10,#filnam,#rec.11> ; /63/ yes
  515. 50$:    movb    state    ,r1        ; retain current state
  516.     return
  517.  
  518.  
  519. rdat.d:    tst    xmode            ; do we need to create the file
  520.     bne    20$            ; no
  521.     tst    outopn            ; did we already open the file?
  522.     bne    20$            ; yes, please don't try again then
  523.     tst    filprot            ; protect existing files?
  524.     beq    30$            ; no
  525.     mov    #filnam    ,r0        ; /63/ pointer to what we'll open
  526.     cmpb    #'L&137    ,(r0)+        ; /63/ is first byte an "L" ?
  527.     bne    10$            ; /63/ nope..
  528.     cmpb    #'P&137    ,(r0)+        ; /63/ is second byte a "P" ?
  529.     bne    10$            ; /63/ nope..
  530.     cmpb    #':    ,(r0)        ; /63/ is "LP" followed by a colon?
  531.     beq    30$            ; /63/ ya, a lookup to LP will hang..
  532. 10$:    clr    index            ; /62/ reset lookup's file counter
  533.     calls    lookup,<#filnam,#srcnam> ; /62/ does file exist already?
  534.     tst    r0            ; /62/ well?
  535.     bne    30$            ; /62/ no
  536.     .purge    #lun.sr            ; /62/ ya, hose dir search channel
  537.     calls    printm    ,<#3,#rec.08,#filnam,#rec.09> ; /62/ ya, say so..
  538.     spack    #msg$ack,paknum,#1,#rec.04 ; /62/ send an ACK with "X" in data
  539.     incm64    paknum            ; increment packet number mod 64
  540.     clr    numtry            ; /48/
  541.     mov    #1    ,outopn        ; never really opened it up
  542.     movb    #sta.dat,r1        ; switch to data state
  543.     return
  544.  
  545. 20$:    br    50$            ; 50$ is otherwise too far away..
  546.  
  547. 30$:    mov    #filnam    ,r4        ; /36/ setup address of file
  548.     calls    create    ,<r4,#lun.ou,image> ; /36/ now create it
  549.     mov    #lun.ou    ,outlun        ; set a real lun for output
  550.     tst    r0            ; did the file create work?
  551.     beq    40$            ; yes
  552.     calls    syserr    ,<r0,#errtxt>    ; no, get the system error text
  553.     calls    error    ,<#3,#errtxt,#aspace,r4> ; /BBS/ add space here
  554.     jmp    rabort            ; /62/ abort
  555.  
  556. 40$:    movb    #'[    ,errtxt        ; /63/ a leading bracket
  557.     mov    #lun.ou    ,r0        ; /63/ the LUN in use here
  558.     asl    r0            ; /63/ word indexing
  559.     mov    sizof(r0),r0        ; /63/ recover the file size
  560.     mov    #errtxt+1,r1        ; /63/ start writing size here
  561.     call    L10012            ; /63/ convert size to ascii
  562.     movb    #']    ,(r1)+        ; /63/ a terminating bracket
  563.     clrb    (r1)            ; /63/ terminate the size string
  564.     mov    image    ,r1        ; /63/ recover current file-type
  565.     asl    r1            ; /63/ word indexing
  566.     mov    fillst(r1),r1        ; /63/ point to its description
  567.     calls    printm    ,<#5,#rec.06,r1,#rec.07,r4,#errtxt> ; /63/ log to term
  568.     mov    #-1    ,outopn        ; flag output as being open
  569.  
  570. 50$:    cmp    r3    ,paknum        ; case "D"
  571.     beq    90$            ; correct packet number?
  572.     inc    numtry            ; no, see if retry limit expired
  573.     cmp    numtry    ,maxtry        ; if so, return abort
  574.     blos    60$            ; no
  575.      jmp    r$retry            ; /62/ log/send notice of error
  576.  
  577. 60$:    mov    paknum    ,r1        ; does this packet=(paknum+63) mod 64?
  578.     dec    r1            ; /62/ if this packet was the one sent
  579.     bge    70$            ; /62/ the last time, we must reACK
  580.     mov    #63    ,r1        ; /62/ that packet and remain
  581. 70$:    cmp    r3    ,r1        ; /62/ in the current state
  582.     bne    80$            ; not the last packet
  583.      jmp    deja$vu            ; /62/ reACK, warn dupe pkt occurred
  584.  
  585. 80$:     jmp    r$sync            ; /62/ log/send the reason for abort
  586.  
  587. 90$:    add    r2    ,charin+2    ; /43/ stats
  588.     adc    charin+0        ; /43/ in 32. bits please
  589.     calls    bufemp    ,<#packet,r2>    ; correct packet, get the data out
  590.     tst    r0            ; did bufemp return any errors?
  591.     beq    100$            ; no
  592.     calls    syserr    ,<r0,#errtxt>    ; ya, lookup error msg text
  593.     calls    error    ,<#1,#errtxt>    ; send error packet or display err msg
  594.     jmp    180$            ; /62/ take the abort exit please
  595.  
  596. 100$:    tst    xmode            ; /62/ amidst an extended reply?
  597.     beq    110$            ; /62/ no
  598.     mov    trace    ,r1        ; /62/ copy of debug status word
  599.     bic    #^c<log$de!log$rp>,r1    ; /62/ hose all except TT options
  600.     beq    110$            ; /62/ not now debugging to terminal
  601.     .newline            ; /62/ using TT, put next in the clear
  602. 110$:    tst    remote            ; are we a local Kermit today?
  603.     bne    150$            ; no, just ACK normally
  604.     tst    cccnt            ; we are local. check for control
  605.     bne    170$            ; c abort for this file please
  606.     call    chkabo            ; check for abort via ^X and ^Z
  607.     cmpb    r0    ,#abt$err&37    ; ^E aborts NOW
  608.     beq    170$            ; yes, abort please
  609.     cmpb    r0    ,#abt$all&37    ; did the user type a ^Z?
  610.     beq    130$            ; yes
  611.     cmpb    r0    ,#abt$cur&37    ; no, what about a ^X then?
  612.     beq    120$            ; /56/ yes
  613.     cmpb    r0    ,#'A&37        ; /56/ ^A stats?
  614.     bne    150$            ; /56/ no
  615.     tst    xmode            ; /BBS/ don't do this
  616.     bne    150$            ; /BBS/ within an extended reply
  617.     call    cs$in            ; /56/ yes, print stats
  618.     br    150$            ; /56/ and exit
  619.  
  620. 120$:    spack    #msg$ack,paknum,#1,#rec.04 ; /62/ ^X typed, send "X" in data
  621.     br    140$
  622. 130$:    spack    #msg$ack,paknum,#1,#rec.05 ; /62/ ^Z typed, ACK with "Z" data
  623. 140$:    tst    xmode            ; /BBS/ is an output file open?
  624.     bne    160$            ; /BBS/ no..
  625.     mov    incfile    ,skipfile    ; /BBS/ pass desired incomplete file
  626.     br    160$            ; /BBS/ disposition to file closer
  627.  
  628. 150$:    spack    #msg$ack,paknum        ; ACK it
  629. 160$:    clr    numtry            ; numtry := 0
  630.     incm64    paknum            ; increment packet number mod 64
  631.     movb    #sta.dat,r1        ; switch to data state
  632.     return
  633.  
  634. 170$:    spack    #msg$err,paknum        ; break the sender out please
  635.     clr    cccnt            ; /36/ clear ^C flag
  636. 180$:    mov    #sta.abo,r1        ; abort for some reason
  637.     return
  638.  
  639.  
  640. rdat.f:                    ; "F", got a file header
  641. rdat.x:                    ; "X", also handle extended reply
  642.     inc    numtry            ; see if retry limit expired
  643.     cmp    numtry    ,maxtry        ; if so, return abort
  644.     blos    10$            ; no
  645.      jmp    r$retry            ; /62/ yes, log/send the reason
  646.  
  647. 10$:    mov    paknum    ,r1        ; does this packet=(paknum+63) mod 64?
  648.     dec    r1            ; /62/ if this packet was the one sent
  649.     bge    20$            ; /62/ the last time, we must reACK
  650.     mov    #63    ,r1        ; /62/ that packet and remain
  651. 20$:    cmp    r3    ,r1        ; /62/ in the current state
  652.     bne    30$            ; not the last packet
  653.      jmp    deja$vu            ; /62/ reACK, warn dupe pack occurred
  654.  
  655. 30$:     jmp    r$sync            ; /62/ log/send the reason for abort
  656.  
  657.  
  658. rdat.z:    cmp    paknum    ,r3        ; end-of-file
  659.     beq    10$            ; if not correct packet return abort
  660.      jmp    r$sync            ; /62/ log/send the reason for abort
  661.  
  662. 10$:    mov    #lun.ou    ,r2        ; assume that we close a disk file
  663.     tst    outopn            ; real output or to the terminal
  664.     beq    20$            ; /BBS/ must be the terminal
  665.     bgt    40$            ; open was aborted via fileprotection
  666.  
  667.     cmpb    #eof$dis,packet        ; /BBS/ real file, other side discard?
  668.     bne    30$            ; /BBS/ no
  669.     mov    incfile    ,skipfile    ; /BBS/ ya, keep or dump it as is SET
  670.     br    30$
  671.  
  672. 20$:    clr    r2            ; it's the console terminal
  673. 30$:    calls    close    ,<r2>        ; do the close now
  674. 40$:    call    clratr            ; attributes no longer valid
  675.     clr    outopn            ; flag it
  676.     spack    #msg$ack,r3        ; ACK the EOF packet
  677.     clr    numtry            ; /48/ then re-init retry counter
  678.     incm64    paknum            ; paknum := (paknum+1) mod 64
  679.     movb    #sta.fil,r1        ; back to receive file state
  680.     clr    xgottn            ; don't have an X packet anymore
  681.     return
  682.  
  683.  
  684.     .sbttl    Dump a buffer out to disk    ; /62/ moved this here..
  685.  
  686. ;    B U F E M P
  687. ;
  688. ;    input:      (r5)    = buffer address
  689. ;         2(r5)    = length
  690. ;    output:       r0    = if <>, error code
  691. ;
  692. ; /63/    NOTE:  This routine can, as it now exists, can process all unprefixed
  693. ;    control chars as C-Kermit 5A(189) might emit if given the command SET
  694. ;    CONTROL UNPREFIX ALL.  The NULL char is used as the record terminator
  695. ;    here and thus MUST be prefixed.  Kermit always prefixes nulls.
  696.  
  697. bufemp:    mov    @r5    ,r2        ; input record address
  698.     mov    2(r5)    ,r3        ; string length
  699.     clr    r0            ; ensure no error for a null packet
  700.  
  701. 10$:    tst    r3            ; anything left in the record?
  702.     ble    100$            ; no
  703.     clr    r0            ; get the next character
  704.     bisb    (r2)+    ,r0        ; into a convenient place
  705.     dec    r3            ; chcount--
  706.  
  707.     mov    #1    ,r4        ; repeat_count = 1
  708.     tst    dorpt            ; are we doing repeat count stuff?
  709.     beq    20$            ; no
  710.     cmpb    r0    ,rptquo        ; yes, is it the agreed upon prefix?
  711.     bne    20$            ; no
  712.     movb    (r2)+    ,r4        ; /63/ yes, get next character
  713.     dec    r3            ; chcount--
  714.     bic    #^c<177>,r4        ; hose possible parity and sxt bits
  715.     unchar    r4    ,r4        ; decode it into a number
  716.     clr    r0            ; now prime with the next character
  717.     bisb    (r2)+    ,r0        ; so we can check for other types of
  718.     dec    r3            ; quoting to be done
  719.     tst    r4            ; ensure the count is legitimate
  720.     bgt    20$            ; it's ok
  721.     mov    #1    ,r4        ; it's fubar, fix it (more or less..)
  722.  
  723. 20$:    clr    set8bit            ; assume we don't have to set bit 7
  724.     tst    do8bit            ; must we do 8-bit unprefixing?
  725.     beq    30$            ; no
  726.     cmpb    r0    ,ebquot        ; yes, is this the 8-bit prefix?
  727.     bne    30$            ; no
  728.     mov    sp    ,set8bit    ; yes, send a flag to set the bit
  729.     clr    r0            ; and get the next character
  730.     bisb    (r2)+    ,r0        ; without sign extension
  731.     dec    r3            ; one less character left in buffer
  732.  
  733. 30$:    cmpb    r0    ,conpar+p.qctl    ; is this a quoted control character?
  734.     bne    40$            ; no
  735.     clr    r0            ; yes, get the next character
  736.     bisb    (r2)+    ,r0        ; must be one you know
  737.     dec    r3            ; chcount := pred(chcount)
  738.     mov    r0    ,r1        ; /63/ copy to check against quote ch
  739.     bic    #^c<177>,r1        ; must avoid sxt here, drop bits 7..15
  740.     cmpb    r1    ,conpar+p.qctl    ; if ch <> myquote
  741.     beq    40$            ;  then
  742.     cmpb    r1    ,#77        ;   if   (ch & 177) >= ctl(del)
  743.     blo    40$            ;    and (ch & 177) <= ctl(del)+40
  744.     cmpb    r1    ,#137        ;    then
  745.     bhi    40$            ;      ch = ctl(ch)
  746.     ctl    r0    ,r0
  747.  
  748. 40$:    tst    set8bit            ; do we need to set the high bit?
  749.     beq    50$            ; no
  750.     bisb    #200    ,r0        ; yes, set the bit on please
  751. 50$:    mov    r0    ,-(sp)        ; save copy of char to output
  752. 60$:    mov    #lun.ou    ,r1        ; channel_number := lun.out
  753.     tst    outopn            ; is there really something open?
  754.     bne    70$            ; yes, put the data to it
  755.     clr    r1            ; no, direct the output to a terminal
  756.     tst    tsxsav            ; running under TSX?
  757.     beq    70$            ; no
  758.     cmpb    @sp    ,m.tsxr        ; ya, is it TSX lead-in char?
  759.     beq    80$            ; ya, don't output to TT
  760. 70$:    mov    @sp    ,r0        ; restore the character to write out
  761.     call    putcr0            ; and do it
  762.     tst    r0            ; /62/ did it work?
  763.     beq    80$            ; /63/ yes
  764.     clr    r3            ; /63/ no, fake end of string to force
  765.     br    90$            ; /63/ exit and bail out of this loop
  766. 80$:    add    #1    ,filein+2    ; stats /62/ r0 is clear in case end..
  767.     adc    filein+0        ; 32. bits worth
  768.     sob    r4    ,60$        ; duplicate the character if need be
  769. 90$:    tst    (sp)+            ; pop the stack where we saved char
  770.     br    10$            ; next character please
  771.  
  772. 100$:    return
  773.  
  774.     .end
  775.