From 617f5ead2300dc42ad0c3f835641fa9994e09174 Mon Sep 17 00:00:00 2001 From: Souryo Date: Tue, 24 Jun 2014 14:28:19 -0400 Subject: [PATCH] CNROM (iNES mapper 3) support --- Core/BaseMapper.h | 42 --------------------------------------- Core/CNROM.h | 22 ++++++++++++++++++++ Core/Core.vcxproj | 3 +++ Core/Core.vcxproj.filters | 9 +++++++++ Core/MapperFactory.h | 10 +++++++--- Core/NROM.h | 23 +++++++++++++++++++++ Core/UNROM.h | 25 +++++++++++++++++++++++ 7 files changed, 89 insertions(+), 45 deletions(-) create mode 100644 Core/CNROM.h create mode 100644 Core/NROM.h create mode 100644 Core/UNROM.h diff --git a/Core/BaseMapper.h b/Core/BaseMapper.h index e5b0435f..3341b40b 100644 --- a/Core/BaseMapper.h +++ b/Core/BaseMapper.h @@ -154,46 +154,4 @@ class BaseMapper : public IMemoryHandler { _chrPages[AddrToCHRSlot(addr)][addr & (GetCHRPageSize() - 1)] = value; } -}; - -class DefaultMapper : public BaseMapper -{ - protected: - virtual uint32_t GetPRGPageSize() { return 0x4000; } - virtual uint32_t GetCHRPageSize() { return 0x2000; } - - virtual void InitMapper() - { - if(_prgSize == 0x4000) { - SelectPRGPage(0, 0); - SelectPRGPage(1, 0); - } else { - SelectPRGPage(0, 0); - SelectPRGPage(1, 1); - } - - SelectCHRPage(0, 0); - } -}; - -class Mapper2 : public BaseMapper -{ - protected: - virtual uint32_t GetPRGPageSize() { return 0x4000; } - virtual uint32_t GetCHRPageSize() { return 0x2000; } - - void InitMapper() - { - //First and last PRG page - SelectPRGPage(0, 0); - SelectPRGPage(1, 0xFF); - - SelectCHRPage(0, 0); - } - - public: - void WriteRAM(uint16_t addr, uint8_t value) - { - SelectPRGPage(0, value); - } }; \ No newline at end of file diff --git a/Core/CNROM.h b/Core/CNROM.h new file mode 100644 index 00000000..40f98ad4 --- /dev/null +++ b/Core/CNROM.h @@ -0,0 +1,22 @@ +#pragma once +#include "stdafx.h" +#include "BaseMapper.h" + +class CNROM : public BaseMapper +{ + protected: + virtual uint32_t GetPRGPageSize() { return 0x8000; } + virtual uint32_t GetCHRPageSize() { return 0x2000; } + + void InitMapper() + { + SelectPRGPage(0, 0); + SelectCHRPage(0, 0); + } + + public: + void WriteRAM(uint16_t addr, uint8_t value) + { + SelectCHRPage(0, value); + } +}; \ No newline at end of file diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 8eb1c71e..d62dc15f 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -89,6 +89,7 @@ + @@ -108,12 +109,14 @@ + + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index 9cc48b89..c0b8427c 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -105,6 +105,15 @@ Header Files\Mappers + + Header Files\Mappers + + + Header Files\Mappers + + + Header Files\Mappers + diff --git a/Core/MapperFactory.h b/Core/MapperFactory.h index 319394a4..bd43f4ae 100644 --- a/Core/MapperFactory.h +++ b/Core/MapperFactory.h @@ -1,6 +1,8 @@ #include "stdafx.h" -#include "BaseMapper.h" +#include "NROM.h" #include "MMC1.h" +#include "UNROM.h" +#include "CNROM.h" #include "ROMLoader.h" class MapperFactory @@ -14,9 +16,11 @@ class MapperFactory BaseMapper* mapper = nullptr; switch(mapperID) { - case 0: mapper = new DefaultMapper(); break; + case 0: mapper = new NROM(); break; case 1: mapper = new MMC1(); break; - case 2: mapper = new Mapper2(); break; + case 2: mapper = new UNROM(); break; + case 3: mapper = new CNROM(); break; + //case 4: mapper = new MMC3(); break; } if(!mapper) { diff --git a/Core/NROM.h b/Core/NROM.h new file mode 100644 index 00000000..7657c53d --- /dev/null +++ b/Core/NROM.h @@ -0,0 +1,23 @@ +#pragma once +#include "stdafx.h" +#include "BaseMapper.h" + +class NROM : public BaseMapper +{ + protected: + virtual uint32_t GetPRGPageSize() { return 0x4000; } + virtual uint32_t GetCHRPageSize() { return 0x2000; } + + virtual void InitMapper() + { + if(_prgSize == 0x4000) { + SelectPRGPage(0, 0); + SelectPRGPage(1, 0); + } else { + SelectPRGPage(0, 0); + SelectPRGPage(1, 1); + } + + SelectCHRPage(0, 0); + } +}; diff --git a/Core/UNROM.h b/Core/UNROM.h new file mode 100644 index 00000000..e4e55d0c --- /dev/null +++ b/Core/UNROM.h @@ -0,0 +1,25 @@ +#pragma once +#include "stdafx.h" +#include "BaseMapper.h" + +class UNROM : public BaseMapper +{ + protected: + virtual uint32_t GetPRGPageSize() { return 0x4000; } + virtual uint32_t GetCHRPageSize() { return 0x2000; } + + void InitMapper() + { + //First and last PRG page + SelectPRGPage(0, 0); + SelectPRGPage(1, -1); + + SelectCHRPage(0, 0); + } + + public: + void WriteRAM(uint16_t addr, uint8_t value) + { + SelectPRGPage(0, value); + } +}; \ No newline at end of file