It looks like you're looking for a "trick" that doesn't really exist. If you have several fruits spread across the addressing space and you want to be able to access them all using the same piece of code, the only way to do it is with indirect indexed addressing via a pointer in ZP (
lda (ZP), y. Or self-modidying code, which can be tricky on the NES since code doesn't normally run from RAM in that machine.
If the fruits are stored closer together, as in all data for all fruits fits in a contiguous block of 256 bytes of memory, you can use an index register as a sort of 8-bit pointer. You can do something like:
Code: Select all
.enum 0
BANANA_OFFSET .dsb 4
APPLE_OFFSET .dsb 4
KIWI_OFFSET .dsb 4
PEAR_OFFSET .dsb 4
;(...)
.ende
.enum 0
FRUIT_COLOR .dsb 1
FRUIT_SIZE .dsb 1
FRUIT_PRICE .dsb 2
.ende
;loads apple's size
ldx #APPLE_OFFSET
lda FruitData+FRUIT_SIZE, x
If the fruits don't all have the same attributes, you can reserve different amounts of memory for each one and create constants for each one's properties (e.g. APPLE_COLOR).
If the fruits are in ROM, instead of enum it'd be better to calculate the offsets using labels:
Code: Select all
FruitData:
BananaData: .db FRUIT_COLOR_YELLOW, FRUIT_SIZE_LARGE, $01, $50
AppleData: .db FRUIT_COLOR_GREEN, FRIT_SIZE_MEDIUM, $02, $00
;(...)
BANANA_OFFSET = BananaData - FruitData
APPLE_OFFSET = AppleData - FruitData
;(...)