Prxes in C++ with libraries (OSLib)

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

Prxes in C++ with libraries (OSLib)

Post by coolkehon »

I posted this on another forum and no one could help me so i was hoping i could get some help here i've been trying to change my program in progress over to use prx's where possible like large games (umds) do so that i can conserve memory and update it easily when necessary through the program but i got this error after i included oslib and linked it

Code: Select all

C:/pspsdk/psp/sdk/lib\libpsplibc.a(glue__sbrk.o): In function `_sbrk':
../../../../pspsdk/src/libc/libcglue.c:95: undefined reference to `sceKernelMaxF
reeMemSize'
How can i fix this and when i include this -lpspuser or -lpspsysmem_user when i try to load it in a test i get this error 8002013C

Here is the makefile

Code: Select all

TARGET = mylib
OBJS = main.o 

# Use the kernel's small inbuilt libc
USE_KERNEL_LIBC = 1
# Use only kernel libraries
USE_KERNEL_LIBS = 1

INCDIR = 
CFLAGS = -O2 -G0 -Wall -fno-builtin-printf
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR =

PRX_EXPORTS = mylib.exp 

STDLIBS = -losl -lpspgu -lpspge -lpspaudio -lpsppower -lpsplibc 
#-losl -mp3 -lmikmod -lpng -lz  
# STDLIBS += -lpspctrl -lpspumd -lpsprtc -lpsppower 
# STDLIBS += -lpspgu -lpspaudiolib -lpspaudio 
# STDLIBS += -lmikmod -lm -lc -lstdc++ -lpspmpeg -lpsprtc
# STDLIBS += -lpspaudiocodec -lpspatrac3 -lpspdisplay_driver 
# STDLIBS += -lpspge -lpspsysmem_kernel -lpspkernel

LIBS = $(STDLIBS) 

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build_prx.mak
main.c

Code: Select all

#include <pspkernel.h>
#include <stdio.h>
#include <oslib/oslib.h>
#include <malloc.h>

PSP_MODULE_INFO&#40;"template", PSP_MODULE_KERNEL, 1, 1&#41;;

int main_thread&#40;SceSize args, void *argp&#41;
&#123;
	printf&#40;"Hello World\n"&#41;;

	return 0;
&#125;
void startDrawing&#40;void&#41;
&#123;
	oslInit&#40;0&#41;;
	oslInitGfx&#40;OSL_PF_8888,1&#41;;
	oslDebug&#40;"prx loaded and osl inited from main"&#41;;

	while&#40;!osl_quit&#41;
	&#123;
		oslStartDrawing&#40;&#41;;
		oslDrawFillRect&#40;0,0,100,100,RGB&#40;255,0,0&#41;&#41;;
		oslEndDrawing&#40;&#41;;
		oslSyncFrame&#40;&#41;;
	&#125;
&#125;

/* Entry point */
int module_start&#40;SceSize args, void *argp&#41;
&#123;
	int thid;

	thid = sceKernelCreateThread&#40;"template", main_thread, 7, 0x800, 0, NULL&#41;;
	if&#40;thid >= 0&#41;
	&#123;
		sceKernelStartThread&#40;thid, args, argp&#41;;
	&#125;
	return 0;
&#125;

/* Module stop entry */
int module_stop&#40;SceSize args, void *argp&#41;
&#123;
	return 0;
&#125;
hope this isnt to much if so i can remove some new to boards
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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

Post by coolkehon »

that sample doesnt use any libraries i need to use oslib in it can you explain how i can use that to help mabye a sample or something
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

coolkehon wrote:that sample doesnt use any libraries i need to use oslib in it can you explain how i can use that to help mabye a sample or something
The process for using user mode prxs is the same as with kernel mode prxs, it's just one uses kernel mode and the other doesn't. Just change the prx mode in the example to user mode (so don't use kernel mode calls or the SetK1 calls), and change it to load into user memory instead of kernel memory. Everything else should be the same. Be sure to leave space in the user memory for the prx and its heap (using PSP_HEAP_SIZE_MAX() will prevent user prxs from being able to load as they won't have any memory).
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

no what i'm trying to do is load a prx then call a function in the prx that uses oslib so the prx uses oslib sakya already gave me that example and when i included oslib i got that error here is The sample could someone take a look at it and see why it doesnt compile[/url]
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Okay, I'll look it over and see what's what. :)

EDIT: Okay, the sample you have needed some fixing. It was trying to make a kernel mode prx out of the library. Here's my working code:

http://www.mediafire.com/download.php?dss3itmelre

It's now a user prx loaded into user memory. I modified the oslib test code in the prx to clear the screen properly and to move the rect around via the dpad. Remember that the prx doesn't know where anything in the main app is. If you want the prx to operate on vars/structs in the main app, be sure to pass a pointer to them.

Anywho, as both the app and the prx are user mode, I modified the export table to use direct jumps for the functions. That should be faster anyway.

You only need to "psp-build-exports -s exports.exp" and copy the resulting S file to the main app directory to use the prx. The other S file you were making isn't needed. I also set it to not create a thread in the prx, so module_start/stop will be called on the main app thread.

Note that this is really the basis for "DLL" type libs on the PSP. Not many devs use them, but they could be handy in a number of cases. For example, if you used a prx like this to do the dynamic recompiling on an emu, you could replace just the prx on updates instead of the whole emulator.

To try the code as it is in the arc, just copy the EBOOT.PBP from the "KJA PDA Prx" directory and the testlib.prx from the "Test Prx" directory into a folder in GAME4XX (for 4.01M33). If you don't copy the testlib.prx file, you'll get an error message stating it couldn't be loaded and the app will exit. If it works, you'll get the osl debug alert, then if you press X, you'll get a red square that you can move around with the dpad. Use Home to exit.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

thank you so much you dont know how long i've been trying to get this working/fixed now one more question what if i want the prx to be able to use kernel function so like a kernel 0x1000 module flags will that work and also how can i send arguments to the prx mabye args[] will work
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Use a separate prx for kernel functions. That prx can be made and loaded just like the example I linked above from the old OE SDK. However, I'd recommend against using kernel functions. There's no reason for using them beyond something like using the MediaEngine. Something like that is best not mixed with a user library for rendering or such as well.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

i needed it to read controls and i wanna split my code up into prx's so that i can load and unload memory cause this is probably gonna become a big thing trying to put windows on psp and making it easy to update using prx's
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

coolkehon wrote:i needed it to read controls and i wanna split my code up into prx's so that i can load and unload memory cause this is probably gonna become a big thing trying to put windows on psp and making it easy to update using prx's
Unless you need to read the Home/Volume/Display/Sound buttons, just use the user control functions. If you DO need to read Home/etc, look at the prx already out that reads Home. You'll find it with the 3.xx version of SNES9x, among other places.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

well i already made one and it works i even got pressed and other functions
Post Reply