John West wrote:
I'm not aware of that sort of document for the 65C02. The 65816 datasheet does document the cycle-by-cycle behaviour, and that looks similar enough to what I remember of the NMOS 6502 that I'll believe the 65C02 will be the same. Instructions like LDA abs,X will have an extra cycle that reads from the wrong page if adding X to the address crosses a page boundary. STA abs, X always has the extra cycle: it will read from an address that has X added to the low 8 bits, then write to the final address. INC abs, X will have an extra read (possibly from the wrong page), then the real read, then write the old data, then write the new data.
I should have read John's answer more carefully. He describes the situation perfectly I think - the address arithmetic is being done piecemeal and results in the wrong high byte on the read and an invalid access as a result. My attempt to reproduce is a bit confusing though:
Code:
000000 fffd: 1 ff
000001 ff00: 1 a9 ff00 a9 02 lda #$02
000002 ff01: 1 02
000003 ff02: 1 aa ff02 aa tax
000004 ff03: 1 9d ff03 9d fd 80 sta $80fd,x
000005 ff03: 1 9d
000006 ff04: 1 fd
000007 ff05: 1 80
000008 80ff: 1 7f
000009 80ff: 0 02
000010 ff06: 1 9d ff06 9d fe 80 sta $80fe,x
000011 ff07: 1 fe
000012 ff08: 1 80
000013 ff08: 1 80
000014 8100: 0 02
000015 ff09: 1 9d ff09 9d ff 80 sta $80ff,x
000016 ff0a: 1 ff
000017 ff0b: 1 80
000018 ff0b: 1 80
000019 8101: 0 02
000020 ff0c: 1 4c L ff0c 4c 00 ff jmp $ff00
Why do the extra read cycles happen at the PC? Arguably this is better behaviour in *both* scenarios, so if this is a "fix" why not fix it all the time?