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

nes.loadRom doesn't seem to accept roms encoded as Uint8Arrays #454

Open
M-Valentino opened this issue Nov 28, 2024 · 0 comments
Open

nes.loadRom doesn't seem to accept roms encoded as Uint8Arrays #454

M-Valentino opened this issue Nov 28, 2024 · 0 comments

Comments

@M-Valentino
Copy link

I'm using the Vanilla JS version of JSNES and modified code from the embeded rom example. I tried to get it to open roms encoded as a byte array from nes.loadRom but couldn't get it to work at all.

I ended up having to create a blob from the URL, and then I created an object URL of that blob. then passed the url to this function from the example:

    function nes_load_url(canvas_id, path) {
      nes_init(canvas_id);

      var req = new XMLHttpRequest();
      req.open("GET", path);
      req.overrideMimeType("text/plain; charset=x-user-defined");
      req.onerror = () => console.log(`Error loading ${path}: ${req.statusText}`);

      req.onload = function () {
        if (this.status === 200) {
          nes_boot(this.responseText);
        } else if (this.status === 0) {
          // Aborted, so ignore error
        } else {
          req.onerror();
        }
      };

      req.send();
    }

Its great that I got my code to read and boot roms, but loading a rom from an object url instead of a byte array seems redundant. Maybe I was doing something wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant