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 Archaemic If you're using SEEK_SET and you start counting from 0, yes. Thanks for the info Archaemic :) ...
-
12-30-2007, 11:55 AM #7321Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Thanks for the info Archaemic :)
Zitat von Archaemic
Would this code work as it is?Code:char gameid[40]; target = sceIoOpen("disc0:/PSP_GAME/SYSDIR/UPDATE/PARAM.SFO", PSP_O_WRONLY, 0777); gameid = sceIoLseek(target, 362, SEEK_SET); sceIoClose(target);
Geändert von eldiablov (12-30-2007 um 12:50 PM Uhr)
-
12-30-2007, 01:10 PM #7322Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
You might want to actually use sceIoRead to read something too.
Also, error check that the file is actually opened etc.
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
-
12-30-2007, 01:15 PM #7323Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Zitat von Insert_Witty_Name
The check will be put in place; but is that correct for now? I just want to make sure I actually understand the functions.Code:int a; char gameid[40]; target = sceIoOpen("disc0:/PSP_GAME/SYSDIR/UPDATE/PARAM.SFO", PSP_O_WRONLY, 0777); gameid = sceIoLseek(target, 362, SEEK_SET); a = sceIoRead(target, void *gameid, 40); sceIoClose(target);
-
12-30-2007, 01:33 PM #7324
- Registriert seit
- Nov 2007
- Ort
- PSP-Development
- Beiträge
- 11
- Points
- 2.935
- Level
- 33
- Downloads
- 0
- Uploads
- 0
did someone ever added a png background to filebrowser.h?
the png showed up fine but no text at all.
also im wondering if there is a sample how to load a prx from a 3.xx app.
obvious i need a external kmode prx with the loader funktion which i load from my usermode app. any hints?
thanks in advance
-
12-30-2007, 01:40 PM #7325
That's probably because you blitted the text before the background. Try blitting the background first.
Zitat von Team-3GO
[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.
-
12-30-2007, 02:14 PM #7326It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
No, it's not.
Zitat von eldiablov
Note that this code has NO checks as it is, and that I have no clue if that offset or length is correct. There is also a chance that gameid won't be NULL-terminated after the read, so be careful.Code:char gameid[40]; target = sceIoOpen("disc0:/PSP_GAME/SYSDIR/UPDATE/PARAM.SFO", PSP_O_RDONLY, 0777); sceIoLseek(target, 362, SEEK_SET); sceIoRead(target, (void *) gameid, 40); sceIoClose(target);
Note! I changed PSP_O_WRONLY to PSP_O_RDONLY. This is an important change, even if it is easy to miss!pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
12-30-2007, 03:20 PM #7327I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Anyone?
Zitat von Auraomega
Also, I'm having a really odd problem, since I've started using intraFont I can't load games when running in VSH mode, only when running in GAME mode, which is causing obvious problems for Project4.
-Aura
-
12-30-2007, 03:20 PM #7328QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Why isn't this working?
Code:char xoptions[7]; FILE *options; if ((options = fopen("./files/options.txt","rb")) == NULL) { printf("Please Check Your Options.txt"); } xoptions[fread(xoptions, 1, 4, options)] = 0; fclose(options); xoptions[7]=0; //Cpu switch(xoptions[0]) { case 's': cpudisplay = 111; break; case 'n': cpudisplay = 222; break; case 'f': cpudisplay = 333; break; } CpuPower(cpudisplay, cpudisplay, cpudisplay/2);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...)
-
12-30-2007, 04:06 PM #7329
whats that for some f****d up code ?!
Zitat von TMNT
this will do it aswell:if ((options = fopen("./files/options.txt","rb")) == NULL)
{
printf("Please Check Your Options.txt");
}
but this is a better coding style:if (fopen("./files/options.txt","rb") == NULL)
{
printf("Please Check Your Options.txt");
}
and please tell me what this is supposed to be:if (!fopen("./files/options.txt","rb"))
{
printf("Please Check Your Options.txt");
}
?!?!xoptions[fread(xoptions, 1, 4, options)] = 0;
this will in the best case equal to:
o_Oxoptions[4] = 0;
next is:
char array with 7 elements, yet you try to write to the 8th element, note it starts from zero ;)char xoptions[7];
..
..
..
xoptions[7]=0;
you sure what you're doing ?
ah and to know what exactly went wrong would be good to know too as I see many possibilities why this doesn't work the way it is meant to be ;)robot mafia
-
12-30-2007, 04:26 PM #7330QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- In a houuuuuuuuuuse.
- Beiträge
- 680
- Points
- 15.527
- Level
- 80
- Downloads
- 0
- Uploads
- 0
I need help, When I go to to compile in linux I get this:
[email protected]:/usr/local/pspdev/projects/counter# make
make: psp-config: Command not found
Makefile:12: /lib/build.mak: No such file or directory
make: *** No rule to make target `/lib/build.mak'. Stop.
this is my Makefile:
I followed This Tutorial.TARGET = count
OBJS = main.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Counter
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Can anyone help?PSPlay Developer
-
12-30-2007, 04:49 PM #7331It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
echo 'export PSPDEV=/usr/local/pspdev' >> ~/.bashrc
echo 'export PATH=$PATH:$PSPDEV/bin' >> ~/.bashrc
Make sure to use apostrophes and not quotes.
Also, I wouldn't follow tommydanger's advice on the fopen line--all that does is check if the file can be opened, and discard the file handle if it can be opened. What a waste. You can only have 9 or so file handles open at once, so don't waste them.pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
12-30-2007, 05:35 PM #7332QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- In a houuuuuuuuuuse.
- Beiträge
- 680
- Points
- 15.527
- Level
- 80
- Downloads
- 0
- Uploads
- 0
thanks
where do I add that?
or do I put it in the terminal?
I tried and it and nothing worked?
What fopen line?PSPlay Developer
-
12-30-2007, 06:05 PM #7333It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
You have to restart the terminal after entering that in. Paste what happens when you enter
tail ~/.bashrc
into the terminal
Also, the fopen line thing was not directed at you.pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
12-30-2007, 06:22 PM #7334QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- In a houuuuuuuuuuse.
- Beiträge
- 680
- Points
- 15.527
- Level
- 80
- Downloads
- 0
- Uploads
- 0
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
that shows up
-= Double Post =-
After i did "make" I get this now:
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150 -c -o main.o main.c
main.c: In function ‘main’:
main.c:51: error: expected expression before ‘[’ token
main.c:53: error: expected ‘;’ before ‘}’ token
main.c:46: warning: unused variable ‘i’
main.c:45: warning: unused variable ‘counter’
main.c: At top level:
main.c:55: error: expected identifier or ‘(’ before ‘while’
make: *** [main.o] Error 1
Spoiler for SOURCE:
any ideas?Geändert von amrcidiot (12-30-2007 um 06:27 PM Uhr) Grund: Automerged Doublepost
PSPlay Developer
-
12-30-2007, 06:27 PM #7335It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Well...then just open ~/.bashrc with your text editor and type in this as the last two lines:
export PSPDEV=/usr/local/pspdev
export PATH=$PATH:$PSPDEV/binpəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
12-30-2007, 06:37 PM #7336QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- In a houuuuuuuuuuse.
- Beiträge
- 680
- Points
- 15.527
- Level
- 80
- Downloads
- 0
- Uploads
- 0
it already was
but ithink that no,it's just a script error
could u take a look at it in the post above you last one?PSPlay Developer
-
12-30-2007, 07:43 PM #7337QJ Gamer Blue
- Registriert seit
- Sep 2005
- Ort
- Chigasaki, Japan
- Beiträge
- 226
- Points
- 4.980
- Level
- 45
- Downloads
- 0
- Uploads
- 0
FWIW, while strings are null terminated, fprintf does not write the terminator to the stream. Meaning only 'n' is written.
Zitat von yaustar
-
12-31-2007, 06:45 AM #7338Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
hi i have a couple of problems with my code
problem one is that i know it wont return how i want it too and
problem two is that i dont think it is set out right either
i would like to enter a scan code and then if the scan code is right i.e. it is being pressed make the function return 1 aka true but how would i do this because my code isnt doing it at the moment here is what i have
i highlighted the section im having trouble with in boldCode:static int lua_irKeybInit(lua_State *L) { if (lua_gettop(L) != 2) return luaL_error(L, "path, kernel mode"); const char *path = luaL_checkstring(L, 1); int kernel = luaL_checkint(L, 2); pspIrKeybInit(path, kernel); return 0; } static int lua_irKeybGetKey(lua_State *L) { if (lua_gettop(L) != 1) return luaL_error(L, "key"); int character = luaL_checkint(L, 1); pspIrKeybOutputMode(PSP_IRKBD_OUTPUT_MODE_SCANCODE); unsigned char raw; unsigned char buffer[255]; SIrKeybScanCodeData * scanData; int i, length, count; pspIrKeybReadinput(buffer, &length); count = length / sizeof(SIrKeybScanCodeData); for( i=0; i < count; i++ ) { scanData=(SIrKeybScanCodeData*) buffer+i; raw = scanData->raw; if( raw == character) return 1; }; return 0; } static int lua_irKeybFinish(lua_State *L) { pspIrKeybFinish(); return 0; }
thanks------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
12-31-2007, 08:14 AM #7339QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
i aint seein nun highlighted bit
-
12-31-2007, 09:11 AM #7340QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Alright, first of all, it doesn't work at all. However, the fread and all that works (it reads contents of file and stores it into an array). The problem i was having was with the "switch" part. Also, if i do it the "better coding style" one, it gives me an error that options is uninitialized. Finally, when did i say i wanted to write to the eight element? I want to READ the first element. Notice the "switch" xoptions[0], meaning read the first element and do the following actions. That's the part that i can't get working.
Zitat von tommydanger
Edit: OMG! I got it working!!! Yes! Lol, it's the stupidest thing that no one could figure out. To Archaemic and tommydanger, thanks for trying to help me out, and thanks Archaemic for helping me learn the switch statements (better than a bunch of else if's). Anyways, here's the full code:
Code://Open File Once char xoptions[4]; FILE *options; if ((options = fopen("./files/options.txt","rb")) == NULL) { printf("Please Check Your Options.txt"); } xoptions[fread(xoptions, 1, 4, options)] = 0; fclose(options); //xoptions[4]=0; -----This Part Was Causing the Problem //Cpu switch(xoptions[0]) { case 's': cpudisplay = 111; break; case 'n': cpudisplay = 222; break; case 'f': cpudisplay = 333; break; } CpuPower(cpudisplay, cpudisplay, cpudisplay/2);Geändert von SuperBatXS (12-31-2007 um 09:25 AM Uhr)
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...)
-
12-31-2007, 10:02 AM #7341QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
It doesn't? Opps. In that case, I am not 100% sure what was causing the crash.
Zitat von kuroneko
-= Double Post =-
@tommydanger: It is a matter of preference checking pointers against NULL rather then using the not operator. I much prefer the checking against NULL because that immediately tells me that the code is checking a pointer. I normally reserve the use of the not operator for bools.
@TMNT: Of course if would cause problems:
Take a look at the size of the array and the element you are trying to write to. As tommydanger said, arrays are 0 based which means you were trying to write to the 5th element of the array which is undefined memory and therefore *may* crash or at least give undefined behaviour.Code:char xoptions[4]; xoptions[4]=0;
Geändert von yaustar (12-31-2007 um 10:07 AM Uhr) Grund: Automerged Doublepost
[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]
-
12-31-2007, 10:13 AM #7342QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Exactly. I need to embrace and utilize my knowledge of arrays more. I was so worried at that time that i couldn't solve the more basic problems...
Zitat von yaustar
Well, glad that's over. :)
I have already found a way to encrypt my txt files for extra security (already tested and working without problems)!
-Thanks everyone for helping me out! ;)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...)
-
12-31-2007, 10:28 AM #7343Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
this bit
Zitat von Xsjado7
Code:static int lua_irKeybGetKey(lua_State *L) { if (lua_gettop(L) != 1) return luaL_error(L, "key"); int character = luaL_checkint(L, 1); pspIrKeybOutputMode(PSP_IRKBD_OUTPUT_MODE_SCANCODE); unsigned char raw; unsigned char buffer[255]; SIrKeybScanCodeData * scanData; int i, length, count; pspIrKeybReadinput(buffer, &length); count = length / sizeof(SIrKeybScanCodeData); for( i=0; i < count; i++ ) { scanData=(SIrKeybScanCodeData*) buffer+i; raw = scanData->raw; if( raw == character) return 1; }; return 0; }------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
12-31-2007, 11:25 AM #7344QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
As for the configuration files, I wrote a configuration parser that someone can use if they want. The configuration file format is '.jpc'. They look like this:
It's in C++, but all the i/o is in C, so it should be easy to convert it from a class to something more C worthy.# A Comment
# Another Comment
option "aconfigoption" 'i'
{
7
}
option "aconfigoption2" 's'
{
"seven"
}
-
12-31-2007, 12:17 PM #7345QJ 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
does this support floats?
Zitat von _dysfunctional
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
12-31-2007, 12:38 PM #7346
you see how it says
Zitat von amrcidiot
main.c:51: error: expected expression before ‘[’ token
that means check line 51 in file main.c. if you check the spoiler you'll see the problem. After you fix that problem try compiling it again
-
12-31-2007, 02:07 PM #7347QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
No, but it would more than easy to add them. I wrote it for a mini http server I made, so I had no need for floats, it would work the same as how the integers are loaded, except you would change the fscanf call to load a float, and change the type to 'f'.
Zitat von BlackShark
-
12-31-2007, 04:17 PM #7348
Could you post the code to that, or send me a copy? I'd like to see it.
Zitat von _dysfunctional
[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.
-
12-31-2007, 07:38 PM #7349QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
To miniHttp or the configuration loader with floats implemented?
-
12-31-2007, 08:34 PM #7350
Sorry, but looks like you already posted it. I feel retarded for not noticing it. Nevermind.
Zitat von _dysfunctional
[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.


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