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; Zitat von Waterbottle outisde of the mainfuction, yes. > more than < less than >= more than or equal <= ...
-
01-15-2007, 12:01 PM #2521QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Thanks. :)
Zitat von Waterbottle
-
01-15-2007, 12:08 PM #2522words 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
Code:== Equal to != Not equal to > Greater than < Less than >= Greater than or equal to <= Less than or equal to & Bitwise AND | Bitwise Inclusive OR ^ Bitwise Exclusive OR ~ Unary complement (bit inversion) << Shift Left >> Shift Right

...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
-
01-15-2007, 12:13 PM #2523QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
|| means or and & means and right?
Zitat von SG57
lol your about eight minutes late but thanks anyway.
I just need to clarify something -
Now if I press up it would just change p1x and not ms?Code://let's say I have this void game() { if(pad.Buttons & PSP_CTRL_UP) { p1x = p1x + 2; } int main() { if(pad.Buttons & PSP_CTRL_UP) { ms = ms + 1; } if(pad.Buttons & PSP_CTRL_START) { game(); }
-
01-15-2007, 12:20 PM #2524words 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
Well I just saw the small list waterbottle gave you, so I did a quick write up of all I knew, then a few defintions I had to google about. And your 1/2 right...
& is bitwise 'and'.
| is bitwise 'or'.
& will copy a bit to the result if it exists in both operands.
| will copy a bit if it exists in either operand.Code:unsigned int a = 60; // 60 = 0011 1100 unsigned int b = 13; // 13 = 0000 1101 unsigned int c = 0; c = a & b; // 12 = 0000 1100
You were talking about the logical operations of the two.Code:unsigned int a = 60; // 60 = 0011 1100 unsigned int b = 13; // 13 = 0000 1101 unsigned int c = 0; c = a | b; //61 = 0011 1101

...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
-
01-15-2007, 12:41 PM #2525QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Yeah I was.
Zitat von SG57
The makefile for these includes would be:
would beCode:#include <pspdisplay.h> #include <pspctrl.h> #include <pspkernel.h> #include <pspdebug.h> #include <pspgu.h> #include <stdio.h> #include "graphics.h"
I'm not good with makefiles so I haven't the foggiest idea.Code:TARGET = lol OBJS = main.o graphics.o framebuffer.o CFLAGS = -O2 -G0 -Wall CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti ASFLAGS = $(CFLAGS) LIBDIR = LIBS = -lpspgu -lz -lm LDFLAGS = EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = secret PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak
EDIT -
Ok now I need some help with my code.
Now this problem may seem obvious to solve but it isn't IMO...
what it is that I defined all my variables in the main loop, but the function is outside of the main loop. The function refers to the variables, thus I get undefined errors.
Help?
-
01-15-2007, 12:51 PM #2526words 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
Add:
Else when using GU calls it may complain it about undefined references to GUM functions...Code:-lpspgum

...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
-
01-15-2007, 12:58 PM #2527
Hey,
i was just trying to make a code to assign the value of 1 to base, if Circle is pressed...i tried this
but that dosn't workCode:if(pad.Buttons & PSP_CTRL_CIRCLE){ base=1; }
...it just assigns 1 to base and carries on with the rest of the code...i tired Break; but that doesnt work....what should i be doing to achive this?
thanks for any help :)
-
01-15-2007, 12:59 PM #2528QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Did that, and it still gives me the undeclared errors. (it was undeclared not undefined)
Zitat von SG57
Ok now I need help with this error:
Maybe for the undeclared I could have a file with all the declarations(ie int, char, my colors) and #include it.Code:main.c:23: error: syntax error before numeric constant Line 23: sceCtrlSetSamplingCycle(0);
[action=PSPduh]goes tries[/action]
ok now this is annoying but I'm not giving up.
lol.h:Code:$ make kxploit psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -c -o main.o mai n.c In file included from main.c:9: lol.h:11: warning: implicit declaration of function 'RGB' lol.h:11: error: initializer element is not constant lol.h:12: error: initializer element is not constant lol.h:13: error: initializer element is not constant lol.h:14: error: initializer element is not constant lol.h:15: error: initializer element is not constant lol.h:16: error: initializer element is not constant lol.h:17: error: initializer element is not constant lol.h:20: error: initializer element is not constant lol.h:21: error: initializer element is not constant lol.h:22: error: initializer element is not constant main.c:24: error: syntax error before numeric constant main.c:24: warning: type defaults to 'int' in declaration of 'sceCtrlSetSampling Cycle' main.c:24: warning: data definition has no type or storage class main.c:25: warning: type defaults to 'int' in declaration of 'sceCtrlSetSampling Mode' main.c:25: warning: parameter names (without types) in function declaration main.c:25: warning: data definition has no type or storage class main.c: In function 'game': main.c:52: error: 'pad' undeclared (first use in this function) main.c:52: error: (Each undeclared identifier is reported only once main.c:52: error: for each function it appears in.) main.c: In function 'main': main.c:108: error: 'sceCtrlData' undeclared (first use in this function)
How the *bleep* do I fix that sceCtrlData error?Code:Color blue = RGB(0,0,255); Color red = RGB(255,0,0); Color green = RGB(0,255,0); Color white = RGB(255,255,255); Color black = RGB(0,0,0); Color orange = RGB(255,140,0); Color yellow = RGB(255,255,0); //char the colors char p1c = white; char bc = red; char p2c = white;
@willolner - What do you mean it doesn't work? If it assigns 1 to base then isn't it mission accomplished?Geändert von PSPduh (01-15-2007 um 01:14 PM Uhr)
-
01-15-2007, 01:40 PM #2529words 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
PSPduh - Give me the snippet of your code that that is found in... Like line 20 to 30 or so...
willolner - Im confused as well... Pressing O will set base to the value of 0. Unless somewhere else in the infinite loop your setting it NOT to 0, then it should be fine (im guessing your initlizing 'base' in your main loop, hence why it doesnt work as you thought)
...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
-
01-15-2007, 03:34 PM #2530QJ Gamer Green
- Registriert seit
- Feb 2006
- Ort
- Australia - A.C.T.
- Beiträge
- 1.517
- Points
- 9.253
- Level
- 64
- Downloads
- 0
- Uploads
- 0
ok this code works fine when i make it a eboot but i need to make it a prx and when i try it doesn't load can anyone help
Code:#include <pspkernel.h> #include <pspdebug.h> #include <string.h> #include <pspctrl.h> PSP_MODULE_INFO("AUTOBOOT", 0x1000, 1, 1); void loadeboot(char *pbpath) { //char *pbpath; const u32 pbplen = strlen(pbpath)+1; struct SceKernelLoadExecParam eloader; eloader.args = pbplen; eloader.argp = pbpath; eloader.key = NULL; eloader.size = sizeof(eloader) + pbplen; if(sceKernelLoadExec(pbpath,&eloader)<0) { printf("EBOOT NOT FOUND, PLZ CHECK THE FILE AND TRY AGAIN\n"); } } int main() { loadeboot("ms0:/PSP/GAME/irshell/EBOOT.PBP"); }thx mafia1ftCode:TARGET = EBOOTLOADER OBJS = main.o BUILD_PRX=1 CFLAGS = -O2 -G0 -Wall CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti ASFLAGS = $(CFLAGS) PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak
Spoiler for LOL:
-
01-15-2007, 03:38 PM #2531QJ Gamer Silver
- Registriert seit
- Oct 2005
- Ort
- Sheffield, UK
- Beiträge
- 844
- Points
- 8.201
- Level
- 61
- Downloads
- 0
- Uploads
- 0
All prx's need exports. Check C:\cygwin\usr\local\pspde v\psp\sdk\samples\prx\tes tprx for an example of exports.
-
01-15-2007, 03:38 PM #2532words 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
PRXs shouldnt have a PSP_MODULE_INFO, I think Ive heard that somewhere... But then again Ive been PSPless for 4 months now, so my memory is fading *sad song plays*

