mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-02 18:21:19 +00:00
Adding Idle APU instructions
This commit is contained in:
+7
-2
@@ -52,7 +52,10 @@ add_executable(unit_tests
|
|||||||
sources/CPU/Instructions/CommonInstructions.hpp
|
sources/CPU/Instructions/CommonInstructions.hpp
|
||||||
sources/Exceptions/InvalidOpcode.hpp
|
sources/Exceptions/InvalidOpcode.hpp
|
||||||
sources/CPU/Instructions/Interrupts.cpp
|
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
|
# include criterion & coverage
|
||||||
target_link_libraries(unit_tests criterion -lgcov)
|
target_link_libraries(unit_tests criterion -lgcov)
|
||||||
@@ -105,7 +108,9 @@ add_executable(ComSquare
|
|||||||
sources/CPU/Instructions/CommonInstructions.hpp
|
sources/CPU/Instructions/CommonInstructions.hpp
|
||||||
sources/Exceptions/InvalidOpcode.hpp
|
sources/Exceptions/InvalidOpcode.hpp
|
||||||
sources/CPU/Instructions/Interrupts.cpp
|
sources/CPU/Instructions/Interrupts.cpp
|
||||||
sources/CPU/Instructions/MathematicalOperations.cpp)
|
sources/CPU/Instructions/MathematicalOperations.cpp
|
||||||
|
sources/APU/Instructions/Standbys.cpp
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries(ComSquare
|
target_link_libraries(ComSquare
|
||||||
sfml-graphics
|
sfml-graphics
|
||||||
|
|||||||
+8
-1
@@ -53,6 +53,12 @@ namespace ComSquare::APU
|
|||||||
uint8_t opcode = read(this->_internalRegisters.pc++);
|
uint8_t opcode = read(this->_internalRegisters.pc++);
|
||||||
|
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
|
case 0x00:
|
||||||
|
return NOP();
|
||||||
|
case 0xEF:
|
||||||
|
return SLEEP();
|
||||||
|
case 0xFF:
|
||||||
|
return STOP();
|
||||||
default:
|
default:
|
||||||
throw InvalidOpcode("APU", opcode);
|
throw InvalidOpcode("APU", opcode);
|
||||||
}
|
}
|
||||||
@@ -62,7 +68,8 @@ namespace ComSquare::APU
|
|||||||
{
|
{
|
||||||
int cycles = 0;
|
int cycles = 0;
|
||||||
|
|
||||||
cycles += executeInstruction();
|
while (this->_state == Running)
|
||||||
|
cycles += executeInstruction();
|
||||||
return cycles;
|
return cycles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,13 @@ namespace ComSquare::APU
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum StateMode
|
||||||
|
{
|
||||||
|
Running,
|
||||||
|
Sleeping,
|
||||||
|
Stopped
|
||||||
|
};
|
||||||
|
|
||||||
class APU : public Memory::IMemory {
|
class APU : public Memory::IMemory {
|
||||||
private:
|
private:
|
||||||
//! @brief All the registers of the APU CPU
|
//! @brief All the registers of the APU CPU
|
||||||
@@ -113,9 +120,18 @@ namespace ComSquare::APU
|
|||||||
//! @brief The DSP component used to produce sound
|
//! @brief The DSP component used to produce sound
|
||||||
std::shared_ptr<DSP::DSP> _dsp;
|
std::shared_ptr<DSP::DSP> _dsp;
|
||||||
|
|
||||||
|
StateMode _state = Running;
|
||||||
|
|
||||||
//! @brief Execute a single instruction.
|
//! @brief Execute a single instruction.
|
||||||
//! @return The number of cycles that the instruction took.
|
//! @return The number of cycles that the instruction took.
|
||||||
int executeInstruction();
|
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:
|
public:
|
||||||
explicit APU();
|
explicit APU();
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user