Page 1 of 1

Understanding nestest STA to $4015

Posted: Mon Sep 03, 2018 3:22 pm
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!

Re: Understanding nestest STA to $4015

Posted: Mon Sep 03, 2018 3:34 pm
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.

Re: Understanding nestest STA to $4015

Posted: Mon Sep 03, 2018 3:40 pm
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?

Re: Understanding nestest STA to $4015

Posted: Mon Sep 03, 2018 3:46 pm
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.

Re: Understanding nestest STA to $4015

Posted: Mon Sep 03, 2018 3:50 pm
by andsve
Makes sense! Thanks man for the help, really been scratching my head at this. :)