Detecting one button input each time

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
zydeoN
Posts: 45
Joined: Sat May 09, 2009 4:01 am

Detecting one button input each time

Post by zydeoN »

Is there a way of saying:
If(square is pressed and the others buttons are not being pressed) then...
?

Help
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

Yeah, the value of pad.button will be unique if only square is pressed.
Look at the value of pad.buttons.
If not actually, then potentially.
zydeoN
Posts: 45
Joined: Sat May 09, 2009 4:01 am

Post by zydeoN »

but the problem is that if i only put:
if(square pressed) {...}

and if im pressing square and say triangle the code inside the brackets of the if statement is processed anyway and im pressing triangle too...
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

dont use & but do it this way.

Code: Select all

if(pad.buttons == PSP_CTRL_BUTTON_SQUARE){
    //do something
}
I think this should be it or something like this.

Code: Select all

int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
zydeoN
Posts: 45
Joined: Sat May 09, 2009 4:01 am

Post by zydeoN »

It doesnt work jojoris
EDIT: Solved. I just had to do:
if(pad.Buttons & PSP_CTRL_RTRIGGER && !(pad.Buttons & PSP_CTRL_SQUARE)) {...}

and this would only be processed if the user didnt press square..
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Re: Detecting one button input each time

Post by Torch »

zydeoN wrote:Is there a way of saying:
If(square is pressed and the others buttons are not being pressed) then...
?

Help
This logic is very different from your solution of if Only Square is NOT pressed.
zydeoN
Posts: 45
Joined: Sat May 09, 2009 4:01 am

Post by zydeoN »

I will just had to add this !(pad.Buttons & ...) to all the buttons.
Btw, why isnt this working:

int pad_ = 0x100000;
if(pad.Buttons & pad_) {...}

The inside of the brackets isnt being processed. I know this uses a bit mask, but they say Buttons is unsigned int. So the problem here could be the type of pad_. What could it be ?

EDIT: just had to use u32 instead of int.
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

actuallt u32 is the same as unsigned int

Code: Select all

u32 i = 0;
unsigned int = 0;
both the same.

Code: Select all

int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

zydeoN wrote:I will just had to add this !(pad.Buttons & ...) to all the buttons.
Btw, why isnt this working:

int pad_ = 0x100000;
if(pad.Buttons & pad_) {...}

The inside of the brackets isnt being processed. I know this uses a bit mask, but they say Buttons is unsigned int. So the problem here could be the type of pad_. What could it be ?

EDIT: just had to use u32 instead of int.
Anything above 0x8000 is kernel only. You won't ever see 0x100000 at user level. That's why there's a kernel PRX floating around to let user mode homebrew check the HOME button.
jsharrad
Posts: 100
Joined: Thu Oct 20, 2005 3:06 am

Post by jsharrad »

huh? isn't u32 pad_ = 0x100000 just the same as doing u32 pad_ = 1048576 ?

Unless you were thinking of memory addresses ... &0x100000
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

J.F. wrote:
zydeoN wrote:I will just had to add this !(pad.Buttons & ...) to all the buttons.
Btw, why isnt this working:

int pad_ = 0x100000;
if(pad.Buttons & pad_) {...}

The inside of the brackets isnt being processed. I know this uses a bit mask, but they say Buttons is unsigned int. So the problem here could be the type of pad_. What could it be ?

EDIT: just had to use u32 instead of int.
Anything above 0x8000 is kernel only. You won't ever see 0x100000 at user level. That's why there's a kernel PRX floating around to let user mode homebrew check the HOME button.
I don't understand what you're trying to say here. I doubt the mask values of the buttons are related to any of the memory addresses (and whether or not those buttons are readable under user or kernel mode; Those buttons must be permanently masked by software in the syscall version of the functions, thats all). Anything above 0x7FFFFFFF is kernel (the upper 2GiB of the 4GiB of memory addresses the CPU can access).

Unless I've completely missed a point somewhere =.=*
SilverSpring
Posts: 110
Joined: Tue Feb 27, 2007 9:43 pm
Contact:

Post by SilverSpring »

He is saying the button masks above 0x8000 (ie. the volume up/down, note, screen, etc. buttons) can only be read in kernel mode. Only the the normal keypad buttons (of which are masked to values under 0x8000) are readable when under user mode. It has nothing to do with memory addresses.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

SilverSpring wrote:He is saying the button masks above 0x8000 (ie. the volume up/down, note, screen, etc. buttons) can only be read in kernel mode. Only the the normal keypad buttons (of which are masked to values under 0x8000) are readable when under user mode. It has nothing to do with memory addresses.
Ok that way... They just got lucky they could split it up like that since the PSP has a limited number of buttons :/
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

SilverSpring wrote:He is saying the button masks above 0x8000 (ie. the volume up/down, note, screen, etc. buttons) can only be read in kernel mode. Only the the normal keypad buttons (of which are masked to values under 0x8000) are readable when under user mode. It has nothing to do with memory addresses.
What he said. Sorry if that confused people. I meant the values that represent individual buttons in the .Buttons field. Those are defined in the pspctrl.h file. 0x0001 to 0x8000 are "normal" buttons like X, O, LTRIGGER, START, etc. Anything from 0x10000 on up are the "extra" buttons on the PSP like HOME, VOLUME_UP, NOTE, etc.

Every once in a while, you'll see someone complain that their loop waiting on the NOTE button doesn't work, and they're confused since old homebrew had no trouble with that. The old homebrew ran in kernel mode, so NOTE was visible. New homebrew is usually user mode, and so it cannot see that button and the loop waits forever.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

moonlight should have added it to kubridge in the very beginning, it would have been really useful.
Post Reply