var gamename = 'smurfs.zip';
var game_file = null;
var js_data = null;
var bios_filenames = 'coleco.zip'.split(' ');
var bios_files = {};
var file_countdown = 1;
if (bios_filenames.length !== 0 && bios_filenames[0] !== '') {
  file_countdown += bios_filenames.length;
}
if (gamename !== '') {
  file_countdown++;
}

var newCanvas = document.createElement('canvas');
newCanvas.id = 'canvas';
newCanvas.width = 256;
newCanvas.height = 256;
var holder = document.getElementById('canvasholder');
holder.appendChild(newCanvas);

var fetch_file = function(url, cb, rt, raw) {
  var xhr = new XMLHttpRequest();
  xhr.open("GET", url, true);
  xhr.responseType = rt ? rt : "arraybuffer";
  xhr.onload = function(e) {
    var ints = raw ? xhr.response :  new Int8Array(xhr.response);
    cb(ints);
  };
  xhr.send();
};

var Module = {
  'arguments': ["coleco","-verbose","-rompath",".","-cart",gamename,"-window","-resolution","256x192","-nokeepaspect"],
  print: (function() {
    var element = document.getElementById('output');
    return function(text) {
      text = text.replace(/&/g, "&amp;");
      text = text.replace(/</g, "&lt;");
      text = text.replace(/>/g, "&gt;");
      text = text.replace('\n', '<br>', 'g');
      element.innerHTML += text + '<br>';
    };
  })(),
  canvas: document.getElementById('canvas'),
  noInitialRun: false,
  preInit: function() {
    // Load the downloaded binary files into the filesystem.
    for (var bios_fname in bios_files) {
      if (bios_files.hasOwnProperty(bios_fname)) {
        Module['FS_createDataFile']('/', bios_fname, bios_files[bios_fname], true, true);
      }
    }
    Module['FS_createDataFile']('/', gamename, game_file, true, true);
  }
};

var update_countdown = function() {
  file_countdown -= 1;
  
  if (file_countdown === 0) {
    var headID = document.getElementsByTagName("head")[0];
    var newScript = document.createElement('script');
    newScript.type = 'text/javascript';
    newScript.text = js_data;
    headID.appendChild(newScript);
  }
};

// Fetch the BIOS and the game we want to run.
for (var i=0; i < bios_filenames.length; i++) {
  var fname = bios_filenames[i];
  if (fname === "") {
    continue;
  }
  fetch_file(fname, function(data) { bios_files[fname] = data; update_countdown(); });
}

if (gamename !== "") {
  fetch_file(gamename, function(data) { game_file = data; update_countdown(); });
}

fetch_file('messcolecovision.js.gz', function(data) { js_data = data; update_countdown(); }, 'text', true);

@@ -131,16 +131,35 @@
 s = %7B%7D;%0A
+var requests = %5B%5D;%0A
 var file
@@ -544,30 +544,1045 @@
 var 
-fetch_file = function(
+draw_loading_status = function() %7B%0A  var font_height = 18;%0A  var line_height = (newCanvas.height - (font_height * 2)) / (requests.length);%0A  var context = newCanvas.getContext('2d');%0A  context.clearRect(0, 0, newCanvas.width, newCanvas.height);%0A  context.font = font_height + 'px sans-serif';%0A  context.fillStyle = 'Black';%0A  context.fillText('Loading...', 0, font_height);%0A  for(var i = 0; i %3C requests.length; i++) %7B%0A     var o = requests%5Bi%5D;%0A     var y = (line_height * i) + (font_height * 2);%0A     context.fillStyle = 'Red';%0A     context.fillRect(0, y, newCanvas.width, line_height);%0A     context.fillStyle = 'Green';%0A     context.fillRect(0, y, newCanvas.width * o.progress, line_height);%0A     context.fillStyle = 'Black';%0A     context.fillText(o.title + ' ' + Math.round(o.progress * 100) + '%25', 0, y + (font_height / 2) + (line_height / 2));     %0A%7D%0A%7D%0A%0Avar progress_fetch_file = function(e) %7B%0A  if(e.lengthComputable) %7B%0A    e.target.progress = e.loaded / e.total;%0A    draw_loading_status();%0A  %7D%0A%7D%0A%0Avar fetch_file = function(title, 
 url,
@@ -1732,24 +1732,75 @@
 nction(e) %7B%0A
+    xhr.progress = 1.0;%0A    draw_loading_status();%0A
     var ints
@@ -1872,16 +1872,119 @@
 );%0A  %7D;%0A
+  xhr.onprogress = progress_fetch_file;%0A  xhr.title = title;%0A  xhr.progress = 0;%0A  requests.push(xhr);%0A
   xhr.se
@@ -3386,16 +3386,24 @@
 ch_file(
+'Bios', 
 fname, f
@@ -3507,16 +3507,24 @@
 ch_file(
+'Game', 
 gamename
@@ -3598,16 +3598,30 @@
 ch_file(
+'Javascript', 
 'messcol
@@ -3701,16 +3701,40 @@
  'text', true);%0A
+%0Adraw_loading_status();%0A

Add download progress