Seite 338 von 340 ErsteErste ... 238 288 328 329 330 331 332 333 334 335 336 337 338 339 340 LetzteLetzte
Zeige Ergebnis 10.111 bis 10.140 von 10174

C/C++ Programming Help Thread

This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; No no no. The step function contains all of the pad if statements. //player.cpp Step(){ if (main.cpp.pad.Buttons & PSP_CTRL_WHATEVER) { ...

  
  1. #10111
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    No no no.
    The step function contains all of the pad if statements.

    //player.cpp
    Step(){

    if (main.cpp.pad.Buttons & PSP_CTRL_WHATEVER)
    {
    doSomething();
    }

    }

    I don't want to make a new instance of SceCtrlData in my player.cpp though, I simply want to access it from main.cpp
    It will also help me to do other things.

    Such as get values like the time in the game, the score in the game, and use conditions based on those (the values in main.cpp)

    Example:
    player.cpp:

    if(main.cpp.score > 100){
    lives++;
    }



  2. #10112
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Beat_Bob - That's just it. It'd be best to do a little re-designing and move the if statements and the SceCtrlPad pad and all that stuff to the main source file but leave what you want to happen in those functions. For example:
    Code:
    // player.h
    class player
    {
      int lives;
      int x;
    
      void Step(){
        x = x + 1;
      }
      void addLife(){
        lives++;
      }
      void loseLife(){
        lives--;
      }
    };
    
    
    
    // main.cpp
    SceCtrlData pad;
    
    if (score > 100){
      player.addLife();
    }
    
    if (pad.Buttons & PSP_CTRL_LEFT){
      player.Step();
    }
    Now you can do what you want.

    Basically let the main.cpp interact with player.h/cpp using functions.

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  3. #10113
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    Okay thanks, however I'm confused why you are defining functions in player.h
    Aren't functions defined in player.cpp?

    Also, I'm simply trying to move the player left, right, up and down, however my screen appears black:
    http://codepad.org/dy5DFcOl

    I draw 2 images:
    a background
    a resized (32x32) image of the background, posing as my player

    But now my screen appears blank.
    I simply want that "resized image" (player) to go left right up or down when I press the corresponding button on my PSP.
    However I see nothing on the screen. (its black)

    I don't think it crashed because I can use the home button still and exit back to the XMB.
    Geändert von Beat_Bob (04-17-2010 um 11:44 AM Uhr)

  4. #10114
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    that's because your not flipping the screen during the main loop, it doesn't magically flip if you don't tell it to flip, you have to put the flipScreen at the bottom of the loop
    1. Failed....again...
    2. http://slicer.gibbocool.com/ stay updated on all my projects
    3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been

  5. #10115
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    I did that, and now I can see black lines running down my background.
    And when I press LEFT RIGHT UP or DOWN, my player doesn't move.
    C++ code - 55 lines - codepad

  6. #10116
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Beat_Bob - Assuming your background image is 480x272, you need to draw that every frame. You aren't using 'Color c' so you don't need that line. You don't need to call 'flipScreen' outside your while(1) loop anywhere so get rid of the one at the bottom. Make sure in your player class you are initializing the X and Y members to 0 or something else it could be drawn anywhere.

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  7. #10117
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    All right well no black lines across the screen now.
    However, my player still refuses to move:

    C code - 54 lines - codepad

    x and y are initialized at 20.
    Geändert von Beat_Bob (04-18-2010 um 12:12 PM Uhr)

  8. #10118
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Get rid of #include <pspdebug.h>
    You only need to 'extern "C" { }' the graphics.h, not all of them.
    Get rid of pspDebugScreenInit.
    Get rid of sceKernelSleepThread.
    Get rid of 'if (myPlayer.x > 50) { done = true; }'.

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  9. #10119
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    Here's the new code:
    C++ code - 80 lines - codepad

    However my player still fails to move when I press a directional button.

  10. #10120
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Oh duhhhh you aren't polling for input you silly goose.

    Add this to the beginning of your while loop:
    Code:
    sceCtrlReadBufferPositive(&pad, 1);

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  11. #10121
    QJ Gamer Green
    Points: 2.003, Level: 27
    Level completed: 2%, Points required for next Level: 147
    Overall activity: 0%

    Registriert seit
    Jun 2009
    Beiträge
    61
    Points
    2.003
    Level
    27
    Downloads
    0
    Uploads
    0

    Standard

    I was trying a filebrowser function out of some1 and i can compile it but when I try it on my psp it gives a blackscreen...I think there's something wrong with my folder.


    Spoiler for filebrowser.c:
    #include "file_browser.h"

    #include <pspctrl.h>
    #include <string.h>
    #include <malloc.h>
    #include <stdio.h>
    #include <pspdisplay.h>
    #include <pspkernel.h>

    #define PAGE_SIZE 31

    // recacheGameDir() by Anonymous tipster
    // game directory display
    struct GameEntry
    {
    char *name;
    };

    int gameEntriesTotal = 0;
    int gameDirSelected = 0;

    char current_dir[200] = "ms0:/PSP/GAME/";

    #define MAX_ENTRIES 1000

    struct GameEntry gameEntry[MAX_ENTRIES];

    void recacheGameDir()
    {
    struct SceIoDirent dir;
    memset( &dir, 0, sizeof(SceIoDirent));
    pspDebugScreenSetXY( 0, 6);

    static int dfd;
    dfd = sceIoDopen(current_dir);

    if(dfd > 0)
    {
    int f = 0;
    for( f = 0; f < MAX_ENTRIES; f++)
    {
    if( gameEntry[f].name)
    {
    free( gameEntry[f].name);
    }
    gameEntry[f].name = NULL;
    }
    int count = 0;
    count = 0;

    while( sceIoDread( dfd, &dir) > 0)
    {
    static char * name;
    name = (char*)memalign( 16, 300);
    sprintf( name,"%s" , dir.d_name);
    static int s = 0;
    s = strlen(name);

    gameEntry[count].name = name;
    count++;

    if(count > MAX_ENTRIES - 1)
    {
    count = MAX_ENTRIES - 1;
    }

    gameEntriesTotal = count;
    if(gameEntriesTotal < 0)
    {
    gameEntriesTotal = 0;
    }
    }
    }
    sceIoDclose(dfd);
    }

    int is_file( const char *filename)
    {
    SceIoStat stats;
    sceIoGetstat( filename, &stats);

    if ( stats.st_mode & FIO_S_IFDIR)
    return 0;
    else
    return 1;
    }


    char* file_browser( const char* initial_dir)
    {
    char* selection = NULL;

    pspDebugScreenClear();
    int browsing = 1;
    int current_selection = 0;

    int current_page = 0;
    int last_page = 0;

    SceCtrlData current_pad;
    SceCtrlData last_pad;

    sceCtrlPeekBufferPositive (&last_pad, 1);

    if( initial_dir != NULL)
    {
    strcpy(current_dir, initial_dir);
    }

    recacheGameDir();

    while(browsing)
    {
    pspDebugScreenSetXY(0,0);

    int min = 0;
    int i = 0;

    current_page = current_selection / PAGE_SIZE;

    if( current_page != last_page)
    {
    pspDebugScreenClear();
    }

    min = PAGE_SIZE * current_page;;

    pspDebugScreenPrintf("Cur rent Directory: %s\nPage Number: %d\n\n", current_dir, current_page);
    for( i = min; ((i < gameEntriesTotal) && (i < (min + PAGE_SIZE))); i++)
    {
    if( i != current_selection)
    {
    pspDebugScreenPrintf("%d: %s\n", i, gameEntry[i].name);
    }
    else
    {
    pspDebugScreenPrintf("%d: %s <-\n", i, gameEntry[i].name);
    }
    }
    last_page = current_page;

    sceCtrlPeekBufferPositive (&current_pad, 1);

    if(last_pad.Buttons != current_pad.Buttons)
    {
    last_pad = current_pad;

    if( (current_pad.Buttons & PSP_CTRL_DOWN) && (current_pad.Buttons & PSP_CTRL_SQUARE))
    {
    if( gameEntriesTotal > PAGE_SIZE)
    {
    current_selection += PAGE_SIZE;

    if( current_selection > gameEntriesTotal)
    {
    current_selection = gameEntriesTotal-1;
    }
    }
    }
    else if( current_pad.Buttons & PSP_CTRL_DOWN)
    {
    current_selection++;
    if( current_selection >= gameEntriesTotal)
    {
    current_selection = 0;
    }
    }

    if( (current_pad.Buttons & PSP_CTRL_UP) && (current_pad.Buttons & PSP_CTRL_SQUARE))
    {
    if( gameEntriesTotal > PAGE_SIZE)
    {
    current_selection -= PAGE_SIZE;

    if( current_selection < 0)
    {
    current_selection = 0;
    }
    }
    }
    else if( current_pad.Buttons & PSP_CTRL_UP)
    {
    current_selection--;
    if( current_selection < 0)
    {
    current_selection = gameEntriesTotal - 1;
    }
    }

    if( current_pad.Buttons & PSP_CTRL_CIRCLE)
    {
    char temp[200];

    int i = 0;
    int max = strlen( current_dir);
    int dir_no = 0;
    while( (i < max))
    {
    if( current_dir[i] == '/')
    {
    dir_no++;
    }
    i++;
    }
    if( dir_no > 1)
    {
    char * temp2 = strtok( current_dir, "/");
    strcpy( temp, temp2);
    strcat( temp, "/");
    i = 2;
    while( (i < dir_no))
    {
    temp2 = strtok( NULL, "/");
    strcat( temp, temp2);
    strcat( temp, "/");
    i++;
    }
    strcpy( current_dir, temp);
    }
    pspDebugScreenClear();
    recacheGameDir();
    current_selection = 0;

    }

    if( current_pad.Buttons & PSP_CTRL_CROSS)
    {
    char temp[200];
    strcpy( temp, current_dir);
    if( strcmp( ".", gameEntry[current_selection].name) != 0 && strcmp( "..", gameEntry[current_selection].name) != 0)
    {
    strcat( temp, gameEntry[current_selection].name);
    if( is_file(temp))
    {
    selection = (char*)malloc( sizeof(temp));
    strcpy( selection, temp);
    browsing = 0;
    }
    else
    {
    current_selection = 0;
    strcpy( current_dir, temp);
    strcat( current_dir, "/");
    pspDebugScreenClear();
    recacheGameDir();
    current_selection = 0;
    }
    }
    else if( strcmp( ".", gameEntry[current_selection].name) == 0)
    {
    sprintf( current_dir, "%s", "ms0:/");
    pspDebugScreenClear();
    recacheGameDir();
    current_selection = 0;
    }
    else if( strcmp( "..", gameEntry[current_selection].name) == 0)
    {
    int i = 0;
    int max = strlen( current_dir);
    int dir_no = 0;
    while( (i < max))
    {
    if( current_dir[i] == '/')
    {
    dir_no++;
    }
    i++;
    }
    if( dir_no > 1)
    {
    char * temp2 = strtok( current_dir, "/");
    strcpy( temp, temp2);
    strcat( temp, "/");
    i = 2;
    while( (i < dir_no))
    {
    temp2 = strtok( NULL, "/");
    strcat( temp, temp2);
    strcat( temp, "/");
    i++;
    }
    strcpy( current_dir, temp);
    }
    pspDebugScreenClear();
    recacheGameDir();
    current_selection = 0;
    }
    }
    }
    sceDisplayWaitVblankStart ();
    }
    pspDebugScreenClear();

    return selection;
    }


    Spoiler for Main.c:
    #include "file_browser.h"
    #include <pspctrl.h>
    #include <string.h>
    #include <malloc.h>
    #include <stdio.h>
    #include <pspdisplay.h>
    #include <pspkernel.h>


    #define PAGE_SIZE 31



    int main(int argc, char *argv[])
    {
    pspDebugScreenInit();
    SceCtrlData pad;
    sceCtrlReadBufferPositive (&pad, 1);


    file_browser(argv[0]);//some1 told me that if I use this it would use the folder of the EBOOT.PBP

    return 0;
    }
    Geändert von LegendMythe (04-18-2010 um 02:18 AM Uhr)

  12. #10122
    QJ Gamer Gold
    Points: 13.372, Level: 75
    Level completed: 31%, Points required for next Level: 278
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    CAD
    Beiträge
    693
    Points
    13.372
    Level
    75
    Downloads
    19
    Uploads
    4

    Standard

    Zitat Zitat von LegendMythe Beitrag anzeigen
    file_browser(argv[0]);//some1 told me that if I use this it would use the folder of the EBOOT.PBP
    Bullcrap, if you want your browser to brwse the argv, then it has to be specified from an external EBOOT (or module) at launching point.
    That epic dude.

  13. #10123
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    Wow, it still refuses to work???
    C++ code - 56 lines - codepad

  14. #10124
    QJ Gamer Gold
    Points: 13.372, Level: 75
    Level completed: 31%, Points required for next Level: 278
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    CAD
    Beiträge
    693
    Points
    13.372
    Level
    75
    Downloads
    19
    Uploads
    4

    Standard

    Well, I don't see why your using booleans in your code, I would remove "bool done = false;" and replace "while(!done) {" with "while(1) {".
    And it's probably a problem with your class, try using static integral values instead of those that are in your class, then see if it works.
    That epic dude.

  15. #10125
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    Not sure what you mean.
    However I instantialized the x and y int's at 20, and that is indeed where it starts.
    So.....why wouldn't it be updating?

    Here's my main and my player class:
    C++ code - 80 lines - codepad

  16. #10126
    QJ Gamer Gold
    Points: 13.372, Level: 75
    Level completed: 31%, Points required for next Level: 278
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    CAD
    Beiträge
    693
    Points
    13.372
    Level
    75
    Downloads
    19
    Uploads
    4

    Standard

    Well, this is how I would do it:
    Spoiler for main.cpp:
    Code:
    #include <pspkernel.h>
    #include <pspctrl.h>
    #include <pspdisplay.h>
    #include "player.h"
    
    PSP_MODULE_INFO("Image Movement", PSP_MODULE_USER, 1, 1);
    
    void player::Step(int a)
    {
    	if(a == -1) x = x; y = y;
    	else if(a == 0) x -= 1;
    	else if(a == 1) x += 1;
    }
    
    int main(void)
    {
    	initGraphics();
    	SceCtrlData pad;
    	player myPlayer;
    	Image *bg = loadImage("back.png");
    	
    	while(1) {
    		sceCtrlReadBufferPositive(&pad, 1);
    		if(pad.Buttons & PSP_CTRL_HOME) sceKernelExitGame();
    		
    		blitAlphaImageToScreen(0, 0, bg->imageWidth, bg->imageHeight, bg, 0, 0);
    		if(pad.Buttons & PSP_CTRL_RIGHT) myPlayer.x++;
    		else if(pad.Buttons & PSP_CTRL_LEFT) myPlayer.x--;
    		else if(pad.Buttons & PSP_CTRL_DOWN) myPlayer.y++;
    		else if(pad.Buttons & PSP_CTRL_UP) myPlayer.y--;
    		if(myPlayer.x > 50) break;
    		blitAlphaImageToScreen(0, 0, 32, 32, bg, myPlayer.x, myPlayer.y);
    		
    		sceDisplayWaitVblankStart();
    		flipScreen();
    	}
    	
    	freeImage(bg);
    	sceKernelSleepThread();
    	return 0;
    }

    Spoiler for player.h:

    Code:
    #ifndef player_h
    #define player_h
    
    #include <psptypes.h>
    
    class player {
    	public:
    	player() : x(20), y(20) {}
    	void Step(int a);
    
    	private:
    	int x, y;
    };
    
    #endif

    But if I were you, I would first learn C, then C++, then pass on to the PSPSDK instead of skipping to the big stuff.
    That epic dude.

  17. #10127
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    But what was wrong with my code though?

  18. #10128
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    moot, it's a good idea to have the primary while loop based off a variable, and not that you would force a break(i.e, what sg suggested with the 3 function's carrying out I/P/O, if i detect an end in P, i still want it to output my data)

    @beat hmm, can you clearly see the player is at 20,20 when u start?, since he's a small part of your background image, idk what your background image is, rather it's unique for the 32x32 in the top left, or what, but my suggestion would be to use an entirely different image for the player, or simply use a fillRect for now to be in place of the player

    otherwise i don't see a problem in that code, input is being handled, the class's x/y is public, so everything should be legal as far as what your doing, and your flipping the screen at the bottom of the loop

    @legend, that is alot of unformatted code to be trying to read through, could you please clean it up and i'll see if i can see what's wrong, also to what moot quoted you on, using "./" should use the relative folder that the eboot is in, argv[0] would just return EBOOT.PBP, which is pointless for what your doing since it's not a folder path, but a filename, really there's not much reason imo to pull the argv's, unless your doing what moot said you'd have to do(launch it from a different eboot, and pass the parameters in)
    1. Failed....again...
    2. http://slicer.gibbocool.com/ stay updated on all my projects
    3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been

  19. #10129
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    Yes I can see that he is indeed at 20,20.
    I can clearly see the image.

    Also when I printf("%i",myPlayer.x);
    It shows 20.

    Again here is my entire code:
    http://codepad.org/jzANAH8j
    Geändert von Beat_Bob (04-18-2010 um 12:13 PM Uhr)

  20. #10130
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    hmm, beat, place that printf in the loop to draw with the rest of your stuff, and see if the value does change as you press buttons
    1. Failed....again...
    2. http://slicer.gibbocool.com/ stay updated on all my projects
    3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been

  21. #10131
    QJ Gamer Green
    Points: 3.606, Level: 37
    Level completed: 71%, Points required for next Level: 44
    Overall activity: 99,0%

    Registriert seit
    Jul 2007
    Beiträge
    88
    Points
    3.606
    Level
    37
    Downloads
    0
    Uploads
    0

    Standard

    Well I honestly don't know what I did but it seems to be working now!
    Thanks for all the help!
    Geändert von Beat_Bob (04-18-2010 um 10:37 PM Uhr)

  22. #10132
    QJ Gamer Silver
    Points: 8.475, Level: 62
    Level completed: 9%, Points required for next Level: 275
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Perth, Scotland
    Beiträge
    1.094
    Points
    8.475
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Beat_Bob Beitrag anzeigen
    Well I honestly don't know what I did but it seems to be working now!
    Thanks for all the help!
    Maybe thats why you should study the language and programming first ;)

  23. #10133
    QJ Gamer Green
    Points: 2.003, Level: 27
    Level completed: 2%, Points required for next Level: 147
    Overall activity: 0%

    Registriert seit
    Jun 2009
    Beiträge
    61
    Points
    2.003
    Level
    27
    Downloads
    0
    Uploads
    0

    Standard

    I using the code to dump the flash0 and 1 from the samples folder in the SDK of PSPMINI but it only makes a folder but doesn't write in the folder so I tough I'll use the original one (wich has error codes) and there came some error codes on my psp screen that he couldn't open the folders to dump.
    what I also noticed was that it's in usersmode and i always tough to read/write nand you should be in Kernelmode, am i wrong or is the sample wrong?or is my psp jut messed up :)?

    here's the original sample code:
    Spoiler for main.c:
    /*
    * PSP Software Development Kit - http://www.pspdev.org
    * -----------------------------------------------------------------------
    * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
    *
    * main.c - Basic sample to demonstrate some fileio functionality.
    *
    * Copyright (c) 2005 Marcus R. Brown <[email protected]>
    * Copyright (c) 2005 James Forshaw <[email protected]>
    * Copyright (c) 2005 John Kelley <[email protected]>
    *
    * $Id: main.c 2389 2008-05-24 17:42:11Z iwn $
    */
    #include <pspkernel.h>
    #include <pspctrl.h>
    #include <pspdebug.h>
    #include <pspdisplay.h>
    #include <pspumd.h>

    #include <string.h>

    PSP_MODULE_INFO("Dumper", 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);
    sceKernelRegisterExitCall back(cbid);

    sceKernelSleepThreadCB();

    return 0;
    }

    /* Sets up the callback thread and returns its thread id */
    int SetupCallbacks(void)
    {
    int thid = 0;

    thid = sceKernelCreateThread("up date_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 DumpBootBin(void)
    {
    int i;
    int fd;

    i = sceUmdCheckMedium();
    if(i == 0)
    {
    printf("Insert UMD\n");
    i = sceUmdWaitDriveStat(PSP_U MD_PRESENT);
    }

    i = sceUmdActivate(1, "disc0:");
    printf("Mounted disc\n");

    i = sceUmdWaitDriveStat(PSP_U MD_READY);

    /* Open the UMD_DATA.BIN */
    fd = sceIoOpen("disc0:/UMD_DATA.BIN", PSP_O_RDONLY, 0777);
    if(fd >= 0)
    {
    char game_id[11];
    char path[256];

    sceIoRead(fd, game_id, 10);
    sceIoClose(fd);
    game_id[10] = 0;
    build_path(path, "ms0:/", game_id, 0);
    sceIoMkdir(path, 0777);

    printf("Found game %s\n", game_id);

    write_file("disc0:/PSP_GAME/SYSDIR", path, "BOOT.BIN");
    }
    }

    /* Dump a filing system */
    void dump_filesystem(const char *root, const char *write_loc)
    {
    int dfd;
    char next_root[256];
    char next_write[256];

    sceIoMkdir(write_loc, 0777);

    dfd = sceIoDopen(root);
    if(dfd > 0)
    {
    SceIoDirent dir;

    while(sceIoDread(dfd, &dir) > 0)
    {
    if(dir.d_stat.st_attr & FIO_SO_IFDIR)
    {
    if(dir.d_name[0] != '.')
    {
    build_path(next_write, write_loc, dir.d_name, 0);
    build_path(next_root, root, dir.d_name, 1);
    dump_filesystem(next_root , next_write);
    }
    }
    else
    {
    write_file(root, write_loc, dir.d_name);
    }
    }
    sceIoDclose(dfd);
    }
    }

    /* Dump memory */
    void dump_memory(void)
    {
    int fd;

    printf("Dumping 28Megs from 0x8400000\n");
    fd = sceIoOpen("ms0:/MEMORY.BIN", PSP_O_CREAT | PSP_O_TRUNC | PSP_O_WRONLY, 0777);
    if(fd >= 0)
    {
    sceIoWrite(fd, (void *) 0x8400000, 28*1024*1024);
    sceIoClose(fd);
    }
    }

    /* Dumps flash rom in bits */
    void dump_flashrom(int lower)
    {
    int fdin;
    int fdout;

    fdin = sceIoOpen("lflash:", PSP_O_RDONLY, 0777);
    if(fdin > 0)
    {
    int i;
    int bytes_read;

    if(lower)
    {
    fdout = sceIoOpen("ms0:/flash_lower.bin", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
    }
    else
    {
    fdout = sceIoOpen("ms0:/flash_upper.bin", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
    }

    if(fdout > 0)
    {
    for(i = 0; i < ((16 * 1024 * 1024) / sizeof(write_buffer)); i++)
    {
    bytes_read = sceIoRead(fdin, write_buffer, sizeof(write_buffer));
    if(lower)
    {
    sceIoWrite(fdout, write_buffer, bytes_read);
    }
    }

    if(!lower)
    {
    for(i = 0; i < ((16 * 1024 * 1024) / sizeof(write_buffer)); i++)
    {
    bytes_read = sceIoRead(fdin, write_buffer, sizeof(write_buffer));
    sceIoWrite(fdout, write_buffer, bytes_read);
    }
    }

    sceIoClose(fdout);
    }

    sceIoClose(fdin);
    }
    else
    {
    printf("Cannot open lflash: device\n");
    sceKernelSleepThread();
    }
    }

    void show_menu(void)
    {
    printf("PSP Dumping Tool - TyRaNiD 2k5. (www.pspdev.org)\n");
    printf("Press triangle to dump umd boot.bin\n");
    printf("Press circle to dump flash0\n");
    printf("Press square to dump flash1\n");
    printf("Press cross to dump memory\n");
    printf("Press L trigger to dump lower 16Mb of flash rom\n");
    printf("Press R trigger to dump lower 16Mb of flash rom\n");
    }

    int main(void)
    {
    SceCtrlData pad_data;

    pspDebugScreenSetBackColo r(0xFFFFFFFF);
    pspDebugScreenSetTextColo r(0);
    pspDebugScreenInit();
    SetupCallbacks();
    sceCtrlSetSamplingCycle(0 );
    sceCtrlSetSamplingMode(1) ;
    show_menu();

    for(;;)
    {
    sceCtrlReadBufferPositive (&pad_data, 1);
    if(pad_data.Buttons & PSP_CTRL_TRIANGLE)
    {
    DumpBootBin();
    pspDebugScreenClear();
    printf("!!!!!!!! DONE !!!!!!!!!!\n");
    show_menu();
    }

    if(pad_data.Buttons & PSP_CTRL_CIRCLE)
    {
    dump_filesystem("flash0:/", "ms0:/flash0");
    pspDebugScreenClear();
    printf("!!!!!!!! DONE !!!!!!!!!!\n");
    show_menu();
    }

    if(pad_data.Buttons & PSP_CTRL_SQUARE)
    {
    dump_filesystem("flash1:/", "ms0:/flash1");
    pspDebugScreenClear();
    printf("!!!!!!!! DONE !!!!!!!!!!\n");
    show_menu();
    }

    if(pad_data.Buttons & PSP_CTRL_CROSS)
    {
    dump_memory();
    pspDebugScreenClear();
    printf("!!!!!!!! DONE !!!!!!!!!!\n");
    show_menu();
    }

    if(pad_data.Buttons & PSP_CTRL_LTRIGGER)
    {
    dump_flashrom(1);
    pspDebugScreenClear();
    printf("!!!!!!!! DONE !!!!!!!!!!\n");
    show_menu();
    }

    if(pad_data.Buttons & PSP_CTRL_RTRIGGER)
    {
    dump_flashrom(0);
    pspDebugScreenClear();
    printf("!!!!!!!! DONE !!!!!!!!!!\n");
    show_menu();
    }

    sceDisplayWaitVblankStart ();
    }

    return 0;
    }

    Spoiler for makefile:
    TARGET = dumper
    OBJS = main.o

    INCDIR =
    CFLAGS = -O2 -G0 -Wall
    CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
    ASFLAGS = $(CFLAGS)

    LIBDIR =
    LIBS = -lpspumd
    LDFLAGS =

    EXTRA_TARGETS = EBOOT.PBP
    PSP_EBOOT_TITLE = File IO example

    PSPSDK=$(shell psp-config --pspsdk-path)
    include $(PSPSDK)/lib/build.mak

  24. #10134
    Points: 1.030, Level: 17
    Level completed: 30%, Points required for next Level: 70
    Overall activity: 0%
    Achievements:
    First 1000 Experience Points

    Registriert seit
    Jun 2010
    Ort
    Mumbai
    Beiträge
    5
    Points
    1.030
    Level
    17
    Downloads
    0
    Uploads
    0

    Standard hello world

    hey,

    i seem to be having a problem with my first EBOOT.PBP.

    main.c

    Code:
    #include <pspkernel.h>
    #include <pspdebug.h>
    
    #define printf pspDebugScreenPrintf
    
    PSP_MODULE_INFO("hello world", 0, 1, 1);
    PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
    
    /* 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;
    }
    
    int main() {
    	pspDebugScreenInit();
    	SetupCallbacks();
    	
    	printf("Hello world\n");
    	sceKernelSleepThread();
    	
    	return 0;
    	
    }
    Makefile

    Code:
    TARGET = HelloWorld
    OBJS = main.o
    
    INCDIR =
    CFLAGS = -O2 -G0 -Wall
    CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
    ASFLAGS = $(CFLAGS)
    
    LIBDIR =
    LDFLAGS =
    
    EXTRA_TARGETS = EBOOT.PBP
    PSP_EBOOT_TITLE = Hello World
    
    PSPSDK=$(shell psp-config --pspsdk-path)
    include $(PSPSDK)/lib/build.mak
    the program compiles fine, and i get the EBOOT.PBP.
    the EBOOT.PBP shows up in the XMB, but after the PSP logo i get a black screen for 15 seconds and the psp goes off...

    my psp is version 5.00 m33-6.
    i'm running the psp in 1.50 kernel mode, and i put the EBOOT.PBP in the following path:
    /PSP/GAME/hello/EBOOT.PBP

    other homebrew apps like gpsp and snes work fine.

    any solution?

  25. #10135
    Developer
    Points: 8.092, Level: 60
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Jul 2008
    Ort
    Grand Rapids! MI
    Beiträge
    125
    Points
    8.092
    Level
    60
    Downloads
    5
    Uploads
    2

    Standard

    Zitat Zitat von neelsav Beitrag anzeigen
    hey,

    i seem to be having a problem with my first EBOOT.PBP.

    main.c

    Code:
    #include <pspkernel.h>
    #include <pspdebug.h>
    
    #define printf pspDebugScreenPrintf
    
    PSP_MODULE_INFO("hello world", 0, 1, 1);
    PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
    
    /* 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;
    }
    
    int main() {
    	pspDebugScreenInit();
    	SetupCallbacks();
    	
    	printf("Hello world\n");
    	sceKernelSleepThread();
    	
    	return 0;
    	
    }
    Makefile

    Code:
    TARGET = HelloWorld
    OBJS = main.o
    
    INCDIR =
    CFLAGS = -O2 -G0 -Wall
    CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
    ASFLAGS = $(CFLAGS)
    
    LIBDIR =
    LDFLAGS =
    
    EXTRA_TARGETS = EBOOT.PBP
    PSP_EBOOT_TITLE = Hello World
    
    PSPSDK=$(shell psp-config --pspsdk-path)
    include $(PSPSDK)/lib/build.mak
    the program compiles fine, and i get the EBOOT.PBP.
    the EBOOT.PBP shows up in the XMB, but after the PSP logo i get a black screen for 15 seconds and the psp goes off...

    my psp is version 5.00 m33-6.
    i'm running the psp in 1.50 kernel mode, and i put the EBOOT.PBP in the following path:
    /PSP/GAME/hello/EBOOT.PBP

    other homebrew apps like gpsp and snes work fine.

    any solution?
    try just using the 5.00 Kernel (From Rev mode)

  26. #10136
    Points: 1.030, Level: 17
    Level completed: 30%, Points required for next Level: 70
    Overall activity: 0%
    Achievements:
    First 1000 Experience Points

    Registriert seit
    Jun 2010
    Ort
    Mumbai
    Beiträge
    5
    Points
    1.030
    Level
    17
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von lilmnm Beitrag anzeigen
    try just using the 5.00 Kernel (From Rev mode)
    changed it to 5.XX
    still nothing.

    i am using a Macboox to compile the EBOOT.PBP
    could it be a problem with the toolchain that i installed?

  27. #10137
    QJ Gamer Gold
    Points: 13.372, Level: 75
    Level completed: 31%, Points required for next Level: 278
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    CAD
    Beiträge
    693
    Points
    13.372
    Level
    75
    Downloads
    19
    Uploads
    4

    Standard

    I already told you the solution: Help Please :)
    That epic dude.

  28. #10138
    Points: 1.030, Level: 17
    Level completed: 30%, Points required for next Level: 70
    Overall activity: 0%
    Achievements:
    First 1000 Experience Points

    Registriert seit
    Jun 2010
    Ort
    Mumbai
    Beiträge
    5
    Points
    1.030
    Level
    17
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von mootjeuh Beitrag anzeigen
    I already told you the solution:
    i tried changing the main like you told me to, with a loop. still the same thing.
    PSP logo comes, followed by a black screen and then it it goes off.

  29. #10139
    QJ Gamer Gold
    Points: 13.372, Level: 75
    Level completed: 31%, Points required for next Level: 278
    Overall activity: 0%

    Registriert seit
    Nov 2008
    Ort
    CAD
    Beiträge
    693
    Points
    13.372
    Level
    75
    Downloads
    19
    Uploads
    4

    Standard

    Interesting, then their's either something wrong with your PSP or your Mac.
    That epic dude.

  30. #10140
    Developer
    Points: 8.092, Level: 60
    Level completed: 72%, Points required for next Level: 58
    Overall activity: 0%

    Registriert seit
    Jul 2008
    Ort
    Grand Rapids! MI
    Beiträge
    125
    Points
    8.092
    Level
    60
    Downloads
    5
    Uploads
    2

    Standard

    Hey guy dose any one have a way to use libcurl to get it to connect to a server for online updates and what not?

    nvm i found some stuff but ill be back when my n00bness catches up with me lol


 

Tags for this Thread

Forumregeln

  • Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
  • Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
  • Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
  • Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
  •  





Alle Zeitangaben in WEZ -8. Es ist jetzt 09:15 PM Uhr.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © , Caputo Media, LLC. All Rights Reserved. Cluster .