Developing for Commander X16 in Prog8 – Part 4

Bitmap graphics

You may now want to draw a bitmap graphic to the screen for your funky title-screen.

There’s a sample image in the Tutorial Assets downloadable.

Here’s how to do that:

You can use Aseprite (free if you build it from source) or Paint.Net (also free) to create the image sized 320×240 in 256 colours. Download the Commander X16 palette from:

Commander X16 LoSpec palette

Convert your image:

    X16PngConverter.exe images/shooty_alien.png -image

Copy the binary and palette files to your project folder and use the following code:

%import gfx_lores
%import palette
%import diskio

%zeropage basicsafe

main {
	sub start() {
    	gfx_lores.graphics_mode()
    	void diskio.vload("shootyalien.bin", 0, $0000)
    	void diskio.vload("shootyalien-palette.bin", 1, $fa00)

    	repeat {}
	}
}

Note: You can also create a png image sized 640×480 in 16 colours and use gfx_hires instead.

If you’re using the demo image in the assets file you should see:

There are also a bunch of useful subroutines you can invoke for drawing primitives in Bitmap mode:

gfx_lores.line(x1,y1,x2,y2,c) – Draw a line from x1,y1 to x2,y2 with palette colour c.

gfx_lores.rect(x,y,w,h,c) – Draw a rectangle starting at x,y with w width and h height with palette colour c.

gfx_lores.fillrect(x,y,w,h,c) – As above but also filling the rectangle with palette colour c..

gfx_lores.circle(x,y,r,c) – Draw a circle with the centre at x,y and a radius of r with palette colour c.

gfx_lores.disc(x,y,r,c) – As in circle() but also filling the circle with palette colour c.

Comments

Leave a Reply