aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/scumm/he/intern_he.h10
-rw-r--r--engines/scumm/he/script_v100he.cpp16
-rw-r--r--engines/scumm/he/script_v60he.cpp62
-rw-r--r--engines/scumm/he/script_v72he.cpp45
-rw-r--r--engines/scumm/scumm.cpp9
5 files changed, 95 insertions, 47 deletions
diff --git a/engines/scumm/he/intern_he.h b/engines/scumm/he/intern_he.h
index 9cba1d1b1b..7c3baba193 100644
--- a/engines/scumm/he/intern_he.h
+++ b/engines/scumm/he/intern_he.h
@@ -30,6 +30,11 @@
#include "scumm/he/wiz_he.h"
#endif
+namespace Common {
+class SeekableReadStream;
+class WriteStream;
+}
+
namespace Scumm {
#ifndef DISABLE_HE
@@ -49,7 +54,9 @@ protected:
const OpcodeEntryv60he *_opcodesv60he;
public:
- Common::File _hFileTable[17];
+ //Common::File _hFileTable[17];
+ Common::SeekableReadStream *_hInFileTable[17];
+ Common::WriteStream *_hOutFileTable[17];
int _heTimers[16];
int getHETimer(int timer);
@@ -57,6 +64,7 @@ public:
public:
ScummEngine_v60he(OSystem *syst, const DetectorResult &dr);
+ ~ScummEngine_v60he();
virtual void scummInit();
diff --git a/engines/scumm/he/script_v100he.cpp b/engines/scumm/he/script_v100he.cpp
index 1551eca420..4dc2f1842f 100644
--- a/engines/scumm/he/script_v100he.cpp
+++ b/engines/scumm/he/script_v100he.cpp
@@ -2308,19 +2308,20 @@ void ScummEngine_v100he::o100_writeFile() {
byte subOp = fetchScriptByte();
+ assert(_hOutFileTable[slot]);
switch (subOp) {
case 5:
fetchScriptByte();
writeFileFromArray(slot, resID);
break;
case 42:
- _hFileTable[slot].writeUint16LE(resID);
+ _hOutFileTable[slot]->writeUint16LE(resID);
break;
case 43:
- _hFileTable[slot].writeUint32LE(resID);
+ _hOutFileTable[slot]->writeUint32LE(resID);
break;
case 45:
- _hFileTable[slot].writeByte(resID);
+ _hOutFileTable[slot]->writeByte(resID);
break;
default:
error("o100_writeFile: default case %d", subOp);
@@ -2618,17 +2619,20 @@ void ScummEngine_v100he::o100_readFile() {
break;
case 42:
slot = pop();
- val = _hFileTable[slot].readUint16LE();
+ assert(_hInFileTable[slot]);
+ val = _hInFileTable[slot]->readUint16LE();
push(val);
break;
case 43:
slot = pop();
- val = _hFileTable[slot].readUint32LE();
+ assert(_hInFileTable[slot]);
+ val = _hInFileTable[slot]->readUint32LE();
push(val);
break;
case 45:
slot = pop();
- val = _hFileTable[slot].readByte();
+ assert(_hInFileTable[slot]);
+ val = _hInFileTable[slot]->readByte();
push(val);
break;
default:
diff --git a/engines/scumm/he/script_v60he.cpp b/engines/scumm/he/script_v60he.cpp
index d3748abb85..8c4324b6c7 100644
--- a/engines/scumm/he/script_v60he.cpp
+++ b/engines/scumm/he/script_v60he.cpp
@@ -985,7 +985,7 @@ void virtScreenSavePackByte(vsPackCtx *ctx, uint8 *&dst, int len, uint8 b) {
}
void ScummEngine_v60he::o60_openFile() {
- int mode, len, slot, l, r;
+ int mode, len, slot, i, r;
byte filename[100];
convertMessageToString(_scriptPointer, filename, sizeof(filename));
@@ -1000,9 +1000,9 @@ void ScummEngine_v60he::o60_openFile() {
mode = pop();
slot = -1;
- for (l = 0; l < 17; l++) {
- if (_hFileTable[l].isOpen() == false) {
- slot = l;
+ for (i = 0; i < 17; i++) {
+ if (_hInFileTable[i] == 0 && _hOutFileTable[i] == 0) {
+ slot = i;
break;
}
}
@@ -1010,18 +1010,25 @@ void ScummEngine_v60he::o60_openFile() {
if (slot != -1) {
switch(mode) {
case 1:
- _hFileTable[slot].open((char*)filename + r, Common::File::kFileReadMode, _saveFileMan->getSavePath());
- if (_hFileTable[slot].isOpen() == false)
- _hFileTable[slot].open((char*)filename + r, Common::File::kFileReadMode);
+ // TODO / FIXME: Consider using listSavefiles to avoid unneccessary openForLoading calls
+ _hInFileTable[slot] = _saveFileMan->openForLoading((char*)filename + r);
+ if (_hInFileTable[slot] == 0) {
+ Common::File *f = new Common::File();
+ f->open((char*)filename + r, Common::File::kFileReadMode);
+ if (!f->isOpen())
+ delete f;
+ else
+ _hInFileTable[slot] = f;
+ }
break;
case 2:
- _hFileTable[slot].open((char*)filename + r, Common::File::kFileWriteMode, _saveFileMan->getSavePath());
+ _hOutFileTable[slot] = _saveFileMan->openForSaving((char*)filename + r);
break;
default:
error("o60_openFile(): wrong open file mode %d", mode);
}
- if (_hFileTable[slot].isOpen() == false)
+ if (_hInFileTable[slot] == 0 && _hOutFileTable[slot] == 0)
slot = -1;
}
@@ -1030,8 +1037,12 @@ void ScummEngine_v60he::o60_openFile() {
void ScummEngine_v60he::o60_closeFile() {
int slot = pop();
- if (slot != -1)
- _hFileTable[slot].close();
+ if (0 <= slot && slot < 17) {
+ delete _hInFileTable[slot];
+ delete _hOutFileTable[slot];
+ _hInFileTable[slot] = 0;
+ _hOutFileTable[slot] = 0;
+ }
}
void ScummEngine_v60he::o60_deleteFile() {
@@ -1079,13 +1090,13 @@ void ScummEngine_v60he::o60_rename() {
}
int ScummEngine_v60he::readFileToArray(int slot, int32 size) {
+ assert(_hInFileTable[slot]);
if (size == 0)
- size = _hFileTable[slot].size() - _hFileTable[slot].pos();
+ size = _hInFileTable[slot]->size() - _hInFileTable[slot]->pos();
writeVar(0, 0);
-
ArrayHeader *ah = defineArray(0, kByteArray, 0, size);
- _hFileTable[slot].read(ah->data, size);
+ _hInFileTable[slot]->read(ah->data, size);
return readVar(0);
}
@@ -1099,11 +1110,12 @@ void ScummEngine_v60he::o60_readFile() {
if ((_game.platform == Common::kPlatformPC) && (_game.id == GID_FBEAR))
size = -size;
+ assert(_hInFileTable[slot]);
if (size == -2) {
- val = _hFileTable[slot].readUint16LE();
+ val = _hInFileTable[slot]->readUint16LE();
push(val);
} else if (size == -1) {
- val = _hFileTable[slot].readByte();
+ val = _hInFileTable[slot]->readByte();
push(val);
} else {
val = readFileToArray(slot, size);
@@ -1115,7 +1127,8 @@ void ScummEngine_v60he::writeFileFromArray(int slot, int resID) {
ArrayHeader *ah = (ArrayHeader *)getResourceAddress(rtString, resID);
int32 size = FROM_LE_16(ah->dim1) * FROM_LE_16(ah->dim2);
- _hFileTable[slot].write(ah->data, size);
+ assert(_hOutFileTable[slot]);
+ _hOutFileTable[slot]->write(ah->data, size);
}
void ScummEngine_v60he::o60_writeFile() {
@@ -1127,10 +1140,11 @@ void ScummEngine_v60he::o60_writeFile() {
if ((_game.platform == Common::kPlatformPC) && (_game.id == GID_FBEAR))
size = -size;
+ assert(_hOutFileTable[slot]);
if (size == -2) {
- _hFileTable[slot].writeUint16LE(resID);
+ _hOutFileTable[slot]->writeUint16LE(resID);
} else if (size == -1) {
- _hFileTable[slot].writeByte(resID);
+ _hOutFileTable[slot]->writeByte(resID);
} else {
writeFileFromArray(slot, resID);
}
@@ -1183,15 +1197,16 @@ void ScummEngine_v60he::o60_seekFilePos() {
if (slot == -1)
return;
+ assert(_hInFileTable[slot]);
switch (mode) {
case 1:
- _hFileTable[slot].seek(offset, SEEK_SET);
+ _hInFileTable[slot]->seek(offset, SEEK_SET);
break;
case 2:
- _hFileTable[slot].seek(offset, SEEK_CUR);
+ _hInFileTable[slot]->seek(offset, SEEK_CUR);
break;
case 3:
- _hFileTable[slot].seek(offset, SEEK_END);
+ _hInFileTable[slot]->seek(offset, SEEK_END);
break;
default:
error("o60_seekFilePos: default case %d", mode);
@@ -1206,7 +1221,8 @@ void ScummEngine_v60he::o60_readFilePos() {
return;
}
- push(_hFileTable[slot].pos());
+ assert(_hInFileTable[slot]);
+ push(_hInFileTable[slot]->pos());
}
void ScummEngine_v60he::o60_redimArray() {
diff --git a/engines/scumm/he/script_v72he.cpp b/engines/scumm/he/script_v72he.cpp
index 7f61a4fcbc..ea0657f6b8 100644
--- a/engines/scumm/he/script_v72he.cpp
+++ b/engines/scumm/he/script_v72he.cpp
@@ -1722,7 +1722,7 @@ void ScummEngine_v72he::o72_openFile() {
slot = -1;
for (i = 1; i < 17; i++) {
- if (_hFileTable[i].isOpen() == false) {
+ if (_hInFileTable[i] == 0 && _hOutFileTable[i] == 0) {
slot = i;
break;
}
@@ -1731,18 +1731,25 @@ void ScummEngine_v72he::o72_openFile() {
if (slot != -1) {
switch(mode) {
case 1:
- _hFileTable[slot].open((char*)filename + r, Common::File::kFileReadMode, _saveFileMan->getSavePath());
- if (_hFileTable[slot].isOpen() == false)
- _hFileTable[slot].open((char*)filename + r, Common::File::kFileReadMode, _gameDataPath.c_str());
+ // TODO / FIXME: Consider using listSavefiles to avoid unneccessary openForLoading calls
+ _hInFileTable[slot] = _saveFileMan->openForLoading((char*)filename + r);
+ if (_hInFileTable[slot] == 0) {
+ Common::File *f = new Common::File();
+ f->open((char*)filename + r, Common::File::kFileReadMode);
+ if (!f->isOpen())
+ delete f;
+ else
+ _hInFileTable[slot] = f;
+ }
break;
case 2:
- _hFileTable[slot].open((char*)filename + r, Common::File::kFileWriteMode, _saveFileMan->getSavePath());
+ _hOutFileTable[slot] = _saveFileMan->openForSaving((char*)filename + r);
break;
default:
error("o72_openFile(): wrong open file mode %d", mode);
}
- if (_hFileTable[slot].isOpen() == false)
+ if (_hInFileTable[slot] == 0 && _hOutFileTable[slot] == 0)
slot = -1;
}
@@ -1751,14 +1758,13 @@ void ScummEngine_v72he::o72_openFile() {
}
int ScummEngine_v72he::readFileToArray(int slot, int32 size) {
+ assert(_hInFileTable[slot]);
if (size == 0)
- size = _hFileTable[slot].size() - _hFileTable[slot].pos();
+ size = _hInFileTable[slot]->size() - _hInFileTable[slot]->pos();
writeVar(0, 0);
ArrayHeader *ah = defineArray(0, kByteArray, 0, 0, 0, size);
-
- if (_hFileTable[slot].isOpen())
- _hFileTable[slot].read(ah->data, size + 1);
+ _hInFileTable[slot]->read(ah->data, size + 1);
return readVar(0);
}
@@ -1771,17 +1777,20 @@ void ScummEngine_v72he::o72_readFile() {
switch (subOp) {
case 4:
slot = pop();
- val = _hFileTable[slot].readByte();
+ assert(_hInFileTable[slot]);
+ val = _hInFileTable[slot]->readByte();
push(val);
break;
case 5:
slot = pop();
- val = _hFileTable[slot].readUint16LE();
+ assert(_hInFileTable[slot]);
+ val = _hInFileTable[slot]->readUint16LE();
push(val);
break;
case 6:
slot = pop();
- val = _hFileTable[slot].readUint32LE();
+ assert(_hInFileTable[slot]);
+ val = _hInFileTable[slot]->readUint32LE();
push(val);
break;
case 8:
@@ -1801,7 +1810,8 @@ void ScummEngine_v72he::writeFileFromArray(int slot, int32 resID) {
int32 size = (FROM_LE_32(ah->dim1end) - FROM_LE_32(ah->dim1start) + 1) *
(FROM_LE_32(ah->dim2end) - FROM_LE_32(ah->dim2start) + 1);
- _hFileTable[slot].write(ah->data, size);
+ assert(_hOutFileTable[slot]);
+ _hOutFileTable[slot]->write(ah->data, size);
}
void ScummEngine_v72he::o72_writeFile() {
@@ -1809,15 +1819,16 @@ void ScummEngine_v72he::o72_writeFile() {
int slot = pop();
byte subOp = fetchScriptByte();
+ assert(_hOutFileTable[slot]);
switch (subOp) {
case 4:
- _hFileTable[slot].writeByte(resID);
+ _hOutFileTable[slot]->writeByte(resID);
break;
case 5:
- _hFileTable[slot].writeUint16LE(resID);
+ _hOutFileTable[slot]->writeUint16LE(resID);
break;
case 6:
- _hFileTable[slot].writeUint32LE(resID);
+ _hOutFileTable[slot]->writeUint32LE(resID);
break;
case 8:
fetchScriptByte();
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index a8a9fbfe30..3c4dbc6493 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -799,9 +799,18 @@ ScummEngine_v6::ScummEngine_v6(OSystem *syst, const DetectorResult &dr)
ScummEngine_v60he::ScummEngine_v60he(OSystem *syst, const DetectorResult &dr)
: ScummEngine_v6(syst, dr) {
+ memset(_hInFileTable, 0, sizeof(_hInFileTable));
+ memset(_hOutFileTable, 0, sizeof(_hOutFileTable));
memset(_heTimers, 0, sizeof(_heTimers));
}
+ScummEngine_v60he::~ScummEngine_v60he() {
+ for (int i = 0; i < 17; ++i) {
+ delete _hInFileTable[i];
+ delete _hOutFileTable[i];
+ }
+}
+
#ifndef DISABLE_HE
ScummEngine_v70he::ScummEngine_v70he(OSystem *syst, const DetectorResult &dr)
: ScummEngine_v60he(syst, dr) {