PRX & Functions, Objects, variables

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

Moderators: cheriff, TyRaNiD

Post Reply
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

PRX & Functions, Objects, variables

Post by LuMo »

hi!
i had a look on the sample prx from pspsdk,
i saw that you can provide functions.
is it also possible to offer classes etc?
if so, how?

i guess varibles are passed by:
psp_export_var*

whats the diff between:
_nid and _hash

thanks in advance
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Well for a start you might want to read http://forums.ps2dev.org/viewtopic.php?t=4269 which describes how to build PRXes in PSPSDK along with descriptions of the various bits in psp-build-exports like the different between _NID and _NAME.

As for exporting C++ objects theoretically you can do it if you want to put in the time. C++ functions are exported as mangled names to the linker, the linker itself doesn't really know they are C++ functions, all it sees is a weird name which it ties with other weird names. Take for example a simple class.

Code: Select all

class Test
{
    public:
        Test();
        ~Test();
        void Hello(const char *str);
};
If you compile that then run nm on the resulting binary you find 5 symbols.

Code: Select all

00000018 T _ZN4Test5HelloEPKc
00000006 T _ZN4TestC1Ev
00000000 T _ZN4TestC2Ev
00000012 T _ZN4TestD1Ev
0000000c T _ZN4TestD2Ev
The first one is the mangled form of Test::Hello(), the next two are constructor definitions and the last two are the destructor definitions.

If you export from your application these function names they should in theory line up and you will be able to import them in your application. There are of course caveats, you probably can't externally access static variables for a start due to the way I think the PSP's variable export works, you probably cannot use exceptions, and it is pretty nasty to maintain if you change anything in your class but it should be doable.

Of course it is questionable if it is even worth it, the library import interface is abit restrictive, for example catching unresolved symbols will be abit of a nightmare, and I can't really see the biggest reason why you would necessarily want importable classes anyway, perhaps it is just me.

Have fun anyway :P
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

creating prx by adding
BUILD_PRX=1
to your makefile...
did not think its that simple
(hope i did not misunderstood that)

greets
lumo
PS: english is NOT my foreign language ;)
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

If you are using the pspsdk makefiles then yes for the most part it is that simple. For example take one of the pspsdk GU samples (say sprite), add that BUILD_PRX=1 line and rebuild it. Magically it will spit out a working PRX :)
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

so all i have to do is put up some documets which referr to the functions...

nice, now i need some beta-testers :D

greets
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Ah well of course if you are using a custom exports file you need to also set PRX_EXPORTS to exports.exp and remove any exports.o from your link line, but it is still simple :)
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

humm...
so exports... class is handled like a var?

greets
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Post Reply