Implementing the CLC/CLI/CLD/CLV

This commit is contained in:
AnonymusRaccoon
2020-02-14 16:35:02 +01:00
parent ad11210771
commit 8787b09546
4 changed files with 71 additions and 1 deletions
+5
View File
@@ -301,6 +301,11 @@ namespace ComSquare::CPU
case Instructions::JSL: this->JSR(this->_getAbsoluteLongAddr()); return 8;
case Instructions::CLC: this->CLC(); return 2;
case Instructions::CLI: this->CLI(); return 2;
case Instructions::CLD: this->CLD(); return 2;
case Instructions::CLV: this->CLV(); return 2;
default:
throw InvalidOpcode("CPU", opcode);
}
+14 -1
View File
@@ -282,7 +282,12 @@ namespace ComSquare::CPU
JSR_ABS = 0x20,
JSR_ABSXi = 0xFC,
JSL = 0x22
JSL = 0x22,
CLC = 0x18,
CLI = 0x58,
CLD = 0xD8,
CLV = 0xB8
};
//! @brief The main CPU
@@ -415,6 +420,14 @@ namespace ComSquare::CPU
void PLX();
//! @brief Pull the y index register to the stack.
void PLY();
//! @brief Clear the carry flag.
void CLC();
//! @brief Clear the Interrupt Disable flag.
void CLI();
//! @brief Clear the decimal flag.
void CLD();
//! @brief Clear the overflow flag.
void CLV();
public:
explicit CPU(std::shared_ptr<Memory::MemoryBus> bus, Cartridge::Header &cartridgeHeader);
CPU(const CPU &) = default;
@@ -112,4 +112,24 @@ namespace ComSquare::CPU
this->_registers.p.z = this->_registers.y == 0;
this->_registers.p.n = this->_registers.y & 0x8000u;
}
void CPU::CLC()
{
this->_registers.p.c = false;
}
void CPU::CLI()
{
this->_registers.p.i = false;
}
void CPU::CLD()
{
this->_registers.p.d = false;
}
void CPU::CLV()
{
this->_registers.p.v = false;
}
}
+32
View File
@@ -405,4 +405,36 @@ Test(PLP, emulation)
auto data = pair.second.cpu->_registers.p.flags;
cr_assert_eq(data, 0b00110000, "The flags should be 0b00110000 but it was %x", data);
cr_assert_eq(pair.second.cpu->_registers.s, 0x1, "The Stack pointer should be equal to 0x1 but it was %x", pair.second.cpu->_registers.s);
}
Test(CLC, clear)
{
auto pair = Init();
pair.second.cpu->_registers.p.flags = 0xFF;
pair.second.cpu->CLC();
cr_assert_eq(pair.second.cpu->_registers.p.c, false, "The carry flag should not be set");
}
Test(CLI, clear)
{
auto pair = Init();
pair.second.cpu->_registers.p.flags = 0xFF;
pair.second.cpu->CLI();
cr_assert_eq(pair.second.cpu->_registers.p.i, false, "The interrupt flag should not be set");
}
Test(CLD, clear)
{
auto pair = Init();
pair.second.cpu->_registers.p.flags = 0xFF;
pair.second.cpu->CLD();
cr_assert_eq(pair.second.cpu->_registers.p.d, false, "The decimal flag should not be set");
}
Test(CLV, clear)
{
auto pair = Init();
pair.second.cpu->_registers.p.flags = 0xFF;
pair.second.cpu->CLV();
cr_assert_eq(pair.second.cpu->_registers.p.v, false, "The overflow flag should not be set");
}