Example #1
0
int gecko_readmem()
{
	u8 startaddress[4];
	u8 endaddress[5];
	u8 ack_packet = 0xAA;
	u8 pcresponse;
	static u8 packetbuffer[packetsize] ATTRIBUTE_ALIGN(32);
	u32 memstart;
	u32 memend;
	u32 memrange;
	u32 fullpackets;
	u32 currentpacket;
	u32 lastpacketbytes;

	// ACK
	usb_sendbuffer_safe(gecko_channel,&ack_packet,1);
	usb_recvbuffer_safe(gecko_channel,&startaddress,4);		
	usb_recvbuffer_safe(gecko_channel,&endaddress,4);		
	
	memstart = be32(startaddress);	
	memend = be32(endaddress);	
	memrange = memend - memstart;

	fullpackets = memrange / packetsize;						
	lastpacketbytes = memrange % packetsize;					

	// Full Packet Size
	for (currentpacket = 0;currentpacket < fullpackets;)
	{	
		memcpy(packetbuffer, (char*)memstart, packetsize);
		usb_sendbuffer(gecko_channel,&packetbuffer, packetsize);
		usb_recvbuffer_safe(gecko_channel,&pcresponse,1);	
		if(pcresponse != 0xAA){								
		//	printf("failed to read packet\n");
			return 0;
		}
			memstart += packetsize;
			currentpacket++;	
	}

	// Remainder
	if(lastpacketbytes > 0) {
		memcpy(packetbuffer, (char*)memstart, lastpacketbytes);
		usb_sendbuffer_safe(gecko_channel,&packetbuffer, lastpacketbytes);
		usb_recvbuffer_safe(gecko_channel,&pcresponse,1);	
	}
	
//	printf("memory dump complete\n");
	return 1;
}
Example #2
0
int gecko_readrange(u32 memstart, u32 memend)
{

	char pcresponse;
	static char packetbuffer[packetsize] ATTRIBUTE_ALIGN(32);
	u32 memrange;
	u32 fullpackets;
	u32 currentpacket;
	u32 lastpacketbytes;

	memrange = memend - memstart;
	
	fullpackets = memrange / packetsize;						
	lastpacketbytes = memrange % packetsize;		

	// Full Packet Size
	for (currentpacket = 0;currentpacket < fullpackets;)
	{	
		memcpy(packetbuffer, (char*)memstart, packetsize);
		usb_sendbuffer_safe(gecko_channel,&packetbuffer, packetsize);
		usb_recvbuffer_safe(gecko_channel,&pcresponse,1);	
		if(pcresponse != 0xAA){								
			return 0;
		}
			memstart += packetsize;
			currentpacket++;	
	}
	// Remainder
	if(lastpacketbytes > 0) {
		memcpy(packetbuffer, (char*)memstart, lastpacketbytes);
		usb_sendbuffer_safe(gecko_channel,&packetbuffer, lastpacketbytes);
		
	}
	return 1;
}
Example #3
0
static int usbread(struct dbginterface *device,void *buffer,int size)
{
	int ret;
	ret = usb_recvbuffer_safe(device->fhndl,buffer,size);
	return ret;
}
Example #4
0
//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------

	s32 ret;
	u8 gamestatus = 0x03;
	u8 versionnumber = 0x80;
	u32 geckoidcheck;
	u8 oldconfigbytes[2];
	
	ret = sd_init();
	if(!ret){
		sd_found = 0;
	}
	else {
		sd_found = 1;
	}
	
	if (*((u32 *) 0x80001804) == 0x53545542 && *((u32 *) 0x80001808) == 0x48415858)
		loaderhbc = 1;
	
	*(u32*)0xCD00643C = 0x00000000;	// 32Mhz on Bus
	
	gecko_attached = usb_isgeckoalive(EXI_CHANNEL_1);
	if(gecko_attached){	
		gecko_channel = 1;
		if (EXI_GetID(gecko_channel, 0x80, &geckoidcheck) == 1)
		{
			if (geckoidcheck != 0)
			{
				gecko_attached = FALSE;
				goto slota;
			}
		}
		else
		{
			gecko_attached = FALSE;
			goto slota;
		}
		usb_flushnew(gecko_channel);
		goto slotb;
	}
	
slota:
	
	gecko_attached = usb_isgeckoalive(EXI_CHANNEL_0);
	if(gecko_attached){	
		gecko_channel = 0;
		if (EXI_GetID(gecko_channel, 0x80, &geckoidcheck) == 1)
		{
			if (geckoidcheck != 0)
			{
				gecko_attached = FALSE;
				goto slotb;
			}
		}
		else
		{
			gecko_attached = FALSE;
			goto slotb;
		}
		usb_flushnew(gecko_channel);
	}
	
