Simple PRX Problem

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

Moderators: cheriff, TyRaNiD

Post Reply
ADePSP
Posts: 58
Joined: Thu Jul 13, 2006 9:07 pm

Simple PRX Problem

Post by ADePSP »

I've been trying to make a simple prx that just writes to a file when you press X but when I load it with DevHook it crashes the PSP when the Playstation animation comes up...

I copied my test.prx file to the root of the memstick ms0:/test.prx and then added that line to the following DevHook files (after the /kd/isofs.prx line),

ms0://dh/260/flash0/kd/pspbtcnf.txt
ms0://dh/260/flash0/kd/pspbtcnf_game.txt

My prx did nothing before I added this to the top of the source and after I did that it started crashing...

PSP_MODULE_INFO("PRX Test", 0x1000, 1, 0);
PSP_MAIN_THREAD_ATTR(0);

Can anyone see what i'm doing wrong here... Here's the main.c file,

Code: Select all

#include <pspctrl.h>
#include <pspkernel.h>
#include <stdio.h>

PSP_MODULE_INFO&#40;"PRX Test", 0x1000, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

int MainThread &#40;SceSize args, void *argp&#41; &#123;

  SceCtrlData pad;
  int i;
  FILE* fp;

  while &#40;1&#41; &#123;

     sceCtrlPeekBufferPositive&#40;&pad, 1&#41;;

     if &#40;pad.Buttons & PSP_CTRL_CROSS&#41; &#123;

        fp = fopen&#40;"ms0&#58;/test.txt","w+"&#41;;
        if &#40;fp&#41; &#123;
           fprintf&#40;fp,"Pressed X"&#41;;
        &#125;
        fclose&#40;fp&#41;;

     &#125;

     for &#40;i=0; i<5; i++&#41; &#123;
        sceDisplayWaitVblankStart&#40;&#41;;
     &#125;

  &#125;

  return 0;

&#125;

int module_start&#40;SceSize args, void *argp&#41; &#123;

  SceUID thid;

  thid = sceKernelCreateThread&#40;"PRX_Test", MainThread, 0x18, 0x1000, 0, NULL&#41;;
  if &#40;thid >= 0&#41; sceKernelStartThread&#40;thid, args, argp&#41;;

  return 0;

&#125;

int module_stop&#40;void&#41; &#123;

  return 0;

&#125;
Here's the makefile,

Code: Select all

TARGET = test
OBJS = main.o

BUILD_PRX=1

USE_PSPSDK_LIBC=1
USE_PSPSDK_LIBS=1
#USE_KERNEL_LIBC=1
#USE_KERNEL_LIBS=1

PRX_EXPORTS=exports.exp

INCDIR = 
CFLAGS = -Os -G0 -Wall -fno-strict-aliasing -fno-builtin-printf
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS = -mno-crt0 -nostartfiles
LIBS =

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
and here's the exports.exp,

Code: Select all

# Define the exports for the prx

PSP_BEGIN_EXPORTS

# These four lines are mandatory &#40;although you can add other functions like module_stop&#41;
# syslib is a psynonym for the single mandatory export.

PSP_EXPORT_START&#40;syslib, 0, 0x8000&#41;

PSP_EXPORT_FUNC&#40;module_start&#41;
PSP_EXPORT_VAR&#40;module_info&#41;
PSP_EXPORT_FUNC&#40;module_stop&#41;

PSP_EXPORT_END

PSP_END_EXPORTS
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

Use sceIO* commands for file manipulation...

Here's a stripped down example of devhook prx:
Makefile:

Code: Select all

TARGET = controls
OBJS = crt0_prx.o

# Define to build this as a prx &#40;instead of a static elf&#41;
BUILD_PRX=1
# Define the name of our custom exports &#40;minus the .exp extension&#41;
PRX_EXPORTS=exports.exp

USE_KERNEL_LIBS = 1
USE_KERNEL_LIBC = 1

INCDIR = 
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
#LIBS =
LDFLAGS =  -nostdlib -nodefaultlibs


PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
crt0_prx.c:

Code: Select all

/*
	based by

 * PSP Software Development Kit - http&#58;//www.pspdev.org
 * -----------------------------------------------------------------------
 * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
 *
 * crt0_prx.c - Pure PRX startup code.
 *
 * Copyright &#40;c&#41; 2005 Marcus R. Brown <[email protected]>
 *
 * $Id&#58; crt0.c 1526 2005-12-06 21&#58;56&#58;06Z tyranid $

*/

#include <pspkerneltypes.h>
#include <pspmoduleinfo.h>
#include <pspiofilemgr.h>
#include <pspthreadman.h>
#include <stdlib.h>
#include <string.h>

PSP_MODULE_INFO&#40;"TESTPLUGIN", 0x3007, 1, 2&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;; // 0 for kernel mode too

int module_start&#40;SceSize args, void *argp&#41; __attribute__&#40;&#40;alias&#40;"_start"&#41;&#41;&#41;;


int _start&#40;SceSize args, void *argp&#41;
&#123;
 int x,ret;

char *done="\nLOADED module!!!\n";
int afd;
afd = sceIoOpen&#40;"ms0&#58;/test.txt", PSP_O_WRONLY|PSP_O_CREAT|PSP_O_APPEND, 0777&#41;;
sceIoWrite&#40;afd, done, strlen&#40;done&#41;*sizeof&#40;char&#41;&#41;;
sceIoClose&#40;afd&#41;;

//
// ADD YOUR THREAD STARTING HERE
//
	return 0;
&#125;
exports.exp:

Code: Select all

# Define the exports for the prx
PSP_BEGIN_EXPORTS

PSP_EXPORT_START&#40;syslib, 0, 0x8000&#41;
PSP_EXPORT_FUNC_HASH&#40;module_start&#41;
PSP_EXPORT_VAR_HASH&#40;module_info&#41;
PSP_EXPORT_END

PSP_END_EXPORTS
Post Reply