home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / s920603.zip / Z8530.ASM < prev    next >
Assembly Source File  |  1992-05-15  |  3KB  |  129 lines

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