nes: reset board state with hard reset
This commit is contained in:
parent
53520540ea
commit
ec82f11884
|
@ -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()
|
||||||
{
|
{
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -525,8 +525,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
||||||
board.PostConfigure();
|
board.PostConfigure();
|
||||||
|
|
||||||
HardReset();
|
HardReset();
|
||||||
SetupMemoryDomains();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -576,7 +574,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
||||||
LoadWriteLine("Could not locate game in nescartdb");
|
LoadWriteLine("Could not locate game in nescartdb");
|
||||||
if (USE_DATABASE)
|
if (USE_DATABASE)
|
||||||
{
|
{
|
||||||
if(hash_md5 != null) choice = IdentifyFromGameDB(hash_md5);
|
if (hash_md5 != null) choice = IdentifyFromGameDB(hash_md5);
|
||||||
if (choice == null)
|
if (choice == null)
|
||||||
{
|
{
|
||||||
choice = IdentifyFromGameDB(hash_sha1);
|
choice = IdentifyFromGameDB(hash_sha1);
|
||||||
|
@ -744,7 +742,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
||||||
board.PostConfigure();
|
board.PostConfigure();
|
||||||
|
|
||||||
HardReset();
|
HardReset();
|
||||||
SetupMemoryDomains();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SyncState(Serializer ser)
|
void SyncState(Serializer ser)
|
||||||
|
|
Loading…
Reference in New Issue