My 6502 CPU core 100% passes all of the CPU opcode test from kevtris' nestest.nes [1], but fails all sbc opcode tests (and others) in blargg's nes_instr_test (nes_instr_test/rom_singles/03-zero_page.nes) [2]. Both test suites pass on FCEUX (v2.2.3 under wine on Linux).
I obtained nestest.nes from [3] on 2017-08-22, and the nes_instr_test roms from cpow's github [4] recently.
This is my SBC implementation:
Code: Select all
void Cpu::op_sbc(uint8_t data)
{
uint16_t t = m_regs.a - data - !m_regs.flag_c;
m_regs.flag_c = !(t & 0x100);
m_regs.flag_v = (m_regs.a ^ t) & (~data ^ t) & 0x80;
m_regs.flag_z = !t;
m_regs.flag_n = t & 0x80;
m_regs.a = t;
}
[1] md5 = 4068f00f3db2fe783e437681fa6b419a
[2] md5 = 67c242cd4954a37f3bfe6c90e887fbd5
[3] http://nickmass.com/images/nestest.nes
[4] https://github.com/christopherpow/nes-test-roms