mirror of
https://github.com/libretro/beetle-pce-fast-libretro.git
synced 2024-11-23 07:50:03 +00:00
replace the FileStream class by macros.
This commit is contained in:
parent
cd10ea1314
commit
09894a7cae
1
Makefile
1
Makefile
@ -207,7 +207,6 @@ OBJECTS += $(CORE_DIR)/cdrom/cdromif.o
|
||||
#mednafen
|
||||
OBJECTS += $(MEDNAFEN_DIR)/settings.o
|
||||
OBJECTS += $(MEDNAFEN_DIR)/general.o
|
||||
OBJECTS += $(MEDNAFEN_DIR)/FileStream.o
|
||||
OBJECTS += $(MEDNAFEN_DIR)/state.o
|
||||
OBJECTS += $(MEDNAFEN_DIR)/endian.o
|
||||
#okiadpcm
|
||||
|
@ -87,7 +87,7 @@ CDAccess_CCD::CDAccess_CCD(const char* path) : img_stream(NULL),
|
||||
|
||||
void CDAccess_CCD::Load(const char* path)
|
||||
{
|
||||
FileStream cf(path);
|
||||
FSTREAM_ID cf = FSTREAM_OPEN(path);
|
||||
std::map<std::string, CCD_Section> Sections;
|
||||
std::string linebuf;
|
||||
std::string cur_section_name;
|
||||
@ -138,7 +138,7 @@ void CDAccess_CCD::Load(const char* path)
|
||||
|
||||
linebuf.reserve(256);
|
||||
|
||||
while (cf.get_line(linebuf) >= 0)
|
||||
while (get_line(cf, linebuf) >= 0)
|
||||
{
|
||||
MDFN_trim(linebuf);
|
||||
|
||||
@ -174,6 +174,8 @@ void CDAccess_CCD::Load(const char* path)
|
||||
}
|
||||
}
|
||||
|
||||
FSTREAM_CLOSE(cf);
|
||||
|
||||
{
|
||||
CCD_Section &ds = Sections["DISC"];
|
||||
unsigned toc_entries = CCD_ReadInt<unsigned>(ds, "TOCENTRIES");
|
||||
@ -345,9 +347,9 @@ void CDAccess_CCD::Load(const char* path)
|
||||
std::string image_path = MDFN_EvalFIP(dir_path,
|
||||
file_base + std::string(".") + std::string(img_extsd));
|
||||
|
||||
img_stream = new FileStream(image_path.c_str());
|
||||
img_stream = FSTREAM_OPEN(image_path.c_str()); // TODO: close stream on deinit
|
||||
|
||||
int64 ss = img_stream->size();
|
||||
int64 ss = FSTREAM_SIZE(img_stream);
|
||||
|
||||
assert(!(ss % 2352));
|
||||
// throw MDFN_Error(0, ("CCD image size is not evenly divisible by 2352."));
|
||||
@ -361,11 +363,12 @@ void CDAccess_CCD::Load(const char* path)
|
||||
std::string sub_path = MDFN_EvalFIP(dir_path,
|
||||
file_base + std::string(".") + std::string(sub_extsd));
|
||||
|
||||
sub_stream = new FileStream(sub_path.c_str());
|
||||
sub_stream = FSTREAM_OPEN(sub_path.c_str()); // TODO: close stream on deinit
|
||||
|
||||
assert(sub_stream->size() == (int64)img_numsectors * 96);
|
||||
assert(FSTREAM_SIZE(sub_stream) == (int64)img_numsectors * 96);
|
||||
// throw MDFN_Error(0, ("CCD SUB file size mismatch."));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CDAccess_CCD::Cleanup(void)
|
||||
@ -413,11 +416,11 @@ void CDAccess_CCD::Read_Raw_Sector(uint8* buf, int32 lba)
|
||||
|
||||
uint8 sub_buf[96];
|
||||
|
||||
img_stream->seek(lba * 2352, SEEK_SET);
|
||||
img_stream->read(buf, 2352);
|
||||
FSTREAM_SEEK(img_stream, lba * 2352, SEEK_SET);
|
||||
FSTREAM_READ(buf, 2352, img_stream);
|
||||
|
||||
sub_stream->seek(lba * 96, SEEK_SET);
|
||||
sub_stream->read(sub_buf, 96);
|
||||
FSTREAM_SEEK(sub_stream, lba * 96, SEEK_SET);
|
||||
FSTREAM_READ(sub_buf, 96, sub_stream);
|
||||
|
||||
subpw_interleave(sub_buf, buf + 2352);
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ public:
|
||||
void Load(const char* path);
|
||||
void Cleanup(void);
|
||||
|
||||
FileStream* img_stream;
|
||||
FileStream* sub_stream;
|
||||
FSTREAM_ID img_stream;
|
||||
FSTREAM_ID sub_stream;
|
||||
size_t img_numsectors;
|
||||
CDUtility_TOC tocd;
|
||||
};
|
||||
|
@ -167,7 +167,7 @@ uint32 CDAccess_Image::GetSectorCount(CDRFILE_TRACK_INFO* track)
|
||||
{
|
||||
if (track->DIFormat == DI_FORMAT_AUDIO)
|
||||
{
|
||||
const int64 size = track->fp->size();
|
||||
const int64 size = FSTREAM_SIZE(track->fp);
|
||||
|
||||
//printf("%d %d %d\n", (int)stat_buf.st_size, (int)track->FileOffset, (int)stat_buf.st_size - (int)track->FileOffset);
|
||||
if (track->SubchannelMode)
|
||||
@ -177,7 +177,7 @@ uint32 CDAccess_Image::GetSectorCount(CDRFILE_TRACK_INFO* track)
|
||||
}
|
||||
else
|
||||
{
|
||||
const int64 size = track->fp->size();
|
||||
const int64 size = FSTREAM_SIZE(track->fp);
|
||||
|
||||
return ((size - track->FileOffset) / DI_Size_Table[track->DIFormat]);
|
||||
}
|
||||
@ -188,14 +188,14 @@ uint32 CDAccess_Image::GetSectorCount(CDRFILE_TRACK_INFO* track)
|
||||
void CDAccess_Image::ParseTOCFileLineInfo(CDRFILE_TRACK_INFO* track,
|
||||
const int tracknum, const std::string &filename, const char* binoffset,
|
||||
const char* msfoffset, const char* length,
|
||||
std::map<std::string, FileStream*> &toc_streamcache)
|
||||
std::map<std::string, FSTREAM_ID> &toc_streamcache)
|
||||
{
|
||||
long offset = 0; // In bytes!
|
||||
long tmp_long;
|
||||
int m, s, f;
|
||||
uint32 sector_mult;
|
||||
long sectors;
|
||||
std::map<std::string, FileStream*>::iterator ribbit;
|
||||
std::map<std::string, FSTREAM_ID>::iterator ribbit;
|
||||
|
||||
ribbit = toc_streamcache.find(filename);
|
||||
|
||||
@ -213,7 +213,7 @@ void CDAccess_Image::ParseTOCFileLineInfo(CDRFILE_TRACK_INFO* track,
|
||||
|
||||
efn = MDFN_EvalFIP(base_dir, filename);
|
||||
|
||||
track->fp = new FileStream(efn.c_str());
|
||||
track->fp = FSTREAM_OPEN(efn.c_str());
|
||||
|
||||
toc_streamcache[filename] = track->fp;
|
||||
}
|
||||
@ -267,7 +267,7 @@ void CDAccess_Image::ParseTOCFileLineInfo(CDRFILE_TRACK_INFO* track,
|
||||
|
||||
void CDAccess_Image::ImageOpen(const char* path)
|
||||
{
|
||||
FileStream fp(path);
|
||||
FSTREAM_ID fp = FSTREAM_OPEN(path);
|
||||
static const unsigned max_args = 4;
|
||||
std::string linebuf;
|
||||
std::string cmdbuf, args[max_args];
|
||||
@ -276,7 +276,7 @@ void CDAccess_Image::ImageOpen(const char* path)
|
||||
int32 AutoTrackInc = 1; // For TOC
|
||||
CDRFILE_TRACK_INFO TmpTrack;
|
||||
std::string file_base, file_ext;
|
||||
std::map<std::string, FileStream*> toc_streamcache;
|
||||
std::map<std::string, FSTREAM_ID> toc_streamcache;
|
||||
|
||||
disc_type = DISC_TYPE_CDDA_OR_M1;
|
||||
memset(&TmpTrack, 0, sizeof(TmpTrack));
|
||||
@ -294,14 +294,14 @@ void CDAccess_Image::ImageOpen(const char* path)
|
||||
{
|
||||
uint8 bom_tmp[3];
|
||||
|
||||
if (fp.read(bom_tmp, 3, false) == 3 && bom_tmp[0] == 0xEF && bom_tmp[1] == 0xBB
|
||||
if (FSTREAM_READ(bom_tmp, 3, fp) == 3 && bom_tmp[0] == 0xEF && bom_tmp[1] == 0xBB
|
||||
&& bom_tmp[2] == 0xBF)
|
||||
{
|
||||
// Print an annoying error message, but don't actually error out.
|
||||
MDFN_PrintError(("UTF-8 BOM detected at start of CUE sheet."));
|
||||
}
|
||||
else
|
||||
fp.seek(0, SEEK_SET);
|
||||
FSTREAM_SEEK(fp, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
|
||||
@ -310,7 +310,7 @@ void CDAccess_Image::ImageOpen(const char* path)
|
||||
LastTrack = 0;
|
||||
|
||||
linebuf.reserve(1024);
|
||||
while (fp.get_line(linebuf) >= 0)
|
||||
while (get_line(fp, linebuf) >= 0)
|
||||
{
|
||||
unsigned argcount = 0;
|
||||
|
||||
@ -514,7 +514,7 @@ void CDAccess_Image::ImageOpen(const char* path)
|
||||
}
|
||||
|
||||
std::string efn = MDFN_EvalFIP(base_dir, args[0]);
|
||||
TmpTrack.fp = new FileStream(efn.c_str());
|
||||
TmpTrack.fp = FSTREAM_OPEN(efn.c_str()); // TODO: close those too on deinit
|
||||
TmpTrack.FirstFileInstance = 1;
|
||||
|
||||
assert(!strcasecmp(args[1].c_str(), "BINARY"));
|
||||
@ -735,6 +735,8 @@ void CDAccess_Image::ImageOpen(const char* path)
|
||||
} // end to track loop
|
||||
|
||||
total_sectors = RunningLBA;
|
||||
|
||||
FSTREAM_CLOSE(fp);
|
||||
}
|
||||
|
||||
void CDAccess_Image::Cleanup(void)
|
||||
@ -800,29 +802,29 @@ void CDAccess_Image::Read_Raw_Sector(uint8* buf, int32 lba)
|
||||
if (ct->SubchannelMode)
|
||||
SeekPos += 96 * (lba - ct->LBA);
|
||||
|
||||
ct->fp->seek(SeekPos, SEEK_SET);
|
||||
FSTREAM_SEEK(ct->fp, SeekPos, SEEK_SET);
|
||||
|
||||
switch (ct->DIFormat)
|
||||
{
|
||||
case DI_FORMAT_AUDIO:
|
||||
ct->fp->read(buf, 2352);
|
||||
FSTREAM_READ(buf, 2352, ct->fp);
|
||||
|
||||
if (ct->RawAudioMSBFirst)
|
||||
Endian_A16_Swap(buf, 588 * 2);
|
||||
break;
|
||||
|
||||
case DI_FORMAT_MODE1:
|
||||
ct->fp->read(buf + 12 + 3 + 1, 2048);
|
||||
FSTREAM_READ(buf + 12 + 3 + 1, 2048, ct->fp);
|
||||
// encode_mode1_sector(lba + 150, buf);
|
||||
break;
|
||||
|
||||
case DI_FORMAT_MODE1_RAW:
|
||||
case DI_FORMAT_MODE2_RAW:
|
||||
ct->fp->read(buf, 2352);
|
||||
FSTREAM_READ(buf, 2352, ct->fp);
|
||||
break;
|
||||
|
||||
case DI_FORMAT_MODE2:
|
||||
ct->fp->read(buf + 16, 2336);
|
||||
FSTREAM_READ(buf + 16, 2336, ct->fp);
|
||||
// encode_mode2_sector(lba + 150, buf);
|
||||
break;
|
||||
|
||||
@ -830,19 +832,19 @@ void CDAccess_Image::Read_Raw_Sector(uint8* buf, int32 lba)
|
||||
// FIXME: M2F1, M2F2, does sub-header come before or after user data(standards say before, but I wonder
|
||||
// about cdrdao...).
|
||||
case DI_FORMAT_MODE2_FORM1:
|
||||
ct->fp->read(buf + 24, 2048);
|
||||
FSTREAM_READ(buf + 24, 2048, ct->fp);
|
||||
//encode_mode2_form1_sector(lba + 150, buf);
|
||||
break;
|
||||
|
||||
case DI_FORMAT_MODE2_FORM2:
|
||||
ct->fp->read(buf + 24, 2324);
|
||||
FSTREAM_READ(buf + 24, 2324, ct->fp);
|
||||
//encode_mode2_form2_sector(lba + 150, buf);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (ct->SubchannelMode)
|
||||
ct->fp->read(buf + 2352, 96);
|
||||
FSTREAM_READ(buf + 2352, 96, ct->fp);
|
||||
|
||||
} // end if audible part of audio track read.
|
||||
break;
|
||||
|
@ -20,7 +20,7 @@ struct CDRFILE_TRACK_INFO
|
||||
int32 index[2];
|
||||
|
||||
int32 sectors; // Not including pregap sectors!
|
||||
FileStream* fp;
|
||||
FSTREAM_ID fp;
|
||||
bool FirstFileInstance;
|
||||
bool RawAudioMSBFirst;
|
||||
long FileOffset;
|
||||
@ -55,7 +55,7 @@ public:
|
||||
|
||||
void ParseTOCFileLineInfo(CDRFILE_TRACK_INFO* track, const int tracknum,
|
||||
const std::string &filename, const char* binoffset, const char* msfoffset,
|
||||
const char* length, std::map<std::string, FileStream*> &toc_streamcache);
|
||||
const char* length, std::map<std::string, FSTREAM_ID> &toc_streamcache);
|
||||
uint32 GetSectorCount(CDRFILE_TRACK_INFO* track);
|
||||
};
|
||||
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include "CDUtility.h"
|
||||
|
||||
//#include <queue>
|
||||
|
||||
typedef CDUtility_TOC CD_TOC;
|
||||
|
||||
class CDIF
|
||||
|
@ -1,101 +0,0 @@
|
||||
// TODO/WIP
|
||||
|
||||
/* 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 <sys/stat.h>
|
||||
#include "mednafen.h"
|
||||
#include "FileStream.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define fseeko fseek
|
||||
#define ftello ftell
|
||||
|
||||
FileStream::FileStream(const char *path)
|
||||
{
|
||||
fp = fopen(path, "rb");
|
||||
|
||||
assert(fp);
|
||||
// throw(MDFN_Error(ene.Errno(), ("Error opening file %s"), ene.StrError()));
|
||||
}
|
||||
|
||||
FileStream::~FileStream()
|
||||
{
|
||||
}
|
||||
|
||||
uint64 FileStream::read(void *data, uint64 count, bool error_on_eos)
|
||||
{
|
||||
return fread(data, 1, count, fp);
|
||||
}
|
||||
|
||||
void FileStream::write(const void *data, uint64 count)
|
||||
{
|
||||
fwrite(data, 1, count, fp);
|
||||
}
|
||||
|
||||
void FileStream::seek(int64 offset, int whence)
|
||||
{
|
||||
fseeko(fp, offset, whence);
|
||||
}
|
||||
|
||||
int64 FileStream::tell(void)
|
||||
{
|
||||
return ftello(fp);
|
||||
}
|
||||
|
||||
int64 FileStream::size(void)
|
||||
{
|
||||
struct stat buf;
|
||||
|
||||
fstat(fileno(fp), &buf);
|
||||
|
||||
return(buf.st_size);
|
||||
}
|
||||
|
||||
void FileStream::close(void)
|
||||
{
|
||||
if(!fp)
|
||||
return;
|
||||
|
||||
FILE *tmp = fp;
|
||||
fp = NULL;
|
||||
fclose(tmp);
|
||||
}
|
||||
int FileStream::get_line(std::string &str)
|
||||
{
|
||||
uint8 c;
|
||||
|
||||
str.clear(); // or str.resize(0)??
|
||||
|
||||
while(read(&c, sizeof(c), false) > 0)
|
||||
{
|
||||
if(c == '\r' || c == '\n' || c == 0)
|
||||
return(c);
|
||||
|
||||
str.push_back(c);
|
||||
}
|
||||
|
||||
return(-1);
|
||||
}
|
@ -20,28 +20,46 @@
|
||||
#ifndef __MDFN_FILESTREAM_H
|
||||
#define __MDFN_FILESTREAM_H
|
||||
|
||||
#ifdef PSP
|
||||
#include <pspiofilemgr.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include "mednafen-types.h"
|
||||
|
||||
class FileStream
|
||||
typedef FILE* FSTREAM_ID;
|
||||
|
||||
static inline long int fsize(FILE* fp)
|
||||
{
|
||||
public:
|
||||
long int curr_pos, size;
|
||||
curr_pos = ftell(fp);
|
||||
fseek(fp,0,SEEK_END);
|
||||
size = ftell(fp);
|
||||
fseek(fp,curr_pos,SEEK_SET);
|
||||
return size;
|
||||
}
|
||||
|
||||
FileStream(const char *path);
|
||||
~FileStream();
|
||||
|
||||
uint64 read(void *data, uint64 count, bool error_on_eos = true);
|
||||
void write(const void *data, uint64 count);
|
||||
void seek(int64 offset, int whence);
|
||||
int64 tell(void);
|
||||
int64 size(void);
|
||||
void close(void);
|
||||
int get_line(std::string &str);
|
||||
#define FSTREAM_OPEN(path) fopen((path), "rb")
|
||||
#define FSTREAM_READ(data, count, fp) fread((data), 1, (count), (fp))
|
||||
#define FSTREAM_SEEK(fp, offset, whence) fseek((fp), (offset), (whence))
|
||||
#define FSTREAM_TELL(fp) ftell(fp)
|
||||
#define FSTREAM_SIZE(fp) fsize(fp)
|
||||
#define FSTREAM_CLOSE(fp) fclose(fp)
|
||||
|
||||
FILE *fp;
|
||||
};
|
||||
static inline int get_line(FSTREAM_ID fp, std::string &str)
|
||||
{
|
||||
uint8 c;
|
||||
|
||||
str.clear(); // or str.resize(0)??
|
||||
|
||||
while(FSTREAM_READ(&c, 1, fp) > 0)
|
||||
{
|
||||
if(c == '\r' || c == '\n' || c == 0)
|
||||
return(c);
|
||||
|
||||
str.push_back(c);
|
||||
}
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user