File: INTERFAC.C | Size: 26,925 bytes | Download file | Back to directory listing | BWPOW's homepage
#include <unistd.h>
#include <conio.h>
#include <string.h>
#include <dir.h>
#include <allegro.h>
#include <tdgui.h>
#include "pp.h"
 
char tmp_cwd[512];
char cur_cwd[256];
 
char vis_on=1;
 
unsigned char siva,red;
 
unsigned char ww;
int tempbuff[4000];
int tempbuf1[4000];
struct ffblk f;
 
BITMAP *interpoz;
BITMAP *bmp;
 
typedef struct FILEZ{
//  char ext[6];
  char filename[256];
  char type,sel;
  unsigned long size;
  char ssize[6];
  unsigned char color;
}FILEZ;
 
FILEZ file[3000];
int num_file=0;
 
int sel_size=0;
 
static char *types[]={
"bmp", // allegro bitmap
"pcx", // allegro bitmap
"tga", // allegro bitmap
"lbm", // allegro bitmap
"jpg", // LibJPEG by Eric Vannier
 
"xm",  // MIDAS Sound System
"mod", // MIDAS Sound System
"s3m", // MIDAS Sound System
"sm1", // MIDAS Sound System
"wav", // allegro stream
"mid", // allegro midi
"mp3", // LAYER III player
 
"fli",
"flc",
 
"vga",
"bga",
"rle",
"dib",
"rl4",
"rl8",
"gif",
"tif",
"vst",
"afi",
"iff",
"vid",
"pgm",
"ppm",
"kps",
"iax",
"xbm",
"spr",
"pse",
 
"voc",
 
"m15",
"mod",
"mtm",
"stm",
"ult",
 
"san",
"jpe",
 
"aud",
 
"png",
"sp1",
NULL
};
 
 
 
 
 
char s_d=8,s_m=0;
int s_w=320,s_h=200;
 
typedef struct{
  int w,h;
  char d;
}RESS;
 
static RESS ress[]={
{ 320, 200, 8},{ 320, 240, 8},{ 400, 300, 8},{ 640, 400, 8},{ 640, 480, 8},
{ 800, 600, 8},{1024, 768, 8},{1280,1024, 8},{1600,1200, 8},
{ 320, 200,15},{ 320, 240,15},{ 400, 300,15},{ 640, 400,15},{ 640, 480,15},
{ 800, 600,15},{1024, 768,15},{1280,1024,15},{1600,1200,15},
{ 320, 200,16},{ 320, 240,16},{ 400, 300,16},{ 640, 400,16},{ 640, 480,16},
{ 800, 600,16},{1024, 768,16},{1280,1024,16},{1600,1200,16},
{ 320, 200,24},{ 320, 240,24},{ 400, 300,24},{ 640, 400,24},{ 640, 480,24},
{ 800, 600,24},{1024, 768,24},{1280,1024,24},{1600,1200,24},{NULL}
};
 
 
void make_res(int c)
{
  s_w=ress[c].w;
  s_h=ress[c].h;
  s_d=ress[c].d;
  s_m=c;
}
 
int res00(){make_res( 0);return 0;}
int res01(){make_res( 1);return 0;}
int res02(){make_res( 2);return 0;}
int res03(){make_res( 3);return 0;}
int res04(){make_res( 4);return 0;}
int res05(){make_res( 5);return 0;}
int res06(){make_res( 6);return 0;}
int res07(){make_res( 7);return 0;}
int res08(){make_res( 8);return 0;}
int res09(){make_res( 9);return 0;}
int res10(){make_res(10);return 0;}
int res11(){make_res(11);return 0;}
int res12(){make_res(12);return 0;}
int res13(){make_res(13);return 0;}
int res14(){make_res(14);return 0;}
int res15(){make_res(15);return 0;}
int res16(){make_res(16);return 0;}
int res17(){make_res(17);return 0;}
int res18(){make_res(18);return 0;}
int res19(){make_res(19);return 0;}
int res20(){make_res(20);return 0;}
int res21(){make_res(21);return 0;}
int res22(){make_res(22);return 0;}
int res23(){make_res(23);return 0;}
int res24(){make_res(24);return 0;}
int res25(){make_res(25);return 0;}
int res26(){make_res(26);return 0;}
int res27(){make_res(27);return 0;}
int res28(){make_res(28);return 0;}
int res29(){make_res(29);return 0;}
int res30(){make_res(30);return 0;}
int res31(){make_res(31);return 0;}
int res32(){make_res(32);return 0;}
int res33(){make_res(33);return 0;}
int res34(){make_res(34);return 0;}
int res35(){make_res(35);return 0;}
 
 
MENU the_resol8[]={
{" 320x 200 8bit",res00,0},
{" 320x 240 8bit",res01,0},
{" 400x 300 8bit",res02,0},
{" 640x 400 8bit",res03,0},
{" 640x 480 8bit",res04,0},
{" 800x 600 8bit",res05,0},
{"1024x 768 8bit",res06,0},
{"1280x1024 8bit",res07,0},
{"1600x1200 8bit",res08,0},
{NULL,0,0}
};
 
