forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Some problems with sceCtrlData...

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
blu_eye4



Joined: 26 Oct 2008
Posts: 37

PostPosted: Sun Oct 26, 2008 8:49 pm    Post subject: Some problems with sceCtrlData... Reply with quote

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:
#include "pspkern.h"
#include <pspkernel.h>
#include <pspiofilemgr.h>
#include <pspctrl.h>
#include "dump.h"
#include <psppower.h>

PSP_MODULE_INFO("esercitazione", 0, 1, 0);
#define printf pspDebugScreenPrintf

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

    for(;;){
            sceCtrlReadBufferPositive(&pad, 1);
    if(pad.Buttons != 0){
    if(pad.Buttons & PSP_CTRL_CROSS)
    {
        scePowerSetClockFrequency(100,100,50);
        printf("frequenza attuale cpu: %d mHz\n", scePowerGetCpuClockFrequency());
        printf("frequenza attuale bus: %d mHz\n", scePowerGetBusClockFrequency());
    }
    if(pad.Buttons & PSP_CTRL_CIRCLE)
    {
        dump_memory();
        printf("\n\nFatto\n\n");

    }
    }
    sceDisplayWaitVblankStart();
    return 0;
}
}


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...
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Sun Oct 26, 2008 10:58 pm    Post subject: Reply with quote

return 0 is inside the for loop :P
Back to top
View user's profile Send private message
blu_eye4



Joined: 26 Oct 2008
Posts: 37

PostPosted: Sun Oct 26, 2008 11:07 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Sun Oct 26, 2008 11:12 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
blu_eye4



Joined: 26 Oct 2008
Posts: 37

PostPosted: Sun Oct 26, 2008 11:50 pm    Post subject: Reply with quote

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:
#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("esercitazione", 0, 1, 0);
#define printf pspDebugScreenPrintf

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

    for(;;){
            sceCtrlReadBufferPositive(&pad, 1);
            sceCtrlReadLatch(&latch);
    if(pad.Buttons != 0){
    if(pad.Buttons & PSP_CTRL_CROSS)
    {
        scePowerSetClockFrequency(100,100,50);
        printf("frequenza attuale cpu: %d mHz\n", scePowerGetCpuClockFrequency());
        printf("frequenza attuale bus: %d mHz\n", scePowerGetBusClockFrequency());
    }
    if(pad.Buttons & PSP_CTRL_CIRCLE)
    {
        dump_memory();
        pspDebugScreenClear();
        printf("\n\nFatto\n\n");
        sceCtrlReadLatch(&latch);

    }
    }

}
   sceDisplayWaitVblankStart();
    return 0;
}


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
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Sun Oct 26, 2008 11:56 pm    Post subject: Reply with quote

Code:
   SceCtrlLatch latch;
   sceCtrlSetSamplingCycle(0);
   sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);
   
   for(;;)
   {
      sceCtrlReadLatch(&latch);
      if (latch.uiMake & PSP_CTRL_CROSS)
      {
         ....
      }
   }

uiMake is on first press only. uiBreak is on release.

All other statements are unnecessary.
Back to top
View user's profile Send private message
blu_eye4



Joined: 26 Oct 2008
Posts: 37

PostPosted: Mon Oct 27, 2008 7:05 am    Post subject: Reply with quote

