home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / Z8530.ASM < prev    next >
Assembly Source File  |  1993-09-16  |  3KB  |  132 lines

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