From db1bfcfdfcfaf562003123be0b4d35d741f5493f Mon Sep 17 00:00:00 2001 From: beirich Date: Tue, 22 May 2012 02:25:41 +0000 Subject: [PATCH] very preliminary genesis savestate support --- .../Consoles/Sega/Genesis/GenVDP.cs | 50 +++++++++++++++++- .../Consoles/Sega/Genesis/Genesis.cs | 52 +++++++++++++++---- 2 files changed, 91 insertions(+), 11 deletions(-) diff --git a/BizHawk.Emulation/Consoles/Sega/Genesis/GenVDP.cs b/BizHawk.Emulation/Consoles/Sega/Genesis/GenVDP.cs index 2f58cd5a40..851d5c313c 100644 --- a/BizHawk.Emulation/Consoles/Sega/Genesis/GenVDP.cs +++ b/BizHawk.Emulation/Consoles/Sega/Genesis/GenVDP.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using System.Globalization; namespace BizHawk.Emulation.Consoles.Sega { @@ -137,7 +139,7 @@ namespace BizHawk.Emulation.Consoles.Sega VdpDataAddr += Registers[0x0F]; break; default: - Console.WriteLine("VDP DATA WRITE WITH UNHANDLED CODE!!!"); + //Console.WriteLine("VDP DATA WRITE WITH UNHANDLED CODE!!!"); break; } } @@ -326,5 +328,51 @@ namespace BizHawk.Emulation.Consoles.Sega { get { return Palette[Registers[7] & 0x3F]; } } + + public void SaveStateText(TextWriter writer) + { + writer.WriteLine("[VDP]"); + + writer.Write("VRAM "); + VRAM.SaveAsHex(writer); + writer.Write("CRAM "); + CRAM.SaveAsHex(writer); + writer.Write("VSRAM "); + VSRAM.SaveAsHex(writer); + writer.Write("Registers "); + Registers.SaveAsHex(writer); + + writer.WriteLine("ControlWordPending {0}", ControlWordPending); + writer.WriteLine("DmaFillModePending {0}", DmaFillModePending); + writer.WriteLine("VdpDataAddr {0:X4}", VdpDataAddr); + writer.WriteLine("VdpDataCode {0}", VdpDataCode); + + writer.WriteLine("[/VDP]"); + } + + public void LoadStateText(TextReader reader) + { + while (true) + { + string[] args = reader.ReadLine().Split(' '); + if (args[0].Trim() == "") continue; + if (args[0] == "[/VDP]") break; + else if (args[0] == "VRAM") VRAM.ReadFromHex(args[1]); + else if (args[0] == "CRAM") CRAM.ReadFromHex(args[1]); + else if (args[0] == "VSRAM") VSRAM.ReadFromHex(args[1]); + else if (args[0] == "Registers") Registers.ReadFromHex(args[1]); + else if (args[0] == "ControlWordPending") ControlWordPending = bool.Parse(args[1]); + else if (args[0] == "DmaFillModePending") DmaFillModePending = bool.Parse(args[1]); + else if (args[0] == "VdpDataAddr") VdpDataAddr = ushort.Parse(args[1], NumberStyles.HexNumber); + else if (args[0] == "VdpDataCode") VdpDataCode = byte.Parse(args[1]); + else + Console.WriteLine("Skipping unrecognized identifier " + args[0]); + } + + for (int i = 0; i < CRAM.Length; i++) + ProcessPalette(i); + for (int i = 0; i < VRAM.Length; i++) + UpdatePatternBuffer(i); + } } } \ No newline at end of file diff --git a/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs b/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs index f781572533..92a0067acc 100644 --- a/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs +++ b/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs @@ -174,24 +174,56 @@ namespace BizHawk.Emulation.Consoles.Sega } } - public void SaveStateText(TextWriter writer) - { - throw new NotImplementedException(); - } + public void SaveStateText(TextWriter writer) + { + writer.WriteLine("[MegaDrive]"); + MainCPU.SaveStateText(writer, "Main68K"); + SoundCPU.SaveStateText(writer); + PSG.SaveStateText(writer); + VDP.SaveStateText(writer); - public void LoadStateText(TextReader reader) - { - throw new NotImplementedException(); - } + writer.Write("MainRAM "); + Ram.SaveAsHex(writer); + writer.Write("Z80RAM "); + Z80Ram.SaveAsHex(writer); + + + writer.WriteLine("[/MegaDrive]"); + } + + public void LoadStateText(TextReader reader) + { + while (true) + { + string[] args = reader.ReadLine().Split(' '); + if (args[0].Trim() == "") continue; + if (args[0] == "[MegaDrive]") continue; + if (args[0] == "[/MegaDrive]") break; + if (args[0] == "MainRAM") + Ram.ReadFromHex(args[1]); + else if (args[0] == "Z80RAM") + Z80Ram.ReadFromHex(args[1]); + else if (args[0] == "[Main68K]") + MainCPU.LoadStateText(reader, "Main68K"); + else if (args[0] == "[Z80]") + SoundCPU.LoadStateText(reader); + else if (args[0] == "[PSG]") + PSG.LoadStateText(reader); + else if (args[0] == "[VDP]") + VDP.LoadStateText(reader); + else + Console.WriteLine("Skipping unrecognized identifier " + args[0]); + } + } public void SaveStateBinary(BinaryWriter writer) { - throw new NotImplementedException(); + //throw new NotImplementedException(); } public void LoadStateBinary(BinaryReader reader) { - throw new NotImplementedException(); + //throw new NotImplementedException(); } public byte[] SaveStateBinary()