From 8497c25414b035d358fcc0af976e2d4c3237f7d8 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 1 Nov 2015 10:44:36 -0600 Subject: [PATCH] CDL - finish SMS memory maps, mostly --- .../Consoles/Sega/SMS/CDL_SMS.cs | 5 +- .../Sega/SMS/MemoryMap.CodeMasters.cs | 29 ++++++++ .../Consoles/Sega/SMS/MemoryMap.ExtRam.cs | 8 +++ .../Consoles/Sega/SMS/MemoryMap.Korea.cs | 31 ++++++++ .../Consoles/Sega/SMS/MemoryMap.Sega.cs | 72 +++++++++---------- .../Consoles/Sega/SMS/TerebiOekaki.cs | 11 +-- 6 files changed, 111 insertions(+), 45 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/CDL_SMS.cs b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/CDL_SMS.cs index 11ac27eb38..b9c11b2679 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/CDL_SMS.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/CDL_SMS.cs @@ -9,7 +9,10 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem enum CDLog_AddrType { None, - ROM, MainRAM, SaveRAM, CartRAM, + ROM, + MainRAM, + SaveRAM, + CartRAM, //"Cart (Volatile) RAM" aka ExtRam } [Flags] diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.CodeMasters.cs b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.CodeMasters.cs index 47c3399c7e..020b424643 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.CodeMasters.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.CodeMasters.cs @@ -20,6 +20,14 @@ return SystemRam[address & RamSizeMask]; } + CDLog_MapResults MapMemoryCM(ushort address, bool write) + { + if (address < 0x4000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = address }; + else if (address < 0x8000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank1 * BankSize) + (address & BankSizeMask) }; + else if (address < 0xC000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank2 * BankSize) + (address & BankSizeMask) }; + else return new CDLog_MapResults() { Type = CDLog_AddrType.MainRAM, Address = address & RamSizeMask }; + } + void WriteMemoryCM(ushort address, byte value) { if (address >= 0xC000) @@ -34,6 +42,7 @@ { ReadMemory = ReadMemoryCM; WriteMemory = WriteMemoryCM; + MapMemory = MapMemoryCM; WriteMemoryCM(0x0000, 0); WriteMemoryCM(0x4000, 1); WriteMemoryCM(0x8000, 0); @@ -63,6 +72,25 @@ return SystemRam[address & RamSizeMask]; } + CDLog_MapResults MapMemoryCMRam(ushort address, bool write) + { + if (address < 0x4000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = address }; + else if (address < 0x8000) + { + if (address >= 0x6000 && RomBank3 == 1) + return new CDLog_MapResults() { Type = CDLog_AddrType.CartRAM, Address = address & 0x1FFF }; + else + return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank1 * BankSize) + (address & BankSizeMask) }; + } + else if (address < 0xC000) + { + if (address >= 0xA000 && RomBank3 == 1) + return new CDLog_MapResults() { Type = CDLog_AddrType.CartRAM, Address = address & 0x1FFF }; + return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank2 * BankSize) + (address & BankSizeMask) }; + } + else return new CDLog_MapResults() { Type = CDLog_AddrType.MainRAM, Address = address & RamSizeMask }; + } + void WriteMemoryCMRam(ushort address, byte value) { if (address >= 0xC000) @@ -87,6 +115,7 @@ { ReadMemory = ReadMemoryCMRam; WriteMemory = WriteMemoryCMRam; + MapMemory = MapMemoryCMRam; WriteMemoryCM(0x0000, 0); WriteMemoryCM(0x4000, 1); WriteMemoryCM(0x8000, 0); diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.ExtRam.cs b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.ExtRam.cs index 0cca42ebcf..0f369a2c61 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.ExtRam.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.ExtRam.cs @@ -19,6 +19,13 @@ return ret; } + CDLog_MapResults MapMemoryExt(ushort address, bool write) + { + if (address < 0x8000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = address }; + else if (address < 0xC000) return new CDLog_MapResults() { Type = CDLog_AddrType.CartRAM, Address = address & ExtRamMask }; + else return new CDLog_MapResults() { Type = CDLog_AddrType.MainRAM, Address = address & RamSizeMask }; + } + void WriteMemoryExt(ushort address, byte value) { if (address < 0xC000 && address >= 0x8000) @@ -33,6 +40,7 @@ ExtRamMask = size - 1; ReadMemory = ReadMemoryExt; WriteMemory = WriteMemoryExt; + MapMemory = MapMemoryExt; } } } \ No newline at end of file diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.Korea.cs b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.Korea.cs index 98cadaa407..27c18c9adc 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.Korea.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.Korea.cs @@ -13,6 +13,13 @@ return SystemRam[address & RamSizeMask]; } + CDLog_MapResults MapMemoryKR(ushort address, bool write) + { + if (address < 0x8000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = address & 0x7FFF }; + else if (address < 0xC000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank2 * BankSize) + (address & BankSizeMask) }; + else return new CDLog_MapResults() { Type = CDLog_AddrType.MainRAM, Address = address & RamSizeMask }; + } + void WriteMemoryKR(ushort address, byte value) { if (address >= 0xC000) @@ -25,6 +32,7 @@ { ReadMemory = ReadMemoryKR; WriteMemory = WriteMemoryKR; + MapMemory = MapMemoryKR; RomBank0 = 0; RomBank1 = 1; RomBank2 = 0; @@ -44,6 +52,16 @@ return SystemRam[address & RamSizeMask]; } + CDLog_MapResults MapMemoryMSX(ushort address, bool write) + { + if (address < 0x4000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = address & 0x3FFF }; + if (address < 0x6000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank0 * 0x2000) + (address & 0x1FFF) }; + if (address < 0x8000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank1 * 0x2000) + (address & 0x1FFF) }; + if (address < 0xA000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank2 * 0x2000) + (address & 0x1FFF) }; + if (address < 0xC000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank3 * 0x2000) + (address & 0x1FFF) }; + else return new CDLog_MapResults() { Type = CDLog_AddrType.MainRAM, Address = address & RamSizeMask }; + } + byte ReadMemoryNemesis(ushort address) { if (address < 0x2000) return RomData[(15 * 0x2000) + (address & 0x1FFF)]; @@ -55,6 +73,17 @@ return SystemRam[address & RamSizeMask]; } + CDLog_MapResults MapMemoryNemesis(ushort address, bool write) + { + if (address < 0x2000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (15 * 0x2000) + (address & 0x1FFF) }; + if (address < 0x4000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = address & 0x3FFF }; + if (address < 0x6000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank0 * 0x2000) + (address & 0x1FFF) }; + if (address < 0x8000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank1 * 0x2000) + (address & 0x1FFF) }; + if (address < 0xA000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank2 * 0x2000) + (address & 0x1FFF) }; + if (address < 0xC000) return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank3 * 0x2000) + (address & 0x1FFF) }; + else return new CDLog_MapResults() { Type = CDLog_AddrType.MainRAM, Address = address & RamSizeMask }; + } + void WriteMemoryMSX(ushort address, byte value) { if (address >= 0xC000) @@ -74,6 +103,7 @@ { ReadMemory = ReadMemoryMSX; WriteMemory = WriteMemoryMSX; + ReadMemory = ReadMemoryMSX; RomBank0 = 0; RomBank1 = 0; RomBank2 = 0; @@ -84,6 +114,7 @@ { InitMSXMapper(); ReadMemory = ReadMemoryNemesis; + MapMemory = MapMemoryNemesis; } } } \ No newline at end of file diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.Sega.cs b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.Sega.cs index 57ca36766b..9ea94543e0 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.Sega.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/MemoryMap.Sega.cs @@ -56,6 +56,42 @@ return ret; } + CDLog_MapResults MapMemorySega(ushort address, bool write) + { + if (address < 0xC000) + { + if ((Port3E & 0x48) == 0x48) // cart and bios disabled, return empty bus + return new CDLog_MapResults(); + else if (BiosMapped && BiosRom != null) + return new CDLog_MapResults(); //bios tracking of CDL is not supported + else if (address < 1024) + return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = address }; + else if (address < 0x4000) + return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank0 * BankSize) + address }; + else if (address < 0x8000) + return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank1 * BankSize) + (address & BankSizeMask) }; + else + { + switch (SaveRamBank) + { + case 0: return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank2 * BankSize) + (address & BankSizeMask) }; + case 1: + if (SaveRAM != null) return new CDLog_MapResults() { Type = CDLog_AddrType.SaveRAM, Address = (address & BankSizeMask) % SaveRAM.Length }; + else return new CDLog_MapResults(); + case 2: + if (SaveRAM != null) return new CDLog_MapResults() { Type = CDLog_AddrType.SaveRAM, Address = (BankSize + (address & BankSizeMask)) & BankSizeMask }; + else return new CDLog_MapResults(); + default: + return new CDLog_MapResults() { Type = CDLog_AddrType.MainRAM, Address = address & RamSizeMask }; + } + } + } + else + { + return new CDLog_MapResults() { Type = CDLog_AddrType.MainRAM, Address = address & RamSizeMask }; + } + } + void WriteMemorySega(ushort address, byte value) { if (address >= 0xC000) @@ -91,42 +127,6 @@ } } - CDLog_MapResults MapMemorySega(ushort address, bool write) - { - if (address < 0xC000) - { - if ((Port3E & 0x48) == 0x48) // cart and bios disabled, return empty bus - return new CDLog_MapResults(); - else if (BiosMapped && BiosRom != null) - return new CDLog_MapResults(); //bios tracking of CDL is not supported - else if (address < 1024) - return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = address }; - else if (address < 0x4000) - return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank0 * BankSize) + address }; - else if (address < 0x8000) - return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank1 * BankSize) + address }; - else - { - switch (SaveRamBank) - { - case 0: return new CDLog_MapResults() { Type = CDLog_AddrType.ROM, Address = (RomBank2 * BankSize) + (address & BankSizeMask) }; - case 1: - if (SaveRAM != null) return new CDLog_MapResults() { Type = CDLog_AddrType.SaveRAM, Address = (address & BankSizeMask) % SaveRAM.Length }; - else return new CDLog_MapResults(); - case 2: - if (SaveRAM != null) return new CDLog_MapResults() { Type = CDLog_AddrType.SaveRAM, Address = (BankSize + (address & BankSizeMask)) & BankSizeMask }; - else return new CDLog_MapResults(); - default: - return new CDLog_MapResults() { Type = CDLog_AddrType.MainRAM, Address = address & RamSizeMask }; - } - } - } - else - { - return new CDLog_MapResults() { Type = CDLog_AddrType.MainRAM, Address = address & RamSizeMask }; - } - } - void InitSegaMapper() { ReadMemory = ReadMemorySega; diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/TerebiOekaki.cs b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/TerebiOekaki.cs index 397c93472e..e534705a2e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/TerebiOekaki.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/TerebiOekaki.cs @@ -2,12 +2,7 @@ { public partial class SMS { - // The CodeMasters mapper has 3 banks of 16kb, like the Sega mapper. - // The differences are that the paging control addresses are different, and the first 1K of ROM is not protected. - // Bank 0: Control Address $0000 - Maps $0000 - $3FFF - // Bank 1: Control Address $4000 - Maps $4000 - $7FFF - // Bank 2: Control Address $8000 - Maps $8000 - $BFFF - // System RAM is at $C000+ as in the Sega mapper. + //This doesn't look functional. Illogical and nothing like http://www.smspower.org/Articles/TerebiOekaki byte xCoord = 128; byte yCoord = 100; @@ -51,8 +46,8 @@ void InitTerebiOekaki() { - Cpu.ReadMemory = ReadMemoryTO; - Cpu.WriteMemory = WriteMemoryTO; + ReadMemory = ReadMemoryTO; + WriteMemory = WriteMemoryTO; } } }