 return xhr;
    },
    complete: function(xhr, status) {
      nes.loadRom(xhr.responseText);
      nes.start();
    }
  });
}

function triggerKey(type, keyCode) {
  var e = jQuery.Event(type);
  e.which = keyCode;
  e.keyCode = keyCode;
  $(document).trigger(e);
}

function sendKey(type, keyCode) {
  ws.send(type + " " + keyCode);
}

function sendScreen(buffer) {
  screen[0].toBlob(function (blob) {
    ws.send(blob);
  });
}

function drawData(data) {
  var img = new Image();
  img.src = data;
  img.onl