
		.file "monio.s"
#include    "config.h"


#if (BOARD == CG16)
 #
 #
 #       ED board hardware constants
 #
	.set	IOBASE	,0xf40000
	.set	busoff	,2
	.set	HPC	,IOBASE + 0x000
	.set	UART	,IOBASE + 0x020
	.set	UART1  	,0xc003f8
	.set	CENT	,IOBASE + 0x040
	.set	STATUS	,IOBASE + 0x060
	.set	BPUCTL	,IOBASE + 0x080
	.set	BPUMSK	,IOBASE + 0x0A0
	.set	BPUCNT	,IOBASE + 0x0C0
	.set	CTLL	,IOBASE + 0x0E0
	.set	DMACD	,IOBASE + 0x100
	.set	DMACT	,IOBASE + 0x120
	.set	DMALO	,IOBASE + 0x140
	.set	DMAHI	,IOBASE + 0x160
#endif
#if (BOARD == SHARK_CCA)
	.set	IOBASE	,0xf80000
	.set	busoff	,2
	.set	UART	,IOBASE + 0x400
	.set	UART1  	,IOBASE + 0x480

#endif
#if (BOARD == LX32)
	.set	busoff	,1
	.set UART1	,0xFF300008              # console (uart 1)
	.set UART	,0xFF300000              # tty     (uart 2)

#endif
#if (BOARD == BARACUDA_CCA)
	.set	busoff	,1
	.set UART1	,0xf0080480              # console (uart 1)
	.set UART	,0xf0080400              # tty     (uart 2)

#endif

 
 #
 #	16550a uart definitions
 #
	.set	RBR	,0 * busoff		#receiver buffer register
	.set	THR	,0 * busoff		#transmitter holding register
	.set	IER	,1 * busoff		#interrupt enable register
	.set	IIR	,2 * busoff		#interrupt ident register
	.set	LCR	,3 * busoff		#line control register
	.set	MCR	,4 * busoff		#MODEM control register
	.set	LSR	,5 * busoff		#line status register
	.set	MSR	,6 * busoff		#MODEM status register
	.set	DLL	,0 * busoff		#Divisor latch (LS)
	.set	DLM	,1 * busoff		#Divisor latch (MS)

	.set	THRE	,5		#Transmitter holding register empty
	.set	RDA	,0		#Received data available


 #
 #
 #    r d c h r      ( read char procedure )
 #
 #
 # char getchar ();
 #
 #
		.globl	_getchar

_getchar:	enter	[],0
	movd	$UART,r0	# r0: address of trminal a
rdchrlp:			# do while in_rdy=0 and rd_wait(fp)=true
	tbitb	$RDA,LSR(r0)	#   input in_rdy
	bfc	rdchrlp		# whit until ready 
	movb	RBR(r0),r0	# rdchr:=usart data
rdchrex:
	exit	[]
	ret	0
 #
 #
 #
 #	putchar   ( print character )
 #
 #	procedure - send one character to terminal
 #
 #	calling sequence putchar(chr)
 #
 #	 chr  - character input  character to be printed
 #
	.globl	_putchar
	.set	chr_pr,8  		# ascii chr
_putchar: enter	[],0
	movd	$UART,r1	# r1: address of trminal a
 #	tbitb   $RDA,LSR(r1)
 #	bfc	prchrlp		# no character in input queue
 #				# check for ctrl s/ctrl q
 #	bsr	_getchar
 #	bsr	_getchar
prchrlp: tbitb	$THRE,LSR(r1)		# if tx-rdy = 0
	bfc	prchrlp
	movb	chr_pr(fp),THR(r1)
	movd	$5,r0
llp:	acbd	-1,r0, llp	#let the character drain.
	exit	[]
	ret	0
