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.
hey all, Just trying to work out a better way of clearing my screen between backgrounds / text ect.
Currently I have this:
HIDE_SPRITES; //hide everything
HIDE_BKG;
clsrn();
clsrn:
void clsrn()
{//screen clearer
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
}
However it doesn't work effectively. In fact it seems to cause the program to hang on a white screen.
I need to remove all backgrounds and sprites from the screen so I can display text.
What is the most effective way of doing this?
Thanks
Last edited by jobalisk (2017-06-04 16:57:09)
Offline
You'd have to clear the BG map. I'm not sure how it's done in GBDK, but it should be something like
HIDE_SPRITES; memset(BG_MAP, 0, 32*32);
No need to hide BG, maybe it'll produce a slight graphical error...
Also I don't know how GBDK handles VRAM inaccessibility.
Offline
I said "something like". This is more pseudo-code than a real implementation.
Offline
An easy way would be to load a map on which all tiles are plain white with set_bkg_tiles.
However, the most efficient way to achieve your goal wouldn't be to clear the screen but to load the map with the text (or whatever you want to display) immediately.
Offline
Jonas wrote:
An easy way would be to load a map on which all tiles are plain white with set_bkg_tiles.
However, the most efficient way to achieve your goal wouldn't be to clear the screen but to load the map with the text (or whatever you want to display) immediately.
I've tried loading a plain white background but that doesn't seem to work. The text comes out as a jumble of tiles. I can see where the text should be but not the actual text itself.
Here's what I'm seeing:
Last edited by jobalisk (2017-06-06 00:26:32)
Offline
Then maybe the tiles that should represent the letters aren't loaded correctly. Take a look at the VRAM viewer in BGB (right click -> Other -> VRAM viewer) and check whether the tiles with the letters are where they should be.
Offline
Well, at startup the VRAM contains nothing but the tiles that form the "Nintendo" logo that is displayed when you turn on the Game Boy. The rest of the VRAM is empty, so restoring it doesn't make any sense.
Since you didn't show any of your code, it isn't easy to find the problem. But let me explain some of the basics and then make some guesses:
The the VRAM viewer shows you the data that is located at memory addesses $8000 to $97FF and interprets that data as tiles. The upper 128 tiles show addresses $8000 to 87FF, the next 128 tiles show addresses $8800 to $8FFF and the last 128 tiles show addresses $9000 to 97FF. If you load tile data to these sections of the memory, you'll see the tiles in the VRAM viewer. If you load anything else to these addresses, you'll see jumble.
The VRAM viewer also shows you which tiles are currently displayed on the screen (these are the ones that are shown in light green).
Note that the Game Boy can't display text unless you load some tiles that contain letters to the VRAM. The exact position is up to the programmer, but it must be somewhere between $8000 and $97FF. You can check that by loading any ROM file of your choice with BGB and open the VRAM viewer. No matter whether it's Tetris, Super Mario Land or Castlevania: You will see the alphabet (or at least parts of it) somewhere in the VRAM.
So, what went wrong in your code?
From what I understand, you were originally able to display text. Then you changed some of your code and it didn't work anymore. In the VRAM viewer I see that you loaded 128 tiles of graphics to $8000 to $87FF and a lot of nonsens to $8800 to $97FF. The tiles that should contain the alphabet should probably be located between $9000 and $97FF since some of these tiles appear in a light green on your screenshot. But for some reason, you loaded jumble to that section of the memory.
There are many ways to do that but here's my guess what happend:
Obviously, you created 128 tiles in the Game Boy Tile Designer and successfully loaded these to the first area of the VRAM. But obviously you also loaded some other data that doesn't contain tiles (and therefore is displayed as jumbe) to the rest of the VRAM. That can happen if you use any of the following functions and load more than the 128 tiles that actually exist:
set_bkg_data
set_win_data
set_sprite_data
So, my advice is to go through you code and look for these functions. Check whether you used a number higher than 128 as the second parameter. If you did, replace that number by 128 (or a lower value) and try again.
If that doesn't work, try to remove the abovementioned functions one by one from your program and check the output.
If that doesn't work either, post some of your code, so somebody here can take a look at it.
Last edited by Jonas (2017-06-06 19:01:38)
Offline
Ok, so I've finally got text displaying, thanks. However the tiles are still being imported over existing characters. I can see there is empty space in the right in this image, how do I import the sprites into there?
Offline
The tiles on the right side are only available on the Game Boy Color (which has an additional bank of VRAM). If you want to create something that runs on the older Game Boy models, simply ignore the right side. If you don't mind that your game will be GBC exclusive, you can use them. As far as I know, it isn't difficult. But I'm afraid somebody else will have to explain the details since I've never coded anything for the GBC.
In general, it should be safe to overwrite any letters you don't need, so you still have plenty of space left.
Personally, I'd recommend not to use GBDK's print functions but simply put any text you want to display on a normal map (think: text is graphics). You will have to create a tileset with the letters manually, but gives you more control over the hardware and allows you to use cool custom fonts.
Last edited by Jonas (2017-06-09 19:00:13)
Offline
Does anyone have a copy of the original sprite collection that I could use then? That way if I need to I could just load that in when needed to return the VRAM to its origonal state.
Never mind, ended up making my own one.
Last edited by jobalisk (2017-06-10 19:03:08)
Offline
Am I the only one where HIDE_BKG actually doesn't hide the background?
Offline
coinfeeder wrote:
Am I the only one where HIDE_BKG actually doesn't hide the background?
Could you post your code?
Offline
In the GBC the BG can't be disabled, that bit only affects its priority. Check the information for bit 0 here: http://bgb.bircd.org/pandocs.htm#lcdcontrolregister
Offline
Cheers folks, I fixed this by using a black-only palette just before and after switching background data, works great
Offline