57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
#include "juiceboy/instructions.hpp"
|
|
|
|
#include "juiceboy/cartridge.hpp"
|
|
#include "juiceboy/processor.hpp"
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <memory>
|
|
|
|
namespace juiceboy::test {
|
|
|
|
namespace {
|
|
class TestCartridge : public Cartridge {
|
|
public:
|
|
std::uint8_t ReadByte(std::uint16_t) override { return 0x00; }
|
|
void WriteByte(std::uint16_t, std::uint16_t) override { /* empty */ }
|
|
};
|
|
|
|
class InstructionsTest : public testing::Test {
|
|
public:
|
|
Processor &GetProcessor() { return processor; }
|
|
|
|
private:
|
|
Processor processor{Memory{std::make_shared<TestCartridge>()}};
|
|
};
|
|
} // namespace
|
|
|
|
TEST_F(InstructionsTest, Noop) {
|
|
const auto cycles = instructions::Nop(GetProcessor());
|
|
|
|
EXPECT_EQ(cycles, 4);
|
|
EXPECT_EQ(GetProcessor().GetRegisters().GetProgramCounter(), 0);
|
|
}
|
|
|
|
TEST_F(InstructionsTest, LdBcD16) {
|
|
GetProcessor().GetMemory().WriteByte(0x8000, 0x34);
|
|
GetProcessor().GetMemory().WriteByte(0x8001, 0x12);
|
|
GetProcessor().GetRegisters().SetProgramCounter(0x8000);
|
|
|
|
const auto cycles = instructions::LdBcD16(GetProcessor());
|
|
|
|
EXPECT_EQ(cycles, 12);
|
|
EXPECT_EQ(GetProcessor().GetRegisters().GetBC(), 0x1234);
|
|
EXPECT_EQ(GetProcessor().GetRegisters().GetProgramCounter(), 0x8002);
|
|
}
|
|
|
|
TEST_F(InstructionsTest, LdBcA) {
|
|
GetProcessor().GetRegisters().SetBC(0x8000);
|
|
GetProcessor().GetRegisters().SetA(0x12);
|
|
|
|
const auto cycles = instructions::LdBcA(GetProcessor());
|
|
|
|
EXPECT_EQ(cycles, 8);
|
|
EXPECT_EQ(GetProcessor().GetMemory().ReadByte(0x8000), 0x12);
|
|
EXPECT_EQ(GetProcessor().GetRegisters().GetProgramCounter(), 0);
|
|
}
|
|
|
|
} // namespace juiceboy::test
|