From 650019fbffddc815eccf80b83615ba9da89f6f1c Mon Sep 17 00:00:00 2001 From: Souryo Date: Wed, 20 Jul 2016 23:17:55 -0400 Subject: [PATCH] Mapper 51 support --- Core/Bmc51.h | 59 +++++++++++++++++++++++++++++++++++++++ Core/Core.vcxproj | 1 + Core/Core.vcxproj.filters | 3 ++ Core/MapperFactory.cpp | 6 ++-- 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 Core/Bmc51.h diff --git a/Core/Bmc51.h b/Core/Bmc51.h new file mode 100644 index 00000000..c6ed1322 --- /dev/null +++ b/Core/Bmc51.h @@ -0,0 +1,59 @@ +#pragma once +#include "stdafx.h" +#include "BaseMapper.h" + +class Bmc51 : public BaseMapper +{ +private: + uint8_t _bank; + uint8_t _mode; + +protected: + virtual uint16_t GetPRGPageSize() { return 0x2000; } + virtual uint16_t GetCHRPageSize() { return 0x2000; } + uint16_t RegisterStartAddress() { return 0x6000; } + uint16_t RegisterEndAddress() { return 0xFFFF; } + + void InitMapper() + { + _bank = 0; + _mode = 1; + UpdateState(); + } + + void StreamState(bool saving) + { + BaseMapper::StreamState(saving); + Stream(_bank, _mode); + if(!saving) { + UpdateState(); + } + } + + void UpdateState() + { + if(_mode & 0x01) { + SelectPrgPage4x(0, _bank << 2); + SetCpuMemoryMapping(0x6000, 0x7FFF, (0x23 | (_bank << 2)), PrgMemoryType::PrgRom); + } else { + SelectPrgPage2x(0, (_bank << 2) | _mode); + SelectPrgPage2x(1, _bank << 2 | 0x0E); + SetCpuMemoryMapping(0x6000, 0x7FFF, (0x2F | (_bank << 2)), PrgMemoryType::PrgRom); + } + + SetMirroringType(_mode == 0x03 ? MirroringType::Horizontal : MirroringType::Vertical); + } + + void WriteRegister(uint16_t addr, uint8_t value) + { + if(addr <= 0x7FFF) { + _mode = ((value >> 3) & 0x02) | ((value >> 1) & 0x01); + } else if(addr >= 0xC000 && addr <= 0xDFFF) { + _bank = value & 0x0F; + _mode = ((value >> 3) & 0x02) | (_mode & 0x01); + } else { + _bank = value & 0x0F; + } + UpdateState(); + } +}; \ No newline at end of file diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 6c1b7fca..5d010d49 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -411,6 +411,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index 122ac46b..6e4dcc34 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -772,6 +772,9 @@ Nes\Mappers + + Nes\Mappers + diff --git a/Core/MapperFactory.cpp b/Core/MapperFactory.cpp index 9f8d9011..3d843999 100644 --- a/Core/MapperFactory.cpp +++ b/Core/MapperFactory.cpp @@ -7,6 +7,8 @@ #include "AXROM.h" #include "Bandai74161_7432.h" #include "BandaiFcg.h" +#include "Bmc51.h" +#include "Bmc235.h" #include "BnRom.h" #include "BF909x.h" #include "BF9096.h" @@ -18,7 +20,6 @@ #include "DaouInfosys.h" #include "FDS.h" #include "FrontFareast.h" -#include "Bmc235.h" #include "GxRom.h" #include "Henggedianzi177.h" #include "Henggedianzi179.h" @@ -138,7 +139,7 @@ Supported mappers: (... denotes bad mappers, --- denotes potentially bad mapper | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 13| | 15| | 16| 17| 18| 19|...| 21| 22| 23| 24| 25| 26| 27| 28| | | 31| | 32| 33| 34| | 36| 37| 38|---| 40| 41| 42|---| 44| 45| 46| 47| -| 48| 49| 50| | 52| | | | 56| 57| 58| | 60| 61| 62| | +| 48| 49| 50| 51| 52| | | | 56| 57| 58| | 60| 61| 62| | | 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| | 80| | 82| | | 85| 86| 87| 88| 89| | 91| 92| 93| 94| 95| | | 97| | 99|...|101| | | | | |107| | | | | @@ -213,6 +214,7 @@ BaseMapper* MapperFactory::GetMapperFromID(RomData &romData) case 48: return new TaitoTc0690(); case 49: return new MMC3_49(); case 50: return new Mapper50(); + case 51: return new Bmc51(); case 52: return new MMC3_52(); case 56: return new Kaiser202(); case 57: return new Mapper57();