Slashdot Mirror


Breathing New Life Into Old DirectDraw Games

An anonymous reader writes "I bought a bunch of old Wing Commander games for Windows, but they use DirectDraw, which Microsoft has deprecated. They don't work too well under Windows 7, so I ended up reimplementing ddraw.dll using OpenGL to output the games' graphics. I wrote an article describing the process and all the fun workarounds I had to come up with, and released all related source code for others to hack on."

23 of 274 comments (clear)

  1. There were some damn fine games in that era... by Dexter+Herbivore · · Score: 4, Insightful

    and we didn't need gimmicks like motion controllers, photo-realistic graphics and high framerates to enjoy them.

    1. Re:There were some damn fine games in that era... by reverendbeer · · Score: 4, Funny

      and we didn't need gimmicks like motion controllers, photo-realistic graphics and high framerates to enjoy them.

      ...consarn it!

    2. Re:There were some damn fine games in that era... by LazLong · · Score: 4, Funny

      and we didn't need gimmicks like motion controllers, photo-realistic graphics and high framerates to enjoy them.

      In my day we didn't have fancy-schmancy graphics. We didn't have graphics all. All we had were alphanumeric characters to manipulate for our games. And that's how it was, and you liked it! Sound? You were lucky if you could get a single-toned beep from your computer. And don't get me started on those fancy motion controllers! All we had was the keyboard. We stabbed ADWS until our fingers bled. And games? We had great games like Lemonade Stand, Tic-Tac-Toe, SpaceWar!, Star Trek, Super Star Trek. And that's how it was, and you liked it! You loved it!

  2. Wine? by Ynot_82 · · Score: 4, Interesting

    I haven't read TFA yet
    but wouldn't this have been a prime use-case for Wine on Windows?

    1. Re:Wine? by Anonymous Coward · · Score: 4, Interesting

      "Funny you should mention that..." I blew this morning trying to get some old PS2 hacking apps running on Wine. In the end I just installed w98 on a spare box. Wine is classic YMMV. It's a good, worthy project, but man, you just can't _count_ that's it's going to deal with even small old VB6 apps ahead of time. Use restraint for recommending it unless you've done exactly what's being discussed.

    2. Re:Wine? by advocate_one · · Score: 4, Insightful

      "Funny you should mention that..." I blew this morning trying to get some old PS2 hacking apps running on Wine. In the end I just installed w98 on a spare box. Wine is classic YMMV. It's a good, worthy project, but man, you just can't _count_ that's it's going to deal with even small old VB6 apps ahead of time. Use restraint for recommending it unless you've done exactly what's being discussed.

      what seriously pisses me off with WINE is that something works with one version of it, but breaks in the next... the database is almost useless with regards to being kept up to date and I'm too old for all this hassle now... and there's TOO much emphasis on having the very latest game running on it to the detriment of making sure other games don't become broken by changes made to support the latest and greatest...

      --
      Donald 'Duck' Dunn: We had a band powerful enough to turn goat piss into gasoline.
    3. Re:Wine? by bmcage · · Score: 4, Insightful

      Wingcommander ran great in wine last time I played it in 2008. I suppose windows developers don't follow linux development?

    4. Re:Wine? by mr_mischief · · Score: 5, Insightful

      Automated testing of all the applications is pretty much a nonstarter. However, automated regression testing to make sure function calls with the same arguments in the same context don't give different results just because you debugged a different set of arguments or in a different environment are easy to do with a proper test harness. The hard part is mapping the applications to test cases, but that's not impossible, just time consuming and somewhat difficult.

  3. Who says DirectDraw is going away? by Man+On+Pink+Corner · · Score: 4, Informative

    My own DirectDraw apps from 1996 work great in Windows 7. The API is deprecated in the sense that Microsoft no longer recommends using it, and who knows if they're still even shipping ddraw.h, for that matter. But as a COM component, runtime support for IDirectDraw isn't any more endangered than CreateWindow().

    1. Re:Who says DirectDraw is going away? by Suiggy · · Score: 5, Insightful

      Yes, DirectDraw still exists on Windows 7, ddraw.dll is still there, and the headers are still a part of the Windows SDK and DirectX SDK. The problem is that graphics card vendors no longer care to test that their drivers work properly with DirectDraw, so it's really hit or miss if you get support.

    2. Re:Who says DirectDraw is going away? by peppepz · · Score: 5, Informative

      But removing IDirectDraw would only break some games from the 90s, while removing CreateWindow (Ex) would kill every single Windows application ever coded.

    3. Re:Who says DirectDraw is going away? by Xest · · Score: 4, Interesting

      Indeed, in fact, this was precisely one of the problems DirectX was always designed to solve from the start, it was designed to provide a multimedia API that could both move with the times and retain backwards compatibility.

      Issues with older games tend to come down to hardware specific optimisations, obsolete libraries such as Glide, or OS specific code.

      For the most part, stuff written with Microsoft's officially provided Windows APIs even back to Windows 95 (and sometimes even further back than that) tends to still run. It's the stuff that doesn't use those APIs that often causes the problems.

      For better or worse, backwards compatbility is one thing that Microsoft certainly does tend to get right most the time. It's just that companies often ignore backwards compatibility when building new apps and just build for the now. Sometimes this is excused, i.e. game companies doing low level optimisations to improve performance, other times it's some MBA falling hook line and sinker for the sales pitch of some fly by night company providing an obscure set of code libraries and mandating all his developers use it.

      I still have apps I wrote in C using the raw Win32 API back in 1995/1996 that work absolutely fine to this day.

      Chances are if a game doesn't run, DirectX version is the least of it's troubles.

    4. Re:Who says DirectDraw is going away? by TheRaven64 · · Score: 5, Informative

      Indeed, in fact, this was precisely one of the problems DirectX was always designed to solve from the start, it was designed to provide a multimedia API that could both move with the times and retain backwards compatibility.

      DirectX was designed to solve precisely one problem: that game developers wrote games for DOS and didn't regard Windows as a sufficiently capable platform for gaming. In its early iterations, it was a very low-level API. It basically gave you a way of bypassing Windows and talking almost directly to the graphics and sound cards.

      Remember that, at the time, graphics cards were very simple devices. A lot were just frame buffers - a blob of memory connected to a DAC that scanned its contents and generated an analogue signal for a monitor. Some supported double buffering (i.e. two frame buffers and a flag to tell the DAC which one to read). They quite often had a BitBlt operation, which would copy a rectangle onto the frame buffer from RAM (across the bus) or from a bit of reserved VRAM, typically with a mask. A very few of them could also do line drawing and scaling of images during the blits.

      DirectDraw provided functions that were very thin wrappers around the graphics card's capabilities. It was designed from the start to make porting DOS games to Windows easy. Most DOS game developers had a small library of functions that implemented a few primitive graphics routines like bitblt in software and would use accelerator functions if they were available. You might remember games like SimCity 2000 requiring you to select which graphics card you had. It would use accelerated line drawing and blits if they were available.

      DirectDraw just replaced these libraries, providing very thin wrappers around the hardware facilities and emulated versions when they were not present (e.g. using memcpy() for BitBlt). It wasn't designed as a high-level API, and directly exposed things like the palette modes in the hardware. The problem that old games are starting to experience comes from this fact. Modern GPUs don't support palette modes at all, but a lot of old games used them because they took less VRAM and let you do some animation effects. At the time, all cards supported palettes and a few also supported true colour - designing for a card that didn't support palettes seemed pointless.

      At the DirectDraw layer, all of this stuff is passed straight down to the driver and on slightly older cards they were then passed directly to the hardware. Companies like nVidia don't always bother properly implementing emulation paths in the driver for old software, so the games stop working.

      --
      I am TheRaven on Soylent News
  4. Re:Or you could by dintech · · Score: 4, Insightful

    But to run Wing Commander on modern hardware, it doesn't need to be optimal. 80/20 rule dude.

  5. Text, I think by Anonymous Coward · · Score: 5, Informative

    In the Beginning

    It all started about a month ago, when one friend of mine had decided to follow his dreams and was moving to the states, and he had to get rid of a lot of stuff. Among his discard pile was a bunch of Wing Commander games, which I bought off him, figuring they might be interesting research material, as I'm planning on a game with similar game play structure (as in story combined with game play, not a 3d space shooter).

    So, I found myself in the possession of Wing Commanders 1, 2, 3 and 4, all Windows versions - the Kilrathi Saga and WC4CD to be specific. I installed the first and tried it out. My Win7 switched to 256 colors at a 640x480 resolution, but the game ran.. with completely wrong palette.

    Bugged by this I played with the compatibility options, and got the game to almost work well, with the palette going wrong at some points.. so the game was sort of playable, but I hated the fact that Windows changed to 256 colors and I couldn't see my mailbox properly in the other screen, etc.

    I also tried WC2 and WC3, and they had similar - or worse - problems. I even learned the steps to get WC3 to work properly:

    1. Find the WC3W.EXE executable, turn on (basically) all the compatibility options.
    2. Start task manager.
    3. Find and kill all instances of explorer.exe. Your desktop will disappear, along with the task bar.
    4. Using task manager, launch WC3W.EXE

    Naturally the screen resolution and color mode will be 640x480 and 256 colors, but if you've bent backwards that much, you probably don't care all that much.

    Seeing that the games use DirectDraw, I decided to roll my own.

    Doing the Homework

    The first step is always to look for prior art. Maybe someone had written a new ddraw.dll already, and I could just use it. As it happens, lots of people have, but nothing that's useful for me. Most of the ddraw.dll hacks are actually wrappers - that get between the game and the real ddraw.dll, change something subtle, but let the real ddraw.dll do the heavy lifting.

    The point of these hacks is to fix small problems, like games that ignore surface pitch, require cleared surfaces or some such. In one case I found a forum thread claiming that deleting ddraw.dll from the game's directory fixes something, so in this case it's a hack gone wrong.

    After further searching I found a project which actually released sources, with a liberal license even. It was a wrapper project (meaning, again, that they just call the real ddraw.dll), only supported DirectDraw7 and only very small parts of it, but it showed me how to get going.

    I also dug up old DirectX SDK:s from my personal CD stack, as Microsoft has helpfully nuked all old DirectDraw documentation off the online MSDN. Thanks, dudes.

    Wing Commander 1

    Wing Commander 1 for Windows uses DirectDraw2. There's no real reason it couldn't just use DirectDraw1, considering that all it does is locking the front buffer and dumping a frame to it, along with some palette manipulation.

    Or well, that's not the whole truth. If the game can set a 320x200 mode, it does what I described above. If this fails, it tries to set up 640x400, and after that fails, 640x480. In the two higher resolution modes, the game allocates a software 320x200 buffer, and uses blt() to scale it up 2x, meaning that in 640x480 mode, black bars are introduced to the top and the bottom, and the aspect ratio is wrong.

    When playing WC1 it astonishes me just how much love has gone into the it when compared to later games. The later ones may be better in some ways, but the polish that can be experienced in WC1 is gone.

    Anyway, I started by writing a wrapper that just dumps out log about what calls are made with what parameters, and then went on to implement a hack dll that only implements those calls.

    The hack dll resizes the application's window to desktop resolution, sets up an OpenGL context, uploads

  6. Re:Or you could by kinema · · Score: 5, Insightful

    What is learned by simply booting up a VM and loading a game? In the story submission he specifically mentioned "all the fun workarounds" that he had to come up with get everything to work on a modern system. Don't you think doing a cleanroom reimplementing a subsystem like DirectDraw presents a great learning experience?

    No, I wouldn't have done this if you had payed me; I have my own interests and passions. I'm not at all interested in graphics programming or for that matter video games, though, apparently someone is and I think it's great that he saw a problem and decided to attempt to find a solution for it.

    This is what being a geek is all about. Bravo.

  7. Re:heads up for combat soldiers' family and friend by linguizic · · Score: 5, Funny

    I try to enjoy parties, but every time I can't help but feel bad for all those poor Indians who died in 1812 during the Boston Tea Party.

    --
    Does this sig remind you of Agatha Christie?
  8. Re:I wonder about this by Rogerborg · · Score: 4, Interesting

    Funny you should mention DX3. Microsoft actually removed some surface caps flags in the transition from DX3 to DX5, and silently flipped the orientation that .BMP files were loaded (i.e. loaded them 'right way up' rather than 'upside down' as they're stored in the file). I know that was like three ice ages ago in Dev Years, but it still hurts when I think about it.

    I realise that TheFineSummary talks about Windows 7, but there's still a fair number of XP boxen out there, for which Direct2D isn't an option. That said, I'd guess (as the article is down) that it's more of an ideological position, or - given that it's clearly a hobby project - just what the author is familiar with, or enjoys using. Given that we're talking about playing games here, I'd go with the latter explanation.

    I do intend to RTFA when it recovers, since I find replacing/subverting dlls quite fun. I kludged up some code a while back to create a shim dll that can be used as the basis for selectively replacing functions in dlls, while calling through to the 'real' one for the other functions, so you can easily hack some functionality without having to re-implement the whole thing.

    --
    If you were blocking sigs, you wouldn't have to read this.
  9. Re:I wonder about this by TheThiefMaster · · Score: 5, Informative

    Not 100% accurate. Windows 7 includes direct-x 9 itself (there's not much to it), but not all the different d3dX9_??.dll extension files. Those are what you have to install.

    The DX web setup will bring you up to date with all direct-x 9 onwards extension files, regardless of whether you're running XP or 7, x86 or x64, Home or Ultimate (just look at the comprehensive supported OSs list!).

    Any older versions of DX are supported, you shouldn't need to install anything for them.

  10. Re:Or you could by Your.Master · · Score: 5, Insightful

    It's only already done if the only ddraw game you want to play is Wing Commander 1-4 (Windows versions). And only with conventional monitor setups and only if you never want to capture the window content, due to the kludges involved. And if you can stand the known bugs he mentioned, eg. the blinking screen effect described in Wing Commander 4.

    So basically, it's only already done if you want a suboptimal experience. But you were just talking about how you wanted an optimal solution, and how a solution that basically works better than this is "never" the optimal solution. To be fair, it sounds like 1-3 work pretty well, but for 4 you have to put up with some crap. And any other ddraw game is unlikely to work all that well.

    This is a fun an interesting reverse engineering project. Stop being such a prick about it.

  11. Oh stop by Sycraft-fu · · Score: 5, Insightful

    The "Back in the day things were so much better," stuff gets annoying no matter what it is about and games are no exception. Were there good games back in the day? Sure were. Guess what? There were also bad ones, you just don't remember them as well. This is in part because our memory tends to deliberately filter out bad experience, but mainly because good games you played a ton, bad games got set aside.

    Know what else? There are good games now. The modern graphics and so on have not stopped people form being able to make good games.

    Also I don't like this elitist "purist" thing that people pretend to of "Oh I don't even like the graphics, I just want good gameplay." Guess what? The graphics and sound can well be a part of that. When games are visually appealing it can add to the immersivness. It is easier to lose yourself in a convincing world.

    So stop getting all "Get off my lawn," about games. There are great old games and you can still enjoy them with the help of emulators. However don't hate on new games just because they look better. That is not a bad thing, it is a good thing.

  12. Which is it -- 80 or 20? by CarpetShark · · Score: 4, Funny

    But to run Wing Commander on modern hardware, it doesn't need to be optimal. 80/20 rule dude.

    But does the 80% go to the rear shields, or the front?