Great, thanks for making these constants.  But I don't think the values are right.. look at line 181, where ITEM_PALETTE_MASK is defined to be the low 8 bits.  Does it still work if you just restrict this to the low 8 bits of the value you're setting?

Specifying this in hex makes it a lot easier to see what's going on.