aboutsummaryrefslogtreecommitdiff
path: root/engines/scumm
diff options
context:
space:
mode:
authorMax Horn2006-10-20 19:44:27 +0000
committerMax Horn2006-10-20 19:44:27 +0000
commit5e9041b1b558f8891435204b15e1db41f0686ad9 (patch)
tree1afbae9cf1e596e046e54fd1c29942d5860dc8dd /engines/scumm
parentff574a63ee368cdb4889dd0e17966b4a1ae1f117 (diff)
downloadscummvm-rg350-5e9041b1b558f8891435204b15e1db41f0686ad9.tar.gz
scummvm-rg350-5e9041b1b558f8891435204b15e1db41f0686ad9.tar.bz2
scummvm-rg350-5e9041b1b558f8891435204b15e1db41f0686ad9.zip
SCUMM: ArrayHeader related cleanup
svn-id: r24395
Diffstat (limited to 'engines/scumm')
-rw-r--r--engines/scumm/he/intern_he.h2
-rw-r--r--engines/scumm/he/script_v100he.cpp10
-rw-r--r--engines/scumm/he/script_v60he.cpp10
-rw-r--r--engines/scumm/he/script_v70he.cpp6
-rw-r--r--engines/scumm/he/script_v72he.cpp30
-rw-r--r--engines/scumm/he/script_v80he.cpp6
-rw-r--r--engines/scumm/intern.h2
-rw-r--r--engines/scumm/resource.cpp3
-rw-r--r--engines/scumm/script_v6.cpp25
-rw-r--r--engines/scumm/script_v8.cpp26
-rw-r--r--engines/scumm/scumm.cpp4
11 files changed, 64 insertions, 60 deletions
diff --git a/engines/scumm/he/intern_he.h b/engines/scumm/he/intern_he.h
index e538927a50..35d026dbb1 100644
--- a/engines/scumm/he/intern_he.h
+++ b/engines/scumm/he/intern_he.h
@@ -276,7 +276,7 @@ protected:
virtual void redrawBGAreas();
- ArrayHeader *defineArray(int array, int type, int dim2start, int dim2end, int dim1start, int dim1end);
+ byte *defineArray(int array, int type, int dim2start, int dim2end, int dim1start, int dim1end);
virtual int readArray(int array, int idx2, int idx1);
virtual void writeArray(int array, int idx2, int idx1, int value);
void redimArray(int arrayId, int newDim2start, int newDim2end,
diff --git a/engines/scumm/he/script_v100he.cpp b/engines/scumm/he/script_v100he.cpp
index d3ac0c2f32..0001d539fd 100644
--- a/engines/scumm/he/script_v100he.cpp
+++ b/engines/scumm/he/script_v100he.cpp
@@ -580,7 +580,7 @@ void ScummEngine_v100he::o100_actorOps() {
}
void ScummEngine_v100he::o100_arrayOps() {
- ArrayHeader *ah;
+ byte *data;
byte string[1024];
int dim1end, dim1start, dim2end, dim2start;
int id, len, b, c, list[128];
@@ -595,14 +595,14 @@ void ScummEngine_v100he::o100_arrayOps() {
case 35:
decodeScriptString(string);
len = resStrLen(string);
- ah = defineArray(array, kStringArray, 0, 0, 0, len);
- memcpy(ah->data, string, len);
+ data = defineArray(array, kStringArray, 0, 0, 0, len);
+ memcpy(data, string, len);
break;
case 77: // SO_ASSIGN_STRING
copyScriptString(string, sizeof(string));
len = resStrLen(string);
- ah = defineArray(array, kStringArray, 0, 0, 0, len);
- memcpy(ah->data, string, len);
+ data = defineArray(array, kStringArray, 0, 0, 0, len);
+ memcpy(data, string, len);
break;
case 128: // SO_ASSIGN_2DIM_LIST
diff --git a/engines/scumm/he/script_v60he.cpp b/engines/scumm/he/script_v60he.cpp
index 7610f9df01..6165f42495 100644
--- a/engines/scumm/he/script_v60he.cpp
+++ b/engines/scumm/he/script_v60he.cpp
@@ -856,7 +856,7 @@ uint8 virtScreenLoadUnpack(vsUnpackCtx *ctx, byte *data) {
void ScummEngine_v60he::o60_kernelGetFunctions() {
int args[29];
- ArrayHeader *ah;
+ byte *data;
getStackList(args, ARRAYSIZE(args));
switch (args[0]) {
@@ -864,8 +864,8 @@ void ScummEngine_v60he::o60_kernelGetFunctions() {
// Used to store images when decorating cake in
// Fatty Bear's Birthday Surprise
writeVar(0, 0);
- ah = defineArray(0, kByteArray, 0, virtScreenSave(0, args[1], args[2], args[3], args[4]));
- virtScreenSave(ah->data, args[1], args[2], args[3], args[4]);
+ data = defineArray(0, kByteArray, 0, virtScreenSave(0, args[1], args[2], args[3], args[4]));
+ virtScreenSave(data, args[1], args[2], args[3], args[4]);
push(readVar(0));
break;
default:
@@ -1078,8 +1078,8 @@ int ScummEngine_v60he::readFileToArray(int slot, int32 size) {
size = _hInFileTable[slot]->size() - _hInFileTable[slot]->pos();
writeVar(0, 0);
- ArrayHeader *ah = defineArray(0, kByteArray, 0, size);
- _hInFileTable[slot]->read(ah->data, size);
+ byte *data = defineArray(0, kByteArray, 0, size);
+ _hInFileTable[slot]->read(data, size);
return readVar(0);
}
diff --git a/engines/scumm/he/script_v70he.cpp b/engines/scumm/he/script_v70he.cpp
index 133d802311..c5dc545732 100644
--- a/engines/scumm/he/script_v70he.cpp
+++ b/engines/scumm/he/script_v70he.cpp
@@ -927,7 +927,7 @@ void ScummEngine_v70he::o70_isResourceLoaded() {
void ScummEngine_v70he::o70_readINI() {
byte option[256];
- ArrayHeader *ah;
+ byte *data;
const char *entry;
int len, type;
@@ -951,8 +951,8 @@ void ScummEngine_v70he::o70_readINI() {
writeVar(0, 0);
len = resStrLen((const byte *)entry);
- ah = defineArray(0, kStringArray, 0, len);
- memcpy(ah->data, entry, len);
+ data = defineArray(0, kStringArray, 0, len);
+ memcpy(data, entry, len);
push(readVar(0));
break;
diff --git a/engines/scumm/he/script_v72he.cpp b/engines/scumm/he/script_v72he.cpp
index db54180f5b..adc81ba992 100644
--- a/engines/scumm/he/script_v72he.cpp
+++ b/engines/scumm/he/script_v72he.cpp
@@ -381,7 +381,7 @@ const char *ScummEngine_v72he::getOpcodeDesc(byte i) {
static const int arrayDataSizes[] = { 0, 1, 4, 8, 8, 16, 32 };
-ScummEngine_v72he::ArrayHeader *ScummEngine_v72he::defineArray(int array, int type, int dim2start, int dim2end,
+byte *ScummEngine_v72he::defineArray(int array, int type, int dim2start, int dim2end,
int dim1start, int dim1end) {
int id;
int size;
@@ -427,7 +427,7 @@ ScummEngine_v72he::ArrayHeader *ScummEngine_v72he::defineArray(int array, int ty
ah->dim2start = TO_LE_32(dim2start);
ah->dim2end = TO_LE_32(dim2end);
- return ah;
+ return ah->data;
}
int ScummEngine_v72he::readArray(int array, int idx2, int idx1) {
@@ -1395,7 +1395,7 @@ void ScummEngine_v72he::o72_findObject() {
}
void ScummEngine_v72he::o72_arrayOps() {
- ArrayHeader *ah;
+ byte *data;
byte string[1024];
int dim1end, dim1start, dim2end, dim2start;
int id, len, b, c, list[128];
@@ -1410,8 +1410,8 @@ void ScummEngine_v72he::o72_arrayOps() {
case 7: // SO_ASSIGN_STRING
copyScriptString(string, sizeof(string));
len = resStrLen(string);
- ah = defineArray(array, kStringArray, 0, 0, 0, len);
- memcpy(ah->data, string, len);
+ data = defineArray(array, kStringArray, 0, 0, 0, len);
+ memcpy(data, string, len);
break;
case 126:
@@ -1489,8 +1489,8 @@ void ScummEngine_v72he::o72_arrayOps() {
case 194:
decodeScriptString(string);
len = resStrLen(string);
- ah = defineArray(array, kStringArray, 0, 0, 0, len);
- memcpy(ah->data, string, len);
+ data = defineArray(array, kStringArray, 0, 0, 0, len);
+ memcpy(data, string, len);
break;
case 208: // SO_ASSIGN_INT_LIST
b = pop();
@@ -1661,14 +1661,14 @@ void ScummEngine_v72he::o72_traceStatus() {
void ScummEngine_v72he::o72_kernelGetFunctions() {
int args[29];
- ArrayHeader *ah;
+ byte *data;
getStackList(args, ARRAYSIZE(args));
switch (args[0]) {
case 1:
writeVar(0, 0);
- ah = defineArray(0, kByteArray, 0, 0, 0, virtScreenSave(0, args[1], args[2], args[3], args[4]));
- virtScreenSave(ah->data, args[1], args[2], args[3], args[4]);
+ data = defineArray(0, kByteArray, 0, 0, 0, virtScreenSave(0, args[1], args[2], args[3], args[4]));
+ virtScreenSave(data, args[1], args[2], args[3], args[4]);
push(readVar(0));
break;
default:
@@ -1772,8 +1772,8 @@ int ScummEngine_v72he::readFileToArray(int slot, int32 size) {
size = _hInFileTable[slot]->size() - _hInFileTable[slot]->pos();
writeVar(0, 0);
- ArrayHeader *ah = defineArray(0, kByteArray, 0, 0, 0, size);
- _hInFileTable[slot]->read(ah->data, size + 1);
+ byte *data = defineArray(0, kByteArray, 0, 0, 0, size);
+ _hInFileTable[slot]->read(data, size + 1);
return readVar(0);
}
@@ -2107,7 +2107,7 @@ void ScummEngine_v72he::copyArrayHelper(ArrayHeader *ah, int idx2, int idx1, int
void ScummEngine_v72he::o72_readINI() {
byte option[128];
- ArrayHeader *ah;
+ byte *data;
const char *entry;
int len;
@@ -2131,8 +2131,8 @@ void ScummEngine_v72he::o72_readINI() {
writeVar(0, 0);
len = resStrLen((const byte *)entry);
- ah = defineArray(0, kStringArray, 0, 0, 0, len);
- memcpy(ah->data, entry, len);
+ data = defineArray(0, kStringArray, 0, 0, 0, len);
+ memcpy(data, entry, len);
push(readVar(0));
break;
diff --git a/engines/scumm/he/script_v80he.cpp b/engines/scumm/he/script_v80he.cpp
index 6ede98b2ec..5f4816ce9e 100644
--- a/engines/scumm/he/script_v80he.cpp
+++ b/engines/scumm/he/script_v80he.cpp
@@ -447,7 +447,7 @@ void ScummEngine_v80he::o80_sourceDebug() {
void ScummEngine_v80he::o80_readConfigFile() {
byte option[128], section[128], filename[256];
- ArrayHeader *ah;
+ byte *data;
Common::String entry;
int len, r;
@@ -477,8 +477,8 @@ void ScummEngine_v80he::o80_readConfigFile() {
writeVar(0, 0);
len = resStrLen((const byte *)entry.c_str());
- ah = defineArray(0, kStringArray, 0, 0, 0, len);
- memcpy(ah->data, entry.c_str(), len);
+ data = defineArray(0, kStringArray, 0, 0, 0, len);
+ memcpy(data, entry.c_str(), len);
push(readVar(0));
break;
default:
diff --git a/engines/scumm/intern.h b/engines/scumm/intern.h
index d6d55e190b..19dda7a354 100644
--- a/engines/scumm/intern.h
+++ b/engines/scumm/intern.h
@@ -630,7 +630,7 @@ protected:
int popRoomAndObj(int *room);
ArrayHeader *getArray(int array);
- ArrayHeader *defineArray(int array, int type, int dim2, int dim1);
+ byte *defineArray(int array, int type, int dim2, int dim1);
int findFreeArrayId();
void nukeArray(int array);
virtual int readArray(int array, int index, int base);
diff --git a/engines/scumm/resource.cpp b/engines/scumm/resource.cpp
index 064195de0e..1be391245f 100644
--- a/engines/scumm/resource.cpp
+++ b/engines/scumm/resource.cpp
@@ -764,7 +764,8 @@ byte *ScummEngine_v6::getStringAddress(int i) {
byte *addr = getResourceAddress(rtString, i);
if (addr == NULL)
return NULL;
- return ((ScummEngine_v6::ArrayHeader *)addr)->data;
+ // Skip over the ArrayHeader
+ return addr + 6;
}
byte *ScummEngine::getStringAddressVar(int i) {
diff --git a/engines/scumm/script_v6.cpp b/engines/scumm/script_v6.cpp
index 0b507979bd..9eae8a4425 100644
--- a/engines/scumm/script_v6.cpp
+++ b/engines/scumm/script_v6.cpp
@@ -397,7 +397,7 @@ int ScummEngine_v6::popRoomAndObj(int *room) {
return obj;
}
-ScummEngine_v6::ArrayHeader *ScummEngine_v6::defineArray(int array, int type, int dim2, int dim1) {
+byte *ScummEngine_v6::defineArray(int array, int type, int dim2, int dim1) {
int id;
int size;
ArrayHeader *ah;
@@ -413,7 +413,7 @@ ScummEngine_v6::ArrayHeader *ScummEngine_v6::defineArray(int array, int type, in
// integer arrays. There seems to be no reason for this, and it wastes
// space. However, we can't just remove this either, as that would
// break savegame compatibility. So do not touch this unless you are
- // also adding code which updated old savegames, too. And of course
+ // also adding code which updates old savegames, too. And of course
// readArray() and writeArray() would have to be updated, too...
if (type != kStringArray)
type = kIntArray;
@@ -454,7 +454,7 @@ ScummEngine_v6::ArrayHeader *ScummEngine_v6::defineArray(int array, int type, in
ah->dim1 = TO_LE_16(dim1 + 1);
ah->dim2 = TO_LE_16(dim2 + 1);
- return ah;
+ return ah->data;
}
void ScummEngine_v6::nukeArray(int a) {
@@ -492,10 +492,11 @@ ScummEngine_v6::ArrayHeader *ScummEngine_v6::getArray(int array) {
if (!ah)
return 0;
- // Workaround for a long standing bug where we save array headers in native
- // endianness, instead of a fixed endianness. We try to detect savegames
- // which were created on a big endian system and convert them to little
- // endian.
+ // Workaround for a long standing bug where we saved array headers in native
+ // endianness, instead of a fixed endianness. We now always store the
+ // dimensions in little endian byte order. But to stay compatible with older
+ // savegames, we try to detect savegames which were created on a big endian
+ // system and convert them to the proper little endian format on the fly.
if ((FROM_LE_16(ah->dim1) & 0xF000) || (FROM_LE_16(ah->dim2) & 0xF000) || (FROM_LE_16(ah->type) & 0xFF00)) {
SWAP16(ah->dim1);
SWAP16(ah->dim2);
@@ -518,6 +519,8 @@ int ScummEngine_v6::readArray(int array, int idx, int base) {
// [03BD] (5D) if ((localvar13 != -1) && (localvar14 != -1)) {
// [03CF] (B6) printDebug.begin()
// ...
+ // So it checks for invalid array indices only *after* using them to access
+ // the array. Ouch.
if (_game.id == GID_FT && array == 447 && _currentRoom == 95 && vm.slot[_currentScript].number == 2010 && idx == -1 && base == -1) {
return 0;
}
@@ -2081,15 +2084,15 @@ void ScummEngine_v6::o6_arrayOps() {
byte subOp = fetchScriptByte();
int array = fetchScriptWord();
int b, c, d, len;
- ArrayHeader *ah;
+ byte *data;
int list[128];
switch (subOp) {
case 205: // SO_ASSIGN_STRING
b = pop();
len = resStrLen(_scriptPointer);
- ah = defineArray(array, kStringArray, 0, len + 1);
- copyScriptString(ah->data + b);
+ data = defineArray(array, kStringArray, 0, len + 1);
+ copyScriptString(data + b);
break;
case 208: // SO_ASSIGN_INT_LIST
b = pop();
@@ -2961,7 +2964,7 @@ void ScummEngine_v6::o6_pickVarRandom() {
num = readArray(value, 0, 0);
- ArrayHeader *ah = (ArrayHeader *)getResourceAddress(rtString, readVar(value));
+ ArrayHeader *ah = getArray(value);
dim1 = FROM_LE_16(ah->dim1) - 1;
if (dim1 < num) {
diff --git a/engines/scumm/script_v8.cpp b/engines/scumm/script_v8.cpp
index e59ddc179f..714d973a99 100644
--- a/engines/scumm/script_v8.cpp
+++ b/engines/scumm/script_v8.cpp
@@ -633,15 +633,15 @@ void ScummEngine_v8::o8_arrayOps() {
byte subOp = fetchScriptByte();
int array = fetchScriptWord();
int b, c, d, len;
- ArrayHeader *ah;
+ byte *data;
int list[128];
switch (subOp) {
case 0x14: // SO_ASSIGN_STRING
b = pop();
len = resStrLen(_scriptPointer);
- ah = defineArray(array, kStringArray, 0, len + 1);
- copyScriptString(ah->data + b);
+ data = defineArray(array, kStringArray, 0, len + 1);
+ copyScriptString(data + b);
break;
case 0x15: // SO_ASSIGN_SCUMMVAR_LIST
b = pop();
@@ -1273,9 +1273,9 @@ void ScummEngine_v8::o8_kernelSetFunctions() {
{
int idx = args[1];
int value = args[2];
- ArrayHeader *ah = (ArrayHeader *)getResourceAddress(rtString, idx);
+ const char *str = (const char *)getStringAddress(idx);
- debugC(DEBUG_GENERAL,"o8_kernelSetFunctions: writeRegistryValue(%s, %d)", (char *)ah->data, value);
+ debugC(DEBUG_GENERAL,"o8_kernelSetFunctions: writeRegistryValue(%s, %d)", str, value);
}
break;
case 33: // paletteSetIntensity
@@ -1371,22 +1371,22 @@ void ScummEngine_v8::o8_kernelGetFunctions() {
case 0xE0: // readRegistryValue
{
int idx = args[1];
- ArrayHeader *ah = (ArrayHeader *)getResourceAddress(rtString, idx);
- if (!strcmp((char *)ah->data, "SFX Volume"))
+ const char *str = (const char *)getStringAddress(idx);
+ if (!strcmp(str, "SFX Volume"))
push(ConfMan.getInt("sfx_volume") / 2);
- else if (!strcmp((char *)ah->data, "Voice Volume"))
+ else if (!strcmp(str, "Voice Volume"))
push(ConfMan.getInt("speech_volume") / 2);
- else if (!strcmp((char *)ah->data, "Music Volume"))
+ else if (!strcmp(str, "Music Volume"))
push(ConfMan.getInt("music_volume") / 2);
- else if (!strcmp((char *)ah->data, "Text Status"))
+ else if (!strcmp(str, "Text Status"))
push(ConfMan.getBool("subtitles"));
- else if (!strcmp((char *)ah->data, "Object Names"))
+ else if (!strcmp(str, "Object Names"))
push(ConfMan.getBool("object_labels"));
- else if (!strcmp((char *)ah->data, "Saveload Page"))
+ else if (!strcmp(str, "Saveload Page"))
push(14);
else // Use defaults
push(-1);
- debugC(DEBUG_GENERAL,"o8_kernelGetFunctions: readRegistryValue(%s)", (char *)ah->data);
+ debugC(DEBUG_GENERAL,"o8_kernelGetFunctions: readRegistryValue(%s)", str);
}
break;
case 0xE1: // imGetMusicPosition
diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp
index 19daa8f166..371017b8b5 100644
--- a/engines/scumm/scumm.cpp
+++ b/engines/scumm/scumm.cpp
@@ -1405,8 +1405,8 @@ void ScummEngine_v99he::resetScumm() {
// Array 129 is set to base name
int len = strlen(_filenamePattern.pattern);
- ArrayHeader *ah = defineArray(129, kStringArray, 0, 0, 0, len);
- memcpy(ah->data, _filenamePattern.pattern, len);
+ byte *data = defineArray(129, kStringArray, 0, 0, 0, len);
+ memcpy(data, _filenamePattern.pattern, len);
}
#endif