home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / intel8051 / i51krmt.asm < prev    next >
Assembly Source File  |  2020-01-01  |  5KB  |  288 lines

  1. $mod51
  2. $nosymbols
  3. $nolist
  4. $include(i51ctrl.inc)
  5. $include(c:\cet\inc\mymon.inc)
  6. $list
  7. $include(i51init.inc)
  8.  
  9. flags    data    21h
  10. ctrl    bit    21h.0
  11. parity    bit    21h.1
  12.  
  13. Mrk    data    24h
  14. Len    data    25h
  15. Seq    data    26h
  16. Typ    data    27h
  17. Chk    data    28h
  18. fph    data    2eh
  19. fpl    data    2fh
  20.  
  21. cksum    data    10h
  22. EOL    data    11h
  23. CTL    DATA    12H
  24. T    data    13h
  25. N    data    14h
  26. try    data    15h
  27. I    data    16h
  28. T7    data    17h
  29. Ptr    data    18h
  30.  
  31.     org    codeaddr
  32. start:    jmp    main
  33.  
  34.  
  35. main:    mov    N,#0        ; initialize sequence number
  36.     clr    parity        ; no parity bit
  37.     setb    runlite
  38. ;=========================================
  39. L2000:    call    L5000
  40.     mov    a,TYP
  41.     cjne    a,#'S',L2035
  42.     sjmp    L2040
  43. L2035:    mov    flags,#0ffh
  44.     mov    dptr,#D    
  45.     mov    a,TYP
  46.     movx    @dptr,a
  47.     inc    dptr
  48.     clr    a
  49.     movx    @dptr,a
  50.     call    strcat
  51.     db    ' Packet in S State',0
  52.     jmp    L9500
  53. ;
  54. ; here on correct packet type
  55. L2040:    mov    dptr,#pktdat
  56.     call    strlen
  57.     push    acc        ; save packet length
  58. ;
  59. ; if pktlen > 4 then EOL=asc(mid$(pktdat,5,1) else EOL=13
  60.     cjne    a,#4,L2042
  61. L2042:    jc    L2044        ; > 4
  62.     mov    dpl,#4
  63.     movx    a,@dptr
  64.     call    unchar
  65.     mov    EOL,a
  66.     sjmp    L2050
  67. L2044:    mov    EOL,#13        ; <= 4
  68. L2050:    pop    acc        ; get packet length
  69. ; if pktlen > 5 then CTL=asc(mid$(pktdat,5,1) else CTL="#"
  70.     cjne    a,#5,L2052
  71. L2052:    jc    L2054
  72.     mov    dpl,#5
  73.     movx    a,@dptr
  74.     mov    CTL,a
  75.     sjmp    L2070
  76. L2054:    mov    CTL,#'#'
  77. L2070:    mov    dptr,#D
  78.     clr    a
  79.     movx    @dptr,a        ; D = ""
  80.     call    strcat
  81. ;
  82. ; MAXL =  80 bytes
  83. ; TIME =  10 seconds
  84. ; NPAD =  none
  85. ; PADC =  NUL
  86. ; EOL  =  13
  87. ; QCTL =  #
  88. ; QBIN =  No 8th bit prefix
  89. ; CHKT =  normal 6 bit checksum
  90.  
  91.     db    'p* @-#N1',0    ; parameter string
  92.     call    L8020        ; send local parameters
  93. ;=========================================
  94. ; get a File Header packet. If a B packet comes, we're all done
  95. L3000:    call    L5000
  96.     mov    a,TYP
  97.     cjne    a,#'B',L3030
  98.     call    L8000
  99.     jmp    L9900
  100. L3030:    cjne    a,#'F',L3035
  101.     sjmp    L3040
  102. L3035:    mov    dptr,#D    
  103.     mov    a,TYP
  104.     movx    @dptr,a
  105.     inc    dptr
  106.     clr    a
  107.     movx    @dptr,a
  108.     call    strcat
  109.     db    ' Packet in F State',0
  110.     jmp    L9500
  111. L3040:    call    fopen        ; open the file
  112. L3060:    call    L8000
  113. ;=========================================
  114. ; get data packets. If a Z packet comes, the file is complete.
  115. L4000:    call    L5000
  116. L4020:    mov    a,TYP
  117.     cjne    a,#'Z',L4030
  118.     call    fclose        ; close the file
  119.     call    L8000
  120.     jmp    L3000
  121. L4030:    cjne    a,#'D',L4035
  122.     sjmp    L4040        ; we have data !
  123. L4035:    mov    dptr,#D    
  124.     mov    a,TYP
  125.     movx    @dptr,a
  126.     inc    dptr
  127.     clr    a
  128.     movx    @dptr,a
  129.     call    strcat
  130.     db    ' Packet in D State',0
  131.     jmp    L9500
  132. L4040:    call    fwrite        ; write to file
  133. L4060:    call    L8000        ; acknowledge
  134. L4070:    jmp    L4000
  135. ;=========================================
  136.  
  137. ; try to get a valid packet with the desired sequence number
  138. L5000:    call    L7000
  139.     mov    try,#1
  140. nxttry:    mov    a,Seq
  141.     cjne    a,N,L5040
  142.     mov    a,Typ
  143.     cjne    a,#'Q',L5090
  144. L5040:    mov    dptr,#sndbuf
  145.     call    print
  146.     call    L7000
  147.     inc    try
  148.     mov    a,try
  149.     cjne    a,#5,nxttry
  150.     mov    TYP,#'T'
  151. L5090:    ret
  152. ;
  153. ;=========================================
  154. ; Send a packet with data D$ of length L, type TYP, sequence #N.
  155. L6000:    mov    dptr,#D
  156.     push    dpl
  157.     push    dph
  158.     mov    a,TYP
  159.     push    acc
  160.     mov    a,N
  161.     push    acc
  162.     mov    a,Len
  163.     push    acc
  164.     call    spack
  165.     ret
  166. ;
  167. ;=========================================
  168.  
  169. ; routine to read and decode a packet
  170. L7000:    call    rpack
  171.     ret
  172. ;
  173. ;=========================================
  174. ; routine to send an ACK and increment the packet number
  175. L8000:    mov    dptr,#D
  176.     clr    a
  177.     movx    @dptr,a        ; d$ = ""
  178. L8020:    mov    TYP,#'Y'
  179.     mov    dptr,#D
  180.     call    strlen
  181.     mov    Len,a        ; L = len(D$)
  182.     call    L6000        ; send packet
  183.     mov    a,N
  184.     inc    a
  185.     anl    a,#3fh        ; 63
  186.     mov    N,a        ; n = (n + 1) and 63
  187.     anl    a,#3
  188.     jnz    L8050
  189.     cpl    runlite
  190. L8050:    ret
  191. ;
  192. ;=========================================
  193. ; Error handler
  194. L9000:    
  195.  
  196. ;=========================================
  197. ; Error packet sender
  198. L9500:    mov    dptr,#D
  199.     call    strlen
  200.     mov    TYP,#'E'
  201.     call    L6000        ; send packet
  202. ; Normal exit point
  203. L9900:    call    fclose
  204.     jmp    WARM
  205. ;
  206. ;=========================================
  207. blkchk:    mov    b,a        ; save check
  208.     anl    a,#192
  209.     swap    a
  210.     rr    a
  211.     rr    a        
  212.     anl    a,#3        ; a = a / 64
  213.     add    a,b        ; add check
  214.     anl    a,#63
  215.     ret
  216. ;
  217. ;=========================================
  218. linput:    mov    dptr,#rcvbuf
  219. linp1:    push    dpl
  220.     push    dph
  221.     call    getchr
  222.     pop    dph
  223.     pop    dpl
  224.     movx    @dptr,a
  225.     inc    dptr
  226.     cjne    a,#cr,linp1
  227.     clr    a
  228.     movx    @dptr,a        ; string terminator
  229.     ret
  230. ;
  231. ;=========================================
  232. ; find char B in string DPTR return index A
  233. instr:    mov    r2,#0
  234. instr1:    movx    a,@dptr
  235.     jz    instr3
  236.     inc    r2
  237.     cjne    a,b,instr2
  238.     sjmp    instr4
  239. instr2:    inc    dptr
  240.     sjmp    instr1
  241. instr3:    mov    r2,a
  242. instr4:    mov    a,r2
  243.     ret
  244. ;
  245. tochar:    add    a,#32
  246.     ret
  247. ;
  248. unchar:    clr    c
  249.     subb    a,#32
  250.     ret
  251. ;
  252. fopen:    mov    dptr,#fileaddr
  253.     mov    fpl,dpl
  254.     mov    fph,dph
  255.     ret
  256. ;
  257. ; write Len bytes from PKTDAT to FPTR
  258. fwrite:    mov    p2,#high pktdat
  259.     mov    r0,#low pktdat
  260.     mov    dpl,fpl
  261.     mov    dph,fph
  262.     mov    r2,Ptr        ; pktdat length
  263. fw1:    movx    a,@r0        ; get byte from pktdat
  264.     movx    @dptr,a        ; put byte to fptr
  265.     inc    r0
  266.     inc    dptr
  267.     djnz    r2,fw1
  268.     mov    fpl,dpl
  269.     mov    fph,dph
  270.     ret
  271.     
  272. fclose:    ret
  273. ;
  274. $include(i51scat.asm)
  275. $include(i51slen.asm)
  276. $include(i51spck.asm)
  277. $include(i51rpck.asm)
  278. $include(i51chkl.asm)
  279. ;
  280.     dseg at    dataaddr
  281. rcvbuf:    ds    128
  282. sndbuf:    ds    1,'# N3',13,0
  283.     ds    128 - ($-sndbuf)
  284. pktdat:    ds    128
  285. D:    ds    128
  286.  
  287.     end
  288.