Odd plugin

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

Moderators: cheriff, TyRaNiD

Post Reply
angelo
Posts: 168
Joined: Wed Aug 29, 2007 9:34 pm

Odd plugin

Post by angelo »

This is very odd...

The plugin loads IRDA.PRX fine in VSH, a Game150 mode however it fails in Game mode.

Why is this?

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <stdio.h>
#include <string.h>
#include <pspirkeyb.h>
#include <pspirkeyb_rawkeys.h>
#include "../sdk/inputdriver.h"
#include "../sdk/inputframework.h"

PSP_MODULE_INFO&#40;"piKeyIR", 0x1000, 1, 1&#41;;
PSP_NO_CREATE_MAIN_THREAD&#40;&#41;;

#define	DRIVERVER	"1"
#define REQUIREDVER	1

SceUID irthread;

int gcurrmode;

int getDriverInfo&#40;DRIVERINFO *infostruct&#41; &#123;
	strcpy&#40;infostruct->driverVersion, DRIVERVER&#41;;
	if&#40;infostruct->apiVersion < REQUIREDVER&#41; return PIKEY_ERROR_VERSION;
	else &#123;
		strcpy&#40;infostruct->driverName, "IR"&#41;;
		infostruct->apiVersion = PIKEY_THIS_VERSION;
		infostruct->unicodeSupported = FALSE;
		return PIKEY_SUCCESS;
	&#125;
&#125;

#define CONFIG_FILE  "ms0&#58;/seplugins/pikey/pspirkeyb.ini"

SceUID threadid;
void               *buffer;
SIrKeybScanCodeData scancodebuffer&#91;255&#93;;
unsigned char       vt100buffer&#91;255&#93;;

SceUID load_module&#40;const char *path, int flags, int type&#41;
&#123;
	SceKernelLMOption option;
	SceUID mpid;

	/* If the type is 0, then load the module in the kernel partition, otherwise load it
	   in the user partition. */
	if &#40;type == 0&#41; &#123;
		mpid = 1;
	&#125; else &#123;
		mpid = 2;
	&#125;

	memset&#40;&option, 0, sizeof&#40;option&#41;&#41;;
	option.size = sizeof&#40;option&#41;;
	option.mpidtext = mpid;
	option.mpiddata = mpid;
	option.position = 0;
	option.access = 1;

	return sceKernelLoadModule&#40;path, flags, type > 0 ? &option &#58; NULL&#41;;
&#125;

int main_thread&#40;SceSize args, void *argp&#41; &#123;
	int ret;
	int status;
	// We have to load the IRDA PRX if we're in VSH mode.
     if &#40;!waitForModule&#40;"sceSIRCS_IrDA_Driver"&#41;&#41;

	&#123;
		sioPrint&#40;"Need to load IRDA\r\n"&#41;;

		// load the IRDA module.
		SceUID modid = load_module&#40;"flash0&#58;/kd/irda.prx", 0, 0&#41;;
		if &#40;modid > 0&#41;
		&#123;
			ret = sceKernelStartModule&#40;modid, 0, NULL, &status, NULL&#41;;
			if &#40;ret < 0&#41;
			&#123;
				sioPrint&#40;"failed to start IRDA&#58; "&#41;;
				sioPrintWord&#40;ret&#41;;
				sioPrint&#40;"\r\n"&#41;;
				return ret;
			&#125;
		&#125;
		else
		&#123;
			sioPrint&#40;"failed to load IRDA&#58; "&#41;;
			sioPrintWord&#40;ret&#41;;
			sioPrint&#40;"\r\n"&#41;;
		  return 4;
		&#125;
	&#125;

	sioPrint&#40;"Starting libpspirkeyb\r\n"&#41;;
	ret = pspIrKeybInit&#40; CONFIG_FILE, 1 &#41;;
	if&#40; ret != PSP_IRKBD_RESULT_OK &#41;
	&#123;
		sioPrint&#40;"!! libpspirkeyb failed !!\r\n"&#41;;
		return 0;
	&#125;

	sioPrint&#40;"IR in ready.\r\n"&#41;;

	gcurrmode = -1;

	for&#40;;;&#41; &#123;	
		// avoid tight loops
		sceKernelDelayThread&#40;1000&#41;;

		// check which mode the framework is in, and switch the IR lib accordingly
		int lmode = getMode&#40;&#41;;
		if &#40;lmode != gcurrmode&#41;
		&#123;
			if &#40;lmode == PIKEY_KEYMODE_VT100STREAM&#41;
			&#123;
				pspIrKeybOutputMode&#40; PSP_IRKBD_OUTPUT_MODE_VT100 &#41;;
				buffer = vt100buffer;
			&#125;
			else if &#40;lmode == PIKEY_KEYMODE_KEYPRESS&#41;
			&#123;
				pspIrKeybOutputMode&#40; PSP_IRKBD_OUTPUT_MODE_SCANCODE &#41;;
				buffer = scancodebuffer;
			&#125;
			gcurrmode = lmode;
		&#125;

    int length, ii;

    ret = pspIrKeybReadinput&#40;buffer, &length&#41;;

		// returns 0 for success, all errors are negative
    if&#40;&#40;ret >= 0&#41; && &#40;length > 0&#41;&#41;
    &#123;
			for &#40;ii = 0; ii < length; ii++&#41;
			&#123;
				if &#40;gcurrmode == PIKEY_KEYMODE_VT100STREAM&#41;
				&#123;
					putNextChar&#40;vt100buffer&#91;ii&#93;&#41;;
				&#125;
				else if &#40;gcurrmode == PIKEY_KEYMODE_KEYPRESS&#41;
				&#123;
					sendKeyPress&#40;scancodebuffer&#91;ii&#93;.raw,
									     scancodebuffer&#91;ii&#93;.pressed,
											 scancodebuffer&#91;ii&#93;.shift,
											 scancodebuffer&#91;ii&#93;.ctrl,
											 scancodebuffer&#91;ii&#93;.alt&#41;;
				&#125;
			&#125;
    &#125;
	&#125;

	return 0;
