/*
	Window function definitions.
	8 Jan 92

NOTE: WINDOW functions compiled using pascal parameter passing convention.
*/

#define WINDOW struct _window		/* and this too (defined below) */
#define NOWINDOW ((struct _window *)0)

/* -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- */

/* IBM PC screen memory cell structure. */

struct _cell {
	unsigned char character;
	unsigned char attribute;
};

#define LINES 25			/* number of lines */
#define COLUMNS 80			/* number of columns (hence line-to-line offset) */
#define CELLS (LINES * COLUMNS)		/* total character cells */

/* Character attributes, bit mapped:

       +------------------- character blink 
       |   +--------------- background color/palette
       |   |   +----------- intensity
       |   |   |   +------- foreground color/palette
       |   |   |   |
       + --+-- + --+--
       x b b b i f f f
*/
#define A_BLINK 0x80			/* blinking (yuck) */
#define A_BRIGHT 0x08			/* high intensity */
#define A_BBG 0x07			/* black background, white foreground */
#define A_WBG 0x70			/* white background, black foreground */

#define A_NORMAL (A_BBG)		/* "normal" white on black */
#define A_REVERSE (A_WBG)		/* reverse video */

/* Funny characters used in drawing windows. */

#define C_NULL 0			/* ASCII null */
#define C_DOTS 177			/* half dotted */
#define C_BLANK 32			/* white-space character */
#define C_CTRDOT 250			/* nice small centered dot */
#define C_THINVERT 179			/* thin vertical bar */
#define C_THICKLEDGE 221		/* thick vertical left edge */
#define C_THICKREDGE 222		/* thick vertical right edge */

/* Box drawing characters. */

#define C_DBOXUL 201			/* double box upper left corner */
#define C_DBOXLL 200			/* double box lower left corner */
#define C_DBOXLR 188			/* double box lower right corner */
#define C_DBOXUR 187			/* double box upper right corner */
#define C_DBOXVERT 186			/* double box vertical bar */
#define C_DBOXHORIZ 205			/* double box horizontal bar */

/* Simulator box */

#define C_SBOXUL 218			/* double box upper left corner */
#define C_SBOXLL 192			/* double box lower left corner */
#define C_SBOXLR 217			/* double box lower right corner */
#define C_SBOXUR 191			/* double box upper right corner */
#define C_SBOXVERT 179			/* double box vertical bar */
#define C_SBOXHORIZ 196			/* double box horizontal bar */

/* Fat box -- asssumes it will be in reverse video... */

#define C_FBOXVERT C_BLANK		/* fat box vertical bar */
#define C_FBOXTOP 223			/* fat box top horiz. bar */
#define C_FBOXBOT 220			/* fat box bot. horiz. bar */

/* -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- */

/* Displayed window structure. Windows are all rectangular, and start and end
on character cell boundaries. */

WINDOW {
	short top_line;			/* top-most line number */
	short window_lines;		/* window size, lines */

	short left_col;			/* left-most column */
	short window_cols;		/* window size, cols */

	char def_attribute;		/* default attribute */
	char box_type;			/* box type, or left edge -- see below */

	char *text;			/* initialization text or 0 */
	char *text2;			/* additional initialization text or 0 */

	/* ------------- */		/* data that changes (generally not initialized) */

	short bits;			/* various W_ bits -- see below */

	short line;			/* current line number */
	short col;			/* current column */
	short lines;			/* text window lines (and bound; 0 - N) */
	short cols;			/* text window columns (and bound; 0 - N)  */
	short line_off;			/* offset to first line (if box) */
	short col_off;			/* offset to first col (if edge/box) */

/* These are for linkage to data items being edited/displayed. */

	int origin;			/* first data item # displayed in window */
	int item;			/* data item # being edited (line) */
	int index;			/* index into data item being edited (col) */
	int active_line;		/* window line where editing is taking place */
	int active_col;			/* ditto first column data is assumed to fit!) */

	char attribute;			/* current attribute */
	char cursor_height;		/* video cursor starting line (see below) */
	char orig_height;		/* previous cursor height */
	char far *buff;			/* *FAR* ptr to under-window save buffer */
	struct _window *next_window;	/* ptr to next window in list (else 0) */
};

