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 

Intercepting home button?

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



Joined: 16 Feb 2007
Posts: 16

PostPosted: Fri Feb 16, 2007 4:36 am    Post subject: Intercepting home button? Reply with quote

Hey there,

I just got into PSP development, and I'd like to thank for all people working on the PSPSDK and especially TyRaNiD for PSPLink, it's working like a bliss even on Mac OSX and it makes development very easy. Keep on going, guys!

Now to my question:
In my application I'd like to intercept the home button, so the user can be asked if he wants to save changes to the current document, but I'm not sure what's the best way to do it. I searched the forums for a while and couldn't find any solution so I'm asking now, sorry if I've been missing something.

Or is this trivial?

Regards,
Pailes
Back to top
View user's profile Send private message Visit poster's website
jas0nuk



Joined: 27 Apr 2006
Posts: 137

PostPosted: Fri Feb 16, 2007 4:42 am    Post subject: Reply with quote

Dirty solution... don't use callbacks. This will prevent the "Do you want to exit?" screen from appearing.

When the Home button is pressed (PSP_CTRL_HOME), just pop up a screen doing whatever you want, and to exit, use sceKernelExitGame();
Back to top
View user's profile Send private message
pailes



Joined: 16 Feb 2007
Posts: 16

PostPosted: Fri Feb 16, 2007 5:54 am    Post subject: Reply with quote

I'm using sceCtrlReadBufferPositive() but it returns 0 in the button member when I press home. Do I need to enable something to make this work with the home button?
Back to top
View user's profile Send private message Visit poster's website
jas0nuk



Joined: 27 Apr 2006
Posts: 137

PostPosted: Fri Feb 16, 2007 5:59 am    Post subject: Reply with quote

This is the code I use in my projects when I want a "Press HOME to exit" prompt, I don't know what could be wrong in your code:

Code:
SceCtrlData pad_data;
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(1);
printf("Press HOME to exit\n");
while(1) {
sceCtrlReadBufferPositive(&pad_data, 1);
if (pad_data.Buttons & PSP_CTRL_HOME)
   sceKernelExitGame();
}
Back to top
View user's profile Send private message
pailes



Joined: 16 Feb 2007
Posts: 16

PostPosted: Fri Feb 16, 2007 6:23 am    Post subject: Reply with quote

Strangely, I use the same code, it doesn't work. I do not install the exit callback, that's all I do. Is it too much to ask to post a complete example code that I can compile and examine?
Back to top
View user's profile Send private message Visit poster's website
jas0nuk



Joined: 27 Apr 2006
Posts: 137

PostPosted: Fri Feb 16, 2007 6:39 am    Post subject: Reply with quote

main.c:
Code:
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspsdk.h>
#include <pspctrl.h>

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

PSP_MODULE_INFO("test", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);

#define printf pspDebugScreenPrintf

int main(void) {
   // init stuff
   pspDebugScreenInit();
   pspDebugScreenClear();

   // pad stuff
   SceCtrlData pad_data;
   sceCtrlSetSamplingCycle(0);
   sceCtrlSetSamplingMode(1);

   printf("Press X to start\n\n");
   while(1) {
      sceCtrlReadBufferPositive(&pad_data, 1);
      if (pad_data.Buttons & PSP_CTRL_CROSS) {
         break;
      }
   }
   
   printf("blah\n");

   printf("\nPress HOME to exit\n");
   while(1) {
   sceCtrlReadBufferPositive(&pad_data, 1);
   if (pad_data.Buttons & PSP_CTRL_HOME)
      sceKernelExitGame();
   }

   return 0;
}


makefile:
Code:
TARGET = out
OBJS = main.c

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = test app

INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR =
LDFLAGS =
LIBS =

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak


Hope this helps.[/code]
Back to top
View user's profile Send private message
pailes



Joined: 16 Feb 2007
Posts: 16

PostPosted: Fri Feb 16, 2007 7:10 am    Post subject: Reply with quote

Thanks for the code, it solved my problem, although I don't understand the reason yet why...

In my code I had the following macros:
Code:

PSP_MODULE_INFO("test", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);

which seemed to cause the problem, because when I changed it to
Code:

PSP_MODULE_INFO("test", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);

it worked ok. Maybe somebody can enlighten me?
Back to top
View user's profile Send private message Visit poster's website
jas0nuk



Joined: 27 Apr 2006
Posts: 137

PostPosted: Fri Feb 16, 2007 7:14 am    Post subject: Reply with quote

This changes it to kernel mode. Maybe kernel mode is needed to detect PSP_CTRL_HOME ?
Back to top
View user's profile Send private message
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Fri Feb 16, 2007 7:23 am    Post subject: Reply with quote

jas0nuk wrote:
This changes it to kernel mode. Maybe kernel mode is needed to detect PSP_CTRL_HOME ?


Yes. Some keys cannot be read by user mode.

That's why there is a vshCtrlReadBufferPositive in vshbridge, to let vsh modules read the same keys as a kernel one.
Back to top
View user's profile Send private message
pailes



Joined: 16 Feb 2007
Posts: 16

PostPosted: Fri Feb 16, 2007 7:39 am    Post subject: Reply with quote

Will it make trouble when I compile my program to run in kernel mode?
Back to top
View user's profile Send private message Visit poster's website
jas0nuk



Joined: 27 Apr 2006
Posts: 137

PostPosted: Fri Feb 16, 2007 7:41 am    Post subject: Reply with quote

No, it's often easier to work in kernel mode.
Back to top
View user's profile Send private message
pailes



Joined: 16 Feb 2007
Posts: 16

PostPosted: Fri Feb 16, 2007 7:54 am    Post subject: Reply with quote

Cool, thanks for the superfast replies :)
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