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

Battery Save / Save State #3

Open
Recognition101 opened this issue Sep 8, 2016 · 1 comment
Open

Battery Save / Save State #3

Recognition101 opened this issue Sep 8, 2016 · 1 comment

Comments

@Recognition101
Copy link

Awesome project!

I was going to extend it to allow controller input and state management. I've already figured out the controller stuff (I basically just create a ControllerInput object and write emulator.input = new ControllerInput()), but I don't know enough about NES architecture to know how to deal with state.

If I wanted the ability to save and load states or export and import a battery save, how would I go about doing that? What functions / files should I look into?

@koenkivits
Copy link
Owner

koenkivits commented Sep 8, 2016

Thanks, and awesome to see you working with it! The things you're looking for have been on my "I wanted to do this, but I never really got around to it" list. :)

Battery save shouldn't be too complex to implement. Every Cartridge instance has ramData field, which is a Uint8Array. I guess you can read and store this data (from nesnes.cartridge, where nesnes is a NesNes instance) while it's running. If you want to load it again it should be a case of setting the ramData of the cartridge right after booting (but before running).
Does this help you? Please let me know if I don't make any sense. :)

Regarding save and load state: this is a little bit more complicated. I think it would require serializing the state of all the main components, and the code is not built for this. Right now the system state is a little bit all over the place. One solution would be to add serializeState and deserializeState method to all components involved, but I'm not sure how much work this would be. I also don't know how other emulators handle this.
By the way, if you want to know what the main components exactly are, look at initCore() in https://github.com/koenkivits/nesnes/blob/master/index.js . This is the method that basically initializes the entire system and all of its components.

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

2 participants