modular application

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

Moderators: cheriff, TyRaNiD

Post Reply
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

modular application

Post by phobox »

i want to build a modular application base on various modules, like vsh.
Graphic library will be vlf.

i thought to load modules (in this example Plugin.prx) and call functions stored inside those.

this is the situation:
main module that loads all other submodules + vlf lib.
calling vlf functions from inside the main module is (ofcourse) everything ok.
BUT if i try to call a vlf function from a submodule it doesn't work.

here the main module (main.c)

Code: Select all

#include <pspkernel.h>
#include <pspctrl.h>
#include <pspsdk.h>
#include <string.h>
#include <vlf.h>

PSP_MODULE_INFO&#40;"VLF_demo", 0x800, 2, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

int addText&#40;&#41;;

int OnCrossPress&#40;void *param&#41;
&#123;
	sceKernelExitGame&#40;&#41;;
	return VLF_EV_RET_REMOVE_HANDLERS;
&#125;
int OnSquarePress&#40;void *param&#41;
&#123;
	addText&#40;&#41;;
	return VLF_EV_RET_NOTHING;
&#125;



int app_main&#40;&#41;
&#123;
	void *bi;
	


	//vlfGuiSetBackgroundPlane&#40;0xFF000000&#41;;
	vlfGuiSetBackgroundSystem&#40;0&#41;;


	vlfGuiCacheResource&#40;"system_plugin"&#41;;
	vlfGuiCacheResource&#40;"system_plugin_fg"&#41;;

	vlfGuiSetModelSystem&#40;&#41;;
	vlfGuiAddBatteryIconSystem&#40;&bi, 10*1000*1000&#41;;
	vlfGuiAddClock&#40;&#41;;

	vlfGuiAddEventHandler&#40;PSP_CTRL_CROSS, -1, OnCrossPress, NULL&#41;;
	vlfGuiAddEventHandler&#40;PSP_CTRL_SQUARE, -1, OnSquarePress, NULL&#41;;
	

	
	while &#40;1&#41;
	&#123;
		vlfGuiDrawFrame&#40;&#41;;
	&#125;	

   	return 0;
&#125;
here the makefile of main module

Code: Select all

release&#58; all
	psppacker 400I VLF_Sample.prx

TARGET = VLF_Sample
OBJS = crt0.o main.o Plugin.o

INCDIR = ./include
CFLAGS = -O2 -G0 -Wall -fshort-wchar -fno-pic -mno-check-zero-division 
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41; -c

LIBDIR = ./lib
LDFLAGS = -mno-crt0 -nostdlib -nodefaultlibs
LIBS = -lvlfgui -lvlfgu -lvlfutils -lvlflibc



BUILD_PRX = 1

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Vlf Sample

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include ./build.mak
here crt0.c (main module)

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <kubridge.h>

#include <stdio.h>
#include <vlf.h>

extern int app_main&#40;int argc, char *argv&#91;&#93;&#41;;

int start_thread&#40;SceSize args, void *argp&#41;
&#123;
	SceUID mod;	
	char *path = &#40;char*&#41; argp;
	int last_trail = -1;
	int i;
	
	if&#40;path&#41;
	&#123;
		for&#40;i=0; path&#91;i&#93;; i++&#41;
		&#123;
			if&#40;path&#91;i&#93; == '/'&#41;
				last_trail = i;
		&#125;
	&#125;
	
	if &#40;last_trail >= 0&#41;
		path&#91;last_trail&#93; = 0;
	
	sceIoChdir&#40;path&#41;;
	path&#91;last_trail&#93; = '/';
	

	mod = sceKernelLoadModule&#40;"iop.prx", 0, NULL&#41;;
	mod = sceKernelStartModule&#40;mod, args, argp, NULL, NULL&#41;;
	mod = sceKernelLoadModule&#40;"intraFont.prx", 0, NULL&#41;;
	mod = sceKernelStartModule&#40;mod, args, argp, NULL, NULL&#41;;
	mod = sceKernelLoadModule&#40;"vlf.prx", 0, NULL&#41;;
	mod = sceKernelStartModule&#40;mod, args, argp, NULL, NULL&#41;;
	mod = sceKernelLoadModule&#40;"Plugin.prx", 0, NULL&#41;;
	mod = sceKernelStartModule&#40;mod, args, argp, NULL, NULL&#41;;
	vlfGuiInit&#40;-1, app_main&#41;;
	
	return sceKernelExitDeleteThread&#40;0&#41;;
