/***
*bios.h - declarations for bios interface functions and supporting definitions
*
*	Copyright (c) 1987-1990, Microsoft Corporation.  All rights reserved.
*
*Purpose:
*	This file declares the constants, structures, and functions
*	used for accessing and using various BIOS interfaces.
*
****/

#ifndef _MT

/* manifest constants for BIOS serial communications (RS-232) support */

/* serial port services */

#define _COM_INIT	0x00	/* init serial port */
#define _COM_INITX	0x01	/* init serial port (with X parameter) */
#define _COM_GETDTL	0x02	/* get data length */
#define _COM_SEND	0x03	/* send character */
#define _COM_RECEIVE	0x04	/* receive character */
#define _COM_COMMAND	0x05	/* get command status */
#define _COM_STATUS	0x06	/* get serial port status */

/* select port */

#define _COM_CH1		0x01	/* default port */
#define _COM_CH2		0x02	/* expansion board's port */
#define _COM_CH3		0x03	/* expansion board's port */

/* serial port initializers.  One and only one constant from each of the
 * following four groups - character size, stop bit, parity, and baud rate -
 * must be specified in the initialization byte.
 */

/* character size initializers */

#define _COM_CHR7		0x08	/* 7 bits characters */
#define _COM_CHR8		0x0C	/* 8 bits characters */

/* stop bit values - on or off */

#define _COM_STOP1		0x40	/* 1 stop bit */
#define _COM_STOP2		0xC0	/* 2 stop bit */

/*  parity initializers */

#define _COM_NOPARITY		0x00	/* no parity */
#define _COM_ODD		0x10	/* odd parity */
#define _COM_EVEN		0x30	/* even parity */

/*  baud rate initializers */

#define _COM_DEFAULT		0xFF	/* default baud */
#define _COM_75			0x00	/* 75 baud */
#define _COM_150		0x01	/* 150 baud */
#define _COM_300		0x02	/* 300 baud */
#define _COM_600		0x03	/* 600 baud */
#define _COM_1200		0x04 	/* 1200 baud */
#define _COM_2400		0x05 	/* 2400 baud */
#define _COM_4800		0x06 	/* 4800 baud */
#define _COM_9600		0x07 	/* 9600 baud */

/* command */

#define _COM_TXEN		0x01	/* transmission enable */
#define _COM_DTR		0x02	/* data terminal ready */
#define _COM_RXEN		0x04	/* enable to receive */
#define _COM_SBRK		0x08	/* send brake character */
#define _COM_ER			0x10	/* error reset */
#define _COM_RTS		0x20	/* request to send */
#define _COM_IR			0x40	/* internal reset */

struct com_t {
	unsigned buad;
	unsigned mode;
	unsigned command;
	unsigned tx_time;
	unsigned rx_time;
	unsigned size;
	void _far *buffer;
};

/* manifest constants for BIOS disk support */

/* disk services */

#define _DISK_READ		0x06	/* disk read */
#define _DISK_WRITE		0x05	/* disk write */
#define _DISK_SEEK		0x10	/* seek disk sector */
#define _DISK_RECALIBRATE	0x07	/* recalibrate */
#define _DISK_FORMATTRACK	0x0D	/* format track */
#define _DISK_INITIALIZE	0x03	/* initialize */
#define _DISK_VERIFY		0x01	/* verify disk sector */
#define _DISK_SENSE		0x04	/* sense disk sector */
#define _DISK_READID		0x0A	/* read ID */
#define _DISK_WRITEDDAM		0x09	/* write deleted data */
#define _DISK_FORMATDRIVE	0x8D	/* format drive */
#define _DISK_ALTERNATE		0x08	/* assign alternate track */
#define _DISK_BADTRACK		0x0B	/* format bad track */
#define _DISK_READDDAM		0x0C	/* read deleted data */
#define _DISK_DIAGNOSTIC	0x02	/* read diagnostic */
#define _DISK_RETRACT		0x0F	/* retract */
#define _DISK_OPMODE		0x0E	/* set operation mode */

#define	_CMD_2HD		0x0090	/* 1MB flopy disk */
#define	_CMD_2DD		0x0070	/* 640KB flopy disk */
#define	_CMD_2D			0x0050	/* 320KB flopy disk */
#define	_CMD_HD			0x0080	/* hard disk */

#define	_CMD_SEEK		0x1000	/* seek operation */
#define	_CMD_MF			0x4000	/* double-density / single-density */
#define	_CMD_MT			0x8000	/* multi track / single track */
#define	_CMD_RETRY		0x2000	/* retry operation */

/* struct used to send/receive information to/from the BIOS disk services */

#ifndef _DISKINFO_T_DEFINED

struct diskinfo_t {
	unsigned command;
	unsigned drive;
	unsigned head;
	unsigned cylinder;
	unsigned data_len;
	unsigned sector_len;
	unsigned sector;
	unsigned nsectors;
	void _far *buffer;
	void _far *result;
	};

#define _DISKINFO_T_DEFINED

#endif

/* manifest constants for BIOS keyboard support */

/* keyboard services */

#define _KEYBRD_READ		0x00	/* read next character from keyboard */
#define _KEYBRD_READY		0x01	/* check for keystroke */
#define _KEYBRD_SHIFTSTATUS	0x02	/* get current shift key status */
#define _KEYBRD_INITIALIZE	0x03	/* init keyboard interface */
#define _KEYBRD_SENSE		0x04	/* sense key input status */

/* manifest constants for BIOS printer support */

/* printer services */

#define _PRN_INIT		0x10	/* initialize printer */
#define _PRN_WRITE		0x11	/* write character to printer */
#define _PRN_STRING		0x30	/* write strings to printer */
#define _PRN_STATUS 		0x12	/* get printer status */

/* manifest constants for BIOS time of day support */

/* time of day services */

#define _TIME_GETCLOCK		0x00	/* get current clock count */
#define _TIME_SETCLOCK		0x01	/* set current clock count */


#ifndef _REGS_DEFINED

/* word registers */

struct WORDREGS {
	unsigned int ax;
	unsigned int bx;
	unsigned int cx;
	unsigned int dx;
	unsigned int si;
	unsigned int di;
	unsigned int cflag;
	};

/* byte registers */

struct BYTEREGS {
	unsigned char al, ah;
	unsigned char bl, bh;
	unsigned char cl, ch;
	unsigned char dl, dh;
	};

/* general purpose registers union -
 *  overlays the corresponding word and byte registers.
 */

union REGS {
	struct WORDREGS x;
	struct BYTEREGS h;
	};

/* segment registers */

struct SREGS {
	unsigned int es;
	unsigned int cs;
	unsigned int ss;
	unsigned int ds;
	};

#define _REGS_DEFINED

#endif /* _REGS_DEFINED */


/* function prototypes */

unsigned _cdecl _bios_disk(unsigned, struct diskinfo_t *);
unsigned _cdecl _bios_equiplist(void);
unsigned _cdecl _bios_keybrd(unsigned, unsigned char *);
unsigned _cdecl _bios_memsize(void);
unsigned _cdecl _bios_printer(unsigned, unsigned char *);
unsigned _cdecl _bios_serialcom(unsigned, unsigned, struct com_t *);
unsigned _cdecl _bios_timeofday(unsigned, char *);
int _cdecl int86(int, union REGS *, union REGS *);
int _cdecl int86x(int, union REGS *, union REGS *, struct SREGS *);

#endif /* _MT */
