gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Static Error (?)

#44625 - strager - Fri Jun 03, 2005 7:35 pm

I have a main loop like so:
Code:

while(1)
{
    static int render = 1;

    if(render == 1)
    {
        render_gfx();
        render = 0;
    };

    /* Get key input */
    {
        u16 old = KEYINPUT;

        while(KEYINPUT == old)
            /* DO NOTHING */;
    }

    /* Process key input */
    if(PRESSED(BTN_A))
    {
        do_btn_a();
        render = 1;
    };
};


Everything works fine, except that when no button is pressed, the screen is not rendered. Could it be a problem with my declaration? Or maybe the structure is incorrect. Either way, I am seeking the answer.

Thanks.

#44632 - DekuTree64 - Fri Jun 03, 2005 8:05 pm

That while(KEYINPUT == old); loop is confusing me... Won't it be locked up there almost 100% of the time, except break for a single frame if you press A? What is it you're trying to do?
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#44635 - strager - Fri Jun 03, 2005 8:09 pm

Yes; other things will be handled by interrupts (future tense, so interrupts have nothing to do with it I am sure). All I want it to do now is render an image every time I press A (or some other buttons for options), to see what the causes and effects of mixed rendering methods.

#44795 - KsChoice - Sun Jun 05, 2005 10:33 am

strager wrote:
Everything works fine, except that when no button is pressed, the screen is not rendered. Could it be a problem with my declaration? Or maybe the structure is incorrect. Either way, I am seeking the answer.

Thanks.


IMO, the current result you describe is what I would expect, because render is only set to 1 when button A is pressed.