Failing to Understand Expected ADC Behavior in Nestest ROM

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Oddant1
Posts: 2
Joined: Fri Jun 05, 2020 3:11 pm

Failing to Understand Expected ADC Behavior in Nestest ROM

Post by Oddant1 » Wed Jun 24, 2020 3:12 pm

Hello all, I've started working on an NES emulator just to keep busy and to push my programming abilities. My CPU is coming along, and I've been testing it using the big nestest rom (http://nickmass.com/images/nestest.nes).

I'm comparing my results to the provided log from Nintendulator (http://www.qmtpro.com/~nes/misc/nestest.log). There's a portion of the ROM at PC = 0xC936 where Nintendulator adds 0x69 to 0x01 and gets 0x6B not 0x6A as I would expect. My emulator is getting 0x6A and failing the test when the CMP at PC = 0xC93C sets the N bit not the Z bit. Can someone explain to me why we want to get 0x6B here? I feel like I must be missing something. Below is the relevant portion of the log from Nintendulator.

Code: Select all

C934  A9 01     LDA #$01                        A:69 X:00 Y:00 P:ED SP:FB PPU:289,  4 CYC:558
C936  69 69     ADC #$69                        A:01 X:00 Y:00 P:6D SP:FB PPU:295,  4 CYC:560
C938  30 0B     BMI $C945                       A:6B X:00 Y:00 P:2C SP:FB PPU:301,  4 CYC:562
C93A  B0 09     BCS $C945                       A:6B X:00 Y:00 P:2C SP:FB PPU:307,  4 CYC:564
C93C  C9 6B     CMP #$6B                        A:6B X:00 Y:00 P:2C SP:FB PPU:313,  4 CYC:566
Thank you.

lidnariq
Posts: 9779
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Failing to Understand Expected ADC Behavior in Nestest ROM

Post by lidnariq » Wed Jun 24, 2020 3:24 pm

ADC is Add with carry, not just add. A+M+C.

Oddant1
Posts: 2
Joined: Fri Jun 05, 2020 3:11 pm

Re: Failing to Understand Expected ADC Behavior in Nestest ROM

Post by Oddant1 » Wed Jun 24, 2020 3:26 pm

lidnariq wrote:
Wed Jun 24, 2020 3:24 pm
ADC is Add with carry, not just add. A+M+C.
I KNEW I WAS MISSING SOMETHING DUMB. Thank you. For some reason I was thinking ADC just set the carry, I didn't understand that it also added the carry if it was already set.

Post Reply