/*
 *  RTERM.H
 *		Header file for RTERM.C - Terminal emulator for iRMX
 */
#define TRUE    0xff
#define FALSE   0x0

#define	NULLPTR			((void *) 0)
#define MK_FP(seg, off) ((void far*) ((unsigned long) (seg)<<16 | (off)));

#define MAXSTR		256	// Max buffer size
#define VMASK		0x30	// Bit mask for testing
#define VPORT		0x410	// Port for equipment status
#define MAXPAGE		8	// Max video pages
#define DOWN		0x07	// Scroll direction
#define UP		0x06

#define	OUTPUTSTOPPED		0x1
#define	SCROLLFLAG		0x1
#define	NUMFLAG			0x2
#define	CAPSFLAG		0x4
#define	ALTFLAG			0x10
#define	CTLFLAG			0x20
#define	SHIFTFLAG		0x40
#define	LF			0xa
#define	CLOSEALTKEY		0xb8
#define	CONTROLQ		0x11
#define	CONTROLS		0x13
#define	BREAKTYPEOFFSET		8
#define	HIGHESTSCANCODE		83	// Support only 84 scan codes
#define	NKEYCODES		84
#define	NORMFUNCTMIN		0x3b	// Normal F1 to F10 keys
#define	NORMFUNCTMAX		0x44
#define	SHCTFUNCTMIN		0x54	// Shift or Control plus
#define	SHCTFUNCTMAX		0x67	// a function key F1 to F10
/*
 * NUL character indicate that the system or application should
 *  interpreted the following character as a special function code.
 */
#define	FUNCTIONKEYCODE		0x0
#define	BREAKCONTACT		0x80
#define	TOGGLELEDCMD		0xed
#define	INDICATORBITS		0x7
#define	INPUTINTERRUPT		0x1

#define	CRTCOLS			80
#define	LASTCOL			79
#define	CRTROWS			25
#define	LASTROW			24
#define	SCREENLENGTH	 (25 * 80) 	// length is 80 * 25

#define	DEFAULTRAWSIZE		256
#define	DEFAULTRAWMASK		255

/* values for console state */

#define	RAWMODE			0x80
#define	LITERALMODE		0x40
#define	CANCELOUTPUT		0x10
#define	MONOINDEXREG		0x3b4	// monochrome
#define	COLORINDEXREG		0x3d4	// CGA adapter
#define	CMOSADDRESS		0x70	// CMOS RAM address
#define	CMOSDATA		0x71
#define	CMOSEQUIPBYTE		0x14
#define	DISPLAYABLECHAR		0x20
#define	BLANKCHARACTER		0x20
#define	DEFAULTATTRIB		0x700	// attribute is white on black
#define	DATAREGOFFSET		0x1
#define	MODEREGOFFSET		0x4
#define	STATREGOFFSET		0x6

//
// All colors can be used as foreground or background color
//

#define BLACK     0 
#define BLUE      1
#define GREEN     2
#define CYAN      3
#define RED       4
#define MAGNETA   5
#define BROWN     6
#define WHITE     7
#define GRAY      8
#define LBLUE     9
#define LGREEN    10
#define LCYAN     11
#define LRED      12
#define LMAGENTA  13
#define YELLOW    14
#define LWHITE    15

#define HI_INTENS  0x08
#define NO_BLINK   0x7f

short  Num_chars;
char   Temp_str[29];              // Temporary buffer for queuing inputs

int Temp_Buff[SCREENLENGTH + 2];  // Temp. buffer to transfer screen data

int save_buffer[4000];            // place to save the DOS screen (not used)
int far *save_buff;               // far address of save_buffer

unsigned int far *bflag_ptr = (unsigned far *) 0x00000472;

unsigned int far *src_ptr;
unsigned int far *des_ptr;
unsigned int far *temp_ptr;
unsigned int tmp = 0;

static unsigned int forground, background;
static unsigned int index;
static unsigned char X_char;
static unsigned char Stop_output;
static unsigned int temp;
static unsigned char *dinfop;
static unsigned int temp_w;
static unsigned int t_count;

typedef int DISPL_MEM[80];
DISPL_MEM far *video_p;

typedef struct {
                  char flag_byte;
                  char data_byte;
                } OUT_BUFFER;

typedef struct {
                  char count;
                  char data_byte[29];
                } IN_BUFFER;

static struct
{
	unsigned int displayw;
	unsigned char column;
	unsigned char row;
	unsigned char mode;
	unsigned char page;
	unsigned long crtlen;
	unsigned char console_state;
	unsigned char routine_index;
	unsigned int output_state;
} r_term;
