Thursday, 29 January 2009

Fast Sprites using Pre-Shifted Data


I wrote this demo on September 15th 2006. 

The purpose was to develop a sprite engine (XOR to remove/display) that allows developer to concentrate on creating graphics and animation and not worry about shifting bytes, or pixel perfect collision.  I also wanted to get as many sprites on the screen at any one time by using the screen refresh to time drawing of each sprite.




  • No need for pre-shifted graphics (Frame 1,2 etc), saving memory space
  • Pixel perfect collision
  • Full screen


On each 1/50th of a second:

For each sprite (1-4):

  • move
  • remove
  • check for collision
  • draw

If more than 4 sprites, we handle it like this (1/25th second)

  • LOOP 1
    Process first 4 sprites (Remove, draw)
    Draw ALL sprite attributes
  • LOOP 2
    Process remaining sprites

This demo allows for the drawing of 8 sprites.  We can do this before the scan line hits the main screen (whilst still in border) if we time sprites right:

The following sprites can appear on the following rows to beat scan line (Flicker/No Visibility):

  1. Sprites 1 and 2 can appear anywhere on screen
  2. Sprite 3 can appear on rows 7-22
  3. Sprite 4 can appear on rows 12-22

The same then applies for 5 and 6,7 and 8 on loop 2.  Then, for all the extra time we have before the next screen refresh, we would fill in the remaining time of the second drawing with music, or other animation.


When the sprite is drawn, to avoid flicker, the screen attributes are

  1. Copied to the attribute buffer
  2. Sprite attributes are written to the buffer
  3. The attribute buffer is copied to the screen


You can download the source code and TAP file from

  • To run, set up your development environment as described in my previous post, and open “fsprites.asm”. 
  • In “ConText”, press F9 to compile, F10 to run in “Spectaculator”

Next Steps

I plan to write a detailed walkthrough of the code to explain how it all works, watch this space ;-) !


  1. Your Blog has started well. Doing a walk through is something I've thought about but never found the time to do. I hope you can keep up the momentum as I'm sure it will be of use to many people. Good luck.

  2. This is a goof beginning for this blog

  3. Download not available ...

  4. Ohhh, download is broken... I was writing a similar article on this, and wanted to see how you solved the problems...

    Shame. Nice to see there's more than one of us, though! :-)