Code: Select all
ldy TABLE_IX
ldx Data,y
Code: Select all
ldy TABLE_IX
lda Data,y
tax
The beauty of this instruction (and its LDY counterpart) is that it acts as a translator between data tables. It's like Inception, dropping down into another level of reality. I used it for interfacing with other hardware, specifically a musical instrument that has its own way of organizing tabular data. It's a table of sixty (or thereabouts) data points, of about a dozen different types and ranges.
So when I designed my own software's tables, they needed to reference the instrument's native data layout. And it's LDX absolute,Y that glues the instrument's data structures and my data structures together!
Imagine a representation of a target system's data in memory, with each index in the table representing a specific attribute. Oscillator A frequency at index 0, Oscillator B frequency at index 1, and so on.
I want to create an abstraction for the idea of "Oscillator frequency," so I have a Types table in the EEPROM that stores the attributes for this kind of field (high/low ranges, pointer to a draw subroutine, and other stuff). Then, I have a third level that specifies physical attributes of each field: which page it's on, where it's placed on the screen, AND (this is the key part) a reference index to the target system's data table. If I know which field the user is currently editing, then sending the real data to a type-specific interface routine goes like this:
Code: Select all
ldy USER_CURRENT_FIELD_INDEX
ldx TARGET_DATA_INDICES,y
lda DRAW_SUBROUTINE_POINTERS_HIGH,y
pha
lda DRAW_SUBROUTINE_POINTERS_LOW,y
pha
lda NATIVE_DATA_TABLE,x
rts
It's a great instruction when you need to create more-complex-than-usual data structures.