nestest.nes vs nes_intr_test (sbc behavior)

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
clueless
Posts: 496
Joined: Sun Sep 07, 2008 7:27 am
Location: Seatlle, WA, USA

nestest.nes vs nes_intr_test (sbc behavior)

Post by clueless »

Hello,

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;
}
is "nestest.nes" considered accurate? Which test suite is the "gold standard" that I should use to verify my emulator?

[1] md5 = 4068f00f3db2fe783e437681fa6b419a
[2] md5 = 67c242cd4954a37f3bfe6c90e887fbd5
[3] http://nickmass.com/images/nestest.nes
[4] https://github.com/christopherpow/nes-test-roms
User avatar
clueless
Posts: 496
Joined: Sun Sep 07, 2008 7:27 am
Location: Seatlle, WA, USA

Re: nestest.nes vs nes_intr_test (sbc behavior)

Post by clueless »

I've replaced my implementation of "op_sbc(data)" with "op_adc(data ^ 0xff)" and now both test suites pass.
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: nestest.nes vs nes_intr_test (sbc behavior)

Post by koitsu »

Mainly for future readers:

ADC/SBC implementations (and code) covered here: viewtopic.php?p=19080#19080

Blargg's post is correct (very similar to yours), as is Disch's post.
Post Reply