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

Commit

Permalink
Merge pull request #23 from NovaSquirrel/master
Browse files Browse the repository at this point in the history
Mapper updates
  • Loading branch information
mkwong98 authored Mar 21, 2022
2 parents 9439174 + af63ef0 commit 0bdc2e1
Show file tree
Hide file tree
Showing 55 changed files with 1,731 additions and 468 deletions.
11 changes: 9 additions & 2 deletions Core/BandaiFcg.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class BandaiFcg : public BaseMapper
}

//Last bank
if( _romInfo.MapperID != 153 && GetPRGPageCount() >= 0x20 )
SelectPRGPage(1, 0x1F);
else
SelectPRGPage(1, 0x0F);
}

Expand Down Expand Up @@ -156,7 +159,7 @@ class BandaiFcg : public BaseMapper
switch(addr & 0x000F) {
case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
_chrRegs[addr & 0x07] = value;
if(_romInfo.MapperID == 153 || GetPRGPageCount() >= 0x20) {
if(_romInfo.MapperID == 153) {
_prgBankSelect = 0;
for(int i = 0; i < 8; i++) {
_prgBankSelect |= (_chrRegs[i] & 0x01) << 4;
Expand All @@ -173,7 +176,11 @@ class BandaiFcg : public BaseMapper
break;

case 0x08:
if( _romInfo.MapperID != 153 && GetPRGPageCount() >= 0x20 )
_prgPage = value & 0x1F;
else
_prgPage = value & 0x0F;

SelectPRGPage(0, _prgPage | _prgBankSelect);
break;

Expand Down Expand Up @@ -232,4 +239,4 @@ class BandaiFcg : public BaseMapper
break;
}
}
};
};
65 changes: 65 additions & 0 deletions Core/Bmc1024CA1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#pragma once
#include "stdafx.h"
#include "MMC3.h"

class Bmc1024CA1 : public MMC3
{
private:
uint8_t _exReg;

protected:
uint16_t GetChrRamPageSize() override { return 0x400; }
uint32_t GetChrRamSize() override { return 0x2000; }
uint32_t GetWorkRamSize() override { return 0x2000; }
uint32_t GetWorkRamPageSize() override { return 0x2000; }
bool ForceWorkRamSize() override { return true; }

void InitMapper() override
{
AddRegisterRange(0x6000, 0x7FFF, MemoryOperation::Write);
_exReg = 0;
MMC3::InitMapper();
}

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

void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override
{
if (_exReg & 0x10) {
MMC3::SelectCHRPage(slot, page, ChrMemoryType::ChrRam);
} else if (_exReg & 0x20) {
MMC3::SelectCHRPage(slot, ((_exReg & 0x07) << 7) | (page & 0xFF));
} else {
MMC3::SelectCHRPage(slot, ((_exReg & 0x07) << 7) | (page & 0x7F));
}
}

void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override
{
if(_exReg & 0x08) {
MMC3::SelectPRGPage(slot, ((_exReg & 0x07) << 4) | (page & 0x1F));
} else {
MMC3::SelectPRGPage(slot, ((_exReg & 0x07) << 4) | (page & 0x0F));
}
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr <= 0x7FFF) {
if(CanWriteToWorkRam()) {
WritePrgRam(addr, value);
if ((_exReg & 0x07) == 0) {
_exReg = addr & 0x3F;
UpdatePrgMapping();
UpdateChrMapping();
}
}
} else {
MMC3::WriteRegister(addr, value);
}
}
};
15 changes: 10 additions & 5 deletions Core/Bmc64in1NoRepeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Bmc64in1NoRepeat : public BaseMapper

void InitMapper() override
{
AddRegisterRange(0x5000, 0x5003, MemoryOperation::Write);
AddRegisterRange(0x5000, 0x5FFF, MemoryOperation::Write);
}

