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.

image

 

Advantages

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

Timing

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.

Colour

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

Download

You can download the source code and TAP file from http://www.peargames.co.uk/downloads/fsprites.zip

  • 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 ;-) !

Wednesday 28 January 2009

Setting up the Development Environment on a Windows PC

When I develop Machine Code games for the Sinclair ZX Spectrum, I use the following Development Tools:

Installing “Spectaculator”

Download and Install “Spectaculator” 30 Day Trial. I cannot recommend this emulator more highly, it is awesome

Installing “Context” Editor

The Editor allows me to write the code with Syntax Highlighting, as well as define events for key presses that assist me in running and testing my programs.

Download the editor (1.6 MB) from http://www.contexteditor.org/ andfollow the installation instructions:

Step 1:

image

Step 2:

image

And follow the wizard until it has installed

Install “Pasmo” Assembler

Next, download the Assembler from http://www.arrakis.es/~ninsesabe/pasmo/

I use the 0.5.3 version, downloadable as a ZIP from pasmo-0.5.3.zip

Once downloaded, Unzip and extract.

image

Install in a directory of your choice

image

Configure Context

  1. From the menu choose “Options -> Environment”. A dialog box will appear.
  2. Click the “Execute Keys” tab.
  3. Click the “Add” button, and add an entry for files with a “asm” extension.

image

Set up the “F9” Functionality.

This will allow the file to be compiled, and a “TAP” file which includes a BASIC loader will be created.

image

  • Execute: Browse To and Select the Pasmo executable.
  • Start in: %p (File path)
  • Parameters: --tapbas %n %F.tap
    • This will create a ZX Spectrum TAP file with BASIC loader, output to same filename with “TAP” extension.
  • Use short DOS names for Pasmo.
  • Output to compiler window.
  • Scroll to last line for verbose output.

Set up the “F10” functionality

This will execute “Spectaculator” and pass in the compiled filename.

image

  • Execute: Points to the Spectaculator executable.
  • Start in: %p (File path)
  • Parameters: %p\%F.tap
    • This means Path, and Filename (tap)
  • Use short DOS names for Emulator

Testing the Development Environment

Create the following test program in Context, and save to your project folder as “text.asm”.

org 08000h

ld hl,04000h

ld (hl),%10101010

ld de,04001h

ld bc,17FFh

ldir

ret

end 08000h

Press “F9” and the program should assemble.

image

Press “F10” to execute “Spectaculator” and you should get the following results:

image

Congratulations! You are now ready to develop Machine Code on your Windows PC!