X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fwebcc.git;a=blobdiff_plain;f=html%2Fjs%2Fthe_march.config.js;fp=html%2Fjs%2Fthe_march.config.js;h=7751827d6b09b194475b76c866ae34a17902de23;hp=0000000000000000000000000000000000000000;hb=fb95ec1cd9d2d15a5580f2e96f0a3c129f9292bb;hpb=88ece196880f76b546112c4d7896ff93d654509c diff --git a/html/js/the_march.config.js b/html/js/the_march.config.js new file mode 100644 index 0000000..7751827 --- /dev/null +++ b/html/js/the_march.config.js @@ -0,0 +1,40 @@ +var Module = + { + 'noExitRuntime': true, + 'arguments': [], + + print: function(text) { for(var i=0; i");}, + 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); +