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

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