 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
angelo
Joined: 29 Aug 2007 Posts: 168
|
Posted: Sat May 03, 2008 7:11 pm Post subject: PSP Crashes in exit. |
|
|
Hello everybody. I'm kinda new to PSP programming, and I'm stuck on this one realy anoying issue.
I've edited the piKey Sample so it works and runs in the 3.XX kernel. I've also added a callback.
The anoying thing, is that it freezes on the "Please Wait..." screen after home is pressed.
What could be wrong? I think maybe IRDA is still active and the PSP doesn't like it, but yet a callback has been added which should stop that.
Here's the code:
| Code: | #include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <string.h>
#include <pikeylib.h>
#include "../sdk/pikeytypes.h"
/* Define the module info section */
PSP_MODULE_INFO("PIKEYTEST", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
PSP_MAIN_THREAD_STACK_SIZE_KB(64);
/* Define printf, just to make typing easier */
#define printf pspDebugScreenPrintf
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int done = 0;
int blink = 0;
int main(void)
{
pspDebugScreenInit();
SetupCallbacks();
int ii;
printf("piKey Sample.\n");
initPikey();
sceKernelDelayThread(1000000);
printf("piKey is detected as %s\n", isPikeyLoaded() ? "running." : "not running.");
requestExclusive();
setMode(PIKEY_KEYMODE_KEYPRESS);
sceKernelDelayThread(1000000);
pspDebugScreenClear();
pspDebugScreenSetXY(0, 5);
printf("Waiting for keys, press ESC to exit...\n\n");
while(!done)
{
sceKernelDelayThread(1000); // don't tight-loop
sceDisplayWaitVblank();
blink += 1;
// clear old display
if(blink > 5){
pspDebugScreenClear();
blink = 0;
}
pspDebugScreenSetXY(0, 5);
printf("Waiting for keys, press 'Home' to exit...\n\n");
#if 0
pspDebugScreenSetXY(0,7);
for (ii = 7; ii < 20; ii++)
{
printf(" \n");
}
#endif
// nothing to do if no keys pressed.
if (numKeysPressed() == 0)
{
continue;
}
pspDebugScreenSetXY(0,7);
for (ii = 0; ii < KEY_MAX; ii++)
{
if (isKeyPressed(ii))
{
printf("Pressed scancode: %d\n", ii);
}
}
int ctrl, alt, shift;
getMetaKeys(&alt, &ctrl, &shift);
pspDebugScreenSetXY(0, 20);
printf(" %s %s %s\n",
ctrl? "CTRL" : " ",
alt? "ALT" : " ",
shift? "SHIFT" : " ");
}
sceKernelSleepThread();
return 0;
} |
|
|
| Back to top |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Sat May 03, 2008 7:50 pm Post subject: |
|
|
Well, for one you're creating your callback thread in kernel mode and you're not handling yielding the loop when the callback is called.
I would do something like this, not sure if it helps any or not :)
| Code: | #include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <string.h>
#include <pikeylib.h>
#include "../sdk/pikeytypes.h"
/* Define the module info section */
PSP_MODULE_INFO("PIKEYTEST", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
PSP_MAIN_THREAD_STACK_SIZE_KB(64);
int done = 0; // moved so accessible by exit_callback
/* Define printf, just to make typing easier */
#define printf pspDebugScreenPrintf
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
done = 1; // set done to 1 on callback
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0); // Changed to user mode
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int blink = 0;
int main(void)
{
pspDebugScreenInit();
SetupCallbacks();
int ii;
printf("piKey Sample.\n");
initPikey();
sceKernelDelayThread(1000000);
printf("piKey is detected as %s\n", isPikeyLoaded() ? "running." : "not running.");
requestExclusive();
setMode(PIKEY_KEYMODE_KEYPRESS);
sceKernelDelayThread(1000000);
pspDebugScreenClear();
pspDebugScreenSetXY(0, 5);
printf("Waiting for keys, press ESC to exit...\n\n");
while(!done)
{
sceKernelDelayThread(1000); // don't tight-loop
sceDisplayWaitVblank();
blink += 1;
// clear old display
if(blink > 5){
pspDebugScreenClear();
blink = 0;
}
pspDebugScreenSetXY(0, 5);
printf("Waiting for keys, press 'Home' to exit...\n\n");
#if 0
pspDebugScreenSetXY(0,7);
for (ii = 7; ii < 20; ii++)
{
printf(" \n");
}
#endif
// nothing to do if no keys pressed.
if (numKeysPressed() == 0)
{
continue;
}
pspDebugScreenSetXY(0,7);
for (ii = 0; ii < KEY_MAX; ii++)
{
if (isKeyPressed(ii))
{
printf("Pressed scancode: %d\n", ii);
}
}
int ctrl, alt, shift;
getMetaKeys(&alt, &ctrl, &shift);
pspDebugScreenSetXY(0, 20);
printf(" %s %s %s\n",
ctrl? "CTRL" : " ",
alt? "ALT" : " ",
shift? "SHIFT" : " ");
}
sceKernelExitGame(); // Exit game when loop is broken
return 0;
} |
One more thing, I'm unsure how pikey works as I've never used it, but stay out of kernel mode whenever possible. If the pikey init is all that requires kernel mode, then spawn a user mode thread after that point to handle everything else. |
|
| Back to top |
|
 |
angelo
Joined: 29 Aug 2007 Posts: 168
|
Posted: Sat May 03, 2008 8:47 pm Post subject: Broke it... |
|
|
O.K...
Now it just boots up and freezes with a black screen.
Very odd. |
|
| Back to top |
|
 |
|
|
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
|