From 4b037162b72acf866712e89730c24c31342473b8 Mon Sep 17 00:00:00 2001 From: Souryo Date: Sat, 23 Jan 2016 12:51:10 -0500 Subject: [PATCH] Mapper 67 (SunSoft 3) support --- Core/Core.vcxproj | 1 + Core/Core.vcxproj.filters | 3 ++ Core/MapperFactory.cpp | 2 ++ Core/SunSoft3.h | 70 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 Core/SunSoft3.h diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 96116349..0aec08bd 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -474,6 +474,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index aee6cfed..bc208c8f 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -434,6 +434,9 @@ Nes\Mappers + + Nes\Mappers + diff --git a/Core/MapperFactory.cpp b/Core/MapperFactory.cpp index 904c3950..5fb3661e 100644 --- a/Core/MapperFactory.cpp +++ b/Core/MapperFactory.cpp @@ -60,6 +60,7 @@ #include "Sachen_147.h" #include "Sachen_148.h" #include "Sachen_149.h" +#include "Sunsoft3.h" #include "Sunsoft89.h" #include "Sunsoft93.h" #include "Sunsoft184.h" @@ -113,6 +114,7 @@ BaseMapper* MapperFactory::GetMapperFromID(ROMLoader &romLoader) case 61: return new Mapper61(); case 62: return new Mapper62(); case 66: return new GxRom(); + case 67: return new SunSoft3(); case 70: return new Bandai74161_7432(false); case 71: return new BF909x(); case 72: return new JalecoJf17_19(false); diff --git a/Core/SunSoft3.h b/Core/SunSoft3.h new file mode 100644 index 00000000..7ec0fb41 --- /dev/null +++ b/Core/SunSoft3.h @@ -0,0 +1,70 @@ +#pragma once +#include "stdafx.h" +#include "BaseMapper.h" +#include "CPU.h" + +class SunSoft3 : public BaseMapper +{ +private: + bool _irqLatch = false; + bool _irqEnabled = false; + uint16_t _irqCounter = 0; + +protected: + virtual uint16_t GetPRGPageSize() { return 0x4000; } + virtual uint16_t GetCHRPageSize() { return 0x800; } + + void InitMapper() + { + SelectPRGPage(1, -1); + } + + virtual void StreamState(bool saving) + { + BaseMapper::StreamState(saving); + Stream(_irqLatch); + Stream(_irqEnabled); + Stream(_irqCounter); + } + + virtual void ProcessCpuClock() + { + if(_irqEnabled) { + _irqCounter--; + if(_irqCounter == 0xFFFF) { + _irqEnabled = false; + CPU::SetIRQSource(IRQSource::External); + } + } + } + + void WriteRegister(uint16_t addr, uint8_t value) + { + switch(addr & 0xF800) { + case 0x8800: SelectCHRPage(0, value); break; + case 0x9800: SelectCHRPage(1, value); break; + case 0xA800: SelectCHRPage(2, value); break; + case 0xB800: SelectCHRPage(3, value); break; + case 0xC800: + _irqCounter &= _irqLatch ? 0xFF00 : 0x00FF; + _irqCounter |= _irqLatch ? value : (value << 8); + _irqLatch = !_irqLatch; + break; + case 0xD800: + _irqEnabled = (value & 0x10) == 0x10; + _irqLatch = false; + CPU::ClearIRQSource(IRQSource::External); + break; + case 0xE800: + switch(value & 0x03) { + case 0: SetMirroringType(MirroringType::Vertical); break; + case 1: SetMirroringType(MirroringType::Horizontal); break; + case 2: SetMirroringType(MirroringType::ScreenAOnly); break; + case 3: SetMirroringType(MirroringType::ScreenBOnly); break; + } + break; + case 0xF800: SelectPRGPage(0, value); break; + } + } +}; +#pragma once