From ddfe9fb4f5d191d4c6e03f403420a44fa198da28 Mon Sep 17 00:00:00 2001 From: Souryo Date: Sat, 12 Nov 2016 10:09:42 -0500 Subject: [PATCH] UNIF KS7057 board support --- Core/Core.vcxproj | 1 + Core/Core.vcxproj.filters | 3 ++ Core/Kaiser7057.h | 71 +++++++++++++++++++++++++++++++++++++++ Core/MapperFactory.cpp | 4 ++- Core/UnifBoards.h | 1 + Core/UnifLoader.h | 2 +- 6 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 Core/Kaiser7057.h diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 5947db1b..1b32f9b6 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -467,6 +467,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index 5e8d4be4..b77bfa77 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -1066,6 +1066,9 @@ Nes\Mappers\Unif + + Nes\Mappers\Unif + diff --git a/Core/Kaiser7057.h b/Core/Kaiser7057.h new file mode 100644 index 00000000..489e1c56 --- /dev/null +++ b/Core/Kaiser7057.h @@ -0,0 +1,71 @@ +#pragma once +#include "stdafx.h" +#include "BaseMapper.h" + +class Kaiser7057 : public BaseMapper +{ +private: + uint8_t _regs[8]; + +protected: + uint16_t GetPRGPageSize() { return 0x800; } + uint16_t GetCHRPageSize() { return 0x2000; } + + void InitMapper() override + { + memset(_regs, 0, sizeof(_regs)); + SelectCHRPage(0, 0); + UpdateState(); + } + + void StreamState(bool saving) + { + BaseMapper::StreamState(saving); + ArrayInfo regs{ _regs, 8 }; + Stream(regs); + + if(!saving) { + UpdateState(); + } + } + + void UpdateState() + { + for(int i = 0; i < 4; i++) { + SetCpuMemoryMapping(0x6000 + 0x800 * i, 0x67FF + 0x800 * i, _regs[4 + i], PrgMemoryType::PrgRom); + SelectPRGPage(i, _regs[i]); + } + SelectPrgPage4x(1, 0x34); + SelectPrgPage4x(2, 0x38); + SelectPrgPage4x(3, 0x3C); + } + + void UpdatePrgReg(int index, uint8_t value, bool low) + { + if(low) { + _regs[index] = (_regs[index] & 0xF0) | (value & 0x0F); + } else { + _regs[index] = (_regs[index] & 0x0F) | ((value << 4) & 0xF0); + } + UpdateState(); + } + + void WriteRegister(uint16_t addr, uint8_t value) override + { + bool low = (addr & 0x01) == 0x00; + switch(addr & 0xF002) { + case 0x8000: case 0x8002: case 0x9000: case 0x9002: + SetMirroringType(value & 0x01 ? MirroringType::Vertical : MirroringType::Horizontal); + break; + + case 0xB000: UpdatePrgReg(0, value, low); break; + case 0xB002: UpdatePrgReg(1, value, low); break; + case 0xC000: UpdatePrgReg(2, value, low); break; + case 0xC002: UpdatePrgReg(3, value, low); break; + case 0xD000: UpdatePrgReg(4, value, low); break; + case 0xD002: UpdatePrgReg(5, value, low); break; + case 0xE000: UpdatePrgReg(6, value, low); break; + case 0xE002: UpdatePrgReg(7, value, low); break; + } + } +}; \ No newline at end of file diff --git a/Core/MapperFactory.cpp b/Core/MapperFactory.cpp index 3565a079..73210267 100644 --- a/Core/MapperFactory.cpp +++ b/Core/MapperFactory.cpp @@ -62,8 +62,9 @@ #include "Kaiser202.h" #include "Kaiser7016.h" #include "Kaiser7022.h" -#include "Kaiser7058.h" #include "Kaiser7037.h" +#include "Kaiser7057.h" +#include "Kaiser7058.h" #include "Lh10.h" #include "Malee.h" #include "Mapper15.h" @@ -503,6 +504,7 @@ BaseMapper* MapperFactory::GetMapperFromID(RomData &romData) case UnifBoards::Kof97: return new MMC3_Kof97(); case UnifBoards::Ks7016: return new Kaiser7016(); case UnifBoards::Ks7037: return new Kaiser7037(); + case UnifBoards::Ks7057: return new Kaiser7057(); case UnifBoards::Lh10: return new Lh10(); case UnifBoards::Malee: return new Malee(); case UnifBoards::NovelDiamond: return new NovelDiamond(); diff --git a/Core/UnifBoards.h b/Core/UnifBoards.h index 8d726fd0..6d30de6c 100644 --- a/Core/UnifBoards.h +++ b/Core/UnifBoards.h @@ -41,5 +41,6 @@ namespace UnifBoards { BmcF15, Lh10, Ks7037, + Ks7057, }; } \ No newline at end of file diff --git a/Core/UnifLoader.h b/Core/UnifLoader.h index a20a8071..cd1ca2d1 100644 --- a/Core/UnifLoader.h +++ b/Core/UnifLoader.h @@ -69,7 +69,7 @@ private: { "KS7031", UnifBoards::UnknownBoard }, { "KS7032", 142 }, { "KS7037", UnifBoards::Ks7037 }, - { "KS7057", UnifBoards::UnknownBoard }, + { "KS7057", UnifBoards::Ks7057 }, { "LE05", UnifBoards::UnknownBoard }, { "LH10", UnifBoards::Lh10 }, { "LH32", 125 },