示例#1
0
static void * GeckoThread(void *arg)
	{
	stopNetworkThread = 0;
	errors = 0;
	
	LWP_SetThreadPriority(geckothread, 8);
	
	printopt("gecko thread running, ready !");

	if (usb_isgeckoalive (EXI_CHANNEL_1))
		{
		wiiload.gecko = 1;
		while (!stopGeckoThread)
			{
			if (!GeckoLoad ())
				usb_flush (EXI_CHANNEL_1);
				
			usleep (100);
			}
		}
	else
		while (!stopGeckoThread)
			{
			usleep (250000);
			}
		
	printopt("exiting gecko thread...");

	stopGeckoThread = 2;

	return 0;
	}
示例#2
0
int main()
{
	void *xfb;
	GXRModeObj *rmode;
	lwp_t handle;
	int r;
	char *stack;

	IOS_ReloadIOS(30);

	VIDEO_Init();

	switch(VIDEO_GetCurrentTvMode())
	{
		case VI_NTSC:
			rmode = &TVNtsc480IntDf;
			break;

		case VI_PAL:
			rmode = &TVPal528IntDf;
			break;

		case VI_MPAL:
			rmode = &TVMpal480IntDf;
			break;

		default:
			rmode = &TVNtsc480IntDf;
			break;
	}

	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 1
	printf("Calling main()\n");
	main_real();
	printf("main() returned\n");
#else
	printf("Creating main thread\n");

	stack = malloc(1024*1024);
	if (stack == 0)
	{
		printf("Unable to allocate stack\n");
		while(1);
	}

	handle = 0;
	r = LWP_CreateThread(&handle, main_real, 0, stack, 1024*1024, 50);
	if (r != 0)
	{
		printf("Failed to create thread\n");
		while(1);
	}
	printf("Main thread created\n");
	LWP_SetThreadPriority(0, 0);

	printf("Looping\n");
	while(1);
#endif
}
示例#3
0
int main(void) {
    int ret;
    void *frame_buffer = NULL;
    GXRModeObj *rmode = NULL;
    
    /* The game's boot loader is statically loaded at 0x81200000, so we'd better
     * not start mallocing there! */
    SYS_SetArena1Hi((void *)0x81200000);

    /* initialise all subsystems */
    if (!Event_Init(&main_event_fat_loaded))
        goto exit_error;
    if (!Apploader_Init())
        goto exit_error;
    if (!Module_Init())
        goto exit_error;
    if (!Search_Init())
        goto exit_error;
    
    /* main thread is UI, so set thread prior to UI */
    LWP_SetThreadPriority(LWP_GetSelf(), THREAD_PRIO_UI);

    /* configure the video */
    VIDEO_Init();
    
    rmode = VIDEO_GetPreferredMode(NULL);
    
    frame_buffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
    if (!frame_buffer)
        goto exit_error;
    console_init(
        frame_buffer, 20, 20, rmode->fbWidth, rmode->xfbHeight,
        rmode->fbWidth * VI_DISPLAY_PIX_SZ);

    /* spawn lots of worker threads to do stuff */
    if (!Apploader_RunBackground())
        goto exit_error;
    if (!Module_RunBackground())
        goto exit_error;
    if (!Search_RunBackground())
        goto exit_error;
        
    VIDEO_Configure(rmode);
    VIDEO_SetNextFramebuffer(frame_buffer);
    VIDEO_SetBlack(false);
    VIDEO_Flush();
    VIDEO_WaitVSync();
    if (rmode->viTVMode & VI_NON_INTERLACE)
        VIDEO_WaitVSync();

    /* display the welcome message */
    printf("\x1b[2;0H");
    printf("BrainSlug Wii  v%x.%02x.%04x"
#ifndef NDEBUG
        " DEBUG build"
#endif
        "\n",
        BSLUG_VERSION_MAJOR(BSLUG_LOADER_VERSION),
        BSLUG_VERSION_MINOR(BSLUG_LOADER_VERSION),
        BSLUG_VERSION_REVISION(BSLUG_LOADER_VERSION));
    printf(" by Chadderz\n\n");
   
    if (!__io_wiisd.startup() || !__io_wiisd.isInserted()) {
        printf("Please insert an SD card.\n\n");
        do {
            __io_wiisd.shutdown();
        } while (!__io_wiisd.startup() || !__io_wiisd.isInserted());
    }
    __io_wiisd.shutdown();
    
    if (!fatMountSimple("sd", &__io_wiisd)) {
        fprintf(stderr, "Could not mount SD card.\n");
        goto exit_error;
    }
    
    Event_Trigger(&main_event_fat_loaded);
        
    printf("Waiting for game disk...\n");
    Event_Wait(&apploader_event_disk_id);
    printf("Game ID: %.4s\n", os0->disc.gamename);
        
    printf("Loading modules...\n");
    Event_Wait(&module_event_list_loaded);
    if (module_list_count == 0) {
        printf("No valid modules found!\n");
    } else {
        size_t module;
        
        printf(
            "%u module%s found.\n",
            module_list_count, module_list_count > 1 ? "s" : "");
        
        for (module = 0; module < module_list_count; module++) {
            printf(
                "\t%s %s by %s (", module_list[module]->name,
                module_list[module]->version, module_list[module]->author);
            Main_PrintSize(module_list[module]->size);
            puts(").");
        }
        
        Main_PrintSize(module_list_size);
        puts(" total.");
    }
    
    Event_Wait(&apploader_event_complete);
    Event_Wait(&module_event_complete);
    fatUnmount("sd");
    __io_wiisd.shutdown();
    
    if (module_has_error) {
        printf("\nPress RESET to exit.\n");
        goto exit_error;
    }
    
    if (apploader_game_entry_fn == NULL) {
        fprintf(stderr, "Error... entry point is NULL.\n");
    } else {
        if (module_has_info || search_has_info) {
            printf("\nPress RESET to launch game.\n");
            
            while (!SYS_ResetButtonDown())
                VIDEO_WaitVSync();
            while (SYS_ResetButtonDown())
                VIDEO_WaitVSync();
        }
        
        SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
        apploader_game_entry_fn();
    }

    ret = 0;
    goto exit;
exit_error:
    ret = -1;
exit:
    while (!SYS_ResetButtonDown())
        VIDEO_WaitVSync();
    while (SYS_ResetButtonDown())
        VIDEO_WaitVSync();
    
    VIDEO_SetBlack(true);
    VIDEO_Flush();
    VIDEO_WaitVSync();
    
    free(frame_buffer);
        
    exit(ret);
        
    return ret;
}
示例#4
0
static bool WiiLoad (s32 connection)
	{
	char wiiloadVersion[2];
	unsigned char header[9];
	size_t buffsize;

	wiiload.status = WIILOAD_RECEIVING;
			
	printopt ("WiiLoad begin");
	
	NetRead(connection, header, 8, 250);

	if (memcmp(header, "HAXX", 4) != 0) // unsupported protocol
		{
		printopt ("unsupported protocol");
		return false;
		}
		
	LWP_SetThreadPriority (networkthread, PRIO_RCV);

	wiiloadVersion[0] = header[4];
	wiiloadVersion[1] = header[5];

	NetRead(connection, (u8 *) &buffsize, 4, 250);

	if (header[4] > 0 || header[5] > 4)
		{
		printopt ("compressed file !");
		NetRead(connection, (u8*) &uncfilesize, 4, 250); // Compressed protocol, read another 4 bytes
		}
	
	/*
	buff = (u8 *) malloc(buffsize);
	if (!buff)
		{
		printopt ("Not enough memory.");
		return false;
		}
	*/
	
	printopt ("Receiving file (%s)...", incommingIP);

	u32 done = 0;
	u32 blocksize = 4096;
	
	u8 *buff = malloc (blocksize);

	int retries = 10;
	int result;
	int isZip = 0;
	
	FILE *f;
	char path[300];
	sprintf (path, "%s/%s", tpath, WIILOAD_TMPFILE);
	f = fopen (path, "wb");

	do
		{
		if (blocksize > buffsize - done)
			blocksize = buffsize - done;

		result = net_read(connection, buff, blocksize);
		if (result <= 0)
			{
			--retries;
			usleep (100000); // lets wait 10 msec
			}
		else
			{
			if (f) fwrite (buff, 1, result, f);
			
			retries = 10;
			
			if (done == 0 && (buff[0] == 'P' && buff[1] == 'K' && buff[2] == 0x03 && buff[3] == 0x04))
				{
				Debug ("This is a ZIP file");
				isZip = 1;
				}
				
			done += result;
			}

		if (retries == 0)
			{
			free (buff);
			buff = 0;
			buffsize = 0;
			if (f) fclose(f);
			printopt ("Transfer failed.");
			return false;
			}

		//printopt ("%d of %d bytes (r %d)", done, buffsize, retries);
		printopt ("!%d%c", (done * 100) / buffsize, 37);
		//fflush(stdout);
		} 
	while (done < buffsize);
	
	if (f) fclose(f);
	
	if (done != buffsize)
		{
		wiiload.status = WIILOAD_IDLE;
		//free (buff);
		//buffsize = 0;
		//buff = 0;
		printopt("Filesize doesn't match.");
		return false;
		}

	// These are the arguments....
	char temp[1024];
	int ret = NetRead(connection, (u8 *) temp, 1023, 250);
	temp[ret] = 0;
	
	//Debug_hexdump (temp, ret);
	
	if (ret > 2 && temp[ret - 1] == '\0' && temp[ret - 2] == '\0') // Check if it is really an arg
		{
		wiiload.args = malloc (ret);
		if (wiiload.args)
			{
			memcpy (wiiload.args, temp, ret);

			// convert arguments in ; separated items
			int i;
			for (i = 0; i < ret; i++)
				{
				if (wiiload.args[i] == '\0' && wiiload.args[i+1] != '\0')
					wiiload.args[i] = ';';
				}

			wiiload.argl = ret;
			}
		}

	temp[ret] = 0;

	printopt("Filename %s (%d)", temp, ret);
	strcpy (wiiload.filename, temp);
	
	wiiload.status = WIILOAD_IDLE;
	UncompressData (wiiloadVersion, isZip);
	
	free (buff);
	
	LWP_SetThreadPriority (networkthread, PRIO_IDLE);
		
	return true;
	}
