From 55cda3aa258e2c214e0442ad726d964bb787cd0e Mon Sep 17 00:00:00 2001 From: Max Lingua Date: Sun, 12 Jul 2009 05:38:08 +0000 Subject: ScummVM/PS2 bugs fixed by this commit: - general file write corruption (eg. ScummVM.ini, etc.) - COMI specific save crash / corruption (added option in engines/scumm/saveload.cpp to disable thumbnails on PS2, as emergency fallback in case the fix should prove to be insufficient) - implemented _screenChange logic (fixes grabOverlay & COMI popup menu) - fixed higher pitch (chipmunk fx) - made NET IRXs optional to allow it to work on fat PS2 without net+hd - fixed cursor restore on RTL - added "." as R2 to skip single lines of dialog - added write cache svn-id: r42404 --- backends/platform/ps2/fileio.cpp | 109 ++++++++++++++++++++++++++++++--------- 1 file changed, 84 insertions(+), 25 deletions(-) (limited to 'backends/platform/ps2/fileio.cpp') diff --git a/backends/platform/ps2/fileio.cpp b/backends/platform/ps2/fileio.cpp index fc35306907..8e5dc1255f 100644 --- a/backends/platform/ps2/fileio.cpp +++ b/backends/platform/ps2/fileio.cpp @@ -61,7 +61,7 @@ Ps2File::Ps2File(void) { // _cache = (uint8 *)malloc(PS2_CACHE_MAX); - _cacheBuf = (uint8*)memalign(64, CACHE_SIZE); + _cacheBuf = (uint8*)memalign(64, CACHE_SIZE * 2); _cacheOpRunning = 0; _filePos = _physFilePos = _cachePos = 0; @@ -80,7 +80,16 @@ Ps2File::Ps2File(void) { } Ps2File::~Ps2File(void) { + uint32 w; if (_fd >= 0) { + + if (_mode != O_RDONLY) { + fio.seek(_fd, 0, SEEK_SET); + fio.write(_fd, _cacheBuf, _filePos); + w = fio.sync(_fd); + printf("flushed wbuf: %x of %x\n", w, _filePos); + } + fio.close(_fd); uint32 r = fio.sync(_fd); printf("close [%d] - sync'd = %d\n", _fd, r); @@ -95,24 +104,87 @@ Ps2File::~Ps2File(void) { } bool Ps2File::open(const char *name, int mode) { - assert(_fd < 0); - +#if 1 _fd = fio.open(name, mode); printf("open %s [%d]\n", name, _fd); if (_fd >= 0) { - _fileSize = fio.seek(_fd, 0, SEEK_END); - if (mode == O_RDONLY) - // if (!(mode & O_APPEND)) + _mode = mode; + _filePos = 0; + + if (_mode == O_RDONLY) { + _fileSize = fio.seek(_fd, 0, SEEK_END); fio.seek(_fd, 0, SEEK_SET); + } + else + _fileSize = 0; + printf(" _mode = %x\n", _mode); + printf(" _fileSize = %d\n", _fileSize); + // printf(" _filePos = %d\n", _filePos); + + return true; + } + + return false; +#else + uint32 r; + + // hack: FIO does not reports size for RW (?) + _fd = fio.open(name, O_RDONLY); + if (_fd >= 0) { + _fileSize = fio.seek(_fd, 0, SEEK_END); + fio.seek(_fd, 0, SEEK_SET); /* rewind ! */ + + if (_fileSize && mode != O_RDONLY) { + fio.read(_fd, _cacheBuf, _fileSize); + r = fio.sync(_fd); + printf(" sz=%d, read=%d\n", _fileSize, r); + assert(r == _fileSize); + } + + fio.close(_fd); + } + else + _fileSize = 0; /* new file */ + + _fd = fio.open(name, mode); + + printf("open %s [%d]\n", name, _fd); + + if (_fd >= 0) { + _mode = mode; + _filePos = 0; + + if (_fileSize) { /* existing data */ + if (mode == O_RDONLY) { + /* DANGER: for w* modes it will truncate your fine files */ + fio.seek(_fd, 0, SEEK_SET); + } + else if (_mode & O_APPEND) { + fio.seek(_fd, 0, _fileSize); + _filePos = _fileSize; + } + #if 0 /* file already trunc'd when opened as w* -> moved up */ + if (mode != O_RDONLY) { + fio.read(_fd, _cacheBuf, _fileSize); + r = fio.sync(_fd); + printf(" sz=%d, read=%d\n", _fileSize, r); + assert(r == _fileSize); + // _fileSize = fio.seek(_fd, 0, SEEK_END); + } + #endif + } + + printf(" _mode = %x\n", _mode); printf(" _fileSize = %d\n", _fileSize); printf(" _filePos = %d\n", _filePos); return true; } else return false; +#endif } int32 Ps2File::tell(void) { @@ -225,7 +297,7 @@ void Ps2File::cacheReadAhead(void) { _cachePos = cachePosEnd = _filePos & ~READ_ALIGN_MASK; assert(_filePos == _physFilePos); } else { - uint32 cacheDiff = _filePos - _cachePos; + uint32 cacheDiff = _filePos - _cachePos; assert(_bytesInCache >= cacheDiff); cacheDiff &= ~READ_ALIGN_MASK; _bytesInCache -= cacheDiff; @@ -344,32 +416,18 @@ uint32 Ps2File::read(void *dest, uint32 len) { } uint32 Ps2File::write(const void *src, uint32 len) { - uint32 w; #ifdef __PS2_FILE_SEMA__ WaitSema(_sema); #endif - _cacheSize = 0; - w = fio.sync(_fd); - assert(w==0); - - fio.seek(_fd, _filePos, SEEK_SET); - fio.write(_fd, src, len); - - w = fio.sync(_fd); + memcpy(&_cacheBuf[_filePos], src, len); + _filePos += len; #ifdef __PS2_FILE_SEMA__ SignalSema(_sema); #endif - if (w) { - _filePos += w; - if (w < len) - _eof = true; - return w; - } - - return 0; + return len; } FILE *ps2_fopen(const char *fname, const char *mode) { @@ -471,7 +529,8 @@ int ps2_ferror(FILE *stream) { if (err) printf("ferror -> %d\n", err); - return err; + return 0; // kyra temp + // return err; } void ps2_clearerr(FILE *stream) { -- cgit v1.2.3 From a0c37549714a9f02351e85d3503ae129b0aae9b0 Mon Sep 17 00:00:00 2001 From: Max Lingua Date: Sun, 12 Jul 2009 21:58:00 +0000 Subject: Split _eof vs. _err. Latter defaults to false for now, there are hooks for possible future implementation. svn-id: r42428 --- backends/platform/ps2/fileio.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'backends/platform/ps2/fileio.cpp') diff --git a/backends/platform/ps2/fileio.cpp b/backends/platform/ps2/fileio.cpp index 8e5dc1255f..864f840e8a 100644 --- a/backends/platform/ps2/fileio.cpp +++ b/backends/platform/ps2/fileio.cpp @@ -58,6 +58,7 @@ Ps2File::Ps2File(void) { _cacheSize = 0; _cachePos = 0; _eof = false; + _err = false; // _cache = (uint8 *)malloc(PS2_CACHE_MAX); @@ -224,10 +225,11 @@ bool Ps2File::eof(void) { } bool Ps2File::getErr(void) { - return _eof; + return _err; } void Ps2File::setErr(bool err) { + _err = err; _eof = err; } @@ -261,7 +263,9 @@ int Ps2File::seek(int32 offset, int origin) { _eof = false; res = 0; } - else _eof = true; + else { + _eof = true; + } // printf("seek [%d] %d %d\n", _fd, offset, origin); // printf(" res = %d\n", res); @@ -350,10 +354,17 @@ uint32 Ps2File::read(void *dest, uint32 len) { printf("read (1) : _cachePos = %d\n", _cachePos); #endif + if (len == 0) { +#ifdef __PS2_FILE_SEMA__ + SignalSema(_sema); +#endif + return 0; + } + if (_filePos >= _fileSize) { _eof = true; #ifdef __PS2_FILE_SEMA__ - SignalSema(_sema); + SignalSema(_sema); #endif return 0; } @@ -526,11 +537,11 @@ int ps2_fflush(FILE *stream) { int ps2_ferror(FILE *stream) { int err = ((Ps2File*)stream)->getErr(); - if (err) + if (err) { printf("ferror -> %d\n", err); + } - return 0; // kyra temp - // return err; + return err; } void ps2_clearerr(FILE *stream) { -- cgit v1.2.3 From 93c91945045b738fb098403228d91bce40b469f7 Mon Sep 17 00:00:00 2001 From: Max Lingua Date: Mon, 13 Jul 2009 00:55:30 +0000 Subject: Reverted my previous change (fprintf vs fputs), and properly implemented fputs for stderr case on PS2 ;-) svn-id: r42433 --- backends/platform/ps2/fileio.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'backends/platform/ps2/fileio.cpp') diff --git a/backends/platform/ps2/fileio.cpp b/backends/platform/ps2/fileio.cpp index 864f840e8a..017286dc45 100644 --- a/backends/platform/ps2/fileio.cpp +++ b/backends/platform/ps2/fileio.cpp @@ -507,6 +507,13 @@ int ps2_fputc(int c, FILE *stream) { int ps2_fputs(const char *s, FILE *stream) { int len = strlen(s); + + if (stream == stderr || stream == stdout) { + printf("%s", s); + sioprintf("%s", s); + return len; + } + if (ps2_fwrite(s, 1, len, stream) == (size_t)len) return len; else -- cgit v1.2.3