home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / trs80model2.zip / trssend.mac < prev    next >
Text File  |  1997-03-26  |  11KB  |  277 lines

  1.         title   ksend/mac   sending unit
  2.         cseg
  3.         ;
  4.         ;
  5.         extrn   recptr,recbuf,rplus,mjump
  6.         extrn   spaket,rpaket,screen
  7.         extrn   rplus,sinit,state,byte,n,r
  8.         extrn   rpack,spack,abort,acsum,flush
  9.         extrn   fcb,writnx,open,rinit,close
  10.         extrn   lrecl,readnx,buffil,filnam,tstack
  11.         public  s_init,s_file,s_open,s_break
  12.         public  s_data,s_eof
  13.         ;
  14.         len     equ     0
  15.         seq     equ     1
  16.         type    equ     2
  17.         data    equ     3
  18.         quote   equ     '#'
  19.         _a      equ     1
  20.         _c      equ     2
  21.         _r      equ     3
  22.         _rf     equ     4
  23.         _rd     equ     5
  24.         _s      equ     6
  25.         _sf     equ     7
  26.         _sd     equ     8
  27.         _se     equ     9
  28.         _sb     equ     10
  29.         _o      equ     11
  30.         ;
  31.         ;
  32.         subttl  macros used in this module
  33.         ;
  34.         ;prmes  to display messages
  35.         ;
  36.         prmes   macro   lab
  37.         .xlist
  38.         extrn   m_&lab,l_&lab
  39.         push    hl
  40.         push    bc
  41.         ld      hl,m_&lab
  42.         ld      bc,(l_&lab)
  43.         ld      c,13
  44.         ld      a,9
  45.         rst     8
  46.         pop     bc
  47.         pop     hl
  48.         .list
  49.         endm
  50.         ;movb
  51.         ;
  52.         movb    macro   value,loc
  53.         .xlist
  54.         push    af
  55.         ld      a,value
  56.         ld      (loc),a
  57.         pop     af
  58.         .list
  59.         endm
  60.         ;
  61.         ;blmov
  62.         ;
  63.         blmov   macro   source,dest,len
  64.         .xlist
  65.         local   $1,$2
  66.         push    hl
  67.         push    bc
  68.         push    de
  69.         ld      hl,source
  70.         ld      de,dest
  71.         ld      a,(len)
  72.         cp      0
  73.         jr      nz,$1
  74.         ld      b,1
  75.         ld      c,0
  76.         jp      $2
  77.         $1:
  78.         ld      b,0
  79.         ld      c,a
  80.         $2:
  81.         ldir
  82.         pop     de
  83.         pop     bc
  84.         pop     hl
  85.         .list
  86.         endm
  87.         ;
  88.         ;fack   to format an ack paket
  89.         ;
  90.         f_ack   macro
  91.         .xlist
  92.         ld      (iy+len),3
  93.         ld      a,(n)
  94.         add     a,' '
  95.         ld      (iy+seq),a
  96.         ld      (iy+type),'Y'
  97.         ld      hl,spaket
  98.         call    acsum
  99.         .list
  100.         endm
  101.         ;
  102.         ;nplus
  103.         ;
  104.         nplus   macro
  105.         .xlist
  106.         ld      hl,n
  107.         inc     (hl)
  108.         res     6,(hl)
  109.         movb    0,r
  110.         .list
  111.         endm
  112.         ;
  113.         subttl  open file (pseudo-state, precedes send_init)
  114.         page
  115.         ;
  116.         ;       open file
  117.         ;
  118.         s_open:
  119.                 call    open            ;open file (assume fcb set)
  120.                 movb    _s,state        ;state = send_init
  121.                 movb    0,n             ;packet number to 0
  122.                 movb    0,r             ;reset retry count
  123.                 call    flush           ;clear comm buffers
  124.                 jp      mjump           ;and back
  125.         subttl  send initialisation routine
  126.         page
  127.         ;
  128.         ;       send init parameters
  129.         ;
  130.         s_init:
  131.                 ld      ix,rpaket
  132.                 ld      iy,spaket
  133.                 ld      (iy+len),12     ;length of init packet
  134.                 ld      (iy+type),'S'   ;type send init
  135.                 ld      a,(n)           ;current packet number
  136.                 add     a,' '           ;make printable
  137.                 ld      (iy+seq),a      ;into packet
  138.                 movb    12,byte         ;number of bytes to move
  139.                 blmov   rinit,spaket+data,byte
  140.                 ld      hl,spaket       ;to point correctly
  141.                 call    acsum           ;compute checksum
  142.                 call    spack           ;and send packet
  143.                 ld      a,(hl)          ;get paket length and fix it
  144.                 sub     ' '             ;because there might be a retry
  145.                 ld      (hl),a          ;save back
  146.                 call    rpack           ;get answer
  147.                 jp      c,rplus         ;no good
  148.                 call    tstack          ;was it a good ack ?
  149.                 jp      c,rplus         ;no, send it again
  150.                 blmov   rpaket+data,sinit,byte
  151.                                         ;move parameters to keep
  152.                 ld      hl,sinit+4      ;address of eol
  153.                 res     5,(hl)          ;sub 32 to get real eol
  154.                 ld      hl,sinit        ;maxlen to send
  155.                 res     5,(hl)          ;sub 32
  156.                 nplus                   ;increment packet count
  157.                 movb    _sf,state       ;state = send file header
  158.                 jp      mjump           ;and back
  159.         subttl  send file header information
  160.         page
  161.         ;
  162.         ;       send file header
  163.         ;
  164.         s_file:
  165.                 ld      hl,filnam+1     ;where the filame start
  166.                 ld      a,(filnam)      ;it's length
  167.                 ld      b,a             ;store len in b
  168.                 ld      a,'/'           ;byte to look for
  169.         s1:
  170.                 cp      (hl)            ;is this a '/' ?
  171.                 jp      z,s2            ;yes change it t '.'
  172.                 inc     hl              ;advance pointer
  173.                 djnz    s1              ;and check next byte
  174.                 jp      s3              ;there was no '/'
  175.         s2:
  176.                 ld      a,'.'           ;a dot to normalize filename
  177.                 ld      (hl),a          ;in place
  178.         s3:
  179.                 ld      (iy+type),'F'   ;of type file header
  180.                 ld      a,(n)           ;get packet count
  181.                 add     a,' '           ;make printable
  182.                 ld      (iy+seq),a      ;insert in spacket
  183.                 blmov   filnam+1,spaket+data,filnam
  184.                                         ;put in filename
  185.                 ld      a,(filnam)      ;get filename length
  186.                 add     a,3             ;add len,seq,type
  187.                 ld      (iy+len),a      ;set in spacket
  188.                 ld      hl,spaket       ;hl to point correctly
  189.                 call    acsum           ;compute checksum
  190.                 call    spack           ;send it
  191.                 ld      a,(hl)          ;get paket length and fix it
  192.                 sub     ' '             ;because there might be a retry
  193.                 ld      (hl),a          ;save back in spaket
  194.                 call    rpack           ;get answer
  195.                 jp      c,rplus         ;no good
  196.                 call    tstack          ;was it a good ack ?
  197.                 jp      c,rplus         ;no
  198.                 nplus                   ;update packet count
  199.  
  200.                 call    buffil          ;get a bufferfull
  201.                 jp      c,s_eof         ;it was the end of file
  202.                 movb    _sd,state       ;state = send_data
  203.                 jp      mjump           ;return
  204.         subttl  send data from file
  205.         page
  206.         ;
  207.         ;       send data
  208.         ;
  209.         s_data:
  210.                 ld      (iy+type),'D'   ;data packet
  211.                 ld      a,(n)           ;packet number
  212.                 add     a,' '           ;make printable
  213.                 ld      (iy+seq),a      ;into packet
  214.                 ld      hl,spaket       ;hl point correctly
  215.                 call    acsum           ;compute checksum
  216.                 call    spack           ;send it
  217.                 ld      a,(hl)          ;get length to fix it in case
  218.                 sub     ' '             ; of a bad ack
  219.                 ld      (hl),a          ;save back in spaket
  220.                 call    rpack           ;get answer
  221.                 jp      c,rplus         ;no good
  222.                 call    tstack          ;a good ack ?
  223.                 jp      c,rplus         ;nope...
  224.                 nplus                   ;yes, update packet count
  225.                 call    buffil          ;get next packet ready
  226.                 jp      c,s_eof         ;we reach the eof
  227.                 jp      mjump           ;and back
  228.         subttl  send end of file
  229.         page
  230.         ;
  231.         ;       send end of file
  232.         ;
  233.         s_eof:
  234.                 movb    _se,state       ;might not be done
  235.                 ld      (iy+type),'Z'   ;eof in spacket
  236.                 ld      (iy+len),3      ;length
  237.                 ld      a,(n)           ;packet number
  238.                 add     a,' '           ;make printable
  239.                 ld      (iy+seq),a      ;into packet
  240.                 ld      hl,spaket       ;to point correctly
  241.                 call    acsum           ;compute checksum
  242.                 call    spack           ;send packet
  243.                 ld      a,(hl)          ;get paket length
  244.                 sub     ' '             ;and fix it
  245.                 ld      (hl),a          ;back in spaket
  246.                 call    rpack           ;get answer
  247.                 jp      c,rplus         ;no good
  248.                 call    tstack          ;test for good ack
  249.                 jp      c,rplus         ;no good
  250.                 nplus                   ;good, update packet count
  251.                 movb    _sb,state       ;state = break transmission
  252.                 jp      mjump           ;and back
  253.         subttl  send break transmission
  254.         page
  255.         ;
  256.         ;       send break transmission
  257.         ;
  258.         s_break:
  259.                 ld      (iy+type),'B'   ;in spaket, set type
  260.                 ld      (iy+len),3      ;and length
  261.                 ld      a,(n)           ;current packet number
  262.                 add     a,' '           ;make printable
  263.                 ld      (iy+seq),a      ;store in spaket
  264.                 ld      hl,spaket       ;hl to point correctly
  265.                 call    acsum           ;compute checksum
  266.                 call    spack           ;send packet
  267.                 ld      a,(hl)          ;get paket length and fix it
  268.                 sub     ' '             ;there might be a retry
  269.                 ld      (hl),a          ;save back in spaket
  270.                 call    rpack           ;get answer
  271.                 jp      c,rplus         ;no good
  272.                 call    tstack          ;check if correct ack
  273.                 jp      c,rplus         ;no, send again
  274.                 movb    _c,state        ;complete
  275.                 jp      mjump           ;FIN...
  276.                 end
  277.