From 78c7a74a0d8f7ab47d0a4e708c6f848d9dd6a712 Mon Sep 17 00:00:00 2001 From: beirich Date: Tue, 1 Feb 2011 05:25:28 +0000 Subject: [PATCH] PCE: improve video timing... slightly --- .../Consoles/PC Engine/PCEngine.cs | 2 +- BizHawk.Emulation/Consoles/PC Engine/VCE.cs | 9 +++++++++ .../Consoles/PC Engine/VDC.Render.cs | 18 +++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs b/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs index f3d249aaef..ac91123c47 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs @@ -258,7 +258,7 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx public byte[] SaveStateBinary() { - var buf = new byte[SuperGrafx ? 166550 : 75852]; + var buf = new byte[SuperGrafx ? 166551 : 75853]; var stream = new MemoryStream(buf); var writer = new BinaryWriter(stream); SaveStateBinary(writer); diff --git a/BizHawk.Emulation/Consoles/PC Engine/VCE.cs b/BizHawk.Emulation/Consoles/PC Engine/VCE.cs index efeac2f31c..1b45d3fd87 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/VCE.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/VCE.cs @@ -10,6 +10,7 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx public ushort VceAddress; public ushort[] VceData = new ushort[512]; public int[] Palette = new int[512]; + public byte DotClock; public void WriteVCE(int port, byte value) { @@ -17,6 +18,9 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx switch (port) { case 0: // Control Port. Doesn't control anything we care about... + DotClock = (byte) (value & 3); + if (DotClock == 3) + DotClock = 2; break; case 2: // Address LSB VceAddress &= 0xFF00; @@ -72,6 +76,7 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx { writer.WriteLine("[VCE]"); writer.WriteLine("VceAddress {0:X4}", VceAddress); + writer.WriteLine("DotClock {0}", DotClock); writer.Write("VceData "); VceData.SaveAsHex(writer); writer.WriteLine("[/VCE]\n"); @@ -86,6 +91,8 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx if (args[0] == "[/VCE]") break; if (args[0] == "VceAddress") VceAddress = ushort.Parse(args[1], NumberStyles.HexNumber); + else if (args[0] == "DotClock") + DotClock = byte.Parse(args[1]); else if (args[0] == "VceData") VceData.ReadFromHex(args[1]); else @@ -99,6 +106,7 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx public void SaveStateBinary(BinaryWriter writer) { writer.Write(VceAddress); + writer.Write(DotClock); for (int i = 0; i < VceData.Length; i++) writer.Write(VceData[i]); } @@ -106,6 +114,7 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx public void LoadStateBinary(BinaryReader reader) { VceAddress = reader.ReadUInt16(); + DotClock = reader.ReadByte(); for (int i = 0; i < VceData.Length; i++) { VceData[i] = reader.ReadUInt16(); diff --git a/BizHawk.Emulation/Consoles/PC Engine/VDC.Render.cs b/BizHawk.Emulation/Consoles/PC Engine/VDC.Render.cs index 18b497b750..6eee266278 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/VDC.Render.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/VDC.Render.cs @@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx register at certain sync points and incremented every scanline. Its values range from 0 - $1FF. + RCRCount is the current offset into the RCR register. It is reset to $40 - on the first active display line of, and incremented every line. Its effective + on the first active display line, and incremented every line. Its effective range is $40 - $146. */ @@ -40,6 +40,18 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx ActiveLine = 0 - latchedDisplayStartLine; ScanLine = 0; + int HDS = (Registers[HSR] >> 8) & 0x7F; + int HDE = (Registers[HDR] >> 8) & 0x7F; + int hblankCycles = (HDS + HDE + 2) * 8; + //hblankCycles -= 2; + + switch (vce.DotClock) + { + case 0: hblankCycles = (hblankCycles * 4) / 3; break; + case 1: break; + case 2: hblankCycles = (hblankCycles*2)/3; break; + } + for (; ScanLine < 262;) { //Log.Note("VDC","ScanLine {0} (ActiveLine {1}, RCR {2}, BGY {3})",ScanLine, ActiveLine, RCRCount, BackgroundY); @@ -69,12 +81,12 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx StatusByte |= StatusVerticalBlanking; cpu.IRQ1Assert = true; } - cpu.Execute(82); + cpu.Execute(hblankCycles); if (InActiveDisplay && render) RenderScanLine(); - cpu.Execute(373); + cpu.Execute(455-hblankCycles); ScanLine++; ActiveLine++;