NeoGeo: remove fixed path, support for subfolders.

This commit is contained in:
sorgelig
2019-07-29 04:04:44 +08:00
parent 48c7d7b28c
commit ca2fbe5b7a
5 changed files with 117 additions and 110 deletions

View File

@@ -598,8 +598,7 @@ int FileLoadConfig(const char *name, void *pBuffer, int size)
int FileExists(const char *name)
{
sprintf(full_path, "%s/%s", getRootDir(), name);
return !access(full_path, F_OK);
return !access(make_fullpath(name), F_OK);
}
int FileCanWrite(const char *name)
@@ -950,32 +949,20 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons
if (mode == SCANF_INIT)
{
file_name[0] = 0;
if (options & SCANO_NEOGEO)
if (options & SCANO_NEOGEO) neogeo_scan_xml();
if ((options & SCANO_NOENTER) || !isPathDirectory(path))
{
neogeo_scan_xml();
uint32_t len = strlen(HomeDir);
if (strlen(path) > len)
char *p = strrchr(path, '/');
if (p)
{
path[len] = 0;
strcpy(file_name, path + len + 1);
strcpy(file_name, p + 1);
*p = 0;
}
}
else
{
if (!isPathDirectory(path))
else
{
bool isfile = isPathRegularFile(path);
char *p = strrchr(path, '/');
if (p)
{
if (isfile) strcpy(file_name, p + 1);
*p = 0;
}
else
{
if (isfile) strcpy(file_name, path);
path[0] = 0;
}
strcpy(file_name, path);
path[0] = 0;
}
}
@@ -989,6 +976,7 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons
int path_len = strlen(full_path);
printf("Start to scan %sdir: %s\n", is_zipped ? "zipped " : "", full_path);
printf("Position on item: %s\n", file_name);
char *zip_path, *file_path_in_zip = (char*)"";
FileIsZipped(full_path, &zip_path, &file_path_in_zip);
@@ -1076,17 +1064,23 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons
{
if (de->d_type != DT_DIR) continue;
if (!strcmp(de->d_name, ".")) continue;
if (!strcmp(de->d_name, "..")) continue;
if (!strcmp(de->d_name, ".."))
{
if (!strlen(path)) continue;
}
direntext_t dext = { *de, 0, "" };
memcpy(dext.altname, de->d_name, sizeof(dext.altname));
full_path[path_len] = 0;
char *altname = neogeo_get_altname(full_path, de->d_name);
if (altname)
{
direntext_t dext = { *de, 0, "" };
dext.de.d_type = DT_REG;
memcpy(dext.altname, altname, sizeof(dext.altname));
DirItem.push_back(dext);
}
DirItem.push_back(dext);
}
else
{

View File

@@ -49,6 +49,7 @@ direntext_t* flist_SelectedItem();
#define SCANO_CORES 4 // only include subdirectories with prefix '_'
#define SCANO_COEFF 8
#define SCANO_NEOGEO 16
#define SCANO_NOENTER 32
void FindStorage();
int getStorage(int from_setting);

View File

@@ -325,9 +325,10 @@ static void SelectFile(const char* pFileExt, unsigned char Options, unsigned cha
{
pFileExt = "TXT";
}
else
else if (strncasecmp(HomeDir, SelectedPath, strlen(HomeDir)))
{
if (strncasecmp(HomeDir, SelectedPath, strlen(HomeDir))) strcpy(SelectedPath, HomeDir);
Options &= ~SCANO_NOENTER;
strcpy(SelectedPath, HomeDir);
}
ScanDirectory(SelectedPath, SCANF_INIT, pFileExt, Options);
@@ -341,7 +342,7 @@ static void SelectFile(const char* pFileExt, unsigned char Options, unsigned cha
strcpy(fs_pFileExt, pFileExt);
fs_ExtLen = strlen(fs_pFileExt);
fs_Options = Options;
fs_Options = Options & ~SCANO_NOENTER;
fs_MenuSelect = MenuSelect;
fs_MenuCancel = MenuCancel;
@@ -1504,7 +1505,7 @@ void HandleUI(void)
if (p[idx] >= '0' && p[idx] <= '9') ioctl_index = p[idx] - '0';
substrcpy(ext, p, 1);
while (strlen(ext) % 3) strcat(ext, " ");
SelectFile(ext, SCANO_DIR | (is_neogeo_core() ? SCANO_NEOGEO : 0), MENU_8BIT_MAIN_FILE_SELECTED, MENU_8BIT_MAIN1);
SelectFile(ext, SCANO_DIR | (is_neogeo_core() ? SCANO_NEOGEO | SCANO_NOENTER : 0), MENU_8BIT_MAIN_FILE_SELECTED, MENU_8BIT_MAIN1);
}
else if (p[0] == 'S')
{

View File

@@ -12,7 +12,6 @@
#include "../../osd.h"
#include "../../menu.h"
bool checked_ok;
static char pchar[] = { 0x8C, 0x8E, 0x8F, 0x90, 0x91, 0x7F };
static void neogeo_osd_progress(const char* name, unsigned int progress)
{
@@ -36,32 +35,23 @@ static void neogeo_osd_progress(const char* name, unsigned int progress)
Info(progress_buf);
}
int neogeo_file_tx(const char* romset, const char* name, unsigned char neo_file_type, unsigned char index, unsigned long offset, unsigned long size)
static int neogeo_file_tx(const char* path, const char* name, unsigned char neo_file_type, unsigned char index, unsigned long offset, unsigned long size)
{
fileTYPE f = {};
uint8_t buf[4096]; // Same in user_io_file_tx
uint8_t buf_out[4096];
static char name_buf[256];
static char name_buf[1024];
struct timespec ts1, ts2; // DEBUG PROFILING
long us_acc = 0; // DEBUG PROFILING
strcpy(name_buf, getRootDir());
strcpy(name_buf, "/NeoGeo/");
if (strlen(romset)) {
strcat(name_buf, romset);
strcat(name_buf, "/");
}
strcat(name_buf, name);
sprintf(name_buf, "%s/%s", path, name);
if (!FileOpen(&f, name_buf, 0)) return 0;
if (!size && offset < f.size) size = f.size - offset;
if (!size) return 0;
unsigned long bytes2send = size;
FileSeek(&f, offset, SEEK_SET);
printf("Loading %s (offset %lu, size %lu, type %u) with index %u\n", name, offset, bytes2send, neo_file_type, index);
// Put pairs of bitplanes in the correct order for the core
@@ -228,11 +218,10 @@ static int xml_get_altname(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, c
return true;
}
int neogeo_scan_xml()
{
static char full_path[1024];
sprintf(full_path, "%s/neogeo/romsets.xml", getRootDir());
sprintf(full_path, "%s/%s/romsets.xml", getRootDir(), HomeDir);
SAX_Callbacks sax;
SAX_Callbacks_init(&sax);
@@ -270,41 +259,56 @@ char *neogeo_get_altname(char *path, char *name)
return NULL;
}
static int checked_ok;
static int romsets = 0;
static int xml_check_files(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, const int n, SAX_Data* sd)
{
const char* romset = (const char*)sd->user;
static int in_correct_romset = 0;
static char full_path[256];
static char full_path[1024];
const char* path = (const char*)sd->user;
if (!path) return 0;
const char* romset = strrchr(path, '/');
if (!romset) return 0;
romset++;
switch (evt)
{
case XML_EVENT_START_NODE:
if (!strcasecmp(node->tag, "romsets")) romsets = 1;
if (!strcasecmp(node->tag, "romset")) {
if (!romsets) {
if (!strcasecmp(node->tag, "romset"))
{
if (!romsets)
{
in_correct_romset = 1;
}
else if (!strcasecmp(node->attributes[0].value, romset)) {
else if (!strcasecmp(node->attributes[0].value, romset))
{
printf("Romset %s found !\n", romset);
in_correct_romset = 1;
}
else {
else
{
in_correct_romset = 0;
}
}
if (in_correct_romset) {
if (!strcasecmp(node->tag, "file")) {
for (int i = 0; i < node->n_attributes; i++) {
if (!strcasecmp(node->attributes[i].name, "name")) {
struct stat64 st;
sprintf(full_path, "%s/neogeo/%s/%s", getRootDir(), romset, node->attributes[i].value);
if (!stat64(full_path, &st)) {
if (in_correct_romset)
{
if (!strcasecmp(node->tag, "file"))
{
for (int i = 0; i < node->n_attributes; i++)
{
if (!strcasecmp(node->attributes[i].name, "name"))
{
sprintf(full_path, "%s/%s", path, node->attributes[i].value);
if (FileExists(full_path))
{
printf("Found %s\n", full_path);
break;
}
else {
else
{
printf("Missing %s\n", full_path);
sprintf(full_path, "Missing %s !", node->attributes[i].value);
Info(full_path);
@@ -317,13 +321,16 @@ static int xml_check_files(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, c
break;
case XML_EVENT_END_NODE:
if (in_correct_romset) {
if (!strcasecmp(node->tag, "romset")) {
if (in_correct_romset)
{
if (!strcasecmp(node->tag, "romset"))
{
checked_ok = true;
return false;
}
}
if (!strcasecmp(node->tag, "romsets")) {
if (!strcasecmp(node->tag, "romsets"))
{
printf("Couldn't find romset %s\n", romset);
return false;
}
@@ -341,7 +348,6 @@ static int xml_check_files(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, c
static int xml_load_files(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, const int n, SAX_Data* sd)
{
const char* romset = (const char*)sd->user;
static char file_name[16 + 1] { "" };
static int in_correct_romset = 0;
static int in_file = 0;
@@ -351,6 +357,12 @@ static int xml_load_files(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, co
static unsigned char hw_type = 0, use_pcm = 0;
static int file_cnt = 0;
const char* path = (const char*)sd->user;
if (!path) return 0;
const char* romset = strrchr(path, '/');
if (!romset) return 0;
romset++;
switch (evt)
{
case XML_EVENT_START_NODE:
@@ -453,22 +465,21 @@ static int xml_load_files(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, co
if (!file_cnt)
{
printf("No parts specified. Trying to load known files:\n");
neogeo_file_tx(romset, "prom", NEO_FILE_RAW, 4, 0, 0);
neogeo_file_tx(romset, "p1rom", NEO_FILE_RAW, 4, 0, 0);
neogeo_file_tx(romset, "p2rom", NEO_FILE_RAW, 6, 0, 0);
neogeo_file_tx(romset, "srom", NEO_FILE_FIX, 8, 0, 0);
neogeo_file_tx(romset, "sfix", NEO_FILE_FIX, 2, 0, 0);
neogeo_file_tx(romset, "crom0", NEO_FILE_SPR, 15, 0, 0);
neogeo_file_tx(romset, "m1rom", NEO_FILE_RAW, 9, 0, 0);
neogeo_file_tx(path, "prom", NEO_FILE_RAW, 4, 0, 0);
neogeo_file_tx(path, "p1rom", NEO_FILE_RAW, 4, 0, 0);
neogeo_file_tx(path, "p2rom", NEO_FILE_RAW, 6, 0, 0);
neogeo_file_tx(path, "srom", NEO_FILE_FIX, 8, 0, 0);
neogeo_file_tx(path, "crom0", NEO_FILE_SPR, 15, 0, 0);
neogeo_file_tx(path, "m1rom", NEO_FILE_RAW, 9, 0, 0);
if (vromb_offset)
{
neogeo_file_tx(romset, "vroma0", NEO_FILE_RAW, 16, 0, vromb_offset);
neogeo_file_tx(romset, "vroma0", NEO_FILE_RAW, 48, vromb_offset, 0);
neogeo_file_tx(path, "vroma0", NEO_FILE_RAW, 16, 0, vromb_offset);
neogeo_file_tx(path, "vroma0", NEO_FILE_RAW, 48, vromb_offset, 0);
}
else
{
neogeo_file_tx(romset, "vroma0", NEO_FILE_RAW, 16, 0, 0);
if(!use_pcm) neogeo_file_tx(romset, "vromb0", NEO_FILE_RAW, 48, 0, 0);
neogeo_file_tx(path, "vroma0", NEO_FILE_RAW, 16, 0, 0);
if(!use_pcm) neogeo_file_tx(path, "vromb0", NEO_FILE_RAW, 48, 0, 0);
}
}
printf("Setting cart hardware type to %u\n", hw_type);
@@ -478,7 +489,7 @@ static int xml_load_files(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, co
return 0;
} else if (!strcasecmp(node->tag, "file")) {
if (in_file)
neogeo_file_tx(romset, file_name, file_type, file_index, file_offset, file_size);
neogeo_file_tx(path, file_name, file_type, file_index, file_offset, file_size);
in_file = 0;
}
}
@@ -494,27 +505,25 @@ static int xml_load_files(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, co
return true;
}
int neogeo_romset_tx(char* name) {
char romset[8 + 1];
int neogeo_romset_tx(char* name)
{
char *romset = strrchr(name, '/');
if (!romset) return 0;
romset++;
int system_type;
static char full_path[1024];
memset(romset, 0, sizeof(romset));
system_type = (user_io_8bit_set_status(0, 0) >> 1) & 3;
printf("System type: %u\n", system_type);
user_io_8bit_set_status(1, 1); // Maintain reset
// Look for the romset's file list in romsets.xml
if (!(system_type & 2)) {
// Get romset name from path
char *p = strrchr(name, '/');
if (!p) return 0;
strncpy(romset, p + 1, strlen(p + 1));
if (!(system_type & 2))
{
sprintf(full_path, "%s/%s/romset.xml", getRootDir(), name);
if (access(full_path, F_OK)) sprintf(full_path, "%s/neogeo/romsets.xml", getRootDir());
if (access(full_path, F_OK)) sprintf(full_path, "%s/%s/romsets.xml", getRootDir(), HomeDir);
printf("xml for %s: %s\n", name, full_path);
@@ -524,58 +533,61 @@ int neogeo_romset_tx(char* name) {
checked_ok = false;
romsets = 0;
sax.all_event = xml_check_files;
XMLDoc_parse_file_SAX(full_path, &sax, romset);
XMLDoc_parse_file_SAX(full_path, &sax, name);
if (!checked_ok) return 0;
sax.all_event = xml_load_files;
XMLDoc_parse_file_SAX(full_path, &sax, romset);
XMLDoc_parse_file_SAX(full_path, &sax, name);
}
// Load system ROMs
if (strcmp(romset, "debug")) {
// Not loading the special 'debug' romset
struct stat64 st;
if (!(system_type & 2)) {
sprintf(full_path, "%s/neogeo/uni-bios.rom", getRootDir());
if (!stat64(full_path, &st)) {
sprintf(full_path, "%s/uni-bios.rom", HomeDir);
if (FileExists(full_path)) {
// Autoload Unibios for cart systems if present
neogeo_file_tx("", "uni-bios.rom", NEO_FILE_RAW, 0, 0, 0x20000);
neogeo_file_tx(HomeDir, "uni-bios.rom", NEO_FILE_RAW, 0, 0, 0x20000);
} else {
// Otherwise load normal system roms
if (system_type == 0)
neogeo_file_tx("", "neo-epo.sp1", NEO_FILE_RAW, 0, 0, 0x20000);
neogeo_file_tx(HomeDir, "neo-epo.sp1", NEO_FILE_RAW, 0, 0, 0x20000);
else
neogeo_file_tx("", "sp-s2.sp1", NEO_FILE_RAW, 0, 0, 0x20000);
neogeo_file_tx(HomeDir, "sp-s2.sp1", NEO_FILE_RAW, 0, 0, 0x20000);
}
} else if (system_type == 2) {
// NeoGeo CD
neogeo_file_tx("", "top-sp1.bin", NEO_FILE_RAW, 0, 0, 0x80000);
neogeo_file_tx(HomeDir, "top-sp1.bin", NEO_FILE_RAW, 0, 0, 0x80000);
} else {
// NeoGeo CDZ
neogeo_file_tx("", "neocd.bin", NEO_FILE_RAW, 0, 0, 0x80000);
neogeo_file_tx(HomeDir, "neocd.bin", NEO_FILE_RAW, 0, 0, 0x80000);
}
}
if (!(system_type & 2))
neogeo_file_tx("", "sfix.sfix", NEO_FILE_FIX, 2, 0, 0x10000);
neogeo_file_tx("", "000-lo.lo", NEO_FILE_8BIT, 1, 0, 0x10000);
if (!(system_type & 2)) neogeo_file_tx(HomeDir, "sfix.sfix", NEO_FILE_FIX, 2, 0, 0x10000);
neogeo_file_tx(HomeDir, "000-lo.lo", NEO_FILE_8BIT, 1, 0, 0x10000);
if (!strcmp(romset, "kof95")) {
if (!strcmp(romset, "kof95"))
{
printf("Enabled sprite gfx gap hack for kof95\n");
user_io_8bit_set_status(0x10000000, 0x30000000);
} else if (!strcmp(romset, "whp")) {
}
else if (!strcmp(romset, "whp"))
{
printf("Enabled sprite gfx gap hack for whp\n");
user_io_8bit_set_status(0x20000000, 0x30000000);
} else if (!strcmp(romset, "kizuna")) {
}
else if (!strcmp(romset, "kizuna"))
{
printf("Enabled sprite gfx gap hack for kizuna\n");
user_io_8bit_set_status(0x30000000, 0x30000000);
} else
user_io_8bit_set_status(0x00000000, 0x30000000);
if (!(system_type & 2))
FileGenerateSavePath(name, (char*)full_path);
}
else
FileGenerateSavePath("ngcd", (char*)full_path);
{
user_io_8bit_set_status(0x00000000, 0x30000000);
}
FileGenerateSavePath((system_type & 2) ? "ngcd" : name, (char*)full_path);
user_io_file_mount((char*)full_path, 2, 1);
user_io_8bit_set_status(0, 1); // Release reset

View File

@@ -5,7 +5,6 @@
#define NEO_FILE_FIX 2
#define NEO_FILE_SPR 3
extern bool checked_ok;
int neogeo_romset_tx(char* name);
int neogeo_scan_xml();
char *neogeo_get_altname(char *path, char *name);