nes: reset board state with hard reset

This commit is contained in:
goyuken 2012-11-06 03:05:43 +00:00
parent 53520540ea
commit ec82f11884
4 changed files with 55 additions and 6 deletions

View File

@ -326,6 +326,44 @@ namespace BizHawk.Emulation.Consoles.Nintendo
return board; return board;
} }
void BoardSystemHardReset()
{
INESBoard newboard;
// fds has a unique activation setup
if (board is FDS)
{
var newfds = new FDS();
var oldfds = board as FDS;
newfds.biosrom = oldfds.biosrom;
newfds.SetDiskImage(oldfds.GetDiskImage());
newboard = newfds;
}
else
{
newboard = CreateBoardInstance(board.GetType());
}
newboard.Create(this);
newboard.Configure(origin);
newboard.ROM = board.ROM;
newboard.VROM = board.VROM;
if (board.WRAM != null)
newboard.WRAM = new byte[board.WRAM.Length];
if (board.VRAM != null)
newboard.VRAM = new byte[board.VRAM.Length];
newboard.PostConfigure();
// the old board's sram must be restored
if (newboard is FDS)
{
var newfds = newboard as FDS;
var oldfds = board as FDS;
newfds.StoreSaveRam(oldfds.ReadSaveRam());
}
else if (board.SaveRam != null)
{
Buffer.BlockCopy(board.SaveRam, 0, newboard.SaveRam, 0, board.SaveRam.Length);
}
}
static NES() static NES()
{ {

View File

@ -130,10 +130,13 @@ namespace BizHawk.Emulation.Consoles.Nintendo
ports[0] = new JoypadPortDevice(this, 0); ports[0] = new JoypadPortDevice(this, 0);
ports[1] = new JoypadPortDevice(this, 1); ports[1] = new JoypadPortDevice(this, 1);
BoardSystemHardReset();
apu = new APU(this, apu); apu = new APU(this, apu);
// don't replace the magicSoundProvider on reset, as it's not needed // don't replace the magicSoundProvider on reset, as it's not needed
// if (magicSoundProvider != null) magicSoundProvider.Dispose(); // if (magicSoundProvider != null) magicSoundProvider.Dispose();
// set up region // set up region
switch (cart.system) switch (cart.system)
{ {
@ -186,6 +189,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo
if ((i & 4) != 0) ram[i] = 0xFF; else ram[i] = 0x00; if ((i & 4) != 0) ram[i] = 0xFF; else ram[i] = 0x00;
} }
SetupMemoryDomains();
//in this emulator, reset takes place instantaneously //in this emulator, reset takes place instantaneously
cpu.PC = (ushort)(ReadMemory(0xFFFC) | (ReadMemory(0xFFFD) << 8)); cpu.PC = (ushort)(ReadMemory(0xFFFC) | (ReadMemory(0xFFFD) << 8));
cpu.P = 0x34; cpu.P = 0x34;

View File

@ -90,6 +90,15 @@ namespace BizHawk.Emulation.Consoles.Nintendo
diskdiffs = new byte[NumSides][]; diskdiffs = new byte[NumSides][];
} }
/// <summary>
/// returns the currently set disk image. no effect on emulation (provided the image is not modified).
/// </summary>
/// <returns></returns>
public byte[] GetDiskImage()
{
return diskimage;
}
// as we have [INESBoardImplCancel], this will only be called with an fds disk image // as we have [INESBoardImplCancel], this will only be called with an fds disk image
public override bool Configure(NES.EDetectionOrigin origin) public override bool Configure(NES.EDetectionOrigin origin)
{ {

View File

@ -525,8 +525,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
board.PostConfigure(); board.PostConfigure();
HardReset(); HardReset();
SetupMemoryDomains();
return; return;
} }
else else
@ -744,7 +742,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
board.PostConfigure(); board.PostConfigure();
HardReset(); HardReset();
SetupMemoryDomains();
} }
void SyncState(Serializer ser) void SyncState(Serializer ser)