/* .box_type definitions. All other non-zero values indicate a
left-edge character. */

#define W_NONE 0			/* no box or left edge */
#define W_DOUBLEBOX 1			/* double bar box */
#define W_SIMBOX 2			/* hash mark box (simulation control screens) */
#define W_HBARS 3			/* fat horiz. bars */
#define W_EDGES 4			/* thick left and right edges */
#define W_EDGES2 5			/* thin left edge, thick left edge */
#define W_FEDGES 6			/* fat edges only */
#define W_NOTSIMBOX 7			/* "not simulated" box */

/* boxtype modifiers -- OR'd into box_type. */

#define W_FULLBOX 128			/* do not use default margins */
#define W_BOXTYPEMASK (~(W_FULLBOX))

/* Bits in the bits field. */

#define W_ACTIVE 1			/* 1 == on screen (else 0) */

/* Cursor size definition. The cursor size is specified as scan lines in 
a cell; we hard-code the bottom scan line, and the top scan line is
bottom - height. (We assume that for all cursors the bottom scan line
should be lit.) */

#define CURSOR_BOTTOM 6		/* last scan line */

/* -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- -*-*- */

/* WINDOW1.C */

void pascal init_window(WINDOW *);
void pascal addwindow(WINDOW *);
void pascal removewindow(WINDOW *);
void pascal unlinkchain(WINDOW *);
WINDOW *pascal lastwindow(WINDOW *);

void pascal statbox(char *);
void pascal momentary(char *);
void pascal indefinite(char *);

int pascal active(WINDOW *);
void pascal activate(WINDOW *);
void pascal deactivate(WINDOW *);

/* WINDOW2.C */

void cdecl w_printf();			/* NOTE not pascal! */
void cdecl p_printf();			/* NOTE not pascal! */
void pascal cursoroff(void);
void pascal w_pos(WINDOW *, short, short);
void pascal w_fill(WINDOW *, char *);
void pascal w_string(WINDOW *, char *);
void pascal w_fieldtext(WINDOW *, char *, int);
void pascal wrap_char(WINDOW *, char);
void pascal p_windowset(WINDOW *);
void pascal p_pos(short, short);
void pascal p_char(char);
void pascal p_chara(char, char);
void pascal p_fill(char *);
void pascal p_string(char *);
void pascal p_fieldtext(char *, int);
void pascal pwrap_char(char);
void pascal p_scrollup(int, int);
void pascal p_scrolldn(int, int);
void pascal p_clreol(void);
void pascal p_cursor(void);

/* WINDOW3.C */

void pascal box_window(WINDOW *);
void pascal w_save(WINDOW *);
void pascal w_restore(WINDOW *);

void pascal w_char(WINDOW *, char);
void pascal w_chara(WINDOW *, char, char);
void pascal w_charal(WINDOW *, char, char);

void pascal w_dim(WINDOW *);
void pascal w_bright(WINDOW *);
void pascal w_reverse(WINDOW *);
void pascal w_unhighlight(WINDOW *);
void pascal w_attr(WINDOW *, char);

void pascal highlight(WINDOW *);
void pascal unhighlight(WINDOW *);
void pascal vhighlight(WINDOW *, int);

void pascal w_cursor(WINDOW *);
void pascal w_blink(WINDOW *);
void pascal w_unblink(WINDOW *);

void pascal w_scrollup(WINDOW *, int, int);
void pascal w_scrolldn(WINDOW *, int, int);
void pascal w_clreol(WINDOW *);

/* WINDOW4.ASM */

void cdecl wininit(void);
char cdecl getcursheight(void);

struct _cell far *cdecl toaddr(unsigned short, unsigned short);
struct _cell far *cdecl rptchar(struct _cell far *, char, char, unsigned short);