&#125;

// called by module_start
int main&#40;void&#41; &#123;
	threadid = sceKernelCreateThread&#40;"IRumode", main_thread, 16, 0xA000, 0, NULL&#41;;
	if &#40;threadid >= 0&#41; sceKernelStartThread&#40;threadid, 0, NULL&#41;;
	else return threadid;

	return 0;
&#125;

SceSize sceKernelMaxFreeMemSize&#40;&#41;
&#123;
	return 0x4000;
&#125;

Smong
Posts: 82
Joined: Tue Sep 04, 2007 4:44 am

Post by Smong »

One reason why something would work in game150 and not game would be an incorrect use of kernel mode.
(+[__]%)
angelo
Posts: 168
Joined: Wed Aug 29, 2007 9:34 pm

Thanks...

Post by angelo »

Thanks for that but that doesn't actually help!

I can feel that it's only a small change but I can't see where!

Help please?

Angelo
pspZorba
Posts: 156
Joined: Sat Sep 22, 2007 11:45 am
Location: NY

Post by pspZorba »

what is your firmware version?

could you provide the makefile?
--pspZorba--
NO to K1.5 !
angelo
Posts: 168
Joined: Wed Aug 29, 2007 9:34 pm

Post by angelo »

I'm on the latest M33 firmware 4.01 M33... no 1.50 addon kernel but I know this works in 1.50 mode.

Makefile:

Code: Select all

TARGET = piKeyIR
OBJS = main.o

BUILD_PRX=1
PRX_EXPORTS=exports.exp

USE_KERNEL_LIBS = 1
USE_PSPSDK_LIBC = 0

INCDIR =
CFLAGS = -O0 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
LIBS=-lpspirkeyb
include $&#40;PSPSDK&#41;/lib/build.mak
LIBS += ../sdk/framework_stub.o -lpsppower_driver -lpspkernel -lpsphprm_driver
pspZorba
Posts: 156
Joined: Sat Sep 22, 2007 11:45 am
Location: NY

Post by pspZorba »

I wasn't able to compile your code ( I miss some file like "../sdk/inputdriver.h" and "../sdk/inputframework.h" )

But I made a simple test:

A prx in kernel mode with one function that loads and starts irda.prx, using your code: SceUID load_module(const char *path, int flags, int type) .


and an eboot in user mode that loads my prx and call the function that loads "flash0:/kd/irda.prx"

well this returns me a valid handle meaning that irda.prx has been loaded and started....


what are the code returned by either load_module and sceKernelStartModule by your HB?
--pspZorba--
NO to K1.5 !
angelo
Posts: 168
Joined: Wed Aug 29, 2007 9:34 pm

Post by angelo »

This is a PRX. I know it works fine, it works perfectly in VSH and Game150, just just not Game3.XX/4.XX.

It's very odd!
pspZorba
Posts: 156
Joined: Sat Sep 22, 2007 11:45 am
Location: NY

Post by pspZorba »

I know it is a prx, my quick test was a prx too and it works under GAME.

So what are the error codes ?
--pspZorba--
NO to K1.5 !
angelo
Posts: 168
Joined: Wed Aug 29, 2007 9:34 pm

Post by angelo »

It compiles fine! It just doesn't load IRDA when in Game mode!

The plugin will only work if I add IRDA in SEPlugins/Game.txt

Very odd!

Thanks for the help!

Angelo
angelo
Posts: 168
Joined: Wed Aug 29, 2007 9:34 pm

Post by angelo »

So what's stopping it from loading irda.prx in Game4.XX mode?

Anybody got any ideas?
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Nothing, didn't read well :)

Anyways, can you post what loadmodule and startmodule are returning when loading irda.prx?
angelo
Posts: 168
Joined: Wed Aug 29, 2007 9:34 pm

Nothing!

Post by angelo »

It doesn't return with anything!

Just to keep in mind this module is loaded by the main engine piKey.PRX.

Actually I'll change the SIO output to displayStatusText and I'll have another look when I get a chance.

Thanks Moonlight!

Angelo
angelo
Posts: 168
Joined: Wed Aug 29, 2007 9:34 pm

Interesting

Post by angelo »

OK here's some intersting facts:

- piKey will not load at all when in GAME 4.XX mode. No debug messages appear... nothing.

- When "flash0:/kd/irda.prx" is added to Game.txt, piKey works in game and all messages appear.

Moonlight, how do your Game, VSH, POPS and Game150 work? My plugin works when I force start the module into a txt file.

Any ideas please?

Angelo
Post Reply