Index: PSP/exceptionhandler/exception.c =================================================================== --- PSP/exceptionhandler/exception.c (revision 0) +++ PSP/exceptionhandler/exception.c (revision 0) @@ -0,0 +1,107 @@ +#include +#include +#include +#include +#include +#include + +PspDebugRegBlock exception_regs; + +extern SceModule module_info; +extern int _ftext; + +static const char *codeTxt[32] = +{ + "Interrupt", "TLB modification", "TLB load/inst fetch", "TLB store", + "Address load/inst fetch", "Address store", "Bus error (instr)", + "Bus error (data)", "Syscall", "Breakpoint", "Reserved instruction", + "Coprocessor unusable", "Arithmetic overflow", "Unknown 14", + "Unknown 15", "Unknown 16", "Unknown 17", "Unknown 18", "Unknown 19", + "Unknown 20", "Unknown 21", "Unknown 22", "Unknown 23", "Unknown 24", + "Unknown 25", "Unknown 26", "Unknown 27", "Unknown 28", "Unknown 29", + "Unknown 31" +}; + +static const unsigned char regName[32][5] = +{ + "zr", "at", "v0", "v1", "a0", "a1", "a2", "a3", + "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", + "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", + "t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra" +}; + +void ExceptionHandler(PspDebugRegBlock * regs) +{ + int i; + SceCtrlData pad; + + pspDebugScreenInit(); + pspDebugScreenSetBackColor(0x00FF0000); + pspDebugScreenSetTextColor(0xFFFFFFFF); + pspDebugScreenClear(); + pspDebugScreenPrintf("Your PSP has just crashed!\n"); + pspDebugScreenPrintf("Exception details:\n\n"); + + pspDebugScreenPrintf("Exception - %s\n", codeTxt[(regs->cause >> 2) & 31]); + pspDebugScreenPrintf("EPC - %08X / %s.text + %08X\n", (int)regs->epc, module_info.modname, (unsigned int)(regs->epc-(int)&_ftext)); + pspDebugScreenPrintf("Cause - %08X\n", (int)regs->cause); + pspDebugScreenPrintf("Status - %08X\n", (int)regs->status); + pspDebugScreenPrintf("BadVAddr - %08X\n", (int)regs->badvaddr); + for(i=0; i<32; i+=4) pspDebugScreenPrintf("%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]); + + sceKernelDelayThread(1000000); + pspDebugScreenPrintf("\n\nPress X to dump information on file exception.log and quit"); + pspDebugScreenPrintf("\nPress O to quit"); + + for (;;){ + sceCtrlReadBufferPositive(&pad, 1); + if (pad.Buttons & PSP_CTRL_CROSS){ + FILE *log = fopen("exception.log", "w"); + if (log != NULL){ + char testo[512]; + snprintf(testo, sizeof(testo), "Exception details:\n\n"); + fwrite(testo, 1, strlen(testo), log); + snprintf(testo, sizeof(testo), "Exception - %s\n", codeTxt[(regs->cause >> 2) & 31]); + fwrite(testo, 1, strlen(testo), log); + snprintf(testo, sizeof(testo), "EPC - %08X / %s.text + %08X\n", (int)regs->epc, module_info.modname, (unsigned int)(regs->epc-(int)&_ftext)); + fwrite(testo, 1, strlen(testo), log); + snprintf(testo, sizeof(testo), "Cause - %08X\n", (int)regs->cause); + fwrite(testo, 1, strlen(testo), log); + snprintf(testo, sizeof(testo), "Status - %08X\n", (int)regs->status); + fwrite(testo, 1, strlen(testo), log); + snprintf(testo, sizeof(testo), "BadVAddr - %08X\n", (int)regs->badvaddr); + fwrite(testo, 1, strlen(testo), log); + for(i=0; i<32; i+=4){ + snprintf(testo, sizeof(testo), "%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]); + fwrite(testo, 1, strlen(testo), log); + } + fclose(log); + } + break; + }else if (pad.Buttons & PSP_CTRL_CIRCLE){ + break; + } + sceKernelDelayThread(100000); + } + sceKernelExitGame(); +} + +void initExceptionHandler() +{ + SceKernelLMOption option; + int args[2], fd, modid; + + memset(&option, 0, sizeof(option)); + option.size = sizeof(option); + option.mpidtext = PSP_MEMORY_PARTITION_KERNEL; + option.mpiddata = PSP_MEMORY_PARTITION_KERNEL; + option.position = 0; + option.access = 1; + + if((modid = sceKernelLoadModule("exception.prx", 0, &option)) >= 0) + { + args[0] = (int)ExceptionHandler; + args[1] = (int)&exception_regs; + sceKernelStartModule(modid, 8, args, &fd, NULL); + } +} Index: PSP/exceptionhandler/exception.h =================================================================== --- PSP/exceptionhandler/exception.h (revision 0) +++ PSP/exceptionhandler/exception.h (revision 0) @@ -0,0 +1,36 @@ +/*typedef struct SceModule2 +{ + struct SceModule *next; // 0 + u16 attribute; // 4 + u8 version[2]; // 6 + char modname[27]; // 8 + char terminal; // 0x23 + char mod_state; // 0x24 + char unk1; // 0x25 + char unk2[2]; // 0x26 + u32 unk3; // 0x28 + SceUID modid; // 0x2C + u32 unk4; // 0x30 + SceUID mem_id; // 0x34 + u32 mpid_text; // 0x38 + u32 mpid_data; // 0x3C + void * ent_top; // 0x40 + unsigned int ent_size; // 0x44 + void * stub_top; // 0x48 + u32 stub_size; // 0x4C + u32 entry_addr_; // 0x50 + u32 unk5[4]; // 0x54 + u32 entry_addr; // 0x64 + u32 gp_value; // 0x68 + u32 text_addr; // 0x6C + u32 text_size; // 0x70 + u32 data_size; // 0x74 + u32 bss_size; // 0x78 + u32 nsegment; // 0x7C + u32 segmentaddr[4]; // 0x80 + u32 segmentsize[4]; // 0x90 +} SceModule2;*/ + +void initExceptionHandler(); + + Index: PSP/exceptionhandler/prx/exception_asm.S =================================================================== --- PSP/exceptionhandler/prx/exception_asm.S (revision 0) +++ PSP/exceptionhandler/prx/exception_asm.S (revision 0) @@ -0,0 +1,225 @@ +/* + * PSP Software Development Kit - http://www.pspdev.org + * ----------------------------------------------------------------------- + * Licensed under the BSD license, see LICENSE in PSPSDK root for details. + * + * pspexception_asm.S - Basic exception handler for applications. + * + * Copyright (c) 2005 James Forshaw + * + * $Id$ + */ +#include "as_reg_compat.h" + .set noreorder + .set noat + +#define BadVAddr $8 // Address for the most recent address-related exception +#define Status $12 // Processor status and control +#define Cause $13 // Cause of last general exception +#define EPC $14 // Program counter at last exception +#define PRId $15 // Processor identification and revision + +#define FSR $31 +#define FIR $0 + +#define REG_GPR_0 (6*4) +#define REG_GPR_1 (REG_GPR_0 + 4) +#define REG_GPR_2 (REG_GPR_1 + 4) +#define REG_GPR_3 (REG_GPR_2 + 4) +#define REG_GPR_4 (REG_GPR_3 + 4) +#define REG_GPR_5 (REG_GPR_4 + 4) +#define REG_GPR_6 (REG_GPR_5 + 4) +#define REG_GPR_7 (REG_GPR_6 + 4) +#define REG_GPR_8 (REG_GPR_7 + 4) +#define REG_GPR_9 (REG_GPR_8 + 4) +#define REG_GPR_10 (REG_GPR_9 + 4) +#define REG_GPR_11 (REG_GPR_10 + 4) +#define REG_GPR_12 (REG_GPR_11 + 4) +#define REG_GPR_13 (REG_GPR_12 + 4) +#define REG_GPR_14 (REG_GPR_13 + 4) +#define REG_GPR_15 (REG_GPR_14 + 4) +#define REG_GPR_16 (REG_GPR_15 + 4) +#define REG_GPR_17 (REG_GPR_16 + 4) +#define REG_GPR_18 (REG_GPR_17 + 4) +#define REG_GPR_19 (REG_GPR_18 + 4) +#define REG_GPR_20 (REG_GPR_19 + 4) +#define REG_GPR_21 (REG_GPR_20 + 4) +#define REG_GPR_22 (REG_GPR_21 + 4) +#define REG_GPR_23 (REG_GPR_22 + 4) +#define REG_GPR_24 (REG_GPR_23 + 4) +#define REG_GPR_25 (REG_GPR_24 + 4) +#define REG_GPR_26 (REG_GPR_25 + 4) +#define REG_GPR_27 (REG_GPR_26 + 4) +#define REG_GPR_28 (REG_GPR_27 + 4) +#define REG_GPR_29 (REG_GPR_28 + 4) +#define REG_GPR_30 (REG_GPR_29 + 4) +#define REG_GPR_31 (REG_GPR_30 + 4) + +#define REG_STATUS (REG_GPR_31 + 4) +#define REG_LO (REG_STATUS + 4) +#define REG_HI (REG_LO + 4) +#define REG_BADVADDR (REG_HI + 4) +#define REG_CAUSE (REG_BADVADDR + 4) +#define REG_EPC (REG_CAUSE + 4) + +#define REG_FPR_0 (REG_EPC + 4) +#define REG_FPR_1 (REG_FPR_0 + 4) +#define REG_FPR_2 (REG_FPR_1 + 4) +#define REG_FPR_3 (REG_FPR_2 + 4) +#define REG_FPR_4 (REG_FPR_3 + 4) +#define REG_FPR_5 (REG_FPR_4 + 4) +#define REG_FPR_6 (REG_FPR_5 + 4) +#define REG_FPR_7 (REG_FPR_6 + 4) +#define REG_FPR_8 (REG_FPR_7 + 4) +#define REG_FPR_9 (REG_FPR_8 + 4) +#define REG_FPR_10 (REG_FPR_9 + 4) +#define REG_FPR_11 (REG_FPR_10 + 4) +#define REG_FPR_12 (REG_FPR_11 + 4) +#define REG_FPR_13 (REG_FPR_12 + 4) +#define REG_FPR_14 (REG_FPR_13 + 4) +#define REG_FPR_15 (REG_FPR_14 + 4) +#define REG_FPR_16 (REG_FPR_15 + 4) +#define REG_FPR_17 (REG_FPR_16 + 4) +#define REG_FPR_18 (REG_FPR_17 + 4) +#define REG_FPR_19 (REG_FPR_18 + 4) +#define REG_FPR_20 (REG_FPR_19 + 4) +#define REG_FPR_21 (REG_FPR_20 + 4) +#define REG_FPR_22 (REG_FPR_21 + 4) +#define REG_FPR_23 (REG_FPR_22 + 4) +#define REG_FPR_24 (REG_FPR_23 + 4) +#define REG_FPR_25 (REG_FPR_24 + 4) +#define REG_FPR_26 (REG_FPR_25 + 4) +#define REG_FPR_27 (REG_FPR_26 + 4) +#define REG_FPR_28 (REG_FPR_27 + 4) +#define REG_FPR_29 (REG_FPR_28 + 4) +#define REG_FPR_30 (REG_FPR_29 + 4) +#define REG_FPR_31 (REG_FPR_30 + 4) + +#define REG_FSR (REG_FPR_31 + 4) +#define REG_FIR (REG_FSR + 4) +#define REG_FP (REG_FIR + 4) + + .extern exception_regs + .extern curr_handler + + .global _pspDebugExceptionHandler + .ent _pspDebugExceptionHandler +_pspDebugExceptionHandler: + nop + nop + + lw $v0, exception_regs + sw $0, REG_GPR_0($v0) + sw $1, REG_GPR_1($v0) + + cfc0 $1, $4 # Get original v0 + sw $1, REG_GPR_2($v0) + cfc0 $1, $5 # Get original v1 + sw $1, REG_GPR_3($v0) + sw $4, REG_GPR_4($v0) + sw $5, REG_GPR_5($v0) + sw $6, REG_GPR_6($v0) + sw $7, REG_GPR_7($v0) + sw $8, REG_GPR_8($v0) + sw $9, REG_GPR_9($v0) + sw $10, REG_GPR_10($v0) + sw $11, REG_GPR_11($v0) + sw $12, REG_GPR_12($v0) + sw $13, REG_GPR_13($v0) + sw $14, REG_GPR_14($v0) + sw $15, REG_GPR_15($v0) + sw $16, REG_GPR_16($v0) + sw $17, REG_GPR_17($v0) + sw $18, REG_GPR_18($v0) + sw $19, REG_GPR_19($v0) + sw $20, REG_GPR_20($v0) + sw $21, REG_GPR_21($v0) + sw $22, REG_GPR_22($v0) + sw $23, REG_GPR_23($v0) + sw $24, REG_GPR_24($v0) + sw $25, REG_GPR_25($v0) + sw $26, REG_GPR_26($v0) + sw $27, REG_GPR_27($v0) + sw $28, REG_GPR_28($v0) + sw $29, REG_GPR_29($v0) + sw $30, REG_GPR_30($v0) + sw $31, REG_GPR_31($v0) + + mflo $v1 + sw $v1, REG_LO($v0) + mfhi $v1 + sw $v1, REG_HI($v0) + mfc0 $v1, BadVAddr + sw $v1, REG_BADVADDR($v0) + mfc0 $v1, Cause + sw $v1, REG_CAUSE($v0) + mfc0 $v1, EPC + sw $v1, REG_EPC($v0) + mfc0 $v1, Status + sw $v1, REG_STATUS($v0) + +# Check if cop1 is enable and skip if not + lui $a0, 0x2000 + and $a0, $a0, $v1 + beq $a0, $0, 1f + nop + + swc1 $0, REG_FPR_0($v0) + swc1 $1, REG_FPR_1($v0) + swc1 $2, REG_FPR_2($v0) + swc1 $3, REG_FPR_3($v0) + swc1 $4, REG_FPR_4($v0) + swc1 $5, REG_FPR_5($v0) + swc1 $6, REG_FPR_6($v0) + swc1 $7, REG_FPR_7($v0) + swc1 $8, REG_FPR_8($v0) + swc1 $9, REG_FPR_9($v0) + swc1 $10, REG_FPR_10($v0) + swc1 $11, REG_FPR_11($v0) + swc1 $12, REG_FPR_12($v0) + swc1 $13, REG_FPR_13($v0) + swc1 $14, REG_FPR_14($v0) + swc1 $15, REG_FPR_15($v0) + swc1 $16, REG_FPR_16($v0) + swc1 $17, REG_FPR_17($v0) + swc1 $18, REG_FPR_18($v0) + swc1 $19, REG_FPR_19($v0) + swc1 $20, REG_FPR_20($v0) + swc1 $21, REG_FPR_21($v0) + swc1 $22, REG_FPR_22($v0) + swc1 $23, REG_FPR_23($v0) + swc1 $24, REG_FPR_24($v0) + swc1 $25, REG_FPR_25($v0) + swc1 $26, REG_FPR_26($v0) + swc1 $27, REG_FPR_27($v0) + swc1 $28, REG_FPR_28($v0) + swc1 $29, REG_FPR_29($v0) + swc1 $30, REG_FPR_30($v0) + swc1 $31, REG_FPR_31($v0) + + cfc1 $t0, FSR + sw $t0, REG_FSR($v0) + cfc1 $t0, FIR + sw $t0, REG_FIR($v0) + ctc1 $0, FSR # Clear any cause flags + +# Jump target for ignore cop1 +1: + + sw $sp, REG_FP($v0) + move $a0, $v0 + + lw $2, curr_handler + mtc0 $2, $14 + nop + nop + eret + nop + nop + + .end _pspDebugExceptionHandler + + #include "pspimport.s" + + IMPORT_START "ExceptionManagerForKernel",0x00010011 + IMPORT_FUNC "ExceptionManagerForKernel",0x565C0B0E,sceKernelRegisterDefaultExceptionHandler371 Index: PSP/exceptionhandler/prx/exports.exp =================================================================== --- PSP/exceptionhandler/prx/exports.exp (revision 0) +++ PSP/exceptionhandler/prx/exports.exp (revision 0) @@ -0,0 +1,7 @@ +PSP_BEGIN_EXPORTS +PSP_EXPORT_START(syslib, 0, 0x8000) +PSP_EXPORT_FUNC_HASH(module_start) +PSP_EXPORT_VAR_HASH(module_info) +PSP_EXPORT_END + +PSP_END_EXPORTS Index: PSP/exceptionhandler/prx/main.c =================================================================== --- PSP/exceptionhandler/prx/main.c (revision 0) +++ PSP/exceptionhandler/prx/main.c (revision 0) @@ -0,0 +1,25 @@ +#include +#include +#include + +PSP_MODULE_INFO("exception", 0x1007, 1, 1); // better not unload + +PspDebugErrorHandler curr_handler; +PspDebugRegBlock *exception_regs; + +void _pspDebugExceptionHandler(void); +int sceKernelRegisterDefaultExceptionHandler(void *func); +int sceKernelRegisterDefaultExceptionHandler371(void *func); + +int module_start(SceSize args, void *argp) +{ + if(args != 8) return -1; + curr_handler = (PspDebugErrorHandler)((int *)argp)[0]; + exception_regs = (PspDebugRegBlock *)((int *)argp)[1]; + if(!curr_handler || !exception_regs) return -1; + + if(sceKernelDevkitVersion() < 0x03070110) + return sceKernelRegisterDefaultExceptionHandler((void *)_pspDebugExceptionHandler); + else + return sceKernelRegisterDefaultExceptionHandler371((void *)_pspDebugExceptionHandler); +} Index: PSP/exceptionhandler/prx/makefile =================================================================== --- PSP/exceptionhandler/prx/makefile (revision 0) +++ PSP/exceptionhandler/prx/makefile (revision 0) @@ -0,0 +1,20 @@ +TARGET = exception +OBJS = main.o exception_asm.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_KERNEL_LIBC = 1 +USE_KERNEL_LIBS = 1 + +INCDIR = +CFLAGS = -Os -G0 -Wall -nostartfiles +CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti +ASFLAGS = $(CFLAGS) + +LIBDIR = + +PSPSDK=$(shell psp-config --pspsdk-path) +include $(PSPSDK)/lib/build.mak Index: PSP/main.c =================================================================== --- PSP/main.c (revision 46) +++ PSP/main.c (working copy) @@ -6,6 +6,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -21,6 +25,10 @@ #include "openssl/rand.h" #endif +#ifdef WITH_EXPCETION_HANDLER +#include "exceptionhandler/exception.h" +#endif + #ifdef WITH_PSP2D #include #endif @@ -50,6 +58,7 @@ #else pspInterruptOccurred = 1; #endif + printf("--------------------------------------------------------------------------------\n"); fclose(stdout); fclose(stderr); sceKernelExitGame(); @@ -104,28 +113,52 @@ tzset(); } +// Set heap size: +/*void setHeapSize(int newSize) +{ + int size = newSize / 1024; + if (size * 1024 < newSize) + size++; + sce_newlib_heap_kb_size = size; +}*/ + int main(int argc, char *argv[]) { SetupCallbacks(); stdout = fopen("pytrace.txt", "a+"); stderr = stdout; setenv("PYTHONPATH", "python.zip", 1); + setenv("PYTHONHOME", "ms0:/", 1); +#ifdef WITH_EXPCETION_HANDLER + initExceptionHandler(); +#endif initTimezone(); time_t now; sceKernelLibcTime(&now); - if (sceUtilityLoadNetModule(1) < 0) +#ifdef WITH_PSPNET + if (sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON) < 0) return 1; - if(sceUtilityLoadNetModule(3) < 0) + if(sceUtilityLoadNetModule(PSP_NET_MODULE_INET) < 0) return 1; - if(pspSdkInetInit() != 0) - return 1; + //if(pspSdkInetInit() != 0) + // return 1; + if (sceNetInit(0x20000, 0x20, 0x1000, 0x20, 0x1000) != 0) + return 1; + if (sceNetInetInit() != 0) + return 1; + if (sceNetResolverInit() != 0) + return 1; + if (sceNetApctlInit(0x1400, 0x42) != 0) + return 1; +#endif #ifdef WITH_PSP2D sceGuInit(); #endif #ifdef WITH_OSLIB oslInit(1); + oslSetExitCallback(exit_callback); #endif #ifdef WITH_SSL @@ -137,9 +170,10 @@ char path[1024]; printf("-------------- Python-PSP started %s\n", ctime(&now)); - printf("Free memory: %d\n", sceKernelTotalFreeMemSize()); - printf("PyPSP running in: %s\n", getcwd(path, sizeof(path))); - printf("Search path: %s\n", Py_GetPath()); + printf("Free stack memory: %d\n", sceKernelGetThreadStackFreeSize(0)); + printf("Free memory : %d\n", sceKernelTotalFreeMemSize()); + printf("PyPSP running in : %s\n", getcwd(path, sizeof(path))); + printf("Search path : %s\n", Py_GetPath()); printf("\n"); //scePowerSetClockFrequency(333, 333, 166); @@ -149,7 +183,7 @@ Py_Initialize(); PySys_SetArgv(argc, argv); - + fp = fopen("script.py", "r"); if (fp) { PyRun_SimpleFile(fp, "script.py"); Index: PSP/Makefile =================================================================== --- PSP/Makefile (revision 46) +++ PSP/Makefile (working copy) @@ -1,14 +1,21 @@ # Default build: psp2d, pspnet, pspsnd # If using OSLIB disable PSP2D and PSPSND +# If using OSLIB MOD disable PSP2D and PSPSND, enable OSLIB and OSLIB_MOD +# +# The exception handler is useful only while developing and testing the interpreter. +# To enable it set to 1 WITH_EXPCETION_HANDLER, build the prx in exceptionhandler\prx and copy +# exception.prx to the PSP with the Stackless EBOOT.PBP WITH_PSP2D = 1 WITH_PSPSND = 1 WITH_PSPNET = 1 WITH_OSLIB = 0 +WITH_OSLIB_MOD = 0 WITH_SQLITE = 1 WITH_PSPOGG = 1 WITH_PSPMP3 = 1 +WITH_EXPCETION_HANDLER = 0 WITH_SSL = 0 # SSL not working yet include Makefile.base Index: PSP/Makefile.base =================================================================== --- PSP/Makefile.base (revision 46) +++ PSP/Makefile.base (working copy) @@ -195,7 +195,7 @@ ../../pymaging/main.o \ ../../pymaging/mask.o \ ../../pymaging/transform.o - + OBJS_PSPSND = \ pspsnd/pspsnd.o \ pspsnd/sound.o \ @@ -204,6 +204,8 @@ OBJS_PSPNET = pspnet/pspnet.o OBJS_OSLIB = osl/osl.o osl/image.o osl/ctrl.o osl/sound.o osl/map.o osl/font.o +OBJS_OSLIB_MOD = osl/sfont.o +OBJS_EXCEPTION_HANDLER = exceptionhandler/exception.o OBJS_PSPOGG = pspogg/oggplayer.o pspogg/pspogg.o @@ -247,10 +249,21 @@ ifeq ($(WITH_OSLIB),1) OBJS += $(OBJS_OSLIB) -LIBS += -losl -lpng -lz -lpspgu -lpspaudio +LIBS += -losl -lpng -lz -lpspgu -lpspgum -lpspaudio -lpsphprm -ljpeg CPPFLAGS += -DWITH_OSLIB endif +ifeq ($(WITH_OSLIB_MOD),1) +OBJS += $(OBJS_OSLIB_MOD) +LIBS += -lpsphttp -lpspssl -lpspwlan +CPPFLAGS += -DWITH_OSLIB_MOD +endif + +ifeq ($(WITH_EXPCETION_HANDLER),1) +OBJS += $(OBJS_EXCEPTION_HANDLER) +CPPFLAGS += -DWITH_EXPCETION_HANDLER +endif + ifeq ($(WITH_PSPOGG),1) OBJS += $(OBJS_PSPOGG) LIBS += -lvorbisidec -lpspaudiolib -lpspaudio @@ -259,7 +272,7 @@ ifeq ($(WITH_PSPMP3),1) OBJS += $(OBJS_PSPMP3) -LIBS += -lmad -lpspaudiolib -lpspaudio +LIBS += -lpspaudio -lpspaudiocodec CPPFLAGS += -DWITH_PSPMP3 endif @@ -276,7 +289,7 @@ LIBS += -lc -lm -CFLAGS = -Os -G0 -Wall -Wno-strict-aliasing -fPIC +CFLAGS = -Os -g -G0 -Wall -Wno-strict-aliasing -fPIC CXXFLAGS = $(CFLAGS) -fno-rtti -fno-strict-aliasing ASFLAGS = $(CFLAGS) @@ -289,7 +302,7 @@ @cp $(PSPDEV)/psp/sdk/include/pspkerror.h ./pspkerror.h python generr.py @rm pspkerror.h - + release: distclean $(PSP_EBOOT) @echo "###### Create release package ######" @echo "1. Creating release directory $(RELEASE_DIRECTORY)/" Index: PSP/Makefile_oslib =================================================================== --- PSP/Makefile_oslib (revision 0) +++ PSP/Makefile_oslib (revision 0) @@ -0,0 +1,21 @@ + +# Default build: psp2d, pspnet, pspsnd +# If using OSLIB disable PSP2D and PSPSND +# If using OSLIB MOD disable PSP2D and PSPSND, enable OSLIB and OSLIB_MOD +# +# The exception handler is useful only while developing and testing the interpreter. +# To enable it set to 1 WITH_EXPCETION_HANDLER, build the prx in exceptionhandler\prx and copy +# exception.prx to the PSP with the Stackless EBOOT.PBP + +WITH_PSP2D = 0 +WITH_PSPSND = 0 +WITH_PSPNET = 1 +WITH_OSLIB = 1 +WITH_OSLIB_MOD = 1 +WITH_SQLITE = 0 +WITH_PSPOGG = 0 +WITH_PSPMP3 = 1 +WITH_EXPCETION_HANDLER = 1 +WITH_SSL = 0 # SSL not working yet + +include Makefile.base Index: PSP/Modules/pspos.c =================================================================== --- PSP/Modules/pspos.c (revision 46) +++ PSP/Modules/pspos.c (working copy) @@ -833,6 +833,19 @@ } */ +static PyObject* PyPSP_freemsspace(PyObject *self, PyObject *args) +{ + if (!PyArg_ParseTuple(args, ":freemsspace")) + return NULL; + + unsigned int buf[5]; + unsigned int *pbuf = buf; + sceIoDevctl("ms0:", 0x02425818, &pbuf, sizeof(pbuf), 0, 0); + double result = buf[1]*buf[3]*buf[4]; + + return Py_BuildValue("d", result); +} + //========================================================================== // @@ -895,7 +908,7 @@ return Py_BuildValue("i", total); } -static PyObject* PyPSP_sendIR(PyObject *self, PyObject *args) +/*static PyObject* PyPSP_sendIR(PyObject *self, PyObject *args) { struct sircs_data *data; PyObject *params; @@ -992,7 +1005,7 @@ Py_INCREF(Py_None); return Py_None; -} +}*/ //========================================================================== // @@ -1036,6 +1049,8 @@ { "getnickname", PyPSP_getnickname, METH_VARARGS, "" }, //{ "setnickname", PyPSP_setnickname, METH_VARARGS, "" }, + { "freemsspace", PyPSP_freemsspace, METH_VARARGS, "" }, + { "realmem", PyPSP_realmem, METH_VARARGS, "" }, // { "sendIR", PyPSP_sendIR, METH_VARARGS, "" }, Index: PSP/osl/ctrl.c =================================================================== --- PSP/osl/ctrl.c (revision 46) +++ PSP/osl/ctrl.c (working copy) @@ -6,7 +6,6 @@ /********************************************************************** Created: 17 Feb 2007 - Copyright (C) 2007 fraca7@free.fr This library is free software; you can redistribute it and/or Index: PSP/osl/image.c =================================================================== --- PSP/osl/image.c (revision 46) +++ PSP/osl/image.c (working copy) @@ -521,7 +521,7 @@ if (PyErr_CheckSignals()) return NULL; - return Py_BuildValue("i", self->pImg->autoStrip); + return Py_BuildValue("i", oslImageGetAutoStrip(self->pImg)); } static int image_setautoStrip(PyImage *self, PyObject *value, void *closure) @@ -541,7 +541,7 @@ return -1; } - self->pImg->autoStrip = PyInt_AsLong(value); + oslImageSetAutoStrip(self->pImg, PyInt_AsLong(value)); return 0; } @@ -591,14 +591,55 @@ //========================================================================== // Methods +static PyObject* image_convert(PyImage *self, + PyObject *args, + PyObject *kwargs) +{ + OSL_IMAGE *pImg; + PyImage *ret; + int newLocation, newFormat; + if (!PyArg_ParseTuple(args, "ii:convert", + &newLocation, &newFormat)) + return NULL; + + pImg = oslConvertImageTo(self->pImg, newLocation, newFormat); + + if (!pImg) + { + PyErr_SetString(osl_Error, "Could not convert image"); + return NULL; + } + + ret = (PyImage*)PyType_GenericNew(PPyImageType, NULL, NULL); + ret->pImg = pImg; + + return (PyObject*)ret; +} + +static PyObject* image_move(PyImage *self, + PyObject *args, + PyObject *kwargs) +{ + int newLocation; + + if (!PyArg_ParseTuple(args, "i:move", &newLocation)) + return NULL; + + oslMoveImageTo(self->pImg, newLocation); + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject* image_copy(PyImage *self, PyObject *args, PyObject *kwargs) { PyImage *other; + int newLocation = self->pImg->location; - if (!PyArg_ParseTuple(args, "O:copy", &other)) + if (!PyArg_ParseTuple(args, "O|i:copy", &other, &newLocation)) return NULL; if (!PyType_IsSubtype(((PyObject*)other)->ob_type, PPyImageType)) @@ -607,7 +648,7 @@ return NULL; } - oslCopyImage(self->pImg, other->pImg); + other->pImg = oslCreateImageCopy(self->pImg, newLocation); Py_INCREF(Py_None); return Py_None; @@ -630,10 +671,12 @@ PyObject *args, PyObject *kwargs) { - if (!PyArg_ParseTuple(args, ":draw")) + int x = self->pImg->x; + int y = self->pImg->y; + if (!PyArg_ParseTuple(args, "|ii:draw", &x, &y)) return NULL; - oslDrawImage(self->pImg); + oslDrawImageXY(self->pImg, x, y); Py_INCREF(Py_None); return Py_None; @@ -704,13 +747,13 @@ return (PyObject*)ret; } -static PyObject* image_swizzle(PyImage *self, +static PyObject* image_swizzleto(PyImage *self, PyObject *args, PyObject *kwargs) { PyImage *other; - if (!PyArg_ParseTuple(args, "O:swizzle", &other)) + if (!PyArg_ParseTuple(args, "O:swizzleto", &other)) return NULL; if (!PyType_IsSubtype(((PyObject*)other)->ob_type, PPyImageType)) @@ -719,12 +762,25 @@ return NULL; } - oslSwizzleImage(other->pImg, self->pImg); + oslSwizzleImageTo(other->pImg, self->pImg); Py_INCREF(Py_None); return Py_None; } +static PyObject* image_swizzle(PyImage *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":swizzle")) + return NULL; + + oslSwizzleImage(self->pImg); + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject* image_clear(PyImage *self, PyObject *args, PyObject *kwargs) @@ -756,8 +812,129 @@ return Py_None; } +static PyObject* image_getpixel(PyImage *self, + PyObject *args, + PyObject *kwargs) +{ + unsigned int x,y; + + if (!PyArg_ParseTuple(args, "II:getpixel", &x, &y)) + return NULL; + + int result = oslConvertColorEx(self->pImg->palette, OSL_PF_8888, self->pImg->pixelFormat, oslGetImagePixel(self->pImg, x, y)); + //int result = oslGetImagePixel(self->pImg, x, y); + + return Py_BuildValue("i", result); +} + +static PyObject* image_setpixel(PyImage *self, + PyObject *args, + PyObject *kwargs) +{ + unsigned int x,y; + int pixelValue; + + if (!PyArg_ParseTuple(args, "IIi:setpixel", &x, &y, &pixelValue)) + return NULL; + + oslLockImage(self->pImg); + pixelValue = oslConvertColorEx(self->pImg->palette, self->pImg->pixelFormat, OSL_PF_8888, pixelValue); + oslSetImagePixel(self->pImg, x, y, pixelValue); + oslUnlockImage(self->pImg); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* image_setRotationCenter(PyImage *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":setRotationCenter")) + return NULL; + + oslSetImageRotCenter(self->pImg); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* image_mirrorH(PyImage *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":mirrorH")) + return NULL; + + oslMirrorImageH(self->pImg); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* image_mirrorV(PyImage *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":mirrorV")) + return NULL; + + oslMirrorImageV(self->pImg); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* image_rotate(PyImage *self, + PyObject *args, + PyObject *kwargs) +{ + int angle; + if (!PyArg_ParseTuple(args, "i:rotate", &angle)) + return NULL; + + self->pImg->angle += angle; + if (self->pImg->angle > 360) + self->pImg->angle -= 360; + else if (self->pImg->angle < -360) + self->pImg->angle += 360; + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* image_setFrameSize(PyImage *self, + PyObject *args, + PyObject *kwargs) +{ + unsigned int w,h; + if (!PyArg_ParseTuple(args, "II:setFrameSize", &w, &h)) + return NULL; + + oslSetImageFrameSize(self->pImg, w, h); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* image_setFrame(PyImage *self, + PyObject *args, + PyObject *kwargs) +{ + int frame; + if (!PyArg_ParseTuple(args, "i:setFrame", &frame)) + return NULL; + + oslSetImageFrame(self->pImg, frame); + + Py_INCREF(Py_None); + return Py_None; +} + static PyMethodDef image_methods[] = { + { "convert", (PyCFunction)image_convert, METH_VARARGS, "" }, { "copy", (PyCFunction)image_copy, METH_VARARGS, "" }, + { "move", (PyCFunction)image_move, METH_VARARGS, "" }, { "uncache", (PyCFunction)image_uncache, METH_VARARGS, "" }, { "draw", (PyCFunction)image_draw, METH_VARARGS, "" }, { "correctHalfBorder", (PyCFunction)image_correctHalfBorder, METH_VARARGS, "" }, @@ -765,9 +942,17 @@ { "unlock", (PyCFunction)image_unlock, METH_VARARGS, "" }, { "tile", (PyCFunction)image_tile, METH_VARARGS, "" }, { "swizzle", (PyCFunction)image_swizzle, METH_VARARGS, "" }, + { "swizzleto", (PyCFunction)image_swizzleto, METH_VARARGS, "" }, { "clear", (PyCFunction)image_clear, METH_VARARGS, "" }, { "write", (PyCFunction)image_write, METH_VARARGS, "" }, - + { "getpixel", (PyCFunction)image_getpixel, METH_VARARGS, "" }, + { "setpixel", (PyCFunction)image_setpixel, METH_VARARGS, "" }, + { "setRotationCenter", (PyCFunction)image_setRotationCenter, METH_VARARGS, "" }, + { "mirrorH", (PyCFunction)image_mirrorH, METH_VARARGS, "" }, + { "mirrorV", (PyCFunction)image_mirrorV, METH_VARARGS, "" }, + { "rotate", (PyCFunction)image_rotate, METH_VARARGS, "" }, + { "setFrameSize", (PyCFunction)image_setFrameSize, METH_VARARGS, "" }, + { "setFrame", (PyCFunction)image_setFrame, METH_VARARGS, "" }, { NULL } }; Index: PSP/osl/osl.c =================================================================== --- PSP/osl/osl.c (revision 46) +++ PSP/osl/osl.c (working copy) @@ -29,7 +29,6 @@ // $Id$ #include - #include "osl.h" #include "image.h" #include "ctrl.h" @@ -37,8 +36,18 @@ #include "map.h" #include "font.h" +#ifdef WITH_OSLIB_MOD +#include "sfont.h" +//#include "saveload.h" +#endif + PyObject* osl_Error = NULL; +#define FPS_UPDATE_RATE 0.25 +static int FPSCounter = 0; +static clock_t lastFPSUpdate = 0; +static int FPS = 0; + //========================================================================== // Functions @@ -65,6 +74,19 @@ return Py_None; } +static PyObject* osl_safeQuit(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":safeQuit")) + return NULL; + + osl_quit = 1; + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject* osl_initGfx(PyObject *self, PyObject *args, PyObject *kwargs) @@ -116,10 +138,34 @@ oslEndDrawing(); + //FPS: + FPSCounter++; + clock_t curticks = clock(); + float tPassed = (float)(curticks - lastFPSUpdate)/(float)CLOCKS_PER_SEC; + if (tPassed >= FPS_UPDATE_RATE) + { + FPS = (int)((float)FPSCounter * (1.0f / tPassed)); + FPSCounter = 0; + lastFPSUpdate = curticks; + } + Py_INCREF(Py_None); return Py_None; } +static PyObject* osl_endFrame(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":endFrame")) + return NULL; + + oslEndFrame(); + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject* osl_waitVSync(PyObject *self, PyObject *args, PyObject *kwargs) @@ -166,12 +212,41 @@ if (!PyArg_ParseTuple(args, ":syncFrame")) return NULL; - oslSyncFrame(); + int result = oslSyncFrame(); + return Py_BuildValue("i", result); +} + +static PyObject* osl_setFrameskip(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + int frameskip; + if (!PyArg_ParseTuple(args, "i:setFrameskip", + &frameskip)) + return NULL; + + oslSetFrameskip(frameskip); + Py_INCREF(Py_None); return Py_None; } +static PyObject* osl_setMaxFrameskip(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + int frameskip; + if (!PyArg_ParseTuple(args, "i:setMaxFrameskip", + &frameskip)) + return NULL; + + oslSetMaxFrameskip(frameskip); + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject* osl_syncFrameEx(PyObject *self, PyObject *args, PyObject *kwargs) @@ -202,6 +277,21 @@ return Py_None; } +static PyObject* osl_setQuitOnLoadFailure(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + int enabled; + if (!PyArg_ParseTuple(args, "i:setQuitOnLoadFailure", + &enabled)) + return NULL; + + oslSetQuitOnLoadFailure(enabled); + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject* osl_disableTransparentColor(PyObject *self, PyObject *args, PyObject *kwargs) @@ -311,6 +401,24 @@ return Py_None; } +static PyObject* osl_saveScreenshot(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + char *fileName; + + if (!PyArg_ParseTuple(args, "s:saveScreenshot", + &fileName)) + return NULL; + + oslWriteImageFilePNG(OSL_SECONDARY_BUFFER, fileName, OSL_WRI_ALPHA); + + + Py_INCREF(Py_None); + return Py_None; +} + + static PyObject* osl_setAlpha(PyObject *self, PyObject *args, PyObject *kwargs) @@ -326,26 +434,17 @@ return Py_None; } -static PyObject* osl_systemMessage(PyObject *self, - PyObject *args, - PyObject *kwargs) +static PyObject* osl_setDithering(PyObject *self, + PyObject *args, + PyObject *kwargs) { - char *msg; - - if (!PyArg_ParseTuple(args, "s:systemMessage", &msg)) + int enabled; + if (!PyArg_ParseTuple(args, "i:setDithering", + &enabled)) return NULL; - // We strdup() here since other threads could destroy the last - // reference to the string + oslSetDithering(enabled); - msg = strdup(msg); - - Py_BEGIN_ALLOW_THREADS - oslSystemMessage(msg); - Py_END_ALLOW_THREADS - - free(msg); - Py_INCREF(Py_None); return Py_None; } @@ -419,7 +518,7 @@ { PyObject* buffer; - if (!PyArg_ParseTuple(args, "O:setDrawBuffer"), &buffer) + if (!PyArg_ParseTuple(args, "O:setDrawBuffer", &buffer)) return NULL; if (PyInt_Check(buffer)) @@ -607,6 +706,22 @@ return Py_None; } +static PyObject* osl_setKeyAnalogToDPad(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + int sensivity; + + if (!PyArg_ParseTuple(args, "i:setKeyAnalogToDPad", + &sensivity)) + return NULL; + + oslSetKeyAnalogToDPad(sensivity); + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject* osl_setKeyAutorepeatMask(PyObject *self, PyObject *args, PyObject *kwargs) @@ -668,20 +783,15 @@ return Py_None; } -static PyObject* osl_setChannelVolume(PyObject *self, - PyObject *args, - PyObject *kwargs) + +static PyObject* osl_getFPS(PyObject *self, + PyObject *args, + PyObject *kwargs) { - int channel, left, right; - - if (!PyArg_ParseTuple(args, "iii:setChannelVolume", - &channel, &left, &right)) + if (!PyArg_ParseTuple(args, ":getFPS")) return NULL; - oslSetChannelVolume(channel, left, right); - - Py_INCREF(Py_None); - return Py_None; + return Py_BuildValue("i", FPS); } //========================================================================== @@ -720,7 +830,507 @@ return Py_None; } +#ifdef WITH_OSLIB_MOD //========================================================================== +//OSLib mod misc functions: +static PyObject* osl_setHoldForAnalog(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + int hold; + + if (!PyArg_ParseTuple(args, "i:setHoldForAnalog", + &hold)) + return NULL; + + oslSetHoldForAnalog(hold); + + Py_INCREF(Py_None); + return Py_None; +} + + +//========================================================================== +//OSLib mod intrafont functions: +static PyObject* osl_intraFontInit(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + unsigned int options; + + if (!PyArg_ParseTuple(args, "I:intraFontInit", + &options)) + return NULL; + + oslIntraFontInit(options); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* osl_intraFontShutdown(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":intraFontShutdown")) + return NULL; + + oslIntraFontShutdown(); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* osl_intraFontSetStyle(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + PyFont *font; + float size; + unsigned int color, shadowcolor, options; + + if (!PyArg_ParseTuple(args, "OfIII:intraFontSetStyle", + &font, &size, &color, &shadowcolor, &options)) + return NULL; + + if (!PyType_IsSubtype(((PyObject*)font)->ob_type, PPyFontType)) + { + PyErr_SetString(PyExc_TypeError, "Argument must be an osl.Font"); + return NULL; + } + + oslIntraFontSetStyle(font->pFont, size, color, shadowcolor, options); + + Py_INCREF(Py_None); + return Py_None; +} + +//========================================================================== +//OSLib mod dialog functions: +static PyObject* osl_initMessageDialog(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + char *message; + int enableYesno; + + if (!PyArg_ParseTuple(args, "si:initMessageDialog", + &message, &enableYesno)) + return NULL; + + oslInitMessageDialog(message, enableYesno); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* osl_initErrorDialog(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + int error; + + if (!PyArg_ParseTuple(args, "i:initErrorDialog", + &error)) + return NULL; + + oslInitErrorDialog(error); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* osl_drawDialog(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":drawDialog")) + return NULL; + + oslDrawDialog(); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* osl_getDialogType(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":getDialogType")) + return NULL; + + int type = oslGetDialogType(); + return Py_BuildValue("i", type); +} + + +static PyObject* osl_getDialogStatus(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":getDialogStatus")) + return NULL; + + int status = oslGetDialogStatus(); + return Py_BuildValue("i", status); +} + +static PyObject* osl_getDialogButtonPressed(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":getDialogButtonPressed")) + return NULL; + + int button = oslGetDialogButtonPressed(); + return Py_BuildValue("i", button); +} + +static PyObject* osl_initNetDialog(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":initNetDialog")) + return NULL; + + oslInitNetDialog(); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* osl_dialogGetResult(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":dialogGetResult")) + return NULL; + + int result = oslDialogGetResult(); + return Py_BuildValue("i", result); +} + + +static PyObject* osl_endDialog(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":endDialog")) + return NULL; + + oslEndDialog(); + + Py_INCREF(Py_None); + return Py_None; +} + +//========================================================================== +//OSLib mod save and load functions: +/*static PyObject* osl_initSaveDialog(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + struct oslSaveLoad *saveLoad; + + if (!PyArg_ParseTuple(args, "O:initSaveDialog", + &saveLoad)) + return NULL; + + if (!PyType_IsSubtype(((PyObject*)saveLoad)->ob_type, PPySaveLoadType )) + { + PyErr_SetString(PyExc_TypeError, "Argument must be an osl.SaveLoad"); + return NULL; + } + + oslInitSaveDialog(saveLoad); + + Py_INCREF(Py_None); + return Py_None; +} + + +static PyObject* osl_initLoadDialog(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + struct oslSaveLoad *saveLoad; + + if (!PyArg_ParseTuple(args, "O:initLoadDialog", + &saveLoad)) + return NULL; + + if (!PyType_IsSubtype(((PyObject*)saveLoad)->ob_type, PPySaveLoadType )) + { + PyErr_SetString(PyExc_TypeError, "Argument must be an osl.SaveLoad"); + return NULL; + } + + oslInitLoadDialog(saveLoad); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* osl_drawSaveLoad(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":drawSaveLoad")) + return NULL; + + oslDrawSaveLoad(); + + Py_INCREF(Py_None); + return Py_None; +} + + +static PyObject* osl_getSaveLoadStatus(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":getSaveLoadStatus")) + return NULL; + + int status = oslGetLoadSaveStatus(); + return Py_BuildValue("i", status); +} + +static PyObject* osl_getSaveLoadType(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":getSaveLoadType")) + return NULL; + + int status = oslGetSaveLoadType(); + return Py_BuildValue("i", status); +} + +static PyObject* osl_saveLoadGetResult(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":saveLoadGetResult")) + return NULL; + + int status = oslSaveLoadGetResult(); + return Py_BuildValue("i", status); +} + +static PyObject* osl_endSaveLoad(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":endSaveLoad")) + return NULL; + + oslEndSaveLoadDialog(); + + Py_INCREF(Py_None); + return Py_None; +}*/ + +//========================================================================== +//OSLib mod OSK functions: +static PyObject* osl_initOsk(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + char *descStr; + char *initialStr; + int textLimit, linesNumber; + int language = -1; + + if (!PyArg_ParseTuple(args, "ssii|i:initOsk", + &descStr, &initialStr, &textLimit, &linesNumber, &language)) + return NULL; + + oslInitOsk(descStr, initialStr, textLimit, linesNumber, language); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* osl_drawOsk(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":drawOsk")) + return NULL; + + oslDrawOsk(); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* osl_oskIsActive(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":oskIsActive")) + return NULL; + + int status = oslOskIsActive(); + return Py_BuildValue("i", status); +} + +static PyObject* osl_getOskStatus(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":getOskStatus")) + return NULL; + + int status = oslGetOskStatus(); + return Py_BuildValue("i", status); +} + +static PyObject* osl_oskGetResult(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":oskGetResult")) + return NULL; + + int status = oslOskGetResult(); + return Py_BuildValue("i", status); +} + + +static PyObject* osl_oskGetText(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":oskGetText")) + return NULL; + + char result[256] = ""; + oslOskGetText(result); + return Py_BuildValue("s", result); +} + +static PyObject* osl_endOsk(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":endOsk")) + return NULL; + + oslEndOsk(); + + Py_INCREF(Py_None); + return Py_None; +} + +//========================================================================== +//OSLib mod network functions: +static PyObject* osl_netInit(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":netInit")) + return NULL; + + int result = oslNetInit();; + + return Py_BuildValue("i", result); +} + +static PyObject* osl_netTerm(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":netTerm")) + return NULL; + + int result = oslNetTerm();; + + return Py_BuildValue("i", result); +} + +//========================================================================== +//OSLib mod browser functions: +/*static PyObject* osl_browserInit(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + char *url; + char *downloadDir; + int browserMemory; + unsigned int displaymode = PSP_UTILITY_HTMLVIEWER_DISPLAYMODE_SMART_FIT; + unsigned int options = PSP_UTILITY_HTMLVIEWER_DISABLE_STARTUP_LIMITS | PSP_UTILITY_HTMLVIEWER_ENABLE_FLASH; + unsigned int interfacemode = PSP_UTILITY_HTMLVIEWER_INTERFACEMODE_FULL; + unsigned int connectmode = PSP_UTILITY_HTMLVIEWER_CONNECTMODE_MANUAL_ALL; + + if (!PyArg_ParseTuple(args, "ssi|IIII:browserInit", &url, &downloadDir, &browserMemory, + &displaymode, &options, &interfacemode, + &connectmode)) + return NULL; + + if (sceKernelTotalFreeMemSize() < browserMemory + 256) + { + setHeapSize( -(browserMemory + 256) ); + } + int result = oslBrowserInit(url, downloadDir, browserMemory, displaymode, options, interfacemode, connectmode); + + return Py_BuildValue("i", result); +} + + +static PyObject* osl_drawBrowser(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":drawBrowser")) + return NULL; + + oslDrawBrowser(); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* osl_browserIsActive(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":browserIsActive")) + return NULL; + + int status = oslBrowserIsActive(); + return Py_BuildValue("i", status); +} + +static PyObject* osl_getBrowserStatus(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":getBrowserStatus")) + return NULL; + + int status = oslGetBrowserStatus(); + return Py_BuildValue("i", status); +} + + +static PyObject* osl_endBrowser(PyObject *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":endBrowser")) + return NULL; + + oslEndBrowser(); + + Py_INCREF(Py_None); + return Py_None; +}*/ +#endif + +//========================================================================== // Macros static PyObject* osl_RGB(PyObject *self, @@ -814,32 +1424,41 @@ static PyMethodDef functions[] = { DECLFUNC(mustQuit, ""), + DECLFUNC(safeQuit, ""), DECLFUNC(doQuit, ""), DECLFUNC(initGfx, ""), DECLFUNC(startDrawing, ""), DECLFUNC(syncDrawing, ""), DECLFUNC(endDrawing, ""), + DECLFUNC(endFrame, ""), DECLFUNC(waitVSync, ""), DECLFUNC(swapBuffers, ""), DECLFUNC(endGfx, ""), + DECLFUNC(getFPS, ""), DECLFUNC(syncFrame, ""), DECLFUNC(syncFrameEx, ""), DECLFUNC(setTransparentColor, ""), DECLFUNC(disableTransparentColor, ""), + DECLFUNC(setQuitOnLoadFailure, ""), + + DECLFUNC(setFrameskip, ""), + DECLFUNC(setMaxFrameskip, ""), + DECLFUNC(drawLine, ""), DECLFUNC(drawRect, ""), DECLFUNC(drawFillRect, ""), DECLFUNC(drawGradientRect, ""), + DECLFUNC(saveScreenshot, ""), DECLFUNC(clearScreen, ""), DECLFUNC(setScreenClipping, ""), + DECLFUNC(setDithering, ""), DECLFUNC(setAlpha, ""), - DECLFUNC(systemMessage, ""), DECLFUNC(messageBox, ""), DECLFUNC(waitKey, ""), @@ -864,11 +1483,10 @@ DECLFUNC(setKeyAutorepeatMask, ""), DECLFUNC(setKeyAutorepeatInit, ""), DECLFUNC(setKeyAutorepeatInterval, ""), + DECLFUNC(setKeyAnalogToDPad, ""), DECLFUNC(flushDataCache, ""), - DECLFUNC(setChannelVolume, ""), - DECLFUNC(drawString, ""), DECLFUNC(drawTextBox, ""), @@ -880,11 +1498,61 @@ DECLFUNC(RGBA12, ""), DECLFUNC(RGBA15, ""), +#ifdef WITH_OSLIB_MOD + DECLFUNC(setHoldForAnalog, ""), + + DECLFUNC(intraFontInit, ""), + DECLFUNC(intraFontShutdown, ""), + DECLFUNC(intraFontSetStyle, ""), + + DECLFUNC(initMessageDialog, ""), + DECLFUNC(initErrorDialog, ""), + DECLFUNC(drawDialog, ""), + DECLFUNC(getDialogType, ""), + DECLFUNC(getDialogStatus, ""), + DECLFUNC(getDialogButtonPressed, ""), + DECLFUNC(initNetDialog, ""), + DECLFUNC(dialogGetResult, ""), + DECLFUNC(endDialog, ""), + + DECLFUNC(initOsk, ""), + DECLFUNC(drawOsk, ""), + DECLFUNC(oskIsActive, ""), + DECLFUNC(getOskStatus, ""), + DECLFUNC(oskGetResult, ""), + DECLFUNC(oskGetText, ""), + DECLFUNC(endOsk, ""), + + DECLFUNC(netInit, ""), + DECLFUNC(netTerm, ""), + + /*DECLFUNC(initSaveDialog, ""), + DECLFUNC(initLoadDialog, ""), + DECLFUNC(drawSaveLoad, ""), + DECLFUNC(getSaveLoadStatus, ""), + DECLFUNC(getSaveLoadType, ""), + DECLFUNC(saveLoadGetResult, ""), + DECLFUNC(endSaveLoad, ""),*/ + + /*DECLFUNC(browserInit, ""), + DECLFUNC(drawBrowser, ""), + DECLFUNC(browserIsActive, ""), + DECLFUNC(getBrowserStatus, ""), + DECLFUNC(endBrowser, ""),*/ + + +#endif + { NULL } }; #define ADDINT(name) PyModule_AddIntConstant(mdl, #name, (int)OSL_##name) +#define ADDINTWITHNAME(oslname, name) PyModule_AddIntConstant(mdl, #name, (int)#oslname) +#ifdef WITH_OSLIB_MOD +#define ADDINTRAFONTINT(name) PyModule_AddIntConstant(mdl, #name, (int)#name) +#endif + void initosl(void) { PyObject *mdl; @@ -904,6 +1572,14 @@ if (PyType_Ready(PPyFontType) < 0) return; +#ifdef WITH_OSLIB_MOD + if (PyType_Ready(PPySFontType) < 0) + return; + + /*if (PyType_Ready(PPySaveLoadType) < 0) + return;*/ +#endif + mdl = Py_InitModule3("osl", functions, ""); if (!mdl) return; @@ -925,6 +1601,7 @@ ADDINT(IN_VRAM); ADDINT(IN_RAM); + ADDINT(SWIZZLED); ADDINT(DEFAULT_BUFFER); ADDINT(SECONDARY_BUFFER); @@ -954,6 +1631,129 @@ ADDINT(FMT_STREAM); ADDINT(FMT_NONE); +#ifdef WITH_OSLIB_MOD + ADDINT(DIALOG_CANCEL); + ADDINT(DIALOG_OK); + ADDINT(DIALOG_NONE); + ADDINT(DIALOG_MESSAGE); + ADDINT(DIALOG_ERROR); + ADDINT(DIALOG_NETCONF); + + /*ADDINT(SAVELOAD_CANCEL); + ADDINT(SAVELOAD_OK); + ADDINT(DIALOG_SAVE); + ADDINT(DIALOG_LOAD);*/ + + ADDINT(OSK_CANCEL); + ADDINT(OSK_OK); + + ADDINT(NET_ERROR_NET); + ADDINT(NET_ERROR_INET); + ADDINT(NET_ERROR_RESOLVER); + ADDINT(NET_ERROR_APCTL); + ADDINT(NET_ERROR_APCTL); + ADDINT(NET_ERROR_SSL); + ADDINT(NET_ERROR_HTTP); + ADDINT(NET_ERROR_HTTPS); + ADDINT(NET_ERROR_CERT); + ADDINT(NET_ERROR_COOKIE); + ADDINT(ERR_APCTL_GETINFO); + ADDINT(ERR_APCTL_CONNECT); + ADDINT(ERR_APCTL_TIMEOUT); + ADDINT(ERR_APCTL_GETSTATE); + ADDINT(ERR_RESOLVER_CREATE); + ADDINT(ERR_RESOLVER_RESOLVING); + ADDINT(ERR_WLAN_OFF); + ADDINT(USER_ABORTED); + + ADDINTWITHNAME(JAPANESE, OSK_JAPANESE); + ADDINTWITHNAME(ENGLISH, OSK_ENGLISH); + ADDINTWITHNAME(FRENCH, OSK_FRENCH); + ADDINTWITHNAME(SPANISH, OSK_SPANISH); + ADDINTWITHNAME(GERMAN, OSK_GERMAN); + ADDINTWITHNAME(ITALIAN, OSK_ITALIAN); + ADDINTWITHNAME(DUTCH, OSK_DUTCH); + ADDINTWITHNAME(PORTUGUESE, OSK_PORTUGUESE); + ADDINTWITHNAME(RUSSIAN, OSK_RUSSIAN); + ADDINTWITHNAME(KOREAN, OSK_KOREAN); + ADDINTWITHNAME(CHINESE_TRADITIONAL, OSK_CHINESE_TRADITIONAL); + ADDINTWITHNAME(CHINESE_SIMPLIFIED, OSK_CHINESE_SIMPLIFIED); + + ADDINTRAFONTINT(INTRAFONT_ADVANCE_H); + ADDINTRAFONTINT(INTRAFONT_ADVANCE_V); + ADDINTRAFONTINT(INTRAFONT_ALIGN_LEFT); + ADDINTRAFONTINT(INTRAFONT_ALIGN_CENTER); + ADDINTRAFONTINT(INTRAFONT_ALIGN_RIGHT); + ADDINTRAFONTINT(INTRAFONT_ALIGN_FULL); + ADDINTRAFONTINT(INTRAFONT_SCROLL_LEFT); + + ADDINTRAFONTINT(INTRAFONT_SCROLL_SEESAW); + ADDINTRAFONTINT(INTRAFONT_SCROLL_RIGHT); + ADDINTRAFONTINT(INTRAFONT_SCROLL_THROUGH); + ADDINTRAFONTINT(INTRAFONT_WIDTH_VAR); + ADDINTRAFONTINT(INTRAFONT_WIDTH_FIX); + ADDINTRAFONTINT(INTRAFONT_ACTIVE); + ADDINTRAFONTINT(INTRAFONT_CACHE_MED); + ADDINTRAFONTINT(INTRAFONT_CACHE_LARGE); + ADDINTRAFONTINT(INTRAFONT_CACHE_ASCII); + ADDINTRAFONTINT(INTRAFONT_CACHE_ALL); + + ADDINTRAFONTINT(INTRAFONT_STRING_ASCII); + ADDINTRAFONTINT(INTRAFONT_STRING_CP437); + ADDINTRAFONTINT(INTRAFONT_STRING_CP850); + ADDINTRAFONTINT(INTRAFONT_STRING_CP866); + ADDINTRAFONTINT(INTRAFONT_STRING_SJIS); + ADDINTRAFONTINT(INTRAFONT_STRING_GBK); + ADDINTRAFONTINT(INTRAFONT_STRING_KOR); + ADDINTRAFONTINT(INTRAFONT_STRING_BIG5); + ADDINTRAFONTINT(INTRAFONT_STRING_CP1251); + ADDINTRAFONTINT(INTRAFONT_STRING_CP1252); + ADDINTRAFONTINT(INTRAFONT_STRING_UTF8); + + /*ADDINT(BROWSER_ERROR_MEMORY); + ADDINT(BROWSER_ERROR_INIT); + + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISCONNECTMODE_ENABLE, HTMLVIEWER_DISCONNECTMODE_ENABLE); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISCONNECTMODE_DISABLE, HTMLVIEWER_DISCONNECTMODE_DISABLE); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISCONNECTMODE_CONFIRM, HTMLVIEWER_DISCONNECTMODE_CONFIRM); + + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_INTERFACEMODE_FULL, HTMLVIEWER_INTERFACEMODE_FULL); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_INTERFACEMODE_LIMITED, HTMLVIEWER_INTERFACEMODE_LIMITED); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_INTERFACEMODE_NONE, HTMLVIEWER_INTERFACEMODE_NONE); + + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_COOKIEMODE_DISABLED, HTMLVIEWER_COOKIEMODE_DISABLED); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_COOKIEMODE_ENABLED, HTMLVIEWER_COOKIEMODE_ENABLED); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_COOKIEMODE_CONFIRM, HTMLVIEWER_COOKIEMODE_CONFIRM); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_COOKIEMODE_DEFAULT, HTMLVIEWER_COOKIEMODE_DEFAULT); + + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_TEXTSIZE_LARGE, HTMLVIEWER_TEXTSIZE_LARGE); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_TEXTSIZE_NORMAL, HTMLVIEWER_TEXTSIZE_NORMAL); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_TEXTSIZE_SMALL, HTMLVIEWER_TEXTSIZE_SMALL); + + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISPLAYMODE_NORMAL, HTMLVIEWER_DISPLAYMODE_NORMAL); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISPLAYMODE_FIT, HTMLVIEWER_DISPLAYMODE_FIT); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISPLAYMODE_SMART_FIT, HTMLVIEWER_DISPLAYMODE_SMART_FIT); + + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_CONNECTMODE_LAST, HTMLVIEWER_CONNECTMODE_LAST); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_CONNECTMODE_MANUAL_ONCE, HTMLVIEWER_CONNECTMODE_MANUAL_ONCE); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_CONNECTMODE_MANUAL_ALL, HTMLVIEWER_CONNECTMODE_MANUAL_ALL); + + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_OPEN_SCE_START_PAGE, HTMLVIEWER_OPEN_SCE_START_PAGE); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISABLE_STARTUP_LIMITS, HTMLVIEWER_DISABLE_STARTUP_LIMITS); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISABLE_EXIT_DIALOG, HTMLVIEWER_DISABLE_EXIT_DIALOG); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISABLE_CURSOR, HTMLVIEWER_DISABLE_CURSOR); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISABLE_DOWNLOAD_COMPLETE_DIALOG, HTMLVIEWER_DISABLE_DOWNLOAD_COMPLETE_DIALOG); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISABLE_DOWNLOAD_START_DIALOG, HTMLVIEWER_DISABLE_DOWNLOAD_START_DIALOG); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISABLE_DOWNLOAD_DESTINATION_DIALOG, HTMLVIEWER_DISABLE_DOWNLOAD_DESTINATION_DIALOG); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_LOCK_DOWNLOAD_DESTINATION_DIALOG, HTMLVIEWER_LOCK_DOWNLOAD_DESTINATION_DIALOG); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISABLE_TAB_DISPLAY, HTMLVIEWER_DISABLE_TAB_DISPLAY); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_ENABLE_ANALOG_HOLD, HTMLVIEWER_ENABLE_ANALOG_HOLD); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_ENABLE_FLASH, HTMLVIEWER_ENABLE_FLASH); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_DISABLE_LRTRIGGER, HTMLVIEWER_DISABLE_LRTRIGGER); + ADDINTWITHNAME(PSP_UTILITY_HTMLVIEWER_CONNECTMODE_MANUAL_ALL, HTMLVIEWER_CONNECTMODE_MANUAL_ALL);*/ + +#endif + osl_Error = PyErr_NewException("osl.Error", NULL, NULL); PyModule_AddObject(mdl, "Error", osl_Error); @@ -971,6 +1771,14 @@ Py_INCREF(PPyFontType); PyModule_AddObject(mdl, "Font", (PyObject*)PPyFontType); + +#ifdef WITH_OSLIB_MOD + Py_INCREF(PPySFontType); + PyModule_AddObject(mdl, "SFont", (PyObject*)PPySFontType); + + /*Py_INCREF(PPySaveLoadType); + PyModule_AddObject(mdl, "SaveLoad", (PyObject*)PPySaveLoadType);*/ +#endif } #ifdef _GNUC Index: PSP/osl/saveload.c =================================================================== --- PSP/osl/saveload.c (revision 0) +++ PSP/osl/saveload.c (revision 0) @@ -0,0 +1,122 @@ + +/** + * @file saveload.c + */ + +/********************************************************************** + + Created: 24 Feb 2007 + + Copyright (C) 2007 fraca7@free.fr + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later + version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + +**********************************************************************/ +// $Id$ + +#include "saveload.h" +#include "osl.h" + +//========================================================================== +// Init & free + +static void saveload_dealloc(PySaveLoad *self) +{ + self->ob_type->tp_free((PyObject*)self); +} + +static PyObject* saveload_new(PyTypeObject *type, + PyObject *args, + PyObject *kwargs) +{ + PySaveLoad *self; + + self = (PySaveLoad*)type->tp_alloc(type, 0); + + if (self) + self->pSaveLoad = NULL; + + return (PyObject*)self; +} + +static int saveload_init(PySaveLoad *self, + PyObject *args, + PyObject *kwargs) +{ + if (!PyArg_ParseTuple(args, ":__init__")) + return -1; + + self->pSaveLoad = NULL; + + return 0; +} + +//========================================================================== +// Methods + + +static PyMethodDef saveload_methods[] = { + { NULL } +}; + +static PyTypeObject PySaveLoadType = { + PyObject_HEAD_INIT(NULL) + 0, + "osl.SaveLoad", + sizeof(PySaveLoad), + 0, + (destructor)saveload_dealloc, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + "SaveLoad objects", + 0, + 0, + 0, + 0, + 0, + 0, + saveload_methods, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + (initproc)saveload_init, + 0, + saveload_new, +}; + +PyTypeObject* PPySaveLoadType = &PySaveLoadType; + +#ifdef _GNUC +static const char* _rcsid_saveload __attribute__((unused)) = "$Id$"; +#endif Index: PSP/osl/saveload.h =================================================================== --- PSP/osl/saveload.h (revision 0) +++ PSP/osl/saveload.h (revision 0) @@ -0,0 +1,52 @@ + +/** + * @file saveload.h + */ + +/********************************************************************** + + Created: 24 Feb 2007 + + Copyright (C) 2007 Frank Buss, Jérôme Laheurte + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. The names of the authors may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**********************************************************************/ +// $Id$ + +#ifndef _SAVELOAD_H +#define _SAVELOAD_H + +#include +#include + +typedef struct +{ + PyObject_HEAD + + struct oslSaveLoad *pSaveLoad; +} PySaveLoad; + +extern PyTypeObject* PPySaveLoadType; + +#endif /* _SAVELOAD_H */ Index: PSP/osl/sfont.c =================================================================== --- PSP/osl/sfont.c (revision 0) +++ PSP/osl/sfont.c (revision 0) @@ -0,0 +1,165 @@ + +/** + * @file sfont.c + */ + +/********************************************************************** + + Created: 05 Aug 2009 + + Copyright (C) 200s sakya_tg@yahoo.it + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later + version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + +**********************************************************************/ +// $Id$ + +#include "sfont.h" +#include "osl.h" + +//========================================================================== +// Init & free + +static void sfont_dealloc(PySFont *self) +{ + if (self->pSFont) + oslDeleteSFont(self->pSFont); + + self->ob_type->tp_free((PyObject*)self); +} + +static PyObject* sfont_new(PyTypeObject *type, + PyObject *args, + PyObject *kwargs) +{ + PySFont *self; + + self = (PySFont*)type->tp_alloc(type, 0); + + if (self) + self->pSFont = NULL; + + return (PyObject*)self; +} + +static int sfont_init(PySFont *self, + PyObject *args, + PyObject *kwargs) +{ + char *filename; + int format = OSL_PF_8888; + + if (!PyArg_ParseTuple(args, "s|i:__init__", &filename, &format)) + return -1; + + self->pSFont = oslLoadSFontFile(filename, format); + + if (!self->pSFont) + { + PyErr_SetString(osl_Error, "Could not load sfont file"); + return -1; + } + + return 0; +} + +//========================================================================== +// Methods + +static PyObject* sfont_drawstring(PySFont *self, + PyObject *args, + PyObject *kwargs) +{ + int x,y; + char *text; + if (!PyArg_ParseTuple(args, "iis:drawString", &x, &y, &text)) + return NULL; + + int result = oslSFontDrawText(self->pSFont, x, y, text); + + return Py_BuildValue("i", result); +} + +static PyObject* sfont_measuretext(PySFont *self, + PyObject *args, + PyObject *kwargs) +{ + char *text; + if (!PyArg_ParseTuple(args, "s:measureText", &text)) + return NULL; + + int result = oslGetSFontTextWidth(self->pSFont, text); + + return Py_BuildValue("i", result); +} + +//========================================================================== + +static PyMethodDef sfont_methods[] = { + { "drawString", (PyCFunction)sfont_drawstring, METH_VARARGS, "" }, + { "measureText", (PyCFunction)sfont_measuretext, METH_VARARGS, "" }, + + { NULL } +}; + +static PyTypeObject PySFontType = { + PyObject_HEAD_INIT(NULL) + 0, + "osl.SFont", + sizeof(PySFont), + 0, + (destructor)sfont_dealloc, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + "SFont objects", + 0, + 0, + 0, + 0, + 0, + 0, + sfont_methods, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + (initproc)sfont_init, + 0, + sfont_new, +}; + +PyTypeObject* PPySFontType = &PySFontType; + +#ifdef _GNUC +static const char* _rcsid_sfont __attribute__((unused)) = "$Id$"; +#endif Index: PSP/osl/sfont.h =================================================================== --- PSP/osl/sfont.h (revision 0) +++ PSP/osl/sfont.h (revision 0) @@ -0,0 +1,16 @@ +#ifndef _PSFONT_H +#define _PSFONT_H + +#include +#include + +typedef struct +{ + PyObject_HEAD + + OSL_SFONT *pSFont; +} PySFont; + +extern PyTypeObject* PPySFontType; + +#endif /* _PSFONT_H */ Index: PSP/PARAM.SFO =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: PSP\PARAM.SFO ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: PSP/pspmp3/MusicEngine.c =================================================================== --- PSP/pspmp3/MusicEngine.c (revision 46) +++ PSP/pspmp3/MusicEngine.c (working copy) @@ -1,305 +1,522 @@ -/*! -* -* This file is created by R.N. den Hollander -* a.k.a Ghoti. -* This file is intended for use for the stackless -* python project. If you want to use this for something -* else that is ok but please let me know. -* -* url: www.ghoti.nl -* -* -*/ - -/*! -* This file is the code of the MP3 streaming -* engine. -* -*/ - -#include "MusicEngine.h" -#include +#include #include #include -#include -#include -#include +#include +#include +#include +#include +#include +#include -#define printf pspDebugScreenPrintf +#include "MusicEngine.h" +#define THREAD_PRIORITY 0x12 +#define OUTPUT_BUFFER_SIZE (AUDIO_SAMPLES*4) -int Init(int channel) { - pspAudioInit(); // init the audio psp +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//Globals: +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +static char currentDir[264]; +static int MP3ME_threadActive = 0; +static char MP3ME_fileName[264]; +static int MP3ME_isPlaying = 0; +static int MP3ME_thid = -1; +static int MP3ME_audio_channel = 0; +static int MP3ME_eof = 0; +static float MP3ME_playingTime = 0; +static int MP3ME_volume = 0; +static double MP3ME_filePos = 0; +static double MP3ME_musicStart = 0; - mad_stream_init(&stream); // create the mad variables, streams etc. - mad_frame_init(&frame); - mad_synth_init(&synth); - mad_timer_reset(&timer); - pspAudioSetChannelCallback(channel, fillOutputBuffer, 0); // set the callback to the function. - mutex = sceKernelCreateSema("myMutexName", 0, 1, 1, 0); // create the mutex for threading secure. - pausesong = 1; // set the variable to pause so no sound is played. - started = 0; // the mp3 has not yet started. - file = 0; // set the file to zero - fileSize = 1; - filePos = 0; - printf("MusicEngine is initialized.\n"); +//shared global vars for ME +static int HW_ModulesInit = 0; +u16 data_align; +u32 sample_per_frame; +u16 channel_mode; +u32 samplerate; +long data_start; +long data_size; +u8 getEDRAM; +u32 channels; +SceUID data_memid; +volatile int OutputBuffer_flip; +static int MP3ME_Loop = 0; - return 1; +//Globals for decoding: +static SceUID MP3ME_handle = -1; + +static int samplerates[4][3] = +{ + {11025, 12000, 8000,},//mpeg 2.5 + {0, 0, 0,}, //reserved + {22050, 24000, 16000,},//mpeg 2 + {44100, 48000, 32000}//mpeg 1 }; +static int bitrates[] = {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 }; +static int bitrates_v2[] = {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 }; +static unsigned char MP3ME_input_buffer[2889]__attribute__((aligned(64)));//mp3 has the largest max frame, at3+ 352 is 2176 +static unsigned long MP3ME_codec_buffer[65]__attribute__((aligned(64))); +static unsigned char MP3ME_output_buffer[2048*4]__attribute__((aligned(64)));//at3+ sample_per_frame*4 +static short OutputBuffer[2][OUTPUT_BUFFER_SIZE]; +static short *OutputPtrME = OutputBuffer[0]; -int Load(const char* musicfile) { - endofstream = 0; // set the endofsong flag to 0. - sceKernelWaitSema(mutex, 1, 0); // wait for thread to be open. - sprintf(Song, "%s", musicfile); // Song is not used by another thread so we can change it - SongIsChanged = 1; // Mark status that the song is changed - sceKernelSignalSema(mutex, 1); // free the lock of this thread. - printf("Music file %s loaded.\n", Song); +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//Private functions: +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//reserve channel +int openAudio(int channel, int samplecount){ + int audio_channel = sceAudioChReserve(channel, samplecount, PSP_AUDIO_FORMAT_STEREO ); + if(audio_channel < 0) + audio_channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, samplecount, PSP_AUDIO_FORMAT_STEREO ); + return audio_channel; +} - return 1; -}; +//release channel +int releaseAudio(void){ + while(sceAudioOutput2GetRestSample() > 0) + sceKernelDelayThread(10); + return sceAudioChRelease(MP3ME_audio_channel); +} +//audio output +int audioOutput(int volume, void *buffer){ + return sceAudioOutputBlocking(MP3ME_audio_channel, volume, buffer); +} -int Play() { - if(pausesong == 1 && started == 0) { - started = 1; - pausesong = 0; - printf("Play music true.\n"); - return 1; - } - printf("Play music false.\n"); - return 0; -}; +//Load a module: +SceUID LoadStartAudioModule(char *modname, int partition){ + SceKernelLMOption option; + SceUID modid; + memset(&option, 0, sizeof(option)); + option.size = sizeof(option); + option.mpidtext = partition; + option.mpiddata = partition; + option.position = 0; + option.access = 1; -int Stop() { - pausesong = 1; - started = 0; - file = 0; - printf("Music file stopped."); - return 1; -}; + modid = sceKernelLoadModule(modname, 0, &option); + if (modid < 0) + return modid; + return sceKernelStartModule(modid, 0, NULL, NULL, NULL); +} +//Load and start needed modules: +int initMEAudioModules(){ + if (!HW_ModulesInit){ + if (sceKernelDevkitVersion() == 0x01050001){ + LoadStartAudioModule("flash0:/kd/me_for_vsh.prx", PSP_MEMORY_PARTITION_KERNEL); + LoadStartAudioModule("flash0:/kd/audiocodec.prx", PSP_MEMORY_PARTITION_KERNEL); + }else{ + sceUtilityLoadAvModule(PSP_AV_MODULE_AVCODEC); + sceUtilityLoadAvModule(PSP_AV_MODULE_ATRAC3PLUS); + } -int Pause() { - pausesong = !pausesong; - printf("Music file paused."); - return 1; -}; + HW_ModulesInit = 1; + } + return 0; +} -int EndOfStream() { - if (endofstream == 1) { - return 1; - } else { - return 0; +//Seek next valid frame +//NOTE: this function comes from Music prx 0.55 source +// all credits goes to joek2100. +int SeekNextFrameMP3(SceUID fd) +{ + int offset = 0; + unsigned char buf[1024]; + unsigned char *pBuffer; + int i; + int size = 0; + + offset = sceIoLseek32(fd, 0, PSP_SEEK_CUR); + sceIoRead(fd, buf, sizeof(buf)); + if (!strncmp((char*)buf, "ID3", 3) || !strncmp((char*)buf, "ea3", 3)) //skip past id3v2 header, which can cause a false sync to be found + { + //get the real size from the syncsafe int + size = buf[6]; + size = (size<<7) | buf[7]; + size = (size<<7) | buf[8]; + size = (size<<7) | buf[9]; + + size += 10; + + if (buf[5] & 0x10) //has footer + size += 10; } -}; -void GetTimeString(char *dest) { - mad_timer_string(timer, dest, "%02lu:%02u:%02u", MAD_UNITS_HOURS, MAD_UNITS_MILLISECONDS, 0); -}; + sceIoLseek32(fd, offset, PSP_SEEK_SET); //now seek for a sync + while(1) + { + offset = sceIoLseek32(fd, 0, PSP_SEEK_CUR); + size = sceIoRead(fd, buf, sizeof(buf)); -void End() { - Stop(); - pspAudioEnd(); - FreeTune(); -}; + if (size <= 2)//at end of file + return -1; -void FreeTune() { - if (FBptr) - free(FBptr); + if (!strncmp((char*)buf, "EA3", 3))//oma mp3 files have non-safe ints in the EA3 header + { + sceIoLseek32(fd, (buf[4]<<8)+buf[5], PSP_SEEK_CUR); + continue; + } - mad_synth_finish(&synth); - mad_frame_finish(&frame); - mad_stream_finish(&stream); -}; + pBuffer = buf; + for( i = 0; i < size; i++) + { + //if this is a valid frame sync (0xe0 is for mpeg version 2.5,2+1) + if ( (pBuffer[i] == 0xff) && ((pBuffer[i+1] & 0xE0) == 0xE0)) + { + offset += i; + sceIoLseek32(fd, offset, PSP_SEEK_SET); + return offset; + } + } + //go back two bytes to catch any syncs that on the boundary + sceIoLseek32(fd, -2, PSP_SEEK_CUR); + } +} -int fillFileBuffer() { - // wait for semaphore to be open - sceKernelWaitSema(mutex, 1, 0); +int swapInt32BigToHost(int arg) +{ + int i=0; + int checkEndian = 1; + if( 1 == *(char *)&checkEndian ) + { + // Intel (little endian) + i=arg; + i=((i&0xFF000000)>>24)|((i&0x00FF0000)>>8)|((i&0x0000FF00)<<8)|((i&0x000000FF)<<24); + } + else + { + // PPC (big endian) + i=arg; + } + return i; +} - // Open the file if it's not open. - if (SongIsChanged == 1) { - SongIsChanged = 0; - if (file>0) sceIoClose(file); // If the file wasn't closed before (got to next song before reaching EOF), close it now - file = 0; - } - if (file <= 0) { - char cd[1024]; - memset(cd, 0, sizeof(cd)); - getcwd(cd, sizeof(cd) - 1); +//Get the id3v2 size +int ID3v2TagSize(const char *mp3path) +{ + int fp = 0; + int size; + char sig[3]; - char fileName[1024]; - memset(fileName, 0, sizeof(fileName)); - snprintf(fileName, sizeof(fileName) - 1, "%s/%s", cd, Song); + fp = sceIoOpen(mp3path, PSP_O_RDONLY, 0777); + if (fp < 0) return 0; - file = sceIoOpen(fileName, PSP_O_RDONLY, 777); - if (file <= 0) - { - pspDebugScreenPrintf("Failed (%s).\n", Song); - sceKernelSignalSema(mutex, 1); - /* - * do something when file is not loaded - */ - return 1; - } + sceIoRead(fp, sig, sizeof(sig)); + if (strncmp("ID3",sig,3) != 0) { + sceIoClose(fp); + return 0; + } - // Get the size. - fileSize = sceIoLseek(file, 0, SEEK_END); - sceIoLseek(file, 0, SEEK_SET); - } + sceIoLseek(fp, 6, PSP_SEEK_SET); + sceIoRead(fp, &size, sizeof(unsigned int)); + /* + * The ID3 tag size is encoded with four bytes where the first bit + * (bit 7) is set to zero in every byte, making a total of 28 bits. The zeroed + * bits are ignored, so a 257 bytes long tag is represented as $00 00 02 01. + */ - // Find out how much to keep and how much to fill. - const unsigned int bytesToKeep = stream.bufend - stream.next_frame; - unsigned int bytesToFill = sizeof(fileBuffer) - bytesToKeep; - //pspDebugScreenPrintf("bytesToFill = %u, bytesToKeep = %u.\n", bytesToFill, bytesToKeep); + size = (unsigned int) swapInt32BigToHost((int)size); + size = ( ( (size & 0x7f000000) >> 3 ) | ( (size & 0x7f0000) >> 2 ) | ( (size & 0x7f00) >> 1 ) | (size & 0x7f) ); + sceIoClose(fp); + return size; +} - // Want to keep any bytes? - if (bytesToKeep) - { - // Copy the tail to the head. - memmove(fileBuffer, fileBuffer + sizeof(fileBuffer) - bytesToKeep, bytesToKeep); - } +//Decode thread: +int decodeThread(SceSize args, void *argp){ + int res; + unsigned char MP3ME_header_buf[4]; + int MP3ME_header; + int version; + int bitrate; + int padding; + int frame_size = 0; + int size; + int total_size; + int offset = 0; - // Read into the rest of the file buffer. - unsigned char* bufferPos = fileBuffer + bytesToKeep; - while (bytesToFill > 0) - { - // Read some. - //pspDebugScreenPrintf("Reading %u bytes...\n", bytesToFill); - const unsigned int bytesRead = sceIoRead(file, bufferPos, bytesToFill); + //printf("pspmp3: Thread started\n"); + sceIoChdir(currentDir); + //printf("pspmp3: chdir to %s\n", currentDir); - // EOF? - if (bytesRead == 0) { - sceKernelSignalSema(mutex, 1); - return 2; //handle stuff when end of file with return value !!!NOT HERE - } + sceAudiocodecReleaseEDRAM(MP3ME_codec_buffer); //Fix: ReleaseEDRAM at the end is not enough to play another mp3. + MP3ME_threadActive = 1; + OutputBuffer_flip = 0; + OutputPtrME = OutputBuffer[0]; - // Adjust where we're writing to. - bytesToFill -= bytesRead; - bufferPos += bytesRead; - filePos += bytesRead; + MP3ME_handle = sceIoOpen(MP3ME_fileName, PSP_O_RDONLY, 0777); + if (MP3ME_handle < 0){ + //printf("pspmp3: Error opening file %s\n", MP3ME_fileName); + MP3ME_threadActive = 0; + } - //pspDebugScreenPrintf("Read %u bytes from the file, %u left to fill.\n", bytesRead, bytesToFill); - //pspDebugScreenPrintf("%u%%.\n", filePos * 100 / fileSize); - } - // release the semaphore - sceKernelSignalSema(mutex, 1); - return 0; -} + //now search for the first sync byte, tells us where the mp3 stream starts + total_size = sceIoLseek32(MP3ME_handle, 0, PSP_SEEK_END); + size = total_size; + sceIoLseek32(MP3ME_handle, 0, PSP_SEEK_SET); + data_start = ID3v2TagSize(MP3ME_fileName); + sceIoLseek32(MP3ME_handle, data_start, PSP_SEEK_SET); + data_start = SeekNextFrameMP3(MP3ME_handle); + if (data_start < 0){ + //printf("pspmp3: Error data_start\n"); + MP3ME_threadActive = 0; + } + MP3ME_musicStart = data_start; + size -= data_start; + memset(MP3ME_codec_buffer, 0, sizeof(MP3ME_codec_buffer)); + memset(MP3ME_input_buffer, 0, sizeof(MP3ME_input_buffer)); + memset(MP3ME_output_buffer, 0, sizeof(MP3ME_output_buffer)); -void decode() { - // While we need to fill the buffer... - while ( - (mad_frame_decode(&frame, &stream) == -1) && - ((stream.error == MAD_ERROR_BUFLEN) || (stream.error == MAD_ERROR_BUFPTR)) - ) - { - // Fill up the remainder of the file buffer. - int tmp; - tmp = fillFileBuffer(); - if (tmp==2) { - endofstream = 1; - //MusicPlayerNextSong(); - /*! - * - * Put here the function that does something when the file has ended. - * - */ - } + if ( sceAudiocodecCheckNeedMem(MP3ME_codec_buffer, 0x1002) < 0 ) + { + //printf("pspmp3: Error sceAudiocodecCheckNeedMem\b"); + MP3ME_threadActive = 0; + } - // Give new buffer to the stream. - mad_stream_buffer(&stream, fileBuffer, sizeof(fileBuffer)); - } - // Add to the timer the stream duration - mad_timer_add(&timer, frame.header.duration); - // Synth the frame. - mad_synth_frame(&synth, &frame); -} + if ( sceAudiocodecGetEDRAM(MP3ME_codec_buffer, 0x1002) < 0 ) + { + //printf("pspmp3: Error sceAudiocodecGetEDRAM\n"); + MP3ME_threadActive = 0; + }else{ + getEDRAM = 1; + } + if ( sceAudiocodecInit(MP3ME_codec_buffer, 0x1002) < 0 ) + { + //printf("pspmp3: Error sceAudiocodecInit\n"); + MP3ME_threadActive = 0; + } + MP3ME_eof = 0; + //printf("pspmp3: MP3ME_threadActive %i\n", MP3ME_threadActive); -short convertSample(mad_fixed_t sample) { - // round - sample += (1L << (MAD_F_FRACBITS - 16)); + while (MP3ME_threadActive){ + while( !MP3ME_eof && MP3ME_isPlaying ) + { + MP3ME_filePos = sceIoLseek32(MP3ME_handle, 0, PSP_SEEK_CUR); + if ( sceIoRead( MP3ME_handle, MP3ME_header_buf, 4 ) != 4 ){ + MP3ME_isPlaying = 0; + MP3ME_threadActive = 0; + continue; + } - // clip - if (sample >= MAD_F_ONE) - sample = MAD_F_ONE - 1; - else if (sample < -MAD_F_ONE) - sample = -MAD_F_ONE; + MP3ME_header = MP3ME_header_buf[0]; + MP3ME_header = (MP3ME_header<<8) | MP3ME_header_buf[1]; + MP3ME_header = (MP3ME_header<<8) | MP3ME_header_buf[2]; + MP3ME_header = (MP3ME_header<<8) | MP3ME_header_buf[3]; - // quantize - return sample >> (MAD_F_FRACBITS + 1 - 16); -} + bitrate = (MP3ME_header & 0xf000) >> 12; + padding = (MP3ME_header & 0x200) >> 9; + version = (MP3ME_header & 0x180000) >> 19; + samplerate = samplerates[version][ (MP3ME_header & 0xC00) >> 10 ]; + if ((bitrate > 14) || (version == 1) || (samplerate == 0) || (bitrate == 0))//invalid frame, look for the next one + { + data_start = SeekNextFrameMP3(MP3ME_handle); + if(data_start < 0) + { + MP3ME_eof = 1; + continue; + } + size -= (data_start - offset); + offset = data_start; + continue; + } + if (version == 3) //mpeg-1 + { + sample_per_frame = 1152; + frame_size = 144000*bitrates[bitrate]/samplerate + padding; + }else{ + sample_per_frame = 576; + frame_size = 72000*bitrates_v2[bitrate]/samplerate + padding; + } -void convertLeftSamples(Sample* first, Sample* last, const mad_fixed_t* src) { - Sample* dst; - for (dst = first; dst != last; ++dst) - dst->left = convertSample(*src++); -} + sceIoLseek32(MP3ME_handle, data_start, PSP_SEEK_SET); //seek back + size -= frame_size; + if ( size <= 0) + { + MP3ME_eof = 1; + continue; + } + //since we check for eof above, this can only happen when the file + // handle has been invalidated by syspend/resume/usb + if ( sceIoRead( MP3ME_handle, MP3ME_input_buffer, frame_size ) != frame_size ){ + //Resume from suspend: + if ( MP3ME_handle >= 0 ){ + sceIoClose(MP3ME_handle); + MP3ME_handle = -1; + } + MP3ME_handle = sceIoOpen(MP3ME_fileName, PSP_O_RDONLY, 0777); + if (MP3ME_handle < 0){ + MP3ME_isPlaying = 0; + MP3ME_threadActive = 0; + continue; + } + size = sceIoLseek32(MP3ME_handle, 0, PSP_SEEK_END); + sceIoLseek32(MP3ME_handle, offset, PSP_SEEK_SET); + data_start = offset; + continue; + } + data_start += frame_size; + offset = data_start; -void convertRightSamples(Sample* first, Sample* last, const mad_fixed_t* src) { - Sample* dst; - for (dst = first; dst != last; ++dst) - dst->right = convertSample(*src++); -} + MP3ME_codec_buffer[6] = (unsigned long)MP3ME_input_buffer; + MP3ME_codec_buffer[8] = (unsigned long)MP3ME_output_buffer; + MP3ME_codec_buffer[7] = MP3ME_codec_buffer[10] = frame_size; + MP3ME_codec_buffer[9] = sample_per_frame * 4; + res = sceAudiocodecDecode(MP3ME_codec_buffer, 0x1002); + if ( res < 0 ) + { + //instead of quitting see if the next frame can be decoded + //helps play files with an invalid frame + //we must look for a valid frame, the offset above may be wrong + data_start = SeekNextFrameMP3(MP3ME_handle); + if(data_start < 0) + { + MP3ME_eof = 1; + continue; + } + size -= (data_start - offset); + offset = data_start; + continue; + } + MP3ME_playingTime += (float)sample_per_frame/(float)samplerate; -void fillOutputBuffer(void* buffer, unsigned int samplesToWrite, void* userData) { + //Output: + memcpy( OutputPtrME, MP3ME_output_buffer, sample_per_frame*4); + OutputPtrME += (sample_per_frame * 4); + if( OutputPtrME + (sample_per_frame * 4) > &OutputBuffer[OutputBuffer_flip][OUTPUT_BUFFER_SIZE]) + { + audioOutput(MP3ME_volume, OutputBuffer[OutputBuffer_flip]); - // Where are we writing to? - Sample* destination = (Sample*)buffer; - unsigned int i = 0; - //printf("filloutputbuffer wordt gedraaid.\n"); - if (pausesong == 1) { - for (i=0; i 0) { - // Enough samples available? - const unsigned int samplesAvailable = synth.pcm.length - samplesRead; + if ( MP3ME_handle >= 0){ + sceIoClose(MP3ME_handle); + MP3ME_handle = -1; + } + //printf("pspmp3: Thread ended\n"); + sceKernelExitThread(0); + return 0; +} - if (samplesAvailable > samplesToWrite) { - // Write samplesToWrite samples. - convertLeftSamples(destination, destination + samplesToWrite, &synth.pcm.samples[0][samplesRead]); - convertRightSamples(destination, destination + samplesToWrite, &synth.pcm.samples[1][samplesRead]); - // We're still using the same PCM data. - samplesRead += samplesToWrite; +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//Public API +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +int Init(int channel) +{ + MP3ME_playingTime = 0; + MP3ME_volume = PSP_AUDIO_VOLUME_MAX; + initMEAudioModules(); + MP3ME_audio_channel = openAudio(channel, AUDIO_SAMPLES); + if (MP3ME_audio_channel < 0){ + //printf("pspmp3: failed to reserve channel\n"); + return 0; + } + //printf("pspmp3: reserved channel %i\n", MP3ME_audio_channel); + return 1; +} - // Done. - samplesToWrite = 0; - } - else { - // Write samplesAvailable samples. - convertLeftSamples(destination, destination + samplesAvailable, &synth.pcm.samples[0][samplesRead]); - convertRightSamples(destination, destination + samplesAvailable, &synth.pcm.samples[1][samplesRead]); - // We need more PCM data. - samplesRead = 0; - decode(); +int Load(const char* musicfile) +{ + getcwd(currentDir, 256); + //printf("pspmp3: Loading %s\n", musicfile); + MP3ME_filePos = 0; + MP3ME_isPlaying = 0; + strcpy(MP3ME_fileName, musicfile); - // We've still got more to write. - destination += samplesAvailable; - samplesToWrite -= samplesAvailable; - } - } -} + MP3ME_thid = -1; + MP3ME_eof = 0; + MP3ME_thid = sceKernelCreateThread("decodeThread", decodeThread, THREAD_PRIORITY, DEFAULT_THREAD_STACK_SIZE, PSP_THREAD_ATTR_USER, NULL); + if(MP3ME_thid < 0) + return 0; + + sceKernelStartThread(MP3ME_thid, 0, NULL); + return 1; +} + +int Play(int loop) +{ + if(MP3ME_thid < 0) + return 0; + MP3ME_Loop = loop; + MP3ME_isPlaying = 1; + return 1; +} + +int Stop() +{ + MP3ME_isPlaying = 0; + MP3ME_threadActive = 0; + sceKernelWaitThreadEnd(MP3ME_thid, NULL); + sceKernelDeleteThread(MP3ME_thid); + strcpy(MP3ME_fileName, ""); + return 1; +} + +int Pause() +{ + MP3ME_isPlaying = !MP3ME_isPlaying; + return 1; +} + +int EndOfStream() +{ + return MP3ME_eof; +} + +void GetTimeString(char *dest) +{ + char timeString[9]; + int secs = (int)MP3ME_playingTime; + int hh = secs / 3600; + int mm = (secs - hh * 3600) / 60; + int ss = secs - hh * 3600 - mm * 60; + snprintf(timeString, sizeof(timeString), "%2.2i:%2.2i:%2.2i", hh, mm, ss); + strcpy(dest, timeString); +} + +void FreeTune() +{ + +} + +void End() +{ + Stop(); + releaseAudio(); + MP3ME_audio_channel = 0; +} Index: PSP/pspmp3/MusicEngine.h =================================================================== --- PSP/pspmp3/MusicEngine.h (revision 46) +++ PSP/pspmp3/MusicEngine.h (working copy) @@ -16,16 +16,12 @@ #define MUSICENGINE_H -#include "mad.h" #include -typedef struct { - short left; - short right; -} Sample; +#define AUDIO_SAMPLES 1152 +#define DEFAULT_THREAD_STACK_SIZE 32*1024 - /*! * * \fn int Init() @@ -53,7 +49,7 @@ /*! * * \fn int Play() -* \brief This functions turns on the flag that the +* \brief This functions turns on the flag that the * current mp3 file can be played. */ int Play(); @@ -66,8 +62,8 @@ * \brief This function does not stop the thread. This * function sets the pause variable to true so * that the callbackfunction passes zero's -* instead of musicparts. So the callbackfunction -* keeps on playing but plays zero's which means +* instead of musicparts. So the callbackfunction +* keeps on playing but plays zero's which means * no sound. Also the file indicator is set to * zero. */ @@ -81,7 +77,7 @@ * \fn int Pause() * \brief This function pauses the music by turning the * variable pausesong to 1. This means that zero's -* are passed to the callbackfunction so that no +* are passed to the callbackfunction so that no * sound is played. * This function does not reset the file indicator. */ @@ -98,81 +94,8 @@ int EndOfStream(); - /*! * -* \fn int fillFileBuffer() -* \brief This function is part of the callback function. -* it reads the file for new parts to store into -* the buffer. -*/ -int fillFileBuffer(); - - - -/*! -* -* \fn void fillOutputBuffer(void* buffer, unsigned int samplesToWrite, void* userData) -* \brief This is the main callback function. -* -* @param buffer -* @param samplesToWrite -* @param userData -* -*/ -void fillOutputBuffer(void* buffer, unsigned int samplesToWrite, void* userData); - - -/*! -* -* \fn void decode() -* \brief This function decodes a frame. -* -*/ -void decode(); - - - -/*! -* -* \fn short convertSample(mad_fixed_t sample) -* \brief This function converts a sample. -* -* @param sample is an sample that needs converting. -* -*/ -short convertSample(mad_fixed_t sample); - - - -/*! -* -* \fn void convertLeftSamples(Sample* first, Sample* last, const mad_fixed_t* src) -* \brief This function coverts the left part of the sample. -* -* @param first is the first sample -* @param last is the last sample -* @param src is the source? -* -*/ -void convertLeftSamples(Sample* first, Sample* last, const mad_fixed_t* src); - - - -/*! -* -* \fn void convertRightSamples(Sample* first, Sample* last, const mad_fixed_t* src) -* \brief This function coverts the right part of the sample. -* -* @param first is the first sample -* @param last is the last sample -* @param src is the source? -* -*/ -void convertRightSamples(Sample* first, Sample* last, const mad_fixed_t* src); - -/*! -* * \fn void GetTimeString(char *dest) * \brief This function returns a string into a reference containing the stream time. * @@ -185,31 +108,4 @@ void End(); -/*! -* -* variables -* -*/ - -struct mad_stream stream; -struct mad_frame frame; -struct mad_synth synth; -mad_timer_t timer; - -int pausesong; -int started; -int endofstream; -char Song[356]; -int SongIsChanged; - - -SceUID mutex; -SceUID file; -unsigned int fileSize; -unsigned int filePos; -unsigned char fileBuffer[2048], *FBptr; -unsigned int samplesRead; - - - #endif Index: PSP/pspmp3/pspmp3.c =================================================================== --- PSP/pspmp3/pspmp3.c (revision 46) +++ PSP/pspmp3/pspmp3.c (working copy) @@ -71,11 +71,11 @@ /* Start MP3 Playback */ static PyObject *pspmp3_play(PyObject *self, PyObject *args) { - if (!PyArg_ParseTuple(args, "")) - return NULL; - //printf("Starting play...\n"); + int loop; + if (!PyArg_ParseTuple(args, "i", &loop)) + return NULL; - Play(); + Play(loop); //printf("Ended play...\n"); Py_INCREF(Py_None); return Py_None; @@ -104,7 +104,7 @@ char time[13]; GetTimeString(time); - + return Py_BuildValue("s", time); Py_INCREF(Py_None); Index: PSP/pspnet/pspnet.c =================================================================== --- PSP/pspnet/pspnet.c (revision 46) +++ PSP/pspnet/pspnet.c (working copy) @@ -20,6 +20,9 @@ #include #include +#define ADDPSPNETINT(name) PyModule_AddIntConstant(mdl, #name, (int)PSP_NET_##name) + +#define PSP_NET_APCTL_STATE_CONNECTED -1 static PyObject* net_error = NULL; @@ -301,7 +304,7 @@ stateLast = state; } - if (state == 4) + if (state == PSP_NET_APCTL_STATE_GOT_IP) break; // connected with static IP // wait a little before polling again @@ -317,6 +320,9 @@ if ((int)(now - started) >= timeout) { PyErr_SetString(net_error, "Timeout while trying to connect"); + Py_BEGIN_ALLOW_THREADS + sceNetApctlDisconnect(); + Py_END_ALLOW_THREADS return NULL; } } @@ -324,7 +330,7 @@ if (callback) { - ret = PyObject_CallFunction(callback, "i", -1); + ret = PyObject_CallFunction(callback, "i", PSP_NET_APCTL_STATE_CONNECTED); if (!ret) return NULL; Py_XDECREF(ret); @@ -354,6 +360,8 @@ return NULL; } + if (state == PSP_NET_APCTL_STATE_GOT_IP) + state = PSP_NET_APCTL_STATE_CONNECTED; return Py_BuildValue("i", state); } @@ -375,7 +383,7 @@ static PyObject* get_ip(PyObject *self, PyObject *args) { - char ipaddr[32]; + union SceNetApctlInfo info; if (!PyArg_ParseTuple(args, ":get_ip")) return NULL; @@ -383,15 +391,53 @@ if (PyErr_CheckSignals()) return NULL; - if (sceNetApctlGetInfo(8, ipaddr) != 0) + if (sceNetApctlGetInfo(PSP_NET_APCTL_INFO_IP, &info) != 0) { PyErr_SetString(net_error, "Could not get IP"); return NULL; } - return Py_BuildValue("s", ipaddr); + return Py_BuildValue("s", info.ip); } +static PyObject* get_signal_strength(PyObject *self, PyObject *args) +{ + union SceNetApctlInfo info; + + if (!PyArg_ParseTuple(args, ":get_signal_strength")) + return NULL; + + if (PyErr_CheckSignals()) + return NULL; + + if (sceNetApctlGetInfo(PSP_NET_APCTL_INFO_STRENGTH, &info) != 0) + { + PyErr_SetString(net_error, "Could not get signal strength"); + return NULL; + } + + return Py_BuildValue("i", (int)info.strength); +} + +static PyObject* get_channel(PyObject *self, PyObject *args) +{ + union SceNetApctlInfo info; + + if (!PyArg_ParseTuple(args, ":get_channel")) + return NULL; + + if (PyErr_CheckSignals()) + return NULL; + + if (sceNetApctlGetInfo(PSP_NET_APCTL_INFO_CHANNEL, &info) != 0) + { + PyErr_SetString(net_error, "Could not get ap channel"); + return NULL; + } + + return Py_BuildValue("i", (int)info.channel); +} + static PyObject* enum_configs(PyObject *self, PyObject *args) { int index = 1; @@ -468,6 +514,8 @@ { "connectToAPCTL", (PyCFunction)connect_to_apctl, METH_VARARGS|METH_KEYWORDS, "" }, { "disconnectAPCTL", (PyCFunction)disconnect_apctl, METH_VARARGS, "" }, { "getAPCTLState", (PyCFunction)get_apctl_state, METH_VARARGS, "" }, + { "getAPCTLSignalStrength", (PyCFunction)get_signal_strength, METH_VARARGS, "" }, + { "getAPCTLChannel", (PyCFunction)get_channel, METH_VARARGS, "" }, { "getIP", (PyCFunction)get_ip, METH_VARARGS, "" }, { "enumConfigs", (PyCFunction)enum_configs, METH_VARARGS, "" }, @@ -495,6 +543,15 @@ if (!mdl) return; + ADDPSPNETINT(APCTL_STATE_CONNECTED); + ADDPSPNETINT(APCTL_STATE_DISCONNECTED); + ADDPSPNETINT(APCTL_STATE_SCANNING); + ADDPSPNETINT(APCTL_STATE_JOINING); + ADDPSPNETINT(APCTL_STATE_GETTING_IP); + ADDPSPNETINT(APCTL_STATE_GOT_IP); + ADDPSPNETINT(APCTL_STATE_EAP_AUTH); + ADDPSPNETINT(APCTL_STATE_KEY_EXCHANGE); + /* Py_INCREF((PyObject*)&PyPSP_AdHocType); PyModule_AddObject(mdl, "AdHoc", (PyObject*)&PyPSP_AdHocType); Index: PSP/samples/osl_mod/bkg.png =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: PSP\samples\osl_mod\bkg.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: PSP/samples/osl_mod/fonts/bkg.png =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: PSP\samples\osl_mod\fonts\bkg.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: PSP/samples/osl_mod/fonts/SansSerif.oft =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: PSP\samples\osl_mod\fonts\SansSerif.oft ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: PSP/samples/osl_mod/fonts/script.py =================================================================== --- PSP/samples/osl_mod/fonts/script.py (revision 0) +++ PSP/samples/osl_mod/fonts/script.py (revision 0) @@ -0,0 +1,52 @@ +# -*- coding: ISO-8859-1 -*- + +import osl, pspos + +osl.initGfx(osl.PF_8888, True) +osl.intraFontInit(osl.INTRAFONT_CACHE_ALL | osl.INTRAFONT_STRING_UTF8) +osl.setQuitOnLoadFailure(True) + +bkg = osl.Image('bkg.png', osl.IN_RAM | osl.SWIZZLED, osl.PF_8888) + +ofont = osl.Font("font.oft") +ifont = osl.Font("flash0:/font/ltn0.pgf") +osl.setTextColor(osl.RGBA(255,255,255,255)) +osl.setBkColor(osl.RGBA(255,255,255,0)) + +sfont = osl.SFont("sfont.png") + +osl.intraFontSetStyle(ifont, 1.0, osl.RGBA(255,255,255,255), osl.RGBA(0,0,0,0), osl.INTRAFONT_ALIGN_LEFT) + +skip = False + +while not osl.mustQuit(): + if not skip: + osl.startDrawing() + + bkg.draw() + + FPS = osl.getFPS() + ofont.set() + osl.drawString(5, 5, "FPS: %i" % FPS) + osl.drawString(5, 20, "CPU: %i" % pspos.getclock()) + osl.drawString(5, 35, "BUS: %i" % pspos.getbus()) + + ifont.set() + osl.drawString(180, 120, "This is IntraFont") + ofont.set() + osl.drawString(180, 140, "This is an OFT") + + sfont.drawString(180, 155, "This is a SFont"); + + ifont.set() + osl.drawString(150, 250, "Press X to quit") + + osl.endDrawing() + osl.endFrame() + skip = osl.syncFrame() + + ctrl = osl.Controller() + if ctrl.held_cross: + osl.safeQuit() + +osl.endGfx() Index: PSP/samples/osl_mod/netDialog/script.py =================================================================== --- PSP/samples/osl_mod/netDialog/script.py (revision 0) +++ PSP/samples/osl_mod/netDialog/script.py (revision 0) @@ -0,0 +1,50 @@ +# -*- coding: ISO-8859-1 -*- + +import osl + +osl.initGfx(osl.PF_8888, True) +osl.intraFontInit(osl.INTRAFONT_CACHE_MED) +osl.setQuitOnLoadFailure(True) +#osl.netInit() + +bkg = osl.Image('bkg.png', osl.IN_RAM | osl.SWIZZLED, osl.PF_8888) + +ifont = osl.Font("flash0:/font/ltn0.pgf") +osl.intraFontSetStyle(ifont, 1.0, osl.RGBA(255,255,255,255), osl.RGBA(0,0,0,0), osl.INTRAFONT_ALIGN_LEFT) +ifont.set() + +skip = False +dialog = osl.DIALOG_NONE + +while not osl.mustQuit(): + if not skip: + osl.startDrawing() + + bkg.draw() + + osl.drawString(5, 5, "FPS: %i" % osl.getFPS()) + + osl.drawString(180, 130, "Network dialog test program") + osl.drawString(180, 160, "Press start to show the network dialog") + + osl.drawString(150, 250, "Press X to quit") + + dialog = osl.getDialogType() + if dialog != osl.DIALOG_NONE: + osl.drawDialog() + if osl.getDialogStatus() == osl.DIALOG_NONE: + osl.endDialog() + + osl.endDrawing() + osl.endFrame() + skip = osl.syncFrame() + + if dialog == osl.DIALOG_NONE: + ctrl = osl.Controller() + if ctrl.pressed_cross: + osl.safeQuit() + elif ctrl.pressed_start: + osl.initNetDialog() + +#osl.netTerm() +osl.endGfx() \ No newline at end of file Index: PSP/samples/osl_mod/objects/drawable.py =================================================================== --- PSP/samples/osl_mod/objects/drawable.py (revision 0) +++ PSP/samples/osl_mod/objects/drawable.py (revision 0) @@ -0,0 +1,94 @@ +import osl + +################################################################################ +# Drawable +################################################################################ +class drawable(object): + """Class Drawable""" + #Constructor + def __init__(self, name=None): + self.name = name + self.visible = True + self.x = 0 + self.y = 0 + self.animations = [] + self.data = {} + + + #Methods: + def draw(self): + for animation in self.animations: + animation(self) + + +################################################################################ +# Image Object +################################################################################ +class imageObj(drawable): + """Class imageObj""" + #Constructor + def __init__(self, name=None): + self.image = None + drawable.__init__(self, name) + + #Methods: + def draw(self): + drawable.draw(self) + if self.visible and self.image: + self.image.draw(self.x, self.y) + + +################################################################################ +# String Object +################################################################################ +class stringObj(drawable): + """Class stringObj""" + #Constructor + def __init__(self, name=None): + self.font = None + self.string = None + self.textColor = osl.RGBA(255,255,255,255) + self.backColor = osl.RGBA(255,255,255,0) + drawable.__init__(self, name) + + #Methods: + def draw(self): + drawable.draw(self) + if self.visible and self.font: + self.font.set() + osl.setTextColor(self.textColor) + osl.setBkColor(self.backColor) + osl.drawString(self.x, self.y, self.string) + + +################################################################################ +# Layer +################################################################################ +class layer(object): + """Class Layer""" + #Constructor + def __init__(self): + self.objects = {} + + #Methods: + def addObject(self, obj): + if obj.name == None: + raise ValueError, 'name' + self.objects[obj.name] = obj + return True + + def removeObject(self, obj): + if obj.name == None: + raise ValueError, 'name' + if obj.name in self.objects: + del self.objects[obj.name] + return True + return False + + def removeObjectByName(self, objName): + obj = drawable(objName) + return self.removeObject(obj) + + def draw(self): + for key, obj in self.objects.iteritems(): + obj.draw() Index: PSP/samples/osl_mod/objects/script.py =================================================================== --- PSP/samples/osl_mod/objects/script.py (revision 0) +++ PSP/samples/osl_mod/objects/script.py (revision 0) @@ -0,0 +1,158 @@ +# -*- coding: ISO-8859-1 -*- +import osl, pspos, drawable, random + +osl.initGfx(osl.PF_5551, True) +osl.setDithering(True) +osl.setQuitOnLoadFailure(True) +osl.setFrameskip(1) +osl.setKeyAnalogToDPad(80) + +bkg = osl.Image('bkg.png', osl.IN_RAM | osl.SWIZZLED, osl.PF_5551) +sprite = osl.Image('sprite.png', osl.IN_RAM | osl.SWIZZLED, osl.PF_5551) + +ofont = osl.Font("font.oft") +osl.setTextColor(osl.RGBA(255,255,255,255)) +osl.setBkColor(osl.RGBA(255,255,255,0)) +ofont.set() + +#Sprite animations (move and rotate) +def spriteAnim(obj): + obj.image.rotate(obj.data["rotate"]) + newX = obj.x + obj.data["moveX"] + newY = obj.y + obj.data["moveY"] + sizeX = obj.image.centerX + sizeY = obj.image.centerY + if newX + sizeX > 480 or newX - sizeX < 0: + obj.data["moveX"] = -obj.data["moveX"] + elif newY + sizeY > 272 or newY - sizeY < 0: + obj.data["moveY"] = -obj.data["moveY"] + obj.x += obj.data["moveX"] + obj.y += obj.data["moveY"] + +def addSprite(layer, objName=None): + if not objName: + objName = "obj_%2.2i" % len(layer.objects) + obj = drawable.imageObj(objName) + obj.image = osl.Image((sprite.sizeX, sprite.sizeY), osl.IN_RAM, osl.PF_5551) + sprite.copy(obj.image) + obj.image.swizzle() + obj.image.setRotationCenter() + obj.x = random.randint(obj.image.centerX, 480 - obj.image.centerX) + obj.y = random.randint(obj.image.centerY, 272 - obj.image.centerY) + obj.data["rotate"] = random.randint(1, 5) + obj.data["moveX"] = random.randint(1, 5) + obj.data["moveY"] = random.randint(1, 5) + obj.animations.append(spriteAnim) + layer.addObject(obj) + + +def removeSprite(layer): + names = layer.objects.keys() + names.sort() + if len(names): + nameObj = names.pop() + layer.removeObjectByName(nameObj) + +layers = [] +#Initial sprite objects +sprites = drawable.layer() +for i in xrange(0, 20, 1): + addSprite(sprites) + +layers.append(sprites) + +#Initial generic objects +objects = drawable.layer() + +#FPS +FPSobj = drawable.stringObj("FPS") +FPSobj.font = ofont +FPSobj.x = 5 +FPSobj.y = 5 +def FPSAnim(obj): + obj.string = "FPS: %i" % osl.getFPS() +FPSobj.animations.append(FPSAnim) +objects.addObject(FPSobj) + +#CPU freq +CPUobj = drawable.stringObj("CPU") +CPUobj.font = ofont +CPUobj.x = 5 +CPUobj.y = 20 +def CPUAnim(obj): + obj.string = "CPU: %i" % pspos.getclock() +CPUobj.animations.append(CPUAnim) +objects.addObject(CPUobj) + +#BUS freq +BUSobj = drawable.stringObj("BUS") +BUSobj.font = ofont +BUSobj.x = 5 +BUSobj.y = 35 +def BUSAnim(obj): + obj.string = "BUS: %i" % pspos.getbus() +BUSobj.animations.append(BUSAnim) +objects.addObject(BUSobj) + +#Objects count +objCount = drawable.stringObj("OBJ") +objCount.font = ofont +objCount.x = 5 +objCount.y = 50 +objCount.data["layer"] = sprites +objCount.data["objects"] = objects +def objCountAnim(obj): + obj.string = "Objects: %i" % (len(obj.data["layer"].objects) + len(obj.data["objects"].objects), ) +objCount.animations.append(objCountAnim) +objects.addObject(objCount) + +#Messages +MSG1obj = drawable.stringObj("MSG1obj") +MSG1obj.font = ofont +MSG1obj.x = 180 +MSG1obj.y = 150 +MSG1obj.string = "Press up to add an object" +objects.addObject(MSG1obj) + +MSG2obj = drawable.stringObj("MSG2obj") +MSG2obj.font = ofont +MSG2obj.x = 180 +MSG2obj.y = 165 +MSG2obj.string = "Press down to remove an object" +objects.addObject(MSG2obj) + +MSG3obj = drawable.stringObj("MSG3obj") +MSG3obj.font = ofont +MSG3obj.x = 150 +MSG3obj.y = 250 +MSG3obj.string = "Press X to quit" +objects.addObject(MSG3obj) + +layers.append(objects) + +################################################################################ +# Main program +################################################################################ +skip = False +while not osl.mustQuit(): + if not skip: + osl.startDrawing() + + bkg.draw() + + for layer in layers: + layer.draw() + + osl.endDrawing() + osl.endFrame() + skip = osl.syncFrame() + + ctrl = osl.Controller() + if ctrl.pressed_up: + addSprite(sprites) + elif ctrl.pressed_down: + removeSprite(sprites) + elif ctrl.pressed_cross: + osl.safeQuit() + +osl.endGfx() Index: PSP/samples/osl_mod/objects/sprite.png =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: PSP\samples\osl_mod\objects\sprite.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: PSP/samples/osl_mod/OSK/script.py =================================================================== --- PSP/samples/osl_mod/OSK/script.py (revision 0) +++ PSP/samples/osl_mod/OSK/script.py (revision 0) @@ -0,0 +1,53 @@ +# -*- coding: ISO-8859-1 -*- + +import osl + +osl.initGfx(osl.PF_8888, True) +osl.intraFontInit(osl.INTRAFONT_CACHE_MED) +osl.setQuitOnLoadFailure(True) + +bkg = osl.Image('bkg.png', osl.IN_RAM | osl.SWIZZLED, osl.PF_8888) + +ifont = osl.Font("flash0:/font/ltn0.pgf") +osl.intraFontSetStyle(ifont, 1.0, osl.RGBA(255,255,255,255), osl.RGBA(0,0,0,0), osl.INTRAFONT_ALIGN_LEFT) +ifont.set() + +skip = False +message = "" + +while not osl.mustQuit(): + if not skip: + osl.startDrawing() + + bkg.draw() + + osl.drawString(5, 5, "FPS: %i" % osl.getFPS()) + + osl.drawString(180, 130, "Sony OSK test program") + osl.drawString(180, 160, "Press start to show the OSK") + osl.drawString(180, 190, message) + + osl.drawString(150, 250, "Press X to quit") + + if osl.oskIsActive(): + osl.drawOsk() + if osl.getOskStatus() == osl.DIALOG_NONE: + if osl.oskGetResult() == osl.OSK_CANCEL: + message = "Cancel" + else: + userText = osl.oskGetText() + message = "You entered: %s" % userText + osl.endOsk() + + osl.endDrawing() + osl.endFrame() + skip = osl.syncFrame() + + if not osl.oskIsActive(): + ctrl = osl.Controller() + if ctrl.held_cross: + osl.safeQuit() + elif ctrl.pressed_start: + osl.initOsk("Please insert some text", "Initial text", 128, 1, osl.OSK_ENGLISH) + +osl.endGfx()