NESemu/src/Mapper.hpp

57 lines
1.2 KiB
C++
Raw Normal View History

2022-02-28 15:04:25 +00:00
#pragma once
#include <vector>
2022-03-05 16:14:07 +00:00
#include "../Log.hpp"
2022-02-28 15:04:25 +00:00
#include "Types.hpp"
class Mapper
{
friend class Disassembler;
2022-03-04 13:16:41 +00:00
friend class PatternTableViewer;
2022-02-28 15:04:25 +00:00
public:
virtual Byte ReadCPU(Word addr) = 0;
virtual Byte ReadPPU(Word addr) = 0;
virtual void WriteCPU(Word addr, Byte val) = 0;
virtual void WritePPU(Word addr, Byte val) = 0;
2022-03-01 02:34:19 +00:00
/**
* The cartridge actually controls the PPUs access to VRAM.
* It can modify the effective address the PPU accesses in order to
* enforce nametable mirroring, or even completely remap the address
* to internal VRAM
*/
2022-03-05 16:14:07 +00:00
virtual bool MapCIRAM(Word& addr)
2022-03-01 02:34:19 +00:00
{
if (header.Flag6.IgnoreMirroringBit)
return true;
if (header.Flag6.Mirroring == 0x0)
{
2022-03-01 17:13:47 +00:00
// Shift Bit 11 into Bit 10
2022-03-01 02:34:19 +00:00
addr &= ~(1 << 10);
addr |= ((addr & (1 << 11)) >> 1);
}
2022-03-01 17:13:47 +00:00
// Unset bit 11
addr &= ~(1 << 11);
2022-03-01 02:34:19 +00:00
return false;
}
virtual Byte ReadVRAM(Word addr) { return 0x00; }
virtual void WriteVRAM(Word addr, Byte val) {}
2022-02-28 15:04:25 +00:00
protected:
2022-03-05 16:14:07 +00:00
Mapper(const Header& header) : header(header), prgBanks(header.PrgROM), chrBanks(header.ChrROM)
{
}
2022-02-28 15:04:25 +00:00
protected:
std::vector<Byte> PRG_ROM;
std::vector<Byte> CHR_ROM;
2022-03-05 16:14:07 +00:00
Byte prgBanks = 0;
Byte chrBanks = 0;
2022-03-01 02:34:19 +00:00
Header header;
2022-02-28 15:04:25 +00:00
};