home *** CD-ROM | disk | FTP | other *** search
- ;-------------------------------------------------------------------------
- ; Low-level Serial Hardware Routines... Called from `C' Code
-
- include 'exec/types.i'
- include 'exec/ables.i'
- include 'hardware/custom.i'
- include 'hardware/intbits.i'
-
- SECTION serhard,CODE
-
- xref _custom
-
- OVRUN equ 15-8 ; Overrun bit
- RBF equ 14-8 ; Receive buffer full bit
- TBE equ 13-8 ; Transmit buffer empty bit
- TSRE equ 12-8 ; Transmit shift reg empty
-
- CLOCK_NTSC equ 3546895
- CLOCK_PAL equ 3546895 ; Beats me...
-
- INT_ABLES
-
- ;------------------------------------------------------------------------
- ; DirectSerBaud (long baud)
- ; D0.L
-
- xdef _DirectSerBaud
- _DirectSerBaud
- move.l 4(sp),d0
- ; Fall through
-
- xdef DirectSerBaud
- DirectSerBaud
- lea _custom,a1
- 1$ btst.b #TSRE,serdatr(a1) ; Wait for transmit complete
- beq.s 1$ ; before switching baud.
- move.l #CLOCK_NTSC,d1
- divu d0,d1
- subq.w #1,d1
- bclr.l #15,d1 ; Set 8 data bits
- move.w d1,serper(a1)
- rts
-
- ;------------------------------------------------------------------------
- ; void DirectSerWrite (char *buffer, short length)
- ; A0 D0.L
-
- xdef _DirectSerWrite
- _DirectSerWrite
- move.l 4(sp),a0
- move.l 8(sp),d0
- ; Fall through
-
- xdef DirectSerWrite
- DirectSerWrite
- lea _custom,a1 ; Point to custom regs
- move.w #$FF00,d1 ; Prep output register.
- bra.s 3$ ; Jump into the loop.
- 1$ move.b (a0)+,d1 ; Get output byte.
- 2$ btst.b #TBE,serdatr(a1) ; Transmit buffer empty?
- beq.s 2$ ; Nope - wait for it.
- move.w d1,serdat(a1) ; Stuff byte and send it.
- 3$ dbf d0,1$ ; Continue sending.
- 9$ rts
-
-
- ;-----------------------------------------------------------------------
- ; short DirectSerRead (char *buffer, short length, long timeout)
- ; D0.L A0 D0.L D1.L
-
- xdef _DirectSerRead
- _DirectSerRead
- move.l 4(sp),a0
- movem.l 8(sp),d0-d1
- ; Fall through
-
- xdef DirectSerRead
- DirectSerRead
- movem.l d2-d4,-(sp) ; Save regs.
- lea _custom,a1 ; Point to custom regs.
- moveq #0,d2 ; Initialize count.
- bra.s 4$ ; Jump into the loop.
-
- 1$ move.l d1,d4 ; Set timeout counter...
- 2$ btst.b #RBF,serdatr(a1) ; Read buffer full?
- bne.s 3$ ; Yes - read the data.
- subq.l #1,d4 ; Decrement timeout count.
- bne.s 2$ ; Not expired, continue.
- bra.s 9$ ; Timed out!!
- 3$ move.w serdatr(a1),d3 ; Get data word.
- move.w #INTF_RBF,intreq(a1) ; Reset interrupt bit.
- move.b d3,(a0)+ ; Store data byte.
- addq.w #1,d2 ; Bump count.
- 4$ dbf d0,1$ ; Read all characters.
-
- 9$ move.l d2,d0 ; Get char count.
- movem.l (sp)+,d2-d4 ; Restore regs.
- rts
-
- ;-----------------------------------------------------------------------
- ; void DirectSerFlush (void)
-
- FLUSHTIME equ $0005FFFF ; About 1/2-3/4 second
-
- xdef _DirectSerFlush
- _DirectSerFlush
- ; Fall through
-
- xdef DirectSerFlush
- DirectSerFlush
- lea _custom,a1
- bra.s 1$
- 0$ move.w #INTF_RBF,intreq(a1) ; Reset interrupt bit.
- 1$ move.l #FLUSHTIME,d0 ; Time in which no data must arrive.
- 2$ btst.b #RBF,serdatr(a1) ; Any data at port?
- bne.s 0$ ; Yes, read until empty.
- subq.l #1,d0 ; Decrement counter.
- bne.s 2$ ; Loop back 'til timeout.
- rts
-
- end
-