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 Auraomega I checked on there about 5 minutes before posting here, the only tutorial I could find was ...
-
08-14-2007, 12:42 PM #6061
why not? you can free the memory it takes up after its done playing.
Zitat von Auraomega
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-14-2007, 12:42 PM #6062It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
http://forums.ps2dev.org/viewtopic.php?t=8469&start=30
Mess around with that source.pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
08-14-2007, 12:45 PM #6063I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
*Sigh*... because loading mp3s into RAM takes up a lot of space, and I have songs that are almost 100mb big (over an hour long) which simply won't fit into the PSPs memory.
Zitat von pspballer07
Thanks, I'll take a look :)
Zitat von Archaemic
-Aura
-
08-14-2007, 01:05 PM #6064Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
what about , dam whats the name again , alright the thing that sony uses to play big mp3files , youresam made one too I guess
-
08-14-2007, 01:07 PM #6065QJ Gamer Blue
- Registriert seit
- Feb 2007
- Ort
- Florida
- Beiträge
- 214
- Points
- 4.031
- Level
- 40
- Downloads
- 0
- Uploads
- 0
Acutally, that's exactly what I need. Thanks a bunch. :)
Zitat von Auraomega
-
08-14-2007, 02:51 PM #6066
dang dude, what would you need a 100 mb song for?
Zitat von Auraomega
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-14-2007, 02:59 PM #6067I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Lol, I just like VNV Nation (a little too much), the song is 94.4mb big... and its not the only one (I have a few others tending towards that sort of size).
Zitat von pspballer07
A lot of my music is over 16mb big anyway (16mb being the biggest you can get in a partition if I remember rightly?), so this is more just so I can play all my music how I want, not with Sony's crappy one that only works in the XMB :Argh:
-Aura
-
08-14-2007, 10:49 PM #6068Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
you dont need to copy the complete file to memory
-
08-14-2007, 10:59 PM #6069
oh i see, but I think the mp3player.c from the psp-programming tuts streams it. Did u try it?
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-14-2007, 11:04 PM #6070Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
streaming that was the word:):):)
-
08-14-2007, 11:09 PM #6071
No I'm pretty sure the mp3 player library given in the psp-programming tutes loads the entire file into memory.
After a bit of a seach I came up with this thread at ps2dev.org: http://forums.ps2dev.org/viewtopic.php?t=5089.
Specifically PeterM's code half way down the page.
It seems others have also had trouble with this, the solution is to buffer the file reading, filling the buffer from the memory stick while the at the same time playing the stream. The code seems pretty easy to follow.
He does note that it is a bit slow however.
-
08-14-2007, 11:37 PM #6072
what i was trying to get across is there is no need for having a buffer at all.. you can just do
Zitat von Auraomega
printf("%s %02f %s", "a string", 2.5f, "another string"); or whatever you want...
printf("%s %02d %s", myCharVariable1, myIntVariable, myCharVariable2); ....
printf("Some Text %s My Int %02d More Text %s", myCharVariable1, myIntVariable, myCharVariable2);
etc etc
of course nobody will have their program just say "hello hi" that's retarded of you to think that is what I was implying.
now of course if you want to make your program twice as long and have to fill a buffer everytime you want to printf something you can always do as mentioned above and do
strcpy(buffer, "Some text");
printf("%s", buffer);
everytime you want something printed...
but then how will you get other variables in there like floats or ints?
you can't with strcpy at least not without casting.. at least as far as I know everytime I try strcpy(buffer, "%s %d", myCharVariable, myIntVariable) I get massive errors ;) (of course I know that doesn't work)
so in the end you would be left with
strcpy(buffer, "some text");
printf("%s %02d", buffer, myIntVariable);
which.. well.. nevermind just do what you want... it all works.
-
08-15-2007, 01:12 AM #6073I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
@psp_jono:
Cheers, the more source code the merrier
I never thought you were implying that, but, if you do what you've done there, you will ALWAYS have the same text, because its not in a variable. All the other peices of code shown allow use of loops, but if you looped any code written how you've done it, there will be no variation because you just hardcode the text you want.
Zitat von califrag
Your way would work fine, but its big and bulky, and taking up a lot of pointless space that could just be simplified a LOT by using sprintf.
As for theumm... how do you expected to get a variable into myCharVariable without using sprintf, or hell, without even using a buffer? Not going to happen.Code:printf("%s %02d %s", myCharVariable1, myIntVariable, myCharVariable2);
-Aura
-
08-15-2007, 03:21 AM #6074QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
char myCharVar[9] = "hello all"
printf("%s",myCharVar);
this would work right? and i didnt use sprintf[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-15-2007, 03:52 AM #6075
Actually no, it would fail because the string is too long for the buffer variable. The string constant "hello all" is actually 10 characters long because of the termenating null character at the end.char myCharVar[9] = "hello all"
printf("%s",myCharVar);
this would work right? and i didnt use sprintf
All strings should have a terminating null character at the end.
Correct code:
:)Code:char myCharVar[10] = "hello all"; printf("%s",myCharVar);
-
08-15-2007, 05:37 AM #6076
yeah jono's right. the compiler automatically adds the '\0' null terminator to a string literal therefore 9 characters isn't enough to store your string. just let the compiler work out the size of myCharVar
Zitat von myschoo
char myCharVar[] = "hello all";
-
08-15-2007, 05:56 AM #6077Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
char hallo[5] = "hallo";
works 100% fine
before u say , i say BS
look at this from cprograming.com
Code:#include <iostream> using namespace std; int main() { int x; int y; int array[8][8]; // Declares an array like a chessboard for ( x = 0; x < 8; x++ ) { for ( y = 0; y < 8; y++ ) array[x][y] = x * y; // Set each element to a value } cout<<"Array Indices:\n"; for ( x = 0; x < 8;x++ ) { for ( y = 0; y < 8; y++ ) cout<<"["<<x<<"]["<<y<<"]="<< array[x][y] <<" "; cout<<"\n"; } cin.get(); }
-
08-15-2007, 06:08 AM #6078
i'm not a c++ programmer so i'm not qualified to comment on that code but i fail to see what a 2 dimensional array of integers has to do with the point i was making about string literals.
Zitat von hallo007
maybe char hallo[5] = "hallo"; does work but that doesn't stop it being wrong
-
08-15-2007, 06:14 AM #6079It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
No, char hallo[5] = "hallo" will not work. "hallo" is six characters long. The double quotes alway add a null byte at the end. Therefore, even though it appears to be five characters long, it's really six.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
08-15-2007, 06:21 AM #6080
i've just seen the point your making, hallo007 (the bolded bit)
when you declare int x[8]; it stores its values like this - x[0] for the first integer of the array and x[7] for the last. thats why the second expression of the for loop is x < 8
-
08-15-2007, 06:26 AM #6081Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
I see my mistak , I mostly use array pointers , they dont have it
-
08-15-2007, 11:38 AM #6082QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
eh? Assuming you are talking about a C string, a null byte is appended to the end of it...
Zitat von hallo007
When you use double quotes, a null byte is appended to the end of the array.[CODE]Random Facts:
irc://irc.malloc.us #wtf #**********
[/CODE]
[SIZE="6"][FONT="Century Gothic"][COLOR="Blue"][URL="http://forums.**********.net"]http://forums.**********.net[/URL][/COLOR][/FONT][/SIZE]
-
08-15-2007, 12:23 PM #6083QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
:o Yay! I spotted a moca!
Zitat von Moca
-
08-15-2007, 01:30 PM #6084QJ Gamer Blue
- Registriert seit
- Feb 2007
- Ort
- Florida
- Beiträge
- 214
- Points
- 4.031
- Level
- 40
- Downloads
- 0
- Uploads
- 0
Is there anything you guys I could suggest for me to be able to save a homebrew game with? (Besides a .txt?)
-
08-15-2007, 01:33 PM #6085lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
.sav file
-
08-15-2007, 03:33 PM #6086
*.anythingyouwant
Zitat von MrChaos
then u could have ur own save file format that stores all the varsCurrent releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
08-15-2007, 03:35 PM #6087QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Just do something similar to,
Then just pick a convenient extension, like '.sav' as Anti has said.Code:typedef struct _GAME_STATE { int blah1; int blah2; char name[20]; char lala; int level; int start; int health; } SGameState; int saveGameState(const char* path, SGameState* gs) { FILE* pFile = fopen(path, "rb"); fwrite(gs, sizeof(SGameState, 1, pFile); fclose(pFile); return 1; } int loadGameState(const char* path, SGameState* gs) { FILE* pFile = fopen(path, "rb"); fread(gs, sizeof(SGameState), 1, pFile); fclose(pFile); return 1; }
(With error checking, of course.)
-
08-15-2007, 04:35 PM #6088
I'm not sure what this post actually means but I'm sorry if I didn't explain the problem well. As you know an array is a collection of common structures stored in sequential memory.I see my mistak , I mostly use array pointers , they dont have it
The string "hello all" should actually be stored in sequential memory as:
rather than:Code:[h] [e] [l] [l] [o] [ ] [a] [l] [l] [\0]
Where the square brackets are a single byte/char variable.Code:[h] [e] [l] [l] [o] [ ] [a] [l] [l]
As you can see the correct example requires the array to be 10 elements long rather than 9.
While a string could be stored in memory without the null char, it isn't a good idea. Many function rely on the null character to signify the end of a string, without it they would continue working past the end of the string reading or writing to random data, this could cause weird, hard to track bugs or complete crashes.
Hopefully this helps :)
I'm pretty sure that wont even compile.char hallo[5] = "hallo";
works 100% fine
I'd go with a binary format like _dysfunctional's example. While easier to understand, text format save files are often too easy for people to edit in order to cheat. With binary you can make it harder to modify the variables that are important to cheaters. Especially those with little knowledge of programming.Originally Posted by MrChaos
Is there anything you guys I could suggest for me to be able to save a homebrew game with? (Besides a .txt?)Geändert von psp_jono (08-15-2007 um 05:02 PM Uhr)
-
08-15-2007, 04:53 PM #6089
I don't see how using "sprintf" and buffers can simplify this code:
Zitat von Auraomega
orCode:printf("Sometext 2 Moretext");
to:Code:printf("%s %02d %s", myCharVariable1, myIntVariable, myCharVariable2);
keep using sprintf's and buffers for everything and i will keep a minimalist approach. Thanks!Code:char myCharVariable1[50], myCharVariable2[50]; int myIntVariable; sprintf(myCharVariable1, "Sometext"); sprintf(myCharVariable2, "Moretext"); myIntVariable = 2; sprintf(buffer, "%s %02d %s", myCharVariable1, myIntVariable, myCharVariable2); printf("%s", buffer);
Plus it all depends on what you are doing and whether the text is static or not, and if it is not static of course you will need to use sprintfs to initialize the variables with the data you need.Geändert von califrag (08-15-2007 um 05:11 PM Uhr)
-
08-15-2007, 04:58 PM #6090It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
So many things wrong with both of those, I don't know where to begin @@
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ


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