em-dosbox and 50 gifts for the new year

    Some things only get better over the years. For example, classic games developed in the DOS era are fascinating. Each of them is a piece product made with great love. Unfortunately, the DOS platform is a thing of the past and wonderful products are leaving with it. To return them to the modern world - is this not a real gift?

    How? Very simple! An interested reader, of course, remembers the emscripten project, thanks to which C ++ code can be converted to JavaScript to work in the browser. It was with his help that the games DOOM, Dune 2, TTD, X-COM and many others were adapted for the browser. However, this path is long and difficult. One project can take up to six months. And if you want everything at once? Is there any other way?


    There is another way - use DosBox. Indeed, why port each project individually, when you can port the entire DOS platform (to be precise, the MS-DOS emulator). This ingenious idea was embodied by Boris Gjenero in the em-dosbox project . This is the DosBox port in JavaScript made using emscripten.

    So, now I will tell you how to transfer "almost any" DOS program to the browser.

    • Browser
    • em-dosbox (dosbox.js)
    • The program works correctly in DosBox

    During operation, the browser downloads dosbox.js and a data packet with the program (usually a binary file with a packed directory of the source program). The dosbox.js script is nothing more than a DosBox ported to JavaScript; when executed, it emulates the DOS platform with a program running in it.

    Compiling dosbox.js

    Everything is simple. We clone the em-dosbox repository and compile using autotools and make
    git clone https://github.com/dreamlayers/em-dosbox.git
    cd em-dosbox

    If successful, dosbox.html and dosbox.js will appear in the src folder

    Improving em-dosbox performance
    Add the option --memory-init-file 0 to dosbox_LDFLAGS in src / Makefile.am . This option disables the generation of a memory file, which is used to speed up loading. In our case, this file will be about thirty megabytes in size, which is not applicable for the browser.
    dosbox_LDFLAGS = -s TOTAL_MEMORY=67108864 --pre-js pre.js --memory-init-file 0

    In the src / dosbox.cpp file I recommend replacing
    emscripten_set_main_loop(em_main_loop, 100, 1); 
    on the
    emscripten_set_main_loop(em_main_loop, 0, 1); 

    This edit will increase productivity by an order of magnitude. But you need to take into account that the target program should be smart enough and able to run at the same speed regardless of computer performance, otherwise your program will work too fast.

    To speed up the emulator, add lines to the main function in the src / gui / sdlmain.cpp file :
    #ifdef EMSCRIPTEN
    	EM_ASM("SDL.defaults.copyOnLock = false; SDL.defaults.discardOnLock = true; SDL.defaults.opaqueFrontBuffer = false;");

    Program packaging

    em-dosbox comes with a script that allows you to pack the directory with the program into a binary file, which can be used in conjunction with dosbox.js. For example, to get a batch file for a Dune 2 game, just do:
    #python src/packager.py <имя пакета> <путь до директории> <исполняемый файл>
    python src/packager.py dune2 ~/dune2 dune2.exe

    If successful, the dune2.html and dune2.data files will be created . The HTML file is created using the dosbox.html template (recall, it lies in the src folder ).

    Change dosbox settings
    By default, dosbox will be launched with a standard configuration. To change it, just create a dosbox.conf file in the program folder . And modify the build script as follows:
    #86 строка
    f.write("Module['arguments'] = [ '-conf', './dosbox.conf', './" + EXECUTABLE + "' ];\n\n")


    So we have three files:
    • program.html
    • program.data
    • dosbox.js

    By placing them on the server we can run the program in a browser.

    Happy New Year.
    50 New Year's gifts.

    List of adapted games
    The following games have been adapted for the browser using em-dosbox:
    • Abuse
    • Alley cat
    • Another world
    • Arcade volleyball
    • Arkanoid
    • Battle chess
    • Budokan: The Martial Spirit
    • Cd-man
    • Colorado
    • Dangerous Dave in the Haunted Mansion
    • Deathtrack
    • Digger
    • Disney's Duck Tales: The Quest for Gold
    • Doom
    • Doom 2
    • Dune 2
    • Dyna blaster
    • Earthworm Jim 2
    • Fire & forget ii
    • Goblins 1-3
    • Golden ax
    • Heretic: Shadow of the Serpent Riders
    • Incredible machine
    • The
    • IndyCar Racing
    • Krypton egg
    • Lamborghini: American Challenge
    • Lode runner
    • Lost Vikings
    • The
    • Metal mutant
    • Micro machines
    • Mine bombers
    • Mortal kombat
    • Pac-man
    • Prehistorik
    • Prehistorik 2
    • Prince of persia
    • Scorched Earth: The Mother of All Games
    • Simcity
    • Stunts
    • Supaplex
    • Test drive
    • Tetris
    • Tower topler
    • Tyrian 2000
    • Ugh!
    • Warcraft: Orcs & Humans
    • Wings of fury
    • Winter Supersports 92
    • Wolfenstein 3D
    • Xonix

    Also popular now: