Genesis-Plus-GX/source/ngc/fileio/filesel.c

221 lines
5.9 KiB
C
Raw Normal View History

2008-12-11 18:38:29 +01:00
/*
* filesel.c
*
* File Selection menu
*
* code by Softdev (2006), Eke-Eke (2007,2008)
*
* 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.
2008-08-07 14:26:07 +02:00
*
2008-12-11 18:38:29 +01:00
* 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.
2008-08-07 14:26:07 +02:00
*
2008-12-11 18:38:29 +01:00
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
********************************************************************************/
2008-08-07 14:26:07 +02:00
#include "shared.h"
#include "font.h"
2008-12-11 18:38:29 +01:00
#include "file_dvd.h"
#include "file_fat.h"
2008-12-10 19:16:30 +01:00
#include "filesel.h"
/* Global Variables */
int maxfiles = 0;
int offset = 0;
int selection = 0;
int old_selection = 0;
int old_offset = 0;
int useFAT = 0;
int useHistory = 0;
int haveDVDdir = 0;
int haveFATdir = 0;
2008-12-11 18:38:29 +01:00
FILEENTRIES filelist[MAXFILES];
char rom_filename[MAXJOLIET];
2008-08-07 14:26:07 +02:00
/***************************************************************************
* ShowFiles
*
* Show filenames list in current directory
***************************************************************************/
static void ShowFiles (int offset, int selection)
{
int i, j;
char text[MAXJOLIET+2];
ClearScreen ();
j = 0;
for (i = offset; i < (offset + PAGESIZE) && (i < maxfiles); i++)
{
memset(text,0,MAXJOLIET+2);
if (filelist[i].flags) sprintf(text, "[%s]", filelist[i].filename + filelist[i].filename_offset);
else sprintf (text, "%s", filelist[i].filename + filelist[i].filename_offset);
2008-12-11 18:38:29 +01:00
if (j == (selection - offset)) WriteCentre_HL ((j * fheight) + PAGEOFFSET, text);
else WriteCentre ((j * fheight) + PAGEOFFSET, text);
2008-08-07 14:26:07 +02:00
j++;
}
SetScreen ();
}
/****************************************************************************
* FileSelector
*
* Let user select a file from the File listing
2008-12-11 18:38:29 +01:00
.* ROM file buffer is provided as input
* ROM size is returned
*
2008-08-07 14:26:07 +02:00
****************************************************************************/
2008-12-11 18:38:29 +01:00
int FileSelector(unsigned char *buffer)
2008-08-07 14:26:07 +02:00
{
short p;
int redraw = 1;
int go_up = 0;
2008-12-10 19:16:30 +01:00
int ret;
2008-08-07 14:26:07 +02:00
int i,size;
while (1)
2008-08-07 14:26:07 +02:00
{
if (redraw) ShowFiles (offset, selection);
redraw = 0;
p = ogc_input__getMenuButtons();
/* scroll displayed filename */
if (p & PAD_BUTTON_LEFT)
{
if (filelist[selection].filename_offset > 0)
{
filelist[selection].filename_offset --;
redraw = 1;
}
}
else if (p & PAD_BUTTON_RIGHT)
{
size = 0;
for (i=filelist[selection].filename_offset; i<strlen(filelist[selection].filename); i++)
size += font_size[(int)filelist[selection].filename[i]];
if (size > back_framewidth)
{
filelist[selection].filename_offset ++;
redraw = 1;
}
}
2008-08-07 14:26:07 +02:00
/* highlight next item */
else if (p & PAD_BUTTON_DOWN)
{
filelist[selection].filename_offset = 0;
selection++;
if (selection == maxfiles) selection = offset = 0;
if ((selection - offset) >= PAGESIZE) offset += PAGESIZE;
redraw = 1;
}
2008-08-07 14:26:07 +02:00
/* highlight previous item */
else if (p & PAD_BUTTON_UP)
{
filelist[selection].filename_offset = 0;
selection--;
if (selection < 0)
{
selection = maxfiles - 1;
offset = selection - PAGESIZE + 1;
}
if (selection < offset) offset -= PAGESIZE;
if (offset < 0) offset = 0;
redraw = 1;
}
2008-08-07 14:26:07 +02:00
/* go back one page */
else if (p & PAD_TRIGGER_L)
{
filelist[selection].filename_offset = 0;
selection -= PAGESIZE;
if (selection < 0)
{
selection = maxfiles - 1;
offset = selection - PAGESIZE + 1;
}
if (selection < offset) offset -= PAGESIZE;
if (offset < 0) offset = 0;
redraw = 1;
}
2008-08-07 14:26:07 +02:00
/* go forward one page */
else if (p & PAD_TRIGGER_R)
{
filelist[selection].filename_offset = 0;
selection += PAGESIZE;
if (selection > maxfiles - 1) selection = offset = 0;
if ((selection - offset) >= PAGESIZE) offset += PAGESIZE;
redraw = 1;
}
2008-08-07 14:26:07 +02:00
/* quit */
if (p & PAD_TRIGGER_Z)
{
filelist[selection].filename_offset = 0;
return 0;
2008-08-07 14:26:07 +02:00
}
2008-08-07 14:26:07 +02:00
/* open selected file or directory */
2008-12-10 19:16:30 +01:00
if ((p & PAD_BUTTON_A) || (p & PAD_BUTTON_B))
2008-08-07 14:26:07 +02:00
{
filelist[selection].filename_offset = 0;
2008-12-10 19:16:30 +01:00
go_up = 0;
if (p & PAD_BUTTON_B)
2008-08-07 14:26:07 +02:00
{
2008-12-10 19:16:30 +01:00
/* go up one directory or quit */
go_up = 1;
selection = useFAT ? 0 : 1;
2008-08-07 14:26:07 +02:00
}
2008-08-07 14:26:07 +02:00
/*** This is directory ***/
if (filelist[selection].flags)
{
2008-12-10 19:16:30 +01:00
/* get new directory */
2008-12-11 18:38:29 +01:00
if (useFAT) ret =FAT_UpdateDir(go_up);
else ret = DVD_UpdateDir(go_up);
2008-08-07 14:26:07 +02:00
2008-12-10 19:16:30 +01:00
/* get new entry list or quit */
2008-12-11 18:38:29 +01:00
if (ret)
{
if (useFAT) maxfiles = FAT_ParseDirectory();
else maxfiles = DVD_ParseDirectory();
}
2008-12-10 19:16:30 +01:00
else return 0;
2008-08-07 14:26:07 +02:00
}
2008-12-10 19:16:30 +01:00
/*** This is a file ***/
else
{
/* root directory ? */
if (go_up) return 0;
2008-12-10 19:16:30 +01:00
/* Load file */
if (useFAT) ret = FAT_LoadFile(buffer);
else ret = DVD_LoadFile(buffer);
if (ret)
{
/* get filename and remove extension */
sprintf(rom_filename,"%s", filelist[selection].filename);
rom_filename[strlen(rom_filename) - 5] = 0;
}
return ret;
}
2008-12-10 19:16:30 +01:00
redraw = 1;
2008-08-07 14:26:07 +02:00
}
}
}