Load Eboot from usermode and controlling it

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

Moderators: cheriff, TyRaNiD

Post Reply
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Load Eboot from usermode and controlling it

Post by coolkehon »

first of all how do i take control of the psp like a shell does when my program is started and also how do i load an eboot from usermode and run it then if they press a key like select be able to put that eboot in the background and come back to my program like irshell does
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

See the sdk provide with the 4.01M33 firmware there is a sample to launch
a cso,iso,ps1 game from a shell program when the program end it comes back
to your shell.

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <psploadexec_kernel.h>
#include <kubridge.h>
#include <systemctrl.h>
#include <systemctrl_se.h>

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

#include "rdriver.h"


PSP_MODULE_INFO&#40;"BootLoad Test", 0x200, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER&#41;;
PSP_HEAP_SIZE_MAX&#40;&#41;;

#define printf    pspDebugScreenPrintf

void ErrorExit&#40;int milisecs, char *fmt, ...&#41;
&#123;
	va_list list;
	char msg&#91;256&#93;;	

	va_start&#40;list, fmt&#41;;
	vsprintf&#40;msg, fmt, list&#41;;
	va_end&#40;list&#41;;
	printf&#40;msg&#41;;

	sceKernelDelayThread&#40;milisecs*1000&#41;;
	sceKernelExitGame&#40;&#41;;
	asm&#40;"break\n"&#41;;
	while &#40;1&#41;;
&#125;

int WriteFile&#40;char *file, void *buf, int size&#41;
&#123;

	SceUID fd = sceIoOpen&#40;file, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777&#41;;

	if &#40;fd < 0&#41;
	&#123;
		return fd;
	&#125;
	int written = sceIoWrite&#40;fd, buf, size&#41;;
	sceIoClose&#40;fd&#41;;
	return written;
&#125;



int Dialog&#40;char *msg&#41;

&#123;
	printf&#40;"%s", msg&#41;;
	while &#40;1&#41;
	&#123;
		SceCtrlData pad;
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if &#40;pad.Buttons & PSP_CTRL_CROSS&#41;
			return 1;

		if &#40;pad.Buttons & PSP_CTRL_RTRIGGER&#41;
			return 0;
		sceKernelDelayThread&#40;50000&#41;;
	&#125;
	return -1;
&#125;



