Hi there,
nice!
Instant initialization of complex pointered structures is not available in C - when dealing with "pointer" types, you need to store an address to a memory location, so initialization would be a 2-stage process, first storing the data, then getting and storing the address of it.
But, data serialization to the rescue. You can write a small "font data serializer" on your real computer, in your favourite language (script language is also fine), that creates a "C readable" seralized font description, that can be directly accessed.
Also, I´d put the different serialized fonts into different header or c files, so the user can include anything that is necessary (and thus reduce code size).
The font_char struct looks quite fine. It has a sizeof 16*2 + 1 + 1 bytes, which would be 34 bytes. Nao, some architectures/compilers do a structure aligning to int-size boundaries (here: 4bytes), i´d therefore make left_lead and width also 16 bits wide (u16), just to be on the safe side (sizeof / 4 = not a fraction), maybe structure aligning is turned off on MIOS32, but me iz not sure, also unsure about the future :).
Ok, long talk, here is some code, you need to strip away the typedefs, the main, and the printf(), i just tried it on a big computer, so that i do not tell you complete nonsense :)
typedef unsigned short u16;
typedef unsigned char u8;
/* One font char contains 18 16-bit words, or 36 bytes */
struct font_char
{
u16 bitmap[16];
u16 left_lead;
u16 width;
};
struct font
{
struct font_char character[96]; /* Starting at ascii character 32, which is a space,
includes numbers, symbols, upper and lowercase letters */
};
/* Generated by off-line generator, made by big computer :) */
/* Put this in a header file and let the user choose which fonts he needs, to save space */
struct font serialized_square_font = { 0x0000, 0x1001, 0xFEED, 0xBEEF /* ,... and 1724 16-bit words more */};
int main()
{
/* Let the user choose which font he wants, be obtaining a pointer to his preferred font */
struct font* myFont = &serialized_square_font;
/* Lets output the second and third bitmap "line" of the first character in the user-selected font */
printf("%x\n", myFont->character[0].bitmap[2]);
printf("%x\n", myFont->character[0].bitmap[3]);
/* Note, you have to subtract "32" from every printed character value, as your
font "starts" at character 32, which is the "space". */
}
Have lots of fun!
Bye, Peter
Edit:
having switched to C++ 10 years or so ago, i was unaware of the following method of struct "by name" initialization - I´d *highly* recommend to go this route:
http://linuxprograms...ation-advanced/
It has the advantage, that the correct element order is not necessary and that less errors can occur - just write a "c font generator" that creates initializations in that format.