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; You got me :), edited above post so as not to lead people the wrong way. I need to know ...
-
08-16-2007, 05:50 PM #6121
You got me :), edited above post so as not to lead people the wrong way.
Heres a simple example using the Image struct and functions from the graphics.h lib from psp-programming:I need to know how i would go about doing some animation. Any links ?
You just have to fill in the blanks for how you wish to draw and initialise the animation, I just provided those implemetations as examples of how you could do it.Code:typedef stuct { Image** images; // An array of image pointers int num_fames; // The number of elements in the above array int current_frame; // The current frame of the animation int anim_time; // The time counter int frame_duration; // The duration of a single frame in milli-seconds } Animation; void updateAnimation( Animation* anim, int dt) { // add the time change in time to the counter anim->anim_time += dt; if( anim->anim_time > ( anim->frame_duration * ( anim->current_frame + 1))) { // if the anim_time exceeds the time for a single frame go to the next one anim->current_frame++; } if( anim->current_frame >= anim->num_frames) { // if the sprite is on it's last frame return to first frame anim->anim_time %= (anim->num_frames * anim->frame_duration); anim->current_frame = 0; } } void loadAnim( Animation* anim, int num_frames, int fps) { // allocate memory for the images array and load the images // set anim->num_frames to the number of images in the anim // set the current_frame and anim_time to 0 // set the frame_duration to the speed you require (about 200 ms looks ok) anim->images = (Image**)malloc( sizeof(Image*) * num_frames); int i = 0; for ( i = 0; i < num_frames; i++) { char buffer[255]; sprintf( buffer, "./anim/frame%d.png", i); anim->images[i] = loadImage( buffer); } anim->num_frames = num_frames; anim->current_frame = anim->anim_time = 0; anim->frame_duration = 1000/fps; } void drawAnim( Animation* anim, int x, int y) { // draw 'anim->images[current_frame];' however you want // maybe blitAlphaImageToScreen( bla, bla, bla ); Image* temp = 'anim->images[current_frame]; blitAlphaImageToScreen( 0, 0, temp->imageWidth, temp->imageHeight, temp, x, y); }
I recommend using a timer to calculate the 'dt' value for the update function but if you don't wish to then just pass it the value 16 everytime.
If you want to reset the anim, just set anim_time and current_frame to zero.
Note: I'm not guarantee'ing this will compile or work but the basic idea is there, if you attempt to understand it you will probably be able to de-bug and use it.
EDIT: Added animation stuff to avoid double post.
Geändert von psp_jono (08-16-2007 um 07:48 PM Uhr)
-
08-16-2007, 06:46 PM #6122
Ok here's a quick question hopefully someone can answer relatively quickly...
I have the following:
(yes I know memset is only 7 but this is the way the sample had it and it seems to be working ok, I believe because I am only using up to sVal[5] and ignoring, 6, 7 and 8.)Code:u8 sVal[8]; memset(sVal, 0, 7); err = sceWlanGetEtherAddr(sVal); sprintf(tmp_buffer, "%02X:%02X:%02X:%02X:%02X:%02X", sVal[0], sVal[1], sVal[2], sVal[3], sVal[4], sVal[5]);
I can use sprintf and strcmp but...
How can I compare u8 variables without sprintf'ing them into a string.
i.e.
what I am trying to accomplish is:
after sprintfing the sVals I get a string such as "36:9b:01:AE:33:94" which is a MAC address.
I want to compare the mac address put into the tmp_buffer to another one (literal string)
I can of course use
to test whether the MAC address is the one I am looking for.Code:strcmp(tmp_buffer, "36:9b:01:AE:33:94");
But
I would like to do it like this instead:
To test each individual sVal, in a sense, testing if "sVal[0] == 3 & 6" and "sVal[1] == 9 & B"Code:if ((sVal[0] == (0x33 & 0x36)) && (sVal[1] == ....))
but that doesn't seem to work.. Do I need to do it this way:
Code:if ((sVal[0] & 0x33 & 0x36) && (sVal[1] & 0x39 & ....))
Geändert von califrag (08-16-2007 um 07:05 PM Uhr)
-
08-16-2007, 06:55 PM #6123It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Uhh, not quite sure what you're trying to do there. The & operator is bitwise AND, and I'm not sure that's what you want right there. Also, memset should be sVal, 0, 8 because the buffer is 8 long, not 7.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
08-16-2007, 07:03 PM #6124
As Archaemic mentioned your memset isn't getting all the elements of the array.
I'm not sure exactly what your comparing the elemets of the sVal array to.
If you were checking if the first elemt was equal to 0x36 and the second to 0x9b you can just compare the values as normal, no bitwise operations would be required.
Ex.
EDIT: I see that you have edited your post significantly, thanks it is now more understandable.Code:if( (sVal[0] == 0x36) && sVal[1] == 0x9b && ........) { // do what ever }
The u8 variables are simple unsigned char's so as above you can compare the individual values like you would compare anything else.
Also you can use strcmp without printing to a string anyway, ie;
Note: for this it is important that the last element in the array is '\0' or 0x00, which is why it would probably be better to look into and use memcmp rather than strcmp:Code:u8 sVal[8]; memset(sVal, 0, 8); err = sceWlanGetEtherAddr(sVal); // the required value 36:9b:01:AE:33:94 u8 required_val[8] = { 0x36, 0x9c, 0x01, 0xAE, 0x33, 0x94}; if( 0 == strcmp( (char*)sVal, (char*)required_val)) { // do what ever }
http://www.cplusplus.com/reference/c...ng/memcmp.html
Hope that helps :)Geändert von psp_jono (08-16-2007 um 07:43 PM Uhr)
-
08-16-2007, 07:22 PM #6125
Thanks I see where my problem was. I opened my file in a hex editor and was assuming that each sVal was composed of two portions of the text string.
sVal[0] being both "3 and 6"
sVal[1] being both "9 and b" and so on.
so I thought that I would need compare each sVal with BOTH of those values
that's why I was using the bitwise & because I thought the two bits were stored together.
so where I was doing "if sVal[0] = 0x33 (3) & 0x36 (6)" I really just needed as you put above "if sVal[0] = 0x36".
The reason I thought I had to do it the way I had it was because when I opened the file in the hex editor, I saw that "3=33, 6=36, 0=30, B=42" etc etc
so thats where I thought I needed to do my comparison. Thanks jono
-
08-16-2007, 07:33 PM #6126
No worries, happy to help :).
-
08-16-2007, 11:51 PM #6127QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
so this is good when we want to have group of variables for 1 thing right?
Zitat von psp_jono
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
08-17-2007, 01:10 AM #6128
Umm yeah, you may want to have a google for 'struct' and 'union' in c/c++ because this is a fairly fundamental feature of the language.
Basically a struct is a memory structure that holds several variables. These variables can be accessed through the name of the structure.
eg.
This is a structure with 3 data members, an integer (a), a floating pt. number (b) and a character (c).Code:typedef struct { int a; float b; char c; } Structure;
Example use:
The above code would give output: 5 18.3 gCode:int main() { Structure s = { 5, 18.3, 'g'}; // declaration and initialisation printf( "%d %f %c", s.a, s.b, s.c); return 0; }
It is well worth investigating the way struct are used in c, it is very important.
-
08-17-2007, 02:51 AM #6129QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
thx Jono
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
08-17-2007, 09:13 AM #6130QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Wow, I used to initialise the variables in a struct separately from the declaration. The way you have done it is much cleaner.
...Just Returned To The Scene...
-
08-17-2007, 12:43 PM #6131Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
jono thanks for taking the time out to write that piece of code. However, i have chosen to go with OSLib because of its great support for sprite sheets.
But i have found OSLib documentation for sprites animation but when i use this code as a template http://oslib.playeradvance.org/doku.php?id=day6 to get myself going i have trouble when changing the sprite sizes etc. it seems that no matter what i change it stays the same ...Geändert von eldiablov (08-17-2007 um 12:45 PM Uhr) Grund: Automerged Doublepost
-
08-17-2007, 12:48 PM #6132Avada Kedavra

- Registriert seit
- May 2007
- Ort
- Spain
- Beiträge
- 703
- Points
- 6.813
- Level
- 54
- Downloads
- 0
- Uploads
- 0
Well,there is a special sprite sheet library for OSLib,maybe it helps you.In the package is a source code example how to use it and of course the libs.
Zitat von eldiablov
http://pspupdates.qj.net/index.php?pg=49&aid=86795
-
08-17-2007, 01:03 PM #6133Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
yeah this should do. Thanks Coolj. I prefer starting from scratch anyway.
-
08-17-2007, 01:17 PM #6134QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
im getting error: implicit declaration of function "atoi"
what does it mean?[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
08-17-2007, 01:20 PM #6135QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
It means that the compiler could not find the prototype/source of that function because you did not include the header that actually had the prototype in it.Code:#include <stdlib.h>
-
08-18-2007, 07:43 AM #6136I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I'm having a problem loading .prx files from .prx files in the vsh (what a mouthful). I keep getting error 0x80020001, or 0x8002012E and I was just wondering if there was anything I specifically have to do to load something in the vsh?
I've tried looking at the documentation thingy to see if there was anything on there telling me how to load in the vsh, but no luck.
Thanks.
-Aura
-
08-18-2007, 07:56 AM #6137Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
u get 0x8002012E when the module isnt found , i dont know what the other one means
-
08-18-2007, 09:44 AM #6138QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- Finland
- Beiträge
- 752
- Points
- 7.385
- Level
- 57
- Downloads
- 0
- Uploads
- 0
0x80020001 is the most descriptive PSP kernel error ever.
Zitat von Auraomega
Yes, that IS the actual error. I didn't make it up.Code:#define SCE_KERNEL_ERROR_ERROR 0x80020001 #define SCE_KERNEL_ERROR_UNKNOWN_MODULE 0x8002012e
wheeee =:D
-
08-18-2007, 12:06 PM #6139I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Eep, typo, the error I'm having is actually 0x80010002, which is even more descriptive (no discription at all -.-)
Zitat von MaTiAz
I guess I may be loading the incorrect path, well, I'm loading the correct path, but seeing as I'm reading the path from another file... meh I'll try hard-coding and seeing if the error pops up.
Cheers
-Aura
Edit: Ok, I hard-coded the filepath, but now I'm getting a new error, specifically 0x8002013B when using / and 0x8002012E when using \
As far as my knowledge stretched on loading modules, you use / right? The error I get from that is SCE_KERNEL_ERROR_LIBRARY_ FOUND...Geändert von Auraomega (08-18-2007 um 12:23 PM Uhr)
-
08-18-2007, 12:43 PM #6140
if you mean in quotes then "example/folder/file.fil" would work but this would not "example\folder\file.fil" . When u use the backslash you would have to put two so "example\\folder\\file.fi l" and thats why i always use a forwardslash. If thats even what ur talkin about lol
Zitat von Auraomega
Geändert von pspballer07 (08-19-2007 um 10:03 AM Uhr)
Current releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
08-18-2007, 12:50 PM #6141It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
0x80010002 Associated file or directory does not exist
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
08-18-2007, 01:06 PM #6142QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- Finland
- Beiträge
- 752
- Points
- 7.385
- Level
- 57
- Downloads
- 0
- Uploads
- 0
uh, isn't it completely the opposite?
Zitat von pspballer07
wheeee =:D
-
08-18-2007, 01:29 PM #6143It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Yes, it is completely the opposite.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
08-18-2007, 01:48 PM #6144I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Bingo, I was trying to load using the incorrect string :ROFL:
Zitat von Archaemic
Now though, (this is using pspSdkLoadStartModule) I get 0x80010132 when loading in kernel (baring in mind its a kernel app), and when switched to user I get 0x8002013B.
When I use sceKernelLoadModule I get error 0x8002013B still...
-Aura
-
08-18-2007, 02:04 PM #6145
I need some basic help with programming for the PSP. I know C for computer but want to start programming for the PSP. I wanted to know whats different about programming for computers and programming for the PSP.
-
08-18-2007, 02:08 PM #6146I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Good question, and something I've not thought of before, I guess the major difference (for me at least) is the processing speed and memory, until I met PSP programming, my optmization skills REALLY sucked, now they only suck
Zitat von drag_93
-Aura
-
08-18-2007, 02:14 PM #6147
I sort of meant stuff in the code (like #include<whatever>) and functions like printf()
-
08-18-2007, 02:32 PM #6148QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Theres includes you need especially for the PSP, and certain things you need to put before main to make sure the program runs correctly. Other than that, you just need a few functions in main. If you wanted to write a useful application for the PSP, its not so similar to PC programming. If you know C for the computer you should have no trouble programming for the PSP in C seeing as its the same language... I suggest following tutorials on how to program for the PSP. A quick google search..
...Just Returned To The Scene...
-
08-18-2007, 02:35 PM #6149QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
From a high level perspective, very little. The C standard libraries work as described in the standard. Any thing else is platform specific.
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
08-18-2007, 02:41 PM #6150QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
I still would suggest a little research before going into PSP programming?
...Just Returned To The Scene...


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