...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
-
01-15-2007, 03:41 PM #2533QJ Gamer Silver
- Registriert seit
- Oct 2005
- Ort
- Sheffield, UK
- Beiträge
- 844
- Points
- 8.201
- Level
- 61
- Downloads
- 0
- Uploads
- 0
They do, nothing in the PSPSDK will compile without the PSP_MODULE_INFO :)
-
01-15-2007, 10:05 PM #2534Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
PSPduh: you seem to be lacking on some of the fundamentals of what you need to know. May I recommend taking my 'Full game' tutorial series (in 3 parts). It deals with variable scope and using multiple files/headers.
Part one starts here: http://www.psp-programming.com/forum....php?topic=359
Check out my homebrew & C tutorials at http://insomniac.0x89.org/
Coder formerly known as Insomniac197
tshirtz: what is irshell ??
Atarian_: it's where people who work for the IRS go when they die
-
01-16-2007, 10:16 AM #2535Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
fixed
-
01-16-2007, 11:08 AM #2536
Hey :)
compiling this
cygwin saysCode:#include <pspkernel.h> #include <pspdebug.h> #include <pspdisplay.h> #include <pspctrl.h> #define printf pspDebugScreenPrintf int i = 0; SceCtrlData pad; /* 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; } PSP_MODULE_INFO("PSPointles", 0, 1, 1); int main () { pspDebugScreenInit(); SetupCallbacks(); /*logo*/ printf("\n\\\\ //// //// //// //// /////////\n \\\\ ////\\\\ //// //// //// /// ///\n \\\\ //// \\\\ //// //// //// //// /// ///\n \\\\//// \\\\//// //// /////// /////// /////////\n "); /*Menu code*/ printf("Welcome To Willo's Absalootly Pointless Game \nPress X To Continue: \n"); while(1) { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_CROSS) { break; } } pspDebugScreenClear(); /*Data input for User */ printf("Press Triangle, and try to fill the screen with 1s") while(1) { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_TRIANGLE) { printf("1"); } }
whats wrong with the sorce?
thanks for any help :)
-
01-16-2007, 11:14 AM #2537QJ Gamer Green
- Registriert seit
- Sep 2006
- Ort
- Cape Town, South Africa
- Beiträge
- 714
- Points
- 5.795
- Level
- 49
- Downloads
- 0
- Uploads
- 0
You forgot the semicolon on the printf before the second while loop.
Zitat von willolner
-
01-16-2007, 11:16 AM #2538
*slaps self on forehead*
lol
thank you :)
-
01-16-2007, 11:22 AM #2539
i dunno if anyone have any experience at all with SDL (Simple DirectMedia Layer) but i have some issues using the SDL_EnableKeyRepeat(3, 3); function but i really need to have that explained maybe an example or something cause i cant get it working at all :)
Never mind ive solved the problem :)Geändert von PSP-Maniac (01-16-2007 um 11:56 AM Uhr)
-
01-16-2007, 08:43 PM #2540QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Quick question:
Is there any way to draw a circle? I mean is there already a predefined function that can draw a circle? Or will I have to go out of my way to make my own?
@Insomniac -
Thanks, I'll take a look. :)
I just like to do things by myself :)
I'll definitely try collision by myself. (Always something I wanted to try.)
-
01-16-2007, 09:28 PM #2541words 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
PSPduh - Using the graphics library I believe so. If not, just look in the Developers Dungeon for a thread on circles... I created it, i cant remember the name right now.

