apc initial implementation
[henge/webcc.git] / html / js / the_march.config.js
index 7751827..4d4afd7 100644 (file)
@@ -2,39 +2,61 @@ var Module =
     {
         'noExitRuntime': true,
         'arguments': [],
+        'argc': 0,
+        'argv_ptr': 0,
 
-        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); },
+        //print: function(text) { for(var i=0; i<text.length; i++) document.write(String.fromCharCode(text.charCodeAt(i))); },
+        print: function(text) { console.log(text); },
+        printErr: function(text) { console.log("stderr| " + text); },
 
         //Execute the default em_main instead of main
-        execute: function(text)
+        setupArgV: function(text)
         {
             const PTR_BYTES = 4;
 
             //Parse argv and argc
             var argv = text.replace(/[\s]+/g," ").split(" ");
-            var argc = argv.length;
+            argc = argv.length;
 
             //Allocate C stack memory for the arg pointers
-            var argv_ptr = Runtime.stackAlloc(argc * PTR_BYTES);
+            //argv_ptr = Runtime.stackAlloc(argc * PTR_BYTES);
+            argv_ptr = Module._malloc(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);
+                arg_ptrs[i] = Module._malloc(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);
+        },
+
+        execute: function(func_name, args)
+        {
+            this.setupArgV(args);
+            console.log(func_name);
+            func_name(argc,argv_ptr, 0);
+            /* Free args? */
+        },
+
+        preRun: function()
+        {
+            FS.mkdir('/auth');
+            FS.mount(IDBFS, {}, '/auth');
+            FS.syncfs(true, function (err) {
+                console.log("synching failed with err:" + err);
+            });
         }
+
+
     };
 
 function start_game(event)
 {
-    Module.execute("the_march");
+    Module.execute(_em_main, "the_march");
 };
 document.getElementById("launch_game").addEventListener("click", start_game, false);