Font Loader in HiSoft Pascal

One of the attractions of the Timex/Sinclair 2068 is its ability to change its screen font through the use of user-defined fonts. As a programmer, you may want to change the display font a program uses for several reasons. A banking or financial program, for instance, would require that you use a font in which no one can possibly mistake a letter like “el” for the number one. To better set the mood of a game set the Middle Ages, you may wish to use a Gothic font. Likewise, a game set in outer space may require a futuristic looking font. Perhaps you want your T/S 2068 to display text in Greek or Russian. In that case, you have to change the entire character set as well as the font. (To the confusion of many, computer programmers and technical writers tend to use “font” to mean either a “font” or a “character set”. Be aware that the program I am about to describe can be used to change both.)

Font loading and activation is much easier in HiSoft Pascal, (henceforth: Pascal), than in BASIC for the following reasons:

Firstly, you don’t have to make any changes to RAM_TOP. To prevent BASIC programs from overwriting a user defined font, the usual practice is to lower RAM_TOP and load the font into the protected area created above. In Pascal, a global array — which is also a static array — is used to reserve space in RAM into which the font is loaded. Pascal keeps track of such arrays and prevents them from being overwritten by any of its operations.

Secondly, you don’t have to worry about where in RAM the font file is loaded. The built-in function ADDR(v) can be used anywhere in a program to locate the start position of any variable the program uses. Even if you should make modifications to your source code which changes the location of a given variable within the compiled program, ADDR(v) will still be able to locate it.

Finally, you are relieved of doing and re-doing the calculations needed to determine which values to poke into the system variable CHARS to activate the new font. Once ADDR(v) has been used to locate the start of the variable being used to store the font, all your program is required to do is to invoke the POKE(l, n) procedure to transfer this value less 256 bytes to CHARS, thus: POKE(23606, ADDR(v) – 256); and your new font becomes active.

There are already font creation programs aplenty written in BASIC. Most of them save the fonts they create as a byte file of 770 bytes. Below is a demonstration program written in Pascal that contains source code which will allow you to load and activate these fonts within a Pascal program.

PROGRAM FONTLOADER;
{
Special note to HiSoft Pascal 1.7M
users:
This program must be compiled in 31
column mode.
}
CONST
Chars = 23606;
{Chars holds the address of the
system
variable CHARS which in turn points
to
the location either in ROM or RAM
where
the current font is located.
The value stored in CHARS is always
256
bytes less than the actual start
location of the current font.}
VAR
CharSet : ARRAY [0..770] OF CHAR;
{Reserve space in RAM for the new
character set}
{Remember: CHAR takes 1 byte,
INTEGER takes 2 bytes}
FileName : ARRAY [1..12] OF CHAR;
{An array for holding the file
name of the font to be loaded}
StartAddr, {To hold the start address
of the new font}
I {A loop counter}
: INTEGER;

BEGIN {MAIN PROGRAM}
PAGE; {Clear the screen}
WRITELN('What is the name');
WRITELN('of the font to load?');
WRITELN('(12 characters padded)');
WRITELN;
WRITE('> ');
READLN; {Required in HS Pascal}
READ(FileName);
{Load in the font}
TIN(FileName, ADDR(CharSet));
StartAddr := ADDR(CharSet);
{Poke location of new font
into the system variable CHARS}
POKE(Chars, StartAddr - 256);
{Print the new font from space to
UDG-U}
FOR I := 32 TO 164 DO
BEGIN
WRITE(CHR(I), ' ');
END;

WRITELN; WRITELN;
{Add font save code here if required}
WRITELN('End of test');
END.

A special note for ZX Microdrive users:

For some reason this Pascal font loader will only load fonts that have been saved on tape. Trying to load font file which has been saved to the Microdrive from BASIC will generate an “invalid file format” error report. If you wish to use the Microdrive to load in a new font, you can, but first you must create a special kind of font file from within a Pascal program for each font and save it on the Microdrive.

First, add the following lines to the source code in the spot indicated in the main program and resave. Then recompile and save the new font loader/saver program.

{Save font routine}
WRITELN('Enter a name to save');
WRITELN('the font to the
microdrive?');
WRITELN('(12 characters padded)');
WRITELN;
WRITE('> ');
READLN; {Required in HS Pascal}
READ(FileName);
{Save the font}
TOUT(FileName, ADDR(CharSet),
SIZE(CharSet));

Next, if you do not have your character sets saved on tape already then using BASIC you will have to load in each font from the Microdrive in and resave it on tape. (I trust that you all know how to do this.)

Once you have your font files saved on tape then you can use the Pascal font loader/saver program to load them back from tape and save them out — and here I would strongly suggest using a new cartridge — to the Microdrive. Now you character sets are ready for you any time you wish to use them in a Pascal program.

The source code for this program is available upon request by sending e-mail to David Solly at [e-mail address omitted]. Source code is saved as an *.MDX file which is compatible with Gerton Lunter’s Z80 ZX Spectrum emulator

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.