User Fonts

z80 » Advanced

Tired of looking at the same font all the time? Well, you can change all that. You can make your own font on the computer stored as bitmaps and use it on the TI86.

Everything discussed in this lesson is embodied in the program FontB.asm. This creates a bold character set switching on or off every other execution.

Every time TI-OS goes to put text on the screen, it checks if certain bit in the System Flags is set. If that bit's set, it then goes to the appropriate memory address which tells it a Absolute Address Pointer of where your font is in memory. At that address it will ready a byte telling it again what size the font is and how many characters are in your font. TI-OS searches for the ASCII character it wants and then displays that character. If the character wasn't found, it uses the default character.

You need to have the following equates in your code. These are the addresses where a 24 bit pointer will be stored. The pointer will have the address of where your font data is at. These addresses are for Cursor Font and Variable Width Font respectively.

_AltLFontPtr	=$d2ed	;large font pointer
_AltSFontPtr	=$d2f0	;small font pointer

There are three steps to setting up your custom font.

  1. At either _AltLFontPtr or _AltSFontPtr, put a 24 bit pointer to where the font data is for that type of font.
  2. Set either bit 0 (Cursor Font) or bit 1 (Variable Width Font) at offset $23 from the System Flags.
  3. Make the font data

24 bit Pointer

From reading the Absolute Addressing Section you should be familiar with 24 bit pointers. The best way to setup your code is to make a pointer to your actual program where the font data is stored, as opposed to copying all the font data somewhere else. The only drawback to this is, if your program gets moved around in RAM, the pointer is invalid. The only work around to that is to somehow make your program the first one on the calculator. I don't know how but there's got to be some way. If you find out, send me an electronic mail.

Here's how to setup the absolute pointer. You will also need the following equate. It is where the name of the current program running is stored in Variable Name Format.

_asapvar	=$d6fc
This routine will find the absolute address of the font data in your program. It then puts the address into the correct pointer to install cursor font.
_altlfontptr	=$d2ed	;large font pointer
_altsfontptr	=$d2f0	;small font pointer
_asapvar	=$d6fc	;prog currently being run

install:
	ld hl,_asapvar		;current program running
	rst 20h			;_mov10toOP1
	rst 10h			;_findsym
				;returns abs address bde!
	ld a,b			;get MSB of address in a
	ld hl,font_data-_asm_exec_ram+2+2
				;offset in ram of font data
				; in program relative
				; to start of this program
				;not _asm_exec_ram!
				;+2 for asm prog identifier
				; bytes
				;+2 for length of asm prog
				; bytes
	add hl,de		;we want to add it to
				; the start of what _findsym
				; returned
	adc a,$00		;account for 24 bit pointer
				; carry
	ld (_AltLFontPtr),a	;load MSB in
	ld (_AltLFontPtr+1),hl	;load the rest in

	ret

Turning It On

Now we need to set the correct bit to verify the user font usage. It would be nice if the user could toggle user font On or Off every time they ran the program, so we're going to xor the bit so it's flipped (set...reset...set) each time the program is run.

Here's how to set the bits.

exceptionflg	=$23	;offset
alt_font	=0	;cursor
alt_vfont	=1	;variable
	set alt_font,(iy+exceptionflg)	;cursor
	set alt_vfont,(iy+exceptionflg)	;variable

Here's the completed code for installing the font.

_altlfontptr	=$d2ed	;large font pointer
_altsfontptr	=$d2f0	;small font pointer
_asapvar	=$d6fc	;current program being run
install:
	ld hl,_asapvar
	rst 20h
	rst 10h
	ld a,b
	ld hl,font_data-_asm_exec_ram+2+2
	add hl,de
	adc a,$00
	ld (_AltLFontPtr),a
	ld (_AltLFontPtr+1),hl
	ld a,%00000001		;bit we're working with
				; for cursor font
	xor (iy+$23)		;flips bit  0 at iy+$23
	ld (iy+$23),a		;load result in
	ret

Font Data

This is the hard part: Designing each character for your font set. It needs to be in the following format.
font_data:
	.db size byte
	.db number of characters
			;easy way to figure this
			; out is:
			; (end_font_data-begin_font_data)/8
			; since each character is
			; 8 bytes long
begin_font_data:
	.db ascii code
	.db %00000	;bitmap, within these
	.db %00000	; constraints, of the
	.db %00000	; character
	.db %00000
	.db %00000
	.db %00000
	.db %00000

	.db next character's ascii code
	.db %00000
	. . .
	. . .

	.db last character
	.db %00000	;bitmap, within these
	.db %00000	; constraints, of the
	.db %00000	; character
	.db %00000
	.db %00000
	.db %00000
	.db %00000
end_font_data:

The size byte is either one of the following telling the size of the subsquent font characters:

cursor_font	=$6f
v_width_font	=$64

Here's a sample of font data for cursor size font.

font_data:
	.db $6f		;type of font (large)
	.db (end_font_data-begin_font_data)/8
			;# of characters in font
			;each is 8 bytes so
			; we take the total space
			; used and divide by
			; 8 to get how many
			; fonts we are doing
begin_font_data:
	.db ' '
	.db %00000
	.db %00000
	.db %00000
	.db %00000
	.db %00000
	.db %00000
	.db %00000

	.db 223		;cursor that blinks usually
	.db %11111
	.db %10001
	.db %10001
	.db %10001
	.db %10001
	.db %10001
	.db %11111

	.db 'A'
	.db %01110
	.db %11111
	.db %11011
	.db %11111
	.db %11011
	.db %11011
	.db %11011

end_font_data:

I condensed the font characters to three just so i could emphasize the format rather than the chracters. These are characters taken from my bold font set program FontB.asm.

The organization of your characters is critical to the speed of printing. Since TI-OS starts searching through the character set to find the right character, it starts at the beginning and works it's way to the end. It's best to put heavily used characters at the beginning so TI-OS can find them fast. Here are the characters in the order they should be listed in your program. You should always include the space, x, and y characters even if you don't change them from the look of the defaults. That way, TI-OS finds them fast!

  1. LSpace ($20) - Always put this in even though it's blank. TI-OS uses it to clear the screen and everything so it's used a ton!
  2. Cursor ($df) - Since it blinks a ton.
  3. x and y ($78-$79) - Used in many math applications.
  4. Numbers (0-9) ($30-$39)
  5. Lowercase Alphabet (a-z) ($61-$7a) - Used more than the uppercase letters.
  6. Uppercase Alphabet (A-Z) ($41-$5a)
For more info on this section, take a look at FontB.asm to see how I made the different characters and how I installed the font.

You can also download an example of an Italic Font.


More from z80 » Advanced
All The Ports // APD // Assembler Directives // Entry Stack // User Fonts // IM 1 // IM 2 // Index, Shadow, and Other Registers // User Interrupt // Morphic Code // On-Off // Reading Keypresses from Port // Shift and Rotate // Simulating Key Presses // Sound // Square-Root Programs // System Flags of TI-OS