nesdev.com
http://forums.nesdev.com/

Setting attribute values according to x and y tile positions
http://forums.nesdev.com/viewtopic.php?f=2&t=15396
Page 2 of 2

Author:  rainwarrior [ Fri Jan 20, 2017 1:36 am ]
Post subject:  Re: Setting attribute values according to x and y tile posit

There are no constants in psychopathicteen's code (a constant would be preceded by an #).

tokumaru's binary number annotation is trying to illustrate an example of how it works step by step, filling in the various variables with an example as he would have generated them (which is different from how you have generated them in your program, but not in an important way)

Author:  tokumaru [ Fri Jan 20, 2017 2:32 am ]
Post subject:  Re: Setting attribute values according to x and y tile posit

rainwarrior wrote:
tokumaru's binary number annotation is trying to illustrate an example of how it works step by step, filling in the various variables with an example as he would have generated them

Exactly, it was just a test to see if the trick really worked, so I picked some arbitrary values for the variables.

As for shifting or not shifting the metatile's attribute data, that comes down to how you store it in the ROM. Many engines will dedicate only 2 bits for defining a metatile's palette index, but I personally prefer to store 4 copies of the same palette index in a byte, so I don't need to spend any time shifting (or deciding how many times to shift) those 2 bits into the correct place. ROM is not so scarce these days, I think I can afford 6 redundant bits per metatile if that will simplify and speed up attribute processing.

Author:  NovaSquirrel [ Fri Jan 20, 2017 5:17 pm ]
Post subject:  Re: Setting attribute values according to x and y tile posit

I set aside a whole byte for attributes too. Makes filling the attributes for scrolling really easy:
Code:
  ; top left corner of attribute byte
  lda (LeftPointer),y
  tax
  lda MetatilePalettes,x
  and #%00000011
  sta Temp

  ; top right corner of attribute byte
  lda (RightPointer),y
  tax
  lda MetatilePalettes,x
  and #%00001100
  ora Temp
  sta Temp
  iny

  ; bottom left corner of attribute byte
  lda (LeftPointer),y
  tax
  lda MetatilePalettes,x
  and #%00110000
  ora Temp
  sta Temp

  ; bottom right corner of attribute byte
  lda (RightPointer),y
  tax
  lda MetatilePalettes,x
  and #%11000000
  ora Temp
  iny

Page 2 of 2 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/