diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 5c07e62d..975b59ea 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -444,6 +444,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index 49d6ec98..60345255 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -703,6 +703,9 @@ Nes\Mappers\Unnamed + + Nes\Mappers\Unnamed + diff --git a/Core/Mapper42.h b/Core/Mapper42.h new file mode 100644 index 00000000..2c51ca92 --- /dev/null +++ b/Core/Mapper42.h @@ -0,0 +1,76 @@ +#pragma once +#include "stdafx.h" +#include "BaseMapper.h" +#include "CPU.h" + +class Mapper42 : public BaseMapper +{ +private: + uint16_t _irqCounter; + bool _irqEnabled; + +protected: + virtual uint16_t GetPRGPageSize() { return 0x2000; } + virtual uint16_t GetCHRPageSize() { return 0x2000; } + + void InitMapper() + { + _irqCounter = 0; + _irqEnabled = false; + + SelectPRGPage(0, 0x0C); + SelectPRGPage(1, 0x0D); + SelectPRGPage(2, 0x0E); + SelectPRGPage(3, 0x0F); + SelectCHRPage(0, 0); + } + + void StreamState(bool saving) + { + BaseMapper::StreamState(saving); + Stream(_irqCounter, _irqEnabled); + } + + void ProcessCpuClock() + { + if(_irqEnabled) { + _irqCounter++; + if(_irqCounter >= 0x8000) { + _irqCounter -= 0x8000; + } + if(_irqCounter >= 0x6000) { + CPU::SetIRQSource(IRQSource::External); + } else { + CPU::ClearIRQSource(IRQSource::External); + } + } + } + + void WriteRegister(uint16_t addr, uint8_t value) + { + switch(addr & 0xE003) { + case 0x8000: + if(_chrRomSize > 0) { + SelectCHRPage(0, value & 0x0F); + } + break; + + case 0xE000: + SetCpuMemoryMapping(0x6000, 0x7FFF, value & 0x0F, PrgMemoryType::PrgRom); + break; + + case 0xE001: + SetMirroringType(value & 0x08 ? MirroringType::Horizontal : MirroringType::Vertical); + break; + + case 0xE002: + _irqEnabled = (value == 0x02); + + if(!_irqEnabled) { + CPU::ClearIRQSource(IRQSource::External); + _irqCounter = 0; + } + break; + } + } +}; diff --git a/Core/MapperFactory.cpp b/Core/MapperFactory.cpp index d1eef048..64a6708c 100644 --- a/Core/MapperFactory.cpp +++ b/Core/MapperFactory.cpp @@ -28,6 +28,7 @@ #include "JalecoSs88006.h" #include "Mapper15.h" #include "Mapper40.h" +#include "Mapper42.h" #include "Mapper50.h" #include "Mapper57.h" #include "Mapper58.h" @@ -118,7 +119,7 @@ Supported mappers: (... denotes bad mappers) ----------------------------------------------------------------- | 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| | | | 31| -| 32| 33| 34| | | 37| 38| | 40| | | | 44| 45| | 47| +| 32| 33| 34| | | 37| 38| | 40| | 42| | 44| 45| | 47| | | 49| 50| | 52| | | | | 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| @@ -183,6 +184,7 @@ BaseMapper* MapperFactory::GetMapperFromID(RomData &romData) case 37: return new MMC3_37(); case 38: return new UnlPci556(); case 40: return new Mapper40(); + case 42: return new Mapper42(); case 44: return new MMC3_44(); case 45: return new MMC3_45(); case 47: return new MMC3_47();