From ab71231fd81dc87baa4956df0a81568d64db50ee Mon Sep 17 00:00:00 2001 From: AnonymusRaccoon Date: Mon, 27 Jan 2020 19:02:49 +0100 Subject: [PATCH] Adding documentation --- CMakeLists.txt | 2 +- sources/Cartridge/Cartridge.hpp | 16 +++++++++++++ sources/Exceptions/InvalidAddress.hpp | 23 +++++++++++++++++++ .../Exceptions/NotImplementedException.hpp | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 sources/Exceptions/InvalidAddress.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b39e2c4..3d3a007 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,4 +36,4 @@ add_executable(ComSquare sources/PPU/Ppu.hpp sources/APU/APU.hpp sources/APU/APU.cpp -) + sources/Exceptions/InvalidAddress.hpp) diff --git a/sources/Cartridge/Cartridge.hpp b/sources/Cartridge/Cartridge.hpp index d898a5d..584e285 100644 --- a/sources/Cartridge/Cartridge.hpp +++ b/sources/Cartridge/Cartridge.hpp @@ -10,6 +10,7 @@ namespace ComSquare::Cartridge { + //! @brief Exception thrown when someone tries to load an invalid rom. class InvalidRomException : std::exception { private: std::string _msg; @@ -18,14 +19,29 @@ namespace ComSquare::Cartridge const char *what() const noexcept override { return this->_msg.c_str(); } }; + //! @brief Contains the rom's memory/instructions. class Cartridge : IMemory { private: + //! @brief The rom data (contains all the instructions). unsigned char *_data; + //! @brief The size of the rom data. size_t _size; + //! @brief Get the size of a rom from it's path. + //! @param romPath The path of the rom to get info from. + //! @return The size of the rom. static size_t getRomSize(const std::string &romPath); public: + //! @brief Load a rom from it's path. explicit Cartridge(const std::string &romPath); + //! @brief Read from the rom. + //! @param addr The address to read from. The address 0x0 should refer to the first byte of the rom's memory. + //! @throw InvalidAddress will be thrown if the address is less than 0 or more than the size of the rom's memory. + //! @return Return the data at the address. uint8_t read(uint32_t addr) override; + //! @brief Write data to the rom. + //! @param addr The address to write to. The address 0x0 should refer to the first byte of the rom's memory. + //! @param data The data to write. + //! @throw InvalidAddress will be thrown if the address is less than 0 or more than the size of the rom's memory. void write(uint32_t addr, uint8_t data) override; }; } diff --git a/sources/Exceptions/InvalidAddress.hpp b/sources/Exceptions/InvalidAddress.hpp new file mode 100644 index 0000000..b044967 --- /dev/null +++ b/sources/Exceptions/InvalidAddress.hpp @@ -0,0 +1,23 @@ +// +// Created by anonymus-raccoon on 1/27/20. +// + +#ifndef COMSQUARE_INVALIDADDRESS_HPP +#define COMSQUARE_INVALIDADDRESS_HPP + +#include +#include + +namespace ComSquare +{ + //! @brief Exception thrown when trying to read/write to an invalid address. + class InvalidAddress : std::exception { + private: + std::string _msg; + public: + explicit InvalidAddress(const std::string &msg) : _msg(msg) {} + const char *what() const noexcept override { return this->_msg.c_str(); } + }; +} + +#endif //COMSQUARE_INVALIDADDRESS_HPP diff --git a/sources/Exceptions/NotImplementedException.hpp b/sources/Exceptions/NotImplementedException.hpp index bb66385..762c655 100644 --- a/sources/Exceptions/NotImplementedException.hpp +++ b/sources/Exceptions/NotImplementedException.hpp @@ -9,6 +9,7 @@ namespace ComSquare { + //! @brief When this is thrown, it means that we should work more. class NotImplementedException : std::exception { public: explicit NotImplementedException() = default;