Emulating Deluxe Ski Jump 2 with DOSBox and wasm

Bartosz Polnik
4 min readMar 22, 2018

A couple of weeks ago, a friend of mine asked me to help him run Deluxe Ski Jump on a modern PC. DSJ 2 is a DOS game that used to be popular in pre Windows Vista era. There are newer versions of this game, but they didn’t gain such popularity as their predecessor.

There is one particularly popular way to run DSJ on Windows 10. It involves installing a DOS emulator, DOSBox and using custom configuration to improve game performance. This isn’t difficult as of itself, but I thought that I could try to run DSJ in a browser. This would make it accessible to everyone without any additional hassle. That’s also the primary reason why I got interested in WebAssembly, a web standard of binary format and execution machine that is able to run code at almost native speed.

The source code of DSJ isn’t publicly available and even if it was, there is no compiler from Turbo Pascal (DSJ implementation language) to wasm. Consequently, the only way to run this game is to use precompiled binaries and an emulator.

Fortunately, DOSBox has already been ported to support emscripten, an LLVM-to-javascript compiler. As a result, every programmer should be able to run DOS games without any difficulty.

A quick search revealed that there were many projects that tried to do the same thing as me, to run DSJ in a browser, but they either didn’t set proper emulator configuration or used the previous standard for executing code in a browser, asm.js. There was undoubtedly room for an improvement.

Emsdk

I started my journey by cloning em-dosbox, a DOSBox port and emsdk, an emscripten environment. To build em-dosbox, we need to have emsdk configured, which makes setup of emsdk our first step.
Following emscripten getting started docs, we should execute the following commands in the emsdk directory:

# Download and install the latest SDK tools.
./emsdk install latest

# Make the “latest” SDK “active” for the current user. (writes ~/.emscripten file)
./emsdk activate latest

# Activate PATH and other environment variables in the current terminal
source ./emsdk_env.sh

All of these steps went smoothly and I could move on to the DOSBox part.

Em-dosbox

Depending on a game, we may need to tune some compiler flags. The most notable are:

  • FORCE_FILESYSTEM=1, which forces embedding filesystem support in DOSBox wasm module. That’s required for DOSBOX to be able to read external files, e.g. games.
  • “BINARYEN_TRAP_MODE=’clamp’” WASM can trap. Certain instructions may halt its execution. One such example is i32.trunc_s/f32, which raises an exception when converting from floating point to integer fails. It’s important to recognize that such situations may occur (in DSJ they happen) and configure emsdk to use either js trap mode (ask it to behave in the same way as js) or clamp. The second choice tries to use reasonable value when deciding on a return value, it doesn’t trap and is faster than js.

These flags are quite general, they are applicable to many games, so I added them to /src/Makefile.am.

Let’s try to build em-dosbox:

After making em-dosbox, we should see dosbox.js and dosbox.wasm files in the src directory.

Packaging DSJ 2

The last part of running DSJ 2 in a browser is packaging the game itself. To obtain a fresh copy, visit Mediamond page and download a free demo. I will assume from now on, that the game archive was unpackaged next to the em-dosbox folder.

Similarly to running DSJ on Windows, we also need a custom DOSBox configuration. This time, however, we will deliver it with the game. Let’s create dosbox.conf file within game directory and use the same settings as suggested for playing DSJ with DOSBox on Windows:

Deluxe Ski Jump relies on a presence of external files within the same directory as the main executable, DSJ.EXE. Therefore, it’s best to package the whole game directory. To do it, we need to issue the following command in em-dosbox/src folder:

That would create two files, dsj.data and dsj.html, next to previously generated DOSBox’s files.

Due to same-origin policy, opening dsj.html directly from a file system will not work and we need to serve all four files, dosbox.js, dosbox.wasm, dsj.data and dsj.html via an HTTP server. For testing purposes, we can use the command emrun to do that:

That step completes configuring emsdk, building em-dosbox and preparing the game.

Now, it’s time for the best part. Playing!

Just one tip: disabling sound helps a little bit to improve performance!

That’s all for today. Thanks for reading!

All resources used in this post are available in my Github repository https://github.com/bartekbp/em-dosbox/tree/deluxe-ski-jump

--

--