Fixing the BRK/COP

This commit is contained in:
Anonymus Raccoon
2020-04-03 22:23:54 +02:00
parent 4ac1169dc2
commit 1feab12fec
4 changed files with 11 additions and 15 deletions
+2 -2
View File
@@ -384,9 +384,9 @@ namespace ComSquare::CPU
//! @brief All the instructions of the CPU.
//! @info Instructions are indexed by their opcode
Instruction _instructions[0x100] = {
{&CPU::BRK, 7, "brk", AddressingMode::Implied, 2}, // 00
{&CPU::BRK, 7, "brk", AddressingMode::Immediate8bits, 2}, // 00
{&CPU::ORA, 6, "ora", AddressingMode::DirectPageIndirectIndexedByX, 2}, // 01
{&CPU::COP, 7, "cop", AddressingMode::Implied, 2}, // 02
{&CPU::COP, 7, "cop", AddressingMode::Immediate8bits, 2}, // 02
{&CPU::ORA, 4, "ora", AddressingMode::StackRelative, 2}, // 03
{&CPU::BRK, 7, "tsb #-#", AddressingMode::Implied, 2}, // 04
{&CPU::ORA, 3, "ora", AddressingMode::DirectPage, 2}, // 05
+2 -6
View File
@@ -24,16 +24,14 @@ namespace ComSquare::CPU
int CPU::BRK(uint24_t, AddressingMode)
{
if (this->_isEmulationMode) {
this->_registers.pc += 2;
this->_push(this->_registers.pc);
this->_registers.p.x_b = true;
this->_push(this->_registers.p.flags);
this->_registers.p.i = true;
this->_registers.p.d = false;
this->_registers.pbr = 0x0;
this->_registers.pc = this->_cartridgeHeader.emulationInterrupts.brk;
} else {
this->_push(this->_registers.pbr);
this->_registers.pc += 2;
this->_push(this->_registers.pc);
this->_push(this->_registers.p.flags);
this->_registers.p.i = true;
@@ -47,16 +45,14 @@ namespace ComSquare::CPU
int CPU::COP(uint24_t, AddressingMode)
{
if (this->_isEmulationMode) {
this->_registers.pc += 2;
this->_push(this->_registers.pc);
this->_push(this->_registers.p.flags);
this->_registers.p.i = true;
this->_registers.p.d = false;
this->_registers.pbr = 0x0;
this->_registers.pc = this->_cartridgeHeader.emulationInterrupts.cop;
} else {
this->_push(this->_registers.pbr);
this->_registers.pc += 2;
this->_push(this->_registers.pc);
this->_push(this->_registers.p.flags);
this->_registers.p.i = true;
+1 -1
View File
@@ -234,7 +234,7 @@ namespace ComSquare::Debugger
DisassemblyContext CPUDebug::_getDisassemblyContext()
{
return {this->_registers.p.m, this->_registers.p.x_b, false};
return {this->_registers.p.m, this->_registers.p.x_b, this->_isEmulationMode};
}
int CPUDebug::RESB()
+6 -6
View File
@@ -20,14 +20,14 @@ Test(CPU_emulated, BRK)
snes.cpu->_registers.pbr = 0x15;
snes.cpu->BRK(0x0, ComSquare::CPU::AddressingMode::Implied);
cr_assert_eq(snes.cpu->_registers.pc, 0x123u, "The program counter should be 0x123u but it was 0x%X", snes.cpu->_registers.pc);
cr_assert_eq(snes.cpu->_registers.pbr, 0x15, "The PBR should be 0x15 but it was 0x%X", snes.cpu->_registers.pbr);
cr_assert_eq(snes.cpu->_registers.pbr, 0x0, "The PBR should be 0x0 but it was 0x%X", snes.cpu->_registers.pbr);
cr_assert_eq(snes.cpu->_registers.p.d, false, "The decimal flag should not be set.");
cr_assert_eq(snes.cpu->_registers.p.i, true, "The Interrupt disable flag should be set.");
cr_assert_eq(snes.cpu->_registers.p.x_b, true, "The break flag should be set.");
int data = snes.cpu->_pop();
cr_assert_eq(data, 0xF1, "The Status Registers should be pushed into the stack with the value 0xF1 but it was 0x%X (expected 0xF1).", data);
data = snes.cpu->_pop16();
cr_assert_eq(data, 0x158u, "The program counter should be incremented by two and pushed on the stack but it was 0x%X (expected 0x158).", data);
cr_assert_eq(data, 0x156u, "The program counter should be incremented by two and pushed on the stack but it was 0x%X (expected 0x158).", data);
}
Test(CPU_native, BRK)
@@ -46,7 +46,7 @@ Test(CPU_native, BRK)
int data = snes.cpu->_pop();
cr_assert_eq(data, 0xF1, "The Status Registers should be pushed into the stack with the value 0xF1 but it was 0x%X (expected 0xF1).", data);
data = snes.cpu->_pop16();
cr_assert_eq(data, 0x158u, "The program counter should be incremented by two and pushed on the stack but it was 0x%X (expected 0x158).", data);
cr_assert_eq(data, 0x156u, "The program counter should be incremented by two and pushed on the stack but it was 0x%X (expected 0x156).", data);
data = snes.cpu->_pop();
cr_assert_eq(data, 0x15, "The program bank register should be pushed on the stack but it was 0x%X (expected 0x15).", data);
}
@@ -61,14 +61,14 @@ Test(CPU_emulated, COP)
snes.cpu->_registers.pbr = 0x15;
snes.cpu->COP(0x0, ComSquare::CPU::AddressingMode::Implied);
cr_assert_eq(snes.cpu->_registers.pc, 0x123u, "The program counter should be 0x123u but it was 0x%X", snes.cpu->_registers.pc);
cr_assert_eq(snes.cpu->_registers.pbr, 0x15, "The PBR should be 0x15 but it was 0x%X", snes.cpu->_registers.pbr);
cr_assert_eq(snes.cpu->_registers.pbr, 0x0, "The PBR should be 0x0 but it was 0x%X", snes.cpu->_registers.pbr);
cr_assert_eq(snes.cpu->_registers.p.d, false, "The decimal flag should not be set.");
cr_assert_eq(snes.cpu->_registers.p.i, true, "The Interrupt disable flag should be set.");
cr_assert_eq(snes.cpu->_registers.p.x_b, false, "The break flag should not be set.");
int data = snes.cpu->_pop();
cr_assert_eq(data, 0x0F, "The Status Registers should be pushed into the stack with the value 0x0F but it was 0x%X (expected 0xF1).", data);
data = snes.cpu->_pop16();
cr_assert_eq(data, 0x158u, "The program counter should be incremented by two and pushed on the stack but it was 0x%X (expected 0x158).", data);
cr_assert_eq(data, 0x156u, "The program counter should be incremented by two and pushed on the stack but it was 0x%X (expected 0x158).", data);
}
Test(CPU_native, COP)
@@ -87,7 +87,7 @@ Test(CPU_native, COP)
int data = snes.cpu->_pop();
cr_assert_eq(data, 0xF1, "The Status Registers should be pushed into the stack with the value 0xF1 but it was 0x%X (expected 0xF1).", data);
data = snes.cpu->_pop16();
cr_assert_eq(data, 0x158u, "The program counter should be incremented by two and pushed on the stack but it was 0x%X (expected 0x158).", data);
cr_assert_eq(data, 0x156u, "The program counter should be incremented by two and pushed on the stack but it was 0x%X (expected 0x156).", data);
data = snes.cpu->_pop();
cr_assert_eq(data, 0x15, "The program bank register should be pushed on the stack but it was 0x%X (expected 0x15).", data);
}