My prx plugin will not print to screen!

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

Moderators: cheriff, TyRaNiD

Post Reply
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

My prx plugin will not print to screen!

Post by ne0h »

All the functions of this plugin will run perfectly, but the plugin never print to
screen! Why?
Or how to printf in kernel mode? I will print "Hello World"

#include <psptypes.h>
#include <pspkernel.h>
#include <string.h>
#include <stdio.h>
#include <pspusb.h>
#include <psppower.h>
#include <pspdisplay.h>
#include <pspdisplay_kernel.h>
#include <pspusbstor.h>

#include "include/systemctrl_se.h"
#include "include/pspmodulemgr_kernel.h"
#include "include/systemctrl.h"
#include <pspsysmem_kernel.h>
#include "include/kubridge.h"

#include "main.h"
#include "translateButtons.h"
#include "blit.h"

PSP_MODULE_INFO("prx plugin", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
PSP_MAIN_THREAD_STACK_SIZE_KB(0);

#define PSP_USBBUS_DRIVERNAME "USBBusDriver"
#define PSP_USBSTOR_DRIVERNAME "USBStor_Driver"
#define PSP_USB_ACTIVATED 0x200

char strMsg[128];

int showMsg = 0;
int showHelp = 1;

int menuDone = 0;

int usePspSlim = 0;

char fullpath[30][128];
int num = 0;

int usbIsInit = 0;
int usbIsActivate = 0;

SceCtrlData pad;
SceCtrlData padIso;
unsigned int pad_old;

SceUID main_thid;
SceUID display_thid;

int build_args(char *args, const char *execfile, int argc, char **argv)
{
int loc = 0;
int i;

strcpy(args, execfile);
loc += strlen(execfile) + 1;
for(i = 0; i < argc; i++)
{
strcpy(&args[loc], argv);
loc += strlen(argv) + 1;
}

return loc;
}

int doBlit(char *msg)
{
strcpy(strMsg, msg);
showMsg=1;
return 0;
}

int loadStartModule(const char *name, int argc, char **argv)
{
SceUID modid;
int status;
char args[128];
int len;

modid = sceKernelLoadModule(name, 0, NULL);
if(modid >= 0)
{
len = build_args(args, name, argc, argv);
modid = sceKernelStartModule(modid, len, (void *) args, &status, NULL);
char tmp[32];
strcpy(tmp, "module loaded : ");
strcat(tmp, name);
doBlit(tmp);
}
else
{
char tmp[32];
strcpy(tmp, "lsm: Error loading module ");
strcat(tmp, name);
doBlit(tmp);
printf("lsm: Error loading module %s\n", name);
}

return modid;
}

int unloadStopModule(char *modname)
{
SceModule *mod;
while ((mod = sceKernelFindModuleByName(modname)))
{
sceKernelStopModule(mod->modid, 0, NULL, NULL, NULL);
sceKernelUnloadModule(mod->modid);
}

return 0;

}

int display_thread(SceSize args, void *argp)
{
while(1)
{
if(showMsg)
{
blit_string(1,33,strMsg,0xffffff,0x000000);
showMsg++;
if(showMsg==600) showMsg=0;
}

if(showHelp)
{
blit_string(1, 9, "PRX Plugin v0.1",0xffffff,0x000000);
blit_string(1, 10, "==========================================",0xffffff,0x000000);
blit_string(1, 12, "NOTE + HOME = Shutdown PSP",0xffffff,0x000000);
blit_string(1, 20, "NOTE + DOWN = Set Max Brightness",0xffffff,0x000000);
blit_string(1, 22, "NOTE + L = Start/Stop Usb Mass",0xffffff,0x000000);
blit_string(1, 28, "NOTE + VOL_DOWN = Show this help",0xffffff,0x000000);
blit_string(1, 30, "Circle = Hide This Help",0xffffff,0x000000);
}

sceKernelDelayThread(2000);
}
return 0;
}

int helpMenu()
{
menuDone=0;

while(!menuDone)
{
showHelp=1;

sceDisplayWaitVblankStart();

sceCtrlPeekBufferPositive(&pad, 1);
if (pad.Buttons != pad_old)
{
if(pad.Buttons & PSP_CTRL_CIRCLE)
{
showHelp=0;
menuDone=1;
}
}
}
pad_old = pad.Buttons;
sceKernelDelayThread(1000);
return 0;
}

void setBrightness(int x)
{
sceDisplaySetBrightness(x,0);
blit_string(1, 30, "Circle = Hide This Help",0xffffff,0x000000);
}

int usbInit(){

u32 retVal;

//start necessary drivers
loadStartModule("flash0:/kd/chkreg.prx", 0, NULL);
loadStartModule("flash0:/kd/npdrm.prx", 0, NULL);
loadStartModule("flash0:/kd/semawm.prx", 0, NULL);
loadStartModule("flash0:/kd/usbstor.prx", 0, NULL);
loadStartModule("flash0:/kd/usbstormgr.prx", 0, NULL);
loadStartModule("flash0:/kd/usbstorms.prx", 0, NULL);
loadStartModule("flash0:/kd/usbstorboot.prx", 0, NULL);

//setup USB drivers
retVal = sceUsbStart(PSP_USBBUS_DRIVERNAME, 0, 0);
if (retVal != 0) {
return -6;
}

retVal = sceUsbStart(PSP_USBSTOR_DRIVERNAME, 0, 0);
if (retVal != 0) {
return -7;
}

retVal = sceUsbstorBootSetCapacity(0x800000);
if (retVal != 0) {
return -8;
}

return 0;
}

int usbActivate()
{
sceUsbActivate(0x1c8);
return 0;
}

int usbDeactivate()
{
sceUsbDeactivate(0x1c8);
sceIoDevctl("fatms0:", 0x0240D81E, NULL, 0, NULL, 0 ); //Avoid corrupted files
return 0;
}

int loadUsb(){
if(!usbIsInit)
{
usbInit();
sceKernelDelayThread(10000);
usbActivate();
usbIsInit=1;
usbIsActivate=1;
}
else
{
if(usbIsActivate)
{
usbDeactivate();
usbIsActivate=0;
}
else
{
usbActivate();
usbIsActivate=1;
}
}
}

int threadMain(SceSize args, void *argp)
{
sceKernelDelayThread(10000);

while(!translateButtons()) {
printf("waiting\n");
}

while(1) {

//cleanBeforeExit();

sceCtrlPeekBufferPositive(&pad, 1);

if (pad.Buttons != pad_old)
{
if((pad.Buttons & (PSP_CTRL_HOME | PSP_CTRL_NOTE)) == (PSP_CTRL_HOME | PSP_CTRL_NOTE))
{
doBlit("Standby requested");
scePowerRequestStandby();
}

if((pad.Buttons & (PSP_CTRL_DOWN | PSP_CTRL_NOTE)) == (PSP_CTRL_DOWN | PSP_CTRL_NOTE))
{
setBrightness(99);
doBlit("Brightness set to maximum value");
}

if((pad.Buttons & (PSP_CTRL_VOLDOWN | PSP_CTRL_NOTE)) == (PSP_CTRL_VOLDOWN | PSP_CTRL_NOTE))
{
helpMenu();
}

if((pad.Buttons & (PSP_CTRL_LTRIGGER | PSP_CTRL_NOTE)) == (PSP_CTRL_LTRIGGER | PSP_CTRL_NOTE))
{
loadUsb();
}

}
pad_old = pad.Buttons;
sceKernelDelayThread(1000);
}
return 0;
}

int module_start(SceSize args, void *argp)
{

display_thid = sceKernelCreateThread("prx_plugin_display", display_thread, 8, 0x200, 0, NULL);
if(display_thid >= 0) sceKernelStartThread(display_thid, args, argp);

main_thid = sceKernelCreateThread("prx_plugin_main", threadMain, 6, 0x800, 0, NULL);
if(main_thid >= 0) sceKernelStartThread(main_thid, args, argp);

return 0;

sceKernelExitDeleteThread(0);
}

int module_stop(SceSize args, void *argp)
{
return 0;
}

I use blit library to print text, can i use other library to printf in a plugin?

Makefile:

TARGET = prx_plugin
OBJS = main.o translateButtons.o blit.o scr_printf.o

BUILD_PRX=1
USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1

INCDIR = include
CFLAGS = -Os -G0 -Wall -fno-strict-aliasing -fno-builtin-printf -D_PSPSLIM
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR = lib
LDFLAGS = -mno-crt0 -nostartfiles
LIBS = -lpspsystemctrl_kernel -lpspusb -lpsppower -lpspusbstor -lpspdebug

include $(PSPSDK)/lib/build_prx.mak



Please, help me...
Question_dev
Posts: 88
Joined: Fri Aug 24, 2007 8:23 pm

Post by Question_dev »

You have to call fisrt (before printing)

Code: Select all

blit_setup&#40;&#41;;

Cu
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

o, thanks but i've already resolved, it's a old post...
Post Reply