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 SodR When I do like this I get a "makes pointer from integer without a cast" error. I ...
-
06-06-2006, 08:46 AM #301Developer

- Registriert seit
- Oct 2005
- Beiträge
- 408
- Points
- 7.058
- Level
- 55
- Downloads
- 0
- Uploads
- 0
You'll get that if you declare "line" as an integer, but "i" should be an integer. I've used line as an array of char pointers like this:
Zitat von SodR
But this is just an example. If you want to list entries in a directory all you really need to do is loop through directory entries and send each entry individually with text_to_screen(), making sure you add to y each time to start a new line. Keep in mind that there's also no screen scrolling so when you get to the bottom of the screen you'll lose anything you print below that.Code:char *line[NUMBER_OF_LINES]; line[0] = "First line"; line[1] = "Next line"; // etc
-
06-06-2006, 09:55 AM #302Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
It might be easier to help me if I give you the full function. Here it's:
I'm going to use this as a menu where the user can select a folder that this function has printed out. Is it possible to use this so I can copy files out of the selected dir?? I mean the let's say the function displays the content of "ms0:/PSP/GAME/MYAPP/FOLDER/" and in that folder I have two subfolders called "SUBFOLDER1" and "SUBFOLDER2"./////////////////////////////////////////////////////////////////////////////
//
// Directory Listing Sample Program
// Copyright (c) 2006 Christopher Phillips <[email protected]> (aka Dr. Vegetable)
//
// This is free software, and is intended for demonstration purposes only.
// You may freely use this program or its source code as long as you assume
// all responsibility for any consequences.
//
/////////////////////////////////////////////////////////////////////////////
//
// This program demonstrates how to use the 'dirent' functions to enumerate
// the names of all files and subdirectories contained in a particular folder.
//
// The listDirectory() function does all of the interesting stuff; the
// remainder of this program is just boilerplate Sony PSP homebrew code.
//
/////////////////////////////////////////////////////////////////////////////
int listDirectory(char* szRoot)
{
// This function prints out the names of all files and directories
// contained in the szRoot directory.
// The szRoot path should be specified in the following general form:
// listDirectory("ms0:/PSP/GAME/");
// (Note trailing backslash!)
DIR* dirParent;
struct dirent* dirEntry;
int n = 0;
if ((dirParent = opendir(szRoot)) != NULL)
{
while ((dirEntry = readdir(dirParent)) != NULL)
{
set_font_color(0xFF000000 ); // black
set_font_size(15); // 15 point
set_font_angle(0.0); // no angle
// It looked like this originally (at least I think so...)
// pspDebugScreenPrintf("%d \n", dirEntry->d_name);
// I just want to do the exact same as above except I have a
// image to print the text on. (and I also want to print the first line to 350, 50
// and the next line of text to 350, 65 ect.)
// This only works if there's only one file/dir in the readdir =S
text_to_screen(dirEntry->d_name, 350, 50);
n++;
}
// No need fo this right now
// pspDebugScreenPrintf("%d files found.\n", n);
closedir(dirParent);
}
return n;
}
The function will print out "Subfolder1" and "subfolder2" to the screen and the user will select one, let's say subfolder2.
Then I want to copy a file from subfolder2, I do that with a function called copy_file (this is already done) so I want it to look like this (when the user have selected subfolder2):
copy_file("ms0:/PSP/GAME/MYAPP/FOLDER/SUBFOLDER2/", "[insertcopy-to dir here]");
(maybe you can do like this?: copy_file("ms0:/PSP/GAME/MYAPP/FOLDER/" Dirname, "[insert copy-to dir here]) Dirname sould be the selected dirs name.
I hope you understand what I mean.
btw. maybe you got a better way to solve my problem?Geändert von SodR (06-06-2006 um 11:59 AM Uhr)
-
06-06-2006, 08:29 PM #303Developer

- Registriert seit
- Oct 2005
- Beiträge
- 408
- Points
- 7.058
- Level
- 55
- Downloads
- 0
- Uploads
- 0
That makes more sense now. Here's a few small changes that will work with flib:
Zitat von SodR
I moved the font color/size/angle functions out of the loop since they only need to be set once, and added a y variable that increments by 15 (this may not be enough for 15-point to look good).Code:int listDirectory(char* szRoot) { // This function prints out the names of all files and directories // contained in the szRoot directory. // The szRoot path should be specified in the following general form: // listDirectory("ms0:/PSP/GAME/"); // (Note trailing backslash!) DIR* dirParent; struct dirent* dirEntry; int n = 0; int y = 50; set_font_color(0xFF000000 ); // black set_font_size(15); // 15 point set_font_angle(0.0); // no angle if ((dirParent = opendir(szRoot)) != NULL) { while ((dirEntry = readdir(dirParent)) != NULL) { // It looked like this originally (at least I think so...) // pspDebugScreenPrintf("%d \n", dirEntry->d_name); // I just want to do the exact same as above except I have a // image to print the text on. (and I also want to print the first line to 350, 50 // and the next line of text to 350, 65 ect.) // This only works if there's only one file/dir in the readdir =S text_to_screen(dirEntry->d_name, 350, y); n++; y += 15; } // No need fo this right now // pspDebugScreenPrintf("%d files found.\n", n); closedir(dirParent); } return n; }
This will only display the directory contents. To allow the user to navigate and select will require quite a bit more code. For one thing you're going to need to keep track of which entry is highlighted and display it differently, either a different color, larger size, drawing a box around it, etc. You'll need code to take button input and change which entry is highlighted. And when the user finally picks an item you'll need to determine what to do with it depending on what your code is intended to accomplish.
-
06-07-2006, 12:20 PM #304Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
I finally got this to work (except one thing...)
Now what I would need is to be able to use the name of the selected file (as a variable). This should go under the 'if Cross is pressed' in the main function. What I would need is like "if dirEntry->d_name = blue (blue is the color of the selected name) then...". I hope you guys can help me.
This is what it looks like:
First some global variables to make this work:
Here is my main code:Code:SceCtrlData pad; DIR* dirParent; struct dirent* dirEntry; int n = 0; int y = 50; int selected = 0; int sel = 3;
Here is the funcion:Code:int main() { blablablabla (display BG and other init functions here) if(!listDirectory("ms0:/PSP/GAME/Stuff/")) { printf("Error opening ms0:/PSP/GAME/Stuff/"); } while (1) { sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_UP) { // Move up in the list: selected = 0; y = 50; sel--; // Refresh Screen screenblit(0, 0, 480, 272, menu); listDirectory("ms0:/PSP/GAME/ThemePSP/Themes/"); flipScreen(); } sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_DOWN) { // Move down in the list: selected = 0; y = 50; sel++; // Refresh Screen screenblit(0, 0, 480, 272, menu); listDirectory("ms0:/PSP/GAME/ThemePSP/Themes/"); flipScreen(); } //This is where I don't know what to do: sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_CROSS) { //I would like to change the working dir to the name that is //selected: (like sceIoChdir(dirEntry->d_name);) //But this doesn't work since the app doesn't which name is selected } sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_CIRCLE) { sceKernelExitGame(); } sceDisplayWaitVblankStart(); } return 0; }
Another thing is that before the file/dirnames are beeing printed out to the screen the function prints out '.' and '..' (wihtout the ' '). Do you know why?Code:int listDirectory(char* szRoot) { if ((dirParent = opendir(szRoot)) != NULL) { while ((dirEntry = readdir(dirParent)) != NULL) { if (selected == sel) { // The selected name will be blue set_font_color(RGB(66,56,255)); // blue set_font_size(15); // 15 point set_font_angle(0.0); // no angle // Maybe something here? } else { // The non selected names will be black set_font_color(RGB(0,0,0)); // black set_font_size(15); // 15 point set_font_angle(0.0); // no angle } text_to_screen(dirEntry->d_name, 340, y); selected++; n++; y += 15; } // No need fo this right now // pspDebugScreenPrintf("%d files found.\n", n); closedir(dirParent); } return n;Geändert von SodR (06-07-2006 um 12:57 PM Uhr)
-
06-07-2006, 03:39 PM #305Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
You just want to work from the 3rd result to the number of results for this kind of thing.
Zitat von SodR
It's a standard thing when working with directorys.
Your n variable will also return 'number of files + 2' I think.Geändert von Insomniac197 (06-07-2006 um 03:43 PM Uhr)
-
06-08-2006, 12:51 PM #306Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Yes, I have figured that out. (btw. the n returns 'number of files +1', not 2). I have also managed to make so the user can't navigate outside the menu. The only thing left now is to edit the function so the program can see a difference between when the "text_to_screen(dirEn try->d_name, 335, y);" is selected or not. If you know how please tell me (cause I'm kinda stuck at this point).
Zitat von Insomniac197
-
06-08-2006, 03:18 PM #307words 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
I too want this, but in printf debug form...
Having a selector of a file/browser is just like a table with a pointer basically...
I can display adn read files easy, its jsut the navigation thats a biotch...
...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
-
06-09-2006, 01:21 AM #308Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Maybe we can make a function that displays the contents of a dir and put each name of a file/folder in a separate string??
Zitat von SG57
-
06-09-2006, 06:23 AM #309words 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
Thats what i was thinking, a table of strings (table = array) then print out the table with a selection in hand...
Well, it is the weekend, do you want to try SodR?
I have a couple resource sfor you to look at here at QJ that discuss File Browsing...
I already can display the contents of a directory, read files when X on select (used to be manual file name entry), and label the amount of files in a directory with a number so we could in fact make a table out of all this...
...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
-
06-09-2006, 12:46 PM #310Bush Programmer

- Registriert seit
- Nov 2005
- Beiträge
- 3.658
- Points
- 60.149
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Was someone paying forum points to sticky this?
-
06-09-2006, 12:55 PM #311Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
The mods unsticked this and created a sticky that was locked with both the lua and c++ help threads. It's idiotic if you ask me, since now we have to bump the thread ourselfs so that someone might see your post and help you instead of just looking at the stickies. And they only spared one "stickie-spot" by creating the "programing help" sticky aswell... (not much of a gain if you ask me)
Zitat von Art
-
06-09-2006, 01:53 PM #312Bush Programmer

- Registriert seit
- Nov 2005
- Beiträge
- 3.658
- Points
- 60.149
- Level
- 100
- Downloads
- 0
- Uploads
- 0
lol, agreed. I didn't notice the new sticky before.
Better to merge some of the other threads in the same way rather than this one..
Like author donation thread, how many ppl will need to bump that.
-
06-09-2006, 01:55 PM #313QJ Gamer Green
- Registriert seit
- Jan 2006
- Beiträge
- 4.289
- Points
- 25.223
- Level
- 95
- Downloads
- 0
- Uploads
- 0
Well somebody should pay forum points to sticky this ;)...
QJ loads way 2 slow & the theme is ugly as hell, gone are the glory days
-
06-09-2006, 01:56 PM #314Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Someone that has the points that is... =)
Zitat von soccerPMN
-
06-09-2006, 02:00 PM #315QJ Gamer Green
- Registriert seit
- Jan 2006
- Beiträge
- 4.289
- Points
- 25.223
- Level
- 95
- Downloads
- 0
- Uploads
- 0
That person would have to be premium ... :icon_wink
Zitat von SodR
QJ loads way 2 slow & the theme is ugly as hell, gone are the glory days
-
06-09-2006, 02:45 PM #316Bush Programmer

- Registriert seit
- Nov 2005
- Beiträge
- 3.658
- Points
- 60.149
- Level
- 100
- Downloads
- 0
- Uploads
- 0
I would pay the 2000 I have in the bank, but I hear the sticky isn't permanent when done
that way, and it costs 9900 points.
Also, I don't think it's up to any member to do it anyway, it should be supported by the site.
It's not as big a deal as I first thought.. at least there's a link to it in a sticky...
not as good, but.. oh well.
-
06-09-2006, 03:13 PM #317Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Maybe SG57 got the points? After all he was the one who started the thread.
Zitat von Art
-
06-09-2006, 06:28 PM #318
I know right now you all are trying to figureout a way to resticky this somehow, but could one of you kindly tell me why this won't even load the sample PRX...
and yes, it's nice to have a form of order around here, I think it would've been easier to have people just start new threads because finding solutions already out there are hard searching through the 100 something pages in one thread instead of using the forum search to point out a past thread with the same problem already.Code://////////////////////Loading a PRX int LoadAndStartModule_PRX(char *ModuleFILE, int UserMode)//UserMode mode: 1==true:0 == false {//start moduling SceKernelLMOption moduleprx; moduleprx.mpidtext = (UserMode+1);// 2 is equivalent to usermode ;) moduleprx.mpiddata = (UserMode+1); moduleprx.position = 0; moduleprx.access = 1;// 2 is equivalent to usermode ;) moduleprx.size = sizeof(moduleprx); SceUID PrxID=0; PrxID = sceKernelLoadModuleMs(ModuleFILE,0,UserMode > 0 ? &moduleprx : NULL);// If in usermode, don't call as NULL >:// this carrys MS for Memory Stick ;) int prxstatus=-1; if( ( sceKernelStartModule (PrxID, 0,NULL,prxstatus,moduleprx) ) !=0) {//I think this is an okay error check<- //do nothing until necessary... :), but this is upon an errors existance }//last argument is 0 for usermode! #3 is NULL because it's okay, and I don't know wtf it's it's honestly asking for... :'( //Finish MODULING: Stop & Unload Relative MODULE sceKernelStopModule(PrxID, 0, NULL,prxstatus,moduleprx); sceKernelUnloadModule(PrxID); return prxstatus; }//end moduling //////////////////////Loading a PRX
-
06-09-2006, 06:31 PM #319QJ Gamer Green
- Registriert seit
- Jan 2006
- Beiträge
- 4.289
- Points
- 25.223
- Level
- 95
- Downloads
- 0
- Uploads
- 0
whats not working with your code? ie what errors are you getting?
QJ loads way 2 slow & the theme is ugly as hell, gone are the glory days
-
06-09-2006, 07:01 PM #320words 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
SodR - I wish, i really do, wish to sticky this, but I have no where near the points to maintain such a hefty price... I agree with Soccer, Art, and you all the same...
Why take away probably the 2 most active threads on this forum away from a spot where it wont matter whethere its stickyd or not since people will just keep posting in it to bump it up, thus cluttering it...
I must say, the PSPU team this month has gone a tad downhill...
The Devhook launcher is one of them... IT does do more good then bad, but why must they start to contemplate themselves with yet another piece of news explaining how they can and will host it here? Obviously we all wernt complaining... And now this? Someone needs a bit brighter MODS....
On Topic: SodR - we need to talk! Soccer hooked me up with a dead link's file so now i have a filebrowser! Its in SDL mainly, so im converting to match pretty much gengeral C in my case...
EDIT
I have around 25 k points in the bank...
not sure if thats enough
Geändert von SG57 (06-09-2006 um 07:03 PM Uhr)

...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
-
06-09-2006, 07:21 PM #321
I'm not getting any errors, it's just that the little message the sample PRX displays won't show... and it compiles nice, but then when I apply the filename argument then run the LoadAndStart function... my screen goes black
-
06-09-2006, 07:26 PM #322QJ Gamer Green
- Registriert seit
- Jan 2006
- Beiträge
- 4.289
- Points
- 25.223
- Level
- 95
- Downloads
- 0
- Uploads
- 0
Have you tried running the PRX using PSPLink or some other app? Perhaps the PRX is messed up, and not the actual loading code.
QJ loads way 2 slow & the theme is ugly as hell, gone are the glory days
-
06-09-2006, 07:31 PM #323
Yeah, I had first compiled the PRX loader in the sample folder, read the code, studied it, and watched it... it worked.
The PRX should say "Hello from the PRX" or something like that
Okay, now I've set in NULL values in the same areas the sample did and now the screen doesn't go black, but it doesn't show the message...
PRX MODULE OPERATOR
PRX MODULE INITIATOR & CALLERCode://////////////////////Loading a PRX int LoadAndStartModule_PRX(char *ModuleFILE, int UserMode)//UserMode mode: 1==true; 0 == false; {//start moduling SceKernelLMOption moduleprx; moduleprx.mpidtext = (UserMode+1);// 2 is equivalent to usermode ;) moduleprx.mpiddata = (UserMode+1);// 2 is equivalent to usermode ;) moduleprx.position = 0; moduleprx.access = 1; moduleprx.size = sizeof(moduleprx); SceUID PrxID=0; PrxID = sceKernelLoadModuleMs(ModuleFILE,0,UserMode > 0 ? &moduleprx : NULL);// If in usermode, don't call as NULL >:// this carrys MS for Memory Stick ;) int prxstatus=-1; if( ( sceKernelStartModule (PrxID, 0,NULL,&prxstatus,NULL) ) !=0)// it was :if( ( sceKernelStartModule (PrxID, 0,NULL,&prxstatus,moduleprx) ) !=0) {//I think this is an okay error check<- //do nothing until necessary... :), but this is on an errors existance }//last argument is 0 for usermode! #3 is NULL becaus it's okay, and I don't know wtf it's it's honestly asking for... :'( //Finish MODULING: Stop & Unload Relative MODULE sceKernelStopModule(PrxID, 0, NULL,&prxstatus,NULL);// it was:sceKernelStopModule(PrxID, 0, NULL,&prxstatus,moduleprx); sceKernelUnloadModule(PrxID); return prxstatus; }//end moduling //////////////////////Loading a PRX
Code:if(Controller.Buttons & PSP_CTRL_LTRIGGER){LoadAndStartModule_PRX("ms0:/XT1_Module.prx", 0);} if(Controller.Buttons & PSP_CTRL_RTRIGGER){LoadAndStartModule_PRX("ms0:/XT1_Module.prx", 1);}Geändert von Devun_06 (06-09-2006 um 09:10 PM Uhr)
-
06-10-2006, 03:07 AM #324Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
It costs 10k to sticky a thread. But it's up to you if you want to do it.
Zitat von SG57
Devun_06: Are you sure that it's not your .prx file that it's something wrong with? And why can't you just use the sample included in the sdk?
btw. It might be time to register at psp-programming.com...Geändert von SodR (06-10-2006 um 04:02 AM Uhr)
-
06-10-2006, 09:40 AM #325
I am using the sample PRX, but it's just renamed
I even changed the sample to read it with the new name, and it still works!
This honestly makes no sense... I though I had done it right :icon_mad: ...
PLEASE HELP ME!
*and why, the only thing at that site is Yalderb's noob tutorials and a list of terms... (which btw didn't define prx&modules...
)
[email protected], I just went, when did it turn into a community???Geändert von Devun_06 (06-10-2006 um 09:46 AM Uhr)
-
06-10-2006, 10:25 AM #326words 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
When you turned less arogant... That community is very live over there... its where all the real devlopers for the PSP actually discuss there problems and acheivements... ps2dev is more lib related problems and acheivements while psp-programming.com is more of a general app and game related problems...

...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
-
06-10-2006, 12:44 PM #327
I wasn't trying to be arrogant, I just see a person who is NEW TO THIS to be a Noob, and with that I then saw the tutorials as learning aids for people who are NEW TO THIS.
Not to say I see my self as better than anyone else, but I've already completed those tutorials and I'm no longer new to this programming thing in general, just to a few pieces of it now... and in that case, I could be considered a Noob too... :icon_bigg
Although, with you guys... I do eat a lot of humble pie and would like to apologize to anyone who thinks I was trying to put them or anyone else down, I had no intentions of using it as an insult.
*in that case, what is pspupdates mainly?Geändert von Devun_06 (06-10-2006 um 12:49 PM Uhr)
-
06-10-2006, 03:37 PM #328words 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
lol, ask the forerunners of this... I came in when KXploit came out I think...

...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
-
06-10-2006, 09:48 PM #329
Alright, I guess this means psp-programming... here I come
(*lol)
-
06-15-2006, 12:12 AM #330Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
hi, i just read my first c book today, (600) pages. and i have 3 questons:
1. is the function main() like the while true do in lua?? i know that while (1) { also means while true do, but is it needed??
2. why do some people put "int main()" instead of "main"??
3. i havent yet read yeldarbs tuts, but do you have to load an image, before blitting it?? if so how?? ( in the psp)
4. whats the use of pointers? they seem useless. who want to know where a int or a char is stored??
yes i know, im a n00b at c, im gonna reread the book again 2morrow.--------------------------------------------------------------------------------------


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