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) { ...
-
04-16-2010, 09:35 PM #10111QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
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++;
}
-
04-16-2010, 10:56 PM #10112words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
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:
Now you can do what you want.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(); }
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
-
04-17-2010, 10:52 AM #10113QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
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)
-
04-17-2010, 02:23 PM #10114QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
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
-
04-17-2010, 04:18 PM #10115QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
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
-
04-17-2010, 08:42 PM #10116words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
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
-
04-17-2010, 09:11 PM #10117QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
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)
-
04-17-2010, 10:00 PM #10118words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
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
-
04-17-2010, 10:31 PM #10119QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Here's the new code:
C++ code - 80 lines - codepad
However my player still fails to move when I press a directional button.
-
04-17-2010, 11:46 PM #10120words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
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
-
04-18-2010, 01:54 AM #10121QJ Gamer Green
- Registriert seit
- Jun 2009
- Beiträge
- 61
- Points
- 2.003
- Level
- 27
- Downloads
- 0
- Uploads
- 0
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:
Spoiler for Main.c:Geändert von LegendMythe (04-18-2010 um 02:18 AM Uhr)
-
04-18-2010, 06:22 AM #10122QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
-
04-18-2010, 07:43 AM #10123QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Wow, it still refuses to work???
C++ code - 56 lines - codepad
-
04-18-2010, 07:54 AM #10124QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
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.
-
04-18-2010, 08:08 AM #10125QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
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
-
04-18-2010, 08:42 AM #10126QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
Well, this is how I would do it:
Spoiler for main.cpp:
Spoiler for player.h:
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.
-
04-18-2010, 08:58 AM #10127QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
But what was wrong with my code though?
-
04-18-2010, 11:45 AM #10128QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
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
-
04-18-2010, 11:49 AM #10129QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
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/jzANAH8jGeändert von Beat_Bob (04-18-2010 um 12:13 PM Uhr)
-
04-18-2010, 12:24 PM #10130QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
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
-
04-18-2010, 03:45 PM #10131QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
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)
-
04-19-2010, 04:15 AM #10132QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- Perth, Scotland
- Beiträge
- 1.094
- Points
- 8.475
- Level
- 62
- Downloads
- 0
- Uploads
- 0
-
04-20-2010, 07:34 AM #10133QJ Gamer Green
- Registriert seit
- Jun 2009
- Beiträge
- 61
- Points
- 2.003
- Level
- 27
- Downloads
- 0
- Uploads
- 0
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:
Spoiler for makefile:
-
06-10-2010, 12:05 PM #10134
Achievements:
- Registriert seit
- Jun 2010
- Ort
- Mumbai
- Beiträge
- 5
- Points
- 1.030
- Level
- 17
- Downloads
- 0
- Uploads
- 0
hello world
hey,
i seem to be having a problem with my first EBOOT.PBP.
main.c
MakefileCode:#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; }
the program compiles fine, and i get the EBOOT.PBP.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 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?
-
06-10-2010, 12:07 PM #10135Developer
- Registriert seit
- Jul 2008
- Ort
- Grand Rapids! MI
- Beiträge
- 125
- Points
- 8.092
- Level
- 60
- Downloads
- 5
- Uploads
- 2
-
06-10-2010, 12:11 PM #10136
Achievements:
- Registriert seit
- Jun 2010
- Ort
- Mumbai
- Beiträge
- 5
- Points
- 1.030
- Level
- 17
- Downloads
- 0
- Uploads
- 0
-
06-10-2010, 12:38 PM #10137QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
I already told you the solution: Help Please :)
That epic dude.
-
06-10-2010, 12:55 PM #10138
Achievements:
- Registriert seit
- Jun 2010
- Ort
- Mumbai
- Beiträge
- 5
- Points
- 1.030
- Level
- 17
- Downloads
- 0
- Uploads
- 0
-
06-10-2010, 01:21 PM #10139QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
Interesting, then their's either something wrong with your PSP or your Mac.
That epic dude.
-
06-17-2010, 09:53 PM #10140Developer
- Registriert seit
- Jul 2008
- Ort
- Grand Rapids! MI
- Beiträge
- 125
- Points
- 8.092
- Level
- 60
- Downloads
- 5
- Uploads
- 2
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


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum