nes/vcs: fix crash if click disassembler before rom loads

This commit is contained in:
Steven Hugg 2019-12-29 12:01:10 -06:00
parent eb990dbf1a
commit 96bdc184d8
3 changed files with 10 additions and 3 deletions

View File

@ -299,7 +299,13 @@ class JSNESPlatform extends Base6502Platform implements Platform, Probeable {
// TODO don't need to save ROM?
saveState() {
//var s = $.extend(true, {}, this.nes);
var s = this.nes.toJSON();
var s;
if (this.nes.mmap) {
s = this.nes.toJSON();
} else {
console.log("no nes.mmap!");
s = { cpu: this.nes.cpu.toJSON(), ppu: this.nes.ppu.toJSON() };
}
s.c = s.cpu;
this.copy6502REGvars(s.c);
s.b = s.cpu.mem = s.cpu.mem.slice(0);

View File

@ -187,8 +187,8 @@ class VCSPlatform extends BasePlatform {
return state;
}
fixState(state) {
var ofs = state.ca.bo || 0;
if (state.ca.fo && (state.c.PC & 0xfff) >= 2048)
var ofs = (state.ca && state.ca.bo) || 0;
if (state.ca && state.ca.fo && (state.c.PC & 0xfff) >= 2048)
ofs = state.ca.fo; // 3E/3F fixed-slice formats
// TODO: for batari BASIC
state.c.EPC = state.c.PC + ofs; // EPC = effective PC for ROM

View File

@ -118,6 +118,7 @@ function testPlatform(platid, romname, maxframes, callback) {
var platform = new emu.PLATFORMS[platid](emudiv);
var rec = new recorder.StateRecorderImpl(platform);
platform.start();
assert.ok(platform.saveState()); // can save before ROM load?
var rom = fs.readFileSync('./test/roms/' + platid + '/' + romname);
rom = new Uint8Array(rom);
platform.loadROM("ROM", rom);