| View previous topic :: View next topic |
| Author |
Message |
alexander
Joined: 26 Jun 2008 Posts: 5
|
Posted: Thu Jun 26, 2008 6:40 am Post subject: question about PSP Controller |
|
|
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 |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
|
| Back to top |
|
 |
jean

Joined: 05 Jan 2008 Posts: 489
|
Posted: Thu Jun 26, 2008 8:05 pm Post subject: |
|
|
| 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 |
|
 |
alexander
Joined: 26 Jun 2008 Posts: 5
|
Posted: Thu Jun 26, 2008 10:57 pm Post subject: |
|
|
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 |
|
 |
jean

Joined: 05 Jan 2008 Posts: 489
|
Posted: Thu Jun 26, 2008 11:51 pm Post subject: |
|
|
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 |
|
 |
alexander
Joined: 26 Jun 2008 Posts: 5
|
Posted: Fri Jun 27, 2008 12:50 am Post subject: |
|
|
| 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 |
|
 |
hibbyware
Joined: 28 Mar 2007 Posts: 78
|
Posted: Fri Jun 27, 2008 1:23 am Post subject: |
|
|
| 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 |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Fri Jun 27, 2008 3:30 am Post subject: |
|
|
| 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 |
|
 |
alexander
Joined: 26 Jun 2008 Posts: 5
|
Posted: Fri Jun 27, 2008 10:59 pm Post subject: |
|
|
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 |
|
 |
jean

Joined: 05 Jan 2008 Posts: 489
|
Posted: Sat Jun 28, 2008 1:02 am Post subject: |
|
|
| 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 |
|
 |
alexander
Joined: 26 Jun 2008 Posts: 5
|
Posted: Mon Jun 30, 2008 4:45 am Post subject: |
|
|
ok, and thank you again.
Bye |
|
| Back to top |
|
 |
SilverSpring
Joined: 27 Feb 2007 Posts: 115
|
|
| Back to top |
|
 |
|