SimpleNES icon indicating copy to clipboard operation
SimpleNES copied to clipboard

CPU::executeBranch may calculate wrong m_skipCycles

Open Froser opened this issue 2 years ago • 1 comments

According to Opcode matrix from http://www.oxyron.de/html/opcodes02.html:

"*" : add 1 cycle if page boundary is crossed. add 1 cycle on branches if taken.

From cpu.cpp line 349: if (branch) { int8_t offset = m_bus.read(r_PC++); ++m_skipCycles; auto newPC = static_cast<Address>(r_PC + offset); setPageCrossed(r_PC, newPC, 2); r_PC = newPC; }

If the branch is taken, and page is crossed, m_skipCycles will increase by 3. But according to the document, only 2 cycles should be added. Is there any mistake, or did I misunderstand the document? Thank you.

Froser avatar Sep 13 '22 10:09 Froser

Hi! I was mostly following this IIRC. There it says:

2 (+1 if branch succeeds +2 if to a new page)

I think I may have misunderstood this to mean that it adds +1 if branch succeeds and another +2 if to a new page. Another source here also seems to match what you point out. I'll run some test roms and do some more digging. Thanks for pointing out!

amhndu avatar Sep 13 '22 14:09 amhndu