From 655ce26b3f09628d9408a4d82efe3a26116999fe Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 13 Sep 2008 16:51:46 +0000 Subject: Big patch changing the signature of various Stream methods (some ports may need to be slightly tweaked to fix overloading errors/warnings) svn-id: r34514 --- backends/platform/ps2/savefile.cpp | 23 +++++++++++++---------- backends/platform/ps2/savefile.h | 20 ++++++++++---------- 2 files changed, 23 insertions(+), 20 deletions(-) (limited to 'backends/platform/ps2') diff --git a/backends/platform/ps2/savefile.cpp b/backends/platform/ps2/savefile.cpp index 5ee724cd3f..7d45aabda7 100644 --- a/backends/platform/ps2/savefile.cpp +++ b/backends/platform/ps2/savefile.cpp @@ -112,24 +112,26 @@ bool UclInSaveFile::eos(void) const { return bufTell() == bufSize(); } -uint32 UclInSaveFile::pos(void) const { +int32 UclInSaveFile::pos(void) const { return bufTell(); } -uint32 UclInSaveFile::size(void) const { +int32 UclInSaveFile::size(void) const { return bufSize(); } -void UclInSaveFile::seek(int pos, int whence) { +bool UclInSaveFile::seek(int pos, int whence) { bufSeek(pos, whence); + return true; } uint32 UclInSaveFile::read(void *ptr, uint32 size) { return (uint32)bufRead(ptr, (int)size); } -void UclInSaveFile::skip(uint32 offset) { +bool UclInSaveFile::skip(uint32 offset) { bufSeek(offset, SEEK_CUR); + return true;s } UclOutSaveFile::UclOutSaveFile(const char *filename, OSystem_PS2 *system, Gs2dScreen *screen, McAccess *mc) : RawWriteFile(mc) { @@ -168,12 +170,12 @@ void UclOutSaveFile::clearIOFailed(void) { _ioFailed = false; } -void UclOutSaveFile::flush(void) { +bool UclOutSaveFile::flush(void) { if (_pos != 0) { if (_wasFlushed) { printf("Multiple calls to UclOutSaveFile::flush!\n"); _ioFailed = true; - return; + return false; } uint32 compSize = _pos * 2; uint8 *compBuf = (uint8*)memalign(64, compSize + 8); @@ -193,6 +195,7 @@ void UclOutSaveFile::flush(void) { } _wasFlushed = true; } + return true; } /* ----------------------------------------- Glue Classes for POSIX Memory Card Access ----------------------------------------- */ @@ -216,11 +219,11 @@ uint32 Ps2McReadFile::write(const void *src, uint32 len) { return 0; } -uint32 Ps2McReadFile::tell(void) { +int32 Ps2McReadFile::tell(void) { return bufTell(); } -uint32 Ps2McReadFile::size(void) { +int32 Ps2McReadFile::size(void) { return bufSize(); } @@ -253,11 +256,11 @@ uint32 Ps2McWriteFile::write(const void *src, uint32 len) { return len; } -uint32 Ps2McWriteFile::tell(void) { +int32 Ps2McWriteFile::tell(void) { return bufTell(); } -uint32 Ps2McWriteFile::size(void) { +int32 Ps2McWriteFile::size(void) { return bufTell(); } diff --git a/backends/platform/ps2/savefile.h b/backends/platform/ps2/savefile.h index 4832b8c3fe..fd09c823d0 100644 --- a/backends/platform/ps2/savefile.h +++ b/backends/platform/ps2/savefile.h @@ -41,7 +41,7 @@ public: UclOutSaveFile(const char *filename, OSystem_PS2 *system, Gs2dScreen *screen, McAccess *mc); virtual ~UclOutSaveFile(void); virtual uint32 write(const void *ptr, uint32 size); - virtual void flush(void); + virtual bool flush(void); virtual bool ioFailed(void) const; virtual void clearIOFailed(void); private: @@ -60,11 +60,11 @@ public: virtual uint32 read(void *ptr, uint32 size); virtual bool ioFailed(void) const; virtual void clearIOFailed(void); - virtual void skip(uint32 offset); + virtual bool skip(uint32 offset); - virtual uint32 pos(void) const; - virtual uint32 size(void) const; - virtual void seek(int pos, int whence = SEEK_SET); + virtual int32 pos(void) const; + virtual int32 size(void) const; + virtual bool seek(int pos, int whence = SEEK_SET); private: Gs2dScreen *_screen; bool _ioFailed; @@ -75,7 +75,7 @@ public: AutoSaveFile(Ps2SaveFileManager *saveMan, const char *filename); ~AutoSaveFile(void); virtual uint32 write(const void *ptr, uint32 size); - virtual void flush(void) {} + virtual bool flush(void) {} virtual bool ioFailed(void) { return false; }; virtual void clearIOFailed(void) {} private: @@ -95,8 +95,8 @@ public: virtual bool open(const char *name); virtual uint32 read(void *dest, uint32 len); virtual uint32 write(const void *src, uint32 len); - virtual uint32 tell(void); - virtual uint32 size(void); + virtual int32 tell(void); + virtual int32 size(void); virtual int seek(int32 offset, int origin); virtual bool eof(void); }; @@ -108,8 +108,8 @@ public: virtual bool open(const char *name); virtual uint32 read(void *dest, uint32 len); virtual uint32 write(const void *src, uint32 len); - virtual uint32 tell(void); - virtual uint32 size(void); + virtual int32 tell(void); + virtual int32 size(void); virtual int seek(int32 offset, int origin); virtual bool eof(void); }; -- cgit v1.2.3 From c8eeae8d4dffa5849a23cf963884027a7789504b Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Sun, 14 Sep 2008 22:28:53 +0000 Subject: Big patch changing semantics of ReadStream::eos(): eos() now only returns true _after_ trying to read past the end of the stream. This has a large potential for regressions. Please test! svn-id: r34549 --- backends/platform/ps2/rawsavefile.cpp | 13 +++++++++++- backends/platform/ps2/rawsavefile.h | 3 +++ backends/platform/ps2/savefile.cpp | 38 +++++++++++++++++------------------ backends/platform/ps2/savefile.h | 17 ++++++++-------- 4 files changed, 41 insertions(+), 30 deletions(-) (limited to 'backends/platform/ps2') diff --git a/backends/platform/ps2/rawsavefile.cpp b/backends/platform/ps2/rawsavefile.cpp index 03270ea9ce..aa3cc57fe7 100644 --- a/backends/platform/ps2/rawsavefile.cpp +++ b/backends/platform/ps2/rawsavefile.cpp @@ -31,6 +31,7 @@ RawReadFile::RawReadFile(McAccess *mcAccess) { _size = -1; _pos = 0; _buf = NULL; + _eof = false; } RawReadFile::~RawReadFile(void) { @@ -79,12 +80,16 @@ int RawReadFile::bufSeek(int ofs, int whence) { _pos = 0; else if (_pos > _size) _pos = _size; + + _eof = false; return _pos; } int RawReadFile::bufRead(void *dest, int size) { - if (_pos + size > _size) + if (_pos + size > _size) { size = _size - _pos; + _eof = true; + } memcpy(dest, _buf + _pos, size); _pos += size; return size; @@ -94,7 +99,13 @@ int RawReadFile::bufSize(void) const { return _size; } +bool RawReadFile::bufEof(void) const { + return _eof; +} +void RawReadFile::bufClearErr(void) const { + _eof = false; +} RawWriteFile::RawWriteFile(McAccess *mcAccess) { _mcAccess = mcAccess; diff --git a/backends/platform/ps2/rawsavefile.h b/backends/platform/ps2/rawsavefile.h index b638d106ab..8e0dba4ab9 100644 --- a/backends/platform/ps2/rawsavefile.h +++ b/backends/platform/ps2/rawsavefile.h @@ -40,11 +40,14 @@ public: int bufTell(void) const; int bufSeek(int ofs, int whence); int bufSize(void) const; + bool bufEof(void) const; + void bufClearErr(void); protected: McAccess *_mcAccess; int _size; uint8 *_buf; int _pos; + bool _eof; }; class RawWriteFile { diff --git a/backends/platform/ps2/savefile.cpp b/backends/platform/ps2/savefile.cpp index 7d45aabda7..bfcaf0f57f 100644 --- a/backends/platform/ps2/savefile.cpp +++ b/backends/platform/ps2/savefile.cpp @@ -71,7 +71,7 @@ uint32 AutoSaveFile::write(const void *ptr, uint32 size) { UclInSaveFile::UclInSaveFile(const char *filename, Gs2dScreen *screen, McAccess *mcAccess) : RawReadFile(mcAccess) { _screen = screen; - _ioFailed = true; + _err = true; if (bufOpen(filename)) { if ((_size > 8) && (*(uint32 *)_buf == UCL_MAGIC)) { @@ -82,13 +82,13 @@ UclInSaveFile::UclInSaveFile(const char *filename, Gs2dScreen *screen, McAccess free(_buf); _buf = decBuf; _size = resSize; - _ioFailed = false; + _err = false; _pos = 0; } else free(decBuf); } } - if (_ioFailed) { + if (_err) { if (_buf) free(_buf); _buf = NULL; @@ -100,16 +100,17 @@ UclInSaveFile::~UclInSaveFile(void) { _screen->wantAnim(false); } -bool UclInSaveFile::ioFailed(void) const { - return _ioFailed; +bool UclInSaveFile::err(void) const { + return _err; } -void UclInSaveFile::clearIOFailed(void) { - _ioFailed = false; +void UclInSaveFile::clearErr(void) { + _err = false; + bufClearErr(); } bool UclInSaveFile::eos(void) const { - return bufTell() == bufSize(); + return bufEof(); } int32 UclInSaveFile::pos(void) const { @@ -131,7 +132,7 @@ uint32 UclInSaveFile::read(void *ptr, uint32 size) { bool UclInSaveFile::skip(uint32 offset) { bufSeek(offset, SEEK_CUR); - return true;s + return true; } UclOutSaveFile::UclOutSaveFile(const char *filename, OSystem_PS2 *system, Gs2dScreen *screen, McAccess *mc) : RawWriteFile(mc) { @@ -139,7 +140,7 @@ UclOutSaveFile::UclOutSaveFile(const char *filename, OSystem_PS2 *system, Gs2dSc _system = system; strcpy(_fileName, filename); - _ioFailed = !bufOpen(filename); + _err = !bufOpen(filename); _wasFlushed = false; } @@ -148,7 +149,7 @@ UclOutSaveFile::~UclOutSaveFile(void) { if (_pos != 0) { printf("Engine didn't call SaveFile::flush()\n"); flush(); - if (ioFailed()) { + if (err()) { // unable to save to memory card and it's too late to return an error code to the engine _system->msgPrintf(5000, "!WARNING!\nCan't write to memory card.\nGame was NOT saved."); printf("~UclOutSaveFile: Flush failed!\n"); @@ -162,19 +163,19 @@ uint32 UclOutSaveFile::write(const void *ptr, uint32 size) { return size; } -bool UclOutSaveFile::ioFailed(void) const { - return _ioFailed; +bool UclOutSaveFile::err(void) const { + return _err; } -void UclOutSaveFile::clearIOFailed(void) { - _ioFailed = false; +void UclOutSaveFile::clearErr(void) { + _err = false; } bool UclOutSaveFile::flush(void) { if (_pos != 0) { if (_wasFlushed) { printf("Multiple calls to UclOutSaveFile::flush!\n"); - _ioFailed = true; + _err = true; return false; } uint32 compSize = _pos * 2; @@ -190,7 +191,7 @@ bool UclOutSaveFile::flush(void) { _pos = compSize + 8; if (!bufFlush()) { printf("UclOutSaveFile::flush failed!\n"); - _ioFailed = true; + _err = true; removeFile(); } _wasFlushed = true; @@ -270,6 +271,3 @@ int Ps2McWriteFile::seek(int32 offset, int origin) { return 0; } -bool Ps2McWriteFile::eof(void) { - return true; -} diff --git a/backends/platform/ps2/savefile.h b/backends/platform/ps2/savefile.h index fd09c823d0..0c0cf922f4 100644 --- a/backends/platform/ps2/savefile.h +++ b/backends/platform/ps2/savefile.h @@ -42,13 +42,13 @@ public: virtual ~UclOutSaveFile(void); virtual uint32 write(const void *ptr, uint32 size); virtual bool flush(void); - virtual bool ioFailed(void) const; - virtual void clearIOFailed(void); + virtual bool err(void) const; + virtual void clearErr(void); private: OSystem_PS2 *_system; Gs2dScreen *_screen; - bool _ioFailed, _wasFlushed; + bool _err, _wasFlushed; char _fileName[128]; }; @@ -58,8 +58,8 @@ public: virtual ~UclInSaveFile(void); virtual bool eos(void) const; virtual uint32 read(void *ptr, uint32 size); - virtual bool ioFailed(void) const; - virtual void clearIOFailed(void); + virtual bool err(void) const; + virtual void clearErr(void); virtual bool skip(uint32 offset); virtual int32 pos(void) const; @@ -67,7 +67,7 @@ public: virtual bool seek(int pos, int whence = SEEK_SET); private: Gs2dScreen *_screen; - bool _ioFailed; + bool _err; }; class AutoSaveFile : public Common::OutSaveFile { @@ -76,8 +76,8 @@ public: ~AutoSaveFile(void); virtual uint32 write(const void *ptr, uint32 size); virtual bool flush(void) {} - virtual bool ioFailed(void) { return false; }; - virtual void clearIOFailed(void) {} + virtual bool err(void) const { return false; } + virtual void clearErr(void) {} private: Ps2SaveFileManager *_saveMan; char _fileName[256]; @@ -111,7 +111,6 @@ public: virtual int32 tell(void); virtual int32 size(void); virtual int seek(int32 offset, int origin); - virtual bool eof(void); }; #endif // __PS2_SAVEFILE__ -- cgit v1.2.3