/**
*
*  BSCREENS.H	Header file for Turbo C TOOLS Screen Functions
*
*  Version 6.00 (C) Copyright Blaise Computing Inc. 1983, 1987-1989
*
**/

#ifndef DEF_BSCREENS		      /* Prevent second reading of    */
#define DEF_BSCREENS 1		      /* these definitions.	      */

#include <butil.h>

#define  SC_BIOS_INT  16	      /* BIOS interrupt for screen    */
				      /* functions.		      */

#define  NORMAL     7		      /* Common attributes for the    */
#define  REVERSE    112 	      /* monochrome adapter	      */
#define  UNDERLINE  1
#define  INTENSITY  8
#define  MONOBLINK  128

#define  SC_BLACK   0		      /* (Byte) values representing   */
#define  SC_BLUE    1		      /* color attributes.	      */
#define  SC_GREEN   2
#define  SC_CYAN    3
#define  SC_RED     4
#define  SC_MAGENTA 5
#define  SC_BROWN   6
#define  SC_WHITE   7

    /* Maximum dimensions of usual PC screens			      */

#define  PC_ROWS      25
#define  PC_COLS      80
#define  LAST_ROW     (PC_ROWS - 1)
#define  LAST_COL     (PC_COLS - 1)
#define  PC_BIG_ROWS  50
#define  MAX_DEVICES  2 	      /* Color and/or monochrome      */
#define  MAX_PAGES    8 	      /* Pages per video adapter      */
				      /* (8 maximum on EGA)	      */

    /* Scrolling directions					      */

#define  SCR_UP      0
#define  SCR_DOWN    1
#define  SCR_RIGHT   0
#define  SCR_LEFT    1

    /* Options for SCPGCUR					      */

#define  CUR_ADJUST	1     /* Adjust cursor size into normal       */
			      /* limits if appropriate		      */
#define  CUR_NO_ADJUST	0     /* Use requested cursor scan lines      */
			      /* without any adjustment 	      */

    /* Options for writing strings to screen			      */

#define  CUR_BEG     0	      /* Leave cursor at beginning of string. */
#define  CUR_AFTER   1	      /* Leave cursor after end of string.    */
			      /*				      */
#define  CHARS_ONLY  0	      /* Buffer contains characters only.     */
#define  CHAR_ATTR   2	      /* Buffer contains (char,attr) pairs.   */
			      /*				      */
#define  MOVE_CUR    0	      /* Leave cursor according to	      */
			      /*   CUR_BEG/CUR_AFTER bit.	      */
#define  NO_MOVE_CUR 4	      /* Preserve cursor location.	      */

    /* Options for SCBLINK					      */

#define  SC_BLINK    1	      /* Attribute bit 7 == foreground blink. */
#define  SC_INTENSE  0	      /* Attribute bit 7 == background	      */
			      /*   intensity.			      */
#define  SC_INTENSITY  0      /* Synonym for SC_INTENSE.	      */

    /* Error codes						      */

#define  SC_NO_ERROR	0     /* Operation successful.		      */
#define  SC_BAD_OPT	1     /* Video adapter does not support this  */
			      /*  operation.			      */
#define  SC_RANGE	2     /* Value out of range or exceeds	      */
			      /*  dimension.			      */
#define  SC_NO_MEMORY	3     /* Insufficient memory to perform       */
			      /*  operation.			      */

    /* Symbols used by SCEQUIP to indicate the state of the various   */
    /* video adapters						      */

#define  SC_DONT_KNOW  (-1)   /* We haven't checked yet               */
#define  SC_ABSENT     (-2)
#define  SC_MONO       0
#define  SC_COLOR      1

#define  SC_HIFUNC     2      /* PGC in high-function graphics mode   */
			      /*   (not CGA emulation mode)	      */

#define  DONT_KNOW   (SC_DONT_KNOW)
#define  ABSENT      (SC_ABSENT)
#define  HIFUNC      (SC_HIFUNC)


    /* Global variables set by SCEQUIP indicating installed video     */
    /* hardware and switch settings				      */

extern int b_mdpa;   /* Monochrome Display & Printer Adapter	      */
		     /*   SC_DONT_KNOW, SC_ABSENT, or SC_MONO	      */
		     /*   (SC_MONO if Hercules graphics adapter.)     */
		     /* 					      */
extern int b_cga;    /* Color/Graphics Monitor Adapter		      */
		     /*   SC_DONT_KNOW, SC_ABSENT, or SC_COLOR	      */
		     /* 					      */
extern int b_ega;    /* Enhanced Graphics Adapter: SC_DONT_KNOW,      */
		     /*   SC_ABSENT, SC_MONO or SC_COLOR	      */
		     /* 					      */
extern int b_mcga;   /* Multicolor Graphics Array: SC_DONT_KNOW,      */
		     /*   SC_ABSENT, or SC_COLOR		      */
		     /* 					      */
extern int b_vga;    /* Video Graphics Array			      */
		     /*  SC_DONT_KNOW, SC_ABSENT, SC_MONO or SC_COLOR */
		     /* 					      */
extern int b_herc;   /* Hercules monochrome graphics adapter	      */
		     /*   SC_DONT_KNOW, SC_ABSENT, or SC_MONO	      */
		     /* 					      */
extern int b_pgc;    /* Professional Graphics Controller:  SC_ABSENT, */
		     /*   SC_DONT_KNOW, SC_COLOR or SC_HIFUNC	      */

extern int b_mem_ega;	      /* Amount of memory installed on EGA in */
			      /* 1024-byte units:  64, 128, 256       */
			      /*				      */
extern unsigned b_sw_ega;     /* Switch settings on EGA 	      */
			      /* Low-order bit set means SW1 off, etc.*/
			      /* (Bit value 1 implies that	      */
			      /* corresponding switch is off.)	      */

    /* Global variables for managing multiple devices & display       */
    /* pages							      */

