mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-05 10:59:38 +00:00
Starting to parse the Rom's header
This commit is contained in:
@@ -75,4 +75,5 @@ add_executable(ComSquare
|
|||||||
sources/Memory/IRectangleMemory.hpp
|
sources/Memory/IRectangleMemory.hpp
|
||||||
sources/DSP/DSP.cpp
|
sources/DSP/DSP.cpp
|
||||||
sources/DSP/DSP.hpp
|
sources/DSP/DSP.hpp
|
||||||
|
sources/Exceptions/InvalidAcction.hpp
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "Cartridge.hpp"
|
#include "Cartridge.hpp"
|
||||||
#include "../Exceptions/InvalidAddress.hpp"
|
#include "../Exceptions/InvalidAddress.hpp"
|
||||||
#include "../Exceptions/InvalidRom.hpp"
|
#include "../Exceptions/InvalidRom.hpp"
|
||||||
|
#include "../Exceptions/InvalidAcction.hpp"
|
||||||
|
|
||||||
namespace ComSquare::Cartridge
|
namespace ComSquare::Cartridge
|
||||||
{
|
{
|
||||||
@@ -20,9 +21,10 @@ namespace ComSquare::Cartridge
|
|||||||
if (!rom)
|
if (!rom)
|
||||||
throw InvalidRomException("Could not open the rom file at " + romPath + ". " + strerror(errno));
|
throw InvalidRomException("Could not open the rom file at " + romPath + ". " + strerror(errno));
|
||||||
this->_size = size;
|
this->_size = size;
|
||||||
this->_data = new unsigned char[size];
|
this->_data = new uint8_t[size];
|
||||||
std::memset(this->_data, 0, size);
|
std::memset(this->_data, 0, size);
|
||||||
fread(this->_data, 1, size, rom);
|
fread(this->_data, 1, size, rom);
|
||||||
|
this->_loadHeader();
|
||||||
} catch (InvalidRomException &ex) {
|
} catch (InvalidRomException &ex) {
|
||||||
std::cerr << "Invalid Rom Error: " << ex.what() << std::endl;
|
std::cerr << "Invalid Rom Error: " << ex.what() << std::endl;
|
||||||
}
|
}
|
||||||
@@ -52,8 +54,28 @@ namespace ComSquare::Cartridge
|
|||||||
|
|
||||||
void Cartridge::write_internal(uint24_t addr, uint8_t data)
|
void Cartridge::write_internal(uint24_t addr, uint8_t data)
|
||||||
{
|
{
|
||||||
if (addr >= this->_size)
|
(void)addr;
|
||||||
throw InvalidAddress("Cartridge write", addr);
|
(void)data;
|
||||||
this->_data[addr] = data;
|
throw InvalidAcction("Witting to the ROM is not allowed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Cartridge::_getHeaderAddress()
|
||||||
|
{
|
||||||
|
return 0x81c0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Cartridge::_loadHeader()
|
||||||
|
{
|
||||||
|
unsigned headerAddress = this->_getHeaderAddress();
|
||||||
|
|
||||||
|
char name[22];
|
||||||
|
std::memcpy(name, &this->_data[headerAddress], 21);
|
||||||
|
name[21] = '\0';
|
||||||
|
this->header.gameName = std::string(name);
|
||||||
|
ADDMAPPINGMODE(this->_data[headerAddress + 21] & 0x10u ? FastRom : SlowRom);
|
||||||
|
ADDMAPPINGMODE(this->_data[headerAddress + 21] & 0x1u ? HiRom : LoRom);
|
||||||
|
if (this->_data[headerAddress + 21] & 0x2u || this->_data[headerAddress + 210] & 0x4u)
|
||||||
|
ADDMAPPINGMODE(ExRom);
|
||||||
|
return headerAddress & 0x200u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,14 +12,13 @@
|
|||||||
|
|
||||||
namespace ComSquare::Cartridge
|
namespace ComSquare::Cartridge
|
||||||
{
|
{
|
||||||
|
#define ADDMAPPINGMODE(flag) (this->header.mappingMode = static_cast<MappingMode>(this->header.mappingMode | (flag)))
|
||||||
enum MappingMode {
|
enum MappingMode {
|
||||||
LowRom,
|
LoRom = 1u << 0u,
|
||||||
HiRom,
|
HiRom = 1u << 1u,
|
||||||
ExLowRom,
|
SlowRom = 1u << 2u,
|
||||||
EwHiRom,
|
FastRom = 1u << 3u,
|
||||||
SA1Rom, // unimplemented
|
ExRom = 1u << 4u,
|
||||||
FastLoRom,
|
|
||||||
FastHiRom
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Header
|
struct Header
|
||||||
@@ -56,6 +55,12 @@ namespace ComSquare::Cartridge
|
|||||||
//! @param romPath The path of the rom to get info from.
|
//! @param romPath The path of the rom to get info from.
|
||||||
//! @return The size of the rom.
|
//! @return The size of the rom.
|
||||||
static size_t getRomSize(const std::string &romPath);
|
static size_t getRomSize(const std::string &romPath);
|
||||||
|
//! @brief Set the public variable header by parsing the header in the ROM.
|
||||||
|
//! @return True if this cartridge has a SCM header, false otherwise.
|
||||||
|
bool _loadHeader();
|
||||||
|
//! @brief Get the address of the header.
|
||||||
|
//! @return The address of this cartridge header.
|
||||||
|
uint32_t _getHeaderAddress();
|
||||||
public:
|
public:
|
||||||
//! @brief Load a rom from it's path.
|
//! @brief Load a rom from it's path.
|
||||||
explicit Cartridge(const std::string &romPath);
|
explicit Cartridge(const std::string &romPath);
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
//
|
||||||
|
// Created by anonymus-raccoon on 1/30/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef COMSQUARE_INVALIDACCTION_HPP
|
||||||
|
#define COMSQUARE_INVALIDACCTION_HPP
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace ComSquare
|
||||||
|
{
|
||||||
|
//! @brief Exception thrown when someone tries to load an invalid rom.
|
||||||
|
class InvalidAcction : std::exception {
|
||||||
|
private:
|
||||||
|
std::string _msg;
|
||||||
|
public:
|
||||||
|
explicit InvalidAcction(const std::string &msg) : _msg(msg) {}
|
||||||
|
const char *what() const noexcept override { return this->_msg.c_str(); }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif //COMSQUARE_INVALIDACCTION_HPP
|
||||||
Reference in New Issue
Block a user