Refresh main function?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
pj1115
Posts: 23
Joined: Mon Jan 22, 2007 4:46 am

Refresh main function?

Post by pj1115 »

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)?
jas0nuk
Posts: 137
Joined: Thu Apr 27, 2006 8:00 am

Post by jas0nuk »

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

Code: Select all

void main(void) {
start:
printf("blah/n");
// do stuff
if (...) goto start;
}
pj1115
Posts: 23
Joined: Mon Jan 22, 2007 4:46 am

Post by pj1115 »

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

Code: Select all

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! :)
pj1115
Posts: 23
Joined: Mon Jan 22, 2007 4:46 am

Post by pj1115 »

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: Select all

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?
User avatar
pailes
Posts: 16
Joined: Fri Feb 16, 2007 4:31 am
Contact:

Post by pailes »

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
pj1115
Posts: 23
Joined: Mon Jan 22, 2007 4:46 am

Post by pj1115 »

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
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

Using lables and goto - bad style. I prefer:

Code: Select all

for(...;...;...)
{
    ...
    if(...) continue;
    ...
}
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

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.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

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
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
Post Reply