Some problems with sceCtrlData...

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

Moderators: cheriff, TyRaNiD

Post Reply
blu_eye4
Posts: 37
Joined: Sun Oct 26, 2008 8:41 pm

Some problems with sceCtrlData...

Post by blu_eye4 »

Hi guys! :)

I'm blu_eye4, a new italian user so, if my english is bad, excuse me...

Well, I'm a beginner coder and I'm learning C programming language: I'm not learn it at school, so I don't know many things and feature...


This is the code:

Code: Select all

#include "pspkern.h"
#include <pspkernel.h>
#include <pspiofilemgr.h>
#include <pspctrl.h>
#include "dump.h"
#include <psppower.h>

PSP_MODULE_INFO&#40;"esercitazione", 0, 1, 0&#41;;
#define printf pspDebugScreenPrintf

int sceIoRead&#40;SceUID fd, void *data, SceSize size&#41;;
int *getcwd&#40;char *buffer, size_t length&#41;;
int sceDisplayWaitVblankStart&#40;&#41;;
int sceIoMkdir&#40;const char *dir, SceMode mode&#41;;
int main&#40;void&#41;
&#123;
    SceCtrlData pad;
    int done = 0;
    pspDebugScreenInit&#40;&#41;;
    pspDebugScreenClear&#40;&#41;;
    SetupCallbacks&#40;&#41;;
    char path&#91;256&#93;;
    getcwd&#40;path, 256&#41;;
    printf&#40;"Siamo nella directory %s\n\n", path&#41;;
    printf&#40;"premere X per cambiare frequenza cpu e bus\n"&#41;;
    printf&#40;"premere O per dump memoria\n"&#41;;

    for&#40;;;&#41;&#123;
            sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
    if&#40;pad.Buttons != 0&#41;&#123;
    if&#40;pad.Buttons & PSP_CTRL_CROSS&#41;
    &#123;
        scePowerSetClockFrequency&#40;100,100,50&#41;;
        printf&#40;"frequenza attuale cpu&#58; %d mHz\n", scePowerGetCpuClockFrequency&#40;&#41;&#41;;
        printf&#40;"frequenza attuale bus&#58; %d mHz\n", scePowerGetBusClockFrequency&#40;&#41;&#41;;
    &#125;
    if&#40;pad.Buttons & PSP_CTRL_CIRCLE&#41;
    &#123;
        dump_memory&#40;&#41;;
        printf&#40;"\n\nFatto\n\n"&#41;;

    &#125;
    &#125;
    sceDisplayWaitVblankStart&#40;&#41;;
    return 0;
&#125;
&#125;
It is a simple homebrew who want dump memory. Cygwin can compile it and it doesn't give me any warning or error, but when I play the homebrew on my psp there is a problem: buttons doesnt't work...
Why? How can I resolve?

Thanks a lot for your time and excuse me if there are some grammatical errors :)


ah... I've given some of code from SDK... the dumping function is given from the example...
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

return 0 is inside the for loop :P
blu_eye4
Posts: 37
Joined: Sun Oct 26, 2008 8:41 pm

Post by blu_eye4 »

oh... now it work, but I would know how print once a thing: if I press X, the homebrew printf a lot of times the cpu frequency... How would I do?

Thank a lot
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Make a copy of the pad.Buttons and compare it with the new value to see if buttons have changed, or if just being held down.

Or use sceCtrlReadLatch. You can detect when the button is first pressed, being held down, and released.
blu_eye4
Posts: 37
Joined: Sun Oct 26, 2008 8:41 pm

Post by blu_eye4 »

Torch wrote:Make a copy of the pad.Buttons and compare it with the new value to see if buttons have changed, or if just being held down.

Or use sceCtrlReadLatch. You can detect when the button is first pressed, being held down, and released.

Code: Select all

#include "pspkern.h"
#include <pspkernel.h>
#include <pspiofilemgr.h>
#include <pspctrl.h>
#include "dump.h"
#include <psppower.h>
#include <pspumd.h>
#include <pspdisplay.h>

PSP_MODULE_INFO&#40;"esercitazione", 0, 1, 0&#41;;
#define printf pspDebugScreenPrintf

int sceIoRead&#40;SceUID fd, void *data, SceSize size&#41;;
int *getcwd&#40;char *buffer, size_t length&#41;;
int sceDisplayWaitVblankStart&#40;&#41;;
int sceIoMkdir&#40;const char *dir, SceMode mode&#41;;
int main&#40;void&#41;
&#123;
    SceCtrlData pad;
    SceCtrlLatch latch;
    int sceCtrlReadLatch&#40;SceCtrlLatch *latch&#41;;
    pspDebugScreenInit&#40;&#41;;
    pspDebugScreenClear&#40;&#41;;
    SetupCallbacks&#40;&#41;;
    char path&#91;256&#93;;
    getcwd&#40;path, 256&#41;;
    printf&#40;"Siamo nella directory %s\n\n", path&#41;;
    printf&#40;"premere X per cambiare frequenza cpu e bus\n"&#41;;
    printf&#40;"premere O per dump memoria\n"&#41;;

    for&#40;;;&#41;&#123;
            sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
            sceCtrlReadLatch&#40;&latch&#41;;
    if&#40;pad.Buttons != 0&#41;&#123;
    if&#40;pad.Buttons & PSP_CTRL_CROSS&#41;
    &#123;
        scePowerSetClockFrequency&#40;100,100,50&#41;;
        printf&#40;"frequenza attuale cpu&#58; %d mHz\n", scePowerGetCpuClockFrequency&#40;&#41;&#41;;
        printf&#40;"frequenza attuale bus&#58; %d mHz\n", scePowerGetBusClockFrequency&#40;&#41;&#41;;
    &#125;
    if&#40;pad.Buttons & PSP_CTRL_CIRCLE&#41;
    &#123;
        dump_memory&#40;&#41;;
        pspDebugScreenClear&#40;&#41;;
        printf&#40;"\n\nFatto\n\n"&#41;;
        sceCtrlReadLatch&#40;&latch&#41;;

    &#125;
    &#125;

&#125;
   sceDisplayWaitVblankStart&#40;&#41;;
    return 0;
&#125;
Ok, now the dumping function doesn't work, I press the button, on the screen i read "dumping 28 Mb..." but after 20 seconds the psp shut down...
I don't understand the problem, I've seen the example and there isn't difference. The example work, my homebrew not...

I've tried how to use sceCtrlReadLatch and I've found some documentation on doxygen, but I can't work it... please help me :)

Thank again for your time
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Code: Select all

	SceCtrlLatch latch;
	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_DIGITAL&#41;;
	
	for&#40;;;&#41;
	&#123;
		sceCtrlReadLatch&#40;&latch&#41;;
		if &#40;latch.uiMake & PSP_CTRL_CROSS&#41;
		&#123;
			....
		&#125;
	&#125;
uiMake is on first press only. uiBreak is on release.

All other statements are unnecessary.
blu_eye4
Posts: 37
Joined: Sun Oct 26, 2008 8:41 pm

Post by blu_eye4 »

Torch wrote:

Code: Select all

	SceCtrlLatch latch;
	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_DIGITAL&#41;;
	
	for&#40;;;&#41;
	&#123;
		sceCtrlReadLatch&#40;&latch&#41;;
		if &#40;latch.uiMake & PSP_CTRL_CROSS&#41;
		&#123;
			....
		&#125;
	&#125;
uiMake is on first press only. uiBreak is on release.

All other statements are unnecessary.
Thanks a lot, now all work!!
Can you resolve this problem also?

Code: Select all

int main&#40;void&#41;
&#123;
    sceIoUnassign&#40;"flash0&#58;"&#41;;
    sceIoAssign&#40;"flash0&#58;", "lflash0&#58;0,0", "flashfat0&#58;", IOASSIGN_RDWR, NULL, 0&#41;;
    SceCtrlData pad;
    SceCtrlLatch latch;
    int sceCtrlReadLatch&#40;SceCtrlLatch *latch&#41;;
    pspDebugScreenInit&#40;&#41;;
    pspDebugScreenClear&#40;&#41;;
    SetupCallbacks&#40;&#41;;
    printf&#40;"DumperXflash v. 1,0 by blu_eye4\n"&#41;;
    printf&#40;"Ringrazio Dark_alex per il cf, ps2dev.org per il supporto così come psp-ita.com\n"&#41;;
    printf&#40;"Grazie a tyrannid per is suoi esempi del SDK\n"&#41;;
    printf&#40;"premere O per dump flash 1\n"&#41;;
    printf&#40;"premere &#91;&#93; per dump flash 0\n"&#41;;
    printf&#40;"premere triangolo per eliminare la cartella dic dalla flash0\n"&#41;;
    printf&#40;"premere HOME per uscire senza effettuare alcuna operazione\n"&#41;;

    for&#40;;;&#41;&#123;
            sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
            sceCtrlReadLatch&#40;&latch&#41;;
    if&#40;latch.uiMake & PSP_CTRL_CIRCLE&#41;
    &#123;
            dump_filesystem&#40;"flash1&#58;/", "ms0&#58;/flash1"&#41;;
			pspDebugScreenClear&#40;&#41;;
            printf&#40;"\n\nFatto\n\n"&#41;;
            printf&#40;"premere O per dump flash 1\n"&#41;;
            printf&#40;"premere &#91;&#93; per dump flash 0\n"&#41;;
            printf&#40;"premere HOME per uscire\n"&#41;;
    &#125;
    if&#40;latch.uiMake & PSP_CTRL_SQUARE&#41;
    &#123;
        dump_filesystem&#40;"flash0&#58;/", "ms0&#58;/flash0"&#41;;
        pspDebugScreenClear&#40;&#41;;
        printf&#40;"\n\nFatto\n\n"&#41;;
        printf&#40;"premere O per dump flash 1\n"&#41;;
        printf&#40;"premere &#91;&#93; per dump flash 0\n"&#41;;
        printf&#40;"premere HOME per uscire \n"&#41;;

    &#125;
    if&#40;latch.uiMake & PSP_CTRL_TRIANGLE&#41;
    &#123;
        sceIoRemove&#40;"flash0&#58;/dic"&#41;;
        printf&#40;"\nFatto\n"&#41;;
