The Complete STOS Reference

 pre-release 0.2 Edited By Dr Phibes

Customising STOS: Changing Fonts

Or "How to hide the fact you used STOS"

by Bob Goodfellow

The Mouse pointers | The default fonts for STOS | The fileselector | Support files (.ABK,MBK,MBS)

Why use different fonts? I mean what's wrong with the standard font?

Good question. (glad you asked it aren't you) There are really two types of fonts. 'Them thar readin fonts' and the display fonts. Reading fonts naturally enough are used for reading large amounts of text. They're designed to be read easily and are consequently very boring. The display fonts are for those situations where you need impact. Imagine if you used the default character set for the title screen in your latest game - laughter would be heard for miles. A bog standard 8x8 font simply can't hack it.

Another reason for changing fonts is to add character to your program. Using an unusual font can make your proggy stand out from the crowd. And that can't be bad.  An important point here is don't mix the two fonts up. If you are going to give the reader a lot of text to read make it simple. A general rule of thumb is; if the text is more than 10 lines then use a reading font.

Some basics about fonts in STOS.

Using alternative fonts is fairly easy in STOS (unlike other languages) you only have to open a window and assign a new font.

On the subject of windows; Due to a typing error on my part I got a window with no border! Excellent. Opening a window without a border gives you back the two characters you normally lose when opening a window. Groovy! - just thought I'd share that.

Oh to use it try this:(assumes medium res!)

windopen 1,0,0,80,25,0 
rem open without a border...
The manual doesn't mention this, but hey it's not perfect - by a long way.

Anyway back to fonts. STOS can hold an astonishing 10 fonts in memory at the same time, and thankfully they don't interfere with memory banks. These extra default fonts should be placed in the STOS and Compiler folders with the extensions .CR3 to .CR9 - in the manual it says that you should call the first additional font CR4 but it will need to be CR3. The reason - I think - is because STOS should have really came with 4 default character sets but only came with 3. Oh well.

Always name the next font you are adding as; the biggest value of CRx +1. So if the biggest value you have is CR5 then the next additional font should be CR6.

The fonts in the STOS folder and the Compiler folder should match. If they don't then the Basic and compiled versions of your program will have a different font. This of course may be desirable, you can have a nice readable font for programming and a pretty but un-readable font for the compiled verson.

What's the difference between the .MBK file that is produced by the fonts accessory and the CR? font that is loaded as a system font?

I'm glad you're asking these questions, shows you're paying attention. All .MBK files have an 18 byte header which has the name 'LIONPOUBNK' and a few other bits of information such as the size of the bank etc. Once the file is loaded this header information is removed.

The CR? format file immediatly starts with the idenfier code which is $6071963, a leek(start(bank)) should return this value if it is truly a font file.

Once the font is in memory you can find out the size of it by using the following:

WIDTH=deek(start(BNK)+4)*8 : HEIGHT=deek(start(BNK)+6)
To change the default character sets you must load a bank holding a font into STOS. Then BSAVE it to the STOS or Compiler folder using a line like:
bsave "8X8.CR1",start(5) to start(5)+length(5)
Where start(5) is the bank where the new font is stored and save it as the default medium resolution font.

When you reboot STOS the new font will be installed as the system font for the medium resolution, and can be used without the need to open a window. Nice. Doing the bsave bit is - simply - a pain in the bum, so on the disk is little accessory (F_SWITCH) that takes the tedium and typing errors out of it. It's straight forward to use and instructions are beside the program itself.

On the disk is a file called A_FONT.MBK this is the font that we are going to use as an example to replace the default set. It's a nice 8x8 character set for the low or medium resolution.

NOTE: DO NOT USE YOUR ORIGINAL SYSTEM DISK TO DO THIS! ALWAYS WORK ON A BACKUP..

  1. Boot up STOS and 'accload' the program F_SWITCH. It needn't be loaded as an accessory but it was designed to be instantly accessible from the STOS environment.
  2. Goto the heading 'File' on the menu bar and select 'Load .MBK'. A file selector will appear prompting you to select a file. Locate A_FONT.MBK and double click or 'Return' from the selector. After a short pause there should be a bit of information about the currently loaded font. To see what the font looks like goto 'View' on the menu bar. Any mouse button or the keyboard will return to the main screen.
  3. At this point you can install the font as system font 1,2,3 or save the font to the STOS or Compiler folders. In this example we will change the medium res system font for the next boot up. Goto the option 'Install' on the menu bar and select 'STOS Folder' A Fileselector will appear. Locate the the STOS folder and find the file 8X8.CR1 and select it.
  4. Once the drive has stopped, re-boot STOS and your new font will now be used. If you normally have the environment set to low res, you will have to change to medium res to see the font
Any recognised font can be used in this manner from 8x8 to 32x32. The compiler option is identical to the STOS option but the font will only be used at compile time.

Okay so we can now change the default character sets without too much fuss. How about changing the font half way through the program. By that I mean (as an example) you have a two screen menu system based in low res. One screen gives you information about the program and the other lets you set parameters. Because these two screens are different in function we have decided it would be quite neat to give each screen a different character and a different font. Using the traditional STOS commands the program Would need to use windows. However there are a number of reasons for not using windows - speed for one, just try the music accessory to see how slow the windows are.

Windows do have a couple of advantages, the main one is lack of hassle as everything is taken care off. It's draw backs are that fonts can only be changed in one entire line. This is not always what you would want. GEM has a neat trick of being able to have different font combinations on the same line. On the disk is a little basic program called ONTHEFLY.BAS which may cause a bit of interest.

The program does a bit of brute jiggery to get the desired results in the 'install as system x' options and a brief explanation of what is happening in the program is needed.

Because the trap call for changing font addresses doesn't appear to work, a brute method of changing the fonts is required. STOS doesn't use the GEM fonts and so keeps a copy of it's fonts in memory somewhere. The somewhere can be found using trap 3. Specifically function 28 in trap 3. It can be used like this:

dreg(7)=28 ; The function called 'GET CHARSET'
dreg(0)=0 ; Which font do we want?  0=system font 1; Low Res
                                    1=system font 2; Med Res
                                    3=system font 3 High Res
                                    4=system font 4
                                        ~~~~~~~~~~
                                    9=system font 9 
trap 3 ; Do the trap call
and finally
CHARSET_ADDRESS=dreg(0) ; The function returns the character set address in register d0
In order to use the routine for your own nefarious purposes chop out this routine from the F_SWITCH program (it's been modified lightly) and just call it. Lines 520-560 holds the actual routine.

Line 520 get the address of the font that we want to switch. As the font location MAY move around it's best to call it every time we want to switch fonts.

520 dreg(7)=28 : dreg(0)=FONT : trap 3

The variable FONT is the font we want to get the address of. STOS keeps two different numbers to represent the fonts. In Basic commands the values are 1-10 but when using this trap the values are 0-9. Values for FONT are:

0    Low res system font
1    Medium res system font
2    High res system font
3    Loaded font 1 (or additional CR3 font)
4    Loaded font 2 (or additional CR4 font)
9    Loaded font 7 (or additional CR9 font)

Line 530 simply stores the address. After calling this trap 3 function the fonts address is stored in the pseudo register dreg(0). I've put it into a variable for clarity and to make sure that it's value doesn't change for some reason. You could use the dreg(0) directly.

530 F_ADD=dreg(0)
Line 540 is VERY important. Obviously trying to replace an 8x8 font with a length of 2k with a 16x16 font with a length of 8k will result in a serious error. It will at best corrupt the text making everything unreadable or - more likely - crash the system. Using the command 'charlen' will return the real length of the font and we use this value to copy the correct number of bytes. Doing this means that only the font will be corrupted, but the system will survive. So remember a font can only be replaced with an equal sized or smaller sized font.
540 CHL=charlen(FONT+1)
Line 550 does the bizz. It copies the block of memory that holds the font. to the address of the system font.
550 copy start(BNK),start(BNK)+CHL to F_ADD
A calling example could be:
10 BNK=5 Where is the NEW font? In this case bank 5
20 FONT=0 Which font to change? In this case low res 
30 gosub 520 Go do it.
A further quite important point is to keep a copy of the font you have switched using 'charcopy' This is so you can restore the font if things go wrong or you just want to leave the system in the same state you found it. A line along the lines of:
charcopy 1 to 6
Should do the trick. This copies the low res font into bank 6. In order to restore the font just set BNK to 6. The other system fonts will need different numbers - see above.

If you have other fonts already included using CR3 to CR9 then you can also find out the addresses of these fonts by using the numbers 3 to 9 in the dreg(0)= definition. A value of '0' means that no font has been assigned.

Wanna be silly?

You can use ANY size of font as a default system font. Printing a line of text goes all over the place but it can be done. On the disk is a file called SILLY_FN.MBK, repeat the above procedure with this memory bank to see what I mean. Again NOTE: do NOT use your master disk for this purpose. Especially as it's a pointless font. Instead of 8x8.cr0 it's best to call it 8x16.cr0, that way you'll remember what size it is!

This could be useful for when there is no reading text apart from titles and scores and stuff. Just use a big font instead of screencopying or whatever, STOS takes some of the donkey work out!! You have to take care that the text does not go off the edges of the screen as STOS may take a disliking to that. STOS assumes that if you are in low or medium res, that the font is going to be 8x8. If you use an 8x16 or 16x16 then STOS gets more than a little confused and could crash.

Next time I've got a surprise. If you can slip this little bit of code into your STOS program it'll confuse everyone. Be there or be..triangular.

Another shoddy article from
Auld Bastid
1994