Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add show bytecode toggle to the GUI app #6

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions coco-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,32 @@
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
<div class="wrapper">
<header>
<h1>👻-8</h1>
</header>
<main>
<canvas id="coco-video" class="coco-video" width="192" height="144"></canvas>
<p>
<section class="coco-controls">
<select name="rom" id="coco-rom-selector">
<option value="empty.rom">Empty</option>
<option value="deo_system_debug.rom">Debug</option>
<option value="put_pixel.rom">Pixel</option>
</select>
</p>

<div>
<input type="checkbox" id="coco-show-bytecode">
<label for="coco-show-bytecode">Show bytecode</label>
</div>
</section>
<section id="coco-bytecode" class="bytecode" style="display: none;"></section>
</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>
</div>
</body>
</html>
17 changes: 16 additions & 1 deletion coco-ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ async function handleFile(file) {
const buffer = await file.arrayBuffer();
const rom = new Uint8Array(buffer);

const bytecode = Array.from(rom)
.map((x) => x.toString(16).padStart(2, "0"))
.join(" ");
document.querySelector("#coco-bytecode").innerHTML = bytecode;

const output = runRom(rom);
if (output.debug) {
console.log(output.debug);
Expand Down Expand Up @@ -33,12 +38,22 @@ function setupRomSelector(selectEl, defaultRom) {
});
}

function setupControls() {
let showBytecodeCheckbox = document.querySelector("#coco-show-bytecode");
let bytecodeEl = document.querySelector("#coco-bytecode");

showBytecodeCheckbox.addEventListener("change", (event) => {
bytecodeEl.style.display = event.target.checked ? "block" : "none";
});
}

async function main() {
const _ = await initWasm("./vendor/coco_ui_bg.wasm");
const romSelector = document.querySelector("#coco-rom-selector");

const defaultRom = "put_pixel.rom";
await setupRomSelector(romSelector, defaultRom);
setupRomSelector(romSelector, defaultRom);
setupControls();

const rom = await fetchRom(`/roms/${defaultRom}`);
if (rom) {
Expand Down
36 changes: 33 additions & 3 deletions coco-ui/styles.css
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
*,
*::before,
*::after {
box-sizing: border-box;
}

* {
margin: 0;
}

body {
display: grid;
justify-content: center;
font-family: monospace;
-webkit-font-smoothing: antialiased;
min-height: 100vh;
}

select, button {
font-family: monospace;
font: inherit;
padding: 0.25rem 1rem;
}

.wrapper {
padding: 1rem;
display: grid;
place-content: center;
row-gap: 1rem;
height: 100vh;
}

.coco-video {
image-rendering: pixelated;
image-rendering: crisp-edges;
width: 768px; /* x4 */
background: black;
}

.coco-controls {
margin: 1rem 0;
display: flex;
justify-content: space-between;
}

.bytecode {
max-height: 20vh;
border: 1px solid black;
padding: 1rem;
}