aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scumm/intern.h2
-rw-r--r--scumm/resource_v7he.cpp54
-rw-r--r--scumm/script_v100he.cpp15
-rw-r--r--scumm/script_v72he.cpp38
-rw-r--r--scumm/script_v80he.cpp38
-rw-r--r--scumm/script_v90he.cpp2
6 files changed, 108 insertions, 41 deletions
diff --git a/scumm/intern.h b/scumm/intern.h
index 16f1504f10..f482116312 100644
--- a/scumm/intern.h
+++ b/scumm/intern.h
@@ -808,6 +808,7 @@ protected:
byte *heFindResource(uint32 tag, byte *ptr);
byte *findWrappedBlock(uint32 tag, byte *ptr, int state, bool flagError);
int findObject(int x, int y, int num, int *args);
+ int getMusicResourceSize(int id);
/* HE version 72 script opcodes */
void o72_pushDWord();
@@ -895,6 +896,7 @@ protected:
void o80_drawWizPolygon();
void o80_unknownE0();
void o80_pickVarRandom();
+ void o80_getResourceSize();
};
struct SpriteInfo;
diff --git a/scumm/resource_v7he.cpp b/scumm/resource_v7he.cpp
index 52e92518b5..4b6eab74d6 100644
--- a/scumm/resource_v7he.cpp
+++ b/scumm/resource_v7he.cpp
@@ -1753,4 +1753,58 @@ byte *ScummEngine_v72he::getStringAddress(int i) {
return ((ScummEngine_v72he::ArrayHeader *)addr)->data;
}
+int ScummEngine_v72he::getMusicResourceSize(int id) {
+ int size, total_size;
+ uint tracks, skip;
+ char buf[32], buf1[128];
+ File musicFile;
+
+ sprintf(buf, "%s.he4", getGameName());
+
+ if (_substResFileNameIndex > 0) {
+ generateSubstResFileName(buf, buf1, sizeof(buf1));
+ strcpy(buf, buf1);
+ }
+ if (musicFile.open(buf) == false) {
+ warning("getMusicResourceSize: Music file is not open");
+ return 0;
+ }
+ musicFile.seek(4, SEEK_SET);
+ total_size = musicFile.readUint32BE();
+ musicFile.seek(+8, SEEK_CUR);
+ tracks = musicFile.readUint32LE();
+
+ skip = 0;
+ if (id >= 8500)
+ skip = (id - 8500);
+ else if (id >= 8000)
+ skip = (id - 8000);
+ else if (id >= 4000)
+ skip = (id - 4000);
+
+ if (skip > tracks - 1)
+ skip = 0;
+
+ if (_heversion >= 80) {
+ // Skip to offsets
+ musicFile.seek(+40, SEEK_CUR);
+
+ // Skip to correct music header
+ skip *= 21;
+ } else {
+ // Skip to offsets
+ musicFile.seek(+4, SEEK_CUR);
+
+ // Skip to correct music header
+ skip *= 25;
+ }
+
+ musicFile.seek(+skip, SEEK_CUR);
+ musicFile.readUint32LE();
+ size = musicFile.readUint32LE();
+ musicFile.close();
+
+ return size;
+}
+
} // End of namespace Scumm
diff --git a/scumm/script_v100he.cpp b/scumm/script_v100he.cpp
index c76d859354..b6e6a93bd3 100644
--- a/scumm/script_v100he.cpp
+++ b/scumm/script_v100he.cpp
@@ -2191,9 +2191,9 @@ void ScummEngine_v100he::o100_writeFile() {
}
void ScummEngine_v100he::o100_getResourceSize() {
- int size = 0, type;
+ int size, type;
- int idx = pop();
+ int resid = pop();
byte subOp = fetchScriptByte();
switch (subOp) {
@@ -2210,9 +2210,8 @@ void ScummEngine_v100he::o100_getResourceSize() {
type = rtScript;
break;
case 72:
- if (idx > _numSounds) {
- // TODO Music resource size
- push(100);
+ if (resid > _numSounds) {
+ push(getMusicResourceSize(resid));
return;
}
type = rtSound;
@@ -2221,9 +2220,9 @@ void ScummEngine_v100he::o100_getResourceSize() {
error("o100_getResourceSize: default type %d", subOp);
}
- const byte *ptr = getResourceAddress(type, idx);
- if (ptr)
- size = READ_BE_UINT32(ptr + 4) - 8;
+ const byte *ptr = getResourceAddress(type, resid);
+ assert(ptr);
+ size = READ_BE_UINT32(ptr + 4) - 8;
push(size);
}
diff --git a/scumm/script_v72he.cpp b/scumm/script_v72he.cpp
index 891cf9af45..8159edf1bc 100644
--- a/scumm/script_v72he.cpp
+++ b/scumm/script_v72he.cpp
@@ -2151,41 +2151,17 @@ void ScummEngine_v72he::o72_writeINI() {
}
void ScummEngine_v72he::o72_getResourceSize() {
- int size = 0, type;
+ int resid, size;
- int idx = pop();
- byte subOp = fetchScriptByte();
-
- switch (subOp) {
- case 13:
- if (idx > _numSounds) {
- // TODO Music resource size
- push(100);
- return;
- }
- type = rtSound;
- break;
- case 14:
- type = rtRoomImage;
- break;
- case 15:
- type = rtImage;
- break;
- case 16:
- type = rtCostume;
- break;
- case 17:
- type = rtScript;
- break;
- default:
- warning("o72_getResourceSize: default type %d", subOp);
- push(0);
+ resid = pop();
+ if (resid > _numSounds) {
+ push(getMusicResourceSize(resid));
return;
}
- const byte *ptr = getResourceAddress(type, idx);
- if (ptr)
- size = READ_BE_UINT32(ptr + 4) - 8;
+ const byte *ptr = getResourceAddress(rtSound, resid);
+ assert(ptr);
+ size = READ_BE_UINT32(ptr + 4) - 8;
push(size);
}
diff --git a/scumm/script_v80he.cpp b/scumm/script_v80he.cpp
index ba931d2ffb..11a002c859 100644
--- a/scumm/script_v80he.cpp
+++ b/scumm/script_v80he.cpp
@@ -352,7 +352,7 @@ void ScummEngine_v80he::setupOpcodes() {
OPCODE(o70_getCharIndexInString),
OPCODE(o6_invalid),
/* F8 */
- OPCODE(o72_getResourceSize),
+ OPCODE(o80_getResourceSize),
OPCODE(o72_setFilePath),
OPCODE(o72_setWindowCaption),
OPCODE(o70_polygonOps),
@@ -808,4 +808,40 @@ void ScummEngine_v80he::o80_pickVarRandom() {
push(readArray(value, 0, num));
}
+void ScummEngine_v80he::o80_getResourceSize() {
+ int size, type;
+
+ int resid = pop();
+ byte subOp = fetchScriptByte();
+
+ switch (subOp) {
+ case 13:
+ if (resid > _numSounds) {
+ push(getMusicResourceSize(resid));
+ return;
+ }
+ type = rtSound;
+ break;
+ case 14:
+ type = rtRoomImage;
+ break;
+ case 15:
+ type = rtImage;
+ break;
+ case 16:
+ type = rtCostume;
+ break;
+ case 17:
+ type = rtScript;
+ break;
+ default:
+ error("o80_getResourceSize: default type %d", subOp);
+ }
+
+ const byte *ptr = getResourceAddress(type, resid);
+ assert(ptr);
+ size = READ_BE_UINT32(ptr + 4) - 8;
+ push(size);
+}
+
} // End of namespace Scumm
diff --git a/scumm/script_v90he.cpp b/scumm/script_v90he.cpp
index 9ea7e74780..4caa20a6bd 100644
--- a/scumm/script_v90he.cpp
+++ b/scumm/script_v90he.cpp
@@ -352,7 +352,7 @@ void ScummEngine_v90he::setupOpcodes() {
OPCODE(o70_getCharIndexInString),
OPCODE(o6_invalid),
/* F8 */
- OPCODE(o72_getResourceSize),
+ OPCODE(o80_getResourceSize),
OPCODE(o72_setFilePath),
OPCODE(o72_setWindowCaption),
OPCODE(o70_polygonOps),