mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-06 07:38:05 -04:00
.cue support, Pico stubs
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@433 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
b923ecbe75
commit
9037e45d9f
16 changed files with 530 additions and 161 deletions
|
@ -1636,6 +1636,10 @@ void PicoMemResetCD(int r3)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef EMU_M68K
|
||||
static void m68k_mem_setup_cd(void);
|
||||
#endif
|
||||
|
||||
PICO_INTERNAL void PicoMemSetupCD(void)
|
||||
{
|
||||
// additional handlers for common code
|
||||
|
@ -1702,6 +1706,9 @@ PICO_INTERNAL void PicoMemSetupCD(void)
|
|||
// PicoMemResetCD() will setup word ram for both
|
||||
}
|
||||
#endif
|
||||
#ifdef EMU_M68K
|
||||
m68k_mem_setup_cd();
|
||||
#endif
|
||||
|
||||
// m68k_poll_addr = m68k_poll_cnt = 0;
|
||||
s68k_poll_adclk = s68k_poll_cnt = 0;
|
||||
|
@ -1709,27 +1716,27 @@ PICO_INTERNAL void PicoMemSetupCD(void)
|
|||
|
||||
|
||||
#ifdef EMU_M68K
|
||||
unsigned char PicoReadCD8w (unsigned int a) {
|
||||
static unsigned int PicoReadCD8w (unsigned int a) {
|
||||
return m68ki_cpu_p == &PicoCpuMS68k ? PicoReadS68k8(a) : PicoReadM68k8(a);
|
||||
}
|
||||
unsigned short PicoReadCD16w(unsigned int a) {
|
||||
static unsigned int PicoReadCD16w(unsigned int a) {
|
||||
return m68ki_cpu_p == &PicoCpuMS68k ? PicoReadS68k16(a) : PicoReadM68k16(a);
|
||||
}
|
||||
unsigned int PicoReadCD32w(unsigned int a) {
|
||||
static unsigned int PicoReadCD32w(unsigned int a) {
|
||||
return m68ki_cpu_p == &PicoCpuMS68k ? PicoReadS68k32(a) : PicoReadM68k32(a);
|
||||
}
|
||||
void PicoWriteCD8w (unsigned int a, unsigned char d) {
|
||||
static void PicoWriteCD8w (unsigned int a, unsigned char d) {
|
||||
if (m68ki_cpu_p == &PicoCpuMS68k) PicoWriteS68k8(a, d); else PicoWriteM68k8(a, d);
|
||||
}
|
||||
void PicoWriteCD16w(unsigned int a, unsigned short d) {
|
||||
static void PicoWriteCD16w(unsigned int a, unsigned short d) {
|
||||
if (m68ki_cpu_p == &PicoCpuMS68k) PicoWriteS68k16(a, d); else PicoWriteM68k16(a, d);
|
||||
}
|
||||
void PicoWriteCD32w(unsigned int a, unsigned int d) {
|
||||
static void PicoWriteCD32w(unsigned int a, unsigned int d) {
|
||||
if (m68ki_cpu_p == &PicoCpuMS68k) PicoWriteS68k32(a, d); else PicoWriteM68k32(a, d);
|
||||
}
|
||||
|
||||
// these are allowed to access RAM
|
||||
unsigned int m68k_read_pcrelative_CD8 (unsigned int a)
|
||||
static unsigned int m68k_read_pcrelative_CD8 (unsigned int a)
|
||||
{
|
||||
a&=0xffffff;
|
||||
if(m68ki_cpu_p == &PicoCpuMS68k) {
|
||||
|
@ -1756,7 +1763,7 @@ unsigned int m68k_read_pcrelative_CD8 (unsigned int a)
|
|||
}
|
||||
return 0;//(u8) lastread_d;
|
||||
}
|
||||
unsigned int m68k_read_pcrelative_CD16(unsigned int a)
|
||||
static unsigned int m68k_read_pcrelative_CD16(unsigned int a)
|
||||
{
|
||||
a&=0xffffff;
|
||||
if(m68ki_cpu_p == &PicoCpuMS68k) {
|
||||
|
@ -1783,7 +1790,7 @@ unsigned int m68k_read_pcrelative_CD16(unsigned int a)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
unsigned int m68k_read_pcrelative_CD32(unsigned int a)
|
||||
static unsigned int m68k_read_pcrelative_CD32(unsigned int a)
|
||||
{
|
||||
u16 *pm;
|
||||
a&=0xffffff;
|
||||
|
@ -1813,5 +1820,28 @@ unsigned int m68k_read_pcrelative_CD32(unsigned int a)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern unsigned int (*pm68k_read_memory_8) (unsigned int address);
|
||||
extern unsigned int (*pm68k_read_memory_16)(unsigned int address);
|
||||
extern unsigned int (*pm68k_read_memory_32)(unsigned int address);
|
||||
extern void (*pm68k_write_memory_8) (unsigned int address, unsigned char value);
|
||||
extern void (*pm68k_write_memory_16)(unsigned int address, unsigned short value);
|
||||
extern void (*pm68k_write_memory_32)(unsigned int address, unsigned int value);
|
||||
extern unsigned int (*pm68k_read_memory_pcr_8) (unsigned int address);
|
||||
extern unsigned int (*pm68k_read_memory_pcr_16)(unsigned int address);
|
||||
extern unsigned int (*pm68k_read_memory_pcr_32)(unsigned int address);
|
||||
|
||||
static void m68k_mem_setup_cd(void)
|
||||
{
|
||||
pm68k_read_memory_8 = PicoReadCD8w;
|
||||
pm68k_read_memory_16 = PicoReadCD16w;
|
||||
pm68k_read_memory_32 = PicoReadCD32w;
|
||||
pm68k_write_memory_8 = PicoWriteCD8w;
|
||||
pm68k_write_memory_16 = PicoWriteCD16w;
|
||||
pm68k_write_memory_32 = PicoWriteCD32w;
|
||||
pm68k_read_memory_pcr_8 = m68k_read_pcrelative_CD8;
|
||||
pm68k_read_memory_pcr_16 = m68k_read_pcrelative_CD16;
|
||||
pm68k_read_memory_pcr_32 = m68k_read_pcrelative_CD32;
|
||||
}
|
||||
#endif // EMU_M68K
|
||||
|
||||
|
|
|
@ -9,15 +9,61 @@
|
|||
|
||||
#include "../PicoInt.h"
|
||||
#include "cd_file.h"
|
||||
#include "cue.h"
|
||||
|
||||
//#define cdprintf(f,...) printf(f "\n",##__VA_ARGS__) // tmp
|
||||
#define DEBUG_CD
|
||||
|
||||
PICO_INTERNAL int Load_CD_Image(const char *iso_name, cd_img_type type)
|
||||
static int audio_track_mp3(const char *fname, int index)
|
||||
{
|
||||
int i, j, num_track, Cur_LBA, index, ret, iso_name_len;
|
||||
_scd_track *Tracks = Pico_mcd->TOC.Tracks;
|
||||
FILE *tmp_file;
|
||||
int fs, ret;
|
||||
|
||||
tmp_file = fopen(fname, "rb");
|
||||
if (tmp_file == NULL)
|
||||
return -1;
|
||||
|
||||
ret = fseek(tmp_file, 0, SEEK_END);
|
||||
fs = ftell(tmp_file); // used to calculate length
|
||||
fseek(tmp_file, 0, SEEK_SET);
|
||||
|
||||
#if DONT_OPEN_MANY_FILES
|
||||
// some systems (like PSP) can't have many open files at a time,
|
||||
// so we work with their names instead.
|
||||
fclose(tmp_file);
|
||||
tmp_file = (void *) strdup(fname);
|
||||
#endif
|
||||
Tracks[index].KBtps = (short) mp3_get_bitrate(tmp_file, fs);
|
||||
Tracks[index].KBtps >>= 3;
|
||||
if (ret != 0 || Tracks[index].KBtps <= 0)
|
||||
{
|
||||
elprintf(EL_STATUS, "track %2i: mp3 bitrate %i", index+1, Tracks[index].KBtps);
|
||||
#if !DONT_OPEN_MANY_FILES
|
||||
fclose(tmp_file);
|
||||
#else
|
||||
free(tmp_file);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
Tracks[index].F = tmp_file;
|
||||
|
||||
// MP3 File
|
||||
Tracks[index].ftype = TYPE_MP3;
|
||||
fs *= 75;
|
||||
fs /= Tracks[index].KBtps * 1000;
|
||||
Tracks[index].Length = fs;
|
||||
Tracks[index].Offset = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
PICO_INTERNAL int Load_CD_Image(const char *cd_img_name, cd_img_type type)
|
||||
{
|
||||
int i, j, num_track, Cur_LBA, index, ret, iso_name_len, missed, cd_img_sectors;
|
||||
_scd_track *Tracks = Pico_mcd->TOC.Tracks;
|
||||
char tmp_name[1024], tmp_ext[10];
|
||||
cue_data_t *cue_data = NULL;
|
||||
pm_file *pmf;
|
||||
static char *exts[] = {
|
||||
"%02d.mp3", " %02d.mp3", "-%02d.mp3", "_%02d.mp3", " - %02d.mp3",
|
||||
|
@ -31,109 +77,134 @@ PICO_INTERNAL int Load_CD_Image(const char *iso_name, cd_img_type type)
|
|||
|
||||
Unload_ISO();
|
||||
|
||||
/* is this .cue? */
|
||||
ret = strlen(cd_img_name);
|
||||
if (ret >= 3 && strcasecmp(cd_img_name + ret - 3, "cue") == 0)
|
||||
cue_data = cue_parse(cd_img_name);
|
||||
if (cue_data != NULL)
|
||||
cd_img_name = cue_data->tracks[1].fname;
|
||||
|
||||
Tracks[0].ftype = type == CIT_BIN ? TYPE_BIN : TYPE_ISO;
|
||||
|
||||
Tracks[0].F = pmf = pm_open(iso_name);
|
||||
Tracks[0].F = pmf = pm_open(cd_img_name);
|
||||
if (Tracks[0].F == NULL)
|
||||
{
|
||||
Tracks[0].ftype = 0;
|
||||
Tracks[0].Length = 0;
|
||||
if (cue_data != NULL)
|
||||
cue_destroy(cue_data);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (Tracks[0].ftype == TYPE_ISO)
|
||||
Tracks[0].Length = pmf->size >>= 11; // size in sectors
|
||||
else Tracks[0].Length = pmf->size /= 2352;
|
||||
cd_img_sectors = pmf->size >>= 11; // size in sectors
|
||||
else cd_img_sectors = pmf->size /= 2352;
|
||||
Tracks[0].Offset = 0;
|
||||
|
||||
Tracks[0].MSF.M = 0; // minutes
|
||||
Tracks[0].MSF.S = 2; // seconds
|
||||
Tracks[0].MSF.F = 0; // frames
|
||||
|
||||
cdprintf("Track 0 - %02d:%02d:%02d DATA", Tracks[0].MSF.M, Tracks[0].MSF.S, Tracks[0].MSF.F);
|
||||
elprintf(EL_STATUS, "Track 0: %02d:%02d:%02d %9i DATA",
|
||||
Tracks[0].MSF.M, Tracks[0].MSF.S, Tracks[0].MSF.F, Tracks[0].Length);
|
||||
|
||||
Cur_LBA = Tracks[0].Length; // Size in sectors
|
||||
Cur_LBA = Tracks[0].Length = cd_img_sectors;
|
||||
|
||||
iso_name_len = strlen(iso_name);
|
||||
if (cue_data != NULL)
|
||||
{
|
||||
if (cue_data->tracks[2].fname == NULL) { // NULL means track2 is in same file as track1
|
||||
Cur_LBA = Tracks[0].Length = cue_data->tracks[2].sector_offset;
|
||||
}
|
||||
for (num_track = 2; num_track <= cue_data->track_count; num_track++)
|
||||
{
|
||||
index = num_track - 1;
|
||||
Cur_LBA += cue_data->tracks[num_track].pregap;
|
||||
if (cue_data->tracks[num_track].type == CT_MP3) {
|
||||
ret = audio_track_mp3(cue_data->tracks[num_track].fname, index);
|
||||
if (ret != 0) break;
|
||||
}
|
||||
else
|
||||
{
|
||||
Tracks[index].ftype = cue_data->tracks[num_track].type;
|
||||
if (cue_data->tracks[num_track].fname != NULL)
|
||||
{
|
||||
Tracks[index].F = fopen(cue_data->tracks[num_track].fname, "rb");
|
||||
elprintf(EL_STATUS, "track %2i (%s): can't determine length",
|
||||
cue_data->tracks[num_track].fname);
|
||||
Tracks[index].Length = 2*75;
|
||||
Tracks[index].Offset = 0;
|
||||
} else {
|
||||
if (num_track < cue_data->track_count)
|
||||
Tracks[index].Length = cue_data->tracks[num_track+1].sector_offset -
|
||||
cue_data->tracks[num_track].sector_offset;
|
||||
else
|
||||
Tracks[index].Length = cd_img_sectors - cue_data->tracks[num_track].sector_offset;
|
||||
Tracks[index].Offset = cue_data->tracks[num_track].sector_offset;
|
||||
}
|
||||
}
|
||||
|
||||
LBA_to_MSF(Cur_LBA, &Tracks[index].MSF);
|
||||
Cur_LBA += Tracks[index].Length;
|
||||
|
||||
elprintf(EL_STATUS, "Track %2i: %02d:%02d:%02d %9i AUDIO - %s", index, Tracks[index].MSF.M,
|
||||
Tracks[index].MSF.S, Tracks[index].MSF.F, Tracks[index].Length,
|
||||
cue_data->tracks[num_track].fname);
|
||||
}
|
||||
cue_destroy(cue_data);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
/* track autosearch, Gens-like */
|
||||
iso_name_len = strlen(cd_img_name);
|
||||
if (iso_name_len >= sizeof(tmp_name))
|
||||
iso_name_len = sizeof(tmp_name) - 1;
|
||||
|
||||
for (num_track = 2, i = 0; i < 100; i++)
|
||||
for (num_track = 2, i = 0, missed = 0; i < 100 && missed < 4; i++)
|
||||
{
|
||||
if (PicoCDLoadProgressCB != NULL && i > 1) PicoCDLoadProgressCB(i);
|
||||
if (PicoCDLoadProgressCB != NULL && i > 1) PicoCDLoadProgressCB(i + (100-i)*missed/4);
|
||||
|
||||
for (j = 0; j < sizeof(exts)/sizeof(char *); j++)
|
||||
{
|
||||
int ext_len;
|
||||
FILE *tmp_file;
|
||||
sprintf(tmp_ext, exts[j], i);
|
||||
ext_len = strlen(tmp_ext);
|
||||
|
||||
memcpy(tmp_name, iso_name, iso_name_len + 1);
|
||||
memcpy(tmp_name, cd_img_name, iso_name_len + 1);
|
||||
tmp_name[iso_name_len - 4] = 0;
|
||||
strcat(tmp_name, tmp_ext);
|
||||
|
||||
tmp_file = fopen(tmp_name, "rb");
|
||||
if (!tmp_file && i > 1 && iso_name_len > ext_len) {
|
||||
index = num_track - 1;
|
||||
ret = audio_track_mp3(tmp_name, index);
|
||||
if (ret != 0 && i > 1 && iso_name_len > ext_len) {
|
||||
tmp_name[iso_name_len - ext_len] = 0;
|
||||
strcat(tmp_name, tmp_ext);
|
||||
tmp_file = fopen(tmp_name, "rb");
|
||||
ret = audio_track_mp3(tmp_name, index);
|
||||
}
|
||||
|
||||
if (tmp_file)
|
||||
if (ret == 0)
|
||||
{
|
||||
int fs;
|
||||
index = num_track - 1;
|
||||
|
||||
ret = fseek(tmp_file, 0, SEEK_END);
|
||||
fs = ftell(tmp_file); // used to calculate lenght
|
||||
fseek(tmp_file, 0, SEEK_SET);
|
||||
|
||||
#if DONT_OPEN_MANY_FILES
|
||||
// some systems (like PSP) can't have many open files at a time,
|
||||
// so we work with their names instead.
|
||||
fclose(tmp_file);
|
||||
tmp_file = (void *) strdup(tmp_name);
|
||||
#endif
|
||||
Tracks[index].KBtps = (short) mp3_get_bitrate(tmp_file, fs);
|
||||
Tracks[index].KBtps >>= 3;
|
||||
if (ret != 0 || Tracks[index].KBtps <= 0)
|
||||
{
|
||||
cdprintf("Error track %i: rate %i", index, Tracks[index].KBtps);
|
||||
#if !DONT_OPEN_MANY_FILES
|
||||
fclose(tmp_file);
|
||||
#else
|
||||
free(tmp_file);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
Tracks[index].F = tmp_file;
|
||||
|
||||
LBA_to_MSF(Cur_LBA, &Tracks[index].MSF);
|
||||
|
||||
// MP3 File
|
||||
Tracks[index].ftype = TYPE_MP3;
|
||||
fs *= 75;
|
||||
fs /= Tracks[index].KBtps * 1000;
|
||||
Tracks[index].Length = fs;
|
||||
Cur_LBA += Tracks[index].Length;
|
||||
|
||||
cdprintf("Track %i: %s - %02d:%02d:%02d len=%i AUDIO", index, tmp_name, Tracks[index].MSF.M,
|
||||
Tracks[index].MSF.S, Tracks[index].MSF.F, fs);
|
||||
elprintf(EL_STATUS, "Track %2i: %02d:%02d:%02d %9i AUDIO - %s", index, Tracks[index].MSF.M,
|
||||
Tracks[index].MSF.S, Tracks[index].MSF.F, Tracks[index].Length, tmp_name);
|
||||
|
||||
num_track++;
|
||||
missed = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret != 0) missed++;
|
||||
}
|
||||
|
||||
finish:
|
||||
Pico_mcd->TOC.Last_Track = num_track - 1;
|
||||
|
||||
index = num_track - 1;
|
||||
|
||||
LBA_to_MSF(Cur_LBA, &Tracks[index].MSF);
|
||||
|
||||
cdprintf("End CD - %02d:%02d:%02d\n\n", Tracks[index].MSF.M,
|
||||
elprintf(EL_STATUS, "End CD - %02d:%02d:%02d\n", Tracks[index].MSF.M,
|
||||
Tracks[index].MSF.S, Tracks[index].MSF.F);
|
||||
|
||||
if (PicoCDLoadProgressCB != NULL) PicoCDLoadProgressCB(100);
|
||||
|
@ -153,11 +224,14 @@ PICO_INTERNAL void Unload_ISO(void)
|
|||
for(i = 1; i < 100; i++)
|
||||
{
|
||||
if (Pico_mcd->TOC.Tracks[i].F != NULL)
|
||||
#if !DONT_OPEN_MANY_FILES
|
||||
fclose(Pico_mcd->TOC.Tracks[i].F);
|
||||
#else
|
||||
free(Pico_mcd->TOC.Tracks[i].F);
|
||||
{
|
||||
#if DONT_OPEN_MANY_FILES
|
||||
if (Pico_mcd->TOC.Tracks[i].type == TYPE_MP3)
|
||||
free(Pico_mcd->TOC.Tracks[i].F);
|
||||
else
|
||||
#endif
|
||||
fclose(Pico_mcd->TOC.Tracks[i].F);
|
||||
}
|
||||
}
|
||||
memset(Pico_mcd->TOC.Tracks, 0, sizeof(Pico_mcd->TOC.Tracks));
|
||||
}
|
||||
|
@ -223,7 +297,6 @@ PICO_INTERNAL int FILE_Read_One_LBA_CDC(void)
|
|||
//pm_read(Pico_mcd->cdc.Buffer + Pico_mcd->cdc.PT.N + 4, 2048, Pico_mcd->TOC.Tracks[0].F);
|
||||
PicoCDBufferRead(Pico_mcd->cdc.Buffer + Pico_mcd->cdc.PT.N + 4, where_read);
|
||||
|
||||
#ifdef DEBUG_CD
|
||||
cdprintf("Read -> WA = %d Buffer[%d] =", Pico_mcd->cdc.WA.N, Pico_mcd->cdc.PT.N & 0x3FFF);
|
||||
cdprintf("Header 1 = %.2X %.2X %.2X %.2X", Pico_mcd->cdc.HEAD.B.B0,
|
||||
Pico_mcd->cdc.HEAD.B.B1, Pico_mcd->cdc.HEAD.B.B2, Pico_mcd->cdc.HEAD.B.B3);
|
||||
|
@ -234,7 +307,6 @@ PICO_INTERNAL int FILE_Read_One_LBA_CDC(void)
|
|||
Pico_mcd->cdc.Buffer[(Pico_mcd->cdc.PT.N + 3) & 0x3FFF],
|
||||
Pico_mcd->cdc.Buffer[(Pico_mcd->cdc.PT.N + 4) & 0x3FFF],
|
||||
Pico_mcd->cdc.Buffer[(Pico_mcd->cdc.PT.N + 5) & 0x3FFF]);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ typedef struct
|
|||
char ftype; // TYPE_ISO, TYPE_BIN, TYPE_MP3
|
||||
void *F;
|
||||
int Length;
|
||||
int Offset; // sector offset, when single file is used for multiple virtual tracks
|
||||
short KBtps; // kbytes per sec for mp3s (bitrate / 1000 / 8)
|
||||
short pad;
|
||||
} _scd_track;
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#include <string.h>
|
||||
#include "cue.h"
|
||||
|
||||
//#include "../PicoInt.h"
|
||||
#define elprintf(w,f,...) printf(f "\n",##__VA_ARGS__);
|
||||
#include "../PicoInt.h"
|
||||
// #define elprintf(w,f,...) printf(f "\n",##__VA_ARGS__);
|
||||
|
||||
static char *mystrip(char *str)
|
||||
{
|
||||
|
@ -42,7 +42,7 @@ static int get_token(const char *buff, char *dest, int len)
|
|||
dest[d++] = *p++;
|
||||
dest[d] = 0;
|
||||
|
||||
if (*p != sep)
|
||||
if (sep == '\"' && *p != sep)
|
||||
elprintf(EL_STATUS, "cue: bad token: \"%s\"", buff);
|
||||
|
||||
return d + skip;
|
||||
|
@ -51,19 +51,19 @@ static int get_token(const char *buff, char *dest, int len)
|
|||
static char *get_ext(char *fname)
|
||||
{
|
||||
int len = strlen(fname);
|
||||
return (len >= 3) ? (fname - 3) : (fname - len);
|
||||
return (len >= 3) ? (fname + len - 3) : fname;
|
||||
}
|
||||
|
||||
|
||||
#define BEGINS(buff,str) (strncmp(buff,str,sizeof(str)-1) == 0)
|
||||
|
||||
/* note: tracks[0] is not used */
|
||||
cue_data *cue_parse(const char *fname)
|
||||
cue_data_t *cue_parse(const char *fname)
|
||||
{
|
||||
char buff[256], current_file[256], buff2[32];
|
||||
FILE *f, *tmpf;
|
||||
int ret, count = 0, count_alloc = 2;
|
||||
cue_data *data;
|
||||
cue_data_t *data;
|
||||
void *tmp;
|
||||
|
||||
f = fopen(fname, "r");
|
||||
|
@ -92,6 +92,7 @@ cue_data *cue_parse(const char *fname)
|
|||
count_alloc *= 2;
|
||||
tmp = realloc(data, sizeof(*data) + count_alloc * sizeof(cue_track));
|
||||
if (tmp == NULL) { count--; break; }
|
||||
data = tmp;
|
||||
}
|
||||
memset(&data->tracks[count], 0, sizeof(data->tracks[0]));
|
||||
if (count == 1 || strcmp(data->tracks[1].fname, current_file) != 0)
|
||||
|
@ -113,11 +114,11 @@ cue_data *cue_parse(const char *fname)
|
|||
count, atoi(buff2));
|
||||
// check type
|
||||
get_token(buff+6+ret, buff2, sizeof(buff2));
|
||||
if (strcmp(buff2, "MODE1/2352"))
|
||||
if (strcmp(buff2, "MODE1/2352") == 0)
|
||||
data->tracks[count].type = CT_BIN;
|
||||
else if (strcmp(buff2, "MODE1/2048"))
|
||||
else if (strcmp(buff2, "MODE1/2048") == 0)
|
||||
data->tracks[count].type = CT_ISO;
|
||||
else if (strcmp(buff2, "AUDIO"))
|
||||
else if (strcmp(buff2, "AUDIO") == 0)
|
||||
{
|
||||
if (data->tracks[count].fname != NULL)
|
||||
{
|
||||
|
@ -132,6 +133,11 @@ cue_data *cue_parse(const char *fname)
|
|||
data->tracks[count].fname);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// propagate previous
|
||||
data->tracks[count].type = data->tracks[count-1].type;
|
||||
}
|
||||
}
|
||||
else {
|
||||
elprintf(EL_STATUS, "unhandled track type: \"%s\"", buff2);
|
||||
|
@ -149,18 +155,28 @@ cue_data *cue_parse(const char *fname)
|
|||
}
|
||||
// offset in file
|
||||
get_token(buff+6+ret, buff2, sizeof(buff2));
|
||||
ret = sscanf(buff2, "%i:%i:%i", &m, &s, &f);
|
||||
ret = sscanf(buff2, "%d:%d:%d", &m, &s, &f);
|
||||
if (ret != 3) {
|
||||
elprintf(EL_STATUS, "cue: failed to parse: \"%s\"", buff);
|
||||
count--; break;
|
||||
}
|
||||
data->tracks[count].sector_offset = m*60*75 + s*75 + f;
|
||||
// some strange .cues may need this
|
||||
if (data->tracks[count].fname != NULL && strcmp(data->tracks[count].fname, current_file) != 0)
|
||||
{
|
||||
free(data->tracks[count].fname);
|
||||
data->tracks[count].fname = strdup(current_file);
|
||||
}
|
||||
if (data->tracks[count].fname == NULL && strcmp(data->tracks[1].fname, current_file) != 0)
|
||||
{
|
||||
data->tracks[count].fname = strdup(current_file);
|
||||
}
|
||||
}
|
||||
else if (BEGINS(buff, "PREGAP "))
|
||||
{
|
||||
int m, s, f;
|
||||
get_token(buff+7, buff2, sizeof(buff2));
|
||||
ret = sscanf(buff2, "%i:%i:%i", &m, &s, &f);
|
||||
ret = sscanf(buff2, "%d:%d:%d", &m, &s, &f);
|
||||
if (ret != 3) {
|
||||
elprintf(EL_STATUS, "cue: failed to parse: \"%s\"", buff);
|
||||
continue;
|
||||
|
@ -169,7 +185,7 @@ cue_data *cue_parse(const char *fname)
|
|||
}
|
||||
else
|
||||
{
|
||||
elprintf(EL_STATUS, "cue: failed to parse: \"%s\"", buff);
|
||||
elprintf(EL_STATUS, "cue: unhandled line: \"%s\"", buff);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,7 +203,7 @@ cue_data *cue_parse(const char *fname)
|
|||
}
|
||||
|
||||
|
||||
void cue_destroy(cue_data *data)
|
||||
void cue_destroy(cue_data_t *data)
|
||||
{
|
||||
int c;
|
||||
|
||||
|
@ -200,19 +216,22 @@ void cue_destroy(cue_data *data)
|
|||
}
|
||||
|
||||
|
||||
#if 0
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
cue_data *data = cue_parse(argv[1]);
|
||||
cue_data_t *data = cue_parse(argv[1]);
|
||||
int c;
|
||||
|
||||
if (data == NULL) return 1;
|
||||
|
||||
for (c = 1; c <= data->track_count; c++)
|
||||
printf("%2i: %i %9i %9i %s\n", c, data->tracks[c].type, data->tracks[c].sector_offset,
|
||||
data->tracks[c].pregap, data->tracks[c].fname);
|
||||
printf("%2i: %i %9i %02i:%02i:%02i %9i %s\n", c, data->tracks[c].type, data->tracks[c].sector_offset,
|
||||
data->tracks[c].sector_offset / (75*60), data->tracks[c].sector_offset / 75 % 60,
|
||||
data->tracks[c].sector_offset % 75, data->tracks[c].pregap, data->tracks[c].fname);
|
||||
|
||||
cue_destroy(data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@ typedef struct
|
|||
{
|
||||
int track_count;
|
||||
cue_track tracks[0];
|
||||
} cue_data;
|
||||
} cue_data_t;
|
||||
|
||||
|
||||
cue_data *cue_parse(const char *fname);
|
||||
void cue_destroy(cue_data *data);
|
||||
cue_data_t *cue_parse(const char *fname);
|
||||
void cue_destroy(cue_data_t *data);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue