Glide patch

Developer's Forum, for discussion of bugs, code, and other developmental aspects of DOSBox.

Glide patch

Postby gulikoza » 2007-8-20 @ 11:49

This patch has been available for a while now in ykhwong's builds. It allows DOSBox to run DOS Glide games (not all of them though) and now I am also releasing the source. The patch is composed of two (3 if you count glide wrapper) parts.

The first part is the GLIDE2X.OVL file. This is a DOS (kinda) DLL file that games use to access the Voodoo board. This OVL has been rewritten to talk to DOSBox instead of the Voodoo board. The file has to be present in the game directory (or somewhere in the path inside DOSBox, it can also be present in DOSBox directory; in this case it will automatically be added to the Z: drive) and is platform independent (since it runs inside DOSBox). There are games which directly access the Voodoo board without loading the OVL file. These games will not work with this patch (these are mostly early 3dfx games/demos: original [not Voodoo Rush] Tomb Rider patch, Fatal Racing, Eurofighter 2000...) and (should) work with 3DFX chip emulation by kekko.

The second part is the DOSBox patch. The patch should be relatively easy to apply and compile, it only requires a few 3dfx headers (sdk2_*.h files) which are available in the OpenGlide cvs. You need to run autogen.sh before running configure. The patch should be fairly crossplatform, but only Linux (x86 & x64), Windows ans MAC OSX have been tested so far...

These two patches allow games to access Glide on the host computer. But since most of you do not have Voodoo boards anymore (Glide DOSBox version has been tested to work with true Voodoo2 board in Win98 without any wrappers ;)) a glide wrapper is also required. You can use any wrapper you like, but some might work better or worse. The tested ones are:
- OpenGlide (see patches here)
- dgVoodoo (be sure to set it to render in window mode)
- zeckensack's (switches to fullscreen automatically)
- psvoodoo
- nGlide (actively supported, windows only)
- dgVoodoo2

OpenGlide is usually included with builds having this patch, but any wrapper can be used. Some games might work better with OpenGlide, others with dgVoodoo or nGlide, but OpenGlide is the only one crossplatform. MAC users, see MACGlide and it might be possible with some simple patches to get OpenGlide to work as well. But DOSBox patch has not been tested on Mac at all :) (Update: DOSBox-Glide has been tested to work on MacOSX, see this thread for OpenGlide patches, use latest dosbox_glide patch).

Currently, the following games have been tested:

Archimedean Dynasty (wrapper related graphics corruption, use nGlide)
Blood (works with dgvooodoo)
Carmageddon (works with dgVoodoo afaik)
Descent2 (works with openglide, use the unofficial 3dfx patch)
Dreams to Reality (working)
Extreme Assault (DEMO version works, full version not tested...)
GTA (no problems)
Lands of Lore 2 (works fine, some wrapper related problems, use nGlide)
RedGuard (no problems)
Screamer 2 & Rally (a bit slow with openglide, works fine with dgvoodoo if LFB access is disabled)
TombRider (no problems, use the patch from Eidos, search for Voodoo Rush patch if the link is broken)
For testing purposes, free Glide SDK tests can be found on the net, which should all work fine.

PROBLEMS:
- OpenGlide (some recent cvs version should be fine) has some serious drawbacks and performance issues. For now, use the version in my builds or compile your own version with the patches (most of the patches have been already commited)
- When glide is active, the wrapper is in control of the DOSBox window. This means that DOSBox window related options (resolution, scaler, ...) do not work
- Because of that, ALT-Enter fullscreen switch will not work as desired. In OpenGlide you have to edit OpenGLid.ini to have fullscreen, other wrappers work in fullscreen by default. With dgVoodoo, if you set the renderer to Direct3D9, ALT-Enter should work ok! (at least it does on my computer :))
- If you receive warnings like "Glide:Warning, unable to load grSstConfigPipeline from glide2x", it's not a problem. These are just functions that the particular wrapper does not support...unless of course the game happens to use them, but that will show as another error :)
- Do not use the mapper when Glide is running
- If you like, you can place 3dfxSpl2.dll from the voodoo drivers in the DOSBox directory and you will see 3dfx splash screen when Glide activates :-)

