Post
by Sik » Sun Oct 08, 2017 10:36 pm
Maybe a better method would be to reserve a small amount of RAM (say 128 bytes) and then copy the hblank handler directly into it, then point the hblank vector there. Sure, somebody could pass a handler that's larger than that, but it's probably safe to assume such a handler is doing something that runs across several line and hence a jump doesn't harm (in that case just put a trampoline as the handler). The big advantage is that you can swap handlers at will to use different effects across the game.
The big issue would be how to handle that from C. You need to get the size of the function somehow (even if just to check if it'll fit), and also make sure GCC actually compiles it as an interrupt handler (i.e. don't clobber registers and return with RTE). This is likely more feasible with handlers written in asm, which you probably want for timing reasons anyway.
Also tsk, SGDK maybe should include some premade handlers for common effects and have functions that just set them up :v (blasting a table to vscroll like in this case could be one, maybe also one that swaps all palettes mid-screen like in Sonic games, etc.).
Sik is pronounced as "seek", not as "sick".