Help with PRX for music app

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

Moderators: cheriff, TyRaNiD

Post Reply
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Help with PRX for music app

Post by theHobbit »

Hello everyone I've been reading about prxes and had an idea about using them like plugins for my music app wich I released some time ago like GameMusicEmu so it would be easier to add more plugins (prx for other song formats) and just load them from the main app.

Right now I have compiled the first prx using the sexypsf code to play psf files. This is the source code:

Code: Select all


/*  PSF MODULE */

#include <pspkernel.h>
#include <pspthreadman.h>
#include <psppower.h>
#include <pspctrl.h>
#include <pspaudio.h>
#include <pspdebug.h>
#define _SPSF_TYPES_H__
#include "../driver.h"

#include <stdio.h>
#include <string.h>
				
PSP_MODULE_INFO&#40;"PSFMODULE", 0, 1, 1&#41;;

#define SAMPLE_COUNT PSP_AUDIO_SAMPLE_ALIGN&#40;512&#41; 
#define SAMPLE_SIZE  &#40;SAMPLE_COUNT * 4&#41;           
#define BUFFER_COUNT 8                            
#define BUFFER_SIZE  &#40;SAMPLE_SIZE * 64&#41; 

#define false	0
#define true	1

static int audio_thread_id;      
static u8 audio_thread_exit_flag; 
static int sexy_thread_id;        
static u8 sexy_thread_exit_flag;  

static u8 sound_buffer&#91;BUFFER_COUNT&#93;&#91;BUFFER_SIZE&#93;; 
static u8 sound_buffer_ready&#91;BUFFER_COUNT&#93;;        
static u8 sound_read_index;                        
static u32 sound_read_offset;                      
static u8 sound_write_index;                       
static u32 sound_write_offset;                     

static int psf_boost;

static PSFINFO *psf_info;               

u8 enable_reverb;
static int pause = false;


static int audio_thread&#40;SceSize args, void *argp&#41;
&#123;
                ...
&#125;

static int sexy_thread&#40;SceSize args, void *argp&#41;
&#123;
	...
&#125;

void sexyd_update&#40;u8 *buffer, int length&#41;
&#123;
	...
&#125;


/* PRX EXPORT FUNCTIONS */
// Loas a song
int loadSong&#40;char *zipfile, char *file, int type&#41;
&#123;
&#125;

// Pauses Unpauses song
void pauseSong&#40;int state&#41;
&#123;
&#125;

// Play loaded song
void playSong&#40;void&#41;
&#123;
&#125;

void stopSong&#40;&#41;
&#123;
&#125;

// Song lenght in secs
int songLen&#40;void&#41;
&#123;
&#125;

// Song name
char *songName&#40;&#41;
&#123;
&#125;

// Song Artist
char *songArtist&#40;&#41;
&#123;
&#125;

char *songType&#40;&#41;
&#123;
	return "PLAYSTATION X SOUND FORMAT";
&#125;

// Fast Forward 
void fastForwardSong&#40;int len&#41;
&#123;
&#125;

// Rewind
void rewindSong&#40;int len&#41;
&#123;
&#125;

////////////////////////////////////

int thread_start&#40;SceSize args, void *argp&#41;
&#123;
	printf&#40;"Inside PSF Module"&#41;;
	return 0;
&#125;

int module_start&#40;SceSize args, void *argp&#41;
&#123;
	SceUID thid = sceKernelCreateThread&#40;"PSFModule", thread_start, 0x16,
		0x00010000, PSP_THREAD_ATTR_USER, NULL&#41;;

	if &#40;thid < 0&#41; &#123;		
		return -1;
	&#125;

	sceKernelStartThread&#40;thid, args, argp&#41;;
	return 0;
&#125;
and here is the makefile:

Code: Select all

TARGET = psfModule

OBJS = main.o unzip.o $&#40;SEXYPSF&#41;

SEXYPSF = ../PsxCounters.o ../PsxDma.o ../PsxBios.o \
	    ../Spu.o     ../PsxHw.o       ../PsxMem.o \
          ../Misc.o ../R3000A.o ../PsxInterpreter.o \
          ../PsxHLE.o ../spu/spu.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_PSPSDK_LIBC = 1
#USE_KERNEL_LIBS = 1

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

LIBS = -lpsppower -lpspaudio -lz

PSPSDK = $&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build_prx.mak
and 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_HASH&#40;module_start&#41;
PSP_EXPORT_VAR_HASH&#40;module_info&#41;
PSP_EXPORT_END

