home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Virtual Reality Zone
/
VRZONE.ISO
/
mac
/
PC
/
PCGLOVE
/
GLOVE
/
OBJGLV.ZIP
/
DOC
/
MEMMODEL.DOC
< prev
next >
Wrap
Text File
|
1992-09-25
|
5KB
|
99 lines
REND386 DRIVERS AND MEMORY MODELS
Written by Dave Stampe, September 1992
Since drivers are loaded at run time and do not support relocation, their
data and code segments must be in the same physical segment. This requires
some assembly interface code to reset the data segment.
However, the stack will not be in the same segment as the data and
code, since the program's runtime stack is used. This means that the
usual tiny memory model cannot be used. Some C compilers support a
varient of the tiny memory model, where SS=DS is not assumed. But
unfortunately the Borland C tiny mode libraries do not conform to this.
So the options are: use tiny model C compilation and no libraries, or
assembly language with .MODEL TINY FARSTACK at the file start. This is
the way BGI files must be built (although the documentation doesn't say
so).
There is a third way that will let the tiny (small mode for Borland C)
libraries be used. This is to switch to a stack inside the driver.
There is a risk, however. Since the stack is reset at each entry into
the driver, the code cannot be reentrant. If one of the functions of the
video driver, for example, is called via an interrupt routine while
another driver routine is being executed, the stack contents of the original
routine will be trashed.
The method I chose is to use the program stack for all routines that may be
called from an interrupt routine, and use an internal driver stack for all
others. The interrupt-processing routines must then either not use any
C library calls or must be written in assembler. The interrupt-processing
routines include vsync(), set_vpage(), and VGA_select() in the video driver,
any interrupt service routines in pointer drivers, and the entire switcher
driver.
CREATING DRIVERS
You may find it easiest to create a driver from within REND386 for debugging
purposes. For video drivers, comment out the video driver loading
code in the initialization, and replace the VDRINTE.ASM module with the
modules containing the actual video driver code. For pointer and switcher
drivers, add a special test to the driver load/initialize call to link to
your code-- examine the internal mouse and PowerGlove drivers to see how
this is done.
Once your code is working, you should restore the REND386 code to its
original state and group all your needed modules together. Make sure that
all your C code will work in the TINY model, and that it will be FAR
callable-- that is, add the "far" keyword to all functions. Also, add
"far" to all pointers passed to and from driver calls, so that the LARGE
model REND386 code can talk to your driver. Change all assembly modules
to .MODEL TINY FARSTACK, and declare all procedures as FAR.
An assembly header file (supplied in the kit) sets a standard interface
and supplies entry/exit from the driver environment, switching SS and DS.
There are 3 headers available for drivers. The video driver header has
a jump table and a 2000 byte stack. There is a reentrant and nonreentrant
(with 2000 byte stack) header file available for driver programs as well.
Reentrant and nonreentrant entry for the video driver is performed in
the VDRINTE.ASM module of REND386, while pointer/switcher driver entry code
is in the header itself.
Use one of the sample batch files as a template for your driver compilation.
The steps are to compile all C code (note the options and use them!)
They are -c -mt -N- -k- -f- for no link, tiny, and no stack.
Assemble the assembly modules, link to an .EXE file with any required C
libraries (you may need to change the path here) with no stack. Then
use EXE2BIN to comvert the .EXE file to a binary driver file.
WARNING: IF YOU SEE "FIXUP REQUIRED" WHILE RUNNING EXE2BIN, YOUR DRIVER
WILL NOT WORK.
The REND386 standard driver extensions are:
.RVD: REND386 video driver
.RPD: REND386 pointer device
.RSD: REND386 switching device
.RHD: REND386 head tracking device.
Note that only the first 2 are used now: the .RHD is optional, as any
pointing device may be used as a head tracking device.
To debug your driver, I suggest Turbo Debugger 386, which will let
REND386 load and run (you'll need extended memory for this). You should
set breakpoints (or Run Until..) at the actual call to a driver function,
then switch to the CPU window and step into the driver. Watch for stuff
like improper pointer conversions, return of near pointers, etc. If the
code runs OK until you turn on the Sega glasses, you probably should
check for interrupt calls to non-reentrant driver or video driver functions.
Of course, any interrupt functions in your code are FARSTACK (SS != DS)
so should not use C library calls or should be written in assembler if
your compiler doesn't support this mode of compilation.
If you're doing anything weird, or having trouble with creating drivers,
contact Dave stampe (dstampe@psych.toronto.edu) for help. I can't fix
everything, but I may be able to give you pointers on what to do.
Good Luck!