Working with Images

Loading Images

This is an easy way to load and display images in Minicube64.

To load external data into memory we use the incbin directive. This is usually done at the end, below any previous existing code.

In this example we are loading an image and it's palette into memory. This can be done in any order but we will call the palette first:

  incbin "owl.pal"
  incbin "owl.raw"

In this example the VIDEO register has not been set and so it defaults to 0x0000 This is so that we can see the beginning of memory and the zero-page, and in turn the palette and image, as it exists in memory.

When we run our program, it should look like this:

The image is clearly visible, along with the palette data above it. The palette data is 256 bytes and the image begins exactly after the palette ends. However the image is not aligned properly and is using the default colours, not the palette data we provided.

To display the image correctly we need to do a couple of things.

Before the incbin directive we can set the data origin to 0x0d00. This ensures we position the data where we need it to be in memory.

 org $0d00

Next we need to set the COLORS register to point to the high-byte of the memory address where the palette is now located, which will then apply the correct colours.

  lda #$0d
  sta COLORS

By previously setting the origin to 0x0d00, this has pushed the image to the next page in memory. We can now change the VIDEO register to 0x1000

  lda #$1
  sta VIDEO

Now when we run the program we can see the image in full, with the correct palette.

Because the image is a 64x64 full screen graphic, we can display this image without needing to use a draw routine.

If your palette data is smaller than 256 bytes, you can use org $1000 before including the image data which will force it into the next memory page rather than rely on the size of the palette to do that.

You can download and try out this example here:

Generating Images

Included with Minicube64 is a Python script that will convert a palette indexed .png image to a .raw format that can be used. A separate palette file will also be generated.

You can find the script called im2cube.py in the Tools folder.

Images must be .png format with an indexed palette.

To convert an image, run the script like so:

python3 im2cube.py owl.png

By default the script will generate a palette based on luminance.

The script will also output a list of colours in hex format that can be copied into your code and used instead of the palette file.

If you need to generate an unsorted palette, you can run the same command with a second argument such as unsorted

Last updated