Site icon xiphod

Commander X16 Font Editor

Advertisements

TABLE OF CONTENTS


How to Get X16 Fonts: X16FONTS is on the X16 SD card under \APPS\X16FONTS
it is also available here https://github.com/voidstar78/X16FONTS


INTRODUCTION

While original Commodore PETSCII has a certain charm, one of the first things I wanted to do with my Commander X16 was make use of custom fonts.

It wasn’t quite clear initially on how to do that. So, I tried writing my own Font Editor in BASLOAD, and X16FONTS.BASL is a result of that. I’m still not exactly sure how I figured it out – but it was a combination of slogging through the X16 Technical Reference (here) and trial and error.

First thing to know is, the “font address” doesn’t appear in the (System) Memory Map. The “standard” System Fonts (and there are multiple of them) are retained in the System ROM exclusively in Bank 6. As part of the system startup, it copies that ROM data over into VRAM.

Where in VRAM? Go to the X16 VERA Programming Reference, and search for “charset.” Instead of “font” the terminology here is “charset.” You will see it says $1:$F000 and goes for 2KB (exactly 2048 bytes). There are 256 separate font entries available, so 2048 / 256 = 8 bytes per font. Each font is represented by a “byte-mask” of 8 rows (where a byte is 8-bits). But how do you access VRAM? I’ll skip on how to do so from assembly for now – first, just know that the BASIC keyword VPOKE and VPEEK were added just for that purpose of accessing Video RAM.

So, try this as an experiment: the first font symbol is (by default) the ‘@’ symbol. Note that fonts go by “display code” index (which is not necessarily the same as keyboard scan code orders). So just type ‘@’ and press RETURN. It’s a command that essentially doesn’t do anything, but we just want a ‘@’ on the screen. Then type VPOKE 1,$F000,0 and see what happens to the ‘@’ symbol.

You’ll notice that the first row of the ‘@’ symbol is now gone, because that portion of the resident VRAM font was set to 0. You can try other values besides 0, like VPOKE 1,$F000,$FF or VPOKE 1,$F000,170 ($FF = 255, 170 = $AA = 10101010 in binary). To restore the default system font, just press SHIFT+ALT to cycle through the main system fonts. You can also do A=VPEEK(1,$F000):?A to see the current byte-mask value. You can do PRINT HEX$(A) or PRINT BIN$(A) if the hex or binary view is more helpful to you.

So now with knowing just that, I was ready to begin writing X16FONTS!


THE X16FONTS MAIN SCREEN

The X16FONTS main screen is divided into four main areas:

UTILITY FUNCTIONS


OPTIONS FOR SAVING YOUR FONT

There are three ways to save your font, and the choice will depend on how you want to handle loading your modified font.

Note that after each file operation, on the left side you will see “ST=xx” appear. This displays the last file system status reported by the file operation (save or load). A “normal” status value is 0, which indicate no error. If there is a problem with the current SD card or file system, then a non-zero value will be displayed.


TYPICAL USAGE

What I do is I keep multiple instances of the X16 emulator running – one for the application I’m developing, then another instance running the X16FONTS program (which I just copy over into the working folder of whatever other application I’m developing). Typically I’ll start with the PETSCII upper/lower font, and then just clear out the later-half (index 128 to 255). Do this by just using WASD to move across them and press C. The later-half is just the inverse of the first half (by default).

After modifying the font for a little while, be sure to use V to save modified rows, or Z to export all the font into a single DAT file. There is no auto-save and you don’t want to lose your work, so just using Z every few minutes is a good idea. If working across a few days, you may want to archive your folder also every once in a while. Inevitably, you may inadvertently do a LOAD instead of a SAVE, thus another way to accidentally lose work (because there is no luxury of an “are you sure?” prompt here).

Then in your development instance, use your preferred approach to loading the font (as described in the prior section). I typically just use the BVLOAD since it is very fast. If you use one of the auto-generated BAS files (to avoid having to pass around another file with your program): remember to add a line in your code to GOSUB to this font initialization (and add a RETURN at the end, since that part isn’t generated for you – since it is unknown how many auto-generated rows you want to use).

As another usage tip: if you press ESCAPE and exit X16FONTS, you won’t lose your fonts right away. They are still resident in VRAM. So if you just “RUN” again (right away), the same font will appear in the editor. This is done so you can press ESCAPE and then exercise a TILE or PRINT CHR$ command to “test” your font. But if you press SHIFT+ALT or load and run some other program, then VRAM will be overwritten. So don’t panic if you accidentally ESCAPE out of X16FONTS, just issue RUN again to get right back where you were.


X16FONTS SAMPLES (and how to load X16FONTS)

If you want to see some starter examples, in the APPS/X16FONTS folder are two examples (fully exported, so those folder both have a lot of files in them). Here is an example of how you would get to the first sample:

After running from the SAMPLE1 folder, then use the Q command to import the FONTALL.DAT and the example should look like this:

Note that you can “compile” the X16FONTS.BASL file also. Do command BASLOAD “X16FONTS.BASL” then RUN.

CONTROL CODES

An overview of ISO mode and Control Codes is in the X16 Reference “Editor” section (here). There is a table there that explains the two sets of 32-character control codes. You can do things like block users from changing character sets (more “professional” application will do this, so users don’t accidentally “crush” your custom font by pressing SHIFT+ALT), change current terminal color, swap FG/BG colors, or some of the ancient ASCII things (like 7 for bell, 10 for linefeed, 13 for carriage return).

Note that you can press CTRL+O (this is to enter ISO mode) and startup X16FONTS to start with the ISO set as the default starting reference. But to exit ISO mode, you have to ESCAPE and do PRINT CHR$($8F) (in upper case).

As mentioned, if you want to print the symbol associated with a control code (instead of invoking that control code), you have to prefix the console output with $80. For example:

PRINT CHR$($80);CHR$($07)

The above will print the font symbol associated with index 7, instead of the normal behavior of invoking a beep audible sound.

OTHER QUESTIONS

Can find me at the X16 Forum or Discord if you have any questions!

Exit mobile version