extern int b_curpage;	      /* Current display page		      */
extern int b_device;	      /* Current adapter:  SC_DONT_KNOW,      */
			      /*   SC_MONO, or SC_COLOR 	      */

extern int b_know_hw;		      /* Flag stating whether we have */
				      /* yet run SCEQUIP:  0 if no, 1 */
				      /* if yes.		      */

typedef struct			      /* CUR_TYPE structure:	      */
{				      /* high and low scan lines      */
    int high,low;		      /* in a cursor.		      */
} CUR_TYPE;

typedef struct			      /* CUR_INFO structure:	      */
{				      /* State, location and size of  */
    int      off;		      /* a cursor.		      */
    int      row;
    int      col;
    CUR_TYPE size;
} CUR_INFO;

    /* Internal structures for preserving BIOS video variables	      */

typedef struct
{
    int  known; 		      /* 1 if this structure has      */
				      /*  valid data, 0 if not.       */
    int  curpage;		      /* Copy of b_curpage.	      */
				      /*			      */
    char pc_area[30];		      /* Standard PC/XT area.	      */
    char video_area[7]; 	      /* Some video data.	      */
    char far *save_ptr; 	      /* Pointer to EGA variables.    */
    char prtsc_status;		      /* Print screen status byte.    */
} VIDEO_STATE;
extern VIDEO_STATE b_adap_state[2];   /* One entry for SC_MONO, one   */
				      /* for SC_COLOR.		      */

typedef struct			      /* ADAP_STATE structure:	      */
{				      /*   state of the video adapter.*/
    int      mode;		      /* Current video mode.	      */
    int      act_page;		      /* Active (displayed) page.     */
    int      cur_page;		      /* Current page.		      */
    int      rows, columns;	      /* Dimensions of screen.	      */
    int      curs_off;		      /* Cursor on or off.	      */
    CUR_TYPE curs_size; 	      /* Cursor high & low scan lines.*/
} ADAP_STATE;

typedef struct			      /* PAGE_STATE structure:	      */
{				      /*   state of the current page. */
    int  curs_row, curs_column;       /* Location of cursor.	      */
    char *pimage;		      /* Compressed screen image.     */
    int  image_length;		      /* Length of compressed image.  */
} PAGE_STATE;

    /* Turbo C TOOLS functions implemented as macros		      */

#define  scpage(page)  (b_curpage = (page))

    /* Function declarations					      */

char cdecl scequip(void);	      /* Sense hardware environment   */
				      /*			      */
int cdecl  scnewdev(int,int);	      /* Reset and select 25 or 43    */
				      /* line font		      */
				      /*			      */
int cdecl  scchgdev(int);	      /* Select adapter 	      */
				      /*			      */
int cdecl  scmode(int *,int *,int*);  /* Return the video mode info   */
				      /*			      */
int cdecl  scrows(void);	      /* Number of rows on screen     */
				      /*			      */
int cdecl  scpages(void);	      /* Number of pages in this mode */
				      /*			      */
int cdecl  scapage(int);	      /* Display (activate) a page    */
				      /*			      */
void cdecl scpclr(void);	      /* Clear the current page       */
				      /*			      */
int cdecl scclrmsg(int,int,int);      /* Clear a message	      */
				      /*			      */
int cdecl  sccurset(int,int);	      /* Set the cursor position      */
				      /*			      */
int cdecl  scpgcur(int,int,int,int);  /* Alter the cursor size on     */
				      /* current page.		      */
				      /*			      */
int cdecl  sccurst(int *,int *,int *, /* Return position & size of    */
		   int *);	      /* cursor on current page.      */
				      /*			      */
char cdecl scread(int *,int *);       /* Read character and attribute */
				      /*			      */
int cdecl  scattrib(int,int,char,     /* Set the display attributes   */
		    unsigned);	      /*			      */
				      /*			      */
int cdecl  scwrite(char,unsigned);    /* Write copies of a character  */
				      /*			      */
int cdecl  scttywrt(char,int);	      /* Write character TTY-style    */
				      /*			      */
int cdecl  scbox(int,int,int,int,     /* Draw a box		      */
		 int,char,int);       /*			      */
				      /*			      */
void cdecl scttywin(int,int,int,int,  /* Write character TTY-style to */
	      char,int,int,int,int);  /* rectangular region.	      */
				      /*			      */
void cdecl scwrap(int,int,int,int,    /* Write to rectangular region  */
      int,const char *,int,int,int);  /* with word wrap 	      */
				      /*			      */
int cdecl  scblink(int);	      /* Choose role of attribute bit */
				      /* 7:  foreground blink or      */
				      /* background intensity.	      */
				      /*			      */
int cdecl  scpalett(const char *);    /* Load EGA palette registers.  */
				      /*			      */
int cdecl  scpal1(unsigned,unsigned); /* Load individual EGA palette  */
				      /* register.		      */
				      /*			      */
int cdecl  scborder(unsigned);	      /* Set screen border color.     */
				      /*			      */
int cdecl  scmode4(int,int);	      /* Set mode 4 palette and       */
				      /* background color.	      */
				      /*			      */
void cdecl scgetvid(ADAP_STATE *);    /* Get the complete video state.*/
				      /*			      */
int cdecl  scsetvid(const	      /* Set the complete video state.*/
		    ADAP_STATE *);    /*			      */
				      /*			      */
int cdecl  scsavepg(PAGE_STATE *);    /* Save the current page.       */
				      /*			      */
int cdecl  screstpg(const	      /* Restore the current page.    */
		    PAGE_STATE *);    /*			      */
				      /*			      */

#endif				      /* Ends "#ifndef DEF_BSCREENS"  */
