using stdout

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

Moderators: cheriff, TyRaNiD

Post Reply
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

using stdout

Post by Shine »

With the latest version in svn repository (currently 694) you can register a handler for stdout and stderr, without starting the application in a kernel mode thread. The 2 step howto:

1. the module must be a kernel module, so use 0x1000 instead of 0 for the modattribute:

PSP_MODULE_INFO("APPNAME", 0x1000, 1, 1);

2. add a constructor function, which is automaticly called before starting the main function:

Code: Select all

__attribute__((constructor)) void stdoutInit()
{
	pspKernelSetKernelPC();
	pspDebugInstallStdoutHandler(pspDebugScreenPrintData);
}
and you are done. Now you can write 'fprintf(stdout, "Hello\n")' and every third party library, which wants to write to stdout, for example when you use 'io.write("Hello")' from within a Lua script, uses the pspDebugScreenPrintData function to write to the display of the PSP. Instead of pspDebugScreenPrintData you can use your own custom function, for example to write to the IrDA port or something else.

The technical details: mrbrown moved the _init call from the _main function in ctr0.c to the _start entry point, so when your program is in kernel mode, you can call kernel mode functions from contructor functions, like registering the tty-kernel-driver for the stdout file routing like explained. After this, the user thread is started, which needs not to be in kernel mode, so your application can run in user mode like a normal application.

This change should be backward compatible, so you don't need to change your existing programs, if you don't need this feature.
Post Reply