Haha, I thought I was the only one who concerned themselves with things like that
Actually, I love this little routine for a couple of reasons - firstly, because it's such a neat and efficient algorithm for doing something you're quite likely to want to do in a game. For sorting sprites by screen line, you don't even need the precision of a normal sort: 8 buckets would probably be enough (to split the screen into 8 zones), and this would execute super quickly using this routine.
Second reason I love it is that this algorithm just translates so
nicely into 6502, using exactly all three registers, and needing no more (e.g. no temporary stores to stack or zp).
I'll definitely turn to this routine any time that I need to do some raster chasing in the future - thanks a lot for posting it.