 sttl 6551 ACIA Interface Routines
 pag

* The routines in this file are specific to an ACIA (6551).

*
* ttconf
*
* Configure the port pointed at by the Y register.  The X
* register is pointing to the terminal table.  All registers
* except D should be preserved.
*

ttconf clr status,y soft reset of chip
 pshs d delay some here
 puls d
 lda status,y get status - see if device is really here
 beq 2f if 0 status - then ok
 bita #$60 see if funny status is ok
 beq 2f if all 0, OK
 sez set false status
 rts return
2 lda tbaud,x get word configuration
 anda #$1C
 lsra
 pshs x
 ldx #TTCONF
 ldd a,x
 puls x
 sta tconf,x command register bits
 ora #NO_RTS|DS_RIN
 sta command,y (no ints enabled & RTS brought high)
 lda tbaud2,x get baud rate
 anda #$0F
 pshs b
 ora ,s+
 sta control,y
 clz set true status
 rts return
*
* Device configuration table
*   Corresponds to 6850 ACIA configuration
*
TTCONF
 fcb $60,$B0 7 Data bits, Even parity, 2 Stop bits
 fcb $40,$B0 7 Data bits, Odd parity,  2 Stop bits
 fcb $60,$30 7 Data bits, Even parity, 1 Stop bit
 fcb $40,$30 7 Data bits, Odd parity,  1 Stop bit
 fcb $00,$90 8 Data bits, No parity,   2 Stop bits
 fcb $00,$10 8 Data bits, No parity,   1 Stop bit
 fcb $60,$90 8 Data bits, Even parity, 1 Stop bit
 fcb $40,$90 8 Data bits, Odd parity,  1 Stop bit


*
* ttputc
*
* Send the character in the B register to the ACIA.  All
* registers should be preserved.  Y points to the device.
*

ttputc stb data,y send character
 rts return


*
* ttgetc
*
* Get the character from the device and return in the B
* register.  Y points to the device and all registers
* should be preserved.
*

ttgetc ldb data,y get the character
 cmpb #$00 Debug escape
 bne 00f
 pshs b
 ldb SWITCH2
 bitb #$F0
 puls b
 beq 00f
 jsr DB_main
00
 rts return


*
* ttenxr
*
* Enable the transmit interrupts and leave the receive
* interrupt enabled (it is enabled upon routine entry).
* Y points to the device and X points to to the terminal
* table entry.  Preserve all registers but D.
*
*

ttenxr lda #EN_DEV|EN_XIN|EN_RIN Enable Xmit and Rcve interrupts
 ora tconf,x
 sta command,y send to acia
 if DEBUG&DBG_6551
 pshs d,x,y
 ldx #00f
 jsr DB_pdata
 ldd 4,s
 jsr DB_phex2
 puls d,x,y
 endif
 rts return
 if DEBUG&DBG_6551
00 fcc $d,'TTY ENXR, (Y) = $',0
 endif


*
* ttdisx
*
* Disable the transmit interrupt and leave the receive
* interrupt enabled.  Y points to the device and X points
* to the terminal table entry.  Preserve all but D.
*

ttdisx lda #EN_DEV|EN_RIN|DS_XIN Enable device with receive interrupts
 ora tconf,x
 sta command,y send to acia
 if DEBUG&DBG_6551
 pshs d,x,y
 ldx #00f
 jsr DB_pdata
 ldd 4,s
 jsr DB_phex2
 puls d,x,y
 endif
 rts return
 if DEBUG&DBG_6551
00 fcc $d,'TTY DISX, (Y) = $',0
 endif


*
* ttenr
*
* Enable the receive interrupts only.  The transmit
* interrupts should be turned off.  Y points to the device
* and X point to the terminal table entry.  Preserve all
* but the D register.
*

ttenr lda #EN_DEV|EN_RIN|DS_XIN Receive interrupts only
 ora tconf,x
 sta command,y send to acia
 if DEBUG&DBG_6551
 pshs d,x,y
 ldx #00f
 jsr DB_pdata
 ldd 4,s
 jsr DB_phex2
 puls d,x,y
 endif
 rts return
 if DEBUG&DBG_6551
00 fcc $d,'TTY ENR, (Y) = $',0
 endif


*
* ttenx
*
* Enable the transmit interrupts only.  The receive
* interrupts should be left disabled.  Y points to the
* device and X points to the terminal table entry.
* All registers but D shoud be preserved.
*

ttenx lda #EN_DEV|EN_XIN|DS_RIN Xmit only, Rcv off
 ora tconf,x
 sta command,y send to acia
 if DEBUG&DBG_6551
 pshs d,x,y
 ldx #00f
 jsr DB_pdata
 ldd 4,s
 jsr DB_phex2
 puls d,x,y
 endif
 rts return
 if DEBUG&DBG_6551
00 fcc $d,'TTY ENX, (Y) = $',0
 endif


*
* ttenno
*
* Disable all interrupts from device and drop the RTS
* line.  Y points to the device and X points to the
* terminal table entry.  Preserve all but D register.
*

