 sttl ACIA interface routines
 pag

* The routines in this file are specific to an ACIA (6850).
* They are called from the "ttyhan" and "ttydrv" files.

*
* 6850 Device table
*
DEV_6850
 fdb bad_cmd  0 -
 fdb open_tty  1 -
 fdb close_tty  2 -
 fdb ttyset  3 -
 fdb ttyget  4 -
 fdb req_write  5 -
 fdb write_data  6 -
 fdb wrt_sc  7 -
 fdb req_read  8 -
 fdb read_data  9 -
 fdb bad_cmd 10 -
 fdb bad_cmd 11 -
 fdb bad_cmd 12 -
 fdb bad_cmd 13 -
 fdb bad_cmd 14 -
 fdb clock_on 15 -
 fdb S2_IRQ
 fdb S2_init
 fdb S2_test
*
 fdb S2ttconf
 fdb S2ttputc
 fdb S2ttgetc
 fdb S2ttenxr
 fdb S2ttdisx
 fdb S2ttenr
 fdb S2ttenx
 fdb S2ttenno
 fdb S2ttxbsy
 fdb S2tttstx
 fdb S2ttiscts
 fdb S2tttstr
 fdb S2tttstb
 fdb S2tttsts
 fdb S2tttstc
 fdb S2tttstd
 fdb S2tttste
 fdb S2ttend
 fdb S2ttwcts
 fdb S2ttwdcd

*
* Check for and process an ACIA interrupt
*  D - Device #
*  X - Device address
*
S2_IRQ pshs d,x,y,u save registers just in case
 lda csr,x check for interrupt
 bita #$80
 beq 10f jump if no interrupt
 ldd 0,s restore device #
 jsr tintr go process interrupt
 sec -- interrupt processed
 bra 99f
10 clc -- no interrupt processed
99 puls d,x,y,u,pc

*
* Initialize ACIA port
*   B - Device #
*   X - Device address
*
S2_init pshs d,x,y,u
 lda #$43 set up reset code
 sta 0,x reset acia
 pshs d delay
 puls d
 puls d,x,y,u,pc

*
* Determine if MP-S2 ACIA board is present
*  D - ACIA port address
*  Y - Device table address
*  <CS> if present & ACIA
*
S2_test pshs d,x,u
 tfr d,u
 lda #$43 set up reset code
 sta 0,u reset acia
 pshs d delay
 puls d
 lda 0,u check response
 beq 00f
 anda #%11110011
 beq 00f
 clc -- not an 8250
 bra 99f
00 lda NUM_TRM compute device table address
 ldb #DEV_SIZE
 mul
 ldy #dev_tab
 leay d,y
 inc NUM_TRM -- bump by 2
 inc NUM_TRM
 ldd 0,s
 ldx #DEV_6850
 std dev_addr,y
 stx dev_type,y
 leay DEV_SIZE,y
 addd #4
 std dev_addr,y
 stx dev_type,y
 leay DEV_SIZE,y
 sec
99 puls d,x,u,pc


*
* 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.
*

S2ttconf lda #3 reset the acia
 sta csr,y
 pshs d delay some here
 puls d
 lda csr,y get status - see if acia is really here
 beq 2f if 0 status - then ok
 bita #$f3 see if funny status is ok
 bne 4f
2 lda tbaud,x get configuration word from table
 ora #ADIVID set up full configuration
 sta csr,y (no ints enabled & RTS brought high)
 lda csr,y get new status
 bita #$8 is CTS ok?
 beq 6f
4 sez set false status
 clc show wait for CTS
 rts return
6 clz set true status
 rts return


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

S2ttputc stb dbuf,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.
*

S2ttgetc ldb dbuf,y get the character
 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.
*
*

S2ttenxr lda tbaud,x get configuration
 ora #ENBXIN|ADIVID|ENBRIN enable int bits
 sta csr,y send to acia
 rts return


*
* 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.
*

S2ttdisx lda tbaud,x get configuration word
 ora #ADIVID|ENBRIN|DSBXIN set bits
 sta csr,y send to acia
 rts return


*
* 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.
*

S2ttenr lda tbaud,x get configuration word
 ora #ADIVID|ENBRIN|DSBXIN set bits
 sta csr,y send to acia
 rts return


*
* 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.
*

S2ttenx lda tbaud,x get configuration word
 ora #ADIVID|ENBXIN set bits
 sta csr,y send to acia
 rts return


*
* 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.
*

S2ttenno lda tbaud,x get configuration word
 ora #ADIVID|$40 set bits
 sta csr,y send to acia
 rts return


*
* 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.
*

S2ttxbsy lda csr,y get status
 bita #ACTBSY is it busy?
 rts return


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

S2tttstx lda csr,y get status
 bita #ACRBSY|$04
 bne S2false
 bra S2true


*
* ttiscts
*
* Test device pointed at by X for "Clear to Send"
* -- Return TRUE (not equal) if yes
*
S2ttiscts lda csr,x check for CTS
 bita #$8 is CTS down?
 bne S2false
S2true clz no - return TRUE
 rts
S2false 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.
*

S2tttstr bita #%00110100 check status
 bne S2false
 bra S2true


*
* 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).
*

S2tttstb bita #$30 check for break condition
 beq 2f
 ldb dbuf,y get character from acia
 pshs d,x,y,u delay some here
 puls d,x,y,u
 lda dbuf,y get next garbage char if any
 clz set true
2 rts return


*
* tttsts
*
* Test device for "CTS" interrupt.
*

S2tttsts bra S2false not currently implemented


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

S2tttstc bita #$04 check for carrier drop
 beq 1f jump if no error
 ldb dbuf,y read reg to reset status
 clz return true
1 rts 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.
*

S2tttste lda dbuf,y read data register to clear any interrupt conditions
 clz return true
 rts return

*
* tttstd - Test for drop in DTR
*
S2tttstd sez -- not supported by hardware
 rts


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

S2ttend rts return (nothing for acia)


*
* ttwcts
*
* Wait for CTS to go high (sleep on it).
*

S2ttwcts bsr S2ttenx enable xmit ints only
 ldb #TTYOPR set priority
 ldy tqout,x point to output q
 jmp sleep sleep on CTS


*
* ttwdcd
*
* Wait for DCD to go high (sleep on it).
*

S2ttwdcd rts currently not implemented
