mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-01 17:55:30 +00:00
Adding the LDA
This commit is contained in:
@@ -249,6 +249,22 @@ namespace ComSquare::CPU
|
||||
case Instructions::STZ_ABSX: this->STX(this->_getAbsoluteIndexedByXAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
case Instructions::STZ_DPX: this->STX(this->_getDirectIndexedByXAddr()); return 4 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
|
||||
case Instructions::LDA_IM: this->LDA(this->_getImmediateAddr()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::LDA_ABS: this->LDA(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
|
||||
case Instructions::LDA_ABSl: this->LDA(this->_getAbsoluteLongAddr()); return 5 + !this->_registers.p.m;
|
||||
case Instructions::LDA_DP: this->LDA(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
case Instructions::LDA_DPi: this->LDA(this->_getDirectIndirectAddr()); return 5 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
case Instructions::LDA_DPil: this->LDA(this->_getDirectIndirectLongAddr()); return 6 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
case Instructions::LDA_ABSX: this->LDA(this->_getAbsoluteIndexedByXAddr()); return 4 + !this->_registers.p.m + this->_hasIndexCrossedPageBoundary;
|
||||
case Instructions::LDA_ABSXl:this->LDA(this->_getAbsoluteIndexedByXLongAddr()); return 5 + !this->_registers.p.m;
|
||||
case Instructions::LDA_ABSY: this->LDA(this->_getAbsoluteIndexedByYAddr()); return 4 + !this->_registers.p.m + this->_hasIndexCrossedPageBoundary;
|
||||
case Instructions::LDA_DPX: this->LDA(this->_getDirectIndexedByXAddr()); return 4 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
case Instructions::LDA_DPXi: this->LDA(this->_getDirectIndirectIndexedXAddr()); return 6 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
case Instructions::LDA_DPYi: this->LDA(this->_getDirectIndirectIndexedYAddr()); return 5 + !this->_registers.p.m + this->_registers.dl != 0 + this->_hasIndexCrossedPageBoundary;
|
||||
case Instructions::LDA_DPYil:this->LDA(this->_getDirectIndirectIndexedYLongAddr()); return 6 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
case Instructions::LDA_SR: this->LDA(this->_getStackRelativeAddr()); return 4 + !this->_registers.p.m;
|
||||
case Instructions::LDA_SRYi: this->LDA(this->_getStackRelativeIndirectIndexedYAddr()); return 7 + !this->_registers.p.m;
|
||||
|
||||
default:
|
||||
throw InvalidOpcode("CPU", opcode);
|
||||
}
|
||||
|
||||
+19
-1
@@ -231,7 +231,23 @@ namespace ComSquare::CPU
|
||||
STZ_ABS = 0x9C,
|
||||
STZ_DP = 0x64,
|
||||
STZ_ABSX = 0x9E,
|
||||
STZ_DPX = 0x74
|
||||
STZ_DPX = 0x74,
|
||||
|
||||
LDA_IM = 0xA9,
|
||||
LDA_ABS = 0xAD,
|
||||
LDA_ABSl = 0xAF,
|
||||
LDA_DP = 0xA5,
|
||||
LDA_DPi = 0xB2,
|
||||
LDA_DPil = 0xA7,
|
||||
LDA_ABSX = 0xBD,
|
||||
LDA_ABSXl = 0xBF,
|
||||
LDA_ABSY = 0xB9,
|
||||
LDA_DPX = 0xB5,
|
||||
LDA_DPXi = 0xA1,
|
||||
LDA_DPYi = 0xB1,
|
||||
LDA_DPYil = 0xB7,
|
||||
LDA_SR = 0xA3,
|
||||
LDA_SRYi = 0xB3
|
||||
};
|
||||
|
||||
//! @brief The main CPU
|
||||
@@ -324,6 +340,8 @@ namespace ComSquare::CPU
|
||||
void STY(uint24_t addr);
|
||||
//! @brief Store zero to the memory.
|
||||
void STZ(uint24_t addr);
|
||||
//! @brief Load the accumulator from memory.
|
||||
void LDA(uint24_t addr);
|
||||
public:
|
||||
explicit CPU(std::shared_ptr<Memory::MemoryBus> bus, Cartridge::Header &cartridgeHeader);
|
||||
//! @brief This function continue to execute the Cartridge code.
|
||||
|
||||
@@ -42,4 +42,17 @@ namespace ComSquare::CPU
|
||||
if (!this->_registers.p.m)
|
||||
this->_bus->write(addr + 1, 0x00);
|
||||
}
|
||||
|
||||
void CPU::LDA(uint24_t addr)
|
||||
{
|
||||
if (this->_registers.p.m) {
|
||||
this->_registers.a = this->_bus->read(addr);
|
||||
this->_registers.p.n = this->_registers.al & 0xF0u;
|
||||
} else {
|
||||
this->_registers.al = this->_bus->read(addr);
|
||||
this->_registers.ah = this->_bus->read(addr + 1);
|
||||
this->_registers.p.n = this->_registers.a & 0xF000u;
|
||||
}
|
||||
this->_registers.p.z = this->_registers.a == 0x0;
|
||||
}
|
||||
}
|
||||
+77
-1
@@ -88,4 +88,80 @@ Test(STZ, 16bits)
|
||||
pair.second.cpu->STZ(0x0);
|
||||
auto data = pair.second.wram->_data[0] + (pair.second.wram->_data[1] << 8u);
|
||||
cr_assert_eq(data, 0x00, "The stored value should be 0x00 but it was 0x%x.", data);
|
||||
}
|
||||
}
|
||||
|
||||
Test(LDA, 8bits)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_registers.p.m = true;
|
||||
pair.second.wram->_data[0] = 0x01;
|
||||
pair.second.cpu->LDA(0x0);
|
||||
auto data = pair.second.cpu->_registers.a;
|
||||
cr_assert_eq(data, 0x01, "The stored value should be 0x01 but it was 0x%x.", data);
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag register should not be set.");
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag register should not be set.");
|
||||
}
|
||||
|
||||
Test(LDA, 8bitsNegative)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_registers.p.m = true;
|
||||
pair.second.wram->_data[0] = 0x11;
|
||||
pair.second.cpu->LDA(0x0);
|
||||
auto data = pair.second.cpu->_registers.a;
|
||||
cr_assert_eq(data, 0x11, "The stored value should be 0x11 but it was 0x%x.", data);
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag register should not be set.");
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag register should be set.");
|
||||
}
|
||||
|
||||
Test(LDA, 8bitsZero)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_registers.p.m = true;
|
||||
pair.second.wram->_data[0] = 0x00;
|
||||
pair.second.wram->_data[1] = 0x11;
|
||||
pair.second.cpu->LDA(0x0);
|
||||
auto data = pair.second.cpu->_registers.a;
|
||||
cr_assert_eq(data, 0x00, "The stored value should be 0x00 but it was 0x%x.", data);
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag register should be set.");
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag register should not be set.");
|
||||
}
|
||||
|
||||
Test(LDA, 16bits)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_registers.p.m = false;
|
||||
pair.second.wram->_data[0] = 0xAB;
|
||||
pair.second.wram->_data[1] = 001;
|
||||
pair.second.cpu->LDA(0x0);
|
||||
auto data = pair.second.cpu->_registers.a;
|
||||
cr_assert_eq(data, 0x01AB, "The stored value should be 0x01AB but it was 0x%x.", data);
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag register should not be set.");
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag register should not be set.");
|
||||
}
|
||||
|
||||
Test(LDA, 16bitsNegative)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_registers.p.m = false;
|
||||
pair.second.wram->_data[0] = 0xAB;
|
||||
pair.second.wram->_data[1] = 0x11;
|
||||
pair.second.cpu->LDA(0x0);
|
||||
auto data = pair.second.cpu->_registers.a;
|
||||
cr_assert_eq(data, 0x11AB, "The stored value should be 0x11AB but it was 0x%x.", data);
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.z, false, "The zero flag register should not be set.");
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.n, true, "The negative flag register should be set.");
|
||||
}
|
||||
|
||||
Test(LDA, 16bitsZero)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_registers.p.m = false;
|
||||
pair.second.wram->_data[0] = 0x00;
|
||||
pair.second.wram->_data[1] = 0x00;
|
||||
pair.second.cpu->LDA(0x0);
|
||||
auto data = pair.second.cpu->_registers.a;
|
||||
cr_assert_eq(data, 0x0000, "The stored value should be 0x0000 but it was 0x%x.", data);
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.z, true, "The zero flag register should be set.");
|
||||
cr_assert_eq(pair.second.cpu->_registers.p.n, false, "The negative flag register should not be set.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user