예제 #1
0
s32 USBStorage2_Init(u32 port)
{
	if(hddInUse[port])
		return 0;

	/* Create heap */
	if (hid < 0)
	{
		hid = iosCreateHeap(UMS_HEAPSIZE);
		if (hid < 0) return IPC_ENOMEM;
	}

	/* Open USB device */
	if (fd < 0) fd = IOS_Open(fs, 0);
	if (fd < 0) fd = IOS_Open(fs2, 0);
	if (fd < 0) fd = IOS_Open(fs3, 0);
	if (fd < 0) return fd;

	USBStorage2_SetPort(port);

	/* Initialize USB storage */
	IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_INIT, ":");

	/* Get device capacity */
	if (USBStorage2_GetCapacity(port, &hdd_sector_size[port]) == 0)
		return IPC_ENOENT;

	hddInUse[port] = true;

	return 0; // 0->HDD, 1->DVD
}
예제 #2
0
파일: ios.c 프로젝트: Alcaro/RetroArch
s32 __IOS_InitHeap(void)
{
	if(__ios_hid <0 ) {
		__ios_hid = iosCreateHeap(IOS_HEAP_SIZE);
		if(__ios_hid < 0) return __ios_hid;
	}
	return 0;
}
예제 #3
0
int ss_init(void)
{
   if (!_ss_inited)
   {
      _ss_heap_id = iosCreateHeap(SS_HEAP_SIZE);
      _ss_inited = 1;
   }
   return 1;
}
예제 #4
0
파일: ssl.c 프로젝트: ds84182/wiitweet
u32 ssl_init(void){

	if(__ssl_hid < 0 ) {
		__ssl_hid = iosCreateHeap(SSL_HEAP_SIZE);
		if(__ssl_hid < 0){
			return __ssl_hid;
		}
	}

	return 0;
}
예제 #5
0
파일: sdhc.c 프로젝트: smurk-too/wodebrew
bool SDHC_Init(void)
{
	s32 ret;

	if (sdhc_mode_sd) {
		return __io_wiisd.startup();
	}

	/* Already open */
	if (fd >= 0)
		return true;

	/* Create heap */
	if (hid < 0) {
		hid = iosCreateHeap(SDHC_HEAPSIZE);
		if (hid < 0)
			goto err;
	}

	// allocate buf2
	if (sdhc_buf2 == NULL) {
		sdhc_buf2 = SYS_AllocArena2MemLo(SDHC_MEM2_SIZE, 32);
	}

	/* Open SDHC device */
	fd = IOS_Open(fs, 0);
	if (fd < 0)
		goto err;

	/* Initialize SDHC */
	ret = IOS_IoctlvFormat(hid, fd, IOCTL_SDHC_INIT, ":");
	if (ret)
		goto err;

	return true;

err:
	/* Close SDHC device */
	if (fd >= 0) {
		IOS_Close(fd);
		fd = -1;
	}

	return false;
}
예제 #6
0
파일: mload.c 프로젝트: gnils/usbloader-gx
int mload_module(void *addr, int len)
{
int ret;
void *buf=NULL;


	if(mload_init()<0) return -1;

    if(hid>=0)
		{
		iosDestroyHeap(hid);
		hid=-1;
		}

	hid = iosCreateHeap(len+0x800);
    
	if(hid<0) return hid;

	buf= iosAlloc(hid, len);

	if(!buf) {ret= -1;goto out;}

	
	memcpy(buf, addr,len);

	ret = IOS_IoctlvFormat(hid, mload_fd, MLOAD_LOAD_MODULE, ":d", buf, len);

	if(ret<0) goto out;
	
	ret=IOS_IoctlvFormat(hid, mload_fd, MLOAD_RUN_MODULE, ":");

	if(ret<0) {ret= -666;goto out;}
	
out:
	if(hid>=0)
		{
		iosDestroyHeap(hid);
		hid=-1;
		}
	
return ret;

}
예제 #7
0
파일: mload.c 프로젝트: gnils/usbloader-gx
int mload_init()
{
int n;

	if(hid<0) hid = iosCreateHeap(0x800);

	if(hid<0)
		{
		if(mload_fd>=0)
			IOS_Close(mload_fd);

		mload_fd=-1;

		return hid;
		}

	if(mload_fd>=0) 
		{
		return 0;
		}

	for(n=0;n<20;n++) // try 5 seconds
	{
		mload_fd=IOS_Open(mload_fs, 0);
		
		if(mload_fd>=0) break;

		usleep(250*1000);
	}

	if(mload_fd<0)
		{
		
		if(hid>=0)
			{
			iosDestroyHeap(hid);
			hid=-1;
			}
		}

return mload_fd;
}
예제 #8
0
파일: sdhc.c 프로젝트: Captnoord/Wodeflow
bool SDHC_Init(void)
{
	s32 ret;

	/* Already open */
	if (fd > 0)
		return true;

	/* Create heap */
	if (hid < 0) {
		hid = iosCreateHeap(SDHC_HEAPSIZE);
		if (hid < 0)
			goto err;
	}

	/* Open SDHC device */
	fd = IOS_Open(fs, 0);
	if (fd < 0)
		goto err;

	/* Initialize SDHC */
	ret = IOS_IoctlvFormat(hid, fd, IOCTL_SDHC_INIT, ":");
	if (ret)
		goto err;

	return true;

err:
	/* Close SDHC device */
	if (fd > 0) {
		IOS_Close(fd);
		fd = -1;
	}

	return false;
}
예제 #9
0
int load_fatffs_module(u8 *discid)
{
	static char fs[] ATTRIBUTE_ALIGN(32) = "fat";
	s32 hid = -1, fd = -1;
	static char file_name[256]  ALIGNED(0x20)="SD:";
	int n;
	char *p;
	s32 ret;

	p=&file_name[0];

	if(mload_init()<0) return -1;

	mload_elf((void *) fatffs_module_bin, &my_data_elf);
	my_thread_id= mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio);
	if(my_thread_id<0) return -1;

    global_mount &=~0xc;

	if(discid)
		{
		sd_ok=ud_ok=1;
				
		/* Function get_fat_name not implemented, this should return the path to the save file */
		// p=get_fat_name(discid);
		p = NULL;
				
		sd_ok=ud_ok=0;
				
		if(!p) return -1;

		global_mount &=~0xf;
			
		// change 'ud:' by 'usb:'
		if(p[0]=='U') {global_mount|=2;file_name[0]='U';file_name[1]='S';file_name[2]='B';memcpy(file_name+3, (void *)p+2, 253);}			   
		else {global_mount|=1;memcpy(file_name, (void *) p, 256);}

		// copy filename to dip_plugin filename area
		mload_seek(*((u32 *) (dip_plugin+14*4)), SEEK_SET);	// offset 14 (filename Address - 256 bytes)
		mload_write(file_name, sizeof(file_name));
		mload_close();

		
		}
	else
		{
		if((global_mount & 3)==0) return 0;
		if(global_mount & 1) p[0]='s';
		if(global_mount & 2) p[0]='u';
		}
	usleep(350*1000);

	/* Create heap */
	if (hid < 0) {
		hid = iosCreateHeap(0x100);
		if (hid < 0)
			return -1; 
	}

	/* Open USB device */
	fd = IOS_Open(fs, 0);
	
	if (fd < 0)
		{
		if(hid>=0)
			{
			iosDestroyHeap(hid);
			hid=-1;
			}
		return -1;
		}
  
	n=30; // try 20 times
	while(n>0)
	{
		if((global_mount & 10)==2) {ret=IOS_IoctlvFormat(hid, fd, IOCTL_FAT_MOUNTUSB, ":");if(ret==0) global_mount|=8;}
		else {ret=IOS_IoctlvFormat(hid, fd, IOCTL_FAT_MOUNTSD, ":");if(ret==0) {global_mount|=4;}}
		
		if((global_mount & 7)==3 && ret==0)	 
			{ret=IOS_IoctlvFormat(hid, fd, IOCTL_FAT_MOUNTSD, ":");if(ret==0) global_mount|=4;}

    if((global_mount & 3)==((global_mount>>2) & 3) && (global_mount & 3)) {ret=0;break;} else ret=-1;
	
	//ret=IOS_IoctlvFormat(hid, fd, IOCTL_FAT_MOUNTSD, ":");
	//if(ret==0) break;
	usleep(500*1000);
	n--;
	}
