/* header file for windowing system 
*
*	(c) Marietta Systems, Inc.  1987
*	All rights reserved
*
*   Global variables for the windowing system.
*	
*	Do not change these! 
*		
*/
#ifndef LATTICE
typedef unsigned char byte;
#define _STACK _stklen
#define fileclose fileclos
#define filewrite filewrit
#endif
/*	
*/
long _SIZMEM = 0;
int SAVEWAIT = 900, A_TRACK = -1;
unsigned SCRN_PTR, CLR_PTR = 0X0000, _DSEG, _DOFF, CLR_SEG = 0XB800, 
	MONO_SEG = 0XB000;
short SCR_SIZE, OLD_CODE, _brkflag;
byte INCHAR = 32, INCHAR_F = 0, _D_ERROR = 0, _D_MSG = 0, FN_DEBUG = 0; 
byte INS_FLAG = 1, CLR_INIT = 0, W_NUM = 0, BUG_TEST = 0, MEM_TEST = 0;
byte COLOR_SC = 0, EGA_SCRN = 0, CLR_CODE = 0 , *MEM_LINE, CLR_TONE = 1;
enum fld_type {alphanum, graphic, flag, boolean, calendar, numeric, value, 
	real, chrono};
enum COLOR_OF  {black,blue,green,cyan,red,magenta,yellow,white};
enum _JUST {left,right,as_typed,center,code,decimal,c_number,date,time};
enum ATTRIB {low,high,reverse,blink,blank,alt_low,alt_high,alt_reverse} 
	OLD_BRIG = low;
enum F_READ {firstrec, previous, nextrec, lastrec, random, relative};
enum F_MODE {append, readonly, recreate, update};
enum F_TYPE {ascii, binary, dbase3, hashed, marietta};
struct CURSR {byte X,Y;} _CURSOR; /* Current cursor position in window */
struct WINDW {  /* window tracking struct */
	byte X, Y, H, W, P, *SCREEN, *FUNCTION;
	int CODE;
	} *WINDOW;
struct CLR_TYPE {
	enum COLOR_OF FORE, BACK;
	int ALT_CLR;
	};
struct DBF_DEF{ /* dBase III Plus data dictionary struct */
	byte dbf_name[11], dbf_type, dbf_len, dbf_dec, dbf_set, dbf_dig;
	byte dbf_fill[16];
	};
struct F_DEF { /* file definition control struct */
	long prime, location, r_count;
	int key_len, offset, start, rec_len, fbloc;
	enum F_TYPE ftype;
	byte keycode, *fptr, *record, write;
	char fname[13];
	char *fnext; /* pointer to data dictionary */
	} FN[20];
/*
*	Configuration constants
*
*	Change their initial value to suit your set-up
*		- but be careful!!
*
*/ 
struct CLR_TYPE COLOR [7] = {	/* number of elements must match 
                                   "_COLOR" config constant */
		{green, black, 6},	    /* base window color, #0 */
		{white, blue, 3},	    /* color #1 */
		{cyan, black, 4},	    /* color #2 */
		{cyan, red, 5},		    /* color #3 */
		{white, magenta, 2},    /* color #4 */
		{yellow, black, 1},	    /* color #5 */
		{white, red, 0},	    /* color #6 */
				};
struct CLR_TYPE	TOP_CLR = {yellow,magenta,6}; /* top line color */
struct CLR_TYPE	ER_COLOR = {green,red,6};    /* bottom line color */
/*		*/
enum ATTRIB ACC_DISP = reverse; /* Attribute of accept fields after entry */
byte ERR_BEEP = 2;	/* For beep length with 'disp_err', 0 = tiny beep */
byte UP_NAME = 0;	/* 1 if names are to be in uppercase only */
byte FLD_FULL = 1;  /* 1 for auto ENTER on full field; 0 = ENTER required */
byte TAB_SET = 4;	/* size of tab increments on screen for '\t' code */
byte _WINDW = 10;	/* maximum number of windows */
byte _COLOR = 7;	/* maximum number of different color selections */
byte SCRN_LEN = 25; /* screen length in lines */
byte SCRN_WID = 80;  /* screen width in columns */
byte TOP_LINE = 1; /* lines dedicated to the "top-frame" at top of screen */
byte MAXFILES = 20; /* maximum number of files for operating system */
byte D_FORMAT = 'U'; /* U for USA format, E for european, I for intl */
byte D_PUNCT = '/';	 /* punctuation character for date formats */
byte D_20XX = 10;    /* split between 20xx and 19xx in years */
byte PERIOD = '.';	 /* decimal point character */
byte COMMA = ',';	 /* thousands seperator */
byte BOOL_YES = 'Y'; /* The TRUE or YES boolean entry code */
byte BOOL_NO = 'N';  /* The FALSE or NO boolean entry code */
char *xgoodbye;
unsigned KEYMATCH[8] /* the key match array which determines which
                        function keys are treated as 'end-of-field'
                        keys by the 'isendch' function */
    = {0X428, 0X584, 0X0, 0X0, 0X0, 0X0, 0X0, 0X0};	
         /* this activates all basic cursor related function keys :
         Pgup, Up, Pgup, Home, Down, End, Ctrl+Enter
         */ 
