
const int ReadChannelBuffer		= 0xa08;
const int WriteChannelBuffer	= 0xb08;
const int ReadChannelStatus		= 0xc00;

const int CONAOK = 0;
#define  MAX_DATA 1024
const int VSERIAL = 3; /* Serial channel */

typedef struct 
{
	long	numBytes;
	long	numFree;
} CHANSTATUS;

extern int ASEBios( long, long, void *, void * );

long GetBytesAvailable( int channel )
{
	CHANSTATUS status;
	if( ASEBios( ReadChannelStatus + channel, 0, ( void * ) 0 , &status ) == CONAOK )
	{
		return status.numBytes;
	}
}

long ReadChannel( int channel, const char * buffer, long size )
{
	long numRead = 0;
	long amountRead = 0;
	if( ASEBios( ReadChannelBuffer + channel, size, buffer, &numRead ) == CONAOK )
	{
		amountRead = numRead;
	}
	return amountRead;
}

void WriteChannel( int channel, char * buffer, long size )
{
	long numWritten = 0;
	while( size )
	{
		long amountWritten = 0;
		if( ASEBios( WriteChannelBuffer + channel, size, buffer + numWritten, &amountWritten ) == CONAOK )
		{
			numWritten += amountWritten;
			size -= amountWritten;
		}
	}
}

int main( void )
{
	for( ; ; )
	{
		long numBytes = GetBytesAvailable( VSERIAL );
		if( numBytes )
		{
			char Buffer[ MAX_DATA ];
			long numRead = ReadChannel( VSERIAL, Buffer, MAX_DATA );
			if( numRead )
			{
				WriteChannel( VSERIAL, Buffer, numRead );
			}
		}

	}
	return 0;
}


