`co(4,7);──────────────────────── /// General Macros ────────────────────────────────`co();
	These are some macros (defined in uw.h) that are for general use
	in your programs!

`co(10,1);/// hibyte`co();
	#define hibyte(c) 			 (uchar) ((c) >> 8)
	Yields the most significant byte of integer c.

`co(10,1);/// lobyte`co();
	#define lobyte(c) 			 (uchar) ((c) & 0x00ff)
	Yields the least significant byte of integer c.

`co(10,1);/// lower`co();
	#define lower (x, y)		 (x < y) ? x : y
	Yields the lesser of the values x and y.

`co(10,1);/// range`co();
	#define range(l,b,h)		 ((((b) >= (l)) && ((b) <= (h))))
	Yields a 1 if b is between l and h inclusive.

`co(10,1);/// swap`co();
	#define swap(a,b,c) 		 ((c) = (a), (a) = (b), (b) = (c))
	Swaps the values a and b utilizing a temporary c.

`co(10,1);/// upper`co();
	#define upper (x, y)		 (x > y) ? x : y
  Yields the greater of the values x and y.

`co(4,7);──────────────────────── /// Window Macros ─────────────────────────────────`co();
	These are some useful window macros (defined in uw.h) that will
	make manipulation of windows a little easier.

`co(10,1);/// cls`co();
	#define cls() 								(setmem(Screen, V_cols * V_rows * 2, 0))
	Clears the entire screen to black.

`co(10,1);/// mv_cs`co();
	#define mv_cs(c,r,wnp)				((wnp)->csr_x = (c), (wnp)->csr_y = (r))
	Moves the "soft" cursor in window wnp to the column and row c and r.
	
`co(10,1);/// wn_att`co();
	#define wn_att(a,wnp) 				((wnp)->att = (a))
	Sets the window attribute in wnp to the value a.

`co(10,1);/// wn_bdratt`co();
	#define wn_bdratt(a,wnp)			((wnp)->bdr_att = (a))
	Sets the window boder attribute in wnp to the value a.	This is
	the complement to the wn_att macro.
	
`co(10,1);/// wn_bdr_color`co();
	#define wn_bdr_color(f,b,wnp) ((wnp)->bdr_att = ((b) << 4) | (f))
	Sets the border foreground and background colors in window wnp.  This
	is the complement to the wn_color macro.

`co(10,1);/// wn_color`co();
	#define wn_color(f,b,wnp) 		((wnp)->att = ((b) << 4) | (f))
	Sets the foreground and background colors in window wnp.	This is
	done by setting the window attribute accordingly.
	
`co(10,1);/// wn_name`co();
	#define wn_name(n, wnp) 			((wnp)->name = (n))
	Sets the name at the top of window wnp to the string n.

`co(10,1);/// wn_name_loc`co();
	#define wn_name_loc(l, wnp) 	((wnp)->name_loc = (l))
	Sets the location of the name in window wnp to left, right, or
	centered.

`co(10,1);/// wn_read`co();
	#define wn_read( wnp )				(wn_io( IN, BUFF, (wnp)))
	Pulls what is actually on the screen under the window into the
	window itself!	This is like wn_save, but instead of pulling the
	area under the window into the save/restore buffer, it pulls it
	into the window.

`co(10,1);/// wn_restore`co();
	#define wn_restore( wnp ) 		(wn_io(OUT, SAVE, (wnp)))
	Restores the area saved (by the macro wn_save) under the window wnp.
	
`co(10,1);/// wn_rfsh`co();
	#define wn_rfsh( wnp )				(wn_io(OUT, BUFF, (wnp)))
	Redraws (refreshes) the window wnp.

`co(10,1);/// wn_save`co();
	#define wn_save( wnp )				(wn_io( IN, SAVE, (wnp)))
	Saves the area under the window wnp to the window save area for later
	restoration.

`co(4,7);───────────────────────── /// Font/EGA Control ──────────────────────────────`co();

