/*
	PC/AT bios service routine header
		T.Tsuda. , DSA	April 21,1995
*/


#ifdef	PCBIOS
#define	EXTERN
#else
#define	EXTERN	extern
#endif


#ifdef	PCBIOS
#define	PC_VIDEO	0x10
#define	PC_COMM	0x14
#define	PC_KEYB	0x16
#endif


/*	scan code and character of pckey() return code	*/
#define	CURSUP	0x4800
#define	CURSLEFT	0x4b00
#define	CURSRIGHT	0x4d00
#define	CURSDOWN	0x5000
#define	INSERT	0x5200
#define	DELETE	0x5300
#define	BACK	0x0e08
#define	HOME	0x4700
#define	END		0x4f00
#define	PAGEUP	0x4900
#define	PAGEDOWN	0x5100
#define	ENTER	0x1c0d
#define	ESCAPE	0x011b


/*	cursor type of curstype()	*/
#define	CURSOFF	0
#define	CURSLIN	1
#define	CURSBOX	2


/*	macros	*/
#ifndef max
#define	max(a,b)    (((a) > (b)) ? (a) : (b))
#endif

#ifndef min
#define	min(a,b)    (((a) < (b)) ? (a) : (b))
#endif

#define	isjis1(c)	(((0x81 <= (c)) && ((c) <= 0x9f)) || ((0xe0 <= (c)) && ((c) <= 0xfc)))
/*	Determines whether or not character is a jis 1st byte	*/

#define	isjis2(c)	(((0x40 <= (c)) && ((c) <= 0x7e)) || ((0x80 <= (c)) && ((c) <= 0xfc)))
/*	Determines whether or not character is a jis 2nd byte	*/


/*	function of prottypes	*/

int	pckey(int operate);
/*
description
	Executes BIOS interrupt number 0x16, the keyboard interface routine.
	The operate argument may specify any of the following operations.
	operation	meaning
		0		Wait for the next key to be pressed. Return the scan code
				and character generated.
		1		Test whether or not a key is pressed. If yes, return the
				scan code and character generated (key remains in keyboard
				input buffer). If no, return 0.
		2		Returns the currect status of the following keys in the
				lower 8 bits of the return value.
*/

int	pcgvmode(void);
/*
description
	Get current video mode
*/

void	pcsvmode(int mode);
/*
description
	Set video mode
*/

void	curstype(int type);
/*
description
	set cursor type
*/

void	poscurso(int row,int col);
/*
description
	positions the cursor to the specified row and col on the screen
*/

int	cursorow(void);
/*
description
	Returns the row position of the cursor on the screen
*/

int	cursocol(void);
/*
description
	Returns the column position of the cursor on the screen
*/

unsigned char	readchr(void);
/*
description
	Reads the character at the current cursor position
*/

unsigned char	readatt(void);
/*
description
	Reads the attribute of the character at the current cursor position
*/

void	writechr(int chr,int n);
/*
description
	Writes n copys of the character chr starting at the current cursor position
*/

void	writecha(int chr,int attr,int n);
/*
description
	Writes n copys of the character chr with attribute attr starting at the
	current cursor position
*/

void	putstr(char *str,int length);
/*
description:
	put string to screen
	if length <= 0 length is length of character
returns: none
*/

void	putbstr(char *str,int length);
/*
description:
	put length bytes of characters in the string str to screen
returns: none
*/

void	putsa(char *str,int attr,int length);
/*
description:
	put string to screen with the attribute
	if length <= 0 length is length of character
returns: none
*/

unsigned long	strtounl(char *str,char **scanstop,int base);
/*
description
	Converts the characters in the string str to an unsigned long integer
	value. The characters in str should represent an integer constant in the
	specified number base. The base argument determines the set of valid
	digits. The base argument must be either 0 or a value between 2 and 36.
*/

int	getcdisk(void);
/*
description
	Gets the current disk drive
*/

int	setcdisk(int drive);
/*
description
	Sets the current disk drive
*/

int	getcudir(int drive,char *dirname);
/*
description
	Determines the name of the current directory on the speciried drive
*/

int	isdbcs(void);
/*
description
	Determines whether or not mode is DBCS mode
returns
	non-zero (true) if mode is DBCS mode
*/


/*	comm port functions	*/

	/* BIOS initialize (BX) */
#define	COMNPAR	0x0000
#define	COMOPAR	0x0100
#define	COMEPAR	0x0200
#define	COMSOPAR	0x0300
#define	COMSEPAR	0x0400
#define	COM1STOP	0x0000
#define	COM2STOP	0x0001
	/* BIOS initialize (CX) */
#define	COM5BIT	0x0000
#define	COM6BIT	0x0100
#define	COM7BIT	0x0200
#define	COM8BIT	0x0300
#define	COM110	0x0000
#define	COM150	0x0001
#define	COM300	0x0002
#define	COM600	0x0003
#define	COM1200	0x0004
#define	COM2400	0x0005
#define	COM4800	0x0006
#define	COM9600	0x0007
#define	COM19200	0x0008

	/* port status (AH) */
#define	COMERR	0x8000
#define	COMTOUT	0x8000
#define	COMTSRE	0x4000
#define	COMTDRE	0x2000
#define	COMBREAK	0x1000
#define	COMFER	0x0800
#define	COMPER	0x0400
#define	COMORE	0x0200
#define	COMRDRF	0x0100

	/* modem status (AL) */
#define	COMCD	0x0080
#define	COMRI	0x0040
#define	COMDSR	0x0020
#define	COMCTS	0x0010
#define	COMCCD	0x0008
#define	COMCRI	0x0004
#define	COMCDSR	0x0002
#define	COMCCTS	0x0001

	/* modem control register (BL) */
#define	COMLOOP	0x10
#define	COMOUT2	0x08
#define	COMOUT1	0x04
#define	COMRTS	0x02
#define	COMDTR	0x01

unsigned int	comminit(int comm,int paristop,int wordbps);
unsigned int	commsend(int comm,int chr);
unsigned int	commrecv(int comm,int *chr);
unsigned int	commstat(int comm);
unsigned int	commcrrd(int comm,int *creg);
unsigned int	commcrwr(int comm,int creg);


#undef	EXTERN
