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-08-03 13:39:38

chris
Member
From: USA
Registered: 2016-11-27
Posts: 102
Website

Changing screen data

So I am having quite the time trying to figure out changing screens without having a bunch of icky tile data flashing on the screen before it changes to the screen I want. I would like to know how to stop it from doing this! The screen on the right shows what I want it to be. The screen on the left however, shows what flashes before it. I don't know what to do. I'm using C, if that helps.
http://www.atari2600land.com/gameboy/garbagescreen.png
And here is the code I am using:
http://www.atari2600land.com/gameboy/ftff8a.zip
Any help would be greatly appreciated!


MidSpace: The Game Boy game I completed: http://www.atari2600land.com/gameboy/midspace.html

Offline

 

#2 2017-08-03 19:25:34

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

Re: Changing screen data

I'll start with a tip on the music player : you should write to NR52 BEFORE anything else. The first writes to NR50 and NR51 are ignored.

Then, I'm sorry, but I can't read your code. Sorry to say this but I can't figure anything without indentation or comments.
The best generic advice I could give you is to either write your own function to set tile data yourself (by also copying during HBlanks, my game does that pretty fine, there may be some slight issues for a fraction of a frame)

Code:

Wait for VBlank (using interrupts if you can)
Start copying using STAT for availability (if required I can hand you my ASM function that does that)

At worst some graphics (by that I mean "some tiles") may look wrong for a single frame. Definitely an improvement, at the very least.

Also if possible, it's recommended to do a fade-out effect (using the palettes), modify tile data and background data, then perform a fade-in.
Since you're on a DMG it should be even easier.
Here's what it looks like in my GBC game :
https://puu.sh/x0WOB/2abfee2da5.gif


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-08-03 20:27:59

chris
Member
From: USA
Registered: 2016-11-27
Posts: 102
Website

Re: Changing screen data

I went through the code and commented everything. I hope you can understand it now.
That fading in and out looks cool. How do I do that in C?
http://www.atari2600land.com/gameboy/ftff10.zip


MidSpace: The Game Boy game I completed: http://www.atari2600land.com/gameboy/midspace.html

Offline

 

#4 2017-08-03 21:44:32

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

Re: Changing screen data

The principle is :
There are 4 colors. So, in order to perform a 4-frame (four different states, with as many frames as you want in-between them) fadein/out, you need to cycle through the values.
I'm not clear, so here's the sequence for a fadeout to black (3) :

Code:

+---------+---+---+---+---+
| Frame   | 0 | 1 | 2 | 3 |
+\\\\\\\\\+   +   +   +   +
| Initial |   |   |   |   |
| color   |   |   |   |   |
|         +---+---+---+---+
|    0    | 0 | 1 | 2 | 3 |
+---------+---+---+---+---+
|    1    | 1 | 2 | 3 | 3 |
+---------+---+---+---+---+
|    2    | 2 | 3 | 3 | 3 |
+---------+---+---+---+---+
|    3    | 3 | 3 | 3 | 3 |
+---------+---+---+---+---+

The table probably isn't clear, so I'll write some approximate code. I don't know GBDK's functions. And by the way, you really should try using something else than `printf`. Like really.

Code:

void fadeout_to_black() {
    UBYTE bgp = BGP_REG;
    UBYTE obp0 = OBP0_REG;
    UBYTE obp1 = OBP1_REG;
    
    // Run 3 frames of animation
    for(UBYTE frame = 0; frame < 3; frame++) {
        // Calculate next colors
        UBYTE mask = 0b11;
        UBYTE add = 0b01;
        
        for(UBYTE color = 0; color < 4; color++) {
            if((bgp & mask) != mask) { // If the color isn't 0b11 (ie. black)
                bgp += add; // "Advance" color (white -> light gray, etc.)
            }
            
            if((obp0 & mask) != mask) {
                obp0 += add;
            }
            if((obp1 & mask) != mask) {
                obp1 += add;
            }
            
            // Go right by 2 bits to go to next color
            mask <<= 2;
            add <<= 2;
        }
        
        // Write back
        wait_vbl_done();
        BGP_REG = bgp;
        OBP_REG = obp0;
        OBP1_REG = obp1;
    }
}

A fadein function would be slightly more difficult to do (considering that you need to specify a destination palette), but it's 4am and I should REALLY go to sleep.

Also in this case it's unacceptable, since the screen transitions should be as seamless as possible.
My best bet would be to get rid of printf to load all tilesets at once. Seriously, no point in using all of these characters, you only need uppercase.
And you could even make your own text function, which could write one character per frame with a little sound, or something.

As I said, I'll look that up tomorrow.


[EDIT] Forgot to mention this : the effect will be a lot less smooth than on my GBC screen, because the DMG has far fewer colors than the GBC. (The fading is done on 32 frames with my code, on 4 frames here)

Last edited by ISSOtm (2017-08-03 21:53:43)


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-08-04 18:48:40

chris
Member
From: USA
Registered: 2016-11-27
Posts: 102
Website

Re: Changing screen data

What should I use in place of printf?


MidSpace: The Game Boy game I completed: http://www.atari2600land.com/gameboy/midspace.html

Offline

 

#6 2017-08-06 05:12:23

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

Re: Changing screen data

Ideally, you'd use a strcpy() for strings, and a custom function to print numbers.
- Allows for custom formatting
- You don't need to redraw the string, just the number
- You can have your custom charset, so no need to load lowercase if you don't need it, THUS more free tiles to have your cat tileset at the same time as your default tileset


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

 

#7 2017-08-11 20:12:21

chris
Member
From: USA
Registered: 2016-11-27
Posts: 102
Website

Re: Changing screen data

I finally got the code to work. It looks pretty good. Here is a direct link to the ROM (and code).
http://www.atari2600land.com/gameboy/ftff19.zip


MidSpace: The Game Boy game I completed: http://www.atari2600land.com/gameboy/midspace.html

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson