addressing-mode6502

Need clarification on the dummy read in absolute X indexed


While messing around with an emulator, I came across the following note (see here):

Note on the MOS 6502:

The value at the specified address, ignoring the the addressing mode's X offset, is read (and discarded) before the final address is read. This may cause side effects in I/O registers.

That made me think that it would do a dummy read at address = page:offset, but when I looked at the a diagram of the registers (see here), I didn't think that was physically possible.

At best, that diagram makes me think that it would have to be address = page:(offset + X) without adding in the carry in just yet.

When I looked at the old hardware manual (see page 176 of here), it instead suggests that it never stores an intermediate calculated address and is always (page+C):(offset+X), which also doesn't make physical sense.

Finally when I found an html copy of the family programming manual (see example 10.3 here), it seemed to confirm my suspicion that the intermediate read is really page:(offset+X) without the carry just yet.

So my question is where is the actual intermediate dummy read at? page:(offset+X), page:offset, or there is no intermediate read aside from (page+C):(offset+X)? And if it is one of the last two options, can someone run me through how that works physically based on the diagram I linked (or is the diagram wrong)?


Solution

  • If you look at the timings, it appears that your assumption must be correct. lda $xxxx,x takes four cycles plus one if a page boundary is crossed.

    Assuming a page boundary is not crossed lda $xxxx,x takes four cycles. The 6502 always does a read or write on every cycle, but it can only do one read or write on every cycle.

    The instruction itself is three bytes long and will thus take three cycles to read in. That leaves only one cycle in order to read the value from memory and put it in the accumulator. It cannot , in that case, do a read of the address before it's added X and the address after its added X - there aren't enough cycles.

    When a page boundary is crossed it takes one more cycle. This is because X has to be added to the low byte of the address and the carry has to be added to the high byte of the address and there's only one 8-bit accumulator to do the adding. So, in this case, there will be a read that is discarded but from the page below the address that you are interested in.