Advertisement
Guest User

Cambios :S

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