 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
elevationsnow
Joined: 10 Sep 2005 Posts: 22
|
Posted: Fri Sep 16, 2005 7:19 am Post subject: How Does this code Look |
|
|
| Code: |
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <string.h>
PSP_MODULE_INFO("menreplace", 0, 1, 1);
#define printf pspDebugScreenPrintf
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
/* Build a path, append a directory slash if requested */
void build_path(char *output, const char *root, const char *path, int append)
{
while(*root != 0)
{
*output++ = *root++;
}
if(*(root-1) != '/')
{
*output++ = '/';
}
while(*path != 0)
{
*output++ = *path++;
}
if(append)
*output++ = '/';
*output++ = 0;
}
/* Define a write buffer */
char write_buffer[128*1024];
void write_file(const char *read_loc, const char *write_loc, const char *name)
{
int fdin;
int fdout;
char readpath[256];
char writepath[256];
build_path(readpath, read_loc, name, 0);
build_path(writepath, write_loc, name, 0);
printf("Writing %s\n", writepath);
fdin = sceIoOpen(readpath, PSP_O_RDONLY, 0777);
if(fdin >= 0)
{
int bytesRead = 1;
fdout = sceIoOpen(writepath, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
if(fdout < 0)
{
printf("Couldn't open %s\n", writepath);
}
bytesRead = sceIoRead(fdin, write_buffer, sizeof(write_buffer));
while((bytesRead > 0) && (fdout >= 0))
{
sceIoWrite(fdout, write_buffer, bytesRead);
bytesRead = sceIoRead(fdin, write_buffer, sizeof(write_buffer));
}
if(fdout >= 0)
{
sceIoClose(fdout);
}
if(fdin >= 0)
{
sceIoClose(fdin);
}
}
else
{
printf("Couldn't open %s\n", readpath);
}
}
void writethefileyo(void)
{
int fd;
fd = sceIoOpen("ms0:/topmenu_plugin.rco", PSP_O_RDONLY, 0777);
if(fd >= 0)
{
char men_id[17];
char path[256];
sceIoRead(fd, men_id, 16);
sceIoClose(fd);
game_id[16] = 0;
build_path(path, "flash0:/vsh/resource/", NULL, 0);
printf("Found Top Menu, Writing... %s\n", men_id);
write_file("ms0:/", path, "topmenu_plugin.rco");
}
}
void show_menu(void)
{
printf("psp top menu replacement tool - by callum bethune");
printf("press [x] to continue/n");
}
int main(void)
{
SceCtrlData pad_data;
pspDebugScreenSetBackColor(0xFFFFFFFF);
pspDebugScreenSetTextColor(0);
pspDebugScreenInit();
SetupCallbacks();
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(1);
show_menu();
for(;;)
{
sceCtrlReadBufferPositive(&pad_data, 1);
if(pad_data.Buttons & PSP_CTRL_CROSS)
{
writethefileyo();
pspDebugScreenClear();
printf("finished thank you for using!\n");
show_menu();
}
sceDisplayWaitVblankStart();
}
return 0;
}
|
i used most teh code from the fileio sample
can some one tell me if that works
i know it compiles but i dont wanna f up my psp |
|
| Back to top |
|
 |
71M
Joined: 21 Jun 2005 Posts: 122 Location: London
|
Posted: Fri Sep 16, 2005 7:53 am Post subject: |
|
|
Dude! You bricked my PSP!!!
Heh, only joking! :)
I don't think you can just write to flash0: like that, could be wrong though...
Good luck,
71M |
|
| Back to top |
|
 |
elevationsnow
Joined: 10 Sep 2005 Posts: 22
|
Posted: Fri Sep 16, 2005 7:56 am Post subject: |
|
|
wait so you made file assistant and you cant tell me if that code would work or not :-P jk jk
well thanks ne ways btw how does file assistant do it
cause i looked through all of your code 100+ pages and didnt comprehend any thing except the printfs but then again flash0 is read only but i figured you just coded it to check if your trying to move to flash0 the menu option to copy doesnt come up. :-D |
|
| Back to top |
|
 |
71M
Joined: 21 Jun 2005 Posts: 122 Location: London
|
Posted: Fri Sep 16, 2005 8:01 am Post subject: |
|
|
I'm afraid I'm not brave enough to mess around with things like that! :)
Give me a minute to try copying a file to flash0: and see what happens...
71M |
|
| Back to top |
|
 |
elevationsnow
Joined: 10 Sep 2005 Posts: 22
|
Posted: Fri Sep 16, 2005 8:03 am Post subject: |
|
|
| lol im not sure if it was me or another homebrew app that f ed up my psp but now i have a 2.0 cause i up'd it thinking it would fix it and it mostly did but my r button is still fed up it freezes on and then if i tap it real fast about 3 times it un freezes :-/^2 but i dont wanna f up my friends psp too! |
|
| Back to top |
|
 |
71M
Joined: 21 Jun 2005 Posts: 122 Location: London
|
Posted: Fri Sep 16, 2005 8:08 am Post subject: |
|
|
Nope, FileAssistant doesn't like copying to flash0: I'm afraid :(
I think you have to do some jiggery pokery to get files copied onto flash0: and like I said before I'm not man enough to do that :)
Laters,
71M |
|
| Back to top |
|
 |
elevationsnow
Joined: 10 Sep 2005 Posts: 22
|
Posted: Fri Sep 16, 2005 8:09 am Post subject: |
|
|
| btw while were talking does the pspsdk not have assert.h and thats why you made your own? |
|
| Back to top |
|
 |
71M
Joined: 21 Jun 2005 Posts: 122 Location: London
|
Posted: Fri Sep 16, 2005 8:18 am Post subject: |
|
|
I didn't realise that there was an assert already in the SDK, but having a quick look it doesn't appear to function quite the same as the one in FileAssistant.
The FA version allows you to skip asserts with the triangle button, allowing the program to continue running and also includes a little bit more information about the assert thats fired.
Cheers,
71M |
|
| Back to top |
|
 |
OmahaStylee
Joined: 29 Aug 2005 Posts: 14 Location: Los Angeles, CA
|
Posted: Fri Sep 16, 2005 3:01 pm Post subject: |
|
|
Back on topic, another dev told me that there was a code burried in these forums somwhere that was used to write to flash0. They were using it to change the background, but said that it was easily edited to write to whichever file you want. Anybody seen it? _________________
 |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|