Is there an efficient way that the community's already coded to efficiently perform this conversion? I'm pretty sure this naïf-approach amalgamation of shifts and carrysets is not the best way.
0010 TTYY YyyX XXxx (nametable byte)
to
0010 TT11 11YY YXXX (attr. table byte)
Also, the lookup from the a1,a6 bits for which bit-pair of the attribute byte? It seems like for this, a 16-entry LUT (with the two palette bits also in the index) for speed would be best...
Though, on thinking, one could replace the "ROL $patterndex"es with
in the address conversion routine, for slower/smaller way to accomplish the same thing.
0010 TTYY YyyX XXxx (nametable byte)
to
0010 TT11 11YY YXXX (attr. table byte)
Code:
;$palettedex already has the desired palette in low two bits, from figuring out what we're putting there
LDA $highaddressin
ORA #$0C
ASL $lowaddressin ;Y yyXX Xxx0
ROL A ;* ***1 1YYY
ASL $lowaddressin ;y yXXX xx00
ROL $palettedex ;* 0000 0ppy
ASL $lowaddressin ;y XXXx x000 (LSB discard)
ASL $lowaddressin ;X XXxx 0000
ROL A ;* **11 YYYX
ASL $lowaddressin ;X Xxx0 0000
ROL A ;* *11Y YYXX
ASL $lowaddressin ;X xx00 0000
ROL A ;* 11YY YXXX
STA $lowaddressout
ASL $lowaddressin ;x x000 0000
ROL $palettedex ;* 0000 ppyx
LDA $highaddressin
ORA #3 ;0010 TT11
STA $highaddressout
LDA $highaddressin
ORA #$0C
ASL $lowaddressin ;Y yyXX Xxx0
ROL A ;* ***1 1YYY
ASL $lowaddressin ;y yXXX xx00
ROL $palettedex ;* 0000 0ppy
ASL $lowaddressin ;y XXXx x000 (LSB discard)
ASL $lowaddressin ;X XXxx 0000
ROL A ;* **11 YYYX
ASL $lowaddressin ;X Xxx0 0000
ROL A ;* *11Y YYXX
ASL $lowaddressin ;X xx00 0000
ROL A ;* 11YY YXXX
STA $lowaddressout
ASL $lowaddressin ;x x000 0000
ROL $palettedex ;* 0000 ppyx
LDA $highaddressin
ORA #3 ;0010 TT11
STA $highaddressout
Also, the lookup from the a1,a6 bits for which bit-pair of the attribute byte? It seems like for this, a 16-entry LUT (with the two palette bits also in the index) for speed would be best...
Code:
.db $00, $00, $00, $00, $01, $04, $10, $40, $02, $08, $20, $80, $03, $0C, $30, $C0
Though, on thinking, one could replace the "ROL $patterndex"es with
Code:
BCC + ;y1
ASL $palettedex ASL $palettedex ASL $palettedex ASL $palettedex
+:
;and
BCC + ;x1
ASL $palettedex ASL $palettedex
+:
ASL $palettedex ASL $palettedex ASL $palettedex ASL $palettedex
+:
;and
BCC + ;x1
ASL $palettedex ASL $palettedex
+:
in the address conversion routine, for slower/smaller way to accomplish the same thing.