diff --git a/sources/APU/APU.cpp b/sources/APU/APU.cpp index cdf06f4..be4d9a6 100644 --- a/sources/APU/APU.cpp +++ b/sources/APU/APU.cpp @@ -5,6 +5,7 @@ #include "APU.hpp" #include "../Exceptions/NotImplementedException.hpp" #include "../Exceptions/InvalidAddress.hpp" +#include "../Exceptions/InvalidOpcode.hpp" namespace ComSquare::APU { @@ -47,8 +48,21 @@ namespace ComSquare::APU } } - bool APU::update() + int APU::executeInstruction() { - throw NotImplementedException(); + uint8_t opcode = read(this->_internalRegisters.pc++); + + switch (opcode) { + default: + throw InvalidOpcode("APU", opcode); + } + } + + int APU::update() + { + int cycles = 0; + + cycles += executeInstruction(); + return cycles; } } diff --git a/sources/APU/APU.hpp b/sources/APU/APU.hpp index 6c67a8f..f700508 100644 --- a/sources/APU/APU.hpp +++ b/sources/APU/APU.hpp @@ -112,6 +112,10 @@ namespace ComSquare::APU //! @brief The DSP component used to produce sound std::shared_ptr _dsp; + + //! @brief Execute a single instruction. + //! @return The number of cycles that the instruction took. + int executeInstruction(); public: explicit APU(); @@ -125,7 +129,9 @@ namespace ComSquare::APU //! @param data The new value of the register. //! @throw InvalidAddress will be thrown if the address is more than $FF (the number of register). void write(uint24_t addr, uint8_t data) override; - bool update(); + //! @brief This function execute the instructions received. + //! @return The number of cycles that elapsed. + int update(); }; }