1.a. If I use sceCtrlReadBufferPositive then the vsh won't respond to anything until I hit the button it's looking for and then it only works while the code is being executed (I know the code is being executed because the memory stick is being accessed)
1.b. I looked around and saw a suggestion to use sceCtrlPeekBufferPositive but when I use that the code won't execute, vsh works fine but the code is never triggered.
2. When the code is executed the wallpaper isn't automatically refreshed, you can see that the wallpaper has indeed changed if you go to Settings->Theme Settings->Theme and switch between Use and Do Not Use or by coldbooting the psp. I know there has to be some syscall that will refresh it and it's probably in the sceDisplay library but I have no idea which one it might be.
I'm running 3.10 OE-A' in 1.50 Kernel mode, here's the code, any nudge in the right direction would be appreciated.
Code: Select all
// Wallpaper Changer .prx
// by S. Holmes Started 01.23.07
//
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <stdio.h>
#include <stdlib.h>
#include <pspdebug.h>
#include <pspiofilemgr.h>
#include <pspctrl.h>
#include <string.h>
#include <time.h>
PSP_MODULE_INFO("WallpaperChanger", 0, 1, 1);
#define printf pspDebugScreenPrintf
#define Screen PSP_CTRL_SCREEN
#define Square PSP_CTRL_SQUARE
#define LTrig PSP_CTRL_LTRIGGER
#define WPDir "ms0:/PSP/PHOTO/Wallpapers"
#define MAXPATH 262
#define ActualWP "flash1:/vsh/theme/wallpaper.bmp"
// The following counts the number of wallpapers in
// your wallpaper directory, code comes from the
// mp3.c file from the open source irsmp3 project
// thank you to whoever wrote that. Modified so it
// only uses ms0:/PSP/PHOTO/Wallpapers and does not
// use/look for subdirs, also currently only looks
// for .jpg's
int nCountWallPapers() {
int nFileDir;
int WPCount = 0;
SceIoDirent d_dir;
memset(&d_dir, 0, sizeof(SceIoDirent));
nFileDir = sceIoDopen(WPDir);
if (nFileDir >= 0)
{
while ((sceIoDread(nFileDir, &d_dir) > 0))
{
if ((d_dir.d_stat.st_attr & FIO_SO_IFDIR) == 0) //not a directory
{
if (!stricmp(d_dir.d_name+strlen(d_dir.d_name)-4, ".jpg")) //if it is a jpg
{
WPCount++;
}
}
}
sceIoDclose(nFileDir);
}
return WPCount;
}
// This code also taken from mp3.c but altered to fit my needs.
char* szGetWPName()
{
int nFileDir;
SceIoDirent d_dir;
int nCount = -1;
int nRWP;
char szWallName[MAXPATH]; //compiler complains about this being uninitialized but
//it's the only way I got this to work
srand(time(0));
nRWP = rand() % nCountWallPapers();
memset(&d_dir, 0, sizeof(SceIoDirent));
nFileDir = sceIoDopen(WPDir);
if (nFileDir >= 0)
{
while ((sceIoDread(nFileDir, &d_dir) > 0))
{
if ((d_dir.d_stat.st_attr & FIO_SO_IFDIR) == 0) //not a directory
{
if (!stricmp(d_dir.d_name+strlen(d_dir.d_name)-4, ".jpg"))
{
if (nCount == nRWP)
{
sprintf(szWallName, "%s/", WPDir);
strcat(szWallName, d_dir.d_name);
nCount = -1;
break;
}
nCount++;
}
}
}
}
return szWallName; //compiler complains about this too but it's the only
//way I can get this to work
}
void ChangeWP()
{
char* szNewWall = szGetWPName();
int c;
FILE* fSource;
FILE* fDest;
fSource = fopen(szNewWall, "rb");
fDest = fopen(ActualWP, "wb");
while ((c = getc(fSource)) != EOF)
{
fputc(c, fDest);
}
fclose(fSource);
fclose(fDest);
}
// The meat!
int main(void) {
SceCtrlData pad;
while(1)
{
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & Square)
{
ChangeWP();
}
}
return 0;
}
Code: Select all
TARGET = WPC
OBJS = main.o
BUILD_PRX = 1
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = WPC
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak