NESemu/src/Cartridge.hpp

74 lines
1.1 KiB
C++
Raw Normal View History

2022-02-28 16:04:25 +01:00
#pragma once
#include <string>
#include <memory>
#include "Types.hpp"
#include "Mapper.hpp"
class Bus;
2022-02-28 16:43:35 +01:00
/**
* @brief iNES ROM header.
*/
2022-02-28 16:04:25 +01:00
struct Header
{
Byte Signature[4];
Byte PrgROM;
Byte ChrROM;
Byte MapperLo;
Byte MapperHi;
Byte PrgRAM;
Byte TV1;
Byte TV2;
Byte Padding[5];
};
2022-02-28 16:43:35 +01:00
/**
* @brief Represents a cartridge and handles CPU/PPU read/writes.
*/
2022-02-28 16:04:25 +01:00
class Cartridge
{
public:
2022-02-28 16:43:35 +01:00
/**
* @brief Add a cartridge to the Bus.
*/
2022-02-28 16:04:25 +01:00
Cartridge(Bus* bus);
~Cartridge();
2022-02-28 16:43:35 +01:00
/**
* @brief Read from the CPU.
*/
inline Byte ReadCPU(Word addr) { return mapper->ReadCPU(addr); }
2022-02-28 16:04:25 +01:00
2022-02-28 16:43:35 +01:00
/**
* @brief Read from the PPU.
*/
inline Byte ReadPPU(Word addr) { return mapper->ReadPPU(addr); }
/**
* @brief Wrote from the CPU.
*/
inline void WriteCPU(Word addr, Byte val) { mapper->WriteCPU(addr, val); }
/**
* @brief Write from the PPU.
*/
inline void WritePPU(Word addr, Byte val) { mapper->WritePPU(addr, val); }
/**
* @brief Load an iNES file from disk.
*/
2022-02-28 16:04:25 +01:00
void Load(std::string path);
2022-02-28 16:43:35 +01:00
/**
* @brief Returns the Mapper used by the cartridge.
*/
2022-02-28 16:04:25 +01:00
inline Mapper* GetMapper() { return mapper; }
private:
Mapper* mapper;
Bus* bus;
};