Updates:
22.8.2007: Fix compilation problems
23.8.2007: Fix buffer overflow
28.8.2007: x86_64 support
03.9.2007: Fix a crash when closing dosbox while glide is active
18.10.2007: Add TombRaider shadow hack (thanks gidierre!)
06.11.2007: Improve TR shadow support (gidierre)
17.2.2008: Updated for current CVS
14.9.2008: Updated for current CVS, allow disabling LFB reads/writes
04.6.2009: Updated for 0.73, add MSVC6 projects for glide2x win9x build
30.8.2009: Fix LFB operations when paging is active
09.10.2009: Various fixes and code cleanups, fix originlocation + splash screen
24.11.2009: Fix some minor issues, add MacOSX support (!)
27.10.2010: Add Pył support, fix grLFBRead/WriteRegion
03.08.2011: Fix polygon rendering
08.06.2012: Fix grTexClampMode (thanks robertmo!)
11.03.2013: Increase LFB mem and support simultaneous locks, fix Unreal GPF
Attachments
glide2x.zip
place OVL in DOSBox directory
includes sources
(98.92 KiB) Downloaded 9552 times
DOSBox_glide.zip
source code patch
(20.74 KiB) Downloaded 8900 times
Last edited by gulikoza on 2013-3-11 @ 15:38, edited 26 times in total.
User avatar
gulikoza
Oldbie
 
Posts: 1682
Joined: 2004-6-25 @ 14:53

Re: Glide patch

Postby wd » 2007-8-21 @ 08:09

Nice, thanks :)
wd
DOSBox Author
 
Posts: 10818
Joined: 2003-12-03 @ 21:23

Re: Glide patch

Postby qsonic » 2007-8-21 @ 09:57

Very cool indeed, works perfectly.

Adding to your note about Archimedean Dynasty: the game seems to display graphics fine using Zeckensacks wrapper, although it has windowing issues (at least for me, controlling the game with his wrapper is impossible).

Seems like OpenGlide has a variety of issues as of now... Hope to be able to fix a couple of them.
qsonic
Newbie
 
Posts: 14
Joined: 2007-7-27 @ 07:16
Location: Austria

Re: Glide patch

Postby gulikoza » 2007-8-21 @ 10:09

Thanks, haven't tried it with zeckensack's yet ;)
Try to set the configuration to render in the game window (the default option is to render in it's own window). But it's still somewhat annoying since it will switch resolutions. Somebody has to hexedit the dll and NOP that ChangeDisplaySetting call :P
User avatar
gulikoza
Oldbie
 
Posts: 1682
Joined: 2004-6-25 @ 14:53

Re: Glide patch

Postby qsonic » 2007-8-21 @ 17:28

Oh, I forgot to mention I am compiling with VC8, and for anyone who wants to do that, as well:

1.) Add the files which the patch adds to the source tree to the VC project file, namely:
src\hardware\glide.cpp
include\glide.h
include\glidedef.h

2.) Change these 2 lines in glide.cpp:
Line 393: typedef FxBool FX_CALL (*pfxSplashInit)(FxU32 hWnd, FxU32 screenWidth, FxU32 screenHeight,
To: typedef FxBool (FX_CALL *pfxSplashInit)(FxU32 hWnd, FxU32 screenWidth, FxU32 screenHeight,

Line 395: typedef void FX_CALL (*pfxSplash)(float x, float y, float w, float h, FxU32 frameNumber);
To: typedef void (FX_CALL *pfxSplash)(float x, float y, float w, float h, FxU32 frameNumber);
qsonic
Newbie
 
Posts: 14
Joined: 2007-7-27 @ 07:16
Location: Austria

Re: Glide patch

Postby Rainmak3r » 2007-8-22 @ 13:51

Hi,

I just tried the patch on Linux, but it fails when compiling glide.cpp:


g++ -DHAVE_CONFIG_H -I. -I../.. -I../../include -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -g -O2 -MT glide.o -MD -MP -MF .deps/glide.Tpo -c -o glide.o glide.cpp
../../include/sdk2_glide.h:53: error: expected `)' before ‘*’ token
glide.cpp: In constructor ‘GLIDE::GLIDE(Section*)’:
glide.cpp:204: error: expected primary-expression before ‘void’
glide.cpp:204: error: expected `)' before ‘void’
glide.cpp: At global scope:
glide.cpp:393: error: typedef ‘__stdcall’ is initialized (use __typeof__ instead)
glide.cpp:393: error: ‘pfxSplashInit’ was not declared in this scope
glide.cpp:395: error: typedef ‘__stdcall’ is initialized (use __typeof__ instead)
glide.cpp:395: error: ‘pfxSplash’ was not declared in this scope


and then the make process fails, quitting with an error...

Looking at line 53 of sdk2_glide.h, the "culprit" is this one:


typedef void (FX_CALL *GrProc)();


It probably isn't a matter of g++ 4.1 vs 3.4, because I tried them both with the same result: besides, I successfully installed Openglide CVS using 4.1.

What could be the reason?
Thanks in advance, hope to hear from you soon!
Rainmak3r
Newbie
 
Posts: 18
Joined: 2007-8-18 @ 12:24

Re: Glide patch

Postby gulikoza » 2007-8-22 @ 14:04

There's one ) missing at glide.cpp:204. The 393 error is probably the same as qsonic reported, will check what's wrong at sdk2_glide.h:53 and fix my patch accordingly :)
User avatar
gulikoza
Oldbie
 
