Hummm,
In rubyQ I implemented a priority management: every sprite starts with a priority of 3 and every frame is not displayed priority is decreased by 1, until reaching 0.
Then, for each sprite I calculated a priority/y position value: upper 2 bits is the priority, the remaining is y position.
After that I sorted all sprites based on priority/y position value with bubblesort: so the first sprites in the array are the upper and/or the older displayed one.
Finally, I distributed all the sprites in the array between P0 and P1, starting for the first one, with this algorithm:
- place the first one on P0
- place the second one on P1
- place the third one on P0 if the first one is completely displayed and there is time to reposition P0 (using only HMOVE); otherwise try the same with P1; otherwise sprite not displayed, decrease priority by 1
... and so on
In this algorithm for each sprite repositioning I calculated the HMP0/1 value at each line to correctly reposition P0/1 for the next sprite (no RESP0/1 used in the kernel due to lack of CPU cycles). Values of HMP0/1 for each line are stored in dedicated datastreams.
Obviously all coded in C for the ARM CPU because it's easier.
I hope it could help you.
Silvio