
Redefining the Commander X16’s character set
The font can be created in a graphics editor like Paint.Net or Aseprite. Both are available for Windows, OSX and Linux. Paint DotNet is available for OSX and Linux as Pinta.
We need the font in a format we can add to our Prog8 PRG file.
You can download a good converter from @joolin1’s GitHub page. This application works on Windows, OSX and Linux.
To use it, extract the converter from its Zip file to a folder on your computer.
Create a folder inside the converter’s folder called ‘images’.
Run this command from your command prompt (cmd.exe on Windows):
X16PngConverter.exe images\GoodFont.png -tiles -h 8 -w 8
This will convert the GoodFont.png file and output GOODFONT.BIN which we can load into our Prog8 application. Windows is not case-sensitive for filenames.
Note: it will also create a file called GOODFONT-PALETTE.BIN
This file is if you are using tiles or a title-screen in your game and want to preserve the colours used in your PNG image file.
%import textio
%import diskio
%zeropage basicsafe
main {
sub start() {
/* Demonstration text program
by Jason Oakley */
; Load the new character set into memory
void diskio.vload("goodfont.bin", 1, $f000)
; Change the font and background colours
txt.color2(1,5)
; Clear the screen
txt.cls() ; Comments can be added after commands
; Output some text
txt.print("Hello and welcome to\n")
txt.print("Programming the Commander X16\n")
txt.print("in Prog8!")
}
}
You should see the text output like this, depending on the font you use:
Make sure your font file is compatible with PETSCII or similar.
You can download a bunch of useful files from the Downloads section of this website.
Note: The default screen mode you get when you start the emulator or turn on your Commander X16 is mode 0 (zero).
This is essentially the first Tile Mode. The character set you see is actually a tile set internally.
As you type, tiles are drawn on the screen as if they were characters. Hence, the default tile size is 8×8 pixels.
Redefining the charset on the fly
%import textio
%import diskio
%zeropage basicsafe
main {
sub start() {
; Load the new character set into memory
void diskio.vload("GOODFONT.BIN", 1, $f000)
cx16.vpoke(1,$f000,%01111110)
cx16.vpoke(1,$f001,%10000001)
cx16.vpoke(1,$f002,%10100101)
cx16.vpoke(1,$f003,%10000001)
cx16.vpoke(1,$f004,%10011001)
cx16.vpoke(1,$f005,%10000001)
cx16.vpoke(1,$f006,%11010101)
cx16.vpoke(1,$f007,%10101010)
txt.print("\nHello World @\n")
}
}
What happened to the @ at sign after “Hello World” ? It sure doesn’t look like an at sign any more!
This is how easy it is to manipulate your font character (which is really just a tile!).
We load our GOODFONT.BIN character set into memory at $f000 and here we’re just overwriting the values of the first character with new ones. Pretty cool, huh?
We used $ to denote a Hexadecimal value – which is our memory locations – and % to denote binary values.
You can also switch to 40×30 character screen mode with:
void cx16.screen_mode(3, false)
Printing text at a specific location on screen:
txt.plot(5,15)
txt.print("Hello!")
Fill the screen with a particular character and colour. “A” and green:
txt.fill_screen(1,5)
Scrolling the screen around by one character:
txt.plot(5,15)
txt.print("hello!")
ubyte i
for i in 0 to 6 {
txt.scroll_left()
sys.wait(20)
}
for i in 0 to 6 {
txt.scroll_down()
sys.wait(20)
}
Of course, there’s also scroll_right() and scroll_up().
Comments