 window.retro = retro = document.createElement 'canvas', 'x-game'
 document.body.appendChild retro
 
-cores =
-  'snes9x-next': require 'snes9x-next'
-  'vba-next': require 'vba-next'
-  'nestopia': require 'nestopia'
-  'gambatte': require 'gambatte'
-
-readFile = (file) ->
-  new Promise (resolve, reject) ->
-    reader = new FileReader()
-    reader.readAsArrayBuffer file
-    reader.onload = (event) ->
-      resolve new Uint8Array reader.result
-    reader.onerror = reject
-
-readFileEntry = (entry) ->
-  new Promise (resolve, reject) ->
-    entry.file resolve, reject
-  .then (file) ->
-    readFile file
-
-getSave = (filename) ->
-  new Promise (resolve, reject) ->
-    chrome.syncFileSystem.requestFileSystem (fs) ->
-      fs.root.getFile filename, create: true, resolve, reject
-    , reject
+onkey = (event) ->
+  if retro.player and settings.keys.hasOwnProperty event.which
+    pressed = event.type == 'keydown'
+    retro.player.inputs[0].buttons[settings.keys[event.which]] ?= {}
+    retro.player.inputs[0].buttons[settings.keys[event.which]].pressed = pressed
+    event.preventDefault()
 
 autosaver = 0
 

  play rom, extension
  .catch (e) ->
    console.error e
    location.reload() # hacky but a fix

load = (file) ->
  return if not file instanceof Blob
  draghint.classList.add 'hidden'
  readFile file
  .then (buffer) ->
    loadData file.name, buffer

window.addEventListener 'drop', (event) ->
  return if draghint.classList.contains 'hidden'

sparkmd5 = require 'sparkmd5'
JSZip = require 'jszip'
localForage = require 'localforage'
require 'x-game'

settings = require './settings.json!'
utils = require './utils'
