Log In  


Cart #font_mapper-4 | 2023-08-25 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3

Here's a cart I threw together for myself to use with the new custom font feature.

When run it will read the spritesheet into memory as a custom font, then copy a code snippet to your clipboard that will import that font into another cart. It doesn't include the values from 0x5f60->0x5f64, that define the overall font attributes. Those must be set manually in the cart you are importing to.

The import has several optimisations. Instead of always copying the entire custom font memory block it starts from the first non-zero memory value in the block and continue to the last. To save characters it will construct two exports: one that uses poke and one that uses poke4 and export whichever is smaller. It will leave out unnecessary zeroes and also trim leading and trailing zeroes in the hex values for the poke4 export. It also stores all the values as a big string that's split and unpacked at runtime to save tokens.

When defining the custom font on the spritesheet each 8x8 tile is one character and any non-zero colour value in the sheet will be interpreted as part of the glyph. The character set included by default is a Irish Gaelic typeface I made myself including character variants with síneadh fada and ponc séimhithe for the appropriate letters.

3


I found the memset function to blank a block of memory at once, without looping:

function resetfont()
 memset(0x5600,0x0,2048)
end

Ah, that's a good point merwork! I included that in the new version which is much more intelligent now. It copies a code snippet to your clipboard to import the font into another cart that has a bunch of optimisations.

I threw the original code together while far too sleep deprived and I'm sure there's plenty of other optimisations and cleanup.



[Please log in to post a comment]