diff --git a/Core/Memory/SmsMemoryBus.cs b/Core/Memory/SmsMemoryBus.cs index 9ab9cb4..d5d54e2 100644 --- a/Core/Memory/SmsMemoryBus.cs +++ b/Core/Memory/SmsMemoryBus.cs @@ -6,6 +6,7 @@ namespace Core.Memory { public class SmsMemoryBus : IMemory { + private bool _isCodemastersMapper = false; //Codemasters used their own memory mapper // SMS has 8KB of internal Work RAM private readonly byte[] _workRam = new byte[0x2000]; @@ -49,6 +50,10 @@ namespace Core.Memory if (address < 0x4000) { + if (!_isCodemastersMapper && address < 0x0400) + { + return _cartridgeRom[address]; + } if (address < 0x0400) { return _cartridgeRom[address]; @@ -76,6 +81,18 @@ namespace Core.Memory public void Write(ushort address, byte value) { + // Codemasters games bank-switch by writing directly to ROM! + if (address == 0x0000 || address == 0x4000 || address == 0x8000) + { + _isCodemastersMapper = true; + int cTotalBanks = _cartridgeRom.Length / 0x4000; + if (cTotalBanks == 0) cTotalBanks = 1; + + if (address == 0x0000) _romBank0 = value % cTotalBanks; + else if (address == 0x4000) _romBank1 = value % cTotalBanks; + else if (address == 0x8000) _romBank2 = value % cTotalBanks; + return; + } if (address < 0x8000) return; // Cannot write to physical ROM if (address < 0xC000) @@ -266,6 +283,7 @@ namespace Core.Memory { Array.Clear(_workRam, 0, _workRam.Length); _mapperControl = 0; + _isCodemastersMapper = false; } } } \ No newline at end of file diff --git a/Desktop/Desktop.csproj b/Desktop/Desktop.csproj index 854299c..7fbf857 100644 --- a/Desktop/Desktop.csproj +++ b/Desktop/Desktop.csproj @@ -27,6 +27,7 @@ + @@ -94,6 +95,8 @@ + + @@ -126,6 +129,7 @@ Never + Never @@ -309,6 +313,8 @@ Never + + Never diff --git a/Desktop/ROMS/Aladdin (USA, Europe, Brazil).gg b/Desktop/ROMS/Aladdin (USA, Europe, Brazil).gg new file mode 100644 index 0000000..46301a8 Binary files /dev/null and b/Desktop/ROMS/Aladdin (USA, Europe, Brazil).gg differ diff --git a/Desktop/ROMS/Sonic The Hedgehog - Triple Trouble (USA, Europe, Brazil).gg b/Desktop/ROMS/Sonic The Hedgehog - Triple Trouble (USA, Europe, Brazil).gg new file mode 100644 index 0000000..d7ee99d Binary files /dev/null and b/Desktop/ROMS/Sonic The Hedgehog - Triple Trouble (USA, Europe, Brazil).gg differ diff --git a/Desktop/ROMS/Sonic The Hedgehog 2 (World).gg b/Desktop/ROMS/Sonic The Hedgehog 2 (World).gg new file mode 100644 index 0000000..6b60690 Binary files /dev/null and b/Desktop/ROMS/Sonic The Hedgehog 2 (World).gg differ