Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Wiireader v1.1
- Copyright (C) 2008 Francisco Muñoz "Hermes" (www.entuwii.net)
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <malloc.h>
- #include <math.h>
- #include "libs/jpeglib/jpeglib.h"
- #include "libs/libpng/pngu/pngu.c"
- #include <setjmp.h>
- #include <ogcsys.h>
- #include <gccore.h>
- #include "ogc/lwp_threads.h"
- #include <wiiuse/wpad.h>
- #include <fat.h>
- #include <fcntl.h>
- #include <dirent.h>
- #include <sys/stat.h>
- #include <sys/statvfs.h>
- #include "unistd.h"
- #include <ogc/conf.h>
- #include "screen.h"
- #include "textreader.h"
- //
- //#include "asnd.h"
- #include "audioplayer.h"
- #include "unzip.h"
- #include "icons.h"
- #define ticks_to_msecs(ticks) ((u32)((ticks)/(TB_TIMER_CLOCK)))
- extern unsigned gettick();
- #define THREAD_PRIORITY() LWP_SetThreadPriority(LWP_GetSelf(),40)
- int is_16_9=0; // screen format 16:9 ?
- /*
- int fprintf(FILE *a,const char *s, ...)
- {
- exit(0);
- }
- int printf(const char *s, ...)
- {
- exit(0);
- }
- */
- //extern char *debug_str;
- char path_file[258]="sd:/";
- char path_txt_cfg[258]="sd:/apps/wiireader/textreader.cfg";
- char path_cfg[258]="sd:/apps/wiireader/textreader.cfg";
- static char extern_char_set[28672];
- unsigned char temp_buffer[32768]; // buffer temporal
- unsigned new_key=0,old_key=0;
- int exit_by_reset=0;
- int return_reset=2;
- void reset_call() {exit_by_reset=return_reset;}
- void power_call() {exit_by_reset=3;}
- #define WII_A 16
- #define WII_B 32
- #define WII_MINUS 64
- #define WII_PLUS 128
- #define WII_HOME 256
- #define WII_START 512
- #define WII_ONE 1024
- #define WII_TWO 2048
- #define WII_RIGHT 2
- #define WII_LEFT 1
- #define WII_UP 4
- #define WII_DOWN 8
- #define QTDEN(a,b) ((a & (b))==(b))
- unsigned wii_nKeys=0;
- static int valid_keys=0;
- void wpad_callback(s32 chan, const WPADData *data)
- {
- if(WPAD_ReadEvent(chan, (WPADData * )data)<0) valid_keys=0;
- }
- unsigned wii_joystick_read(int sel)
- {
- u32 type[4]={0,0,0,0};
- u32 butt=0;
- s32 retj[4]={-1,-1,-1,-1};
- int n;
- unsigned ret=0;
- static expansion_t w_exp;
- int is_readed=0;
- //debug_str="WPAD_ScanPads()";
- DI_AudioThread(1);
- valid_keys=1;
- n=WPAD_ReadPending(WPAD_CHAN_ALL, wpad_callback);//WPAD_ScanPads();
- DI_AudioThread(0);
- if(n<WPAD_ERR_NONE || !valid_keys) {return 0;}
- //debug_str="wii_joystick_read()";
- if(exit_by_reset)
- {
- exit(0);
- }
- DI_AudioThread(1);
- // lee los 4 wiimotes
- for(n=0;n<4;n++)
- retj[n]=WPAD_Probe(n, &type[n]);
- for(n=0;n<4;n++)
- {
- if(retj[n]>=0)
- {
- butt=WPAD_ButtonsHeld(n);
- is_readed=1;
- if(butt & WPAD_BUTTON_HOME) ret|=WII_HOME;
- if(type[n]==WPAD_EXP_NUNCHUK)
- {
- WPAD_Expansion(n,&w_exp);
- if(w_exp.nunchuk.js.pos.y<(128-48)) ret|=WII_DOWN;
- if(w_exp.nunchuk.js.pos.y>(128+48)) ret|=WII_UP;
- if(w_exp.nunchuk.js.pos.x<(128-48)) ret|=WII_LEFT;
- if(w_exp.nunchuk.js.pos.x>(128+48)) ret|=WII_RIGHT;
- if(butt & WPAD_NUNCHUK_BUTTON_C) ret|=WII_A;
- if(butt & WPAD_NUNCHUK_BUTTON_Z) ret|=WII_B;
- }
- if(butt & WPAD_BUTTON_A) ret|=WII_A;
- if(butt & WPAD_BUTTON_B) ret|=WII_B;
- if(butt & WPAD_BUTTON_1) ret|=WII_ONE;
- if(butt & WPAD_BUTTON_2) ret|=WII_TWO;
- if(butt & WPAD_BUTTON_UP) ret|=WII_UP;
- if(butt & WPAD_BUTTON_DOWN) ret|=WII_DOWN;
- if(butt & WPAD_BUTTON_RIGHT) ret|=WII_RIGHT;
- if(butt & WPAD_BUTTON_LEFT) ret|=WII_LEFT;
- if(butt & WPAD_BUTTON_MINUS) ret|=WII_MINUS;
- if(butt & WPAD_BUTTON_PLUS) ret|=WII_PLUS;
- }
- }
- DI_AudioThread(0);
- if(!is_readed) return wii_nKeys;
- //debug_str="Undef";
- return ret;
- }
- char * get_name(char *name);
- int volume=204;
- ////////////////////////////////////////////////////////////////////////
- /***************************************************************************/
- // seleccion de ficheros
- /***************************************************************************/
- int nfiles=0;
- int ndirs=0;
- #define MAX_ENTRY 512
- struct _files
- {
- int size;
- char name[258];
- char is_directory;
- char is_selected;
- } files[MAX_ENTRY],swap_file;
- int njpg_files=0,npng_files=0,nmusic_files=0,play_file=-1,current_jpg=-1,current_png=-1;
- int music_playing=0, music_loop=0;
- struct _play_files
- {
- char name[258];
- } jpg_files[MAX_ENTRY], png_files[MAX_ENTRY], music_files[MAX_ENTRY], txt_file, swap_music;
- // textreader
- char *txt_file_mem=NULL;
- int txt_file_len=0;
- void music_shuffle()
- {
- int n,k;
- int s;
- if(nmusic_files<=1) return;
- for(s=0;s<10;s++)
- for(n=0;n<nmusic_files;n++)
- {
- k=((rand() & 511)* nmusic_files)/512;
- swap_music= music_files[n];
- music_files[n]=music_files[k];
- music_files[k]= swap_music;
- }
- StopAudio();music_playing=0;play_file=-1;
- }
- // test_music_file: mode 0 -> Activa flag si fichero está en la lista; mode 1-> añade o borra fichero
- void test_music_file(int index, int mode)
- {
- int n;
- int test;
- //if(index>=nfiles) return;
- if(files[index].is_directory) {files[index].is_selected=0;return;}
- test=0;
- for(n=0;n<nmusic_files;n++)
- {
- if(!strcmp(files[index].name, music_files[n].name))
- {
- test=1;break;
- }
- }
- if(mode==0)
- {
- if(test)
- files[index].is_selected=1;
- else
- files[index].is_selected=0;
- }
- if(mode==1)
- {
- if(!test)
- {
- if(nmusic_files<MAX_ENTRY) {files[index].is_selected=1;memcpy(music_files[nmusic_files].name,files[index].name,258);nmusic_files++;}
- }
- else
- {
- files[index].is_selected=0;
- if(nmusic_files>0) nmusic_files--;
- for(;n<nmusic_files;n++) {music_files[n]=music_files[n+1];}
- }
- }
- }
- int loop_music_playing()
- {
- int n;
- if(play_file>=0 && music_playing)
- {
- n=StatusAudio();
- if(n!=AUDIO_STATUS_RUNNING && n!=AUDIO_STATUS_PAUSED)
- {
- play_file++;
- if(music_loop) if(play_file>=nmusic_files) play_file=0;
- if(play_file<nmusic_files) {music_playing=1;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0; return 1;}
- else {StopAudio();music_playing=0;play_file=-1;}
- }
- }
- return 0;
- }
- int is_ext(char *a,char *b) // compara extensiones
- {
- int n,m;
- m=0;n=0;
- while(a[n]!=0) {if(a[n]=='.') m=n; n++;}
- n=0;
- while(b[n]!=0) {
- unsigned char t1,t2;
- t1=a[m];t2=b[n];
- if(t1>='A' && t1<='Z') t1+=32;
- if(t2>='A' && t2<='Z') t2+=32;
- if(t1!=t2) return 0; m++; n++;
- }
- if(a[m]==0) return 1;
- return 0;
- }
- char * get_name_short(char *name) // devuelve el nombre del fichero recortado a 36 caracteres
- {
- #define MAX_STR 36
- #define BRK_STR 17
- static unsigned char name2[MAX_STR+4];
- int n,m,l;
- m=0;n=-1;
- while(name[m]!=0) {if(name[m]=='/') n=m;m++;} // elimina la parte de directorio
- n++;
- l=n;
- while(name[l]!=0) l++;
- l-=n;
- if(l>=MAX_STR)
- {
- memcpy(name2,&name[n],BRK_STR);
- name2[BRK_STR]='.';
- name2[BRK_STR+1]='.';
- n+=(l-MAX_STR)+(BRK_STR+2);
- for(m=BRK_STR+2;m<MAX_STR;m++)
- {
- name2[m]=name[n];
- if(name[n]==0) break;
- n++;
- }
- }
- else
- {
- for(m=0;m<MAX_STR;m++)
- {
- name2[m]=name[n];
- if(name[n]==0) break;
- n++;
- }
- }
- name2[m]=0;
- #undef MAX_STR
- #undef BRK_STR
- return ((char *)name2);
- }
- char * get_name_short_fromUTF8(char *name) // devuelve el nombre del fichero recortado a 36 caracteres
- {
- #define MAX_STR 36
- #define BRK_STR 17
- static unsigned char name2[MAX_STR+4];
- int n,m,l,s;
- m=0;n=-1;
- while(name[m]!=0) {if(name[m]=='/') n=m;m++;} // elimina la parte de directorio
- n++;
- l=n;
- while(name[l]!=0) l++;
- l-=n;
- if(l>=MAX_STR)
- {
- s=n;
- for(m=0;m<BRK_STR;m++)
- {
- if((name[s] & 0xc0)==0xc0 && (name[s+1] & 0xc0)==0x80)
- {
- name2[m]= (((name[s] & 3)<<6) | (name[s+1] & 63));
- s++;
- }
- else name2[m]=name[s];
- s++;
- }
- //memcpy(name2,&name[n],BRK_STR);
- name2[m]='.';
- name2[m+1]='.';
- m+=2;
- n+=(l-MAX_STR)+(m);
- for(;m<MAX_STR;m++)
- {
- if((name[n] & 0xc0)==0xc0 && (name[n+1] & 0xc0)==0x80)
- {
- name2[m]= (((name[n] & 3)<<6) | (name[n+1] & 63));
- n++;
- }
- else name2[m]=name[n];
- if(name[n]==0) break;
- n++;
- }
- }
- else
- {
- for(m=0;m<MAX_STR;m++)
- {
- if((name[n] & 0xc0)==0xc0 && (name[n+1] & 0xc0)==0x80)
- {
- name2[m]= (((name[n] & 3)<<6) | (name[n+1] & 63));
- n++;
- }
- else name2[m]=name[n];
- if(name[n]==0) break;
- n++;
- }
- }
- name2[m]=0;
- #undef MAX_STR
- #undef BRK_STR
- return ((char *)name2);
- }
- void char_to_utf8(char *s, char *d)
- {
- u8 *c= (u8 *) s;
- while(*c!=0)
- {
- if((*c & 0xc0)==0xc0 && (*(c+1) & 0xc0)==0x80) // esto es UTF-8!
- {
- *d++=*c++;
- *d++=*c;
- }
- else
- if(*c>=0x80) // convierte a UTF-8
- {
- *d++= 192 | (*c>>6);
- *d++= 128 | (*c & 63);
- }
- else *d++=*c;
- c++;
- }
- *d=0;
- }
- void utf8_to_char(char *s, char *d)
- {
- u8 *c= (u8 *) s;
- while(*c!=0)
- {
- if((*c & 0xc0)==0xc0 && (*(c+1) & 0xc0)==0x80)
- {
- *d++= (((*c & 3)<<6) | (*(c+1) & 63));
- c++;
- }
- else *d++=*c;
- c++;
- }
- *d=0;
- }
- char * get_name(char *name) // devuelve el nombre del fichero completo
- {
- static unsigned char name2[256];
- int n,m;
- m=0;n=-1;
- while(name[m]!=0) {if(name[m]=='/') n=m;m++;}
- n++;
- for(m=0;m<255;m++)
- {
- name2[m]=name[n];
- if(name[n]==0) break;
- n++;
- }
- name2[m]=0;
- return ((char *) name2);
- }
- char * get_name_from_UTF8(char *name) // devuelve el nombre del fichero completo
- {
- static unsigned char name2[256];
- int n,m;
- m=0;n=-1;
- while(name[m]!=0) {if(name[m]=='/') n=m;m++;}
- n++;
- for(m=0;m<255;m++)
- {
- if((name[n] & 0xc0)==0xc0 && (name[n+1] & 0xc0)==0x80)
- {
- name2[m]= (((name[n] & 3)<<6) | (name[n+1] & 63));
- n++;
- }
- else
- name2[m]=name[n];
- if(name[n]==0) break;
- n++;
- }
- name2[m]=0;
- return ((char *) name2);
- }
- char * LoadZipTxt(char *name, int *fsize)
- {
- unz_global_info gi;
- unzFile uf;
- int error;
- int n;
- char zip_file[256];
- unz_file_info zip_file_info;
- char *mem=NULL;
- *fsize=0;
- uf = unzOpen (name);
- if (uf == NULL) return NULL;
- error = unzGetGlobalInfo (uf, &gi);
- if(error != UNZ_OK) {unzClose(uf);return NULL;}
- for (n=0; n<gi.number_entry; n++)
- {
- error = unzGetCurrentFileInfo (uf, &zip_file_info, zip_file,
- sizeof (zip_file), NULL, 0, NULL, 0);
- if(error != UNZ_OK) {unzClose(uf);return NULL;}
- if (is_ext(zip_file, ".txt")) break;
- if (n < (gi.number_entry-1))
- {
- error = unzGoToNextFile (uf);
- if(error != UNZ_OK) {unzClose(uf);return NULL;}
- }
- }
- //
- mem =malloc(zip_file_info.uncompressed_size+0x2000);
- if (mem == NULL) {unzClose(uf);return NULL;}
- error = unzOpenCurrentFile (uf);
- if(error != UNZ_OK) {free(mem);mem=0;unzClose(uf);return NULL;}
- *fsize=zip_file_info.uncompressed_size;
- n=0;
- while(n<zip_file_info.uncompressed_size)
- {
- error = unzReadCurrentFile (uf, mem+n, zip_file_info.uncompressed_size-n);
- if (error <= 0) break;
- n+=error;
- }
- if(error <0) {*fsize=0;free(mem);mem=0;unzCloseCurrentFile(uf);unzClose(uf);return NULL;}
- error = unzCloseCurrentFile (uf);
- if(error != UNZ_OK) {*fsize=0;unzClose(uf);free(mem);mem=0;return NULL;}
- return mem;
- }
- int have_device=0;
- int current_device=0;
- void read_list_file(unsigned char *dirname, int flag)
- {
- DIR *fd;
- static char namefile[256*4];
- static struct stat filestat;
- //struct dirent* temp = NULL;
- static char swap[257];
- int n,m,f;
- if(!dirname) sprintf(swap, "%s", path_file);
- else
- {
- sprintf(path_file, "%s", dirname);
- n=0;while(dirname[n]!=0) n++;
- if(dirname[n-1]=='/') // esto solo pasa si es directorio raiz
- {sprintf(swap, "%s", dirname);dirname=0;}
- else
- {
- sprintf(swap, "%s/", dirname);
- if(swap[n-1]=='.')
- {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
- }
- }
- ndirs=0;
- nfiles = 0;
- files[nfiles].is_selected=0;
- if(!dirname)
- {
- if(current_device==0 && (have_device & 2)!=0)
- {
- sprintf(files[nfiles].name, ".[USB]");
- ndirs++;files[nfiles].is_directory=1;
- files[nfiles].is_selected=0;
- nfiles++;
- }
- if(current_device==1 && (have_device & 1)!=0)
- {
- sprintf(files[nfiles].name, ".[SD]");
- ndirs++;files[nfiles].is_directory=1;
- files[nfiles].is_selected=0;
- nfiles++;
- }
- }
- fd = opendir(swap);
- if(fd != NULL)
- {
- while(nfiles < MAX_ENTRY)
- {
- files[nfiles].is_directory=0;
- files[nfiles].is_selected=0;
- //if(readdir(fd, namefile, &filestat)!=0) break;
- /*snprintf(fullpath, sizeof(fullpath), "%s/%s", path, temp->d_name);
- if(stat( fullpath, &filestat) == 0) {
- if(dirnext( fd, namefile, &filestat) != 0) break;*/
- if(namefile[0]=='.' && namefile[1]==0) continue;
- sprintf(files[nfiles].name, "%s%s", swap, namefile);
- if((filestat.st_mode & S_IFDIR))
- {
- files[nfiles].size=0;
- ndirs++;files[nfiles].is_directory=1;
- }
- else
- {
- if(flag==0)
- {
- if(!(is_ext(files[nfiles].name,".mp3") || is_ext(files[nfiles].name,".ogg") || is_ext(files[nfiles].name,".m3u") )) continue;
- if(!is_ext(files[nfiles].name,".m3u")) test_music_file(nfiles, 0);
- }
- if(flag==1)
- if(!(is_ext(files[nfiles].name,".jpg") || is_ext(files[nfiles].name,".jpeg") || is_ext(files[nfiles].name,".png"))) continue;
- if(flag==2)
- if(!(is_ext(files[nfiles].name,".txt") || is_ext(files[nfiles].name,".zip"))) continue;
- files[nfiles].size=filestat.st_size;
- }
- nfiles++;
- }
- closedir(fd);
- }
- if(!nfiles)
- {
- if(current_device==0 && (have_device & 2)!=0)
- {
- sprintf(files[nfiles].name, ".[USB]");
- ndirs++;files[nfiles].is_directory=1;
- files[nfiles].is_selected=0;
- nfiles++;
- }
- if(current_device==1 && (have_device & 1)!=0)
- {
- sprintf(files[nfiles].name, ".[SD]");
- ndirs++;files[nfiles].is_directory=1;
- files[nfiles].is_selected=0;
- nfiles++;
- }
- }
- for(n=0;n<(nfiles);n++) //ordena
- for(m=n+1;m<nfiles;m++)
- {
- f=0;
- if(files[m].is_directory==1 && files[n].is_directory==0) f=1;
- if(f==0)
- if(files[m].is_directory==files[n].is_directory)
- if(strcmp(files[m].name,files[n].name)<0) f=1;
- if(f)
- {
- f=0;
- swap_file=files[m];
- files[m]=files[n];
- files[n]=swap_file;
- }
- }
- }
- void fun_exit()
- {
- int m=0;
- Screen_flip();
- autocenter=0;
- sizeletter=1;
- m=SCR_HEIGHT/2;
- SetTexture(MOSAIC_PATTERN);
- DrawRoundFillBox(32,m-128, 640-64, 256, 0,0xff803000);
- SetTexture(NULL);
- DrawRoundBox(32,m-128, 640-64, 256, 0, 6, 0xfff08020);
- autocenter=1;
- PX=0;PY=m-16;
- s_printf("Closing All");
- autocenter=0;
- Screen_flip();
- StopAudio();
- write_cfg(path_txt_cfg);
- WPAD_Shutdown();
- ASND_End();
- if(have_device & 1) fatUnmount("sd");
- if(have_device & 2) fatUnmount("usb");
- VIDEO_WaitVSync();
- VIDEO_WaitVSync();
- sleep(2);
- if(exit_by_reset==2)
- SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
- if(exit_by_reset==3)
- SYS_ResetSystem(SYS_POWEROFF_STANDBY, 0, 0);
- }
- struct my_error_mgr {
- struct jpeg_error_mgr pub; /* "public" fields */
- jmp_buf setjmp_buffer; /* for return to caller */
- };
- typedef struct my_error_mgr * my_error_ptr;
- char jpg_error_str[JMSG_LENGTH_MAX];
- void my_error_exit (j_common_ptr cinfo)
- {
- /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
- my_error_ptr myerr = (my_error_ptr) cinfo->err;
- /* Always display the message. */
- /* We could postpone this until after returning, if we chose. */
- // (*cinfo->err->output_message) (cinfo);
- (*cinfo->err->format_message) (cinfo, jpg_error_str);
- /* Return control to the setjmp point */
- longjmp(myerr->setjmp_buffer, 1);
- }
- unsigned *jpeg_buf=NULL;
- int jpeg_tdx,jpeg_tdy; // texel w-h
- int jpeg_w,jpeg_h; // pixel w-h
- int read_JPEG_file (char * filename)
- {
- /* This struct contains the JPEG decompression parameters and pointers to
- * working space (which is allocated as needed by the JPEG library).
- */
- struct jpeg_decompress_struct cinfo;
- /* We use our private extension JPEG error handler.
- * Note that this struct must live as long as the main JPEG parameter
- * struct, to avoid dangling-pointer problems.
- */
- struct my_error_mgr jerr;
- /* More stuff */
- FILE * infile; /* source file */
- JSAMPARRAY buffer; /* Output row buffer */
- int row_stride; /* physical row width in output buffer */
- int n,m;
- int a,b,k,l,same_w;
- int rr,gg,bb;
- u8 *buf;
- /* In this example we want to open the input file before doing anything else,
- * so that the setjmp() error recovery below can assume the file is open.
- * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
- * requires it in order to read binary files.
- */
- jpg_error_str[0]=0;
- if ((infile = fopen(filename, "rb")) == NULL) {
- sprintf(jpg_error_str,"Can't open file");
- return 0;
- }
- /* Step 1: allocate and initialize JPEG decompression object */
- /* We set up the normal JPEG error routines, then override error_exit. */
- cinfo.err = jpeg_std_error(&jerr.pub);
- jerr.pub.error_exit = my_error_exit;
- /* Establish the setjmp return context for my_error_exit to use. */
- if (setjmp(jerr.setjmp_buffer)) {
- /* If we get here, the JPEG code has signaled an error.
- * We need to clean up the JPEG object, close the input file, and return.
- */
- //printf("Error!!!\n");
- jpeg_destroy_decompress(&cinfo);
- fclose(infile);
- return 0;
- }
- /* Now we can initialize the JPEG decompression object. */
- jpeg_create_decompress(&cinfo);
- /* Step 2: specify data source (eg, a file) */
- jpeg_stdio_src(&cinfo, infile);
- /* Step 3: read file parameters with jpeg_read_header() */
- (void) jpeg_read_header(&cinfo, TRUE);
- /* We can ignore the return value from jpeg_read_header since
- * (a) suspension is not possible with the stdio data source, and
- * (b) we passed TRUE to reject a tables-only JPEG file as an error.
- * See libjpeg.doc for more info.
- */
- /* Step 4: set parameters for decompression */
- /* In this example, we don't need to change any of the defaults set by
- * jpeg_read_header(), so we do nothing here.
- */
- /* Step 5: Start decompressor */
- (void) jpeg_start_decompress(&cinfo);
- /* We can ignore the return value since suspension is not possible
- * with the stdio data source.
- */
- /* We may need to do some setup of our own at this point before reading
- * the data. After jpeg_start_decompress() we have the correct scaled
- * output image dimensions available, as well as the output colormap
- * if we asked for color quantization.
- * In this example, we need to make an output work buffer of the right size.
- */
- /* JSAMPLEs per row in output buffer */
- row_stride = cinfo.output_width * cinfo.output_components;
- // printf("width %i %i\n",cinfo.output_width, cinfo.output_components);
- /* Make a one-row-high sample array that will go away when done with image */
- buffer = (*cinfo.mem->alloc_sarray)
- ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
- jpeg_w=cinfo.output_width;
- jpeg_h=cinfo.output_height;
- if(!buffer || jpg_error_str[0]!=0)
- {
- jpeg_destroy_decompress(&cinfo);
- fclose(infile);
- return 0;
- }
- /* Step 6: while (scan lines remain to be read) */
- /* jpeg_read_scanlines(...); */
- /* Here we use the library's state variable cinfo.output_scanline as the
- * loop counter, so that we don't have to keep track ourselves.
- */
- n=0;
- jpeg_tdx=(jpeg_w>>3)<<3; if(jpeg_tdx>1024) jpeg_tdx=1024;
- jpeg_tdy=(jpeg_h>>3)<<3; if(jpeg_tdy>1024) jpeg_tdy=1024;
- a=0;k=0;
- while (cinfo.output_scanline < cinfo.output_height) {
- /* jpeg_read_scanlines expects an array of pointers to scanlines.
- * Here the array is only one element long, but you could ask for
- * more than one scanline at a time if that's more convenient.
- */
- (void) jpeg_read_scanlines(&cinfo, buffer, 1);
- /* Assume put_scanline_someplace wants a pointer and sample count. */
- // put_scanline_someplace(buffer[0], row_stride);
- if(jpg_error_str[0]!=0)
- {
- jpeg_destroy_decompress(&cinfo);
- fclose(infile);
- return 0;
- }
- buf=(u8 *) buffer[0];
- rr=buf[2];
- gg=buf[1];
- bb=buf[0];
- b=0;l=0;
- same_w=0;
- for(m=0;m<jpeg_w;m++) // re-scale to the max 1024x1024
- {
- if(!same_w)
- {
- jpeg_buf[(k*jpeg_tdx)+l]=0xff000000 | (bb<<16) | (gg<<8) | (rr);
- }
- else
- {
- rr+=buf[2];
- gg+=buf[1];
- bb+=buf[0];
- }
- buf+=3;
- b+=jpeg_tdx;if(b>=jpeg_w)
- {
- if(same_w)
- {
- same_w++;
- rr/=same_w;
- gg/=same_w;
- bb/=same_w;
- jpeg_buf[(k*jpeg_tdx)+l]=0xff000000 | (bb<<16) | (gg<<8) | (rr);
- }
- same_w=0;b-=jpeg_w;l++;if(l>=jpeg_tdx) break;
- rr=buf[2];
- gg=buf[1];
- bb=buf[0];
- } else same_w++;
- }
- a+=jpeg_tdy;if(a>=jpeg_h) {a-=jpeg_h;k++;if(k>=jpeg_tdy) break;}
- n++;
- }
- /* Step 7: Finish decompression */
- (void) jpeg_finish_decompress(&cinfo);
- /* We can ignore the return value since suspension is not possible
- * with the stdio data source.
- */
- /* Step 8: Release JPEG decompression object */
- /* This is an important step since it will release a good deal of memory. */
- jpeg_destroy_decompress(&cinfo);
- /* After finish_decompress, we can close the input file.
- * Here we postpone it until after no more JPEG errors are possible,
- * so as to simplify the setjmp error logic above. (Actually, I don't
- * think that jpeg_destroy can do an error exit, but why assume anything...)
- */
- fclose(infile);
- /* At this point you may want to check to see whether any corrupt-data
- * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
- */
- if(jpg_error_str[0]!=0)
- {
- return 0;
- }
- /* And we're done! */
- return 1;
- }
- int read_PNG_file (char * filename)
- {
- PNGUPROP imgProp;
- IMGCTX ctx;
- char *texture_buff;
- //ctx = PNGU_SelectImageFromDevice (filename);
- if ( !(ctx = PNGU_SelectImageFromDevice (filename)) ){
- return 0;
- }
- PNGU_GetImageProperties (ctx, &imgProp);
- texture_buff = memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4);
- PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, texture_buff, 255);
- PNGU_ReleaseImageContext (ctx);
- DCFlushRange (texture_buff, imgProp.imgWidth * imgProp.imgHeight * 4);
- return 1;
- }
- GXTexObj scr_tex;
- GXTexObj icon_tex[icons_num_sprites];
- u16 *animate_mem=NULL;
- void animate_background()
- {
- int n,m,k;
- static int l=0;
- n=icons_num_sprites-2;
- if(!animate_mem) animate_mem=memalign(32, icons_sprites[n].sx*icons_sprites[n].sy*2);
- if(!animate_mem) return;
- l++;
- k=l>>2;
- for(m=0;m<icons_sprites[n].sy;m++)
- {
- k=(k % icons_sprites[n].sy);
- memcpy(animate_mem+k*icons_sprites[n].sx, ((u16 *)icons_sprites[n].ptr)+m*icons_sprites[n].sx, icons_sprites[n].sx*2);
- k++;
- }
- CreateTexture(&icon_tex[n], TLUT_SRGB5A1, animate_mem, icons_sprites[n].sx, icons_sprites[n].sy, 0);
- }
- int audio_pause=0;
- void select_file(int flag)
- {
- int n,m,l,f=0,len,max_entry;
- static int posfile=0;
- static int old_flag=-1;
- int flash=0;
- read_list_file((void *) path_file, flag);
- if(flag!=old_flag)
- {
- posfile=0;
- old_flag=flag;
- }
- while(1)
- {
- flash++;
- if(exit_by_reset) break;
- loop_music_playing();
- m=0;
- sizeletter=4;
- // SetTexture(MOSAIC_PATTERN);DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff603000);
- animate_background();
- SetTexture(&icon_tex[icons_num_sprites-2]);
- DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff906000);
- // header
- SetTexture(CROSS_PATTERN);
- DrawRoundFillBox(8,8, 640-16, 32, 0, 0xff302000);
- SetTexture(NULL_PATTERN);
- DrawRoundBox(8,8, 640-16, 32, 0, 2, 0xff804000);
- PX=0;PY=16;color=0xffffffff;autocenter=1;
- if(flag==0) s_printf("SELECT MUSIC FILES");
- if(flag==1) s_printf("SELECT IMAGE FILES");
- if(flag==2) s_printf("SELECT TEXT FILES");
- autocenter=0;
- // file list
- SetTexture(CROSS_PATTERN);
- DrawRoundFillBox(8,48, 640-16, SCR_HEIGHT-32-48, 0, 0xff302000);
- SetTexture(NULL_PATTERN);
- DrawRoundBox(8, 48, 640-16, SCR_HEIGHT-32-48, 0, 2, 0xff804000);
- max_entry=(SCR_HEIGHT-32-48)/20;
- SetTexture(NULL);
- DrawRoundFillBox(8,SCR_HEIGHT-28, 640-16, 24, 0, 0xff201010);
- SetTexture(NULL_PATTERN);
- DrawRoundBox(8,SCR_HEIGHT-28, 640-16, 24, 0, 2, 0xff804000);
- PX=24;PY=SCR_HEIGHT-24;color=0xffffffff;autocenter=1;
- sizeletter=3;
- if(flag==0)
- s_printf("Use A to select one file and PLUS to select All");
- if(flag==1)
- s_printf("Use A to select one file and PLUS to select All");
- if(flag==2)
- s_printf("Use A to select one file");
- autocenter=0;
- sizeletter=4;
- for(n=(posfile-max_entry/2)*(nfiles>=max_entry);n<posfile+max_entry;n++)
- {
- if(n<0) continue;
- if(n>=nfiles) break;
- if(m>=max_entry) break;
- PX=16;PY=48+2+m*20;
- color=0xffffffff;
- if(n==posfile)
- {
- len=38;
- //if(flash & 8)
- DrawRoundFillBox(PX,PY-2, len*16, 20, 0, 0xff00004f);
- DrawRoundBox(PX,PY-2, len*16, 20, 0, 2, 0xff30ffff);
- }
- if(files[n].is_directory)
- {
- if(files[n].name[0]=='.' && files[n].name[1]=='[')
- {
- color=0xffffff00;
- s_printf("%s",&files[n].name[1]);
- }
- else
- {
- color=0xff00ffff;
- s_printf("<%s>",get_name_short_fromUTF8(&files[n].name[0]));
- }
- }
- else
- {
- color=0xffffffff;
- if(files[n].is_selected) color=0xff6fff6f;
- if(flag==2)
- if(!strcmp(files[n].name,txt_file.name)) color=0xff6fff6f;
- s_printf("%s", (char *) get_name_short_fromUTF8(&files[n].name[0]));
- }
- bkcolor=0;color=0xffffffff;
- m++;
- }
- wii_nKeys=wii_joystick_read(0);
- new_key=wii_nKeys & (~old_key);
- old_key=wii_nKeys;
- if(!(old_key & (WII_UP | WII_DOWN))) f=0;
- if(old_key & WII_UP)
- {
- if(f==0) f=2;
- else if(f & 1) f=2;
- else {f+=2;if(f>40) {f=34;new_key|=WII_UP;}}
- }
- if(old_key & WII_DOWN)
- {
- if(f==0) f=1;
- else if(!(f & 1)) f=1;
- else {f+=2;if(f>41) {f=35;new_key|=WII_DOWN;}}
- }
- if(new_key & (WII_HOME | WII_ONE | WII_TWO)) break;
- if(nfiles>0) if(new_key & WII_PLUS)
- {
- if(flag==1)
- {
- current_jpg=-1;
- njpg_files=0;
- for(n=0;n<nfiles;n++)
- {
- if(!files[n].is_directory)
- if(is_ext(files[n].name,".jpg") || is_ext(files[n].name,".jpeg") || is_ext(files[n].name,".png"))
- {
- memcpy(jpg_files[njpg_files].name,files[n].name,258);
- current_jpg=0;
- njpg_files++;
- if(njpg_files>=MAX_ENTRY) break;
- }
- }
- break;
- }
- else
- if(flag==0)
- {
- for(n=0;n<nfiles;n++)
- {
- if(!files[n].is_directory)
- if(is_ext(files[n].name,".mp3") || is_ext(files[n].name,".ogg"))
- {
- test_music_file(n, 1);
- }
- }
- }
- }
- if(nfiles>0) if(new_key & WII_A)
- {
- if(!files[posfile].is_directory)
- {
- if(is_ext(files[posfile].name,".txt") || is_ext(files[posfile].name,".zip"))
- {
- FILE *fp;
- memcpy(txt_file.name,files[posfile].name,258);
- if(txt_file_mem) free(txt_file_mem);txt_file_mem=0;
- txt_file_len=0;
- if(is_ext(files[posfile].name,".zip"))
- txt_file_mem = LoadZipTxt(txt_file.name, &txt_file_len);
- else
- {
- fp=fopen(txt_file.name,"r"); // lee el fichero de texto
- if(fp!=0)
- {
- fseek(fp,0,SEEK_END);
- txt_file_len=ftell(fp);
- fseek(fp,0,SEEK_SET);
- txt_file_mem=malloc(txt_file_len+128);
- if(txt_file_mem)
- {n=fread(txt_file_mem,1,txt_file_len,fp);
- if(n<0) {txt_file_len=0;free(txt_file_mem);txt_file_mem=0;} else txt_file_len=n;
- }
- else txt_file_len=0;
- fclose(fp);
- }
- }
- if(txt_file_len!=0)
- {
- read_txt_cfg(path_txt_cfg);
- text_init(txt_file_mem, txt_file_len, txt_file.name);
- break;
- }
- }
- else
- if(is_ext(files[posfile].name,".jpg") || is_ext(files[posfile].name,".jpeg") || is_ext(files[posfile].name,".png"))
- {
- current_jpg=-1;
- njpg_files=0;
- for(n=0;n<nfiles;n++)
- {
- if(!files[n].is_directory)
- if(is_ext(files[n].name,".jpg") || is_ext(files[n].name,".jpeg") || is_ext(files[n].name,".png"))
- {
- memcpy(jpg_files[njpg_files].name,files[n].name,258);
- if(n==posfile) current_jpg=njpg_files;
- njpg_files++;
- if(njpg_files>=MAX_ENTRY) break;
- }
- }
- break;
- }
- else
- {
- #if 1
- if(nmusic_files<MAX_ENTRY)
- {
- if(is_ext(files[posfile].name,".mp3") || is_ext(files[posfile].name,".ogg"))
- {
- test_music_file(posfile, 1);
- }
- else
- if(is_ext(files[posfile].name,".m3u"))
- {
- FILE *fp;
- memcpy(temp_buffer,files[posfile].name,258); // copia el nombre al archivo temporal
- m=n=0;
- while(temp_buffer[n]!=0) {if(temp_buffer[n]=='/') m=n+1; n++;}
- l=m;
- temp_buffer[l]=0;
- fp=fopen(files[posfile].name,"r"); // lee el fichero m3u
- if(fp!=0)
- {
- nmusic_files=0;
- while(fgets((void *) &temp_buffer[512], 256, fp))
- {
- n=512;
- while(temp_buffer[n]!=0) {if(temp_buffer[n]<32) {temp_buffer[n]=0;break;} n++;}
- if(is_ext((void *) &temp_buffer[512],".mp3") || is_ext((void *) &temp_buffer[512],".ogg"))
- {
- if(nmusic_files<MAX_ENTRY)
- {
- m=n=512;
- while(temp_buffer[n]!=0) {if(temp_buffer[n]=='/' || temp_buffer[n]=='\\') m=n+1; n++;}
- n-=512;
- if((l+n)>258) {n=257-l;temp_buffer[n+512]=0;}
- sprintf((void *) &temp_buffer[1024],"%s%s",&temp_buffer[0],&temp_buffer[m]);
- char_to_utf8((void *) &temp_buffer[1024],music_files[nmusic_files].name);
- nmusic_files++;
- }
- else break;
- }
- }
- fclose(fp);
- if(nmusic_files)
- {
- play_file=0;
- music_playing=1;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0;
- break; // retorna al player
- }
- } //clos
- }// m3u
- }
- #endif
- }
- }
- else
- {
- // cambio de device
- if(files[posfile].name[0]=='.' && files[posfile].name[1]=='[')
- {
- if(files[posfile].name[2]=='U')
- {
- current_device=1;
- sprintf(path_file, "fat%i:/", "usb");
- read_list_file(NULL, flag);
- posfile=0;
- }
- else
- if(files[posfile].name[2]=='S')
- {
- current_device=0;
- sprintf(path_file, "fat%i:/", "sd");
- read_list_file(NULL, flag);
- posfile=0;
- }
- }
- else
- {read_list_file((void *) &files[posfile].name[0], flag);posfile=0;}
- }
- }
- if((new_key & WII_UP)) {posfile--;if(posfile<0) posfile=nfiles-1;}
- if((new_key & WII_DOWN)){posfile++;if(posfile>=nfiles) posfile=0;}
- Screen_flip();
- }
- Screen_flip();
- }
- void music_player();
- void jpeg_player()
- {
- int dx,dy;
- int posx=0,posy=0;
- static int mode=0;
- static int amp=100;
- int n;
- int osd_time=0;
- unsigned time;
- if(current_jpg<0) return;
- while(1) // proteccion contra pulsaciones
- {
- if(exit_by_reset) break;
- wii_nKeys=wii_joystick_read(1);
- new_key=wii_nKeys & (~old_key);
- old_key=wii_nKeys;
- if(!(old_key &
- (WII_LEFT | WII_RIGHT | WII_UP | WII_DOWN ))) break;
- }
- Next_jpg:
- posx=0;posy=0;
- osd_time=0;
- time=ticks_to_msecs(gettick());
- if(is_ext(jpg_files[current_jpg].name,".jpg") || is_ext(jpg_files[current_jpg].name,".jpeg")){
- if(read_JPEG_file(jpg_files[current_jpg].name))
- {
- CreateTexture(&scr_tex, TILE_RGBA8, (void *) jpeg_buf, jpeg_tdx, jpeg_tdy, 0);
- }
- else
- {
- jpeg_tdx=jpeg_tdy=64;
- jpeg_w=256;jpeg_h=256;
- memset((void *) jpeg_buf,0,jpeg_tdx*jpeg_tdy*4);
- for(n=0;n<jpeg_tdx;n++)
- {
- jpeg_buf[jpeg_tdx*n+n]=0xffff0000;
- if((n+1)<jpeg_tdx) jpeg_buf[jpeg_tdx*n+n+1]=0xffff0000;
- if((n+2)<jpeg_tdx) jpeg_buf[jpeg_tdx*n+n+2]=0xffff0000;
- if((n+3)<jpeg_tdx) jpeg_buf[jpeg_tdx*n+n+3]=0xffff0000;
- jpeg_buf[jpeg_tdx*n+jpeg_tdx-n-1]=0xffff0000;
- if((jpeg_tdx-n-2)>0) jpeg_buf[jpeg_tdx*n+jpeg_tdx-n-2]=0xffff0000;
- if((jpeg_tdx-n-3)>0) jpeg_buf[jpeg_tdx*n+jpeg_tdx-n-3]=0xffff0000;
- if((jpeg_tdx-n-4)>0) jpeg_buf[jpeg_tdx*n+jpeg_tdx-n-4]=0xffff0000;
- }
- CreateTexture(&scr_tex, TILE_RGBA8, (void *) jpeg_buf, jpeg_tdx, jpeg_tdy, 0);
- }
- }else if(is_ext(jpg_files[current_jpg].name,".png")){
- if(read_PNG_file(jpg_files[current_jpg].name))
- {
- CreateTexture(&scr_tex, TILE_RGBA8, (void *) jpeg_buf, jpeg_tdx, jpeg_tdy, 0);
- }
- else
- {
- jpeg_tdx=jpeg_tdy=64;
- jpeg_w=256;jpeg_h=256;
- memset((void *) jpeg_buf,0,jpeg_tdx*jpeg_tdy*4);
- for(n=0;n<jpeg_tdx;n++)
- {
- jpeg_buf[jpeg_tdx*n+n]=0xffff0000;
- if((n+1)<jpeg_tdx) jpeg_buf[jpeg_tdx*n+n+1]=0xffff0000;
- if((n+2)<jpeg_tdx) jpeg_buf[jpeg_tdx*n+n+2]=0xffff0000;
- if((n+3)<jpeg_tdx) jpeg_buf[jpeg_tdx*n+n+3]=0xffff0000;
- jpeg_buf[jpeg_tdx*n+jpeg_tdx-n-1]=0xffff0000;
- if((jpeg_tdx-n-2)>0) jpeg_buf[jpeg_tdx*n+jpeg_tdx-n-2]=0xffff0000;
- if((jpeg_tdx-n-3)>0) jpeg_buf[jpeg_tdx*n+jpeg_tdx-n-3]=0xffff0000;
- if((jpeg_tdx-n-4)>0) jpeg_buf[jpeg_tdx*n+jpeg_tdx-n-4]=0xffff0000;
- }
- CreateTexture(&scr_tex, TILE_RGBA8, (void *) jpeg_buf, jpeg_tdx, jpeg_tdy, 0);
- }
- }
- if((ticks_to_msecs(gettick())-time)<500) // espera al menos medio segundo
- usleep(500*1000);
- while(1)
- {
- int flag;
- if(exit_by_reset) break;
- loop_music_playing();
- sizeletter=4;
- PX=24;PY=SCR_HEIGHT-24;color=0xffffffff;
- SetTexture(&scr_tex);
- //DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xffffffff);
- wii_nKeys=wii_joystick_read(1);
- new_key=wii_nKeys & (~old_key);
- old_key=wii_nKeys;
- flag=0;
- 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;}}
- if(new_key & WII_MINUS) {flag=1;amp-=25;if(amp<100) {mode=0;amp=100;}}
- if(new_key & WII_B)
- {
- current_jpg++;
- if(current_jpg>=njpg_files)
- {
- current_jpg--;
- amp=100;mode=0;
- }
- Screen_flip();
- SetTexture(NULL);
- goto Next_jpg;
- }
- if(new_key & WII_A)
- {
- current_jpg--;
- if(current_jpg<0)
- {
- current_jpg++;
- amp=100;mode=0;
- }
- Screen_flip();
- SetTexture(NULL);
- goto Next_jpg;
- }
- if(new_key & WII_HOME) break;
- if(amp==100 && mode==0)
- {
- if(!is_16_9)
- {
- dx=640;
- dy=(640*jpeg_h)/jpeg_w;
- if(dy>480)
- {
- dy=480;
- dx=(480*jpeg_w)/jpeg_h;
- }
- dy=SCR_HEIGHT*dy/480;
- }
- else
- {
- dx=853;
- dy=(853*jpeg_h)/jpeg_w;
- if(dy>480)
- {
- dy=480;
- dx=(480*jpeg_w)/jpeg_h;
- }
- dy=SCR_HEIGHT*dy/480;
- dx=dx*640/853;
- }
- posx=(640-dx)/2;
- posy=(SCR_HEIGHT-dy)/2;if(posy<0) posy=0;
- }
- else
- {
- if(is_16_9) dy=(((SCR_HEIGHT)*jpeg_h)/jpeg_w)*16/9;
- else dy=((SCR_HEIGHT/3)*4*jpeg_h)/jpeg_w;
- dx=640;
- dx=dx*amp/100;
- dy=dy*amp/100;
- #if 0
- if(new_key & WII_LEFT) {posx+=128/*dx/3*/;flag=1;}
- if(new_key & WII_RIGHT) {posx-=128/*dx/3*/;flag=1;}
- if(new_key & WII_UP) {posy+=64;flag=1;}
- if(new_key & WII_DOWN) {posy-=64;flag=1;}
- #endif
- if(old_key & WII_LEFT) {posx+=16;flag=1;}
- if(old_key & WII_RIGHT) {posx-=16;flag=1;}
- if(old_key & WII_UP) {posy+=16;flag=1;}
- if(old_key & WII_DOWN) {posy-=16;flag=1;}
- }
- if(flag)
- {
- if(posx>0 && flag!=2) posx=0;
- if(posy>0) posy=0;
- if(posx<-(dx-640)) posx=-(dx-640);
- if(posy<-(dy-(SCR_HEIGHT))) posy=-(dy-(SCR_HEIGHT));
- osd_time=0;
- }
- 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;}
- //DrawFillBox(0,0, 640, dy, 0,0xffffffff);
- if(mode==1 && amp>=100)
- {
- DrawFillBox(posx,posy, dx, dy, 100,0xffffffff);
- if(osd_time<120)
- {
- osd_time++;
- SetTexture(CROSS_PATTERN);
- DrawRoundFillBox(8,SCR_HEIGHT-24, 640-16, 24, 0, 0xff302000);
- SetTexture(NULL_PATTERN);
- DrawRoundBox(8,SCR_HEIGHT-24, 640-16, 24, 0, 4, 0xffff7f2f);
- PX=16;PY=SCR_HEIGHT-20;autocenter=1;s_printf("ZOOM: %i%% Img: (%i/%i)",amp, current_jpg+1, njpg_files);autocenter=0;
- }
- }
- else
- {
- DrawFillBox(posx,posy, dx, dy, 100,0xffffffff);
- if(osd_time<120)
- {
- osd_time++;
- SetTexture(CROSS_PATTERN);
- DrawRoundFillBox(8,SCR_HEIGHT-24, 640-16, 24, 0, 0xff302000);
- SetTexture(NULL_PATTERN);
- DrawRoundBox(8,SCR_HEIGHT-24, 640-16, 24, 0, 4, 0xffff7f2f);
- 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;
- }
- }
- if(jpg_error_str[0]!=0)
- {
- SetTexture(CROSS_PATTERN);
- DrawRoundFillBox(8,SCR_HEIGHT-24, 640-16, 24, 0, 0xff302000);
- SetTexture(NULL_PATTERN);
- DrawRoundBox(8,SCR_HEIGHT-24, 640-16, 24, 0, 4, 0xffff7f2f);
- autocenter=1;
- PX=16;PY=SCR_HEIGHT-20;s_printf("%s",jpg_error_str);
- autocenter=0;
- }
- Screen_flip();
- if(new_key & WII_ONE) {music_player();}
- }
- Screen_flip();
- SetTexture(NULL);
- }
- void music_gfx();
- void music_player()
- {
- int n,m;
- int f=0;
- int mode=0;
- int select=0;
- int select2=2;
- int time_playing=0;
- int time_playing_old=0;
- unsigned time_total=0;
- int left_count=0,right_count=0;
- int ang_suma=0;
- int status;
- int flash=0;
- int osd_volume=0;
- int fast=0;
- if(play_file>=0 && music_playing) select=play_file;
- wii_nKeys=wii_joystick_read(1);
- new_key=wii_nKeys & (~old_key);
- old_key=wii_nKeys;
- while(1)
- {
- int max_entry;
- if(exit_by_reset) break;
- flash++;
- status=StatusAudio();
- if(status==AUDIO_STATUS_RUNNING || fast) {ang_suma++;ang_suma %=360;}
- //SetTexture(MOSAIC_PATTERN);DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff603000);
- animate_background();
- SetTexture(&icon_tex[icons_num_sprites-2]);
- DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff906000);
- for(n=0;n<9;n++)
- {
- SetTexture(NULL_PATTERN);
- switch(n)
- {
- case 1:
- if(left_count)
- DrawFillBox(140+40*n,48, 32, 32, 0,0xff000000);
- else
- DrawFillBox(140+40*n,48, 32, 32, 0,0xff808080);
- break;
- case 2:
- if(status==AUDIO_STATUS_RUNNING && left_count==0 && right_count==0)
- DrawFillBox(140+40*n,48, 32, 32, 0,0xff000000);
- else
- DrawFillBox(140+40*n,48, 32, 32, 0,0xff808080);
- break;
- case 3:
- if(status==AUDIO_STATUS_PAUSED && (flash & 16)!=0 && fast==0)
- DrawFillBox(140+40*n,48, 32, 32, 0,0xff000000);
- else
- DrawFillBox(140+40*n,48, 32, 32, 0,0xff808080);
- break;
- case 4:
- if(!music_playing)
- DrawFillBox(140+40*n,48, 32, 32, 0,0xff000000);
- else
- DrawFillBox(140+40*n,48, 32, 32, 0,0xff808080);
- break;
- case 5:
- if(right_count)
- DrawFillBox(140+40*n,48, 32, 32, 0,0xff000000);
- else
- DrawFillBox(140+40*n,48, 32, 32, 0,0xff808080);
- break;
- case 6:
- DrawFillBox(140+40*n,48, 32, 32, 0,0xff000000);
- break;
- case 7:
- if(music_loop)
- DrawFillBox(140+40*n,48, 32, 32, 0,0xff0000ff);
- else
- DrawFillBox(140+40*n,48, 32, 32, 0,0xff808080);
- break;
- }
- SetTexture(&icon_tex[n]);
- if(select2==n && mode==0) DrawFillBox(140+40*n,48, 32, 32, 0,0xff40ff40);
- else DrawFillBox(140+40*n,48, 32, 32, 0,0xffffffff);
- }
- SetTexture(CROSS_PATTERN);
- DrawRoundFillBox(8, 88, 640-16, SCR_HEIGHT-16-88+8*(SCR_HEIGHT>480), 0, 0xff302000);
- SetTexture(NULL_PATTERN);
- DrawRoundBox(8, 88, 640-16, SCR_HEIGHT-16-88+8*(SCR_HEIGHT>480), 0, 2, 0xff804000);
- sizeletter=2;
- autocenter=1;
- PX=0;PY=12;
- color=0xfff08020;
- SetTexture(NULL_PATTERN);
- DrawRoundBox(208,8, 640-416, 32, 0, 2, 0xfff08020);
- s_printf("Music Player");
- autocenter=0;
- sizeletter=4;
- if(!fast) time_playing=GetTimeAudio()/1000; else time_playing=time_playing_old;
- time_total=GetTotalTimeAudio()/1000;
- if(!music_playing) {time_playing_old=0;time_playing=0;}
- else
- if(time_playing>0) time_playing_old=time_playing;
- if(status==AUDIO_STATUS_RUNNING || status==AUDIO_STATUS_PAUSED || fast)
- {
- SetTexture(MOSAIC_PATTERN);
- DrawFillSlice(320,88+(SCR_HEIGHT-16-88)/2, 120, 120, 0, 0, 360, 0xff603000);
- SetTexture(NULL_PATTERN);
- DrawSlice(320,88+(SCR_HEIGHT-16-88)/2, 120, 120, 0, 4, 0, 360, 0xff804000);
- SetTexture(STRIPED_PATTERN);
- DrawFillSlice(320,88+(SCR_HEIGHT-16-88)/2, 116, 116, 0, ang_suma, ang_suma+time_playing_old*360/time_total, 0x80000040);
- }
- SetTexture(NULL_PATTERN);
- PX=80-32-16;
- PY=32;
- color=0xff00f0f0;s_printf("Time");
- PX=600-48-32;
- s_printf("Length");
- color=0xffffffff;
- PX=16;
- PY=48;
- {
- unsigned color=0xff00ff00;
- unsigned temp=time_playing_old/60;
- int lh=20+4*(SCR_HEIGHT<=480);
- SetTexture(CROSS_PATTERN);
- DrawRoundFillBox(PX-8, PY, 120, 32, 0, 0xff302000);
- SetTexture(NULL_PATTERN);
- DrawRoundBox(PX-8, PY, 120, 32, 0, 2, 0xff804000);
- if((status==AUDIO_STATUS_PAUSED && (flash & 16)!=0) || status!=AUDIO_STATUS_PAUSED || fast)
- {
- if(temp/100)
- {
- SetTexture(&icon_tex[9+temp/100]);
- DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=20;
- }
- else PX+=10;
- temp %=100;
- SetTexture(&icon_tex[9]+temp/10);
- DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=20;temp %=10;
- SetTexture(&icon_tex[9]+temp);
- DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=16;
- SetTexture(&icon_tex[19]);
- DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=16;
- temp=time_playing_old % 60;
- SetTexture(&icon_tex[9+temp/10]);
- DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=20;temp %=10;
- SetTexture(&icon_tex[9+temp]);
- DrawFillBox(PX,PY+4, 20, lh, 0,color);
- }
- // total time
- PX=548-32;
- temp=time_total/60;
- SetTexture(CROSS_PATTERN);
- DrawRoundFillBox(PX-8, PY, 120, 32, 0, 0xff302000);
- SetTexture(NULL_PATTERN);
- DrawRoundBox(PX-8, PY, 120, 32, 0, 2, 0xff804000);
- if(temp/100)
- {
- SetTexture(&icon_tex[9+temp/100]);
- DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=20;
- }
- else PX+=10;
- temp %=100;
- SetTexture(&icon_tex[9]+temp/10);
- DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=20;temp %=10;
- SetTexture(&icon_tex[9]+temp);
- DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=16;
- SetTexture(&icon_tex[19]);
- DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=16;
- temp=time_total % 60;
- SetTexture(&icon_tex[9+temp/10]);
- DrawFillBox(PX,PY+4, 20, lh, 0,color);PX+=20;temp %=10;
- SetTexture(&icon_tex[9+temp]);
- DrawFillBox(PX,PY+4, 20, lh, 0,color);
- SetTexture(NULL_PATTERN);
- }
- //s_printf("%2.2u:%2.2u ",time_playing/60, time_playing % 60);
- sizeletter=4;
- /* color=0xff00f080;s_printf("Length: ");
- color=0xffffffff;
- s_printf("%2.2u:%2.2u",time_total/60, time_total % 60);*/
- max_entry=(SCR_HEIGHT-16-88)/20;
- PX=24;PY=SCR_HEIGHT-24;color=0xffffffff;
- m=0;
- if(mode==0) if(play_file>=0) select=play_file;
- if(nmusic_files>0)
- for(n=(select-max_entry/2)*(nmusic_files>=max_entry);n<select+max_entry;n++)
- {
- if(n<0) continue;
- if(n>=nmusic_files) break;
- if(m>=max_entry) break;
- PX=16;PY=88+8+2+m*20;
- color=0xffffffff;
- if(n==play_file)
- {
- DrawRoundFillBox(PX,PY-2, 38*16, 20, 0, 0xff004f00);
- //DrawRoundBox(PX,PY-2, 38*16, 20, 0, 2, 0xff30ffff);
- }
- if(mode!=0)
- if(n==select)
- {
- DrawRoundFillBox(PX,PY-2, 38*16, 20, 0, 0xff00004f);
- DrawRoundBox(PX,PY-2, 38*16, 20, 0, 2, 0xff30ffff);
- }
- s_printf("%s", (char *) get_name_short_fromUTF8(&music_files[n].name[0]));
- bkcolor=0;color=0xffffffff;
- m++;
- }
- if(osd_volume>0)
- {
- osd_volume--;
- SetTexture(MOSAIC_PATTERN);
- DrawBox(8,SCR_HEIGHT-16, 640-16, 16, 0, 2, 0xff00c000);
- SetTexture(MOSAIC_PATTERN);
- DrawFillBox(12,SCR_HEIGHT-16+4, (640-24)*volume/255, 8, 0, 0xff00c000);
- }
- wii_nKeys=wii_joystick_read(1);
- new_key=wii_nKeys & (~old_key);
- old_key=wii_nKeys;
- if(new_key & WII_HOME) break;
- if(old_key & WII_MINUS) {volume--;if(volume<0) volume=0;SetVolumeAudio(volume);osd_volume=60;}
- if(old_key & WII_PLUS) {volume++;if(volume>255) volume=255;SetVolumeAudio(volume);osd_volume=60;}
- if(!(old_key & (WII_UP | WII_DOWN))) f=0;
- if(old_key & WII_UP)
- {
- if(f==0) f=2;
- else if(f & 1) f=2;
- else {f+=2;if(f>40) {f=34;new_key|=WII_UP;}}
- }
- if(old_key & WII_DOWN)
- {
- if(f==0) f=1;
- else if(!(f & 1)) f=1;
- else {f+=2;if(f>41) {f=35;new_key|=WII_DOWN;}}
- }
- if(mode==0)
- {
- if(new_key & WII_LEFT) {select2--;if(select2<0) select2=8;}
- if(new_key & WII_RIGHT) {select2++;if(select2>8) select2=0;}
- if(new_key & WII_B)
- {
- if(music_playing)
- {
- n=StatusAudio();
- if(n==AUDIO_STATUS_RUNNING) PauseAudio(1);
- else if(n==AUDIO_STATUS_PAUSED) PauseAudio(0);
- }
- }
- if(new_key & WII_A)
- {
- if(select2==0) // getfiles
- {
- select_file(0);
- new_key=0;
- }
- else
- if(select2==1 && left_count==0) // <<
- {
- left_count=1;
- }
- else
- if(select2==2 && nmusic_files>0 && right_count==0) // play
- {
- if(music_playing)
- {
- n=StatusAudio();
- if(play_file==select && n==AUDIO_STATUS_PAUSED)
- {
- PauseAudio(0);
- }
- else {time_playing_old=0;music_playing=1;play_file=select;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0;}
- }
- else {time_playing_old=0;music_playing=1;play_file=select;if(PlayAudio(music_files[play_file].name, 0, 0)<0) music_playing=0;}
- }
- else
- if(select2==3) // pause
- {
- if(music_playing)
- {
- n=StatusAudio();
- if(n==AUDIO_STATUS_RUNNING) PauseAudio(1);
- else if(n==AUDIO_STATUS_PAUSED) PauseAudio(0);
- }
- }
- else
- if(select2==4) // stop
- {
- StopAudio();fast=0;music_playing=0;
- }
- else
- if(select2==5) // >>
- {
- right_count=1;
- }
- else
- if(select2==6) // shuffle
- {
- music_shuffle();
- }
- else
- if(select2==7) // loop
- {
- music_loop^=1;
- }
- else
- if(select2==8) // trash
- {
- nmusic_files=0;
- play_file=-1;
- }
- } // wii_a
- else
- if(old_key & WII_A)
- {
- if(select2==1) // <<
- {
- if(time_playing>0)
- 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);*/}
- left_count++;
- }
- if(select2==5) // >>
- {
- if(time_playing>0)
- 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);*/}
- right_count++;
- }
- }
- else // << >> liberado
- {
- if(fast)
- {
- fast=0;
- SetTimeAudio(time_playing_old*1000);PauseAudio(0);
- }
- if(left_count>=1 && left_count<40)
- {
- fast=0;
- play_file--;
- if(music_loop) if(play_file<0) play_file=nmusic_files-1;
- 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;}
- else {StopAudio();music_playing=0;play_file=-1;}
- }
- left_count=0;
- if(right_count>=1 && right_count<40)
- {
- fast=0;
- play_file++;
- if(music_loop) if(play_file>=nmusic_files) play_file=0;
- 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;}
- else {StopAudio();music_playing=0;play_file=-1;}
- }
- right_count=0;
- }
- }
- else
- if(mode==1)
- {
- if(new_key & WII_UP) {select--;if(select<0) select=nmusic_files-1;}
- if(new_key & WII_DOWN) {select++;if(select>=nmusic_files) select=0;}
- if(music_playing)
- {
- if(new_key & WII_RIGHT) right_count=1;
- else
- {
- if(old_key & WII_RIGHT)
- {
- if(time_playing>0)
- 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);*/}
- right_count++;
- }
- else
- {
- if(fast && right_count)
- {
- fast=0;
- SetTimeAudio(time_playing_old*1000);PauseAudio(0);
- }
- if(right_count>=1 && right_count<40)
- {
- fast=0;
- play_file++;
- if(music_loop) if(play_file>=nmusic_files) play_file=0;
- 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;}
- else {StopAudio();music_playing=0;play_file=-1;}
- }
- right_count=0;
- }
- }
- if(new_key & WII_LEFT) left_count=1;
- else
- {
- if(old_key & WII_LEFT)
- {
- if(time_playing>0)
- 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);*/}
- left_count++;
- }
- else
- {
- if(fast && left_count)
- {
- fast=0;
- SetTimeAudio(time_playing_old*1000);PauseAudio(0);
- }
- if(left_count>=1 && left_count<40)
- {
- play_file--;
- if(music_loop) if(play_file<0) play_file=nmusic_files-1;
- 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;}
- else {StopAudio();music_playing=0;play_file=-1;}
- }
- left_count=0;
- }
- }
- }
- if(new_key & WII_B)
- {
- if(music_playing)
- {
- n=StatusAudio();
- if(n==AUDIO_STATUS_RUNNING) PauseAudio(1);
- else if(n==AUDIO_STATUS_PAUSED) PauseAudio(0);
- }
- }
- if(new_key & WII_A)
- {
- if(fast)
- {
- fast=0;
- SetTimeAudio(time_playing_old*1000);PauseAudio(0);
- }
- if(music_playing)
- {
- n=StatusAudio();
- if(play_file==select && n==AUDIO_STATUS_PAUSED)
- {
- PauseAudio(0);
- }
- else
- if(play_file==select && n==AUDIO_STATUS_RUNNING)
- {
- StopAudio();music_playing=0;
- }
- 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;}
- }
- 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;}
- }
- } // mode==1
- if(mode==0 && nmusic_files>0)
- {
- if(new_key & (WII_ONE | WII_DOWN)) mode=1;
- if(new_key & WII_TWO)
- {if(fast)
- {
- fast=0;
- SetTimeAudio(time_playing_old*1000);PauseAudio(0);
- }
- music_gfx();
- }
- }
- else
- if(mode==1)
- {
- if(new_key & WII_ONE) mode=0;
- if(new_key & WII_TWO)
- {if(fast)
- {
- fast=0;
- SetTimeAudio(time_playing_old*1000);PauseAudio(0);
- }
- music_gfx();
- }//mode=1; // to do: mode=2 visual effects
- }
- Screen_flip();
- if(loop_music_playing()) {select=play_file;time_playing_old=0;}
- }
- if(fast)
- {
- fast=0;
- SetTimeAudio(time_playing_old*1000);PauseAudio(0);
- }
- Screen_flip();
- SetTexture(NULL);
- }
- void txt_player()
- {
- unsigned time1,time2;
- if(txt_file_len==0) return;
- time1=time2=ticks_to_msecs(gettick());
- while(1)
- {
- if(exit_by_reset) break;
- loop_music_playing();
- SetTexture(MOSAIC_PATTERN);
- DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff603000);
- wii_nKeys=wii_joystick_read(0);
- new_key=wii_nKeys & (~old_key);
- old_key=wii_nKeys;
- if(new_key & WII_HOME) break;
- time2=ticks_to_msecs(gettick());
- SelectFontTexture(1);
- if(time1>time2) time1=time2;
- if((time2-time1)>60000) text_main(128, new_key, old_key);
- else text_main(0, new_key, old_key);
- SelectFontTexture(0);
- Screen_flip();
- if((time2-time1)>60000) {write_cfg(path_txt_cfg);time1=time2=ticks_to_msecs(gettick());}
- if(new_key & WII_ONE) {Screen_flip();write_cfg(path_txt_cfg);music_player();time1=time2=ticks_to_msecs(gettick());}
- }
- Screen_flip();
- write_cfg(path_txt_cfg);
- }
- void exit_menu()
- {
- int n, m;
- int select=0;
- int loop=1;
- while(loop)
- {
- if(exit_by_reset) break;
- loop_music_playing();
- //SetTexture(CROSS_PATTERN);
- //DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff603000);
- animate_background();
- SetTexture(&icon_tex[icons_num_sprites-2]);
- DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff906000);
- sizeletter=1;
- autocenter=1;
- PX=0;PY=12;
- color=0xfff08020;
- SetTexture(NULL_PATTERN);
- DrawRoundBox(144,8, 640-256-32, 40, 0, 2, 0xfff08020);
- s_printf("WiiReader");
- color=0xffffffff;
- sizeletter=1;
- for(n=0;n<3;n++)
- {
- m=SCR_HEIGHT/2-110+n*110;//48+n*110+50+20;
- SetTexture(MOSAIC_PATTERN);
- DrawRoundFillBox(32,m-32, 640-64, 64, 0,0xff803000);
- SetTexture(NULL_PATTERN);
- if(n==select)
- DrawRoundBox(32,m-32, 640-64, 64, 0, 10, 0xff00f0f0);
- else
- DrawRoundBox(32,m-32, 640-64, 64, 0, 6, 0xfff08020);
- switch(n)
- {
- case 0:
- autocenter=1;
- PX=0;PY=m-16;
- if(return_reset==1)
- s_printf("Homebrew Channel");
- else
- s_printf("Reset");
- autocenter=0;break;
- case 1:
- autocenter=1;
- PX=0;PY=m-16;
- s_printf("Power Off");
- autocenter=0;break;
- case 2:
- autocenter=1;
- PX=0;PY=m-16;
- s_printf("Abort");
- autocenter=0;break;
- }
- }
- sizeletter=4;
- PX=24;PY=SCR_HEIGHT-24;color=0xffffffff;
- wii_nKeys=wii_joystick_read(1);
- new_key=wii_nKeys & (~old_key);
- old_key=wii_nKeys;
- if(new_key & WII_UP) {select--;if(select<0) select=2;}
- if(new_key & WII_DOWN) {select++;if(select>2) select=0;}
- Screen_flip();
- if(new_key & WII_A)
- {
- switch(select)
- {
- case 0:
- exit_by_reset=return_reset;
- exit(0);
- break;
- case 1:
- exit_by_reset=3;
- exit(0);
- break;
- case 2:
- loop=0;
- break;
- }
- }
- if(new_key & WII_B) break;
- }
- Screen_flip();
- SetTexture(NULL);
- }
- void main_menu()
- {
- int n,m;
- int last_menu=-1;
- static int select=0;
- while(1)
- {
- if(exit_by_reset) break;
- loop_music_playing();
- //SetTexture(CROSS_PATTERN);
- animate_background();
- SetTexture(&icon_tex[icons_num_sprites-2]);
- DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff906000);
- sizeletter=1;
- autocenter=1;
- PX=0;PY=12;
- color=0xfff08020;
- SetTexture(NULL_PATTERN);
- DrawRoundBox(144,8, 640-256-32, 40, 0, 2, 0xfff08020);
- s_printf("WiiReader");
- sizeletter=2;
- PX=0;PY=48+3*100+50+48;color=0xffffffff;
- s_printf("%s","\251 Francisco Muñoz 'Hermes' - v1.1");
- autocenter=0;
- sizeletter=1;
- for(n=0;n<4;n++)
- {
- m=48+n*100+50;
- SetTexture(MOSAIC_PATTERN);
- DrawRoundFillBox(32,m-32, 640-64, 64, 0,0xff803000);
- SetTexture(NULL_PATTERN);
- if(n==select)
- DrawRoundBox(32,m-32, 640-64, 64, 0, 10, 0xff00f0f0);
- else
- DrawRoundBox(32,m-32, 640-64, 64, 0, 6, 0xfff08020);
- switch(n)
- {
- case 0:
- autocenter=1;
- PX=0;PY=m-16;
- s_printf("JPEG Viewer");
- autocenter=0;break;
- case 1:
- autocenter=1;
- PX=0;PY=m-16;
- s_printf("Music Player");
- autocenter=0;break;
- case 2:
- autocenter=1;
- PX=0;PY=m-16;
- s_printf("TXT Reader");
- autocenter=0;break;
- case 3:
- autocenter=1;
- PX=0;PY=m-16;
- s_printf("Exit");
- autocenter=0;break;
- }
- }
- sizeletter=4;
- PX=24;PY=SCR_HEIGHT-24;color=0xffffffff;
- wii_nKeys=wii_joystick_read(1);
- new_key=wii_nKeys & (~old_key);
- old_key=wii_nKeys;
- if(new_key & WII_UP) {select--;if(select<0) select=3;}
- if(new_key & WII_DOWN) {select++;if(select>3) select=0;}
- Screen_flip();
- if(new_key & WII_B)
- {
- switch(last_menu)
- {
- case 0:
- last_menu=0;
- jpeg_player();
- break;
- case 1:
- last_menu=1;
- music_player();
- break;
- case 2:
- last_menu=2;
- txt_player();
- break;
- }
- }
- if(new_key & WII_A)
- {
- switch(select)
- {
- case 0:
- last_menu=0;
- select_file(1);
- jpeg_player();
- break;
- case 1:
- last_menu=1;
- music_player();
- break;
- case 2:
- last_menu=2;
- select_file(2);
- txt_player();
- break;
- case 3:
- exit_menu();
- break;
- }
- }
- }
- Screen_flip();
- SetTexture(NULL);
- }
- void credits()
- {
- int n;
- for(n=0;n<6*60;n++)
- {
- animate_background();
- SetTexture(&icon_tex[icons_num_sprites-2]);
- DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0xff906000);
- sizeletter=1;
- autocenter=1;
- PX=0;PY=12;
- color=0xfff08020;
- SetTexture(NULL_PATTERN);
- DrawRoundBox(144,8, 640-256-32, 40, 0, 2, 0xfff08020);
- s_printf("WiiReader");
- sizeletter=2;
- color=0xffffffff;
- PY=60;
- PX=0;s_printf("%s","\251 Francisco Muñoz 'Hermes' - v1.1");PY+=24;
- PX=0;s_printf("Under General Public License (GPL) Terms");PY+=60;
- color=0xff00ffff;
- PX=0;s_printf("This software is based in part on the");PY+=24;
- PX=0;s_printf("work of the Independent JPEG Group");PY+=24;
- PX=0;s_printf("Copyright (C) 1994-1998, Thomas G. Lane");PY+=32;
- PX=0;s_printf("Also based in libmpg123 copyrighted by ");PY+=24;
- PX=0;s_printf("Michael Hipp under LGPL 2.1");PY+=32;
- PX=0;s_printf("Also based in the 'Tremor' lib");PY+=24;
- PX=0;s_printf("Copyright (c) 2002, Xiph.org Foundation");PY+=32;
- PX=0;s_printf("Also based in libogc/DevkitPro");PY+=24;
- PX=0;s_printf("Copyright: Michael Wiedenbauer (shagkur)");PY+=24;
- PX=0;s_printf("and Dave Murphy (WinterMute)");PY+=32;
- PX=0;s_printf("Also based in unzip lib");PY+=24;
- PX=0;s_printf("Copyright (C) 1998 Gilles Vollant");
- autocenter=0;
- Screen_flip();
- }
- }
- int main(int argc, char *argv[])
- {
- int n;
- DIR *dir;
- return_reset=1;
- if(argc<1) return_reset=2;
- CONF_Init();
- is_16_9=CONF_GetAspectRatio();
- InitScreen();
- srand(gettick());
- //console_init(frameBuffer[0],20,20,screenMode->fbWidth,screenMode->xfbHeight,screenMode->fbWidth*VI_DISPLAY_PIX_SZ);
- SYS_SetResetCallback(reset_call); // esto es para que puedas salir al pulsar boton de RESET
- SYS_SetPowerCallback(power_call); // esto para apagar con power
- PAD_Init();
- WPAD_Init();
- WPAD_SetIdleTimeout(60*5); // 5 minutes
- //WPAD_SetVRes(WPAD_CHAN_ALL, 640, SCR_HEIGHT);
- THREAD_PRIORITY();
- ASND_Init(/*INIT_RATE_48000*/); // Initialize the Sound Lib
- ASND_Pause(0);
- ASND_PauseVoice(0, 0);
- atexit(fun_exit);
- VIDEO_WaitVSync();
- fatInit(8, false);
- sleep(2);
- fatInitDefault();
- have_device=0;
- {
- path_file[3]=48+3;
- path_txt_cfg[3]=48+3;
- for(n=0;n<5;n++)
- {
- dir = opendir(path_file);
- if (dir) {closedir(dir); have_device|=1;fatInitDefault();break;}
- usleep(200*1000);
- }
- path_file[3]=48+3;
- for(n=0;n<5;n++)
- {
- dir = opendir(path_file);
- if (dir) {closedir(dir); have_device|=2;fatInitDefault();break;}
- usleep(200*1000);
- }
- }
- current_device=0;
- if(have_device & 1) path_file[3]=48+3;
- else if(have_device & 2) {current_device=1; path_file[3]=48+4;}
- for(n=0;n<icons_num_sprites-2;n++)
- {
- CreateTexture(&icon_tex[n], TLUT_SRGB5A1, icons_sprites[n].ptr, icons_sprites[n].sx, icons_sprites[n].sy, 0);
- }
- credits();
- //sleep(1);
- jpeg_buf=memalign(32,1024*1024*4);
- sprintf(path_txt_cfg,"%sapps", path_file);
- if(have_device & 1)
- mkdir(path_txt_cfg, S_IREAD | S_IWRITE);
- //usleep(1000*500);
- sprintf(path_txt_cfg,"%sapps/wiireader", path_file);
- if(have_device & 1)
- mkdir(path_txt_cfg, S_IREAD | S_IWRITE);
- sprintf(path_txt_cfg,"%sapps/wiireader/textreader.cfg", path_file);
- usleep(1000*500);
- sprintf(path_cfg,"%sapps/wiireader/font.bin", path_file);
- {
- FILE *fp;
- fp=fopen(path_cfg,"r"); // lee el fichero de texto
- if(fp!=0)
- {
- n=fread(extern_char_set,1, 28672 ,fp);
- if(n==28672) {UploadFontTextureExt((void *) extern_char_set);}
- fclose(fp);
- }
- }
- sprintf(path_cfg,"%sapps/wiireader/wiireader.cfg", path_file);
- SetVolumeAudio(volume);
- main_menu();
- Screen_flip();
- StopAudio();
- return(0);
- }
- static GXTexObj gfx_tex;
- static u32 gfx_texture[256*128] ATTRIBUTE_ALIGN(32);
- static u32 gfx_buff[256*128] ATTRIBUTE_ALIGN(8);
- static void inline set_gfx_pix(u32 x,u32 y, u32 c)
- {
- if(x>=256 || y>=128) return;
- gfx_buff[(y<<8)+x]=c;
- }
- static u32 inline get_gfx_pix(u32 x,u32 y)
- {
- if(x>=256 || y>=128) return 0xff400040;
- return gfx_buff[(y<<8)+x];
- }
- static void line_gfx(int x1,int y1,int x2,int y2, unsigned color)
- {
- int n,m;
- int a,b,a2,b2;
- x2-=x1;
- y2-=y1;
- a2=x2;if(a2<0) {a2=-a2;x2=-1;} else x2=1;
- b2=y2;if(b2<0) {b2=-b2;y2=-1;} else y2=1;
- m=a2;if(b2>m) m=b2;
- a=0;b=0;
- for(n=0;n<m;n++)
- {
- set_gfx_pix(x1, y1, color);
- a+=a2;if(a>=m) {a-=m;x1+=x2;}
- b+=b2;if(b>=m) {b-=m;y1+=y2;}
- }
- }
- static void gfx_fun()
- {
- int n,m,s;
- int r,g,b;
- for(n=0;n<128;n++)
- {
- s=1;if(n>64) s=-1;
- for(m=0;m<256;m++)
- {
- register u32 color;
- color=get_gfx_pix(m,n);
- r=(color) & 255;
- g=(color>>8) & 255;
- b=(color>>16) & 255;
- color=get_gfx_pix(m,n-s);
- r+=(color) & 255;
- g+=(color>>8) & 255;
- b+=(color>>16) & 255;
- color=get_gfx_pix(m-1,n+s);
- r+=(color) & 255;
- g+=(color>>8) & 255;
- b+=(color>>16) & 255;
- color=get_gfx_pix(m+1,n+s);
- r+=(color) & 255;
- g+=(color>>8) & 255;
- b+=(color>>16) & 255;
- r>>=2;g>>=2;b>>=2;
- if(r<32 && g<32 && b<32) b=32;
- color=((0xff00+b)<<16) | (g<<8) | r;
- set_gfx_pix(m, n, color);
- }
- }
- }
- static void gfx_fun2()
- {
- int n,m,s;
- int r,g,b;
- for(n=0;n<128;n++)
- {
- s=1;//if(n>128) s=-1;
- for(m=0;m<256;m++)
- {
- register u32 color;
- color=get_gfx_pix(m,n);
- r=(color) & 255;
- g=(color>>8) & 255;
- b=(color>>16) & 255;
- color=get_gfx_pix(m,n-s);
- r+=(color) & 255;
- g+=(color>>8) & 255;
- b+=(color>>16) & 255;
- color=get_gfx_pix(m-1,n);
- r+=(color) & 255;
- g+=(color>>8) & 255;
- b+=(color>>16) & 255;
- color=get_gfx_pix(m+1,n);
- r+=(color) & 255;
- g+=(color>>8) & 255;
- b+=(color>>16) & 255;
- color=get_gfx_pix(m,n+s);
- r+=(color) & 255;
- g+=(color>>8) & 255;
- b+=(color>>16) & 255;
- r/=5;g/=5;b/=5;
- color=((0xff00+b)<<16) | (g<<8) | r;
- set_gfx_pix(m, n, color);
- }
- }
- }
- void music_gfx()
- {
- int n,m;
- short l,r,oldl=0,oldr=0;
- u16 *punt;
- int hahaha=0;
- memset(gfx_buff, 0, 256*256/2*4);
- memset(pcm_outsample,0,512*2);
- while(1)
- {
- if(exit_by_reset) break;
- wii_nKeys=wii_joystick_read(1);
- new_key=wii_nKeys & (~old_key);
- old_key=wii_nKeys;
- if(new_key & (WII_HOME | WII_ONE | WII_TWO | WII_A | WII_B)) break;
- for(n=0;n<256;n+=4)
- {
- l=(pcm_outsample[n<<1]>>10)+64;
- r=(pcm_outsample[(n<<1)+1]>>10)+64;
- if(hahaha & 128)
- {
- set_gfx_pix(n,l,0xff008fff);
- set_gfx_pix(n,r,0xff00ff8f);
- }
- else
- {
- line_gfx(n-4,oldl, n, l, 0xff008fff);
- line_gfx(n-4,oldr, n, r, 0xff008fff);
- }
- set_gfx_pix(n+2, -(l<<12), 0xff8f00ff+((l & 255)<<8));
- set_gfx_pix(n+2, -(r<<12), 0xffff008f+((r & 255)<<8));
- oldl=l;oldr=r;
- }
- for(n=0;n<256;n++)
- {
- l=(pcm_outsample[n<<1]>>10)+64;
- r=(pcm_outsample[(n<<1)+1]>>10)+64;
- line_gfx(n-1,128-oldl, n, 128-l, 0xff400000+(l<<1));
- line_gfx(n-1,128-oldr, n, 128-r, 0xffff0000+(r<<1));
- oldl=l;oldr=r;
- }
- hahaha++;
- if((hahaha & 0xffff)>3600)
- {
- if(hahaha>=(65536+3603)) hahaha=0;
- else
- if(hahaha>3605 && hahaha<65536) hahaha=65536+3500;
- punt= (u16 *) icons_sprites[icons_num_sprites-1].ptr;
- for(n=0;n<96;n++)
- for(m=0;m<128;m++)
- {
- if(punt[((n/3)<<5) | (m>>2)]==0x8000)
- set_gfx_pix(64+m, 16+n, 0xff000000);
- else if(punt[((n>>1)<<5) | (m>>2)])
- set_gfx_pix(64+m, 16+n, 0xffffffff);
- }
- }
- gfx_fun();
- for(n=0;n<256;n+=8)
- {
- l=(pcm_outsample[n<<1]>>10)+64;
- r=(pcm_outsample[(n<<1)+1]>>10)+64;
- line_gfx(n-8,oldl, n, l, 0xffff8f00+(l<<1));
- line_gfx(n-8,oldr, n, r, 0xffff008f+((127-r)<<9));
- oldl=l;oldr=r;
- }
- gfx_fun2();
- memcpy(gfx_texture,gfx_buff, 256*256/2*4);
- CreateTexture(&gfx_tex, TILE_SRGBA8, (void *) gfx_texture, 256, 256/2, 0);
- SetTexture(&gfx_tex);
- DrawFillBox(-40,-40, 640+80, SCR_HEIGHT+80, 0,0xffffffff);
- DrawFillBox(0,0, 640, SCR_HEIGHT, 0,0x80ffffff);
- Screen_flip();
- loop_music_playing();
- }
- Screen_flip();
- SetTexture(NULL);
- }
- /* end */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement