danShumway / serverboy.js

Pure nodeJS gameboy emulator with hooks for scripting and streaming output.
GNU General Public License v2.0
34 stars 4 forks source link

clone instance #4

Open ggomaeng opened 7 months ago

ggomaeng commented 7 months ago

first of all, what a gem find! thanks for your amazing work.

this is really fun to play with :-)

is there a way to clone the instance?

danShumway commented 7 months ago

I'm not sure I fully understand what you mean, but the emulator is cheap to initialize, so a clone might be as simple as just making a new instance and passing in a savestate.

var rom = fs.readFileSync(file_path);

var gameboy = new Gameboy();
gameboy.loadRom(rom);

/* Do some stuff */

var state = gameboy.getMemory();
var clone = new Gameboy();
clone.loadRom(rom, gameboy.getSaveData());
clone.setMemory(state);

/* Start running the clone */

I haven't looked at this code in a while, so there might be caveats I'm not thinking of. More up-to-date code is at https://gitlab.com/piglet-plays/serverboy.js -- but I haven't played around much with things like save states.