int DISCBLCK = 512; /* maximum record size of any file to be opened,
               Minimum size is 65, but recommended minimum is 256.  */
short MEM_WARN = 4096; /* Warning will be issued when unused heap memory is
	                      under this.  Maximum is 9999, minimum is 2048 */
long MAX_WIND = 15000L;	/* maximum amount of heap space for windowing 
               functions. The minimum size of MAX_WIND should be 8500.
			   To calculate, use the formula :-
			   ((number of windows * average size * 2) + 2500)
			     where 'average size' is (height * width)
				   	 */
long _MNEED = 20000L; /* minimum heap space to be allocated, which must be 
               at least MAX_WIND + 5000. */
unsigned _STACK = 10000; /* size of stack, (at least 5000) */
/* 
*
* 	This section contains the #define codes 
*	
*/
#define CTL_A     1 /* all the other CTL combinations can be defined here */
#define PGDN      3
#define CRS_RT    4 /* Right cursor */
#define CRS_UP    5 /* Up cursor */
#define DEL       7
#define B_SPACE   8
#define TAB       9
#define CTL_ENT  10
#define SFT_TAB  11
#define ENTER    13
#define PGUP     18
#define CRS_LT   19 /* Left cursor */
#define CTL_BSPC 20 /* Ctrl + backspace */
#define INS      22
#define HOME     23
#define CRS_DN   24 /* Down cursor */
#define END      26
#define CTL_Z    26 /* 0X1A */
#define ESC      27
#define ALT_Q   129 /* The other ALT alpha keys can be defined here */
#define ALT_P   138 /* Print translated screen */
#define QUIT_NOW 158 /* Alt+X used for fast terminate of program */
#define ALT_M   163
#define HELP    168 /* F1 Key  */
#define UNDO    169 /* F2 Key  */
#define SEARCH  170 /* F3 Key  */
#define MOVE    171 /* F4 Key  */
#define INSERT  172 /* F5 Key  */
#define DELETE  173 /* F6 Key  */
#define ZOOM    174 /* F7 Key  */
#define AMEND   175 /* F8 Key  */
#define KEY_CH  176 /* F9 Key  */
#define QUIT    177 /* F10 Key */
/* 174 thru 218 reserved for standard graphics characters */
#define SFT_F1  220 /* The other SHIFT+Fnn keys can be defined here */ 
#define SFT_F10 229
#define CTL_LT  248 /* Ctrl + left cursor */
#define CTL_RT  249 /* Ctrl + right cursor */
#define CTL_END 250
#define CTL_PGDN 251
#define CTL_HOME 252
#define CTL_PGUP 254
/* 		*/
#define DELETED 0X2A /* '*' code has dBase 3+ compatibility */
#define IN_USE  0X20 /* ' ' code has dBase 3+ compatibility */
#define EMPTY   0X26 /* '&' code, for hashed files */
#define SYS_REC 0X03 /* code has dBase 3+ compatibility */
/*		*/
#define MFALSE  128
#define MTRUE   129
/* 
*
*	The external functions used by windowing software	
*
*/
extern int   accept(byte*,enum _JUST,enum ATTRIB,int,int);
extern void  box_scrn(void);
extern void  check_f(void);
extern void  clr_scrn(char*);
extern void  clr_wndw(void);
extern byte*  concat(byte*,int);
extern int   datecomp(char*,char*);
extern long  datelong(char*);
extern void  datemath(char*,int);
extern void  dateread(char*);
extern void  date_in(char*,char*);
extern void  date_out(char*,char*);
extern int   dbf_fld(int);
extern void  display(byte*,int,int,enum ATTRIB);
extern void  disp_err(char*,int);
extern void  disp_msg(char*,int);
extern byte  disp_qry(char*);
extern int   fileback(char*);
extern int   fileclos(int);
extern int   filedbf(int,struct DBF_DEF**);
extern int   fileinit(int,unsigned,unsigned,long);
extern int   fileopen(char*,enum F_TYPE,enum F_MODE);
extern int   fileread(int,enum F_READ,long*);
extern int   fileseek(int,long);
extern int   filewrit(int,long*);
extern int   file_err(int,int);
extern int   fld_len(enum _JUST,int,int);
extern void  goodbye(short); 
extern byte  grabchar(void);
extern int   hashmake(char*,unsigned,unsigned,long,unsigned,unsigned);
extern long  hashread(int,byte*,int);
extern void  helpmenu(int);
extern int   helpscrn(byte*);
extern void  idleloop(int);
extern int   isendch(byte*,byte,enum ATTRIB);
extern void  justify(enum _JUST,byte*,byte*,int,int);
extern int   menu(char*,int,int,int);
extern int   mk_wndw(int,int,int,int,byte*);
extern int   mrtbrk(void);
extern long  primenbr(long);
extern void  prn_scrn(void);
extern void  read_kb(void);
extern int   rm_wndw(void);
extern void  scrnsave(int);
extern void  scrn_map(byte*,int,int);
extern void  scroll(int,int);
extern void  set_clr (int,enum ATTRIB);
extern void  set_crsr (int,int);
extern int   top_menu(char*,int,int);
extern void  top_spot(int);
extern int   validate(byte*,enum _JUST,int,int);
extern int   v_bool(char);
extern void  warble(int);
/* 	end of header file */