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

[POC]: fix(rust): allocation not working #78

Closed
Closed
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
2 changes: 1 addition & 1 deletion cli/assets/templates/rust/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rustflags = [
# Import memory from WASM-4
"-C", "link-arg=--import-memory",
"-C", "link-arg=--initial-memory=65536",
"-C", "link-arg=--max-memory=65536",
"-C", "link-arg=--max-memory=131072",

# Reserve 1024 bytes of stack space, offset from 6580
"-C", "link-arg=-zstack-size=7584",
Expand Down
4 changes: 4 additions & 0 deletions runtimes/web/src/framebuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const FONT = new Uint8Array([ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc7,0xc7,

export class Framebuffer {
constructor (memory) {
this.updateMemory(memory);
}

updateMemory(memory) {
this.bytes = new Uint8Array(memory, constants.ADDR_FRAMEBUFFER, WIDTH*HEIGHT >> 2);
this.drawColors = new Uint16Array(memory, constants.ADDR_DRAW_COLORS, 1);
}
Expand Down
4 changes: 3 additions & 1 deletion runtimes/web/src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Runtime {

this.apu = new APU();

this.memory = new WebAssembly.Memory({initial: 1, maximum: 1});
this.memory = new WebAssembly.Memory({initial: 1, maximum: 2});
this.data = new DataView(this.memory.buffer);

this.framebuffer = new Framebuffer(this.memory.buffer);
Expand Down Expand Up @@ -282,6 +282,8 @@ export class Runtime {
this.framebuffer.clear();
if (this.wasm.exports.update != null) {
this.wasm.exports.update();
this.data = new DataView(this.memory.buffer);
this.framebuffer.updateMemory(this.memory.buffer);
}

this.composite();
Expand Down