Quote:
Originally Posted by Deokishisu
Related but unrelated, can we use the built-in tint functionality to overwrite (instead of tint) specific colors in a palette when (re)loaded with a minor rewrite? Or would the palette be overwritten by GameFreak's engine on the next VBlank, requiring a different approach? I know that messing with palettes can be tricky because of how GameFreak handles them.
|
Yes you can do that. It will not be overwritten on vblank because it's (palette_xxx_unfaded) a copy of the palette memory in EWRAM, not in Palette RAM . The only way it will be overwritten is if there is another routine that gets run later that writes to the same buffer.
Basically, GameFreak handled the palettes by having two buffers in EWRAM: palette_xxx_unfaded and palette_xxx_faded. The palette_xxx_unfaded is the working buffer and this is where everything loads palettes into. Near the end of a callback, the function 080704D0 (fade_and_return_progress_probably) is usually called. This handles the fadescreen-like commands and will fade every colour in palette_xxx_unfaded to a given fade colour (usually black or white, but it can be any colour). This faded copy gets written to palette_xxx_faded. Finally, when the vblank handler is called this usually calls the function 08070474 (gpu_pal_upload). This function copies the palette_xxx_faded buffer to palette RAM (and applies handles some specialised palette fading cases with the built-in IO register-controlled blending).
In case you're wondering, this practice of maintaining a buffer for palettes, tilemaps, etc. is quite common (and actually is the recommended approach). It's called
double buffering, where a working buffer is used to write images during the frame and then swapped with an active buffer (copied to) during vblank so that the display never shows the buffer being worked on and thus causing screen tearing. Therefore, as long as you write to the working buffer and not directly to Pallete RAM/VRAM/whereever you should be good. It's just an issue of reading the code and figuring out where that buffer is.
__________________

A Pokemon that is discriminated!
Support squirtle and make it everyone's favourite.