aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
Diffstat (limited to 'backends')
-rw-r--r--backends/fs/stdiostream.cpp6
-rw-r--r--backends/fs/stdiostream.h4
-rw-r--r--backends/fs/symbian/symbianstream.cpp7
-rw-r--r--backends/fs/symbian/symbianstream.h4
-rw-r--r--backends/platform/dc/vmsave.cpp12
-rw-r--r--backends/platform/ds/arm9/source/ramsave.cpp10
-rw-r--r--backends/platform/ds/arm9/source/ramsave.h2
-rw-r--r--backends/platform/ps2/rawsavefile.cpp13
-rw-r--r--backends/platform/ps2/rawsavefile.h3
-rw-r--r--backends/platform/ps2/savefile.cpp38
-rw-r--r--backends/platform/ps2/savefile.h17
-rw-r--r--backends/saves/compressed/compressed-saves.cpp19
12 files changed, 81 insertions, 54 deletions
diff --git a/backends/fs/stdiostream.cpp b/backends/fs/stdiostream.cpp
index fafcca989b..4f353ee7c2 100644
--- a/backends/fs/stdiostream.cpp
+++ b/backends/fs/stdiostream.cpp
@@ -114,11 +114,11 @@ StdioStream::~StdioStream() {
fclose((FILE *)_handle);
}
-bool StdioStream::ioFailed() const {
- return eos() || ferror((FILE *)_handle) != 0;
+bool StdioStream::err() const {
+ return ferror((FILE *)_handle) != 0;
}
-void StdioStream::clearIOFailed() {
+void StdioStream::clearErr() {
clearerr((FILE *)_handle);
}
diff --git a/backends/fs/stdiostream.h b/backends/fs/stdiostream.h
index f40ddd9867..3d44062d7f 100644
--- a/backends/fs/stdiostream.h
+++ b/backends/fs/stdiostream.h
@@ -46,8 +46,8 @@ public:
StdioStream(void *handle);
virtual ~StdioStream();
- bool ioFailed() const;
- void clearIOFailed();
+ bool err() const;
+ void clearErr();
bool eos() const;
virtual uint32 write(const void *dataPtr, uint32 dataSize);
diff --git a/backends/fs/symbian/symbianstream.cpp b/backends/fs/symbian/symbianstream.cpp
index 4d2ec11ab3..5944cab892 100644
--- a/backends/fs/symbian/symbianstream.cpp
+++ b/backends/fs/symbian/symbianstream.cpp
@@ -177,12 +177,13 @@ SymbianStdioStream::~SymbianStdioStream() {
delete (TSymbianFileEntry*)(_handle);
}
-bool SymbianStdioStream::ioFailed() const {
- return eos() || ((TSymbianFileEntry*)(_handle))->_lastError != 0;
+bool SymbianStdioStream::err() const {
+ return ((TSymbianFileEntry*)(_handle))->_lastError != 0;
}
-void SymbianStdioStream::clearIOFailed() {
+void SymbianStdioStream::clearErr() {
((TSymbianFileEntry*)(_handle))->_lastError = 0;
+ ((TSymbianFileEntry*)(_handle))->_eofReached = 0;
}
bool SymbianStdioStream::eos() const {
diff --git a/backends/fs/symbian/symbianstream.h b/backends/fs/symbian/symbianstream.h
index 180e6bffcb..d783856687 100644
--- a/backends/fs/symbian/symbianstream.h
+++ b/backends/fs/symbian/symbianstream.h
@@ -46,8 +46,8 @@ public:
SymbianStdioStream(void *handle);
virtual ~SymbianStdioStream();
- bool ioFailed() const;
- void clearIOFailed();
+ bool err() const;
+ void clearErr();
bool eos() const;
virtual uint32 write(const void *dataPtr, uint32 dataSize);
diff --git a/backends/platform/dc/vmsave.cpp b/backends/platform/dc/vmsave.cpp
index 5fe532e1f1..d17e1f6213 100644
--- a/backends/platform/dc/vmsave.cpp
+++ b/backends/platform/dc/vmsave.cpp
@@ -269,6 +269,7 @@ class InVMSave : public Common::InSaveFile {
private:
char *buffer;
int _pos, _size;
+ bool _eos;
uint32 read(void *buf, uint32 cnt);
bool skip(uint32 offset);
@@ -276,7 +277,7 @@ private:
public:
InVMSave()
- : _pos(0), buffer(NULL)
+ : _pos(0), buffer(NULL), _eos(false)
{ }
~InVMSave()
@@ -285,7 +286,8 @@ public:
delete[] buffer;
}
- bool eos() const { return _pos >= _size; }
+ bool eos() const { return _eos; }
+ void clearErr() { _eos = false; }
int32 pos() const { return _pos; }
int32 size() const { return _size; }
@@ -312,8 +314,8 @@ public:
~OutVMSave();
- bool ioFailed() const { return iofailed; }
- void clearIOFailed() { iofailed = false; }
+ bool err() const { return iofailed; }
+ void clearErr() { iofailed = false; }
void finalize();
};
@@ -370,6 +372,7 @@ uint32 InVMSave::read(void *buf, uint32 cnt)
int nbyt = cnt;
if (_pos + nbyt > _size) {
cnt = (_size - _pos);
+ _eos = true;
nbyt = cnt;
}
if (nbyt)
@@ -404,6 +407,7 @@ bool InVMSave::seek(int32 offs, int whence)
_pos = 0;
else if (_pos > _size)
_pos = _size;
+ _eos = false;
return true;
}
diff --git a/backends/platform/ds/arm9/source/ramsave.cpp b/backends/platform/ds/arm9/source/ramsave.cpp
index 8442fd6b88..30c3a06721 100644
--- a/backends/platform/ds/arm9/source/ramsave.cpp
+++ b/backends/platform/ds/arm9/source/ramsave.cpp
@@ -64,6 +64,7 @@ DSSaveFile::DSSaveFile(SCUMMSave* s, bool compressed, u8* data) {
}
isTempFile = false;
+ eosReached = false;
}
DSSaveFile::~DSSaveFile() {
@@ -167,11 +168,13 @@ int DSSaveFile::saveToSaveRAM(vu8* address) {
void DSSaveFile::reset() {
ptr = 0;
+ eosReached = false;
}
uint32 DSSaveFile::read(void *buf, uint32 size) {
if (ptr + size > save.size) {
size = save.size - ptr;
+ eosReached = true;
if (size < 0) size = 0;
}
memcpy(buf, saveData + ptr, size);
@@ -204,11 +207,16 @@ bool DSSaveFile::seek(int32 pos, int whence) {
break;
}
}
+ eosReached = false;
return true;
}
bool DSSaveFile::eos() const {
- return ptr >= (int) save.size;
+ return eosReached;
+}
+
+void DSSaveFile::clearErr() {
+ eosReached = false;
}
bool DSSaveFile::skip(uint32 bytes) {
diff --git a/backends/platform/ds/arm9/source/ramsave.h b/backends/platform/ds/arm9/source/ramsave.h
index e276775b66..98430b9d11 100644
--- a/backends/platform/ds/arm9/source/ramsave.h
+++ b/backends/platform/ds/arm9/source/ramsave.h
@@ -52,6 +52,7 @@ class DSSaveFile : public Common::InSaveFile, public Common::OutSaveFile {
SCUMMSave* origHeader;
bool isOpenFlag;
bool isTempFile;
+ bool eosReached;
public:
DSSaveFile();
@@ -62,6 +63,7 @@ public:
bool isOpen() const { return isOpenFlag; }
virtual bool eos() const;
+ virtual void clearErr();
virtual bool skip(uint32 size);
virtual int32 pos() const;
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__
diff --git a/backends/saves/compressed/compressed-saves.cpp b/backends/saves/compressed/compressed-saves.cpp
index 27b8749911..000fec9553 100644
--- a/backends/saves/compressed/compressed-saves.cpp
+++ b/backends/saves/compressed/compressed-saves.cpp
@@ -98,8 +98,8 @@ public:
delete _wrapped;
}
- bool ioFailed() const { return (_zlibErr != Z_OK) && (_zlibErr != Z_STREAM_END); }
- void clearIOFailed() { /* errors here are not recoverable! */ }
+ bool err() const { return (_zlibErr != Z_OK) && (_zlibErr != Z_STREAM_END); }
+ void clearErr() { /* errors here are not recoverable! */ }
uint32 read(void *dataPtr, uint32 dataSize) {
_stream.next_out = (byte *)dataPtr;
@@ -166,7 +166,7 @@ public:
// huge amounts of data, but usually client code will only skip a few
// bytes, so this should be fine.
byte tmpBuf[1024];
- while (!ioFailed() && offset > 0) {
+ while (!err() && offset > 0) {
offset -= read(tmpBuf, MIN((int32)sizeof(tmpBuf), offset));
}
@@ -236,14 +236,15 @@ public:
delete _wrapped;
}
- bool ioFailed() const {
- return (_zlibErr != Z_OK && _zlibErr != Z_STREAM_END) || _wrapped->ioFailed();
+ bool err() const {
+ // CHECKME: does Z_STREAM_END make sense here?
+ return (_zlibErr != Z_OK && _zlibErr != Z_STREAM_END) || _wrapped->err();
}
- void clearIOFailed() {
+ void clearErr() {
// Note: we don't reset the _zlibErr here, as it is not
- // clear in general ho
- _wrapped->clearIOFailed();
+ // clear in general how
+ _wrapped->clearErr();
}
void finalize() {
@@ -267,7 +268,7 @@ public:
}
uint32 write(const void *dataPtr, uint32 dataSize) {
- if (ioFailed())
+ if (err())
return 0;
// Hook in the new data ...