Cartridge.hpp
Go to the documentation of this file.
//
// Created by anonymus-raccoon on 1/27/20.
//
#ifndef COMSQUARE_CARTRIDGE_HPP
#define COMSQUARE_CARTRIDGE_HPP
#include <string>
#include "../Memory/IMemory.hpp"
#include "../Models/Ints.hpp"
#include "../Memory/IRectangleMemory.hpp"
#include "InterruptVectors.hpp"
namespace ComSquare::Cartridge
{
#define ADDMAPPINGMODE(x, flag) (x = static_cast<MappingMode>(x | (flag)))
enum MappingMode {
LoRom = 1u << 0u,
HiRom = 1u << 1u,
SlowRom = 1u << 2u,
FastRom = 1u << 3u,
ExRom = 1u << 4u,
};
struct Header
{
std::string gameName;
MappingMode mappingMode;
uint8_t romType;
unsigned romSize;
unsigned sramSize;
union {
uint8_t creatorIDs[2];
uint16_t creatorID;
};
uint8_t version;
union {
uint8_t checksumComplements[2];
uint16_t checksumComplement;
};
union {
uint8_t checksums[2];
uint16_t checksum;
};
InterruptVectors nativeInterrupts;
InterruptVectors emulationInterrupts;
};
class Cartridge : Memory::IRectangleMemory {
private:
uint8_t *_data;
size_t _size;
static size_t getRomSize(const std::string &romPath);
bool _loadHeader();
uint32_t _getHeaderAddress();
Header _mapHeader(uint32_t headerAddress);
public:
explicit Cartridge(const std::string &romPath);
~Cartridge();
Header header;
uint8_t read_internal(uint24_t addr) override;
void write_internal(uint24_t addr, uint8_t data) override;
};
}
#endif //COMSQUARE_CARTRIDGE_HPP
ComSquare::Memory::IRectangleMemory
Superset of the IMemory to map non continuous rectangle to the memory. (A rectangle that spam across ...
Definition: IRectangleMemory.hpp:14
ComSquare::Cartridge::Header::emulationInterrupts
InterruptVectors emulationInterrupts
The interrupt vectors used to halt the CPU in emulation mode.
Definition: Cartridge.hpp:57
ComSquare::Cartridge::LoRom
@ LoRom
Definition: Cartridge.hpp:18
ComSquare::Cartridge::Header::checksums
uint8_t checksums[2]
Definition: Cartridge.hpp:51
ComSquare::Cartridge::Header::sramSize
unsigned sramSize
The size of the SRom inside the cartridge.
Definition: Cartridge.hpp:36
ComSquare::Cartridge::Header::mappingMode
MappingMode mappingMode
The memory mapping of the ROM.
Definition: Cartridge.hpp:30
ComSquare::Cartridge::Header::gameName
std::string gameName
The name of the game.
Definition: Cartridge.hpp:28
ComSquare::Cartridge::Cartridge::_size
size_t _size
The size of the rom data.
Definition: Cartridge.hpp:66
ComSquare::Cartridge::Cartridge::write_internal
void write_internal(uint24_t addr, uint8_t data) override
Write data to the rom.
Definition: Cartridge.cpp:55
ComSquare::Cartridge::Cartridge::_data
uint8_t * _data
The rom data (contains all the instructions).
Definition: Cartridge.hpp:64
uint24_t
unsigned uint24_t
Definition: Ints.hpp:8
ComSquare::Cartridge
Definition: Cartridge.cpp:13
ComSquare::Cartridge::Header::creatorIDs
uint8_t creatorIDs[2]
Definition: Cartridge.hpp:39
ComSquare::Cartridge::Header::romType
uint8_t romType
The rom type (special information about the rom, still don't know what).
Definition: Cartridge.hpp:32
ComSquare::Cartridge::Cartridge::Cartridge
Cartridge(const std::string &romPath)
Load a rom from it's path.
Definition: Cartridge.cpp:15
ComSquare::Cartridge::Cartridge::~Cartridge
~Cartridge()
Destructor that free the cartridge data.
Definition: Cartridge.cpp:33
ComSquare::Cartridge::Cartridge::_getHeaderAddress
uint32_t _getHeaderAddress()
Get the address of the header.
Definition: Cartridge.cpp:110
ComSquare::Cartridge::MappingMode
MappingMode
Definition: Cartridge.hpp:17
ComSquare::Cartridge::Header::nativeInterrupts
InterruptVectors nativeInterrupts
The interrupt vectors used to halt the CPU in native mode.
Definition: Cartridge.hpp:55
ComSquare::Cartridge::FastRom
@ FastRom
Definition: Cartridge.hpp:21
InterruptVectors.hpp
ComSquare::Cartridge::SlowRom
@ SlowRom
Definition: Cartridge.hpp:20
ComSquare::Cartridge::Header::checksumComplement
uint16_t checksumComplement
Definition: Cartridge.hpp:47
ComSquare::Cartridge::Cartridge::read_internal
uint8_t read_internal(uint24_t addr) override
Read from the rom.
Definition: Cartridge.cpp:48
ComSquare::Cartridge::InterruptVectors
Definition: InterruptVectors.hpp:10
ComSquare::Cartridge::Cartridge
Contains the rom's memory/instructions.
Definition: Cartridge.hpp:61
ComSquare::Cartridge::ExRom
@ ExRom
Definition: Cartridge.hpp:22
ComSquare::Cartridge::Header
Definition: Cartridge.hpp:25
ComSquare::Cartridge::Cartridge::getRomSize
static size_t getRomSize(const std::string &romPath)
Get the size of a rom from it's path.
Definition: Cartridge.cpp:38
ComSquare::Cartridge::Cartridge::header
Header header
The header of the cartridge.
Definition: Cartridge.hpp:89
ComSquare::Cartridge::Header::checksumComplements
uint8_t checksumComplements[2]
Definition: Cartridge.hpp:46
ComSquare::Cartridge::Header::romSize
unsigned romSize
The size (in bytes) of the ram.
Definition: Cartridge.hpp:34
ComSquare::Cartridge::Cartridge::_loadHeader
bool _loadHeader()
Set the public variable header by parsing the header in the ROM.
Definition: Cartridge.cpp:169
ComSquare::Cartridge::Header::creatorID
uint16_t creatorID
Definition: Cartridge.hpp:40
ComSquare::Cartridge::HiRom
@ HiRom
Definition: Cartridge.hpp:19
ComSquare::Cartridge::Cartridge::_mapHeader
Header _mapHeader(uint32_t headerAddress)
Parse the memory to get a readable header.
Definition: Cartridge.cpp:62
ComSquare::Cartridge::Header::checksum
uint16_t checksum
Definition: Cartridge.hpp:52
ComSquare::Cartridge::Header::version
uint8_t version
The version of the game.
Definition: Cartridge.hpp:43