
 lib environment
 sttl 8250 interface routines
 pag
 name tty_8250
 global ttconf,ttputc,ttgetc,ttenxr,ttdisx,ttenr,ttenx,ttenno
 global ttxbsy,tttstx,tttstr,tttstb,tttstc,tttste,ttend,ttsbrg
 global ttiscts

* The routines in this file are specific to an 8250 serial interface.
* They are called from the "ttyhan" and "ttydrv" files.


*
* 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 lda #$80 set up br
 sta 3,y
 ldd #26 9600 BR divisor
 exg a,b
 std 0,y
 lda #3 set up data type
 sta 3,y
 sta 4,y
 clr 1,y disable ints
**  lda 2,y is it there?
**  bne 4f
 lda #$0f enable ints
 sta 1,y
 lda 6,y get modem lines
 anda #$b0
 cmpa #$b0 cts & dcd ok?
 beq 6f
4 sez set false status
 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.
*

ttputc
 pshs d,x,y,u save registers
 lda DATBOX+$0F check I/O map
 coma
 cmpa #io_map
 beq 10f
 ldx #00f
 jsr Pdata
 lda DATBOX+$0F
 coma
 jsr Phex
 ldx #01f
 jsr Pdata
 leax 8,s
 leay 47,x
 jsr DumpXY
 jmp Montor
10 puls d,x,y,u restore registers
 stb 0,y send character
 rts return
00 fcc $d,'TTPUTC - Wrong Map: ',0
01 fcc $d,'Stack: ',0


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

ttenxr rts


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


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


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


*
* 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 clr 1,y disable ints
 clr 4,y turn off modem lines
 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.
*

ttxbsy lda 6,y check rts
 bita #$10 cts ok?
 beq 2f
 lda 5,y check empty
 bita #$20
2 rts


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

tttstx lda 6,s get status
 cmpa #2
 bne 2f
 clz set TRUE
 rts return
2 sez set FALSE
 rts return

*
* ttiscts
*
* Test device pointed at by X for "Clear to Send"
* -- Return TRUE (not equal) if yes
*
ttiscts lda 6,x check for CTS
 bita #%00010000 is CTS 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 cmpa #4
 bne 2f
 clz set true
 rts return
2 sez set false
 rts return


*
* 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 cmpa #6
 bne 2f
 ldb 5,y get status
 bitb #$10 is it break?
 beq 2f
 ldb 0,y read character
 clz
 rts
2 sez set status
 rts


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

tttstc cmpa #0
 bne 2f
 ldb 6,y get status
 bitb #$80 dcd ok?
 bne 2f
 clz set true
 rts
2 sez set false
 rts


*
* 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 rts return (nothing for acia)


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

ttend rts return (nothing for acia)


*
* ttsbrg
*
* Set up the baud rate generators - if any.  On entry,
* Y points to xmit BRG and U points to rcvr BRG.  X is
* pointing to the terminal table entry (tbaud2,x has
* byte for baud rate generator).
*

ttsbrg rts return
 lda tbaud2,x get speed byte
 sta 0,y set xmit speed
 sta 0,u set rcvr speed
 rts return
