What happens if you index past the end of 64k address space?
This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade. View original topic
What happens if you index past the end of 64k address space?
by GradualGames on 2017-03-03 (#190414)
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?
Re: What happens if you index past the end of 64k address sp
by dougeff on 2017-03-03 (#190415)
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.
Re: What happens if you index past the end of 64k address sp
by GradualGames on 2017-03-03 (#190417)
*warns the programmer that bad things are happening*
Re: What happens if you index past the end of 64k address sp
by rainwarrior on 2017-03-03 (#190418)
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.)
Re: What happens if you index past the end of 64k address sp
by Bregalad on 2017-03-04 (#190426)
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.