aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2002-12-27 14:36:28 +0000
committerMax Horn2002-12-27 14:36:28 +0000
commit8049e0625811b4fef2113f08a348cb6fba273cbf (patch)
treefd3c581ca89dcb744230cce03fa065a36c4bb659
parent81c421ec0cd4324aefa181c4b2719f2bd775a0e1 (diff)
downloadscummvm-rg350-8049e0625811b4fef2113f08a348cb6fba273cbf.tar.gz
scummvm-rg350-8049e0625811b4fef2113f08a348cb6fba273cbf.tar.bz2
scummvm-rg350-8049e0625811b4fef2113f08a348cb6fba273cbf.zip
fixed flobject loading in V8
svn-id: r6198
-rw-r--r--scumm/object.cpp58
-rw-r--r--scumm/script_v8.cpp13
-rw-r--r--scumm/scumm.h2
3 files changed, 46 insertions, 27 deletions
diff --git a/scumm/object.cpp b/scumm/object.cpp
index f784ccfe95..26d13c8d80 100644
--- a/scumm/object.cpp
+++ b/scumm/object.cpp
@@ -420,11 +420,11 @@ void Scumm::loadRoomObjects()
error("More than %d objects in room %d", _numLocalObjects, _roomResource);
od = &_objs[1];
-
if (_features & GF_AFTER_V8)
searchptr = rootptr = getResourceAddress(rtRoomScripts, _roomResource);
else
searchptr = rootptr = room;
+ assert(searchptr);
for (i = 0; i < _numObjectsInRoom; i++, od++) {
ptr = findResource(MKID('OBCD'), searchptr);
@@ -445,6 +445,9 @@ void Scumm::loadRoomObjects()
do {
char buf[32];
sprintf(buf, "roomobj-%d-", _roomResource);
+ if (_features & GF_AFTER_V8)
+ // TODO - maybe V8 is not the only that needs this?
+ ptr = findResource(MKID('VERB'), ptr, 0);
dumpResource(buf, od->obj_nr, ptr);
} while (0);
#endif
@@ -537,19 +540,19 @@ void Scumm::loadRoomObjectsSmall()
searchptr = NULL;
}
- od = &_objs[1];
- for (i = 1; i <= _numObjectsInRoom; i++, od++) {
- setupRoomObject(od, room);
+ for (i = 1; i <= _numObjectsInRoom; i++) {
+ setupRoomObject(&_objs[i], room);
}
CHECK_HEAP
}
-void Scumm::setupRoomObject(ObjectData *od, byte *room)
+void Scumm::setupRoomObject(ObjectData *od, byte *room, byte *searchptr)
{
CodeHeader *cdhd = NULL;
ImageHeader *imhd = NULL;
- byte *searchptr = NULL;
+
+ assert(room);
if (_features & GF_SMALL_HEADER) {
@@ -579,11 +582,13 @@ void Scumm::setupRoomObject(ObjectData *od, byte *room)
return;
}
- if (_features & GF_AFTER_V8)
- searchptr = getResourceAddress(rtRoomScripts, _roomResource);
- else
- searchptr = room;
-
+ if (searchptr == NULL) {
+ if (_features & GF_AFTER_V8)
+ searchptr = getResourceAddress(rtRoomScripts, _roomResource);
+ else
+ searchptr = room;
+ }
+
cdhd = (CodeHeader *)findResourceData(MKID('CDHD'), searchptr + od->OBCDoffset);
if (cdhd == NULL)
error("Room %d missing CDHD blocks(s)", _roomResource);
@@ -894,6 +899,7 @@ void Scumm::findObjectInRoom(FindObjectInRoom *fo, byte findWhat, uint id, uint
}
if (findWhat & foCodeHeader) {
searchptr = roomptr;
+ assert(searchptr);
for (i = 0;;) {
if (_features & GF_SMALL_HEADER)
obcdptr = findResourceSmall(MKID('OBCD'), searchptr);
@@ -926,6 +932,7 @@ void Scumm::findObjectInRoom(FindObjectInRoom *fo, byte findWhat, uint id, uint
roomptr = fo->roomptr;
if (findWhat & foImageHeader) {
searchptr = roomptr;
+ assert(searchptr);
for (i = 0;;) {
if (_features & GF_SMALL_HEADER)
obimptr = findResourceSmall(MKID('OBIM'), searchptr);
@@ -1286,10 +1293,10 @@ void Scumm::drawBlastObject(BlastObject *eo)
} else {
idx = getObjectIndex(eo->number);
assert(idx != -1);
- ptr = getResourceAddress(1, _roomResource) + _objs[idx].OBIMoffset;
+ ptr = getResourceAddress(rtRoom, _roomResource) + _objs[idx].OBIMoffset;
}
if (!ptr)
- error("BlastObject object %d image not found", eo->number);
+ error("BlastObject object %d (%d) image not found", eo->number, idx);
if (_features & GF_AFTER_V8) {
// The OBIM contains an IMAG, which in turn contains a WRAP, which contains
@@ -1594,39 +1601,44 @@ void Scumm::loadFlObject(uint object, uint room)
byte *flob, *roomptr;
uint32 obcd_size, obim_size, flob_size;
- /* Don't load an already loaded object */
+ // Don't load an already loaded object
if (whereIsObject(object) != WIO_NOT_FOUND)
return;
- /* Locate the object in the room resource */
+ // Locate the object in the room resource
findObjectInRoom(&foir, foImageHeader | foCodeHeader, object, room);
- /* Add an entry for the new floating object in the local object table */
+ // Add an entry for the new floating object in the local object table
if (++_numObjectsInRoom > _numLocalObjects)
error("loadFlObject: Local Object Table overflow");
od = &_objs[_numObjectsInRoom];
- /* Setup sizes */
+ // Setup sizes
obcd_size = READ_BE_UINT32_UNALIGNED(foir.obcd + 4);
od->OBCDoffset = 8;
od->OBIMoffset = obcd_size + 8;
obim_size = READ_BE_UINT32_UNALIGNED(foir.obim + 4);
flob_size = obcd_size + obim_size + 8;
- /* Allocate slot & memory for floating object */
+ // Get room pointer
+ roomptr = getResourceAddress(rtRoom, room);
+ assert(roomptr);
+
+ // Allocate slot & memory for floating object
slot = findFlObjectSlot();
createResource(rtFlObject, slot, flob_size);
-
- /* Copy object code + object image to floating object */
- roomptr = getResourceAddress(rtRoom, room);
flob = getResourceAddress(rtFlObject, slot);
+ assert(flob);
+
+ // Copy object code + object image to floating object
((uint32 *)flob)[0] = MKID('FLOB');
((uint32 *)flob)[1] = TO_BE_32(flob_size);
+
memcpy(flob + 8, roomptr - foir.roomptr + foir.obcd, obcd_size);
memcpy(flob + 8 + obcd_size, roomptr - foir.roomptr + foir.obim, obim_size);
- /* Setup local object flags */
- setupRoomObject(od, flob);
+ // Setup local object flags
+ setupRoomObject(od, flob, flob);
od->fl_object_index = slot;
}
diff --git a/scumm/script_v8.cpp b/scumm/script_v8.cpp
index de32d8013f..b818737887 100644
--- a/scumm/script_v8.cpp
+++ b/scumm/script_v8.cpp
@@ -199,8 +199,8 @@ void Scumm_v8::setupOpcodes()
OPCODE(o6_stopObjectCode),
/* 7C */
OPCODE(o6_stopScript),
- OPCODE(o6_jumpToScript), // FIXME - is this right? "O_CHAIN_SCRIPT"
- OPCODE(o6_dummy), // FIXME - O_RETURN ? WTF is this, why don't they use the stack?
+ OPCODE(o6_jumpToScript),
+ OPCODE(o6_dummy), // O_RETURN boils down to a NOP
OPCODE(o6_startObjectEx),
/* 80 */
OPCODE(o6_stopObjectScript), // FIXME - is this right?
@@ -907,7 +907,12 @@ void Scumm_v8::o8_resourceRoutines()
ensureResourceLoaded(rtCostume, resid);
break;
case 0x3E: // SO_HEAP_LOAD_OBJECT Load object to heap
- // TODO - is 'object' in COMI the same as FlObject in Sam&Max ?!?
+ {
+ // FIXME
+ int room = getObjectRoom(resid);
+ warning("o8_resourceRoutines: SO_HEAP_LOAD_OBJECT %d/%d", resid, room);
+ loadFlObject(resid, room);
+ }
break;
case 0x3F: // SO_HEAP_LOAD_ROOM Load room to heap
ensureResourceLoaded(rtRoom, resid);
@@ -1300,6 +1305,7 @@ void Scumm_v8::o6_kernelSetFunctions()
switch (args[0]) {
case 11: // lockObject
warning("o6_kernelSetFunctions: lockObject(%d)", args[1]);
+ lock(rtFlObject, args[1]); // FIXME - no idea if this is right?
// getObjectIndex(args[1]);
// if (ObjData.field28 != 0) {
// ObjData.field32 = 1;
@@ -1307,6 +1313,7 @@ void Scumm_v8::o6_kernelSetFunctions()
break;
case 12: // unlockObject
warning("o6_kernelSetFunctions: unlockObject(%d)", args[1]);
+ unlock(rtFlObject, args[1]); // FIXME - no idea if this is right?
// getObjectIndex(args[1]);
// if (ObjData.field28 != 0) {
// ObjData.field32 = 0;
diff --git a/scumm/scumm.h b/scumm/scumm.h
index 235131aa24..00956710d3 100644
--- a/scumm/scumm.h
+++ b/scumm/scumm.h
@@ -556,7 +556,7 @@ public:
int findInventory(int owner, int index);
int getInventoryCount(int owner);
- void setupRoomObject(ObjectData *od, byte *room);
+ void setupRoomObject(ObjectData *od, byte *room, byte *searchptr = NULL);
void removeObjectFromRoom(int obj);
void loadFlObject(uint object, uint room);
void nukeFlObjects(int min, int max);