diff --git a/chip8.wasm b/chip8.wasm index f8c8264..4b5a9c9 100755 Binary files a/chip8.wasm and b/chip8.wasm differ diff --git a/index.html b/index.html index 2f8f064..a3bc323 100644 --- a/index.html +++ b/index.html @@ -8,6 +8,57 @@ +
+
+ Select ROM + +
+ + +
+ Keyboard +
    +
  • ↑ = 1
  • +
  • ↓ = Q
  • +
+
+
+ +
+ + +
+ Keyboard +
    +
  • ↑ = 2
  • +
  • → = E
  • +
  • ↓ = S
  • +
  • ← = Q
  • +
  • Restart = V
  • +
+
+
+ +
+ + +
+ Keyboard +
    +
  • Shoot = W
  • +
  • ← = Q
  • +
  • → = E
  • +
  • Start/Restart = W
  • +
+
+
+
+ +

When running game press ESC to reload

+ + +
+ diff --git a/js/wasm_load.js b/js/wasm_load.js index 7d4bd56..cdc1ff9 100644 --- a/js/wasm_load.js +++ b/js/wasm_load.js @@ -1,5 +1,29 @@ -const go = new Go() +const form = document.querySelector("form#select-rom") -WebAssembly - .instantiateStreaming(fetch("chip8.wasm"), go.importObject) - .then(result => go.run(result.instance)) +form.addEventListener("submit", (e) => { + e.preventDefault() + + const data = new FormData(form) + + const rom = data.get("rom") + + document.rom = rom + + form.remove() + + const go = new Go() + + WebAssembly + .instantiateStreaming(fetch(`chip8.wasm`), go.importObject) + .then(result => { + go.run(result.instance) + const canvas = document.getElementsByTagName("canvas")[0] + + canvas.addEventListener("keydown", (e) => { + console.log(e.key) + if (e.key == "Escape") { + location.reload() + } + }) + }) +}) diff --git a/roms/PONG.ch8 b/roms/PONG.ch8 new file mode 100644 index 0000000..65d6310 Binary files /dev/null and b/roms/PONG.ch8 differ diff --git a/roms/SNAKE.ch8 b/roms/SNAKE.ch8 new file mode 100644 index 0000000..525ed50 Binary files /dev/null and b/roms/SNAKE.ch8 differ diff --git a/roms/SPACE_INVADERS.ch8 b/roms/SPACE_INVADERS.ch8 new file mode 100644 index 0000000..3ada8df Binary files /dev/null and b/roms/SPACE_INVADERS.ch8 differ