home *** CD-ROM | disk | FTP | other *** search
- `co(4,7);────────────────────────── /// General Macros ────────────────────────────────`co();
- UltraWin also makes extensive use of macros ( defined in UW.H ) for simple
- operations that do not justify the overhead of a function, and make your
- programs more readable. The following are for general use.
-
- `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();
- Many of the things you do with windows are only accomplished with the
- window marcros. The macros will allow you to perform several forms of
- input/output to a window, change the window attributes, move the window
- cursor within the window, and more. A close look at these macros will
- give you some insight into how UltraWin uses the window structure.
-
- `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 to supplement the material presented
- here.
-
- UltraWin gives you the ability to use our own EGA/VGA fonts, or create
- your own with our powerful font editor. UltraWin also lets you use a full
- 16 background colors, and even change the EGA/VGA palette. However, it is
- not possible to actually 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);
- 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);
- 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);
- 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. You should either allocate the appropriate
- number of bytes and pass the pointer to this function or pass the name
- of a sufficiently large global array of bytes. 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);
- Saves a font pattern from memory into a file. This is the complement
- of `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);
- Installs a font loaded into memory, into the EGA/VGA bios area. Two
- sets of 256 characters can be resident at one time. The "block" parameter
- determines which set to install. 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" );
- install_font( Font8x14, 1, 0, 256, 14, 0 );
-
- `co(10,1);/// get_font_info`co(); `keyword(source,[UW_FONT.C]~get_font_info);
- Returns the address, number of 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);
- Enables or 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);
- Enables or 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);
- Sets the two possible active fonts as primary and 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" );
- install_font( Font8x14, 0, 0, 256, 14, 0 );
- load_font( Font8x14, "8x14icon.fnt" );
- install_font( Font8x14, 1, 0, 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);
- Loads the video BIOS 8x8 font into the desired block and optionally
- resets the video mode
-
- 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);
- Loads the video BIOS 8x14 font into the desired block and optionally
- resets the video mode.
-
- 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);
- 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);
- 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);
- 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);
- 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);
- 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 is a unique library in that although primarily designed for
- text modes it has the capability to use EGA/VGA graphic modes as well.
- This is due to the flexibility of UltraWin's text output routines. It was
- a fairly simple task for us to route all text output through one routine
- which places one character on the screen. This does not slow down normal
- text output whatsoever, as all output is routed through this special g_ch
- function only when the global Graphics flag is set.
-
- Please understand though, UltraWin does not add a graphics libarary or
- any other graphics routines other than the output of a single character.
- All UltraWin output is still cell based. This is no great limitation as
- you can use a third-party graphics library (or the one bundled with your
- compiler) to do all your lines, polygons, circles, etc. To get UltraWin
- to use graphics, first use your graphics library to put the video into
- either EGA 640x350x16 or VGA 640x480x16 mode and call `keyword(init_uw_graphics,/// init_uw_graphics);.
- It's that easy!
-
- Since UltraWin gives you this flexibility the library can become quite
- literally hardware independent. For instance, all that would be necessary
- to make UltraWin work with custom hardware ( or even a dumb terminal )
- would be to write ONE routine (g_ch) that outputs a single character on
- the display device, and then call init_uw_graphics. All output would then
- go through g_ch. Please see `keyword(g_ch,/// g_ch); for more information.
-
- `co(10,1);/// init_uw_graphics`co(); `keyword(source,[UW_GRAPH.C]~init_uw_graphics);
- 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);
- Outputs a single character to the graphics screen. This function will
- not normally be called by you. It is a very important function for those
- of you interested in using UltraWin in graphic modes. All UltraWin output
- will go through this routine when the Graphics flag is set. This feature
- gives you the power to write your own g_ch to support other graphics
- standards, dumb-terminals, and virtually any non-standard hardware.
- (Please note that when the global variable G_opt is set, g_ch will not
- draw if the character is already on the screen in the proper colors.)
-
- It is very important to understand what happens here. We simply replace
- output routines - no other graphics support is provided - UltraWin works
- exactly as it does in text mode. It will not save/restore graphics areas
- under windows - you must do this yourself, if you wish.
-
- Also note that this function, along with get_font_info and install_font
- are only compilable under the Borland compilers, Microsoft users can link
- the object module into their programs if need be. Of course if you use the
- library for your compiler, then it is all automatic.
-
- 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');
-