diff --git a/psx/mednadisc/Mednadisc.cpp b/psx/mednadisc/Mednadisc.cpp
index 41d1e95487..25a6dc13a8 100644
--- a/psx/mednadisc/Mednadisc.cpp
+++ b/psx/mednadisc/Mednadisc.cpp
@@ -25,7 +25,7 @@ EW_EXPORT void* mednadisc_LoadCD(const char* fname)
{
CDAccess* disc = NULL;
try {
- disc = cdaccess_open_image(fname,false);
+ disc = CDAccess_Open(fname,false);
}
catch(MDFN_Error &) {
return NULL;
@@ -53,6 +53,9 @@ EW_EXPORT void mednadisc_ReadTOC(MednaDisc* md, JustTOC* justToc, CDUtility::TOC
memcpy(tracks101,toc.tracks,sizeof(toc.tracks));
}
+//NOTE: the subcode will come out interleaved.
+//this is almost useless, but it won't always be needed, so we're not deinterleaving it here yet
+//we should probably have more granular control than just reading this one sector eventually
EW_EXPORT int32 mednadisc_ReadSector(MednaDisc* md, int lba, void* buf2448)
{
CDAccess* disc = md->disc;
diff --git a/psx/mednadisc/bizhawk/mednadisc.filters b/psx/mednadisc/bizhawk/mednadisc.filters
deleted file mode 100644
index 72d05a57b3..0000000000
--- a/psx/mednadisc/bizhawk/mednadisc.filters
+++ /dev/null
@@ -1,248 +0,0 @@
-
-
-
-
- {00f73db4-1182-4bf7-b891-66bf860d3742}
-
-
- {f69cc8f2-7480-44d6-9a32-9dca789d2bf6}
-
-
- {57a8e6ec-9225-410d-b38f-ba209abae070}
-
-
- {76abb796-5411-4d33-b3e0-f1f3873f138e}
-
-
- {cb700979-4dce-4b10-8521-3ab71a313271}
-
-
- {d1f71901-17a5-441a-8b4f-f7da34a057c1}
-
-
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
-
- emuware
-
-
- video
-
-
- video
-
-
- emuware
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- cdrom
-
-
-
-
- psx
-
-
- psx
-
-
- emuware
-
-
- psx
-
-
- psx
-
-
-
-
-
- psx
-
-
-
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
- psx\input
-
-
- emuware\msvc
-
-
- emuware\msvc
-
-
- video
-
-
- video
-
-
- emuware
-
-
- cdrom
-
-
- psx
-
-
- psx
-
-
- cdrom
-
-
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
- psx
-
-
-
\ No newline at end of file
diff --git a/psx/mednadisc/bizhawk/mednadisc.vcxproj b/psx/mednadisc/bizhawk/mednadisc.vcxproj
index 1dfd3512b7..f2cbc6f816 100644
--- a/psx/mednadisc/bizhawk/mednadisc.vcxproj
+++ b/psx/mednadisc/bizhawk/mednadisc.vcxproj
@@ -11,10 +11,10 @@
-
+
@@ -30,12 +30,15 @@
+
+
+
-
+
@@ -51,6 +54,7 @@
+
{5F35CAFC-6208-4FBE-AD17-0E69BA3F70EC}
@@ -81,7 +85,7 @@
true
- $(ProjectDir)\..\..\..\output\dll\
+ $(ProjectDir)..\..\..\output\dll\
false
@@ -92,7 +96,7 @@
NotUsing
Level3
Disabled
- EW_EXPORT;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;OCTOSHOCK_EXPORTS;%(PreprocessorDefinitions)
+ TRIO_PUBLIC=;TRIO_PRIVATE=static;EW_EXPORT;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;OCTOSHOCK_EXPORTS;%(PreprocessorDefinitions)
../emuware/msvc;..
diff --git a/psx/mednadisc/bizhawk/mednadisc.vcxproj.filters b/psx/mednadisc/bizhawk/mednadisc.vcxproj.filters
index 9aaf63d447..2b0d826726 100644
--- a/psx/mednadisc/bizhawk/mednadisc.vcxproj.filters
+++ b/psx/mednadisc/bizhawk/mednadisc.vcxproj.filters
@@ -10,6 +10,9 @@
{798fa5bd-6381-487a-99d2-35a15a6da439}
+
+ {a43930f5-41a5-4b2b-92ef-bd90f9716127}
+
@@ -51,10 +54,19 @@
string
-
+
+
+ trio
+
+
cdrom
-
+
+ trio
+
+
+ trio
+
@@ -96,9 +108,12 @@
string
-
+
+
+ trio
+
+
cdrom
-
\ No newline at end of file
diff --git a/psx/mednadisc/cdrom/CDAFReader.cpp b/psx/mednadisc/cdrom/CDAFReader.cpp
new file mode 100644
index 0000000000..37bafe358c
--- /dev/null
+++ b/psx/mednadisc/cdrom/CDAFReader.cpp
@@ -0,0 +1,83 @@
+/* Mednafen - Multi-system Emulator
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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
+ */
+
+// CDAFR_Open(), and CDAFReader, will NOT take "ownership" of the Stream object(IE it won't ever delete it). Though it does assume it has exclusive access
+// to it for as long as the CDAFReader object exists.
+
+// Don't allow exceptions to propagate into the vorbis/musepack/etc. libraries, as it could easily leave the state of the library's decoder "object" in an
+// inconsistent state, which would cause all sorts of unfun when we try to destroy it while handling the exception farther up.
+
+#include "emuware/emuware.h"
+#include "CDAFReader.h"
+#include "CDAFReader_Vorbis.h"
+#include "CDAFReader_MPC.h"
+
+#ifdef HAVE_LIBSNDFILE
+#include "CDAFReader_SF.h"
+#endif
+
+CDAFReader::CDAFReader() : LastReadPos(0)
+{
+
+}
+
+CDAFReader::~CDAFReader()
+{
+
+}
+
+CDAFReader* CDAFR_Null_Open(Stream* fp)
+{
+ return NULL;
+}
+
+CDAFReader *CDAFR_Open(Stream *fp)
+{
+ static CDAFReader* (* const OpenFuncs[])(Stream* fp) =
+ {
+#ifdef HAVE_MPC
+ CDAFR_MPC_Open,
+#endif
+
+#ifdef HAVE_VORBIS
+ CDAFR_Vorbis_Open, // Must come before CDAFR_SF_Open
+#endif
+
+#ifdef HAVE_LIBSNDFILE
+ CDAFR_SF_Open,
+#endif
+
+ CDAFR_Null_Open
+ };
+
+ for(int idx=0;idxrewind();
+ return f(fp);
+ }
+ catch(int i)
+ {
+
+ }
+ }
+
+ return(NULL);
+}
+
diff --git a/psx/mednadisc/cdrom/CDAFReader.h b/psx/mednadisc/cdrom/CDAFReader.h
new file mode 100644
index 0000000000..9ac0880294
--- /dev/null
+++ b/psx/mednadisc/cdrom/CDAFReader.h
@@ -0,0 +1,41 @@
+#ifndef __MDFN_CDAFREADER_H
+#define __MDFN_CDAFREADER_H
+
+#include "Stream.h"
+
+class CDAFReader
+{
+ public:
+ CDAFReader();
+ virtual ~CDAFReader();
+
+ virtual uint64 FrameCount(void) = 0;
+ INLINE uint64 Read(uint64 frame_offset, int16 *buffer, uint64 frames)
+ {
+ uint64 ret;
+
+ if(LastReadPos != frame_offset)
+ {
+ //puts("SEEK");
+ if(!Seek_(frame_offset))
+ return(0);
+ LastReadPos = frame_offset;
+ }
+
+ ret = Read_(buffer, frames);
+ LastReadPos += ret;
+ return(ret);
+ }
+
+ private:
+ virtual uint64 Read_(int16 *buffer, uint64 frames) = 0;
+ virtual bool Seek_(uint64 frame_offset) = 0;
+
+ uint64 LastReadPos;
+};
+
+// AR_Open(), and CDAFReader, will NOT take "ownership" of the Stream object(IE it won't ever delete it). Though it does assume it has exclusive access
+// to it for as long as the CDAFReader object exists.
+CDAFReader *CDAFR_Open(Stream *fp);
+
+#endif
diff --git a/psx/mednadisc/cdrom/CDAFReader_MPC.cpp b/psx/mednadisc/cdrom/CDAFReader_MPC.cpp
new file mode 100644
index 0000000000..3f26026c17
--- /dev/null
+++ b/psx/mednadisc/cdrom/CDAFReader_MPC.cpp
@@ -0,0 +1,238 @@
+/* Mednafen - Multi-system Emulator
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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
+ */
+
+#include
+#include "CDAFReader.h"
+#include "CDAFReader_MPC.h"
+
+#if 0
+ #include
+#else
+ #include
+#endif
+
+class CDAFReader_MPC final : public CDAFReader
+{
+ public:
+ CDAFReader_MPC(Stream *fp);
+ ~CDAFReader_MPC();
+
+ uint64 Read_(int16 *buffer, uint64 frames) override;
+ bool Seek_(uint64 frame_offset) override;
+ uint64 FrameCount(void) override;
+
+ private:
+ mpc_reader reader;
+ mpc_demux *demux;
+ mpc_streaminfo si;
+
+ MPC_SAMPLE_FORMAT MPCBuffer[MPC_DECODER_BUFFER_LENGTH];
+
+ uint32 MPCBufferIn;
+ uint32 MPCBufferOffs;
+ Stream *fw;
+};
+
+
+/// Reads size bytes of data into buffer at ptr.
+static mpc_int32_t impc_read(mpc_reader *p_reader, void *ptr, mpc_int32_t size)
+{
+ Stream *fw = (Stream*)(p_reader->data);
+
+ try
+ {
+ return fw->read(ptr, size, false);
+ }
+ catch(...)
+ {
+ return(MPC_STATUS_FAIL);
+ }
+}
+
+/// Seeks to byte position offset.
+static mpc_bool_t impc_seek(mpc_reader *p_reader, mpc_int32_t offset)
+{
+ Stream *fw = (Stream*)(p_reader->data);
+
+ try
+ {
+ fw->seek(offset, SEEK_SET);
+ return(MPC_TRUE);
+ }
+ catch(...)
+ {
+ return(MPC_FALSE);
+ }
+}
+
+/// Returns the current byte offset in the stream.
+static mpc_int32_t impc_tell(mpc_reader *p_reader)
+{
+ Stream *fw = (Stream*)(p_reader->data);
+
+ try
+ {
+ return fw->tell();
+ }
+ catch(...)
+ {
+ return(MPC_STATUS_FAIL);
+ }
+}
+
+/// Returns the total length of the source stream, in bytes.
+static mpc_int32_t impc_get_size(mpc_reader *p_reader)
+{
+ Stream *fw = (Stream*)(p_reader->data);
+
+ try
+ {
+ return fw->size();
+ }
+ catch(...)
+ {
+ return(MPC_STATUS_FAIL);
+ }
+}
+
+/// True if the stream is a seekable stream.
+static mpc_bool_t impc_canseek(mpc_reader *p_reader)
+{
+ return(MPC_TRUE);
+}
+
+CDAFReader_MPC::CDAFReader_MPC(Stream *fp) : fw(fp)
+{
+ demux = NULL;
+ memset(&si, 0, sizeof(si));
+ memset(MPCBuffer, 0, sizeof(MPCBuffer));
+ MPCBufferOffs = 0;
+ MPCBufferIn = 0;
+
+ memset(&reader, 0, sizeof(reader));
+ reader.read = impc_read;
+ reader.seek = impc_seek;
+ reader.tell = impc_tell;
+ reader.get_size = impc_get_size;
+ reader.canseek = impc_canseek;
+ reader.data = (void*)fp;
+
+ if(!(demux = mpc_demux_init(&reader)))
+ {
+ throw(0);
+ }
+ mpc_demux_get_info(demux, &si);
+
+ if(si.channels != 2)
+ {
+ mpc_demux_exit(demux);
+ demux = NULL;
+ throw MDFN_Error(0, _("MusePack stream has wrong number of channels(%u); the correct number is 2."), si.channels);
+ }
+
+ if(si.sample_freq != 44100)
+ {
+ mpc_demux_exit(demux);
+ demux = NULL;
+ throw MDFN_Error(0, _("MusePack stream has wrong samplerate(%u Hz); the correct samplerate is 44100 Hz."), si.sample_freq);
+ }
+}
+
+CDAFReader_MPC::~CDAFReader_MPC()
+{
+ if(demux)
+ {
+ mpc_demux_exit(demux);
+ demux = NULL;
+ }
+}
+
+uint64 CDAFReader_MPC::Read_(int16 *buffer, uint64 frames)
+{
+ mpc_status err;
+ int16 *cowbuf = (int16 *)buffer;
+ int32 toread = frames * 2;
+
+ while(toread > 0)
+ {
+ int32 tmplen;
+
+ if(!MPCBufferIn)
+ {
+ mpc_frame_info fi;
+ memset(&fi, 0, sizeof(fi));
+
+ fi.buffer = MPCBuffer;
+ if((err = mpc_demux_decode(demux, &fi)) < 0 || fi.bits == -1)
+ return(frames - toread / 2);
+
+ MPCBufferIn = fi.samples * 2;
+ MPCBufferOffs = 0;
+ }
+
+ tmplen = MPCBufferIn;
+
+ if(tmplen >= toread)
+ tmplen = toread;
+
+ for(int x = 0; x < tmplen; x++)
+ {
+#ifdef MPC_FIXED_POINT
+ int32 samp = MPCBuffer[MPCBufferOffs + x] >> MPC_FIXED_POINT_FRACTPART;
+#else
+ #warning Floating-point MPC decoding path not tested.
+ int32 samp = (int32)(MPCBuffer[MPCBufferOffs + x] * 32767);
+#endif
+ if(samp < -32768)
+ samp = -32768;
+
+ if(samp > 32767)
+ samp = 32767;
+
+ *cowbuf = (int16)samp;
+ cowbuf++;
+ }
+
+ MPCBufferOffs += tmplen;
+ toread -= tmplen;
+ MPCBufferIn -= tmplen;
+ }
+
+ return(frames - toread / 2);
+}
+
+bool CDAFReader_MPC::Seek_(uint64 frame_offset)
+{
+ MPCBufferOffs = 0;
+ MPCBufferIn = 0;
+
+ if(mpc_demux_seek_sample(demux, frame_offset) < 0)
+ return(false);
+
+ return(true);
+}
+
+uint64 CDAFReader_MPC::FrameCount(void)
+{
+ return(mpc_streaminfo_get_length_samples(&si));
+}
+
+
+CDAFReader* CDAFR_MPC_Open(Stream* fp)
+{
+ return new CDAFReader_MPC(fp);
+}
diff --git a/psx/mednadisc/cdrom/CDAFReader_MPC.h b/psx/mednadisc/cdrom/CDAFReader_MPC.h
new file mode 100644
index 0000000000..6580fba79c
--- /dev/null
+++ b/psx/mednadisc/cdrom/CDAFReader_MPC.h
@@ -0,0 +1,6 @@
+#ifndef __MDFN_CDAFREADER_MPC_H
+#define __MDFN_CDAFREADER_MPC_H
+
+CDAFReader* CDAFR_MPC_Open(Stream* fp);
+
+#endif
diff --git a/psx/mednadisc/cdrom/CDAFReader_SF.cpp b/psx/mednadisc/cdrom/CDAFReader_SF.cpp
new file mode 100644
index 0000000000..9abc6a6f0d
--- /dev/null
+++ b/psx/mednadisc/cdrom/CDAFReader_SF.cpp
@@ -0,0 +1,155 @@
+/* Mednafen - Multi-system Emulator
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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
+ */
+
+#include
+#include "CDAFReader.h"
+#include "CDAFReader_SF.h"
+
+#include
+
+class CDAFReader_SF final : public CDAFReader
+{
+ public:
+
+ CDAFReader_SF(Stream *fp);
+ ~CDAFReader_SF();
+
+ uint64 Read_(int16 *buffer, uint64 frames) override;
+ bool Seek_(uint64 frame_offset) override;
+ uint64 FrameCount(void) override;
+
+ private:
+ SNDFILE *sf;
+ SF_INFO sfinfo;
+ SF_VIRTUAL_IO sfvf;
+
+ Stream *fw;
+};
+
+static sf_count_t isf_get_filelen(void *user_data)
+{
+ Stream *fw = (Stream*)user_data;
+
+ try
+ {
+ return fw->size();
+ }
+ catch(...)
+ {
+ return(-1);
+ }
+}
+
+static sf_count_t isf_seek(sf_count_t offset, int whence, void *user_data)
+{
+ Stream *fw = (Stream*)user_data;
+
+ try
+ {
+ //printf("Seek: offset=%lld, whence=%lld\n", (long long)offset, (long long)whence);
+
+ fw->seek(offset, whence);
+ return fw->tell();
+ }
+ catch(...)
+ {
+ //printf(" SEEK FAILED\n");
+ return(-1);
+ }
+}
+
+static sf_count_t isf_read(void *ptr, sf_count_t count, void *user_data)
+{
+ Stream *fw = (Stream*)user_data;
+
+ try
+ {
+ sf_count_t ret = fw->read(ptr, count, false);
+
+ //printf("Read: count=%lld, ret=%lld\n", (long long)count, (long long)ret);
+
+ return ret;
+ }
+ catch(...)
+ {
+ //printf(" READ FAILED\n");
+ return(0);
+ }
+}
+
+static sf_count_t isf_write(const void *ptr, sf_count_t count, void *user_data)
+{
+ return(0);
+}
+
+static sf_count_t isf_tell(void *user_data)
+{
+ Stream *fw = (Stream*)user_data;
+
+ try
+ {
+ return fw->tell();
+ }
+ catch(...)
+ {
+ return(-1);
+ }
+}
+
+CDAFReader_SF::CDAFReader_SF(Stream *fp) : fw(fp)
+{
+ memset(&sfvf, 0, sizeof(sfvf));
+ sfvf.get_filelen = isf_get_filelen;
+ sfvf.seek = isf_seek;
+ sfvf.read = isf_read;
+ sfvf.write = isf_write;
+ sfvf.tell = isf_tell;
+
+ memset(&sfinfo, 0, sizeof(sfinfo));
+ if(!(sf = sf_open_virtual(&sfvf, SFM_READ, &sfinfo, (void*)fp)))
+ throw(0);
+}
+
+CDAFReader_SF::~CDAFReader_SF()
+{
+ sf_close(sf);
+}
+
+uint64 CDAFReader_SF::Read_(int16 *buffer, uint64 frames)
+{
+ return(sf_read_short(sf, (short*)buffer, frames * 2) / 2);
+}
+
+bool CDAFReader_SF::Seek_(uint64 frame_offset)
+{
+ // FIXME error condition
+ if((uint64)sf_seek(sf, frame_offset, SEEK_SET) != frame_offset)
+ return(false);
+
+ return(true);
+}
+
+uint64 CDAFReader_SF::FrameCount(void)
+{
+ return(sfinfo.frames);
+}
+
+
+CDAFReader* CDAFR_SF_Open(Stream* fp)
+{
+ return new CDAFReader_SF(fp);
+}
diff --git a/psx/mednadisc/cdrom/CDAFReader_SF.h b/psx/mednadisc/cdrom/CDAFReader_SF.h
new file mode 100644
index 0000000000..2ab145bb37
--- /dev/null
+++ b/psx/mednadisc/cdrom/CDAFReader_SF.h
@@ -0,0 +1,6 @@
+#ifndef __MDFN_CDAFREADER_SF_H
+#define __MDFN_CDAFREADER_SF_H
+
+CDAFReader* CDAFR_SF_Open(Stream* fp);
+
+#endif
diff --git a/psx/mednadisc/cdrom/CDAFReader_Vorbis.cpp b/psx/mednadisc/cdrom/CDAFReader_Vorbis.cpp
new file mode 100644
index 0000000000..5975b215b2
--- /dev/null
+++ b/psx/mednadisc/cdrom/CDAFReader_Vorbis.cpp
@@ -0,0 +1,158 @@
+/* Mednafen - Multi-system Emulator
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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
+ */
+
+#include
+#include "CDAFReader.h"
+#include "CDAFReader_Vorbis.h"
+
+#if 0
+ #include
+#else
+ #include
+#endif
+
+class CDAFReader_Vorbis final : public CDAFReader
+{
+ public:
+ CDAFReader_Vorbis(Stream *fp);
+ ~CDAFReader_Vorbis();
+
+ uint64 Read_(int16 *buffer, uint64 frames) override;
+ bool Seek_(uint64 frame_offset) override;
+ uint64 FrameCount(void) override;
+
+ private:
+ OggVorbis_File ovfile;
+ Stream *fw;
+};
+
+
+static size_t iov_read_func(void *ptr, size_t size, size_t nmemb, void *user_data)
+{
+ Stream *fw = (Stream*)user_data;
+
+ if(!size)
+ return(0);
+
+ try
+ {
+ return fw->read(ptr, size * nmemb, false) / size;
+ }
+ catch(...)
+ {
+ return(0);
+ }
+}
+
+static int iov_seek_func(void *user_data, ogg_int64_t offset, int whence)
+{
+ Stream *fw = (Stream*)user_data;
+
+ try
+ {
+ fw->seek(offset, whence);
+ return(0);
+ }
+ catch(...)
+ {
+ return(-1);
+ }
+}
+
+static int iov_close_func(void *user_data)
+{
+ Stream *fw = (Stream*)user_data;
+
+ try
+ {
+ fw->close();
+ return(0);
+ }
+ catch(...)
+ {
+ return EOF;
+ }
+}
+
+static long iov_tell_func(void *user_data)
+{
+ Stream *fw = (Stream*)user_data;
+
+ try
+ {
+ return fw->tell();
+ }
+ catch(...)
+ {
+ return(-1);
+ }
+}
+
+CDAFReader_Vorbis::CDAFReader_Vorbis(Stream *fp) : fw(fp)
+{
+ ov_callbacks cb;
+
+ memset(&cb, 0, sizeof(cb));
+ cb.read_func = iov_read_func;
+ cb.seek_func = iov_seek_func;
+ cb.close_func = iov_close_func;
+ cb.tell_func = iov_tell_func;
+
+ if(ov_open_callbacks(fp, &ovfile, NULL, 0, cb))
+ throw(0);
+}
+
+CDAFReader_Vorbis::~CDAFReader_Vorbis()
+{
+ ov_clear(&ovfile);
+}
+
+uint64 CDAFReader_Vorbis::Read_(int16 *buffer, uint64 frames)
+{
+ uint8 *tw_buf = (uint8 *)buffer;
+ int cursection = 0;
+ long toread = frames * sizeof(int16) * 2;
+
+ while(toread > 0)
+ {
+ long didread = ov_read(&ovfile, (char*)tw_buf, toread, &cursection);
+
+ if(didread == 0)
+ break;
+
+ tw_buf = (uint8 *)tw_buf + didread;
+ toread -= didread;
+ }
+
+ return(frames - toread / sizeof(int16) / 2);
+}
+
+bool CDAFReader_Vorbis::Seek_(uint64 frame_offset)
+{
+ ov_pcm_seek(&ovfile, frame_offset);
+ return(true);
+}
+
+uint64 CDAFReader_Vorbis::FrameCount(void)
+{
+ return(ov_pcm_total(&ovfile, -1));
+}
+
+CDAFReader* CDAFR_Vorbis_Open(Stream* fp)
+{
+ return new CDAFReader_Vorbis(fp);
+}
diff --git a/psx/mednadisc/cdrom/CDAFReader_Vorbis.h b/psx/mednadisc/cdrom/CDAFReader_Vorbis.h
new file mode 100644
index 0000000000..f4a8c55b4f
--- /dev/null
+++ b/psx/mednadisc/cdrom/CDAFReader_Vorbis.h
@@ -0,0 +1,7 @@
+#ifndef __MDFN_CDAFREADER_VORBIS_H
+#define __MDFN_CDAFREADER_VORBIS_H
+
+CDAFReader* CDAFR_Vorbis_Open(Stream* fp);
+
+#endif
+
diff --git a/psx/mednadisc/cdrom/CDAccess.cpp b/psx/mednadisc/cdrom/CDAccess.cpp
index 641fc4c4ae..14cf659adf 100644
--- a/psx/mednadisc/cdrom/CDAccess.cpp
+++ b/psx/mednadisc/cdrom/CDAccess.cpp
@@ -1,58 +1,46 @@
-/* Mednafen - Multi-system Emulator
- *
- * 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.
- *
- * 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.
- *
- * 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
- */
-
-#include "emuware/emuware.h"
-#include "CDAccess.h"
-#include "CDAccess_Image.h"
-#include "CDAccess_CCD.h"
-
-#ifdef HAVE_LIBCDIO
-#include "CDAccess_Physical.h"
-#endif
-
-using namespace CDUtility;
-
-CDAccess::CDAccess()
-{
-
-}
-
-CDAccess::~CDAccess()
-{
-
-}
-
-CDAccess *cdaccess_open_image(const std::string& path, bool image_memcache)
-{
- CDAccess *ret = NULL;
-
- if(path.size() >= 4 && !strcasecmp(path.c_str() + path.size() - 4, ".ccd"))
- ret = new CDAccess_CCD(path, image_memcache);
- else
- ret = new CDAccess_Image(path, image_memcache);
-
- return ret;
-}
-
-CDAccess *cdaccess_open_phys(const std::string& devicename)
-{
- #ifdef HAVE_LIBCDIO
- return new CDAccess_Physical(devicename);
- #else
- throw MDFN_Error(0, ("Physical CD access support not compiled in."));
- #endif
-}
+/* Mednafen - Multi-system Emulator
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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
+ */
+
+#include "emuware/emuware.h"
+#include "CDAccess.h"
+#include "CDAccess_Image.h"
+#include "CDAccess_CCD.h"
+
+using namespace CDUtility;
+
+CDAccess::CDAccess()
+{
+
+}
+
+CDAccess::~CDAccess()
+{
+
+}
+
+CDAccess* CDAccess_Open(const std::string& path, bool image_memcache)
+{
+ CDAccess *ret = NULL;
+
+ if(path.size() >= 4 && !strcasecmp(path.c_str() + path.size() - 4, ".ccd"))
+ ret = new CDAccess_CCD(path, image_memcache);
+ else
+ ret = new CDAccess_Image(path, image_memcache);
+
+ return ret;
+}
+
diff --git a/psx/mednadisc/cdrom/CDAccess.h b/psx/mednadisc/cdrom/CDAccess.h
index 667c6b8b66..fd4338d15e 100644
--- a/psx/mednadisc/cdrom/CDAccess.h
+++ b/psx/mednadisc/cdrom/CDAccess.h
@@ -1,32 +1,33 @@
-#ifndef __MDFN_CDROMFILE_H
-#define __MDFN_CDROMFILE_H
-
-#include
-#include
-
-#include "CDUtility.h"
-
-class CDAccess
-{
- public:
-
- CDAccess();
- virtual ~CDAccess();
-
- virtual void Read_Raw_Sector(uint8 *buf, int32 lba) = 0;
-
- virtual void Read_TOC(CDUtility::TOC *toc) = 0;
-
- virtual bool Is_Physical(void) throw() = 0;
-
- virtual void Eject(bool eject_status) = 0; // Eject a disc if it's physical, otherwise NOP. Returns true on success(or NOP), false on error
-
- private:
- CDAccess(const CDAccess&); // No copy constructor.
- CDAccess& operator=(const CDAccess&); // No assignment operator.
-};
-
-CDAccess *cdaccess_open_image(const std::string& path, bool image_memcache);
-CDAccess *cdaccess_open_phys(const std::string& devicename);
-
-#endif
+#ifndef __MDFN_CDROMFILE_H
+#define __MDFN_CDROMFILE_H
+
+#include
+#include
+
+#include "CDUtility.h"
+
+class CDAccess
+{
+ public:
+
+ CDAccess();
+ virtual ~CDAccess();
+
+ virtual void Read_Raw_Sector(uint8 *buf, int32 lba) = 0;
+
+ // Returns false if the read wouldn't be "fast"(i.e. reading from a disk),
+ // or if the read can't be done in a thread-safe re-entrant manner.
+ //
+ // Writes 96 bytes into pwbuf, and returns 'true' otherwise.
+ virtual bool Fast_Read_Raw_PW_TSRE(uint8* pwbuf, int32 lba) const noexcept = 0;
+
+ virtual void Read_TOC(CDUtility::TOC *toc) = 0;
+
+ private:
+ CDAccess(const CDAccess&); // No copy constructor.
+ CDAccess& operator=(const CDAccess&); // No assignment operator.
+};
+
+CDAccess* CDAccess_Open(const std::string& path, bool image_memcache);
+
+#endif
diff --git a/psx/mednadisc/cdrom/CDAccess_CCD.cpp b/psx/mednadisc/cdrom/CDAccess_CCD.cpp
index 6817a20d03..0ec073e17d 100644
--- a/psx/mednadisc/cdrom/CDAccess_CCD.cpp
+++ b/psx/mednadisc/cdrom/CDAccess_CCD.cpp
@@ -1,435 +1,432 @@
-/* Mednafen - Multi-system Emulator
- *
- * 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.
- *
- * 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.
- *
- * 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
- */
-
-#include "emuware/emuware.h"
-#include "../general.h"
-#include "../string/trim.h"
-#include "CDAccess_CCD.h"
-//#include
-
-//wrapper to repair gettext stuff
-#define _(X) X
-
-#include
-#include
-#include