mirror of
https://github.com/ekeeke/Genesis-Plus-GX.git
synced 2024-11-14 06:45:09 +01:00
logic
This commit is contained in:
parent
f4808e1b74
commit
1a41bb1eed
139
core/cd_hw/cdd.c
139
core/cd_hw/cdd.c
@ -36,6 +36,7 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
#include "shared.h"
|
#include "shared.h"
|
||||||
|
#include "streams/file_stream.h"
|
||||||
|
|
||||||
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
||||||
#define SUPPORTED_EXT 20
|
#define SUPPORTED_EXT 20
|
||||||
@ -170,7 +171,7 @@ static void ogg_free(int i)
|
|||||||
cdd.toc.tracks[i].vf.seekable = 1;
|
cdd.toc.tracks[i].vf.seekable = 1;
|
||||||
|
|
||||||
/* reset file reading position */
|
/* reset file reading position */
|
||||||
fseek(cdd.toc.tracks[i].fd, 0, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[i].fd, 0, SEEK_SET);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -255,14 +256,14 @@ int cdd_context_load(uint8 *state)
|
|||||||
if (cdd.toc.sub)
|
if (cdd.toc.sub)
|
||||||
{
|
{
|
||||||
/* 96 bytes per sector */
|
/* 96 bytes per sector */
|
||||||
fseek(cdd.toc.sub, lba * 96, SEEK_SET);
|
filestream_seek(cdd.toc.sub, lba * 96, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* seek to current track position */
|
/* seek to current track position */
|
||||||
if (cdd.toc.tracks[cdd.index].type)
|
if (cdd.toc.tracks[cdd.index].type)
|
||||||
{
|
{
|
||||||
/* DATA track */
|
/* DATA track */
|
||||||
fseek(cdd.toc.tracks[cdd.index].fd, lba * cdd.sectorSize, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[cdd.index].fd, lba * cdd.sectorSize, SEEK_SET);
|
||||||
}
|
}
|
||||||
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
||||||
else if (cdd.toc.tracks[cdd.index].vf.seekable)
|
else if (cdd.toc.tracks[cdd.index].vf.seekable)
|
||||||
@ -278,7 +279,7 @@ int cdd_context_load(uint8 *state)
|
|||||||
else if (cdd.toc.tracks[cdd.index].fd)
|
else if (cdd.toc.tracks[cdd.index].fd)
|
||||||
{
|
{
|
||||||
/* PCM AUDIO track */
|
/* PCM AUDIO track */
|
||||||
fseek(cdd.toc.tracks[cdd.index].fd, (lba * 2352) - cdd.toc.tracks[cdd.index].offset, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[cdd.index].fd, (lba * 2352) - cdd.toc.tracks[cdd.index].offset, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bufferptr;
|
return bufferptr;
|
||||||
@ -298,7 +299,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
cdd_unload();
|
cdd_unload();
|
||||||
|
|
||||||
/* open file */
|
/* open file */
|
||||||
fd = fopen(filename, "rb");
|
fd = filestream_open(filename, RFILE_MODE_READ, -1);
|
||||||
if (!fd) return (-1);
|
if (!fd) return (-1);
|
||||||
|
|
||||||
/* save a copy of base filename */
|
/* save a copy of base filename */
|
||||||
@ -310,7 +311,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
int len;
|
int len;
|
||||||
|
|
||||||
/* read first 16 bytes */
|
/* read first 16 bytes */
|
||||||
fread(header, 0x10, 1, fd);
|
filestream_read(fd, header, 0x10);
|
||||||
|
|
||||||
/* look for valid CD image identifier */
|
/* look for valid CD image identifier */
|
||||||
if (!memcmp("SEGADISCSYSTEM", header, 14))
|
if (!memcmp("SEGADISCSYSTEM", header, 14))
|
||||||
@ -321,7 +322,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* read next 16 bytes */
|
/* read next 16 bytes */
|
||||||
fread(header, 0x10, 1, fd);
|
filestream_read(fd, header, 0x10);
|
||||||
|
|
||||||
/* look for valid CD image identifier */
|
/* look for valid CD image identifier */
|
||||||
if (!memcmp("SEGADISCSYSTEM", header, 14))
|
if (!memcmp("SEGADISCSYSTEM", header, 14))
|
||||||
@ -335,7 +336,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
if (cdd.sectorSize)
|
if (cdd.sectorSize)
|
||||||
{
|
{
|
||||||
/* read CD image header + security code */
|
/* read CD image header + security code */
|
||||||
fread(header + 0x10, 0x200, 1, fd);
|
filestream_read(fd, header + 0x10, 0x200);
|
||||||
|
|
||||||
/* initialize first track file descriptor */
|
/* initialize first track file descriptor */
|
||||||
cdd.toc.tracks[0].fd = fd;
|
cdd.toc.tracks[0].fd = fd;
|
||||||
@ -344,8 +345,8 @@ int cdd_load(char *filename, char *header)
|
|||||||
cdd.toc.tracks[0].type = TYPE_CDROM;
|
cdd.toc.tracks[0].type = TYPE_CDROM;
|
||||||
|
|
||||||
/* DATA track end LBA (based on DATA file length) */
|
/* DATA track end LBA (based on DATA file length) */
|
||||||
fseek(fd, 0, SEEK_END);
|
filestream_seek(fd, 0, SEEK_END);
|
||||||
cdd.toc.tracks[0].end = ftell(fd) / cdd.sectorSize;
|
cdd.toc.tracks[0].end = filestream_tell(fd) / cdd.sectorSize;
|
||||||
|
|
||||||
/* DATA track length should be at least 2s (BIOS requirement) */
|
/* DATA track length should be at least 2s (BIOS requirement) */
|
||||||
if (cdd.toc.tracks[0].end < 150)
|
if (cdd.toc.tracks[0].end < 150)
|
||||||
@ -354,7 +355,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* DATA track start LBA (logical block 0) */
|
/* DATA track start LBA (logical block 0) */
|
||||||
fseek(fd, 0, SEEK_SET);
|
filestream_seek(fd, 0, SEEK_SET);
|
||||||
cdd.toc.tracks[0].start = 0;
|
cdd.toc.tracks[0].start = 0;
|
||||||
|
|
||||||
/* initialize TOC */
|
/* initialize TOC */
|
||||||
@ -367,14 +368,14 @@ int cdd_load(char *filename, char *header)
|
|||||||
isCDfile = 0;
|
isCDfile = 0;
|
||||||
|
|
||||||
/* close file */
|
/* close file */
|
||||||
fclose(fd);
|
filestream_close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* automatically try to mount CD associated CUE file */
|
/* automatically try to mount CD associated CUE file */
|
||||||
len = strlen(fname);
|
len = strlen(fname);
|
||||||
while ((len && (fname[len] != '.')) || (len > 251)) len--;
|
while ((len && (fname[len] != '.')) || (len > 251)) len--;
|
||||||
strcpy(&fname[len], ".cue");
|
strcpy(&fname[len], ".cue");
|
||||||
fd = fopen(fname, "rb");
|
fd = filestream_open(fname, RFILE_MODE_READ, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse CUE file */
|
/* parse CUE file */
|
||||||
@ -431,7 +432,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
*ptr = 0;
|
*ptr = 0;
|
||||||
|
|
||||||
/* open current track file descriptor */
|
/* open current track file descriptor */
|
||||||
cdd.toc.tracks[cdd.toc.last].fd = fopen(fname, "rb");
|
cdd.toc.tracks[cdd.toc.last].fd = filestream_open(fname, RFILE_MODE_READ, -1);
|
||||||
if (!cdd.toc.tracks[cdd.toc.last].fd)
|
if (!cdd.toc.tracks[cdd.toc.last].fd)
|
||||||
{
|
{
|
||||||
/* error opening file */
|
/* error opening file */
|
||||||
@ -449,32 +450,32 @@ int cdd_load(char *filename, char *header)
|
|||||||
{
|
{
|
||||||
/* read file header */
|
/* read file header */
|
||||||
unsigned char head[28];
|
unsigned char head[28];
|
||||||
fseek(cdd.toc.tracks[cdd.toc.last].fd, 8, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[cdd.toc.last].fd, 8, SEEK_SET);
|
||||||
fread(head, 28, 1, cdd.toc.tracks[cdd.toc.last].fd);
|
filestream_read(cdd.toc.tracks[cdd.toc.last].fd, head, 28);
|
||||||
fseek(cdd.toc.tracks[cdd.toc.last].fd, 0, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[cdd.toc.last].fd, 0, SEEK_SET);
|
||||||
|
|
||||||
/* autodetect WAVE file header (44.1KHz 16-bit stereo format only) */
|
/* autodetect WAVE file header (44.1KHz 16-bit stereo format only) */
|
||||||
if (!memcmp(head, waveHeader, 28))
|
if (!memcmp(head, waveHeader, 28))
|
||||||
{
|
{
|
||||||
/* look for 'data' chunk id */
|
/* look for 'data' chunk id */
|
||||||
int dataOffset = 0;
|
int dataOffset = 0;
|
||||||
fseek(cdd.toc.tracks[cdd.toc.last].fd, 36, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[cdd.toc.last].fd, 36, SEEK_SET);
|
||||||
while (fread(head, 4, 1, cdd.toc.tracks[cdd.toc.last].fd))
|
while (filestream_read(cdd.toc.tracks[cdd.toc.last].fd, head, 4))
|
||||||
{
|
{
|
||||||
if (!memcmp(head, "data", 4))
|
if (!memcmp(head, "data", 4))
|
||||||
{
|
{
|
||||||
dataOffset = ftell(cdd.toc.tracks[cdd.toc.last].fd) + 4;
|
dataOffset = filestream_tell(cdd.toc.tracks[cdd.toc.last].fd) + 4;
|
||||||
fseek(cdd.toc.tracks[cdd.toc.last].fd, 0, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[cdd.toc.last].fd, 0, SEEK_SET);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fseek(cdd.toc.tracks[cdd.toc.last].fd, -2, SEEK_CUR);
|
filestream_seek(cdd.toc.tracks[cdd.toc.last].fd, -2, SEEK_CUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if 'data' chunk has not been found */
|
/* check if 'data' chunk has not been found */
|
||||||
if (!dataOffset)
|
if (!dataOffset)
|
||||||
{
|
{
|
||||||
/* invalid WAVE file */
|
/* invalid WAVE file */
|
||||||
fclose(cdd.toc.tracks[cdd.toc.last].fd);
|
filestream_close(cdd.toc.tracks[cdd.toc.last].fd);
|
||||||
cdd.toc.tracks[cdd.toc.last].fd = 0;
|
cdd.toc.tracks[cdd.toc.last].fd = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -499,7 +500,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* unsupported audio file */
|
/* unsupported audio file */
|
||||||
fclose(cdd.toc.tracks[cdd.toc.last].fd);
|
filestream_close(cdd.toc.tracks[cdd.toc.last].fd);
|
||||||
cdd.toc.tracks[cdd.toc.last].fd = 0;
|
cdd.toc.tracks[cdd.toc.last].fd = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -515,7 +516,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
/* close any opened file */
|
/* close any opened file */
|
||||||
if (cdd.toc.tracks[cdd.toc.last].fd)
|
if (cdd.toc.tracks[cdd.toc.last].fd)
|
||||||
{
|
{
|
||||||
fclose(cdd.toc.tracks[cdd.toc.last].fd);
|
filestream_close(cdd.toc.tracks[cdd.toc.last].fd);
|
||||||
cdd.toc.tracks[cdd.toc.last].fd = 0;
|
cdd.toc.tracks[cdd.toc.last].fd = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,7 +539,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
cdd.sectorSize = 2352;
|
cdd.sectorSize = 2352;
|
||||||
|
|
||||||
/* skip 16-byte header */
|
/* skip 16-byte header */
|
||||||
fseek(cdd.toc.tracks[0].fd, 0x10, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[0].fd, 0x10, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cdd.sectorSize)
|
if (cdd.sectorSize)
|
||||||
@ -547,8 +548,8 @@ int cdd_load(char *filename, char *header)
|
|||||||
cdd.toc.tracks[0].type = TYPE_CDROM;
|
cdd.toc.tracks[0].type = TYPE_CDROM;
|
||||||
|
|
||||||
/* read CD image header + security code */
|
/* read CD image header + security code */
|
||||||
fread(header, 0x210, 1, cdd.toc.tracks[0].fd);
|
filestream_read(cdd.toc.tracks[0].fd, header, 0x210);
|
||||||
fseek(cdd.toc.tracks[0].fd, 0, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[0].fd, 0, SEEK_SET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -638,18 +639,18 @@ int cdd_load(char *filename, char *header)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* current track end time */
|
/* current track end time */
|
||||||
fseek(cdd.toc.tracks[cdd.toc.last].fd, 0, SEEK_END);
|
filestream_seek(cdd.toc.tracks[cdd.toc.last].fd, 0, SEEK_END);
|
||||||
if (cdd.toc.tracks[cdd.toc.last].type)
|
if (cdd.toc.tracks[cdd.toc.last].type)
|
||||||
{
|
{
|
||||||
/* DATA track length */
|
/* DATA track length */
|
||||||
cdd.toc.tracks[cdd.toc.last].end = cdd.toc.tracks[cdd.toc.last].start + ((ftell(cdd.toc.tracks[cdd.toc.last].fd) + cdd.sectorSize - 1) / cdd.sectorSize);
|
cdd.toc.tracks[cdd.toc.last].end = cdd.toc.tracks[cdd.toc.last].start + ((filestream_tell(cdd.toc.tracks[cdd.toc.last].fd) + cdd.sectorSize - 1) / cdd.sectorSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* AUDIO track length */
|
/* AUDIO track length */
|
||||||
cdd.toc.tracks[cdd.toc.last].end = cdd.toc.tracks[cdd.toc.last].start + ((ftell(cdd.toc.tracks[cdd.toc.last].fd) + 2351) / 2352);
|
cdd.toc.tracks[cdd.toc.last].end = cdd.toc.tracks[cdd.toc.last].start + ((filestream_tell(cdd.toc.tracks[cdd.toc.last].fd) + 2351) / 2352);
|
||||||
}
|
}
|
||||||
fseek(cdd.toc.tracks[cdd.toc.last].fd, 0, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[cdd.toc.last].fd, 0, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* adjust track start time (based on current file start time + index absolute time) */
|
/* adjust track start time (based on current file start time + index absolute time) */
|
||||||
@ -687,11 +688,11 @@ int cdd_load(char *filename, char *header)
|
|||||||
#endif
|
#endif
|
||||||
if (cdd.toc.tracks[cdd.toc.last].fd)
|
if (cdd.toc.tracks[cdd.toc.last].fd)
|
||||||
{
|
{
|
||||||
fclose(cdd.toc.tracks[cdd.toc.last].fd);
|
filestream_close(cdd.toc.tracks[cdd.toc.last].fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* close CUE file */
|
/* close CUE file */
|
||||||
fclose(fd);
|
filestream_close(fd);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -705,7 +706,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
{
|
{
|
||||||
/* auto-detect wrong initial track index */
|
/* auto-detect wrong initial track index */
|
||||||
sprintf(ptr, extensions[i], cdd.toc.last);
|
sprintf(ptr, extensions[i], cdd.toc.last);
|
||||||
fd = fopen(fname, "rb");
|
fd = filestream_open(fname, RFILE_MODE_READ, -1);
|
||||||
if (fd)
|
if (fd)
|
||||||
{
|
{
|
||||||
offset = 0;
|
offset = 0;
|
||||||
@ -713,7 +714,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sprintf(ptr, extensions[i], cdd.toc.last + 1);
|
sprintf(ptr, extensions[i], cdd.toc.last + 1);
|
||||||
fd = fopen(fname, "rb");
|
fd = filestream_open(fname, RFILE_MODE_READ, -1);
|
||||||
if (fd) break;
|
if (fd) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -722,31 +723,31 @@ int cdd_load(char *filename, char *header)
|
|||||||
{
|
{
|
||||||
/* read file HEADER */
|
/* read file HEADER */
|
||||||
unsigned char head[28];
|
unsigned char head[28];
|
||||||
fseek(fd, 8, SEEK_SET);
|
filestream_seek(fd, 8, SEEK_SET);
|
||||||
fread(head, 28, 1, fd);
|
filestream_read(fd, head, 28);
|
||||||
fseek(fd, 0, SEEK_SET);
|
filestream_seek(fd, 0, SEEK_SET);
|
||||||
|
|
||||||
/* check if this is a valid WAVE file (44.1KHz 16-bit stereo format only) */
|
/* check if this is a valid WAVE file (44.1KHz 16-bit stereo format only) */
|
||||||
if (!memcmp(head, waveHeader, 28))
|
if (!memcmp(head, waveHeader, 28))
|
||||||
{
|
{
|
||||||
/* look for 'data' chunk id */
|
/* look for 'data' chunk id */
|
||||||
int dataOffset = 0;
|
int dataOffset = 0;
|
||||||
fseek(fd, 36, SEEK_SET);
|
filestream_seek(fd, 36, SEEK_SET);
|
||||||
while (fread(head, 4, 1, fd))
|
while (filestream_read(fd, head, 4))
|
||||||
{
|
{
|
||||||
if (!memcmp(head, "data", 4))
|
if (!memcmp(head, "data", 4))
|
||||||
{
|
{
|
||||||
dataOffset = ftell(fd) + 4;
|
dataOffset = filestream_tell(fd) + 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fseek(fd, -2, SEEK_CUR);
|
filestream_seek(fd, -2, SEEK_CUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if 'data' chunk has not been found */
|
/* check if 'data' chunk has not been found */
|
||||||
if (!dataOffset)
|
if (!dataOffset)
|
||||||
{
|
{
|
||||||
/* invalid WAVE file */
|
/* invalid WAVE file */
|
||||||
fclose(fd);
|
filestream_close(fd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -760,16 +761,16 @@ int cdd_load(char *filename, char *header)
|
|||||||
cdd.toc.tracks[cdd.toc.last].start += 150;
|
cdd.toc.tracks[cdd.toc.last].start += 150;
|
||||||
|
|
||||||
/* current track end time */
|
/* current track end time */
|
||||||
fseek(fd, 0, SEEK_END);
|
filestream_seek(fd, 0, SEEK_END);
|
||||||
cdd.toc.tracks[cdd.toc.last].end = cdd.toc.tracks[cdd.toc.last].start + ((ftell(fd) - dataOffset + 2351) / 2352);
|
cdd.toc.tracks[cdd.toc.last].end = cdd.toc.tracks[cdd.toc.last].start + ((filestream_tell(fd) - dataOffset + 2351) / 2352);
|
||||||
|
|
||||||
/* initialize file read offset for current track */
|
/* initialize file read offset for current track */
|
||||||
cdd.toc.tracks[cdd.toc.last].offset = cdd.toc.tracks[cdd.toc.last].start * 2352;
|
cdd.toc.tracks[cdd.toc.last].offset = cdd.toc.tracks[cdd.toc.last].start * 2352;
|
||||||
|
|
||||||
/* auto-detect PAUSE within audio files */
|
/* auto-detect PAUSE within audio files */
|
||||||
fseek(fd, 100 * 2352, SEEK_SET);
|
filestream_seek(fd, 100 * 2352, SEEK_SET);
|
||||||
fread(head, 4, 1, fd);
|
filestream_read(fd, head, 4);
|
||||||
fseek(fd, 0, SEEK_SET);
|
filestream_seek(fd, 0, SEEK_SET);
|
||||||
if (*(int32 *)head == 0)
|
if (*(int32 *)head == 0)
|
||||||
{
|
{
|
||||||
/* assume 2s PAUSE is included at the beginning of the file */
|
/* assume 2s PAUSE is included at the beginning of the file */
|
||||||
@ -852,7 +853,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* unsupported audio file format */
|
/* unsupported audio file format */
|
||||||
fclose(fd);
|
filestream_close(fd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -861,7 +862,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
|
|
||||||
/* try to open next audio track file */
|
/* try to open next audio track file */
|
||||||
sprintf(ptr, extensions[i], cdd.toc.last + offset);
|
sprintf(ptr, extensions[i], cdd.toc.last + offset);
|
||||||
fd = fopen(fname, "rb");
|
fd = filestream_open(fname, RFILE_MODE_READ, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -976,7 +977,7 @@ int cdd_load(char *filename, char *header)
|
|||||||
|
|
||||||
/* Automatically try to open associated subcode data file */
|
/* Automatically try to open associated subcode data file */
|
||||||
strncpy(&fname[strlen(fname) - 4], ".sub", 4);
|
strncpy(&fname[strlen(fname) - 4], ".sub", 4);
|
||||||
cdd.toc.sub = fopen(fname, "rb");
|
cdd.toc.sub = filestream_open(fname, RFILE_MODE_READ, -1);
|
||||||
|
|
||||||
/* return 1 if loaded file is CD image file */
|
/* return 1 if loaded file is CD image file */
|
||||||
return (isCDfile);
|
return (isCDfile);
|
||||||
@ -1014,13 +1015,13 @@ void cdd_unload(void)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* close file */
|
/* close file */
|
||||||
fclose(cdd.toc.tracks[i].fd);
|
filestream_close(cdd.toc.tracks[i].fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* close any opened subcode file */
|
/* close any opened subcode file */
|
||||||
if (cdd.toc.sub) fclose(cdd.toc.sub);
|
if (cdd.toc.sub) filestream_close(cdd.toc.sub);
|
||||||
|
|
||||||
/* CD unloaded */
|
/* CD unloaded */
|
||||||
cdd.loaded = 0;
|
cdd.loaded = 0;
|
||||||
@ -1042,16 +1043,16 @@ void cdd_read_data(uint8 *dst)
|
|||||||
if (cdd.sectorSize == 2048)
|
if (cdd.sectorSize == 2048)
|
||||||
{
|
{
|
||||||
/* Mode 1 COOKED data (ISO) */
|
/* Mode 1 COOKED data (ISO) */
|
||||||
fseek(cdd.toc.tracks[0].fd, cdd.lba * 2048, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[0].fd, cdd.lba * 2048, SEEK_SET);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Mode 1 RAW data (skip 16-byte header) */
|
/* Mode 1 RAW data (skip 16-byte header) */
|
||||||
fseek(cdd.toc.tracks[0].fd, cdd.lba * 2352 + 16, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[0].fd, cdd.lba * 2352 + 16, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read sector data (Mode 1 = 2048 bytes) */
|
/* read sector data (Mode 1 = 2048 bytes) */
|
||||||
fread(dst, 2048, 1, cdd.toc.tracks[0].fd);
|
filestream_read(cdd.toc.tracks[0].fd, dst, 2048);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1139,7 +1140,7 @@ void cdd_read_audio(unsigned int samples)
|
|||||||
#else
|
#else
|
||||||
uint8 *ptr = cdc.ram;
|
uint8 *ptr = cdc.ram;
|
||||||
#endif
|
#endif
|
||||||
fread(cdc.ram, 1, samples * 4, cdd.toc.tracks[cdd.index].fd);
|
filestream_read(cdd.toc.tracks[cdd.index].fd, cdc.ram, samples * 4);
|
||||||
|
|
||||||
/* process 16-bit (little-endian) stereo samples */
|
/* process 16-bit (little-endian) stereo samples */
|
||||||
for (i=0; i<samples; i++)
|
for (i=0; i<samples; i++)
|
||||||
@ -1217,7 +1218,7 @@ static void cdd_read_subcode(void)
|
|||||||
index = (scd.regs[0x68>>1].byte.l + 0x100) >> 1;
|
index = (scd.regs[0x68>>1].byte.l + 0x100) >> 1;
|
||||||
|
|
||||||
/* read interleaved subcode data from .sub file (12 x 8-bit of P subchannel first, then Q subchannel, etc) */
|
/* read interleaved subcode data from .sub file (12 x 8-bit of P subchannel first, then Q subchannel, etc) */
|
||||||
fread(subc, 1, 96, cdd.toc.sub);
|
filestream_read(cdd.toc.sub, subc, 96);
|
||||||
|
|
||||||
/* convert back to raw subcode format (96 bytes with 8 x P-W subchannel bits per byte) */
|
/* convert back to raw subcode format (96 bytes with 8 x P-W subchannel bits per byte) */
|
||||||
for (i=0; i<96; i+=2)
|
for (i=0; i<96; i+=2)
|
||||||
@ -1353,7 +1354,7 @@ void cdd_update(void)
|
|||||||
#endif
|
#endif
|
||||||
if (cdd.toc.tracks[cdd.index].fd)
|
if (cdd.toc.tracks[cdd.index].fd)
|
||||||
{
|
{
|
||||||
fseek(cdd.toc.tracks[cdd.index].fd, (cdd.toc.tracks[cdd.index].start * 2352) - cdd.toc.tracks[cdd.index].offset, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[cdd.index].fd, (cdd.toc.tracks[cdd.index].start * 2352) - cdd.toc.tracks[cdd.index].offset, SEEK_SET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1431,14 +1432,14 @@ void cdd_update(void)
|
|||||||
/* seek to current subcode position */
|
/* seek to current subcode position */
|
||||||
if (cdd.toc.sub)
|
if (cdd.toc.sub)
|
||||||
{
|
{
|
||||||
fseek(cdd.toc.sub, cdd.lba * 96, SEEK_SET);
|
filestream_seek(cdd.toc.sub, cdd.lba * 96, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* seek to current track position */
|
/* seek to current track position */
|
||||||
if (cdd.toc.tracks[cdd.index].type)
|
if (cdd.toc.tracks[cdd.index].type)
|
||||||
{
|
{
|
||||||
/* DATA track */
|
/* DATA track */
|
||||||
fseek(cdd.toc.tracks[0].fd, cdd.lba * cdd.sectorSize, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[0].fd, cdd.lba * cdd.sectorSize, SEEK_SET);
|
||||||
}
|
}
|
||||||
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
||||||
else if (cdd.toc.tracks[cdd.index].vf.seekable)
|
else if (cdd.toc.tracks[cdd.index].vf.seekable)
|
||||||
@ -1458,7 +1459,7 @@ void cdd_update(void)
|
|||||||
else if (cdd.toc.tracks[cdd.index].fd)
|
else if (cdd.toc.tracks[cdd.index].fd)
|
||||||
{
|
{
|
||||||
/* PCM AUDIO track */
|
/* PCM AUDIO track */
|
||||||
fseek(cdd.toc.tracks[cdd.index].fd, (cdd.lba * 2352) - cdd.toc.tracks[cdd.index].offset, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[cdd.index].fd, (cdd.lba * 2352) - cdd.toc.tracks[cdd.index].offset, SEEK_SET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1659,14 +1660,14 @@ void cdd_process(void)
|
|||||||
/* seek to current subcode position */
|
/* seek to current subcode position */
|
||||||
if (cdd.toc.sub)
|
if (cdd.toc.sub)
|
||||||
{
|
{
|
||||||
fseek(cdd.toc.sub, lba * 96, SEEK_SET);
|
filestream_seek(cdd.toc.sub, lba * 96, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* seek to current track position */
|
/* seek to current track position */
|
||||||
if (cdd.toc.tracks[index].type)
|
if (cdd.toc.tracks[index].type)
|
||||||
{
|
{
|
||||||
/* DATA track */
|
/* DATA track */
|
||||||
fseek(cdd.toc.tracks[0].fd, lba * cdd.sectorSize, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[0].fd, lba * cdd.sectorSize, SEEK_SET);
|
||||||
}
|
}
|
||||||
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
||||||
else if (cdd.toc.tracks[index].vf.seekable)
|
else if (cdd.toc.tracks[index].vf.seekable)
|
||||||
@ -1678,7 +1679,7 @@ void cdd_process(void)
|
|||||||
else if (cdd.toc.tracks[index].fd)
|
else if (cdd.toc.tracks[index].fd)
|
||||||
{
|
{
|
||||||
/* PCM AUDIO track */
|
/* PCM AUDIO track */
|
||||||
fseek(cdd.toc.tracks[index].fd, (lba * 2352) - cdd.toc.tracks[index].offset, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[index].fd, (lba * 2352) - cdd.toc.tracks[index].offset, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* no audio track playing (yet) */
|
/* no audio track playing (yet) */
|
||||||
@ -1758,7 +1759,7 @@ void cdd_process(void)
|
|||||||
if (cdd.toc.tracks[index].type)
|
if (cdd.toc.tracks[index].type)
|
||||||
{
|
{
|
||||||
/* DATA track */
|
/* DATA track */
|
||||||
fseek(cdd.toc.tracks[0].fd, lba * cdd.sectorSize, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[0].fd, lba * cdd.sectorSize, SEEK_SET);
|
||||||
}
|
}
|
||||||
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
||||||
else if (cdd.toc.tracks[index].vf.seekable)
|
else if (cdd.toc.tracks[index].vf.seekable)
|
||||||
@ -1770,13 +1771,13 @@ void cdd_process(void)
|
|||||||
else if (cdd.toc.tracks[index].fd)
|
else if (cdd.toc.tracks[index].fd)
|
||||||
{
|
{
|
||||||
/* PCM AUDIO track */
|
/* PCM AUDIO track */
|
||||||
fseek(cdd.toc.tracks[index].fd, (lba * 2352) - cdd.toc.tracks[index].offset, SEEK_SET);
|
filestream_seek(cdd.toc.tracks[index].fd, (lba * 2352) - cdd.toc.tracks[index].offset, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* seek to current subcode position */
|
/* seek to current subcode position */
|
||||||
if (cdd.toc.sub)
|
if (cdd.toc.sub)
|
||||||
{
|
{
|
||||||
fseek(cdd.toc.sub, lba * 96, SEEK_SET);
|
filestream_seek(cdd.toc.sub, lba * 96, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* no audio track playing */
|
/* no audio track playing */
|
||||||
|
@ -61,10 +61,12 @@
|
|||||||
|
|
||||||
#define CD_MAX_TRACKS 100
|
#define CD_MAX_TRACKS 100
|
||||||
|
|
||||||
|
typedef struct RFILE RFILE;
|
||||||
|
|
||||||
/* CD track */
|
/* CD track */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
FILE *fd;
|
RFILE *fd;
|
||||||
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
#if defined(USE_LIBTREMOR) || defined(USE_LIBVORBIS)
|
||||||
OggVorbis_File vf;
|
OggVorbis_File vf;
|
||||||
#endif
|
#endif
|
||||||
@ -80,7 +82,7 @@ typedef struct
|
|||||||
int end;
|
int end;
|
||||||
int last;
|
int last;
|
||||||
track_t tracks[CD_MAX_TRACKS];
|
track_t tracks[CD_MAX_TRACKS];
|
||||||
FILE *sub;
|
RFILE *sub;
|
||||||
} toc_t;
|
} toc_t;
|
||||||
|
|
||||||
/* CDD hardware */
|
/* CDD hardware */
|
||||||
|
Loading…
Reference in New Issue
Block a user