Mode 3 font hello world

Topics related to the API, programming discussions & questions, coding tips, bugs, etc. should go here.
User avatar
danboid
Posts: 265
Joined: Sun Jun 14, 2020 12:14 am

Re: Mode 3 font hello world

Post by danboid » Wed Oct 05, 2022 7:46 pm

To use Print(), I also have to use SetFontTilesIndex() which requires I tell it how may tiles are in my tileset and I must confess that I'm really not sure. I've tred to manually count them but I'm not sure I'm counting them correctly. It doesn't seem that I am because I'm not seeing the correct characters being printed by Print() so I doubt I've #define'd TILESET_SIZE correctly. Would a simple count of the instances of `const char` in a tiles include file (presuming they're all in the one file) give me an accurate count?

Has anyone written a script, program or function to count how many tiles there are in a given (include) file? Do I need to include my sound patches before the tileset and font?

Thanks

User avatar
danboid
Posts: 265
Joined: Sun Jun 14, 2020 12:14 am

Re: Mode 3 font hello world

Post by danboid » Thu Oct 06, 2022 8:06 pm

I think I've mostly cracked using Print() now. Fixing my CFLAGS was definitely the trickiest bit.

To answer my own question, it doesn't really matter how many tiles you have before the tiletable you specify in SetTileTable(). Whichever tiletable you specify with SetTileTable(), put that at the end of you tiles include file then you only have to count the number of tiles in that tile table and this is the same value you define and feed into SetFontTilesIndex(), presuming you put your font include file directly after your tileset include file.

User avatar
nicksen782
Posts: 703
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Mode 3 font hello world

Post by nicksen782 » Tue Oct 11, 2022 6:27 pm

danboid wrote:
Wed Oct 05, 2022 7:46 pm
Has anyone written a script, program or function to count how many tiles there are in a given (include) file? Do I need to include my sound patches before the tileset and font?
GconvertJs will give you an output of the reduced tileset and you can over over each tile to get the tileId for that tile.

However, Print requires you to have a full tileset for the fontset, at least the numbers and letters. This can be wasteful if you do not need each letter/number. A solution that I have used was to create my own print function and a tilemap of the entire tileset. Get the first tileId of that tileset and do some math with the ASCII value of the character (subtract 32, add the value plus the tileId for space (first tile in fontset)) and use SetTile for each character. This removes the need to put your tileset in a specific place (right after your main tileset) and also allows you to use less tiles for the tileset. Of course, my solution takes away from your 255-RAM_TILES_COUNT budget for your tileset. I do have an example of this in Uno. Function is called N782_print. (https://github.com/nicksen782/Uzebox_Un ... UNO.c#L400). This is an older example but enough to demonstrate the concept at least.

A much more complex solution that I used in my UZERPG game was to not store the tileset tiles in flash at all. Just store them in the SPI RAM with a lookup for each tile. Then the graphics for each tile would be loaded into a ram tile and displayed with SetRamTile. The limitation then became how many unique characters I had in a particular message string and of course pretty much eating all my ram tiles to do it. Benefits of course were that those tiles were ram tiles and could be modified such as for color swaps. Look here at https://nicksen782.net/r_uzerpg.php Dialog Test 1 for an example. Either character has a different colored font (although it is somewhat hard to see here.) The requirements for this were exhausting and required a custom datafile to be generated. But, if you want a game with a ton of dialog then you should probably build a generator like this anyway.

Just two ideas that I've had to handle issues with fonts.

User avatar
danboid
Posts: 265
Joined: Sun Jun 14, 2020 12:14 am

Re: Mode 3 font hello world

Post by danboid » Tue Oct 11, 2022 10:32 pm

Some very useful info and tips there Nick! Thanks.

Are you saying the Uzebox kernel doesn't support more than 255 RAM tiles even if you have the SPI RAM added, hence your custom tile solution?

User avatar
nicksen782
Posts: 703
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Mode 3 font hello world

Post by nicksen782 » Sat Oct 15, 2022 7:05 pm

You're welcome! And I've really enjoyed seeing what you've been posting here.

The Uzebox kernel can support as many ram tiles or tiles as the data-type of the VRAM will allow. Typically, VRAM is 8-bit so you get 255 max and the ram tiles are counted in that same limit. But, Mode 1 could use 16-bit VRAM giving you far more tiles available but at twice the cost per index. 8-bit vram with say 28 by 28 tiles for the screen would be exactly 28*28 bytes (784). But, with 16-bit vram that would be 784*2 (1568). That's just for the vram itself. All the tile ids in your tileset would also be 16-bit numbers taking two bytes per id instead of 1. Tilemaps would take up twice as much space as well. Say you had a 2*2 map (think small Mario). It would take 4 values plus 2 for the dimensions. 6 bytes. It would be 12 with 16-bit numbers. There is only 4k ram available and a 28*28 screen would eat up nearly 40% just for the VRAM. ... Mode 1 didn't support ram tiles anyway though but it could do 8-bit and 16-bit vram and also 6*8 and 8*8 tiles.

So, I don't think that is a kernel limitation so much as the data type of the VRAM used.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest