From ec9a8d4330c9e8e99f7bb30eed1607040542d4b4 Mon Sep 17 00:00:00 2001 From: Sour Date: Sat, 16 Jun 2018 20:02:07 -0400 Subject: [PATCH] UNIF: Added support for BMC-8157 and BMC-830118C --- Core/Bmc8157.h | 68 +++++++++++++++++++++++++++++++++++++++ Core/Bmc830118C.h | 59 +++++++++++++++++++++++++++++++++ Core/Core.vcxproj | 2 ++ Core/Core.vcxproj.filters | 6 ++++ Core/MapperFactory.cpp | 4 +++ Core/UnifBoards.h | 2 ++ Core/UnifLoader.cpp | 4 +-- 7 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 Core/Bmc8157.h create mode 100644 Core/Bmc830118C.h diff --git a/Core/Bmc8157.h b/Core/Bmc8157.h new file mode 100644 index 00000000..4f40f60c --- /dev/null +++ b/Core/Bmc8157.h @@ -0,0 +1,68 @@ +#pragma once +#pragma once +#include "stdafx.h" +#include "BaseMapper.h" + +class Bmc8157 : public BaseMapper +{ +private: + uint16_t _lastAddr; + bool _dipSwitch; + +protected: + uint16_t GetPRGPageSize() override { return 0x4000; } + uint16_t GetCHRPageSize() override { return 0x2000; } + + void InitMapper() override + { + _lastAddr = 0; + UpdateState(); + SelectCHRPage(0, 0); + } + + void Reset(bool softReset) override + { + _dipSwitch = !_dipSwitch; + } + + void StreamState(bool saving) override + { + BaseMapper::StreamState(saving); + Stream(_lastAddr, _dipSwitch); + + if(!saving) { + UpdateState(); + } + } + + void UpdateState() + { + uint8_t innerPrg0 = (_lastAddr >> 2) & 0x07; + uint8_t innerPrg1 = ((_lastAddr >> 7) & 0x01) | ((_lastAddr >> 8) & 0x02); + uint8_t outer128Prg = (_lastAddr >> 5) & 0x03; + uint8_t outer512Prg = (_lastAddr >> 8) & 0x01; + + int baseBank; + if(innerPrg1 == 0) { + baseBank = 0; + } else if(innerPrg1 == 1) { + baseBank = innerPrg0; + } else { + baseBank = 7; + } + + if(outer512Prg && _prgSize <= 1024 * 512 && _dipSwitch) { + RemoveCpuMemoryMapping(0x8000, 0xFFFF); + } else { + SelectPRGPage(0, (outer512Prg << 6) | (outer128Prg << 3) | innerPrg0); + SelectPRGPage(1, (outer512Prg << 6) | (outer128Prg << 3) | baseBank); + SetMirroringType(_lastAddr & 0x02 ? MirroringType::Horizontal : MirroringType::Vertical); + } + } + + void WriteRegister(uint16_t addr, uint8_t value) override + { + _lastAddr = addr; + UpdateState(); + } +}; \ No newline at end of file diff --git a/Core/Bmc830118C.h b/Core/Bmc830118C.h new file mode 100644 index 00000000..92bef11b --- /dev/null +++ b/Core/Bmc830118C.h @@ -0,0 +1,59 @@ +#pragma once +#include "stdafx.h" +#include "MMC3.h" + +class Bmc830118C : public MMC3 +{ +private: + uint8_t _reg; + +protected: + void InitMapper() override + { + _reg = 0; + MMC3::InitMapper(); + AddRegisterRange(0x6800, 0x68FF, MemoryOperation::Write); + } + + void Reset(bool softReset) override + { + _reg = 0; + MMC3::Reset(softReset); + } + + void StreamState(bool saving) override + { + MMC3::StreamState(saving); + Stream(_reg); + } + + void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override + { + MMC3::SelectCHRPage(slot, ((_reg & 0x0C) << 5) | (page & 0x7F), memoryType); + } + + void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override + { + if((_reg & 0x0C) == 0x0C) { + if(slot == 0) { + MMC3::SelectPRGPage(0, ((_reg & 0x0C) << 2) | (page & 0x0F)); + MMC3::SelectPRGPage(2, 0x32 | (page & 0x0F)); + } else if(slot == 1) { + MMC3::SelectPRGPage(1, ((_reg & 0x0C) << 2) | (page & 0x0F)); + MMC3::SelectPRGPage(3, 0x32 | (page & 0x0F)); + } + } else { + MMC3::SelectPRGPage(slot, ((_reg & 0x0C) << 2) | (page & 0x0F)); + } + } + + void WriteRegister(uint16_t addr, uint8_t value) override + { + if(addr < 0x8000) { + _reg = value; + UpdateState(); + } else { + MMC3::WriteRegister(addr, value); + } + } +}; \ No newline at end of file diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 0fc59cd8..1e194ec5 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -518,6 +518,8 @@ + + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index e65740ce..0389378f 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -1378,6 +1378,12 @@ Nes\Mappers\Unif + + Nes\Mappers\Unif + + + Nes\Mappers\Unif + diff --git a/Core/MapperFactory.cpp b/Core/MapperFactory.cpp index 32c41734..c73f09d8 100644 --- a/Core/MapperFactory.cpp +++ b/Core/MapperFactory.cpp @@ -19,6 +19,7 @@ #include "Bmc11160.h" #include "Bmc12in1.h" #include "Bmc51.h" +#include "Bmc8157.h" #include "Bmc63.h" #include "Bmc64in1NoRepeat.h" #include "Bmc70in1.h" @@ -26,6 +27,7 @@ #include "Bmc235.h" #include "Bmc255.h" #include "Bmc810544CA1.h" +#include "Bmc830118C.h" #include "Bmc8in1.h" #include "BmcG146.h" #include "BmcNtd03.h" @@ -522,6 +524,8 @@ BaseMapper* MapperFactory::GetMapperFromID(RomData &romData) case UnifBoards::Bmc70in1B: return new Bmc70in1(); case UnifBoards::Bmc190in1: return new Bmc190in1(); case UnifBoards::Bmc810544CA1: return new Bmc810544CA1(); + case UnifBoards::Bmc830118C: return new Bmc830118C(); + case UnifBoards::Bmc8157: return new Bmc8157(); case UnifBoards::Bmc8in1: return new Bmc8in1(); case UnifBoards::BmcF15: return new MMC3_BmcF15(); case UnifBoards::BmcG146: return new BmcG146(); diff --git a/Core/UnifBoards.h b/Core/UnifBoards.h index 05dd1f69..7cd07753 100644 --- a/Core/UnifBoards.h +++ b/Core/UnifBoards.h @@ -39,6 +39,8 @@ namespace UnifBoards { Bmc12in1, Bmc64in1NoRepeat, Bmc810544CA1, + Bmc8157, + Bmc830118C, Bmc8in1, BmcF15, Lh10, diff --git a/Core/UnifLoader.cpp b/Core/UnifLoader.cpp index 1cca8eb1..7bcc6789 100644 --- a/Core/UnifLoader.cpp +++ b/Core/UnifLoader.cpp @@ -17,10 +17,10 @@ std::unordered_map UnifLoader::_boardMappings = std::unordered_map< { "70in1", UnifBoards::Bmc70in1 }, { "70in1B", UnifBoards::Bmc70in1B }, { "810544-C-A1", UnifBoards::Bmc810544CA1 }, - { "8157", UnifBoards::UnknownBoard }, + { "8157", UnifBoards::Bmc8157 }, { "8237", 215 }, { "8237A", UnifBoards::UnknownBoard }, - { "830118C", UnifBoards::UnknownBoard }, + { "830118C", UnifBoards::Bmc830118C }, { "A65AS", UnifBoards::A65AS }, { "AC08", UnifBoards::Ac08 }, { "ANROM", 7 },