First off to get the sceKernelExitGame function working you need to setup your main function in a thread, if you are using nem's source for hellopsp you will need to change the _start: function in startup.s. Here is an example.
Code: Select all
		.ent _start
		.weak _start
_start:
		addiu 	$sp, 0x10
		sw		$ra, 0($sp)	
		sw		$s0, 4($sp)
		sw		$s1, 8($sp)
		move	$s0, $a0				# Save args
		move	$s1, $a1
		la  	$a0, _main_thread_name	# Main thread setup
		la		$a1, xmain
		li		$a2, 0x20				# Priority
		li		$a3, 0x40000			# Stack size
		lui		$t0, 0x8000				# Attributes
		jal		sceKernelCreateThread
		move	$t1, $0
		move	$a0, $v0				# Start thread
		move	$a1, $s0
		jal		sceKernelStartThread
		move	$a2, $s1
		lw		$ra, 0($sp)
		lw		$s0, 4($sp)
		lw		$s1, 8($sp)
		move	$v0, $0
		jr 		$ra
		addiu	$sp, 0x10
_main_thread_name:
		.asciiz	"user_main"
The home button will generate a callback whenever it is pressed, but only if one is registered. If one is not registered it will do nothing at all so to do this we call sceKernelCreateCallback to make a new callback and then pass it to SetExitCallback. So...
Code: Select all
int exit_callback(void)
{
// Cleanup the games resources etc (if required)
// Exit game
	sceKernelExitGame();
	return 0;
}
#define POWER_CB_POWER		0x80000000
#define POWER_CB_HOLDON		0x40000000
#define POWER_CB_STANDBY	0x00080000
#define POWER_CB_RESCOMP	0x00040000
#define POWER_CB_RESUME		0x00020000
#define POWER_CB_SUSPEND	0x00010000
#define POWER_CB_EXT		0x00001000
#define POWER_CB_BATLOW		0x00000100
#define POWER_CB_BATTERY 	0x00000080
#define POWER_CB_BATTPOWER	0x0000007F
void power_callback(int unknown, int pwrflags)
{
	// Combine pwrflags and the above defined masks
}
// Thread to create the callbacks and then begin polling
int CallbackThread(void *arg)
{
	int cbid;
	cbid = sceKernelCreateCallback("Exit Callback", exit_callback);
	sceKernelRegisterExitCallback(cbid);
	cbid = sceKernelCreateCallback("Power Callback", power_callback);
	scePowerRegisterCallback(0, cbid);
	KernelPollCallbacks();
}
/* 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;
}
Before you ask the functions used in here are all listed in http://forums.ps2dev.org/viewtopic.php?t=1594
