Loading sprites into the Next is pretty straight forward once you have the images in the required format. They can be stored on the SD card and accessed using regular file operations. There is no need to combine them into data structures within your code.
Editing sprites to 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. It is much easier to leave the sprite images as files so you can work on them with an appropriate tool and the convert the image data into structures the Next understands.
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.