home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / 8530.ASM < prev    next >
Assembly Source File  |  1991-01-27  |  3KB  |  131 lines

  1. ; 8530 general-purpose control subroutines
  2. ; Copyright 1991 Phil Karn, KA9Q
  3.     .MODEL    MEMMOD,C
  4.     LOCALS
  5.     %MACS
  6.     .LALL
  7.     
  8.     .DATA
  9.  
  10.     .CODE
  11. ; Write a 8530 register. Called from C as
  12. ; write_scc(int ctl,char reg,char val);
  13.     public    write_scc
  14. write_scc    proc
  15.     arg    ctl:word,reg:byte,val:byte
  16.     pushf
  17.     mov    dx,ctl
  18.     mov    al,reg
  19.     cmp    al,0
  20.     jz    @@doit        ; no need to set register 0
  21.     cli
  22.     out    dx,al
  23. ; Allow enough delay for 16 MHz 80386 and a 4.9152 MHz 8530
  24. ; The delay uses a NOP in a loop because of the pipeline in the 80386.
  25. ; The loop instruction causes the 80386 to flush the pipeline and reload.
  26. ; The 8530 requires a delay of 6 PCLK + 200 ns - a loop of 8 should be
  27. ; adequate to a 16 Mhz 80386.
  28.     mov    cx,8
  29. @@w1:    nop
  30.     loop    @@w1
  31. @@doit:    mov    al,val
  32.     out    dx,al
  33.     popf
  34.     ret
  35. write_scc    endp
  36.  
  37. ; Read a 8530 register. Called from C as
  38. ; read_scc(int ctl,char reg);
  39.     public    read_scc
  40. read_scc    proc
  41.     arg    ctl:word,reg:byte
  42.     pushf
  43.     mov    dx,ctl
  44.     mov    al,reg
  45.     cmp    al,0
  46.     jz    @@doit    ; no need to set reg if R0
  47.     cli
  48.     out    dx,al
  49. ; allow enough delay for the 8530 to settle (see comments above)
  50.     mov    cx,8
  51. @@r1:    nop
  52.     loop    @@r1
  53. @@doit:    in    al,dx
  54.     mov    ah,0
  55.     popf
  56.     ret
  57. read_scc    endp
  58.  
  59. ; Read packets from the 8530 receiver.
  60. ; Returns when either a good frame is received, or when carrier drops.
  61. ; If a good frame is received, the length is returned; otherwise -1.
  62.     public    rx8530
  63. rx8530    proc
  64.     arg    ctl:word,data:word,buf:ptr,bufsize:word    
  65.     uses    di
  66.  
  67. @@restart:
  68.     if    @Datasize NE 0
  69.         les    di,buf
  70.     else
  71.         mov    di,buf    ; cp = buf
  72.         mov    ax,ds
  73.         mov    es,ax
  74.     endif
  75.  
  76.     cld
  77.     mov    cx,0        ; cnt = 0
  78. @@rxloop:
  79.     mov    dx,ctl    ; read status
  80.     in    al,dx        ; into al
  81.     test    al,08h        ; DCD still present?
  82.     jz    @@dcdoff    ; nope, quit
  83.     test    al,080h        ; Abort?
  84.     jnz    @@restart    ; yes, start again
  85.     test    al,01h        ; character available?
  86.     jz    @@nochar    ; nope, go on
  87.     mov    dx,data
  88.     in    al,dx        ; get it
  89.     stosb            ; and stash: *cp++ = char
  90.     inc    cx        ; cnt++
  91.     cmp    cx,bufsize    ; cx == bufsize?
  92.     jnz    @@rxloop
  93.  
  94.     mov    dx,ctl    ; buffer overflowed; abort receiver
  95.     mov    al,3        ; select register 3
  96.     out    dx,al
  97.     mov    al,0d9h        ; ENT_HM|RxENABLE|RxCRC_ENAB|Rx8
  98.     nop
  99.     nop
  100.     nop
  101.     nop
  102.     nop
  103.     out    dx,al
  104.     jmp    @@restart
  105. @@nochar:
  106.     mov    al,1        ; Select error register (R1)
  107.     mov    dx,ctl
  108.     out    dx,al
  109.     nop
  110.     nop
  111.     nop
  112.     nop
  113.     nop
  114.     nop
  115.     in    al,dx        ; read error reg (R1)
  116.     test    al,080h        ; end of frame?
  117.     jz    @@rxloop    ; nope, keep looking
  118.  
  119.     test    al,040h        ; End of frame. CRC error?
  120.     jnz    @@restart    ; yup; start again
  121.     mov    ax,cx        ; good frame; return with count
  122.     ret
  123.  
  124. @@dcdoff:
  125.     mov    ax,0ffffh    ; DCD dropped, return -1
  126.     ret
  127.  
  128. rx8530    endp
  129.     end
  130.  
  131.