mirror of
https://github.com/zoriya/ComSquare.git
synced 2025-12-20 06:05:11 +00:00
Starting the jump
This commit is contained in:
@@ -370,6 +370,13 @@ namespace ComSquare::CPU
|
|||||||
case Instructions::BRA: this->BRA(this->_registers.pc++); return 3 + this->_isEmulationMode;
|
case Instructions::BRA: this->BRA(this->_registers.pc++); return 3 + this->_isEmulationMode;
|
||||||
case Instructions::BRL: this->BRL(this->_registers.pc); this->_registers.pc += 2; return 4;
|
case Instructions::BRL: this->BRL(this->_registers.pc); this->_registers.pc += 2; return 4;
|
||||||
|
|
||||||
|
case Instructions::JMP_ABS: this->JMP(this->_getAbsoluteAddr()); return 3;
|
||||||
|
case Instructions::JMP_ABSi: this->JMP(this->_getAbsoluteIndirectAddr()); return 3;
|
||||||
|
case Instructions::JMP_ABSXi: this->JMP(this->_getAbsoluteIndexedByXAddr()); return 3;
|
||||||
|
|
||||||
|
case Instructions::JML_ABSl: this->JML(this->_getAbsoluteLongAddr()); return 3;
|
||||||
|
//case Instructions::JML_ABSil: this->JML(this->_getAbsoluteLong()); return 3;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw InvalidOpcode("CPU", opcode);
|
throw InvalidOpcode("CPU", opcode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -352,7 +352,14 @@ namespace ComSquare::CPU
|
|||||||
BVC = 0x50,
|
BVC = 0x50,
|
||||||
BVS = 0x70,
|
BVS = 0x70,
|
||||||
BRA = 0x80,
|
BRA = 0x80,
|
||||||
BRL = 0x82
|
BRL = 0x82,
|
||||||
|
|
||||||
|
JMP_ABS = 0x4C,
|
||||||
|
JMP_ABSi = 0x6C,
|
||||||
|
JMP_ABSXi = 0x7C,
|
||||||
|
|
||||||
|
JML_ABSl = 0x5C,
|
||||||
|
JML_ABSil = 0xDC
|
||||||
};
|
};
|
||||||
|
|
||||||
//! @brief The main CPU
|
//! @brief The main CPU
|
||||||
@@ -540,6 +547,10 @@ namespace ComSquare::CPU
|
|||||||
bool BRA(uint24_t valueAddr);
|
bool BRA(uint24_t valueAddr);
|
||||||
//! @brief Branch always long
|
//! @brief Branch always long
|
||||||
bool BRL(uint24_t valueAddr);
|
bool BRL(uint24_t valueAddr);
|
||||||
|
//! @brief Jump.
|
||||||
|
void JMP(uint24_t valueAddr);
|
||||||
|
//! @brief Long jump.
|
||||||
|
void JML(uint24_t valueAddr);
|
||||||
public:
|
public:
|
||||||
explicit CPU(std::shared_ptr<Memory::MemoryBus> bus, Cartridge::Header &cartridgeHeader);
|
explicit CPU(std::shared_ptr<Memory::MemoryBus> bus, Cartridge::Header &cartridgeHeader);
|
||||||
CPU(const CPU &) = default;
|
CPU(const CPU &) = default;
|
||||||
|
|||||||
@@ -297,4 +297,21 @@ namespace ComSquare::CPU
|
|||||||
this->_registers.pac += static_cast<int8_t>(this->_bus->read(valueAddr));
|
this->_registers.pac += static_cast<int8_t>(this->_bus->read(valueAddr));
|
||||||
return this->_registers.p.v;
|
return this->_registers.p.v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CPU::JMP(uint24_t valueAddr)
|
||||||
|
{
|
||||||
|
unsigned value = this->_bus->read(valueAddr);
|
||||||
|
value += this->_bus->read(valueAddr + 1) << 8u;
|
||||||
|
|
||||||
|
this->_registers.pc = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPU::JML(uint24_t valueAddr)
|
||||||
|
{
|
||||||
|
unsigned value = this->_bus->read(valueAddr);
|
||||||
|
value += this->_bus->read(valueAddr + 1) << 8u;
|
||||||
|
value += this->_bus->read(valueAddr + 2) << 16u;
|
||||||
|
|
||||||
|
this->_registers.pac = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -366,6 +366,13 @@ namespace ComSquare::Debugger
|
|||||||
case Instructions::BRA: return "BRA " + this->_getImmediateValue8Bits(pc);
|
case Instructions::BRA: return "BRA " + this->_getImmediateValue8Bits(pc);
|
||||||
case Instructions::BRL: return "BRL " + this->_getImmediateValue16Bits(pc);
|
case Instructions::BRL: return "BRL " + this->_getImmediateValue16Bits(pc);
|
||||||
|
|
||||||
|
case Instructions::JMP_ABS: return "JMP " + this->_getAbsoluteValue(pc);
|
||||||
|
case Instructions::JMP_ABSi: return "JMP "; //+ this->_getAbsoluteIndire(pc);
|
||||||
|
case Instructions::JMP_ABSXi: return "JMP "; //+ this->_getAbsoluteValue(pc);
|
||||||
|
|
||||||
|
case Instructions::JML_ABSl: return "JML";
|
||||||
|
case Instructions::JML_ABSil: return "JML";
|
||||||
|
|
||||||
default: return "Unknown";
|
default: return "Unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -206,11 +206,6 @@ namespace ComSquare::PPU
|
|||||||
void PPU::update(unsigned cycles)
|
void PPU::update(unsigned cycles)
|
||||||
{
|
{
|
||||||
(void)cycles;
|
(void)cycles;
|
||||||
this->_bus->write(0x2121, 0);
|
|
||||||
for (uint16_t value = 0; value <= 256; value++) {
|
|
||||||
this->_bus->write(0x2122, 0b11100000);
|
|
||||||
this->_bus->write(0x2122, 0b00000011);
|
|
||||||
}
|
|
||||||
uint16_t tmp;
|
uint16_t tmp;
|
||||||
uint8_t red;
|
uint8_t red;
|
||||||
uint8_t green;
|
uint8_t green;
|
||||||
|
|||||||
@@ -883,4 +883,25 @@ Test(BVS, noJump)
|
|||||||
pair.second.wram->_data[0] = 0x90;
|
pair.second.wram->_data[0] = 0x90;
|
||||||
pair.second.cpu->BVS(0x0);
|
pair.second.cpu->BVS(0x0);
|
||||||
cr_assert_eq(pair.second.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", pair.second.cpu->_registers.pc);
|
cr_assert_eq(pair.second.cpu->_registers.pc, 0x80, "The program counter should be equal to 0x80 but it was 0x%x.", pair.second.cpu->_registers.pc);
|
||||||
|
}
|
||||||
|
|
||||||
|
Test(JMP, simpleJump)
|
||||||
|
{
|
||||||
|
auto pair = Init();
|
||||||
|
pair.second.cpu->_registers.pc = 0x8000;
|
||||||
|
pair.second.wram->_data[0] = 0x00;
|
||||||
|
pair.second.wram->_data[1] = 0x10;
|
||||||
|
pair.second.cpu->JMP(0x0);
|
||||||
|
cr_assert_eq(pair.second.cpu->_registers.pc, 0x1000, "The program counter should be equal to 0x9000 but it was 0x%x.", pair.second.cpu->_registers.pc);
|
||||||
|
}
|
||||||
|
|
||||||
|
Test(JML, simpleJump)
|
||||||
|
{
|
||||||
|
auto pair = Init();
|
||||||
|
pair.second.cpu->_registers.pc = 0x8000;
|
||||||
|
pair.second.wram->_data[0] = 0x00;
|
||||||
|
pair.second.wram->_data[1] = 0xAB;
|
||||||
|
pair.second.wram->_data[2] = 0x10;
|
||||||
|
pair.second.cpu->JML(0x0);
|
||||||
|
cr_assert_eq(pair.second.cpu->_registers.pac, 0x10AB00, "The program counter should be equal to 0x10AB00 but it was 0x%x.", pair.second.cpu->_registers.pac);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user