[FAT32] Avoid indexed access with base in IO range on 65C816 #355
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bank area blockwise reads and writes which wrap RAM banks in the middle of the read or write operation formerly used indirect indexed mode in $9Fxx,y to continue the operation, where .Y would start with the offset to put the first byte at $A000.
This change prevents that condition on the 65C816.
Backstory:
On the 65C816, when doing indexed reads and writes, the cycle immediately before the valid operation is a read of the indexed offset without carry.
For instance
For the
lda
instruction on the 65C816, just like on the original 6502, the CPU will first add .Y to the address without carry, and do a read cycle. This will read from$9f00
. If the page wrapped, the CPU will do another cycle, and on this the carry of the wrap will be added to the effective address, and will do the actual read from$a000
and continue execution.In the FAT32 code, this is done via indirect, but the effect is the same
The
lda
instruction on the '816 will dereferenceptr
, and then do the exact same read cycle as above.For stores, the process is similar, but slightly different
On the first cycle, just like above .Y will be added to the effective address without carry, and the CPU will always do a read cycle on the resulting address, even if the page did not wrap. On the next cycle, any carry will be applied and the CPU will do a write cycle on the effective address.
Indirect has the same cycle pattern after dereferencing.
Of note, an indexed write will always have that extra read cycle, otherwise in the case of a page wrap, the extra cycle will have affected the wrong address. The CPU assumes that the read doesn't have a side effect.