home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Virtual Reality Zone
/
VRZONE.ISO
/
mac
/
PC
/
PCGLOVE
/
GLOVE
/
OBJGLV.ZIP
/
DOC
/
VDRIVERS.DOC
< prev
next >
Wrap
Text File
|
1992-09-25
|
8KB
|
200 lines
REND386 VIDEO DRIVER CREATION
Written by Dave Stampe, September 1992
Video drivers are compiled in pseudo-tiny mode (code, data in one
segment, stack not assumed in the same segment). The interface is through
an assembly routine linked to REND386, and through a call table at the start
of the driver.
During development, the call module (vdrinte.asm) may be left out of the
REND386 link, and the video driver code itself linked in. At this stage,
all assembly modules should use the .MODEL LARGE directive.
See the file MEMMODEL for a description of the memory modes, and how to
compile your driver.
-------------------------------
FUNCTIONS TO BE SUPPORTED BY VIDEO DRIVER:
Note all the FAR attributes of the prototypes: VERY IMPORTANT.
----
struct Screeninfo {
int xmin, ymin, xmax, ymax, xcent, ycent, colors, pages, bw;
char id[80];
};
struct Screeninfo far * far screen_data();
This is usually the first call made by REND386 to the driver, and it should
return a far pointer to a Screeninfo structure inside the driver. Most of
the attributes in the structure are self-explanatory. "bw" is 0 if a color
palette is to be used, 1 if a monochrome palette is preferred.
----
void far set_gmode(int arg); /* enters graphics, clears screen */
void far exit_gmode(); /* exits to text mode */
These functions are self-explanetory. If you have multiple video
sources for a HMD, this should initialize all sources in one call.
set_gmode() may be passed a single parameter to, for example, set
the video mode on a SVGA card from the .cfg file.
----
#define MAIN_VGA 1 /* for multi-VGA only */
#define LEFT_VGA 2
#define RIGHT_VGA 4
#define ALL_VGA 7
extern void far VGA_select(int card);
This functions selects one (or all) video sources to be drawn to.
If multiple bits are set (i.e to clear all sources in parallel, or
to draw to the main monitor and one of the HMD eye sources at once,
your driver should detect and handle this appropriately.
This function is reentrant (FARSTACK): see MEMMODEL for data.
----
extern void far vsync(); /* pause till vert. retrace */
Self explanatory. Used to setup the Sega/switcher timing, so it may
be called from interrupt handlers.
This function is reentrant (FARSTACK): see MEMMODEL for data.
----
extern void far set_vpage(int page); /* set video page */
Since this may be called by an interrupt handler, it should
NOT use BIOS calls to set the visible page.
This function is reentrant (FARSTACK): see MEMMODEL for data.
----
#define PUT 0 /* defines of VGA write modes */
#define AND 1 /* for use with setup_hdwe() */
#define OR 2
#define XOR 3
extern void far setup_hdwe(int mode); /* setup VGA for bunch of line */
/* or poly draws: once per set */
extern void far reset_hdwe(); /* reset VGA to BIOS state after drawing */
Used to initialize hardware for drawing, and reset to standard mode after.
The drawing modes are optional: passing 0 always is safest. setup_hdwe()
will be called before rendering screen polys etc; reset_hdwe() will be called
afterwards. It may be called at other times as well.
-----
/* clear video page to solid color: 10 mS */
/* returns -1 if bad page # */
extern int far clr_page(int page, int color);
-----
/* copy one page to another for use as */
/* background: 21 mS per call */
/* returns -1 if bad page # */
extern int far copy_page(int source, int dest);
------
/* fast VGA line draw: about 15600 24-pixel */
/* vectors/sec (horizontal much faster) */
extern void far vgaline(int x1, int y1, int x2, int y2, int color);
------
void far set_clip_rect(int l, int t, int r, int b);
/* does C-S clipping and draws line */
extern void far clipline(int x1, int y1, int x2, int y2, int color);
These functions are not currently used by REND386, and may be stubbed off
if desired.
-----
int far set_drawpage(int page); /* set page for drawing on (0-7) */
Use this to set page to draw to, for ALL functions that do not take a
page number as an argument.
-----
/* N_SIDED POLY DRAW for up to 20-sided */
/* convex polygons. Pass pointer to int */
/* array with X, Y coords in that order */
/* and count. No clipping, CCW order */
void far fastpoly(int count, int far *pcoords, int color);
/* same as fastpoly() but with color cycling */
/* and masking (halftone). Color cycles in */
/* its lowest 4 bits, up then down. Bit 8 */
/* has been added as a "sign" bit for the */
/* initial cycle direction. 0000000SHHHHCCCC */
/* the mask is XOR'ed with the toggle every */
/* line for 2x8 halftone patterns */
void far m_fastpoly(int count, int far *pcoords, int color, int gmask, int toggle);
These functions should draw filled convex polygons from the point list
given. You can emulate them with triangle poly calls internally: the
current REND386 slices the poly into trapezoidal segments and draws these.
The special-effects poly draw shoulds at least draw halftoned polys, using
gmask as the drawing mask, and XORing it with toggle on odd lines. The color
argument is explained above, and should cycle up then down through a 16-color
sequence. See the assembly code for a better explanation.
-----
/* print text in foreground only-- */
/* reversed = 1 for right-to-left */
/* with x now right side of text */
void far printxyr(int x, int y, int color, char far *pstring, int reversed);
No background clearing is performed. Should be capable of printing at
any horizontal offset. Reversed text prints left from start position,
normal text prints right. Reversed text is only used if one of your
video devices will be used in horizontally-flipped mode: if none are,
you may stub it off. (Please support for widely-used drivers!).
-----
/* draw "+" cursor on screen */
/* save s screen under cursor */
void far draw_cursor(int x, int y, int color, int savebuff);
/* restores 8x8 area saved when */
void far erase_cursor(int savebuff); /* cursor was drawn */
These are used for mouse cursor support. The savebuff is device-specific,
so would be seperate for each of multiple VGA cards, for example. During
cursor drawing, the screen under the cursor will be saved, then restore
when rase_cursor is called. There should be as many savebuff's as there are
video pages on your device.
-----
/* copy any byte-aligned rectangle */
/* this is every 8 pixels (assumed for all modes) */
/* x coords (left) are truncated to */
/* left byte boundary: x size is */
/* bumped up to next full 8-pixel count */
extern int far copy_block(int spage, int sx, int sy, /* source */
int dpage, int dx, int dy, /* dest */
int xs, int ys); /* # lines, pixels */
/* clear any byte-aligned block */
/* 15-30% slower than full page clear */
/* left edge rounded down, right edge */
/* rounded up to nearest byte boundary */
extern int far clr_block(int left, int top, int right, int bottom,
int page, int color);
These should support the 8-pixel granularity as noted above for
compatibility.
-------
/* 3 entries each for n colors: RGB, 0->63 */
/* load always starts with slot 0 */
/* set pal=NULL for default (still give n) */
/* bw=1 will transform palette into B&W */
extern void far load_DAC_colors(char far *pal, int n, int bw);
extern void far read_DEC_colors(char far *pal, int n);
These should load or save the DAC palette. The video driver should have its
own private color table: pass NULL to use this table. The table ideally
should support the standard REND386 color mappings (see colormap.c).
------------------------------------------------
SUGGESTIONS:
Read through the 16- and 256- color VGA driver source if in doubt.
Always debug you code by linking it into REND386 directly first.
If you have trouble, suspect the memory-model interactions, and check for
missing FAR declarations, etc. If in doubt use TD386 to single-step
through the REND386 calls to screen_data(), set_gmode(), and load_DAC_colors.
ALWAYS check the validity of returned data.