text: (window["webpackJsonp"] = window["webpackJsonp"] || []).push([[0],{
  
  /***/ "../pkg sync recursive":
  /*!*******************!*\
    !*** ../pkg sync ***!
    \*******************/
  /*! no static exports found */
  /***/ (function(module, exports) {
  
  eval("function webpackEmptyContext(req) {\n\tvar e = new Error(\"Cannot find module '\" + req + \"'\");\n\te.code = 'MODULE_NOT_FOUND';\n\tthrow e;\n}\nwebpackEmptyContext.keys = function() { return []; };\nwebpackEmptyContext.resolve = webpackEmptyContext;\nmodule.exports = webpackEmptyContext;\nwebpackEmptyContext.id = \"../pkg sync recursive\";\n\n//# sourceURL=webpack:///../pkg_sync?");
  
  /***/ }),
  
  /***/ "../pkg/wasm_chip_8.js":
  /*!*****************************!*\
    !*** ../pkg/wasm_chip_8.js ***!
    \*****************************/
  /*! exports provided: __wbg_new_3a746f2619705add, __wbg_call_f54d3a6dadb199ca, __wbg_self_ac379e780a0d8b94, __wbg_crypto_1e4302b85d4f64a2, __wbg_getRandomValues_1b4ba144162a5c9e, __wbg_getRandomValues_1ef11e888e5228e9, __wbg_require_6461b1e9a0d7c34a, __wbg_randomFillSync_1b52c8482374c55b, __wbindgen_is_undefined, __wbindgen_jsval_eq, __wbindgen_throw, CPU, Output, __wbindgen_object_drop_ref */
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
  
  "use strict";
  eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"__wbg_new_3a746f2619705add\", function() { return __wbg_new_3a746f2619705add; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"__wbg_call_f54d3a6dadb199ca\", function() { return __wbg_call_f54d3a6dadb199ca; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"__wbg_self_ac379e780a0d8b94\", function() { return __wbg_self_ac379e780a0d8b94; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"__wbg_crypto_1e4302b85d4f64a2\", function() { return __wbg_crypto_1e4302b85d4f64a2; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"__wbg_getRandomValues_1b4ba144162a5c9e\", function() { return __wbg_getRandomValues_1b4ba144162a5c9e; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"__wbg_getRandomValues_1ef11e888e5228e9\", function() { return __wbg_getRandomValues_1ef11e888e5228e9; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"__wbg_require_6461b1e9a0d7c34a\", function() { return __wbg_require_6461b1e9a0d7c34a; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"__wbg_randomFillSync_1b52c8482374c55b\", function() { return __wbg_randomFillSync_1b52c8482374c55b; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"__wbindgen_is_undefined\", function() { return __wbindgen_is_undefined; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"__wbindgen_jsval_eq\", function() { return __wbindgen_jsval_eq; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"__wbindgen_throw\", function() { return __wbindgen_throw; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"CPU\", function() { return CPU; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Output\", function() { return Output; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"__wbindgen_object_drop_ref\", function() { return __wbindgen_object_drop_ref; });\n/* harmony import */ var _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./wasm_chip_8_bg */ \"../pkg/wasm_chip_8_bg.wasm\");\n\n\nlet cachegetUint8Memory = null;\nfunction getUint8Memory() {\n    if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"memory\"].buffer) {\n        cachegetUint8Memory = new Uint8Array(_wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"memory\"].buffer);\n    }\n    return cachegetUint8Memory;\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nfunction passArray8ToWasm(arg) {\n    const ptr = _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"__wbindgen_malloc\"](arg.length * 1);\n    getUint8Memory().set(arg, ptr / 1);\n    WASM_VECTOR_LEN = arg.length;\n    return ptr;\n}\n\nfunction getArrayU8FromWasm(ptr, len) {\n    return getUint8Memory().subarray(ptr / 1, ptr / 1 + len);\n}\n\nlet cachedGlobalArgumentPtr = null;\nfunction globalArgumentPtr() {\n    if (cachedGlobalArgumentPtr === null) {\n        cachedGlobalArgumentPtr = _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"__wbindgen_global_argument_ptr\"]();\n    }\n    return cachedGlobalArgumentPtr;\n}\n\nlet cachegetUint32Memory = null;\nfunction getUint32Memory() {\n    if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"memory\"].buffer) {\n        cachegetUint32Memory = new Uint32Array(_wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"memory\"].buffer);\n    }\n    return cachegetUint32Memory;\n}\n\nlet cachedTextDecoder = new TextDecoder('utf-8');\n\nfunction getStringFromWasm(ptr, len) {\n    return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len));\n}\n\nconst heap = new Array(32);\n\nheap.fill(undefined);\n\nheap.push(undefined, null, true, false);\n\nlet heap_next = heap.length;\n\nfunction addHeapObject(obj) {\n    if (heap_next === heap.length) heap.push(heap.length + 1);\n    const idx = heap_next;\n    heap_next = heap[idx];\n\n    heap[idx] = obj;\n    return idx;\n}\n\nfunction __wbg_new_3a746f2619705add(arg0, arg1) {\n    let varg0 = getStringFromWasm(arg0, arg1);\n    return addHeapObject(new Function(varg0));\n}\n\nfunction getObject(idx) { return heap[idx]; }\n\nfunction __wbg_call_f54d3a6dadb199ca(arg0, arg1) {\n    return addHeapObject(getObject(arg0).call(getObject(arg1)));\n}\n\nfunction __wbg_self_ac379e780a0d8b94(arg0) {\n    return addHeapObject(getObject(arg0).self);\n}\n\nfunction __wbg_crypto_1e4302b85d4f64a2(arg0) {\n    return addHeapObject(getObject(arg0).crypto);\n}\n\nfunction __wbg_getRandomValues_1b4ba144162a5c9e(arg0) {\n    return addHeapObject(getObject(arg0).getRandomValues);\n}\n\nfunction __wbg_getRandomValues_1ef11e888e5228e9(arg0, arg1, arg2) {\n    let varg1 = getArrayU8FromWasm(arg1, arg2);\n    getObject(arg0).getRandomValues(varg1);\n}\n\nfunction __wbg_require_6461b1e9a0d7c34a(arg0, arg1) {\n    let varg0 = getStringFromWasm(arg0, arg1);\n    return addHeapObject(__webpack_require__(\"../pkg sync recursive\")(varg0));\n}\n\nfunction __wbg_randomFillSync_1b52c8482374c55b(arg0, arg1, arg2) {\n    let varg1 = getArrayU8FromWasm(arg1, arg2);\n    getObject(arg0).randomFillSync(varg1);\n}\n\nfunction __wbindgen_is_undefined(i) { return getObject(i) === undefined ? 1 : 0; }\n\nfunction __wbindgen_jsval_eq(a, b) { return getObject(a) === getObject(b) ? 1 : 0; }\n\nfunction __wbindgen_throw(ptr, len) {\n    throw new Error(getStringFromWasm(ptr, len));\n}\n\nfunction freeCPU(ptr) {\n\n    _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"__wbg_cpu_free\"](ptr);\n}\n/**\n*/\nclass CPU {\n\n    static __wrap(ptr) {\n        const obj = Object.create(CPU.prototype);\n        obj.ptr = ptr;\n\n        return obj;\n    }\n\n    free() {\n        const ptr = this.ptr;\n        this.ptr = 0;\n        freeCPU(ptr);\n    }\n\n    /**\n    * @returns {CPU}\n    */\n    static new() {\n        return CPU.__wrap(_wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"cpu_new\"]());\n    }\n    /**\n    * @returns {void}\n    */\n    reset() {\n        return _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"cpu_reset\"](this.ptr);\n    }\n    /**\n    * @param {Uint8Array} data\n    * @returns {void}\n    */\n    load(data) {\n        const ptr0 = passArray8ToWasm(data);\n        const len0 = WASM_VECTOR_LEN;\n        try {\n            return _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"cpu_load\"](this.ptr, ptr0, len0);\n\n        } finally {\n            _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"__wbindgen_free\"](ptr0, len0 * 1);\n\n        }\n\n    }\n    /**\n    * @param {number} key\n    * @returns {void}\n    */\n    key_down(key) {\n        return _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"cpu_key_down\"](this.ptr, key);\n    }\n    /**\n    * @param {number} key\n    * @returns {void}\n    */\n    key_up(key) {\n        return _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"cpu_key_up\"](this.ptr, key);\n    }\n    /**\n    * @returns {Output}\n    */\n    emulate_cycle() {\n        return Output.__wrap(_wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"cpu_emulate_cycle\"](this.ptr));\n    }\n}\n\nfunction freeOutput(ptr) {\n\n    _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"__wbg_output_free\"](ptr);\n}\n/**\n*/\nclass Output {\n\n    static __wrap(ptr) {\n        const obj = Object.create(Output.prototype);\n        obj.ptr = ptr;\n\n        return obj;\n    }\n\n    free() {\n        const ptr = this.ptr;\n        this.ptr = 0;\n        freeOutput(ptr);\n    }\n\n    /**\n    * @param {Uint8Array} vram\n    * @param {boolean} beep\n    * @returns {Output}\n    */\n    static new(vram, beep) {\n        const ptr0 = passArray8ToWasm(vram);\n        const len0 = WASM_VECTOR_LEN;\n        return Output.__wrap(_wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"output_new\"](ptr0, len0, beep));\n    }\n    /**\n    * @returns {Uint8Array}\n    */\n    get_vram() {\n        const retptr = globalArgumentPtr();\n        _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"output_get_vram\"](retptr, this.ptr);\n        const mem = getUint32Memory();\n        const rustptr = mem[retptr / 4];\n        const rustlen = mem[retptr / 4 + 1];\n\n        const realRet = getArrayU8FromWasm(rustptr, rustlen).slice();\n        _wasm_chip_8_bg__WEBPACK_IMPORTED_MODULE_0__[\"__wbindgen_free\"](rustptr, rustlen * 1);\n        return realRet;\n\n    }\n}\n\nfunction dropObject(idx) {\n    if (idx < 36) return;\n    heap[idx] = heap_next;\n    heap_next = idx;\n}\n\nfunction __wbindgen_object_drop_ref(i) { dropObject(i); }\n\n\n\n//# sourceURL=webpack:///../pkg/wasm_chip_8.js?");
  
  /***/ }),
  
  /***/ "../pkg/wasm_chip_8_bg.wasm":
  /*!**********************************!*\
    !*** ../pkg/wasm_chip_8_bg.wasm ***!
    \**********************************/
  /*! exports provided: memory, __wbindgen_global_argument_ptr, __wbg_cpu_free, cpu_new, cpu_reset, cpu_load, cpu_key_down, cpu_key_up, cpu_emulate_cycle, __wbg_output_free, output_new, output_get_vram, __wbindgen_malloc, __wbindgen_free */
  /***/ (function(module, exports, __webpack_require__) {
  
  eval("\"use strict\";\n// Instantiate WebAssembly module\nvar wasmExports = __webpack_require__.w[module.i];\n__webpack_require__.r(exports);\n// export exports from WebAssembly module\nfor(var name in wasmExports) if(name != \"__webpack_init__\") exports[name] = wasmExports[name];\n// exec imports from WebAssembly module (for esm order)\n/* harmony import */ var m0 = __webpack_require__(/*! ./wasm_chip_8 */ \"../pkg/wasm_chip_8.js\");\n\n\n// exec wasm module\nwasmExports[\"__webpack_init__\"]()\n\n//# sourceURL=webpack:///../pkg/wasm_chip_8_bg.wasm?");
  
  /***/ }),
  
  /***/ "./index.js":
  /*!******************!*\
    !*** ./index.js ***!
    \******************/
  /*! no exports provided */
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
  
  "use strict";
  eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var wasm_chip_8__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! wasm-chip-8 */ \"../pkg/wasm_chip_8.js\");\n\r\n\r\nconst WIDTH = 64;\r\nconst HEIGHT = 32;\r\n\r\nconst initCanvas = (w, h) => {\r\n  const canvas = document.getElementById(\"canvas\");\r\n  const ctx = canvas.getContext(\"2d\");\r\n  ctx.fillStyle = \"rgb(16, 15, 22)\";\r\n  ctx.fillRect(0, 0, w, h);\r\n\r\n  return ctx;\r\n};\r\n\r\nconst updateDisplay = (state, ctx, w, h) => {\r\n  const imageData = ctx.createImageData(w, h);\r\n\r\n  for (let i = 0; i < state.length; i++) {\r\n    imageData.data[i * 4] = state[i] === 1 ? 255 : 16;\r\n    imageData.data[i * 4 + 1] = state[i] === 1 ? 95 : 15;\r\n    imageData.data[i * 4 + 2] = state[i] === 1 ? 0 : 22;\r\n    imageData.data[i * 4 + 3] = 255;\r\n  }\r\n\r\n  ctx.putImageData(imageData, 0, 0);\r\n};\r\n\r\nconst getGameData = async rom => {\r\n  const res = await window.fetch(`roms/${rom}`);\r\n  const gameData = await res.arrayBuffer();\r\n\r\n  return new Uint8Array(gameData);\r\n};\r\n\r\nconst tick = (cpu, ctx) => {\r\n  const cpuOutput = cpu.emulate_cycle();\r\n  let displayState = cpuOutput.get_vram();\r\n\r\n  updateDisplay(displayState, ctx, WIDTH, HEIGHT);\r\n};\r\n\r\nconst stopLoop = id => {\r\n  window.cancelAnimationFrame(id);\r\n};\r\n\r\nconst translateKeys = {\r\n  \"1\": 0x1,\r\n  \"2\": 0x2,\r\n  \"3\": 0x3,\r\n  \"4\": 0xc,\r\n  q: 0x4,\r\n  w: 0x5,\r\n  e: 0x6,\r\n  r: 0xd,\r\n  a: 0x7,\r\n  s: 0x8,\r\n  d: 0x9,\r\n  f: 0xe,\r\n  z: 0xa,\r\n  x: 0x0,\r\n  c: 0xb,\r\n  v: 0xf\r\n};\r\n\r\nconst ROMS = [\r\n  \"15PUZZLE\",\r\n  \"BLINKY\",\r\n  \"BLITZ\",\r\n  \"BRIX\",\r\n  \"CONNECT4\",\r\n  \"GUESS\",\r\n  \"HIDDEN\",\r\n  \"INVADERS\",\r\n  \"KALEID\",\r\n  \"MAZE\",\r\n  \"MERLIN\",\r\n  \"MISSILE\",\r\n  \"PONG\",\r\n  \"PONG2\",\r\n  \"PUZZLE\",\r\n  \"SYZYGY\",\r\n  \"TANK\",\r\n  \"TETRIS\",\r\n  \"TICTAC\",\r\n  \"UFO\",\r\n  \"VBRIX\",\r\n  \"VERS\",\r\n  \"WIPEOFF\"\r\n];\r\n\r\n// function to create new elements to append to drop down list\r\nconst el = domStr => {\r\n  const html = new DOMParser().parseFromString(domStr, \"text/html\");\r\n\r\n  return html.body.firstChild;\r\n};\r\n\r\nwindow.onload = (async () => {\r\n  const ctx = initCanvas(WIDTH, HEIGHT);\r\n  const cpu = wasm_chip_8__WEBPACK_IMPORTED_MODULE_0__[\"CPU\"].new();\r\n\r\n  let roms = document.getElementById(\"roms\");\r\n  ROMS.forEach(rom => {\r\n    roms.append(el(`<option value=\"${rom}\">${rom}</option>`));\r\n  });\r\n\r\n  roms.addEventListener(\"change\", async e => {\r\n    const gameData = await getGameData(e.target.value);\r\n    cpu.reset();\r\n    cpu.load(gameData);\r\n  });\r\n\r\n  document.addEventListener(\"keydown\", e => {\r\n    cpu.key_down(translateKeys[e.key]);\r\n  });\r\n\r\n  document.addEventListener(\"keyup\", e => {\r\n    cpu.key_up(translateKeys[e.key]);\r\n  });\r\n\r\n  let runState = false;\r\n  let animId;\r\n\r\n  const runLoop = () => {\r\n    for (let i = 0; i < 5; i++) {\r\n      tick(cpu, ctx);\r\n    }\r\n\r\n    animId = window.requestAnimationFrame(runLoop);\r\n  };\r\n\r\n  const startBtn = document.getElementById(\"start\");\r\n  startBtn.addEventListener(\"click\", () => {\r\n    if (runState) {\r\n      startBtn.innerHTML = \"Start\";\r\n      stopLoop(animId);\r\n      runState = false;\r\n    } else {\r\n      runState = true;\r\n      runLoop();\r\n      startBtn.innerHTML = \"Stop\";\r\n    }\r\n  });\r\n})();\r\n\n\n//# sourceURL=webpack:///./index.js?");
  
  /***/ })
  
  }]);