Torch wrote:
Code:
   SceCtrlLatch latch;
   sceCtrlSetSamplingCycle(0);
   sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);
   
   for(;;)
   {
      sceCtrlReadLatch(&latch);
      if (latch.uiMake & PSP_CTRL_CROSS)
      {
         ....
      }
   }

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:
int main(void)
{
    sceIoUnassign("flash0:");
    sceIoAssign("flash0:", "lflash0:0,0", "flashfat0:", IOASSIGN_RDWR, NULL, 0);
    SceCtrlData pad;
    SceCtrlLatch latch;
    int sceCtrlReadLatch(SceCtrlLatch *latch);
    pspDebugScreenInit();
    pspDebugScreenClear();
    SetupCallbacks();
    printf("DumperXflash v. 1,0 by blu_eye4\n");
    printf("Ringrazio Dark_alex per il cf, ps2dev.org per il supporto cosė come psp-ita.com\n");
    printf("Grazie a tyrannid per is suoi esempi del SDK\n");
    printf("premere O per dump flash 1\n");
    printf("premere [] per dump flash 0\n");
    printf("premere triangolo per eliminare la cartella dic dalla flash0\n");
    printf("premere HOME per uscire senza effettuare alcuna operazione\n");

    for(;;){
            sceCtrlReadBufferPositive(&pad, 1);
            sceCtrlReadLatch(&latch);
    if(latch.uiMake & PSP_CTRL_CIRCLE)
    {
            dump_filesystem("flash1:/", "ms0:/flash1");
         pspDebugScreenClear();
            printf("\n\nFatto\n\n");
            printf("premere O per dump flash 1\n");
            printf("premere [] per dump flash 0\n");
            printf("premere HOME per uscire\n");
    }
    if(latch.uiMake & PSP_CTRL_SQUARE)
    {
        dump_filesystem("flash0:/", "ms0:/flash0");
        pspDebugScreenClear();
        printf("\n\nFatto\n\n");
        printf("premere O per dump flash 1\n");
        printf("premere [] per dump flash 0\n");
        printf("premere HOME per uscire \n");

    }
    if(latch.uiMake & PSP_CTRL_TRIANGLE)
    {
        sceIoRemove("flash0:/dic");
        printf("\nFatto\n");


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?
Back to top
View user's profile Send private message
blu_eye4



Joined: 26 Oct 2008
Posts: 37

PostPosted: Mon Oct 27, 2008 7:06 am    Post subject: Reply with quote

blu_eye4 wrote:
Torch wrote:
Code:
   SceCtrlLatch latch;
   sceCtrlSetSamplingCycle(0);
   sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);
   
   for(;;)
   {
      sceCtrlReadLatch(&latch);
      if (latch.uiMake & PSP_CTRL_CROSS)
      {
         ....
      }
   }

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:
int main(void)
{
    sceIoUnassign("flash0:");
    sceIoAssign("flash0:", "lflash0:0,0", "flashfat0:", IOASSIGN_RDWR, NULL, 0);
    SceCtrlData pad;
    SceCtrlLatch latch;
    int sceCtrlReadLatch(SceCtrlLatch *latch);
    pspDebugScreenInit();
    pspDebugScreenClear();
    SetupCallbacks();
    printf("DumperXflash v. 1,0 by blu_eye4\n");
    printf("Ringrazio Dark_alex per il cf, ps2dev.org per il supporto cosė come psp-ita.com\n");
    printf("Grazie a tyrannid per is suoi esempi del SDK\n");
    printf("premere O per dump flash 1\n");
    printf("premere [] per dump flash 0\n");
    printf("premere triangolo per eliminare la cartella dic dalla flash0\n");
    printf("premere HOME per uscire senza effettuare alcuna operazione\n");

    for(;;){
            sceCtrlReadBufferPositive(&pad, 1);
            sceCtrlReadLatch(&latch);
    if(latch.uiMake & PSP_CTRL_CIRCLE)
    {
            dump_filesystem("flash1:/", "ms0:/flash1");
         pspDebugScreenClear();
            printf("\n\nFatto\n\n");
            printf("premere O per dump flash 1\n");
            printf("premere [] per dump flash 0\n");
            printf("premere HOME per uscire\n");
    }
    if(latch.uiMake & PSP_CTRL_SQUARE)
    {
        dump_filesystem("flash0:/", "ms0:/flash0");
        pspDebugScreenClear();
        printf("\n\nFatto\n\n");
        printf("premere O per dump flash 1\n");
        printf("premere [] per dump flash 0\n");
        printf("premere HOME per uscire \n");

    }
    if(latch.uiMake & PSP_CTRL_TRIANGLE)
    {
        sceIoRemove("flash0:/dic");
        printf("\nFatto\n");
}
}


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?
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Mon Oct 27, 2008 11:29 am    Post subject: Reply with quote

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);
Back to top
View user's profile Send private message
blu_eye4



Joined: 26 Oct 2008
Posts: 37

PostPosted: Tue Oct 28, 2008 1:55 am    Post subject: Reply with quote

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:
#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("DumperXflash", 0x800, 1, 0);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_VSH);
#define printf pspDebugScreenPrintf



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

    for(;;){
            sceCtrlReadLatch(&latch);
    if(latch.uiMake & PSP_CTRL_CIRCLE)
    {
            dump_filesystem("flash1:/", "ms0:/flash1");
         pspDebugScreenClear();
            printf("\n\nFatto\n\n");
            printf("premere O per dump flash 1\n");
            printf("premere [] per dump flash 0\n");
            printf("premere HOME per uscire\n");
    }
    if(latch.uiMake & PSP_CTRL_SQUARE)
    {
        dump_filesystem("flash0:/", "ms0:/flash0");
        pspDebugScreenClear();
        printf("\n\nFatto\n\n");
        printf("premere O per dump flash 1\n");
        printf("premere [] per dump flash 0\n");
        printf("premere HOME per uscire \n");

    }
    if(latch.uiMake & PSP_CTRL_TRIANGLE)
    {
        sceIoRmdir("flash0:/dic");
        printf("\nFatto\n");
        printf("premere O per dump flash 1\n");
        printf("premere [] per dump flash 0\n");
        printf("premere HOME per uscire \n");
    }
    }

    sceDisplayWaitVblankStart();
    return 0;
}
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...
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Tue Oct 28, 2008 2:07 am    Post subject: Reply with quote

Put BUILD_PRX = 1 in the makefile.
The main program should be either 0x800 mode or 0x0 mode.
Back to top
View user's profile Send private message
blu_eye4



Joined: 26 Oct 2008
Posts: 37

PostPosted: Tue Oct 28, 2008 2:56 am    Post subject: Reply with quote

and for flash problem do you know how I have to do? And the main program is 0x800 mode, what's wrong?
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Tue Oct 28, 2008 3:03 am    Post subject: Reply with quote

Look at the return values from the sce functions. See what error codes they are.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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