static MENU the_resol15[]={
{" 320x 200 15bit",res09,0},
{" 320x 240 15bit",res10,0},
{" 400x 300 15bit",res11,0},
{" 640x 400 15bit",res12,0},
{" 640x 480 15bit",res13,0},
{" 800x 600 15bit",res14,0},
{"1024x 768 15bit",res15,0},
{"1280x1024 15bit",res16,0},
{"1600x1200 15bit",res17,0},
{NULL,0,0}
};
 
static MENU the_resol16[]={
{" 320x 200 16bit",res18,0},
{" 320x 240 16bit",res19,0},
{" 400x 300 16bit",res20,0},
{" 640x 400 16bit",res21,0},
{" 640x 480 16bit",res22,0},
{" 800x 600 16bit",res23,0},
{"1024x 768 16bit",res24,0},
{"1280x1024 16bit",res25,0},
{"1600x1200 16bit",res26,0},
{NULL,0,0}
};
 
static MENU the_resol24[]={
{" 320x 200 24bit",res27,0},
{" 320x 240 24bit",res28,0},
{" 400x 300 24bit",res29,0},
{" 640x 400 24bit",res30,0},
{" 640x 480 24bit",res31,0},
{" 800x 600 24bit",res32,0},
{"1024x 768 24bit",res33,0},
{"1280x1024 24bit",res34,0},
{"1600x1200 24bit",res35,0},
{NULL,0,0}
};
 
 
static MENU the_resol[]={
{"8 bit",0,the_resol8},
{"15 bit",0,the_resol15},
{"16 bit",0,the_resol16},
{"24 bit",0,the_resol24},
{NULL,0,0}
};
 
int from_pict_make_gfx_mode()
{
  if(do_billmenu(the_resol,0,0)==-1) return 0;
  return 1;
}
 
 
void delete_this_gfx_mode()
{
  if(s_d==8) the_resol8[s_m].flags=D_DISABLED;
  if(s_d==15) the_resol15[s_m-9].flags=D_DISABLED;
  if(s_d==16) the_resol16[s_m-18].flags=D_DISABLED;
  if(s_d==24) the_resol24[s_m-27].flags=D_DISABLED;
  make_res(0);
}
 
int is_gfx_mode_disabled(int c)
{
  if(c<=8)  return the_resol8[c].flags;
  if(c<=17) return the_resol15[c-9].flags;
  if(c<=26) return the_resol16[c-18].flags;
  return the_resol24[c-27].flags;
}
 
 
void nahraj_config()
{
  int i;
  char tbuf[20];
 
  set_config_file("c://pp.ini");
 
  for(i=0;i<36;i++){
    sprintf(tbuf,"mode%02d",i);
    if(get_config_int("modes",tbuf,1)==0){
      make_res(i);
      delete_this_gfx_mode();
    }
  }
 
  s_m=get_config_int("screen","mode",0);
  make_res(s_m);
 
  if(vis_on==1)
    vis_on=get_config_int("interface","visualisation",1);
 
  if(get_config_int(0,"sb_freq",0)==0)
    set_config_int(0,"sb_freq",45454);
}
 
int inter_get_ext(char filename[256])
{
  int i;
  char ext[4];
  strcpy(ext,strlwr(get_extension(filename)));
  for(i=0;types[i];i++)
    if(strcmp(types[i],ext)==0) return i;
  return -1;
}
 
 
void uloz_config()
{
  int i;
  char tbuf[20];
  set_config_file("c://pp.ini");
  set_config_int("screen","mode",s_m);
 
  set_config_int("interface","visualisation",vis_on);
 
  for(i=0;i<36;i++){
    sprintf(tbuf,"mode%02d",i);
    if(is_gfx_mode_disabled(i)!=0)
      set_config_int("modes",tbuf,0);
    else
      set_config_int("modes",tbuf,1);
  }
 
  set_config_string("version","version","PACEPLAY 2.0.09b");
  set_config_string("version","info","IdeaZ 1999");
}
static char tm[4]={'k','M','G','T'};
 
