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 2014-10-28 14:32:09

Crona
Member
From: Wisconsin
Registered: 2014-09-23
Posts: 58
Website

How do I use text within a game?

Ok so an issue I have been having is that I have to go and create tiles for the whole alphabet and numbers if I want to display a score or a hint or something without removing the background of the game. Do I have to do that? Is there something that I am missing that lets you do like dialogue boxes without having to remove everything else from the screen? Because how I am doing it now is WAY to much work having to set a sprite and move it to its spot for each letter or number.

Offline

 

#2 2014-10-29 08:45:54

RoboTwo
Member
From: Sweden
Registered: 2014-10-29
Posts: 19

Re: How do I use text within a game?

Depending on where you want to place the dialog box you might have to alter the main BG, yes.

If you're okay with having your dialog box on the right side of the screen, in the lower right, or bottom part of the screen you could place your text and dialog box in the window section and neatly slide it in from the bottom part of the screen smile
This allows for having dialog boxes that are just as big as your screen and they can be moved about without much of a hassle (can't pass outside the left side and upper bounds of the screen though).
I'm not quite sure if one COULD time disabling the window precisely enough to cut it off on the right hand side (this would require very precise timing since last HBlank), this could be risky though as I've heard that altering the screen setup outside of VBlank may cause damage to the screen.

Otherwise you're pretty much doomed to align the BG, rewrite the part of the tilemap you want to use your dialog box on, and once you remove the dialog box, look through the tilemap in ROM and restore the section it once covered.

Last edited by RoboTwo (2014-10-29 08:47:53)


Shake well before use

Offline

 

#3 2014-10-29 08:55:12

Crona
Member
From: Wisconsin
Registered: 2014-09-23
Posts: 58
Website

Re: How do I use text within a game?

but doesn't text use the background layer? how would I switch it to use the window layer?

Last edited by Crona (2014-10-29 08:56:36)

Offline

 

#4 2014-10-29 09:14:58

RoboTwo
Member
From: Sweden
Registered: 2014-10-29
Posts: 19

Re: How do I use text within a game?

Oh, I'm guessing you use GBDK then.
Sorry, haven't worked much with that, but the window and BG can share tiles and have individual tile maps, so the window is a excellent way to present dialogs without manipulating the main tilemap.

Will have to look into this and I'll return if I find something about drawing to the window map instead.


Shake well before use

Offline

 

#5 2014-10-29 12:22:13

nitro2k01
Administrator
Registered: 2008-02-22
Posts: 249

Re: How do I use text within a game?

RoboTwo wrote:

I'm not quite sure if one COULD time disabling the window precisely enough to cut it off on the right hand side (this would require very precise timing since last HBlank), this could be risky though as I've heard that altering the screen setup outside of VBlank may cause damage to the screen.

The timing is the least of your problems at that point. Once the LCD state machine is in the "rendering window" state, you can't disable the window rendering until the end of that line, if I recall correctly.

As for damaging the screen, the big no-no is disabling the LCD outside of VBlank. For other illegal actions, the worst that can happen is typically just that the write is ignored.


Blog: Gameboy Genius
"A journey of a thousand miles begins with one small step"
Old Chinese Proverb

Offline

 

#6 2014-10-29 13:24:43

RoboTwo
Member
From: Sweden
Registered: 2014-10-29
Posts: 19

Re: How do I use text within a game?

nitro2k01 wrote:

The timing is the least of your problems at that point. Once the LCD state machine is in the "rendering window" state, you can't disable the window rendering until the end of that line, if I recall correctly.

Ah, well I guess that's not a viable exploit then sad

Do you have any further knowledge about the text implementation of the GBDK, keeping with the subject?
Is there any easy way to switch it over to put characters into the $9C00 and onwards instead of $9800 and onwards?

I skimmed through some of the functions and noticed that there's functions for poking tiles manually into the window map in there, but found nothing about altering the destination map of the text functions.


Shake well before use

Offline

 

#7 2014-10-29 13:32:55

Crona
Member
From: Wisconsin
Registered: 2014-09-23
Posts: 58
Website

Re: How do I use text within a game?

So then I assume its easier to do that in asm? I haven't learned much about asm, but I know gbdk supports inline asm or something like that.

Offline

 

#8 2014-10-29 14:04:27

RoboTwo
Member
From: Sweden
Registered: 2014-10-29
Posts: 19

Re: How do I use text within a game?

Well it's pretty straightforward in ASM, considering you just poke a byte into the tilemap addresses you want to be represented graphically with the tile with that specific identifier.

But there's no native functionality for stuff like drawing text, loading fonts or the like.
So if you were to tackle making the game in ASM you'd have to set up a function to properly interpret the ASCII values and poke the correct tiles into the map, or make a tool for converting strings into a list of bytes representing the right tiles.

Skimming through the GBDK documentation there appears to be functions for manipulating the window already, mainly:

set_win_data(UBYTE first_tile,
                     UBYTE nb_tiles,
                     unsigned char *data);

and
move_win(UBYTE x,
                UBYTE y);


hardware wise the window layer can be enabled separately from the BG layer, so I'm guessing just like 'SHOW_BKG' you'll have to specify 'SHOW_WIN'.
I'm not sure about that though, just speculation.

there's also 'scroll_win', which takes the same arguments as 'move_win', but is relative to the windows current position, where as move_win is the absolute position.

So you can try using that for now if you haven't worked with the window earlier to get more familiar with how it works and what can and can't be done with it.

So far I can see no sign of the 'printf' function supporting the window, but it might be a easy fix depending on how it's structured.


Shake well before use

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson