How Does this code Look

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

Moderators: cheriff, TyRaNiD

Post Reply
elevationsnow
Posts: 22
Joined: Sat Sep 10, 2005 6:45 am

How Does this code Look

Post by elevationsnow »

Code: Select all


#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>

#include <string.h>

PSP_MODULE_INFO&#40;"menreplace", 0, 1, 1&#41;;

#define printf pspDebugScreenPrintf


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

        return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41;
&#123;
        int cbid;

        cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
        sceKernelRegisterExitCallback&#40;cbid&#41;;

        sceKernelSleepThreadCB&#40;&#41;;

        return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
        int thid = 0;

        thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
        if&#40;thid >= 0&#41;
        &#123;
                sceKernelStartThread&#40;thid, 0, 0&#41;;
        &#125;

        return thid;
&#125;

/* Build a path, append a directory slash if requested */
void build_path&#40;char *output, const char *root, const char *path, int append&#41;
&#123;
        while&#40;*root != 0&#41;
        &#123;
                *output++ = *root++;
        &#125;

        if&#40;*&#40;root-1&#41; != '/'&#41;
        &#123;
                *output++ = '/';
        &#125;

        while&#40;*path != 0&#41;
        &#123;
                *output++ = *path++;
        &#125;
        if&#40;append&#41;
                *output++ = '/';

        *output++ = 0;
&#125;

/* Define a write buffer */
char write_buffer&#91;128*1024&#93;;

void write_file&#40;const char *read_loc, const char *write_loc, const char *name&#41;
&#123;
        int fdin;
        int fdout;
        char readpath&#91;256&#93;;
        char writepath&#91;256&#93;;

        build_path&#40;readpath, read_loc, name, 0&#41;;
        build_path&#40;writepath, write_loc, name, 0&#41;;
        printf&#40;"Writing %s\n", writepath&#41;;

        fdin = sceIoOpen&#40;readpath, PSP_O_RDONLY, 0777&#41;;
        if&#40;fdin >= 0&#41;
        &#123;
                int bytesRead = 1;
                fdout = sceIoOpen&#40;writepath, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777&#41;;
                if&#40;fdout < 0&#41;
                &#123;
                        printf&#40;"Couldn't open %s\n", writepath&#41;;
                &#125;

                bytesRead = sceIoRead&#40;fdin, write_buffer, sizeof&#40;write_buffer&#41;&#41;;
                while&#40;&#40;bytesRead > 0&#41; && &#40;fdout >= 0&#41;&#41;
                &#123;
                        sceIoWrite&#40;fdout, write_buffer, bytesRead&#41;;
                        bytesRead = sceIoRead&#40;fdin, write_buffer, sizeof&#40;write_buffer&#41;&#41;;
                &#125;

                if&#40;fdout >= 0&#41;
                &#123;
                        sceIoClose&#40;fdout&#41;;
                &#125;

                if&#40;fdin >= 0&#41;
                &#123;
                        sceIoClose&#40;fdin&#41;;
                &#125;
        &#125;
        else
        &#123;
                printf&#40;"Couldn't open %s\n", readpath&#41;;
        &#125;
&#125;

void writethefileyo&#40;void&#41;
&#123;
        int fd;
         fd = sceIoOpen&#40;"ms0&#58;/topmenu_plugin.rco", PSP_O_RDONLY, 0777&#41;;
        if&#40;fd >= 0&#41;
        &#123;
                char men_id&#91;17&#93;;
                char path&#91;256&#93;;

                sceIoRead&#40;fd, men_id, 16&#41;;
                sceIoClose&#40;fd&#41;;
                game_id&#91;16&#93; = 0;
                build_path&#40;path, "flash0&#58;/vsh/resource/", NULL, 0&#41;;

                printf&#40;"Found Top Menu, Writing... %s\n", men_id&#41;;

                write_file&#40;"ms0&#58;/", path, "topmenu_plugin.rco"&#41;;
        &#125;
&#125;



void show_menu&#40;void&#41;
&#123;
 printf&#40;"psp top menu replacement tool - by callum bethune"&#41;;
 printf&#40;"press &#91;x&#93; to continue/n"&#41;;
&#125;

int main&#40;void&#41;
&#123;
        SceCtrlData pad_data;

        pspDebugScreenSetBackColor&#40;0xFFFFFFFF&#41;;
        pspDebugScreenSetTextColor&#40;0&#41;;
        pspDebugScreenInit&#40;&#41;;
        SetupCallbacks&#40;&#41;;
        sceCtrlSetSamplingCycle&#40;0&#41;;
        sceCtrlSetSamplingMode&#40;1&#41;;
        show_menu&#40;&#41;;

        for&#40;;;&#41;
        &#123;
                sceCtrlReadBufferPositive&#40;&pad_data, 1&#41;;
                if&#40;pad_data.Buttons & PSP_CTRL_CROSS&#41;
                &#123;
                        writethefileyo&#40;&#41;;
                        pspDebugScreenClear&#40;&#41;;
                        printf&#40;"finished thank you for using!\n"&#41;;
                        show_menu&#40;&#41;;
                &#125;

                sceDisplayWaitVblankStart&#40;&#41;;
        &#125;

        return 0;
&#125;
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
71M
Posts: 122
Joined: Tue Jun 21, 2005 5:28 am
Location: London

Post by 71M »

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
elevationsnow
Posts: 22
Joined: Sat Sep 10, 2005 6:45 am

Post by elevationsnow »

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
71M
Posts: 122
Joined: Tue Jun 21, 2005 5:28 am
Location: London

Post by 71M »

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
elevationsnow
Posts: 22
Joined: Sat Sep 10, 2005 6:45 am

Post by elevationsnow »

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!
71M
Posts: 122
Joined: Tue Jun 21, 2005 5:28 am
Location: London

Post by 71M »

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
elevationsnow
Posts: 22
Joined: Sat Sep 10, 2005 6:45 am

Post by elevationsnow »

btw while were talking does the pspsdk not have assert.h and thats why you made your own?
71M
Posts: 122
Joined: Tue Jun 21, 2005 5:28 am
Location: London

Post by 71M »

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
OmahaStylee
Posts: 14
Joined: Mon Aug 29, 2005 5:00 pm
Location: Los Angeles, CA
Contact:

Post by OmahaStylee »

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?
Image
Post Reply