Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

mappers #115

Merged
merged 6 commits into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -799,14 +799,20 @@
<ClInclude Include="Mapper357.h" />
<ClInclude Include="Mapper359.h" />
<ClInclude Include="Mapper360.h" />
<ClInclude Include="Mapper362.h" />
<ClInclude Include="Mapper375.h" />
<ClInclude Include="Mapper380.h" />
<ClInclude Include="Mapper382.h" />
<ClInclude Include="Mapper385.h" />
<ClInclude Include="Mapper389.h" />
<ClInclude Include="Mapper398.h" />
<ClInclude Include="Mapper400.h" />
<ClInclude Include="Mapper449.h" />
<ClInclude Include="Mapper452.h" />
<ClInclude Include="Mapper455.h" />
<ClInclude Include="Mapper456.h" />
<ClInclude Include="Mapper457.h" />
<ClInclude Include="Mapper458.h" />
<ClInclude Include="Mapper500.h" />
<ClInclude Include="Mapper501.h" />
<ClInclude Include="Mapper502.h" />
Expand Down
18 changes: 18 additions & 0 deletions Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,9 @@
<ClInclude Include="Mapper360.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Mapper362.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Mapper375.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
Expand All @@ -1567,6 +1570,9 @@
<ClInclude Include="Mapper389.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Mapper398.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Mapper400.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
Expand All @@ -1576,6 +1582,18 @@
<ClInclude Include="Mapper452.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Mapper455.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Mapper456.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Mapper457.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Mapper458.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
<ClInclude Include="Mapper500.h">
<Filter>Nes\Mappers\Unnamed</Filter>
</ClInclude>
Expand Down
74 changes: 74 additions & 0 deletions Core/MMC3_455.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma once

#include "stdafx.h"
#include "MMC3.h"

class MMC3_455: public MMC3
{
private:
uint8_t _exRegs[2];

protected:
void InitMapper() override
{
_exRegs[0] = 0;
_exRegs[1] = 1;

AddRegisterRange(0x4100, 0x5FFF, MemoryOperation::Write);

MMC3::InitMapper();
MMC3::WriteRegister(0xA001, 0x80);
}

void Reset(bool softReset) override
{
_exRegs[0] = 0;
_exRegs[1] = 1;

MMC3::UpdateState();
}


void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override
{
uint16_t base = (((_exRegs[1] >> 2) & 0x10) | ((_exRegs[0] << 1) & 0x08) | ((_exRegs[1] >> 2) & 0x07)) << 4;
uint16_t mask = 0xFF >> !(_exRegs[0] & 0x02);

MMC3::SelectCHRPage(slot, (base & ~mask) | (page & mask));
}

void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override
{
uint16_t base = (((_exRegs[1] >> 2) & 0x10) | ((_exRegs[0] << 1) & 0x08) | ((_exRegs[1] >> 2) & 0x07)) << 1;
uint16_t mask = 0x1F >> !(_exRegs[0] & 0x01);

if(_exRegs[1] & 0x01) {
uint8_t nrom = _exRegs[1] & 0x02;
base = (slot & 0x02) ? (base | nrom) : (base & ~nrom);
mask = 0x01;
page = slot & 0x01;
}

MMC3::SelectPRGPage(slot, (base & ~mask) | (page & mask));
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0x8000) {
if((GetState().RegA001 & 0x80) && (addr & 0x100)) {
_exRegs[0] = (addr & 0xFF);
_exRegs[1] = value;
MMC3::UpdatePrgMapping();
MMC3::UpdateChrMapping();
}
} else {
MMC3::WriteRegister(addr, value);
}
}

void StreamState(bool saving) override
{
MMC3::StreamState(saving);
Stream(_exRegs[0], _exRegs[1]);
}
};
57 changes: 57 additions & 0 deletions Core/MMC3_456.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once

#include "stdafx.h"
#include "MMC3.h"

