apc initial implementation
[henge/webcc.git] / html / js / the_march.config.js
1 var Module =
2 {
3 'noExitRuntime': true,
4 'arguments': [],
5 'argc': 0,
6 'argv_ptr': 0,
7
8 //print: function(text) { for(var i=0; i<text.length; i++) document.write(String.fromCharCode(text.charCodeAt(i))); },
9 print: function(text) { console.log(text); },
10 printErr: function(text) { console.log("stderr| " + text); },
11
12 //Execute the default em_main instead of main
13 setupArgV: function(text)
14 {
15 const PTR_BYTES = 4;
16
17 //Parse argv and argc
18 var argv = text.replace(/[\s]+/g," ").split(" ");
19 argc = argv.length;
20
21 //Allocate C stack memory for the arg pointers
22 //argv_ptr = Runtime.stackAlloc(argc * PTR_BYTES);
23 argv_ptr = Module._malloc(argc * PTR_BYTES);
24
25 var arg_ptrs = [];
26 for(var i = 0; i < argc; i++)
27 {
28 //stack allocate for each argument
29 arg_ptrs[i] = Module._malloc(argv[i].length+1);
30 //Add to argv's list of pointers in c-memory, then copy data
31 setValue(argv_ptr + i * PTR_BYTES, arg_ptrs[i], 'i32');
32 writeStringToMemory(argv[i], arg_ptrs[i]);
33 }
34
35 },
36
37 execute: function(func_name, args)
38 {
39 this.setupArgV(args);
40 console.log(func_name);
41 func_name(argc,argv_ptr, 0);
42 /* Free args? */
43 },
44
45 preRun: function()
46 {
47 FS.mkdir('/auth');
48 FS.mount(IDBFS, {}, '/auth');
49 FS.syncfs(true, function (err) {
50 console.log("synching failed with err:" + err);
51 });
52 }
53
54
55 };
56
57 function start_game(event)
58 {
59 Module.execute(_em_main, "the_march");
60 };
61 document.getElementById("launch_game").addEventListener("click", start_game, false);
62