Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2017-05-05 04:50:41

Xephyr
Member
From: France
Registered: 2015-02-26
Posts: 59

Storing Variable Width Fonts

Hi there!

So I was thinking of adding a variable width font to my game.
As you may know, this allows to display more text on your screen and it is, in my opinion, more esthetic. There's not a lot of GameBoy games which does it though as far as I know, maybe Pokémon Trading Card Game if it can be considered as a variable font? Though, some fan translation tends to implement them now.

Anyway, what I wanted to know is how this kind of stuff is originally stored in the ROM. Does they store two arrays, one with the actual characters, a second one with the width of each character? Is there some way to gain some place with this? Though it would take maybe 256 bytes for an ASCII font which isn't that big depending on the cartridge your working with.

Offline

 

#2 2017-05-05 12:45:38

DonaldHays
Member
From: Seattle
Registered: 2016-08-01
Posts: 36
Website

Re: Storing Variable Width Fonts

Infinity has variable-width fonts, and its source code is available, so you can dig around in that code and see how they do it.

Yeah, you would need a separate array with width information. You could store width in one byte per character, and, yes, that would be 256 bytes for an ASCII font. You could trim the number of bytes by only supporting a subset of ASCII. ASCII itself only actually defines 128 characters, and 33 of those are non-printing. If your characters wouldn't be wider than 15 pixels, you could also pack the widths for two characters into a single byte.

Actually drawing the text will be a good deal more complex than for a fixed-width font. With fixed-width, you just load a character into tile memory and then write its index to the map. You can't do that with variable-width. Instead, you have to draw the tiles using a procedure. You will have to support multiple characters per tile, and multiple tiles per character. Thankfully, because the Game Boy uses a row-based ordering for tile graphics, you can probably pull this off with just some bit-shifts and bitwise ORs.

Last edited by DonaldHays (2017-05-05 12:47:53)

Offline

 

#3 2017-05-05 16:20:08

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 129
Website

Re: Storing Variable Width Fonts

Pokémon TCG doesn't use variable-width font. AFAIK it just has a set of preloaded groups of two characters, so it's more of a two-character-per-tile fixed-width font. Which does look nicer, I'll grant you that.


The French Lord Of Laziness.
Legend of Zelda and Undertale fan, I also tend to break Pokémon R/B/Y a little too much.

Twitter | Me on GCL | Discord : ISSOtm#9015 | Skype : isso.tm (I don't login anymore)

Offline

 

#4 2017-05-05 18:53:40

Xephyr
Member
From: France
Registered: 2015-02-26
Posts: 59

Re: Storing Variable Width Fonts

@DonaldHays Yeah it's true that Infinity does include a variable width font, I haven't checked the sources yet but I'll see if I find something interesting.
I've thought about packing two characters widths in one byte but I'm afraid it makes decoding longer for maybe not that much of space. Removing the non-printing characters will already help.
I've written my algorithm for the procedure, I'll post an update here or on an other topic once I've implemented it.

@ISSOtm Oh okay, I wasn't really sure since I remembered that it was a fixed width font, but also that they used to characters per tile.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson