diff --git a/Core/BaseMapper.h b/Core/BaseMapper.h index 3e5f92d4..67d04b46 100644 --- a/Core/BaseMapper.h +++ b/Core/BaseMapper.h @@ -86,6 +86,7 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat //Save ram is battery backed and saved to disk virtual uint32_t GetSaveRamSize() { return 0x2000; } virtual uint32_t GetSaveRamPageSize() { return 0x2000; } + virtual bool ForceBattery() { return false; } virtual uint32_t GetChrRamSize() { return 0x2000; } @@ -321,7 +322,7 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat romLoader.GetCHRRam(&_chrRam); _prgSize = romLoader.GetPRGSize(); _chrSize = romLoader.GetCHRSize(); - _hasBattery = romLoader.HasBattery(); + _hasBattery = romLoader.HasBattery() || ForceBattery(); _isPalRom = romLoader.IsPalRom(); _saveRam = new uint8_t[_saveRamSize]; diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 982175b2..ab9996ed 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -338,6 +338,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index f985e13b..411a9f18 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -275,6 +275,9 @@ Header Files\Mappers + + Header Files\Mappers + diff --git a/Core/MapperFactory.cpp b/Core/MapperFactory.cpp index 36dbb6f0..0b9f2db8 100644 --- a/Core/MapperFactory.cpp +++ b/Core/MapperFactory.cpp @@ -21,6 +21,7 @@ #include "Nina03_06.h" #include "NROM.h" #include "TaitoTc0190.h" +#include "TaitoX1005.h" #include "UnlPci556.h" #include "UNROM.h" #include "VRC2_4.h" @@ -61,6 +62,7 @@ BaseMapper* MapperFactory::GetMapperFromID(uint8_t mapperID) case 70: return new Bandai74161_7432(false); case 71: return new BF909x(); case 79: return new Nina03_06(); + case 80: return new TaitoX1005(); case 87: return new JalecoJfxx(false); case 101: return new JalecoJfxx(true); case 152: return new Bandai74161_7432(true); diff --git a/Core/TaitoX1005.h b/Core/TaitoX1005.h new file mode 100644 index 00000000..aeab4230 --- /dev/null +++ b/Core/TaitoX1005.h @@ -0,0 +1,90 @@ +#pragma once +#include "stdafx.h" +#include "BaseMapper.h" + +class TaitoX1005 : public BaseMapper +{ +private: + uint8_t _ramPermission; + + void UpdateRamAccess() + { + SetCpuMemoryMapping(0x7F00, 0x7FFF, 0, HasBattery() ? PrgMemoryType::SaveRam : PrgMemoryType::WorkRam, _ramPermission == 0xA3 ? MemoryAccessType::ReadWrite : MemoryAccessType::NoAccess); + } + +protected: + virtual uint16_t GetPRGPageSize() { return 0x2000; } + virtual uint16_t GetCHRPageSize() { return 0x0400; } + virtual uint16_t RegisterStartAddress() { return 0x7EF0; } + virtual uint16_t RegisterEndAddress() { return 0x7EFF; } + + virtual uint32_t GetWorkRamSize() { return 0x100; } + virtual uint32_t GetWorkRamPageSize() { return 0x100; } + virtual uint32_t GetSaveRamSize() { return 0x100; } + virtual uint32_t GetSaveRamPageSize() { return 0x100; } + + void InitMapper() + { + _ramPermission = 0; + + SelectPRGPage(3, -1); + + UpdateRamAccess(); + } + + virtual bool ForceBattery() + { + //Patch: Force battery, because some headers are marked as having no battery even though the game expects one + return true; + } + + void WriteRegister(uint16_t addr, uint8_t value) + { + switch(addr) { + case 0x7EF0: + SelectCHRPage(0, value); + SelectCHRPage(1, value + 1); + break; + case 0x7EF1: + SelectCHRPage(2, value ); + SelectCHRPage(3, value + 1); + break; + + case 0x7EF2: SelectCHRPage(4, value); break; + case 0x7EF3: SelectCHRPage(5, value); break; + case 0x7EF4: SelectCHRPage(6, value); break; + case 0x7EF5: SelectCHRPage(7, value); break; + + case 0x7EF6: case 0x7EF7: + SetMirroringType((value & 0x01) == 0x01 ? MirroringType::Vertical : MirroringType::Horizontal); + break; + + case 0x7EF8: case 0x7EF9: + _ramPermission = value; + UpdateRamAccess(); + break; + + case 0x7EFA: case 0x7EFB: + SelectPRGPage(0, value); + break; + + case 0x7EFC: case 0x7EFD: + SelectPRGPage(1, value); + break; + + case 0x7EFE: case 0x7EFF: + SelectPRGPage(2, value); + break; + } + } + + virtual void StreamState(bool saving) + { + BaseMapper::StreamState(saving); + Stream(_ramPermission); + + if(!saving) { + UpdateRamAccess(); + } + } +}; \ No newline at end of file