Alright - so I'm attempting to do some optimization. Using ASM6, and using CHR ram. Essentially, I have different *types* of tiles that can be loaded (background, screen object, paths), and the loading of each treated slightly differently...and indexes to each are buried in their own tables. It gets pretty unruly, and I'm trying to logically simplify.
In my loadChrRam routine, I end up first checking the type (type by type), where what I'd like to have is a look up table that populates the indexing based on the type. I'm making this sound really confusing...ok...
Right now, I have something like:
This works fine. And I could keep it this way. But since there are about 8 *types*, there's a lot of redundant code here (checking for each one, instead loading #CHR1_TableLo, etc). In an attempt to free up a little ROM space, I'm trying to create a table that points to the tables that points to the values. But I'm never getting the expected results.
So like, it would be something more like:
LDY chrType
LDA chrTypeTableLo,y ;; which, if zero, would have #CHR0_TableLo
STA pointer
LDA chrTypeTableHi,y
STA pointer+1
JMP gotMyChrTile
Now, of course, this doesn't directly work, because what I'm really trying to do is point to an address....so i was trying things like creating a whole other table with high and low address values for both the high and low references there:
dummyPointerTableLo_lo:
.db <chrTypeTableLo
dummyPointerTableLo_hi:
.db >chrTypeTableLo
And then in the routine, things like:
LDY #$00
LDA dummyPointerTableLo_lo
STA pointer
LDA dummyPointerTableLo_hi
STA pointer+1
LDY chrType
LDA (pointer),y
STA pointer
;;;;;;; JUST TESTING ABOVE TO SEE IF THAT GIVES ME THE VALUE FOR LOW BYTE, FINISHING THE HI BYTE AS BEFORE;;;;
LDA #CHR0_TableHi,x
STA pointer+1
JMP gotMyChrTile ;; now this pointer SHOULD reference the right tile in the following routine.
At this point, I'm just sort of going cross eyed with it. i'm likely doing something dumb, as I have this sort of addressing all over my game, but...*shrugs*. I've got to move on to some other pressing things in the interim...anyone see glaring issues and/or suggest how to correctly mine this data?
In my loadChrRam routine, I end up first checking the type (type by type), where what I'd like to have is a look up table that populates the indexing based on the type. I'm making this sound really confusing...ok...
Right now, I have something like:
Code:
LDX specifcTile ;; offset in lookup tables of specific tile to load
LDA chrType
BNE notZeroTileType
;;; if it is zero tile type
LDA #CHR0_TableLo,x
STA pointer
LDA #CHR0_TableHi,x
STA pointer+1
JMP gotMyChrTile ;; now this pointer references the right tile in the following routine.
notZeroTileType:
;;;; check other tile types
LDA chrType
BNE notZeroTileType
;;; if it is zero tile type
LDA #CHR0_TableLo,x
STA pointer
LDA #CHR0_TableHi,x
STA pointer+1
JMP gotMyChrTile ;; now this pointer references the right tile in the following routine.
notZeroTileType:
;;;; check other tile types
This works fine. And I could keep it this way. But since there are about 8 *types*, there's a lot of redundant code here (checking for each one, instead loading #CHR1_TableLo, etc). In an attempt to free up a little ROM space, I'm trying to create a table that points to the tables that points to the values. But I'm never getting the expected results.
So like, it would be something more like:
Code:
LDY chrType
LDA chrTypeTableLo,y ;; which, if zero, would have #CHR0_TableLo
STA pointer
LDA chrTypeTableHi,y
STA pointer+1
JMP gotMyChrTile
Now, of course, this doesn't directly work, because what I'm really trying to do is point to an address....so i was trying things like creating a whole other table with high and low address values for both the high and low references there:
Code:
dummyPointerTableLo_lo:
.db <chrTypeTableLo
dummyPointerTableLo_hi:
.db >chrTypeTableLo
And then in the routine, things like:
Code:
LDY #$00
LDA dummyPointerTableLo_lo
STA pointer
LDA dummyPointerTableLo_hi
STA pointer+1
LDY chrType
LDA (pointer),y
STA pointer
;;;;;;; JUST TESTING ABOVE TO SEE IF THAT GIVES ME THE VALUE FOR LOW BYTE, FINISHING THE HI BYTE AS BEFORE;;;;
LDA #CHR0_TableHi,x
STA pointer+1
JMP gotMyChrTile ;; now this pointer SHOULD reference the right tile in the following routine.
At this point, I'm just sort of going cross eyed with it. i'm likely doing something dumb, as I have this sort of addressing all over my game, but...*shrugs*. I've got to move on to some other pressing things in the interim...anyone see glaring issues and/or suggest how to correctly mine this data?