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.
- Loading branch information
Showing
4 changed files
with
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef MAPPERUXROM_H | ||
#define MAPPERUXROM_H | ||
#include "Mapper.h" | ||
|
||
namespace sn | ||
{ | ||
class MapperUxROM : public Mapper | ||
{ | ||
public: | ||
MapperUxROM(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_usesCharacterRAM; | ||
|
||
const Byte* m_lastBankPtr; | ||
Address m_selectPRG; | ||
|
||
std::vector<Byte> m_characterRAM; | ||
|
||
}; | ||
} | ||
#endif // MAPPERUXROM_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
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,58 @@ | ||
#include "MapperUxROM.h" | ||
#include "Log.h" | ||
|
||
namespace sn | ||
{ | ||
MapperUxROM::MapperUxROM(Cartridge &cart) : | ||
Mapper(cart, Mapper::UxROM), | ||
m_selectPRG(0) | ||
{ | ||
if (cart.getVROM().size() == 0) | ||
{ | ||
m_usesCharacterRAM = true; | ||
m_characterRAM.resize(0x2000); | ||
LOG(Info) << "Uses character RAM" << std::endl; | ||
} | ||
else | ||
m_usesCharacterRAM = false; | ||
|
||
m_lastBankPtr = &cart.getROM()[cart.getROM().size() - 0x4000]; //last - 16KB | ||
} | ||
|
||
Byte MapperUxROM::readPRG(Address addr) | ||
{ | ||
if (addr < 0xc000) | ||
return m_cartridge.getROM()[((addr - 0x8000) & 0x3fff) | (m_selectPRG << 14)]; | ||
else | ||
return *(m_lastBankPtr + (addr & 0x3fff)); | ||
} | ||
|
||
void MapperUxROM::writePRG(Address addr, Byte value) | ||
{ | ||
m_selectPRG = value; | ||
} | ||
|
||
const Byte* MapperUxROM::getPagePtr(Address addr) | ||
{ | ||
if (addr < 0xc000) | ||
return &m_cartridge.getROM()[((addr - 0x8000) & 0x3fff) | (m_selectPRG << 14)]; | ||
else | ||
return m_lastBankPtr + (addr & 0x3fff); | ||
} | ||
|
||
Byte MapperUxROM::readCHR(Address addr) | ||
{ | ||
if (m_usesCharacterRAM) | ||
return m_characterRAM[addr]; | ||
else | ||
return m_cartridge.getVROM()[addr]; | ||
} | ||
|
||
void MapperUxROM::writeCHR(Address addr, Byte value) | ||
{ | ||
if (m_usesCharacterRAM) | ||
m_characterRAM[addr] = value; | ||
else | ||
LOG(Info) << "Read-only CHR memory write attempt at " << std::hex << addr << std::endl; | ||
} | ||
} |