First post, by jez
- Rank
- Member
-mwindows <--- the bane of my existance. 😀 Let me explain.
The official release of DOSbox 0.58 ran as a console application. This is exactly what's needed, because DOSbox uses STDOUT to output normal (non-debug) messages. It's not much good writing 'frameskip at 8' or whatever to a file, after DOSbox has been closed! You need live output to a console window.
But how to get DOSbox to compile as a console app? I was determined to use a Unix-like compiler (gcc port) and ended up using MingW, but Cygwin would probably work too. The MingW documentation tells you that it compiles applications as console apps by default, and indeed it does. You can also specify a -mwindows flag to get it to compile as a windowed application, and -mwindows -mconsole also spits out a console window for STDOUT and STDERR to go to. This seemed like the best solution, explicitly declaring a windowed app AND a console, so I went for that.
You'd think that, to get make to add these flags when compiling the relevant files (just dosbox.exe as far as I can tell), you'd need to change something in the DOSbox source directory. Wrong. DOSbox copies a load of flags from SDL, using the SDL_LIBS environment variable. After much searching, I found the origin of this variable to be SDL's ./configure script.
I recommend that anyone compiling DOSbox first changes SDL's ./configure and ./configure.in before making and installing SDL, to make DOSbox compile as an application with a console window. I did this by modifying the code like so:
# MODIFIED BY JEZ
# SDL_LIBS="-lmingw32 -lSDLmain $SDL_LIBS -mwindows -mno-cygwin"
SDL_LIBS="-lmingw32 -lSDLmain $SDL_LIBS -mwindows -mconsole -mno-cygwin"
;;
*-*-mingw32*)
# MODIFIED BY JEZ
# SDL_LIBS="-lmingw32 -lSDLmain $SDL_LIBS -mwindows"
SDL_LIBS="-lmingw32 -lSDLmain $SDL_LIBS -mwindows -mconsole"
;;
However, there's yet another complication (or 2). ./autogen.sh, the script that creates ./configure for SDL, doesn't seem to work on my system; it just screws up the configuration totally. Fortunately, SDL comes bundled with a premade ./configure, so I just use that. However, In order for that to work, ./configure.in must be a certain age or older, or ./configure just screws up the make. I have no idea why, Unix shell scripts are not my forté. Maybe it tries to recreate ./configure unsuccessfully, or something. So, after modifying ./configure and ./configure.in, you need to forcibly set ./configure.in's modified date back to before a certain date/time, probably a date/time that's hardcoded somewhere in the sourcetree for SDL; in my case, that date/time was Sunday, 06 October 2002, 13:34:54. I just set the modified date for ./configure.in to some time back in 2001. 😀 You can do this in Windows with a tool like FileDate, found here.
I said there was another complication. There is. SDL for Windows is configured, by default, to redirect STDOUT etc to textfiles, because it defaults to a non-console app and if it didn't do that redirection, STDOUT etc would just be discarded. You can change this by using the ./configure parameter --disable-stdio-redirect, but that's annoying to have to do every time you configure, so I just modified src/main/win32/sdl_main.c like this:
/* Do we really not want stdio redirection with Windows CE? */
#ifdef _WIN32_WCE
#define NO_STDIO_REDIRECT
#endif
/* ADDED BY JEZ */
/* What we want is NEVER to have STDIO redirection! */
#define NO_STDIO_REDIRECT
Simple.
So, now after finally making and installing SDL, DOSbox will compile as a console application, and what it outputs to STDOUT will be pushed into a console window live, instead of written to a textfile after DOSbox closes. Amazing how many of DOSbox's build settings are controlled by SDL's configuration. 😀
For anyone interested, I'm attaching a .zip file containing the 3 modified files (./configure, ./configure.in, and src/main/sdl_main.c) that I used in the SDL sourcetree to get this favourable configuration, complete with the 2001 modified date for ./configure.in and all. 😀 They can happily be overwritten into your SDL sourcetree (my version is SDL 1.2.5) before making and installing SDL.
*** Update: Stupid board doesn't let you delete an attachment then upload a new one, check below for the attachment posted in a seperate reply. ***
Sorry about the length of this post, but I think it's quite an informative tutorial, and it took me quite a while to figure it out (most people I asked didn't seem to know much about it).
Plans for my future builds:
- Get DOSbox to start outputting more messages again, like current CPU cycles/second.
- Get DOSbox to start pausing and waiting for a keypress again before exiting, when it crashes!
- Massively improve keyboard code, maybe even allow custom keyboard mappings.
- Try and achieve more speed by compiling SDL to use DirectX instead of the Windows GDI.
- Try and achieve more speed by compiling SDL and/or DOSbox with some extra compiler optimizations.
- Get native screenshot support into my builds by getting libPNG to work with DOSbox.
- And probably much much more... 😀
Ah, the adventures of trying to improve a cool app.
Just for the record, DOSbox rules. If I can run something like Magic Carpet at a few FPS, with perfect sound and good graphics emulation, right now on my AMD Athlon 1.4ghz, I'm sure that in 1 or 2 years' time, we'll have a perfect 386/486 w/ DOS emulator. Great work guys... keep it up, and NEVER let the DOS classics die out!!
== Jez ==