/*	OXEGE1.C
**
**	Single-character inout/output (and status) routines
**	NOTE that these routines are specific to CP/M Plus and
**	will not function under CP/M 2.2.
*/

#include "a:stdio.h"
#include "b:oxege.h"

#define	INPUT	253

/*	AIS - AUX: INPUT STATUS
*/
ais()
	{
	return DOS ( 7, NULL );
	}

/*	AI - AUX: INPUT
*/
ai()
	{
	return DOS ( 3, NULL );
	}

/*	AO - AUX: OUTPUT
*/
ao( character )
	int character;
	{
	DOS ( 4, character );
	}

/*	CIS - CON: INPUT STATUS
*/
cis()
	{
	return DOS ( 11, NULL );
	}

/*	CI - CON: INPUT
*/
ci()
	{
	return DOS ( 6, INPUT );
	}

/*	CO - CON: OUTPUT
*/
co( character )
	int character;
	{
	DOS ( 6, character );
	}

/*	LO - LST: OUTPUT
*/
lo( character )
	int character;
	{
	Ubdos( 5, character );
	}

#define	MODCTL	13
#define	MODDAT	12

/*	RXSTAT -- Receive Status
*/
rxstat()
	{
	outp( MODCTL, 16 );
	return( inp( MODCTL ) & 1 );
	}

/*	RX - Receive a byte
*/
rx()
	{
	while ( rxstat() == NULL ) { ; }
	return inp( MODDAT );
	}

/*	TXSTAT - TRANSMIT STATUS
*/
txstat()
	{
	outp( MODCTL, 16 );
	return( inp( MODCTL ) & 4 );
	}


/*	TX - Transmit a byte
*/
tx( data )
	int data;
	{
	int counter;
	counter = 0;
	while( counter < 10000 )
		{
		if ( txstat() != NULL )
			{
			outp( MODDAT, (data & 127) );
			return 1;
			}
		++counter;
		}
	return 0;
	}

/*	TERMINIT -- Initialize RS-232 communications
*/
terminit()
	{
	outp( MODCTL, 0 );
	outp( MODCTL, 24 );
	outp( MODCTL, 4 );
	outp( MODCTL, 68 );
	outp( MODCTL, 3 );
	outp( MODCTL, 193 );
	outp( MODCTL, 5 );
	outp( MODCTL, 234 );
	}


/*	PORT I/O FOR SMALL-C COMPILER
*/

#ifdef	SMALL

char	GLport;
char	GLdata;

inp( port )
	int port;
	{
	GLport = port;
#asm
	.z80
	ld	hl,GLport
	ld	c,(hl)
	in	a,(c)
	ld	(hl),a
	.8080
#endasm
	return GLport;
	}

outp( port, data )
	int port, data;
	{
	GLport = port;
	GLdata = data;
#asm
	.z80
	ld	hl,GLport
	ld	c,(hl)
	ld	hl,GLdata
	ld	a,(hl)
	out	(c),a
	.8080
#endasm
	}

#endif

Ldata = data;
#asm
	.z80
	ld	hl,GLport
	ld	c,(hl)
	ld	hl,GLdata
	ld	a,(hl)
	out	(c),a
