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-06-04 16:56:44

jobalisk
Member
From: I don't even know anymore...
Registered: 2017-05-28
Posts: 55
Website

clearing the screen effectivly

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

 

#2 2017-06-04 17:48:36

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

Re: clearing the screen effectivly

You'd have to clear the BG map. I'm not sure how it's done in GBDK, but it should be something like

Code:

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.


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

 

#3 2017-06-04 18:45:39

jobalisk
Member
From: I don't even know anymore...
Registered: 2017-05-28
Posts: 55
Website

Re: clearing the screen effectivly

um... that doesn't work at all. I just get an implicit delcleartion warning and then a whole heap of jumbled background tiles

Offline

 

#4 2017-06-04 18:57:26

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

Re: clearing the screen effectivly

I said "something like". This is more pseudo-code than a real implementation.


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

 

#5 2017-06-04 19:23:36

jobalisk
Member
From: I don't even know anymore...
Registered: 2017-05-28
Posts: 55
Website

Re: clearing the screen effectivly

I see

Offline

 

#6 2017-06-05 07:39:40

Jonas
Member
From: Frankfurt, Germany
Registered: 2016-06-06
Posts: 96
Website

Re: clearing the screen effectivly

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

 

#7 2017-06-05 15:34:49

jobalisk
Member
From: I don't even know anymore...
Registered: 2017-05-28
Posts: 55
Website

Re: clearing the screen effectivly

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:

https://image.ibb.co/jyJ7Vv/Capture.jpg

Last edited by jobalisk (2017-06-06 00:26:32)

Offline

 

#8 2017-06-06 02:33:18

Jonas
Member
From: Frankfurt, Germany
Registered: 2016-06-06
Posts: 96
Website

Re: clearing the screen effectivly

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

 

#9 2017-06-06 15:24:43

jobalisk
Member
From: I don't even know anymore...
Registered: 2017-05-28
Posts: 55
Website

Re: clearing the screen effectivly

I know they represent the letters, I'll have a look at the VRAM.

So I'm getting this:

Anyway to reset the VRAM back to its original form?

https://image.ibb.co/gxXztF/Capture1.jpg

Offline

 

#10 2017-06-06 18:51:52

Jonas
Member
From: Frankfurt, Germany
Registered: 2016-06-06
Posts: 96
Website

Re: clearing the screen effectivly

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

 

#11 2017-06-06 19:59:48

jobalisk
Member
From: I don't even know anymore...
Registered: 2017-05-28
Posts: 55
Website

Re: clearing the screen effectivly

Thanks for the heads up. On reflection my 99% positive that I did load junk into the game so ill fix that.

Offline

 

#12 2017-06-09 14:40:25

jobalisk
Member
From: I don't even know anymore...
Registered: 2017-05-28
Posts: 55
Website

Re: clearing the screen effectivly

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?

https://image.ibb.co/gbz20v/Capture.jpg

Offline

 

#13 2017-06-09 18:57:19

Jonas
Member
From: Frankfurt, Germany
Registered: 2016-06-06
Posts: 96
Website

Re: clearing the screen effectivly

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. cool

Last edited by Jonas (2017-06-09 19:00:13)

Offline

 

#14 2017-06-09 22:22:16

jobalisk
Member
From: I don't even know anymore...
Registered: 2017-05-28
Posts: 55
Website

Re: clearing the screen effectivly

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

 

#15 2019-06-04 08:08:11

coinfeeder
New member
Registered: 2019-06-04
Posts: 4

Re: clearing the screen effectivly

Am I the only one where HIDE_BKG actually doesn't hide the background?

Offline

 

#16 2019-06-04 12:29:11

gbjosh
Member
From: KY
Registered: 2016-06-15
Posts: 43

Re: clearing the screen effectivly

coinfeeder wrote:

Am I the only one where HIDE_BKG actually doesn't hide the background?

Could you post your code?

Offline

 

#17 2019-06-05 06:42:24

AntonioND
Member
Registered: 2014-06-17
Posts: 114
Website

Re: clearing the screen effectivly

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

 

#18 2019-06-05 20:30:17

coinfeeder
New member
Registered: 2019-06-04
Posts: 4

Re: clearing the screen effectivly

Cheers folks, I fixed this by using a black-only palette just before and after switching background data, works great smile

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson