home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / pdp11 / k11rec.mac < prev    next >
Text File  |  2020-01-01  |  21KB  |  757 lines

  1.     .title    K11REC    recieve processing
  2.     .ident    /T2.23/
  3.  
  4.  
  5.     .if ndf, K11INC
  6.     .ift
  7.     .include    /IN:K11MAC.MAC/
  8.     .include    /IN:K11DEF.MAC/
  9.     .endc
  10.  
  11.     .psect
  12.     .enabl    gbl
  13.  
  14. ;    13-Oct-84  14:06:43  Brian Nelson
  15. ;
  16. ;    Creation: Moved from K11PAK
  17. ;
  18. ;
  19. ;    Copyright (C) 1983 1984   Change Software, Inc.
  20. ;    
  21. ;    
  22. ;    This software is furnished under a license and may
  23. ;    be  used  and  copied  only in accordance with the
  24. ;    terms of such license and with  the  inclusion  of
  25. ;    the  above copyright notice.  This software or any
  26. ;    other copies thereof may not be provided or other-
  27. ;    wise made available to any other person.  No title
  28. ;    to and ownership of the software is hereby  trans-
  29. ;    ferred.
  30. ;    
  31. ;    The information in this  software  is  subject  to
  32. ;    change  without notice and should not be construed
  33. ;    as a commitment by the author.
  34. ;
  35. ;
  36.     .sbttl    recsw    state table controller for receiving files
  37.     .enabl    lsb
  38.  
  39. recsw::    clr    paknum            ; packet_number := 0
  40. rec.sw::movb    @r5    ,state        ; assume RECEIVE-INIT for starters
  41.     clr    cccnt            ; control_c_count := 0
  42.     mov    $image    ,image        ; insure correct default for mode
  43.     movb    #defchk    ,chktyp        ; reset checksum type to default
  44.     mov    #1    ,chksiz        ; the size of the checksum
  45.     clr    numtry            ; number_trys   := 0
  46.     clr    oldtry            ; 
  47.     add    pcnt.r+2,reccnt+2    ; /43/ Save rec packet count
  48.     adc    reccnt+0        ; /43/ 32 bits today
  49.     add    pcnt.r+0,reccnt+0    ; /43/ 32 bits in the total
  50.     call    clrsta            ; clear the stats out now
  51.     clr    outopn            ; say nothing is open now
  52.     tst    remote            ; local or remote
  53.     bne    5$            ; remote
  54.     call    ttrini            ; perhaps special init for local tt:
  55. 5$:    call    rechdr
  56.     call    incsta            ; /43/ Timer stats init
  57.  
  58. 10$:    call    recdeb            ; perhaps debugging should be done
  59.     cmp    incpar    ,#1        ; /56/ Is it possible that parity
  60.     bne    15$            ; /56/ is messed up?
  61.     CALLS    printm    ,<#1,#300$>    ; /56/ Warn, but only once
  62. 15$:    tst    remote            ; /43/ Control C and a server?
  63.     bne    20$            ; /43/ Yep, ignore random noise.
  64.     tst    cccnt            ; /36/ control C abort ?
  65.     beq    20$            ; /36/ no
  66.     movb    #STA.CCABO,state    ; /36/ yes, enter ABORT state
  67. 20$:    scan    state    ,#200$        ; case state of
  68.     asl    r0            ; dispatch to correct routine
  69.     jsr    pc    ,@210$(r0)
  70.     bcc    10$
  71.  
  72.  
  73. 100$:    movb    #defchk    ,chktyp        ; reset type of checksum to 1
  74.     mov    #1    ,chksiz        ; the size of the checksum
  75.     save    <r0>            ; insure files are closed
  76.     tst    remote            ; remote or local
  77.     bne    105$            ; remote
  78.     call    ttrfin            ; local, perhaps clean up console
  79. 105$:    tst    outopn            ; file open from a failure ?
  80.     bpl    110$            ; no
  81.     calls    close    ,<#lun.ou>    ; insure that it's closed
  82. 110$:    clr    outopn
  83.     call    incsta            ; /43/ Timer stats init
  84.     unsave    <r0>            ; pop exit status code please
  85.     return
  86.  
  87.     .save
  88.     .psect    $PDATA    ,D
  89. 200$:    .byte    STA.RIN    ,STA.FIL,STA.DAT,STA.COM,STA.ABO,STA.CCABO,0
  90.     .even
  91. 210$:    .word    recs.$
  92.     .word    recs.r    ,recs.f    ,recs.d    ,recs.c    ,recs.a, ccabort
  93.  
  94. 300$:    .asciz    / Warning: Parity possibly being used by sender./
  95.     .even
  96.     .restore
  97.     .dsabl    lsb
  98.  
  99.  
  100.  
  101. recs.$:    clc                ; Unknown state
  102.     return                ; back to caller
  103.  
  104. recs.r:    call    rinit            ; receive-init
  105.     movb    r1    ,state        ; set state and exit
  106.     clc                ; saying there is more to come
  107.     return                ; bye
  108.  
  109. recs.f:    call    rfile            ; receive-file
  110.     movb    r1    ,state
  111.     clc
  112.     return
  113.  
  114. recs.d:    call    rdata            ; receive-data
  115.     movb    r1    ,state
  116.     clc
  117.     return
  118.  
  119. recs.c:    clr    r0            ; complete
  120.     sec
  121.     return
  122.  
  123. ccabort:strlen    #ccmsg0            ; /43/ Send msg text over
  124.     spack    #MSG$ERROR,paknum,r0,#ccmsg0 ; /36/ break out the sender please
  125. recs.a:    mov    sp    ,r0        ; abort
  126.     sec
  127.     return
  128.  
  129.     .save
  130.     .psect    $PDATA    ,D
  131. ccmsg0:    .asciz    /Control C abort on file receive/
  132.     .even
  133.     .restore
  134.  
  135.     global    <cccnt    ,chktyp    ,outopn    ,remote    ,state    ,ttrfin    ,ttrini>
  136.     global    <incpar>
  137.  
  138.  
  139.  
  140.     .sbttl    debugging and logging for receive
  141.     .enabl    lsb
  142.  
  143.  
  144. recdeb:    save    <r1,r2>
  145.     sub    #50    ,sp
  146.     mov    sp    ,r1        ; allocate a small buffer
  147.     mov    #200$    ,r2        ; point to a header
  148. 10$:    movb    (r2)+    ,(r1)+        ; copy a header please
  149.     bne    10$            ; until we find a null
  150.     dec    r1            ; all done
  151.     movb    state    ,(r1)+        ; copy the current state over
  152.     movb    #40    ,(r1)+        ;
  153.     sub    sp    ,r1        ; get the record length
  154.     mov    sp    ,r0        ; and point back to the record
  155.     bit    #log$st    ,trace        ; debugging for RECSW
  156.     beq    30$            ; if trace is on then dump the
  157.     calls    putrec    ,<r0,r1,#lun.lo>; dump it
  158. 30$:    tst    debug            ; terminal debugging on ?
  159.     beq    40$            ; no
  160.     print    r0    ,r1
  161.     .newli                ; and a crlf
  162.  
  163. 40$:    tst    remote            ; running locally ?
  164.     bne    100$            ; no
  165.     tst    xmode            ; simply printing text to ti: ?
  166.     bne    100$            ; yes, skip the packet stats then
  167.     call    reclog
  168.     
  169. 100$:    add    #50    ,sp
  170.     unsave    <r2,r1>
  171.     return
  172.  
  173.     .save
  174.     .psect    $PDATA
  175. 200$:    .asciz    /Recsw - state is /
  176.     .even
  177.     .restore
  178.     .dsabl    lsb
  179.  
  180.     global    <reccnt    ,pcnt.r    ,pcnt.s    ,state    ,trace    ,xmode>
  181.  
  182.  
  183.     .sbttl    rinit    receive initialization
  184.  
  185.  
  186. ;    R I N I T
  187. ;
  188. ;    input:    nothing
  189.  
  190.     .enabl    lsb
  191.  
  192. rinit:    save    <r2,r3,r4>        ; get registers we use saved
  193.     inc    numtry            ; check for retry count
  194.     cmp    numtry    ,maxtry        ; been here too often ?
  195.     blos    10$            ; no
  196.      call    m$retry            ; log/send the reason for the abort
  197.      movb    #STA.ABO,r1        ; yes, return ABORT state
  198.      br    100$
  199.  
  200.  
  201. 10$:    rpack    r2,r3,#packet        ; get the next packet please
  202.     scan    r1,#200$        ; look for the packet type
  203.     asl    r0            ; and dispatch to it
  204.     jsr    pc    ,@210$(r0)    ; simple
  205. 100$:    unsave    <r4,r3,r2>
  206.     return
  207.  
  208.     .save
  209.     .psect    $PDATA
  210. 200$:    .byte    MSG$SND    ,MSG$ERROR,TIMOUT,BADCHK,0
  211.     .even
  212. 210$:    .word    rini.$
  213.     .word    rini.S    ,rini.E    ,rini$$    ,rini$$
  214.     .restore
  215.     .dsabl    lsb
  216.  
  217.  
  218. rini.$:                    ; unknown packet type
  219. rini$$:    spack    #MSG$NAK,paknum        ; error, send a NAK
  220.     movb    state    ,r1        ; and exit
  221.     return
  222.  
  223. rini.e:    calls    prerrp    ,<#packet>
  224.     movb    #STA.ABO,r1
  225.     return
  226.  
  227. rini.s:    calls    rpar    ,<#packet,r2>    ; SEND-INIT
  228.     calls    spar    ,<#packet>    ; get other sides init and fill with
  229.     spack    #MSG$ACK,paknum,sparsz,#packet; ours
  230.     mov    numtry    ,oldtry
  231.     clr    numtry
  232.     incm64    paknum            ; paknum := (paknum+1) mod 64
  233.     call    inirepeat        ; initialize repeat processing
  234.     movb    #STA.FIL,r1        ; state  := FILE-RECEIVE
  235.     return
  236.  
  237.  
  238.  
  239.     .sbttl    rfile    receive file header
  240.     .enabl    lsb
  241.  
  242.  
  243. rfile:    save    <r2,r3,r4>        ; get registers we use saved
  244.     call    clratr            ; insure attribute stuff is cleared
  245.     movb    conpar+p.chkt,chktyp    ; time to use new checksum ?
  246.     movb    chktyp    ,chksiz        ; compute the checksum size also
  247.     sub    #'0    ,chksiz        ; simple
  248.     mov    $image    ,image        ; insure correct default for mode
  249.     inc    numtry            ; check for retry count
  250.     cmp    numtry    ,maxtry        ; been here too often ?
  251.     blos    5$            ; no
  252.      call    m$retry            ; log why we aborted please
  253.      movb    #STA.ABO,r1        ; yes, return ABORT state
  254.      br    100$
  255. 5$:    tst    xgottn            ; already get the x packet ?
  256.     beq    10$            ; no
  257.     movb    #STA.TYP,r1        ; yes, fake that we already got it
  258.     br    20$
  259.  
  260.  
  261. 10$:    rpack    r2,r3,#packet        ; get the next packet please
  262. 20$:    scan    r1,#200$        ; look for the packet type
  263.     asl    r0            ; and dispatch to it
  264.     jsr    pc    ,@210$(r0)    ; simple
  265. 100$:    unsave    <r4,r3,r2>
  266.     return
  267.  
  268.  
  269.     .save
  270.     .psect    $PDATA
  271. 200$:    .byte    MSG$SND    ,MSG$EOF,MSG$FILE,MSG$BREAK,MSG$ERROR,MSG$TEXT
  272.     .byte    timout    ,badchk    ,0
  273.     .even
  274.  
  275. 210$:    .word    rfil.$
  276.     .word    rfil.s    ,rfil.z    ,rfil.f    ,rfil.b    ,rfil.e    ,rfil.x
  277.     .word    rfil$$    ,rfil$$
  278.     .restore
  279.     .dsabl    lsb
  280.  
  281.  
  282.  
  283.     .sbttl    more rfile
  284.  
  285.  
  286.  
  287. rfil.$:                    ; unknow packet type
  288. rfil$$:    spack    #MSG$NAK,paknum        ; timeout or checksum error, send
  289.     movb    state    ,r1        ; NAK and continue in current state
  290.     return
  291.  
  292.  
  293. rfil.b:    cmp    r3    ,paknum        ; Break XMIT (EOT)
  294.     beq    10$            ; insure BREAK is for current packet
  295.      call    m$synch            ; for abort, say we are out of synch
  296.      movb    #STA.ABO,r1        ; no, return 'ABORT"
  297.      return                ; exit
  298.  
  299.  
  300. 10$:    spack    #MSG$ACK,paknum        ; ACK the BREAK
  301.     movb    #STA.COM,r1        ; and return state as 'COMPLETE'
  302.     return
  303.  
  304.  
  305. rfil.e:    calls    prerrp    ,<#packet>    ; error packet, print it out
  306.     movb    #STA.ABO,r1        ; return 'ABORT'
  307.     return
  308.  
  309.  
  310. rfil.s:    inc    oldtry            ; SEND-INIT, must have lost ours
  311.     cmp    oldtry    ,maxtry        ; tried this too many times ?
  312.     blos    10$            ; no
  313.      call    m$retry            ; log the reason for the abort
  314.      movb    #STA.ABO,r1        ; yes, return 'ABORT'
  315.      return
  316.  
  317. 10$:    mov    paknum    ,r1        ; see if thispacket=(paknum+63) mod 64
  318.     add    #77    ,r1        ; ie, check if this data packet was the
  319.     clr    r0            ; one sent the last time. if so, we
  320.     div    #100    ,r0        ; must reack that packet and remain
  321.     clr    r0            ; in the current state.
  322.     cmp    r3    ,r1        ; 
  323.     bne    20$            ; no
  324.      calls    spar    ,<#packet>    ; resend our SEND-INIT stuff
  325.      spack    #MSG$ACK,r3,sparsz,#packet ; reack this then
  326.  
  327.      clr    numtry            ; clear out retry counter
  328.      movb    state    ,r1        ; and return current state
  329.      return
  330.  
  331. 20$:     call    m$synch            ; log the reason for this event please
  332.      movb    #STA.ABO,r1        ; otherwise return ABORT since we must
  333.      return                ; be way out of synch then.
  334.  
  335. rfil.z:    inc    oldtry            ; END-OF-FILE ?
  336.     cmp    oldtry    ,maxtry        ; tried this too many times ?
  337.     blos    10$            ; no
  338.      call    m$retry            ; log the reason for this event
  339.      movb    #STA.ABO,r1        ; yes, return 'ABORT'
  340.      return
  341.  
  342. 10$:    mov    paknum    ,r1        ; see if thispacket=(paknum+63) mod 64
  343.     add    #77    ,r1        ; ie, check if this data packet was the
  344.     clr    r0            ; one sent the last time. if so, we
  345.     div    #100    ,r0        ; must reack that packet and remain
  346.     clr    r0            ; in the current state.
  347.     cmp    r3    ,r1        ; 
  348.     bne    20$            ; not the last one after all
  349.      spack    #MSG$ACK,r3        ; reack this then
  350.      clr    numtry            ; clear out retry counter
  351.      movb    state    ,r1        ; and return current state
  352.      return
  353.  
  354. 20$:     call    m$retry            ; log the reason for this please
  355.      movb    #STA.ABO,r1        ; otherwise return ABORT since we must
  356.      return                ; be way out of synch then.
  357.  
  358.  
  359.  
  360.  
  361.     .sbttl    more rfile subroutines
  362.     .enabl    lsb
  363.  
  364. ;    Move the actual file create to RDATA so we can create
  365. ;    the output file after all attribute packets have come.
  366. ;    Thus, when we get the first DATA packet is when we go
  367. ;    and create the file.
  368. ;
  369. ;    18-Apr-84  10:24:45  Brian Nelson
  370.  
  371.  
  372.  
  373. rfil.f:    cmp    r3    ,paknum        ; FILE name
  374.     beq    10$            ; insure correct packet numer
  375.      call    m$synch            ; log the reason for this ABORT
  376.      movb    #STA.ABO,r1        ; no, return 'ABORT'
  377.      return                ; bye
  378.  
  379. 10$:    STRCPY    #srcnam    ,#packet    ; /53/ Temp copy
  380.     calls    bufunp    ,<#srcnam,#packet>; /53/
  381.     clrb    packet(r1)        ; /53/ Insure .asciz
  382.     calls    fixfil    ,<#packet,#srcnam>; check for invalid chars
  383.     tst    r0            ; was the filname ok ?
  384.     beq    15$            ; yes
  385.     calls    printm    ,<#3,#packet,#200$,#srcnam>
  386. 15$:    calls    fparse    ,<#srcnam,#filnam>; parse and fill in defaults
  387.     tst    r0            ; /42/ Successful $PARSE?
  388.     bne    100$            ; /42/ No
  389.     tst    outopn            ; output already open as if from
  390.     bpl    20$            ; a NAK or something
  391.     calls    close    ,<#lun.ou>    ; yes, close it please
  392. 20$:    clr    outopn            ; it's closed
  393.     spack    #MSG$ACK,paknum        ; please ack the fileheader packet
  394.     mov    numtry    ,oldtry        ; update number of retrys
  395.     clr    numtry            ; and init the current retry count
  396.     incm64    paknum            ; paknum := (paknum+1) mod 64
  397.     movb    #STA.DAT,r1        ; return 'DATA'
  398.     return
  399.  
  400. 100$:    calls    syserr    ,<r0,#errtxt>    ; /42/ no, get the system error text
  401.     calls    error    ,<#3,#230$,#errtxt,r4> /42/
  402.     movb    #STA.ABO,r1        ; /42/ return 'ABORT'
  403.     return
  404.  
  405.  
  406.     .save
  407.     .psect    $PDATA
  408. 200$:    .asciz    / was renamed to /
  409. 230$:    .asciz    /RMS $PARSE failed /    ; /42/
  410.     .even
  411.     .restore
  412.     .dsabl    lsb
  413.  
  414.  
  415. rfil.x:    cmp    r3    ,paknum        ; X header name
  416.     beq    10$            ; insure correct packet numer
  417.      movb    #STA.ABO,r1        ; no, return 'ABORT'
  418.      return                ; bye
  419. 10$:    spack    #MSG$ACK,paknum        ; ACK the filename
  420.     clr    outlun            ; not a real file to output to
  421.     clr    outopn            ; nothing is open for output
  422.     mov    sp    ,xmode        ; flag this also please
  423.     MESSAGE                ; /54/ Dump a CRLF
  424.     mov    numtry    ,oldtry        ; update number of retrys
  425.     clr    numtry            ; and init the current retry count
  426.     incm64    paknum            ; paknum := (paknum+1) mod 64
  427.     movb    #STA.DAT,r1        ; return 'DATA'
  428.     return
  429.  
  430.  
  431.     global    <filnam    ,errtxt    ,numtry    ,oldtry    ,packet    ,paknum>
  432.     global    <outlun>
  433.  
  434.  
  435.  
  436.     .sbttl    rdata    receive data from pc
  437.     .enabl    lsb
  438.  
  439. ;    R D A T A
  440. ;
  441. ;    input:    nothing
  442. ;    output:    global    paknum    packet number
  443. ;            oldtry    retry count
  444. ;            packet    packet just received
  445. ;            numtry
  446. ;        r1    returned state
  447.  
  448.  
  449.  
  450.  
  451. rdata:    save    <r2,r3,r4>
  452.     clr    datauk            ; /43/ Unknown/out synch NAK count
  453.     clr    r0            ; error := 0
  454.     inc    numtry            ; abort of retry count is too large
  455.     cmp    numtry    ,maxtry        ; been here too many times ?
  456.     blos    10$            ; no
  457.     call    m$retry            ; log/send error message about it
  458.     movb    #STA.ABO,r1        ; yes, return state(abort)
  459.     br    100$            ; bye
  460.  
  461. 10$:    rpack    r2,r3,#packet        ; get the next imcoming packet
  462.     scan    r1    ,#200$        ; look for the packet type and dispatch
  463.     asl    r0            ; to the correct routine. ie, a crude
  464.     jsr    pc    ,@210$(r0)    ; case statement
  465. 100$:    unsave    <r4,r3,r2>
  466.     return
  467.  
  468.  
  469.     .save
  470.     .psect    $PDATA
  471. 200$:    .byte    MSG$ATR    ,MSG$DATA,MSG$ERROR,MSG$FILE,MSG$EOF,MSG$TEXT
  472.     .byte    timout    ,badchk    ,0
  473.     .even
  474. 210$:    .word    rdat.$
  475.     .word    rdat.a    ,rdat.d    ,rdat.e    ,rdat.f    ,rdat.z    ,rdat.x
  476.     .word    rdat$$    ,rdat$$
  477.     .restore
  478.     .dsabl    lsb
  479.  
  480.  
  481.     global    <numtry    ,oldtry    ,packet    ,paknum    ,state    >
  482.  
  483.     .sbttl    rdata packet handlers
  484.     .enabl    lsb
  485.  
  486.  
  487.  
  488. rdat.d:    tst    xmode            ; do we need to create the file
  489.     bne    1$            ; no
  490.     tst    outopn            ; did we already open the file up?
  491.     bne    1$            ; yes, please don't try again then.
  492.     tst    filprot            ; no supercede on file creates ?
  493.     beq    2$            ; no
  494.     clr    -(sp)            ; yes, check for the file already
  495.     mov    sp    ,r0        ; there please
  496.     calls    lookup    ,<#3,#filnam,r0,#srcnam>
  497.     tst    (sp)+            ; pop context for lookup
  498.     tst    r0            ; did we find the file today?
  499.     bne    2$            ; no
  500.     calls    printm    ,<#2,#250$,#filnam>
  501.     spack    #MSG$ACK,paknum,#1,#220$; yes, send ack with X in data
  502.     incm64    paknum            ; increment packet number mod 64
  503.     clr    numtry            ; /48/
  504.     mov    #1    ,outopn        ; never really opened it up
  505.     movb    #STA.DAT,r1        ; switch to data state
  506.     return                ; bye
  507.  
  508. 1$:    br    10$
  509.  
  510. 2$:    mov    #filnam    ,r4        ; /36/ setup address of file
  511.     tstb    asname            ; /36/ use alternate name for file?
  512.     beq    3$            ; /36/ nothing there
  513.     calls    fparse    ,<#asname,r4>    ; /37/ insure defaults are inserted
  514.     tst    r0            ; /37/ is parse successful
  515.     bne    4$            ; /37/ no, exit
  516. 3$:    calls    create    ,<r4,#lun.ou,image>; /36/ now create it
  517.     clrb    asname            ; /36/ one shot for alternate name
  518.     mov    #lun.ou    ,outlun        ; set a real LUN for output
  519.     tst    r0            ; did the file create work ?
  520.     beq    5$            ; yes
  521. 4$:    calls    syserr    ,<r0,#errtxt>    ; no, get the system error text
  522.     tst    remote            ; /51/ Are we LOCAL or Remote
  523.     bne    444$            ; /51/ We must be the server
  524.     strlen    #errtxt            ; /51/ We are local, get the
  525.     spack    #MSG$ERR,paknum,r0,#errtxt ; /51/ Other side to STOP.
  526. 444$:    calls    error    ,<#3,#230$,#errtxt,r4> /36/
  527.     movb    #STA.ABO,r1        ; return 'ABORT'
  528.     return
  529.  
  530.  
  531. 5$:    calls    fillog    ,<#0,r4>    ; /36/ log to disk perhaps ?
  532.     calls    printm    ,<#2,#240$,r4>    ; /36/ log to terminal perhaps?
  533.     mov    #-1    ,outopn        ; flag output as being open
  534.  
  535. 10$:    cmp    r3    ,paknum        ; case "D"
  536.     beq    40$            ; Correct packet number ?
  537.     inc    oldtry            ; no, see if retry limit expired
  538.     cmp    oldtry    ,maxtry        ; if so, return ABORT
  539.     blos    20$            ; no
  540.      call    m$retry            ; log/send notice of what happened
  541.      movb    #STA.ABO,r1        ; yes, return 'ABORT'
  542.      return                ; bye
  543.  
  544. 20$:    mov    paknum    ,r1        ; see if thispacket=(paknum+63) mod 64
  545.     add    #77    ,r1        ; ie, check if this data packet was the
  546.     clr    r0            ; one sent the last time. if so, we
  547.     div    #100    ,r0        ; must reack that packet and remain
  548.     clr    r0            ; in the current state.
  549.     cmp    r3    ,r1        ; insure r0 is not affected
  550.     bne    30$            ; not the last packet
  551.      spack    #MSG$ACK,r3        ; reack this then
  552.      clr    numtry            ; clear out retry counter
  553.      movb    state    ,r1        ; and return current state
  554.      return
  555.  
  556. 30$:     call    m$synch            ; log/send the reason for the abort
  557.      movb    #STA.ABO,r1        ; otherwise return ABORT since we must
  558.      return                ; be way out of synch then.
  559.  
  560.  
  561. 40$:    add    r2    ,charin+2    ; /43/ Stats
  562.     adc    charin+0        ; /43/ In 32 bits please
  563.     calls    bufemp    ,<#packet,r2>    ; correct packet, get the data out
  564.     tst    r0            ; did BUFEMP return any errors?
  565.     beq    41$            ; no
  566.     calls    syserr    ,<r0,#errtxt>    ; it failed, send error packet
  567.     calls    error    ,<#2,#200$,#errtxt>
  568.     br    100$            ; take the abort exit please
  569.  
  570. 41$:    tst    remote            ; are we a local kermit today ?
  571.     bne    70$            ; no, just ack normally
  572.     tst    cccnt            ; we are local. check for control
  573.     bne    60$            ; c abort for this file please
  574.     call    chkabo            ; check for abort via ^X and ^Z
  575.     cmpb    r0    ,#ABT$ERROR&37    ; control E aborts NOW
  576.     beq    60$            ; yes, abort please
  577.     cmpb    r0    ,#ABT$ALL&37    ; did the user type a control Z?
  578.     beq    50$            ; yes
  579.     cmpb    r0    ,#ABT$CUR&37    ; no, what about a control X then?
  580.     beq    45$            ; /56/ Yes
  581.     cmpb    r0    ,#'A&37        ; /56/ Control A ?
  582.     bne    70$            ; /56/ No
  583.     call    cs$in            ; /56/ Yes, print stats
  584.     br    70$            ; /56/ And exit
  585.  
  586. 45$:    spack    #MSG$ACK,paknum,#1,#220$; ^X typed, send an X in the data
  587.     br    80$
  588. 50$:    spack    #MSG$ACK,paknum,#1,#210$; yes, send an ACK with "Z" data
  589.     br    80$            ;
  590. 60$:    spack    #MSG$ERROR,paknum    ; break the sender out please
  591.     clr    cccnt            ; /36/ clear control C flag
  592.     br    100$            ; bye
  593.  
  594. 70$:    spack    #MSG$ACK,paknum        ; ack it
  595. 80$:    mov    numtry    ,oldtry        ; oldtry_count:= numtry
  596.     clr    numtry            ; numtry := 0
  597.     incm64    paknum            ; increment packet number mod 64
  598.     movb    #STA.DAT,r1        ; switch to data state
  599.     return                ; bye
  600.  
  601. 100$:    mov    #STA.ABO,r1        ; abort for some reason
  602.     return
  603.  
  604.  
  605.     global    <chkabo    ,errtxt    ,numtry    ,oldtry    ,packet    ,paknum    ,state    >
  606.     global    <filpro>
  607.  
  608.  
  609.     .save
  610.     .psect    $PDATA
  611. 200$:    .asciz    /Local KERMIT error: /
  612. 210$:    .byte    ABT$ALL    ,0
  613. 220$:    .byte    ABT$CUR    ,0
  614. 230$:    .asciz    /Create failed - /
  615. 240$:    .asciz    /Created file - /
  616. 250$:    .asciz    /File exists, not superceded - /
  617.     .even
  618.     .restore
  619.     .dsabl    lsb
  620.  
  621.  
  622.  
  623.  
  624.     .sbttl    rdata subroutines, continued
  625.  
  626.                     ; 'F', got a FILE HEADER
  627. rdat.x:                    ; 'X', also handle EXTENED REPLY
  628. rdat.f:    inc    oldtry            ; no, see if retry limit expired
  629.     cmp    oldtry    ,maxtry        ; if so, return ABORT
  630.     blos    10$            ; no
  631.      call    m$retry            ; log/send the reason for the abort
  632.      movb    #STA.ABO,r1        ; yes, return 'ABORT'
  633.      return                ; bye
  634.  
  635. 10$:    mov    paknum    ,r1        ; see if thispacket=(paknum+63) mod 64
  636.     add    #77    ,r1        ; ie, check if this data packet was the
  637.     clr    r0            ; one sent the last time. if so, we
  638.     div    #100    ,r0        ; must reack that packet and remain
  639.     clr    r0            ; in the current state.
  640.     cmp    r3    ,r1        ; 
  641.     bne    20$            ; not the last packet
  642.      spack    #MSG$ACK,r3        ; reack this then
  643.      clr    numtry            ; clear out retry counter
  644.      movb    state    ,r1        ; and return current state
  645.      return
  646.  
  647. 20$:    call    m$synch            ; log/send the reason for the abort
  648.     movb    #STA.ABO,r1        ; else return ABORT
  649.     return
  650.  
  651.  
  652. rdat.e:    calls    prerrp    ,<#packet>    ; flag error, print it
  653.     movb    #STA.ABO,r1        ; return ABORT
  654.     return
  655.  
  656. rdat.z:    cmp    paknum    ,r3        ; END OF FILE. If not correct packet
  657.     beq    10$            ; the return 'ABORT'
  658.      call    m$synch            ; log/send the reason for the abort
  659.      movb    #STA.ABO,r1        ; switch to abort state
  660.      return                ; and exit
  661.  
  662. 10$:    mov    #lun.ou    ,r2        ; assume that we close a disk file
  663.     tst    outopn            ; real output or to the terminal
  664.     bmi    20$            ; it's a for real disk file today
  665.     bgt    30$            ; open was aborted via fileprotection
  666.     clr    r2            ; no, it's the console terminal
  667. 20$:    calls    close    ,<r2>        ; do the close now
  668.     call    clratr            ; attributes no longer valid
  669. 30$:    clr    outopn            ; flag it
  670.     spack    #MSG$ACK,r3        ; acknowledge the eof packet
  671.     mov    numtry    ,oldtry        ; /48/
  672.     clr    numtry            ; /48/
  673.     incm64    paknum            ; paknum := (paknum+1) mod 64
  674.     movb    #STA.FIL,r1        ; back to receive file state
  675.     clr    xgottn            ; don't have an X packet anymore
  676.     return
  677.  
  678.  
  679.     .enabl    lsb
  680.  
  681. rdat.$:    inc    datauk            ; /43/ Unknown packet type
  682.     cmp    datauk    ,#2        ; /43/ Been here too often ?
  683.     blo    rdat$$            ; /43/ No, simply NAK it
  684.     strlen    #200$            ; /43/ Yes, send error packet
  685.     spack    #MSG$ERROR,paknum,r0,#200$ ; /43/ ...
  686.     movb    #STA.ABO,r1        ; /43/ Exit please
  687.     return
  688.  
  689.     .save
  690.     .psect    $PDATA
  691. 200$:    .asciz    /Expecting ACK, packet type not valid in current RDATA state/
  692.     .even
  693.     .restore
  694.     .dsabl    lsb
  695.  
  696. rdat$$:    spack    #MSG$NAK,paknum        ; timed out or checksum error
  697.     movb    state    ,r1        ; NAK it and return current state
  698.     return
  699.  
  700.     global    <outopn    ,paknum    ,state    ,xgottn    ,clratr>
  701.     global    <datauk>
  702.  
  703.  
  704.  
  705.     .sbttl    receive data attribute packets
  706.     .enabl    lsb
  707.  
  708.  
  709. rdat.a:    cmp    r3    ,paknum        ; case "A"
  710.     beq    40$            ; Correct packet number ?
  711.     inc    oldtry            ; no, see if retry limit expired
  712.     cmp    oldtry    ,maxtry        ; if so, return ABORT
  713.     blos    20$            ; no
  714.      call    m$retry            ; log/send the reason for the abort
  715.      movb    #STA.ABO,r1        ; yes, return 'ABORT'
  716.      return                ; bye
  717.  
  718. 20$:    mov    paknum    ,r1        ; see if thispacket=(paknum+63) mod 64
  719.     add    #77    ,r1        ; ie, check if this data packet was the
  720.     clr    r0            ; one sent the last time. if so, we
  721.     div    #100    ,r0        ; must reack that packet and remain
  722.     clr    r0            ; in the current state.
  723.     cmp    r3    ,r1        ; insure r0 is not affected
  724.     bne    30$            ; not the last packet
  725.      spack    #MSG$ACK,r3        ; reack this then
  726.      clr    numtry            ; clear out retry counter
  727.      movb    state    ,r1        ; and return current state
  728.      return
  729.  
  730. 30$:     movb    #STA.ABO,r1        ; otherwise return ABORT since we must
  731.      return                ; be way out of synch then.
  732.  
  733. 40$:    calls    r$attr    ,<#packet>    ; simple
  734.     tst    r0            ; was this successful ?
  735.     bne    50$            ; no
  736.     spack    #MSG$ACK,paknum
  737.     mov    numtry    ,oldtry        ; oldtry_count:= numtry
  738.     clr    numtry            ; numtry := 0
  739.     incm64    paknum            ; increment packet number mod 64
  740.     movb    state    ,r1        ; retain current state
  741.     br    100$            ; all done
  742.  
  743. 50$:    movb    #STA.ABO,r1        ; new state
  744.     br    100$            ; bye
  745.  
  746. 100$:    return                ; exti
  747.  
  748.  
  749.     .save
  750.     .psect    $PDATA
  751. 200$:    .asciz    /Attribute packet error - /
  752.     .even
  753.     .restore
  754.     .dsabl    lsb
  755.  
  756.     .end
  757.