Advertisement
Guest User

Wiireader original

a guest
Mar 13th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 63.97 KB | None | 0 0
  1. /*  Wiireader v1.1
  2.     Copyright (C) 2008 Francisco Muñoz "Hermes" (www.entuwii.net)
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  17.  
  18. */
  19.  
  20.  
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <malloc.h>
  26. #include <math.h>
  27.  
  28. #include "jpeglib.h"
  29. #include <setjmp.h>
  30.  
  31. #include <ogcsys.h>
  32. #include <gccore.h>
  33. #include "ogc/lwp_threads.h"
  34. #include <wiiuse/wpad.h>
  35. #include <fat.h>
  36. #include <fcntl.h>
  37. #include "sys/dir.h"
  38. #include <sys/statvfs.h>
  39. #include "unistd.h"
  40. #include <ogc/conf.h>
  41.  
  42. #include "screen.h"
  43. #include "textreader.h"
  44. //
  45. //#include "asnd.h"
  46. #include "audioplayer.h"
  47. #include "unzip.h"
  48.  
  49. #include "icons.h"
  50.  
  51.  
  52.  
  53. #define ticks_to_msecs(ticks)     ((u32)((ticks)/(TB_TIMER_CLOCK)))
  54.  
  55. extern unsigned gettick();
  56.  
  57. #define THREAD_PRIORITY() LWP_SetThreadPriority(LWP_GetSelf(),40)
  58.  
  59. int is_16_9=0; // screen format 16:9 ?
  60.  
  61. /*
  62. int fprintf(FILE *a,const char *s, ...)
  63. {
  64.     exit(0);
  65. }
  66.  
  67. int printf(const char *s, ...)
  68. {
  69.     exit(0);
  70. }
  71. */
  72.  
  73.  
  74. extern char *debug_str;
  75.  
  76. char path_file[258]="fat0:/";
  77. char path_txt_cfg[258]="fat0:/apps/wiireader/textreader.cfg";
  78. char path_cfg[258]="fat0:/apps/wiireader/textreader.cfg";
  79.  
  80. static char extern_char_set[28672];
  81.  
  82. unsigned char temp_buffer[32768]; // buffer temporal
  83.  
  84. unsigned new_key=0,old_key=0;
  85.  
  86.  
  87. int exit_by_reset=0;
  88.  
  89. int return_reset=2;
  90.  
  91. void reset_call() {exit_by_reset=return_reset;}
  92. void power_call() {exit_by_reset=3;}
  93.  
  94.  
  95. #define WII_A 16
  96. #define WII_B 32
  97.  
  98. #define WII_MINUS 64
  99. #define WII_PLUS 128
  100.  
  101. #define WII_HOME 256
  102. #define WII_START 512
  103.  
  104. #define WII_ONE 1024
  105. #define WII_TWO 2048
  106.  
  107.  
  108. #define WII_RIGHT 2
  109. #define WII_LEFT  1
  110. #define WII_UP    4
  111. #define WII_DOWN  8
  112.  
  113.  
  114. #define QTDEN(a,b)  ((a & (b))==(b))
  115.  
  116.  
  117. unsigned wii_nKeys=0;
  118.  
  119.  
  120. static int valid_keys=0;
  121.  
  122. void wpad_callback(s32 chan, const WPADData *data)
  123. {
  124. if(WPAD_ReadEvent(chan, (WPADData * )data)<0)  valid_keys=0;
  125.  
  126. }
  127.  
  128. unsigned wii_joystick_read(int sel)
  129. {
  130. u32 type[4]={0,0,0,0};
  131. u32 butt=0;
  132. s32 retj[4]={-1,-1,-1,-1};
  133.  
  134. int n;
  135.  
  136. unsigned ret=0;
  137. static expansion_t w_exp;
  138.  
  139. int is_readed=0;
  140.  
  141.  
  142.        
  143.     debug_str="WPAD_ScanPads()";
  144.  
  145.     DI_AudioThread(1);
  146.     valid_keys=1;
  147.     n=WPAD_ReadPending(WPAD_CHAN_ALL, wpad_callback);//WPAD_ScanPads();
  148.     DI_AudioThread(0);
  149.  
  150. if(n<WPAD_ERR_NONE || !valid_keys) {return 0;}
  151.    
  152.     debug_str="wii_joystick_read()";
  153.  
  154.     if(exit_by_reset)
  155.         {
  156.         exit(0);
  157.         }
  158.  
  159. DI_AudioThread(1);
  160. // lee los 4 wiimotes
  161. for(n=0;n<4;n++)
  162.     retj[n]=WPAD_Probe(n, &type[n]);
  163.  
  164.  
  165.    
  166.     for(n=0;n<4;n++)
  167.     {
  168.     if(retj[n]>=0)
  169.         {
  170.         butt=WPAD_ButtonsHeld(n);
  171.         is_readed=1;
  172.  
  173.         if(butt & WPAD_BUTTON_HOME) ret|=WII_HOME;
  174.  
  175.    
  176.  
  177.             if(type[n]==WPAD_EXP_NUNCHUK)
  178.                 {
  179.                 WPAD_Expansion(n,&w_exp);
  180.                 if(w_exp.nunchuk.js.pos.y<(128-48)) ret|=WII_DOWN;
  181.                 if(w_exp.nunchuk.js.pos.y>(128+48)) ret|=WII_UP;
  182.                 if(w_exp.nunchuk.js.pos.x<(128-48)) ret|=WII_LEFT;
  183.                 if(w_exp.nunchuk.js.pos.x>(128+48)) ret|=WII_RIGHT;
  184.  
  185.                 if(butt & WPAD_NUNCHUK_BUTTON_C) ret|=WII_A;
  186.                 if(butt & WPAD_NUNCHUK_BUTTON_Z) ret|=WII_B;
  187.                 }
  188.  
  189.             if(butt & WPAD_BUTTON_A) ret|=WII_A;
  190.             if(butt & WPAD_BUTTON_B) ret|=WII_B;
  191.  
  192.             if(butt & WPAD_BUTTON_1) ret|=WII_ONE;
  193.             if(butt & WPAD_BUTTON_2) ret|=WII_TWO;
  194.  
  195.             if(butt & WPAD_BUTTON_UP)   ret|=WII_UP;
  196.             if(butt & WPAD_BUTTON_DOWN) ret|=WII_DOWN;
  197.  
  198.             if(butt & WPAD_BUTTON_RIGHT) ret|=WII_RIGHT;
  199.             if(butt &  WPAD_BUTTON_LEFT) ret|=WII_LEFT;
  200.            
  201.  
  202.             if(butt & WPAD_BUTTON_MINUS) ret|=WII_MINUS;
  203.             if(butt & WPAD_BUTTON_PLUS) ret|=WII_PLUS;
  204.            
  205.        
  206.         }
  207.     }
  208. DI_AudioThread(0);
  209. if(!is_readed) return wii_nKeys;   
  210.  
  211. debug_str="Undef";
  212. return ret;
  213. }
  214.  
  215.  
  216.  
  217. char * get_name(char *name);
  218.  
  219.  
  220.  
  221.  
  222. int volume=204;
  223.  
  224.  
  225.  
  226. ////////////////////////////////////////////////////////////////////////
  227.  
  228.  
  229. /***************************************************************************/
  230. // seleccion de ficheros
  231. /***************************************************************************/
  232.  
  233.  
  234.  
  235. int nfiles=0;
  236. int ndirs=0;
  237.  
  238. #define MAX_ENTRY 512
  239.  
  240. struct _files
  241. {
  242.     int size;
  243.     char name[258];
  244.     char is_directory;
  245.     char is_selected;
  246. } files[MAX_ENTRY],swap_file;
  247.  
  248.  
  249. int njpg_files=0,nmusic_files=0,play_file=-1,current_jpg=-1;
  250. int music_playing=0, music_loop=0;
  251.  
  252. struct _play_files
  253. {
  254.     char name[258];
  255. } jpg_files[MAX_ENTRY], music_files[MAX_ENTRY], txt_file, swap_music;
  256.  
  257.  
  258.  
  259. // textreader
  260.  
  261. char *txt_file_mem=NULL;
  262. int txt_file_len=0;
  263.  
  264.  
  265. void music_shuffle()
  266. {
  267. int n,k;
  268. int s;
  269.     if(nmusic_files<=1) return;
  270.  
  271. for(s=0;s<10;s++)
  272.     for(n=0;n<nmusic_files;n++)
  273.         {
  274.         k=((rand() & 511)* nmusic_files)/512;
  275.         swap_music= music_files[n];
  276.         music_files[n]=music_files[k];
  277.         music_files[k]= swap_music;
  278.         }
  279.  
  280.     StopAudio();music_playing=0;play_file=-1;
  281.  
  282. }
  283.  
  284. // test_music_file: mode 0 -> Activa flag si fichero está en la lista; mode 1-> añade o borra fichero
  285.  
  286. void test_music_file(int index, int mode)
  287. {
  288. int n;
  289. int test;
  290.  
  291. //if(index>=nfiles) return;
  292. if(files[index].is_directory) {files[index].is_selected=0;return;}
  293.  
  294.     test=0;
  295.     for(n=0;n<nmusic_files;n++)
  296.         {
  297.         if(!strcmp(files[index].name, music_files[n].name))
  298.             {
  299.             test=1;break;
  300.             }
  301.         }
  302.     if(mode==0)
  303.         {
  304.         if(test)
  305.             files[index].is_selected=1;
  306.         else
  307.             files[index].is_selected=0;
  308.         }
  309.     if(mode==1)
  310.         {
  311.         if(!test)
  312.             {
  313.             if(nmusic_files<MAX_ENTRY) {files[index].is_selected=1;memcpy(music_files[nmusic_files].name,files[index].name,258);nmusic_files++;}
  314.             }
  315.         else
  316.             {
  317.             files[index].is_selected=0;
  318.             if(nmusic_files>0) nmusic_files--;
  319.             for(;n<nmusic_files;n++) {music_files[n]=music_files[n+1];}
  320.             }
  321.         }
  322. }
  323.  
  324. int loop_music_playing()
  325. {
  326. int n;
  327.  
  328.     if(play_file>=0 && music_playing)
  329.         {
  330.         n=StatusAudio();
  331.         if(n!=AUDIO_STATUS_RUNNING && n!=AUDIO_STATUS_PAUSED)
  332.             {
  333.             play_file++;
  334.             if(music_loop) if(play_file>=nmusic_files) play_file=0;
  335.             if(play_file<nmusic_files) {music_playing=1;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0; return 1;}
  336.             else {StopAudio();music_playing=0;play_file=-1;}
  337.             }
  338.         }
  339. return 0;
  340. }
  341.  
  342. int is_ext(char *a,char *b) // compara extensiones
  343. {
  344. int n,m;
  345.  
  346.     m=0;n=0;
  347.     while(a[n]!=0) {if(a[n]=='.') m=n; n++;}
  348.  
  349.     n=0;
  350.     while(b[n]!=0) {
  351.                    unsigned char t1,t2;
  352.                    t1=a[m];t2=b[n];
  353.                    if(t1>='A' && t1<='Z') t1+=32;
  354.                    if(t2>='A' && t2<='Z') t2+=32;
  355.                    if(t1!=t2) return 0; m++; n++;
  356.                    }
  357.  
  358.     if(a[m]==0) return 1;
  359.  
  360. return 0;
  361. }
  362.  
  363. char * get_name_short(char *name) // devuelve el nombre del fichero recortado a 36 caracteres
  364. {
  365. #define MAX_STR 36
  366. #define BRK_STR 17
  367.  
  368. static unsigned char name2[MAX_STR+4];
  369.  
  370. int n,m,l;
  371.  
  372.  
  373. m=0;n=-1;
  374. while(name[m]!=0) {if(name[m]=='/') n=m;m++;} // elimina la parte de directorio
  375. n++;
  376.  
  377. l=n;
  378. while(name[l]!=0) l++;
  379.  
  380. l-=n;
  381. if(l>=MAX_STR)
  382.     {
  383.     memcpy(name2,&name[n],BRK_STR);
  384.     name2[BRK_STR]='.';
  385.     name2[BRK_STR+1]='.';
  386.     n+=(l-MAX_STR)+(BRK_STR+2);
  387.  
  388.     for(m=BRK_STR+2;m<MAX_STR;m++)
  389.         {
  390.         name2[m]=name[n];
  391.         if(name[n]==0) break;
  392.         n++;
  393.         }
  394.     }
  395. else
  396.     {
  397.     for(m=0;m<MAX_STR;m++)
  398.         {
  399.         name2[m]=name[n];
  400.         if(name[n]==0) break;
  401.         n++;
  402.         }
  403.     }
  404.     name2[m]=0;
  405.  
  406. #undef MAX_STR
  407. #undef BRK_STR
  408.  
  409. return ((char *)name2);
  410. }
  411.  
  412. char * get_name_short_fromUTF8(char *name) // devuelve el nombre del fichero recortado a 36 caracteres
  413. {
  414. #define MAX_STR 36
  415. #define BRK_STR 17
  416.  
  417. static unsigned char name2[MAX_STR+4];
  418.  
  419. int n,m,l,s;
  420.  
  421.  
  422. m=0;n=-1;
  423. while(name[m]!=0) {if(name[m]=='/') n=m;m++;} // elimina la parte de directorio
  424. n++;
  425.  
  426. l=n;
  427. while(name[l]!=0) l++;
  428.  
  429. l-=n;
  430. if(l>=MAX_STR)
  431.     {
  432.     s=n;
  433.     for(m=0;m<BRK_STR;m++)
  434.         {
  435.         if((name[s] & 0xc0)==0xc0 && (name[s+1] & 0xc0)==0x80)
  436.             {
  437.             name2[m]= (((name[s] & 3)<<6) | (name[s+1] & 63));
  438.             s++;
  439.             }
  440.         else name2[m]=name[s];
  441.         s++;
  442.         }
  443.    
  444.     //memcpy(name2,&name[n],BRK_STR);
  445.     name2[m]='.';
  446.     name2[m+1]='.';
  447.     m+=2;
  448.     n+=(l-MAX_STR)+(m);
  449.  
  450.     for(;m<MAX_STR;m++)
  451.         {
  452.         if((name[n] & 0xc0)==0xc0 && (name[n+1] & 0xc0)==0x80)
  453.             {
  454.             name2[m]= (((name[n] & 3)<<6) | (name[n+1] & 63));
  455.             n++;
  456.             }
  457.         else name2[m]=name[n];
  458.  
  459.         if(name[n]==0) break;
  460.         n++;
  461.         }
  462.     }
  463. else
  464.     {
  465.     for(m=0;m<MAX_STR;m++)
  466.         {
  467.         if((name[n] & 0xc0)==0xc0 && (name[n+1] & 0xc0)==0x80)
  468.             {
  469.             name2[m]= (((name[n] & 3)<<6) | (name[n+1] & 63));
  470.             n++;
  471.             }
  472.         else name2[m]=name[n];
  473.         if(name[n]==0) break;
  474.         n++;
  475.         }
  476.     }
  477.     name2[m]=0;
  478.  
  479. #undef MAX_STR
  480. #undef BRK_STR
  481.  
  482. return ((char *)name2);
  483. }
  484.  
  485. void char_to_utf8(char *s, char *d)
  486. {
  487. u8 *c= (u8 *) s;
  488.  
  489. while(*c!=0)
  490.     {
  491.     if((*c & 0xc0)==0xc0 && (*(c+1) & 0xc0)==0x80) // esto es UTF-8!
  492.         {
  493.         *d++=*c++;
  494.         *d++=*c;
  495.         }
  496.     else
  497.     if(*c>=0x80) // convierte a UTF-8
  498.         {
  499.         *d++= 192 | (*c>>6);
  500.         *d++= 128 | (*c & 63);
  501.         }
  502.     else *d++=*c;
  503.  
  504.     c++;
  505.     }
  506. *d=0;
  507. }
  508.  
  509. void utf8_to_char(char *s, char *d)
  510. {
  511. u8 *c= (u8 *) s;
  512.  
  513. while(*c!=0)
  514.     {
  515.    
  516.     if((*c & 0xc0)==0xc0 && (*(c+1) & 0xc0)==0x80)
  517.         {
  518.         *d++= (((*c & 3)<<6) | (*(c+1) & 63));
  519.         c++;
  520.         }
  521.     else *d++=*c;
  522.  
  523.     c++;
  524.     }
  525. *d=0;
  526. }
  527.  
  528. char * get_name(char *name) // devuelve el nombre del fichero completo
  529. {
  530. static unsigned char name2[256];
  531.  
  532. int n,m;
  533.  
  534.     m=0;n=-1;
  535.  
  536.     while(name[m]!=0) {if(name[m]=='/') n=m;m++;}
  537.     n++;
  538.  
  539.     for(m=0;m<255;m++)
  540.         {
  541.         name2[m]=name[n];
  542.         if(name[n]==0) break;
  543.         n++;
  544.         }
  545.  
  546.     name2[m]=0;
  547.  
  548. return ((char *) name2);
  549. }
  550.  
  551. char * get_name_from_UTF8(char *name) // devuelve el nombre del fichero completo
  552. {
  553. static unsigned char name2[256];
  554.  
  555. int n,m;
  556.  
  557.     m=0;n=-1;
  558.  
  559.     while(name[m]!=0) {if(name[m]=='/') n=m;m++;}
  560.     n++;
  561.  
  562.     for(m=0;m<255;m++)
  563.         {
  564.         if((name[n] & 0xc0)==0xc0 && (name[n+1] & 0xc0)==0x80)
  565.             {
  566.             name2[m]= (((name[n] & 3)<<6) | (name[n+1] & 63));
  567.             n++;
  568.             }
  569.         else
  570.             name2[m]=name[n];
  571.  
  572.         if(name[n]==0) break;
  573.         n++;
  574.         }
  575.  
  576.     name2[m]=0;
  577.  
  578. return ((char *) name2);
  579. }
  580.  
  581. char * LoadZipTxt(char *name, int *fsize)
  582. {
  583. unz_global_info gi;
  584. unzFile uf;
  585. int error;
  586. int n;
  587. char zip_file[256];
  588. unz_file_info zip_file_info;
  589.  
  590. char *mem=NULL;
  591.  
  592. *fsize=0;
  593.  
  594.     uf = unzOpen (name);
  595.  
  596.     if (uf == NULL) return NULL;
  597.  
  598.     error = unzGetGlobalInfo (uf, &gi);
  599.     if(error != UNZ_OK)  {unzClose(uf);return NULL;}
  600.  
  601.     for (n=0; n<gi.number_entry; n++)
  602.         {
  603.           error = unzGetCurrentFileInfo (uf, &zip_file_info, zip_file,
  604.                        sizeof (zip_file), NULL, 0, NULL, 0);
  605.  
  606.           if(error != UNZ_OK)  {unzClose(uf);return NULL;}
  607.  
  608.           if (is_ext(zip_file, ".txt")) break;
  609.            
  610.           if (n < (gi.number_entry-1))
  611.             {
  612.             error = unzGoToNextFile (uf);
  613.             if(error != UNZ_OK)  {unzClose(uf);return NULL;}
  614.             }
  615.         }
  616.     //
  617.  
  618.     mem =malloc(zip_file_info.uncompressed_size+0x2000);
  619.     if (mem == NULL) {unzClose(uf);return NULL;}
  620.  
  621.     error = unzOpenCurrentFile (uf);
  622.     if(error != UNZ_OK)  {free(mem);mem=0;unzClose(uf);return NULL;}
  623.  
  624.     *fsize=zip_file_info.uncompressed_size;
  625.     n=0;
  626.     while(n<zip_file_info.uncompressed_size)
  627.         {
  628.         error = unzReadCurrentFile (uf, mem+n, zip_file_info.uncompressed_size-n);
  629.         if (error <= 0) break;
  630.  
  631.         n+=error;
  632.         }
  633.      
  634.  
  635.      if(error <0)  {*fsize=0;free(mem);mem=0;unzCloseCurrentFile(uf);unzClose(uf);return NULL;}
  636.  
  637.      error = unzCloseCurrentFile (uf);
  638.      if(error != UNZ_OK)  {*fsize=0;unzClose(uf);free(mem);mem=0;return NULL;}
  639.  
  640. return mem;
  641. }
  642.  
  643.  
  644.  
  645. int have_device=0;
  646.  
  647. int current_device=0;
  648.  
  649.  
  650. void read_list_file(unsigned char *dirname, int flag)
  651. {
  652. DIR_ITER *fd;
  653.  
  654. static char namefile[256*4];
  655.  
  656. static struct stat filestat;
  657.  
  658.  
  659. static char swap[257];
  660.  
  661. int n,m,f;
  662.  
  663. if(!dirname) sprintf(swap, "%s", path_file);
  664. else
  665.     {
  666.     sprintf(path_file, "%s", dirname);
  667.  
  668.     n=0;while(dirname[n]!=0) n++;
  669.     if(dirname[n-1]=='/') // esto solo pasa si es directorio raiz
  670.         {sprintf(swap, "%s", dirname);dirname=0;}
  671.     else  
  672.         {
  673.         sprintf(swap, "%s/", dirname);
  674.         if(swap[n-1]=='.')
  675.             {n--;while(swap[n]!='/') n--;n--;while(swap[n]!='/') n--; if(swap[n-1]==':') dirname=0; n++;swap[n]=0;} // para volver al directorio anterior
  676.         }
  677.     }
  678.  
  679. ndirs=0;
  680. nfiles = 0;
  681. files[nfiles].is_selected=0;
  682. if(!dirname)
  683.     {
  684.    
  685.     if(current_device==0 && (have_device & 2)!=0)
  686.         {
  687.         sprintf(files[nfiles].name, ".[USB]");
  688.         ndirs++;files[nfiles].is_directory=1;
  689.         files[nfiles].is_selected=0;
  690.         nfiles++;
  691.         }
  692.     if(current_device==1 && (have_device & 1)!=0)
  693.         {
  694.         sprintf(files[nfiles].name, ".[SD]");
  695.         ndirs++;files[nfiles].is_directory=1;
  696.         files[nfiles].is_selected=0;
  697.         nfiles++;
  698.         }
  699.     }
  700.  
  701.     fd = diropen(swap);
  702.  
  703.     if(fd != NULL)
  704.         {
  705.  
  706.         while(nfiles < MAX_ENTRY)
  707.             {
  708.             files[nfiles].is_directory=0;
  709.             files[nfiles].is_selected=0;
  710.  
  711.             if(dirnext(fd, namefile, &filestat)!=0) break;
  712.  
  713.             if(namefile[0]=='.' && namefile[1]==0) continue;
  714.            
  715.             sprintf(files[nfiles].name, "%s%s", swap, namefile);
  716.        
  717.             if((filestat.st_mode & S_IFDIR))
  718.                 {
  719.                 files[nfiles].size=0;
  720.                 ndirs++;files[nfiles].is_directory=1;
  721.                 }
  722.             else
  723.                 {
  724.                 if(flag==0)
  725.                     {
  726.                     if(!(is_ext(files[nfiles].name,".mp3") || is_ext(files[nfiles].name,".ogg") || is_ext(files[nfiles].name,".m3u") )) continue;
  727.                     if(!is_ext(files[nfiles].name,".m3u")) test_music_file(nfiles, 0);
  728.                     }
  729.  
  730.                 if(flag==1)
  731.                     if(!(is_ext(files[nfiles].name,".jpg") || is_ext(files[nfiles].name,".jpeg"))) continue;
  732.  
  733.                 if(flag==2)
  734.                     if(!(is_ext(files[nfiles].name,".txt") || is_ext(files[nfiles].name,".zip"))) continue;
  735.  
  736.                 files[nfiles].size=filestat.st_size;
  737.                 }
  738.            
  739.             nfiles++;
  740.             }
  741.    
  742.     dirclose(fd);  
  743.     }
  744.    
  745.   if(!nfiles)
  746.         {
  747.        
  748.         if(current_device==0 && (have_device & 2)!=0)
  749.             {
  750.             sprintf(files[nfiles].name, ".[USB]");
  751.             ndirs++;files[nfiles].is_directory=1;
  752.             files[nfiles].is_selected=0;
  753.             nfiles++;
  754.             }
  755.         if(current_device==1 && (have_device & 1)!=0)
  756.             {
  757.             sprintf(files[nfiles].name, ".[SD]");
  758.             ndirs++;files[nfiles].is_directory=1;
  759.             files[nfiles].is_selected=0;
  760.             nfiles++;
  761.             }
  762.            
  763.         }
  764.  
  765.     for(n=0;n<(nfiles);n++) //ordena
  766.     for(m=n+1;m<nfiles;m++)
  767.         {
  768.         f=0;
  769.            
  770.         if(files[m].is_directory==1 && files[n].is_directory==0) f=1;
  771.         if(f==0)
  772.             if(files[m].is_directory==files[n].is_directory)
  773.                 if(strcmp(files[m].name,files[n].name)<0) f=1;
  774.         if(f)
  775.             {
  776.             f=0;
  777.             swap_file=files[m];
  778.             files[m]=files[n];
  779.             files[n]=swap_file;
  780.             }
  781.         }
  782.  
  783. }
  784.  
  785.  
  786. void fun_exit()
  787. {
  788. int m=0;
  789.  
  790.     Screen_flip();
  791.     autocenter=0;
  792.     sizeletter=1;
  793.  
  794.         m=SCR_HEIGHT/2;
  795.  
  796.         SetTexture(MOSAIC_PATTERN);
  797.         DrawRoundFillBox(32,m-128, 640-64, 256, 0,0xff803000);
  798.         SetTexture(NULL);
  799.         DrawRoundBox(32,m-128, 640-64, 256, 0, 6, 0xfff08020);
  800.  
  801.         autocenter=1;
  802.         PX=0;PY=m-16;
  803.         s_printf("Closing All");
  804.         autocenter=0;
  805.  
  806.     Screen_flip();
  807.     StopAudio();
  808.  
  809.     write_cfg(path_txt_cfg);
  810.  
  811.     WPAD_Shutdown();
  812.     ASND_End();
  813.  
  814.     if(have_device & 1) fatUnmount(PI_INTERNAL_SD);
  815.     if(have_device & 2) fatUnmount(PI_USBSTORAGE);
  816.  
  817.     VIDEO_WaitVSync();
  818.     VIDEO_WaitVSync();
  819.  
  820.     sleep(2);
  821.  
  822.     if(exit_by_reset==2)
  823.         SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
  824.     if(exit_by_reset==3)
  825.         SYS_ResetSystem(SYS_POWEROFF_STANDBY, 0, 0);
  826. }
  827.  
  828.  
  829.  
  830. struct my_error_mgr {
  831.   struct jpeg_error_mgr pub;    /* "public" fields */
  832.  
  833.   jmp_buf setjmp_buffer;    /* for return to caller */
  834. };
  835.  
  836. typedef struct my_error_mgr * my_error_ptr;
  837.  
  838. char jpg_error_str[JMSG_LENGTH_MAX];
  839.  
  840. void  my_error_exit (j_common_ptr cinfo)
  841. {
  842.   /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
  843.   my_error_ptr myerr = (my_error_ptr) cinfo->err;
  844.  
  845.   /* Always display the message. */
  846.   /* We could postpone this until after returning, if we chose. */
  847.  // (*cinfo->err->output_message) (cinfo);
  848. (*cinfo->err->format_message) (cinfo, jpg_error_str);
  849.   /* Return control to the setjmp point */
  850.   longjmp(myerr->setjmp_buffer, 1);
  851. }
  852.  
  853. unsigned *jpeg_buf=NULL;
  854.  
  855. int jpeg_tdx,jpeg_tdy; // texel w-h
  856.  
  857. int jpeg_w,jpeg_h; // pixel w-h
  858.  
  859.  
  860. int read_JPEG_file (char * filename)
  861. {
  862. /* This struct contains the JPEG decompression parameters and pointers to
  863. * working space (which is allocated as needed by the JPEG library).
  864. */
  865. struct jpeg_decompress_struct cinfo;
  866. /* We use our private extension JPEG error handler.
  867. * Note that this struct must live as long as the main JPEG parameter
  868. * struct, to avoid dangling-pointer problems.
  869. */
  870. struct my_error_mgr jerr;
  871. /* More stuff */
  872. FILE * infile;      /* source file */
  873. JSAMPARRAY buffer;      /* Output row buffer */
  874. int row_stride;     /* physical row width in output buffer */
  875.  
  876. int n,m;
  877.  
  878. int a,b,k,l,same_w;
  879. int rr,gg,bb;
  880.  
  881. u8 *buf;
  882.  
  883. /* In this example we want to open the input file before doing anything else,
  884. * so that the setjmp() error recovery below can assume the file is open.
  885. * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
  886. * requires it in order to read binary files.
  887. */
  888.     jpg_error_str[0]=0;
  889.     if ((infile = fopen(filename, "rb")) == NULL) {
  890.  
  891.     sprintf(jpg_error_str,"Can't open file");
  892.     return 0;
  893.     }
  894.  
  895.     /* Step 1: allocate and initialize JPEG decompression object */
  896.  
  897.     /* We set up the normal JPEG error routines, then override error_exit. */
  898.     cinfo.err = jpeg_std_error(&jerr.pub);
  899.     jerr.pub.error_exit = my_error_exit;
  900.     /* Establish the setjmp return context for my_error_exit to use. */
  901.     if (setjmp(jerr.setjmp_buffer)) {
  902.     /* If we get here, the JPEG code has signaled an error.
  903.      * We need to clean up the JPEG object, close the input file, and return.
  904.      */
  905.  
  906.     //printf("Error!!!\n");
  907.     jpeg_destroy_decompress(&cinfo);
  908.     fclose(infile);
  909.     return 0;
  910.     }
  911.     /* Now we can initialize the JPEG decompression object. */
  912.     jpeg_create_decompress(&cinfo);
  913.  
  914.     /* Step 2: specify data source (eg, a file) */
  915.  
  916.     jpeg_stdio_src(&cinfo, infile);
  917.  
  918.     /* Step 3: read file parameters with jpeg_read_header() */
  919.  
  920.     (void) jpeg_read_header(&cinfo, TRUE);
  921.     /* We can ignore the return value from jpeg_read_header since
  922.     *   (a) suspension is not possible with the stdio data source, and
  923.     *   (b) we passed TRUE to reject a tables-only JPEG file as an error.
  924.     * See libjpeg.doc for more info.
  925.     */
  926.  
  927.     /* Step 4: set parameters for decompression */
  928.  
  929.     /* In this example, we don't need to change any of the defaults set by
  930.     * jpeg_read_header(), so we do nothing here.
  931.     */
  932.  
  933.     /* Step 5: Start decompressor */
  934.  
  935.     (void) jpeg_start_decompress(&cinfo);
  936.     /* We can ignore the return value since suspension is not possible
  937.     * with the stdio data source.
  938.     */
  939.  
  940.     /* We may need to do some setup of our own at this point before reading
  941.     * the data.  After jpeg_start_decompress() we have the correct scaled
  942.     * output image dimensions available, as well as the output colormap
  943.     * if we asked for color quantization.
  944.     * In this example, we need to make an output work buffer of the right size.
  945.     */
  946.     /* JSAMPLEs per row in output buffer */
  947.     row_stride = cinfo.output_width * cinfo.output_components;
  948.  
  949.     // printf("width %i %i\n",cinfo.output_width, cinfo.output_components);
  950.     /* Make a one-row-high sample array that will go away when done with image */
  951.     buffer = (*cinfo.mem->alloc_sarray)
  952.         ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
  953.  
  954.  
  955.  
  956.     jpeg_w=cinfo.output_width;
  957.     jpeg_h=cinfo.output_height;
  958.  
  959.  
  960.     if(!buffer || jpg_error_str[0]!=0)
  961.     {
  962.     jpeg_destroy_decompress(&cinfo);
  963.     fclose(infile);
  964.     return 0;
  965.     }
  966.     /* Step 6: while (scan lines remain to be read) */
  967.     /*           jpeg_read_scanlines(...); */
  968.  
  969.     /* Here we use the library's state variable cinfo.output_scanline as the
  970.     * loop counter, so that we don't have to keep track ourselves.
  971.     */
  972.     n=0;
  973.     jpeg_tdx=(jpeg_w>>3)<<3; if(jpeg_tdx>1024) jpeg_tdx=1024;
  974.     jpeg_tdy=(jpeg_h>>3)<<3; if(jpeg_tdy>1024) jpeg_tdy=1024;
  975.     a=0;k=0;
  976.     while (cinfo.output_scanline < cinfo.output_height) {
  977.     /* jpeg_read_scanlines expects an array of pointers to scanlines.
  978.      * Here the array is only one element long, but you could ask for
  979.      * more than one scanline at a time if that's more convenient.
  980.      */
  981.     (void) jpeg_read_scanlines(&cinfo, buffer, 1);
  982.     /* Assume put_scanline_someplace wants a pointer and sample count. */
  983.     // put_scanline_someplace(buffer[0], row_stride);
  984.     if(jpg_error_str[0]!=0)
  985.     {
  986.     jpeg_destroy_decompress(&cinfo);
  987.     fclose(infile);
  988.     return 0;
  989.     }
  990.  
  991.     buf=(u8 *) buffer[0];
  992.     rr=buf[2];
  993.     gg=buf[1];
  994.     bb=buf[0];
  995.  
  996.         b=0;l=0;
  997.         same_w=0;
  998.         for(m=0;m<jpeg_w;m++) // re-scale to the max 1024x1024
  999.             {
  1000.             if(!same_w)
  1001.                 {
  1002.                 jpeg_buf[(k*jpeg_tdx)+l]=0xff000000 | (bb<<16) | (gg<<8) |  (rr);
  1003.                 }
  1004.             else
  1005.                 {
  1006.                 rr+=buf[2];
  1007.                 gg+=buf[1];
  1008.                 bb+=buf[0];
  1009.                 }
  1010.            
  1011.             buf+=3;
  1012.             b+=jpeg_tdx;if(b>=jpeg_w)
  1013.                 {
  1014.                 if(same_w)
  1015.                   {
  1016.                   same_w++;
  1017.                   rr/=same_w;
  1018.                   gg/=same_w;
  1019.                   bb/=same_w;
  1020.                   jpeg_buf[(k*jpeg_tdx)+l]=0xff000000 | (bb<<16) | (gg<<8) |  (rr);
  1021.                   }
  1022.                 same_w=0;b-=jpeg_w;l++;if(l>=jpeg_tdx) break;
  1023.                 rr=buf[2];
  1024.                 gg=buf[1];
  1025.                 bb=buf[0];
  1026.                 } else same_w++;
  1027.             }
  1028.         a+=jpeg_tdy;if(a>=jpeg_h) {a-=jpeg_h;k++;if(k>=jpeg_tdy) break;}
  1029.        
  1030.    
  1031.     n++;
  1032.     }
  1033.  
  1034.     /* Step 7: Finish decompression */
  1035.  
  1036.     (void) jpeg_finish_decompress(&cinfo);
  1037.     /* We can ignore the return value since suspension is not possible
  1038.     * with the stdio data source.
  1039.     */
  1040.  
  1041.     /* Step 8: Release JPEG decompression object */
  1042.  
  1043.     /* This is an important step since it will release a good deal of memory. */
  1044.     jpeg_destroy_decompress(&cinfo);
  1045.  
  1046.     /* After finish_decompress, we can close the input file.
  1047.     * Here we postpone it until after no more JPEG errors are possible,
  1048.     * so as to simplify the setjmp error logic above.  (Actually, I don't
  1049.     * think that jpeg_destroy can do an error exit, but why assume anything...)
  1050.     */
  1051.     fclose(infile);
  1052.  
  1053.     /* At this point you may want to check to see whether any corrupt-data
  1054.     * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
  1055.     */
  1056.     if(jpg_error_str[0]!=0)
  1057.     {
  1058.     return 0;
  1059.     }
  1060.     /* And we're done! */
  1061. return 1;
  1062. }
  1063.  
  1064.  
  1065.  
  1066.  
  1067.  
  1068. GXTexObj scr_tex;
  1069. GXTexObj icon_tex[icons_num_sprites];
  1070.  
  1071. u16 *animate_mem=NULL;
  1072.  
  1073. void animate_background()
  1074. {
  1075. int n,m,k;
  1076. static int l=0;
  1077.  
  1078. n=icons_num_sprites-2;
  1079.  
  1080. if(!animate_mem) animate_mem=memalign(32, icons_sprites[n].sx*icons_sprites[n].sy*2);
  1081. if(!animate_mem) return;
  1082. l++;
  1083.  
  1084. k=l>>2;
  1085. for(m=0;m<icons_sprites[n].sy;m++)
  1086.     {
  1087.     k=(k % icons_sprites[n].sy);
  1088.     memcpy(animate_mem+k*icons_sprites[n].sx, ((u16 *)icons_sprites[n].ptr)+m*icons_sprites[n].sx, icons_sprites[n].sx*2);
  1089.     k++;
  1090.     }
  1091. CreateTexture(&icon_tex[n], TLUT_SRGB5A1, animate_mem, icons_sprites[n].sx, icons_sprites[n].sy, 0);
  1092. }
  1093.  
  1094.  
  1095. int audio_pause=0;
  1096.  
  1097.  
  1098. void select_file(int flag)
  1099. {
  1100. int n,m,l,f=0,len,max_entry;
  1101. static  int posfile=0;
  1102. static int old_flag=-1;
  1103. int flash=0;
  1104.  
  1105. read_list_file((void *) path_file, flag);
  1106.  
  1107. if(flag!=old_flag)
  1108.     {
  1109.     posfile=0;
  1110.     old_flag=flag;
  1111.     }
  1112.  
  1113. while(1)
  1114.     {
  1115.    
  1116.  
  1117.     flash++;
  1118.  
  1119.     if(exit_by_reset) break;
  1120.  
  1121.     loop_music_playing();
  1122.  
  1123.     m=0;
  1124.    
  1125.     sizeletter=4;
  1126.  
  1127.    // SetTexture(MOSAIC_PATTERN);DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff603000);
  1128.     animate_background();
  1129.     SetTexture(&icon_tex[icons_num_sprites-2]);
  1130.     DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff906000);
  1131.    
  1132.  
  1133.     // header
  1134.     SetTexture(CROSS_PATTERN);
  1135.     DrawRoundFillBox(8,8, 640-16, 32, 0, 0xff302000);
  1136.     SetTexture(NULL_PATTERN);
  1137.     DrawRoundBox(8,8, 640-16, 32, 0, 2, 0xff804000);
  1138.     PX=0;PY=16;color=0xffffffff;autocenter=1;
  1139.    
  1140.     if(flag==0) s_printf("SELECT MUSIC FILES");
  1141.     if(flag==1) s_printf("SELECT JPEG FILES");
  1142.     if(flag==2) s_printf("SELECT TEXT FILES");
  1143.  
  1144.     autocenter=0;
  1145.    
  1146.     // file list
  1147.    
  1148.  
  1149.     SetTexture(CROSS_PATTERN);
  1150.     DrawRoundFillBox(8,48, 640-16, SCR_HEIGHT-32-48, 0, 0xff302000);
  1151.  
  1152.     SetTexture(NULL_PATTERN);
  1153.     DrawRoundBox(8, 48, 640-16, SCR_HEIGHT-32-48, 0, 2, 0xff804000);
  1154.  
  1155.    
  1156.     max_entry=(SCR_HEIGHT-32-48)/20;
  1157.  
  1158.     SetTexture(NULL);
  1159.     DrawRoundFillBox(8,SCR_HEIGHT-28, 640-16, 24, 0, 0xff201010);
  1160.     SetTexture(NULL_PATTERN);
  1161.     DrawRoundBox(8,SCR_HEIGHT-28, 640-16, 24, 0, 2, 0xff804000);
  1162.    
  1163.     PX=24;PY=SCR_HEIGHT-24;color=0xffffffff;autocenter=1;
  1164.     sizeletter=3;
  1165.     if(flag==0)
  1166.         s_printf("Use A to select one file and PLUS to select All");
  1167.     if(flag==1)
  1168.         s_printf("Use A to select one file and PLUS to select All");
  1169.     if(flag==2)
  1170.         s_printf("Use A to select one file");
  1171.     autocenter=0;
  1172.     sizeletter=4;
  1173.  
  1174.     for(n=(posfile-max_entry/2)*(nfiles>=max_entry);n<posfile+max_entry;n++)
  1175.             {
  1176.             if(n<0) continue;
  1177.             if(n>=nfiles) break;
  1178.             if(m>=max_entry) break;
  1179.            
  1180.            
  1181.             PX=16;PY=48+2+m*20;
  1182.             color=0xffffffff;
  1183.  
  1184.             if(n==posfile)
  1185.                 {
  1186.                 len=38;
  1187.  
  1188.                 //if(flash & 8)
  1189.                 DrawRoundFillBox(PX,PY-2, len*16, 20, 0, 0xff00004f);
  1190.                
  1191.                 DrawRoundBox(PX,PY-2, len*16, 20, 0, 2, 0xff30ffff);
  1192.  
  1193.                 }
  1194.  
  1195.             if(files[n].is_directory)
  1196.                 {
  1197.                 if(files[n].name[0]=='.' && files[n].name[1]=='[')
  1198.                     {
  1199.                     color=0xffffff00;
  1200.                     s_printf("%s",&files[n].name[1]);
  1201.                     }
  1202.                 else
  1203.                     {
  1204.                     color=0xff00ffff;
  1205.                
  1206.                     s_printf("<%s>",get_name_short_fromUTF8(&files[n].name[0]));
  1207.                     }
  1208.                 }
  1209.             else
  1210.                 {
  1211.                 color=0xffffffff;
  1212.                 if(files[n].is_selected) color=0xff6fff6f;
  1213.                
  1214.                 if(flag==2)
  1215.                     if(!strcmp(files[n].name,txt_file.name)) color=0xff6fff6f;
  1216.  
  1217.                 s_printf("%s", (char *) get_name_short_fromUTF8(&files[n].name[0]));
  1218.                 }
  1219.            
  1220.             bkcolor=0;color=0xffffffff;
  1221.             m++;
  1222.             }
  1223.    
  1224.      wii_nKeys=wii_joystick_read(0);
  1225.    
  1226.      new_key=wii_nKeys & (~old_key);
  1227.      old_key=wii_nKeys;
  1228.  
  1229.      if(!(old_key  & (WII_UP | WII_DOWN))) f=0;
  1230.            
  1231.             if(old_key  & WII_UP)
  1232.                 {
  1233.                 if(f==0) f=2;
  1234.                 else if(f & 1) f=2;
  1235.                 else {f+=2;if(f>40) {f=34;new_key|=WII_UP;}}
  1236.                 }
  1237.             if(old_key  & WII_DOWN)
  1238.                 {
  1239.                 if(f==0) f=1;
  1240.                 else if(!(f & 1)) f=1;
  1241.                 else {f+=2;if(f>41) {f=35;new_key|=WII_DOWN;}}
  1242.                 }
  1243.             if(new_key & (WII_HOME | WII_ONE | WII_TWO)) break;
  1244.            
  1245.        
  1246.  
  1247.             if(nfiles>0) if(new_key & WII_PLUS)
  1248.                 {
  1249.                
  1250.                         if(flag==1)
  1251.                             {
  1252.                             current_jpg=-1;
  1253.                             njpg_files=0;
  1254.                             for(n=0;n<nfiles;n++)
  1255.                                 {
  1256.                                 if(!files[n].is_directory)
  1257.                                 if(is_ext(files[n].name,".jpg") || is_ext(files[n].name,".jpeg"))
  1258.                                     {
  1259.                                     memcpy(jpg_files[njpg_files].name,files[n].name,258);
  1260.                                     current_jpg=0;
  1261.                                     njpg_files++;
  1262.                                     if(njpg_files>=MAX_ENTRY) break;
  1263.                                     }
  1264.                                 }
  1265.                             break;
  1266.                             }
  1267.                         else
  1268.                         if(flag==0)
  1269.                             {
  1270.                             for(n=0;n<nfiles;n++)
  1271.                                 {
  1272.                                 if(!files[n].is_directory)
  1273.                                 if(is_ext(files[n].name,".mp3") || is_ext(files[n].name,".ogg"))
  1274.                                     {
  1275.                                     test_music_file(n, 1);
  1276.                                    
  1277.                                     }
  1278.                                 }
  1279.                            
  1280.                             }
  1281.                            
  1282.            
  1283.                 }
  1284.  
  1285.             if(nfiles>0) if(new_key & WII_A)
  1286.                 {
  1287.                
  1288.                
  1289.                     if(!files[posfile].is_directory)
  1290.                         {
  1291.                        
  1292.                         if(is_ext(files[posfile].name,".txt") || is_ext(files[posfile].name,".zip"))
  1293.                             {
  1294.                             FILE *fp;
  1295.                            
  1296.                             memcpy(txt_file.name,files[posfile].name,258);
  1297.                        
  1298.                             if(txt_file_mem) free(txt_file_mem);txt_file_mem=0;
  1299.  
  1300.                             txt_file_len=0;
  1301.  
  1302.                             if(is_ext(files[posfile].name,".zip"))
  1303.                                 txt_file_mem = LoadZipTxt(txt_file.name, &txt_file_len);
  1304.                             else
  1305.                                 {
  1306.                                 fp=fopen(txt_file.name,"r"); // lee el fichero de texto
  1307.                                 if(fp!=0)
  1308.                                     {
  1309.                                     fseek(fp,0,SEEK_END);
  1310.                                     txt_file_len=ftell(fp);
  1311.                                     fseek(fp,0,SEEK_SET);
  1312.                                     txt_file_mem=malloc(txt_file_len+128);
  1313.                                     if(txt_file_mem)
  1314.                                         {n=fread(txt_file_mem,1,txt_file_len,fp);
  1315.                                         if(n<0) {txt_file_len=0;free(txt_file_mem);txt_file_mem=0;} else txt_file_len=n;
  1316.                                         }
  1317.                                     else txt_file_len=0;
  1318.                                     fclose(fp);
  1319.                                     }
  1320.                                 }
  1321.  
  1322.                             if(txt_file_len!=0)
  1323.                                 {
  1324.                                 read_txt_cfg(path_txt_cfg);
  1325.                                 text_init(txt_file_mem, txt_file_len, txt_file.name);
  1326.                                 break;
  1327.                                 }
  1328.                             }
  1329.                         else
  1330.                         if(is_ext(files[posfile].name,".jpg") || is_ext(files[posfile].name,".jpeg"))
  1331.                             {
  1332.                             current_jpg=-1;
  1333.                             njpg_files=0;
  1334.                             for(n=0;n<nfiles;n++)
  1335.                                 {
  1336.                                 if(!files[n].is_directory)
  1337.                                 if(is_ext(files[n].name,".jpg") || is_ext(files[n].name,".jpeg"))
  1338.                                     {
  1339.                                     memcpy(jpg_files[njpg_files].name,files[n].name,258);
  1340.                                     if(n==posfile) current_jpg=njpg_files;
  1341.                                     njpg_files++;
  1342.                                     if(njpg_files>=MAX_ENTRY) break;
  1343.                                     }
  1344.                                 }
  1345.                             break;
  1346.                             }
  1347.                         else
  1348.                             {
  1349.                             #if 1
  1350.                             if(nmusic_files<MAX_ENTRY)
  1351.                                 {
  1352.                                 if(is_ext(files[posfile].name,".mp3") || is_ext(files[posfile].name,".ogg"))
  1353.                                     {
  1354.                                     test_music_file(posfile, 1);
  1355.                                     }
  1356.                                  else
  1357.                                  if(is_ext(files[posfile].name,".m3u"))
  1358.                                     {
  1359.                                     FILE *fp;
  1360.  
  1361.                                     memcpy(temp_buffer,files[posfile].name,258); // copia el nombre al archivo temporal
  1362.                                     m=n=0;
  1363.                                     while(temp_buffer[n]!=0) {if(temp_buffer[n]=='/') m=n+1; n++;}
  1364.                                     l=m;
  1365.                                     temp_buffer[l]=0;
  1366.  
  1367.                                     fp=fopen(files[posfile].name,"r"); // lee el fichero m3u
  1368.  
  1369.                                     if(fp!=0)
  1370.                                         {
  1371.                                         nmusic_files=0;
  1372.  
  1373.                                         while(fgets((void *) &temp_buffer[512], 256, fp))
  1374.                                             {
  1375.                                            
  1376.                                             n=512;
  1377.                                             while(temp_buffer[n]!=0) {if(temp_buffer[n]<32) {temp_buffer[n]=0;break;} n++;}
  1378.                                            
  1379.                                             if(is_ext((void *) &temp_buffer[512],".mp3") || is_ext((void *) &temp_buffer[512],".ogg"))
  1380.                                                 {
  1381.                                                
  1382.                                                 if(nmusic_files<MAX_ENTRY)
  1383.                                                     {
  1384.                                                     m=n=512;
  1385.                                                     while(temp_buffer[n]!=0) {if(temp_buffer[n]=='/' || temp_buffer[n]=='\\') m=n+1; n++;}
  1386.                                                     n-=512;
  1387.                                                     if((l+n)>258) {n=257-l;temp_buffer[n+512]=0;}
  1388.                                                     sprintf((void *) &temp_buffer[1024],"%s%s",&temp_buffer[0],&temp_buffer[m]);
  1389.                                                     char_to_utf8((void *) &temp_buffer[1024],music_files[nmusic_files].name);
  1390.  
  1391.                                                     nmusic_files++;
  1392.                                                     }
  1393.                                                 else break;
  1394.                                                
  1395.                                                 }
  1396.                                            
  1397.                                             }
  1398.                                        
  1399.                                         fclose(fp);
  1400.  
  1401.                                         if(nmusic_files)
  1402.                                             {
  1403.                                             play_file=0;
  1404.                                             music_playing=1;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0;
  1405.                                             break; // retorna al player
  1406.                                             }
  1407.                                         } //clos
  1408.                                     }// m3u
  1409.                                 }
  1410.                             #endif
  1411.                             }
  1412.                
  1413.                         }
  1414.                       else
  1415.                         {
  1416.                          // cambio de device
  1417.                          if(files[posfile].name[0]=='.' && files[posfile].name[1]=='[')
  1418.                             {
  1419.                            
  1420.                             if(files[posfile].name[2]=='U')
  1421.                                 {
  1422.                                
  1423.                                 current_device=1;
  1424.                                 sprintf(path_file, "fat%i:/", PI_USBSTORAGE);
  1425.                                 read_list_file(NULL, flag);
  1426.                                 posfile=0;
  1427.                            
  1428.                                 }
  1429.                             else
  1430.                             if(files[posfile].name[2]=='S')
  1431.                                 {
  1432.  
  1433.                                 current_device=0;
  1434.                                 sprintf(path_file, "fat%i:/", PI_INTERNAL_SD);
  1435.                                 read_list_file(NULL, flag);
  1436.                                 posfile=0;
  1437.                                
  1438.                                 }
  1439.                             }
  1440.                          else
  1441.                             {read_list_file((void *) &files[posfile].name[0], flag);posfile=0;}
  1442.                          
  1443.                          
  1444.                         }
  1445.                        
  1446.                 }
  1447.  
  1448.  
  1449.            
  1450.  
  1451.                 if((new_key & WII_UP)) {posfile--;if(posfile<0) posfile=nfiles-1;}
  1452.                 if((new_key & WII_DOWN)){posfile++;if(posfile>=nfiles) posfile=0;}
  1453.            
  1454.        
  1455.    
  1456.     Screen_flip();
  1457.    
  1458.     }
  1459. Screen_flip();
  1460. }
  1461.  
  1462. void music_player();
  1463.  
  1464. void jpeg_player()
  1465. {
  1466. int dx,dy;
  1467.  
  1468. int posx=0,posy=0;
  1469. static int mode=0;
  1470. static int amp=100;
  1471.  
  1472. int n;
  1473. int osd_time=0;
  1474.  
  1475. unsigned time;
  1476.  
  1477. if(current_jpg<0) return;
  1478.  
  1479. while(1) // proteccion contra pulsaciones
  1480.     {
  1481.     if(exit_by_reset) break;
  1482.  
  1483.     wii_nKeys=wii_joystick_read(1);
  1484.    
  1485.     new_key=wii_nKeys & (~old_key);
  1486.     old_key=wii_nKeys;
  1487.  
  1488.     if(!(old_key &
  1489.         (WII_LEFT | WII_RIGHT | WII_UP | WII_DOWN ))) break;
  1490.     }
  1491.  
  1492. Next_jpg:
  1493.  
  1494. posx=0;posy=0;
  1495. osd_time=0;
  1496.  
  1497. time=ticks_to_msecs(gettick());
  1498.  
  1499. if(read_JPEG_file(jpg_files[current_jpg].name))
  1500.     {
  1501.     CreateTexture(&scr_tex, TILE_RGBA8, (void *) jpeg_buf, jpeg_tdx, jpeg_tdy, 0);
  1502.     }
  1503.  else
  1504.     {
  1505.     jpeg_tdx=jpeg_tdy=64;
  1506.     jpeg_w=256;jpeg_h=256;
  1507.     memset((void *) jpeg_buf,0,jpeg_tdx*jpeg_tdy*4);
  1508.    
  1509.     for(n=0;n<jpeg_tdx;n++)
  1510.         {
  1511.         jpeg_buf[jpeg_tdx*n+n]=0xffff0000;
  1512.         if((n+1)<jpeg_tdx) jpeg_buf[jpeg_tdx*n+n+1]=0xffff0000;
  1513.         if((n+2)<jpeg_tdx) jpeg_buf[jpeg_tdx*n+n+2]=0xffff0000;
  1514.         if((n+3)<jpeg_tdx) jpeg_buf[jpeg_tdx*n+n+3]=0xffff0000;
  1515.  
  1516.         jpeg_buf[jpeg_tdx*n+jpeg_tdx-n-1]=0xffff0000;
  1517.         if((jpeg_tdx-n-2)>0) jpeg_buf[jpeg_tdx*n+jpeg_tdx-n-2]=0xffff0000;
  1518.         if((jpeg_tdx-n-3)>0) jpeg_buf[jpeg_tdx*n+jpeg_tdx-n-3]=0xffff0000;
  1519.         if((jpeg_tdx-n-4)>0) jpeg_buf[jpeg_tdx*n+jpeg_tdx-n-4]=0xffff0000;
  1520.         }
  1521.     CreateTexture(&scr_tex, TILE_RGBA8, (void *) jpeg_buf, jpeg_tdx, jpeg_tdy, 0);
  1522.     }
  1523.  
  1524. if((ticks_to_msecs(gettick())-time)<500)  // espera al menos medio segundo
  1525.                 usleep(500*1000);
  1526.  
  1527.  
  1528. while(1)
  1529.     {
  1530.            
  1531.     int flag;
  1532.  
  1533.     if(exit_by_reset) break;
  1534.    
  1535.     loop_music_playing();
  1536.    
  1537.     sizeletter=4;
  1538.    
  1539.     PX=24;PY=SCR_HEIGHT-24;color=0xffffffff;
  1540.  
  1541.    
  1542.  
  1543.     SetTexture(&scr_tex);
  1544.  
  1545.     //DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xffffffff);
  1546.  
  1547.     wii_nKeys=wii_joystick_read(1);
  1548.    
  1549.     new_key=wii_nKeys & (~old_key);
  1550.     old_key=wii_nKeys;
  1551.  
  1552.     flag=0;
  1553.     if(new_key & WII_PLUS) {flag=1;if(mode==0) {mode=1;posx=posy=0;if(jpeg_w>=jpeg_h) amp=125;} else {if(amp==100) {posx=posy=0;} amp+=25;if(amp>400) amp=400;}}
  1554.     if(new_key & WII_MINUS) {flag=1;amp-=25;if(amp<100) {mode=0;amp=100;}}
  1555.  
  1556.    
  1557.     if(new_key & WII_B)
  1558.         {
  1559.        
  1560.         current_jpg++;
  1561.        
  1562.         if(current_jpg>=njpg_files)
  1563.             {
  1564.             current_jpg--;
  1565.             amp=100;mode=0;
  1566.             }
  1567.  
  1568.         Screen_flip();
  1569.         SetTexture(NULL);
  1570.  
  1571.         goto Next_jpg;
  1572.         }
  1573.  
  1574.     if(new_key & WII_A)
  1575.         {
  1576.        
  1577.         current_jpg--;
  1578.        
  1579.         if(current_jpg<0)
  1580.             {
  1581.             current_jpg++;
  1582.             amp=100;mode=0;
  1583.             }
  1584.  
  1585.         Screen_flip();
  1586.         SetTexture(NULL);
  1587.    
  1588.         goto Next_jpg;
  1589.         }
  1590.    
  1591.     if(new_key & WII_HOME) break;
  1592.  
  1593.    
  1594.  
  1595.    
  1596.  
  1597.     if(amp==100 && mode==0)
  1598.         {
  1599.             if(!is_16_9)
  1600.                 {
  1601.                 dx=640;
  1602.                 dy=(640*jpeg_h)/jpeg_w;
  1603.  
  1604.                 if(dy>480)
  1605.                     {
  1606.                     dy=480;
  1607.                     dx=(480*jpeg_w)/jpeg_h;
  1608.                     }
  1609.                 dy=SCR_HEIGHT*dy/480;
  1610.                 }
  1611.             else
  1612.                 {
  1613.                 dx=853;
  1614.                 dy=(853*jpeg_h)/jpeg_w;
  1615.  
  1616.                 if(dy>480)
  1617.                     {
  1618.                     dy=480;
  1619.                     dx=(480*jpeg_w)/jpeg_h;
  1620.                     }
  1621.                 dy=SCR_HEIGHT*dy/480;
  1622.                 dx=dx*640/853;
  1623.                 }
  1624.  
  1625.             posx=(640-dx)/2;
  1626.            
  1627.             posy=(SCR_HEIGHT-dy)/2;if(posy<0) posy=0;
  1628.  
  1629.        
  1630.         }
  1631.      else
  1632.         {
  1633.         if(is_16_9) dy=(((SCR_HEIGHT)*jpeg_h)/jpeg_w)*16/9;
  1634.         else dy=((SCR_HEIGHT/3)*4*jpeg_h)/jpeg_w;
  1635.         dx=640;
  1636.         dx=dx*amp/100;
  1637.         dy=dy*amp/100;
  1638.        
  1639.         #if 0
  1640.         if(new_key & WII_LEFT) {posx+=128/*dx/3*/;flag=1;}
  1641.         if(new_key & WII_RIGHT) {posx-=128/*dx/3*/;flag=1;}
  1642.         if(new_key & WII_UP) {posy+=64;flag=1;}
  1643.         if(new_key & WII_DOWN) {posy-=64;flag=1;}
  1644.         #endif
  1645.  
  1646.         if(old_key & WII_LEFT) {posx+=16;flag=1;}
  1647.         if(old_key & WII_RIGHT) {posx-=16;flag=1;}
  1648.         if(old_key & WII_UP) {posy+=16;flag=1;}
  1649.         if(old_key & WII_DOWN) {posy-=16;flag=1;}
  1650.        
  1651.         }
  1652.  
  1653.     if(flag)
  1654.         {
  1655.         if(posx>0 && flag!=2) posx=0;
  1656.         if(posy>0) posy=0;
  1657.         if(posx<-(dx-640)) posx=-(dx-640);
  1658.         if(posy<-(dy-(SCR_HEIGHT))) posy=-(dy-(SCR_HEIGHT));
  1659.  
  1660.         osd_time=0;
  1661.         }
  1662.  
  1663.     if(amp==100 && jpeg_w>=jpeg_h && jpeg_h<=SCR_HEIGHT && (!is_16_9 || mode==0)) {posy=(SCR_HEIGHT-dy)/2;if(posy<0) posy=0;}
  1664.     //DrawFillBox(0,0, 640, dy, 0,0xffffffff);
  1665.     if(mode==1 && amp>=100)
  1666.         {
  1667.         DrawFillBox(posx,posy, dx, dy, 100,0xffffffff);
  1668.        
  1669.  
  1670.         if(osd_time<120)
  1671.             {
  1672.             osd_time++;
  1673.             SetTexture(CROSS_PATTERN);
  1674.             DrawRoundFillBox(8,SCR_HEIGHT-24, 640-16, 24, 0, 0xff302000);
  1675.             SetTexture(NULL_PATTERN);
  1676.             DrawRoundBox(8,SCR_HEIGHT-24, 640-16, 24, 0, 4, 0xffff7f2f);
  1677.             PX=16;PY=SCR_HEIGHT-20;autocenter=1;s_printf("ZOOM: %i%% Img: (%i/%i)",amp, current_jpg+1, njpg_files);autocenter=0;
  1678.             }
  1679.         }
  1680.     else
  1681.         {
  1682.         DrawFillBox(posx,posy, dx, dy, 100,0xffffffff);
  1683.         if(osd_time<120)
  1684.             {
  1685.             osd_time++;
  1686.             SetTexture(CROSS_PATTERN);
  1687.             DrawRoundFillBox(8,SCR_HEIGHT-24, 640-16, 24, 0, 0xff302000);
  1688.             SetTexture(NULL_PATTERN);
  1689.             DrawRoundBox(8,SCR_HEIGHT-24, 640-16, 24, 0, 4, 0xffff7f2f);
  1690.             PX=16;PY=SCR_HEIGHT-20;autocenter=1;s_printf("Img: (%i/%i) Res: %ix%i",current_jpg+1, njpg_files, jpeg_w, jpeg_h);autocenter=0;
  1691.             }
  1692.         }
  1693.     if(jpg_error_str[0]!=0)
  1694.         {
  1695.         SetTexture(CROSS_PATTERN);
  1696.         DrawRoundFillBox(8,SCR_HEIGHT-24, 640-16, 24, 0, 0xff302000);
  1697.         SetTexture(NULL_PATTERN);
  1698.         DrawRoundBox(8,SCR_HEIGHT-24, 640-16, 24, 0, 4, 0xffff7f2f);
  1699.         autocenter=1;
  1700.         PX=16;PY=SCR_HEIGHT-20;s_printf("%s",jpg_error_str);
  1701.         autocenter=0;
  1702.         }
  1703.        
  1704.     Screen_flip();
  1705.  
  1706.     if(new_key & WII_ONE) {music_player();}
  1707.    
  1708.    
  1709.     }
  1710.  
  1711. Screen_flip();
  1712. SetTexture(NULL);
  1713.  
  1714. }
  1715. void music_gfx();
  1716.  
  1717. void music_player()
  1718. {
  1719. int n,m;
  1720.  
  1721. int f=0;
  1722.  
  1723. int mode=0;
  1724. int select=0;
  1725.  
  1726. int select2=2;
  1727.  
  1728. int time_playing=0;
  1729. int time_playing_old=0;
  1730. unsigned time_total=0;
  1731.  
  1732. int left_count=0,right_count=0;
  1733.  
  1734. int ang_suma=0;
  1735.  
  1736. int status;
  1737.  
  1738. int flash=0;
  1739.  
  1740. int osd_volume=0;
  1741.  
  1742. int fast=0;
  1743.  
  1744. if(play_file>=0 && music_playing) select=play_file;
  1745.  
  1746. wii_nKeys=wii_joystick_read(1);
  1747.    
  1748. new_key=wii_nKeys & (~old_key);
  1749. old_key=wii_nKeys;
  1750.  
  1751.  
  1752. while(1)
  1753.     {
  1754.     int max_entry;
  1755.  
  1756.     if(exit_by_reset) break;
  1757.  
  1758.     flash++;
  1759.  
  1760.     status=StatusAudio();
  1761.  
  1762.     if(status==AUDIO_STATUS_RUNNING || fast) {ang_suma++;ang_suma %=360;}
  1763.  
  1764.     //SetTexture(MOSAIC_PATTERN);DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff603000);
  1765.     animate_background();
  1766.     SetTexture(&icon_tex[icons_num_sprites-2]);
  1767.     DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff906000);
  1768.  
  1769.    
  1770.     for(n=0;n<9;n++)
  1771.         {
  1772.         SetTexture(NULL_PATTERN);
  1773.         switch(n)
  1774.             {
  1775.             case 1:
  1776.                 if(left_count)
  1777.                     DrawFillBox(140+40*n,48, 32, 32, 0,0xff000000);
  1778.                 else
  1779.                     DrawFillBox(140+40*n,48, 32, 32, 0,0xff808080);
  1780.                 break;
  1781.             case 2:
  1782.                 if(status==AUDIO_STATUS_RUNNING && left_count==0 && right_count==0)
  1783.                     DrawFillBox(140+40*n,48, 32, 32, 0,0xff000000);
  1784.                 else
  1785.                     DrawFillBox(140+40*n,48, 32, 32, 0,0xff808080);
  1786.                 break;
  1787.             case 3:
  1788.                 if(status==AUDIO_STATUS_PAUSED && (flash & 16)!=0 && fast==0)
  1789.                     DrawFillBox(140+40*n,48, 32, 32, 0,0xff000000);
  1790.                 else
  1791.                     DrawFillBox(140+40*n,48, 32, 32, 0,0xff808080);
  1792.                 break;
  1793.             case 4:
  1794.                 if(!music_playing)
  1795.                     DrawFillBox(140+40*n,48, 32, 32, 0,0xff000000);
  1796.                 else
  1797.                     DrawFillBox(140+40*n,48, 32, 32, 0,0xff808080);
  1798.                 break;
  1799.             case 5:
  1800.                 if(right_count)
  1801.                     DrawFillBox(140+40*n,48, 32, 32, 0,0xff000000);
  1802.                 else
  1803.                     DrawFillBox(140+40*n,48, 32, 32, 0,0xff808080);
  1804.                 break;
  1805.             case 6:
  1806.                 DrawFillBox(140+40*n,48, 32, 32, 0,0xff000000);
  1807.                 break;
  1808.             case 7:
  1809.                 if(music_loop)
  1810.                     DrawFillBox(140+40*n,48, 32, 32, 0,0xff0000ff);
  1811.                 else
  1812.                     DrawFillBox(140+40*n,48, 32, 32, 0,0xff808080);
  1813.                 break;
  1814.             }
  1815.         SetTexture(&icon_tex[n]);
  1816.  
  1817.         if(select2==n && mode==0) DrawFillBox(140+40*n,48, 32, 32, 0,0xff40ff40);
  1818.             else DrawFillBox(140+40*n,48, 32, 32, 0,0xffffffff);
  1819.         }
  1820.  
  1821.     SetTexture(CROSS_PATTERN);
  1822.     DrawRoundFillBox(8, 88, 640-16, SCR_HEIGHT-16-88+8*(SCR_HEIGHT>480), 0, 0xff302000);
  1823.     SetTexture(NULL_PATTERN);
  1824.     DrawRoundBox(8, 88, 640-16, SCR_HEIGHT-16-88+8*(SCR_HEIGHT>480), 0, 2, 0xff804000);
  1825.  
  1826.     sizeletter=2;
  1827.     autocenter=1;
  1828.     PX=0;PY=12;
  1829.     color=0xfff08020;
  1830.     SetTexture(NULL_PATTERN);
  1831.     DrawRoundBox(208,8, 640-416, 32, 0, 2, 0xfff08020);
  1832.     s_printf("Music Player");
  1833.     autocenter=0;
  1834.  
  1835.     sizeletter=4;
  1836.  
  1837.     if(!fast) time_playing=GetTimeAudio()/1000; else time_playing=time_playing_old;
  1838.     time_total=GetTotalTimeAudio()/1000;
  1839.    
  1840.     if(!music_playing) {time_playing_old=0;time_playing=0;}
  1841.         else
  1842.             if(time_playing>0) time_playing_old=time_playing;
  1843.  
  1844.     if(status==AUDIO_STATUS_RUNNING || status==AUDIO_STATUS_PAUSED || fast)
  1845.         {
  1846.        
  1847.        
  1848.         SetTexture(MOSAIC_PATTERN);
  1849.         DrawFillSlice(320,88+(SCR_HEIGHT-16-88)/2, 120, 120, 0, 0, 360, 0xff603000);
  1850.         SetTexture(NULL_PATTERN);
  1851.         DrawSlice(320,88+(SCR_HEIGHT-16-88)/2, 120, 120, 0, 4, 0, 360, 0xff804000);
  1852.         SetTexture(STRIPED_PATTERN);
  1853.         DrawFillSlice(320,88+(SCR_HEIGHT-16-88)/2, 116, 116, 0, ang_suma, ang_suma+time_playing_old*360/time_total, 0x80000040);
  1854.        
  1855.         }
  1856.        
  1857.         SetTexture(NULL_PATTERN);
  1858.  
  1859.        
  1860.         PX=80-32-16;
  1861.         PY=32;
  1862.         color=0xff00f0f0;s_printf("Time");
  1863.         PX=600-48-32;
  1864.         s_printf("Length");
  1865.  
  1866.         color=0xffffffff;
  1867.        
  1868.        
  1869.         PX=16;
  1870.         PY=48;
  1871.         {
  1872.         unsigned color=0xff00ff00;
  1873.         unsigned temp=time_playing_old/60;
  1874.         int lh=20+4*(SCR_HEIGHT<=480);
  1875.      
  1876.         SetTexture(CROSS_PATTERN);
  1877.         DrawRoundFillBox(PX-8, PY, 120, 32, 0, 0xff302000);
  1878.         SetTexture(NULL_PATTERN);
  1879.         DrawRoundBox(PX-8, PY, 120, 32, 0, 2, 0xff804000);
  1880.         if((status==AUDIO_STATUS_PAUSED && (flash & 16)!=0) || status!=AUDIO_STATUS_PAUSED || fast)
  1881.             {
  1882.             if(temp/100)
  1883.                 {
  1884.                 SetTexture(&icon_tex[9+temp/100]);
  1885.                 DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=20;
  1886.                 }
  1887.             else PX+=10;
  1888.  
  1889.             temp %=100;
  1890.             SetTexture(&icon_tex[9]+temp/10);
  1891.             DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=20;temp %=10;
  1892.             SetTexture(&icon_tex[9]+temp);
  1893.             DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=16;
  1894.  
  1895.             SetTexture(&icon_tex[19]);
  1896.             DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=16;
  1897.  
  1898.             temp=time_playing_old % 60;
  1899.             SetTexture(&icon_tex[9+temp/10]);
  1900.             DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=20;temp %=10;
  1901.             SetTexture(&icon_tex[9+temp]);
  1902.             DrawFillBox(PX,PY+4, 20, lh, 0,color);
  1903.             }
  1904.  
  1905.         // total time
  1906.         PX=548-32;
  1907.  
  1908.         temp=time_total/60;
  1909.  
  1910.         SetTexture(CROSS_PATTERN);
  1911.         DrawRoundFillBox(PX-8, PY, 120, 32, 0, 0xff302000);
  1912.         SetTexture(NULL_PATTERN);
  1913.         DrawRoundBox(PX-8, PY, 120, 32, 0, 2, 0xff804000);
  1914.        
  1915.         if(temp/100)
  1916.             {
  1917.             SetTexture(&icon_tex[9+temp/100]);
  1918.             DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=20;
  1919.             }
  1920.         else PX+=10;
  1921.  
  1922.         temp %=100;
  1923.         SetTexture(&icon_tex[9]+temp/10);
  1924.         DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=20;temp %=10;
  1925.         SetTexture(&icon_tex[9]+temp);
  1926.         DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=16;
  1927.  
  1928.         SetTexture(&icon_tex[19]);
  1929.         DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=16;
  1930.  
  1931.         temp=time_total % 60;
  1932.         SetTexture(&icon_tex[9+temp/10]);
  1933.         DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=20;temp %=10;
  1934.         SetTexture(&icon_tex[9+temp]);
  1935.         DrawFillBox(PX,PY+4, 20, lh, 0,color);
  1936.        
  1937.         SetTexture(NULL_PATTERN);
  1938.         }
  1939.         //s_printf("%2.2u:%2.2u ",time_playing/60, time_playing % 60);
  1940.  
  1941.         sizeletter=4;
  1942.        /* color=0xff00f080;s_printf("Length: ");
  1943.         color=0xffffffff;
  1944.        
  1945.         s_printf("%2.2u:%2.2u",time_total/60, time_total % 60);*/
  1946.        
  1947.  
  1948.     max_entry=(SCR_HEIGHT-16-88)/20;
  1949.  
  1950.     PX=24;PY=SCR_HEIGHT-24;color=0xffffffff;
  1951.  
  1952.     m=0;
  1953.    
  1954.     if(mode==0) if(play_file>=0) select=play_file;
  1955.  
  1956.     if(nmusic_files>0)
  1957.     for(n=(select-max_entry/2)*(nmusic_files>=max_entry);n<select+max_entry;n++)
  1958.             {
  1959.             if(n<0) continue;
  1960.             if(n>=nmusic_files) break;
  1961.             if(m>=max_entry) break;
  1962.            
  1963.            
  1964.             PX=16;PY=88+8+2+m*20;
  1965.             color=0xffffffff;
  1966.            
  1967.             if(n==play_file)
  1968.                 {
  1969.  
  1970.                 DrawRoundFillBox(PX,PY-2, 38*16, 20, 0, 0xff004f00);
  1971.                
  1972.                 //DrawRoundBox(PX,PY-2, 38*16, 20, 0, 2, 0xff30ffff);
  1973.  
  1974.                 }
  1975.  
  1976.             if(mode!=0)
  1977.             if(n==select)
  1978.                 {
  1979.  
  1980.                 DrawRoundFillBox(PX,PY-2, 38*16, 20, 0, 0xff00004f);
  1981.                
  1982.                 DrawRoundBox(PX,PY-2, 38*16, 20, 0, 2, 0xff30ffff);
  1983.  
  1984.                 }
  1985.  
  1986.    
  1987.                 s_printf("%s", (char *) get_name_short_fromUTF8(&music_files[n].name[0]));
  1988.        
  1989.            
  1990.             bkcolor=0;color=0xffffffff;
  1991.             m++;
  1992.             }
  1993.  
  1994.     if(osd_volume>0)
  1995.         {
  1996.         osd_volume--;
  1997.        
  1998.         SetTexture(MOSAIC_PATTERN);
  1999.         DrawBox(8,SCR_HEIGHT-16, 640-16, 16, 0, 2, 0xff00c000);
  2000.         SetTexture(MOSAIC_PATTERN);
  2001.         DrawFillBox(12,SCR_HEIGHT-16+4, (640-24)*volume/255, 8, 0, 0xff00c000);
  2002.         }
  2003.  
  2004.     wii_nKeys=wii_joystick_read(1);
  2005.    
  2006.     new_key=wii_nKeys & (~old_key);
  2007.     old_key=wii_nKeys;
  2008.  
  2009.     if(new_key & WII_HOME) break;
  2010.  
  2011.     if(old_key & WII_MINUS) {volume--;if(volume<0) volume=0;SetVolumeAudio(volume);osd_volume=60;}
  2012.     if(old_key & WII_PLUS) {volume++;if(volume>255) volume=255;SetVolumeAudio(volume);osd_volume=60;}
  2013.  
  2014.     if(!(old_key  & (WII_UP | WII_DOWN))) f=0;
  2015.            
  2016.         if(old_key  & WII_UP)
  2017.             {
  2018.             if(f==0) f=2;
  2019.             else if(f & 1) f=2;
  2020.             else {f+=2;if(f>40) {f=34;new_key|=WII_UP;}}
  2021.             }
  2022.         if(old_key  & WII_DOWN)
  2023.             {
  2024.             if(f==0) f=1;
  2025.             else if(!(f & 1)) f=1;
  2026.             else {f+=2;if(f>41) {f=35;new_key|=WII_DOWN;}}
  2027.             }
  2028.  
  2029.     if(mode==0)
  2030.         {
  2031.  
  2032.         if(new_key & WII_LEFT) {select2--;if(select2<0) select2=8;}
  2033.         if(new_key & WII_RIGHT) {select2++;if(select2>8) select2=0;}
  2034.        
  2035.  
  2036.         if(new_key & WII_B)
  2037.             {
  2038.             if(music_playing)
  2039.                 {
  2040.                 n=StatusAudio();
  2041.                
  2042.                 if(n==AUDIO_STATUS_RUNNING) PauseAudio(1);
  2043.                 else if(n==AUDIO_STATUS_PAUSED) PauseAudio(0);
  2044.                
  2045.                 }
  2046.            
  2047.             }
  2048.        
  2049.         if(new_key & WII_A)
  2050.             {
  2051.             if(select2==0) // getfiles
  2052.                 {
  2053.                 select_file(0);
  2054.                 new_key=0;
  2055.                 }
  2056.             else
  2057.             if(select2==1 && left_count==0) // <<
  2058.                 {
  2059.                 left_count=1;
  2060.                 }
  2061.             else
  2062.             if(select2==2 && nmusic_files>0 && right_count==0) // play
  2063.                 {
  2064.                 if(music_playing)
  2065.                     {
  2066.                     n=StatusAudio();
  2067.                     if(play_file==select && n==AUDIO_STATUS_PAUSED)
  2068.                         {
  2069.                         PauseAudio(0);
  2070.                         }
  2071.                     else {time_playing_old=0;music_playing=1;play_file=select;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0;}
  2072.                     }
  2073.                 else {time_playing_old=0;music_playing=1;play_file=select;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0;}
  2074.                 }
  2075.             else
  2076.             if(select2==3) // pause
  2077.                 {
  2078.                 if(music_playing)
  2079.                     {
  2080.                     n=StatusAudio();
  2081.                    
  2082.                     if(n==AUDIO_STATUS_RUNNING) PauseAudio(1);
  2083.                     else if(n==AUDIO_STATUS_PAUSED) PauseAudio(0);
  2084.                    
  2085.                     }
  2086.                
  2087.                 }
  2088.             else
  2089.             if(select2==4) // stop
  2090.                 {  
  2091.                 StopAudio();fast=0;music_playing=0;
  2092.                 }
  2093.             else
  2094.             if(select2==5) // >>
  2095.                 {  
  2096.                 right_count=1;
  2097.                 }
  2098.             else
  2099.             if(select2==6) // shuffle
  2100.                 {
  2101.                 music_shuffle();
  2102.                 }
  2103.             else
  2104.             if(select2==7) // loop
  2105.                 {
  2106.                 music_loop^=1;
  2107.                 }
  2108.             else
  2109.             if(select2==8) // trash
  2110.                 {
  2111.                 nmusic_files=0;
  2112.                 play_file=-1;
  2113.                 }
  2114.            
  2115.             } // wii_a
  2116.         else
  2117.             if(old_key & WII_A)
  2118.                 {
  2119.                 if(select2==1) // <<
  2120.                     {
  2121.                     if(time_playing>0)
  2122.                     if(left_count>42) {fast=1;PauseAudio(1);left_count=40;time_playing_old-=5;if(time_playing_old<0) time_playing_old=0;time_playing=time_playing_old;/*SetTimeAudio(time_playing_old*1000);*/}
  2123.                     left_count++;
  2124.                     }
  2125.                 if(select2==5) // >>
  2126.                     {
  2127.                     if(time_playing>0)
  2128.                     if(right_count>42) {fast=1;PauseAudio(1);right_count=40;time_playing_old+=5;if(time_playing_old>=time_total) time_playing_old=time_total;time_playing=time_playing_old;/*SetTimeAudio(time_playing_old*1000);*/}
  2129.                     right_count++;
  2130.                     }
  2131.                 }
  2132.             else // << >> liberado
  2133.                 {
  2134.                 if(fast)
  2135.                         {
  2136.                         fast=0;
  2137.                        
  2138.                         SetTimeAudio(time_playing_old*1000);PauseAudio(0);
  2139.                         }
  2140.                 if(left_count>=1 && left_count<40)
  2141.                         {
  2142.                         fast=0;
  2143.                         play_file--;
  2144.                         if(music_loop) if(play_file<0) play_file=nmusic_files-1;
  2145.                         if(play_file>=0 && nmusic_files>0) {time_playing_old=0;music_playing=1;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0;}
  2146.                         else {StopAudio();music_playing=0;play_file=-1;}
  2147.                         }
  2148.                
  2149.                 left_count=0;
  2150.                 if(right_count>=1 && right_count<40)
  2151.                         {
  2152.                         fast=0;
  2153.                         play_file++;
  2154.                         if(music_loop) if(play_file>=nmusic_files) play_file=0;
  2155.                         if(play_file<nmusic_files) {time_playing_old=0;music_playing=1;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0;}
  2156.                         else {StopAudio();music_playing=0;play_file=-1;}
  2157.                         }
  2158.                
  2159.                 right_count=0;
  2160.                 }
  2161.                
  2162.         }
  2163.     else
  2164.     if(mode==1)
  2165.         {
  2166.         if(new_key & WII_UP) {select--;if(select<0) select=nmusic_files-1;}
  2167.         if(new_key & WII_DOWN) {select++;if(select>=nmusic_files) select=0;}
  2168.  
  2169.         if(music_playing)
  2170.             {
  2171.             if(new_key & WII_RIGHT) right_count=1;
  2172.             else
  2173.                 {
  2174.                 if(old_key & WII_RIGHT)
  2175.                     {
  2176.                     if(time_playing>0)
  2177.                     if(right_count>42) {fast=1;PauseAudio(1);right_count=40;time_playing_old+=5;if(time_playing_old>=time_total) time_playing_old=time_total; time_playing=time_playing_old;/*SetTimeAudio(time_playing_old*1000);*/}
  2178.                     right_count++;
  2179.                     }
  2180.                 else
  2181.                     {
  2182.                     if(fast && right_count)
  2183.                         {
  2184.                         fast=0;
  2185.                    
  2186.                         SetTimeAudio(time_playing_old*1000);PauseAudio(0);
  2187.                         }
  2188.                     if(right_count>=1 && right_count<40)
  2189.                         {
  2190.                         fast=0;
  2191.                         play_file++;
  2192.                         if(music_loop) if(play_file>=nmusic_files) play_file=0;
  2193.                         if(play_file<nmusic_files) {time_playing_old=0;music_playing=1;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0;}
  2194.                         else {StopAudio();music_playing=0;play_file=-1;}
  2195.                         }
  2196.                     right_count=0;
  2197.                     }
  2198.                 }
  2199.  
  2200.             if(new_key & WII_LEFT) left_count=1;
  2201.             else
  2202.                 {
  2203.                 if(old_key & WII_LEFT)
  2204.                     {
  2205.                     if(time_playing>0)
  2206.                     if(left_count>42) {fast=1;PauseAudio(1);left_count=40;time_playing_old-=5;if(time_playing_old<0) time_playing_old=0; time_playing=time_playing_old;/*SetTimeAudio(time_playing_old*1000);*/}
  2207.                     left_count++;
  2208.                     }
  2209.                 else
  2210.                     {
  2211.                     if(fast && left_count)
  2212.                         {
  2213.                         fast=0;
  2214.                         SetTimeAudio(time_playing_old*1000);PauseAudio(0);
  2215.                         }
  2216.                     if(left_count>=1 && left_count<40)
  2217.                         {
  2218.                         play_file--;
  2219.                         if(music_loop) if(play_file<0) play_file=nmusic_files-1;
  2220.                         if(play_file>=0 && nmusic_files>0) {time_playing_old=0;music_playing=1;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0;}
  2221.                         else {StopAudio();music_playing=0;play_file=-1;}
  2222.                         }
  2223.                     left_count=0;
  2224.                     }
  2225.                 }
  2226.            
  2227.             }
  2228.         if(new_key & WII_B)
  2229.             {
  2230.             if(music_playing)
  2231.                 {
  2232.                 n=StatusAudio();
  2233.                
  2234.                 if(n==AUDIO_STATUS_RUNNING) PauseAudio(1);
  2235.                 else if(n==AUDIO_STATUS_PAUSED) PauseAudio(0);
  2236.                
  2237.                 }
  2238.            
  2239.             }
  2240.  
  2241.         if(new_key & WII_A)
  2242.             {
  2243.             if(fast)
  2244.                 {
  2245.                 fast=0;
  2246.            
  2247.                 SetTimeAudio(time_playing_old*1000);PauseAudio(0);
  2248.                 }
  2249.             if(music_playing)
  2250.                 {
  2251.                 n=StatusAudio();
  2252.                 if(play_file==select && n==AUDIO_STATUS_PAUSED)
  2253.                     {
  2254.                     PauseAudio(0);
  2255.                     }
  2256.                 else
  2257.                 if(play_file==select && n==AUDIO_STATUS_RUNNING)
  2258.                     {
  2259.                     StopAudio();music_playing=0;
  2260.                     }
  2261.                 else if(nmusic_files>0){time_playing_old=0;music_playing=1;play_file=select;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0;}
  2262.                 }
  2263.             else if(nmusic_files>0){time_playing_old=0;music_playing=1;play_file=select;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0;}
  2264.             }
  2265.         } // mode==1
  2266.  
  2267.     if(mode==0 && nmusic_files>0)
  2268.         {
  2269.         if(new_key & (WII_ONE | WII_DOWN)) mode=1;
  2270.         if(new_key & WII_TWO)
  2271.             {if(fast)
  2272.                 {
  2273.                 fast=0;
  2274.  
  2275.                 SetTimeAudio(time_playing_old*1000);PauseAudio(0);
  2276.                 }
  2277.             music_gfx();
  2278.             }
  2279.         }
  2280.     else
  2281.     if(mode==1)
  2282.         {
  2283.         if(new_key & WII_ONE) mode=0;
  2284.         if(new_key & WII_TWO)
  2285.             {if(fast)
  2286.                 {
  2287.                 fast=0;
  2288.  
  2289.                 SetTimeAudio(time_playing_old*1000);PauseAudio(0);
  2290.                 }
  2291.             music_gfx();
  2292.             }//mode=1; // to do: mode=2 visual effects
  2293.         }
  2294.    
  2295.     Screen_flip();
  2296.    
  2297.     if(loop_music_playing()) {select=play_file;time_playing_old=0;}
  2298.    
  2299.     }
  2300. if(fast)
  2301.     {
  2302.     fast=0;
  2303.  
  2304.     SetTimeAudio(time_playing_old*1000);PauseAudio(0);
  2305.     }
  2306. Screen_flip();
  2307. SetTexture(NULL);
  2308. }
  2309.  
  2310.  
  2311.  
  2312. void txt_player()
  2313. {
  2314. unsigned time1,time2;
  2315.  
  2316.  
  2317. if(txt_file_len==0) return;
  2318.  
  2319.  
  2320. time1=time2=ticks_to_msecs(gettick());
  2321.  
  2322.  
  2323.  
  2324. while(1)
  2325.     {
  2326.     if(exit_by_reset) break;
  2327.  
  2328.     loop_music_playing();
  2329.  
  2330.     SetTexture(MOSAIC_PATTERN);
  2331.     DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff603000);
  2332.  
  2333.     wii_nKeys=wii_joystick_read(0);
  2334.  
  2335.     new_key=wii_nKeys & (~old_key);
  2336.     old_key=wii_nKeys;
  2337.  
  2338.     if(new_key & WII_HOME) break;
  2339.    
  2340.     time2=ticks_to_msecs(gettick());
  2341.  
  2342.     SelectFontTexture(1);
  2343.     if(time1>time2) time1=time2;
  2344.     if((time2-time1)>60000) text_main(128, new_key, old_key);
  2345.     else text_main(0, new_key, old_key);
  2346.  
  2347.     SelectFontTexture(0);
  2348.     Screen_flip();
  2349.    
  2350.     if((time2-time1)>60000) {write_cfg(path_txt_cfg);time1=time2=ticks_to_msecs(gettick());}
  2351.  
  2352.     if(new_key & WII_ONE) {Screen_flip();write_cfg(path_txt_cfg);music_player();time1=time2=ticks_to_msecs(gettick());}
  2353.  
  2354.     }
  2355. Screen_flip();
  2356. write_cfg(path_txt_cfg);
  2357. }
  2358.  
  2359. void exit_menu()
  2360. {
  2361. int n, m;
  2362. int select=0;
  2363. int loop=1;
  2364.  
  2365. while(loop)
  2366.     {
  2367.     if(exit_by_reset) break;
  2368.  
  2369.     loop_music_playing();
  2370.  
  2371.     //SetTexture(CROSS_PATTERN);
  2372.     //DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff603000);
  2373.  
  2374.     animate_background();
  2375.     SetTexture(&icon_tex[icons_num_sprites-2]);
  2376.     DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff906000);
  2377.  
  2378.     sizeletter=1;
  2379.     autocenter=1;
  2380.     PX=0;PY=12;
  2381.     color=0xfff08020;
  2382.     SetTexture(NULL_PATTERN);
  2383.     DrawRoundBox(144,8, 640-256-32, 40, 0, 2, 0xfff08020);
  2384.     s_printf("WiiReader");
  2385.    
  2386.     color=0xffffffff;
  2387.     sizeletter=1;
  2388.  
  2389.     for(n=0;n<3;n++)
  2390.         {
  2391.         m=SCR_HEIGHT/2-110+n*110;//48+n*110+50+20;
  2392.  
  2393.         SetTexture(MOSAIC_PATTERN);
  2394.         DrawRoundFillBox(32,m-32, 640-64, 64, 0,0xff803000);
  2395.  
  2396.         SetTexture(NULL_PATTERN);
  2397.         if(n==select)
  2398.             DrawRoundBox(32,m-32, 640-64, 64, 0, 10, 0xff00f0f0);
  2399.         else
  2400.             DrawRoundBox(32,m-32, 640-64, 64, 0, 6, 0xfff08020);
  2401.  
  2402.         switch(n)
  2403.             {
  2404.             case 0:
  2405.                 autocenter=1;
  2406.                 PX=0;PY=m-16;
  2407.                 if(return_reset==1)
  2408.                     s_printf("Homebrew Channel");
  2409.                 else
  2410.                     s_printf("Reset");
  2411.  
  2412.                 autocenter=0;break;
  2413.             case 1:
  2414.                 autocenter=1;
  2415.                 PX=0;PY=m-16;
  2416.                 s_printf("Power Off");
  2417.                 autocenter=0;break;
  2418.             case 2:
  2419.                 autocenter=1;
  2420.                 PX=0;PY=m-16;
  2421.                 s_printf("Abort");
  2422.                 autocenter=0;break;
  2423.             }
  2424.         }
  2425.  
  2426.  
  2427.     sizeletter=4;
  2428.     PX=24;PY=SCR_HEIGHT-24;color=0xffffffff;
  2429.  
  2430.     wii_nKeys=wii_joystick_read(1);
  2431.    
  2432.     new_key=wii_nKeys & (~old_key);
  2433.     old_key=wii_nKeys;
  2434.  
  2435.     if(new_key & WII_UP) {select--;if(select<0) select=2;}
  2436.     if(new_key & WII_DOWN) {select++;if(select>2) select=0;}
  2437.  
  2438.  
  2439.     Screen_flip();
  2440.    
  2441.     if(new_key & WII_A)
  2442.         {
  2443.         switch(select)
  2444.             {
  2445.             case 0:
  2446.                 exit_by_reset=return_reset;
  2447.                 exit(0);
  2448.                 break;
  2449.             case 1:
  2450.                 exit_by_reset=3;
  2451.                 exit(0);
  2452.                 break;
  2453.             case 2:
  2454.                 loop=0;
  2455.                 break;
  2456.             }
  2457.         }
  2458.    
  2459.     if(new_key & WII_B) break;
  2460.  
  2461.     }
  2462. Screen_flip();
  2463. SetTexture(NULL);
  2464. }
  2465.  
  2466. void main_menu()
  2467. {
  2468. int n,m;
  2469.  
  2470. int last_menu=-1;
  2471.  
  2472. static int select=0;
  2473.  
  2474. while(1)
  2475.     {
  2476.     if(exit_by_reset) break;
  2477.  
  2478.     loop_music_playing();
  2479.  
  2480.     //SetTexture(CROSS_PATTERN);
  2481.    
  2482.     animate_background();
  2483.     SetTexture(&icon_tex[icons_num_sprites-2]);
  2484.     DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff906000);
  2485.  
  2486.     sizeletter=1;
  2487.     autocenter=1;
  2488.     PX=0;PY=12;
  2489.     color=0xfff08020;
  2490.     SetTexture(NULL_PATTERN);
  2491.     DrawRoundBox(144,8, 640-256-32, 40, 0, 2, 0xfff08020);
  2492.     s_printf("WiiReader");
  2493.     sizeletter=2;
  2494.  
  2495.     PX=0;PY=48+3*100+50+48;color=0xffffffff;
  2496.     s_printf("%s","\251 Francisco Muñoz 'Hermes' - v1.1");
  2497.     autocenter=0;
  2498.     sizeletter=1;
  2499.     for(n=0;n<4;n++)
  2500.         {
  2501.         m=48+n*100+50;
  2502.  
  2503.         SetTexture(MOSAIC_PATTERN);
  2504.         DrawRoundFillBox(32,m-32, 640-64, 64, 0,0xff803000);
  2505.  
  2506.         SetTexture(NULL_PATTERN);
  2507.         if(n==select)
  2508.             DrawRoundBox(32,m-32, 640-64, 64, 0, 10, 0xff00f0f0);
  2509.         else
  2510.             DrawRoundBox(32,m-32, 640-64, 64, 0, 6, 0xfff08020);
  2511.  
  2512.         switch(n)
  2513.             {
  2514.             case 0:
  2515.                 autocenter=1;
  2516.                 PX=0;PY=m-16;
  2517.                 s_printf("JPEG Viewer");
  2518.                 autocenter=0;break;
  2519.             case 1:
  2520.                 autocenter=1;
  2521.                 PX=0;PY=m-16;
  2522.                 s_printf("Music Player");
  2523.                 autocenter=0;break;
  2524.             case 2:
  2525.                 autocenter=1;
  2526.                 PX=0;PY=m-16;
  2527.                 s_printf("TXT Reader");
  2528.                 autocenter=0;break;
  2529.             case 3:
  2530.                 autocenter=1;
  2531.                 PX=0;PY=m-16;
  2532.                 s_printf("Exit");
  2533.                 autocenter=0;break;
  2534.             }
  2535.         }
  2536.  
  2537.  
  2538.     sizeletter=4;
  2539.     PX=24;PY=SCR_HEIGHT-24;color=0xffffffff;
  2540.  
  2541.     wii_nKeys=wii_joystick_read(1);
  2542.    
  2543.     new_key=wii_nKeys & (~old_key);
  2544.     old_key=wii_nKeys;
  2545.  
  2546.     if(new_key & WII_UP) {select--;if(select<0) select=3;}
  2547.     if(new_key & WII_DOWN) {select++;if(select>3) select=0;}
  2548.  
  2549.  
  2550.     Screen_flip();
  2551.  
  2552.     if(new_key & WII_B)
  2553.         {
  2554.         switch(last_menu)
  2555.             {
  2556.             case 0:
  2557.                 last_menu=0;
  2558.                 jpeg_player();
  2559.                 break;
  2560.             case 1:
  2561.                 last_menu=1;
  2562.                 music_player();
  2563.                 break;
  2564.             case 2:
  2565.                 last_menu=2;
  2566.                 txt_player();
  2567.                 break;
  2568.             }
  2569.         }
  2570.    
  2571.     if(new_key & WII_A)
  2572.         {
  2573.         switch(select)
  2574.             {
  2575.             case 0:
  2576.                 last_menu=0;
  2577.                 select_file(1);
  2578.                 jpeg_player();
  2579.                 break;
  2580.             case 1:
  2581.                 last_menu=1;
  2582.                 music_player();
  2583.                 break;
  2584.             case 2:
  2585.                 last_menu=2;
  2586.                 select_file(2);
  2587.                 txt_player();
  2588.                 break;
  2589.             case 3:
  2590.                 exit_menu();
  2591.                 break;
  2592.             }
  2593.         }
  2594.  
  2595.    
  2596.     }
  2597. Screen_flip();
  2598. SetTexture(NULL);
  2599. }
  2600.  
  2601. void credits()
  2602. {
  2603. int n;
  2604.  
  2605. for(n=0;n<6*60;n++)
  2606.     {
  2607.     animate_background();
  2608.     SetTexture(&icon_tex[icons_num_sprites-2]);
  2609.     DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff906000);
  2610.  
  2611.     sizeletter=1;
  2612.     autocenter=1;
  2613.     PX=0;PY=12;
  2614.     color=0xfff08020;
  2615.     SetTexture(NULL_PATTERN);
  2616.     DrawRoundBox(144,8, 640-256-32, 40, 0, 2, 0xfff08020);
  2617.     s_printf("WiiReader");
  2618.  
  2619.     sizeletter=2;
  2620.     color=0xffffffff;
  2621.     PY=60;
  2622.     PX=0;s_printf("%s","\251 Francisco Muñoz 'Hermes' - v1.1");PY+=24;
  2623.     PX=0;s_printf("Under General Public License (GPL) Terms");PY+=60;
  2624.    
  2625.     color=0xff00ffff;
  2626.     PX=0;s_printf("This software is based in part on the");PY+=24;
  2627.     PX=0;s_printf("work of the Independent JPEG Group");PY+=24;
  2628.     PX=0;s_printf("Copyright (C) 1994-1998, Thomas G. Lane");PY+=32;
  2629.  
  2630.     PX=0;s_printf("Also based in libmpg123 copyrighted by ");PY+=24;
  2631.     PX=0;s_printf("Michael Hipp under LGPL 2.1");PY+=32;
  2632.  
  2633.     PX=0;s_printf("Also based in the 'Tremor' lib");PY+=24;
  2634.     PX=0;s_printf("Copyright (c) 2002, Xiph.org Foundation");PY+=32;
  2635.  
  2636.     PX=0;s_printf("Also based in libogc/DevkitPro");PY+=24;
  2637.     PX=0;s_printf("Copyright: Michael Wiedenbauer (shagkur)");PY+=24;
  2638.     PX=0;s_printf("and Dave Murphy (WinterMute)");PY+=32;
  2639.  
  2640.     PX=0;s_printf("Also based in unzip lib");PY+=24;
  2641.     PX=0;s_printf("Copyright (C) 1998 Gilles Vollant");
  2642.  
  2643.  
  2644.    
  2645.     autocenter=0;
  2646.    
  2647.     Screen_flip();
  2648.     }
  2649.  
  2650. }
  2651.  
  2652. int main(int argc, char *argv[])
  2653. {
  2654.  
  2655. int n;
  2656.  
  2657. DIR_ITER *dir;
  2658.  
  2659.  
  2660. return_reset=1;
  2661.  
  2662. if(argc<1) return_reset=2;
  2663.  
  2664. CONF_Init();
  2665.  
  2666. is_16_9=CONF_GetAspectRatio();
  2667.  
  2668.     InitScreen();
  2669.  
  2670.     srand(gettick());
  2671.  
  2672.    //console_init(frameBuffer[0],20,20,screenMode->fbWidth,screenMode->xfbHeight,screenMode->fbWidth*VI_DISPLAY_PIX_SZ);  
  2673.                          
  2674.  
  2675.     SYS_SetResetCallback(reset_call); // esto es para que puedas salir al pulsar boton de RESET
  2676.     SYS_SetPowerCallback(power_call); // esto para apagar con power
  2677.  
  2678.     PAD_Init();
  2679.     WPAD_Init();
  2680.     WPAD_SetIdleTimeout(60*5); // 5 minutes
  2681.    
  2682.     //WPAD_SetVRes(WPAD_CHAN_ALL, 640, SCR_HEIGHT);
  2683.        
  2684.  
  2685.     THREAD_PRIORITY();
  2686.  
  2687.     ASND_Init(/*INIT_RATE_48000*/); // Initialize the Sound Lib
  2688.  
  2689.     ASND_Pause(0);
  2690.     ASND_PauseVoice(0, 0);
  2691.  
  2692.  
  2693.     atexit(fun_exit);
  2694.  
  2695.  
  2696.     VIDEO_WaitVSync();
  2697.    
  2698.     fatInit(8, false);
  2699.  
  2700.     sleep(2);
  2701.  
  2702.     fatSetDefaultInterface(PI_INTERNAL_SD);
  2703.    
  2704.     have_device=0;
  2705.  
  2706.     {
  2707.     path_file[3]=48+PI_INTERNAL_SD;
  2708.     path_txt_cfg[3]=48+PI_INTERNAL_SD;
  2709.    
  2710.     for(n=0;n<5;n++)
  2711.         {
  2712.         dir = diropen(path_file);
  2713.         if (dir) {dirclose(dir); have_device|=1;fatEnableReadAhead(PI_INTERNAL_SD, 12, 32);break;}
  2714.         usleep(200*1000);
  2715.         }
  2716.  
  2717.     path_file[3]=48+PI_USBSTORAGE;
  2718.  
  2719.     for(n=0;n<5;n++)
  2720.         {
  2721.         dir = diropen(path_file);
  2722.         if (dir) {dirclose(dir);  have_device|=2;fatEnableReadAhead(PI_USBSTORAGE, 12, 32);break;}
  2723.         usleep(200*1000);
  2724.         }
  2725.     }
  2726.    
  2727.    
  2728.     current_device=0;
  2729.     if(have_device & 1) path_file[3]=48+PI_INTERNAL_SD;
  2730.     else if(have_device & 2) {current_device=1; path_file[3]=48+PI_USBSTORAGE;}
  2731.  
  2732.     for(n=0;n<icons_num_sprites-2;n++)
  2733.     {
  2734.     CreateTexture(&icon_tex[n], TLUT_SRGB5A1, icons_sprites[n].ptr, icons_sprites[n].sx, icons_sprites[n].sy, 0);
  2735.     }
  2736.  
  2737.     credits();
  2738.     //sleep(1);
  2739.  
  2740.  
  2741. jpeg_buf=memalign(32,1024*1024*4);
  2742.  
  2743.  
  2744. sprintf(path_txt_cfg,"%sapps", path_file);
  2745. if(have_device & 1)
  2746.     mkdir(path_txt_cfg, S_IREAD | S_IWRITE);
  2747.  
  2748. //usleep(1000*500);
  2749. sprintf(path_txt_cfg,"%sapps/wiireader", path_file);
  2750. if(have_device & 1)
  2751.     mkdir(path_txt_cfg, S_IREAD | S_IWRITE);
  2752. sprintf(path_txt_cfg,"%sapps/wiireader/textreader.cfg", path_file);
  2753. usleep(1000*500);
  2754. sprintf(path_cfg,"%sapps/wiireader/font.bin", path_file);
  2755.  
  2756. {
  2757. FILE *fp;
  2758. fp=fopen(path_cfg,"r"); // lee el fichero de texto
  2759. if(fp!=0)
  2760.     {
  2761.     n=fread(extern_char_set,1, 28672 ,fp);
  2762.     if(n==28672) {UploadFontTextureExt((void *) extern_char_set);}
  2763.     fclose(fp);
  2764.     }
  2765. }
  2766.  
  2767. sprintf(path_cfg,"%sapps/wiireader/wiireader.cfg", path_file);
  2768.  
  2769. SetVolumeAudio(volume);
  2770. main_menu();
  2771.  
  2772. Screen_flip();
  2773. StopAudio();
  2774. return(0);
  2775.  
  2776. }
  2777.  
  2778. static GXTexObj gfx_tex;
  2779.  
  2780. static u32 gfx_texture[256*128] ATTRIBUTE_ALIGN(32);
  2781. static u32 gfx_buff[256*128] ATTRIBUTE_ALIGN(8);
  2782.  
  2783. static void inline set_gfx_pix(u32 x,u32 y, u32 c)
  2784. {
  2785.     if(x>=256 || y>=128) return;
  2786.  
  2787.     gfx_buff[(y<<8)+x]=c;
  2788. }
  2789.  
  2790. static u32 inline get_gfx_pix(u32 x,u32 y)
  2791. {
  2792.     if(x>=256 || y>=128) return 0xff400040;
  2793.  
  2794. return gfx_buff[(y<<8)+x];
  2795. }
  2796.  
  2797. static void line_gfx(int x1,int y1,int x2,int y2, unsigned color)
  2798. {
  2799. int n,m;
  2800. int a,b,a2,b2;
  2801.  
  2802.     x2-=x1;
  2803.     y2-=y1;
  2804.  
  2805.     a2=x2;if(a2<0) {a2=-a2;x2=-1;} else x2=1;
  2806.     b2=y2;if(b2<0) {b2=-b2;y2=-1;} else y2=1;
  2807.  
  2808.     m=a2;if(b2>m) m=b2;
  2809.  
  2810.     a=0;b=0;
  2811.  
  2812.     for(n=0;n<m;n++)
  2813.         {
  2814.         set_gfx_pix(x1, y1, color);
  2815.         a+=a2;if(a>=m) {a-=m;x1+=x2;}
  2816.         b+=b2;if(b>=m) {b-=m;y1+=y2;}
  2817.         }
  2818. }
  2819.  
  2820. static void gfx_fun()
  2821. {
  2822.  
  2823. int n,m,s;
  2824.  
  2825. int r,g,b;
  2826.  
  2827. for(n=0;n<128;n++)
  2828.     {
  2829.     s=1;if(n>64) s=-1;
  2830.  
  2831.     for(m=0;m<256;m++)
  2832.         {
  2833.         register u32 color;
  2834.  
  2835.         color=get_gfx_pix(m,n);
  2836.  
  2837.         r=(color) & 255;
  2838.         g=(color>>8) & 255;
  2839.         b=(color>>16) & 255;
  2840.  
  2841.    
  2842.  
  2843.         color=get_gfx_pix(m,n-s);
  2844.  
  2845.         r+=(color) & 255;
  2846.         g+=(color>>8) & 255;
  2847.         b+=(color>>16) & 255;
  2848.  
  2849.         color=get_gfx_pix(m-1,n+s);
  2850.  
  2851.         r+=(color) & 255;
  2852.         g+=(color>>8) & 255;
  2853.         b+=(color>>16) & 255;
  2854.  
  2855.         color=get_gfx_pix(m+1,n+s);
  2856.  
  2857.         r+=(color) & 255;
  2858.         g+=(color>>8) & 255;
  2859.         b+=(color>>16) & 255;
  2860.  
  2861.  
  2862.         r>>=2;g>>=2;b>>=2;
  2863.        
  2864.         if(r<32 && g<32 && b<32) b=32;
  2865.  
  2866.         color=((0xff00+b)<<16) | (g<<8) | r;
  2867.  
  2868.  
  2869.         set_gfx_pix(m, n, color);
  2870.        
  2871.         }
  2872.     }
  2873.  
  2874. }
  2875.  
  2876.  
  2877. static void gfx_fun2()
  2878. {
  2879.  
  2880. int n,m,s;
  2881.  
  2882. int r,g,b;
  2883.  
  2884. for(n=0;n<128;n++)
  2885.     {
  2886.     s=1;//if(n>128) s=-1;
  2887.  
  2888.     for(m=0;m<256;m++)
  2889.         {
  2890.         register u32 color;
  2891.  
  2892.         color=get_gfx_pix(m,n);
  2893.  
  2894.         r=(color) & 255;
  2895.         g=(color>>8) & 255;
  2896.         b=(color>>16) & 255;
  2897.  
  2898.    
  2899.  
  2900.         color=get_gfx_pix(m,n-s);
  2901.  
  2902.         r+=(color) & 255;
  2903.         g+=(color>>8) & 255;
  2904.         b+=(color>>16) & 255;
  2905.  
  2906.         color=get_gfx_pix(m-1,n);
  2907.  
  2908.         r+=(color) & 255;
  2909.         g+=(color>>8) & 255;
  2910.         b+=(color>>16) & 255;
  2911.  
  2912.         color=get_gfx_pix(m+1,n);
  2913.  
  2914.         r+=(color) & 255;
  2915.         g+=(color>>8) & 255;
  2916.         b+=(color>>16) & 255;
  2917.  
  2918.         color=get_gfx_pix(m,n+s);
  2919.  
  2920.         r+=(color) & 255;
  2921.         g+=(color>>8) & 255;
  2922.         b+=(color>>16) & 255;
  2923.  
  2924.        
  2925.         r/=5;g/=5;b/=5;
  2926.  
  2927.        
  2928.        
  2929.         color=((0xff00+b)<<16) | (g<<8) | r;
  2930.  
  2931.  
  2932.         set_gfx_pix(m, n, color);
  2933.        
  2934.         }
  2935.     }
  2936.  
  2937. }
  2938.  
  2939.  
  2940.  
  2941. void music_gfx()
  2942. {
  2943.  
  2944. int n,m;
  2945. short l,r,oldl=0,oldr=0;
  2946. u16 *punt;
  2947. int hahaha=0;
  2948.  
  2949. memset(gfx_buff, 0, 256*256/2*4);
  2950.  
  2951. memset(pcm_outsample,0,512*2);
  2952.  
  2953. while(1)
  2954.     {
  2955.     if(exit_by_reset) break;
  2956.     wii_nKeys=wii_joystick_read(1);
  2957.    
  2958.     new_key=wii_nKeys & (~old_key);
  2959.     old_key=wii_nKeys;
  2960.  
  2961.     if(new_key & (WII_HOME | WII_ONE | WII_TWO | WII_A | WII_B)) break;
  2962.  
  2963.    
  2964.    
  2965.  
  2966.     for(n=0;n<256;n+=4)
  2967.         {
  2968.         l=(pcm_outsample[n<<1]>>10)+64;
  2969.         r=(pcm_outsample[(n<<1)+1]>>10)+64;
  2970.        
  2971.         if(hahaha & 128)
  2972.             {
  2973.             set_gfx_pix(n,l,0xff008fff);
  2974.             set_gfx_pix(n,r,0xff00ff8f);
  2975.             }
  2976.         else
  2977.             {
  2978.             line_gfx(n-4,oldl, n, l, 0xff008fff);
  2979.             line_gfx(n-4,oldr, n, r, 0xff008fff);
  2980.             }
  2981.  
  2982.         set_gfx_pix(n+2, -(l<<12), 0xff8f00ff+((l & 255)<<8));
  2983.         set_gfx_pix(n+2, -(r<<12), 0xffff008f+((r & 255)<<8));
  2984.  
  2985.         oldl=l;oldr=r;
  2986.         }
  2987.    
  2988.  
  2989.     for(n=0;n<256;n++)
  2990.         {
  2991.        
  2992.        
  2993.         l=(pcm_outsample[n<<1]>>10)+64;
  2994.         r=(pcm_outsample[(n<<1)+1]>>10)+64;
  2995.        
  2996.    
  2997.         line_gfx(n-1,128-oldl, n, 128-l, 0xff400000+(l<<1));
  2998.         line_gfx(n-1,128-oldr, n, 128-r, 0xffff0000+(r<<1));
  2999.         oldl=l;oldr=r;
  3000.         }
  3001.  
  3002.     hahaha++;
  3003.     if((hahaha & 0xffff)>3600)
  3004.         {
  3005.         if(hahaha>=(65536+3603)) hahaha=0;
  3006.         else
  3007.             if(hahaha>3605 && hahaha<65536) hahaha=65536+3500;
  3008.  
  3009.         punt= (u16 *) icons_sprites[icons_num_sprites-1].ptr;
  3010.  
  3011.         for(n=0;n<96;n++)
  3012.         for(m=0;m<128;m++)
  3013.             {
  3014.             if(punt[((n/3)<<5) | (m>>2)]==0x8000)
  3015.                 set_gfx_pix(64+m, 16+n, 0xff000000);
  3016.             else if(punt[((n>>1)<<5) | (m>>2)])
  3017.                     set_gfx_pix(64+m, 16+n, 0xffffffff);
  3018.             }
  3019.         }
  3020.  
  3021.     gfx_fun();
  3022.  
  3023.     for(n=0;n<256;n+=8)
  3024.         {
  3025.        
  3026.        
  3027.         l=(pcm_outsample[n<<1]>>10)+64;
  3028.         r=(pcm_outsample[(n<<1)+1]>>10)+64;
  3029.        
  3030.    
  3031.         line_gfx(n-8,oldl, n, l, 0xffff8f00+(l<<1));
  3032.         line_gfx(n-8,oldr, n, r, 0xffff008f+((127-r)<<9));
  3033.         oldl=l;oldr=r;
  3034.         }
  3035.  
  3036.    
  3037.     gfx_fun2();
  3038.  
  3039.    
  3040.    
  3041.     memcpy(gfx_texture,gfx_buff, 256*256/2*4);
  3042.    
  3043.     CreateTexture(&gfx_tex, TILE_SRGBA8, (void *) gfx_texture, 256, 256/2, 0);
  3044.     SetTexture(&gfx_tex);
  3045.  
  3046.     DrawFillBox(-40,-40, 640+80, SCR_HEIGHT+80, 0,0xffffffff);
  3047.  
  3048.     DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0x80ffffff);
  3049.  
  3050.  
  3051.     Screen_flip();
  3052.    
  3053.     loop_music_playing();
  3054.  
  3055.  
  3056.    
  3057.     }
  3058. Screen_flip();
  3059. SetTexture(NULL);
  3060. }
  3061.  
  3062. /* end */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement