Advertising (This ad goes away for registered users. You can Login or Register)

Menu API and cascading menus

This is the development forum of the half-byte loader project. For general Half Byte Loader questions, visit the Half Byte Loader forum.
Forum rules
This forum is for HBL Development discussions ONLY. For User support or HBL general discussions, go to viewforum.php?f=3 . Messages that are not development related will be deleted.
User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Menu API and cascading menus

Post by m0skit0 » Tue Dec 14, 2010 10:34 pm

I wouldn't return void on functions. It's better to return an unsigned int as Sony does, just to keep the protocol. Doesn't really matter for hblRequestQuitToXmb.
JJS wrote:hblSetNextHomebrew
Why not hblSetNextExec better? More generic. Also const char* path goes better on the parameter.
JJS wrote:hblGetCreditsString
JJS wrote:hblGetVersionName
I would declare better an exported constant for these,instead of a function. Otherwise I would try to remove that max_size argument, feels a bit unnatural for me. Maybe another call that returns the size of the strings. Or the HBL function itself allocates the needed space and returns a pointer (worst option so far IMO).
Advertising
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

User avatar
neur0n
Guru
Posts: 46
Joined: Tue Sep 28, 2010 2:52 am
Contact:

Re: Menu API and cascading menus

Post by neur0n » Wed Dec 15, 2010 8:37 am

JJS wrote: Anyway, are there comments about the API itself?
Edit: I noticed that a way to get the default path is missing. How about "void hblGetHomebrewPath(char* path)".
Why not edit hblGet~ functions like this?

before

Code: Select all

void hblGetHomebrewPath(char* path);
unsigned int hblGetCreditsString(char* credits, unsigned int max_size);
unsigned int hblGetVersionName(char* version, unsigned int max_size);
after

Code: Select all

char* hblGetHomebrewPath(void);
char* hblGetCreditsString(void);
char* hblGetVersionName(void);
Advertising
I have two Savedata Exploit.
One is Monster Hunter :)

JJS
Big Beholder
Posts: 1416
Joined: Mon Sep 27, 2010 2:18 pm
Contact:

Re: Menu API and cascading menus

Post by JJS » Wed Dec 15, 2010 8:48 am

m0skit0 wrote:I wouldn't return void on functions. It's better to return an unsigned int as Sony does, just to keep the protocol. Doesn't really matter for hblRequestQuitToXmb.
Ok. So the return codes should be Sony style? That is >= 0 for success and < 0 for error.
m0skit0 wrote:I would declare better an exported constant for these,instead of a function. Otherwise I would try to remove that max_size argument, feels a bit unnatural for me. Maybe another call that returns the size of the strings. Or the HBL function itself allocates the needed space and returns a pointer (worst option so far IMO).
I wasn't sure how to do this. Initially I thought of having only one function that gives a pointer to a struct for HBL to fill out (like the current menu api), but that would be hard to make future proof in case there should be more values passed someday. So I made a function for each string.

I must admit that I don't know how a variable import is handled usually. But I guess that an imported variable is not copied over to the importing module, but instead the variable points into the module that exports the variable. If so this sounds like a hack to me and is not really different from the last method you mentioned (that you think is the worst and I agree).

As for the separate "getSize" function I am torn. While it is more flexible to have them (since you can call it and then allocate a right sized buffer) I think they are less safe for use by the average lazy programmer. If you give the correct max size a buffer can hold (and I doubt anyone would "lie" here) then the callee will never write past the buffers bounds.


Fake edit: I again took too long to write my reply :D :
neur0n wrote:Why not edit hblGet~ functions like this?
I would rather copy the strings instead of exposing them directly with a pointer. This adds some protection against the homebrew messing around in HBLs memory.

User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Menu API and cascading menus

Post by m0skit0 » Wed Dec 15, 2010 9:31 am

@neur0n: I already pointed that ;)
m0skit0 wrote:I would declare better an exported constant for these,instead of a function
m0skit0 wrote: Or the HBL function itself allocates the needed space and returns a pointer (worst option so far IMO).
JJS wrote:Ok. So the return codes should be Sony style? That is >= 0 for success and < 0 for error.
Yup
JJS wrote:I must admit that I don't know how a variable import is handled usually. But I guess that an imported variable is not copied over to the importing module, but instead the variable points into the module that exports the variable. If so this sounds like a hack to me and is not really different from the last method you mentioned (that you think is the worst and I agree).
It's different on the interfacing (direct access versus API wrapper). And PSP's kernel architecture makes that work this way, I mean, some modules also export variables and they do it this way. Blame Sony :lol: . My point here is that how's the programmer gonna know how much space he needs for the buffer to have the whole string? I mean, how long are those strings? :? There should be at least a function for the size, although IMO doing it the Sony way (exporting the variable) is the right way to go, just to keep the protocol/convention used. This can be done through a function wrap if you wish.
JJS wrote: would rather copy the strings instead of exposing them directly with a pointer. This adds some protection against the homebrew messing around in HBLs memory.
Well, I agree with your point, but Sony likes to do it this way. I'm comfortable with your POV though.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

JJS
Big Beholder
Posts: 1416
Joined: Mon Sep 27, 2010 2:18 pm
Contact:

Re: Menu API and cascading menus

Post by JJS » Thu Dec 16, 2010 9:28 am

I looked around for information on how to use a variable import and there is nothing to be found. Well, except for an interesting thread from 2005 on ps2dev.org, this post and the answer by TyRaNiD makes me believe that there is no way to use variable exports/imports with the SDK. I don't think anything has changed in that regard since then. The exports for syslib are probably hacked in somwhere.

So it is

Code: Select all

char* hblGetHomebrewPath(void);
then I guess.

User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Menu API and cascading menus

Post by m0skit0 » Thu Dec 16, 2010 9:39 am

I still think copying the string is better as you said, but go on as you prefer.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

JJS
Big Beholder
Posts: 1416
Joined: Mon Sep 27, 2010 2:18 pm
Contact:

Re: Menu API and cascading menus

Post by JJS » Thu Dec 16, 2010 9:52 am

Somehow I got the impression that the everyone leaned towards giving just the pointer. But if not:

Then I will use string copying like in the first draft and add a function to retrieve the string length.

Edit: This I mean:

Code: Select all

unsigned int hblGetCreditsString(char* credits, unsigned int max_size);
unsigned int hblGetCreditsStringLength();
That way allows for static and dynamic memory allocation for the string and it is always safe even if a too small buffer for the whole string is given.

User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Menu API and cascading menus

Post by m0skit0 » Thu Dec 16, 2010 10:43 am

That looks OK for me. We can also implement hblGetCreditsString to return an error value if max_size is too small/big (filling the buffer anyway).
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

JJS
Big Beholder
Posts: 1416
Joined: Mon Sep 27, 2010 2:18 pm
Contact:

Re: Menu API and cascading menus

Post by JJS » Thu Dec 16, 2010 12:12 pm

Yes, the way I wanted to do it is to just fill the buffer up to max_size.

Then return the number of characters written into the buffer. It would also be possible to return the size of the whole string instead, not sure what is more sensible. The only case an error could be returned is when the pointer is NULL I think.

User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Menu API and cascading menus

Post by m0skit0 » Thu Dec 16, 2010 12:25 pm

I meant to return an error when max_size != hblGetCreditsStringLength() but fill the buffer up to max_size anyway.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

Post Reply

Return to “Half Byte Loader Development”