What happens if you index past the end of 64k address space?
Moderator: Moderators
- GradualGames
- Posts: 1106
- Joined: Sun Nov 09, 2008 9:18 pm
- Location: Pennsylvania, USA
- Contact:
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?
Re: What happens if you index past the end of 64k address sp
WDC programming the 65816 manual, page 98
The next one past ffff is 0000, yes, zero page.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.
nesdoug.com -- blog/tutorial on programming for the NES
- GradualGames
- Posts: 1106
- Joined: Sun Nov 09, 2008 9:18 pm
- Location: Pennsylvania, USA
- Contact:
Re: What happens if you index past the end of 64k address sp
*warns the programmer that bad things are happening*
- rainwarrior
- Posts: 8734
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
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.)
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
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.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?