slotb:
	
	sd_load_config();
	
	tempgameconf = (char *) sdbuffer;
	autobootcheck = 1;
	memset(gameidbuffer, 0, 8);
	app_loadgameconfig(gameidbuffer);
	autobootcheck = 0;
	
	loadStartupIOS();
	iosversion = IOS_GetVersion();
	
	if(config_not_loaded == 0){
		menu_load_config();
		config_not_loaded = 1;
	}
	
	if (autoboothbc || !loaderhbc)
	{
		if (autoboot == 1)
		{
			rebooter_thread();
			menu_number = 12;
			rebooter_thread_state = 0;
		}
	}
	else
		autoboot = 0;
	
	WPAD_Init();
	PAD_Init();
	VIDEO_Init();
	AUDIO_Init (NULL);
	
	SYS_SetPowerCallback (power_cb);
    SYS_SetResetCallback (reset_cb);
	
	if (CONF_GetProgressiveScan() > 0 && VIDEO_HaveComponentCable()) {
		progmode = 1;
	}

	if (CONF_GetAspectRatio()) {
		widescreen = 1;
	}
	
	gfx_init();
	gfx_load_gfx();
	
	gfx_load_gfx1();
	if (autoboot == 0 || autobootwait > 1)
		gfx_fade_logo();
	
	VIDEO_WaitVSync();
	
	if(!gecko_attached){	
		gecko_channel = 2;
	}

	gfx_int_stars();
	
	while(1)
	{
		if(gecko_attached){
			usb_recvbuffer(gecko_channel,&gecko_command,1);
			switch(gecko_command)
			{
				//case 0x04:	
				//	gecko_readmem();	
				//break;
				
				case 0x14:		// Load DOL
					load_geckoexe(0);
				break;
					
				case 0x24:		// Load DOL
					load_geckoexe(1);
				break;

				case 0x42:
					// Debugger on, pause start off
					config_bytes[7] = 0x01;
					config_bytes[5] = 0x00;
					usb_recvbuffer_safe(gecko_channel,&oldconfigbytes,2);	// Get config
					config_bytes[0] = oldconfigbytes[0];
					switch (oldconfigbytes[1])
					{
					case 0x00:
						config_bytes[1] = 0x00;
						break;
					case 0x01:
						config_bytes[1] = 0x01;
						break;
					case 0x02:
						config_bytes[1] = 0x00;
						break;
					case 0x03:
						config_bytes[1] = 0x01;
						break;
					case 0x04:
						config_bytes[1] = 0x03;
						break;
					case 0x05:
						config_bytes[1] = 0x03;
						break;
					case 0x06:
						config_bytes[1] = 0x02;
						break;
					case 0x07:
						config_bytes[1] = 0x02;
						break;
					}
					menu_number = 8;
					apploader_thread();
					gecko_command = 0;
				break;
					
				case 0x43:
					// Debugger on, pause start on
					config_bytes[7] = 0x01;
					config_bytes[5] = 0x01;
					usb_recvbuffer_safe(gecko_channel,&oldconfigbytes,2);	// Get config
					config_bytes[0] = oldconfigbytes[0];
					switch (oldconfigbytes[1])
					{
						case 0x00:
							config_bytes[1] = 0x00;
							break;
						case 0x01:
							config_bytes[1] = 0x01;
							break;
						case 0x02:
							config_bytes[1] = 0x00;
							break;
						case 0x03:
							config_bytes[1] = 0x01;
							break;
						case 0x04:
							config_bytes[1] = 0x03;
							break;
						case 0x05:
							config_bytes[1] = 0x03;
							break;
						case 0x06:
							config_bytes[1] = 0x02;
							break;
						case 0x07:
							config_bytes[1] = 0x02;
							break;
					}
					menu_number = 8;
					apploader_thread();
					gecko_command = 0;
				break;

				case 0x50:		
					usb_sendbuffer_safe(gecko_channel,&gamestatus,1);
				break;

				case 0x99:		
					usb_sendbuffer_safe(gecko_channel,&versionnumber,1); 
				break;
			}

		}
		
		if(error_sd || confirm_sd || error_video){
			sleep(1);
			error_sd = 0;
			confirm_sd = 0;
			error_video = 0;
		}

		if(loadedpng && !alphapng){	// if custom backdrop draw bubbles after image
			gfx_draw_image(0, 0, 640, 480, tex_logo1, 0, 1, 1,0xff);
			gfx_draw_stars();
		}
		else{
			gfx_draw_stars(); // else if own back drop do in this order due to border clip
			gfx_draw_image(0, 0, 640, 480, tex_logo1, 0, 1, 1,0xff);
		};
		
		menu_draw();
		gfx_render_direct();
	}

	return 0;
}