Homebrew development - Sleep()

Discussion in 'Wii - Hacking' started by diego_pmc, Sep 21, 2009.

Sep 21, 2009
  1. diego_pmc
    OP

    Newcomer diego_pmc Advanced Member

    Joined:
    Sep 8, 2009
    Messages:
    52
    Country:
    United States
    [Sorry, wrong forum; should have posted this in Homebrew Games & Applications.]

    I'm trying to port a little game I made a few months ago over to Wii Homebrew. Does anyone know what library the sleep() function is defined in? In Windows it is defined in "windows.h". (I am using devkitPro.)

    EDIT: Also, I have a few getch() ("conio.h" in Windows) functions in my source; is there any predefined function for Wii that has a similar effect? I created two custom functions to replace the getch() but if there already is a 'standard' function for this kind of things I would like to use that. Here's the two functions I created that are supposed to have the same effect on Wii as getch() has on Windows:

    Code:
    void WaitInput() {
    ÂÂÂÂwhile (true) {
    ÂÂÂÂÂÂÂÂ// Call WPAD_ScanPads each loop, this reads the latest controller states
    ÂÂÂÂÂÂÂÂWPAD_ScanPads();
    
    ÂÂÂÂÂÂÂÂ// WPAD_ButtonsDown tells us which buttons were pressed in this loop
    ÂÂÂÂÂÂÂÂ// this is a "one shot" state which will not fire again until the button has been released
    ÂÂÂÂÂÂÂÂu32 pressed = WPAD_ButtonsDown(0);
    ÂÂÂÂÂÂÂÂ
    ÂÂÂÂÂÂÂÂ// check if any of the buttons on the Wii Remote have been pressed;
    ÂÂÂÂÂÂÂÂ// if yes break from the loop
    ÂÂÂÂÂÂÂÂif (AnyWiimoteBtnPressed(pressed)) break;
    ÂÂÂÂ}
    }
    
    bool AnyWiimoteBtnPressed(u32& pressed) {
    ÂÂÂÂif (pressed & WPAD_BUTTON_2) return true;
    ÂÂÂÂelse if (pressed & WPAD_BUTTON_1) return true;
    ÂÂÂÂelse if (pressed & WPAD_BUTTON_B) return true;
    ÂÂÂÂelse if (pressed & WPAD_BUTTON_A) return true;
    ÂÂÂÂelse if (pressed & WPAD_BUTTON_MINUS) return true;
    ÂÂÂÂelse if (pressed & WPAD_BUTTON_HOME) return true;
    ÂÂÂÂelse if (pressed & WPAD_BUTTON_LEFT) return true;
    ÂÂÂÂelse if (pressed & WPAD_BUTTON_RIGHT) return true;
    ÂÂÂÂelse if (pressed & WPAD_BUTTON_DOWN) return true;
    ÂÂÂÂelse if (pressed & WPAD_BUTTON_UP) return true;
    ÂÂÂÂelse if (pressed & WPAD_BUTTON_PLUS) return true;
    ÂÂÂÂelse return false;
    }
     
  2. WiiPower

    Member WiiPower GBAtemp Guru

    Joined:
    Oct 17, 2008
    Messages:
    8,165
    Country:
    Germany
    sleep is defined in sys/unistd.h, but what is the other function you use?
     
  3. diego_pmc
    OP

    Newcomer diego_pmc Advanced Member

    Joined:
    Sep 8, 2009
    Messages:
    52
    Country:
    United States
    Thanks!
    What other function? I'm not using anything instead of sleep() ATM. Or are you talking about getch()? If it's that, getch() pauses the execution of the console program until the user presses a key on the keyboard. I wanted to know if there is a similar standard function for Wii; if not, I'm going to use my own functions. [​IMG]
     
  4. WiiPower

    Member WiiPower GBAtemp Guru

    Joined:
    Oct 17, 2008
    Messages:
    8,165
    Country:
    Germany
    I wrote this for wii mote and GC controller:

    Code:
    void waitforbuttonpress(u32 *out, u32 *outGC)
    {
    ÂÂÂÂu32 pressed = 0;
    ÂÂÂÂu32 pressedGC = 0;
    
    ÂÂÂÂwhile (true)
    ÂÂÂÂ{
    ÂÂÂÂÂÂÂÂWPAD_ScanPads();
    ÂÂÂÂÂÂÂÂpressed = WPAD_ButtonsDown(0);
    
    ÂÂÂÂÂÂÂÂPAD_ScanPads();
    ÂÂÂÂÂÂÂÂpressedGC = PAD_ButtonsDown(0);
    
    ÂÂÂÂÂÂÂÂif(pressed || pressedGC) 
    ÂÂÂÂÂÂÂÂ{
    ÂÂÂÂÂÂÂÂÂÂÂÂif (pressedGC)
    ÂÂÂÂÂÂÂÂÂÂÂÂ{
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ// Without waiting you can't select anything
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂusleep (20000);
    ÂÂÂÂÂÂÂÂÂÂÂÂ}
    ÂÂÂÂÂÂÂÂÂÂÂÂif (out) *out = pressed;
    ÂÂÂÂÂÂÂÂÂÂÂÂif (outGC) *outGC = pressedGC;
    ÂÂÂÂÂÂÂÂÂÂÂÂreturn;
    ÂÂÂÂÂÂÂÂ}
    ÂÂÂÂ}
    }
    The usleep is necessary because you wouldn't be able to select anything as it would tell you 10 times a second that the button you pressed is pressed. The include is: sys/unistd.h.
     
  5. diego_pmc
    OP

    Newcomer diego_pmc Advanced Member

    Joined:
    Sep 8, 2009
    Messages:
    52
    Country:
    United States
    Thanks, but I don't need the user to select anything. The user is supposed to press a button when he has finished reading the text — he doesn't have to select anything. Is this what you meant?
     

Share This Page