📜 ⬆️ ⬇️

JS-DOS API: we start DOS in the browser

For over 5 years , the emscripten project has existed. During the existence of the project has been done a lot of work. Surprise the sophisticated reader has become much more difficult. We have already seen DOOM, Dune 2, TTD, C & C and a lot more in the browser. However, it is still difficult to launch a DOS program in the browser: you need to understand C / C ++ and emscripten not bad. Experiments with Dosbox resulted in an em-dosbox project, most DOS programs are available for the browser. To put an end, it remains only to create an open API for running DOS programs in the browser.

A holy place is never empty. The concept is simple, to run the DOS program you will need:


Alley cat


The wonderful game of 1983, which I recall with great warmth. So many great ideas implemented in this game, perhaps this is the first game with mini games. Try again to plunge into the world of childhood. So, we try to start.

First of all, you need to set the dosbox screen size, in the page styles, set the size to the dosbox-container class. This is a utility class for styling the dosbox screen.
.dosbox-container { width: 640px; height: 400px; } 

')
Create a DOM element in which, after initialization, the dosbox screen will be placed. You can use any DOM element that can be referenced through the id attribute.

 <div id="dosbox"></div> 

During initialization, js-dos will create child DOM elements to display the game loading process and a canvas element to display the dosbox screen.

Note: I do not recommend stylizing the dosbox screen with shadows or translucent gradients due to significant FPS subsidence in any browser.

It remains only to connect and configure the js-dos engine.

 01. <script type="text/javascript" src="http://js-dos.com/cdn/js-dos-api.js"></script> 02. <script type="text/javascript"> 03. var dosbox = new Dosbox({ 04. id: "dosbox", 05. onload: function (dosbox) { 06. dosbox.run("http://js-dos.com/cdn/alley_cat.zip", "./CAT.EXE"); 07. }, 08. onrun: function (dosbox, app) { 09. console.log("App '" + app + "' is runned"); 10. } 11. }); 12. </script> 

The first line connects the js-dos engine, the script can be downloaded and used locally. The following is the dosbox instance creation code (line 03).


Line 06 shows the actual launch code for the game.

 06. dosbox.run("http://js-dos.com/cdn/alley_cat.zip", "./CAT.EXE"); 


Full page plunk .

Source
 <!doctype html> <html lang="en-us"> <head> <meta charset="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>js-dos api</title> <style type="text/css"> .dosbox-container { width: 640px; height: 400px; } .dosbox-container > .dosbox-overlay { background: url(http://js-dos.com/cdn/alley_cat.png); } .dosbox-start { font-size: 35px !important; } </style> </head> <body> <div id="dosbox"></div> <br/> <button onclick="dosbox.requestFullScreen();">Make fullscreen</button> <script type="text/javascript" src="http://js-dos.com/cdn/js-dos-api.js"></script> <script type="text/javascript"> var dosbox = new Dosbox({ id: "dosbox", onload: function (dosbox) { dosbox.run("http://js-dos.com/cdn/alley_cat.zip", "./CAT.EXE"); }, onrun: function (dosbox, app) { console.log("App '" + app + "' is runned"); } }); </script> </body> </html> 


Now you can run Alley Cat or anything else in the browser.

PS: The source code can be run using the file: // protocol in the browser

Source: https://habr.com/ru/post/271363/


All Articles