libwolfssl ported
[henge/webcc.git] / html / js / the_march.config.js
1 var Module =
2 {
3 'noExitRuntime': true,
4 'arguments': [],
5
6 print: function(text) { for(var i=0; i<text.length; i++) document.write(String.fromCharCode(text.charCodeAt(i))); document.write("<br />");},
7 printErr: function(text) { console.log("ERR: " + text); },
8
9 //Execute the default em_main instead of main
10 execute: function(text)
11 {
12 const PTR_BYTES = 4;
13
14 //Parse argv and argc
15 var argv = text.replace(/[\s]+/g," ").split(" ");
16 var argc = argv.length;
17
18 //Allocate C stack memory for the arg pointers
19 var argv_ptr = Runtime.stackAlloc(argc * PTR_BYTES);
20
21 var arg_ptrs = [];
22 for(var i = 0; i < argc; i++)
23 {
24 //stack allocate for each argument
25 arg_ptrs[i] = Runtime.stackAlloc(argv[i].length+1);
26 //Add to argv's list of pointers in c-memory, then copy data
27 setValue(argv_ptr + i * PTR_BYTES, arg_ptrs[i], 'i32');
28 writeStringToMemory(argv[i], arg_ptrs[i]);
29 }
30
31 _em_main(argc, argv_ptr, 0);
32 }
33 };
34
35 function start_game(event)
36 {
37 Module.execute("the_march");
38 };
39 document.getElementById("launch_game").addEventListener("click", start_game, false);
40