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; Hey, iv been messing with the stuff on the computer, setting up a my function. Just a quick question, is ...
-
04-01-2008, 04:45 AM #8341QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
Hey, iv been messing with the stuff on the computer, setting up a my function. Just a quick question, is it possible to do something like:
Obviously it doesnt work but is there anything like this?Code:char str[32]="Im a string"; string str2; strcpy(str2, str);
-
04-01-2008, 04:52 AM #8342QJ Gamer Bronze

- Registriert seit
- Sep 2006
- Ort
- france
- Beiträge
- 170
- Points
- 6.359
- Level
- 52
- Downloads
- 0
- Uploads
- 0
I think this will do it:
Zitat von Xsjado7
even this works (only to show you that you can do things like that, example above is better for this exact case you have)Code:char str[32]="Im a string"; string str2(str);
of course if you just want to declare a string that is initialized, do it simply like this:Code:char str[32]="Im a string"; string str2=str; //or string str2="Im a string"
http://www.cplusplus.com/reference/s...ng/string.htmlCode:string str2("Im a string");
-
04-01-2008, 04:53 AM #8343QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Code:char str[32]="Im a string"; string str2( str ); string str3 = str;
[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]
-
04-01-2008, 04:58 AM #8344QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
Sweet, thanks guys
-= Double Post =-
okay, iv got m function working perfectly on computer but i just put it into my game and i get:
Iv added -lstdc++ in my makefile so what am i missing?Code:scores.cpp(34) : error: 'string' was not declared in this scope
-= Double Post =-
iv got past that error now, i just had to include <string>. Now im getting a few errors:
those lines consist of:Code:source/scores.cpp(57) : error: incompatible types in assignment of 'std::basic_s tring<char, std::char_traits<char>, std::allocator<char> >' to 'char [128]' source/scores.cpp(73) : error: incompatible types in assignment of 'std::basic_s tring<char, std::char_traits<char>, std::allocator<char> >' to 'char [128]' source/scores.cpp(83) : error: incompatible types in assignment of 'std::basic_s tring<char, std::char_traits<char>, std::allocator<char> >' to 'char [128]' source/scores.cpp(93) : error: incompatible types in assignment of 'std::basic_s tring<char, std::char_traits<char>, std::allocator<char> >' to 'char [128]' source/scores.cpp(103) : error: incompatible types in assignment of 'std::basic_ string<char, std::char_traits<char>, std::allocator<char> >' to 'char [128]'
just with a different variable name e.g score.hs2name...Code:score.hs1name = loadbuff3.substr(1, seperator-1);
Note: Everything worked fine on the computerGeändert von Xsjado7 (04-01-2008 um 08:09 AM Uhr) Grund: Automerged Doublepost
-
04-01-2008, 12:28 PM #8345QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
What datatype is score.hs2name?
[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]
-
04-01-2008, 01:18 PM #8346
can anyone help me out, i've been trying to shutdown the psp with the square button and including psppower.h but i dont know what is needed to power off in 3.90 as this call is old afaik

i've been tryingCode:else if (pad.Buttons & PSP_CTRL_SQUARE) { sceSysconPowerStandby(); }
-
04-01-2008, 02:17 PM #8347
Does this work on PSP? Can I use a file descriptor?Code:int write(int fd, char *Buff, int NumBytes);
-
04-01-2008, 02:42 PM #8348words 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
Considering your function name is so vague and not in the SDK or STL no *rolls eyes*

...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-01-2008, 02:49 PM #8349
Yeah... It's for dos;
Zitat von SG57
Now-a-days i'm intermixing multiple platforms (3 to be exact)
-
04-01-2008, 03:56 PM #8350
actually it should work fine. its posix (unistd.h) fwrite works, which just wraps write. just ignore sg57. you can use it.
-- Code Monkey : Sarien, Fishguts, Cracks and Crevices --
"Did IQ's just drop sharply while I was away?" (Ripley)
-
04-01-2008, 05:54 PM #8351QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 132
- Points
- 4.296
- Level
- 41
- Downloads
- 0
- Uploads
- 0
ok guys iv been trying to get this right for a few days but have had no luck.
so i have a code for collision right, but i dont know how to correctly modify it so it works for one more sprite on the screen.
this is the code for 1 sprite collision:
now when i try to modify it for another sprite on the screen, the second sprite still has no collision =\ but the first sprite still does.Code:if ((img1posX + img1width > img2posX) && (img1posX < img2posX + img2width) && (img1posY + img1height > img2posY) && (img1posY < img2posY + img2height) )
my code:
Code:if ((img1posX + img1width > img2posX) && (img1posX < img2posX + img2width) && (img1posX + img1width > img3posX) && (img1posX < img2posX + img3width) && (img1posY + img1height > img2posY) && (img1posY < img2posY + img2height) )
-
04-01-2008, 08:00 PM #8352QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
Spoiler for Post:
-
04-02-2008, 12:02 AM #8353QJ Gamer Bronze