void addfile()
{
  long size;
  char ext[6],i,e;
  if(num_file>=3000) return;
  if(f.ff_attrib&FA_DIREC)
  {
    if(strcmp(f.ff_name,".")!=0){
//      strcpy(file[num_file].filename,get_filename(f.ff_name));
      strcpy(file[num_file].filename,f.ff_name);
      file[num_file].color=10;
      if(f.ff_attrib&FA_HIDDEN) file[num_file].color=155;
      if(f.ff_attrib&FA_SYSTEM) file[num_file].color=siva;
//      strcpy(file[num_file].ext ,get_extension(f.ff_name));
      file[num_file].type=-1;
      file[num_file].sel=0;
      num_file++;
    }
  }
  else{
    strcpy(ext,strlwr(get_extension(f.ff_name)));
    e=-1;
    for(i=0;types[i];i++)
      if(strcmp(types[i],ext)==0) e=i;
    if(e==-1) return;
 
    file[num_file].color=0;
//    if(f.ff_attrib&FA_HIDDEN) file[num_file].color=155;
//    if(f.ff_attrib&FA_SYSTEM) file[num_file].color=siva;
//    if(f.ff_attrib&FA_RDONLY) file[num_file].color=red;
 
//    strcpy(file[num_file].ext,ext);
    strcpy(file[num_file].filename,f.ff_name);
    file[num_file].type=e;
    file[num_file].sel=0;
//    file[num_file].size=f.ff_fsize;
    file[num_file].size=f.ff_fsize;
    size=f.ff_fsize;
 
    i=0;
    while(size>0){
      if(size<=9999){
        if(i!=0) sprintf(file[num_file].ssize,"%4d%cB",size,tm[i-1]);
        else sprintf(file[num_file].ssize,"%5dB",size);
        break;
      }
      size/=1024;
      i++;
    }
 
    num_file++;
  }
}
 
int qsort_helper_by_size(const void *e1,const void *e2)
{
  if(strcmp(((FILEZ *)e1)->filename,"..")==0) return -1;
  if(((FILEZ *)e1)->type==-1&&((FILEZ *)e2)->type!=-1) return -1;
  if(((FILEZ *)e1)->type!=-1&&((FILEZ *)e2)->type==-1) return 1;
  return -strcasecmp(((FILEZ *)e2)->filename,((FILEZ *)e1)->filename);
}
 
 
static char *tps[]={
    "<DIRECTORY>",
    "Bitmap",
    "ZSoft pict",
    "TGA bitmap",
    "LBM bitmap",
    "JPEG",
    "XModule",
    "Module",
    "ST3 module",
    "SMK module",
    "Sound wave",
    "MIDI music",
    "LAYER 3",
    "VGA FLIC",
    "FLIC",
 
    "VGApicture",
    "BGApicture",
    "RLEpicture",
    "DIBpicture",
    "RL4picture",
    "RL8picture",
    "GIFpicture",
    "TIFpicture",
    "VSTpicture",
    "AFIpicture",
    "IFFpicture",
    "VIDpicture",
    "PGMpicture",
    "PPMpicture",
    "KPSpicture",
    "IAXpicture",
    "XBMpicture",
    "SPRITE",
    "PSEpicture",
 
    "VOC music",
    "M15 module",
    "MOD module",
    "MTM module",
    "STM module",
    "ULT module",
    "SAN movie",
    "JPEG",
    "AUD music",
    "PNGpicture",
    "SP1picture",
    NULL
};
 
char returntxt[80];
 
void copymem(char bufe[50],int wh)
{
  int i,l;
  l=strlen(bufe);
  for(i=0;i<l;i++)
    returntxt[i+wh]=bufe[i];
}
 
 
int file_getter(int index,char fileinfo[77])
{
   char tstr[20];
   if (index < 0) {
      return num_file;
   }
   else{
      memset(returntxt,32,75);
      copymem(file[index].filename,0);
      if(file[index].type!=-1){
//        sprintf(tstr,"%9ld",file[index].size);
        copymem(file[index].ssize,69);
      }
      copymem(tps[file[index].type+1],58);
      memcpy(fileinfo,returntxt,75);
   }
   fileinfo[75]=0;
}
 
