srctree

Johan Norberg parent 7ee2b5de 21f771f6
Fix brk-instruction not setting interrupt flag

core/src/mos6502.cpp added: 14, removed: 9, total 5
@@ -108,7 +108,10 @@ Pipeline Mos6502::parse_next_instruction() {
stack_.push_byte(static_cast<uint8_t>(registers_->pc & 0xFFu));
});
result.push([this] { stack_.push_byte(registers_->p | B_FLAG); });
result.push([this] { tmp_ = mmu_->read_byte(kBrkAddress); });
result.push([this] {
tmp_ = mmu_->read_byte(kBrkAddress);
set_flag(I_FLAG);
});
result.push([this] {
const uint16_t pch = mmu_->read_byte(kBrkAddress + 1) << 8u;
registers_->pc = pch | tmp_;
 
core/test/src/test_cpu.cpp added: 14, removed: 9, total 5
@@ -117,6 +117,7 @@ TEST_F(CpuTest, brk) {
expected.pc = 0xDEAD;
 
expected.sp -= 2 + 1; // 1 word and 1 byte
expected.p |= I_FLAG;
 
// Dummy read
EXPECT_CALL(mmu, read_byte(0x1235));
 
core/test/src/test_cpuintegration.cpp added: 14, removed: 9, total 5
@@ -116,6 +116,7 @@ TEST_F(CpuIntegrationTest, simple_program) {
expected.sp =
registers.sp - static_cast<uint8_t>(3); // PC (2 bytes) + P (1 byte)
expected.pc = 0xDEAD;
expected.p = I_FLAG;
 
const int expected_cycles = 2 + 4 + 2 + 4 + 2 + 4 + 7;
 
@@ -162,7 +163,7 @@ TEST_F(CpuIntegrationTest, branch) {
expected.sp =
registers.sp - static_cast<uint8_t>(3); // PC (2 bytes) + P (1 byte)
expected.pc = 0xDEAD;
expected.p = C_FLAG | Z_FLAG;
expected.p = static_cast<uint8_t>(C_FLAG | Z_FLAG) | I_FLAG;
 
// BNE takes 3 cycles when branch is taken, two when it is not.
const int expected_cycles =
@@ -236,7 +237,7 @@ TEST_F(CpuIntegrationTest, stack) {
expected.sp =
registers.sp - static_cast<uint8_t>(3); // PC (2 bytes) + P (1 byte)
expected.pc = 0xDEAD;
expected.p = C_FLAG | Z_FLAG;
expected.p = static_cast<uint8_t>(C_FLAG | Z_FLAG) | I_FLAG;
 
const int pre_loop = 2 + 2;
const int first_loop = (2 + 5 + 3 + 2 + 2 + 2) * 16 + 15 * 3 + 2;
@@ -259,7 +260,8 @@ TEST_F(CpuIntegrationTest, stack) {
// wrote.
EXPECT_EQ(0x06, mmu.read_byte(kStackOffset + 0xFF));
EXPECT_EQ(0x18 + 2, mmu.read_byte(kStackOffset + 0xFE));
EXPECT_EQ(expected.p | B_FLAG, mmu.read_byte(kStackOffset + 0xFD));
EXPECT_EQ(static_cast<uint8_t>(C_FLAG | Z_FLAG) | B_FLAG,
mmu.read_byte(kStackOffset + 0xFD));
 
for (uint8_t i = 3; i < 0x10; ++i) {
EXPECT_EQ(i, mmu.read_byte(kStackOffset + 0xFF - i));
 
romtest/test_rom.py added: 14, removed: 9, total 5
@@ -171,7 +171,6 @@ TESTS = [
rom="instr_test-v5/rom_singles/15-brk.nes",
pass_pattern="Passed",
cycles=10000000,
failing=True,
),
Test(
rom="instr_test-v5/rom_singles/16-special.nes",