nesdev.com
http://forums.nesdev.com/

What happens if you index past the end of 64k address space?
http://forums.nesdev.com/viewtopic.php?f=2&t=15611
Page 1 of 1

Author:  GradualGames [ Fri Mar 03, 2017 7:55 pm ]
Post subject:  What happens if you index past the end of 64k address space?

If a game attempts to access a location past the end of 64k address space with indirect addressing, does this wrap all the way back to ZP, or only within the last page?

Author:  dougeff [ Fri Mar 03, 2017 8:04 pm ]
Post subject:  Re: What happens if you index past the end of 64k address sp

WDC programming the 65816 manual, page 98

Quote:
On the 6502, 65C02, and 65802, if an index plus its base would exceed $FFFF, it wraps to continue
from the beginning of the 64K bank zero; that is, when index is added to base, any carry out of the low-order
sixteen bits lost.


The next one past ffff is 0000, yes, zero page.

Author:  GradualGames [ Fri Mar 03, 2017 8:17 pm ]
Post subject:  Re: What happens if you index past the end of 64k address sp

*warns the programmer that bad things are happening*

Author:  rainwarrior [ Fri Mar 03, 2017 8:22 pm ]
Post subject:  Re: What happens if you index past the end of 64k address sp

The same thing happens with ZP indexing too, by the way. (The relevant instructions wrap within the ZP, they won't go into $1XX) I don't think this comes up very often though.

There's also a weird wrap with indirect pointers placed at $FF, or JMP ($XXFF) where the high byte doesn't get incremented to fetch the second half of the pointer. i.e. ($FF) is the pointer at $00:$FF, not $100:$FF. (Probably comes up even less often.)

Author:  Bregalad [ Sat Mar 04, 2017 7:31 am ]
Post subject:  Re: What happens if you index past the end of 64k address sp

GradualGames wrote:
If a game attempts to access a location past the end of 64k address space with indirect addressing, does this wrap all the way back to ZP, or only within the last page?

I don't think there's any question to add there. The same principle of $ff + $01 = $00 applies everywhere in digital electronics, it would be totally weird to have it stick to $ff. Such a behaviour is totally unnatural and requires extra circuitery to work. Some advanced CPUs have instructions to do such calculation, which are useful for example when mixing audio. However it is always explicitely mentionned when such a saturation is implemented. There for your question is a non-question - obviously going past $ffff will roll back to $0000.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/