home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / misc / imagefx_sdk / sas / scanlib / serhard.a < prev    next >
Encoding:
Text File  |  1992-06-19  |  4.7 KB  |  122 lines

  1. ;-------------------------------------------------------------------------
  2. ; Low-level Serial Hardware Routines... Called from `C' Code
  3.  
  4.                 include 'exec/types.i'
  5.                 include 'exec/ables.i'
  6.                 include 'hardware/custom.i'
  7.                 include 'hardware/intbits.i'
  8.  
  9.                 SECTION serhard,CODE
  10.  
  11.                 xref    _custom
  12.  
  13. OVRUN           equ     15-8            ; Overrun bit
  14. RBF             equ     14-8            ; Receive buffer full bit
  15. TBE             equ     13-8            ; Transmit buffer empty bit
  16. TSRE            equ     12-8            ; Transmit shift reg empty
  17.  
  18. CLOCK_NTSC      equ     3546895
  19. CLOCK_PAL       equ     3546895         ; Beats me...
  20.  
  21.                 INT_ABLES
  22.  
  23. ;------------------------------------------------------------------------
  24. ; DirectSerBaud (long baud)
  25. ;                D0.L
  26.  
  27.                 xdef    _DirectSerBaud
  28. _DirectSerBaud
  29.                 move.l  4(sp),d0
  30.                 ; Fall through
  31.  
  32.                 xdef    DirectSerBaud
  33. DirectSerBaud
  34.                 lea     _custom,a1
  35. 1$              btst.b  #TSRE,serdatr(a1)       ; Wait for transmit complete
  36.                 beq.s   1$                      ; before switching baud.
  37.                 move.l  #CLOCK_NTSC,d1
  38.                 divu    d0,d1
  39.                 subq.w  #1,d1
  40.                 bclr.l  #15,d1                  ; Set 8 data bits
  41.                 move.w  d1,serper(a1)
  42.                 rts
  43.  
  44. ;------------------------------------------------------------------------
  45. ; void DirectSerWrite (char *buffer, short length)
  46. ;                      A0            D0.L
  47.  
  48.                 xdef    _DirectSerWrite
  49. _DirectSerWrite
  50.                 move.l  4(sp),a0
  51.                 move.l  8(sp),d0
  52.                 ; Fall through
  53.  
  54.                 xdef    DirectSerWrite
  55. DirectSerWrite
  56.                 lea     _custom,a1              ; Point to custom regs
  57.                 move.w  #$FF00,d1               ; Prep output register.
  58.                 bra.s    3$            ; Jump into the loop.
  59. 1$              move.b  (a0)+,d1                ; Get output byte.
  60. 2$              btst.b  #TBE,serdatr(a1)        ; Transmit buffer empty?
  61.                 beq.s   2$                      ; Nope - wait for it.
  62.                 move.w  d1,serdat(a1)           ; Stuff byte and send it.
  63. 3$              dbf     d0,1$                   ; Continue sending.
  64. 9$              rts
  65.  
  66.  
  67. ;-----------------------------------------------------------------------
  68. ; short DirectSerRead (char *buffer, short length, long timeout)
  69. ; D0.L                 A0            D0.L          D1.L
  70.  
  71.                 xdef    _DirectSerRead
  72. _DirectSerRead
  73.                 move.l  4(sp),a0
  74.                 movem.l 8(sp),d0-d1
  75.                 ; Fall through
  76.  
  77.                 xdef    DirectSerRead
  78. DirectSerRead
  79.                 movem.l d2-d4,-(sp)             ; Save regs.
  80.                 lea     _custom,a1              ; Point to custom regs.
  81.                 moveq   #0,d2                   ; Initialize count.
  82.                 bra.s    4$            ; Jump into the loop.
  83.  
  84. 1$              move.l  d1,d4                   ; Set timeout counter...
  85. 2$              btst.b  #RBF,serdatr(a1)        ; Read buffer full?
  86.                 bne.s   3$                      ; Yes - read the data.
  87.                 subq.l  #1,d4                   ; Decrement timeout count.
  88.                 bne.s   2$                      ; Not expired, continue.
  89.                 bra.s   9$                      ; Timed out!!
  90. 3$              move.w  serdatr(a1),d3          ; Get data word.
  91.                 move.w  #INTF_RBF,intreq(a1)    ; Reset interrupt bit.
  92.                 move.b  d3,(a0)+                ; Store data byte.
  93.                 addq.w  #1,d2                   ; Bump count.
  94. 4$              dbf     d0,1$                   ; Read all characters.
  95.  
  96. 9$              move.l  d2,d0                   ; Get char count.
  97.                 movem.l (sp)+,d2-d4             ; Restore regs.
  98.                 rts
  99.  
  100. ;-----------------------------------------------------------------------
  101. ; void DirectSerFlush (void)
  102.  
  103. FLUSHTIME       equ     $0005FFFF               ; About 1/2-3/4 second
  104.  
  105.                 xdef    _DirectSerFlush
  106. _DirectSerFlush
  107.                 ; Fall through
  108.  
  109.                 xdef    DirectSerFlush
  110. DirectSerFlush
  111.                 lea     _custom,a1
  112.                 bra.s   1$
  113. 0$              move.w  #INTF_RBF,intreq(a1)    ; Reset interrupt bit.
  114. 1$              move.l  #FLUSHTIME,d0           ; Time in which no data must arrive.
  115. 2$              btst.b  #RBF,serdatr(a1)        ; Any data at port?
  116.                 bne.s   0$                      ; Yes, read until empty.
  117.                 subq.l  #1,d0                   ; Decrement counter.
  118.                 bne.s   2$                      ; Loop back 'til timeout.
  119.                 rts
  120.  
  121.                 end
  122.