Skip to content

Commit

Permalink
Fix stepping bug
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Oct 3, 2023
1 parent 37c61dd commit de9eb1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
11 changes: 11 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
import * as textEditor from "./js/text-editor.js";
import * as gfxEditor from "./js/gfx-editor.js";

if (import.meta.env.DEV) {
globalThis._rgbdsDebug = {
compiler,
emulator,
storage,
editors,
textEditor,
gfxEditor,
};
}

var cpu_line_marker = undefined;
var start_address;
var rom;
Expand Down
27 changes: 7 additions & 20 deletions js/emulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ export function init(canvas, rom_data) {

var required_size = ((rom_data.length - 1) | 0x3fff) + 1;
if (required_size < 0x8000) required_size = 0x8000;
if (rom_size < required_size) {
if (typeof rom_ptr != "undefined") Module._free(rom_ptr);
rom_ptr = Module._malloc(required_size);
rom_size = required_size;
}
for (var n = 0; n < rom_size; n++) Module.HEAP8[rom_ptr + n] = 0;
for (var n = 0; n < rom_data.length; n++)
Module.HEAP8[rom_ptr + n] = rom_data[n];
if (typeof rom_ptr != "undefined") Module._free(rom_ptr);
rom_ptr = Module._malloc(required_size);
rom_size = required_size;

const romView = Module.HEAP8.subarray(rom_ptr, rom_ptr + rom_size);
romView.fill(0);
romView.set(rom_data);

e = Module._emulator_new_simple(
rom_ptr,
Expand Down Expand Up @@ -69,18 +68,6 @@ export function init(canvas, rom_data) {
audio_time = audio_ctx.currentTime;
}

export function updateRom(rom_data) {
if (!isAvailable()) return false;

var required_size = ((rom_data.length - 1) | 0x3fff) + 1;
if (required_size < 0x8000) required_size = 0x8000;
if (rom_size < required_size) return false;
for (var n = 0; n < rom_size; n++) Module.HEAP8[rom_ptr + n] = 0;
for (var n = 0; n < rom_data.length; n++)
Module.HEAP8[rom_ptr + n] = rom_data[n];
return true;
}

export function destroy() {
if (!isAvailable()) return;
Module._emulator_delete(e);
Expand Down

0 comments on commit de9eb1d

Please sign in to comment.