int pd;
char disks[35];
char dstr[5];
 
char *diskbox_getter(int index, int *list_size)
{
   if (index < 0) {
      *list_size = pd;
      return NULL;
   }
   else{
     memset(dstr,32,5);
     sprintf(dstr,"%c:",disks[index]+'A');
     return ((char *)dstr);
   }
}
 
 
static DIALOG the_diskchange[] =
{
   /* (dialog proc)     (x)   (y)   (w)   (h)   (fg)  (bg)  (key) (flags)  (d1)  (d2)  (dp) */
   { d_billwin_proc,   260,  210,   120,  60,     0,  0,    0,     0,       0,    0,    "Change disk"},
   { d_billlist_proc,  265,  225,    40,  40,     0,  0,    0,D_EXIT,       0,    0,    diskbox_getter },
   { d_billbutton_proc,310,  225,    65,  15,     0,  0,    0,D_EXIT,       0,    0,    "OK"},
   { d_billbutton_proc,310,  245,    65,  15,     0,  0,    0,D_EXIT,       0,    0,    "Cancel"},
   { NULL }  //14
};
 
int change_disk()
{
  int i,r;
  pd=0;
 
  for(i=2;i<35;i++){
    setdisk(i);
    if(getdisk()==i){
      disks[pd]=i;
      pd++;
    }
  }
 
  r=moveable_do_dialog(the_diskchange,-1);
  if(r==-1) return 0;
  if(r==3) return 0;
 
  setdisk(the_diskchange[1].d1+2);
  return 1;
}
 
int interfac_convert(int num_o)
{
  int cnv=0,unc=0,err=0,i,t=0,n=0;
  char r;
 
  r=cnvrt_tabulka();
  if(r==-1) return 0;
  t=r;
 
  for(i=0;i<num_o;i++){
    while(file[n].sel!=1) n++;
    if(file[n].type>=0){
      r=convert(file[n].filename,file[n].type,t);
      if(r==-1) err++;
      if(r==0) cnv++;
      if(r==1) unc++;
 
    }
    else unc++;
    n++;
  }
 
  cnvrt_draw_koniec(cnv,unc,err);
  if(cnv>0) return 1;
  return 0;
}
 
int interfac_copy(int num_o)
{
  int i,n=0;
  char r;
 
  r=cpy_dest();
  if(r==-1) return 0;
 
  for(i=0;i<num_o;i++){
    while(file[n].sel!=1) n++;
    if(file[n].type>=0){
      r=cpy_copy(file[n].filename);
      if(r==-1) billalert("ERROR","Can't open file",file[n].filename,"&OK",0,'o',0);
      if(r==-2) billalert("ERROR","Can't write file",file[n].filename,"&OK",0,'o',0);
      if(r==-3) billalert("ERROR","Can't read from file",file[n].filename,"&OK",0,'o',0);
      if(r==-4) billalert("ERROR","Can't write to file",file[n].filename,"&OK",0,'o',0);
    }
    n++;
  }
 
  return 1;
}
 
void init_interface()
{
  int x,y;
  text_mode(-1);
 
  clear_to_color(interpoz,makecol(50,50,50));
  if(vis_on==1)
    for(x=0;x<5000;x++){
      y=random()%50+40;
      line(interpoz,random()%740-50,random()%580-50,
                    random()%740-50,random()%580-50,makecol(y,y,y));
    }
 
  tdbox1(interpoz,15,70,610,400,6);
  // 47 riadkov
  tdbox1(interpoz,17,73,606,380,5);
 
 
  blit(data_pp,interpoz,0,0,420,7,205,55);
  tdbox1(interpoz,420,6,205,56,2);
 
  tdbox1(interpoz,171, 6,75,26,6);
  tdbox1(interpoz,171,36,75,26,6);
 
  tdbox1(interpoz,255, 6,75,26,6);
  tdbox1(interpoz,255,36,75,26,6);
 
  tdbox1(interpoz,339, 6,75,26,6);
  tdbox1(interpoz,339,36,75,26,6);
 
  textout_centre(interpoz,font,"VIEW",170+37,15,100);
  textout_centre(interpoz,font,"VIEW",171+37,16,0);
 
  textout_centre(interpoz,font,"CONVERT",171+36,45,100);
  textout_centre(interpoz,font,"CONVERT",171+37,46,0);
 
  textout_centre(interpoz,font,"TOOLS",255+36,15,100);
  textout_centre(interpoz,font,"TOOLS",255+37,16,0);
 
  textout_centre(interpoz,font,"COPY",255+36,45,100);
  textout_centre(interpoz,font,"COPY",255+37,46,0);
 
  textout_centre(interpoz,font,"SYSTEM",339+36,15,100);
  textout_centre(interpoz,font,"SYSTEM",339+37,16,0);
 
  textout_centre(interpoz,font,"EXIT",339+36,45,100);
  textout_centre(interpoz,font,"EXIT",339+37,46,0);
 
  tdbox1(interpoz,15,6,150,26,6);
  tdbox1(interpoz,15,36,150,26,6);
 
  textout_centre(interpoz,font,"CHANGE DISK",89,15,100);
  textout_centre(interpoz,font,"CHANGE DISK",90,16,0);
}
 
