aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/ps2
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2008-09-14 22:28:53 +0000
committerWillem Jan Palenstijn2008-09-14 22:28:53 +0000
commitc8eeae8d4dffa5849a23cf963884027a7789504b (patch)
tree1f2a0de23851cb7e7d1d77114c8379aa27f4fb85 /backends/platform/ps2
parentfbfe30bf861af9b83325e0c7fecd4b0a68da5af9 (diff)
downloadscummvm-rg350-c8eeae8d4dffa5849a23cf963884027a7789504b.tar.gz
scummvm-rg350-c8eeae8d4dffa5849a23cf963884027a7789504b.tar.bz2
scummvm-rg350-c8eeae8d4dffa5849a23cf963884027a7789504b.zip
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
Diffstat (limited to 'backends/platform/ps2')
-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
4 files changed, 41 insertions, 30 deletions
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__