Classic Computer Magazine Archive HI-RES VOL. 1, NO. 4 / MAY/JUNE 1984 / PAGE 33


by Stephen Reed

Have you ever wondered how the computer knows to display the letter "A" when it's supposed to -- especially since all it really understands is 1s and 0s? The answer to this comes from something called the Video Character Generator or Character Matrix.

Simply put, this is a Read Only Memory (ROM) which is filled with data that tells the computer what each character in the alphabet is supposed to look like.

Whenever the computer needs to display a "S," for example, it looks through ROM until it finds the correct data for displaying a "S" on the screen. And since this matrix of data is stored in ROM, it's ready as soon as you turn on your Commodore 64.

Suppose you could change the data in the character matrix so the computer would display your own character set instead of the original. You easily could make your screen characters appear in Old English, or even other languages such as Russian or Greek complete with their special letters. You could define special characters such as smiling faces, Pac-man, stars, etc. Imagine the impact of a game with a special character font to match the game theme. Well, all this can be done.

The ROM which stores this character matrix cannot be altered, but there is a vector in the Commodore 64 which tells the computer where ROM is, and this vector is in RAM, which means it can be changed.

Therefore, if we change the vector so it looks into RAM to get the character matrix, we can have our own character information right there waiting for it.

The purpose of the Commodore Font Editor is to provide an easy interface to create character fonts. The program itself is straightforward with few tricks. Type the program in slowly and try to understand each module as it is entered.

Before trying to design a character font, first develop it on paper. This allows you to verify consistency between the letters before you go into the editor. First, make up a character matrix such as fig. 1.

Then, define your character within the box. Remember to leave one side column and either the top or bottom row empty so your characters won't touch each other on the screen. If, of course, you are defining a cursive font, you will want the characters to connect with some sort of standard so they look consistent.

Also, you should not leave blank columns if you are designing special symbols that require more than one character, like a pointing hand.

Using the Font Editor

The first thing the program does after you type "RUN" is to load the character area with the data stored in ROM. This takes about 30 seconds and is only done the first time you type RUN. If you stop the program and type RUN a second time, the program will not get the ROM characters again. This is designed to prevent the program from wiping out a font you've been designing. The program checks for this by looking at the top row of the @ or character code 0, so don't alter the top row of this character.

Fig. 1: Sample Character Matrix

After initializing the system, the program places the main menu on line. From this point, you can go anywhere in the editor.

Note: The character codes displayed and the inputs requested are not ASCII, but rather the Commodore Screen Display Codes, given on page 132 of C64 Users Guide and page 376 of the C64 Programmers Reference Guide.

Also, the character buffer for the font editor is from 12288 to 14335, (3000H to 37FFH). The program and variable areas are from 2048 to 12287, (800H to 3000H). The program protects the character buffer from BASIC so your characters will not get wiped out by accident.

Saving a Character Font

After selecting Item 1 on the main menu, you will be asked for a filespec. After putting a disk into the drive, type the name you want your font called. The name must be a valid Commodore filespec and can be no longer than eight characters. After you depress RETURN, the program will save your font to disk. The file format is a valid "PGM" file that loads into the character data area defined. Once a file has been developed and SAVEd, all you need to do to use it in your own programs is:

1) Protect the matrix area.

2) Set the matrix vector with: POKE 53272, (PEEK 53272) AND 240) + 12.

3) Load the font file.

Loading a Character Font

After choosing main menu Item 2, enter the name of the file you want to load. This file must exist on the disk in drive 8. The program will then load the file, displaying the current character as it loads. When finished, you will return to the main menu.

Editing a Character

After selecting this option, you are asked which character you wish to edit -- simply type your choice. You then will be given a sub-menu of commands to use for editing a given character.

  • The E key will erase the character so you can start from scratch.
  • The * and the . keys will set the pixel underneath the cursor.
  • The space bar will reset or erase the pixel underneath the cursor.
  • To move the cursor, use the cursor control keys in the normal manner.
  • When finished with a character, depress RETURN and the new character data will be placed into the matrix.

Moving Characters

This function (menu Item 4) is used to move characters around in the character set. Be careful to avoid overlapping character areas. To use this option, you enter three values:

1) The first character to move.

2) The last character to move.

3) The first character of the area to move, too. The system will then update the character matrix.

Note: This routine does not have wrap-around when moving characters, so keep this in mind.

Swapping Characters

Swapping characters (menu Item 5) is exactly like Item 4 (Move Characters) except the two areas affected are swapped, not overwritten as in Item 4.

Inverse Characters

This option allows you to create inverse characters from normal characters and vice versa. The parameters required are a starting and an ending character number. Once you develop your own font, simply move it into the inverse area, then reverse it. This will give you your font in the normal Commodore fashion.

Downloading Characters

This routine allows you to selectively replace areas of your font with the character data which is stored in ROM. A starting and ending character input is required.

Increment/Decrement Display

These options (menu Items 8 and 9) allow you to scan through the characters so you can examine them close-up in the editing window.

Variable Table

Powers of 2, 128 . . . 1
Current character being displayed
Previous character displayed
Keyboard scan, etc.
Print offset to place text on screen
Byte value of current location
Flag to indicate pixel set/reset
Result of numeric input routine
File name of disk file
Value of data in editing window
Horizontal printing offset
Vertical printing offset
Flag for common routine usage

(Program code not yet available for download.)