2

I'm building an emulator for the 6502 and 65C02 and I don't have the actual chip (yet).
I tried looking this up in the datasheet but it doesn't say what will happen when this occurs:

LDA #$FF    ; 0xFF -> A
LDX #$20    ; 0x20 -> X

STA #$F4, X
; A -> M[0x00F4 + X]
; A -> M[0x00F4 + 0x20]
; A -> M[0x0114] ?
; OR
; A -> M[(0x00F4 + X) & 0x00FF]
; A -> M[(0x00F4 + 0x20) & 0x00FF]
; A -> M[0x0114 & 0x00FF]
; A -> M[0x0014] ?

STA with a single byte address will store the result in the zero page. But if the offset crosses the page boundary, will it be written to the next page over (stack) or will it stay on the zero page and wrap around?

Is it the same behavior for the 6502 NMOS and 65C02 CMOS?

Will the page boundary cross for the zero page add an additional clock cycle as it does for absolute addressing modes with indexing?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
FalcoGer
  • 2,278
  • 1
  • 12
  • 34
  • 2
    It wraps, and no clock cycle is added since you remain in the same page. As for the behavior on the 65C02, I can't see it being different when it comes to the wrapping since that would break compatibility. – Michael Jan 28 '21 at 15:43
  • 1
    the 65c02 has fixed the jump bug not crossing page boundaries when reading the second (high) byte of the jump address. i was thinking a similar thing would apply here. – FalcoGer Jan 28 '21 at 15:48
  • Also, IIRC the extra cycle for absolute indexed memory access only applies to loads, not to stores. – Michael Jan 28 '21 at 15:52
  • You may find [Visual6502 Remix](https://floooh.github.io/visual6502remix/) useful if you want to trace what goes on in a 6502 when it executes a specific sequence of instructions. – Michael Jan 28 '21 at 15:57
  • 1
    @FalcoGer A zero-page read is a zero-page read. I don't think it would make sense to have a special case for the one possible read at a address 0xFF. – Thomas Jager Jan 28 '21 at 16:20
  • @ThomasJager: It's not just one special case, it's the sum of two arbitrary 8-bit numbers isn't it? So if they were zero-extended before a wider addition, the range of addresses would be 0..1FE, vs. 0..FF if it's just 8-bit addition. – Peter Cordes Jan 30 '21 at 08:34

1 Answers1

0

No. The carry during the addition of the index will not be used.

FalcoGer
  • 2,278
  • 1
  • 12
  • 34