int inter_x=0,inter_f=0,inter_sel=0;
 
#define PATH_MAX 1024
 
void make_cur_cwd()
{
  char *tok,*bp=getcwd(0,PATH_MAX);
  for (tok=strtok(bp,":\\/");tok;tok=strtok(0,":\\/"))
    if(tok!=0) strcpy(cur_cwd,strlwr(tok));
}
 
char _bt=0;
void press_button(int c)
{
/*
  if(c==-1&&_bt==1){
    _bt=0;
    tdbox1(interpoz,15,6,150,26,2);
    tdbox1(interpoz,15,36,150,26,2);
 
    tdbox1(interpoz,171, 6,75,26,2);
    tdbox1(interpoz,171,36,75,26,2);
 
    tdbox1(interpoz,255, 6,75,26,2);
    tdbox1(interpoz,255,36,75,26,2);
 
    tdbox1(interpoz,339, 6,75,26,2);
    tdbox1(interpoz,339,36,75,26,2);
 
    tdbox1(interpoz,420,6,205,56,2);
    return;
  }
*/
//  if(c>=0) _bt=1;
  show_mouse(0);
  if(c==0) tdbox1(screen,15,6,150,26,1);
  if(c==1) tdbox1(screen,15,36,150,26,1);
  if(c==2) tdbox1(screen,171, 6,75,26,1);
  if(c==3) tdbox1(screen,171,36,75,26,1);
  if(c==4) tdbox1(screen,255, 6,75,26,1);
  if(c==5) tdbox1(screen,255,36,75,26,1);
  if(c==6) tdbox1(screen,339, 6,75,26,1);
  if(c==7) tdbox1(screen,339,36,75,26,1);
  if(c==8) tdbox1(screen,420,6,205,56,1);
  show_mouse(screen);
  delay(100);
 
}
 
char *_npp_getter(int index,int *list_size)
{
  if(index<0){
    short i;
    for(i=1;tps[i];i++);
    *list_size=i-1;
    return NULL;
  }
  return tps[index+1];
}
 
static DIALOG na_plus_pad[] =
{
   /* (dialog proc)     (x)   (y)   (w)   (h)   (fg)  (bg)  (key) (flags)  (d1)  (d2)  (dp) */
   { d_billwin_proc,   220,  180,   200, 180,     0,  0,    0,     0,       0,    0,    "FILES TO SELECT"},
 
   { d_billbutton_proc,230,  340,    80,  15,     0,  0,    0,D_EXIT,       0,    0,    "OK"},
   { d_billbutton_proc,330,  340,    80,  15,     0,  0,    0,D_EXIT,       0,    0,    "Cancel"},
 
   { d_billlist_proc,  230,  210,   180, 125,     0,  0,    0,     0,       0,    0,    _npp_getter},
   { d_billtext_proc,  230,  200,    80,  90,     0,  0,    0,     0,       0,    0,    "File type"},
 
   { NULL }  //14
};
 
static DIALOG na_minus_pad[] =
{
   /* (dialog proc)     (x)   (y)   (w)   (h)   (fg)  (bg)  (key) (flags)  (d1)  (d2)  (dp) */
   { d_billwin_proc,   220,  180,   200, 180,     0,  0,    0,     0,       0,    0,    "FILES TO UNSELECT"},
 
   { d_billbutton_proc,230,  340,    80,  15,     0,  0,    0,D_EXIT,       0,    0,    "OK"},
   { d_billbutton_proc,330,  340,    80,  15,     0,  0,    0,D_EXIT,       0,    0,    "Cancel"},
 
   { d_billlist_proc,  230,  210,   180, 125,     0,  0,    0,     0,       0,    0,    _npp_getter},
   { d_billtext_proc,  230,  200,    80,  90,     0,  0,    0,     0,       0,    0,    "File type"},
 
   { NULL }  //14
};
 
 
int oznac_vsetky(short type,int osel)
{
  int sel,i;
 
  sel=osel;
 
  for(i=0;i<num_file;i++)
    if(file[i].sel==0&&file[i].type==type){
      sel_size+=file[i].size;
      sel++;
      file[i].sel=1;
    }
  return sel;
}
 
