DOSBox ported to Emscripten
DOSBox is distributed under the GNU General Public License. See the COPYING file for more information.
Em-DOSBox runs most games successfully in web browsers. Although DOSBox has not been fully re-structured for running as an Emscripten main loop, most functionality is available thanks to emterpreter sync. A few programs can still run into problems due to paging exceptions.
- Game save files are written into the Emscripten file system, which is by default an in-memory file system. Saved games will be lost when you close the web page.
- Compiling in Windows is not supported. The build process requires a Unix-like environment due to use of GNU Autotools. See Emscripten issue 2208.
- Emscripten issue 1909
used to make large switch statements highly inefficient. It seems fixed now,
2275 prevents large switch
statements from being optimized. Because of this, the simple, normal and
prefetch cores are automatically transformed. Case
statements for x86 instructions become functions, and an array of function
pointers is used instead of the switch statements. The
--enable-funarrayconfigure option controls this and defaults to yes.
- The same origin policy prevents access to data files when running via a
file:// URL in some browsers. Use a web server such as
python -m SimpleHTTPServerinstead.
- In Firefox, ensure that dom.max_script_run_time is set to a reasonable value that will allow you to regain control in case of a hang.
- Firefox may use huge amounts of memory when starting asm.js builds which have not been minified.
- The FPU code uses doubles and does not provide full 80 bit precision. DOSBox can only give full precision when running on an x86 CPU.
Use the latest stable version of Emscripten (from the master branch). For more information see the the Emscripten installation instructions. Em-DOSBox depends on bug fixes and new features found in recent versions of Emscripten. Some Linux distributions have packages with old versions, which should not be used.
./configure by running
emconfigure ./configure and build with
This will create
src/dosbox.js which contains DOSBox and
a web page for use as a template by the packager. These cannot be used as-is.
You need to provide DOSBox with files to run and command line arguments for
This branch supports SDL 2 and uses it by default. Emscripten will
automatically fetch SDL 2 from Emscripten Ports and build it. Use of
to speed up compilation by running multiple Emscripten processes in parallel
may break this.
Once SDL 2 has been built by Emscripten, you can use
To use a different pre-built copy of Emscripten SDL 2, specify a path as in
emconfigure ./configure --with-sdl2=/path/to/SDL-emscripten. To use SDL 1,
--without-sdl2 argument to
Emscripten emterpreter sync is used by default. This enables more DOSBox
features to work, but requires an Emscripten version after 1.29.4 and may
cause a small performance penalty. To disable use of emterpreter sync,
--disable-sync argument to
./configure. When sync is used,
memory initialization file
is enabled, which means
dosbox.html.mem needs to be in the same folder as
dosbox.js. The memory initialization file is large. Serve it in compressed
format to save bandwidth.
WebAssembly is a
binary format which is meant to be a more efficient replacement for asm.js.
To build to WebAssembly instead of asm.js, the
-s WASM=1 option needs to
be added to the final
emcc link command. There is no need to rebuild the
object files. You can do this using the
--enable-wasm option when running
./configure. Since WebAssembly is still under very active development, use
the latest incoming Emscripten and browser development builds like
Firefox Nightly and
Building with WebAssembly changes the dosbox.html file. Files packaged using a dosbox.html without WebAssembly will not work with a WebAssembly build.
Running DOS Programs
To run DOS programs, you need to provide a suitable web page, load files into the Emscripten file system, and give command line arguments to DOSBox. The simplest method is by using the included packager tools.
The normal packager tool is
src/packager.py, which runs the Emscripten
packager. It requires
dosbox.html, which is created when building Em-DOSBox.
If you do not have Emscripten installed, you need to use
instead. Any packager or repackager HTML output file can be used as a template
for the repackager. Name it
template.html and put it in the same directory
The following instructions assume use of the normal packager. If using
repackager.py. You need
Python 2 to run either packager.
If you have a single DOS executable such as
it in the same
src directory as
packager.py and package it using:
./packager.py gwbasic Gwbasic.exe
gwbasic.data. Placing those in the same
dosbox.js and viewing
gwbasic.html will run the program in a
Some browsers have a same origin policy that prevents access to the required
data files while using
file:// URLs. To get around this you can use Python's
built in Really Simple HTTP Server and point the browser to
python -m SimpleHTTPServer 8000
If you need to package a collection of DOS files. Place all the files in a
single directory and package that directory with the executable specified. For
example, if Major Stryker's files are in the subdirectory
and it's launched using
STRYKER.EXE you would package it using:
./packager.py stryker major_stryker STRYKER.EXE
Again, place the created
stryker.data files in the same
dosbox.js and view
stryker.html to run the game in browser.
You can also include a DOSBox
configuration file that will be
acknowledged by the emulator to modify any speed, audio or graphic settings.
Simply include a
dosbox.conf text file in the package directory before you
To attempt to run Major Stryker in CGA graphics mode, you would create the
/src/major_stryker/dosbox.conf and include this body of
Then package it using:
./packager.py stryker-cga major_stryker STRYKER.EXE
Most of the credit belongs to the DOSBox crew. They created DOSBox and made it compatible with a wide variety of DOS games. Ismail Khatib got DOSBox to compile with Emscripten, but didn't get it to work. Boris Gjenero started with that and got it to work. Then, Boris re-implemented Ismail's changes a cleaner way, fixed issues and improved performance to make many games usable in web browsers. Meanwhile, Alon Zakai quickly fixed Emscripten bugs which were encountered and added helpful Emscripten features.