-
Notifications
You must be signed in to change notification settings - Fork 833
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
Problems loading .nes files in Node.js #113
Comments
Hm! Interesting. Honestly, I’ve never tested Node properly so it’d be nice to get this working and documented. Here is what I did in the tests: https://github.com/bfirsh/jsnes/blob/master/test/nes.spec.js Slight variation on what you are doing. Does that work or is it the same issue? |
Yeh the test is where I got the idea for how to load the files, the only difference between that method and mine is sync vs async file loading. It’s strange because it appears to be running and the test will pass, but no frames are generated. |
Hm! Yes odd. Sounds like the test is broken in that case. It’d be nice to compare some frame output in the test to make sure it’s doing the right thing. When I have some time I’ll look into this too... |
I'm using Angular 4 which is hosted in node.js and this is what I'm using (mostly taken from @bfirsh web jsnes project)
Hope this is able to help you get a step or two closer to resolving |
Finally figured it out, you have to specify encoding as const file = fs.readFileSync('file/to/rom.nes', { encoding: 'binary' })
nes.loadROM(file)
nes.frame() The default I'll raise a pull request to add this info to the Readme to make it clear. |
Ideally there should be a way to detect if the wrong type of encoding is used, it seems at the moment the ROM loader is very lenient in parsing & checking the file is valid, meaning a variety of encodings can bypass it even though the actual data is invalid. In the meantime I've added a test to check the output is correct over a few frames, it should help diagnose this in the future. |
I'm also having this issue but I'm writing an emulator for os.js const loadFile = async file => {
if(intv > -1) clearInterval(intv);
nes.crashMessage = null;
const data = await core.make("osjs/vfs").readfile(file);
if(!data.toString().startsWith("NES")) return core.make("osjs/dialog","alert",{ message: "File is not a valid NES rom!" },(btn, value) => {});
nes.reset();
nes.loadROM(Buffer.from(data).toString("binary"));
intv = setInterval(() => {
if(nes.cpu.crash) {
clearInterval(intv);
intv = -1;
return;
}
nes.frame();
},100);
}; I defined stop myself but it caused more issues. |
I'm trying to load an NES rom using jsnes in a node environment. I'm loading the
.nes
file by doing:No errors occur, but looking at the frame buffer I get a frame of a black border & grey background over and over each time I run
nes.frame()
. Something is happening, I still get frames & a framerate but they are all the same, as if it's not loading properly.Interestingly, loading the same rom in a browser environment works fine. Using
nes.toJSON()
, saving the output to a .json file and then importing that with the below in node also works:Both the above work (with some minor graphical glitches using the first option as covered in #16 )
Is it just the encoding causing a problem? Dropping the
ascii
encoding option causes an error reading the header (rom.js:84 - data.charCodeAt is not a function
) and using other encodings cause similar errors.The text was updated successfully, but these errors were encountered: