From 8b00da908e2869a0ba08d0a53c3115338edb7fb4 Mon Sep 17 00:00:00 2001 From: beirich Date: Sun, 19 Jun 2011 01:37:09 +0000 Subject: [PATCH] [PCE] TurboCD Battery RAM implemented --- BizHawk.Emulation/BizHawk.Emulation.csproj | 1 + .../Consoles/PC Engine/Compat.txt | 7 ++-- BizHawk.Emulation/Consoles/PC Engine/Input.cs | 4 +- .../Consoles/PC Engine/MemoryMap.cs | 25 +++++++++++++ .../Consoles/PC Engine/PCEngine.cs | 30 +++++++++++---- .../Consoles/PC Engine/TurboCD.cs | 37 +++++++++++++++++++ 6 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 BizHawk.Emulation/Consoles/PC Engine/TurboCD.cs diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj index fdba9bf1c8..153b14a559 100644 --- a/BizHawk.Emulation/BizHawk.Emulation.csproj +++ b/BizHawk.Emulation/BizHawk.Emulation.csproj @@ -111,6 +111,7 @@ + diff --git a/BizHawk.Emulation/Consoles/PC Engine/Compat.txt b/BizHawk.Emulation/Consoles/PC Engine/Compat.txt index 54e55f1ceb..9bbc996a4c 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/Compat.txt +++ b/BizHawk.Emulation/Consoles/PC Engine/Compat.txt @@ -11,19 +11,20 @@ General: Air Zonk - Fully playable, doesn't freeze, but some gfx/timing issues Battle Ace - Some gfx glitches +Cadash - Minor raster issue. Timing sensitive game. Chase HQ - Press start -"O" sprite gets left on screen. probably timing on SATB DMA +Coryoon - Recent VDC updates broke scrolling. Generally timing sensitive game. Cross Wiber - Minor; Raster on wrong line Davis Cup Tennis - Some timing issue, splash screen is too slow Dungeon Explorer - Freeze in 'intro' - gfx corruption in-game Fighting Run - Corruption issues -Gunboat - Crash / CPU Break (Needs BRAM) Legend of Hero Ton- Slight gfx- check top of screen Lode Runner - Freezes in new game Madoo Granzort - Graphics issues because SGX VPC renderer is not using new frame timing MML Demo - Echo channels are too loud (equal volume!) -Outrun - Raster issues, music slows when paused +Outrun - OK currently but timing sensitive game for future testing Paranoia - Game hits BREAK on 3rd level. need to investigate -Populous - Game freezes on starting new game - *** NEEDS BATTERY SAVERAM *** +Populous - Game freezes on starting new game - unclear if related to battery RAM Power Drift - Timing glitch... starting new game runs slower than it should Power Tennis - Elaborate intro screen doesnt display right Raiden - Sprites and BG get out of sync with current timing diff --git a/BizHawk.Emulation/Consoles/PC Engine/Input.cs b/BizHawk.Emulation/Consoles/PC Engine/Input.cs index 2dc8746496..36b20cf896 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/Input.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/Input.cs @@ -63,8 +63,8 @@ if (Region == "Japan") value |= 0x40; - if (Type != NecSystemType.TurboCD) - value |= 0x80; + /*if (Type != NecSystemType.TurboCD) + value |= 0x80;*/ return value; } diff --git a/BizHawk.Emulation/Consoles/PC Engine/MemoryMap.cs b/BizHawk.Emulation/Consoles/PC Engine/MemoryMap.cs index 0147f0c65c..397962ccce 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/MemoryMap.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/MemoryMap.cs @@ -23,6 +23,18 @@ if ((addr & ~1) == 0x1FF400) return IOBuffer; if (addr == 0x1FF402) { IOBuffer = (byte) (Cpu.IRQControlByte | (IOBuffer & 0xF8)); return IOBuffer; } if (addr == 0x1FF403) { IOBuffer = (byte) (Cpu.ReadIrqStatus() | (IOBuffer & 0xF8)); return IOBuffer; } + if (addr >= 0x1FF800) return ReadCD(addr); + } + + if (addr >= 0x1EE000 && addr <= 0x1EE7FF) // BRAM + { + if (BramEnabled && BramLocked == false) + { + System.Console.WriteLine("READ BRAM[{0}] ; ret {1:X2}", addr & 0x7FF, BRAM[addr & 0x7FF]); + return BRAM[addr & 0x7FF]; + } + System.Console.WriteLine("attemped BRAM read while locked"); + return 0xFF; } Log.Error("MEM", "UNHANDLED READ: {0:X6}", addr); @@ -49,8 +61,21 @@ addr < 0x1FF400) { IOBuffer = value; WriteInput(value); } else if (addr == 0x1FF402) { IOBuffer = value; Cpu.WriteIrqControl(value); } else if (addr == 0x1FF403) { IOBuffer = value; Cpu.WriteIrqStatus(); } + else if (addr >= 0x1FF800) { WriteCD(addr, value); } else Log.Error("MEM", "unhandled hardware write [{0:X6}] : {1:X2}", addr, value); } + + else if (addr >= 0x1EE000 && addr <= 0x1EE7FF) // BRAM + { + if (BramEnabled && BramLocked == false) + { + System.Console.WriteLine("WRITE BRAM[{0}] : {1:X2}", addr & 0x7FF, value); + BRAM[addr & 0x7FF] = value; + SaveRamModified = true; + } + else System.Console.WriteLine("attemped BRAM write while locked!"); + } + else Log.Error("MEM","UNHANDLED WRITE: {0:X6}:{1:X2}",addr,value); } diff --git a/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs b/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs index dfcb75aaa0..d3a2dd75d7 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs @@ -31,6 +31,11 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx private bool TurboGrafx { get { return Type == NecSystemType.TurboGrafx; } } private bool SuperGrafx { get { return Type == NecSystemType.SuperGrafx; } } private bool TurboCD { get { return Type == NecSystemType.TurboCD; } } + + // BRAM + private bool BramEnabled = false; + private bool BramLocked = true; + private byte[] BRAM; // Memory system public byte[] Ram; @@ -92,6 +97,18 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx RomData = game.GetRomData(); RomLength = RomData.Length; } + + if (game.GetOptions().Contains("BRAM")) + { + BramEnabled = true; + BRAM = new byte[2048]; + Console.WriteLine("ENABLE BRAM!"); + + // pre-format BRAM + BRAM[0] = 0x48; BRAM[1] = 0x55; BRAM[2] = 0x42; BRAM[3] = 0x4D; + BRAM[4] = 0x00; BRAM[5] = 0x88; BRAM[6] = 0x10; BRAM[7] = 0x80; + } + Cpu.ResetPC(); SetupMemoryDomains(); } @@ -144,14 +161,10 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx public byte[] SaveRam { - get { throw new NotImplementedException(); } + get { return BRAM; } } - public bool SaveRamModified - { - get { return false; } - set { throw new NotImplementedException(); } - } + public bool SaveRamModified { get; set; } public void SaveStateText(TextWriter writer) { @@ -275,7 +288,10 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx public byte[] SaveStateBinary() { - var buf = new byte[SuperGrafx ? 166552 : 75854]; + int buflen = SuperGrafx ? 166552 : 75854; + if (BramEnabled) buflen += 2048; + + var buf = new byte[buflen]; var stream = new MemoryStream(buf); var writer = new BinaryWriter(stream); SaveStateBinary(writer); diff --git a/BizHawk.Emulation/Consoles/PC Engine/TurboCD.cs b/BizHawk.Emulation/Consoles/PC Engine/TurboCD.cs new file mode 100644 index 0000000000..0a33ccb881 --- /dev/null +++ b/BizHawk.Emulation/Consoles/PC Engine/TurboCD.cs @@ -0,0 +1,37 @@ +using System; + +namespace BizHawk.Emulation.Consoles.TurboGrafx +{ + public partial class PCEngine + { + private void WriteCD(int addr, byte value) + { + switch (addr & 0x1FFF) + { + case 0x1807: + + if (BramEnabled && (value & 0x80) != 0) + { + Console.WriteLine("UNLOCK BRAM!"); + BramLocked = false; + } + break; + } + } + + public byte ReadCD(int addr) + { + switch (addr & 0x1FFF) + { + case 0x1803: + if (BramEnabled) + { + Console.WriteLine("LOCKED BRAM!"); + BramLocked = true; + } + break; + } + return 0xFF; + } + } +}