Search This Blog

Sunday, July 29, 2018

ChibiTerm - Font conversion

Projects / ChibiTerm  Original post date: 03/05/2016

I am using "Less Perfect DOS VGA" , a windows TTF font (12 point) for this project at Laemeur's website. Other 7x15 fonts can be used.

I use GLCD Font Creator from MikroElektronika to convert. This program also let you edit or create your own font.

GLCD Font Creator - GUI
The exported C data structure is used for their XGLCD Libraries. It organizes the pixels in columns for LCD controllers and requires some extra work (and CPU cycles) to convert to a row format for generating video. George Gardner's website talks about the data format here.
Font creator export menu
I hack together some spaghetti code for parsing the bitmap and reorganize the data into rows for scan line. The size is padded to simply access as my code needs all the help it can get.


I tried using binary notation for the font data, but Keil C doesn't support it natively and ended up using C Macro. It is not as easy to see the pixels. It is now a compile time option. (Remind me of mine sweeper for some reasons.)

Symbol: & (I think) in Binary '0' and '1' using my BIN8() macro
This is a quick and dirty hack. Part of the code logic is so bad that this is the first time I had to use a goto statement in C ever. I have only tested it with one 7x15 font as that's all I'll need for now. There is some code logic for wider and/or shorter fonts, but they have not been tested at all.

Messy code: here. Don't say I didn't warned you.
I use Pelles C for Windows from here.

Updated the file conversion program.
Source now in Github:https://github.com/FPGA-Computer/STM32F030F4-VGA


font conv.exe   [option]

[option] m = Macro or b= binary

option m enclose the output data in a C macro. It let you take advantage of the C preprocessor to modify font data. e.g. inverse font, add overstrike etc.


BM(0x00,0x00,0x18,0x3c,0x3c, ... ,0x00,0x00),

option b enclose the output data in binary format in a C macro.


BIN8(0,0,0,0,0,0,0,0),


It let you visualize the bitmap, but it is kind of hard to read.

Also added extra macros to add the FONT_xx_START and FONT_xx_END constants to make life a bit easier.

Found 1 bug. Told you that this is badly written code.

Stop processing input file at character 26. This happens to be end of file marker in text file. This fools the fgets() I used to read the input file. Not high on my priority list to fix this at the moment.

Work around: Edit the GCLD font file with a text editor to remove the offending '→' in "// Code for char → "
It turns out that GLCD Font Creator can also import raster fonts (.fon). i.e. fix sized bitmap fonts.

There is another font editor program for the Propeller, but seems to be flexible enough in the ways it export fonts.  http://www.rayslogic.com/Software/RaysFontEditor/RaysFontEditor.htm

I found "term_hex regular" in my font directory. It is a 8x12 raster font which means that I can show 80 x 40 lines of text. It turns out it came from RealTerm which carries "BSD License". It doesn't say which version, but since it is old I am going assume the original BSD license.

Anyhow, I changed a few lines of my code and get it to work. I now only have 16 bytes of RAM available, so I guess this text resolution has reached the limits. I'll have to start to squeeze RAM usage.

Video output from ChibiTerm using converted font

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.