&#125;

int module_start&#40;SceSize args, void *argp&#41;
&#123;
	SceUID thid = sceKernelCreateThread&#40;"start_thread", start_thread, 0x10, 0x4000, 0, NULL&#41;;
	if &#40;thid < 0&#41;
		return thid;

	sceKernelStartThread&#40;thid, args, argp&#41;;
	
	return 0;
&#125;
now the submodules,
in this case a module called Plugin.prx that SHOULD display a text on the screen but it doesn't work (lol)

main.c

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <vlf.h>

PSP_MODULE_INFO&#40;"Plugin", 0x1006, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

u32 k1;

int addText&#40;&#41;&#123;
    k1 = pspSdkSetK1&#40;0&#41;;
    vlfGuiAddText&#40;200, 10, "Please display this!"&#41;;
    pspSdkSetK1&#40;k1&#41;;
    return 0;
&#125;


int module_start&#40;SceSize args, void *argp&#41;
&#123;
   return 0;
&#125;

int module_stop&#40;&#41;
&#123;
   return 0;
&#125;
the makefile

Code: Select all

TARGET = Plugin
OBJS = main.o

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

BUILD_PRX = 1
PRX_EXPORTS = exports.exp

USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1

LIBDIR =
LDFLAGS = -mno-crt0 -nostartfiles
LIBS = -lvlfgui -lvlfgu -lvlfutils -lvlflibc


PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak 
the exports

Code: Select all

# Define the exports for the prx
PSP_BEGIN_EXPORTS

# These four lines are mandatory &#40;although you can add other functions like module_stop&#41;
# syslib is a psynonym for the single mandatory export.
PSP_EXPORT_START&#40;syslib, 0, 0x8000&#41;
PSP_EXPORT_FUNC_HASH&#40;module_start&#41;
PSP_EXPORT_VAR_HASH&#40;module_info&#41;
PSP_EXPORT_END

# Export our function
PSP_EXPORT_START&#40;Plugin, 0, 0x4001&#41;
PSP_EXPORT_FUNC&#40;addText&#41;
PSP_EXPORT_END

PSP_END_EXPORTS

please try to help me solve this problem.
Ciao! from Italy
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

You are calling an user function (vlfGuiAddText), from a kernel module. And that doesn't work, the kernel won't ever resolve the library.
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

moonlight wrote:You are calling an user function (vlfGuiAddText), from a kernel module. And that doesn't work, the kernel won't ever resolve the library.
so if i convert the kernel module to an user one it will work? i'll try it now
thanks.

EDIT: still don't work.

I changed:
PSP_MODULE_INFO("Plugin", 0, 1, 1);
removed k1 stuff
removed
USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1

PSP_EXPORT_START(Plugin, 0, 0)

what else should i do?
Ciao! from Italy
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

sorry for double post.
don't know why i changed PSP_EXPORT_START(Plugin, 0, 0) ...

it should be PSP_EXPORT_START(Plugin, 0, 0x0001) cause a user module is loading an user module.

now i'll try

edit: it is working! i think i was drunk when i changed the params of PSP_EXPORT_START...
Ciao! from Italy
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

0x0001 -> export to modules with same privileges (resolved with jumps)
0x4001 -> export from kernel to user (resolved with syscalls)
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

moonlight wrote:0x0001 -> export to modules with same privileges (resolved with jumps)
0x4001 -> export from kernel to user (resolved with syscalls)
yeah yeah i know.. i read it from the module tuto from this site. thanks anyway...

now a bug for you...
Image

look at the shadow of the battery...

the title bar is called by the plugin module...
Ciao! from Italy
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

What is the code? Have you tried to add the battery icon yourself without using vlfGuiAddBatteryIcon?
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

Ciao! from Italy
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

The problem is this: vlfGuiSetTitleBar(u, 0, 1, 0);

when it should be vlfGuiSetTitleBar(u, -1, 1, 0);

0 is a valid handler for a picture, and was assigned to the battery shadow internally when calling vlfGuiAddBatteryIconSystem.
phobox
Posts: 127
Joined: Mon Mar 24, 2008 6:22 pm

Post by phobox »

thanks

now i have another problem, it seems that module_start function is not called when the module is started. in that function i load texts and pictures but they result not loaded.

is the problem when loading/starting module?
Ciao! from Italy
Post Reply