Loading and Saving Font Files
One of the cool things that I see TI-99 programs written by experienced people is the use of custom fonts.
I downloaded the gif file library of fonts by Sometimes99er and it is amazing.
I brought some of those into Magellan to look at them and then exported some of them out as BASIC DATA.
This was not a perfect format for my Forth graphics wordset, so I wrote a Forth word that would work a little better with that data requiring a little text search and replace.
I called it … wait for it …
CALLCHAR. What would you call it?
It uses some stuff I made that CHOPS a string quickly and then I use the ANS Forth word >NUMBER to convert each 8 character HEX string into a 32 bit integer.
A font source code file using CALLCHAR looks like this:
CR .( FONT277 for 32 column mode only)
NEEDS CALLCHAR FROM DSK2.CALLCHAR
\ character data
33 S" 0010101010001000" CALLCHAR
34 S" 0024240000000000" CALLCHAR
35 S" 00247E24247E2400" CALLCHAR
36 S" 00083E283E0A3E08" CALLCHAR
37 S" 0062640810264600" CALLCHAR
CALLCHAR lets me INTERPRET a file of character definitions for the entire character set in about 10 seconds. (ASCII 33..127)
Remember that is reading a text file and interpreting it line by line in "normal" TI-99 speed. It uses no program memory permanently to do the job. Data goes directly into VDP RAM.
However 10 seconds is a long time.
Armed with my new DSRLINK courtesy the great people on Atariage, I thought I would try using the LOAD and SAVE functions of the file system.
This is an example of where Forth shows it's colours. Because I had done all the work to define a little language to work with the PABs and call the DSRLINK here is all it took to make routines to LOAD and save directly to VDP memory from files.
Edit: fixed late night mistakes
\ loadfile savefile utilties
0B CONSTANT W/O100 \ output, internal, relative, fixed 100
0D CONSTANT R/O100 \ input, internal, relative, fixed 100
: SETPAB ( VDPaddr count file$ len mode -- ) (common factor for both routines)
[PAB FLG] VC! \ set file access mode byte
[PAB FNAME] VPLACE \ set file name
0 [PAB RECLEN] VC! \ set rec. length to 0
[PAB REC#] V! \ set #bytes to save (int)
[PAB FBUFF] V! ; \ set start address in VDP Ram (int)
: SAVE-FILE ( VDPaddr count file$ len mode -- ior) (*ior: I/O response)
PSHPAB SETPAB 6 FILEOP ?FILERR POPPAB ;
: LOAD-FILE ( VDPaddr count file$ len mode -- ior)
PSHPAB SETPAB 5 FILEOP ?FILERR POPPAB ;
Using these commands I will create SAVE-FONT LOAD-FONT commands like this:
: SAVE-FONT ( file$ len --) 800 400 2SWAP W/O100 SAVE-FILE ;
: LOAD-FONT ( file$ len --) 800 400 2SWAP R/O100 LOAD-FILE ; \ edited the last typo
Where 800 is the pattern descriptor table and 400 is the 1K bytes, from character 0 to character 128 ASCII.
In testing the process loading a font is virtually instant, so I can include a font file in the Forth START file that loads when Forth boots up.
Now I have to decide which font to load... That might be harder for me to decide than writing the code!
The process will be to create source code files with help from Magellan, compile the files to VDP memory, then SAVE-FONT to a TI-99 binary file.
Edited by TheBF, Wed Nov 21, 2018 9:16 AM.