Ejemplo n.º 1
0
    void Browser::Update() {
        
#ifdef WIN32
        W32Update();
#endif
        Hw::SystemPoll();

        get_controller_data(&ctrl, 0);
        {
            int up = 0;
            int down = 0;
            
            // button pressed
            if(ctrl.up && !old_ctrl.up){
                up++;
                lChange[0]=mftb();
            }
            else if (ctrl.down && !old_ctrl.down){
                down++;
                lChange[1]=mftb();
            }
            // button released
            if(!ctrl.up){
                lChange[0]=0;
            }
            if(!ctrl.down){
                lChange[1]=0;
            }
            
            uint64_t now = mftb();

            if(lChange[0]>0)
            if(tb_diff_msec(now,lChange[0])>250){
                static int uh=0;
                uh=!uh;
                if (uh) up++;
            }
            if(lChange[1]>0)
            if(tb_diff_msec(now,lChange[1])>250){
                static int dh=0;
                dh=!dh;
                if (dh) down++;
            }
            
            
            //if (get_controller_data(&ctrl, 0)) {
            if (up) {
                switch (panelSelected) {
                    case PANEL_FILE_LIST:
                        entrySelected--;
                        break;
                    case PANEL_ACTION:
                        actionSelected--;
                        break;
                }
            }

            if (down) {
                switch (panelSelected) {
                    case PANEL_FILE_LIST:
                        entrySelected++;
                        break;
                    case PANEL_ACTION:
                        actionSelected++;
                        break;
                }
            }
            if (ctrl.b && !old_ctrl.b) {
                switch (panelSelected) {
                    case PANEL_FILE_LIST:
                        append_dir_to_path(currentPath, "..");
                        ScanDir();
                        break;
                }
            }
            if (ctrl.back && !old_ctrl.back) {
#ifdef LIBXENON
                switch (panelSelected) {
                    case PANEL_FILE_LIST:
                        char path[2048];
                        
                        handle = get_devices(handle, path);

                        strcpy(currentPath, path);
                        ScanDir();
                        break;
                }
#endif
            }
            if
                (
                    (ctrl.start && !old_ctrl.start) || (ctrl.a && !old_ctrl.a)
                    ) {
                switch (panelSelected) {
                    case PANEL_FILE_LIST:
                    {
                        if (vEntry.size() == 0)
                            break;

                        FileEntry currentEntry = vEntry.at(entrySelected);

                        if (currentEntry.type == 1) {
                            append_dir_to_path(currentPath, (char*) currentEntry.name.c_str());
                            ScanDir();
                        } else {
                            sprintf(currentFile, "%s/%s", currentPath, currentEntry.name.c_str());
                            if (ActionLaunchFile != NULL)
                                ActionLaunchFile(currentFile);
                        }
                        break;
                    }
                    case PANEL_ACTION:
                    {
                        if (nbAction == 0)
                            break;

                        // Exec action ...
                        //FileEntry currentEntry = vEntry.at(entrySelected);
                        lpBrowserActionEntry currentAction = vAction[actionSelected];
                        if (currentAction != NULL && currentAction->action != NULL) {
                            currentAction->param = (void*) currentPath;
                            //currentAction->param = 
                            currentAction->action(currentAction);
                        }
                        break;
                    }
                }
            }

            if (ctrl.left && !old_ctrl.left) {
                //if(panelSelected!=PANEL_PROGRESS)
                panelSelected--;
            }
            if (ctrl.right && !old_ctrl.right) {
                //if(panelSelected!=PANEL_PROGRESS)
                panelSelected++;
            }

            // clamp ...
            CLAMP(entrySelected, 0, vEntry.size() - 1);
            CLAMP(actionSelected, 0, nbAction - 1);
            CLAMP(panelSelected, 0, 1);


            // Save the old value
            old_ctrl = ctrl;

            // Erase for the big loop
            memset(&ctrl, 0, sizeof (struct controller_data_s));
        }


    }