this is the main function of my homebrew. Now I want to delete some things from flash0: Why do this code not work? I've seen many post where there weren't these problems: I've red them, I've corrected the code but it doesn't work... why?
blu_eye4
Posts: 37
Joined: Sun Oct 26, 2008 8:41 pm

Post by blu_eye4 »

blu_eye4 wrote:
Torch wrote:

Code: Select all

	SceCtrlLatch latch;
	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_DIGITAL&#41;;
	
	for&#40;;;&#41;
	&#123;
		sceCtrlReadLatch&#40;&latch&#41;;
		if &#40;latch.uiMake & PSP_CTRL_CROSS&#41;
		&#123;
			....
		&#125;
	&#125;
uiMake is on first press only. uiBreak is on release.

All other statements are unnecessary.
Thanks a lot, now all work!!
Can you resolve this problem also?

Code: Select all

int main&#40;void&#41;
&#123;
    sceIoUnassign&#40;"flash0&#58;"&#41;;
    sceIoAssign&#40;"flash0&#58;", "lflash0&#58;0,0", "flashfat0&#58;", IOASSIGN_RDWR, NULL, 0&#41;;
    SceCtrlData pad;
    SceCtrlLatch latch;
    int sceCtrlReadLatch&#40;SceCtrlLatch *latch&#41;;
    pspDebugScreenInit&#40;&#41;;
    pspDebugScreenClear&#40;&#41;;
    SetupCallbacks&#40;&#41;;
    printf&#40;"DumperXflash v. 1,0 by blu_eye4\n"&#41;;
    printf&#40;"Ringrazio Dark_alex per il cf, ps2dev.org per il supporto così come psp-ita.com\n"&#41;;
    printf&#40;"Grazie a tyrannid per is suoi esempi del SDK\n"&#41;;
    printf&#40;"premere O per dump flash 1\n"&#41;;
    printf&#40;"premere &#91;&#93; per dump flash 0\n"&#41;;
    printf&#40;"premere triangolo per eliminare la cartella dic dalla flash0\n"&#41;;
    printf&#40;"premere HOME per uscire senza effettuare alcuna operazione\n"&#41;;

    for&#40;;;&#41;&#123;
            sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
            sceCtrlReadLatch&#40;&latch&#41;;
    if&#40;latch.uiMake & PSP_CTRL_CIRCLE&#41;
    &#123;
            dump_filesystem&#40;"flash1&#58;/", "ms0&#58;/flash1"&#41;;
			pspDebugScreenClear&#40;&#41;;
            printf&#40;"\n\nFatto\n\n"&#41;;
            printf&#40;"premere O per dump flash 1\n"&#41;;
            printf&#40;"premere &#91;&#93; per dump flash 0\n"&#41;;
            printf&#40;"premere HOME per uscire\n"&#41;;
    &#125;
    if&#40;latch.uiMake & PSP_CTRL_SQUARE&#41;
    &#123;
        dump_filesystem&#40;"flash0&#58;/", "ms0&#58;/flash0"&#41;;
        pspDebugScreenClear&#40;&#41;;
        printf&#40;"\n\nFatto\n\n"&#41;;
        printf&#40;"premere O per dump flash 1\n"&#41;;
        printf&#40;"premere &#91;&#93; per dump flash 0\n"&#41;;
        printf&#40;"premere HOME per uscire \n"&#41;;

    &#125;
    if&#40;latch.uiMake & PSP_CTRL_TRIANGLE&#41;
    &#123;
        sceIoRemove&#40;"flash0&#58;/dic"&#41;;
        printf&#40;"\nFatto\n"&#41;;
&#125;
&#125;
this is the main function of my homebrew. Now I want to delete some things from flash0: Why do this code not work? I've seen many post where there weren't these problems: I've red them, I've corrected the code but it doesn't work... why?
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Remove the
SceCtrlData pad;
and
sceCtrlReadBufferPositive(&pad, 1);
Its not needed.

You need to make your program as VSH mode like this with 0x800 flag.
PSP_MODULE_INFO("TestApp", 0x800, 1, 0);
blu_eye4
Posts: 37
Joined: Sun Oct 26, 2008 8:41 pm

