Understanding nestest STA to $4015

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
andsve
Posts: 5
Joined: Mon Sep 03, 2018 2:41 pm

Understanding nestest STA to $4015

Post by andsve »

Hi all, long time lurker here! :) Been hacking for a while, but now I'm in dire need for some help about something I can't wrap my head around regarding nestest.log.

On line 8981 the rom does a STA, where A is 02, to $4015. My emu writes 02 to this address (which should be APU status reg?), but according to the log it looks like it should be writing FF somehow? Up until that point everything matches to my emu.

Code: Select all

...
  C689  A9 02     LDA #$02                        A:00 X:FF Y:15 P:27 SP:FB CYC: 80 SL:212
> C68B  8D 15 40  STA $4015 = FF                  A:02 X:FF Y:15 P:25 SP:FB CYC: 86 SL:212
  C68E  A9 3F     LDA #$3F                        A:02 X:FF Y:15 P:25 SP:FB CYC: 98 SL:212
...
Am I missing something fundamental about the log or the behaviour of the CPU/APU? Up until this point I have been assuming that " = XX" in the log indicates what value is being written.

Thanks for a great community and resource!
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Understanding nestest STA to $4015

Post by rainwarrior »

Are you talking about the "= FF" part? This is indicating a value at the prospective write before this instruction takes place. In the case of registers in that region, for that particular instruction I don't think it's a meaningful value in the log (maybe just a default open bus value that the emulator assigned?). For variables in RAM, though, it should indicate the last value that had been stored there. For similar reasons, some of the variables written at the beginning of the log have "meaningless" starting values too, which would on a real thing be random/unreliable.
User avatar
andsve
Posts: 5
Joined: Mon Sep 03, 2018 2:41 pm

Re: Understanding nestest STA to $4015

Post by andsve »

Aha! I was thinking along those lines, but it didn't make sense to me since $4015 should be set to 0x00 at init?
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Understanding nestest STA to $4015

Post by rainwarrior »

$4015 doesn't work like a RAM address. What you write to it doesn't really match what you'll read back from it. Its read function is a status poll.

So... I would assume whatever the emulator uses as it's inspected pre-instruction value is treating something like that as special, and $FF is just the default 'nothing connected' value there, not really indicative of anything.
User avatar
andsve
Posts: 5
Joined: Mon Sep 03, 2018 2:41 pm

Re: Understanding nestest STA to $4015

Post by andsve »

Makes sense! Thanks man for the help, really been scratching my head at this. :)
Post Reply