Ejemplo n.º 2
0
int main(){
	const char * s;
	char path[256];
	
	int handle;
	struct controller_data_s pad;
	int pos=0,ppos=-1,start,count,i;

	xenos_init(VIDEO_MODE_AUTO);
	console_init();

	xenon_make_it_faster(XENON_SPEED_FULL);
	
	usb_init();
	usb_do_poll();
	
	xenon_ata_init();

	xenon_atapi_init();
	
	fatInitDefault();

	handle=-1;
    handle=bdev_enum(handle,&s);
    if(handle<0) return 0;

	strcpy(path,s);
	strcat(path,":/");	

	load_dir(path);
	
	for(;;){
 		usb_do_poll();		
 		get_controller_data(&pad, 0);
		
		if (pad.s1_y>STICK_THRESHOLD) --pos;
		if (pad.s1_y<-STICK_THRESHOLD) ++pos;
		
		if (entrycount && (pos<0 || pos>=entrycount)){
			pos=ppos;
			continue;
		}
		
		if (pad.logo) return 0;
		
		if (pad.a){
			if(entries[pos].d_type&DT_DIR){
				append_dir_to_path(path,entries[pos].d_name);
				load_dir(path);
				ppos=-1;
				pos=0;
			}else{
				char fn[256];
				strcpy(fn,path);
				strcat(fn,entries[pos].d_name);
				
				printf("%s\n",fn);

				if (strstr(entries[pos].d_name,".elf") || strstr(entries[pos].d_name,".elf32")) { // ugly
					elf_runFromDisk(fn);
				}else{
					FILE * f=fopen(fn,"rb");
					if(f){
						int size=1024*1024;
						int totred=0,red;

						void * buf=malloc(size);

						u64 beg=mftb();
						do{
							red=fread(buf,1,size,f);
							totred+=red;
							console_putch('.');
						}while(red==size);

						printf("\n%d bytes, %f KB/s\n",totred, (float)(totred/1024.0)/((float)(mftb()-beg)/PPC_TIMEBASE_FREQ));

						free(buf);

						fclose(f);
					}
				}
			}
		}
		
		if(pad.back){
			append_dir_to_path(path,"..");
			load_dir(path);
			ppos=-1;
			pos=0;
		}
		
		if(pad.b){
		    do{
				handle=bdev_enum(handle,&s);
			}while(handle<0);
			strcpy(path,s);
			strcat(path,":/");
			load_dir(path);
			ppos=-1;
			pos=0;
		}

		if (ppos==pos) continue;
		
		memset(&pad,0,sizeof(struct controller_data_s));
		
		console_set_colors(BG_COL,FG_COL);
		console_clrscr();
		printf("A: select, B: change disk, Back: parent dir, Logo: reload Xell\n\n%s\n\n",path);
		
		start=MAX(0,pos-MAX_DISPLAYED_ENTRIES/2);
		count=MIN(MAX_DISPLAYED_ENTRIES,entrycount-start);
		
		for(i=start;i<start+count;++i){
			struct dirent *de = &entries[i];

			if (i==pos){
				console_set_colors(FG_COL,BG_COL);
			}else{
				console_set_colors(BG_COL,FG_COL);
			}
			
			if (de->d_type&DT_DIR) console_putch('[');

			s=de->d_name;
			while(*s) console_putch(*s++);
			
			if (de->d_type&DT_DIR) console_putch(']');

			console_putch('\r');
			console_putch('\n');
		}
			
		ppos=pos;
		
		do{
	 		usb_do_poll();		
			get_controller_data(&pad, 0);
		}while(pad.a || pad.b || pad.back || pad.s1_y>STICK_THRESHOLD || pad.s1_y<-STICK_THRESHOLD);
	}
	
	
	return 0;
}
Ejemplo n.º 3
0
int main(void)
{
   const char *s = NULL;
   char path[256];

   int handle;
   struct controller_data_s pad;
   int pos = 0, ppos = -1;

   xenos_init(VIDEO_MODE_AUTO);
   console_init();
   xenon_make_it_faster(XENON_SPEED_FULL);
   usb_init();
   usb_do_poll();
   xenon_ata_init();
   dvd_init();

   handle = -1;
   handle = bdev_enum(handle, &s);
   if (handle < 0)
      return 0;

   strcpy(path, s);
   strcat(path, ":/");	

   load_dir(path);

   for (;;)
   {
      usb_do_poll();		
      get_controller_data(&pad, 0);

      if (pad.s1_y > STICK_THRESHOLD || pad.up)
         pos--;
      if (pad.s1_y < -STICK_THRESHOLD || pad.down)
         pos++;

      if (entrycount && (pos < 0 || pos >= entrycount))
      {
         pos = ppos;
         continue;
      }

      if (pad.logo)
         return 0;

      if (pad.a)
      {
         if (entries[pos].d_type & DT_DIR)
         {
            append_dir_to_path(path,entries[pos].d_name);
            load_dir(path);
            ppos = -1;
            pos = 0;
         }
         else
         {
            char fn[256];
            strcpy(fn, path);
            strcat(fn, entries[pos].d_name);

            printf("%s\n", fn);

            start_ssnes(fn);
         }
      }

      if (pad.select)
      {
         append_dir_to_path(path, "..");
         load_dir(path);
         ppos = -1;
         pos = 0;
      }

      if (pad.b)
      {
         do
         {
            handle = bdev_enum(handle, &s);
         } while (handle < 0);

         strcpy(path, s);
         strcat(path, ":/");
         load_dir(path);
         ppos = -1;
         pos = 0;
      }

      if (ppos == pos)
         continue;

      memset(&pad, 0, sizeof(pad));

      console_set_colors(BG_COL, FG_COL);
      console_clrscr();
      printf("A: select, B: change disk, Back: parent dir, Logo: reload Xell\n\n%s\n\n", path);

      int start = MAX(0, pos - MAX_DISPLAYED_ENTRIES / 2);
      int count = MIN(MAX_DISPLAYED_ENTRIES, entrycount - start);

      for (int i = start; i < start + count; i++)
      {
         struct dirent *de = &entries[i];

         if (i == pos)
            console_set_colors(FG_COL, BG_COL);
         else
            console_set_colors(BG_COL, FG_COL);

         if (de->d_type & DT_DIR)
            console_putch('[');

         s = de->d_name;
         while (*s)
            console_putch(*s++);

         if (de->d_type & DT_DIR)
            console_putch(']');

         console_putch('\r');
         console_putch('\n');
      }

      ppos = pos;

      do
      {
         usb_do_poll();		
         get_controller_data(&pad, 0);
      } while (pad.a || pad.b || pad.select || pad.s1_y > STICK_THRESHOLD || pad.s1_y < -STICK_THRESHOLD);
   }

   return 0;
}