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

  1. $mod51
  2. $nosymbols
  3. $nolist
  4. $include(i51ctrl.inc)
  5. $list
  6. $include(i51hedr.inc)
  7.  
  8.     org    codeaddr
  9. start:    jmp    main
  10. $include(i51init.asm)        ; initialization
  11. $include(i51misc.asm)        ; misc functions
  12. $include(i51sprm.asm)        ; parameters
  13. $include(i51file.asm)        ; file i/o routines
  14. $include(i51strf.asm)        ; string functions
  15. $include(i51spck.asm)        ; send packet
  16. $include(i51rpck.asm)        ; receive packet
  17. $include(i51getv.asm)
  18. $include(i51sakn.asm)
  19.  
  20. main:    call    initialize
  21. ;=========================================
  22. RECV:    call    getvp        ; get valid packet
  23.     mov    a,TYP
  24.     cjne    a,#'S',L2035
  25.     sjmp    L2040
  26. L2035:    mov    flags,#0ffh
  27.     mov    dptr,#GDA
  28.     mov    a,TYP
  29.     movx    @dptr,a
  30.     inc    dptr
  31.     clr    a
  32.     movx    @dptr,a
  33.     call    strcat
  34.     db    ' Packet in S State',0
  35.     jmp    L9500
  36. ;
  37. ; here on correct packet type
  38. L2040:    mov    dptr,#pktdat
  39.     call    strlen
  40.     push    acc        ; save packet length
  41. ;
  42. ; if pktlen > 4 then EOL=asc(mid$(pktdat,5,1) else EOL=13
  43.     cjne    a,#4,L2042
  44. L2042:    jc    L2044        ; > 4
  45.     mov    dpl,#4
  46.     movx    a,@dptr
  47.     unchar
  48.     mov    EOL,a
  49.     sjmp    L2050
  50. L2044:    mov    EOL,#13        ; <= 4
  51. L2050:    pop    acc        ; get packet length
  52. ; if pktlen > 5 then CTL=asc(mid$(pktdat,5,1) else CTL="#"
  53.     cjne    a,#5,L2052
  54. L2052:    jc    L2054
  55.     mov    dpl,#5
  56.     movx    a,@dptr
  57.     mov    CTL,a
  58.     sjmp    L2070
  59. L2054:    mov    CTL,#'#'
  60. L2070:    mov    TYP,#'Y'
  61.     call    send        ; send local parameters
  62.  
  63. ;=========================================
  64. ; get a File Header packet. If a B packet comes, we're all done
  65. L3000:    call    getvp
  66.     mov    a,TYP
  67.     cjne    a,#'B',L3030
  68.     call    sakn        ; send acknowledge
  69.     jmp    L9900
  70. L3030:    cjne    a,#'F',L3035
  71.     sjmp    L3040
  72. L3035:    mov    dptr,#GDA    
  73.     mov    a,TYP
  74.     movx    @dptr,a
  75.     inc    dptr
  76.     clr    a
  77.     movx    @dptr,a
  78.     call    strcat
  79.     db    ' Packet in F State',0
  80.     jmp    L9500
  81. L3040:    call    fopen        ; open the file
  82. L3060:    call    sakn        ; send acknowledge
  83. ;=========================================
  84. ; get data packets. If a Z packet comes, the file is complete.
  85. L4000:    call    getvp
  86. L4020:    mov    a,TYP
  87.     cjne    a,#'Z',L4030
  88.     call    fclose        ; close the file
  89.     call    sakn        ; send acknowledge
  90.     jmp    L3000
  91. L4030:    cjne    a,#'D',L4035
  92.     sjmp    L4040        ; we have data !
  93. L4035:    mov    dptr,#GDA    
  94.     mov    a,TYP
  95.     movx    @dptr,a
  96.     inc    dptr
  97.     clr    a
  98.     movx    @dptr,a
  99.     call    strcat
  100.     db    ' Packet in D State',0
  101.     jmp    L9500
  102. L4040:    call    fwrite        ; write to file
  103. L4060:    call    sakn        ; send acknowledge
  104. L4070:    jmp    L4000
  105.  
  106. ; Error handler
  107. L9000:    
  108.  
  109. ;=========================================
  110. ; Error packet sender
  111. L9500:    mov    dptr,#GDA
  112.     call    strlen
  113.     mov    TYP,#'E'
  114.     call    spack        ; send packet
  115. ; Normal exit point
  116. L9900:    call    fclose
  117.     jmp    sys_warm
  118. ;
  119. ;=========================================
  120. ;
  121. $include(i51data.asm)        ; ram data
  122. ;
  123.     end
  124.  
  125.