| View previous topic :: View next topic |
| Author |
Message |
pailes

Joined: 16 Feb 2007 Posts: 16
|
Posted: Fri Feb 16, 2007 4:36 am Post subject: Intercepting home button? |
|
|
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 |
|
 |
jas0nuk
Joined: 27 Apr 2006 Posts: 137
|
Posted: Fri Feb 16, 2007 4:42 am Post subject: |
|
|
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 |
|
 |
pailes

Joined: 16 Feb 2007 Posts: 16
|
Posted: Fri Feb 16, 2007 5:54 am Post subject: |
|
|
| 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 |
|
 |
jas0nuk
Joined: 27 Apr 2006 Posts: 137
|
Posted: Fri Feb 16, 2007 5:59 am Post subject: |
|
|
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 |
|
 |
pailes

Joined: 16 Feb 2007 Posts: 16
|
Posted: Fri Feb 16, 2007 6:23 am Post subject: |
|
|
| 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 |
|
 |
jas0nuk
Joined: 27 Apr 2006 Posts: 137
|
Posted: Fri Feb 16, 2007 6:39 am Post subject: |
|
|
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 |
|
 |
pailes

Joined: 16 Feb 2007 Posts: 16
|
Posted: Fri Feb 16, 2007 7:10 am Post subject: |
|
|
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 |
|
 |
jas0nuk
Joined: 27 Apr 2006 Posts: 137
|
Posted: Fri Feb 16, 2007 7:14 am Post subject: |
|
|
| This changes it to kernel mode. Maybe kernel mode is needed to detect PSP_CTRL_HOME ? |
|
| Back to top |
|
 |
moonlight
Joined: 26 Oct 2005 Posts: 567
|
Posted: Fri Feb 16, 2007 7:23 am Post subject: |
|
|
| 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 |
|
 |
pailes

Joined: 16 Feb 2007 Posts: 16
|
Posted: Fri Feb 16, 2007 7:39 am Post subject: |
|
|
| Will it make trouble when I compile my program to run in kernel mode? |
|
| Back to top |
|
 |
jas0nuk
Joined: 27 Apr 2006 Posts: 137
|
Posted: Fri Feb 16, 2007 7:41 am Post subject: |
|
|
| No, it's often easier to work in kernel mode. |
|
| Back to top |
|
 |
pailes

Joined: 16 Feb 2007 Posts: 16
|
Posted: Fri Feb 16, 2007 7:54 am Post subject: |
|
|
| Cool, thanks for the superfast replies :) |
|
| Back to top |
|
 |
|