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

  1.         subttl  kutil2/mac utilities and other odd routines
  2.         extrn   rlen,slen,csvc,rsvc,ssvc,r,n,mjump
  3.         extrn   spaket,rpaket,byte,recptr,sinit
  4.         extrn   fcb,lrecl,filbuf,recbuf,lrecl,paraml
  5.         extrn   readnx,crp,cbp,word
  6.         public  tstack,buffil,eof
  7.         ;
  8.         ;       useful symbols
  9.         ;
  10.         soh     equ     1
  11.         tout    equ     10
  12.         len     equ     0
  13.         seq     equ     1
  14.         type    equ     2
  15.         data    equ     3
  16.         dfport  equ     'A'
  17.         ;
  18.         ;
  19.         ;
  20.         ;svc    to make a trsdos supervisor call
  21.         ;       syntax  svc code
  22.         ;       where   code is the trsdos code
  23.         ;
  24.         svc     macro   code
  25.         ld      a,code
  26.         rst     8
  27.         endm
  28.         ;
  29.         ;
  30.         ;prmes  to print messages on the screen
  31.         ;       syntax  prmes  lab
  32.         ;       where   lab if the label as defined with mssg
  33.         ;
  34.         prmes   macro   lab
  35.         .xlist
  36.         extrn   m_&lab,l_&lab
  37.         push    hl
  38.         push    bc
  39.         ld      hl,m_&lab       ;get address of message
  40.         ld      bc,(l_&lab)     ;and length
  41.         ld      c,13            ;add a CR at end of ttyout
  42.         svc     9               ;call dos
  43.         pop     bc
  44.         pop     hl
  45.         .list
  46.         endm
  47.         ;
  48.         ;blmov  to move a block of text
  49.         ;       syntax  blmov source,destination,length
  50.         ;               if length is 0 then assume 256
  51.         ;
  52.         blmov   macro   source,dest,len
  53.         .xlist
  54.         local   $1,$2
  55.         push    hl
  56.         push    bc
  57.         push    de
  58.         ld      hl,source       ;address of source
  59.         ld      de,dest         ;address of destination
  60.         ld      a,(len)         ;get length
  61.         cp      0               ;is it zero ?
  62.         jr      nz,$1
  63.         ld      b,1             ;then set bc = 256
  64.         ld      c,0             ;(b=1 ; c=0)
  65.         jp      $2              ;go to start move
  66.         $1:
  67.         ld      b,0
  68.         ld      c,a             ;bc = length
  69.         $2:
  70.         ldir                    ;move and check if bc=0
  71.         pop     de
  72.         pop     bc
  73.         pop     hl
  74.         .list
  75.         endm
  76.         movb    macro   value,loc
  77.         .xlist
  78.         push    af
  79.         ld      a,value
  80.         ld      (loc),a
  81.         pop     af
  82.         .list
  83.         endm
  84.         ;
  85.         ;
  86.         ;       tstack  to test a received packet for a good ack
  87.         ;
  88.         tstack:
  89.                 ld      a,(n)           ;cirrent packet count
  90.                 add     a,' '           ;make printable
  91.                 cp      (ix+seq)        ;equal to seq received ?
  92.                 jp      nz,plus1        ;no, test n+1
  93.                 ld      a,(ix+type)     ;get packet type
  94.                 cp      'Y'             ;is an ack ?
  95.                 jp      nz,nogood       ;no return error code
  96.         $1:
  97.                 scf
  98.                 ccf
  99.                 ret                     ;return no error
  100.         plus1:
  101.                 inc     a               ;increment packet count
  102.                 cp      (ix+seq)        ;equal to received ?
  103.                 jp      z,$1            ;yes, all ok
  104.         nogood:
  105.                 scf                     ;set carry
  106.                 ret
  107.         ;
  108.         ;       buffil  to fill a send packet data field from
  109.         ;               record buffer
  110.         ;
  111.         buffil:
  112.                 movb    3,cbp           ;initialize buffer pointer
  113.         b5:
  114.                 ld      a,(cbp)         ;get buffer pointer
  115.                 inc     a               ;it might be one less
  116.                 ld      hl,sinit        ;maxlen to send
  117.                 cp      (hl)            ;equal to max or max-1 ?
  118.                 jp      c,b0            ;no, there is room
  119.         b4:
  120.                 ld      a,(cbp)         ;buffer pointer
  121.                 ld      (iy+len),a      ;in packet
  122.                 scf
  123.                 ccf
  124.                 ret                     ;return all ok
  125.         b0:
  126.                 xor     a               ;clear a
  127.                 ld      hl,crp          ;record pointer address
  128.                 cp      (hl)            ;buffer empty ?
  129.                 jp      nz,b1           ;no
  130.                 call    readnx          ;get something (EOF...)
  131.                 jp      nc,b1           ;not end of file yet
  132.                 ld      a,(cbp)         ;spaket pointer
  133.                 ld      (iy+len),a      ;put in place
  134.                 cp      3               ;is this the start ?
  135.                 jp      nz,b13          ;not yet, return normally
  136.                 scf                     ;flag to never return here
  137.         b13:    ret
  138.         b1:
  139.                 ld      a,(cbp)         ;buffer pointer
  140.                 ld      b,a             ;save in b
  141.                 ld      a,(sinit)       ;maxlen to send
  142.                 sub     b               ;a=SA=mxl-cbp
  143.                 ld      (byte),a        ;save in byte
  144.                 ld      a,(crp)         ;record pointer
  145.                 ld      b,a             ;save in b
  146.                 ld      a,(lrecl)       ;record length
  147.                 sub     b               ;a=BA=lrecl-crp
  148.                 ld      hl,byte         ;get byte address
  149.                 cp      (hl)            ;BA > SA ?
  150.                 jp      nc,b2           ;go move SA bytes
  151.                 ld      (byte),a        ;save BA in byte
  152.         b2:
  153.                 ld      hl,spaket       ;packet address
  154.                 ld      a,(cbp)         ;current pointer
  155.                 add     a,l             ;add to low byte
  156.                 ld      l,a             ;save back
  157.                 ld      a,0             ;clear a keeping carry
  158.                 adc     a,h             ;add carry to high byte
  159.                 ld      h,a             ;save back
  160.                 ex      de,hl           ;save in DE
  161.                 ld      hl,recbuf       ;record address
  162.                 ld      a,(crp)         ;record pointer
  163.                 add     a,l             ;add to low byte
  164.                 ld      l,a             ;save back
  165.                 ld      a,0             ;clear a keeping carry
  166.                 adc     a,h             ;add to high byte
  167.                 ld      h,a             ;save back
  168.                 ;
  169.                 ; here we move from recbuf to spaket
  170.                 ; making sure the control caracters are quoted,
  171.                 ; and uncontrollified (same thing for del),
  172.                 ; and that the quote caracter is itself quoted.
  173.                 ;
  174.                 movb    0,word          ;this will be the count from recbuf
  175.                 movb    0,word+1        ;and the count of quote bytes
  176.         b9:
  177.                 ld      a,31            ;limit of control char.
  178.                 ld      b,(hl)          ;get character in b to
  179.                 res     7,b             ; reset seventh bit
  180.                 cp      b               ;compare 31 to byte to send
  181.                 jp      c,b6            ;this is not a control char.
  182.         b8:
  183.                 ld      a,(sinit+5)     ;get the quote byte
  184.                 ld      (de),a          ;move in spaket
  185.                 inc     de              ;update spaket pointer
  186.                 push    hl              ;save
  187.                 ld      hl,word+1       ;points to quote count
  188.                 inc     (hl)            ;update count
  189.                 pop     hl              ;restore
  190.                 ld      a,64            ;to uncontrollify
  191.                 xor     (hl)            ;the byte to send
  192.                 ld      (hl),a          ;and put it back in recbuf
  193.                 jp      b7              ;go send it
  194.         b6:
  195.                 ld      a,127           ;del byte
  196.                 cp      b               ;is this it ?
  197.                 jp      z,b8            ;yes go uncontrollify it
  198.                 ;
  199.                 ld      a,(sinit+5)     ;quote byte
  200.                 cp      (hl)            ;is this what we are sending ?
  201.                 jp      nz,b7           ;no, go on
  202.                 ld      (de),a          ;yes put it in spaket
  203.                 inc     de              ;and update pointer
  204.                 push    hl              ;save
  205.                 ld      hl,word+1       ;get quote count address
  206.                 inc     (hl)            ;and update it
  207.                 pop     hl              ;restore hl
  208.         b7:
  209.                 ldi                     ;move the byte in spaket
  210.                 push    hl              ;save
  211.                 ld      hl,word         ;count address
  212.                 inc     (hl)            ;update it
  213.                 ld      a,(hl)          ;get count of bytes from recbuf
  214.                 ld      hl,word+1       ;and count of quote bytes
  215.                 add     a,(hl)          ;add them to get real count
  216.                 ld      hl,byte         ;address of max to moved
  217.                 inc     a               ;increment real count
  218.                                         ; to get to max-1 or max
  219.                 cp      (hl)            ;compare count+1 to max
  220.                 jp      nc,b10          ;this is it, finish.
  221.                 pop     hl              ;restore
  222.                 jp      b9              ;one more time...
  223.         b10:
  224.                 ld      a,(word)        ;real count moved from recbuf
  225.                 ld      (byte),a        ;put where we need it
  226.                 pop     hl              ;restore to recbuf
  227.         b11:
  228.                 ;
  229.                 ; at this point we have moved up to (byte) bytes
  230.                 ; maby less if there was only one control character
  231.                 ; Most of those bytes come from recbuf plus some
  232.                 ; instances of the quote byte.
  233.                 ;
  234.                 ld      a,(word)        ;number of bytes moved
  235.                 ld      hl,word+1       ;address of quote count
  236.                 add     a,(hl)          ;a = total count
  237.                 ld      hl,cbp          ;buffer pointer
  238.                 add     a,(hl)          ;increment
  239.                 ld      (hl),a          ;save back in cbp
  240.                 ld      hl,crp          ;record pointer
  241.                 ld      a,(word)        ;get back bytes moved from rec
  242.                 add     a,(hl)          ;fix pointer
  243.                 ld      (hl),a          ;save back in cbp
  244.                 ld      a,(lrecl)       ;record length
  245.                 cp      (hl)            ;equal to record pointer ?
  246.                 jp      nz,b3           ;no, go on
  247.                 movb    0,crp           ;yes, reset crp
  248.         b3:
  249.                 jp      b5              ;one more time
  250.          ;
  251.         ;       eof     this routine will be accessed automatically
  252.         ;               from a read of eof by trsdos.
  253.         ;               Might be accessed twice ...
  254.         ;
  255.         eof:
  256.                 scf                     ;set carry
  257.                 ret
  258.                 end
  259.