question about PSP Controller

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

Moderators: cheriff, TyRaNiD

Post Reply
alexander
Posts: 5
Joined: Thu Jun 26, 2008 6:29 am

question about PSP Controller

Post by alexander »

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???
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

If not actually, then potentially.
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

Here, before you get attacked...
No,no it's a good question...it's PSP related and

Code: Select all

#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: Select all

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: Select all

oldData = data;
data = pollForData();
justPressed = data & !oldData;
justReleased = oldData & !data;
so you can do something like

Code: Select all

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.
alexander
Posts: 5
Joined: Thu Jun 26, 2008 6:29 am

Post by alexander »

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

Code: Select all

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?
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

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: Select all

// 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??
alexander
Posts: 5
Joined: Thu Jun 26, 2008 6:29 am

Post by alexander »

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.
hibbyware
Posts: 78
Joined: Wed Mar 28, 2007 10:29 am

Post by hibbyware »

As sceCtrlRegisterButtonCallback is in pspctrl_kernel.h I think you need to put it into a kernel mode prx and do the k1 thing,
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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
alexander
Posts: 5
Joined: Thu Jun 26, 2008 6:29 am

Post by alexander »

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.
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

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.
alexander
Posts: 5
Joined: Thu Jun 26, 2008 6:29 am

Post by alexander »

ok, and thank you again.
Bye
SilverSpring
Posts: 110
Joined: Tue Feb 27, 2007 9:43 pm
Contact:

Post by SilverSpring »

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

0x5E77BC8A sceCtrlGetButtonIntercept
0x7CA723DC sceCtrlSetButtonIntercept

You can rename with the real name now in sdk.
Post Reply