added documentation to cartridge
This commit is contained in:
parent
377a9a3741
commit
7c424b3137
|
@ -8,7 +8,7 @@
|
|||
#include "mappers/Mapper000.hpp"
|
||||
|
||||
Cartridge::Cartridge(Bus* bus) :
|
||||
bus(bus)
|
||||
bus(bus), mapper(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -17,36 +17,19 @@ Cartridge::~Cartridge()
|
|||
delete mapper;
|
||||
}
|
||||
|
||||
Byte Cartridge::ReadCPU(Word addr)
|
||||
{
|
||||
return mapper->ReadCPU(addr);
|
||||
}
|
||||
|
||||
Byte Cartridge::ReadPPU(Word addr)
|
||||
{
|
||||
return mapper->ReadPPU(addr);
|
||||
}
|
||||
|
||||
void Cartridge::WriteCPU(Word addr, Byte val)
|
||||
{
|
||||
mapper->WriteCPU(addr, val);
|
||||
}
|
||||
|
||||
void Cartridge::WritePPU(Word addr, Byte val)
|
||||
{
|
||||
mapper->WritePPU(addr, val);
|
||||
}
|
||||
|
||||
void Cartridge::Load(std::string path)
|
||||
{
|
||||
// Try to load file from disk
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
if (!file)
|
||||
throw std::runtime_error("Failed to open file " + path);
|
||||
|
||||
// Read header into (temporary) structure
|
||||
LOG_CORE_INFO("Extracting header");
|
||||
Header header;
|
||||
file.read((char*)&header, sizeof(Header));
|
||||
|
||||
// Figure out which mapper the cartridge uses and create a mapper object
|
||||
uint8_t mapperNumber = (header.MapperHi & 0xF0) | (header.MapperLo >> 4);
|
||||
LOG_CORE_INFO("Cartridge requires Mapper {0:d}", mapperNumber);
|
||||
switch (mapperNumber)
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
|
||||
class Bus;
|
||||
|
||||
/**
|
||||
* @brief iNES ROM header.
|
||||
*/
|
||||
struct Header
|
||||
{
|
||||
Byte Signature[4];
|
||||
|
@ -21,19 +24,47 @@ struct Header
|
|||
Byte Padding[5];
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a cartridge and handles CPU/PPU read/writes.
|
||||
*/
|
||||
class Cartridge
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Add a cartridge to the Bus.
|
||||
*/
|
||||
Cartridge(Bus* bus);
|
||||
~Cartridge();
|
||||
|
||||
Byte ReadCPU(Word addr);
|
||||
Byte ReadPPU(Word addr);
|
||||
void WriteCPU(Word addr, Byte val);
|
||||
void WritePPU(Word addr, Byte val);
|
||||
/**
|
||||
* @brief Read from the CPU.
|
||||
*/
|
||||
inline Byte ReadCPU(Word addr) { return mapper->ReadCPU(addr); }
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
void Load(std::string path);
|
||||
|
||||
/**
|
||||
* @brief Returns the Mapper used by the cartridge.
|
||||
*/
|
||||
inline Mapper* GetMapper() { return mapper; }
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue