64 lines
1.2 KiB
C++
64 lines
1.2 KiB
C++
//
|
|
// Created by Selim Mustafaev on 09.08.2023.
|
|
//
|
|
|
|
#ifndef NES_CARTRIDGE_H
|
|
#define NES_CARTRIDGE_H
|
|
|
|
#include "Mapper/Mapper0.h"
|
|
|
|
#include <filesystem>
|
|
#include <memory>
|
|
#include <span>
|
|
|
|
namespace nes {
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
constexpr uint32_t ROM_MAGIC = 0x4E45531A;
|
|
constexpr size_t PRG_CHUNK_SIZE = 16*1024;
|
|
constexpr size_t CHR_CHUNK_SIZE = 8*1024;
|
|
|
|
class Cartridge {
|
|
public:
|
|
enum Mirroring {
|
|
Horizontal,
|
|
Vertical
|
|
};
|
|
|
|
struct Flags {
|
|
uint8_t mirroring: 1;
|
|
uint8_t reserved: 7;
|
|
};
|
|
|
|
struct RomHeader {
|
|
uint32_t magic;
|
|
uint8_t prgChunks;
|
|
uint8_t chrChunks;
|
|
Flags flags;
|
|
uint8_t reserved[9];
|
|
};
|
|
|
|
public:
|
|
explicit Cartridge(const fs::path& path);
|
|
|
|
public:
|
|
uint8_t readPrg(uint16_t address);
|
|
uint8_t readChr(uint16_t address);
|
|
Mirroring mirroring() const;
|
|
|
|
private:
|
|
std::unique_ptr<uint8_t[]> _romData;
|
|
std::unique_ptr<Mapper> _mapper;
|
|
RomHeader* _header;
|
|
std::span<uint8_t> _prgRom;
|
|
std::span<uint8_t> _chrRom;
|
|
|
|
private:
|
|
Mirroring _mirroring;
|
|
};
|
|
|
|
}
|
|
|
|
#endif //NES_CARTRIDGE_H
|