forked from amhndu/SimpleNES
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Games like Adventure Island and Paperboy work.
- Loading branch information
Showing
4 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef MAPPERCNROM_H | ||
#define MAPPERCNROM_H | ||
#include "Mapper.h" | ||
|
||
namespace sn | ||
{ | ||
class MapperCNROM : public Mapper | ||
{ | ||
public: | ||
MapperCNROM(Cartridge& cart); | ||
void writePRG (Address addr, Byte value); | ||
Byte readPRG (Address addr); | ||
const Byte* getPagePtr(Address addr); | ||
|
||
Byte readCHR (Address addr); | ||
void writeCHR (Address addr, Byte value); | ||
private: | ||
bool m_oneBank; | ||
|
||
Address m_selectCHR; | ||
}; | ||
} | ||
#endif // MAPPERCNROM_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "MapperCNROM.h" | ||
#include "Log.h" | ||
|
||
namespace sn | ||
{ | ||
MapperCNROM::MapperCNROM(Cartridge &cart) : | ||
Mapper(cart, Mapper::CNROM), | ||
m_selectCHR(0) | ||
{ | ||
if (cart.getROM().size() == 0x4000) //1 bank | ||
{ | ||
m_oneBank = true; | ||
} | ||
else //2 banks | ||
{ | ||
m_oneBank = false; | ||
} | ||
} | ||
|
||
Byte MapperCNROM::readPRG(Address addr) | ||
{ | ||
if (!m_oneBank) | ||
return m_cartridge.getROM()[addr - 0x8000]; | ||
else //mirrored | ||
return m_cartridge.getROM()[(addr - 0x8000) & 0x3fff]; | ||
} | ||
|
||
void MapperCNROM::writePRG(Address addr, Byte value) | ||
{ | ||
m_selectCHR = value & 0x3; | ||
} | ||
|
||
const Byte* MapperCNROM::getPagePtr(Address addr) | ||
{ | ||
if (!m_oneBank) | ||
return &m_cartridge.getROM()[addr - 0x8000]; | ||
else //mirrored | ||
return &m_cartridge.getROM()[(addr - 0x8000) & 0x3fff]; | ||
} | ||
|
||
Byte MapperCNROM::readCHR(Address addr) | ||
{ | ||
return m_cartridge.getVROM()[addr | (m_selectCHR << 13)]; | ||
} | ||
|
||
void MapperCNROM::writeCHR(Address addr, Byte value) | ||
{ | ||
LOG(Info) << "Read-only CHR memory write attempt at " << std::hex << addr << std::endl; | ||
} | ||
} |