Posts: 1682
Joined: 2004-6-25 @ 14:53

Re: Glide patch

Postby Rainmak3r » 2007-8-22 @ 14:17

I managed to turn around the compilation problems this way:

1) I forced the defines of FX_ENTRY and FX_CALL to
#define FX_ENTRY extern
#define FX_CALL
in sdk2_3dfx.h, because otherwise it kept introducing __stdcall which doesn't exist in Linux;

2) I didn't notice the mixxing bracket at line 204, you're right; however, I just removed the (void*) caster, since dlsym already returns a void*, and it compiled fine.


Unfortunately, dosbox crashes when trying to start it...


CONFIG:Loading primary settings from config file dosbox.conf
ALSA:Client initialised [17:0]
MIDI:Opened device:alsa
Glide:Warning, unable to load grSstConfigPipeline from glide2x
Glide:Warning, unable to load grSstVidMode from glide2x
Glide:Warning, unable to load guMPDrawTriangle from glide2x
Glide:Warning, unable to load guMPInit from glide2x
Glide:Warning, unable to load guMPTexCombineFunction from glide2x
Glide:Warning, unable to load guMPTexSource from glide2x
Glide:Warning, unable to load guMovieSetName from glide2x
Glide:Warning, unable to load guMovieStart from glide2x
Glide:Warning, unable to load guMovieStop from glide2x
Segmentation fault



This is the backtrace:


[Thread debugging using libthread_db enabled]
[New Thread -1208506640 (LWP 13227)]
[New Thread 25160592 (LWP 13230)]
CONFIG:Loading primary settings from config file dosbox.conf
[New Thread 35650448 (LWP 13231)]
ALSA:Client initialised [17:0]
MIDI:Opened device:alsa
Glide:Warning, unable to load grSstConfigPipeline from glide2x
Glide:Warning, unable to load grSstVidMode from glide2x
Glide:Warning, unable to load guMPDrawTriangle from glide2x
Glide:Warning, unable to load guMPInit from glide2x
Glide:Warning, unable to load guMPTexCombineFunction from glide2x
Glide:Warning, unable to load guMPTexSource from glide2x
Glide:Warning, unable to load guMovieSetName from glide2x
Glide:Warning, unable to load guMovieStart from glide2x
Glide:Warning, unable to load guMovieStop from glide2x

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1208506640 (LWP 13227)]
0x00ceff5c in malloc_consolidate () from /lib/libc.so.6
(gdb) bt
#0 0x00ceff5c in malloc_consolidate () from /lib/libc.so.6
#1 0x00cf20bd in _int_malloc () from /lib/libc.so.6
#2 0x00cf3ebe in malloc () from /lib/libc.so.6
#3 0x07a42557 in operator new () from /usr/lib/libstdc++.so.6
#4 0x07a1dc0b in std::string::_Rep::_S_create () from /usr/lib/libstdc++.so.6
#5 0x07a1e7a8 in std::string::_Rep::_M_clone () from /usr/lib/libstdc++.so.6
#6 0x07a1f358 in std::string::reserve () from /usr/lib/libstdc++.so.6
#7 0x07a18003 in std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::overflow () from /usr/lib/libstdc++.so.6
#8 0x07a1cdd1 in std::basic_streambuf<char, std::char_traits<char> >::xsputn
() from /usr/lib/libstdc++.so.6
#9 0x07a1217b in std::operator<< <std::char_traits<char> > ()
from /usr/lib/libstdc++.so.6
#10 0x080e8841 in GLIDE_Init (sec=0x9e92158)
at /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/ostream.tcc:86
#11 0x081c4f5b in Section::ExecuteInit (this=0x9e92158, initall=true)
at /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_list.h:131
#12 0x081c4f95 in Config::Init (this=0xbfb88070)
at /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/stl_list.h:212
#13 0x080fa877 in main (argc=1, argv=0xbfb88134) at sdlmain.cpp:1499



The dosbox.conf I used is exactly the same as the one I used wih the stable dosbox, with the only addons being the [glide] context copied from ykhwong's one.

Any idea what it could be?
Rainmak3r
Newbie
 
Posts: 18
Joined: 2007-8-18 @ 12:24

Re: Glide patch

