Skip to content

Commit 0e3ea67

Browse files
committed
First working code
1 parent 48ecd65 commit 0e3ea67

File tree

18 files changed

+1567
-0
lines changed

18 files changed

+1567
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
testing-binaries

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Silicon8
2+
3+
This is my first experiment with WebAssembly and with Go. So I'll probably look
4+
back on this repository with shame in a very short amount of time 😉 But that's
5+
the point of this, this is a learning project for me.
6+
7+
Silicon8 is an implementation of a runtime for Chip-8, SCHIP and XO-Chip in Go
8+
that can run as a standard Go module, or be compiled to WebAssembly with TinyGo.
9+
It's still missing a couple of features and instructions, and I'm sure there's
10+
still a few problems here and there on the Chip interpretation side of things.
11+
But most of the hard WASM/Go/JavaScript boundary related stuff is done.
12+
13+
The interpreter currently builds and runs as WebAssembly on NodeJS in the
14+
terminal with `npm start`. You'll have to hard-code a file to load in `run.js`.
15+
I'm still playing with a pure Go front-end, and the browser front-end is also
16+
still a to do. But I can probably use this pretty much as a drop-in replacement
17+
for my existing [web based Chip-8 play thing](https://github.com/Timendus/chip-8).
18+
19+
We'll see where this goes 😄

docs/index.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!doctype html>
2+
<!--
3+
Copyright 2018 The Go Authors. All rights reserved.
4+
Use of this source code is governed by a BSD-style
5+
license that can be found in the LICENSE file.
6+
-->
7+
<html>
8+
9+
<head>
10+
<meta charset="utf-8">
11+
<title>Go wasm</title>
12+
</head>
13+
14+
<body>
15+
<script src="wasm_exec.js"></script>
16+
<script>
17+
if (!WebAssembly.instantiateStreaming) { // polyfill
18+
WebAssembly.instantiateStreaming = async (resp, importObject) => {
19+
const source = await (await resp).arrayBuffer();
20+
return await WebAssembly.instantiate(source, importObject);
21+
};
22+
}
23+
24+
const go = new Go();
25+
let mod, inst;
26+
WebAssembly.instantiateStreaming(fetch("test.wasm"), go.importObject).then((result) => {
27+
mod = result.module;
28+
inst = result.instance;
29+
document.getElementById("runButton").disabled = false;
30+
}).catch((err) => {
31+
console.error(err);
32+
});
33+
34+
async function run() {
35+
console.clear();
36+
await go.run(inst);
37+
inst = await WebAssembly.instantiate(mod, go.importObject); // reset instance
38+
}
39+
</script>
40+
41+
<button onClick="run();" id="runButton" disabled>Run</button>
42+
</body>
43+
44+
</html>

docs/silicon8.wasm

95.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)