aboutsummaryrefslogtreecommitdiff
path: root/resource.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'resource.cpp')
-rw-r--r--resource.cpp237
1 files changed, 203 insertions, 34 deletions
diff --git a/resource.cpp b/resource.cpp
index 1afb2351a6..bff925159a 100644
--- a/resource.cpp
+++ b/resource.cpp
@@ -17,6 +17,9 @@
*
* Change Log:
* $Log$
+ * Revision 1.3 2001/10/16 10:01:47 strigeus
+ * preliminary DOTT support
+ *
* Revision 1.2 2001/10/10 10:02:33 strigeus
* alternative mouse cursor
* basic save&load
@@ -164,6 +167,7 @@ void Scumm::askForDisk() {
error("askForDisk: not yet implemented");
}
+#if !defined(DOTT)
void Scumm::readIndexFile(int mode) {
uint32 blocktype,itemsize;
@@ -192,18 +196,18 @@ void Scumm::readIndexFile(int mode) {
break;
case MKID('DOBJ'):
- _maxNrObjects = fileReadWordLE();
- _objectFlagTable = (byte*)alloc(_maxNrObjects);
+ _numGlobalObjects = fileReadWordLE();
+ _objectFlagTable = (byte*)alloc(_numGlobalObjects);
if (mode==1) {
fileSeek(_fileHandle, itemsize - 10, 1);
break;
}
- _classData = (uint32*)alloc(_maxNrObjects * sizeof(uint32));
- fileRead(_fileHandle, _objectFlagTable, _maxNrObjects);
- fileRead(_fileHandle, _classData, _maxNrObjects * sizeof(uint32));
+ _classData = (uint32*)alloc(_numGlobalObjects * sizeof(uint32));
+ fileRead(_fileHandle, _objectFlagTable, _numGlobalObjects);
+ fileRead(_fileHandle, _classData, _numGlobalObjects * sizeof(uint32));
#if defined(SCUMM_BIG_ENDIAN)
- for (i=0; i<_maxNrObjects; i++)
+ for (i=0; i<_numGlobalObjects; i++)
_classData[i] = FROM_LE_32(_classData[i]);
#endif
break;
@@ -239,7 +243,7 @@ void Scumm::readIndexFile(int mode) {
case MKID('DSOU'):
readResTypeList(4,MKID('SOUN'),"sound");
break;
-
+
default:
error("Bad ID %c%c%c%c found in directory!", blocktype&0xFF, blocktype>>8, blocktype>>16, blocktype>>24);
return;
@@ -253,27 +257,147 @@ void Scumm::readIndexFile(int mode) {
openRoom(-1);
- _numGlobalScriptsUsed = _maxScripts;
+ _numGlobalScripts = _maxScripts;
_dynamicRoomOffsets = true;
}
+#else
-void Scumm::readResTypeList(int id, uint32 tag, const char *name) {
+
+void Scumm::readIndexFile() {
+ uint32 blocktype,itemsize;
+ int numblock = 0;
int num;
+
+ debug(9, "readIndexFile()");
+
+ openRoom(-1);
+ openRoom(0);
+
+ while (1) {
+ blocktype = fileReadDword();
+
+ if (fileReadFailed(_fileHandle))
+ break;
+ itemsize = fileReadDwordBE();
+
+ numblock++;
+
+ switch(blocktype) {
+ case MKID('DCHR'):
+ readResTypeList(6,MKID('CHAR'),"charset");
+ break;
+
+ case MKID('DOBJ'):
+ num = fileReadWordLE();
+ assert(num == _numGlobalObjects);
+ fileRead(_fileHandle, _objectFlagTable, num);
+ fileRead(_fileHandle, _classData, num * sizeof(uint32));
#if defined(SCUMM_BIG_ENDIAN)
- int i;
+ for (i=0; i<_numGlobalObjects; i++)
+ _classData[i] = FROM_LE_32(_classData[i]);
#endif
+ break;
+
+ case MKID('RNAM'):
+ fileSeek(_fileHandle, itemsize-8,1);
+ break;
+
+ case MKID('DROO'):
+ readResTypeList(1,MKID('ROOM'),"room");
+ break;
+
+ case MKID('DSCR'):
+ readResTypeList(2,MKID('SCRP'),"script");
+ break;
+
+ case MKID('DCOS'):
+ readResTypeList(3,MKID('COST'),"costume");
+ break;
+
+ case MKID('MAXS'):
+ readMAXS();
+ break;
+
+ case MKID('DSOU'):
+ readResTypeList(4,MKID('SOUN'),"sound");
+ break;
+
+ case MKID('AARY'):
+ readArrayFromIndexFile();
+ break;
+
+ default:
+ error("Bad ID %c%c%c%c found in directory!", blocktype&0xFF, blocktype>>8, blocktype>>16, blocktype>>24);
+ return;
+ }
+ }
+
+ clearFileReadFailed(_fileHandle);
+
+ if (numblock!=9)
+ error("Not enough blocks read from directory");
+
+ openRoom(-1);
+}
+#endif
+
+
+#if defined(DOTT)
+void Scumm::readArrayFromIndexFile() {
+ int num;
+ int a,b,c;
+
+ while ((num = fileReadWordLE()) != 0) {
+ a = fileReadWordLE();
+ b = fileReadWordLE();
+ c = fileReadWordLE();
+ if (c==1)
+ defineArray(num, 1, a, b);
+ else
+ defineArray(num, 5, a, b);
+ }
+}
+
+#endif
+
+#if defined(DOTT)
+
+void Scumm::readResTypeList(int id, uint32 tag, const char *name) {
+ int num,i;
+
+ debug(9, "readResTypeList(%d,%x,%s)",id,FROM_LE_32(tag),name);
+
+ num = fileReadWordLE();
+ assert(num == res.num[id]);
+
+ fileRead(_fileHandle, res.roomno[id], num*sizeof(uint8));
+ fileRead(_fileHandle, res.roomoffs[id], num*sizeof(uint32));
+#if defined(SCUMM_BIG_ENDIAN)
+ for (i=0; i<num; i++)
+ res.roomoffs[id][i] = FROM_LE_32(res.roomoffs[id][i]);
+#endif
+
+}
+
+
+
+#else
+
+void Scumm::readResTypeList(int id, uint32 tag, const char *name) {
+ int num;
+ int i;
debug(9, "readResTypeList(%d,%x,%s)",id,FROM_LE_32(tag),name);
num = fileReadWordLE();
- if (num>0xFF) {
+ if (num>=0xFF) {
error("Too many %ss (%d) in directory", name, num);
}
allocResTypeData(id, tag, num, name, 1);
- fileRead(_fileHandle, res.roomno[id], num);
+ fileRead(_fileHandle, res.roomno[id], num*sizeof(uint8));
fileRead(_fileHandle, res.roomoffs[id], num*sizeof(uint32));
#if defined(SCUMM_BIG_ENDIAN)
@@ -282,8 +406,16 @@ void Scumm::readResTypeList(int id, uint32 tag, const char *name) {
#endif
}
+#endif
+
void Scumm::allocResTypeData(int id, uint32 tag, int num, const char *name, int mode) {
debug(9, "allocResTypeData(%d,%x,%d,%s,%d)",id,FROM_LE_32(tag),num,name,mode);
+ assert(id>=0 && id<sizeof(res.mode)/sizeof(res.mode[0]));
+
+ if (num>=512) {
+ error("Too many %ss (%d) in directory", name, num);
+ }
+
res.mode[id] = mode;
res.num[id] = num;
res.tags[id] = tag;
@@ -336,7 +468,7 @@ void Scumm::ensureResourceLoaded(int type, int i) {
loadResource(type, i);
if (type==1 && i==_roomResource)
- vm.vars[VAR_ROOM_FLAG] = 1;
+ _vars[VAR_ROOM_FLAG] = 1;
}
int Scumm::loadResource(int type, int index) {
@@ -436,7 +568,6 @@ int Scumm::readSoundResource(int type, int index) {
return 0;
}
-
int Scumm::getResourceRoomNr(int type, int index) {
if (type==1)
return index;
@@ -448,7 +579,7 @@ byte *Scumm::getResourceAddress(int type, int index) {
debug(9, "getResourceAddress(%d,%d)", type, index);
- checkHeap();
+ CHECK_HEAP
validateResource("getResourceAddress", type, index);
@@ -473,7 +604,7 @@ void Scumm::setResourceFlags(int type, int index, byte flag) {
byte *Scumm::createResource(int type, int index, uint32 size) {
byte *ptr;
- checkHeap();
+ CHECK_HEAP
debug(9, "createResource(%d,%d,%d)", type, index,size);
@@ -483,7 +614,7 @@ byte *Scumm::createResource(int type, int index, uint32 size) {
validateResource("allocating", type, index);
nukeResource(type, index);
- checkHeap();
+ CHECK_HEAP
ptr = (byte*)alloc(size + sizeof(ResHeader));
if (ptr==NULL) {
@@ -509,7 +640,7 @@ void Scumm::nukeResource(int type, int index) {
debug(9, "nukeResource(%d,%d)", type, index);
- checkHeap();
+ CHECK_HEAP
assert( res.address[type] );
assert( index>=0 && index < res.num[type]);
@@ -607,22 +738,10 @@ void Scumm::loadPtrToResource(int type, int resindex, byte *source) {
int i,len;
nukeResource(type, resindex);
- if (!source) {
- ptr = _scriptPointer;
- } else {
- ptr = source;
- }
- len = 0;
- do {
- i = *ptr++;
- if (!i) break;
- len++;
- if (i==0xFF)
- ptr += 3, len += 3;
- } while (1);
-
- if (++len <= 1)
+ len = getStringLen(source);
+
+ if (len <= 1)
return;
alloced = createResource(type, resindex, len);
@@ -648,7 +767,57 @@ void Scumm::unkHeapProc2(int a, int b) {
}
void Scumm::unkResProc(int a, int b) {
- error("unkResProc:not implemented");
+ warning("unkResProc:not implemented");
}
+#if defined(DOTT)
+void Scumm::readMAXS() {
+ _numVariables = fileReadWordLE();
+ fileReadWordLE();
+ _numBitVariables = fileReadWordLE();
+ _numLocalObjects = fileReadWordLE();
+ _numArray = fileReadWordLE();
+ fileReadWordLE();
+ _numVerbs = fileReadWordLE();
+ _numFlObject = fileReadWordLE();
+ _numInventory = fileReadWordLE();
+ _numRooms = fileReadWordLE();
+ _numScripts = fileReadWordLE();
+ _numSounds = fileReadWordLE();
+ _numCharsets = fileReadWordLE();
+ _numCostumes = fileReadWordLE();
+ _numGlobalObjects = fileReadWordLE();
+
+ allocResTypeData(3, MKID('COST'), _numCostumes, "costume", 1);
+ allocResTypeData(1, MKID('ROOM'), _numRooms, "room", 1);
+ allocResTypeData(4, MKID('SOUN'), _numSounds, "sound", 1);
+ allocResTypeData(2, MKID('SCRP'), _numScripts, "script", 1);
+ allocResTypeData(6, MKID('CHAR'), _numCharsets, "charset", 1);
+ allocResTypeData(5, MKID('NONE'), _numInventory, "inventory", 0);
+ allocResTypeData(8, MKID('NONE'), _numVerbs,"verb", 0);
+ allocResTypeData(7, MKID('NONE'), _numArray,"array", 0);
+ allocResTypeData(13, MKID('NONE'),_numFlObject,"flobject", 0);
+ allocResTypeData(12,MKID('NONE'),10, "temp", 0);
+ allocResTypeData(11,MKID('NONE'),5, "scale table", 0);
+ allocResTypeData(9, MKID('NONE'),13,"actor name", 0);
+ allocResTypeData(10, MKID('NONE'),10,"buffer", 0);
+ allocResTypeData(14, MKID('NONE'),10,"boxes", 0);
+ allocResTypeData(16, MKID('NONE'),50,"new name", 0);
+
+ _objectFlagTable = (byte*)alloc(_numGlobalObjects);
+ _inventory = (uint16*)alloc(_numInventory * sizeof(uint16));
+ _arrays = (byte*)alloc(_numArray);
+ _verbs = (VerbSlot*)alloc(_numVerbs * sizeof(VerbSlot));
+ _objs = (ObjectData*)alloc(_numLocalObjects * sizeof(ObjectData));
+ _vars = (int16*)alloc(_numVariables * sizeof(int16));
+ _bitVars = (byte*)alloc(_numBitVariables >> 3);
+ _newNames = (uint16*)alloc(50 * sizeof(uint16));
+ _classData = (uint32*)alloc(_numGlobalObjects * sizeof(uint32));
+
+ _numGlobalScripts = 200;
+ _dynamicRoomOffsets = 1;
+}
+#endif
+
+