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 slasher2661996 Aura im not putting it into FixItPSP i just want to play with mine (ive got PLENTY ...
-
01-02-2009, 03:06 AM #9451Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
something like that should work.Code:SceUID idDumpUID; char idFilePath[200]; u16 key; char dump[512]; for( key = 0x000; key <= 0x200; key++ ) { sceIdStorageReadLeaf( key , dump ); sprintf(idFilePath,"dump/Idstorage/0x%03X.bin",key); idDumpUID = sceIoOpen(idFilePath, PSP_O_CREAT | PSP_O_TRUNC | PSP_O_WRONLY, 0777); if( idDumpUID < 0) return -1; sceIoWrite(idDumpUID, dump, 512); if(sceIoClose(idDumpUID) < 0) return -1; }
-=Double Post Merge =-
C/C++ Programming Help Thread
I aint doing anything at all , even the untouched samples in the sdk doesnt work:s
Geändert von hallo007 (01-02-2009 um 03:14 AM Uhr) Grund: Automerged Doublepost
-
01-02-2009, 09:25 AM #9452Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
Any plugins running in the background?

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
-
01-03-2009, 08:57 AM #9453Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
nop , only my prx (wich is packed into an eboot) => that's the reason?
-
01-03-2009, 05:47 PM #9454I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
A retarded suggestion at best but... have you tried adding a delay of about 10 seconds in first? I've had simillarly strange errors in Project4 where loading something straight away failed but loading a fraction of time later worked. Try adding the delay if it still fails you've lost nothing, if its successful however play around with the time until its as low as possible. 10 seconds is overkill by any stretch but gives a sufficient time scale to test once for certainty.
-AuraGeändert von Auraomega (01-03-2009 um 05:58 PM Uhr) Grund: I got a little too punctuation happy again ^.^
-
01-03-2009, 05:59 PM #9455
Oh, that's true. I know anything I write waits until the kernel is loaded before touching a thing.
I gone and made that one power spoofer and that gay cheat device.
-
01-03-2009, 10:13 PM #9456
- Registriert seit
- Sep 2005
- Beiträge
- 33
- Points
- 4.574
- Level
- 43
- Downloads
- 0
- Uploads
- 0
hey why wont this function properly copy a file? i have been trying to write a copying function without help but i am kinda stumped. thanks guys
btw i have print defined as pspDebugScreenKprintf but when I call this function in a usermode module for some reason it wont print anything to the screen.Code:int CopyFile(char *file, char *dst){ pspDebugInstallKprintfHandler(NULL); pspDebugInstallErrorHandler(NULL); pspDebugInstallStdoutHandler(pspDebugScreenPrintData); pspSdkInstallNoPlainModuleCheckPatch(); int size = (sizeof(file)); char buffer[size]; int fd = sceIoOpen(file, PSP_O_RDONLY, 0777); if(fd < 0){print("error opening %s\n", file); return -1;} else{ int read = sceIoRead(fd, buffer, size); if(read<0){print("error reading %s into buffer\n", file); return -1;} else{ sceIoClose(fd); fclose(file); int dest = sceIoOpen(dst, PSP_O_WRONLY|PSP_O_CREAT|PSP_O_TRUNC, 0777); if(dest<0){print("error opening %s\n", dst); return -1;} else{ while(sizeof(dest) < size){ sceIoWrite(dest, buffer, size); } if(dest<0){print("error writing to %s", dst); return -1;} else{ sceIoClose(dest); print("Success! Copied %s to %s\n\n", file, dst); return 1; } }}}}
-
01-04-2009, 04:03 AM #9457I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
When reading from a file I find using malloc is the best method for creating a buffer. Also I'd suggest streaming the file rather than loading the entire thing into memory, allocate maybe 1mb and keep looping it until completes... remember the PSP has only 32mb of memory in total, and not all of that is accessible for numerous reasons, try to use as little as possible.
Yes pspDegbuScreenKprintf is a kernel function, you want pspDebugScreenPrintf for user mode/update mode/[insert any other non kernel mode]
-Aura
-
01-04-2009, 09:34 AM #9458
- Registriert seit
- Sep 2005
- Beiträge
- 33
- Points
- 4.574
- Level
- 43
- Downloads
- 0
- Uploads
- 0
-
01-04-2009, 10:02 AM #9459Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
Problems at a glance:
int size = (sizeof(file)); // You're asking for the size of a pointer (4 bytes on PSP).
fclose(file); // Where'd that come from?!?
sizeof(dest) // This is also 4 bytes, and not what you want.
If you want to get the size of a physical file in bytes, look at sceIoLseek() and friends - if you seek to the end of a file it will return the size for you.
Are you writing a user or kernel mode program?
Also, you may want to try writing well formatted code. That's one big illegible mess.
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
-
01-04-2009, 12:00 PM #9460
- Registriert seit
- Sep 2005
- Beiträge
- 33
- Points
- 4.574
- Level
- 43
- Downloads
- 0
- Uploads
- 0
thanks insert_witty_name you always have helpful comments. i am trying what you said, unfortunately i get some errors. btw the copy function is in a kernel mode prx, being called in a usermode prx. also, if i just assign flash0 within a kernel prx, can i access the flash with usermode functions?
-
01-04-2009, 12:04 PM #9461
int size = sceIoLseek(file, 0, 2); sceIoLseek(file, 0, 0);
would get you the size of the file and skip back to the beginning.I gone and made that one power spoofer and that gay cheat device.
-
01-04-2009, 12:55 PM #9462It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Symbolic constants make everything more readable.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
01-04-2009, 02:09 PM #9463
- Registriert seit
- Sep 2005
- Beiträge
- 33
- Points
- 4.574
- Level
- 43
- Downloads
- 0
- Uploads
- 0
-
01-04-2009, 02:31 PM #9464xMod.
- Registriert seit
- Oct 2008
- Ort
- Melbourne, Australia
- Beiträge
- 675
- Points
- 4.576
- Level
- 43
- My Mood
-
- Downloads
- 0
- Uploads
- 0
hi guys
i was wondering if there war any function to get the pommel,fuse id and the rest of them???
~!SlasheR!~
-
01-04-2009, 02:39 PM #9465QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- Perth, Scotland
- Beiträge
- 1.094
- Points
- 8.475
- Level
- 62
- Downloads
- 0
- Uploads
- 0
-
01-04-2009, 03:16 PM #9466
Very true, I once forgot an include and was too lazy to scroll up, so I just popped in 2. Same thing.
I gone and made that one power spoofer and that gay cheat device.
-
01-04-2009, 04:02 PM #9467I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I'm normally firmly against providing full code because people tend to copy/paste and not learn, but I've posted part of my patching for Project4 which copies files in the flash (renaming fails for various reasons, so it was the only way I could get it to work). I'm pretty sure the code will compile, the only thing I've added is the loop (my patching never required copying anything larger than 5mb).
This method removes the need to know the size of the file... dunno why I coded it like that but it worked and I never changed it; I have the same method as above in normal fileIO, just ported it to the PSP.Code:int renamePatch(char* oldFile, char* newFile) { SceUID oFile, nFile; //files, equivalent to FILE* char* buffer; //buffer to malloc int read = 0, write = 0; oFile = sceIoOpen(oldFile, PSP_O_RDONLY, 0777); //open file in read only (equivalent to r in fopen) if(oFile < 0) { return oFile; //if opening failed return error code supplied by sceIo } nFile = sceIoOpen(newFile, PSP_O_CREAT|PSP_O_WRONLY, 0777); //create and open file in read/write (equivalent to w in fopen) if(nFile < 0) { return nFile; //if opening failed return error code supplied by sceIo } buffer = (char*) malloc (5*1024*1024); //allocate 5mb of user memory for patching pureposes if(buffer == NULL) //if buffer address is null allocation failed { return 0x800000FF; //random error code I created } read = sceIoRead(oFile, buffer, 5*1024*1024); //read up to 5mb in size if(read == 0) { free(buffer); //free the allocated 5mb of user memory, avoid memory leak! return 0x80AA00AA; //random error code I created } while(1) { if(read <= 0) { break; //if read is equal to or less (somehow) than 0 } { write = sceIoWrite(nFile, buffer, read); if(write != read) { //if data written isn't same length as data read return an error return 0x80BB00BB; //random error code I created } } read = sceIoRead(oFile, buffer, 5*1024*1024); //read up to 5mb in size } //close files, same method as fclose sceIoClose(nFile); sceIoClose(oFile); free(buffer); //free the allocated 5mb of user memory, avoid memory leak! return 1; }
You can write to flash0 without being in kernel mode, you'll need to be in updater mode/extended mode... whatever people call it, which is 0x800, this gives you flash read/write capabilites in a user module. Finally, you'll need to assign the flash0 in read/write mode. Really, theres no need for the above to be in kernel mode (if thats what you were intending).
Hopefully thats of some help just don't copy and paste it :)
-Aura
-
01-05-2009, 04:15 PM #9468
- Registriert seit
- Sep 2005
- Beiträge
- 33
- Points
- 4.574
- Level
- 43
- Downloads
- 0
- Uploads
- 0
for some reason that function still just makes the file but the new file is 0kb
-
01-05-2009, 04:28 PM #9469
Doesn't use malloc, but it works fine for me.Code:int copy_file(char *src_file, char *dst_file) { /* Found it in my archives of source * I think Anti-QuickJay wrote this * */ unsigned char buffer[40]; SceUID infd = sceIoOpen(src_file, PSP_O_RDONLY, 0777); SceUID outfd = sceIoOpen(dst_file, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); int bytesread; if (infd < 0 || outfd < 0) { pspDebugScreenClear(); sceIoRemove(dst_file); sceKernelDelayThread(5*1000*1000); sceKernelExitGame(); } while ((bytesread = sceIoRead(infd, buffer, 8192)) > 0) { sceIoWrite(outfd, buffer, bytesread); } sceIoClose(infd); sceIoClose(outfd); return 0; }I gone and made that one power spoofer and that gay cheat device.
-
01-05-2009, 04:53 PM #9470
- Registriert seit
- Sep 2005
- Beiträge
- 33
- Points
- 4.574
- Level
- 43
- Downloads
- 0
- Uploads
- 0
thanks man this works great
-
01-05-2009, 05:16 PM #9471QJ Gamer Blue
- Registriert seit
- Sep 2005
- Ort
- Chigasaki, Japan
- Beiträge
- 226
- Points
- 4.980
- Level
- 45
- Downloads
- 0
- Uploads
- 0
How do you fit 8K into a 40byte buffer?Code:int copy_file(char *src_file, char *dst_file) { ... unsigned char buffer[40]; ... while ((bytesread = sceIoRead(infd, buffer, 8192)) > 0) ... }
-
01-06-2009, 12:36 AM #9472xMod.
- Registriert seit
- Oct 2008
- Ort
- Melbourne, Australia
- Beiträge
- 675
- Points
- 4.576
- Level
- 43
- My Mood
-
- Downloads
- 0
- Uploads
- 0
-
01-06-2009, 08:19 AM #9473I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Buffer overflow? Exceptionally large char? I noticed this but thought I was missing something else, seems I'm not the only one who got a bit worried. This is why I prefer using malloc as you can do on the fly memory allocation and expand on the memory as you need (within reason).
-Aura
-
01-06-2009, 10:19 AM #9474QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Hi
I have problems setting up the environment paths. When I try to compile this example he tells me
where c:/dev/pspsdk/ is my path to my minPSPw installation (I have a full cygwin-installation, but minPSPw promised to come with a lot of libraries so I wanted to give it a shot), anyways, the files he needs are all in "freetype2/freetype" in the same directory as ft2build.h.c:/dev/pspsdk/lib/gcc/../../psp/include/ft2build.h (56) :38: error: freetype/config/ftheader.h: No such file or directory
How do I tell him where to find it?
-
01-06-2009, 10:32 AM #9475Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
Instead of linking -lfreetype in the Makefile, do something like this instead:
You may also need to do the following in the CFLAGS too:Code:$(shell $(PSPBIN)/bin/freetype-config --libs)
Finally, you'd be a lot better using pgeFont than Fontloader, search these forums for it.Code:$(shell $(PSPBIN)/bin/freetype-config --cflags)

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
-
01-07-2009, 03:47 AM #9476QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- Germany
- Beiträge
- 216
- Points
- 4.511
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Thanks insomaniac, I'll try pgeFont. But the Makefile still won't work. I only get errormessages:
psp-gcc -I. -IC:/dev/pspsdk/psp/sdk/include -O2 -G0 -Wall -g -D_PSP_FW_VERSION=150 -c -o ../../pgeFont.o ../../pgeFont.c
process_begin: CreateProcess((null), /bin/freetype-config --cflags, ...) failed.
process_begin: CreateProcess((null), /bin/freetype-config --libs, ...) failed.
[...]
-
01-07-2009, 12:33 PM #9477
Well that is because you have to change your makefile according to pgeFont.
I am not sure what libs it uses so I cannot help you there.
-
01-07-2009, 12:39 PM #9478QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
No, it's because PSPBIN isn't defined as an environment variable, so it can't find the executable 'freetype-config'. You have too options:
- Export PSPBIN as an environment variable to your SDKs bin path.
- Get rid of "$(PSPBIN)" and just type out the entire path to the freetype-config executable.
-
01-07-2009, 12:45 PM #9479
Okay. Sorry i did not know that pgeFont used 'freetype-config'. :Cry:
-
01-07-2009, 02:16 PM #9480QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
>_>psp-gcc -I. -IC:/dev/pspsdk/psp/sdk/include -O2 -G0 -Wall -g -D_PSP_FW_VERSION=150 -c -o ../../pgeFont.o ../../pgeFont.c
process_begin: CreateProcess((null), /bin/freetype-config --cflags, ...) failed.
process_begin: CreateProcess((null), /bin/freetype-config --libs, ...) failed.
[...]


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