From f53ff5ec4eea5f716cf92c3c1e7366c1ac8bea24 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 20 Nov 2012 22:08:57 +0100 Subject: [PATCH] (Mednafen PSX) Gets around 'exits' caused by exception throwing on consoles - starts up TOC-based CD images now on consoles --- mednafen/cdrom/CDAccess_Image.cpp | 24 ++++++++++++++++++++---- mednafen/cdrom/CDAccess_Image.h | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/mednafen/cdrom/CDAccess_Image.cpp b/mednafen/cdrom/CDAccess_Image.cpp index 14f070b..c4b5fef 100644 --- a/mednafen/cdrom/CDAccess_Image.cpp +++ b/mednafen/cdrom/CDAccess_Image.cpp @@ -185,7 +185,7 @@ uint32 CDAccess_Image::GetSectorCount(CDRFILE_TRACK_INFO *track) return(0); } -void CDAccess_Image::ParseTOCFileLineInfo(CDRFILE_TRACK_INFO *track, const int tracknum, const char *filename, const char *binoffset, const char *msfoffset, const char *length, bool image_memcache) +bool CDAccess_Image::ParseTOCFileLineInfo(CDRFILE_TRACK_INFO *track, const int tracknum, const char *filename, const char *binoffset, const char *msfoffset, const char *length, bool image_memcache) { long offset = 0; // In bytes! long tmp_long; @@ -195,6 +195,16 @@ void CDAccess_Image::ParseTOCFileLineInfo(CDRFILE_TRACK_INFO *track, const int t std::string efn; efn = MDFN_EvalFIP(base_dir, filename); + + FILE *dummy = fopen(efn.c_str(), "rb"); + + // test if file exists - if not exit prematurely + + if(dummy) + fclose(dummy); + else + return false; + track->fp = new FileStream(efn.c_str(), FileStream::MODE_READ); if(MDFN_GetSettingB("libretro.cd_load_into_ram")) track->fp = new MemoryStream(track->fp); @@ -204,7 +214,10 @@ void CDAccess_Image::ParseTOCFileLineInfo(CDRFILE_TRACK_INFO *track, const int t track->AReader = AR_Open(track->fp); if(!track->AReader) - throw MDFN_Error(0, "TODO ERROR"); + { + fprintf(stderr, "TODO ERROR.\n"); + return false; + } } sector_mult = DI_Size_Table[track->DIFormat]; @@ -250,13 +263,16 @@ void CDAccess_Image::ParseTOCFileLineInfo(CDRFILE_TRACK_INFO *track, const int t if(tmp_long > sectors) { - throw MDFN_Error(0, _("Length specified in TOC file for track %d is too large by %ld sectors!\n"), tracknum, (long)(tmp_long - sectors)); + fprintf(stderr, "Length specified in TOC file for track %d is too large by %ld sectors!\n", tracknum, (long)(tmp_long - sectors)); + return false; } sectors = tmp_long; } track->FirstFileInstance = 1; track->sectors = sectors; + + return true; } @@ -814,7 +830,7 @@ void CDAccess_Image::Read_Raw_Sector(uint8 *buf, int32 lba) if(!TrackFound) { - throw(MDFN_Error(0, _("Could not find track for sector %u!"), lba)); + fprintf(stderr, "Could not find track for sector %u!\n", lba); } } diff --git a/mednafen/cdrom/CDAccess_Image.h b/mednafen/cdrom/CDAccess_Image.h index 9429d0b..f56e06b 100644 --- a/mednafen/cdrom/CDAccess_Image.h +++ b/mednafen/cdrom/CDAccess_Image.h @@ -60,7 +60,7 @@ class CDAccess_Image : public CDAccess // MakeSubPQ will OR the simulated P and Q subchannel data into SubPWBuf. void MakeSubPQ(int32 lba, uint8 *SubPWBuf); - void ParseTOCFileLineInfo(CDRFILE_TRACK_INFO *track, const int tracknum, const char *filename, const char *binoffset, const char *msfoffset, const char *length, bool image_memcache); + bool ParseTOCFileLineInfo(CDRFILE_TRACK_INFO *track, const int tracknum, const char *filename, const char *binoffset, const char *msfoffset, const char *length, bool image_memcache); uint32 GetSectorCount(CDRFILE_TRACK_INFO *track); };