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 2016-06-26 11:49:47

holtkamp
Member
From: Orlando, FL
Registered: 2016-06-23
Posts: 14
Website

Question about VBLANK: How much time do I have to run my code?

Am I supposed to have all my game logic execute within the VBLANK region? Since I can't access VRAM outside of the VBLANK interval, I would think that I need all my code to execute during VBLANK. And that doesn't seem like much time to get things done.

VBLANK is 10 scanlines long... so that means my code would have to execute in (10/154) * (1/60) =  1.08 milliseconds per frame? Wow!

I just need a sanity check, thanks guys. Also it's great to see an active gameboy development community!! Really excited to join the forum.

Offline

 

#2 2016-06-26 13:38:06

Tag365
Member
Registered: 2016-06-01
Posts: 44

Re: Question about VBLANK: How much time do I have to run my code?

Normally you would put the code that deals with updating the visuals (sprites, tileset, background, window) inside the VBLANK interval. You can put the internal game logic (like updating enemies) outside the VBlank time period. Peforming actions such as changing sprites or moving the background outside the VBLANK interval can result in strange visual effects, such as screen tearing, or possibly wavy background effects.

Offline

 

#3 2016-06-26 14:12:54

holtkamp
Member
From: Orlando, FL
Registered: 2016-06-23
Posts: 14
Website

Re: Question about VBLANK: How much time do I have to run my code?

Ah! So right now my game loop looks like this

while (true)
{
    WaitForVBLANK();
    PollJoypadInput();
    UpdatePlayer();
    UpdateEnemies();
    TransferDataToOAM();
}

I was always under the mindset that I had to wait for VBLANK until I could run my code, but instead I could wait for an arbitrary scanline, let's say number 100
and then I could make my loop look something like this:

while (true)
{
    WaitForLine100();
    PollJoypadInput();
    UpdatePlayer();
    UpdateEnemies();
   
    WaitForVBLANK();
    TransferDataToOAM();
}

And now I split up the code into two sections; first section updates the internal RAM and then second updates VRAM. And now I have 44 scanlines worth of time before VBLANK that I can update game logic like player collisions and stuff.
Wow this is much, much better!

I guess another way of rearranging the game loop is like this:

while (true)
{
    WaitForVBLANK();
    TransferDataToOAM();
    PollJoypadInput();
    UpdatePlayer();
    UpdateEnemies();
}

But then it takes almost a whole frame of time until the graphics are updated from the players input. But this is another possible solution. I don't think 1/60th of a second of input lag would be noticeable at all.

Thank you for the help Tag!

Offline

 

#4 2016-06-27 11:00:11

Tag365
Member
Registered: 2016-06-01
Posts: 44

Re: Question about VBLANK: How much time do I have to run my code?

You could put the wait_vbl_done() function and the updating visual code after you update the gameplay related stuff.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson