-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create coco-vm crate * Init coco-ui web app * Load ROM from web-land and run it in Rust
- Loading branch information
1 parent
aa6eddc
commit 5d13a11
Showing
13 changed files
with
417 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = ["coco-core"] | ||
members = ["coco-core", "coco-vm"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Use cargo to build the wasm module made in Rust | ||
cargo build --release --target wasm32-unknown-unknown | ||
|
||
# Build ESM modules in coco-ui | ||
wasm-bindgen target/wasm32-unknown-unknown/release/coco_vm.wasm --out-dir coco-ui/vendor --target web --no-typescript | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,3 @@ | |
name = "coco-core" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>👻 COCO-8</title> | ||
<script type="module" defer src="./index.js"></script> | ||
<link rel="stylesheet" href="styles.css" type="text/css" | ||
</head> | ||
<body> | ||
<header> | ||
<h1>👻-8</h1> | ||
</header> | ||
<main> | ||
<canvas id="coco-video" class="coco-video" width="192" height="144"></canvas> | ||
<p> | ||
<select name="rom" id="coco-rom-selector"> | ||
<option value="empty.rom">Empty</option> | ||
</select> | ||
</p> | ||
</main> | ||
<footer> | ||
<p>Crafted with 🖤 by <a href="https://www.ladybenko.net">ladybenko</a>.</p> | ||
<p> | ||
<a href="https://github.com/PIWEEK/coco-8">Source code</a> | ||
</p> | ||
</footer> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import initWasm, { runRom } from "./vendor/coco_vm.js"; | ||
|
||
async function handleFile(file) { | ||
const buffer = file.arrayBuffer(); | ||
const rom = new Uint8Array(buffer); | ||
|
||
const output = runRom(rom); | ||
console.debug(`PC: 0x${output.pc.toString(16)}`); | ||
} | ||
|
||
async function fetchRom(path) { | ||
try { | ||
const response = await fetch(path); | ||
return response; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
return null; | ||
} | ||
|
||
function setupRomSelector(selectEl, defaultRom) { | ||
const defaultOption = selectEl.querySelector(`option[value="${defaultRom}"]`); | ||
defaultOption.selected = true; | ||
|
||
selectEl.addEventListener("change", async (event) => { | ||
const romUrl = `/roms/${event.target.value}`; | ||
const rom = await fetchRom(romUrl); | ||
if (rom) { | ||
await handleFile(rom); | ||
} | ||
}); | ||
} | ||
|
||
async function main() { | ||
const _ = await initWasm("./vendor/coco_vm_bg.wasm"); | ||
const romSelector = document.querySelector("#coco-rom-selector"); | ||
|
||
const defaultRom = "empty.rom"; | ||
await setupRomSelector(romSelector, defaultRom); | ||
|
||
const rom = await fetchRom(`/roms/${defaultRom}`); | ||
if (rom) { | ||
await handleFile(rom); | ||
} | ||
} | ||
|
||
main(); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
body { | ||
display: grid; | ||
justify-content: center; | ||
font-family: monospace; | ||
} | ||
|
||
select, button { | ||
font-family: monospace; | ||
padding: 0.25rem 1rem; | ||
} | ||
|
||
.coco-video { | ||
image-rendering: pixelated; | ||
image-rendering: crisp-edges; | ||
width: 768px; /* x4 */ | ||
background: black; | ||
} |
Oops, something went wrong.