1 - Loading Sprites [Spectrum Next]
Load sprites into the Next is pretty straight forward once you have the images in the required format.
Edit sprites and make a sprite sheet
It’s best to work out a workflow for creating sprites and editing them, the tutorials always show ready-made pixel data included as a C header file. This is inefficient.
Draw / edit sprites using a tool such as ASeprite and save it as a sprite sheet in a bitmap file.
Make sure you set the format of the sprites to palette based, and load a 256 colour palette in (potentially remapping your existing sprites).
You also need to set the background of your sprites to index 227 which is the default palette index for transparent sprites.
When exporting the sprite sheet, make it export a vertical sheet, not a horizontal one.
Convert the sprite sheet to raw data
The Next expects its sprite pattern data as
- Raw bitmap data in 8 bit palette based format
- A separate palette with RGB332 format
There are several tools to do this:
I use Stefan’s BMP tools as they can be incorporated into a Makefile. They produce an image file and a palette file. The general procedure I follow is
nexbmpto convert the BMP file (this might not be needed)
-sep-paletteswitch to generate the palette file
Load the sprite sheet into the Next
You need to copy the resulting sprite sheet and palette file onto the Next’s SD card so it can be loaded in at runtime.
The code to load the images is quite easy and can be found in my Github repo in simple-sprites.c:load_sprite_patterns(). All it does is uses the ESXDOS commands to read the data and push it into the Next’s Sprite pattern memory.
Setting up the Sprite System
Before doing any of this we need to put the sprite’s pixel data into sprite pattern memory.
We do this by setting Next register hex 303B to zero - what this register is and how it works will be explained soon.
Then we need to read in the bytes of image data from somewhere and write them to port 58B hex - the Sprite Pattern Upload port, a byte at a time.
The sprite patterns are stored in a special area of memory in the FPGA that the CPU doesn’t have direct access to called the sprite pattern memory.