- Registriert seit
- Sep 2006
- Ort
- france
- Beiträge
- 170
- Points
- 6.359
- Level
- 52
- Downloads
- 0
- Uploads
- 0
I guess it's a char[128].
Zitat von yaustar
the = operator works only in one way:
string = char[] is ok
char[] = string doesn't work
but you can get a const char* from a string with mystring.c_str() if that helps.
-= Double Post =-
xsjado, maybe I can help you with this function:
it splits a string given a delimiter, and returns it as a vector.Code:vector<string> split(string str, string delim) { vector<string> results; unsigned int cutAt; while((cutAt = str.find_first_of(delim)) != str.npos) { if(cutAt > 0) { results.push_back(str.substr(0,cutAt)); } str = str.substr(cutAt+1); } if(str.length() > 0) { results.push_back(str); } return results; }
for example, split("032.5=Me|034.9=You |105.0=Someone|096.6=Some oneelse|025.2=Santa", "|") will give you a vector containing this:
"032.5=Me"
"034.9=You"
"105.0=Someone"
etc...
and with the same technique you can get what you want from the string.
-= Double Post =-
cruisx, if you have a working function for collision between 2 sprites, just call it for all your sprites on screen, change the parameters that's all...
-
04-02-2008, 12:19 AM #8354QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
I spend two hours learning C++ functions and writing out my function then i log on today to find this
-
04-02-2008, 12:29 AM #8355QJ Gamer Bronze

- Registriert seit
- Sep 2006
- Ort
- france
- Beiträge
- 170
- Points
- 6.359
- Level
- 52
- Downloads
- 0
- Uploads
- 0
-
04-02-2008, 12:53 AM #8356QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
Do you know why my code isnt working though? It just gets to:
and nothing happens, doesnt do itCode:name1 = loadbuff3.substr(1, seperator-1);
-
04-02-2008, 01:12 AM #8357QJ Gamer Bronze

- Registriert seit
- Sep 2006
- Ort
- france
- Beiträge
- 170
- Points
- 6.359
- Level
- 52
- Downloads
- 0
- Uploads
- 0
-
04-02-2008, 01:23 AM #8358QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
Code:pspDebugScreenInit(); //This is for the seperator between scores int seperator; //This is for the "=" sign between the time and name in a highscore int equals; //The buffer for use with atof char* loadbuff2; //The buffer for use with string:: functions string loadbuff3; //For storing the highscore names string name1, name2, name3, name4, name5; //Conversions //Convert global.loadbuff for use with string:: functions loadbuff3 = global.loadbuff; loadbuff2 = new char [loadbuff3.size()+1]; strcpy(loadbuff2, loadbuff3.c_str()); pspDebugScreenPrintf("loadbuff3 copied to loadbuff2\n"); //Get first highscore data //Get score.hs1 score.hs1 = atof(loadbuff2); pspDebugScreenPrintf("Got time from first highscore\n"); //Remove score.hs1 from loadbuff3 loadbuff3.erase(0, 5); pspDebugScreenPrintf("Erased furst highscore from loadbuff3\n"); //Get the seperator from between the data of the first and second highscores seperator = loadbuff3.find("|"); pspDebugScreenPrintf("Found seperator from between highscore 1 and 2\n"); //Read from six bytes in to the seperator AKA get the name for the first highscore name1 = loadbuff3.substr(1, seperator-1); pspDebugScreenPrintf("Got first highscore name\n");
-
04-02-2008, 01:52 AM #8359QJ Gamer Bronze