Postby gulikoza » 2007-8-22 @ 15:32

Okay...fixed the compilation problems, the patch is updated in the first post.
But this crash is strange...I can't reproduce it, and it crashes somewhere inside malloc??
User avatar
gulikoza
Oldbie
 
Posts: 1682
Joined: 2004-6-25 @ 14:53

Re: Glide patch

Postby Rainmak3r » 2007-8-22 @ 16:01

Just tried recompiling with your new patch, and now it compiles fine without having to touch anything. I also added --enable-debug to see if it gave me more info about the crash. However, now it didn't crash at all!
So I made a few tests:

The 3dfx diagnostic kit tests worked fine;

Tomb Raider also did start fine, even if it crashed when leaving the game;

Redguard instead crashed after leaving the game menu, which, as it was in ykhwong's build, was corrupt anyway (the main diary page is invisible, you can see the side of the book on the right).

But it's a great step ahead from the previous issues :happy:
Rainmak3r
Newbie
 
Posts: 18
Joined: 2007-8-18 @ 12:24

Re: Glide patch

Postby Rainmak3r » 2007-8-22 @ 16:20

I recompiled disabling the debug, and dosbox crashes again on startup... it looks like debug mode made it more fault tolerant. :confused:
Rainmak3r
Newbie
 
Posts: 18
Joined: 2007-8-18 @ 12:24

Re: Glide patch

Postby `Moe` » 2007-8-22 @ 18:53

Crashes inside malloc usually result from a buffer overrun that has clobbered malloc's data structures. A double free might also apply, but IIRC modern glibcs should detect those.

BTW, is that a 32-bit or a 64-bit build?
User avatar
`Moe`
Oldbie
 
Posts: 1169
Joined: 2004-4-29 @ 01:06
Location: Oldenburg, Germany

Re: Glide patch

Postby Rainmak3r » 2007-8-22 @ 23:00

Hi Moe,
it's a 32-bit build, in a Fedora 7 OS. Let me know if there's anything I can do to help you sort out the problem.
Rainmak3r
Newbie
 
Posts: 18
Joined: 2007-8-18 @ 12:24

Re: Glide patch

Postby Rainmak3r » 2007-8-23 @ 11:57

Investigating the issues another bit, I found out a line where the problem might be. The backtrace reports:

Code: Select all
(gdb) bt
#0  0x00ceff5c in malloc_consolidate () from /lib/libc.so.6
#1  0x00cf20bd in _int_malloc () from /lib/libc.so.6
#2  0x00cf3ebe in malloc () from /lib/libc.so.6
#3  0x07a42557 in operator new () from /usr/lib/libstdc++.so.6
#4  0x07a1dc0b in std::string::_Rep::_S_create () from /usr/lib/libstdc++.so.6
#5  0x07a1e7a8 in std::string::_Rep::_M_clone () from /usr/lib/libstdc++.so.6
#6  0x07a1f358 in std::string::reserve () from /usr/lib/libstdc++.so.6
#7  0x07a18003 in std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::overflow () from /usr/lib/libstdc++.so.6
#8  0x07a1cdd1 in std::basic_streambuf<char, std::char_traits<char> >::xsputn
    () from /usr/lib/libstdc++.so.6
#9  0x07a1217b in std::operator<< <std::char_traits<char> > ()
   from /usr/lib/libstdc++.so.6
#10 0x080eca53 in GLIDE (this=0xabf5c80, configuration=0xabc2158)
    at glide.cpp:217
#11 0x080ec309 in GLIDE_Init (sec=0xabc2158) at glide.cpp:268
#12 0x081d4655 in Section::ExecuteInit (this=0xabc2158, initall=true)
    at setup.cpp:271
#13 0x081d4ca8 in Config::Init (this=0xbfd6f25c) at setup.cpp:256
#14 0x080ff887 in main (argc=Cannot access memory at address 0x1
) at sdlmain.cpp:1499


The overflow appears when compiling a string at the line:

Code: Select all
   ostringstream temp;
   temp << "SET GLIDE=" << hex << setw(3) << glide_base << ends;


I have no idea why such an operation should fail, I guess temp is correctly initialized... however, considering glide_base is statically set up as 0x300, I removed those lines and forced a static

Code: Select all
       autoexecline.Install("SET GLIDE=0x300");


which should do the same.
Doing this, dosbox stops crashing at that point but crashes somewhere else:

