/* Console Input/Output Routines */

.set	RXCS,0x20	/* Recieve CSR */
.set	RXDB,0x21	/* Recieve data */
.set	TXCS,0x22	/* Transmit CSR */
.set	TXDB,0x23	/* Transmit data */
.set	READY,0x80	/* Ready bit */

.set	NEWLINE,0x0a	/* newline (or linefeed) */
.set	CR,0x0d		/* carriage return */

/* Writes a character to the console. */
	.globl	_putchar
_putchar:
	.word	0
1:	mfpr	$TXCS,r0	/* Get the TX status */
	bitl	$READY,r0	/* Check READY bit */
	beql	1b		/* If not ready wait */
	movzbl	4(ap),r1	/* Get byte argument */
	cmpb	$NEWLINE,r1	/* Check for newline */
	bneq	3f		/* If not then just send character */
	mtpr	$CR,$TXDB	/* If yes, then send a CR followed by a LF */
2:	mfpr	$TXCS,r0	/*  Get the TX status */
	bitl	$READY,r0	/*  Check READY bit */
	beql	2b		/*  If not ready wait */
3:	mtpr	r1,$TXDB	/* Send data */
	ret

/* Gets a character from the console. */
	.globl	_getchar
_getchar:
	.word	0
1:	mfpr	$RXCS,r0	/* Get RX status */
	bitl	$READY,r0	/* Check READY bit */
	beql	1b		/* If not ready wait */
	mfpr	$RXDB,r0	/* Get data */
	movzbl	r0,r0		/* Only return a byte */
	ret
