Skip to content

Commit

Permalink
deploy: 87989e7
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoliveira21 committed Dec 23, 2023
1 parent 00ca601 commit 87a31f8
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
Binary file modified chip8.wasm
Binary file not shown.
51 changes: 51 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,57 @@
</head>

<body>
<form id="select-rom">
<fieldset>
<legend>Select ROM</legend>

<div>
<input type="radio" id="pong" name="rom" value="PONG.ch8" checked />
<label for="PONG">Pong</label>
<details open>
<summary>Keyboard</summary>
<ul>
<li>↑ = <kbd>1</kbd></li>
<li>↓ = <kbd>Q</kbd></li>
</ul>
</details>
</div>

<div>
<input type="radio" id="snake" name="rom" value="SNAKE.ch8" />
<label for="snake">Snake [steveRoll]</label>
<details open>
<summary>Keyboard</summary>
<ul>
<li>↑ = <kbd>2</kbd></li>
<li>→ = <kbd>E</kbd></li>
<li>↓ = <kbd>S</kbd></li>
<li>← = <kbd>Q</kbd></li>
<li>Restart = <kbd>V</kbd></li>
</ul>
</details>
</div>

<div>
<input type="radio" id="space-invaders" name="rom" value="SPACE_INVADERS.ch8" />
<label for="space-invaders">Space Invaders [David Winter]</label>
<details open>
<summary>Keyboard</summary>
<ul>
<li>Shoot = <kbd>W</kbd></li>
<li>← = <kbd>Q</kbd></li>
<li>→ = <kbd>E</kbd></li>
<li>Start/Restart = <kbd>W</kbd></li>
</ul>
</details>
</div>
</fieldset>

<p>When running game press <kbd>ESC</kbd> to reload</p>

<button type="submit">Confirm</button>
</form>

<script src="js/wasm_exec.js"></script>
<script src="js/polyfill.js"></script>
<script src="js/wasm_load.js"></script>
Expand Down
32 changes: 28 additions & 4 deletions js/wasm_load.js
Original file line number Diff line number Diff line change
@@ -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()
}
})
})
})
Binary file added roms/PONG.ch8
Binary file not shown.
Binary file added roms/SNAKE.ch8
Binary file not shown.
Binary file added roms/SPACE_INVADERS.ch8
Binary file not shown.

0 comments on commit 87a31f8

Please sign in to comment.