Where am I going wrong?

Discussion in 'Wii - Emulation and Homebrew' started by VashTS, Jun 11, 2011.

  1. VashTS
    OP

    VashTS Beat it, son

    Member
    3,866
    690
    Mar 14, 2009
    United States
    Upstate NY
    For some reason this program just loops the printed text over and over infinitely. Pressing Home works to end the program, but what am I doing wrong? I working with the codemii site to try to learn some programming for the Wii.

    CODE#include
    #include
    #include
    #include

    static u32 *xfb;
    static GXRModeObj *rmode;


    void Initialise() {
    ÂÂ
    ÂÂÂÂVIDEO_Init();
    ÂÂÂÂWPAD_Init();

    ÂÂÂÂrmode = VIDEO_GetPreferredMode(NULL);

    ÂÂÂÂxfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
    ÂÂÂÂconsole_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);

    ÂÂÂÂVIDEO_Configure(rmode);
    ÂÂÂÂVIDEO_SetNextFramebuffer(xfb);
    ÂÂÂÂVIDEO_SetBlack(FALSE);
    ÂÂÂÂVIDEO_Flush();
    ÂÂÂÂVIDEO_WaitVSync();
    ÂÂÂÂif(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
    }

    int main()

    {
    ÂÂÂÂInitialise();
    ÂÂÂÂ
    ÂÂÂÂprintf("Hello World! My first Wii program.\n");
    ÂÂÂÂ
    ÂÂÂÂwhile(1) {
    ÂÂÂÂ
    ÂÂÂÂWPAD_ScanPads();
    ÂÂÂÂ
    ÂÂÂÂu16 buttonsDown = WPAD_ButtonsDown(0);
    ÂÂÂÂif (buttonsDown & WPAD_BUTTON_A);
    ÂÂÂÂ{
    ÂÂÂÂÂÂÂÂprintf("You pressed button A! Good job!\n");
    ÂÂÂÂ}
    ÂÂÂÂ
    ÂÂÂÂu16 buttonsHeld = WPAD_ButtonsHeld(0);
    ÂÂÂÂif (buttonsHeld & WPAD_BUTTON_A);
    ÂÂÂÂ{
    ÂÂÂÂÂÂÂÂprintf("You held button A! Good job!\n");
    ÂÂÂÂ}
    ÂÂÂÂ
    ÂÂÂÂif (buttonsHeld & WPAD_BUTTON_B);
    ÂÂÂÂ{
    ÂÂÂÂÂÂÂÂprintf("You held button B! Good Job!\n");
    ÂÂÂÂ}
    ÂÂÂÂ
    ÂÂÂÂif (buttonsHeld & WPAD_BUTTON_1);
    ÂÂÂÂ{
    ÂÂÂÂÂÂÂÂprintf("You held button 1! Good Job!\n");
    ÂÂÂÂ}
    ÂÂÂÂ
    ÂÂÂÂu16 buttonsUp = WPAD_ButtonsUp(0);
    ÂÂÂÂif (buttonsUp & WPAD_BUTTON_A);
    ÂÂÂÂ{
    ÂÂÂÂÂÂÂÂprintf("You released button A! Good job!\n");
    ÂÂÂÂ}
    ÂÂÂÂ
    ÂÂÂÂif (buttonsDown & WPAD_BUTTON_HOME)
    ÂÂÂÂ{
    ÂÂÂÂÂÂÂÂexit(0);
    ÂÂÂÂ}
    }

    return 0;

    }

    Can anyone shed some light?
     
  2. obcd

    obcd GBAtemp Advanced Maniac

    Member
    1,594
    278
    Apr 5, 2011
    Belgium
    I would expect the buttonsheld to trigger every loop with the most actual state of the buttons.
    In that case, you will need to save that state and you should only do a print when the state of a button changes.
    You also need a Video_WaitVsync(); in your while loop. It will give the cpu some idle time.

    That are the 2 things that cross my mind right away, as I am not totally awake yet.