int main&#40;int argc, char *argv&#91;&#93;&#41;
&#123;

	struct SceKernelLoadExecVSHParam param;
	int apitype = 0;
	char *program = NULL;
	char *mode = NULL;
	
	pspDebugScreenInit&#40;&#41;;

	SceUID mod = sceKernelLoadModule&#40;"rdriver.prx", 0, NULL&#41;;
       if &#40;mod >= 0&#41;
	&#123;
		mod = sceKernelStartModule&#40;mod, 0, NULL, NULL, NULL&#41;;
		if &#40;mod < 0&#41;
			ErrorExit&#40;5000, "Error 0x%08X starting module.\n", mod&#41;;
	&#125;
	else
	&#123;
		if &#40;mod == SCE_KERNEL_ERROR_EXCLUSIVE_LOAD&#41;
		&#123;
			// Ignore this error, it means the module loaded on reboot
		&#125;

		else
		&#123;
			ErrorExit&#40;5000, "Error 0x%08X loading module.\n",  mod&#41;;
		&#125;
	&#125;


    printf&#40;"Press X to run homebrew at ms0&#58;/PSP/GAME/HOMEBREW/EBOOT.PBP\n"&#41;;
	printf&#40;"Press O to run UMD.\n"&#41;;
	printf&#40;"Press triangle to run iso at ms0&#58;/ISO/iso.iso in current M33 config mode.\n"&#41;;
	printf&#40;"Press square to run pops game at ms0&#58;/PSP/GAME/PSX/EBOOT.PBP.\n"&#41;;
	printf&#40;"Press select to run updater at ms0&#58;/PSP/GAME/UPDATE/EBOOT.PBP.\n"&#41;;
	printf&#40;"Press start to exit.\n\n"&#41;;
	printf&#40;"Note&#58; when you exit in one of these programs, you will return here.\n"&#41;;
	while &#40;1&#41;
	&#123;
		SceCtrlData pad;
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if &#40;pad.Buttons & PSP_CTRL_CROSS&#41;
		&#123;
			apitype = 0x141;
			program = "ms0&#58;/PSP/GAME/HOMEBREW/EBOOT.PBP";
			mode = "game";
			break;
		&#125;
		else if &#40;pad.Buttons & PSP_CTRL_CIRCLE&#41;
		&#123;
			apitype = 0x120;
			program = "disc0&#58;/PSP_GAME/SYSDIR/EBOOT.BIN";
			mode = "game";
			break;
		&#125;
		else if &#40;pad.Buttons & PSP_CTRL_TRIANGLE&#41;
		&#123;
			SEConfig config;		
			apitype = 0x120;
			program = "disc0&#58;/PSP_GAME/SYSDIR/EBOOT.BIN";
			mode = "game";
			SetUmdFile&#40;"ms0&#58;/ISO/iso.iso"&#41;;
			sctrlSEGetConfigEx&#40;&config, sizeof&#40;config&#41;&#41;;
			if &#40;config.umdmode == MODE_MARCH33&#41;
			&#123;
				SetConfFile&#40;1&#41;;
			&#125;
			else if &#40;config.umdmode == MODE_NP9660&#41;
			&#123;
				SetConfFile&#40;2&#41;;
			&#125;
			else
			&#123;
				// Assume this is is normal umd mode, as isofs will be deleted soon
				SetConfFile&#40;0&#41;;
			&#125;
			break;
		&#125;
		else if &#40;pad.Buttons & PSP_CTRL_SQUARE&#41;
		&#123;
			apitype = 0x143;
			program = "ms0&#58;/PSP/GAME/PSX/EBOOT.PBP";
			mode = "pops";
			break;
		&#125;
		else if &#40;pad.Buttons & PSP_CTRL_SELECT&#41;
		&#123;
			apitype = 0x140;
			program = "ms0&#58;/PSP/GAME/UPDATE/EBOOT.PBP";
			mode = "updater";
			break;
		&#125;
		else if &#40;pad.Buttons & PSP_CTRL_START&#41;
		&#123;
			RestoreExitGame&#40;&#41;;
			sceKernelExitGame&#40;&#41;;
		&#125;
		sceKernelDelayThread&#40;50000&#41;;
	&#125;
	sceDisplaySetHoldMode&#40;1&#41;;
	pspDebugScreenSetTextColor&#40;0x0000FF00&#41;;
	printf&#40;"\n\nLoading selection...\n"&#41;;

	memset&#40;&param, 0, sizeof&#40;param&#41;&#41;;
	param.size = sizeof&#40;param&#41;;
	param.args = strlen&#40;program&#41;+1;
	param.argp = program;
	param.key = mode;

	sctrlKernelLoadExecVSHWithApitype&#40;apitype, program, &param&#41;;
    return 0;

&#125;
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

thanks this is great but what i was asking about was like how irshell has it to where you can press L + Select to go back and forth between the loaded program how can i do that in my program
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

See google for pluggin for m33 active him for vhs,game and psx1
Dariusc123456
Posts: 388
Joined: Tue Aug 12, 2008 12:46 am

Post by Dariusc123456 »

Try to reverse the irshell prx files. Thats if you cant find the way todo so. Its not that easy todo so, including on what you are trying todo.
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

Wasn't irshell a kernel mode program?
It supposedly runs in kernel memory, which I guess is why some larger 1.50 kernel mode programs caused it to crash.
If not actually, then potentially.
Dariusc123456
Posts: 388
Joined: Tue Aug 12, 2008 12:46 am

Post by Dariusc123456 »

Yes it run in kernel mode. Ill post a example later then on how to run programs in the back ground. Its not that hard unless you want it to switch back and forth without and changes to happen. You can also output a file with some data on what or where it should be at.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

ok now i got it to load an eboot and come back too it but i was wondering using the bootload sample can some explain how it works like does the original game where the second game was launched stay in memory or exit and will it crash the psp if the original one was using alot of memory

also how can i restart the game and have it come back to it or shutdown the psp and have it come back to the game
Post Reply