Subversion Repositories pspware

Compare Revisions

Ignore whitespace Rev 349 → Rev 350

/trunk/LuaPlayer/CHANGELOG
1,6 → 1,14
 
v0.19
==========
- directory detection bugfix [moonlight]
- Changed System.loadModule to loadlib to work. [Oobles]
the same as the traditional lua loadlib function.
- Made loadlib check if a module is already loaded before trying
to load. [Oobles]
- Removed getLuaState export. No longer required. [Oobles]
- Made debugOutput work in the same way as printf in bootstrap. [Oobles]
- Added loadlib.prx kernel module. required for module loading. [Oobles]
 
v0.18alpha (blame Oobles for all changes)
================================================
/trunk/LuaPlayer/src/luaplayer.cpp
11,12 → 11,6
 
static lua_State *L;
 
extern "C" {
lua_State * getLuaState()
{
return L;
}
}
 
const char * runScript(const char* script, bool isStringBuffer )
{
28,7 → 22,9
luaopen_table(L);
luaopen_string(L);
luaopen_math(L);
luaopen_loadlib(L);
 
// luasystem.cpp defines our loadlib.
// luaopen_loadlib(L);
// Modules
luaSound_init(L);
/trunk/LuaPlayer/src/exports.exp
10,7 → 10,6
 
# Export our functions
PSP_EXPORT_START(LUAPLAYER, 0, 0x0001)
PSP_EXPORT_FUNC_HASH(getLuaState)
PSP_EXPORT_FUNC_HASH(lua_atpanic)
PSP_EXPORT_FUNC_HASH(lua_call)
PSP_EXPORT_FUNC_HASH(lua_checkstack)
117,7 → 116,7
PSP_EXPORT_FUNC_HASH(luaopen_table)
PSP_EXPORT_FUNC_HASH(luaopen_string)
PSP_EXPORT_FUNC_HASH(luaopen_math)
PSP_EXPORT_FUNC_HASH(luaopen_loadlib)
#PSP_EXPORT_FUNC_HASH(luaopen_loadlib)
PSP_EXPORT_FUNC_HASH(luaC_collectgarbage)
PSP_EXPORT_END
 
/trunk/LuaPlayer/src/main.cpp
31,7 → 31,7
#include "boot.cpp"
 
/* Define the module info section */
PSP_MODULE_INFO("LUAPLAYER", 0, 1, 1);
PSP_MODULE_INFO(LUAPLAYER, 0, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
PSP_HEAP_SIZE_KB(10024); /* 10MB */
 
/trunk/LuaPlayer/src/luasystem.cpp
149,35 → 149,35
getcwd( modulePath, 256 );
}
 
extern "C" {
extern SceUID psploadlib( const char * name, char * init );
extern void **findFunction( SceUID id, const char * library, const char * name );
extern int init( lua_State *L);
}
 
#define LOADMODULE_ARGERROR "Argument error: System.loadModule(module, init) takes a module name and init method as string arguments."
 
static int lua_loadModule(lua_State *L)
{
char path[256];
u32 loadResult;
u32 startResult;
int status;
 
const char *name = luaL_checkstring(L, 1);
if (!name) return luaL_error(L, "Argument error: System.loadModule(name) takes a module name as string as argument.");
const char *init = luaL_checkstring(L, 2);
 
strcpy( path, modulePath );
strcat( path, "/" );
strcat( path, name );
strcat( path, ".lrx" );
 
loadResult = sceKernelLoadModule(path,0, NULL);
if (loadResult & 0x80000000)
{
return luaL_error(L, "Argument error: Failed to load module");
SceUID uid = psploadlib( name, NULL );
if ( uid >= 0 ) {
lua_CFunction f = (lua_CFunction) *(findFunction( uid, name, init ));
if (f != NULL)
{
lua_pushlightuserdata(L,(void*)uid);
lua_pushcclosure(L,f,1);
return 1;
}
}
 
startResult = sceKernelStartModule( loadResult, strlen(path)+1,(void*) path, &status, NULL );
if ( loadResult != startResult )
{
printf( "Module error: Failed to load module\n" );
return luaL_error(L, "Module error: Failed to load module");
}
lua_pushnil(L);
lua_pushstring(L, LOADMODULE_ARGERROR );
lua_pushstring(L, (uid >= 0) ? "init" : "open");
 
return 0;
return 3;
}
 
static int lua_usbActivate(lua_State *L)
421,7 → 421,6
{"createDirectory", lua_createDir},
{"removeDirectory", lua_removeDir},
{"removeFile", lua_removeFile},
{"loadModule", lua_loadModule},
{"usbDiskModeActivate", lua_usbActivate},
{"usbDiskModeDeactivate", lua_usbDeactivate},
{"powerIsPowerOnline", lua_powerIsPowerOnline},
448,5 → 447,6
void luaSystem_init(lua_State *L) {
setModulePath();
luaL_openlib(L, "System", System_functions, 0);
lua_register(L, "loadlib", lua_loadModule);
}
 
/trunk/LuaPlayer/Makefile.psp.common
3,7 → 3,7
 
TARGET = luaplayer
OBJS = src/graphics.o src/sound.o src/luaplayer.o src/utility.o src/main.o src/framebuffer.o \
src/luacontrols.o src/luagraphics.o src/luasound.o src/luatimer.o src/luasystem.o src/luawlan.o src/lua3d.o
src/luacontrols.o src/luagraphics.o src/luasound.o src/luatimer.o src/luasystem.o src/luawlan.o src/lua3d.o loadlib.o
INCDIR =
CFLAGS = -g -G0 -Wall -O0 -fno-strict-aliasing -mno-explicit-relocs $(EXTRA_CFLAGS) $(shell freetype-config --cflags)
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
20,6 → 20,9
 
include $(PSPSDK)/lib/build.mak
 
loadlib.S: modules/loadlib/exports.exp
$(shell psp-config --pspdev-path)/bin/psp-build-exports --build-stubs $<
 
src/main.o: boot.cpp vera.cpp veraMono.cpp
 
boot.cpp: src/auxiliary/boot.lua
/trunk/LuaPlayer/modules/loadlib/libs.c
New file
0,0 → 1,185
/*
* PSPLINK
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPLINK root for details.
*
* libs.c - Module library code for psplink.
*
* Copyright (c) 2005 James F <tyranid@gmail.com>
*
* $HeadURL: svn://svn.pspdev.org/psp/trunk/psplink/psplink/libs.c $
* $Id: libs.c 1798 2006-02-11 13:55:19Z tyranid $
*/
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsysmem_kernel.h>
#include <psputilsforkernel.h>
#include <pspmoduleexport.h>
#include <psploadcore.h>
#include <stdio.h>
#include <string.h>
#include "libs.h"
 
static struct SceLibraryEntryTable *_libsFindLibrary(SceUID uid, const char *library)
{
struct SceLibraryEntryTable *entry;
SceModule *pMod;
void *entTab;
int entLen;
 
pMod = sceKernelFindModuleByUID(uid);
if(pMod != NULL)
{
int i = 0;
 
entTab = pMod->ent_top;
entLen = pMod->ent_size;
while(i < entLen)
{
entry = (struct SceLibraryEntryTable *) (entTab + i);
 
if((entry->libname) && (strcmp(entry->libname, library) == 0))
{
return entry;
}
 
i += (entry->len * 4);
}
}
 
return NULL;
}
 
void* libsFindExportAddrByNid(SceUID uid, const char *library, u32 nid)
{
struct SceLibraryEntryTable *entry;
u32 *addr = NULL;
 
entry = _libsFindLibrary(uid, library);
if(entry)
{
int count;
int total;
unsigned int *vars;
 
total = entry->stubcount + entry->vstubcount;
vars = entry->entrytable;
 
if(entry->stubcount > 0)
{
for(count = 0; count < entry->stubcount; count++)
{
if(vars[count] == nid)
{
return &vars[count+total];
}
}
}
}
 
return addr;
}
 
void* libsFindExportAddrByName(SceUID uid, const char *library, const char *name)
{
u8 digest[20];
u32 nid;
 
if(sceKernelUtilsSha1Digest((u8 *) name, strlen(name), digest) >= 0)
{
nid = digest[0] | (digest[1] << 8) | (digest[2] << 16) | (digest[3] << 24);
//printf("nid: %08X\n", nid);
return libsFindExportAddrByNid(uid, library, nid);
}
 
return NULL;
}
 
u32 libsFindExportByName(SceUID uid, const char *library, const char *name)
{
u32 *addr;
 
addr = libsFindExportAddrByName(uid, library, name);
if(!addr)
{
return 0;
}
 
return *addr;
}
 
u32 libsFindExportByNid(SceUID uid, const char *library, u32 nid)
{
u32 *addr;
 
addr = libsFindExportAddrByNid(uid, library, nid);
if(!addr)
{
return 0;
}
 
return *addr;
}
 
int libsPrintEntries(SceUID uid)
{
struct SceLibraryEntryTable *entry;
SceModule *pMod;
void *entTab;
int entLen;
 
pMod = sceKernelFindModuleByUID(uid);
if(pMod != NULL)
{
int i = 0;
 
entTab = pMod->ent_top;
entLen = pMod->ent_size;
printf("entTab %p - entLen %d\n", entTab, entLen);
while(i < entLen)
{
int count;
int total;
unsigned int *vars;
 
entry = (struct SceLibraryEntryTable *) (entTab + i);
 
if(entry->libname)
{
printf("Export Library %s\n", entry->libname);
}
else
{
printf("Export library syslib\n");
}
total = entry->stubcount + entry->vstubcount;
vars = entry->entrytable;
 
if(entry->stubcount > 0)
{
printf("Function Exports:\n");
for(count = 0; count < entry->stubcount; count++)
{
printf("Entry %-3d: UID 0x%08X, Function 0x%08X\n", count+1, vars[count], vars[count+total]);
}
}
 
if(entry->vstubcount > 0)
{
for(count = 0; count < entry->vstubcount; count++)
{
printf("Entry %-3d: UID 0x%08X, Variable 0x%08X\n", count+1, vars[count+entry->stubcount],
vars[count+entry->stubcount+total]);
}
}
 
i += (entry->len * 4);
}
}
else
{
return 0;
}
 
return 1;
}
/trunk/LuaPlayer/modules/loadlib/Makefile
New file
0,0 → 1,29
TARGET = loadlib
OBJS = main.o libs.o
 
# Define to build this as a prx (instead of a static elf)
BUILD_PRX=1
# Define the name of our custom exports (minus the .exp extension)
PRX_EXPORTS=exports.exp
 
USE_NEWLIB_LIBC = 1
 
INCDIR = -I ..
CFLAGS = -O2 -G0 -Wall -mno-explicit-relocs
CXXFLAGS = $(CFLAGS) -mno-explicit-relocs -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBS = -lc
LIBDIR =
 
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
 
 
EXTRA_CLEAN = luaplayer.S exports.o simple.elf
 
release: all
cp loadlib.prx ../loadlib.prx
 
luaplayer.S: ../../src/exports.exp
$(shell psp-config --pspdev-path)/bin/psp-build-exports --build-stubs $<
 
/trunk/LuaPlayer/modules/loadlib/exports.exp
New file
0,0 → 1,16
# Define the exports for the prx
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.
PSP_EXPORT_START(syslib, 0, 0x8000)
PSP_EXPORT_FUNC_HASH(module_start)
PSP_EXPORT_END
 
# Export our function
PSP_EXPORT_START(loadlib, 0, 0x4001)
PSP_EXPORT_FUNC_HASH(findFunction)
PSP_EXPORT_FUNC_HASH(psploadlib)
PSP_EXPORT_END
 
PSP_END_EXPORTS
/trunk/LuaPlayer/modules/loadlib/libs.h
New file
0,0 → 1,22
/*
* PSPLINK
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPLINK root for details.
*
* libs.h - Module library code for psplink
*
* Copyright (c) 2005 James F <tyranid@gmail.com>
*
* $HeadURL: svn://svn.pspdev.org/psp/trunk/psplink/psplink/libs.h $
* $Id: libs.h 1798 2006-02-11 13:55:19Z tyranid $
*/
#ifndef __LIBS_H__
#define __LIBS_H__
 
int libsPrintEntries(SceUID uid);
u32 libsFindExportByName(SceUID uid, const char *library, const char *name);
u32 libsFindExportByNid(SceUID uid, const char *library, u32 nid);
void* libsFindExportAddrByName(SceUID uid, const char *library, const char *name);
void* libsFindExportAddrByNid(SceUID uid, const char *library, u32 nid);
 
#endif
/trunk/LuaPlayer/modules/loadlib/main.c
New file
0,0 → 1,82
/*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* main.c - Kernel mode loadlib PRX.
*
* Copyright (c) 2005 David Ryan <oobles@hotmail.com>
*
* $Id: main.c 1531 2005-12-07 18:27:12Z tyranid $
*/
#include <stdlib.h>
#include <pspkernel.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include "luamodule.h"
#include "libs.h"
 
PSP_MODULE_INFO("LOADLIB", 0x1000, 1, 1);
PSP_HEAP_SIZE_KB(1);
PSP_NO_CREATE_MAIN_THREAD();
 
static char modulePath[256];
 
static void setModulePath()
{
getcwd( modulePath, 256 );
}
 
void** findFunction( SceUID id, const char *library, const char * name )
{
return libsFindExportAddrByName( id, library, name );
}
 
 
SceUID psploadlib( char * name, char * init )
{
char path[256];
u32 loadResult;
u32 startResult;
int status;
 
 
if (!name) return -1;
 
// check if the module is already loaded.
SceModule *pMod;
pMod = sceKernelFindModuleByName( name );
if (pMod != NULL ) {
loadResult = pMod->modid;
return loadResult;
}
 
strcpy( path, modulePath );
strcat( path, "/" );
strcat( path, name );
strcat( path, ".lrx" );
 
loadResult = sceKernelLoadModule(path,0, NULL);
if (loadResult & 0x80000000)
{
return loadResult;
}
 
startResult = sceKernelStartModule( loadResult, strlen(path)+1,(void*) path, &status, NULL );
if ( loadResult != startResult )
{
return -1;
}
 
return loadResult;
}
 
 
int main(int argc, char *argv[] )
{
setModulePath();
return 0;
}
 
/trunk/LuaPlayer/modules/sound/main.cpp
22,22 → 22,16
PSP_NO_CREATE_MAIN_THREAD();
 
 
extern "C" {
 
extern lua_State * getLuaState();
int init( lua_State * L )
{
luaSound_init( L );
}
 
 
int main(int argc, char *argv[] )
{
printf( "sound.lrx loaded\n" );
 
lua_State * L;
 
L = getLuaState();
 
luaSound_init( L );
 
return 0;
}
 
/trunk/LuaPlayer/modules/simple/main.c
New file
0,0 → 1,49
/*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* main.c - Simple LRX example.
*
* Copyright (c) 2005 David Ryan <oobles@hotmail.com>
*
* $Id: main.c 1531 2005-12-07 18:27:12Z tyranid $
*/
#include <stdlib.h>
#include <pspkernel.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include "luamodule.h"
 
PSP_MODULE_INFO("simple", 0, 1, 1);
PSP_HEAP_SIZE_KB(240);
PSP_NO_CREATE_MAIN_THREAD();
 
#define WELCOME_MESSAGE "Simple LRX loaded"
 
 
static int lua_doSomething(lua_State *L)
{
if (lua_gettop(L) != 0) return luaL_error(L, "wrong number of arguments");
lua_pushstring(L, WELCOME_MESSAGE );
return 1;
}
 
static const luaL_reg Simple_functions[] = {
{"doSomething", lua_doSomething},
{0,0}
};
 
 
int init(lua_State *L )
{
luaL_openlib(L, "Simple", Simple_functions, 0);
return 0;
}
 
int main(int argc, char *argv[] )
{
return 0;
}
 
/trunk/LuaPlayer/modules/simple/exports.exp
8,7 → 8,8
PSP_EXPORT_END
 
# Export our function
PSP_EXPORT_START(MyLib, 0, 0x0001)
PSP_EXPORT_START(simple, 0, 0x0001)
PSP_EXPORT_FUNC_HASH(init)
PSP_EXPORT_END
 
PSP_END_EXPORTS
/trunk/LuaPlayer/modules/Makefile
1,6 → 1,6
# LuaPlayer Modules
 
SUBDIRS = simple sound
SUBDIRS = loadlib simple sound
 
.PHONY: dummy
 
/trunk/LuaPlayer/modules/luamodule.h
4,12 → 4,10
#include <stdlib.h>
#include <tdefs.h>
 
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
extern void luaC_collectgarbage (lua_State *L);
}
 
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define CLAMP(val, min, max) ((val)>(max)?(max):((val)<(min)?(min):(val)))
51,11 → 49,6
return 1; \
}
 
extern int runScript(const char* script, bool isStringBuffer);
extern void luaC_collectgarbage (lua_State *L);
 
extern void stackDump (lua_State *L);
 
 
#endif
 
/trunk/LuaPlayer/bootstrap/Makefile
1,10 → 1,6
TARGET = luaboot
OBJS = bootstrap.o sio.o
OBJS = bootstrap.o sio.o
 
 
# Define the name of our custom exports (minus the .exp extension)
PRX_EXPORTS=exports.exp
 
PSP_EBOOT_TITLE = LuaPlayer 0.18
PSP_EBOOT_ICON = title-icon.png
 
14,6 → 10,7
ASFLAGS = $(CFLAGS)
LIBS = -lpspdebug -lpsphprm_driver
LIBDIR =
LDFLAGS =
 
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
/trunk/LuaPlayer/bootstrap/bootstrap.cpp
23,11 → 23,12
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
 
#include "sio.h"
 
/* Define the module info section */
PSP_MODULE_INFO("LUABOOT", 0x1000, 1, 1);
PSP_MODULE_INFO(LUABOOT, 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
PSP_MAIN_THREAD_STACK_SIZE_KB(32);
PSP_HEAP_SIZE_KB(32);
35,10 → 36,14
// startup path
char path[256];
 
int debugOutput(const char *buff, int size)
int debugOutput(const char *format, ...)
{
va_list opt;
char buffer[2048];
int bufsz;
 
static int debugInitialized = 0;
if(!buff) {
if(!format) {
debugInitialized = 0;
return 0;
}
47,9 → 52,12
pspDebugScreenInit();
debugInitialized = 1;
}
return pspDebugScreenPrintData(buff, size);
va_start(opt, format);
bufsz = vsnprintf( buffer, (size_t) sizeof(buffer), format, opt);
return pspDebugScreenPrintData(buffer, bufsz);
}
 
 
int loadModule( char * moduleLocation )
{
char path[256];
59,8 → 67,8
int retVal = sceKernelLoadModule( path, 0, NULL );
if (retVal < 0)
{
debugOutput("Error: loadModule luaplayer.prx\n", 33);
debugOutput( path, strlen(path) );
debugOutput("Error: loadModule %s %x\n", path, retVal);
debugOutput("Loading from %s\n", path );
return retVal;
}
 
68,7 → 76,7
retVal = sceKernelStartModule( retVal, strlen(path)+1, path, &fd, NULL );
if ( retVal < 0 )
{
debugOutput("Error: strtModule luaplayer.prx\n", 33);
debugOutput("Error: strtModule %s %x\n", path, retVal);
return retVal;
}
 
75,10 → 83,12
return 0;
}
 
int main( int argc, void **argp )
int main( SceSize args, void *argp )
{
pspSdkInstallNoDeviceCheckPatch();
pspSdkInstallNoPlainModuleCheckPatch();
registerSIODriver();
 
getcwd(path, 256);
int err = pspSdkLoadInetModules();
88,29 → 98,21
sceKernelDelayThread(5*1000000); // 5 sec to read error
}
 
int retVal = loadModule( "/luaplayer.prx" );
int retVal = loadModule( "/loadlib.prx" );
if (retVal < 0 )
{
debugOutput("Error: failed loadModule loadlib.prx\n");
sceKernelSleepThread();
}
 
retVal = loadModule( "/luaplayer.prx" );
if (retVal < 0)
{
debugOutput("Error: failed loadModule luaplayer.prx\n", 31);
debugOutput("Error: failed loadModule luaplayer.prx\n");
sceKernelSleepThread();
}
 
sceKernelSleepThread();
return 0;
}
/*
__attribute__((constructor)) void stdoutInit()
{
//pspKernelSetKernelPC();
pspSdkInstallNoDeviceCheckPatch();
pspSdkInstallNoPlainModuleCheckPatch();
//pspKernelSetKernelPC();
//pspKernelSetKernelPC();
//pspSdkInstallNoDeviceCheckPatch();
//pspDebugInstallKprintfHandler(NULL);
registerSIODriver();
 
// ignore startup messages from kernel, but install the tty driver in kernel mode
//pspDebugInstallStdoutHandler(nullOutput);
}
*/
/trunk/LuaPlayer/bootstrap/exports.exp
8,3 → 8,4
PSP_EXPORT_VAR_HASH(module_info)
PSP_EXPORT_END
 
PSP_END_EXPORTS
/trunk/LuaPlayer/Makefile.psp
26,6 → 26,7
mkdir -p $(RELEASEFOLDER)/luaplayer
cp bootstrap/EBOOT.PBP $(RELEASEFOLDER)/luaplayer/EBOOT.PBP
cp luaplayer.prx $(RELEASEFOLDER)/luaplayer
cp modules/loadlib.prx $(RELEASEFOLDER)/luaplayer
cp modules/*.lrx $(RELEASEFOLDER)/luaplayer
-cd build && zip -r "LuaPlayer_v$(VERSION)_firmware10".zip $(RELEASEF)
36,6 → 37,7
cp bootstrap/luaboot/EBOOT.PBP $(RELEASEFOLDER)/luaplayer/EBOOT.PBP
cp bootstrap/luaboot%/EBOOT.PBP $(RELEASEFOLDER)/luaplayer%/EBOOT.PBP
cp luaplayer.prx $(RELEASEFOLDER)/luaplayer
cp modules/loadlib.prx $(RELEASEFOLDER)/luaplayer
cp modules/*.lrx $(RELEASEFOLDER)/luaplayer
-cd build && zip -r "LuaPlayer_v$(VERSION)_firmware15".zip $(RELEASEF)
 
72,6 → 74,7
cp bootstrap/luaboot/EBOOT.PBP $(INSTALL_PATH)/luaplayer
cp bootstrap/luaboot%/EBOOT.PBP $(INSTALL_PATH)/luaplayer%
cp luaplayer.prx $(INSTALL_PATH)/luaplayer
cp modules/loadlib.prx $(INSTALL_PATH)/luaplayer
cp modules/*.lrx $(INSTALL_PATH)/luaplayer
mkdir -p $(INSTALL_PATH)/luaplayer/System
cp -R System/system.lua $(INSTALL_PATH)/luaplayer/System/