BuildSys1
[henge/webcc.git] / html / js / the_march.config.js
diff --git a/html/js/the_march.config.js b/html/js/the_march.config.js
new file mode 100644 (file)
index 0000000..7751827
--- /dev/null
@@ -0,0 +1,40 @@
+var Module =
+    {
+        'noExitRuntime': true,
+        'arguments': [],
+
+        print: function(text) { for(var i=0; i<text.length; i++) document.write(String.fromCharCode(text.charCodeAt(i))); document.write("<br />");},
+        printErr: function(text) { console.log("ERR: " + text); },
+
+        //Execute the default em_main instead of main
+        execute: function(text)
+        {
+            const PTR_BYTES = 4;
+
+            //Parse argv and argc
+            var argv = text.replace(/[\s]+/g," ").split(" ");
+            var argc = argv.length;
+
+            //Allocate C stack memory for the arg pointers
+            var argv_ptr = Runtime.stackAlloc(argc * PTR_BYTES);
+
+            var arg_ptrs = [];
+            for(var i = 0; i < argc; i++)
+            {
+                //stack allocate for each argument
+                arg_ptrs[i] = Runtime.stackAlloc(argv[i].length+1);
+                //Add to argv's list of pointers in c-memory, then copy data
+                setValue(argv_ptr + i * PTR_BYTES, arg_ptrs[i], 'i32');
+                writeStringToMemory(argv[i], arg_ptrs[i]);
+            }
+
+            _em_main(argc, argv_ptr, 0);
+        }
+    };
+
+function start_game(event)
+{
+    Module.execute("the_march");
+};
+document.getElementById("launch_game").addEventListener("click", start_game, false);
+