int odznac_vsetky(short type,int osel)
{
  int sel,i;
 
  sel=osel;
 
  for(i=0;i<num_file;i++)
    if(file[i].sel==1&&file[i].type==type){
      sel_size-=file[i].size;
      sel--;
      file[i].sel=0;
    }
  return sel;
}
 
 
 
int the_interface()
{
  char c=2,k=0;
  int x=0,f=0,sel=inter_sel,i,mx,my;
  char tbuf[80];
  char mouse_pres=0;
 
  x=inter_x;
  f=inter_f;
 
  while(k!=1){
    if(c==2){
      text_mode(-1);
      tdbox1(interpoz,15,36,150,26,6);
      sprintf(tbuf,"%dx%d %dbit",s_w,s_h,s_d);
      textout_centre(interpoz,font,tbuf,89,45,100);
      textout_centre(interpoz,font,tbuf,90,46,0);
      c=1;
    }
    if(c==1){
      memcpy(bmp->dat,interpoz->dat,307200); // prekopcenie bufra
 
//      press_button(-1);
 
      inter_x=x;
      inter_f=f;
      inter_sel=sel;
 
      for(i=0;i<47;i++){
        if(i+f>=num_file) break;
        if(x==i) rectfill(bmp,19,75+i*8,621,82+i*8,200);
 
 
        file_getter(i+f,tbuf);
        if(file[i+f].sel==0)
          textout(bmp,font,tbuf,20,75+i*8,file[i+f].color);
        else
          textout(bmp,font,tbuf,20,75+i*8,255);
      }
 
      if(sel>0){
        sprintf(tbuf,"%d file(s) selected - %d bytes",sel,sel_size);
        textout(bmp,font,tbuf,19,457,0);
        textout(bmp,font,tbuf,20,458,ww);
      }
      else{
        textout(bmp,font,file[x+f].filename,19,457,100);
        textout(bmp,font,file[x+f].filename,20,458,0);
      }
 
      show_mouse(0);
      blit(bmp,screen,0,0,0,0,640,480);
//      save_pcx("pp.pcx",bmp,data_pal);
      show_mouse(screen);
      c=0;
      clear_keybuf();
 
    }
    if(mouse_b) mouse_pres=1;
    else mouse_pres=0;
 
    i=0;
    if(key[KEY_DOWN]) i=1;
    if(key[KEY_UP]) i=2;
 
    if(key[KEY_END]) i=3;
    if(key[KEY_HOME]){x=0;c=1;f=0;}
 
    if(key[KEY_PGUP]) i=5;
    if(key[KEY_PGDN]) i=4;
 
 
    /* MENU KEYS */
    if(key[KEY_F1]){
      press_button(8);
      about_it();
      c=1;
    }
    if(key[KEY_F2]){
      press_button(3);
      c=0;
      if(sel==0){sel=1;file[f+x].sel=1;c=1;}
      if(interfac_convert(sel)==1) return -3;
      if(c==1){sel=0;file[f+x].sel=0;}
      c=1;
    }
    if(key[KEY_F4]){
      c=0;
      press_button(5);
      if(sel==0){sel=1;file[f+x].sel=1;c=1;}
      if(interfac_copy(sel)==1) return -3;
      if(c==1){sel=0;file[f+x].sel=0;}
      c=1;
    }
    if(key[KEY_F5]){
      press_button(6);
      sstn_system();
      c=1;
    }
 
    if(key[KEY_PLUS_PAD]){
      if(moveable_do_dialog(na_plus_pad,-1)==1){
        sel=oznac_vsetky(na_plus_pad[3].d1,sel);
        c=1;
      }
    }
 
    if(key[KEY_MINUS_PAD]){
      if(moveable_do_dialog(na_minus_pad,-1)==1){
        sel=odznac_vsetky(na_minus_pad[3].d1,sel);
        c=1;
      }
    }
 
 
 
    if(key[KEY_ASTERISK]){
      press_button(1);
      do_billmenu(the_resol,65,62);
      clear_keybuf();
      text_mode(-1);
      c=2;
    }
 
    if(key[KEY_ENTER]) return f+x;
    if(key[KEY_TAB]){
      press_button(0);
      return -2;
    }
 
    if(key[KEY_INSERT]){
      file[x+f].sel=!file[x+f].sel;
      if(file[x+f].sel==1){
        sel++;
        sel_size+=file[x+f].size;
      }
      else{
        sel--;
        sel_size-=file[x+f].size;
      }
      i=1;
    }
 
 
    if(i==1){ // down
      x++;
      if(x>=47){
        f++;
        if(f+x>=num_file) f--;
        x=46;
      }
      else
        if(f+x>=num_file) x--;
      c=1;
    }
 
    if(i==2){ // up
      x--;
      if(x<0){
        f--;
        if(f<0) f++;
        x=0;
      }
      c=1;
    }
 
    if(i==3){ // end
      x=0;f=0;
      for(i=0;i<num_file;i++){
        x++;
        if(x>=47){
          f++;
          if(f+x>=num_file) f--;
          x=46;
        }
        else
          if(f+x>=num_file) x--;
      }
      c=1;i=0;
    }
 
    if(i==4){ // pagedown
      for(i=0;i<47;i++){
        x++;
        if(x>=47){
          f++;
          if(f+x>=num_file) f--;
          x=46;
        }
        else
          if(f+x>=num_file) x--;
      }
      c=1;i=0;
    }
 
    if(i==5){ // pageup
      for(i=0;i<47;i++){
        x--;
        if(x<0){
          f--;
          if(f<0) f++;
          x=0;
        }
      }
      c=1;i=0;
    }
 
 
 
    /* MOUSE */
    if(mouse_b){
      mx=mouse_x;my=mouse_y;
 
      if(mx>17&&mx<623&&my>75&&my<452&&mouse_b==1&&mouse_pres==0){
        i=(my-75)/8;
        if(i>=num_file)
          x=num_file-1;
        else{
          if(x==i) return f+x;
          x=i;
        }
        c=1;
      }
 
      if(mx>17&&mx<623&&my>75&&my<452&&mouse_b==2){
        i=(my-75)/8;
        if((mouse_pres==1&&i!=x)||(mouse_pres==0)){
          if(i>=num_file)
            x=num_file-1;
          else{
            x=i;
            file[x+f].sel=!file[x+f].sel;
            if(file[x+f].sel==1) sel++;
            else sel--;
          }
          c=1;
        }
      }
/*
  tdbox1(interpoz,15,6,150,26,6);
  tdbox1(interpoz,15,36,150,26,6);
*/
      if(mx>420&&mx<625&&my>6&&my<72){
        press_button(8);
        about_it();
        c=1;
      }
 
      if(mx>171&&mx<246&&my>6&&my<32){
        press_button(2);
        return f+x;
      }
      if(mx>171&&mx<246&&my>36&&my<62){ // convert
        press_button(3);
        c=0;
        if(sel==0){sel=1;file[f+x].sel=1;c=1;}
        if(interfac_convert(sel)==1) return -3;
        if(c==1){sel=0;file[f+x].sel=0;}
        c=1;
      }
 
      if(mx>255&&mx<330&&my>6&&my<32){
        press_button(4);
        billalert("EDIT","Not enough memory!",0,"&OK",0,'o',0);
        billalert("FUN","You have enough memory, but","I haven't made it, yet.","&OK",0,'o',0);
        c=1;
      }
 
      if(mx>255&&mx<330&&my>36&&my<62){ // copy
        c=0;
        press_button(5);
        if(sel==0){sel=1;file[f+x].sel=1;c=1;}
        if(interfac_copy(sel)==1) return -3;
        if(c==1){sel=0;file[f+x].sel=0;}
        c=1;
      }
 
      if(mx>339&&mx<414&&my>6&&my<32){
        press_button(6);
        sstn_system();
        c=1;
      }
 
      if(mx>339&&mx<414&&my>36&&my<62){
        press_button(7);
        return -1;
      }
 
      if(mx>15&&mx<165&&my>6&&my<32){
        press_button(0);
        return -2;
      }
 
      if(mx>15&&mx<165&&my>36&&my<62){
        press_button(1);
        while(mouse_b);
        do_billmenu(the_resol,65,62);
        clear_keybuf();
        text_mode(-1);
        c=2;
      }
 
 
    }
 
 
    if(key[KEY_ESC]) return -1;
  }
  return -1;
}
 
 
int select_file()
{
  int k=0,c=1;
  int h=0,f=0,i;
  char r;
  PALETTE pal;
 
  for(;;){
    i=the_interface();
    if(i==-1) return -1;
    if(i==-2){
      if(change_disk()==1) return 0;
    }
    if(i==-3) return 0;
    if(i>=0){
      c=i;
      if(file[c].type==-1){
        if(!strcmp(file[c].filename,"..")){
          make_cur_cwd();
          chdir(dirname(getcwd(0,PATH_MAX)));
          return 1;
        }
        else{
          chdir(file[c].filename);
        }
        return 0;
      }
      else{
        r=1;
        while(r>0){
          k=file[c].type;
          if(k==-1) break;
          r=-1;
          if(k>=0&&k<=3)   r=paceplay_view(0,s_d,s_w,s_h,file[c].filename);
          if(k==4)         r=paceplay_view(1,s_d,s_w,s_h,file[c].filename);
 
          if(k>=12&&k<=13) r=paceplay_view(2,s_d,s_w,s_h,file[c].filename);
          if(k>=14&&k<=32) r=paceplay_view(3,s_d,s_w,s_h,file[c].filename);
 
          if(k==10)        paceplay_play(0,file[c].filename,bmp);
          if(k==9)         paceplay_play(1,file[c].filename,bmp);
          if(k==33)        paceplay_play(1,file[c].filename,bmp);
          if(k==11)        paceplay_play(2,file[c].filename,bmp);
 
          if(k>=5&&k<=8)   paceplay_play(3,file[c].filename,bmp);
          if(k>=34&&k<=38) paceplay_play(3,file[c].filename,bmp);
          if(k==39)        r=paceplay_view(4,s_d,s_w,s_h,file[c].filename);
          if(k==40)        r=paceplay_view(1,s_d,s_w,s_h,file[c].filename);
          if(k==41)        paceplay_play(5,file[c].filename,bmp);
          if(k==42)        r=paceplay_view(5,s_d,s_w,s_h,file[c].filename);
          if(k==43)        r=paceplay_view(6,s_d,s_w,s_h,file[c].filename);
 
          if(r==3){
            file[inter_x+inter_f].sel=!file[inter_x+inter_f].sel;
            if(file[inter_x+inter_f].sel==1) inter_sel++;
            else inter_sel--;
            r=1;
          }
 
 
          if(r==1){ // down
            inter_x++;
            if(inter_x>=47){
              inter_f++;
              if(inter_f+inter_x>=num_file){inter_f--;r=-2;}
              inter_x=46;
            }
            else
              if(inter_f+inter_x>=num_file){inter_x--;r=-2;}
          }
 
          if(r==2){ // up
            inter_x--;
            if(inter_x<0){
              inter_f--;
              if(inter_f<0){inter_f++;r=-2;}
              inter_x=0;
            }
          }
          c=inter_x+inter_f;
        } //while(r!=-2){
        default_gfx();
 
 
      }
 
    }
  }
}
 
