Skip to content

Commit

Permalink
quit on error
Browse files Browse the repository at this point in the history
  • Loading branch information
lesleyrs committed Mar 20, 2024
1 parent 30df3d0 commit da087b6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions docs/gb/gb.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ class GameBoy {
window.addEventListener('keydown', this.keyDown);
window.addEventListener('keyup', this.keyUp);

this.wasm.instance.exports.main() && this.exit();
this.wasm.instance.exports.main() && this.quit();

const memory = new Uint16Array(this.wasm.instance.exports.memory.buffer);
const imageData = this.ctx.createImageData(canvas.width, canvas.height);
const audioCtx = new AudioContext();

const update = () => {
if (this.quit_request) {
this.quit = true;
this.exit = true;
return;
}

Expand Down Expand Up @@ -349,7 +349,7 @@ class GameBoy {
update();
}

exit() {
quit() {
this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
this.quit_request = true;
}
Expand Down Expand Up @@ -384,7 +384,7 @@ class GameBoy {
}

#await_quit(romBytes, savBytes) {
if (this.quit) {
if (this.exit) {
this.#reset(romBytes, savBytes);
} else {
// NOTE: is there no better way to do this? 10 is magic
Expand Down Expand Up @@ -418,7 +418,7 @@ class GameBoy {
this.keyDown = undefined;
this.keyUp = undefined;
this.quit_request = undefined;
this.quit = undefined;
this.exit = undefined;
this.fetching = undefined;
this.startSec = undefined;
this.start({ wasmPath: "gb.wasm", canvasId: "gb", rom: romBytes, sav: savBytes });
Expand Down
Binary file modified docs/gb/gb.wasm
Binary file not shown.
10 changes: 5 additions & 5 deletions docs/gbc/gb.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ class GameBoy {
window.addEventListener('keydown', this.keyDown);
window.addEventListener('keyup', this.keyUp);

this.wasm.instance.exports.main() && this.exit();
this.wasm.instance.exports.main() && this.quit();

const memory = new Uint16Array(this.wasm.instance.exports.memory.buffer);
const imageData = this.ctx.createImageData(canvas.width, canvas.height);
const audioCtx = new AudioContext();

const update = () => {
if (this.quit_request) {
this.quit = true;
this.exit = true;
return;
}

Expand Down Expand Up @@ -349,7 +349,7 @@ class GameBoy {
update();
}

exit() {
quit() {
this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
this.quit_request = true;
}
Expand Down Expand Up @@ -384,7 +384,7 @@ class GameBoy {
}

#await_quit(romBytes, savBytes) {
if (this.quit) {
if (this.exit) {
this.#reset(romBytes, savBytes);
} else {
// NOTE: is there no better way to do this? 10 is magic
Expand Down Expand Up @@ -418,7 +418,7 @@ class GameBoy {
this.keyDown = undefined;
this.keyUp = undefined;
this.quit_request = undefined;
this.quit = undefined;
this.exit = undefined;
this.fetching = undefined;
this.startSec = undefined;
this.start({ wasmPath: "gb.wasm", canvasId: "gb", rom: romBytes, sav: savBytes });
Expand Down
Binary file modified docs/gbc/gb.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion gb.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ void gb_error(struct gb_s *gb, const enum gb_error_e gb_err,
"HALT FOREVER"};
uint8_t instr_byte = __gb_read(gb, addr);

// TODO: see what happens on a real error, can call this.quit if needed
save();

if (addr >= 0x4000 && addr < 0x8000) {
Expand All @@ -116,6 +115,7 @@ void gb_error(struct gb_s *gb, const enum gb_error_e gb_err,
}

alert("Error: check browser console");
quit();
}

#if ENABLE_LCD
Expand Down
10 changes: 5 additions & 5 deletions gb.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ class GameBoy {
window.addEventListener('keydown', this.keyDown);
window.addEventListener('keyup', this.keyUp);

this.wasm.instance.exports.main() && this.exit();
this.wasm.instance.exports.main() && this.quit();

const memory = new Uint16Array(this.wasm.instance.exports.memory.buffer);
const imageData = this.ctx.createImageData(canvas.width, canvas.height);
const audioCtx = new AudioContext();

const update = () => {
if (this.quit_request) {
this.quit = true;
this.exit = true;
return;
}

Expand Down Expand Up @@ -349,7 +349,7 @@ class GameBoy {
update();
}

exit() {
quit() {
this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
this.quit_request = true;
}
Expand Down Expand Up @@ -384,7 +384,7 @@ class GameBoy {
}

#await_quit(romBytes, savBytes) {
if (this.quit) {
if (this.exit) {
this.#reset(romBytes, savBytes);
} else {
// NOTE: is there no better way to do this? 10 is magic
Expand Down Expand Up @@ -418,7 +418,7 @@ class GameBoy {
this.keyDown = undefined;
this.keyUp = undefined;
this.quit_request = undefined;
this.quit = undefined;
this.exit = undefined;
this.fetching = undefined;
this.startSec = undefined;
this.start({ wasmPath: "gb.wasm", canvasId: "gb", rom: romBytes, sav: savBytes });
Expand Down

0 comments on commit da087b6

Please sign in to comment.