PSX: add simple CUE parser.

This commit is contained in:
Sorgelig
2021-12-19 04:51:30 +08:00
parent d0085907d2
commit 069368347a
3 changed files with 119 additions and 8 deletions

View File

@@ -13,6 +13,103 @@
static char buf[1024];
static int sgets(char *out, int sz, char **in)
{
*out = 0;
do
{
char *instr = *in;
int cnt = 0;
while (*instr && *instr != 10)
{
if (*instr == 13)
{
instr++;
continue;
}
if (cnt < sz - 1)
{
out[cnt++] = *instr;
out[cnt] = 0;
}
instr++;
}
if (*instr == 10) instr++;
*in = instr;
} while (!*out && **in);
return *out;
}
static int get_bin(const char *cue)
{
static char line[128];
char *ptr, *lptr;
int bb;
int res = 0;
buf[0] = 0;
int sz = FileLoad(cue, 0, 0);
if (sz)
{
char *toc = new char[sz + 1];
if (toc)
{
if (FileLoad(cue, toc, sz))
{
toc[sz] = 0;
char *tbuf = toc;
while (sgets(line, sizeof(line), &tbuf))
{
lptr = line;
while (*lptr == 0x20) lptr++;
/* decode FILE commands */
if (!(memcmp(lptr, "FILE", 4)))
{
strcpy(buf, cue);
ptr = strrchr(buf, '/');
if (!ptr) ptr = buf;
else ptr++;
lptr += 4;
while (*lptr == 0x20) lptr++;
char stp = 0x20;
if (*lptr == '\"')
{
lptr++;
stp = '\"';
}
while ((*lptr != stp) && (lptr <= (line + 128)) && (ptr < (buf + 1023))) *ptr++ = *lptr++;
*ptr = 0;
}
/* decode TRACK commands */
else if ((sscanf(lptr, "TRACK %02d %*s", &bb)) || (sscanf(lptr, "TRACK %d %*s", &bb)))
{
if (buf[0] && (strstr(lptr, "MODE1") || strstr(lptr, "MODE2")))
{
res = 1;
break;
}
}
}
}
delete(toc);
}
}
return res;
}
void psx_mount_cd(int f_index, int s_index, const char *filename)
{
static char last_dir[1024] = {};
@@ -45,9 +142,20 @@ void psx_mount_cd(int f_index, int s_index, const char *filename)
if (!loaded) Info("CD BIOS not found!", 4000);
}
if (loaded && *filename)
if (loaded)
{
int len = strlen(filename);
user_io_set_index(f_index);
user_io_file_mount(filename, s_index);
process_ss(filename, len != 0);
if (len > 4 && !strcasecmp(filename + len - 4, ".cue") && get_bin(filename))
{
user_io_file_mount(buf, s_index);
}
else
{
user_io_file_mount(filename, s_index);
}
}
}

View File

@@ -1491,17 +1491,21 @@ static void kbd_fifo_poll()
kbd_fifo_r = (kbd_fifo_r + 1)&(KBD_FIFO_SIZE - 1);
}
static int process_ss(const char *rom_name)
int process_ss(const char *rom_name, int enable)
{
static char ss_name[1024] = {};
static char *ss_sufx = 0;
static uint32_t ss_cnt[4] = {};
static void *base[4] = {};
static int enabled = 0;
if (!ss_base) return 0;
if (rom_name)
{
enabled = enable;
if (!enabled) return 0;
uint32_t len = ss_size;
uint32_t map_addr = ss_base;
fileTYPE f = {};
@@ -1554,6 +1558,8 @@ static int process_ss(const char *rom_name)
return 1;
}
if (!enabled) return 0;
static unsigned long ss_timer = 0;
if (ss_timer && !CheckTimer(ss_timer)) return 0;
ss_timer = GetTimer(1000);
@@ -1667,11 +1673,6 @@ int user_io_file_mount(const char *name, unsigned char index, char pre)
int ret = 0;
int len = strlen(name);
if ((index == 1) && is_psx() && len)
{
process_ss(name);
}
sd_image_cangrow[index] = (pre != 0);
sd_type[index] = 0;

View File

@@ -267,6 +267,8 @@ char * GetMidiLinkSoundfont();
void user_io_store_filename(char *filename);
int user_io_use_cheats();
int process_ss(const char *rom_name, int enable = 1);
void diskled_on();
#define DISKLED_ON diskled_on()
#define DISKLED_OFF void()