| Products: CX100 and CX104
This application note explains
the mechanism for writing text to overlay RAM and explains how you can
do this with or without a VGA card. This is particularly useful in an
embedded system that uses the CX104. Many PC/104 systems do not have a
VGA card.
BACKGROUND
All CX Series frame grabbers can be purchased
with overlay memory. This extra RAM chip is 4-bits wide and is available
only at the video output connector. There has been some confusion over
the years as to whether this RAM chip can display overlay graphics on
the VGA screen. It cannot. The CX has a video output connector for an
external video monitor. The signal that is available on the video output
connector always consists of the data in video RAM and can be mixed with
the data in overlay RAM when the ENABLE_OVERLAY bit is enabled.
The text and graphics functions
that are supplied with the CX frame grabbers do not make any assumptions
about the destinations of their writes. Overlay RAM is controlled by 2
bits: OVERLAY_ENABLE and DISPLAY_OVERLAY.
When OVERLAY_ENABLE is set,
all text and graphics writes will go to overlay RAM. When OVERLAY_ENABLE
is clear, all text and graphics writes will go to video RAM.
When DISPLAY_OVERLAY is
set, the contents of overlay RAM will be mixed with the contents of video
RAM at the video output connector.
The overlay RAM is 4-bits
wide. It gives you 15 shades of gray, and 0 is transparent.
WHERE THE TEXT COMES
FROM
The text comes from your VGA card. All VGA cards
contain 3 text fonts. During initialization, the CX libraries obtain a
pointer to the text fonts that have been mapped into memory.
PROBLEM
If you have a system
that has no VGA card, you have no fonts. All of the text functions will
fail.
SOLUTION
The solution is to use a file of fonts and modify
the CX libraries. This gives you the flexibility of using the font file
that we provide or using a custom font file. The CX libraries are easy
to modify, because the DOS source code is provided on the distribution
disk. This is specifically a DOS problem since Windows will not run without
a VGA card. In fact, we use this file method for displaying text under
Windows since Windows has protected the VGA memory and will not let the
DLL get the pointer to the fonts.
The source code for the
DOS 16-bit library is in the following location after installation, assuming
you used the default directory.
C:\CX100\DOS\CX100.C
The source code for the Watcom
32-bit library is in the following location after installation, assuming
you used the default directory.
C:\CX100\WATCOM\CX4GW.C
The font file we provide is
in the following location after installation, assuming you used the default
directory.
C:\CX100\WINDOWS\VGA.FNT
The above font file matches
the fonts in your VGA card. It is a dump from a generic VGA card.
The CX libraries could have
been built to either take the fonts from a file or from VGA memory. However,
it was built to assume that the fonts are in the VGA memory. We felt that
allowing you to give it a file name would be misleading since the file
would have to match the VGA fonts exactly. Building it the way we did,
gives you the flexibility of using a custom font file.
MODIFICATION PROCEDURE
The following explanation shows you how to modify the DOS libraries
to read fonts from a font file instead of a VGA card.
NOTE: The following procedure only works with the font file we supply.
If you want to read a file of a different size or with a different number
of fonts, you will need to make your own modifications. You will need
to modify the following routines:
ft_setfont()
ft_print()
To modify the DOS libraries to read fonts from a file instead of the
VGA card do the following.
1. CHANGE THE _FP VARIABLE FROM A FAR POINTER TO AN INTERNAL ARRAY.
In the CX100 library, we use the variable "_fp" as a pointer to the
fonts in the vga card. If you redefine _fp as an array of 4096, then you
can read one of the three fonts from the file VGA.FNT.
DELETE THE FOLLOWING 3 LINES:
static BYTE far *_fp; /* font pointer */
static int near _fontsel;
static WORD near _fontseg, near _fontoff;
INSERT THE FOLLOWING LINE:
static BYTE _fp[4096]; /* font array */
2. REPLACE THE FUNCTION FT_SETFONT() WITH THE FOLLOWING CODE
To download the following function click
here
/**************************************************************************
* Name: FT_SETFONT
***************************************************************************
* This function reads one of the three fonts from VGA.FNT and closes
the
* file. The file needs to be in the same directory as the program
unless
* you add a path to the file name in the OpenR() statement.
*
* When you change fonts, the file is read again. 4096 is the size
of the
* largest font. If you know you will always use a smaller font and
you
* are tight on memory, you can reduce the size of _fp accordingly.
***************************************************************************/
int ft_setfont(int font)
{
long offset;
int ret;
int fh;
ret = 0;
switch(font) {
case 1: _ysize= 8; offset=0l; break;
case 2: _ysize=14; offset=256l*8l; break;
case 3: _ysize=16; offset=(256l*8l) + (256l*14l); break;
default: return 0;
}
x_char = _xsize*fm;
y_char = _ysize*fm;
fh = OpenR("vga.fnt");
if(fh < 0)
return 0;
lseek(fh, offset, SEEK_SET);
ret = read(fh, _fp, (unsigned)(256*_ysize));
close(fh);
if(ret != (256*_ysize))
return 0;
return 1;
}
3. ADD A REFERENCE TO STDIO.H
If you are using a Borland compiler you won't need to include stdio.h.
But if you are using a Microsoft compiler you will need to add a reference
to stdio.h to pick up the value of SEEK_SET. You can put the reference
in CX100.H or in CX100.C
#include <stdio.h>
4. REBUILD THE LIBRARIES
Rebuild the version of the library that you use. There are several modules
in the libraries that you do not have the source for, so do not delete the
library. Use the -+ command to replace the CX100 module.
TURBO COMPILERS:
tcc -ml -w- -c cx100.c
tlib cx100_b -+cx100
If you use a Turbo compiler, you will probably get an error on
BYTE_MOVEDATA. It appears to have no effect on the library.
BORLAND COMPILERS:
bcc -ml -w -c cx100.c
tlib cx100_b -+cx100
MICROSOFT COMPILERS version 7.0 and later:
cl /AL /W3 /c /f- /Gs cx100.c
lib cx100_m -+cx100, cx100_m.lst, cx100_m
MICROSOFT COMPILERS version 6.0:
cl /AL /W3 /c /Gs cx100.c
lib cx100_m6 -+cx100, cx100_m6.lst, cx100_m6
WATCOM COMPILERS 32-bit:
wcc386 -s -w4 cx4gw.c
wlib cx4gw -+cx4gw
|