Assemble kernel on client
This commit is contained in:
16
boot.js
16
boot.js
@@ -1,7 +1,19 @@
|
|||||||
|
import { Assembler } from './asm.js';
|
||||||
|
|
||||||
|
const assemble = (async () => {
|
||||||
|
const asm = new Assembler();
|
||||||
|
const resp = await fetch('wipforth.ws');
|
||||||
|
for await (const chunk of resp.body) {
|
||||||
|
asm.push(chunk);
|
||||||
|
}
|
||||||
|
return asm.wasm();
|
||||||
|
})();
|
||||||
|
|
||||||
self.onmessage = async (e) => {
|
self.onmessage = async (e) => {
|
||||||
const exports = { emu: { mem: e.data } };
|
const exports = { emu: { mem: e.data } };
|
||||||
const mod = await WebAssembly.instantiateStreaming(
|
const wasm = await assemble;
|
||||||
fetch('wipforth.wasm'), exports)
|
const mod = await WebAssembly.instantiate(wasm, exports);
|
||||||
|
await self.postMessage('booting');
|
||||||
mod.instance.exports.reset();
|
mod.instance.exports.reset();
|
||||||
console.log('System halt');
|
console.log('System halt');
|
||||||
};
|
};
|
||||||
|
|||||||
9
emu.js
9
emu.js
@@ -11,6 +11,7 @@ const RXBUF_SIZE = 32;
|
|||||||
const PERIPHS_SIZE = 81;
|
const PERIPHS_SIZE = 81;
|
||||||
|
|
||||||
const POLL_INTERVAL_MS = 20;
|
const POLL_INTERVAL_MS = 20;
|
||||||
|
const DOT_INTERVAL_MS = 120;
|
||||||
|
|
||||||
const COLS = 80;
|
const COLS = 80;
|
||||||
const TAB_WIDTH = 8;
|
const TAB_WIDTH = 8;
|
||||||
@@ -50,8 +51,14 @@ class Emulator {
|
|||||||
document.addEventListener('keydown', (e) => this.handle_keydown(e));
|
document.addEventListener('keydown', (e) => this.handle_keydown(e));
|
||||||
window.addEventListener('resize', () => this.handle_resize());
|
window.addEventListener('resize', () => this.handle_resize());
|
||||||
|
|
||||||
this.worker = new Worker('boot.js');
|
this.print("Assembling kernel ");
|
||||||
|
const dots = setInterval(() => this.print("."), DOT_INTERVAL_MS);
|
||||||
|
this.worker = new Worker('boot.js', { type: 'module' });
|
||||||
this.worker.postMessage(this.mem);
|
this.worker.postMessage(this.mem);
|
||||||
|
this.worker.onmessage = (e) => {
|
||||||
|
clearInterval(dots);
|
||||||
|
this.print(" done\n");
|
||||||
|
};
|
||||||
|
|
||||||
fetch('prelude.f')
|
fetch('prelude.f')
|
||||||
.then(res => res.text())
|
.then(res => res.text())
|
||||||
|
|||||||
Reference in New Issue
Block a user