Nestest.nes wierd-stuff(?)

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
oRBIT2002
Posts: 634
Joined: Sun Mar 19, 2006 3:06 am
Location: Gothenburg/Sweden

Nestest.nes wierd-stuff(?)

Post by oRBIT2002 » Sun Mar 26, 2006 10:45 am

I've been using nestest.nes quite frequently and discovered that my emulator behaved wierd when using the (indirect),y test.
I traced the code and found the problem, nestest actually jumps to a wierd address that causes my emulator to go crazy, look at the code below:
It's the JMP that causes the problem, but as you can see, $300 is written too twice (see below) and "corrupts" the address that is being jumped to.
Anyone knows why nestest does this? I've removed some "uninteresting" parts of the code that wasn't affecting the JMP....


0000DB7E: A9 00 lda #$00
0000DB80: 8D FF 02 sta $02FF
0000DB83: A9 01 lda #$01
0000DB85: 8D 00 03 sta $0300

----

0000DB9C: A9 A9 lda #$A9
0000DB9E: 8D 00 03 sta $0300
---
0000DBAB: 20 B5 DB jsr $DBB5
--
0000DBB4: 60 rts
--
0000DBB5: 6C FF 02 jmp ($02FF)
---

tepples
Posts: 22281
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Nestest.nes wierd-stuff(?)

Post by tepples » Sun Mar 26, 2006 10:56 am

oRBIT2002 wrote:but as you can see, $300 is written too twice (see below) and "corrupts" the address that is being jumped to.
[snip]
0000DBB5: 6C FF 02 jmp ($02FF)
---
On a 6502 (not a 65C02 or 65C816), the instruction JMP ($02FF) has absolutely nothing to do with address $0300. It reads from $02FF and $0200.

User avatar
oRBIT2002
Posts: 634
Joined: Sun Mar 19, 2006 3:06 am
Location: Gothenburg/Sweden

Post by oRBIT2002 » Sun Mar 26, 2006 11:33 am

Oh! So the jump "wraps" to $200 instead of $300. This was something new to me, thanks. :)

dxprog
Posts: 34
Joined: Thu Nov 17, 2005 2:44 pm

Post by dxprog » Sun Mar 26, 2006 2:35 pm

On the page barrier (xxFF) the least significant byte is ignored.

mozz
Posts: 94
Joined: Mon Mar 06, 2006 3:42 pm
Location: Montreal, canada

Re: Nestest.nes wierd-stuff(?)

Post by mozz » Sun Mar 26, 2006 3:45 pm

tepples wrote:On a 6502 (not a 65C02 or 65C816), the instruction JMP ($02FF) has absolutely nothing to do with address $0300. It reads from $02FF and $0200.
As you say, this "jmp $xxFF bug" exists on older NMOS 6502 (such as the NES cpu) but not newer CMOS 65C02, and the bug is also fixed in the 65C816 (which the SNES cpu core is based on). A while ago someone (anomie?) verified that the bug is definitely fixed on an SNES (even in emulation mode it would read $02FF and $0300).

"Table 8-1: Caveats" in the 65C816 datasheet (http://www.westerndesigncenter.com/wdc/ ... 5c816s.pdf) has this to say:
Compatibility issue: B. Jump Indirect Operand=XXFF
NMOS 6502: 5 cycles and invalid page crossing
W65C02/W65C02S: 6 cycles
W65C816S: 5 cycles

So it is consistent with the "invalid page crossing" occuring only on the original NMOS 6502.

Post Reply