Nadia wrote:
I want to write accumulator to the address held in mapPtr1 using something like below:
STA (mapPtr1,x)
**mapPtr1 is in ZERO page and x holds the offset of current byte to be written to the uncompressed map.
I think you didn't understand how this addressing mode works. STA (Pointer, X) will add X to Pointer (as opposed to the value
at Pointer, like happens with STA (Pointer), Y) in order to get the actual pointer, which means X is not indexing
data, it's indexing
pointers. This addressing mode is only useful if you have a series of pointers and you want the value in X to select which pointer will be used. If I understood correctly, this is not what you want. Actually I think this is the least used addressing mode of the 6502, it's not very useful.
Do you really need a pointer for outputting the decompressed data? I mean, it's understandable that you use a pointer for reading the data, since maps can be scattered across the whole ROM, but often we have a specific area in RAM where they are decompressed to, and this area is up to 256 bytes large you can use absolute indexed addressing (STA Map, X), no need for pointers.
If you actually need to use a pointer (which is the case if your maps can be decompressed to an area larger than 256 bytes), you'll have to use Y. And since Y is also used for reading, you'll have to constantly save and load Y in order to use it for both reading and writing.
The only other way I can think of is if you keep X as 0 when doing STA (Pointer, X) and increment the low byte of Pointer instead of incrementing X. If X is always 0 when these write occur, it will not make a difference when added to the pointer.