class MMC3_456: public MMC3
{
private:
uint8_t _outerBank;

protected:
void InitMapper() override
{
_outerBank = 0;

AddRegisterRange(0x4100, 0x5FFF, MemoryOperation::Write);

MMC3::InitMapper();
}

void Reset(bool softReset) override
{
_outerBank = 0;

MMC3::UpdateState();
}


void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override
{
MMC3::SelectCHRPage(slot, (_outerBank << 7) | (page & 0x7F));
}

void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override
{
MMC3::SelectPRGPage(slot, (_outerBank << 4) | (page & 0x0F));
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0x8000) {
if(CanWriteToWorkRam()) {
_outerBank = value;
MMC3::UpdatePrgMapping();
MMC3::UpdateChrMapping();
}
} else {
MMC3::WriteRegister(addr, value);
}
}

void StreamState(bool saving) override
{
MMC3::StreamState(saving);
Stream(_outerBank);
}
};
60 changes: 60 additions & 0 deletions Core/MMC3_457.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#pragma once

#include "stdafx.h"
#include "MMC3.h"

class MMC3_457: public MMC3
{
private:
uint8_t _outerBank;

protected:
void InitMapper() override
{
_outerBank = 0;

AddRegisterRange(0x6000, 0x7FFF, MemoryOperation::Write);

MMC3::InitMapper();
}

void Reset(bool softReset) override
{
_outerBank = 0;

MMC3::UpdateState();
}


void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override
{
uint8_t mask = 0xFF >> !(_outerBank & 0x08);
MMC3::SelectCHRPage(slot, ((_outerBank << 7) & ~mask) | (page & mask));
}

void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override
{
uint8_t mask = 0x1F >> !(_outerBank & 0x08);
MMC3::SelectPRGPage(slot, ((_outerBank << 4) & ~mask) | (page & mask));
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0x8000) {
WritePrgRam(addr, value);
if(CanWriteToWorkRam()) {
_outerBank = value;
MMC3::UpdatePrgMapping();
MMC3::UpdateChrMapping();
}
} else {
MMC3::WriteRegister(addr, value);
}
}

void StreamState(bool saving) override
{
MMC3::StreamState(saving);
Stream(_outerBank);
}
};
71 changes: 71 additions & 0 deletions Core/MMC3_458.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#pragma once
#include "MMC3.h"

class MMC3_458 : public MMC3
{
private:
uint8_t _exReg;

protected:
uint32_t GetDipSwitchCount() override { return 2; }
bool AllowRegisterRead() override { return true; }

void InitMapper() override
{
_exReg = 0;
MMC3::InitMapper();

AddRegisterRange(0x6000, 0x7FFF, MemoryOperation::Write);
}

void Reset(bool softReset) override
{
_exReg = 0;

MMC3::UpdateState();
}

void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override
{
MMC3::SelectCHRPage(slot, ((_exReg << 4) & ~0x7F) | (page & 0x7F));
}

void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override
{
uint16_t base = _exReg & 0x0F;
uint16_t nrom = (_romInfo.SubMapperID == 1) ? ((_exReg & 0x02) >> 3) : ((_exReg & 0x10) >> 4);

page = (slot & 1);
page |= ((slot & 0x02) ? (base | nrom) : (base & ~nrom)) << 1;

MMC3::SelectPRGPage(slot, page);
}

uint8_t ReadRegister(uint16_t addr) override
{
uint8_t dipValue = GetDipSwitches() & 0x03;

if((_exReg & 0x20) && dipValue) {
addr = (addr & ~0x03) | dipValue;
}

return InternalReadRam(addr);
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0x8000) {
_exReg = addr & 0xFF;
MMC3::UpdatePrgMapping();
MMC3::UpdateChrMapping();
} else {
MMC3::WriteRegister(addr, value);
}
}

void StreamState(bool saving) override
{
MMC3::StreamState(saving);
Stream(_exReg);
}
};
Loading