Hello, after writing previous blogs on how great stack blasting is, I’ve recently found out about an even faster sprite rendering method called Compiled Sprites. A few weeks ago I was watching a CoCo youtube video and just briefly they mentioned using Compiled Sprites for game rendering. So I googled it and there wasn’t much information on the technique. I guess this is because most computers had built in hardware for sprites so only a few computers like the CoCo had hires graphics but no sprite hardware. So what are Compiled Sprites? It is a method of writing the data that needs to be put on the screen as assembly code that stores the picture data directly to the video RAM. Can you guess what this example is?
LEAX 7,X LDD #$9999 STD -5,X STD 122,X LDB #$90 STD 124,X STB -3,X LEAX 256,X LDB #$99 STD -6,X STD 122,X STA -4,X LDA #$90 STA 124,X LDA #$09 STA -7,X STA 121,X LEAX 256,X LDA #$99 STD -7,X STD 121,X STA -5,X LDA #$90 STA 123,X LEAX 256,X LDA #$99 STD -7,X STD 121,X LDA #$90 STA 123,X LEAX 256,X LDA #$99 STD -7,X STD 122,X STA -5,X LDA #$90 STA 124,X LDA #$09 STA 121,X LEAX 256,X LDA #$99 STD -6,X STD 122,X LDB #$90 STD 124,X STA -4,X LDA #$09 STA -7,X LEAX 256,X LDD #$9999 STD -5,X LDA #$90 STA -3,X RTS
The above code is actually a sprite of Pac Man just like the picture below.
It turns out that rendering data to the screen as a bunch of LDD,LDA,LDB and STD,STA,STB instructions is faster then stack blasting! It takes more RAM to store the sprites as code but not a lot more. From my tests I’ve taken the stack blasting 16×14 sprites take 529 cycles. Compiled Sprites vary in size since it depends on how much detail is in the 16×14 pixel sprite. I’ve had some as low as 263 cycles and the larger ones are still around 450 cycles. These are incredible considering how fast stack blasting already is. There are also some extra benefits to Compiled sprites besides speed. You don’t have to worry about the stack pointers like you do with stack blasting. You also get transparency since you only write the bits that you need to the screen.
I’m now in the process of converting my sprites to Compiled Sprites and then I’ll have to implement the new sprite handling into my Pac Man transcode. This is going to be a lot of work, but in the end it will be that much better.
See you in the next post.