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; Guys.......i didn't post the buttons LTrigger part for asking if i need to use oldpad or not. I just did ...
-
03-30-2007, 05:55 AM #3571
Guys.......i didn't post the buttons LTrigger part for asking if i need to use oldpad or not. I just did it to show the general function. I only need to test the 4th brightness, and get it working. I have enough knowledge to know about oldpad. So, i just need someone to help me with the brightness code, and not the controls code.
-
03-30-2007, 06:56 AM #3572QJ Gamer Green
- Registriert seit
- Sep 2006
- Ort
- Cape Town, South Africa
- Beiträge
- 714
- Points
- 5.795
- Level
- 49
- Downloads
- 0
- Uploads
- 0
For oldpad, I do this:
keysPressed will now give you all the keys that have just been pressed. It's simple and efficient.Code:unsigned long keysPressed = (currentPad.Buttons ^ oldPad.Button) & currentPad.Buttons ;
By the way, what's "int *100" supposed to do?
-
03-30-2007, 10:15 AM #3573
Let me quote this again. For the last time, I AM NOT ASKING FOR OLDPAD OR THE CONTROLS FOR BRIGHTNESS, BUT THE FUNCTION FOR THE BRIGHTNESS. HOW IS THAT HARD TO UNDERSTAND?
Zitat von Xylem
-
03-30-2007, 11:09 AM #3574QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Where the hell are you getting this code from?Code:void sceDisplay_driver_9E3C6DC6(int 100,int 0);//a0 0-100,a1 = 0/1 (set to 0) #define sceDisplaySetBrightness sceDisplay_driver_9E3C6DC6 void sceDisplay_driver_31C4BAA8(int *100,int *0); #define sceDisplayGetBrightness sceDisplay_driver_31C4BAA8
[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]
-
03-30-2007, 11:13 AM #3575I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Zitat von Xylem
Why is that so hard to understand?Code:if(pad.Buttons & PSP_CTRL_LTRIGGER) { sceDisplaySetBrightness(100,0); }
-
03-30-2007, 12:36 PM #3576QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
How do you set the psp debug text to a different size? / is there a way?
Thank youNEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
03-30-2007, 12:37 PM #3577QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
No.
Zitat von BlackShark
Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
-
03-30-2007, 06:09 PM #3578
Hey,
Listen guys, i am very sorry about my behavior earlier. I was just pretty angry because of the bad grade at school, and i was very sensitive about that (lol, it turned out to be someone else's grade.....teacher made a mistake). Anyways, my point is that my behavior was really bad, and i was being really rude (especially to Yaustar and Access_Denied, who have helped me a lot the past days in coding). Just like to say sorry.
Also, i have one last question. Here is the code:
In that code, what do i need to change to make it work? Do i change the a0 to 100 and a1 to 0? Or do i leave that, but put the 100 and 0 in the set part like i did?Code:void sceDisplay_driver_9E3C6DC6(int a0,int a1);//a0 0-100,a1 = 0/1 (set to 0) #define sceDisplaySetBrightness sceDisplay_driver_9E3C6DC6 //later in main loop controls if(pad.Buttons & PSP_CTRL_LTRIGGER) { sceDisplaySetBrightness(100,0); }Geändert von Xylem (03-30-2007 um 06:21 PM Uhr)
-
03-30-2007, 08:01 PM #3579QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Hey, i need help with I/O functions. Right now, i am optimizing the code for the G-Pack and trying to make it look more organized and look clean. I need to put all my settings in one file. I know how to read X to Y bytes, but i don't know how to write from X to Y bytes. If anyone could explain or give me the code, then i can understand and learn it. Thanks.
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
03-30-2007, 08:04 PM #3580words 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
fprintf(FILE *stream, const char * format, ...);
ftw...
...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
-
03-30-2007, 08:09 PM #3581QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Lol, i have no idea what you are saying....if you could give me an example code, i can understand it better. Btw, here is the code for reading the 6th to the 7th character in my g-pack:
Zitat von SG57
It reads the 6th to the 7th character (being the 7th character- 9999991 or 9999990). I know how to read it, but how do you write. I had another question about that, why do you need a [2] after the variables i declared. Whenever i put another number in the [-], the program doesn't work...Code:char x[7]; char variable[2] = "0"; char variable1[2] = "1"; FILE *credit; if ((credit = fopen("./files/credit.txt","rb")) == NULL) { printf("There is nothing in this file"); } x[fread(x, 1, 7, credit)] = 0; fclose(credit); x[7]=0; if(strcmp (variable,x+6) == 0) { appmain(); } if(strcmp (variable1,x+6) == 0) { credits(); }Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
03-30-2007, 08:54 PM #3582QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Example code using fprintf
Zitat von superbatxs
Code:char text[12] = "Hello World"; FILE *d; if ((d = fopen("ms0:/test.txt", "a+b")) == NULL) { printf("Dest. file could not be opened for writing"); fclose(d); return -1; } fprintf(d,"Just like printf but prints to file instead of screen. BTW, %s", text); fclose(d);[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]
-
03-30-2007, 08:59 PM #3583words 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
super - You need to learn to use your resources more effectively... A quick google search will give you something similar to what Moca posted.

...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
-
03-30-2007, 09:00 PM #3584QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Yea, but............what about using it to print numbers instead of letters, or printing to a X to Y position. How come this doesn't work:
Zitat von Moca
I am trying to write something in to the 7th character in a file.Code:char x[7]; char variable1[2] = "0"; credit = fopen ( "./files/credit2.txt" , "wb" ); x[7]=0; fprintf (credit, x+6, variable1); fclose (credit);
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
03-30-2007, 09:43 PM #3585QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
:|
Zitat von superbatxs
INSTEAD OF PRINTING TO THE SCREEN IT PRINTS TO A FILE... Do you know how to use printf :|
or...Code:fprintf(credit,"x + 6 = %d \n variable1 = %d",x+6,variable1);
btw, if you want to write to an offset,Code:sprintf(text,"x + 6 = %d \n variable1 = %d",x+6,variable1); fprintf(credit,text);
fseek(credit,offset,SEEK_ SET);
This goes to the offset that you want. Then write what you want from there.[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]
-
03-30-2007, 11:06 PM #3586QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
ok, ive asked this before and it was answered so kindly by SG57, but I could not find it again, I searched for at least an hour (not exaggerated) on this thread and could not find it so, (very sorry) but here it goes.
How do I find the last 4 characters of a file (using a filebrowser)? like how would you tell if a file is an .mp3 ?
Thank you, and sorry for asking that twice.NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
03-31-2007, 02:04 AM #3587QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
The first thing that comes to mind is fread + strcmp
fseek(file,-4,SEEK_END); // Seeks -4 bytes from the end of the file
Then read the four bytes with fread and store it in a string. Compare the string with "mp3" and if strcmp returns 0, they are equal.
btw, i guess you could read the header of every file in a directory then work from there.Geändert von Moca (03-31-2007 um 02:20 AM Uhr)
[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]
-
03-31-2007, 07:23 AM #3588QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Lol, believe it or not, i was asking you guys the wrong question. Sorry for all the trouble. What i actually wanted to do was write only one character in a certain place in a file (like write a 0 instead of 6 in "1234567", etc.). I learned that you need SEEK_END to set the origin where you need to replace the character. I know how to do it now, but sorry for asking you guys the wrong question. I myself was confused, and probably made you guys confused as well. :o
Zitat von Moca
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
03-31-2007, 07:40 AM #3589I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Check out the functions on this page, they will greatly help you.
Zitat von superbatxs
http://www.psp-programming.com/code/...id=c:functions
-
03-31-2007, 08:04 AM #3590QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Yep, your sig is huge. Seriously, i am going to post the code in the C examples thread to help other people who need help with writing blocks of data from X to Y bytes. I got mine to work now. Hint: the origin should be changed, and same for where you want to stop (example- SEEK_END).
Zitat von Access_Denied
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
03-31-2007, 08:09 AM #3591Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
what does that mean:Code:PSP_USB_CONNECTION_ESTABLISHED
that at the moment a file is transfering to psp?
or that the psp is connected to pc?
-
03-31-2007, 08:34 AM #3592QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
I think it's that the psp is connected to the pc.
Zitat von hallo007
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
03-31-2007, 08:37 AM #3593Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
oke
does anyone know wich byte of the return is for currently transfering , or doesnt it returns that info?Code:sceUsbGetState(void);
-
03-31-2007, 10:02 AM #3594QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Ok, i was wrong. I don't understand how to write X to Y bytes in a file. If anyone could help, that would be great. I tried using this:
I wanted to replace a 6 with 0 in "1234567". However, when i used it, it gave me "123450". It deleted the 7. I know why, because i did SEEK_END, and the program seeked from the 5 to the 7 because of it. But even when i tried "SEEK_END - 1", it still gave me the same thing. Even when i put 6 instead of SEEK_END, it still gives me a "0" in the whole file.Code:char buffer20[] = { '0' }; credit = fopen ( "./files/credit.txt" , "wb" ); fseek(credit, 5, SEEK_END); fwrite(buffer20, sizeof(buffer20[0]) , sizeof(buffer20), credit); fclose (credit);Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
03-31-2007, 10:09 AM #3595Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
Try using SEEK_SET to position from the start of the file.
The second argument of fseek is what you need to alter to get the correct value, not the third argument.
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
-
03-31-2007, 10:49 AM #3596QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
I tried:
Zitat von Insert_Witty_Name
and:Code:char buffer20[] = { '0' }; credit = fopen ( "./files/credit.txt" , "wb" ); fseek(credit, SEEK_SET, 5); fwrite(buffer20, sizeof(buffer20[0]) , sizeof(buffer20), credit); fclose (credit);
The first one gave me a "0", and the second one gave me a "123450". How do i make it so it gives me a "1234507"?Code:char buffer20[] = { '0' }; credit = fopen ( "./files/credit.txt" , "wb" ); fseek(credit, 5, SEEK_SET); fwrite(buffer20, sizeof(buffer20[0]) , sizeof(buffer20), credit); fclose (credit);Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
03-31-2007, 10:58 AM #3597It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
would seek to the offset 5 in the file.Code:fseek(credit, 5, SEEK_SET);
The other one is invalid.
It looks to me like you're truncating the file, but I'm not sure, I've never tried to write to the middle of the file.
-
03-31-2007, 11:05 AM #3598QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
So would you happen to know what to do? I have been testing and patiently waiting for someone to help for hours, and i want to finish this before i do any other optimizations to my shell.
Zitat von Archaemic
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
03-31-2007, 11:31 AM #3599QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
wouldn't writing to the middle of the file overwrite whatevers written there?
which for now you could save whatever is after that point and re-write it after writing whatever you need 2 write there1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been
-
03-31-2007, 11:38 AM #3600QJ Gamer Bronze
- Registriert seit
- Mar 2007
- Beiträge
- 103
- Points
- 3.754
- Level
- 38
- Downloads
- 0
- Uploads
- 0
superbatxs
Take a look at...
http://www.cplusplus.com/reference/c...dio/fseek.html
It has example and it should help,


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