┌──────────────────────────────────────────────────────────────────────────┐	
│          `keyword(encode_color,/// encode_color);                      `keyword(decode_color,/// decode_color);                  │
│          `keyword(load_font,/// load_font);                         `keyword(save_font,/// save_font);                     │
│          `keyword(install_font,/// install_font);                      `keyword(get_font_info,/// get_font_info);                 │
│          `keyword(blink_enable,/// blink_enable);                      `keyword(replicate_enable,/// replicate_enable);              │
│          `keyword(set_block_ab,/// set_block_ab);                      `keyword(rom8x8,/// rom8x8);                        │
│          `keyword(rom8x14,/// rom8x14);                           `keyword(rom8x16,/// rom8x16);                       │
│          `keyword(read_palette,/// read_palette);                      `keyword(read_palette_all,/// read_palette_all);              │
│          `keyword(write_palette,/// write_palette);                     `keyword(write_palette_all,/// write_palette_all);             │
└──────────────────────────────────────────────────────────────────────────┘

These functions are specific to EGA/VGA boards and are advanced features.
We do not attempt to explain all the details and quirks of the EGA/VGA video
subsystems.  We recommend you have some reference material detailing the
EGA/VGA video system if our descriptions are not clear or complete enough.

It is not possible to read the palette registers on an EGA board.  We
resolve this deficiency by keeping a "shadow" palette that is initialized
to the standard EGA values.  When you read/write the palette registers,
you are also accessing this "shadow" area.

`co(10,1);/// encode_color`co();   `keyword(source,[UW_FONT.C]~encode_color);
  This routine takes the individual Red, Green, and Blue color components 
  and encodes them into a format suitable for the EGA/VGA palette registers,
  returning this value as an integer.
                       see also `keyword(decode_color,/// decode_color);

Prototype:
void encode_color(int r, int g, int b);

Parameters:
`co(11,1);	int r, g, b`co();
		Integers containing each color component.

Usage:
	int color, r = 2, g = 3, b = 1;
	...
	color = encode_color( r, g, b );

`co(10,1);/// decode_color`co();   `keyword(source,[UW_FONT.C]~decode_color);
  This routine takes an EGA/VGA color encoded value as it would be stored
  in a palette register and returns the individual Red, Green, and Blue
  components.
                       see also `keyword(encode_color,/// encode_color);

Prototype:
void decode_color(int color, int *r, int *g, int *b);

Parameters:
`co(11,1);	int color;`co();
		The EGA/VGA encoded color value.
`co(11,1);	int *r, *g, *b`co();
		Integer pointers to store each color component.

Usage:
	int color, r, g, b;
	color = random(64);
	...
	decode_color( color, &r, &g, &b );

`co(10,1);/// load_font`co();   `keyword(source,[UW_FONT.C]~load_font);
  This routine loads a font pattern file into memory. The fonts are stored
  int raw format, with no header information residing in the file.  As an
  example, let's say we have a file containing 256 8x14 characters.  The
  first characters' pattern is contained in the first 14 bytes, the second
  in bytes 15-28, and so on.  This is the complement of save_font.  Upon a
  successful load, the function will return the number of scan lines that
  are in each character, or 0 upon failure.
                            see also `keyword(save_font,/// save_font);
Prototype:
int load_font( uchar *font, char *fname );

Parameters:
`co(11,1);	uchar *font;`co();
		A pointer to an area large enough to hold the font pattern data.
`co(11,1);	char  *fname;`co();
		A pointer to the filename that contains the font pattern data.

Usage:
	uchar Font8x14[256][14];                      					  /* global array */
	int Scan_lines;
	...
	Scan_lines = load_font( Font8x14, "8x14icon.fnt");

`co(10,1);/// save_font`co();   `keyword(source,[UW_FONT.C]~save_font);
  This routine saves a font pattern from memory into a file.
  This is the complement of load_font.
                            see also `keyword(load_font,/// load_font);
  
Prototype:
int save_font( uchar *font, char *fname, int scan_lines );

Parameters:
`co(11,1);	uchar *font;`co();
		A pointer to an area containing the font pattern data.
`co(11,1);	char  *fname;`co();
		A pointer to the filename to which to save the font data.
`co(11,1);	int   scan_lines;`co();
		The number of scan_lines the font contains (typically 8/14/16).

Usage:
	uchar Font8x14[256][14];                      					  /* global array */
	...
	save_font( Font8x14, "8x14ICON.FNT", 14 );

`co(10,1);/// install_font`co();   `keyword(source,[UW_FONT.C]~install_font);
  This routine installs a font loaded into memory, into the EGA/VGA bios
  area.  Two sets of 256 characters can be resident at one time.  "block"
  determines which set to install this font as.  If "setmode" is non-zero,
  the video mode will be reset.
  
Prototype:
void install_font(uchar *font, int block, int offset, int cnt,
	int scan_lines, int setmode );

Parameters:
`co(11,1);	uchar *font;`co();
		A pointer to an area containing the font pattern data.
`co(11,1);	int   block;`co();
		The character set in which to load this font. (0 or 1).
`co(11,1);	int   offset;`co();
		The character offset to load the new font data, typically 0.
`co(11,1);	int   cnt;`co();
		The number of characters to install (max 256).
`co(11,1);	int   scan_lines;`co();
		The number of scan_lines the font contains (typically 8/14/16).
`co(11,1);	int   set_mode;`co();
		If non-zero, the video mode will be reset.

Usage:
	uchar Font8x14[256][14];                      					  /* global array */
	...
	load_font( Font8x14, "8x14icon.fnt", 256, 14 );
  install_font( Font8x14, 1, 0, 256, 14, 0 );

`co(10,1);/// get_font_info`co();   `keyword(source,[UW_FONT.C]~get_font_info);
  This routine returns the address, scan_lines, and video character rows 
  of the current font.
    
Prototype:
uchar far *get_font_info( int type, int *scan_lines, int *rows );

Parameters:
`co(11,1);	int   type;`co();
    2 - get address of ROM 8x14 font
    3 - get address of ROM 8x8 font
    4 - get address of second half of ROM 8x8 font
    5 - get address of ROM 9x14 alternate font
    6 - get address of ROM 8x16 font
    7 - get address of ROM 9x16 alternate font
`co(11,1);	int   *scan_lines;`co();
		A pointer to an integer in which to store the number of scan lines in 
    the current font.
`co(11,1);	int   *rows;`co();
		A pointer to an integer in which to store the number of character rows
    for the current screen mode.

Usage:
	int scan_lines, rows;
	uchar far  *font;
	...
	font = get_font_info( 2, &scan_lines, &rows );

`co(10,1);/// blink_enable`co();   `keyword(source,[UW_FONT.C]~blink_enable);
  This routine enables/disables blinking on EGA/VGA systems. When the
  blink bit is disabled, all 256 possible color combinations (16 foreground,
  16 background) can be displayed at one time with no blinking.  If enabled,
  those character cells whose background color is 8-15 will blink.

Prototype:
void blink_enable(int state);

Parameters:
`co(11,1);	int   state;`co();
		1 to enable blink, 0 to disable blink.

Usage:
	...
	blink_enable(1);

`co(10,1);/// replicate_enable`co();   `keyword(source,[UW_FONT.C]~replicate_enable);
  This routine enables/disables 9th pixel replication for the 32 characters
  0xC0 - 0xDF on EGA/VGA boards.  The use of this function depends on the
  video card in use.  Some cards (especially in monochrome modes) use a 9
  pixel wide cell, even though the font is only 8 pixels wide. This usually
  causes no problem as the hardware hides this from us.  However, when 
  performing line drawing or other operations where characters must join,
  a gap may exist.  The hardware is capable of replicating the 8th bit
  into the 9th bit to allow for continuous characters. The hardware only
  does this for the line drawing character block 0xC0 - 0xDF. In short, if
  you modify your own fonts and create new borders, lines, etc. that need to
  be continuous, it is recommended that you store these characters in this 
  area and enable replication.  No other character cells will be affected.

Prototype:
void replicate_enable(int state);

Parameters:
`co(11,1);	int   state;`co();
		1 to enable 9th pixel replication, 0 to disable replication.

Usage:
	...
	replicate_enable(1);

`co(10,1);/// set_block_ab`co();   `keyword(source,[UW_FONT.C]~set_block_ab);
  This routine sets the two possible active fonts as primary secondary.
  Both blocks can be set to the same mode.  For example, if we load
  a standard 8x14 font into block 0, and an 8x14 icon font into block 1,
  we might say "set_block_ab(0,1)".  This sets the 8x14 as the primary 
  font and the icon font as secondary. (Displayed if the background 
  is 8-15).  If "set_block_ab(1,0)" is called, the two fonts will be
  effectively switched.  "set_block_ab(0,0)" will always display the
  8x14 font regardless of attribute settings.

Prototype:
void set_block_ab(int a, int b);

Parameters:
`co(11,1);	int   a;`co();
		0 - set font 0 as primary font, 1 - set font 0 as alternate font.
`co(11,1);	int   b;`co();
		0 - set font 1 as primary font, 1 - set font 1 as alternate font.

Usage:
	...
	load_font( Font8x14, "8x14.fnt", 256, 14 );
  install_font( Font8x14, 0, 256, 14, 0 );
	load_font( Font8x14, "8x14icon.fnt", 256, 14 );
  install_font( Font8x14, 1, 256, 14, 0 );
	set_block_ab(0,1);                    /* 8x14 - block 0, 8x14icon block 1 */

`co(10,1);/// rom8x8`co();   `keyword(source,[UW_FONT.C]~rom8x8);
  This routine loads the video BIOS 8x8 font into the desired block
  and optionally resets the video mode. (EGA/VGA)

Prototype:
void rom8x8(int block, int setmode);

Parameters:
`co(11,1);	int   block;`co();
		0 - load font into block 0, 1 - load font into block 1.
`co(11,1);	int   setmode;`co();
		0 - do not reset video mode. 1- set video mode.

Usage:
	...
	rom8x8(0,1);												/* load as primary, reset video mode  */

`co(10,1);/// rom8x14`co();   `keyword(source,[UW_FONT.C]~rom8x14);
  This routine loads the video BIOS 8x14 font into the desired block
  and optionally resets the video mode. (EGA/VGA)

Prototype:
void rom8x14(int block, int setmode);

Parameters:
`co(11,1);	int   block;`co();
		0 - load font into block 0, 1 - load font into block 1.
`co(11,1);	int   setmode;`co();
		0 - do not reset video mode. 1- set video mode.

Usage:
	...
	rom8x14(1,0);												/* load as alternate, don't reset     */

`co(10,1);/// rom8x16`co();   `keyword(source,[UW_FONT.C]~rom8x16);
  This routine loads the video BIOS 8x16 font into the desired block
  and optionally resets the video mode. (VGA only)

Prototype:
void rom8x16(int block, int setmode);

Parameters:
`co(11,1);	int   block;`co();
		0 - load font into block 0, 1 - load font into block 1.
`co(11,1);	int   setmode;`co();
		0 - do not reset video mode. 1- set video mode.

Usage:
	...
	rom8x16(0,0);												/* load as primary, don't reset mode  */

`co(10,1);/// read_palette`co();   `keyword(source,[UW_FONT.C]~read_palette);
  This routine reads a single palette register and returns the value.
  To determine the RGB components, see `keyword(decode_color,/// decode_color); above.

Prototype:
int read_palette( int pnum );

Parameters:
`co(11,1);	int   pnum;`co();
		The color palette index to read (0-15).

Usage:
	int color;
	...
	color = read_palette(6);

`co(10,1);/// read_palette_all`co();   `keyword(source,[UW_FONT.C]~read_palette_all);
  This routine reads all 16 palette registers and stores the values into
  the desired area.

Prototype:
int read_palette_all( uchar *vals );

Parameters:
`co(11,1);	uchar  *vals;`co();
		A pointer to an array (at least 16 bytes) in which to store the values.

Usage:
	uchar colors[16];
	...
	read_palette_all(colors);

`co(10,1);/// write_palette`co();   `keyword(source,[UW_FONT.C]~write_palette);
  This routine writes a value to a single palette register. To specify the
  color in RGB components, see `keyword(encode_color,/// encode_color); above.

Prototype:
int write_palette( int pnum, uchar val );

Parameters:
`co(11,1);	int   pnum;`co();
		The color palette index to write (0-15).
`co(11,1);	uchar val;`co();
		The color palette value.

Usage:
	...
  write_palette(6, encode_color(1,3,2));

`co(10,1);/// write_palette_all`co();   `keyword(source,[UW_FONT.C]~write_palette_all);
  This routine writes values to all palette registers.

Prototype:
int write_palette_all( uchar *vals );

Parameters:
`co(11,1);	uchar *vals;`co();
		The 16 color palette values.

Usage:
char palette[16] =
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14,	0x07,
	0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f };
	...
  write_palette_all(palette);

`color(RED,LIGHTGRAY);────────────────────────  /// Graphics Support ─────────────────────────────`color();
  UltraWin version 2.0 adds EGA/VGA graphics support.  It does not add
  a graphics library or initilization routines.  You must first have your
  system in either EGA 640x350x16 or VGA 640x480x16 mode.  To tell UltraWin
  that it should draw all text in graphics mode, simply call `keyword(init_uw_graphics,/// init_uw_graphics);.
  See `keyword(g_ch,/// g_ch); for details on graphics output.

`co(10,1);/// init_uw_graphics`co();   `keyword(source,[UW_GRAPH.C]~init_uw_graphics);
  This routine initializes UltraWin to support EGA/VGA graphics output.

Prototype:
int init_uw_graphics( int xres, int yres, int font_rows,
                      int font_spacing, int seg, int off );

Parameters:
  Parameters:
`co(11,1);  int xres, yres`co();   - resolution in pixels for EGA/VGA         
`co(11,1);  int font_rows`co();    - number of scan lines for current font    
`co(11,1);  int font_spacing`co(); - number of scan lines between characters  
`co(11,1);  int seg`co();          - graphics segment (-1 sets default 0xa000)
`co(11,1);  int off`co();          - graphics offset  (-1 sets default 0x0000)

Usage:
	...
	init_uw_graphics( 640, 350, 14, 14, -1, -1 );

`co(10,1);/// g_ch`co();   `keyword(source,[UW_GRAPH.C]~g_ch);
  This routine outputs a single character to the graphics screen.  It will
  not normally be called by you.  It is a very important function for those
  of you interested in non-text mode support.  All UltraWin output will go
  through this routine when the graphics flag is set.  This allows you to
  not only use our function, but to write your own to support other graphics
  standards, dumb-terminals, and virtually any non-standard hardware.  Note
  that when the global variable G_opt is set, the output routine will not
  draw if the character is already on the screen in the proper color.
  Also note that this function, along with get_font_info and install_font
  are only compilable under the Borland compilers, Microsoft users can
  link this module into their programs if need be.
  It is very important to understand what happens here.  We simply replace
  output routines - no other graphics support is supported - UltraWin
  works exactly as it does in text mode.  It will not save/restore graphics
  areas under windows - you must do this yourself, if desired.

Prototype:
int g_ch( int c, int r, int v );

Parameters:
  Parameters:
`co(11,1);	int c;`co(); - col (UltraWin col 0-V_cols - 1, not pixel col)
`co(11,1);  int r;`co(); - row (UltraWin row 0-V_rows - 1, not pixel row)
`co(11,1);  int v;`co(); - character value (0-255)

Usage:
	...
	g_ch(10, 15, 'x');

`co(4,7);─ End ──────────────────────────────────────────────────────────────────────`co();`sound(1024,10);
