forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

question about PSP Controller

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
alexander



Joined: 26 Jun 2008
Posts: 5

PostPosted: Thu Jun 26, 2008 6:40 am    Post subject: question about PSP Controller Reply with quote

hello there, it's a couple of days I'm learning about PSP programming.

I want to know if there is another method for reading the Controller state different from sceCtrlReadBufferPositive. I' m looking a method that can call a particular function when a key is pressed. Is there any possible implementation of this using something like an interrupt???
Back to top
View user's profile Send private message
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Thu Jun 26, 2008 9:27 am    Post subject: Reply with quote

Here, before you get attacked...

http://forums.ps2dev.org/viewtopic.php?t=10177&highlight=
_________________
If not actually, then potentially.
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Thu Jun 26, 2008 6:49 pm    Post subject: Reply with quote

http://forums.ps2dev.org/viewtopic.php?t=6973&highlight=callback
Back to top
View user's profile Send private message
jean



Joined: 05 Jan 2008
Posts: 489

PostPosted: Thu Jun 26, 2008 8:05 pm    Post subject: Reply with quote

Quote:
Here, before you get attacked...

No,no it's a good question...it's PSP related and
Code:
#define sceCtrlRegisterButtonCallback sceCtrl_driver_5C56C779
is not being used that much.
Personally i've never used it, but i guess its use is something like (cut-n-paste from a googled page):
Code:
void buttonCallback(int curr, int last, void *arg)
{
...
}
...
sceCtrlRegisterButtonCallback(3, key1 | key2, buttonCallback, NULL);

I reccomend not to use it: you always need input once per frame, so polling it with standard sceCtrlReadBufferPositive in main loop and so on will be enough, or you'll spend very much to cure your headhaches for synchronization. Consider using tricks like

Code:
oldData = data;
data = pollForData();
justPressed = data & !oldData;
justReleased = oldData & !data;


so you can do something like

Code:
if (justPressed & key1) ...


to detect button presses only once.
Happy coding.


Last edited by jean on Fri Jun 27, 2008 2:10 am; edited 1 time in total
Back to top
View user's profile Send private message
alexander



Joined: 26 Jun 2008
Posts: 5

PostPosted: Thu Jun 26, 2008 10:57 pm    Post subject: Reply with quote

thank you for your help, it seems to be what I mean.
However I can't use the API
Code:

int sceCtrl_driver_5C56C779  ( int  no, 
  unsigned int  mask, 
  void(*)(int, int, void *)  cb, 
  void *  arg   
 )

because the program doesn't start with my PSP.
Is this function working only with 1.50 kernel? And if not how must I implement it?
Back to top
View user's profile Send private message
jean



Joined: 05 Jan 2008
Posts: 489

PostPosted: Thu Jun 26, 2008 11:51 pm    Post subject: Reply with quote

Well, if you're asking how to implement a *real* interrupt-driven function, then i'm not able to drive you step by step...it's a quite tough task and requires some additional thinking! If you want to fake the behaviour of the original function at no-(thinking)cost you should create a standalone thread (search around for a thread example...there are plenty) that continuously polls (twice the vsync frequency should be enough) controller status and then calls a function (supplied with function pointer technique) when
Code:

// according to my previous snippet:
if ((data^oldData)!=0) callbackFunction(data);

But i again reccomend not to make your life difficult with asynchronous functions. If you REALLY need to process pad data asynchronously, then do all you can to make supplied function work instead of doing another that mimic it. If your async needs do born because you're in the middle of development of some vsh plugin messing with inputs, then consider learn about realtime patching.

What does compiler say when you build anyhow??
Back to top
View user's profile Send private message
alexander



Joined: 26 Jun 2008
Posts: 5

PostPosted: Fri Jun 27, 2008 12:50 am    Post subject: Reply with quote

no, the function you told me is what I need (sceCtrlRegisterButtonCallback). The problem is that I don't know how put it in my program to make it runnable on a psp slim with CF 3.90M33 (the only I have). If I use the function my psp doesn't run the program. If I comment out the call to that function the program works.
Back to top
View user's profile Send private message
hibbyware



Joined: 28 Mar 2007
Posts: 78

PostPosted: Fri Jun 27, 2008 1:23 am    Post subject: Reply with quote

As sceCtrlRegisterButtonCallback is in pspctrl_kernel.h I think you need to put it into a kernel mode prx and do the k1 thing,
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Fri Jun 27, 2008 3:30 am    Post subject: Reply with quote

hibbyware wrote:
As sceCtrlRegisterButtonCallback is in pspctrl_kernel.h I think you need to put it into a kernel mode prx and do the k1 thing,


And for that, start here: http://forums.ps2dev.org/viewtopic.php?p=58653#58653
Back to top
View user's profile Send private message AIM Address
alexander



Joined: 26 Jun 2008
Posts: 5

PostPosted: Fri Jun 27, 2008 10:59 pm    Post subject: Reply with quote

thank you very much. I' ve finally managed to make the program work. I put
the function that register the callback in the prx and the function called in the main executable. In this way it works perfectly. But I haven't understood yet what's the meaning of the first int in the sceCtrlRegisterButtonCallback that the pspsdk reference says refers to the number of the callback, but I don't know what it needs.
Back to top
View user's profile Send private message
jean



Joined: 05 Jan 2008
Posts: 489

PostPosted: Sat Jun 28, 2008 1:02 am    Post subject: Reply with quote

Don't trust me so certainly, but i guess it's similar to a techinque used in multithreading where you get a pre-specified id number back on thread start: so i guess you can get back that int in callback function somehow for identification of caller purpose.
Back to top
View user's profile Send private message
alexander



Joined: 26 Jun 2008
Posts: 5

PostPosted: Mon Jun 30, 2008 4:45 am    Post subject: Reply with quote

ok, and thank you again.
Bye
Back to top
View user's profile Send private message
SilverSpring



Joined: 27 Feb 2007
Posts: 115

PostPosted: Mon Jun 30, 2008 12:27 pm    Post subject: Reply with quote

From the thread hlide posted: http://forums.ps2dev.org/viewtopic.php?t=6973&highlight=callback

0x5E77BC8A sceCtrlGetButtonIntercept
0x7CA723DC sceCtrlSetButtonIntercept

You can rename with the real name now in sdk.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group