gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > GBA Text mode?

#173244 - Coddy - Sun Mar 28, 2010 9:46 pm

Hello I am a new comer to ARM and GBA ARM assembly, I have read the regs a few
instructions and played with a kind of clear screen (more or less fill screen with color)
demo. But I simply want to display some text on the screen so I have searched google
and here a little bit, but I really don't want to look through a billion pages to find that this
is not posible.

So, Can the GBA run in a text mode? (like on IBM PC, text and graffics modes.) If so how?
all I can seem to find is graphic modes.

If this is posible, a link, a post saying how, any thing, even some code that prints one char
in text mode, Any thing like that will do.

Thanks in advance!
_________________
I am a LLU (Low Lever User)

#173245 - gauauu - Sun Mar 28, 2010 10:05 pm

GBA doesn't really support a text mode. It's all graphics.

Now there are various ways of faking it (do some searches here to read about the details). The most common ways of faking it are either using a background, where 1 background tile = 1 character (probably the easiest way to do it), or to do a similar thing with sprites (1 sprite per chracter), or, slightly harder, draw the text graphics into vram, then show that either using a background or one or more sprites.

As far as faking it, libgba has functions in it for doing just that -- easily faking a text mode so you can get some text on the screen. Check out the ansi_console example in the libgba examples. It basically boils down to (in C):

Code:

   consoleDemoInit();

   // ansi escape sequence to set print co-ordinates
   // /x1b[line;columnH
   iprintf("\x1b[10;10HHello World!\n")



Those examples (and most of libgba) is written in C, and since you posted this in the ASM section, you probably are looking for something in assembly.....but I'll assume you're smart enough to translate this to assembly as necessary (otherwise, just use C, which is good enough for most uses in gba development)

#173246 - Dwedit - Sun Mar 28, 2010 10:05 pm

There are bitmap modes, and tilemap modes. The usual tilemap mode allows 4 background layers, in addition to sprites. Background tiles are 8x8 in size. So for a "text mode", you'd just use a tilemap mode, and load in a font so it will display text characters as the tiles.

If you want to quickly make a GBA program that displays some text, and don't care about how the hardware works, use the Console Functions from Libgba. Look for an example program in "C:\devkitpro\examples\gba\graphics\ansi_console".

Of course, you can do a lot more. You could dynamically write new graphics in a tilemapped mode to accomplish a variable-width font, TONC has an example of that.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#173247 - Coddy - Sun Mar 28, 2010 10:56 pm

Thanks, I will probably use tilemap mode and fake it in this case... There are plenty of
demos for doing something like that that I saw...

@gauauu: Actually, I have almost always used ASM and don't really know but the slim
basics of C or really any HLL but exsept for browser scripting languages. Though I sorta
get it from the comments.

Thanks everyone! Cheers!
_________________
I am a LLU (Low Lever User)

#173299 - Kyoufu Kawa - Tue Mar 30, 2010 7:39 pm

When you think about it, what is text mode on a PC other than a map of indices into a set of graphic tiles? One byte tile index, one byte attributes, it's obvious.

I wonder if that's why it's called text mode in this thread.

#173308 - Coddy - Wed Mar 31, 2010 1:46 am

Yes, That is all text mode is, but text mode is much easier to work with because the PC
handles all of it and the coder does not. All the coder has to do is send whatever byte to
the VGA and it handles the rest. (mov byte [0xB8000], 'a')
_________________
I am a LLU (Low Lever User)

#173314 - Exophase - Wed Mar 31, 2010 4:29 am

Tiles are really just colorful text, that can be scrolled per pixel and layered on top of each other. The only real limitation is that you can't set two colors independently, but only a contiguous set of colors for the palette. If this is a problem for you then you can emulate it by using two tile layers.

The other thing is that there's no actual font builtin to a GBA so one has to be copied to VRAM, but libgba comes with one.

Other than that, setting a tile on the map is a lot like setting a character on the screen. You just write to a single value in memory.

#173316 - Dwedit - Wed Mar 31, 2010 7:22 am

By the way, all writes to video ram must be 16-bit or larger.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."