- Registriert seit
- Sep 2006
- Ort
- france
- Beiträge
- 170
- Points
- 6.359
- Level
- 52
- Downloads
- 0
- Uploads
- 0
it's because:
- strings indices start at 0
- substr is like this: string.substr(size_t pos = 0, size_t n = npos) with pos = where to start, n = length of the substring, and not where to stop.
your code (I suppose loadbuff=="Me|"):
name1 = loadbuff3.substr(1, seperator-1);
does this:
name1 = loadbuff3.substr(1, 1);
so name="e".
I haven't tested but maybe try to write name1 = loadbuff3.substr(0, seperator); to see if I'm right.
http://www.cplusplus.com/reference/s...ng/substr.html
-
04-02-2008, 02:19 AM #8360QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
Forgot to mention, each float is stored as 5 characters, 3 digits for the seconds, a full stop and one digit for the miliseconds if that helps for anything.
Also its:
because i havent removed the "=" sign so its going to be "=Me|".Code:name1 = loadbuff3.substr(1, seperator-1);
-= Double Post =-
So does anyone have any ideas as to why the PSP gets caught at using .substr? Doesnt make any senseGeändert von Xsjado7 (04-02-2008 um 06:34 AM Uhr) Grund: Automerged Doublepost
-
04-02-2008, 09:50 AM #8361I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
How do I make a buffer start at a specific memory address of my own choice? I need it for this function:
I also keep getting errors when I try and use a function from another module. I've made a module that has all the graphics things I need in order to remove all the libraries from my main code and shrink it, it loads fine and without error, but when I attempt to use the functions it crashes giving me 0x8002013A, library not yet linked. Is there a common fix for this or should I post my makefile and stub?Code:/** * Load a module from a buffer * * @param buf - Pointer to a buffer containing the module to load. The buffer must reside at an * address that is a multiple to 64 bytes. * @param bufsize - Size (in bytes) of the buffer pointed to by buf. * @param flags - Unused, always 0. * @param option - Pointer to an optional ::SceKernelLMOption structure. * * @returns The UID of the loaded module on success, otherwise one of ::PspKernelErrorCodes. */ SceUID sceKernelLoadModuleBuffer(void *buf, SceSize bufsize, int flags, SceKernelLMOption *option);
Thanks.
-Aura
-
04-02-2008, 11:33 AM #8362
add enough to get it to round to the next size without overflowing the buffer.
Zitat von Auraomega
something like that. you'll need the original address to pass to free() so dont throw it away....Code:uint8_t *buff = malloc( 63 + buffsize); void *rebase = buff & ~0x3F;
-- Code Monkey : Sarien, Fishguts, Cracks and Crevices --
"Did IQ's just drop sharply while I was away?" (Ripley)
-
04-02-2008, 11:43 AM #8363Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
memalign() should work.

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
-
04-02-2008, 04:02 PM #8364lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
I go this
Now how do I get that value + an offset into a new pointer?Code:unsigned int *personapointer=(unsigned int*) (0x004FFE8C+0x08800000);
?Code:unsigned int *newPointer=(unsigned int*) (personapointer + 0x0000006E);
-
04-02-2008, 04:08 PM #8365
I think you have to add '&', signifying you mean the value of the address the pointer points to, not the pointer itself.
Zitat von Anti-QuickJay
Code:unsigned int *newPointer = (unsigned int*) (&personapointer+0x0000006E);
[IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]
Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.
-
04-02-2008, 04:13 PM #8366It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Well, you asked me this over AIM, but you never responded to me after I gave you your answer :/
First off, pointer arithmetic is different. Say you have this:
What do you think this would output if the first printf outputs 4?Code:printf("%u\n",sizeof(some_t)); some_t *pSome = NULL; pSome += 1; printf("%u",pSome);
Here's what it doesn't output:
Here's what it does output:Code:4 1
Why? Because "adding one" to a pointer actually adds the size of the pointer. Here's an analogy (that should be unambiguous):Code:4 4
So yeah, pointer arithmetic is different.Code:some_t* operator+(some_t *pointer, int incr) { return (some_t*)((unsigned int)pointer + (sizeof(some_t)*incr)); }
Second, if you actually want to go to the position 0x6E after personapointer, you'd be going to an invalid address for a unsigned int type and would get a bus error if you tried to access the location in memory.
(PS: Judas, that would give you 0x6E positions after the POINTER to personapointer, not what personapointer was pointing to)pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
04-02-2008, 04:18 PM #8367lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Ok, thanx
Sorry about not responding to your AIM, my internet got disconnected for some reason so I just went to play God of War.
:/
-
04-03-2008, 01:44 AM #8368Developer

- Registriert seit
- Aug 2007
- Beiträge
- 74
- Points
- 3.206
- Level
- 35
- Downloads
- 0
- Uploads
- 0
You don't need to choose your own address, just need to make sure your buffer is 64 Byte aligned.
Zitat von Auraomega
This is a kmode function btw.Code:const u8 myModule[MY_MODULE_SIZE] __attribute__((aligned(64))) = { // ...your bin2c'd module... }; sceKernelLoadModuleBuffer(myModule, MY_MODULE_SIZE, 0, NULL);
EDIT:
Yea you need to post the stub, specifically your imports attributes flag. Is your lib for umode or kmode exports, or both? Post your exports attributes flag from your exports file as well then.
Zitat von Auraomega
Geändert von SilverSpring (04-03-2008 um 02:06 AM Uhr)
PSP PRX LibDoc's Lives On!
http://silverspring.lan.st/
My new home:
http://my.malloc.us/silverspring/
-
04-03-2008, 02:00 AM #8369QJ Gamer Silver

- Registriert seit
- Sep 2007
- Ort
- AUS
- Beiträge
- 284
- Points
- 12.501
- Level
- 73
- Downloads
- 0
- Uploads
- 0
Hey guy's,
I can't seem to get my head around some adhoc scaning for my luaplayer.
This is the function so far
void scanadhoc(int *length,void *buf)
{
struct SceNetAdhocctlScanInfo *scaninfo;
/** Scan info structure */
sceNetAdhocctlScan();
sceNetAdhocctlGetScanInfo (length, buf);
}
It compiles well and when called it runs fine but i cant seem to get the adhoc list (the list of availabe adhoc networks to show)
Regards
Homemister
PS and help would be great.Wyvern. That is all
-
04-03-2008, 02:16 AM #8370words 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 really haven't given us the problem. You gave us a function that apparently works, not how your using it which is what we need I could write up a quick lua player specific function (the one you add to the array of functions and their name according) if you'd like. I'm busy for like an hour now though :X

...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


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