forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Refresh main function?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
pj1115



Joined: 22 Jan 2007
Posts: 23

PostPosted: Tue Feb 20, 2007 4:09 am    Post subject: Refresh main function? Reply with quote

Hey

Quick question:
If I was in the middle of the main function, would there be a way to start from the beginning again, like restart it? (ie, could I use main(); or is there another way)?
Back to top
View user's profile Send private message
jas0nuk



Joined: 27 Apr 2006
Posts: 137

PostPosted: Tue Feb 20, 2007 4:47 am    Post subject: Reply with quote

It's better to use a while loop, but you could use labels
e.g.

Code:
void main(void) {
start:
printf("blah/n");
// do stuff
if (...) goto start;
}
Back to top
View user's profile Send private message
pj1115



Joined: 22 Jan 2007
Posts: 23

PostPosted: Tue Feb 20, 2007 5:25 am    Post subject: Reply with quote

jas0nuk wrote:
It's better to use a while loop, but you could use labels
e.g.

Code:
void main(void) {
start:
printf("blah/n");
// do stuff
if (...) goto start;
}


Thanks a bunch, jas0nuk!

Expect a release from me in a few hours! :)
Back to top
View user's profile Send private message
pj1115



Joined: 22 Jan 2007
Posts: 23

PostPosted: Tue Feb 20, 2007 5:32 am    Post subject: Reply with quote

Oh, and I have another question.

I'm not using callbacks (so there's no "Do you want to exit the game?" screen), and in my program I'm using:
Code:
if(pad.Buttons & PSP_CTRL_HOME) {
                pspDebugScreenClear();
                printf("\n\n\n\n\n\n\n\n\n\n Bye, Bye! \n\n"
                "- This has been a pj1115 production!");


      sceKernelDelayThread(10*1000*1000);

      sceKernelExitGame();
}


But when I press [Home], it doesn't do anything. Is there something wrong with my code?
Back to top
View user's profile Send private message
pailes



Joined: 16 Feb 2007
Posts: 16

PostPosted: Tue Feb 20, 2007 6:25 am    Post subject: Reply with quote

Your program needs to run in kernel mode when you want to catch the home button. I had the same problem recently.

Check this:
http://forums.ps2dev.org/viewtopic.php?t=7663
Back to top
View user's profile Send private message Visit poster's website
pj1115



Joined: 22 Jan 2007
Posts: 23

PostPosted: Tue Feb 20, 2007 7:47 am    Post subject: Reply with quote

Thanks, worked like a charm!

I'm releasing it now, it's called 'Outa-Space PSP'.

Here's the download, and I've submitted it to QJ.
http://www.sendspace.com/file/as9nxq
Back to top
View user's profile Send private message
Cy-4AH



Joined: 31 Jan 2007
Posts: 44
Location: Belarus

PostPosted: Tue Feb 20, 2007 6:49 pm    Post subject: Reply with quote

Using lables and goto - bad style. I prefer:
Code:

for(...;...;...)
{
    ...
    if(...) continue;
    ...
}
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Wed Feb 21, 2007 9:22 am    Post subject: Reply with quote

Using labels and gotos is only considered bad style if you buy into the whole "structured" programming style. If you aren't trying to be 100% structured, there's absolutely nothing bad about using labels and gotos in any manner at all.

I think they push structured programming style too much these days. It's one of the main contributors to code bloat.
Back to top
View user's profile Send private message AIM Address
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Wed Feb 21, 2007 6:23 pm    Post subject: Reply with quote

You'll find a lot of debate about goto/labels...
In certain cases, and if you're a good programmer, you can make clean and efficient use of goto and labels; the Linux kernel for example uses them frequently for clean error handling.
But for most new programmers, it's recommended that you just steer clear of them completely, as they can quickly lead to bad habits and keep you from learning other useful code structures like do/while, switch/case, etc.
Back to top
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Wed Feb 21, 2007 6:33 pm    Post subject: Reply with quote

not to mention you goto somewhere; and you miss closing
a file pointerf or even opening one :P ....this is most common
problem

memory drip drip drip
_________________
10011011 00101010 11010111 10001001 10111010
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Wed Feb 21, 2007 6:50 pm    Post subject: Reply with quote

dot_blank wrote:
not to mention you goto somewhere; and you miss closing a file pointerf or even opening one :P ....this is most common problem

memory drip drip drip


These "problems" and "bad habits" people like to claim are more prevalent in non-structured programs are just as common in structured programs in my experience. Not closing files or freeing memory is due to a poorly constructed program, not the style of construction.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group