Did u miss my post few pages back?Zitat:
Zitat von MrChaos
Printable View
Did u miss my post few pages back?Zitat:
Zitat von MrChaos
Zitat:
Zitat von MrChaos
I've been using this in an app I've been working on, not sure if this is what you want though...
-AuraCode:int button; //global
SceCtrlData pad; //another global, can be used here, or made local
void buttoncheck(SceSize args, void* argp)
{
//sceCtrlData pad; //un-comment if using as a local
while(1){
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & 0xFFFF) button = 1;
sceCtrlReadBufferNegatve(&pad, 1); //only use if required
if(pad.Buttons & 0xFFFF) button = 0; // || || || ||
sceKernelDelayThread(10000); //make sure other threads get processing time
}
}
void buttoncheckinit(SceSize args, void* argp)
{
SceUID buttonchect = sceKernelCreateThread("buttoncheck", buttoncheck, 0x30, 0x10000, 0, NULL);
sceKernelStartThread(buttoncheckt, args, argp);
}
int main(SceSize args, void* argp)
{
buttoncheckinit(args, argp);
//rest of code here
}
code:
result:Zitat:
sprintf(buffer,"Hello");
printf("%s",buffer);
sprintf(buffer,"Hi");
printf("%s",buffer);
Hello
Hillo
but i need:
Hello
Hi
does anyone know how to clear buffer? i tried free(buffer) but that just freezes my app
I'm not sure, but puttingZitat:
Zitat von myschoo
may do the trick, I think you can also NULL it, but again, I'm not totally sure.Code:buffer = "";
Alternatively, you could do...which will only give the first 2 letters, this probably will get tedious and if you're using variable length, then its not going to really be suitable, but I do know for a fact that works.Code:sprintf(buffer,"Hello");
printf("%s",buffer);
sprintf(buffer,"Hi");
printf("%0.2s",buffer);
As for free(buffer) not working, thats freeing up the memory, when you then try and sprint, it has nowhere to actually store the value and causes a buffer overflow.
-Aura
thx i will try it ;)
also tried to use memset and still same problem o_O
While I think about it, if you putZitat:
Zitat von myschoo
it should also work, seeing as \0 is the NULL flag, and I'm pritty sure variables stop reading once they reach a NULL flag.Code:sprintf(buffer, "Hi\0");
-Aura
Code:sprintf(buffer,"Hello");
printf("%s",buffer);
memset(buffer, 0, sizeof(buffer));
sprintf(buffer,"Hi");
printf("%s",buffer);
or bzero(buffer , sizeof(buffer) );
txh both of u.. it works
u could've just doneZitat:
Zitat von myschoo
Code:strcpy(buffer,"Hello");
printf("%s",buffer);
strcpy(buffer,"Hi");
printf("%s",buffer);
edit: my bad, read wrong >_>, sorry about that
If you actually bothered to read both peices of code properly you would notice that the original used sprintf, and that uses strcpy.Zitat:
Zitat von nataku92
-Aura
Zitat:
Zitat von pspballer07
or even simpler:
orCode:printf("%s\n", "Hello");
printf("%s", "Hi");
Code:printf("Hello\n");
printf("Hi");
Zitat:
Zitat von califrag
would be even simplier, but I doubt anyone is going to want their program to just sayCode:printf("Hello");
printf("Hi");
Hello
Hi
The string is going to have different values store in it no doubt, which makes both of the above useless.
-Aura
^^^^^^^^^^^^^^
listen to him ;) :D
How would I go about streaming an mp3? The only good peice of source code I've found for playing music loads it directly to memory, and needless to say, an mp3 takes a big chunk of the PSPs RAM.
-Aura
Manually Keep filling libmad's stream decoding buffer as it exhausts.Zitat:
Zitat von Auraomega
-4m psp
psp-programming.com has a tut for thatZitat:
Zitat von Auraomega
That may be what I need, but what would be the use for sceCtrlReadBufferNegative ?Zitat:
Zitat von Auraomega
Zitat:
Zitat von MrChaos
I wasn't sure if you wanted it so that it registers a 1 ONLY when a button is being pressed or not. If you want a 1 to register only when a button is pressed, then when nothing is pressed the negative kicks in, and allows the code under it to run. As I said, only use if you need it :tup:
I checked on there about 5 minutes before posting here, the only tutorial I could find was for loading it all into RAM, which isn't really suitable.Zitat:
Zitat von pspballer07
How would I go about doing that? Limiting how much is read should be easy, but updating everytime its running low, not sure how I should do that...Zitat:
Zitat von Mr305
-Aura
why not? you can free the memory it takes up after its done playing.Zitat:
Zitat von Auraomega
http://forums.ps2dev.org/viewtopic.php?t=8469&start=30
Mess around with that source.
*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:
Zitat von pspballer07
Thanks, I'll take a look :)Zitat:
Zitat von Archaemic
-Aura
what about , dam whats the name again , alright the thing that sony uses to play big mp3files , youresam made one too I guess
Acutally, that's exactly what I need. Thanks a bunch. :)Zitat:
Zitat von Auraomega
dang dude, what would you need a 100 mb song for?Zitat:
Zitat von Auraomega
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:
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
you dont need to copy the complete file to memory
oh i see, but I think the mp3player.c from the psp-programming tuts streams it. Did u try it?
streaming that was the word:):):)
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.
what i was trying to get across is there is no need for having a buffer at all.. you can just doZitat:
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.
@psp_jono:
Cheers, the more source code the merrier :tup:
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:
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
char myCharVar[9] = "hello all"
printf("%s",myCharVar);
this would work right? and i didnt use sprintf
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.Zitat:
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);
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 myCharVarZitat:
Zitat von myschoo
char myCharVar[] = "hello all";
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();
}
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:
Zitat von hallo007
maybe char hallo[5] = "hallo"; does work but that doesn't stop it being wrong
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.
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