You have to watch and be careful not the generalize or think “I change this and now it works, that’s the fix”… even if it seems to work for all cases. Sometimes this register stuff can be so tricky… the only way to fix it for sure is to first FIND the issue and then attack the issue, not just change things until it works.
I’ve tried several things now (to test different hypothesizes) with no luck:
- Protecting X, Y, and Z (push/popping the whole lot of them)
- Reducing the register pressure by 3 by calculating buffer_ofs_2 inside the assembly itself removing the need for two temporary registers and then also removing y_count which isn’t actually used
- Disabling hardware interrupts completely to make sure no weird side effects were happening elsewhere.
- Adding “memory” to the clobbers
Originally it seems that somehow
sprite_ofs_jump is being corrupted. In a case like this where you’re rending the FULL sprite that offset should be 0… yet it seems to be much higher (so high it quickly burns thru the sprite and starts dumping random flash). Removing the add statements for sprite_ofs_jump and this works fine. (although it would break in cases of partial sprite renders). Setting sprite_ofs_jump to 0 doesn’t work however.
Another weird thing is after I reduced the register pressure the corruption changes… now the CORRECT sprite pixels seem to be drawn, but they are spread out all over the buffer much further than they should be… making it seem that
buffer_ofs_jump was being mishandled.
It almost feels like the compiled is overlapping registers or something. I could be missing something simple here, but this is very weird.