Code: Select all
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1208301840 (LWP 14368)]
0x00ceff5c in malloc_consolidate () from /lib/libc.so.6
(gdb) bt
#0  0x00ceff5c in malloc_consolidate () from /lib/libc.so.6
#1  0x00cf20bd in _int_malloc () from /lib/libc.so.6
#2  0x00cf3ebe in malloc () from /lib/libc.so.6
#3  0x07a42557 in operator new () from /usr/lib/libstdc++.so.6
#4  0x080aa2a4 in DOS_SetupFiles () at dos_files.cpp:1091
#5  0x080a7690 in DOS (this=0xa0a0630, configuration=0xa06b278) at dos.cpp:1089
#6  0x080a5149 in DOS_Init (sec=0xa06b278) at dos.cpp:1122
#7  0x081d40e5 in Section::ExecuteInit (this=0xa06b278, initall=true)
    at setup.cpp:271
#8  0x081d4738 in Config::Init (this=0xbff72c5c) at setup.cpp:256
#9  0x080ff317 in main (argc=Cannot access memory at address 0x1
) at sdlmain.cpp:1499


These errors are related to setting up the file systems, so I really have no idea how I could mess around with this...

I hope all this helped, hope to hear from you soon.
Rainmak3r
Newbie
 
Posts: 18
Joined: 2007-8-18 @ 12:24

Re: Glide patch

Postby Qbix » 2007-8-23 @ 11:59

your stack is allready corrupt before that.
have you tried running it through valgrind ?
Water flows down the stream
How to ask questions the smart way!
User avatar
Qbix
DOSBox Author
 
Posts: 10134
Joined: 2002-11-27 @ 14:50
Location: Fryslan

Re: Glide patch

Postby gulikoza » 2007-8-23 @ 12:06

The autoexec line is not even needed. And it is created the same way as other autoexec lines (sblaster...)
Something seems very wrong here. If you start with glide disabled (or even without the patch compiled in), does dosbox work??
User avatar
gulikoza
Oldbie
 
Posts: 1682
Joined: 2004-6-25 @ 14:53

Re: Glide patch

Postby Rainmak3r » 2007-8-23 @ 12:16

I just did it, you can find the output in the attached file. Running through Valgrind doesn't make dosbox crash (as the dosbox --enable-debug did). However, trying one of the 3dfx tests freezes dosbox.

My guess is the problem starts here:

Code: Select all
==14936== Invalid write of size 4
==14936==    at 0x80EC8CB: GLIDE::GLIDE(Section*) (glide.cpp:204)
==14936==    by 0x80EC308: GLIDE_Init(Section*) (glide.cpp:268)
==14936==    by 0x81D4664: Section::ExecuteInit(bool) (setup.cpp:271)
==14936==    by 0x81D4CB7: Config::Init() (setup.cpp:256)
==14936==    by 0x80FF896: main (sdlmain.cpp:1499)
==14936==  Address 0x4D0F384 is 0 bytes after a block of size 516 alloc'd
==14936==    at 0x40054E5: malloc (vg_replace_malloc.c:149)
==14936==    by 0x80EC88D: GLIDE::GLIDE(Section*) (glide.cpp:192)
==14936==    by 0x80EC308: GLIDE_Init(Section*) (glide.cpp:268)
==14936==    by 0x81D4664: Section::ExecuteInit(bool) (setup.cpp:271)
==14936==    by 0x81D4CB7: Config::Init() (setup.cpp:256)
==14936==    by 0x80FF896: main (sdlmain.cpp:1499)
==14936==


but I'm not sure of it...
Attachments
dosboxgl-valgrind.txt
(14.41 KiB) Downloaded 1030 times
Rainmak3r
Newbie
 
Posts: 18
Joined: 2007-8-18 @ 12:24

Re: Glide patch

Postby Rainmak3r » 2007-8-23 @ 12:18

Yes, with glide disabled dosbox works just fine, so it surely is a problem in the glide initialization somewhere...
Rainmak3r
Newbie
 
Posts: 18
Joined: 2007-8-18 @ 12:24

Re: Glide patch

Postby gulikoza » 2007-8-23 @ 12:56

That malloc might indeed be 1 element too small :)

try

fn_pt = (void**)malloc(sizeof(void*)*(GLIDE_END-GLIDE_START)+1);
User avatar
gulikoza
Oldbie
 
Posts: 1682
Joined: 2004-6-25 @ 14:53

Re: Glide patch

Postby Qbix » 2007-8-23 @ 13:03

if it 1 element shouldn't it be
fn_pt = (void**)malloc(sizeof(void*)*(GLIDE_END-GLIDE_START+1));
Water flows down the stream
How to ask questions the smart way!
User avatar
Qbix
DOSBox Author
 
Posts: 10134
Joined: 2002-11-27 @ 14:50
Location: Fryslan

Next

Return to DOSBox Development

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests