#ifndef _CONIO_H_
#define _CONIO_H_

#ifndef _HC11_H_
#include "hc11.h"
#endif

/*
 * The following getchar() and putchar(x) routines are very similar to the
 * assembly language routines INSCI() and OUTSCI() provided in the buffalo
 * monitor.
 */

int getchar()
{
  while( ! ( SCSR & RDRF ) ) ;  /* loop until char available  */
  return SCDR & 0x7f;           /* read char from RX register */
}

int putchar( int x )
{
  while( ! ( SCSR & TDRE ) ) ;  /* loop until SCI ready to TX */
  return (SCDR = x & 0x7f);     /* write char to TX register  */
}

/*
 * The putc() function calls putchar() but "\n" is mapped to "\r\n".
 */

void putc( char x )
{
  if( x == 10 )
	putchar( 13 );
  putchar( x );
}

/*
 * The puts() functions would normally be provided with printf() but we
 * place it here to give the user the option of completely ignoring the
 * (relatively) large printf code.
 */

void puts( char * x )
{
  while( *x )
	putc( *x++ );
}

#endif /* _HC11_H_ */