Welcome! Log In Create A New Profile

Advanced

How do I exit the GUI in libwiigui?

Posted by Tonyyyyyyy 
How do I exit the GUI in libwiigui?
July 21, 2010 10:43PM
How can I exit the GUI, to go to the console?
For example, I'm trying to implement ELF/DOL launching, and to do that, I need to exit the GUI, call the launch function, and then restart the GUI.

Also, when I exit, I want to print "Exiting" to the screen.
However, when I exit, the screen turns black for a second, and returns to the Homebrew Channel.

Code:
int
main(int argc, char *argv[])
{
	InitVideo(); // Initialize video
	SetupPads(); // Initialize input
	InitAudio(); // Initialize audio
	fatInitDefault(); // Initialize file system
	InitFreeType((u8*)font_ttf, font_ttf_size); // Initialize font system
	InitGUIThreads(); // Initialize GUI

	DefaultSettings();
	MainMenu(MENU_SETTINGS);
	
	VIDEO_Init();
	
	WPAD_Init();
	
	rmode = VIDEO_GetPreferredMode(NULL);

	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);

	VIDEO_Configure(rmode);

	VIDEO_SetNextFramebuffer(xfb);
	
	VIDEO_SetBlack(FALSE);

	VIDEO_Flush();

	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

	printf("\x1b[2;0H");
	
	printf("\n\n\n\n\n\n\nGUI Exited.\n");
	printf("Press any key to exit...\n");
	
	while(true)
	{
		printf(" ... ");
		sleep(500);
		
		WPAD_ScanPads();
		
		u32 pressed = WPAD_ButtonsDown(0);
		
		if(pressed)
			exit(0);
			
		VIDEO_WaitVSync();
	}
	
	return 0;
}



Edited 1 time(s). Last edit at 07/21/2010 11:02PM by SifJar.
Re: How do I exit the GUI in libwiigui?
July 21, 2010 11:02PM
Please use
 tags in future.
Re: How do I exit the GUI in libwiigui?
July 21, 2010 11:22PM
Quote
SifJar
Please use
 tags in future.

Thanks for editing, but unfortunately, that doesn't solve my question. :P
Re: How do I exit the GUI in libwiigui?
July 21, 2010 11:29PM
Sorry, can't help there, I don't know much about coding. :P
Re: How do I exit the GUI in libwiigui?
July 22, 2010 02:14AM
why do you need to exit the gui to load a dol? the 2 things are completely unrelated. and then you want to start up the gui again? this makes no sense.
Re: How do I exit the GUI in libwiigui?
July 22, 2010 02:20AM
I don't need to???
But I still want to exit to the console...
Re: How do I exit the GUI in libwiigui?
July 22, 2010 10:04AM
I think the better way is to display the "Exiting" into Libwiigui and not into a console.

Generally, you mustn't mix Console and GUI application.
Re: How do I exit the GUI in libwiigui?
July 22, 2010 06:51PM
Well, I tried to launch a DOL...and the bg music on libwiigui started "lagging", like
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

I don't really know how to explain it. O_O
I also need the console to debug my load function, so I'll know what's wrong.

Is there a problem with my code?

dol.c
 
 /*
  * @author: Tonyyyyyyy
  * 
  * @summary:  This file provides functions for launching DOLs.
  * @origin: Based off of *cough* ripped off of *cough* geckoloader.
  *
  * @date: 7.19.2010
 */
 
 #include "dol.h"

// This is from geckoloader...
// this code was contributed by shagkur of the devkitpro team, thx!

typedef struct _dolheader {
	u32 text_pos[7];
	u32 data_pos[11];
	u32 text_start[7];
	u32 data_start[11];
	u32 text_size[7];
	u32 data_size[11];
	u32 bss_start;
	u32 bss_size;
	u32 entry_point;
} dolheader;

u32 load_dol_image (void *dolstart) {
	u32 i;
	dolheader *dolfile;

	if (dolstart) {
		dolfile = (dolheader *) dolstart;
		for (i = 0; i < 7; i++) {
			if ((!dolfile->text_size) || (dolfile->text_start < 0x100))
                continue;
\
			ICInvalidateRange ((void *) dolfile->text_start,
                                                    dolfile->text_size);
			memmove ((void *) dolfile->text_start,
                                 dolstart+dolfile->text_pos,
                                 dolfile->text_size);
		}

		for(i = 0; i < 11; i++) {
			if ((!dolfile->data_size) ||
                            (dolfile->data_start < 0x100))
                                continue;

			memmove ((void*) dolfile->data_start,
                                 dolstart+dolfile->data_pos,
                                 dolfile->data_size);
			DCFlushRangeNoSync ((void *) dolfile->data_start,
                                            dolfile->data_size);
		}
		
		memset ((void *) dolfile->bss_start, 0, dolfile->bss_size);
		DCFlushRange((void *) dolfile->bss_start, dolfile->bss_size);

        return dolfile->entry_point;
	}

    return 0;
}

#include "launch.h"

//extern void __exception_closeall();
//extern s32 __IOS_ShutdownSubsystems();

s32 getImageType(void * addr)
{
	Elf32_Ehdr *ehdr; /* Elf header structure pointer */

    ehdr = (Elf32_Ehdr *) addr;

    if (!IS_ELF (*ehdr))
        return 0;

    if (ehdr->e_type != ET_EXEC)
        return -1;

    if (ehdr->e_machine != EM_PPC)
        return -1;

    return 1;
}

int launch(char locdir[999], char filname[13])
{
/*
	//Set this...
	unsigned int i;
	
	for(i = 0; i < strlen(locdir); i++)
	{
		if((i+1) != strlen(locdir))
			locdir = locdir[i +1];
		else
			locdir = '/';
	}
	printf("%s", locdir);
	sleep(5000);*/
	//Variables
	/*
	FATFS ffs;
	DIR appdir;
	
	char filename[50+1];
	char thefile[1][50];
	FILINFO finfo;
	FIL fp;
	
	WORD bytes_read;
	u32 bytes_read_total;
	u8 *data = (u8 *)0x92000000;
	*/
	s32 res;
	u32 level;
	
	if(!fatInitDefault())
	{
		//Error handler here...
	}
	
	//ELF/DOL buffer
	void * buffer;
	//Entry point
	void (*ep)();
	
	char formatted[999];
	
	sprintf(formatted, "%s/%s", locdir, filname);
	
	//Mount FAT FS
	
	//if(f_mount(0, &ffs) != FR_OK)
		//return -1;
		
	//res = f_opendir(&appdir, locdir);
	
	//if(res != FR_OK)
		//return -1;
		
	FILE * inputFile;
	
	inputFile = fopen(formatted, "rb");
	
/*	
	memset(&finfo, 0, sizeof(finfo));
	f_readdir(&appdir, &finfo);
	
	while(strlen(finfo.fname) != 0)
	{
		if(strtoupper(finfo.fname) == strtoupper(filname))
		{
			memcpy(thefile[0], finfo.fname, strlen(finfo.fname));
			printf(thefile[0]);
			sleep(5000);
		}
		
		f_readdir(&appdir, &finfo);
	}
	snprintf(filename, 50, "%s%s", locdir, filname);
	
	//"Pre-checking" phase
	if(f_stat(filename, &finfo) != FR_OK)
		return -1;
	if(f_open(&fp, filename, FA_READ) != FR_OK)
		return -1;
	*/
	
	int pos = ftell(inputFile);
	fseek(inputFile, 0, SEEK_END);
	int size = ftell(inputFile);
	fseek(inputFile, pos, SEEK_SET);
	
	buffer = malloc(size);
	
	fread(buffer, 1, size, inputFile);
	
	//Now that we're done with our checks, let's start reading the file.
	//bytes_read = bytes_read_total = 0;
	
	res = getImageType(buffer);
	
	if(res == 1)//ELF
	{
		
	}
	else//Probably a DOL...
	{
		ep = (void(*)())load_dol_image(buffer);
	}
	fclose(inputFile);
	
	__IOS_ShutdownSubsystems();
	_CPU_ISR_Disable (level);
	__exception_closeall ();
	//This is it!
	ep();
	//And we're back.
	_CPU_ISR_Restore (level);
	
	//Successful?
	return 0;
}

int test()
{
	return 1;
}
Re: How do I exit the GUI in libwiigui?
July 22, 2010 07:00PM
Well, first of all you can't do what you're doing in main:

starting video, input, sound.
launch gui
start video, input, and bring up a console.


See a problem here? You can't just reinit the video and input like that. The advice to stay within the GUI is the right one. If you want to debug the DOL loading code, start by putting it in a separate app with ONLY a console and make sure you understand how it works and that it doesn't crash.
Re: How do I exit the GUI in libwiigui?
July 23, 2010 11:18AM
In fact, Your sound is lagging because you are playing the sound, loading the dol and display the UI in the same thread.
This is a very bad idea. I think you must play the sound and load the doal in a different Thread.

Then when the dol is ready to launch (ie loaded into the wii memory), in the UI thread, close all and start the dol.
Re: How do I exit the GUI in libwiigui?
July 23, 2010 08:43PM
AH!
That's a very good idea!
I've been trying to exit the GUI by shutting down audio and video, and it didn't seem to be working. :P
I'll try it with threads, and I'll get back to you.
Sorry, only registered users may post in this forum.

Click here to login