예제 #10
0
파일: usb.c 프로젝트: comex/libogc
s32 USB_Initialize()
{
	if(hId==-1) hId = iosCreateHeap(USB_HEAPSIZE);
	if(hId<0) return IPC_ENOMEM;
	return IPC_OK;
}
예제 #11
0
int main(int argc, char **argv) 
{
int ret;

	VIDEO_Init();                                        //Inicialización del Vídeo.
                                      
	rmode = VIDEO_GetPreferredMode(NULL);                //mediante esta función rmode recibe el valor de tu modo de vídeo.
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));  //inicialización del buffer.
	console_init(xfb,20,20,rmode->fbWidth,rmode->        //inicialización de la consola.
	xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);  
	VIDEO_Configure(rmode);                              //configuración del vídeo.
	VIDEO_SetNextFramebuffer(xfb);                       //Configura donde guardar el siguiente buffer .
	VIDEO_SetBlack(FALSE);                               //Hace visible el display  .                     
	VIDEO_Flush();
	VIDEO_WaitVSync();                                   
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

	SYS_SetResetCallback(reset_call);

	IOS_ReloadIOS(222);
	sleep(1);

	/* secuencias de escape 

	\33[2J -> borra pantalla y posiciona en 1,1
	\33[1;1H -> posiciona en 1,1
	\33[42m -> color de fondo verde (0->negro, 1->rojo, 2->verde, 3-> amarillo, 4->azul, 5->magenta 6->cyan 7->blanco )
	\33[32m -> color de letras verde

	*/

	printf("\33[2J\n\n\n \33[42m dev/mload Test \33[40m \n\n\n\n");

	ret=mload_init();
	if(ret<0)
		{
		printf("fail to get dev/mload\n");
		
		goto out;
		}
	else
		{
		u32 addr;
		int len;

		printf("Hello!: my name is dev/mload and my thread id is %i\n", mload_get_thread_id());
		mload_get_load_base(&addr, &len);
		printf("You have from 0x%x to 0x%x to work\n\n", addr, addr+len-1);
		}
	/*
	mload_elf((void *) ehcmodule_elf, &my_data_elf);
	my_thread_id=mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio);
	*/

	printf("Loading example1.elf (Starlet)\n");

	if(((u32) example1_elf) & 3) {printf("Unaligned elf!\n"); goto out;}

	mload_elf((void *) example1_elf, &my_data_elf);

	printf("Running... at 0x%x\n", (u32) my_data_elf.start);

	my_thread_id=mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio);

    if(my_thread_id<0) {printf("fail to init the starlet thread: %i\n", my_thread_id); goto out;}

	printf("Module thread id: %i Priority in elf: 0x%x\n", my_thread_id, my_data_elf.prio);

	printf("The example Module counts seconds and report the thread id and the priority\n");

	{
	#if 0
		int n,m;

		sleep(1);
		#define UMS_BASE			(('U'<<24)|('M'<<16)|('S'<<8))
		#define USB_IOCTL_UMS_INIT	        (UMS_BASE+0x1)
		
		s32 hid2 = -1;
		hid2 = iosCreateHeap(1024);
		n=IOS_Open(ehc_fs, 0);
		if(n<0) printf("Error: device not found\n");
		else {
			printf("OK\n");
		     /* Initialize USB storage */
		     m=IOS_IoctlvFormat(hid2, n, USB_IOCTL_UMS_INIT, ":");

			 }

    #endif	
	}

	while(1)
		{
		static u32 data[8] ATTRIBUTE_ALIGN(32);

		if(exit_by_reset) break;

		mload_seek(0x13740000, SEEK_SET);
		mload_read(&data,32);
		printf("\33[16;16H Starlet activity: %i Thid: %i Prio: 0x%x    \n",data[0],data[1],data[2]);
		
		VIDEO_WaitVSync();
		}

	// you can stops the Starlet thread using this function:
	 mload_stop_thread(my_thread_id);
out:
	mload_close();
VIDEO_WaitVSync();
sleep(4);

return 0;
}