ttenno lda #NO_RTS|DS_RIN|DS_DEV Disable device, RTS high
 ora tconf,x
 sta command,y send to acia
 if DEBUG&DBG_6551
 pshs d,x,y
 ldx #00f
 jsr DB_pdata
 ldd 4,s
 jsr DB_phex2
 puls d,x,y
 endif
 rts return
 if DEBUG&DBG_6551
00 fcc $d,'TTY ENNO, (Y) = $',0
 endif


*
* ttxbsy
*
* Test if the transmit buffer is empty.  Return TRUE if
* it is empty (N.E. status). Y points to the device and
* all but A needs preserved.
*

ttxbsy lda status,y get status
 bita #AC_XBSY is it busy?
 if DEBUG&DBG_6551
 pshs cc,d,x,y
 ldx #00f
 jsr DB_pdata
 ldd 1+4,s
 jsr DB_phex2
 ldx #01f
 jsr DB_pdata
 lda 0,s
 jsr DB_phex
 puls cc,d,x,y
 endif
 rts return
 if DEBUG&DBG_6551
00 fcc $d,'TTY XBSY, (Y) = $',0
01 fcc ', CC = $',0
 endif


*
* tttstx
*
* Test device pointed at by Y for a transmit interrupt.
* Return TRUE if interrupt present.  Preserve all but
* the A register.
*

tttstx lda status,y get status
 bita #AC_RBSY|AC_OVRN|AC_FE|AC_PE
 bne 2f
 clz set TRUE
 bra 9f
2 sez set FALSE
 if DEBUG&DBG_6551
9 pshs cc,d,x,y
 ldx #00f
 jsr DB_pdata
 ldd 1+4,s
 jsr DB_phex2
 ldx #01f
 jsr DB_pdata
 lda 0,s
 jsr DB_phex
 puls cc,d,x,y
 rts return
00 fcc $d,'TTY TSTX, (Y) = $',0
01 fcc ', CC = $',0
 else
9 rts
 endif

*
* ttiscts
*
* Test device pointed at by X for "Clear to Send"
* -- Return TRUE (not equal) if yes
*
ttiscts lda status,x check for CTS
 bita #AC_DSR is DSR down?
 bne 2f
 clz no - return TRUE
 rts
2 sez yes - return FALSE
 rts


*
* tttstr
*
* Test device pointed at by Y for a receive interrupt.
* Return TRUE if interrupt present.  Preserve all but
* the A register.
*

tttstr lda status,y get device status
 bita #AC_RBSY check status
 beq 5f jump if not receive interrupt
 bita #AC_FE|AC_PE|AC_OVRN check for errors
 bne 5f if any - no receive int
 clz return true
 rts return
5 sez return false
 rts


*
* tttstb
*
* Test device pointed at by Y for a "break" condition.
* Return TRUE if found.  Preserve all registers but A
* and return NULL in B (for break character).
*

tttstb pshs a check for break
 anda #AC_RBSY|AC_FE must have both!
 cmpa #AC_RBSY|AC_FE
 puls a
 bne 2f
 ldb data,y get character from acia
 pshs d,x,y,u delay some here
 puls d,x,y,u
 lda data,y get next garbage char if any
 clrb
 clz set true
 rts return
2 sez return false
 rts


*
* tttstc
*
* Test device pointed at by Y for drop "Carrier Detect"
* type interrupt.  Return TRUE if so.  Preserve all registers
* but A.
*

tttstc bita #AC_DCD check for carrier drop
 beq 1f jump if no error
 ldb data,y read reg to reset status
 clz return true
1 rts return

*
* tttstd
*
* Test device pointed at by Y for a change in DSR
* type interrupt.  Return TRUE if so.  Preserve all registers
* but A.
*

tttstd pshs a save old status
 bita #AC_DSR get state of DSR
 beq 1f jump if present
 lda tstate2,x was it there?
 bita #DSR_OK
 beq 6f no - no change
 bra 5f yes - change in DSR
1 lda tstate2,x was DSR not there?
 bita #DSR_OK
 bne 6f no - change
5 clz return true - DSR has changed
 bra 9f exit
6 sez return false - DSR has not changed
9 puls a,pc return


*
* tttste
*
* Test device pointed at by Y for error conditions.
* Handle all errors local to this routine - no status
* returned.  Preserve all but A.
*

tttste bita #AC_OVRN|AC_PE
 beq 5f jump if none set
 bita #AC_RBSY not valid unless this is set also
 beq 5f jump if no error interrupt
 lda data,y read data register to clear any interrupt conditions
 clz return true
5 rts return


*
* ttend
*
* Terminate i/o operation for device pointed at by Y.
* Preserve all but D.
*

ttend rts return (nothing for acia)

*
* Reset All 6551 ports
*
rs_ports
 clra reset 6551 devices
 ifn DEBUG
 sta PORT3+reset
 endif
 sta PORT1+reset
 sta PORT2+reset
 clrb response code = no errors
 rts
