diff options
author | Travis Howell | 2005-03-10 11:06:37 +0000 |
---|---|---|
committer | Travis Howell | 2005-03-10 11:06:37 +0000 |
commit | a913095ee017793b278a5079e224c2b23ae025d9 (patch) | |
tree | 99a3aeea239eaf9b70588b90290145410c4c5190 /scumm | |
parent | e21b1755b5ba3e3d57af75541e0409ba255a1c9d (diff) | |
download | scummvm-rg350-a913095ee017793b278a5079e224c2b23ae025d9.tar.gz scummvm-rg350-a913095ee017793b278a5079e224c2b23ae025d9.tar.bz2 scummvm-rg350-a913095ee017793b278a5079e224c2b23ae025d9.zip |
Add HE specific versions of findResource/findResourceData.
Required by WizImage functions, which sometimes alter data.
svn-id: r17060
Diffstat (limited to 'scumm')
-rw-r--r-- | scumm/intern.h | 4 | ||||
-rw-r--r-- | scumm/script_v100he.cpp | 4 | ||||
-rw-r--r-- | scumm/script_v72he.cpp | 57 | ||||
-rw-r--r-- | scumm/script_v90he.cpp | 8 | ||||
-rw-r--r-- | scumm/wiz_he.cpp | 69 |
5 files changed, 90 insertions, 52 deletions
diff --git a/scumm/intern.h b/scumm/intern.h index f6d63c4f61..4ef80496be 100644 --- a/scumm/intern.h +++ b/scumm/intern.h @@ -753,7 +753,9 @@ protected: void decodeScriptString(byte *dst, bool scriptString = false); void copyScriptString(byte *dst); - const byte *findWrappedBlock(uint32 tag, const byte *ptr, int state, bool flagError); + byte *heFindResourceData(uint32 tag, byte *ptr); + byte *heFindResource(uint32 tag, byte *ptr); + byte *findWrappedBlock(uint32 tag, byte *ptr, int state, bool flagError); /* HE version 72 script opcodes */ void o72_pushDWord(); diff --git a/scumm/script_v100he.cpp b/scumm/script_v100he.cpp index d3019b2f2b..792c0a44e1 100644 --- a/scumm/script_v100he.cpp +++ b/scumm/script_v100he.cpp @@ -2767,8 +2767,8 @@ void ScummEngine_v100he::decodeParseString(int m, int n) { break; case 78: { - const byte *dataPtr = getResourceAddress(rtTalkie, pop()); - const byte *text = findWrappedBlock(MKID('TEXT'), dataPtr, 0, 0); + byte *dataPtr = getResourceAddress(rtTalkie, pop()); + byte *text = findWrappedBlock(MKID('TEXT'), dataPtr, 0, 0); size = getResourceDataSize(text); memcpy(name, text, size); printString(m, name); diff --git a/scumm/script_v72he.cpp b/scumm/script_v72he.cpp index 36cf34b030..d9995b2680 100644 --- a/scumm/script_v72he.cpp +++ b/scumm/script_v72he.cpp @@ -585,16 +585,53 @@ void ScummEngine_v72he::decodeScriptString(byte *dst, bool scriptString) { *dst = 0; } -const byte *ScummEngine_v72he::findWrappedBlock(uint32 tag, const byte *ptr, int state, bool errorFlag) { +byte *ScummEngine_v72he::heFindResourceData(uint32 tag, byte *ptr) { + ptr = heFindResource(tag, ptr); + + if (ptr == NULL) + return NULL; + return ptr + _resourceHeaderSize; +} + +byte *ScummEngine_v72he::heFindResource(uint32 tag, byte *searchin) { + uint32 curpos, totalsize, size; + + debugC(DEBUG_RESOURCE, "heFindResource(%s, %lx)", tag2str(tag), searchin); + + assert(searchin); + searchin += 4; + _resourceLastSearchSize = totalsize = READ_BE_UINT32(searchin); + curpos = 8; + searchin += 4; + + while (curpos < totalsize) { + if (READ_UINT32(searchin) == tag) { + return searchin; + } + + size = READ_BE_UINT32(searchin + 4); + if ((int32)size <= 0) { + error("(%s) Not found in %d... illegal block len %d", tag2str(tag), 0, size); + return NULL; + } + + curpos += size; + searchin += size; + } + + return NULL; +} + +byte *ScummEngine_v72he::findWrappedBlock(uint32 tag, byte *ptr, int state, bool errorFlag) { if (READ_UINT32(ptr) == MKID('MULT')) { - const byte *offs, *wrap; + byte *offs, *wrap; uint32 size; - wrap = findResource(MKID('WRAP'), ptr); + wrap = heFindResource(MKID('WRAP'), ptr); if (wrap == NULL) return NULL; - offs = findResourceData(MKID('OFFS'), wrap); + offs = heFindResourceData(MKID('OFFS'), wrap); if (offs == NULL) return NULL; @@ -603,17 +640,17 @@ const byte *ScummEngine_v72he::findWrappedBlock(uint32 tag, const byte *ptr, int offs += READ_LE_UINT32(offs + state * sizeof(uint32)); - offs = findResourceData(tag, offs - 8); + offs = heFindResourceData(tag, offs - 8); if (offs) return offs; - offs = findResourceData(MKID('DEFA'), ptr); + offs = heFindResourceData(MKID('DEFA'), ptr); if (offs == NULL) return NULL; - return findResourceData(tag, offs - 8); + return heFindResourceData(tag, offs - 8); } else { - return findResourceData(tag, ptr); + return heFindResourceData(tag, ptr); } } @@ -2048,8 +2085,8 @@ void ScummEngine_v72he::decodeParseString(int m, int n) { break; case 0xE1: { - const byte *dataPtr = getResourceAddress(rtTalkie, pop()); - const byte *text = findWrappedBlock(MKID('TEXT'), dataPtr, 0, 0); + byte *dataPtr = getResourceAddress(rtTalkie, pop()); + byte *text = findWrappedBlock(MKID('TEXT'), dataPtr, 0, 0); size = getResourceDataSize(text); memcpy(name, text, size); printString(m, name); diff --git a/scumm/script_v90he.cpp b/scumm/script_v90he.cpp index 8e16881fe2..52e29ccde4 100644 --- a/scumm/script_v90he.cpp +++ b/scumm/script_v90he.cpp @@ -1994,18 +1994,18 @@ void ScummEngine_v90he::setHEPaletteFromCostume(int palSlot, int resId) { void ScummEngine_v90he::setHEPaletteFromImage(int palSlot, int resId, int state) { assert(palSlot >= 1 && palSlot <= _numPalettes); - const uint8 *data = getResourceAddress(rtImage, resId); + uint8 *data = getResourceAddress(rtImage, resId); assert(data); - const uint8 *rgbs = findWrappedBlock(MKID('RGBS'), data, state, 0); + uint8 *rgbs = findWrappedBlock(MKID('RGBS'), data, state, 0); assert(rgbs); setHEPaletteFromPtr(palSlot, rgbs); } void ScummEngine_v90he::setHEPaletteFromRoom(int palSlot, int resId, int state) { assert(palSlot >= 1 && palSlot <= _numPalettes); - const uint8 *data = getResourceAddress(rtRoom, resId); + uint8 *data = getResourceAddress(rtRoom, resId); assert(data); - const uint8 *rgbs = findWrappedBlock(MKID('PALS'), data, state, 0); + uint8 *rgbs = findWrappedBlock(MKID('PALS'), data, state, 0); assert(rgbs); setHEPaletteFromPtr(palSlot, rgbs); } diff --git a/scumm/wiz_he.cpp b/scumm/wiz_he.cpp index 427497ad8d..94c6b718d0 100644 --- a/scumm/wiz_he.cpp +++ b/scumm/wiz_he.cpp @@ -841,9 +841,9 @@ void ScummEngine_v72he::displayWizImage(const WizImage *pwi) { } void ScummEngine_v72he::getWizImageDim(int resnum, int state, int32 &w, int32 &h) { - const uint8 *dataPtr = getResourceAddress(rtImage, resnum); + uint8 *dataPtr = getResourceAddress(rtImage, resnum); assert(dataPtr); - const uint8 *wizh = findWrappedBlock(MKID('WIZH'), dataPtr, state, 0); + uint8 *wizh = findWrappedBlock(MKID('WIZH'), dataPtr, state, 0); assert(wizh); w = READ_LE_UINT32(wizh + 0x4); h = READ_LE_UINT32(wizh + 0x8); @@ -852,12 +852,12 @@ void ScummEngine_v72he::getWizImageDim(int resnum, int state, int32 &w, int32 &h uint8 *ScummEngine_v72he::drawWizImage(int restype, const WizImage *pwi) { debug(1, "drawWizImage(%d, %d, %d, %d, 0x%X)", restype, pwi->resNum, pwi->x1, pwi->y1, pwi->flags); uint8 *dst = NULL; - const uint8 *dataPtr = getResourceAddress(restype, pwi->resNum); + uint8 *dataPtr = getResourceAddress(restype, pwi->resNum); if (dataPtr) { - const uint8 *rmap = NULL; - const uint8 *xmap = findWrappedBlock(MKID('XMAP'), dataPtr, pwi->state, 0); + uint8 *rmap = NULL; + uint8 *xmap = findWrappedBlock(MKID('XMAP'), dataPtr, pwi->state, 0); - const uint8 *wizh = findWrappedBlock(MKID('WIZH'), dataPtr, pwi->state, 0); + uint8 *wizh = findWrappedBlock(MKID('WIZH'), dataPtr, pwi->state, 0); assert(wizh); uint32 comp = READ_LE_UINT32(wizh + 0x0); uint32 width = READ_LE_UINT32(wizh + 0x4); @@ -865,17 +865,17 @@ uint8 *ScummEngine_v72he::drawWizImage(int restype, const WizImage *pwi) { debug(1, "wiz_header.comp = %d wiz_header.w = %d wiz_header.h = %d)", comp, width, height); assert(comp == 0 || comp == 1 || comp == 2 || comp == 3 || comp == 10 || comp == 11); - const uint8 *wizd = findWrappedBlock(MKID('WIZD'), dataPtr, pwi->state, 0); + uint8 *wizd = findWrappedBlock(MKID('WIZD'), dataPtr, pwi->state, 0); assert(wizd); if (pwi->flags & 1) { - const uint8 *pal = findWrappedBlock(MKID('RGBS'), dataPtr, pwi->state, 0); + uint8 *pal = findWrappedBlock(MKID('RGBS'), dataPtr, pwi->state, 0); assert(pal); setPaletteFromPtr(pal, 256); } if (pwi->flags & 2) { rmap = findWrappedBlock(MKID('RMAP'), dataPtr, pwi->state, 0); assert(rmap); - const uint8 *rgbs = findWrappedBlock(MKID('RGBS'), dataPtr, pwi->state, 0); + uint8 *rgbs = findWrappedBlock(MKID('RGBS'), dataPtr, pwi->state, 0); assert(rgbs); warning("drawWizImage() unhandled flag 0x2"); // XXX modify 'RMAP' buffer @@ -912,7 +912,7 @@ uint8 *ScummEngine_v72he::drawWizImage(int restype, const WizImage *pwi) { _wiz.copyWizImage(dst, wizd, cw, ch, pwi->x1, pwi->y1, width, height, &rScreen); } } else if (comp == 0 || comp == 2 || comp == 3) { - const uint8 *trns = findWrappedBlock(MKID('TRNS'), dataPtr, pwi->state, 0); + uint8 *trns = findWrappedBlock(MKID('TRNS'), dataPtr, pwi->state, 0); int color = (trns == NULL) ? VAR(VAR_WIZ_TCOLOR) : -1; const uint8 *pal = xmap; if (pwi->flags & 2) { @@ -1117,9 +1117,9 @@ void ScummEngine_v72he::flushWizBuffer() { } void ScummEngine_v80he::loadImgSpot(int resId, int state, int16 &x, int16 &y) { - const uint8 *dataPtr = getResourceAddress(rtImage, resId); + uint8 *dataPtr = getResourceAddress(rtImage, resId); assert(dataPtr); - const uint8 *spotPtr = findWrappedBlock(MKID('SPOT'), dataPtr, state, 0); + uint8 *spotPtr = findWrappedBlock(MKID('SPOT'), dataPtr, state, 0); if (spotPtr) { x = (int16)READ_LE_UINT32(spotPtr + 0); y = (int16)READ_LE_UINT32(spotPtr + 4); @@ -1317,9 +1317,9 @@ void ScummEngine_v90he::fillWizRect(const WizParameters *params) { if (params->processFlags & kWPFNewState) { state = params->img.state; } - const uint8 *dataPtr = getResourceAddress(rtImage, params->img.resNum); + uint8 *dataPtr = getResourceAddress(rtImage, params->img.resNum); if (dataPtr) { - const uint8 *wizh = findWrappedBlock(MKID('WIZH'), dataPtr, state, 0); + uint8 *wizh = findWrappedBlock(MKID('WIZH'), dataPtr, state, 0); assert(wizh); uint32 ic = READ_LE_UINT32(wizh + 0x0); uint32 iw = READ_LE_UINT32(wizh + 0x4); @@ -1341,16 +1341,15 @@ void ScummEngine_v90he::fillWizRect(const WizParameters *params) { } else { color = VAR(93); } - // XXX -// uint8 *wizd = findWrappedBlock(MKID('WIZD'), dataPtr, state, 0); -// assert(wizd); -// int dx = r1.width(); -// int dy = r1.height(); -// wizd += r1.top * iw + r1.left; -// while (dy--) { -// memset(wizd, color, dx); -// wizd += iw; -// } + uint8 *wizd = findWrappedBlock(MKID('WIZD'), dataPtr, state, 0); + assert(wizd); + int dx = r1.width(); + int dy = r1.height(); + wizd += r1.top * iw + r1.left; + while (dy--) { + memset(wizd, color, dx); + wizd += iw; + } } } @@ -1412,7 +1411,7 @@ void ScummEngine_v90he::processWizImage(const WizParameters *params) { } break; case 6: - /*if (params->processFlags & 0x40) { + if (params->processFlags & 0x40) { int state = (params->processFlags & 0x400) ? params->img.state : 0; int num = params->remapNum; const uint8 *index = params->remapIndex; @@ -1425,7 +1424,7 @@ void ScummEngine_v90he::processWizImage(const WizParameters *params) { uint8 idx = *index++; rmap[0xC + idx] = params->remapColor[idx]; } - }*/ + } break; // HE 99+ case 8: @@ -1462,14 +1461,14 @@ int ScummEngine_v90he::getWizImageStates(int resnum) { int ScummEngine_v90he::isWizPixelNonTransparent(int restype, int resnum, int state, int x, int y, int flags) { int ret = 0; - const uint8 *data = getResourceAddress(restype, resnum); + uint8 *data = getResourceAddress(restype, resnum); assert(data); - const uint8 *wizh = findWrappedBlock(MKID('WIZH'), data, state, 0); + uint8 *wizh = findWrappedBlock(MKID('WIZH'), data, state, 0); assert(wizh); uint32 c = READ_LE_UINT32(wizh + 0x0); int w = READ_LE_UINT32(wizh + 0x4); int h = READ_LE_UINT32(wizh + 0x8); - const uint8 *wizd = findWrappedBlock(MKID('WIZD'), data, state, 0); + uint8 *wizd = findWrappedBlock(MKID('WIZD'), data, state, 0); assert(wizd); if (x >= 0 && x < w && y >= 0 && y < h) { if (flags & kWIFFlipX) { @@ -1489,14 +1488,14 @@ int ScummEngine_v90he::isWizPixelNonTransparent(int restype, int resnum, int sta uint8 ScummEngine_v90he::getWizPixelColor(int restype, int resnum, int state, int x, int y, int flags) { uint8 color; - const uint8 *data = getResourceAddress(restype, resnum); + uint8 *data = getResourceAddress(restype, resnum); assert(data); - const uint8 *wizh = findWrappedBlock(MKID('WIZH'), data, state, 0); + uint8 *wizh = findWrappedBlock(MKID('WIZH'), data, state, 0); assert(wizh); uint32 c = READ_LE_UINT32(wizh + 0x0); uint32 w = READ_LE_UINT32(wizh + 0x4); uint32 h = READ_LE_UINT32(wizh + 0x8); - const uint8 *wizd = findWrappedBlock(MKID('WIZD'), data, state, 0); + uint8 *wizd = findWrappedBlock(MKID('WIZD'), data, state, 0); assert(wizd); if (c == 1) { color = _wiz.getWizPixelColor(wizd, x, y, w, h, VAR(VAR_WIZ_TCOLOR)); @@ -1512,14 +1511,14 @@ int ScummEngine_v90he::computeWizHistogram(int resnum, int state, int x, int y, writeVar(0, 0); defineArray(0, kDwordArray, 0, 0, 0, 255); if (readVar(0) != 0) { - const uint8 *data = getResourceAddress(rtImage, resnum); + uint8 *data = getResourceAddress(rtImage, resnum); assert(data); - const uint8 *wizh = findWrappedBlock(MKID('WIZH'), data, state, 0); + uint8 *wizh = findWrappedBlock(MKID('WIZH'), data, state, 0); assert(wizh); uint32 ic = READ_LE_UINT32(wizh + 0x0); uint32 iw = READ_LE_UINT32(wizh + 0x4); uint32 ih = READ_LE_UINT32(wizh + 0x8); - const uint8 *wizd = findWrappedBlock(MKID('WIZD'), data, state, 0); + uint8 *wizd = findWrappedBlock(MKID('WIZD'), data, state, 0); assert(wizd); Common::Rect rWiz(iw, ih); Common::Rect rCap(x, y, w + 1, h + 1); |