-Separated the logging from the save state function.

-Made it so that the log only opens when logging is true and that the file closes upon destruction.
--Still, BizHawk says that it can't open the file again when I load a game again. This is because the emulator class gets recreated without deleting the original one every time you load a game.
---adelikat convinced me not to care about this.
-Fixed the initial state of the GB CPU:
--It was setting AF to 0x01, not A. This is effectively setting F to 0x01, which gets overwritten later anyway.
--Two BIOS flags were used in different places; merging them gets the PC to start in the right place.
-By fixing the initial state, most of the log now matches up.
--The only differences are the VBA has some repeated records (Where all of the registers, including PC, are the same as the previous record) whereas BizHawk doesn't.
--This very well might be an issue with how I'm logging it
--Alternatively, it could be some kind of lagging mechanism.
--I'm not sure which version is even correct...VBA is far from accruate.
--All in all, considering that the vast majority of the diff comes out as the same, I think I fixed the biggest CPU related bug. Will investigate more later.
This commit is contained in:
brandman211 2012-05-24 17:19:33 +00:00
parent db1bfcfdfc
commit b29c9835ff
3 changed files with 388 additions and 383 deletions

View File

@ -27,7 +27,7 @@ namespace BizHawk.Emulation.CPUs.Z80GB
public Func<ushort, byte> ReadMemory; public Func<ushort, byte> ReadMemory;
public Action<ushort, byte> WriteMemory; public Action<ushort, byte> WriteMemory;
private bool logging = false; private bool logging = true;
private TextWriter log = File.CreateText("log.txt"); private TextWriter log = File.CreateText("log.txt");
public void UnregisterMemoryMapper() public void UnregisterMemoryMapper()
@ -150,7 +150,14 @@ namespace BizHawk.Emulation.CPUs.Z80GB
{ {
if (!logging) if (!logging)
return; return;
SaveStateText(log); log.WriteLine("AF {0:X4}", RegAF.Word);
log.WriteLine("BC {0:X4}", RegBC.Word);
log.WriteLine("DE {0:X4}", RegDE.Word);
log.WriteLine("HL {0:X4}", RegHL.Word);
log.WriteLine("SP {0:X4}", RegSP.Word);
log.WriteLine("PC {0:X4}", RegPC.Word);
log.WriteLine("------");
log.WriteLine();
} }
} }
} }

View File

@ -277,8 +277,6 @@ namespace BizHawk.Emulation.Consoles.Gameboy
HardReset(); HardReset();
} }
public bool BootFromBios = true;
public void HardReset() public void HardReset()
{ {
Cpu = new CPUs.Z80GB.Z80(); Cpu = new CPUs.Z80GB.Z80();
@ -296,13 +294,13 @@ namespace BizHawk.Emulation.Consoles.Gameboy
{ {
case ESystemType.GB: case ESystemType.GB:
case ESystemType.SGB: case ESystemType.SGB:
Cpu.RegisterAF = 0x01; Cpu.RegisterA = 0x01;
break; break;
case ESystemType.GBP: case ESystemType.GBP:
Cpu.RegisterAF = 0xFF; Cpu.RegisterA = 0xFF;
break; break;
case ESystemType.GBC: case ESystemType.GBC:
Cpu.RegisterAF = 0x11; Cpu.RegisterA = 0x11;
break; break;
case ESystemType.GBA: case ESystemType.GBA:
throw new NotImplementedException(); //decide what to do throw new NotImplementedException(); //decide what to do
@ -315,8 +313,8 @@ namespace BizHawk.Emulation.Consoles.Gameboy
Cpu.RegisterDE = 0x00D8; Cpu.RegisterDE = 0x00D8;
Cpu.RegisterHL = 0x014D; Cpu.RegisterHL = 0x014D;
Cpu.RegisterSP = 0xFFFE; Cpu.RegisterSP = 0xFFFE;
if (BootFromBios) Cpu.RegisterPC = 0x0000; if (skipBIOS) Cpu.RegisterPC = 0x0100;
else Cpu.RegisterPC = 0x0100; else Cpu.RegisterPC = 0x0000;
WRam = new byte[32 * 1024]; //GB has 4KB of WRam; GBC has 32KB of WRam WRam = new byte[32 * 1024]; //GB has 4KB of WRam; GBC has 32KB of WRam
SRam = new byte[8 * 1024]; //different carts may have different amounts of this SRam = new byte[8 * 1024]; //different carts may have different amounts of this