void Reset(bool softReset) override
Expand All @@ -37,14 +37,15 @@ class Bmc64in1NoRepeat : public BaseMapper
{
if(_regs[0] & 0x80) {
if(_regs[1] & 0x80) {
SelectPrgPage2x(0, (_regs[1] & 0x1F) << 1);
SelectPrgPage2x(0, (_regs[1] & 0x3F) << 1);
} else {
int bank = ((_regs[1] & 0x1F) << 1) | ((_regs[1] >> 6) & 0x01);
int bank = ((_regs[1] & 0x3F) << 1) | ((_regs[1] >> 6) & 0x01);
SelectPRGPage(0, bank);
SelectPRGPage(1, bank);
}
} else {
SelectPRGPage(1, ((_regs[1] & 0x1F) << 1) | ((_regs[1] >> 6) & 0x01));
SelectPRGPage(0, ((_regs[1] & 0x3F) << 1) | (_regs[3] & 0x07));
SelectPRGPage(1, ((_regs[1] & 0x3F) << 1) | 0x07);
}
SetMirroringType(_regs[0] & 0x20 ? MirroringType::Horizontal : MirroringType::Vertical);
SelectCHRPage(0, (_regs[2] << 2) | ((_regs[0] >> 1) & 0x03));
Expand All @@ -53,7 +54,11 @@ class Bmc64in1NoRepeat : public BaseMapper
void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0x8000) {
_regs[addr & 0x03] = value;
if(HasChrRom() == false) {
_regs[addr & 0x01] = value;
} else {
_regs[addr & 0x03] = value;
}
} else {
_regs[3] = value;
}
Expand Down
7 changes: 4 additions & 3 deletions Core/Bmc70in1.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ class Bmc70in1 : public BaseMapper
{
if(addr & 0x4000) {
_bankMode = addr & 0x30;
_prgReg = addr & 0x07;
_prgReg = addr & 0x0F;
} else {
SetMirroringType(addr & 0x20 ? MirroringType::Horizontal : MirroringType::Vertical);
if(_useOuterBank) {
_outerBank = (addr & 0x03) << 3;
_outerBank = (addr & 0x07) << 3;
} else {
_chrReg = addr & 0x07;
_chrReg = addr & 0x0F;
}

}

UpdateState();
Expand Down
1 change: 1 addition & 0 deletions Core/Bmc830118C.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Bmc830118C : public MMC3
{
_reg = 0;
MMC3::Reset(softReset);
UpdateState();
}

void StreamState(bool saving) override
Expand Down
59 changes: 59 additions & 0 deletions Core/Bmc830134C.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once
#include "stdafx.h"
#include "MMC3.h"

class Bmc830134C : public MMC3
{
private:
uint8_t _exReg;

protected:
void InitMapper() override
{
_exReg = 0;
MMC3::InitMapper();
AddRegisterRange(0x6800, 0x68FF, MemoryOperation::Write);
}

void Reset(bool softReset) override
{
_exReg = 0;
MMC3::Reset(softReset);
UpdateState();
}

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

void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override
{
MMC3::SelectCHRPage(slot, ((_exReg & 0x01) << 8) | ((_exReg & 0x02) << 6) | ((_exReg & 0x08) << 3) | (page & 0xFF));
}

void SelectPRGPage(uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override
{
if((_exReg & 0x06) == 0x06) {
if(slot == 0) {
MMC3::SelectPRGPage(0, ((_exReg & 0x06) << 3) | (page & 0x0F));
MMC3::SelectPRGPage(2, 0x32 | (page & 0x0F));
} else if (slot == 1) {
MMC3::SelectPRGPage(1, ((_exReg & 0x06) << 3) | (page & 0x0F));
MMC3::SelectPRGPage(3, 0x32 | (page & 0x0F));
}
} else
MMC3::SelectPRGPage(slot, ((_exReg & 0x06) << 3) | (page & 0x0F));
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0x8000) {
_exReg = value;
UpdateState();
} else {
MMC3::WriteRegister(addr, value);
}
}
};
67 changes: 67 additions & 0 deletions Core/Bmc891227.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#pragma once
#include "stdafx.h"
#include "BaseMapper.h"

class Bmc891227 : public BaseMapper
{
private:
uint8_t _reg;

protected:
virtual uint16_t GetPRGPageSize() override { return 0x4000; }
virtual uint16_t GetCHRPageSize() override { return 0x2000; }

void InitMapper() override
{
SelectCHRPage(0, 0);
}

void Reset(bool softReset) override
{
if(!softReset) {
_reg = 0;
}
UpdateState();
}

void StreamState(bool saving) override
{
BaseMapper::StreamState(saving);
Stream(_reg);
}

void UpdateState() {
uint8_t prgPage = _reg & 0x1F;

SetCpuMemoryMapping(0x6000, 0x7FFF, PrgMemoryType::PrgRom, 0x2000, MemoryAccessType::Read);

switch((_reg & 0x60) >> 5) {
case 0: // NROM-128
SelectPRGPage(0, _reg & 0x1F);
SelectPRGPage(1, _reg & 0x1F);
break;

case 1: // NROM-256
SelectPrgPage2x(0, _reg & 0x1E);
break;

default: // UNROM
SelectPRGPage(0, _reg & 0x3F);
SelectPRGPage(1, (_reg & 0x3F) | 7);
break;
}
SetMirroringType(_reg & 0x80 ? MirroringType::Horizontal : MirroringType::Vertical);
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0xC000) {
_reg &= 0x07;
_reg |= value & ~0x07;
} else {
_reg &= _reg & ~0x07;
_reg |= value & 0x07;
}
UpdateState();
}
};
31 changes: 31 additions & 0 deletions Core/BmcCtc09.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once
#include "stdafx.h"
#include "BaseMapper.h"

class BmcCtc09 : public BaseMapper
{
protected:
uint16_t GetPRGPageSize() override { return 0x4000; }
uint16_t GetCHRPageSize() override { return 0x2000; }

void InitMapper() override
{
WriteRegister(0x8000, 0);
WriteRegister(0xC000, 0);
}

void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr >= 0xC000) {
if (value & 0x10) {
SelectPRGPage(0, ((value << 1) & 0x0E) | ((value >> 3) & 0x01));
SelectPRGPage(1, ((value << 1) & 0x0E) | ((value >> 3) & 0x01));
} else {
SelectPrgPage2x(0, (value & 0x07) << 1);
}
SetMirroringType(((value & 0x40) == 0x40) ? MirroringType::Horizontal : MirroringType::Vertical);
} else {
SelectCHRPage(0, value & 0x0F);
}
}
};
Loading

0 comments on commit 0bdc2e1

Please sign in to comment.