Does the Indirect JMP instruction wrap around?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
timl132
Posts: 35
Joined: Tue Jul 23, 2019 10:41 am

Does the Indirect JMP instruction wrap around?

Post by timl132 » Sun Jul 28, 2019 7:33 am

Hello,

I have a bug in my CPU where JMP Indirect reads the wrong address. I used the Nintendulator debugger to find out what it's supposed to be, and I think that the Indirect JMP instruction needs to wrap around at the end of a page.
The instruction is JMP($02FF) which is supposed to end up jumping to address 0300. I looked at the NES CPU memory in Nintendulator, and indeed the memory location 02FF has 00, and 0200 has 03 in it, which would result in 0300. This leads me to think the Indirect mode requires page wrap around.

However, I am unable to find anything about this in the MOS6502 documentation or the 6502 reference site.

So does anyone know if Indirect mode requires page wrap around or not?

Thanks!

User avatar
tokumaru
Posts: 11646
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Does the Indirect JMP instruction wrap around?

Post by tokumaru » Sun Jul 28, 2019 8:16 am

Yes, that's how JMP indirect works. I won't go through the trouble of looking for references now, but this is not a secret or an obscure behaviour by any means, it's mentioned fairly frequently in documents about the 6502. Maybe it's not mentioned along with the JMP instruction itself, but there's usually a section of observations somewhere that mentions this behavior.

timl132
Posts: 35
Joined: Tue Jul 23, 2019 10:41 am

Re: Does the Indirect JMP instruction wrap around?

Post by timl132 » Sun Jul 28, 2019 8:29 am

tokumaru wrote:Yes, that's how JMP indirect works. I won't go through the trouble of looking for references now, but this is not a secret or an obscure behaviour by any means, it's mentioned fairly frequently in documents about the 6502. Maybe it's not mentioned along with the JMP instruction itself, but there's usually a section of observations somewhere that mentions this behavior.
Okay thanks!
I did look for it in here:
http://archive.6502.org/datasheets/mos_ ... g_1975.pdf
and here:
http://www.obelisk.me.uk/6502/reference.html
and here:
http://www.obelisk.me.uk/6502/addressing.html
But couldn't find it anywhere.

User avatar
tokumaru
Posts: 11646
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Does the Indirect JMP instruction wrap around?

Post by tokumaru » Sun Jul 28, 2019 9:26 am

This one mentions it very clearly in the section about the JMP instruction:
NB:
An original 6502 has does not correctly fetch the target address if the indirect vector falls on a page boundary (e.g. $xxFF where xx is any value from $00 to $FF). In this case fetches the LSB from $xxFF as expected but takes the MSB from $xx00. This is fixed in some later chips like the 65SC02 so for compatibility always ensure the indirect vector is not at the end of the page.

timl132
Posts: 35
Joined: Tue Jul 23, 2019 10:41 am

Re: Does the Indirect JMP instruction wrap around?

Post by timl132 » Sun Jul 28, 2019 10:47 am

tokumaru wrote:
This one mentions it very clearly in the section about the JMP instruction:
NB:
An original 6502 has does not correctly fetch the target address if the indirect vector falls on a page boundary (e.g. $xxFF where xx is any value from $00 to $FF). In this case fetches the LSB from $xxFF as expected but takes the MSB from $xx00. This is fixed in some later chips like the 65SC02 so for compatibility always ensure the indirect vector is not at the end of the page.
Oh sorry, wow. I even remember reading that, but completely forgot about it.
Thanks for pointing out.

Post Reply