mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-03 10:26:36 +00:00
Implementing the LDX
This commit is contained in:
@@ -265,6 +265,12 @@ namespace ComSquare::CPU
|
||||
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;
|
||||
|
||||
case Instructions::LDX_IM: this->LDX(this->_getImmediateAddr()); return 2 + !this->_registers.p.m;
|
||||
case Instructions::LDX_ABS: this->LDX(this->_getAbsoluteAddr()); return 4 + !this->_registers.p.m;
|
||||
case Instructions::LDX_DP: this->LDX(this->_getDirectAddr()); return 3 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
case Instructions::LDX_ABSY: this->LDX(this->_getAbsoluteIndexedByYAddr()); return 4 + !this->_registers.p.m + this->_hasIndexCrossedPageBoundary;
|
||||
case Instructions::LDX_DPY: this->LDX(this->_getDirectIndexedByYAddr()); return 4 + !this->_registers.p.m + this->_registers.dl != 0;
|
||||
|
||||
default:
|
||||
throw InvalidOpcode("CPU", opcode);
|
||||
}
|
||||
|
||||
+9
-1
@@ -247,7 +247,13 @@ namespace ComSquare::CPU
|
||||
LDA_DPYi = 0xB1,
|
||||
LDA_DPYil = 0xB7,
|
||||
LDA_SR = 0xA3,
|
||||
LDA_SRYi = 0xB3
|
||||
LDA_SRYi = 0xB3,
|
||||
|
||||
LDX_IM = 0xA2,
|
||||
LDX_ABS = 0xAE,
|
||||
LDX_DP = 0xA6,
|
||||
LDX_ABSY = 0xBE,
|
||||
LDX_DPY = 0xB6
|
||||
};
|
||||
|
||||
//! @brief The main CPU
|
||||
@@ -342,6 +348,8 @@ namespace ComSquare::CPU
|
||||
void STZ(uint24_t addr);
|
||||
//! @brief Load the accumulator from memory.
|
||||
void LDA(uint24_t addr);
|
||||
//! @brief Load the X index register from memory.
|
||||
void LDX(uint24_t addr);
|
||||
public:
|
||||
explicit CPU(std::shared_ptr<Memory::MemoryBus> bus, Cartridge::Header &cartridgeHeader);
|
||||
CPU(const CPU &) = default;
|
||||
|
||||
@@ -55,4 +55,17 @@ namespace ComSquare::CPU
|
||||
}
|
||||
this->_registers.p.z = this->_registers.a == 0x0;
|
||||
}
|
||||
|
||||
void CPU::LDX(uint24_t addr)
|
||||
{
|
||||
if (this->_registers.p.x_b) {
|
||||
this->_registers.x = this->_bus->read(addr);
|
||||
this->_registers.p.n = this->_registers.xl & 0xF0u;
|
||||
} else {
|
||||
this->_registers.xl = this->_bus->read(addr);
|
||||
this->_registers.xh = this->_bus->read(addr + 1);
|
||||
this->_registers.p.n = this->_registers.x & 0xF000u;
|
||||
}
|
||||
this->_registers.p.z = this->_registers.x == 0x0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user