# Export our function
PSP_EXPORT_START&#40;ModuleLib, 0, 0x0001&#41;
PSP_EXPORT_FUNC_HASH&#40;loadSong&#41;
PSP_EXPORT_FUNC_HASH&#40;playSong&#41;
PSP_EXPORT_FUNC_HASH&#40;pauseSong&#41;
PSP_EXPORT_FUNC_HASH&#40;stopSong&#41;
PSP_EXPORT_FUNC_HASH&#40;songName&#41;
PSP_EXPORT_FUNC_HASH&#40;songLen&#41;
PSP_EXPORT_FUNC_HASH&#40;songArtist&#41;
PSP_EXPORT_FUNC_HASH&#40;songType&#41;
PSP_EXPORT_FUNC_HASH&#40;fastForwardSong&#41;
PSP_EXPORT_FUNC_HASH&#40;rewindSong&#41;
PSP_EXPORT_END

PSP_END_EXPORTS
Now I have a main app that just tries to load the prx and test
the the songType export but it seems the prx can't send the pointer to the string "PLAYSTATION X SONG FORMAT" and the main app just prints garbage..
Well this is the code of the main app:

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspsdk.h>
#include <string.h>

PSP_MODULE_INFO&#40;"GMP", 0x1000, 1, 1&#41;;
/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

/* Define printf, just to make typing easier */
#define printf	pspDebugScreenPrintf

/* Imported function */
int loadSong&#40;char *zipfile, char *file, int type&#41;;
void pauseSong&#40;int state&#41;;
void playSong&#40;void&#41;;
void stopSong&#40;&#41;;
int songLen&#40;void&#41;;
char *songName&#40;&#41;;
char *songArtist&#40;&#41;;
char *songType&#40;&#41;;
void fastForwardSong&#40;int len&#41;;
void rewindSong&#40;int len&#41;;


/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
    sceKernelExitGame&#40;&#41;;

	return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41;
&#123;
    int cbid;
    cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
    sceKernelRegisterExitCallback&#40;cbid&#41;;
    sceKernelSleepThreadCB&#40;&#41;;

	return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
    int thid = 0;
    thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0xa0000000, 0&#41;;
    if &#40;thid >= 0&#41;
	sceKernelStartThread&#40;thid, 0, 0&#41;;
    return thid;
&#125;

int main&#40;int argc, char *argv&#91;&#93;&#41;
&#123;
	SceUID modid;
	SceModule *mod;

	pspDebugScreenInit&#40;&#41;;

	/* Install all our funky err thingamybobs */
	pspDebugInstallKprintfHandler&#40;NULL&#41;;
	pspDebugInstallErrorHandler&#40;NULL&#41;;
	pspDebugInstallStdoutHandler&#40;pspDebugScreenPrintData&#41;;
	pspSdkInstallNoPlainModuleCheckPatch&#40;&#41;;
	SetupCallbacks&#40;&#41;;

	printf&#40;"\nStart my module\n"&#41;;
	modid = pspSdkLoadStartModule&#40;"ms0&#58;/psp/GAME/GMPBeta/modules/PSFModule.prx", PSP_MEMORY_PARTITION_USER&#41;;
	printf&#40;"Module ID %08X\n", modid&#41;;

	/* Test the module exports */
	printf&#40;"MODULE SONG TYPE = %s\n", songType&#41;;

	/* Let's bug out */
	sceKernelExitDeleteThread&#40;0&#41;;

	return 0;
&#125;
And the makefile:

Code: Select all

TARGET = GMPBeta
OBJS = main.o ModuleLib.o

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

LIBDIR =
LDFLAGS = -mno-crt0

LIBS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = GMP Beta 0.1

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
And the ModuleLib.S:

Code: Select all

	.set noreorder

#include "pspstub.s"

	STUB_START "ModuleLib",0x00090000,0x000a0005
	STUB_FUNC  0x40B4EC07,loadSong
	STUB_FUNC  0x3E60441C,playSong
	STUB_FUNC  0xE9C9DF51,pauseSong
	STUB_FUNC  0x14414654,stopSong
	STUB_FUNC  0x5B8E3357,songName
	STUB_FUNC  0xBBD4BC78,songLen
	STUB_FUNC  0xF9AFE7D9,songArtist
	STUB_FUNC  0x84609128,songType
	STUB_FUNC  0xCCFE74ED,fastForwardSong
	STUB_FUNC  0x1145E038,rewindSong
	STUB_END
Well that is I really hope anybody helps because I've been trying for some days now and I can's seem to solve this : (
Post Reply