...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
-
01-17-2007, 06:27 AM #2542Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
i am trying to how many space there is left on flash0:
this should prinf the used space on flash0Code:int totalegrote=0; void check_space( const char *root) { int dfd; char next_root[256]; char next_write[256]; sceIoUnassign("flash0:"); sceIoAssign("flash0:", "lflash0:0,0", "flashfat0:", IOASSIGN_RDWR, NULL, 0); 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_root, root, dir.d_name, 1); check_space(next_root); } } else { struct stat fileStats; if (stat(root, &fileStats) == 0) { int grote=fileStats.st_size; totalegrote=totalegrote+grote; } } } sceIoDclose(dfd); } } int main() { check_space("flash0:/"); printf("\n%i", totalegrote); return 0; }
while i test this , it prints 6209536 (5,9mb) , thats fault there is more than 20mb used!!!
what did i wrong??Geändert von hallo007 (01-17-2007 um 06:41 AM Uhr)
-
01-17-2007, 12:16 PM #2543QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Hmm, I scanned graphics.c and I didn't find a circle function.
Zitat von SG57
Yeah I seen the thread for snippets and found one but I'm trying to make one but the best I have is a rounded rectangle.
EDIT -
If anybody wants the code for the rounded rectangle or a triangle here it is:
Spoiler for code:
Um I need some help now...collision. Okay I know there are guides around the forums dealing with collision but I can make one by myself if I know the answer to this question:
-When you blit the image, using x and y, what would the right side of the figure be? Top side? Bottom side? Left side? (In relation to x and y I mean. (like if the bottom side is y + something))Geändert von PSPduh (01-17-2007 um 04:44 PM Uhr)
-
01-17-2007, 05:25 PM #2544words 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
PSPduh - Your confusing.
Collision, boudning boxes, compares to rectangles and checks whether one would be in side the other (rectangles as in just there size and placement).
So, to start you off:
Then youcould do:Code:int Collision ( int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2 ) { if (blah collide checks==true) { return true; } else { return false; } } }
As you can guess...Code:if (Collision ( guy.x, guy.y, guy.width, guy.height, enemy.x, enemy.y, enemy.width, enemy.height)) { // collision! } else { // no collision! }
x1 = x placement of first object
y1 = y placement of first object
w1 = width of first object
h1 = hieght of first object
Same with the 2's but for the seconf object. And it doesnt have to be an image, you can compare numbers for all i care... In that LUA tutorial i did on bounding boxes (search these forums) I had 2 strings move around, and if collided print on them they collied, else print they didnt.
Collision is very very easy stuff, should be the least of peoples worries when making agame.
Also, to answer your question... The 'right' side of an image is the X placement of the image + the images width. So,,,
guy.x + guy.width = right side of guy image
...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
-
01-17-2007, 05:43 PM #2545QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Oh ok, I gotcha. I know collision is easy, I just was confused on what the right side of what image is and what side blah is etc.
Zitat von SG57
so:
guy.x + guy.width = right side
guy.x - guy.width = left side (?)
guy.y + guy.height = top side
guy.y - guy.height = bottom side
Right?
-
01-17-2007, 05:45 PM #2546words 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
You arent thinking logically PSPduh... Why would we ADD the width of the image to its X coordinate, if the PSP blits images from teh top left (lua i mean).
Subtracting the width from the X will give you leftside-width of what you want. The left side of the image is just its X value. Same with top of image ;)
...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
-
01-17-2007, 05:51 PM #2547QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
See I didn't now where the PSP blits the image. Whether it be the center, top left, bottom, but now I know that it is the top left. OH I GET it.
Zitat von SG57
so...(let's try this again lol)
Now I'm sure that's right?Code:left side = x right side = x + width top side = y bottom side = y - height
Still need to find out how to draw a circle. I just don't like using outside images...I like doing everything inside the code, for some reason it feels like I have more control over everything.
And now that I know what the sides are then I can do the collision...but dang it I still need to figure out how to do speed.
WAIT HOLY FO SHNIZZLE I THINK I GOT TEH SPEEd.
-
01-17-2007, 06:06 PM #2548
- Registriert seit
- Nov 2006
- Beiträge
- 48
- Points
- 3.751
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Here's a circle drawing function a found awhile back, its not a perfect circle, but good enough for my purposes at least. It's also fairly fast. Just change DrawPixel() to whatever your pixel drawing function is. I think it's pretty self explanatory on how to use it.
Code:void drawCircle(int x, int y, int r, Color color) { int pos_x, pos_y = -r, tx = 0, ty = 4*r, a = 0, b = 2*ty+9, x1 = int(r*0.707010678 + 0.5); DrawPixel(x+r,y,color); DrawPixel(x-r,y,color); DrawPixel(x,y+r,color); DrawPixel(x,y-r,color); DrawPixel(x+x1,y+x1,color); DrawPixel(x+x1,y-x1,color); DrawPixel(x-x1,y+x1,color); DrawPixel(x-x1,y-x1,color); for(pos_x = 1;pos_x < x1;pos_x++) { a += 8; tx += a; if(tx > ty) { pos_y++; b -= 8; ty += b; } DrawPixel(x+pos_x,y+pos_y,color); DrawPixel(x-pos_x,y+pos_y,color); DrawPixel(x+pos_x,y-pos_y,color); DrawPixel(x-pos_x,y-pos_y,color); DrawPixel(x+pos_y,y+pos_x,color); DrawPixel(x-pos_y,y+pos_x,color); DrawPixel(x+pos_y,y-pos_x,color); DrawPixel(x-pos_y,y-pos_x,color); } }
-
01-17-2007, 06:07 PM #2549words 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
*takes off belt*
PSPduh... you know I dont like being lied to... ok, maybe you didnt know but you know now... The PSP blits the image from the top left of the image... so... the top of the image is the y coordinate, the left is the x, the bottom is y + height, the right is x + width.
*puts belt back on before pants fall down and lets PSPDuh away with a warning and a firm shaking finger*
...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
-
01-17-2007, 06:53 PM #2550QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Er?
Zitat von SG57
Oh yeah I forgot that the y increments downward...whoops. :o
@trevis - thanks. :)
Now I need to tweak it to make a filled in circle. (which is what I need)
Now I think I can commence making the actual game...


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