Adding Idle APU instructions

This commit is contained in:
Melefo
2020-02-11 13:23:57 +01:00
parent b8a2da54a5
commit 6d7d0edf5e
5 changed files with 101 additions and 3 deletions
+7 -2
View File
@@ -52,7 +52,10 @@ add_executable(unit_tests
sources/CPU/Instructions/CommonInstructions.hpp
sources/Exceptions/InvalidOpcode.hpp
sources/CPU/Instructions/Interrupts.cpp
sources/CPU/Instructions/MathematicalOperations.cpp)
sources/CPU/Instructions/MathematicalOperations.cpp
sources/APU/Instructions/Standbys.cpp
tests/APU/testAPUInstructions.cpp
)
# include criterion & coverage
target_link_libraries(unit_tests criterion -lgcov)
@@ -105,7 +108,9 @@ add_executable(ComSquare
sources/CPU/Instructions/CommonInstructions.hpp
sources/Exceptions/InvalidOpcode.hpp
sources/CPU/Instructions/Interrupts.cpp
sources/CPU/Instructions/MathematicalOperations.cpp)
sources/CPU/Instructions/MathematicalOperations.cpp
sources/APU/Instructions/Standbys.cpp
)
target_link_libraries(ComSquare
sfml-graphics
+8 -1
View File
@@ -53,6 +53,12 @@ namespace ComSquare::APU
uint8_t opcode = read(this->_internalRegisters.pc++);
switch (opcode) {
case 0x00:
return NOP();
case 0xEF:
return SLEEP();
case 0xFF:
return STOP();
default:
throw InvalidOpcode("APU", opcode);
}
@@ -62,7 +68,8 @@ namespace ComSquare::APU
{
int cycles = 0;
cycles += executeInstruction();
while (this->_state == Running)
cycles += executeInstruction();
return cycles;
}
}
+16
View File
@@ -103,6 +103,13 @@ namespace ComSquare::APU
};
enum StateMode
{
Running,
Sleeping,
Stopped
};
class APU : public Memory::IMemory {
private:
//! @brief All the registers of the APU CPU
@@ -113,9 +120,18 @@ namespace ComSquare::APU
//! @brief The DSP component used to produce sound
std::shared_ptr<DSP::DSP> _dsp;
StateMode _state = Running;
//! @brief Execute a single instruction.
//! @return The number of cycles that the instruction took.
int executeInstruction();
//! @brief No Operation instruction, do nothing than delay
int NOP();
//! @brief Sleep instruction, halts the processor with SLEEP mode
int SLEEP();
//! @brief Stop instruction, halts the processor with STOP mode
int STOP();
public:
explicit APU();
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Melefo on 11/02/2020.
//
#include "../APU.hpp"
namespace ComSquare::APU
{
int APU::NOP()
{
return 2;
}
int APU::SLEEP()
{
this->_state = Sleeping;
return 3;
}
int APU::STOP()
{
this->_state = Stopped;
return 3;
}
}
+45
View File
@@ -0,0 +1,45 @@
//
// Created by Melefo on 11/02/2020.
//
#include <criterion/criterion.h>
#include "../tests.hpp"
#include "../../sources/SNES.hpp"
#include "../../sources/APU/APU.hpp"
using namespace ComSquare;
////////////////////
// //
// Standbys tests //
// //
////////////////////
Test(Standbys, NOP)
{
auto apu = Init().second.apu;
int result = 0;
result = apu->NOP();
cr_assert_eq(result, 2);
}
Test(Standbys, SLEEP)
{
auto apu = Init().second.apu;
int result = 0;
result = apu->SLEEP();
cr_assert_eq(result, 3);
cr_assert_eq(apu->_state, APU::Sleeping);
}
Test(Standbys, STOP)
{
auto apu = Init().second.apu;
int result = 0;
result = apu->STOP();
cr_assert_eq(result, 3);
cr_assert_eq(apu->_state, APU::Stopped);
}