Post by blu_eye4 »

Torch wrote:Remove the
SceCtrlData pad;
and
sceCtrlReadBufferPositive(&pad, 1);
Its not needed.

You need to make your program as VSH mode like this with 0x800 flag.
PSP_MODULE_INFO("TestApp", 0x800, 1, 0);

Code: Select all

#include "pspkern.h"
#include <pspkernel.h>
#include <pspiofilemgr.h>
#include <pspctrl.h>
#include "dump.h"
#include <psppower.h>
#include <pspumd.h>
#include <pspdisplay.h>


PSP_MODULE_INFO&#40;"DumperXflash", 0x800, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_VSH&#41;;
#define printf pspDebugScreenPrintf



int sceIoRead&#40;SceUID fd, void *data, SceSize size&#41;;
int *getcwd&#40;char *buffer, size_t length&#41;;
int sceDisplayWaitVblankStart&#40;&#41;;
int sceIoMkdir&#40;const char *dir, SceMode mode&#41;;
int sceIoRemove&#40;const char *file&#41;;
int sceIoRmdir&#40;const char *path&#41;;
int main&#40;void&#41;
&#123;
    sceIoUnassign&#40;"flash0&#58;"&#41;;
    sceIoAssign&#40;"flash0&#58;", "lflash0&#58;0,0", "flashfat0&#58;", IOASSIGN_RDWR, NULL, 0&#41;;
    SceCtrlLatch latch;
    int sceCtrlReadLatch&#40;SceCtrlLatch *latch&#41;;
    pspDebugScreenInit&#40;&#41;;
    pspDebugScreenClear&#40;&#41;;
    SetupCallbacks&#40;&#41;;
    printf&#40;"DumperXflash v. 1,0 by blu_eye4\n"&#41;;
    printf&#40;"Ringrazio Dark_alex per il cf, ps2dev.org per il supporto così come psp-ita.com\n"&#41;;
    printf&#40;"Grazie a tyrannid per is suoi esempi del SDK\n"&#41;;
    printf&#40;"premere O per dump flash 1\n"&#41;;
    printf&#40;"premere &#91;&#93; per dump flash 0\n"&#41;;
    printf&#40;"premere triangolo per eliminare il file config.se dalla flash1\n"&#41;;
    printf&#40;"premere HOME per uscire senza effettuare alcuna operazione\n"&#41;;

    for&#40;;;&#41;&#123;
            sceCtrlReadLatch&#40;&latch&#41;;
    if&#40;latch.uiMake & PSP_CTRL_CIRCLE&#41;
    &#123;
            dump_filesystem&#40;"flash1&#58;/", "ms0&#58;/flash1"&#41;;
			pspDebugScreenClear&#40;&#41;;
            printf&#40;"\n\nFatto\n\n"&#41;;
            printf&#40;"premere O per dump flash 1\n"&#41;;
            printf&#40;"premere &#91;&#93; per dump flash 0\n"&#41;;
            printf&#40;"premere HOME per uscire\n"&#41;;
    &#125;
    if&#40;latch.uiMake & PSP_CTRL_SQUARE&#41;
    &#123;
        dump_filesystem&#40;"flash0&#58;/", "ms0&#58;/flash0"&#41;;
        pspDebugScreenClear&#40;&#41;;
        printf&#40;"\n\nFatto\n\n"&#41;;
        printf&#40;"premere O per dump flash 1\n"&#41;;
        printf&#40;"premere &#91;&#93; per dump flash 0\n"&#41;;
        printf&#40;"premere HOME per uscire \n"&#41;;

    &#125;
    if&#40;latch.uiMake & PSP_CTRL_TRIANGLE&#41;
    &#123;
        sceIoRmdir&#40;"flash0&#58;/dic"&#41;;
        printf&#40;"\nFatto\n"&#41;;
        printf&#40;"premere O per dump flash 1\n"&#41;;
        printf&#40;"premere &#91;&#93; per dump flash 0\n"&#41;;
        printf&#40;"premere HOME per uscire \n"&#41;;
    &#125;
    &#125;

    sceDisplayWaitVblankStart&#40;&#41;;
    return 0;
&#125;
I've understand what I have to do, but my code don't work... why?
And an other thing, availing your balminess, could you tell me how do I do to export the homebrew to kernel 3.xx? You're very aware :) and excuse me for bad english...
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Put BUILD_PRX = 1 in the makefile.
The main program should be either 0x800 mode or 0x0 mode.
blu_eye4
Posts: 37
Joined: Sun Oct 26, 2008 8:41 pm

Post by blu_eye4 »

and for flash problem do you know how I have to do? And the main program is 0x800 mode, what's wrong?
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Look at the return values from the sce functions. See what error codes they are.
Post Reply