void interface()
{
  char k,done,int_dir[800];
  ww=100;
 
  siva=makecol(150,150,150);
  red=makecol(150,0,0);
 
  interpoz=create_bitmap(640,480);
  bmp=create_bitmap(640,480);
  nahraj_config();
  init_interface();
  init_player(); // init player bitmaps
 
 
  k=0;
  while(k!=-1){
    inter_x=0;inter_f=0;
    inter_sel=0;
    num_file=0;
 
    strcpy(int_dir,getcwd(0,800));
    strcat(int_dir,"/*.*");
    done=findfirst(int_dir,&f,FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH|FA_DIREC);
    while (!done){
      addfile();
      done = findnext(&f);
    }
    qsort(file, num_file, sizeof(FILEZ), qsort_helper_by_size);
 
    if(k==1){
      while(strcasecmp(file[inter_x+inter_f].filename,cur_cwd)!=0){
        if(file[inter_x+inter_f].type!=-1) break;
        inter_x++;
        if(inter_x>=47){
          inter_f++;
          if(inter_f+inter_x>=num_file) inter_f--;
          inter_x=46;
        }
        else
          if(inter_f+inter_x>=num_file) inter_x--;
 
        if(inter_f+inter_x>=num_file){
          inter_x=0;inter_f=0;
          break;
        }
      }
    }
 
    k=select_file();
    clear_keybuf();
 
  }
  uloz_config();
}