示例#5
0
static bool GeckoLoad (void)
	{
	int compressed = 0;
	int ret;
	char wiiloadVersion[2];
	unsigned char header[16];
	size_t buffsize;
	u8 *buff;
	
	memset (header, 0, sizeof (header));
	ret = GeckoRead(EXI_CHANNEL_1, header, 16, 1000);
	if (ret < 16)
		return false;

	if (memcmp(header, "HAXX", 4) != 0) // unsupported protocol
		{
		usb_flush (EXI_CHANNEL_1);
		return false;
		}
		
	LWP_SetThreadPriority (geckothread, PRIO_RCV);

	wiiloadVersion[0] = header[4];
	wiiloadVersion[1] = header[5];
	
	memcpy ((u8 *) &buffsize, &header[8], 4);
	if (header[4] > 0 || header[5] > 4)
		{
		//printopt ("compressed file !");
		compressed = 1;
		memcpy ((u8 *) &uncfilesize, &header[12], 4);
		}
	
	buff = NULL;

	buff = (u8 *) malloc(buffsize);
	if (!buff)
		{
		usb_flush (EXI_CHANNEL_1);
		printopt ("Not enough memory.");
		return false;
		}

	LWP_SetThreadPriority(geckothread, 64);
	//printopt ("Receiving file (%s)...", incommingIP);

	u32 done = 0;
	u32 blocksize = 1024*16;
	int result;
	
	if (!compressed) // if the file isn't compressed, 4 bytes of file are in the header vect...
		{
		memcpy ((u8 *) buff, &header[12], 4);
		done += 4;
		}

	do
		{
		if (blocksize > buffsize - done)
			blocksize = buffsize - done;

		result = GeckoRead(EXI_CHANNEL_1, buff+done, blocksize, 1000);
		if (result > 0)
			done += result;
		else
			break;

		printopt ("!%d%c", (done * 100) / buffsize, 37);
		} 
	while (done < buffsize);
	
	LWP_SetThreadPriority(geckothread, 8);
	
	if (done != buffsize)
		{
		wiiload.status = WIILOAD_IDLE;
		free (buff);
		buffsize = 0;
		buff = 0;
		printopt("Filesize doesn't match.");
		return false;
		}

	// These are the arguments....
	char temp[1024];
	ret = GeckoRead(EXI_CHANNEL_1, (u8 *) temp, 1023, 1000);
	
	temp[ret] = 0;
	
	if (ret > 2 && temp[ret - 1] == '\0' && temp[ret - 2] == '\0') // Check if it is really an arg
		{
		wiiload.args = malloc (ret);
		if (wiiload.args)
			{
			memcpy (wiiload.args, temp, ret);
			
			// convert arguments in ; separated items
			int i;
			for (i = 0; i < ret; i++)
				{
				if (wiiload.args[i] == '\0' && wiiload.args[i+1] != '\0')
					wiiload.args[i] = ';';
				}

			wiiload.argl = ret;
			}
		}
	temp[ret] = 0;

	printopt("Filename %s (%d)", temp, ret);
	strcpy (wiiload.filename, temp);
	
	int isZip = 0;
	if (buff[0] == 'P' && buff[1] == 'K' && buff[2] == 0x03 && buff[3] == 0x04)
		isZip = 1;

	// to keep compatibility with wiiload over network, we must store the file on device...
	char path[256];
	sprintf (path, "%s/%s", tpath, WIILOAD_TMPFILE);

	//mt_Lock();
	ret = fsop_WriteFile (path, buff, buffsize);
	//mt_Unlock();
	
	free (buff);
	buff = NULL;
	
	if (ret)
		{
		UncompressData (wiiloadVersion, isZip);
		}
		
	free (buff);
	
	LWP_SetThreadPriority (geckothread, PRIO_IDLE);
	
	return true;
	}