Skip to content

Add advanced techniques documentation on PRX Module#104

Open
xeonliu wants to merge 9 commits intopspdev:masterfrom
xeonliu:master
Open

Add advanced techniques documentation on PRX Module#104
xeonliu wants to merge 9 commits intopspdev:masterfrom
xeonliu:master

Conversation

@xeonliu
Copy link
Copy Markdown

@xeonliu xeonliu commented May 4, 2026

Draft for #103

Maybe examples should be more concrete. Wonder if implementation details should be included here.

@xeonliu xeonliu marked this pull request as draft May 4, 2026 04:28
@xeonliu xeonliu marked this pull request as ready for review May 4, 2026 04:28
Copy link
Copy Markdown
Member

@sharkwouter sharkwouter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Thanks @xeonliu, this is really useful. I'll go through it fully later. What I can say now is that I feel like we can still improve the navigation on the site here. Maybe the "Advanced Techniques" page that links to "Creating PRX Modules" page, like we do with the installation instructions. There it links to platform specific pages that are not shown in the side bar. What do you think?

@xeonliu
Copy link
Copy Markdown
Author

xeonliu commented May 4, 2026

Cool! Thanks @xeonliu, this is really useful. I'll go through it fully later. What I can say now is that I feel like we can still improve the navigation on the site here. Maybe the "Advanced Techniques" page that links to "Creating PRX Modules" page, like we do with the installation instructions. There it links to platform specific pages that are not shown in the side bar. What do you think?

It makes sense to me. However I am not sure if Advanced Technique is an appropriate title since I think Debugging is also somewhat an advanced technique 😂

Copy link
Copy Markdown
Member

@sharkwouter sharkwouter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @xeonliu thanks for updating the layout and for the work on this PR! I made some comments as someone who doesn't work with modules much and doesn't understand them very well. I hope that helps. I think it is great to have this info and the advance techniques page would enable us to document more things that in the past wouldn't really fit on the website :)

Comment thread techniques/prx_modules.md Outdated

To load a PRX module, the main module needs to know which functions it can call within that module. This is done by creating a stub library, a static library containing the signatures of the functions in the PRX module. The main module links against this stub library and calls the functions in the PRX module just like regular functions.

The stub library only contains the Module Name, the NID (Native ID?) of the function and a stub implementation of the function.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NID stands for name identifier it seems: https://psp-re.github.io/blog/nid-cracking/

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"which I believe stands for Name Identifier"

Maybe I should just explain what it is rather than its real name

Comment thread techniques/prx_modules.md Outdated

> Guidelines
> 1. `syslib` is an essential keyword that must be included in the export table.
> 2. It is generally not recommended to export global variables. (TODO: Reference needed)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove the TODO here. This makes sense to me without additional context, as the user cannot know what modifies the exported global variable or what effect modifying it will have on the program.

Copy link
Copy Markdown
Author

@xeonliu xeonliu May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this restriction is documented in a document which I read before. I couldn't remember where.

Comment thread techniques/prx_modules.md
PSP_EXPORT_END

# Export our function
PSP_EXPORT_START(MyLib, 0, 0x0001)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be good to specify where MyLib comes from.

Comment thread techniques/prx_modules.md Outdated
PSP_BEGIN_EXPORTS

# These four lines are mandatory (although you can add other functions like module_stop)
# syslib is a psynonym for the single mandatory export.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is less confusing without this second line.

Comment thread techniques/prx_modules.md Outdated
# Define the exports for the prx
PSP_BEGIN_EXPORTS

# These four lines are mandatory (although you can add other functions like module_stop)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to explicitly explain how to export a function below this code example as well.

Comment thread techniques/prx_modules.md
### Compile the PRX Module
{: .fs-4 .fw-700 }

If you are using Makefiles, you can add the following lines to your Makefile to compile the PRX module:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to also add instructions for CMake? We have an example here: https://psp-re.github.io/blog/nid-cracking/

Since we mostly use CMake in our examples on the website.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure yes. CMake can do that.

I choose Makefile because most existing projects still use them.

I think I will provide 2 versions if possible.

Comment thread techniques/prx_modules.md
### Generate the Stub Library
{: .fs-4 .fw-700 }

To generate the stub library, first run the following command in the terminal:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be good to specify in this section how this relates to the Makefile/CMake and building more.

Comment thread techniques/prx_modules.md
Comment thread advanced_techniques.md Outdated
Comment thread techniques/prx_modules.md
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to cover the coding limitations for prx modules as well? From what I understand using libraries in a module is difficult.

Copy link
Copy Markdown
Author

@xeonliu xeonliu May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be many restrictions. I haven't figured out the exact restrictions yet, only some suggestions.

It would be better if others in the channel can help verify them

But as for my observation, most problem comes from using standard C lib or libstdc++

Use only PSPSDK functions and writing the code in C without crt0 can avoid most problems.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I would still merge this if this is not yet included here now. It can be added later. Maybe having one sentence about the limitation would be good for now. I'll leave it up to you.

Comment thread techniques/prx_modules.md Outdated

Instead of writing a standard `main` function, you write a `module_start` function (called when the module is loaded) and a `module_stop` function (called when unloaded). These functions should return 0 on success and a negative value on failure.

> Make sure to use at least on function form other modules (for example, `pspDebugScreenPrintf`), otherwise `psp-fixup-imports` will complain `Error, no .lib.stub section found`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> Make sure to use at least on function form other modules (for example, `pspDebugScreenPrintf`), otherwise `psp-fixup-imports` will complain `Error, no .lib.stub section found`.
> Make sure to use at least one function form other modules (for example, `pspDebugScreenPrintf`), otherwise `psp-fixup-imports` will complain `Error, no .lib.stub section found`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants