diff options
author | Matthew Hoops | 2012-03-20 14:18:57 -0400 |
---|---|---|
committer | Matthew Hoops | 2012-03-20 14:49:16 -0400 |
commit | 71756bdf4eae5ba9cc3f329b85e894f04640aaef (patch) | |
tree | 40d464262da107ab5eed82f198685209161ebac1 /engines/dreamweb | |
parent | 03eba05b09e5c9e5a351f8111185934b92a3fed3 (diff) | |
parent | 3c3576a224b92c703b4e8ea20008ac8a069980dd (diff) | |
download | scummvm-rg350-71756bdf4eae5ba9cc3f329b85e894f04640aaef.tar.gz scummvm-rg350-71756bdf4eae5ba9cc3f329b85e894f04640aaef.tar.bz2 scummvm-rg350-71756bdf4eae5ba9cc3f329b85e894f04640aaef.zip |
Merge remote branch 'upstream/master' into pegasus
Diffstat (limited to 'engines/dreamweb')
31 files changed, 9574 insertions, 13341 deletions
diff --git a/engines/dreamweb/README b/engines/dreamweb/README deleted file mode 100644 index d184613249..0000000000 --- a/engines/dreamweb/README +++ /dev/null @@ -1,12 +0,0 @@ - -WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - -Some files(dreamgen.*) in this directory is auto-generated. This means -(at least for some time) any changes to them will be lost. - -Please look into /devtools/tasmrecover directory, patch assembler source -or translator and run ./tasm-recover script. - -Then copy dreamgen.cpp/dreamgen.h to engine/dreamweb and check the diffs. - -If you'd like to reimplement something, blacklist it, then run script. diff --git a/engines/dreamweb/backdrop.cpp b/engines/dreamweb/backdrop.cpp index 3e005fdec9..1db2663624 100644 --- a/engines/dreamweb/backdrop.cpp +++ b/engines/dreamweb/backdrop.cpp @@ -22,13 +22,12 @@ #include "dreamweb/dreamweb.h" -namespace DreamGen { +namespace DreamWeb { -void DreamGenContext::doBlocks() { - uint16 dstOffset = data.word(kMapady) * 320 + data.word(kMapadx); - uint16 mapOffset = kMap + data.byte(kMapy) * kMapwidth + data.byte(kMapx); - const uint8 *mapData = getSegment(data.word(kMapdata)).ptr(mapOffset, 0); - const uint8 *blocks = getSegment(data.word(kBackdrop)).ptr(kBlocks, 0); +void DreamWebEngine::doBlocks() { + uint16 dstOffset = _mapAdY * 320 + _mapAdX; + uint16 mapOffset = _mapY * kMapWidth + _mapX; + const uint8 *mapData = _mapData + mapOffset; uint8 *dstBuffer = workspace() + dstOffset; for (size_t i = 0; i < 10; ++i) { @@ -36,7 +35,7 @@ void DreamGenContext::doBlocks() { uint16 blockType = mapData[j]; if (blockType != 0) { uint8 *dst = dstBuffer + i * 320 * 16 + j * 16; - const uint8 *block = blocks + blockType * 256; + const uint8 *block = _backdropBlocks + blockType * 256; for (size_t k = 0; k < 4; ++k) { memcpy(dst, block, 16); block += 16; @@ -49,7 +48,6 @@ void DreamGenContext::doBlocks() { dst += 320; } dst += 4; - ax = 0x0dfdf; memset(dst, 0xdf, 16); dst += 320; memset(dst, 0xdf, 16); @@ -59,271 +57,223 @@ void DreamGenContext::doBlocks() { memset(dst, 0xdf, 16); } } - mapData += kMapwidth; + mapData += kMapWidth; } } -uint8 DreamGenContext::getXAd(const uint8 *setData, uint8 *result) { +uint8 DreamWebEngine::getXAd(const uint8 *setData, uint8 *result) { uint8 v0 = setData[0]; uint8 v1 = setData[1]; uint8 v2 = setData[2]; if (v0 != 0) return 0; - if (v1 < data.byte(kMapx)) + if (v1 < _mapX) return 0; - v1 -= data.byte(kMapx); + v1 -= _mapX; if (v1 >= 11) return 0; *result = (v1 << 4) | v2; return 1; } -uint8 DreamGenContext::getYAd(const uint8 *setData, uint8 *result) { +uint8 DreamWebEngine::getYAd(const uint8 *setData, uint8 *result) { uint8 v0 = setData[3]; uint8 v1 = setData[4]; - if (v0 < data.byte(kMapy)) + if (v0 < _mapY) return 0; - v0 -= data.byte(kMapy); + v0 -= _mapY; if (v0 >= 10) return 0; *result = (v0 << 4) | v1; return 1; } -void DreamGenContext::getMapAd() { - ch = getMapAd((const uint8 *)es.ptr(si, 5)); -} - -uint8 DreamGenContext::getMapAd(const uint8 *setData) { +uint8 DreamWebEngine::getMapAd(const uint8 *setData, uint16 *x, uint16 *y) { uint8 xad, yad; if (getXAd(setData, &xad) == 0) return 0; - data.word(kObjectx) = xad; + *x = xad; if (getYAd(setData, &yad) == 0) return 0; - data.word(kObjecty) = yad; + *y = yad; return 1; } -void DreamGenContext::calcFrFrame(uint16 frame) { - uint8 width, height; - calcFrFrame(frame, &width, &height); - cl = width; - ch = height; -} - -void DreamGenContext::calcFrFrame(uint16 frameNum, uint8* width, uint8* height) { - const Frame *frame = (const Frame *)getSegment(data.word(kFrsegment)).ptr(frameNum * sizeof(Frame), sizeof(Frame)); - data.word(kSavesource) = data.word(kFramesad) + frame->ptr(); - data.byte(kSavesize+0) = frame->width; - data.byte(kSavesize+1) = frame->height; - data.word(kOffsetx) = frame->x; - data.word(kOffsety) = frame->y; - *width = frame->width; - *height = frame->height; -} +void DreamWebEngine::calcFrFrame(const Frame &frame, uint8 *width, uint8 *height, uint16 x, uint16 y, ObjPos *objPos) { + *width = frame.width; + *height = frame.height; -void DreamGenContext::finalFrame() { - uint16 x, y; - finalFrame(&x, &y); - di = x; - bx = y; + objPos->xMin = (x + frame.x) & 0xff; + objPos->yMin = (y + frame.y) & 0xff; + objPos->xMax = objPos->xMin + frame.width; + objPos->yMax = objPos->yMin + frame.height; } -void DreamGenContext::finalFrame(uint16 *x, uint16 *y) { - data.byte(kSavex) = (data.word(kObjectx) + data.word(kOffsetx)) & 0xff; - data.byte(kSavey) = (data.word(kObjecty) + data.word(kOffsety)) & 0xff; - *x = data.word(kObjectx); - *y = data.word(kObjecty); +void DreamWebEngine::makeBackOb(SetObject *objData, uint16 x, uint16 y) { + if (_vars._newObs == 0) + return; + uint8 priority = objData->priority; + uint8 type = objData->type; + Sprite *sprite = makeSprite(x, y, false, &_setFrames); + + sprite->_objData = objData; + if (priority == 255) + priority = 0; + sprite->priority = priority; + sprite->type = type; + sprite->delay = 0; + sprite->animFrame = 0; } -void DreamGenContext::showAllObs() { - data.word(kListpos) = kSetlist; - memset(getSegment(data.word(kBuffers)).ptr(kSetlist, 0), 0xff, 128 * 5); - data.word(kFrsegment) = data.word(kSetframes); - data.word(kDataad) = kFramedata; - data.word(kFramesad) = kFrames; +void DreamWebEngine::showAllObs() { + _setList.clear(); - const Frame *frames = (const Frame *)getSegment(data.word(kFrsegment)).ptr(0, 0); - SetObject *setEntries = (SetObject *)getSegment(data.word(kSetdat)).ptr(0, 128 * sizeof(SetObject)); + const GraphicsFile &frameBase = _setFrames; for (size_t i = 0; i < 128; ++i) { - SetObject *setEntry = setEntries + i; - if (getMapAd(setEntry->mapad) == 0) + SetObject *setEntry = &_setDat[i]; + uint16 x, y; + if (getMapAd(setEntry->mapad, &x, &y) == 0) continue; uint8 currentFrame = setEntry->frames[0]; if (currentFrame == 0xff) continue; - calcFrFrame(currentFrame); - uint16 x, y; - finalFrame(&x, &y); + uint8 width, height; + ObjPos objPos; + calcFrFrame(frameBase._frames[currentFrame], &width, &height, x, y, &objPos); setEntry->index = setEntry->frames[0]; if ((setEntry->type == 0) && (setEntry->priority != 5) && (setEntry->priority != 6)) { - x += data.word(kMapadx); - y += data.word(kMapady); - showFrame(frames, x, y, currentFrame, 0); + x += _mapAdX; + y += _mapAdY; + showFrame(frameBase, x, y, currentFrame, 0); } else - makeBackOb(setEntry); - - ObjPos *objPos = (ObjPos *)getSegment(data.word(kBuffers)).ptr(data.word(kListpos), sizeof(ObjPos)); - objPos->xMin = data.byte(kSavex); - objPos->yMin = data.byte(kSavey); - objPos->xMax = data.byte(kSavex) + data.byte(kSavesize+0); - objPos->yMax = data.byte(kSavey) + data.byte(kSavesize+1); - objPos->index = i; - data.word(kListpos) += sizeof(ObjPos); - } -} + makeBackOb(setEntry, x, y); -void DreamGenContext::getDimension() { - uint8 mapXstart, mapYstart; - uint8 mapXsize, mapYsize; - getDimension(&mapXstart, &mapYstart, &mapXsize, &mapYsize); - cl = mapXstart; - ch = mapYstart; - dl = mapXsize; - dh = mapYsize; + objPos.index = i; + _setList.push_back(objPos); + } } -bool DreamGenContext::addAlong(const uint8 *mapFlags) { +static bool addAlong(const MapFlag *mapFlags) { for (size_t i = 0; i < 11; ++i) { - if (mapFlags[3 * i] != 0) + if (mapFlags[i]._flag != 0) return true; } return false; } -bool DreamGenContext::addLength(const uint8 *mapFlags) { +static bool addLength(const MapFlag *mapFlags) { for (size_t i = 0; i < 10; ++i) { - if (mapFlags[3 * 11 * i] != 0) + if (mapFlags[11 * i]._flag != 0) return true; } return false; } -void DreamGenContext::getDimension(uint8 *mapXstart, uint8 *mapYstart, uint8 *mapXsize, uint8 *mapYsize) { - const uint8 *mapFlags = getSegment(data.word(kBuffers)).ptr(kMapflags, 0); - +void DreamWebEngine::getDimension(uint8 *mapXstart, uint8 *mapYstart, uint8 *mapXsize, uint8 *mapYsize) { uint8 yStart = 0; - while (! addAlong(mapFlags + 3 * 11 * yStart)) + while (! addAlong(_mapFlags + 11 * yStart)) ++yStart; uint8 xStart = 0; - while (! addLength(mapFlags + 3 * xStart)) + while (! addLength(_mapFlags + xStart)) ++xStart; uint8 yEnd = 10; - while (! addAlong(mapFlags + 3 * 11 * (yEnd - 1))) + while (! addAlong(_mapFlags + 11 * (yEnd - 1))) --yEnd; uint8 xEnd = 11; - while (! addLength(mapFlags + 3 * (xEnd - 1))) + while (! addLength(_mapFlags + (xEnd - 1))) --xEnd; *mapXstart = xStart; *mapYstart = yStart; *mapXsize = xEnd - xStart; *mapYsize = yEnd - yStart; - data.word(kMapxstart) = xStart << 4; - data.word(kMapystart) = yStart << 4; - data.byte(kMapxsize) = *mapXsize << 4; - data.byte(kMapysize) = *mapYsize << 4; + _mapXStart = xStart << 4; + _mapYStart = yStart << 4; + _mapXSize = *mapXsize << 4; + _mapYSize = *mapYsize << 4; } -void DreamGenContext::calcMapAd() { +void DreamWebEngine::calcMapAd() { uint8 mapXstart, mapYstart; uint8 mapXsize, mapYsize; getDimension(&mapXstart, &mapYstart, &mapXsize, &mapYsize); - data.word(kMapadx) = data.word(kMapoffsetx) - 8 * (mapXsize + 2 * mapXstart - 11); - data.word(kMapady) = data.word(kMapoffsety) - 8 * (mapYsize + 2 * mapYstart - 10); + _mapAdX = _mapOffsetX - 8 * (mapXsize + 2 * mapXstart - 11); + _mapAdY = _mapOffsetY - 8 * (mapYsize + 2 * mapYstart - 10); } -void DreamGenContext::showAllFree() { - data.word(kListpos) = kFreelist; - ObjPos *listPos = (ObjPos *)getSegment(data.word(kBuffers)).ptr(kFreelist, 80 * sizeof(ObjPos)); - memset(listPos, 0xff, 80 * sizeof(ObjPos)); - - data.word(kFrsegment) = data.word(kFreeframes); - data.word(kDataad) = kFrframedata; - data.word(kFramesad) = kFrframes; - data.byte(kCurrentfree) = 0; - const DynObject *freeObjects = (const DynObject *)getSegment(data.word(kFreedat)).ptr(0, 0); - for (size_t i = 0; i < 80; ++i) { - uint8 mapAd = getMapAd(freeObjects[i].mapad); +void DreamWebEngine::showAllFree() { + const unsigned int count = 80; + + _freeList.clear(); + + const DynObject *freeObjects = _freeDat; + const GraphicsFile &frameBase = _freeFrames; + for (size_t i = 0; i < count; ++i) { + uint16 x, y; + uint8 mapAd = getMapAd(freeObjects[i].mapad, &x, &y); if (mapAd != 0) { uint8 width, height; - uint16 currentFrame = 3 * data.byte(kCurrentfree); - calcFrFrame(currentFrame, &width, &height); - uint16 x, y; - finalFrame(&x, &y); + ObjPos objPos; + uint16 currentFrame = 3 * i; + calcFrFrame(frameBase._frames[currentFrame], &width, &height, x, y, &objPos); if ((width != 0) || (height != 0)) { - x += data.word(kMapadx); - y += data.word(kMapady); + x += _mapAdX; + y += _mapAdY; assert(currentFrame < 256); - showFrame((Frame *)getSegment(data.word(kFrsegment)).ptr(0, 0), x, y, currentFrame, 0); - ObjPos *objPos = (ObjPos *)getSegment(data.word(kBuffers)).ptr(data.word(kListpos), sizeof(ObjPos)); - objPos->xMin = data.byte(kSavex); - objPos->yMin = data.byte(kSavey); - objPos->xMax = data.byte(kSavex) + data.byte(kSavesize+0); - objPos->yMax = data.byte(kSavey) + data.byte(kSavesize+1); - objPos->index = i; - data.word(kListpos) += sizeof(ObjPos); + showFrame(frameBase, x, y, currentFrame, 0); + objPos.index = i; + _freeList.push_back(objPos); } } - - ++data.byte(kCurrentfree); } } -void DreamGenContext::drawFlags() { - uint8 *mapFlags = getSegment(data.word(kBuffers)).ptr(kMapflags, 0); - const uint8 *mapData = getSegment(data.word(kMapdata)).ptr(kMap + data.byte(kMapy) * kMapwidth + data.byte(kMapx), 0); - const uint8 *backdropFlags = getSegment(data.word(kBackdrop)).ptr(kFlags, 0); +void DreamWebEngine::drawFlags() { + MapFlag *mapFlag = _mapFlags; + uint16 mapOffset = _mapY * kMapWidth + _mapX; + const uint8 *mapData = _mapData + mapOffset; for (size_t i = 0; i < 10; ++i) { for (size_t j = 0; j < 11; ++j) { - uint8 tile = mapData[i * kMapwidth + j]; - mapFlags[0] = backdropFlags[2 * tile + 0]; - mapFlags[1] = backdropFlags[2 * tile + 1]; - mapFlags[2] = tile; - mapFlags += 3; + uint8 tile = mapData[i * kMapWidth + j]; + mapFlag->_flag = _backdropFlags[tile]._flag; + mapFlag->_flagEx = _backdropFlags[tile]._flagEx; + mapFlag->_type = tile; + mapFlag++; } } } -void DreamGenContext::showAllEx() { - data.word(kListpos) = kExlist; - memset(getSegment(data.word(kBuffers)).ptr(kExlist, 100 * 5), 0xff, 100 * 5); +void DreamWebEngine::showAllEx() { + const unsigned int count = 100; + + _exList.clear(); - data.word(kFrsegment) = data.word(kExtras); - data.word(kDataad) = kExframedata; - data.word(kFramesad) = kExframes; - data.byte(kCurrentex) = 0; - DynObject *objects = (DynObject *)getSegment(data.word(kExtras)).ptr(kExdata, sizeof(DynObject)); - for (size_t i = 0; i < 100; ++i, ++data.byte(kCurrentex)) { + DynObject *objects = _exData; + const GraphicsFile &frameBase = _exFrames; + for (size_t i = 0; i < count; ++i) { DynObject *object = objects + i; if (object->mapad[0] == 0xff) continue; - if (object->currentLocation != data.byte(kReallocation)) + if (object->currentLocation != _realLocation) continue; - if (getMapAd(object->mapad) == 0) + uint16 x, y; + if (getMapAd(object->mapad, &x, &y) == 0) continue; uint8 width, height; - uint16 currentFrame = 3 * data.byte(kCurrentex); - calcFrFrame(currentFrame, &width, &height); - uint16 x, y; - finalFrame(&x, &y); + ObjPos objPos; + uint16 currentFrame = 3 * i; + calcFrFrame(frameBase._frames[currentFrame], &width, &height, x, y, &objPos); if ((width != 0) || (height != 0)) { assert(currentFrame < 256); - showFrame((Frame *)getSegment(data.word(kFrsegment)).ptr(0, 0), x + data.word(kMapadx), y + data.word(kMapady), currentFrame, 0); - ObjPos *objPos = (ObjPos *)getSegment(data.word(kBuffers)).ptr(data.word(kListpos), sizeof(ObjPos)); - objPos->xMin = data.byte(kSavex); - objPos->yMin = data.byte(kSavey); - objPos->xMax = data.byte(kSavesize + 0) + data.byte(kSavex); - objPos->yMax = data.byte(kSavesize + 1) + data.byte(kSavey); - objPos->index = i; - data.word(kListpos) += sizeof(ObjPos); + showFrame(frameBase, x + _mapAdX, y + _mapAdY, currentFrame, 0); + objPos.index = i; + _exList.push_back(objPos); } } } -} // End of namespace DreamGen +} // End of namespace DreamWeb diff --git a/engines/dreamweb/detection.cpp b/engines/dreamweb/detection.cpp index ba7152beb5..9d3797db03 100644 --- a/engines/dreamweb/detection.cpp +++ b/engines/dreamweb/detection.cpp @@ -25,7 +25,12 @@ #include "common/algorithm.h" #include "common/system.h" +#include "engines/advancedDetector.h" + +#include "graphics/thumbnail.h" + #include "dreamweb/dreamweb.h" +#include "dreamweb/structs.h" static const PlainGameDescriptor dreamWebGames[] = { { "dreamweb", "DreamWeb" }, @@ -56,6 +61,7 @@ public: virtual SaveStateList listSaves(const char *target) const; virtual int getMaximumSaveSlot() const; virtual void removeSaveState(const char *target, int slot) const; + SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; }; bool DreamWebMetaEngine::hasFeature(MetaEngineFeature f) const { @@ -63,6 +69,10 @@ bool DreamWebMetaEngine::hasFeature(MetaEngineFeature f) const { case kSupportsListSaves: case kSupportsLoadingDuringStartup: case kSupportsDeleteSave: + case kSavesSupportMetaInfo: + case kSavesSupportThumbnail: + case kSavesSupportCreationDate: + case kSavesSupportPlayTime: return true; default: return false; @@ -116,6 +126,71 @@ SaveStateList DreamWebMetaEngine::listSaves(const char *target) const { int DreamWebMetaEngine::getMaximumSaveSlot() const { return 99; } void DreamWebMetaEngine::removeSaveState(const char *target, int slot) const { + Common::String fileName = Common::String::format("DREAMWEB.D%02d", slot); + g_system->getSavefileManager()->removeSavefile(fileName); +} + +SaveStateDescriptor DreamWebMetaEngine::querySaveMetaInfos(const char *target, int slot) const { + Common::String filename = Common::String::format("DREAMWEB.D%02d", slot); + Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename.c_str()); + + if (in) { + DreamWeb::FileHeader header; + in->read((uint8 *)&header, sizeof(DreamWeb::FileHeader)); + + Common::String saveName; + byte descSize = header.len(0); + byte i; + + for (i = 0; i < descSize; i++) + saveName += (char)in->readByte(); + + SaveStateDescriptor desc(slot, saveName); + desc.setDeletableFlag(true); + desc.setWriteProtectedFlag(false); + + // Check if there is a ScummVM data block + if (header.len(6) == SCUMMVM_BLOCK_MAGIC_SIZE) { + // Skip the game data + for (i = 1; i <= 5; i++) + in->skip(header.len(i)); + + uint32 tag = in->readUint32BE(); + if (tag != SCUMMVM_HEADER) { + warning("ScummVM data block found, but the block header is incorrect - skipping"); + delete in; + return desc; + } + + byte version = in->readByte(); + if (version > SAVEGAME_VERSION) { + warning("ScummVM data block found, but it has been saved with a newer version of ScummVM - skipping"); + delete in; + return desc; + } + + uint32 saveDate = in->readUint32LE(); + uint32 saveTime = in->readUint32LE(); + uint32 playTime = in->readUint32LE(); + Graphics::Surface *thumbnail = Graphics::loadThumbnail(*in); + + int day = (saveDate >> 24) & 0xFF; + int month = (saveDate >> 16) & 0xFF; + int year = saveDate & 0xFFFF; + int hour = (saveTime >> 16) & 0xFF; + int minutes = (saveTime >> 8) & 0xFF; + + desc.setSaveDate(year, month, day); + desc.setSaveTime(hour, minutes); + desc.setPlayTime(playTime * 1000); + desc.setThumbnail(thumbnail); + } + + delete in; + return desc; + } + + return SaveStateDescriptor(); } #if PLUGIN_ENABLED_DYNAMIC(DREAMWEB) @@ -142,4 +217,12 @@ bool DreamWebEngine::canSaveGameStateCurrently() { return false; } +Common::Language DreamWebEngine::getLanguage() const { + return _gameDescription->desc.language; +} + +bool DreamWebEngine::isCD() { + return _gameDescription->desc.flags & ADGF_CD; +} + } // End of namespace DreamWeb diff --git a/engines/dreamweb/detection_tables.h b/engines/dreamweb/detection_tables.h index 75f5786268..216e6715dc 100644 --- a/engines/dreamweb/detection_tables.h +++ b/engines/dreamweb/detection_tables.h @@ -25,6 +25,10 @@ namespace DreamWeb { +struct DreamWebGameDescription { + ADGameDescription desc; +}; + static const DreamWebGameDescription gameDescriptions[] = { // International floppy release { diff --git a/engines/dreamweb/dreambase.h b/engines/dreamweb/dreambase.h deleted file mode 100644 index 3d5c9ce88b..0000000000 --- a/engines/dreamweb/dreambase.h +++ /dev/null @@ -1,217 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef DREAMBASE_H -#define DREAMBASE_H - -#include "common/scummsys.h" - -#include "dreamweb/segment.h" - -namespace DreamWeb { - class DreamWebEngine; -} - - -namespace DreamGen { - -/** - * This class is one of the parent classes of DreamGenContext. Its sole purpose - * is to allow us to incrementally move things out of DreamGenContext into this - * base class, as soon as they don't modify any context registers (ax, bx, cx, ...) - * anymore. - * Ultimately, DreamGenContext should be empty, at which point it can be removed - * together with class Context. When that happens, we can probably merge - * DreamBase into DreamWebEngine. - */ -class DreamBase : public SegmentManager { -protected: - DreamWeb::DreamWebEngine *engine; - -public: - DreamBase(DreamWeb::DreamWebEngine *en) : engine(en) { } - -public: - // from monitor.cpp - void printOuterMon(); - void showCurrentFile(); - void accessLightOn(); - void accessLightOff(); - void turnOnPower(); - void powerLightOn(); - void powerLightOff(); - void printLogo(); - void scrollMonitor(); - const char *monPrint(const char *string); - void lockLightOn(); - void lockLightOff(); - - // from object.cpp - void obIcons(); - - // from pathfind.cpp - Common::Point _lineData[200]; // Output of Bresenham - void checkDest(const RoomPaths *roomsPaths); - RoomPaths *getRoomsPaths(); - void faceRightWay(); - void setWalk(); - void autoSetWalk(); - void findXYFromPath(); - void bresenhams(); - void workoutFrames(); - - // from print.cpp - uint8 getNextWord(const Frame *charSet, const uint8 *string, uint8 *totalWidth, uint8 *charCount); - void printChar(const Frame* charSet, uint16 *x, uint16 y, uint8 c, uint8 nextChar, uint8 *width, uint8 *height); - void printChar(const Frame* charSet, uint16 x, uint16 y, uint8 c, uint8 nextChar, uint8 *width, uint8 *height); - void printBoth(const Frame* charSet, uint16 *x, uint16 y, uint8 c, uint8 nextChar); - uint8 printDirect(const uint8** string, uint16 x, uint16 *y, uint8 maxWidth, bool centered); - uint8 printDirect(const uint8* string, uint16 x, uint16 y, uint8 maxWidth, bool centered); - uint8 getNumber(const Frame *charSet, const uint8 *string, uint16 maxWidth, bool centered, uint16 *offset); - uint8 kernChars(uint8 firstChar, uint8 secondChar, uint8 width); - uint8 printSlow(const uint8 *string, uint16 x, uint16 y, uint8 maxWidth, bool centered); - uint16 waitFrames(); - void printCurs(); - void delCurs(); - - // from saveload.cpp - char _saveNames[17*7]; - char _saveNamesOld[17*7]; - void showNames(); - - // from sound.cpp - bool loadSpeech(byte type1, int idx1, byte type2, int idx2); - void volumeAdjust(); - void cancelCh0(); - void cancelCh1(); - void loadRoomsSample(); - void playChannel0(uint8 index, uint8 repeat); - void playChannel1(uint8 index); - - // from sprite.cpp - Sprite *spriteTable(); - Reel *getReelStart(uint16 reelPointer); - const Frame *findSource(uint16 &frame); - void showReelFrame(Reel *reel); - const Frame *getReelFrameAX(uint16 frame); - void soundOnReels(uint16 reelPointer); - void rollEndCredits(); - - // from stubs.cpp - void crosshair(); - void showBlink(); - void dumpBlink(); - void dumpPointer(); - void showPointer(); - void delPointer(); - void showRyanPage(); - Frame *tempGraphics(); - Frame *tempGraphics2(); - Frame *tempGraphics3(); - void showArrows(); - void showOpBox(); - void middlePanel(); - void showDiary(); - void readMouse(); - uint16 readMouseState(); - void hangOn(uint16 frameCount); - bool quitRequested(); - void lockMon(); - uint8 *textUnder(); - void readKey(); - void findOrMake(uint8 index, uint8 value, uint8 type); - DynObject *getFreeAd(uint8 index); - DynObject *getExAd(uint8 index); - DynObject *getEitherAdCPP(); - void showWatch(); - void showTime(); - void showExit(); - void showMan(); - void panelIcons1(); - SetObject *getSetAd(uint8 index); - void *getAnyAd(uint8 *value1, uint8 *value2); - const uint8 *getTextInFile1(uint16 index); - - // from use.cpp - void placeFreeObject(uint8 index); - void removeFreeObject(uint8 index); - - // from vgafades.cpp - uint8 *mainPalette(); - uint8 *startPalette(); - uint8 *endPalette(); - void clearStartPal(); - void clearEndPal(); - void palToStartPal(); - void endPalToStart(); - void startPalToEnd(); - void palToEndPal(); - void fadeDOS(); - void doFade(); - void fadeCalculation(); - void fadeScreenUp(); - void fadeScreenUps(); - void fadeScreenUpHalf(); - void fadeScreenDown(); - void fadeScreenDowns(); - void greyscaleSum(); - void allPalette(); - void dumpCurrent(); - - // from vgagrafx.cpp - uint8 _workspace[(0x1000 + 2) * 16]; - inline uint8 *workspace() { return _workspace; } - void clearWork(); - - uint8 *mapStore(); - void panelToMap(); - void mapToPanel(); - void dumpMap(); - - void transferInv(); - - void multiGet(uint8 *dst, uint16 x, uint16 y, uint8 width, uint8 height); - void multiPut(const uint8 *src, uint16 x, uint16 y, uint8 width, uint8 height); - void multiDump(uint16 x, uint16 y, uint8 width, uint8 height); - void workToScreenCPP(); - void printUnderMon(); - void cls(); - void frameOutV(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, int16 x, int16 y); - void frameOutNm(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y); - void frameOutBh(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y); - void frameOutFx(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y); - void doShake(); - void vSync(); - void setMode(); - void showPCX(const Common::String &name); - void showFrame(const Frame *frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag, uint8 *width, uint8 *height); - void showFrame(const Frame *frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag); - void loadPalFromIFF(); - void createPanel(); - void createPanel2(); - void showPanel(); -}; - - -} // End of namespace DreamGen - -#endif diff --git a/engines/dreamweb/dreamgen.cpp b/engines/dreamweb/dreamgen.cpp deleted file mode 100644 index 6d3da6d0f2..0000000000 --- a/engines/dreamweb/dreamgen.cpp +++ /dev/null @@ -1,5693 +0,0 @@ -/* PLEASE DO NOT MODIFY THIS FILE. ALL CHANGES WILL BE LOST! LOOK FOR README FOR DETAILS */ - -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "dreamgen.h" - -namespace DreamGen { - -void DreamGenContext::receptionist() { - STACK_CHECK; - checkSpeed(); - if (!flags.z()) - goto gotrecep; - _cmp(data.byte(kCardpassflag), 1); - if (!flags.z()) - goto notsetcard; - _inc(data.byte(kCardpassflag)); - es.byte(bx+7) = 1; - es.word(bx+3) = 64; -notsetcard: - _cmp(es.word(bx+3), 58); - if (!flags.z()) - goto notdes1; - randomNumber(); - _cmp(al, 30); - if (flags.c()) - goto notdes2; - es.word(bx+3) = 55; - goto gotrecep; -notdes1: - _cmp(es.word(bx+3), 60); - if (!flags.z()) - goto notdes2; - randomNumber(); - _cmp(al, 240); - if (flags.c()) - goto gotrecep; - es.word(bx+3) = 53; - goto gotrecep; -notdes2: - _cmp(es.word(bx+3), 88); - if (!flags.z()) - goto notendcard; - es.word(bx+3) = 53; - goto gotrecep; -notendcard: - _inc(es.word(bx+3)); -gotrecep: - showGameReel(); - addToPeopleList(); - al = es.byte(bx+7); - _and(al, 128); - if (flags.z()) - return /* (nottalkedrecep) */; - data.byte(kTalkedtorecep) = 1; -} - -void DreamGenContext::bartender() { - STACK_CHECK; - checkSpeed(); - if (!flags.z()) - goto gotsmoket; - _cmp(es.word(bx+3), 86); - if (!flags.z()) - goto notsmoket1; - randomNumber(); - _cmp(al, 18); - if (flags.c()) - goto notsmoket2; - es.word(bx+3) = 81; - goto gotsmoket; -notsmoket1: - _cmp(es.word(bx+3), 103); - if (!flags.z()) - goto notsmoket2; - es.word(bx+3) = 81; - goto gotsmoket; -notsmoket2: - _inc(es.word(bx+3)); -gotsmoket: - showGameReel(); - _cmp(data.byte(kGunpassflag), 1); - if (!flags.z()) - goto notgotgun; - es.byte(bx+7) = 9; -notgotgun: - addToPeopleList(); -} - -void DreamGenContext::helicopter() { - STACK_CHECK; - ax = es.word(bx+3); - _cmp(ax, 203); - if (flags.z()) - goto heliwon; - checkSpeed(); - if (!flags.z()) - goto helispeed; - ax = es.word(bx+3); - _inc(ax); - _cmp(ax, 53); - if (!flags.z()) - goto notbeforehdead; - _inc(data.byte(kCombatcount)); - _cmp(data.byte(kCombatcount), 8); - if (flags.c()) - goto waitabit; - data.byte(kMandead) = 2; -waitabit: - ax = 49; - goto gotheliframe; -notbeforehdead: - _cmp(ax, 9); - if (!flags.z()) - goto gotheliframe; - _dec(ax); - _cmp(data.byte(kLastweapon), 1); - if (!flags.z()) - goto notgunonheli; - data.byte(kLastweapon) = -1; - ax = 55; - goto gotheliframe; -notgunonheli: - ax = 5; - _inc(data.byte(kCombatcount)); - _cmp(data.byte(kCombatcount), 20); - if (!flags.z()) - goto gotheliframe; - data.byte(kCombatcount) = 0; - ax = 9; -gotheliframe: - es.word(bx+3) = ax; -helispeed: - showGameReel(); - al = data.byte(kMapx); - es.byte(bx+1) = al; - ax = es.word(bx+3); - _cmp(ax, 9); - if (!flags.c()) - goto notwaitingheli; - _cmp(data.byte(kCombatcount), 7); - if (flags.c()) - goto notwaitingheli; - data.byte(kPointermode) = 2; - data.word(kWatchingtime) = 0; - return; -notwaitingheli: - data.byte(kPointermode) = 0; - data.word(kWatchingtime) = 2; - return; -heliwon: - data.byte(kPointermode) = 0; -} - -void DreamGenContext::mugger() { - STACK_CHECK; - ax = es.word(bx+3); - _cmp(ax, 138); - if (flags.z()) - goto endmugger1; - _cmp(ax, 176); - if (flags.z()) - return /* (endmugger2) */; - _cmp(ax, 2); - if (!flags.z()) - goto havesetwatch; - data.word(kWatchingtime) = 175*2; -havesetwatch: - checkSpeed(); - if (!flags.z()) - goto notmugger; - _inc(es.word(bx+3)); -notmugger: - showGameReel(); - al = data.byte(kMapx); - es.byte(bx+1) = al; - return; -endmugger1: - push(es); - push(bx); - createPanel2(); - showIcon(); - al = 41; - findPuzText(); - di = 33+20; - bx = 104; - dl = 241; - ah = 0; - printDirect(); - workToScreen(); - cx = 300; - hangOn(); - bx = pop(); - es = pop(); - push(es); - push(bx); - es.word(bx+3) = 140; - data.byte(kManspath) = 2; - data.byte(kFinaldest) = 2; - findXYFromPath(); - data.byte(kResetmanxy) = 1; - al = 'W'; - ah = 'E'; - cl = 'T'; - ch = 'A'; - findExObject(); - data.byte(kCommand) = al; - data.byte(kObjecttype) = 4; - removeObFromInv(); - al = 'W'; - ah = 'E'; - cl = 'T'; - ch = 'B'; - findExObject(); - data.byte(kCommand) = al; - data.byte(kObjecttype) = 4; - removeObFromInv(); - makeMainScreen(); - al = 48; - bl = 68-32; - bh = 54+64; - cx = 70; - dx = 10; - setupTimedUse(); - data.byte(kBeenmugged) = 1; - bx = pop(); - es = pop(); -} - -void DreamGenContext::businessMan() { - STACK_CHECK; - data.byte(kPointermode) = 0; - data.word(kWatchingtime) = 2; - ax = es.word(bx+3); - _cmp(ax, 2); - if (!flags.z()) - goto notfirstbiz; - push(ax); - push(bx); - push(es); - al = 49; - cx = 30; - dx = 1; - bl = 68; - bh = 174; - setupTimedUse(); - es = pop(); - bx = pop(); - ax = pop(); -notfirstbiz: - _cmp(ax, 95); - if (flags.z()) - goto buscombatwonend; - _cmp(ax, 49); - if (flags.z()) - return /* (buscombatend) */; - checkSpeed(); - if (!flags.z()) - goto busspeed; - ax = es.word(bx+3); - _inc(ax); - _cmp(ax, 48); - if (!flags.z()) - goto notbeforedeadb; - data.byte(kMandead) = 2; - goto gotbusframe; -notbeforedeadb: - _cmp(ax, 15); - if (!flags.z()) - goto buscombatwon; - _dec(ax); - _cmp(data.byte(kLastweapon), 3); - if (!flags.z()) - goto notshieldonbus; - data.byte(kLastweapon) = -1; - data.byte(kCombatcount) = 0; - ax = 51; - goto gotbusframe; -notshieldonbus: - _inc(data.byte(kCombatcount)); - _cmp(data.byte(kCombatcount), 20); - if (!flags.z()) - goto gotbusframe; - data.byte(kCombatcount) = 0; - ax = 15; - goto gotbusframe; -buscombatwon: - _cmp(ax, 91); - if (!flags.z()) - goto gotbusframe; - push(bx); - push(es); - al = 0; - turnPathOn(); - al = 1; - turnPathOn(); - al = 2; - turnPathOn(); - al = 3; - turnPathOff(); - data.byte(kManspath) = 5; - data.byte(kFinaldest) = 5; - findXYFromPath(); - data.byte(kResetmanxy) = 1; - es = pop(); - bx = pop(); - ax = 92; - goto gotbusframe; -gotbusframe: - es.word(bx+3) = ax; -busspeed: - showGameReel(); - al = data.byte(kMapy); - es.byte(bx+2) = al; - ax = es.word(bx+3); - _cmp(ax, 14); - if (!flags.z()) - return /* (buscombatend) */; - data.word(kWatchingtime) = 0; - data.byte(kPointermode) = 2; - return; -buscombatwonend: - data.byte(kPointermode) = 0; - data.word(kWatchingtime) = 0; -} - -void DreamGenContext::poolGuard() { - STACK_CHECK; - ax = es.word(bx+3); - _cmp(ax, 214); - if (flags.z()) - goto combatover2; - _cmp(ax, 258); - if (flags.z()) - goto combatover2; - _cmp(ax, 185); - if (flags.z()) - goto combatover1; - _cmp(ax, 0); - if (!flags.z()) - goto notfirstpool; - al = 0; - turnPathOn(); -notfirstpool: - checkSpeed(); - if (!flags.z()) - goto guardspeed; - ax = es.word(bx+3); - _inc(ax); - _cmp(ax, 122); - if (!flags.z()) - goto notendguard1; - _dec(ax); - _cmp(data.byte(kLastweapon), 2); - if (!flags.z()) - goto notaxeonpool; - data.byte(kLastweapon) = -1; - ax = 122; - goto gotguardframe; -notaxeonpool: - _inc(data.byte(kCombatcount)); - _cmp(data.byte(kCombatcount), 40); - if (!flags.z()) - goto gotguardframe; - data.byte(kCombatcount) = 0; - ax = 195; - goto gotguardframe; -notendguard1: - _cmp(ax, 147); - if (!flags.z()) - goto gotguardframe; - _dec(ax); - _cmp(data.byte(kLastweapon), 1); - if (!flags.z()) - goto notgunonpool; - data.byte(kLastweapon) = -1; - ax = 147; - goto gotguardframe; -notgunonpool: - _inc(data.byte(kCombatcount)); - _cmp(data.byte(kCombatcount), 40); - if (!flags.z()) - goto gotguardframe; - data.byte(kCombatcount) = 0; - ax = 220; -gotguardframe: - es.word(bx+3) = ax; -guardspeed: - showGameReel(); - ax = es.word(bx+3); - _cmp(ax, 121); - if (flags.z()) - goto iswaitingpool; - _cmp(ax, 146); - if (flags.z()) - goto iswaitingpool; - data.byte(kPointermode) = 0; - data.word(kWatchingtime) = 2; - return; -iswaitingpool: - data.byte(kPointermode) = 2; - data.word(kWatchingtime) = 0; - return; -combatover1: - data.word(kWatchingtime) = 0; - data.byte(kPointermode) = 0; - al = 0; - turnPathOn(); - al = 1; - turnPathOff(); - return; -combatover2: - showGameReel(); - data.word(kWatchingtime) = 2; - data.byte(kPointermode) = 0; - _inc(data.byte(kCombatcount)); - _cmp(data.byte(kCombatcount), 100); - if (flags.c()) - return /* (doneover2) */; - data.word(kWatchingtime) = 0; - data.byte(kMandead) = 2; -} - -void DreamGenContext::heavy() { - STACK_CHECK; - al = es.byte(bx+7); - _and(al, 127); - es.byte(bx+7) = al; - _cmp(es.word(bx+3), 43); - if (flags.z()) - goto heavywait; - data.word(kWatchingtime) = 10; - _cmp(es.word(bx+3), 70); - if (!flags.z()) - goto notafterhshot; - _inc(data.byte(kCombatcount)); - _cmp(data.byte(kCombatcount), 80); - if (!flags.z()) - goto gotheavyframe; - data.byte(kMandead) = 2; - goto gotheavyframe; -notafterhshot: - checkSpeed(); - if (!flags.z()) - goto gotheavyframe; - _inc(es.word(bx+3)); - goto gotheavyframe; -heavywait: - _cmp(data.byte(kLastweapon), 1); - if (!flags.z()) - goto gotheavyframe; - _cmp(data.byte(kManspath), 5); - if (!flags.z()) - goto gotheavyframe; - _cmp(data.byte(kFacing), 4); - if (!flags.z()) - goto gotheavyframe; - data.byte(kLastweapon) = -1; - _inc(es.word(bx+3)); - data.byte(kCombatcount) = 0; -gotheavyframe: - showGameReel(); - addToPeopleList(); -} - -void DreamGenContext::endGameSeq() { - STACK_CHECK; - checkSpeed(); - if (!flags.z()) - goto notendseq; - ax = es.word(bx+3); - _inc(ax); - _cmp(ax, 51); - if (!flags.z()) - goto gotendseq; - _cmp(data.byte(kIntrocount), 140); - if (flags.z()) - goto gotendseq; - _inc(data.byte(kIntrocount)); - push(es); - push(bx); - textForEnd(); - bx = pop(); - es = pop(); - ax = 50; -gotendseq: - es.word(bx+3) = ax; - _cmp(ax, 134); - if (!flags.z()) - goto notfadedown; - push(es); - push(bx); - push(ax); - fadeScreenDownHalf(); - ax = pop(); - bx = pop(); - es = pop(); - goto notendseq; -notfadedown: - _cmp(ax, 324); - if (!flags.z()) - goto notfadeend; - push(es); - push(bx); - push(ax); - fadeScreenDowns(); - data.byte(kVolumeto) = 7; - data.byte(kVolumedirection) = 1; - ax = pop(); - bx = pop(); - es = pop(); -notfadeend: - _cmp(ax, 340); - if (!flags.z()) - goto notendseq; - data.byte(kGetback) = 1; -notendseq: - showGameReel(); - al = data.byte(kMapy); - es.byte(bx+2) = al; - ax = es.word(bx+3); - _cmp(ax, 145); - if (!flags.z()) - return /* (notendcreds) */; - es.word(bx+3) = 146; - rollEndCredits(); -} - -void DreamGenContext::checkForExit() { - STACK_CHECK; - cl = data.byte(kRyanx); - _add(cl, 12); - ch = data.byte(kRyany); - _add(ch, 12); - checkOne(); - data.byte(kLastflag) = cl; - data.byte(kLastflagex) = ch; - data.byte(kFlagx) = dl; - data.byte(kFlagy) = dh; - al = data.byte(kLastflag); - _test(al, 64); - if (flags.z()) - goto notnewdirect; - al = data.byte(kLastflagex); - data.byte(kAutolocation) = al; - return; -notnewdirect: - _test(al, 32); - if (flags.z()) - goto notleave; - push(es); - push(bx); - _cmp(data.byte(kReallocation), 2); - if (!flags.z()) - goto notlouis; - bl = 0; - push(bx); - al = 'W'; - ah = 'E'; - cl = 'T'; - ch = 'A'; - isRyanHolding(); - bx = pop(); - if (flags.z()) - goto noshoe1; - _inc(bl); -noshoe1: - push(bx); - al = 'W'; - ah = 'E'; - cl = 'T'; - ch = 'B'; - isRyanHolding(); - bx = pop(); - if (flags.z()) - goto noshoe2; - _inc(bl); -noshoe2: - _cmp(bl, 2); - if (flags.z()) - goto notlouis; - al = 42; - _cmp(bl, 0); - if (flags.z()) - goto notravmessage; - _inc(al); -notravmessage: - cx = 80; - dx = 10; - bl = 68; - bh = 64; - setupTimedUse(); - al = data.byte(kFacing); - _add(al, 4); - _and(al, 7); - data.byte(kTurntoface) = al; - bx = pop(); - es = pop(); - return; -notlouis: - bx = pop(); - es = pop(); - data.byte(kNeedtotravel) = 1; - return; -notleave: - _test(al, 4); - if (flags.z()) - goto notaleft; - adjustLeft(); - return; -notaleft: - _test(al, 2); - if (flags.z()) - goto notaright; - adjustRight(); - return; -notaright: - _test(al, 8); - if (flags.z()) - goto notadown; - adjustDown(); - return; -notadown: - _test(al, 16); - if (flags.z()) - return /* (notanup) */; - adjustUp(); -} - -void DreamGenContext::adjustDown() { - STACK_CHECK; - push(es); - push(bx); - _add(data.byte(kMapy), 10); - al = data.byte(kLastflagex); - cl = 16; - _mul(cl); - es.byte(bx+11) = al; - data.byte(kNowinnewroom) = 1; - bx = pop(); - es = pop(); -} - -void DreamGenContext::adjustUp() { - STACK_CHECK; - push(es); - push(bx); - _sub(data.byte(kMapy), 10); - al = data.byte(kLastflagex); - cl = 16; - _mul(cl); - es.byte(bx+11) = al; - data.byte(kNowinnewroom) = 1; - bx = pop(); - es = pop(); -} - -void DreamGenContext::adjustLeft() { - STACK_CHECK; - push(es); - push(bx); - data.byte(kLastflag) = 0; - _sub(data.byte(kMapx), 11); - al = data.byte(kLastflagex); - cl = 16; - _mul(cl); - es.byte(bx+10) = al; - data.byte(kNowinnewroom) = 1; - bx = pop(); - es = pop(); -} - -void DreamGenContext::adjustRight() { - STACK_CHECK; - push(es); - push(bx); - _add(data.byte(kMapx), 11); - al = data.byte(kLastflagex); - cl = 16; - _mul(cl); - _sub(al, 2); - es.byte(bx+10) = al; - data.byte(kNowinnewroom) = 1; - bx = pop(); - es = pop(); -} - -void DreamGenContext::reminders() { - STACK_CHECK; - _cmp(data.byte(kReallocation), 24); - if (!flags.z()) - return /* (notinedenslift) */; - _cmp(data.byte(kMapx), 44); - if (!flags.z()) - return /* (notinedenslift) */; - _cmp(data.byte(kProgresspoints), 0); - if (!flags.z()) - return /* (notfirst) */; - al = 'D'; - ah = 'K'; - cl = 'E'; - ch = 'Y'; - isRyanHolding(); - if (flags.z()) - goto forgotone; - al = 'C'; - ah = 'S'; - cl = 'H'; - ch = 'R'; - findExObject(); - _cmp(al, (114)); - if (flags.z()) - goto forgotone; - ax = es.word(bx+2); - _cmp(al, 4); - if (!flags.z()) - goto forgotone; - _cmp(ah, 255); - if (flags.z()) - goto havegotcard; - cl = 'P'; - ch = 'U'; - dl = 'R'; - dh = 'S'; - _xchg(al, ah); - compare(); - if (!flags.z()) - goto forgotone; -havegotcard: - _inc(data.byte(kProgresspoints)); - return; -forgotone: - al = 50; - bl = 54; - bh = 70; - cx = 48; - dx = 8; - setupTimedUse(); -} - -void DreamGenContext::transferMap() { - STACK_CHECK; - di = data.word(kExframepos); - push(di); - al = data.byte(kExpos); - ah = 0; - bx = ax; - _add(ax, ax); - _add(ax, bx); - cx = 6; - _mul(cx); - es = data.word(kExtras); - bx = (0); - _add(bx, ax); - _add(di, (0+2080)); - push(bx); - al = data.byte(kItemtotran); - ah = 0; - bx = ax; - _add(ax, ax); - _add(ax, bx); - cx = 6; - _mul(cx); - ds = data.word(kFreeframes); - bx = (0); - _add(bx, ax); - si = (0+2080); - al = ds.byte(bx); - ah = 0; - cl = ds.byte(bx+1); - ch = 0; - _add(si, ds.word(bx+2)); - dx = ds.word(bx+4); - bx = pop(); - es.byte(bx+0) = al; - es.byte(bx+1) = cl; - es.word(bx+4) = dx; - _mul(cx); - cx = ax; - push(cx); - _movsb(cx, true); - cx = pop(); - ax = pop(); - es.word(bx+2) = ax; - _add(data.word(kExframepos), cx); -} - -void DreamGenContext::fadeScreenDownHalf() { - STACK_CHECK; - palToStartPal(); - palToEndPal(); - cx = 768; - es = data.word(kBuffers); - bx = (0+(228*13)+32+60+(32*32)+(11*10*3)+768); -halfend: - al = es.byte(bx); - _shr(al, 1); - es.byte(bx) = al; - _inc(bx); - if (--cx) - goto halfend; - ds = data.word(kBuffers); - es = data.word(kBuffers); - si = (0+(228*13)+32+60+(32*32)+(11*10*3))+(56*3); - di = (0+(228*13)+32+60+(32*32)+(11*10*3)+768)+(56*3); - cx = 3*5; - _movsb(cx, true); - si = (0+(228*13)+32+60+(32*32)+(11*10*3))+(77*3); - di = (0+(228*13)+32+60+(32*32)+(11*10*3)+768)+(77*3); - cx = 3*2; - _movsb(cx, true); - data.byte(kFadedirection) = 1; - data.byte(kFadecount) = 31; - data.byte(kColourpos) = 0; - data.byte(kNumtofade) = 32; -} - -void DreamGenContext::rollEm() { - STACK_CHECK; - cl = 160; - ch = 160; - di = 25; - bx = 20; - ds = data.word(kMapstore); - si = 0; - multiGet(); - es = data.word(kTextfile1); - si = 49*2; - ax = es.word(si); - si = ax; - _add(si, (66*2)); - cx = 80; -endcredits21: - push(cx); - bx = 10; - cx = data.word(kLinespacing); -endcredits22: - push(cx); - push(si); - push(di); - push(es); - push(bx); - vSync(); - cl = 160; - ch = 160; - di = 25; - bx = 20; - ds = data.word(kMapstore); - si = 0; - multiPut(); - vSync(); - bx = pop(); - es = pop(); - di = pop(); - si = pop(); - push(si); - push(di); - push(es); - push(bx); - cx = 18; -onelot2: - push(cx); - di = 25; - dx = 161; - ax = 0; - printDirect(); - _add(bx, data.word(kLinespacing)); - cx = pop(); - if (--cx) - goto onelot2; - vSync(); - cl = 160; - ch = 160; - di = 25; - bx = 20; - multiDump(); - bx = pop(); - es = pop(); - di = pop(); - si = pop(); - cx = pop(); - _cmp(data.byte(kLasthardkey), 1); - if (flags.z()) - goto endearly2; - _dec(bx); - if (--cx) - goto endcredits22; - cx = pop(); -looknext2: - al = es.byte(si); - _inc(si); - _cmp(al, ':'); - if (flags.z()) - goto gotnext2; - _cmp(al, 0); - if (flags.z()) - goto gotnext2; - goto looknext2; -gotnext2: - _cmp(data.byte(kLasthardkey), 1); - if (flags.z()) - return /* (endearly) */; - if (--cx) - goto endcredits21; - cx = 120; - hangOne(); - return; -endearly2: - cx = pop(); -} - -void DreamGenContext::fadeDownMon() { - STACK_CHECK; - palToStartPal(); - palToEndPal(); - es = data.word(kBuffers); - di = (0+(228*13)+32+60+(32*32)+(11*10*3)+768)+(231*3); - cx = 3*8; - ax = 0; - _stosb(cx, true); - di = (0+(228*13)+32+60+(32*32)+(11*10*3)+768)+(246*3); - _stosb(); - _stosw(); - data.byte(kFadedirection) = 1; - data.byte(kFadecount) = 63; - data.byte(kColourpos) = 0; - data.byte(kNumtofade) = 128; - cx = 64; - hangOn(); -} - -void DreamGenContext::fadeUpMon() { - STACK_CHECK; - palToStartPal(); - palToEndPal(); - es = data.word(kBuffers); - di = (0+(228*13)+32+60+(32*32)+(11*10*3))+(231*3); - cx = 3*8; - ax = 0; - _stosb(cx, true); - di = (0+(228*13)+32+60+(32*32)+(11*10*3))+(246*3); - _stosb(); - _stosw(); - data.byte(kFadedirection) = 1; - data.byte(kFadecount) = 63; - data.byte(kColourpos) = 0; - data.byte(kNumtofade) = 128; - cx = 128; - hangOn(); -} - -void DreamGenContext::initialMonCols() { - STACK_CHECK; - palToStartPal(); - es = data.word(kBuffers); - di = (0+(228*13)+32+60+(32*32)+(11*10*3))+(230*3); - cx = 3*9; - ax = 0; - _stosb(cx, true); - di = (0+(228*13)+32+60+(32*32)+(11*10*3))+(246*3); - _stosb(); - _stosw(); - ds = data.word(kBuffers); - si = (0+(228*13)+32+60+(32*32)+(11*10*3))+(230*3); - al = 230; - cx = 18; - showGroup(); -} - -void DreamGenContext::runEndSeq() { - STACK_CHECK; - atmospheres(); - data.byte(kGetback) = 0; -moreendseq: - vSync(); - spriteUpdate(); - vSync(); - delEverything(); - printSprites(); - reelsOnScreen(); - afterIntroRoom(); - useTimedText(); - vSync(); - dumpMap(); - dumpTimedText(); - vSync(); - _cmp(data.byte(kGetback), 1); - if (!flags.z()) - goto moreendseq; -} - -void DreamGenContext::fillOpen() { - STACK_CHECK; - delTextLine(); - getOpenedSize(); - _cmp(ah, 4); - if (flags.c()) - goto lessthanapage; - ah = 4; -lessthanapage: - al = 1; - push(ax); - es = data.word(kBuffers); - di = (0+(228*13)); - findAllOpen(); - si = (0+(228*13)); - di = (80); - bx = (58)+96; - cx = pop(); -openloop1: - push(cx); - push(di); - push(bx); - ax = es.word(si); - _add(si, 2); - push(si); - push(es); - _cmp(ch, cl); - if (flags.c()) - goto nextopenslot; - obToInv(); -nextopenslot: - es = pop(); - si = pop(); - bx = pop(); - di = pop(); - cx = pop(); - _add(di, (44)); - _inc(cl); - _cmp(cl, 5); - if (!flags.z()) - goto openloop1; - underTextLine(); -} - -void DreamGenContext::findAllOpen() { - STACK_CHECK; - push(di); - cx = 16; - ax = 0x0ffff; - _stosw(cx, true); - di = pop(); - cl = data.byte(kOpenedob); - dl = data.byte(kOpenedtype); - ds = data.word(kExtras); - bx = (0+2080+30000); - ch = 0; -findopen1: - _cmp(ds.byte(bx+3), cl); - if (!flags.z()) - goto findopen2; - _cmp(ds.byte(bx+2), dl); - if (!flags.z()) - goto findopen2; - _cmp(data.byte(kOpenedtype), 4); - if (flags.z()) - goto noloccheck; - al = ds.byte(bx+5); - _cmp(al, data.byte(kReallocation)); - if (!flags.z()) - goto findopen2; -noloccheck: - al = ds.byte(bx+4); - ah = 0; - push(di); - _add(di, ax); - _add(di, ax); - al = ch; - ah = 4; - _stosw(); - di = pop(); -findopen2: - _add(bx, 16); - _inc(ch); - _cmp(ch, (114)); - if (!flags.z()) - goto findopen1; - cl = data.byte(kOpenedob); - dl = data.byte(kOpenedtype); - push(dx); - ds = data.word(kFreedat); - dx = pop(); - bx = 0; - ch = 0; -findopen1a: - _cmp(ds.byte(bx+3), cl); - if (!flags.z()) - goto findopen2a; - _cmp(ds.byte(bx+2), dl); - if (!flags.z()) - goto findopen2a; - al = ds.byte(bx+4); - ah = 0; - push(di); - _add(di, ax); - _add(di, ax); - al = ch; - ah = 2; - _stosw(); - di = pop(); -findopen2a: - _add(bx, 16); - _inc(ch); - _cmp(ch, 80); - if (!flags.z()) - goto findopen1a; -} - -void DreamGenContext::incRyanPage() { - STACK_CHECK; - _cmp(data.byte(kCommandtype), 222); - if (flags.z()) - goto alreadyincryan; - data.byte(kCommandtype) = 222; - al = 31; - commandOnly(); -alreadyincryan: - ax = data.word(kMousebutton); - _cmp(ax, data.word(kOldbutton)); - if (flags.z()) - return /* (noincryan) */; - _and(ax, 1); - if (!flags.z()) - goto doincryan; - return; -doincryan: - ax = data.word(kMousex); - _sub(ax, (80)+167); - data.byte(kRyanpage) = -1; -findnewpage: - _inc(data.byte(kRyanpage)); - _sub(ax, 18); - if (!flags.c()) - goto findnewpage; - delPointer(); - fillRyan(); - readMouse(); - showPointer(); - workToScreen(); - delPointer(); -} - -void DreamGenContext::openOb() { - STACK_CHECK; - al = data.byte(kOpenedob); - ah = data.byte(kOpenedtype); - di = offset_commandline; - copyName(); - di = (80); - bx = (58)+86; - al = 62; - dl = 240; - printMessage(); - di = data.word(kLastxpos); - _add(di, 5); - bx = (58)+86; - es = cs; - si = offset_commandline; - dl = 220; - al = 0; - ah = 0; - printDirect(); - fillOpen(); - getOpenedSize(); - al = ah; - ah = 0; - cx = (44); - _mul(cx); - _add(ax, (80)); - bx = offset_openchangesize; - cs.word(bx) = ax; -} - -void DreamGenContext::describeOb() { - STACK_CHECK; - getObTextStart(); - di = 33; - bx = 92; - _cmp(data.byte(kForeignrelease), 0); - if (flags.z()) - goto notsetd; - _cmp(data.byte(kObjecttype), 1); - if (!flags.z()) - goto notsetd; - bx = 82; -notsetd: - dl = 241; - ah = 16; - data.word(kCharshift) = 91+91; - printDirect(); - data.word(kCharshift) = 0; - di = 36; - bx = 104; - _cmp(data.byte(kForeignrelease), 0); - if (flags.z()) - goto notsetd2; - _cmp(data.byte(kObjecttype), 1); - if (!flags.z()) - goto notsetd2; - bx = 94; -notsetd2: - dl = 241; - ah = 0; - printDirect(); - push(bx); - obsThatDoThings(); - bx = pop(); - additionalText(); -} - -void DreamGenContext::additionalText() { - STACK_CHECK; - _add(bx, 10); - push(bx); - al = data.byte(kCommand); - ah = data.byte(kObjecttype); - cl = 'C'; - ch = 'U'; - dl = 'P'; - dh = 'E'; - compare(); - if (flags.z()) - goto emptycup; - al = data.byte(kCommand); - ah = data.byte(kObjecttype); - cl = 'C'; - ch = 'U'; - dl = 'P'; - dh = 'F'; - compare(); - if (flags.z()) - goto fullcup; - bx = pop(); - return; -emptycup: - al = 40; - findPuzText(); - bx = pop(); - di = 36; - dl = 241; - ah = 0; - printDirect(); - return; -fullcup: - al = 39; - findPuzText(); - bx = pop(); - di = 36; - dl = 241; - ah = 0; - printDirect(); -} - -void DreamGenContext::getObTextStart() { - STACK_CHECK; - es = data.word(kFreedesc); - si = (0); - cx = (0+(82*2)); - _cmp(data.byte(kObjecttype), 2); - if (flags.z()) - goto describe; - es = data.word(kSetdesc); - si = (0); - cx = (0+(130*2)); - _cmp(data.byte(kObjecttype), 1); - if (flags.z()) - goto describe; - es = data.word(kExtras); - si = (0+2080+30000+(16*114)); - cx = (0+2080+30000+(16*114)+((114+2)*2)); -describe: - al = data.byte(kCommand); - ah = 0; - _add(ax, ax); - _add(si, ax); - ax = es.word(si); - _add(ax, cx); - si = ax; - bx = ax; -tryagain: - push(si); - findNextColon(); - al = es.byte(si); - cx = si; - si = pop(); - _cmp(data.byte(kObjecttype), 1); - if (!flags.z()) - return /* (cantmakeoneup) */; - _cmp(al, 0); - if (flags.z()) - goto findsometext; - _cmp(al, ':'); - if (flags.z()) - goto findsometext; - return; -findsometext: - searchForSame(); - goto tryagain; -} - -void DreamGenContext::searchForSame() { - STACK_CHECK; - si = cx; -searchagain: - _inc(si); - al = es.byte(bx); -search: - _cmp(es.byte(si), al); - if (flags.z()) - goto gotstartletter; - _inc(cx); - _inc(si); - _cmp(si, 8000); - if (flags.c()) - goto search; - si = bx; - ax = pop(); - return; -gotstartletter: - push(bx); - push(si); -keepchecking: - _inc(si); - _inc(bx); - al = es.byte(bx); - ah = es.byte(si); - _cmp(al, ':'); - if (flags.z()) - goto foundmatch; - _cmp(al, 0); - if (flags.z()) - goto foundmatch; - _cmp(al, ah); - if (flags.z()) - goto keepchecking; - si = pop(); - bx = pop(); - goto searchagain; -foundmatch: - si = pop(); - bx = pop(); -} - -void DreamGenContext::setPickup() { - STACK_CHECK; - _cmp(data.byte(kObjecttype), 1); - if (flags.z()) - goto cantpick; - _cmp(data.byte(kObjecttype), 3); - if (flags.z()) - goto cantpick; - getAnyAd(); - al = es.byte(bx+2); - _cmp(al, 4); - if (!flags.z()) - goto canpick; -cantpick: - blank(); - return; -canpick: - _cmp(data.byte(kCommandtype), 209); - if (flags.z()) - goto alreadysp; - data.byte(kCommandtype) = 209; - bl = data.byte(kCommand); - bh = data.byte(kObjecttype); - al = 33; - commandWithOb(); -alreadysp: - ax = data.word(kMousebutton); - _cmp(ax, 1); - if (!flags.z()) - return /* (nosetpick) */; - _cmp(ax, data.word(kOldbutton)); - if (!flags.z()) - goto dosetpick; - return; -dosetpick: - createPanel(); - showPanel(); - showMan(); - showExit(); - examIcon(); - data.byte(kPickup) = 1; - data.byte(kInvopen) = 2; - _cmp(data.byte(kObjecttype), 4); - if (flags.z()) - goto pickupexob; - al = data.byte(kCommand); - data.byte(kItemframe) = al; - data.byte(kOpenedob) = 255; - transferToEx(); - data.byte(kItemframe) = al; - data.byte(kObjecttype) = 4; - getEitherAd(); - es.byte(bx+2) = 20; - es.byte(bx+3) = 255; - openInv(); - workToScreenM(); - return; -pickupexob: - al = data.byte(kCommand); - data.byte(kItemframe) = al; - data.byte(kOpenedob) = 255; - openInv(); - workToScreenM(); -} - -void DreamGenContext::reExFromInv() { - STACK_CHECK; - findInvPos(); - ax = es.word(bx); - data.byte(kCommandtype) = ah; - data.byte(kCommand) = al; - data.byte(kExamagain) = 1; - data.byte(kPointermode) = 0; -} - -void DreamGenContext::swapWithInv() { - STACK_CHECK; - al = data.byte(kItemframe); - ah = data.byte(kObjecttype); - _cmp(ax, data.word(kOldsubject)); - if (!flags.z()) - goto difsub7; - _cmp(data.byte(kCommandtype), 243); - if (flags.z()) - goto alreadyswap1; - data.byte(kCommandtype) = 243; -difsub7: - data.word(kOldsubject) = ax; - bx = ax; - al = 34; - commandWithOb(); -alreadyswap1: - ax = data.word(kMousebutton); - _cmp(ax, data.word(kOldbutton)); - if (flags.z()) - return /* (cantswap1) */; - _and(ax, 1); - if (!flags.z()) - goto doswap1; - return; -doswap1: - ah = data.byte(kObjecttype); - al = data.byte(kItemframe); - push(ax); - findInvPos(); - ax = es.word(bx); - data.byte(kItemframe) = al; - data.byte(kObjecttype) = ah; - getEitherAd(); - es.byte(bx+2) = 20; - es.byte(bx+3) = 255; - bl = data.byte(kItemframe); - bh = data.byte(kObjecttype); - ax = pop(); - data.byte(kObjecttype) = ah; - data.byte(kItemframe) = al; - push(bx); - findInvPos(); - delPointer(); - al = data.byte(kItemframe); - getEitherAd(); - es.byte(bx+2) = 4; - es.byte(bx+3) = 255; - al = data.byte(kLastinvpos); - es.byte(bx+4) = al; - ax = pop(); - data.byte(kObjecttype) = ah; - data.byte(kItemframe) = al; - fillRyan(); - readMouse(); - showPointer(); - workToScreen(); - delPointer(); -} - -void DreamGenContext::swapWithOpen() { - STACK_CHECK; - al = data.byte(kItemframe); - ah = data.byte(kObjecttype); - _cmp(ax, data.word(kOldsubject)); - if (!flags.z()) - goto difsub8; - _cmp(data.byte(kCommandtype), 242); - if (flags.z()) - goto alreadyswap2; - data.byte(kCommandtype) = 242; -difsub8: - data.word(kOldsubject) = ax; - bx = ax; - al = 34; - commandWithOb(); -alreadyswap2: - ax = data.word(kMousebutton); - _cmp(ax, data.word(kOldbutton)); - if (flags.z()) - return /* (cantswap2) */; - _and(ax, 1); - if (!flags.z()) - goto doswap2; - return; -doswap2: - getEitherAd(); - isItWorn(); - if (!flags.z()) - goto notwornswap; - wornError(); - return; -notwornswap: - delPointer(); - al = data.byte(kItemframe); - _cmp(al, data.byte(kOpenedob)); - if (!flags.z()) - goto isntsame2; - al = data.byte(kObjecttype); - _cmp(al, data.byte(kOpenedtype)); - if (!flags.z()) - goto isntsame2; - errorMessage1(); - return; -isntsame2: - checkObjectSize(); - _cmp(al, 0); - if (flags.z()) - goto sizeok2; - return; -sizeok2: - ah = data.byte(kObjecttype); - al = data.byte(kItemframe); - push(ax); - findOpenPos(); - ax = es.word(bx); - data.byte(kItemframe) = al; - data.byte(kObjecttype) = ah; - _cmp(ah, 4); - if (!flags.z()) - goto makeswapex; - getEitherAd(); - es.byte(bx+2) = 20; - es.byte(bx+3) = 255; - goto actuallyswap; -makeswapex: - transferToEx(); - data.byte(kItemframe) = al; - data.byte(kObjecttype) = 4; - getEitherAd(); - es.byte(bx+2) = 20; - es.byte(bx+3) = 255; -actuallyswap: - bl = data.byte(kItemframe); - bh = data.byte(kObjecttype); - ax = pop(); - data.byte(kObjecttype) = ah; - data.byte(kItemframe) = al; - push(bx); - findOpenPos(); - getEitherAd(); - al = data.byte(kOpenedtype); - es.byte(bx+2) = al; - al = data.byte(kOpenedob); - es.byte(bx+3) = al; - al = data.byte(kLastinvpos); - es.byte(bx+4) = al; - al = data.byte(kReallocation); - es.byte(bx+5) = al; - ax = pop(); - data.byte(kObjecttype) = ah; - data.byte(kItemframe) = al; - fillOpen(); - fillRyan(); - underTextLine(); - readMouse(); - useOpened(); - showPointer(); - workToScreen(); - delPointer(); -} - -void DreamGenContext::inToInv() { - STACK_CHECK; - _cmp(data.byte(kPickup), 0); - if (!flags.z()) - goto notout; - outOfInv(); - return; -notout: - findInvPos(); - ax = es.word(bx); - _cmp(al, 255); - if (flags.z()) - goto canplace1; - swapWithInv(); - return; -canplace1: - al = data.byte(kItemframe); - ah = data.byte(kObjecttype); - _cmp(ax, data.word(kOldsubject)); - if (!flags.z()) - goto difsub1; - _cmp(data.byte(kCommandtype), 220); - if (flags.z()) - goto alreadyplce; - data.byte(kCommandtype) = 220; -difsub1: - data.word(kOldsubject) = ax; - bx = ax; - al = 35; - commandWithOb(); -alreadyplce: - ax = data.word(kMousebutton); - _cmp(ax, data.word(kOldbutton)); - if (flags.z()) - return /* (notletgo2) */; - _and(ax, 1); - if (!flags.z()) - goto doplace; - return; -doplace: - delPointer(); - al = data.byte(kItemframe); - getExAd(); - es.byte(bx+2) = 4; - es.byte(bx+3) = 255; - al = data.byte(kLastinvpos); - es.byte(bx+4) = al; - data.byte(kPickup) = 0; - fillRyan(); - readMouse(); - showPointer(); - outOfInv(); - workToScreen(); - delPointer(); -} - -void DreamGenContext::outOfInv() { - STACK_CHECK; - findInvPos(); - ax = es.word(bx); - _cmp(al, 255); - if (!flags.z()) - goto canpick2; - blank(); - return; -canpick2: - bx = data.word(kMousebutton); - _cmp(bx, 2); - if (!flags.z()) - goto canpick2a; - reExFromInv(); - return; -canpick2a: - _cmp(ax, data.word(kOldsubject)); - if (!flags.z()) - goto difsub3; - _cmp(data.byte(kCommandtype), 221); - if (flags.z()) - goto alreadygrab; - data.byte(kCommandtype) = 221; -difsub3: - data.word(kOldsubject) = ax; - bx = ax; - al = 36; - commandWithOb(); -alreadygrab: - ax = data.word(kMousebutton); - _cmp(ax, data.word(kOldbutton)); - if (flags.z()) - return /* (notletgo) */; - _and(ax, 1); - if (!flags.z()) - goto dograb; - return; -dograb: - delPointer(); - data.byte(kPickup) = 1; - findInvPos(); - ax = es.word(bx); - data.byte(kItemframe) = al; - data.byte(kObjecttype) = ah; - getExAd(); - es.byte(bx+2) = 20; - es.byte(bx+3) = 255; - fillRyan(); - readMouse(); - showPointer(); - inToInv(); - workToScreen(); - delPointer(); -} - -void DreamGenContext::getFreeAd() { - STACK_CHECK; - ah = 0; - cl = 4; - _shl(ax, cl); - bx = ax; - es = data.word(kFreedat); -} - -void DreamGenContext::getExAd() { - STACK_CHECK; - ah = 0; - bx = 16; - _mul(bx); - bx = ax; - es = data.word(kExtras); - _add(bx, (0+2080+30000)); -} - -void DreamGenContext::getEitherAd() { - STACK_CHECK; - _cmp(data.byte(kObjecttype), 4); - if (flags.z()) - goto isinexlist; - al = data.byte(kItemframe); - getFreeAd(); - return; -isinexlist: - al = data.byte(kItemframe); - getExAd(); -} - -void DreamGenContext::getAnyAd() { - STACK_CHECK; - _cmp(data.byte(kObjecttype), 4); - if (flags.z()) - goto isex; - _cmp(data.byte(kObjecttype), 2); - if (flags.z()) - goto isfree; - al = data.byte(kCommand); - getSetAd(); - ax = es.word(bx+4); - return; -isfree: - al = data.byte(kCommand); - getFreeAd(); - ax = es.word(bx+7); - return; -isex: - al = data.byte(kCommand); - getExAd(); - ax = es.word(bx+7); -} - -void DreamGenContext::getOpenedSize() { - STACK_CHECK; - _cmp(data.byte(kOpenedtype), 4); - if (flags.z()) - goto isex2; - _cmp(data.byte(kOpenedtype), 2); - if (flags.z()) - goto isfree2; - al = data.byte(kOpenedob); - getSetAd(); - ax = es.word(bx+3); - return; -isfree2: - al = data.byte(kOpenedob); - getFreeAd(); - ax = es.word(bx+7); - return; -isex2: - al = data.byte(kOpenedob); - getExAd(); - ax = es.word(bx+7); -} - -void DreamGenContext::getSetAd() { - STACK_CHECK; - ah = 0; - bx = 64; - _mul(bx); - bx = ax; - es = data.word(kSetdat); -} - -void DreamGenContext::findInvPos() { - STACK_CHECK; - cx = data.word(kMousex); - _sub(cx, (80)); - bx = -1; -findinv1: - _inc(bx); - _sub(cx, (44)); - if (!flags.c()) - goto findinv1; - cx = data.word(kMousey); - _sub(cx, (58)); - _sub(bx, 5); -findinv2: - _add(bx, 5); - _sub(cx, (44)); - if (!flags.c()) - goto findinv2; - al = data.byte(kRyanpage); - ah = 0; - cx = 10; - _mul(cx); - _add(bx, ax); - al = bl; - data.byte(kLastinvpos) = al; - _add(bx, bx); - es = data.word(kBuffers); - _add(bx, (0+(228*13)+32)); -} - -void DreamGenContext::findOpenPos() { - STACK_CHECK; - cx = data.word(kMousex); - _sub(cx, (80)); - bx = -1; -findopenp1: - _inc(bx); - _sub(cx, (44)); - if (!flags.c()) - goto findopenp1; - al = bl; - data.byte(kLastinvpos) = al; - _add(bx, bx); - es = data.word(kBuffers); - _add(bx, (0+(228*13))); -} - -void DreamGenContext::dropObject() { - STACK_CHECK; - _cmp(data.byte(kCommandtype), 223); - if (flags.z()) - goto alreadydrop; - data.byte(kCommandtype) = 223; - _cmp(data.byte(kPickup), 0); - if (flags.z()) - { blank(); return; }; - bl = data.byte(kItemframe); - bh = data.byte(kObjecttype); - al = 37; - commandWithOb(); -alreadydrop: - ax = data.word(kMousebutton); - _cmp(ax, data.word(kOldbutton)); - if (flags.z()) - return /* (nodrop) */; - _and(ax, 1); - if (!flags.z()) - goto dodrop; - return; -dodrop: - getEitherAd(); - isItWorn(); - if (!flags.z()) - goto nowornerror; - wornError(); - return; -nowornerror: - _cmp(data.byte(kReallocation), 47); - if (flags.z()) - goto nodrop2; - cl = data.byte(kRyanx); - _add(cl, 12); - ch = data.byte(kRyany); - _add(ch, 12); - checkOne(); - _cmp(cl, 2); - if (flags.c()) - goto nodroperror; -nodrop2: - dropError(); - return; -nodroperror: - _cmp(data.byte(kMapxsize), 64); - if (!flags.z()) - goto notinlift; - _cmp(data.byte(kMapysize), 64); - if (!flags.z()) - goto notinlift; - dropError(); - return; -notinlift: - al = data.byte(kItemframe); - ah = 4; - cl = 'G'; - ch = 'U'; - dl = 'N'; - dh = 'A'; - compare(); - if (flags.z()) - { cantDrop(); return; }; - al = data.byte(kItemframe); - ah = 4; - cl = 'S'; - ch = 'H'; - dl = 'L'; - dh = 'D'; - compare(); - if (flags.z()) - { cantDrop(); return; }; - data.byte(kObjecttype) = 4; - al = data.byte(kItemframe); - getExAd(); - es.byte(bx+2) = 0; - al = data.byte(kRyanx); - _add(al, 4); - cl = 4; - _shr(al, cl); - _add(al, data.byte(kMapx)); - ah = data.byte(kRyany); - _add(ah, 8); - cl = 4; - _shr(ah, cl); - _add(ah, data.byte(kMapy)); - es.byte(bx+3) = al; - es.byte(bx+5) = ah; - al = data.byte(kRyanx); - _add(al, 4); - _and(al, 15); - ah = data.byte(kRyany); - _add(ah, 8); - _and(ah, 15); - es.byte(bx+4) = al; - es.byte(bx+6) = ah; - data.byte(kPickup) = 0; - al = data.byte(kReallocation); - es.byte(bx) = al; -} - -void DreamGenContext::removeObFromInv() { - STACK_CHECK; - _cmp(data.byte(kCommand), 100); - if (flags.z()) - return /* (obnotexist) */; - getAnyAd(); - di = bx; - cl = data.byte(kCommand); - ch = 0; - deleteExObject(); -} - -void DreamGenContext::selectOpenOb() { - STACK_CHECK; - al = data.byte(kCommand); - getAnyAd(); - _cmp(al, 255); - if (!flags.z()) - goto canopenit1; - blank(); - return; -canopenit1: - _cmp(data.byte(kCommandtype), 224); - if (flags.z()) - goto alreadyopob; - data.byte(kCommandtype) = 224; - bl = data.byte(kCommand); - bh = data.byte(kObjecttype); - al = 38; - commandWithOb(); -alreadyopob: - ax = data.word(kMousebutton); - _cmp(ax, data.word(kOldbutton)); - if (flags.z()) - return /* (noopenob) */; - _and(ax, 1); - if (!flags.z()) - goto doopenob; - return; -doopenob: - al = data.byte(kCommand); - data.byte(kOpenedob) = al; - al = data.byte(kObjecttype); - data.byte(kOpenedtype) = al; - createPanel(); - showPanel(); - showMan(); - examIcon(); - showExit(); - openInv(); - openOb(); - underTextLine(); - readMouse(); - showPointer(); - workToScreen(); - delPointer(); -} - -void DreamGenContext::useOpened() { - STACK_CHECK; - _cmp(data.byte(kOpenedob), 255); - if (flags.z()) - return /* (cannotuseopen) */; - _cmp(data.byte(kPickup), 0); - if (!flags.z()) - goto notout2; - outOfOpen(); - return; -notout2: - findOpenPos(); - ax = es.word(bx); - _cmp(al, 255); - if (flags.z()) - goto canplace3; - swapWithOpen(); - return; -canplace3: - _cmp(data.byte(kPickup), 1); - if (flags.z()) - goto intoopen; - blank(); - return; -intoopen: - al = data.byte(kItemframe); - ah = data.byte(kObjecttype); - _cmp(ax, data.word(kOldsubject)); - if (!flags.z()) - goto difsub2; - _cmp(data.byte(kCommandtype), 227); - if (flags.z()) - goto alreadyplc2; - data.byte(kCommandtype) = 227; -difsub2: - data.word(kOldsubject) = ax; - bx = ax; - al = 35; - commandWithOb(); -alreadyplc2: - ax = data.word(kMousebutton); - _cmp(ax, data.word(kOldbutton)); - if (flags.z()) - return /* (notletgo3) */; - _cmp(ax, 1); - if (flags.z()) - goto doplace2; - return; -doplace2: - getEitherAd(); - isItWorn(); - if (!flags.z()) - goto notworntoopen; - wornError(); - return; -notworntoopen: - delPointer(); - al = data.byte(kItemframe); - _cmp(al, data.byte(kOpenedob)); - if (!flags.z()) - goto isntsame; - al = data.byte(kObjecttype); - _cmp(al, data.byte(kOpenedtype)); - if (!flags.z()) - goto isntsame; - errorMessage1(); - return; -isntsame: - checkObjectSize(); - _cmp(al, 0); - if (flags.z()) - goto sizeok1; - return; -sizeok1: - data.byte(kPickup) = 0; - al = data.byte(kItemframe); - getEitherAd(); - al = data.byte(kOpenedtype); - es.byte(bx+2) = al; - al = data.byte(kOpenedob); - es.byte(bx+3) = al; - al = data.byte(kLastinvpos); - es.byte(bx+4) = al; - al = data.byte(kReallocation); - es.byte(bx+5) = al; - fillOpen(); - underTextLine(); - readMouse(); - useOpened(); - showPointer(); - workToScreen(); - delPointer(); -} - -void DreamGenContext::checkObjectSize() { - STACK_CHECK; - getOpenedSize(); - push(ax); - al = data.byte(kItemframe); - getEitherAd(); - al = es.byte(bx+9); - cx = pop(); - _cmp(al, 255); - if (!flags.z()) - goto notunsized; - al = 6; -notunsized: - _cmp(al, 100); - if (!flags.c()) - goto specialcase; - _cmp(cl, 100); - if (flags.c()) - goto isntspecial; - errorMessage3(); - goto sizewrong; -isntspecial: - _cmp(cl, al); - if (!flags.c()) - goto sizeok; -specialcase: - _sub(al, 100); - _cmp(cl, 100); - if (!flags.c()) - goto bothspecial; - _cmp(cl, al); - if (!flags.c()) - goto sizeok; - errorMessage2(); - goto sizewrong; -bothspecial: - _sub(cl, 100); - _cmp(al, cl); - if (flags.z()) - goto sizeok; - errorMessage3(); -sizewrong: - al = 1; - return; -sizeok: - al = 0; -} - -void DreamGenContext::outOfOpen() { - STACK_CHECK; - _cmp(data.byte(kOpenedob), 255); - if (flags.z()) - goto cantuseopen; - findOpenPos(); - ax = es.word(bx); - _cmp(al, 255); - if (!flags.z()) - goto canpick4; -cantuseopen: - blank(); - return; -canpick4: - _cmp(ax, data.word(kOldsubject)); - if (!flags.z()) - goto difsub4; - _cmp(data.byte(kCommandtype), 228); - if (flags.z()) - goto alreadygrb; - data.byte(kCommandtype) = 228; -difsub4: - data.word(kOldsubject) = ax; - bx = ax; - al = 36; - commandWithOb(); -alreadygrb: - ax = data.word(kMousebutton); - _cmp(ax, data.word(kOldbutton)); - if (flags.z()) - return /* (notletgo4) */; - _cmp(ax, 1); - if (flags.z()) - goto dogrb; - _cmp(ax, 2); - if (!flags.z()) - return /* (notletgo4) */; - reExFromOpen(); - return; -dogrb: - delPointer(); - data.byte(kPickup) = 1; - findOpenPos(); - ax = es.word(bx); - data.byte(kItemframe) = al; - data.byte(kObjecttype) = ah; - _cmp(ah, 4); - if (!flags.z()) - goto makeintoex; - getEitherAd(); - es.byte(bx+2) = 20; - es.byte(bx+3) = 255; - goto actuallyout; -makeintoex: - transferToEx(); - data.byte(kItemframe) = al; - data.byte(kObjecttype) = 4; - getEitherAd(); - es.byte(bx+2) = 20; - es.byte(bx+3) = 255; -actuallyout: - fillOpen(); - underTextLine(); - readMouse(); - useOpened(); - showPointer(); - workToScreen(); - delPointer(); -} - -void DreamGenContext::transferToEx() { - STACK_CHECK; - emergencyPurge(); - getExPos(); - al = data.byte(kExpos); - push(ax); - push(di); - al = data.byte(kItemframe); - ah = 0; - bx = 16; - _mul(bx); - ds = data.word(kFreedat); - si = ax; - cx = 8; - _movsw(cx, true); - di = pop(); - al = data.byte(kReallocation); - es.byte(di) = al; - es.byte(di+11) = al; - al = data.byte(kItemframe); - es.byte(di+1) = al; - es.byte(di+2) = 4; - es.byte(di+3) = 255; - al = data.byte(kLastinvpos); - es.byte(di+4) = al; - al = data.byte(kItemframe); - data.byte(kItemtotran) = al; - transferMap(); - transferInv(); - transferText(); - al = data.byte(kItemframe); - ah = 0; - bx = 16; - _mul(bx); - ds = data.word(kFreedat); - si = ax; - ds.byte(si+2) = 254; - pickupConts(); - ax = pop(); -} - -void DreamGenContext::pickupConts() { - STACK_CHECK; - al = ds.byte(si+7); - _cmp(al, 255); - if (flags.z()) - return /* (notopenable) */; - al = data.byte(kItemframe); - ah = data.byte(kObjecttype); - dl = data.byte(kExpos); - es = data.word(kFreedat); - bx = 0; - cx = 0; -pickupcontloop: - push(cx); - push(es); - push(bx); - push(dx); - push(ax); - _cmp(es.byte(bx+2), ah); - if (!flags.z()) - goto notinsidethis; - _cmp(es.byte(bx+3), al); - if (!flags.z()) - goto notinsidethis; - data.byte(kItemtotran) = cl; - transferConToEx(); -notinsidethis: - ax = pop(); - dx = pop(); - bx = pop(); - es = pop(); - cx = pop(); - _add(bx, 16); - _inc(cx); - _cmp(cx, 80); - if (!flags.z()) - goto pickupcontloop; -} - -void DreamGenContext::transferConToEx() { - STACK_CHECK; - push(es); - push(bx); - push(dx); - push(es); - push(bx); - getExPos(); - si = pop(); - ds = pop(); - push(di); - cx = 8; - _movsw(cx, true); - di = pop(); - dx = pop(); - al = data.byte(kReallocation); - es.byte(di) = al; - es.byte(di+11) = al; - al = data.byte(kItemtotran); - es.byte(di+1) = al; - es.byte(di+3) = dl; - es.byte(di+2) = 4; - transferMap(); - transferInv(); - transferText(); - si = pop(); - ds = pop(); - ds.byte(si+2) = 255; -} - -void DreamGenContext::purgeALocation() { - STACK_CHECK; - push(ax); - es = data.word(kExtras); - di = (0+2080+30000); - bx = pop(); - cx = 0; -purgeloc: - _cmp(bl, es.byte(di+0)); - if (!flags.z()) - goto dontpurge; - _cmp(es.byte(di+2), 0); - if (!flags.z()) - goto dontpurge; - push(di); - push(es); - push(bx); - push(cx); - deleteExObject(); - cx = pop(); - bx = pop(); - es = pop(); - di = pop(); -dontpurge: - _add(di, 16); - _inc(cx); - _cmp(cx, (114)); - if (!flags.z()) - goto purgeloc; -} - -void DreamGenContext::emergencyPurge() { - STACK_CHECK; -checkpurgeagain: - ax = data.word(kExframepos); - _add(ax, 4000); - _cmp(ax, (30000)); - if (flags.c()) - goto notnearframeend; - purgeAnItem(); - goto checkpurgeagain; -notnearframeend: - ax = data.word(kExtextpos); - _add(ax, 400); - _cmp(ax, (18000)); - if (flags.c()) - return /* (notneartextend) */; - purgeAnItem(); - goto checkpurgeagain; -} - -void DreamGenContext::purgeAnItem() { - STACK_CHECK; - es = data.word(kExtras); - di = (0+2080+30000); - bl = data.byte(kReallocation); - cx = 0; -lookforpurge: - al = es.byte(di+2); - _cmp(al, 0); - if (!flags.z()) - goto cantpurge; - _cmp(es.byte(di+12), 2); - if (flags.z()) - goto iscup; - _cmp(es.byte(di+12), 255); - if (!flags.z()) - goto cantpurge; -iscup: - _cmp(es.byte(di+11), bl); - if (flags.z()) - goto cantpurge; - deleteExObject(); - return; -cantpurge: - _add(di, 16); - _inc(cx); - _cmp(cx, (114)); - if (!flags.z()) - goto lookforpurge; - di = (0+2080+30000); - bl = data.byte(kReallocation); - cx = 0; -lookforpurge2: - al = es.byte(di+2); - _cmp(al, 0); - if (!flags.z()) - goto cantpurge2; - _cmp(es.byte(di+12), 255); - if (!flags.z()) - goto cantpurge2; - deleteExObject(); - return; -cantpurge2: - _add(di, 16); - _inc(cx); - _cmp(cx, (114)); - if (!flags.z()) - goto lookforpurge2; -} - -void DreamGenContext::deleteExObject() { - STACK_CHECK; - push(cx); - push(cx); - push(cx); - push(cx); - al = 255; - cx = 16; - _stosb(cx, true); - ax = pop(); - cl = al; - _add(al, al); - _add(al, cl); - deleteExFrame(); - ax = pop(); - cl = al; - _add(al, al); - _add(al, cl); - _inc(al); - deleteExFrame(); - ax = pop(); - deleteExText(); - bx = pop(); - bh = bl; - bl = 4; - di = (0+2080+30000); - cx = 0; -deleteconts: - _cmp(es.word(di+2), bx); - if (!flags.z()) - goto notinsideex; - push(bx); - push(cx); - push(di); - deleteExObject(); - di = pop(); - cx = pop(); - bx = pop(); -notinsideex: - _add(di, 16); - _inc(cx); - _cmp(cx, (114)); - if (!flags.z()) - goto deleteconts; -} - -void DreamGenContext::deleteExFrame() { - STACK_CHECK; - di = (0); - ah = 0; - _add(ax, ax); - _add(di, ax); - _add(ax, ax); - _add(di, ax); - al = es.byte(di); - ah = 0; - cl = es.byte(di+1); - ch = 0; - _mul(cx); - si = es.word(di+2); - push(si); - _add(si, (0+2080)); - cx = (30000); - _sub(cx, es.word(di+2)); - di = si; - _add(si, ax); - push(ax); - ds = es; - _movsb(cx, true); - bx = pop(); - _sub(data.word(kExframepos), bx); - si = pop(); - cx = (114)*3; - di = (0); -shuffleadsdown: - ax = es.word(di+2); - _cmp(ax, si); - if (flags.c()) - goto beforethisone; - _sub(ax, bx); -beforethisone: - es.word(di+2) = ax; - _add(di, 6); - if (--cx) - goto shuffleadsdown; -} - -void DreamGenContext::deleteExText() { - STACK_CHECK; - di = (0+2080+30000+(16*114)); - ah = 0; - _add(ax, ax); - _add(di, ax); - ax = es.word(di); - si = ax; - di = ax; - _add(si, (0+2080+30000+(16*114)+((114+2)*2))); - _add(di, (0+2080+30000+(16*114)+((114+2)*2))); - ax = 0; -findlenextext: - cl = es.byte(si); - _inc(ax); - _inc(si); - _cmp(cl, 0); - if (!flags.z()) - goto findlenextext; - cx = (18000); - bx = si; - _sub(bx, (0+2080+30000+(16*114)+((114+2)*2))); - push(bx); - push(ax); - _sub(cx, bx); - _movsb(cx, true); - bx = pop(); - _sub(data.word(kExtextpos), bx); - si = pop(); - cx = (114); - di = (0+2080+30000+(16*114)); -shuffletextads: - ax = es.word(di); - _cmp(ax, si); - if (flags.c()) - goto beforethistext; - _sub(ax, bx); -beforethistext: - es.word(di) = ax; - _add(di, 2); - if (--cx) - goto shuffletextads; -} - -void DreamGenContext::startTalk() { - STACK_CHECK; - data.byte(kTalkmode) = 0; - al = data.byte(kCharacter); - _and(al, 127); - getPersonText(); - data.word(kCharshift) = 91+91; - di = 66; - bx = 64; - dl = 241; - al = 0; - ah = 79; - printDirect(); - data.word(kCharshift) = 0; - di = 66; - bx = 80; - dl = 241; - al = 0; - ah = 0; - printDirect(); - data.byte(kSpeechloaded) = 0; - al = data.byte(kCharacter); - _and(al, 127); - ah = 0; - cx = 64; - _mul(cx); - cl = 'C'; - dl = 'R'; - dh = data.byte(kReallocation); - loadSpeech(); - _cmp(data.byte(kSpeechloaded), 1); - if (!flags.z()) - return /* (nospeech1) */; - data.byte(kVolumedirection) = 1; - data.byte(kVolumeto) = 6; - al = 50+12; - playChannel1(); -} - -void DreamGenContext::getPersonText() { - STACK_CHECK; - ah = 0; - cx = 64*2; - _mul(cx); - si = ax; - es = data.word(kPeople); - _add(si, (0+24)); - cx = (0+24+(1026*2)); - ax = es.word(si); - _add(ax, cx); - si = ax; -} - -void DreamGenContext::doSomeTalk() { - STACK_CHECK; -dospeech: - al = data.byte(kTalkpos); - al = data.byte(kCharacter); - _and(al, 127); - ah = 0; - cx = 64; - _mul(cx); - cx = ax; - al = data.byte(kTalkpos); - ah = 0; - _add(ax, cx); - _add(ax, ax); - si = ax; - es = data.word(kPeople); - _add(si, (0+24)); - cx = (0+24+(1026*2)); - ax = es.word(si); - _add(ax, cx); - si = ax; - _cmp(es.byte(si), 0); - if (flags.z()) - goto endheartalk; - push(es); - push(si); - createPanel(); - showPanel(); - showMan(); - showExit(); - convIcons(); - si = pop(); - es = pop(); - di = 164; - bx = 64; - dl = 144; - al = 0; - ah = 0; - printDirect(); - al = data.byte(kCharacter); - _and(al, 127); - ah = 0; - cx = 64; - _mul(cx); - cl = data.byte(kTalkpos); - ch = 0; - _add(ax, cx); - cl = 'C'; - dl = 'R'; - dh = data.byte(kReallocation); - loadSpeech(); - _cmp(data.byte(kSpeechloaded), 0); - if (flags.z()) - goto noplay1; - al = 62; - playChannel1(); -noplay1: - data.byte(kPointermode) = 3; - workToScreenM(); - cx = 180; - hangOnPQ(); - if (!flags.c()) - goto _tmp1; - return; -_tmp1: - _inc(data.byte(kTalkpos)); - al = data.byte(kTalkpos); - al = data.byte(kCharacter); - _and(al, 127); - ah = 0; - cx = 64; - _mul(cx); - cx = ax; - al = data.byte(kTalkpos); - ah = 0; - _add(ax, cx); - _add(ax, ax); - si = ax; - es = data.word(kPeople); - _add(si, (0+24)); - cx = (0+24+(1026*2)); - ax = es.word(si); - _add(ax, cx); - si = ax; - _cmp(es.byte(si), 0); - if (flags.z()) - goto endheartalk; - _cmp(es.byte(si), ':'); - if (flags.z()) - goto skiptalk2; - _cmp(es.byte(si), 32); - if (flags.z()) - goto skiptalk2; - push(es); - push(si); - createPanel(); - showPanel(); - showMan(); - showExit(); - convIcons(); - si = pop(); - es = pop(); - di = 48; - bx = 128; - dl = 144; - al = 0; - ah = 0; - printDirect(); - al = data.byte(kCharacter); - _and(al, 127); - ah = 0; - cx = 64; - _mul(cx); - cl = data.byte(kTalkpos); - ch = 0; - _add(ax, cx); - cl = 'C'; - dl = 'R'; - dh = data.byte(kReallocation); - loadSpeech(); - _cmp(data.byte(kSpeechloaded), 0); - if (flags.z()) - goto noplay2; - al = 62; - playChannel1(); -noplay2: - data.byte(kPointermode) = 3; - workToScreenM(); - cx = 180; - hangOnPQ(); - if (!flags.c()) - goto skiptalk2; - return; -skiptalk2: - _inc(data.byte(kTalkpos)); - goto dospeech; -endheartalk: - data.byte(kPointermode) = 0; -} - -void DreamGenContext::lookAtPlace() { - STACK_CHECK; - _cmp(data.byte(kCommandtype), 224); - if (flags.z()) - goto alreadyinfo; - data.byte(kCommandtype) = 224; - al = 27; - commandOnly(); -alreadyinfo: - ax = data.word(kMousebutton); - _and(ax, 1); - if (flags.z()) - return /* (noinfo) */; - _cmp(ax, data.word(kOldbutton)); - if (flags.z()) - return /* (noinfo) */; - bl = data.byte(kDestpos); - _cmp(bl, 15); - if (!flags.c()) - return /* (noinfo) */; - push(bx); - delPointer(); - delTextLine(); - getUnderCentre(); - ds = data.word(kTempgraphics3); - al = 0; - ah = 0; - di = 60; - bx = 72; - showFrame(); - al = 4; - ah = 0; - di = 60; - bx = 72+55; - showFrame(); - _cmp(data.byte(kForeignrelease), 0); - if (flags.z()) - goto _tmp1; - al = 4; - ah = 0; - di = 60; - bx = 72+55+21; - showFrame(); -_tmp1: - bx = pop(); - bh = 0; - _add(bx, bx); - es = data.word(kTraveltext); - si = es.word(bx); - _add(si, (66*2)); - findNextColon(); - di = 63; - bx = 84; - _cmp(data.byte(kForeignrelease), 0); - if (flags.z()) - goto _tmp2; - bx = 84+4; -_tmp2: - dl = 191; - al = 0; - ah = 0; - printDirect(); - workToScreenM(); - cx = 500; - hangOnP(); - data.byte(kPointermode) = 0; - data.byte(kPointerframe) = 0; - putUnderCentre(); - workToScreenM(); -} - -void DreamGenContext::getUnderCentre() { - STACK_CHECK; - di = 58; - bx = 72; - ds = data.word(kMapstore); - si = 0; - cl = 254; - ch = 110; - multiGet(); -} - -void DreamGenContext::putUnderCentre() { - STACK_CHECK; - di = 58; - bx = 72; - ds = data.word(kMapstore); - si = 0; - cl = 254; - ch = 110; - multiPut(); -} - -void DreamGenContext::locationPic() { - STACK_CHECK; - getDestInfo(); - al = es.byte(si); - push(es); - push(si); - di = 0; - _cmp(al, 6); - if (!flags.c()) - goto secondlot; - ds = data.word(kTempgraphics); - _add(al, 4); - goto gotgraphic; -secondlot: - _sub(al, 6); - ds = data.word(kTempgraphics2); -gotgraphic: - _add(di, 104); - bx = 138+14; - ah = 0; - showFrame(); - si = pop(); - es = pop(); - al = data.byte(kDestpos); - _cmp(al, data.byte(kReallocation)); - if (!flags.z()) - goto notinthisone; - al = 3; - di = 104; - bx = 140+14; - ds = data.word(kTempgraphics); - ah = 0; - showFrame(); -notinthisone: - bl = data.byte(kDestpos); - bh = 0; - _add(bx, bx); - es = data.word(kTraveltext); - si = es.word(bx); - _add(si, (66*2)); - di = 50; - bx = 20; - dl = 241; - al = 0; - ah = 0; - printDirect(); -} - -void DreamGenContext::getDestInfo() { - STACK_CHECK; - al = data.byte(kDestpos); - ah = 0; - push(ax); - dx = data; - es = dx; - si = 1249; - _add(si, ax); - cl = es.byte(si); - ax = pop(); - push(cx); - dx = data; - es = dx; - si = 1265; - _add(si, ax); - ax = pop(); -} - -void DreamGenContext::resetLocation() { - STACK_CHECK; - push(ax); - _cmp(al, 5); - if (!flags.z()) - goto notdelhotel; - purgeALocation(); - al = 21; - purgeALocation(); - al = 22; - purgeALocation(); - al = 27; - purgeALocation(); - goto clearedlocations; -notdelhotel: - _cmp(al, 8); - if (!flags.z()) - goto notdeltvstud; - purgeALocation(); - al = 28; - purgeALocation(); - goto clearedlocations; -notdeltvstud: - _cmp(al, 6); - if (!flags.z()) - goto notdelsarters; - purgeALocation(); - al = 20; - purgeALocation(); - al = 25; - purgeALocation(); - goto clearedlocations; -notdelsarters: - _cmp(al, 13); - if (!flags.z()) - goto notdelboathouse; - purgeALocation(); - al = 29; - purgeALocation(); - goto clearedlocations; -notdelboathouse: -clearedlocations: - ax = pop(); - ah = 0; - bx = ax; - dx = data; - es = dx; - _add(bx, 1249); - es.byte(bx) = 0; -} - -void DreamGenContext::lookInInterface() { - STACK_CHECK; - al = 'I'; - ah = 'N'; - cl = 'T'; - ch = 'F'; - findSetObject(); - ah = 1; - checkInside(); - _cmp(cl, (114)); - if (flags.z()) - goto emptyinterface; - al = es.byte(bx+15); - _inc(al); - return; -emptyinterface: - al = 0; -} - -void DreamGenContext::makeCaps() { - STACK_CHECK; - _cmp(al, 'a'); - if (flags.c()) - return /* (notupperc) */; - _sub(al, 32); -} - -void DreamGenContext::execCommand() { - STACK_CHECK; - es = cs; - bx = offset_comlist; - ds = cs; - si = 1283; - al = ds.byte(si); - _cmp(al, 0); - if (!flags.z()) - goto notblankinp; - scrollMonitor(); - return; -notblankinp: - cl = 0; -comloop: - push(bx); - push(si); -comloop2: - al = ds.byte(si); - _add(si, 2); - ah = es.byte(bx); - _inc(bx); - _cmp(ah, 32); - if (flags.z()) - goto foundcom; - _cmp(al, ah); - if (flags.z()) - goto comloop2; - si = pop(); - bx = pop(); - _add(bx, 10); - _inc(cl); - _cmp(cl, 6); - if (!flags.z()) - goto comloop; - netError(); - al = 0; - return; -foundcom: - si = pop(); - bx = pop(); - _cmp(cl, 1); - if (flags.z()) - goto testcom; - _cmp(cl, 2); - if (flags.z()) - goto directory; - _cmp(cl, 3); - if (flags.z()) - goto accesscom; - _cmp(cl, 4); - if (flags.z()) - goto signoncom; - _cmp(cl, 5); - if (flags.z()) - goto keyscom; - goto quitcom; -directory: - dirCom(); - al = 0; - return; -signoncom: - signOn(); - al = 0; - return; -accesscom: - read(); - al = 0; - return; -keyscom: - showKeys(); - al = 0; - return; -testcom: - al = 6; - monMessage(); - al = 0; - return; -quitcom: - al = 1; -} - -void DreamGenContext::dirCom() { - STACK_CHECK; - cx = 30; - randomAccess(); - parser(); - _cmp(es.byte(di+1), 0); - if (flags.z()) - goto dirroot; - dirFile(); - return; -dirroot: - data.byte(kLogonum) = 0; - ds = cs; - si = offset_rootdir; - _inc(si); - es = cs; - di = 1125; - _inc(di); - cx = 12; - _movsb(cx, true); - monitorLogo(); - scrollMonitor(); - al = 9; - monMessage(); - es = data.word(kTextfile1); - searchForFiles(); - es = data.word(kTextfile2); - searchForFiles(); - es = data.word(kTextfile3); - searchForFiles(); - scrollMonitor(); -} - -void DreamGenContext::searchForFiles() { - STACK_CHECK; - bx = (66*2); -directloop1: - al = es.byte(bx); - _inc(bx); - _cmp(al, '*'); - if (flags.z()) - return /* (endofdir) */; - _cmp(al, 34); - if (!flags.z()) - goto directloop1; - monPrint(); - goto directloop1; -} - -void DreamGenContext::signOn() { - STACK_CHECK; - parser(); - _inc(di); - ds = cs; - si = offset_keys; - cx = 4; -signonloop: - push(cx); - push(si); - push(di); - _add(si, 14); - cx = 11; -signonloop2: - _lodsb(); - _cmp(al, 32); - if (flags.z()) - goto foundsign; - makeCaps(); - ah = es.byte(di); - _inc(di); - _cmp(al, ah); - if (!flags.z()) - goto nomatch; - if (--cx) - goto signonloop2; -nomatch: - di = pop(); - si = pop(); - cx = pop(); - _add(si, 26); - if (--cx) - goto signonloop; - al = 13; - monMessage(); - return; -foundsign: - di = pop(); - si = pop(); - cx = pop(); - bx = si; - es = ds; - _cmp(es.byte(bx), 0); - if (flags.z()) - goto notyetassigned; - al = 17; - monMessage(); - return; -notyetassigned: - push(es); - push(bx); - scrollMonitor(); - al = 15; - monMessage(); - di = data.word(kMonadx); - bx = data.word(kMonady); - push(di); - push(bx); - input(); - bx = pop(); - di = pop(); - data.word(kMonadx) = di; - data.word(kMonady) = bx; - bx = pop(); - es = pop(); - push(es); - push(bx); - _add(bx, 2); - ds = cs; - si = 1283; -checkpass: - _lodsw(); - ah = es.byte(bx); - _inc(bx); - _cmp(ah, 32); - if (flags.z()) - goto passpassed; - _cmp(al, ah); - if (flags.z()) - goto checkpass; - bx = pop(); - es = pop(); - scrollMonitor(); - al = 16; - monMessage(); - return; -passpassed: - al = 14; - monMessage(); - bx = pop(); - es = pop(); - push(es); - push(bx); - _add(bx, 14); - monPrint(); - scrollMonitor(); - bx = pop(); - es = pop(); - es.byte(bx) = 1; -} - -void DreamGenContext::showKeys() { - STACK_CHECK; - cx = 10; - randomAccess(); - scrollMonitor(); - al = 18; - monMessage(); - es = cs; - bx = offset_keys; - cx = 4; -keysloop: - push(cx); - push(bx); - _cmp(es.byte(bx), 0); - if (flags.z()) - goto notheld; - _add(bx, 14); - monPrint(); -notheld: - bx = pop(); - cx = pop(); - _add(bx, 26); - if (--cx) - goto keysloop; - scrollMonitor(); -} - -void DreamGenContext::read() { - STACK_CHECK; - cx = 40; - randomAccess(); - parser(); - _cmp(es.byte(di+1), 0); - if (!flags.z()) - goto okcom; - netError(); - return; -okcom: - es = cs; - di = 1125; - ax = data.word(kTextfile1); - data.word(kMonsource) = ax; - ds = ax; - si = (66*2); - searchForString(); - _cmp(al, 0); - if (flags.z()) - goto foundfile2; - ax = data.word(kTextfile2); - data.word(kMonsource) = ax; - ds = ax; - si = (66*2); - searchForString(); - _cmp(al, 0); - if (flags.z()) - goto foundfile2; - ax = data.word(kTextfile3); - data.word(kMonsource) = ax; - ds = ax; - si = (66*2); - searchForString(); - _cmp(al, 0); - if (flags.z()) - goto foundfile2; - al = 7; - monMessage(); - return; -foundfile2: - getKeyAndLogo(); - _cmp(al, 0); - if (flags.z()) - goto keyok1; - return; -keyok1: - es = cs; - di = offset_operand1; - ds = data.word(kMonsource); - searchForString(); - _cmp(al, 0); - if (flags.z()) - goto findtopictext; - al = data.byte(kOldlogonum); - data.byte(kLogonum) = al; - al = 11; - monMessage(); - return; -findtopictext: - _inc(bx); - push(es); - push(bx); - monitorLogo(); - scrollMonitor(); - bx = pop(); - es = pop(); -moretopic: - monPrint(); - al = es.byte(bx); - _cmp(al, 34); - if (flags.z()) - goto endoftopic; - _cmp(al, '='); - if (flags.z()) - goto endoftopic; - _cmp(al, '*'); - if (flags.z()) - goto endoftopic; - push(es); - push(bx); - processTrigger(); - cx = 24; - randomAccess(); - bx = pop(); - es = pop(); - goto moretopic; -endoftopic: - scrollMonitor(); -} - -void DreamGenContext::dirFile() { - STACK_CHECK; - al = 34; - es.byte(di) = al; - push(es); - push(di); - ds = data.word(kTextfile1); - si = (66*2); - searchForString(); - _cmp(al, 0); - if (flags.z()) - goto foundfile; - di = pop(); - es = pop(); - push(es); - push(di); - ds = data.word(kTextfile2); - si = (66*2); - searchForString(); - _cmp(al, 0); - if (flags.z()) - goto foundfile; - di = pop(); - es = pop(); - push(es); - push(di); - ds = data.word(kTextfile3); - si = (66*2); - searchForString(); - _cmp(al, 0); - if (flags.z()) - goto foundfile; - di = pop(); - es = pop(); - al = 7; - monMessage(); - return; -foundfile: - ax = pop(); - ax = pop(); - getKeyAndLogo(); - _cmp(al, 0); - if (flags.z()) - goto keyok2; - return; -keyok2: - push(es); - push(bx); - ds = cs; - si = offset_operand1+1; - es = cs; - di = 1125+1; - cx = 12; - _movsb(cx, true); - monitorLogo(); - scrollMonitor(); - al = 10; - monMessage(); - bx = pop(); - es = pop(); -directloop2: - al = es.byte(bx); - _inc(bx); - _cmp(al, 34); - if (flags.z()) - goto endofdir2; - _cmp(al, '*'); - if (flags.z()) - goto endofdir2; - _cmp(al, '='); - if (!flags.z()) - goto directloop2; - monPrint(); - goto directloop2; -endofdir2: - scrollMonitor(); -} - -void DreamGenContext::getKeyAndLogo() { - STACK_CHECK; - _inc(bx); - al = es.byte(bx); - _sub(al, 48); - data.byte(kNewlogonum) = al; - _add(bx, 2); - al = es.byte(bx); - _sub(al, 48); - data.byte(kKeynum) = al; - _inc(bx); - push(es); - push(bx); - al = data.byte(kKeynum); - ah = 0; - cx = 26; - _mul(cx); - es = cs; - bx = offset_keys; - _add(bx, ax); - al = es.byte(bx); - _cmp(al, 1); - if (flags.z()) - goto keyok; - push(bx); - push(es); - al = 12; - monMessage(); - es = pop(); - bx = pop(); - _add(bx, 14); - monPrint(); - scrollMonitor(); - bx = pop(); - es = pop(); - al = 1; - return; -keyok: - bx = pop(); - es = pop(); - al = data.byte(kNewlogonum); - data.byte(kLogonum) = al; - al = 0; -} - -void DreamGenContext::searchForString() { - STACK_CHECK; - dl = es.byte(di); - cx = di; -restartlook: - di = cx; - bx = si; - dh = 0; -keeplooking: - _lodsb(); - makeCaps(); - _cmp(al, '*'); - if (flags.z()) - goto notfound; - _cmp(dl, '='); - if (!flags.z()) - goto nofindingtopic; - _cmp(al, 34); - if (flags.z()) - goto notfound; -nofindingtopic: - ah = es.byte(di); - _cmp(al, dl); - if (!flags.z()) - goto notbracket; - _inc(dh); - _cmp(dh, 2); - if (flags.z()) - goto complete; -notbracket: - _cmp(al, ah); - if (!flags.z()) - goto restartlook; - _inc(di); - goto keeplooking; -complete: - es = ds; - al = 0; - bx = si; - return; -notfound: - al = 1; -} - -void DreamGenContext::parser() { - STACK_CHECK; - es = cs; - di = offset_operand1; - cx = 13; - al = 0; - _stosb(cx, true); - di = offset_operand1; - al = '='; - _stosb(); - ds = cs; - si = 1283; -notspace1: - _lodsw(); - _cmp(al, 32); - if (flags.z()) - goto stillspace1; - _cmp(al, 0); - if (!flags.z()) - goto notspace1; - goto finishpars; -stillspace1: - _lodsw(); - _cmp(al, 32); - if (flags.z()) - goto stillspace1; -copyin1: - _stosb(); - _lodsw(); - _cmp(al, 0); - if (flags.z()) - goto finishpars; - _cmp(al, 32); - if (!flags.z()) - goto copyin1; -finishpars: - di = offset_operand1; -} - -void DreamGenContext::processTrigger() { - STACK_CHECK; - _cmp(data.byte(kLasttrigger), '1'); - if (!flags.z()) - goto notfirsttrigger; - al = 8; - setLocation(); - al = 45; - triggerMessage(); - return; -notfirsttrigger: - _cmp(data.byte(kLasttrigger), '2'); - if (!flags.z()) - goto notsecondtrigger; - al = 9; - setLocation(); - al = 55; - triggerMessage(); - return; -notsecondtrigger: - _cmp(data.byte(kLasttrigger), '3'); - if (!flags.z()) - return /* (notthirdtrigger) */; - al = 2; - setLocation(); - al = 59; - triggerMessage(); -} - -void DreamGenContext::triggerMessage() { - STACK_CHECK; - push(ax); - di = 174; - bx = 153; - cl = 200; - ch = 63; - ds = data.word(kMapstore); - si = 0; - multiGet(); - ax = pop(); - findPuzText(); - di = 174; - bx = 156; - dl = 141; - ah = 16; - printDirect(); - cx = 140; - hangOn(); - workToScreen(); - cx = 340; - hangOn(); - di = 174; - bx = 153; - cl = 200; - ch = 63; - ds = data.word(kMapstore); - si = 0; - multiPut(); - workToScreen(); - data.byte(kLasttrigger) = 0; -} - -void DreamGenContext::runTap() { - STACK_CHECK; - _cmp(data.byte(kWithobject), 255); - if (!flags.z()) - goto tapwith; - withWhat(); - return; -tapwith: - al = data.byte(kWithobject); - ah = data.byte(kWithtype); - cl = 'C'; - ch = 'U'; - dl = 'P'; - dh = 'E'; - compare(); - if (flags.z()) - goto fillcupfromtap; - al = data.byte(kWithobject); - ah = data.byte(kWithtype); - cl = 'C'; - ch = 'U'; - dl = 'P'; - dh = 'F'; - compare(); - if (flags.z()) - goto cupfromtapfull; - cx = 300; - al = 56; - showPuzText(); - putBackObStuff(); - return; -fillcupfromtap: - al = data.byte(kWithobject); - getExAd(); - es.byte(bx+15) = 'F'-'A'; - al = 8; - playChannel1(); - cx = 300; - al = 57; - showPuzText(); - putBackObStuff(); - return; -cupfromtapfull: - cx = 300; - al = 58; - showPuzText(); - putBackObStuff(); -} - -void DreamGenContext::notHeldError() { - STACK_CHECK; - createPanel(); - showPanel(); - showMan(); - showExit(); - obIcons(); - di = 64; - bx = 100; - al = 63; - ah = 1; - dl = 201; - printmessage2(); - workToScreenM(); - cx = 50; - hangOnP(); - putBackObStuff(); -} - -void DreamGenContext::usePipe() { - STACK_CHECK; - _cmp(data.byte(kWithobject), 255); - if (!flags.z()) - goto pipewith; - withWhat(); - return; -pipewith: - al = data.byte(kWithobject); - ah = data.byte(kWithtype); - cl = 'C'; - ch = 'U'; - dl = 'P'; - dh = 'E'; - compare(); - if (flags.z()) - goto fillcup; - al = data.byte(kWithobject); - ah = data.byte(kWithtype); - cl = 'C'; - ch = 'U'; - dl = 'P'; - dh = 'F'; - compare(); - if (flags.z()) - goto alreadyfull; - cx = 300; - al = 14; - showPuzText(); - putBackObStuff(); - return; -fillcup: - cx = 300; - al = 36; - showPuzText(); - putBackObStuff(); - al = data.byte(kWithobject); - getExAd(); - es.byte(bx+15) = 'F'-'A'; - return; -alreadyfull: - cx = 300; - al = 35; - showPuzText(); - putBackObStuff(); -} - -void DreamGenContext::useSLab() { - STACK_CHECK; - _cmp(data.byte(kWithobject), 255); - if (!flags.z()) - goto slabwith; - withWhat(); - return; -slabwith: - al = data.byte(kWithobject); - ah = data.byte(kWithtype); - cl = 'J'; - ch = 'E'; - dl = 'W'; - dh = 'L'; - compare(); - if (flags.z()) - goto nextslab; - cx = 300; - al = 14; - showPuzText(); - putBackObStuff(); - return; -nextslab: - al = data.byte(kWithobject); - getExAd(); - es.byte(bx+2) = 0; - al = data.byte(kCommand); - push(ax); - removeSetObject(); - ax = pop(); - _inc(al); - push(ax); - placeSetObject(); - ax = pop(); - _cmp(al, 54); - if (!flags.z()) - goto notlastslab; - al = 0; - turnPathOn(); - data.word(kWatchingtime) = 22; - data.word(kReeltowatch) = 35; - data.word(kEndwatchreel) = 48; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; -notlastslab: - _inc(data.byte(kProgresspoints)); - showFirstUse(); - data.byte(kGetback) = 1; -} - -void DreamGenContext::useOpenBox() { - STACK_CHECK; - _cmp(data.byte(kWithobject), 255); - if (!flags.z()) - goto openboxwith; - withWhat(); - return; -openboxwith: - al = data.byte(kWithobject); - ah = data.byte(kWithtype); - cl = 'C'; - ch = 'U'; - dl = 'P'; - dh = 'F'; - compare(); - if (flags.z()) - goto destoryopenbox; - al = data.byte(kWithobject); - ah = data.byte(kWithtype); - cl = 'C'; - ch = 'U'; - dl = 'P'; - dh = 'E'; - compare(); - if (flags.z()) - goto openboxwrong; - showFirstUse(); - return; -destoryopenbox: - _inc(data.byte(kProgresspoints)); - cx = 300; - al = 37; - showPuzText(); - al = data.byte(kWithobject); - getExAd(); - es.byte(bx+15) = 'E'-'A'; - data.word(kWatchingtime) = 140; - data.word(kReeltowatch) = 105; - data.word(kEndwatchreel) = 181; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - al = 4; - turnPathOn(); - data.byte(kGetback) = 1; - return; -openboxwrong: - cx = 300; - al = 38; - showPuzText(); - putBackObStuff(); -} - -void DreamGenContext::useAltar() { - STACK_CHECK; - al = 'C'; - ah = 'N'; - cl = 'D'; - ch = 'A'; - findExObject(); - _cmp(al, (114)); - if (flags.z()) - goto thingsonaltar; - al = 'C'; - ah = 'N'; - cl = 'D'; - ch = 'B'; - findExObject(); - _cmp(al, (114)); - if (flags.z()) - goto thingsonaltar; - _cmp(data.byte(kCanmovealtar), 1); - if (flags.z()) - goto movealtar; - cx = 300; - al = 23; - showPuzText(); - data.byte(kGetback) = 1; - return; -movealtar: - _inc(data.byte(kProgresspoints)); - showSecondUse(); - data.word(kWatchingtime) = 160; - data.word(kReeltowatch) = 81; - data.word(kEndwatchreel) = 174; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - al = 47; - bl = 52; - bh = 76; - cx = 32; - dx = 98; - setupTimedUse(); - data.byte(kGetback) = 1; - return; -thingsonaltar: - showFirstUse(); - data.byte(kGetback) = 1; -} - -void DreamGenContext::nextColon() { - STACK_CHECK; -lookcolon: - al = es.byte(si); - _inc(si); - _cmp(al, ':'); - if (!flags.z()) - goto lookcolon; -} - -void DreamGenContext::drawItAll() { - STACK_CHECK; - createPanel(); - drawFloor(); - printSprites(); - showIcon(); -} - -void DreamGenContext::useCashCard() { - STACK_CHECK; - getRidOfReels(); - loadKeypad(); - createPanel(); - showPanel(); - showExit(); - showMan(); - di = 114; - bx = 120; - _cmp(data.byte(kForeignrelease), 0); - if (flags.z()) - goto _tmp1; - bx = 120-3; -_tmp1: - ds = data.word(kTempgraphics); - al = 39; - ah = 0; - showFrame(); - ax = data.word(kCard1money); - moneyPoke(); - getObTextStart(); - nextColon(); - nextColon(); - di = 36; - bx = 98; - dl = 241; - al = 0; - ah = 0; - printDirect(); - di = 160; - bx = 155; - es = cs; - si = offset_money1poke; - data.word(kCharshift) = 91*2+75; - al = 0; - ah = 0; - dl = 240; - printDirect(); - di = 187; - bx = 155; - es = cs; - si = offset_money2poke; - data.word(kCharshift) = 91*2+85; - al = 0; - ah = 0; - dl = 240; - printDirect(); - data.word(kCharshift) = 0; - workToScreenM(); - cx = 400; - hangOnP(); - getRidOfTemp(); - restoreReels(); - putBackObStuff(); -} - -void DreamGenContext::lookAtCard() { - STACK_CHECK; - data.byte(kManisoffscreen) = 1; - getRidOfReels(); - loadKeypad(); - createPanel2(); - di = 160; - bx = 80; - ds = data.word(kTempgraphics); - al = 42; - ah = 128; - showFrame(); - getObTextStart(); - findNextColon(); - findNextColon(); - findNextColon(); - di = 36; - bx = 124; - dl = 241; - al = 0; - ah = 0; - printDirect(); - push(es); - push(si); - workToScreenM(); - cx = 280; - hangOnW(); - createPanel2(); - di = 160; - bx = 80; - ds = data.word(kTempgraphics); - al = 42; - ah = 128; - showFrame(); - si = pop(); - es = pop(); - di = 36; - bx = 130; - dl = 241; - al = 0; - ah = 0; - printDirect(); - workToScreenM(); - cx = 200; - hangOnW(); - data.byte(kManisoffscreen) = 0; - getRidOfTemp(); - restoreReels(); - putBackObStuff(); -} - -void DreamGenContext::moneyPoke() { - STACK_CHECK; - bx = offset_money1poke; - cl = 48-1; -numberpoke0: - _inc(cl); - _sub(ax, 10000); - if (!flags.c()) - goto numberpoke0; - _add(ax, 10000); - cs.byte(bx) = cl; - _inc(bx); - cl = 48-1; -numberpoke1: - _inc(cl); - _sub(ax, 1000); - if (!flags.c()) - goto numberpoke1; - _add(ax, 1000); - cs.byte(bx) = cl; - _inc(bx); - cl = 48-1; -numberpoke2: - _inc(cl); - _sub(ax, 100); - if (!flags.c()) - goto numberpoke2; - _add(ax, 100); - cs.byte(bx) = cl; - _inc(bx); - cl = 48-1; -numberpoke3: - _inc(cl); - _sub(ax, 10); - if (!flags.c()) - goto numberpoke3; - _add(ax, 10); - cs.byte(bx) = cl; - bx = offset_money2poke; - _add(al, 48); - cs.byte(bx) = al; -} - -void DreamGenContext::useControl() { - STACK_CHECK; - _cmp(data.byte(kWithobject), 255); - if (!flags.z()) - goto gotcontrolwith; - withWhat(); - return; -gotcontrolwith: - al = data.byte(kWithobject); - ah = data.byte(kWithtype); - cl = 'K'; - ch = 'E'; - dl = 'Y'; - dh = 'A'; - compare(); - if (flags.z()) - goto rightkey; - _cmp(data.byte(kReallocation), 21); - if (!flags.z()) - goto balls; - al = data.byte(kWithobject); - ah = data.byte(kWithtype); - cl = 'K'; - ch = 'N'; - dl = 'F'; - dh = 'E'; - compare(); - if (flags.z()) - goto jimmycontrols; - al = data.byte(kWithobject); - ah = data.byte(kWithtype); - cl = 'A'; - ch = 'X'; - dl = 'E'; - dh = 'D'; - compare(); - if (flags.z()) - goto axeoncontrols; -balls: - showFirstUse(); - putBackObStuff(); - return; -rightkey: - al = 16; - playChannel1(); - _cmp(data.byte(kLocation), 21); - if (flags.z()) - goto goingdown; - cx = 300; - al = 0; - showPuzText(); - data.byte(kNewlocation) = 21; - data.byte(kCounttoclose) = 8; - data.byte(kCounttoopen) = 0; - data.word(kWatchingtime) = 80; - data.byte(kGetback) = 1; - return; -goingdown: - cx = 300; - al = 3; - showPuzText(); - data.byte(kNewlocation) = 30; - data.byte(kCounttoclose) = 8; - data.byte(kCounttoopen) = 0; - data.word(kWatchingtime) = 80; - data.byte(kGetback) = 1; - return; -jimmycontrols: - al = 50; - placeSetObject(); - al = 51; - placeSetObject(); - al = 26; - placeSetObject(); - al = 30; - placeSetObject(); - al = 16; - removeSetObject(); - al = 17; - removeSetObject(); - al = 14; - playChannel1(); - cx = 300; - al = 10; - showPuzText(); - _inc(data.byte(kProgresspoints)); - data.byte(kGetback) = 1; - return; -axeoncontrols: - cx = 300; - al = 16; - showPuzText(); - _inc(data.byte(kProgresspoints)); - putBackObStuff(); -} - -void DreamGenContext::useHandle() { - STACK_CHECK; - al = 'C'; - ah = 'U'; - cl = 'T'; - ch = 'W'; - findSetObject(); - al = es.byte(bx+58); - _cmp(al, 255); - if (!flags.z()) - goto havecutwire; - cx = 300; - al = 12; - showPuzText(); - data.byte(kGetback) = 1; - return; -havecutwire: - cx = 300; - al = 13; - showPuzText(); - data.byte(kNewlocation) = 22; - data.byte(kGetback) = 1; -} - -void DreamGenContext::useKey() { - STACK_CHECK; - _cmp(data.byte(kLocation), 5); - if (flags.z()) - goto usekey1; - _cmp(data.byte(kLocation), 30); - if (flags.z()) - goto usekey1; - _cmp(data.byte(kLocation), 21); - if (flags.z()) - goto usekey2; - cx = 200; - al = 1; - showPuzText(); - putBackObStuff(); - return; -usekey1: - _cmp(data.byte(kMapx), 22); - if (!flags.z()) - goto wrongroom1; - _cmp(data.byte(kMapy), 10); - if (!flags.z()) - goto wrongroom1; - cx = 300; - al = 0; - showPuzText(); - data.byte(kCounttoclose) = 100; - data.byte(kGetback) = 1; - return; -usekey2: - _cmp(data.byte(kMapx), 11); - if (!flags.z()) - goto wrongroom1; - _cmp(data.byte(kMapy), 10); - if (!flags.z()) - goto wrongroom1; - cx = 300; - al = 3; - showPuzText(); - data.byte(kNewlocation) = 30; - al = 2; - fadeScreenDown(); - showFirstUse(); - putBackObStuff(); - return; -wrongroom1: - cx = 200; - al = 2; - showPuzText(); - putBackObStuff(); -} - -void DreamGenContext::useStereo() { - STACK_CHECK; - _cmp(data.byte(kLocation), 0); - if (flags.z()) - goto stereook; - cx = 400; - al = 4; - showPuzText(); - putBackObStuff(); - return; -stereook: - _cmp(data.byte(kMapx), 11); - if (!flags.z()) - goto stereonotok; - _cmp(data.byte(kMapy), 0); - if (flags.z()) - goto stereook2; -stereonotok: - cx = 400; - al = 5; - showPuzText(); - putBackObStuff(); - return; -stereook2: - al = 'C'; - ah = 'D'; - cl = 'P'; - ch = 'L'; - findSetObject(); - ah = 1; - checkInside(); - _cmp(cl, (114)); - if (!flags.z()) - goto cdinside; - al = 6; - cx = 400; - showPuzText(); - putBackObStuff(); - getAnyAd(); - al = 255; - es.byte(bx+10) = al; - return; -cdinside: - getAnyAd(); - al = es.byte(bx+10); - _xor(al, 1); - es.byte(bx+10) = al; - _cmp(al, 255); - if (flags.z()) - goto stereoon; - al = 7; - cx = 400; - showPuzText(); - putBackObStuff(); - return; -stereoon: - al = 8; - cx = 400; - showPuzText(); - putBackObStuff(); -} - -void DreamGenContext::useAxe() { - STACK_CHECK; - _cmp(data.byte(kReallocation), 22); - if (!flags.z()) - goto notinpool; - _cmp(data.byte(kMapy), 10); - if (flags.z()) - goto axeondoor; - showSecondUse(); - _inc(data.byte(kProgresspoints)); - data.byte(kLastweapon) = 2; - data.byte(kGetback) = 1; - removeObFromInv(); - return; -notinpool: - showFirstUse(); - return; -/*continuing to unbounded code: axeondoor from useelvdoor:19-30*/ -axeondoor: - al = 15; - cx = 300; - showPuzText(); - _inc(data.byte(kProgresspoints)); - data.word(kWatchingtime) = 46*2; - data.word(kReeltowatch) = 31; - data.word(kEndwatchreel) = 77; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; -} - -void DreamGenContext::withWhat() { - STACK_CHECK; - createPanel(); - showPanel(); - showMan(); - showExit(); - al = data.byte(kCommand); - ah = data.byte(kObjecttype); - es = cs; - di = offset_commandline; - copyName(); - di = 100; - bx = 21; - dl = 200; - al = 63; - ah = 2; - printmessage2(); - di = data.word(kLastxpos); - _add(di, 5); - bx = 21; - es = cs; - si = offset_commandline; - dl = 220; - al = 0; - ah = 0; - printDirect(); - di = data.word(kLastxpos); - _add(di, 5); - bx = 21; - dl = 200; - al = 63; - ah = 3; - printmessage2(); - fillRyan(); - data.byte(kCommandtype) = 255; - readMouse(); - showPointer(); - workToScreen(); - delPointer(); - data.byte(kInvopen) = 2; -} - -void DreamGenContext::selectOb() { - STACK_CHECK; - findInvPos(); - ax = es.word(bx); - _cmp(al, 255); - if (!flags.z()) - goto canselectob; - blank(); - return; -canselectob: - data.byte(kWithobject) = al; - data.byte(kWithtype) = ah; - _cmp(ax, data.word(kOldsubject)); - if (!flags.z()) - goto diffsub3; - _cmp(data.byte(kCommandtype), 221); - if (flags.z()) - goto alreadyselob; - data.byte(kCommandtype) = 221; -diffsub3: - data.word(kOldsubject) = ax; - bx = ax; - al = 0; - commandWithOb(); -alreadyselob: - ax = data.word(kMousebutton); - _cmp(ax, data.word(kOldbutton)); - if (flags.z()) - return /* (notselob) */; - _and(ax, 1); - if (!flags.z()) - goto doselob; - return; -doselob: - delPointer(); - data.byte(kInvopen) = 0; - useRoutine(); -} - -void DreamGenContext::findSetObject() { - STACK_CHECK; - _sub(al, 'A'); - _sub(ah, 'A'); - _sub(cl, 'A'); - _sub(ch, 'A'); - es = data.word(kSetdat); - bx = 0; - dl = 0; -findsetloop: - _cmp(al, es.byte(bx+12)); - if (!flags.z()) - goto nofind; - _cmp(ah, es.byte(bx+13)); - if (!flags.z()) - goto nofind; - _cmp(cl, es.byte(bx+14)); - if (!flags.z()) - goto nofind; - _cmp(ch, es.byte(bx+15)); - if (!flags.z()) - goto nofind; - al = dl; - return; -nofind: - _add(bx, 64); - _inc(dl); - _cmp(dl, 128); - if (!flags.z()) - goto findsetloop; - al = dl; -} - -void DreamGenContext::findExObject() { - STACK_CHECK; - _sub(al, 'A'); - _sub(ah, 'A'); - _sub(cl, 'A'); - _sub(ch, 'A'); - es = data.word(kExtras); - bx = (0+2080+30000); - dl = 0; -findexloop: - _cmp(al, es.byte(bx+12)); - if (!flags.z()) - goto nofindex; - _cmp(ah, es.byte(bx+13)); - if (!flags.z()) - goto nofindex; - _cmp(cl, es.byte(bx+14)); - if (!flags.z()) - goto nofindex; - _cmp(ch, es.byte(bx+15)); - if (!flags.z()) - goto nofindex; - al = dl; - return; -nofindex: - _add(bx, 16); - _inc(dl); - _cmp(dl, (114)); - if (!flags.z()) - goto findexloop; - al = dl; -} - -void DreamGenContext::isRyanHolding() { - STACK_CHECK; - _sub(al, 'A'); - _sub(ah, 'A'); - _sub(cl, 'A'); - _sub(ch, 'A'); - es = data.word(kExtras); - bx = (0+2080+30000); - dl = 0; -searchinv: - _cmp(es.byte(bx+2), 4); - if (!flags.z()) - goto nofindininv; - _cmp(al, es.byte(bx+12)); - if (!flags.z()) - goto nofindininv; - _cmp(ah, es.byte(bx+13)); - if (!flags.z()) - goto nofindininv; - _cmp(cl, es.byte(bx+14)); - if (!flags.z()) - goto nofindininv; - _cmp(ch, es.byte(bx+15)); - if (!flags.z()) - goto nofindininv; - al = dl; - _cmp(al, (114)); - return; -nofindininv: - _add(bx, 16); - _inc(dl); - _cmp(dl, (114)); - if (!flags.z()) - goto searchinv; - al = dl; - _cmp(al, (114)); -} - -void DreamGenContext::checkInside() { - STACK_CHECK; - es = data.word(kExtras); - bx = (0+2080+30000); - cl = 0; -insideloop: - _cmp(al, es.byte(bx+3)); - if (!flags.z()) - goto notfoundinside; - _cmp(ah, es.byte(bx+2)); - if (!flags.z()) - goto notfoundinside; - return; -notfoundinside: - _add(bx, 16); - _inc(cl); - _cmp(cl, (114)); - if (!flags.z()) - goto insideloop; -} - -void DreamGenContext::findPuzText() { - STACK_CHECK; - ah = 0; - si = ax; - _add(si, si); - es = data.word(kPuzzletext); - ax = es.word(si); - _add(ax, (66*2)); - si = ax; -} - -void DreamGenContext::removeFreeObject() { - STACK_CHECK; - push(es); - push(bx); - getFreeAd(); - es.byte(bx+2) = 255; - bx = pop(); - es = pop(); -} - -void DreamGenContext::setupTimedUse() { - STACK_CHECK; - _cmp(data.word(kTimecount), 0); - if (!flags.z()) - return /* (cantsetup) */; - data.byte(kTimedy) = bh; - data.byte(kTimedx) = bl; - data.word(kCounttotimed) = cx; - _add(dx, cx); - data.word(kTimecount) = dx; - bl = al; - bh = 0; - _add(bx, bx); - es = data.word(kPuzzletext); - cx = (66*2); - ax = es.word(bx); - _add(ax, cx); - bx = ax; - data.word(kTimedseg) = es; - data.word(kTimedoffset) = bx; -} - -void DreamGenContext::useGun() { - STACK_CHECK; - _cmp(data.byte(kObjecttype), 4); - if (flags.z()) - goto istakengun; - showSecondUse(); - putBackObStuff(); - return; -istakengun: - _cmp(data.byte(kReallocation), 22); - if (!flags.z()) - goto notinpoolroom; - cx = 300; - al = 34; - showPuzText(); - data.byte(kLastweapon) = 1; - data.byte(kCombatcount) = 39; - data.byte(kGetback) = 1; - _inc(data.byte(kProgresspoints)); - return; -notinpoolroom: - _cmp(data.byte(kReallocation), 25); - if (!flags.z()) - goto nothelicopter; - cx = 300; - al = 34; - showPuzText(); - data.byte(kLastweapon) = 1; - data.byte(kCombatcount) = 19; - data.byte(kGetback) = 1; - data.byte(kDreamnumber) = 2; - data.byte(kRoomafterdream) = 38; - data.byte(kSartaindead) = 1; - _inc(data.byte(kProgresspoints)); - return; -nothelicopter: - _cmp(data.byte(kReallocation), 27); - if (!flags.z()) - goto notinrockroom; - cx = 300; - al = 46; - showPuzText(); - data.byte(kPointermode) = 2; - data.byte(kRockstardead) = 1; - data.byte(kLastweapon) = 1; - data.byte(kNewsitem) = 1; - data.byte(kGetback) = 1; - data.byte(kRoomafterdream) = 32; - data.byte(kDreamnumber) = 0; - _inc(data.byte(kProgresspoints)); - return; -notinrockroom: - _cmp(data.byte(kReallocation), 8); - if (!flags.z()) - goto notbystudio; - _cmp(data.byte(kMapx), 22); - if (!flags.z()) - goto notbystudio; - _cmp(data.byte(kMapy), 40); - if (!flags.z()) - goto notbystudio; - al = 92; - isSetObOnMap(); - if (flags.z()) - goto notbystudio; - _cmp(data.byte(kManspath), 9); - if (flags.z()) - goto notbystudio; - data.byte(kDestination) = 9; - data.byte(kFinaldest) = 9; - autoSetWalk(); - data.byte(kLastweapon) = 1; - data.byte(kGetback) = 1; - _inc(data.byte(kProgresspoints)); - return; -notbystudio: - _cmp(data.byte(kReallocation), 6); - if (!flags.z()) - goto notsarters; - _cmp(data.byte(kMapx), 11); - if (!flags.z()) - goto notsarters; - _cmp(data.byte(kMapy), 20); - if (!flags.z()) - goto notsarters; - al = 5; - isSetObOnMap(); - if (!flags.z()) - goto notsarters; - data.byte(kDestination) = 1; - data.byte(kFinaldest) = 1; - autoSetWalk(); - al = 5; - removeSetObject(); - al = 6; - placeSetObject(); - al = 1; - ah = data.byte(kRoomnum); - _dec(ah); - turnAnyPathOn(); - data.byte(kLiftflag) = 1; - data.word(kWatchingtime) = 40*2; - data.word(kReeltowatch) = 4; - data.word(kEndwatchreel) = 43; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; - _inc(data.byte(kProgresspoints)); - return; -notsarters: - _cmp(data.byte(kReallocation), 29); - if (!flags.z()) - goto notaide; - data.byte(kGetback) = 1; - al = 13; - resetLocation(); - al = 12; - setLocation(); - data.byte(kDestpos) = 12; - data.byte(kDestination) = 2; - data.byte(kFinaldest) = 2; - autoSetWalk(); - data.word(kWatchingtime) = 164*2; - data.word(kReeltowatch) = 3; - data.word(kEndwatchreel) = 164; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kAidedead) = 1; - data.byte(kDreamnumber) = 3; - data.byte(kRoomafterdream) = 33; - _inc(data.byte(kProgresspoints)); - return; -notaide: - _cmp(data.byte(kReallocation), 23); - if (!flags.z()) - goto notwithboss; - _cmp(data.byte(kMapx), 0); - if (!flags.z()) - goto notwithboss; - _cmp(data.byte(kMapy), 50); - if (!flags.z()) - goto notwithboss; - _cmp(data.byte(kManspath), 5); - if (flags.z()) - goto pathokboss; - data.byte(kDestination) = 5; - data.byte(kFinaldest) = 5; - autoSetWalk(); -pathokboss: - data.byte(kLastweapon) = 1; - data.byte(kGetback) = 1; - return; -notwithboss: - _cmp(data.byte(kReallocation), 8); - if (!flags.z()) - goto nottvsoldier; - _cmp(data.byte(kMapx), 11); - if (!flags.z()) - goto nottvsoldier; - _cmp(data.byte(kMapy), 10); - if (!flags.z()) - goto nottvsoldier; - _cmp(data.byte(kManspath), 2); - if (flags.z()) - goto pathoktv; - data.byte(kDestination) = 2; - data.byte(kFinaldest) = 2; - autoSetWalk(); -pathoktv: - data.byte(kLastweapon) = 1; - data.byte(kGetback) = 1; - return; -nottvsoldier: - showFirstUse(); - putBackObStuff(); -} - -void DreamGenContext::updateSymbolTop() { - STACK_CHECK; - _cmp(data.byte(kSymboltopdir), 0); - if (flags.z()) - return /* (topfinished) */; - _cmp(data.byte(kSymboltopdir), -1); - if (flags.z()) - goto backwards; - _inc(data.byte(kSymboltopx)); - _cmp(data.byte(kSymboltopx), 49); - if (!flags.z()) - goto notwrapfor; - data.byte(kSymboltopx) = 0; - _dec(data.byte(kSymboltopnum)); - _cmp(data.byte(kSymboltopnum), -1); - if (!flags.z()) - return /* (topfinished) */; - data.byte(kSymboltopnum) = 5; - return; -notwrapfor: - _cmp(data.byte(kSymboltopx), 24); - if (!flags.z()) - return /* (topfinished) */; - data.byte(kSymboltopdir) = 0; - return; -backwards: - _dec(data.byte(kSymboltopx)); - _cmp(data.byte(kSymboltopx), -1); - if (!flags.z()) - goto notwrapback; - data.byte(kSymboltopx) = 48; - _inc(data.byte(kSymboltopnum)); - _cmp(data.byte(kSymboltopnum), 6); - if (!flags.z()) - return /* (topfinished) */; - data.byte(kSymboltopnum) = 0; - return; -notwrapback: - _cmp(data.byte(kSymboltopx), 24); - if (!flags.z()) - return /* (topfinished) */; - data.byte(kSymboltopdir) = 0; -} - -void DreamGenContext::updateSymbolBot() { - STACK_CHECK; - _cmp(data.byte(kSymbolbotdir), 0); - if (flags.z()) - return /* (botfinished) */; - _cmp(data.byte(kSymbolbotdir), -1); - if (flags.z()) - goto backwardsbot; - _inc(data.byte(kSymbolbotx)); - _cmp(data.byte(kSymbolbotx), 49); - if (!flags.z()) - goto notwrapforb; - data.byte(kSymbolbotx) = 0; - _dec(data.byte(kSymbolbotnum)); - _cmp(data.byte(kSymbolbotnum), -1); - if (!flags.z()) - return /* (botfinished) */; - data.byte(kSymbolbotnum) = 5; - return; -notwrapforb: - _cmp(data.byte(kSymbolbotx), 24); - if (!flags.z()) - return /* (botfinished) */; - data.byte(kSymbolbotdir) = 0; - return; -backwardsbot: - _dec(data.byte(kSymbolbotx)); - _cmp(data.byte(kSymbolbotx), -1); - if (!flags.z()) - goto notwrapbackb; - data.byte(kSymbolbotx) = 48; - _inc(data.byte(kSymbolbotnum)); - _cmp(data.byte(kSymbolbotnum), 6); - if (!flags.z()) - return /* (botfinished) */; - data.byte(kSymbolbotnum) = 0; - return; -notwrapbackb: - _cmp(data.byte(kSymbolbotx), 24); - if (!flags.z()) - return /* (botfinished) */; - data.byte(kSymbolbotdir) = 0; -} - -void DreamGenContext::showDiaryKeys() { - STACK_CHECK; - _cmp(data.byte(kPresscount), 0); - if (flags.z()) - return /* (nokeyatall) */; - _dec(data.byte(kPresscount)); - _cmp(data.byte(kPresscount), 0); - if (flags.z()) - return /* (nokeyatall) */; - _cmp(data.byte(kPressed), 'N'); - if (!flags.z()) - goto nokeyn; - al = 3; - _cmp(data.byte(kPresscount), 1); - if (flags.z()) - goto gotkeyn; - al = 4; -gotkeyn: - ah = 0; - di = (68+24)+94; - bx = (48+12)+97; - ds = data.word(kTempgraphics); - showFrame(); - _cmp(data.byte(kPresscount), 1); - if (!flags.z()) - return /* (notshown) */; - showDiaryPage(); - return; -nokeyn: - al = 5; - _cmp(data.byte(kPresscount), 1); - if (flags.z()) - goto gotkeyp; - al = 6; -gotkeyp: - ah = 0; - di = (68+24)+151; - bx = (48+12)+71; - ds = data.word(kTempgraphics); - showFrame(); - _cmp(data.byte(kPresscount), 1); - if (!flags.z()) - return /* (notshowp) */; - showDiaryPage(); -} - -void DreamGenContext::dumpDiaryKeys() { - STACK_CHECK; - _cmp(data.byte(kPresscount), 1); - if (!flags.z()) - goto notdumpdiary; - _cmp(data.byte(kSartaindead), 1); - if (flags.z()) - goto notsartadd; - _cmp(data.byte(kDiarypage), 5); - if (!flags.z()) - goto notsartadd; - _cmp(data.byte(kDiarypage), 5); - if (!flags.z()) - goto notsartadd; - al = 6; - getLocation(); - _cmp(al, 1); - if (flags.z()) - goto notsartadd; - al = 6; - setLocation(); - delPointer(); - al = 12; - findText1(); - di = 70; - bx = 106; - dl = 241; - ah = 16; - printDirect(); - workToScreenM(); - cx = 200; - hangOnP(); - createPanel(); - showIcon(); - showDiary(); - showDiaryPage(); - workToScreenM(); - showPointer(); - return; -notsartadd: - di = (68+24)+48; - bx = (48+12)+15; - cl = 200; - ch = 16; - multiDump(); -notdumpdiary: - di = (68+24)+94; - bx = (48+12)+97; - cl = 16; - ch = 16; - multiDump(); - di = (68+24)+151; - bx = (48+12)+71; - cl = 16; - ch = 16; - multiDump(); -} - -void DreamGenContext::showDiaryPage() { - STACK_CHECK; - al = 0; - ah = 0; - di = (68+24); - bx = (48+12); - ds = data.word(kTempgraphics); - showFrame(); - al = data.byte(kDiarypage); - findText1(); - data.byte(kKerning) = 1; - useTempCharset(); - di = (68+24)+48; - bx = (48+12)+16; - dl = 240; - ah = 16; - data.word(kCharshift) = 91+91; - printDirect(); - di = (68+24)+129; - bx = (48+12)+16; - dl = 240; - ah = 16; - printDirect(); - di = (68+24)+48; - bx = (48+12)+23; - dl = 240; - ah = 16; - printDirect(); - data.byte(kKerning) = 0; - data.word(kCharshift) = 0; - useCharset1(); -} - -void DreamGenContext::findText1() { - STACK_CHECK; - ah = 0; - si = ax; - _add(si, si); - es = data.word(kTextfile1); - ax = es.word(si); - _add(ax, (66*2)); - si = ax; -} - -void DreamGenContext::selectSlot() { - STACK_CHECK; - _cmp(data.byte(kCommandtype), 244); - if (flags.z()) - goto alreadysel; - data.byte(kCommandtype) = 244; - al = 45; - commandOnly(); -alreadysel: - ax = data.word(kMousebutton); - _cmp(ax, 1); - if (!flags.z()) - return /* (noselslot) */; - _cmp(ax, data.word(kOldbutton)); - if (flags.z()) - return /* (noselslot) */; - _cmp(data.byte(kLoadingorsave), 3); - if (!flags.z()) - goto notnocurs; - _dec(data.byte(kLoadingorsave)); -notnocurs: - oldToNames(); - ax = data.word(kMousey); - _sub(ax, (52)+4); - cl = -1; -getslotnum: - _inc(cl); - _sub(ax, 11); - if (!flags.c()) - goto getslotnum; - data.byte(kCurrentslot) = cl; - delPointer(); - showOpBox(); - showSlots(); - showNames(); - _cmp(data.byte(kLoadingorsave), 1); - if (flags.z()) - goto isloadmode; - showSaveOps(); - readMouse(); - showPointer(); - workToScreen(); - delPointer(); - return; -isloadmode: - showLoadOps(); - readMouse(); - showPointer(); - workToScreen(); - delPointer(); -} - -void DreamGenContext::showSlots() { - STACK_CHECK; - di = (60)+7; - bx = (52)+8; - al = 2; - ds = data.word(kTempgraphics); - ah = 0; - showFrame(); - di = (60)+10; - bx = (52)+11; - cl = 0; -slotloop: - push(cx); - push(di); - push(bx); - _cmp(cl, data.byte(kCurrentslot)); - if (!flags.z()) - goto nomatchslot; - al = 3; - ds = data.word(kTempgraphics); - ah = 0; - showFrame(); -nomatchslot: - bx = pop(); - di = pop(); - cx = pop(); - _add(bx, 10); - _inc(cl); - _cmp(cl, 7); - if (!flags.z()) - goto slotloop; -} - -void DreamGenContext::entryTexts() { - STACK_CHECK; - _cmp(data.byte(kLocation), 21); - if (!flags.z()) - goto notloc15; - al = 28; - cx = 60; - dx = 11; - bl = 68; - bh = 64; - setupTimedUse(); - return; -notloc15: - _cmp(data.byte(kLocation), 30); - if (!flags.z()) - goto notloc43; - al = 27; - cx = 60; - dx = 11; - bl = 68; - bh = 64; - setupTimedUse(); - return; -notloc43: - _cmp(data.byte(kLocation), 23); - if (!flags.z()) - goto notloc23; - al = 29; - cx = 60; - dx = 11; - bl = 68; - bh = 64; - setupTimedUse(); - return; -notloc23: - _cmp(data.byte(kLocation), 31); - if (!flags.z()) - goto notloc44; - al = 30; - cx = 60; - dx = 11; - bl = 68; - bh = 64; - setupTimedUse(); - return; -notloc44: - _cmp(data.byte(kLocation), 20); - if (!flags.z()) - goto notsarters2; - al = 31; - cx = 60; - dx = 11; - bl = 68; - bh = 64; - setupTimedUse(); - return; -notsarters2: - _cmp(data.byte(kLocation), 24); - if (!flags.z()) - goto notedenlob; - al = 32; - cx = 60; - dx = 3; - bl = 68; - bh = 64; - setupTimedUse(); - return; -notedenlob: - _cmp(data.byte(kLocation), 34); - if (!flags.z()) - return /* (noteden2) */; - al = 33; - cx = 60; - dx = 3; - bl = 68; - bh = 64; - setupTimedUse(); -} - -void DreamGenContext::entryAnims() { - STACK_CHECK; - data.word(kReeltowatch) = -1; - data.byte(kWatchmode) = -1; - _cmp(data.byte(kLocation), 33); - if (!flags.z()) - goto notinthebeach; - switchRyanOff(); - data.word(kWatchingtime) = 76*2; - data.word(kReeltowatch) = 0; - data.word(kEndwatchreel) = 76; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - return; -notinthebeach: - _cmp(data.byte(kLocation), 44); - if (!flags.z()) - goto notsparkys; - al = 8; - resetLocation(); - data.word(kWatchingtime) = 50*2; - data.word(kReeltowatch) = 247; - data.word(kEndwatchreel) = 297; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - switchRyanOff(); - return; -notsparkys: - _cmp(data.byte(kLocation), 22); - if (!flags.z()) - goto notinthelift; - data.word(kWatchingtime) = 31*2; - data.word(kReeltowatch) = 0; - data.word(kEndwatchreel) = 30; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - switchRyanOff(); - return; -notinthelift: - _cmp(data.byte(kLocation), 26); - if (!flags.z()) - goto notunderchurch; - data.byte(kSymboltopnum) = 2; - data.byte(kSymbolbotnum) = 1; - return; -notunderchurch: - _cmp(data.byte(kLocation), 45); - if (!flags.z()) - goto notenterdream; - data.byte(kKeeperflag) = 0; - data.word(kWatchingtime) = 296; - data.word(kReeltowatch) = 45; - data.word(kEndwatchreel) = 198; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - switchRyanOff(); - return; -notenterdream: - _cmp(data.byte(kReallocation), 46); - if (!flags.z()) - goto notcrystal; - _cmp(data.byte(kSartaindead), 1); - if (!flags.z()) - goto notcrystal; - al = 0; - removeFreeObject(); - return; -notcrystal: - _cmp(data.byte(kLocation), 9); - if (!flags.z()) - goto nottopchurch; - al = 2; - checkIfPathIsOn(); - if (flags.z()) - goto nottopchurch; - _cmp(data.byte(kAidedead), 0); - if (flags.z()) - goto nottopchurch; - al = 3; - checkIfPathIsOn(); - if (!flags.z()) - goto makedoorsopen; - al = 2; - turnPathOn(); -makedoorsopen: - al = 4; - removeSetObject(); - al = 5; - placeSetObject(); - return; -nottopchurch: - _cmp(data.byte(kLocation), 47); - if (!flags.z()) - goto notdreamcentre; - al = 4; - placeSetObject(); - al = 5; - placeSetObject(); - return; -notdreamcentre: - _cmp(data.byte(kLocation), 38); - if (!flags.z()) - goto notcarpark; - data.word(kWatchingtime) = 57*2; - data.word(kReeltowatch) = 4; - data.word(kEndwatchreel) = 57; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - switchRyanOff(); - return; -notcarpark: - _cmp(data.byte(kLocation), 32); - if (!flags.z()) - goto notalley; - data.word(kWatchingtime) = 66*2; - data.word(kReeltowatch) = 0; - data.word(kEndwatchreel) = 66; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - switchRyanOff(); - return; -notalley: - _cmp(data.byte(kLocation), 24); - if (!flags.z()) - return /* (notedensagain) */; - al = 2; - ah = data.byte(kRoomnum); - _dec(ah); - turnAnyPathOn(); -} - -void DreamGenContext::clearBuffers() { - STACK_CHECK; - es = data.word(kBuffers); - cx = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)+(5*80)+(250*4)+(256*30)+(6*64)+916-459+68-0)/2; - ax = 0; - di = 0; - _stosw(cx, true); - es = data.word(kExtras); - cx = (0+2080+30000+(16*114)+((114+2)*2)+18000)/2; - ax = 0x0ffff; - di = 0; - _stosw(cx, true); - es = data.word(kBuffers); - di = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)+(5*80)+(250*4)+(256*30)+(6*64)); - ds = cs; - si = 459; - cx = (916-459); - _movsb(cx, true); - es = data.word(kBuffers); - di = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)+(5*80)+(250*4)+(256*30)+(6*64)+916-459); - ds = cs; - si = 0; - cx = (68-0); - _movsb(cx, true); - clearChanges(); -} - -void DreamGenContext::clearChanges() { - STACK_CHECK; - es = data.word(kBuffers); - cx = (250)*2; - ax = 0x0ffff; - di = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)+(5*80)); - _stosw(cx, true); - ds = data.word(kBuffers); - si = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)+(5*80)+(250*4)+(256*30)+(6*64)); - es = cs; - di = 459; - cx = (916-459); - _movsb(cx, true); - ds = data.word(kBuffers); - si = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)+(5*80)+(250*4)+(256*30)+(6*64)+916-459); - es = cs; - di = 0; - cx = (68-0); - _movsb(cx, true); - data.byte(kExpos) = 0; - data.word(kExframepos) = 0; - data.word(kExtextpos) = 0; - es = data.word(kExtras); - cx = (0+2080+30000+(16*114)+((114+2)*2)+18000)/2; - ax = 0x0ffff; - di = 0; - _stosw(cx, true); - es = cs; - di = 1249; - al = 1; - _stosb(2); - al = 0; - _stosb(); - al = 1; - _stosb(); - ax = 0; - cx = 6; - _stosw(cx, true); -} - -void DreamGenContext::identifyOb() { - STACK_CHECK; - _cmp(data.word(kWatchingtime), 0); - if (!flags.z()) - { blank(); return; }; - ax = data.word(kMousex); - _sub(ax, data.word(kMapadx)); - _cmp(ax, 22*8); - if (flags.c()) - goto notover1; - blank(); - return; -notover1: - bx = data.word(kMousey); - _sub(bx, data.word(kMapady)); - _cmp(bx, 20*8); - if (flags.c()) - goto notover2; - blank(); - return; -notover2: - data.byte(kInmaparea) = 1; - ah = bl; - push(ax); - findPathOfPoint(); - data.byte(kPointerspath) = dl; - ax = pop(); - push(ax); - findFirstPath(); - data.byte(kPointerfirstpath) = al; - ax = pop(); - checkIfEx(); - if (!flags.z()) - return /* (finishidentify) */; - checkIfFree(); - if (!flags.z()) - return /* (finishidentify) */; - checkIfPerson(); - if (!flags.z()) - return /* (finishidentify) */; - checkIfSet(); - if (!flags.z()) - return /* (finishidentify) */; - ax = data.word(kMousex); - _sub(ax, data.word(kMapadx)); - cl = al; - ax = data.word(kMousey); - _sub(ax, data.word(kMapady)); - ch = al; - checkOne(); - _cmp(al, 0); - if (flags.z()) - goto nothingund; - _cmp(data.byte(kMandead), 1); - if (flags.z()) - goto nothingund; - ah = 3; - obName(); - return; -nothingund: - blank(); -} - -void DreamGenContext::findPathOfPoint() { - STACK_CHECK; - push(ax); - bx = (0); - es = data.word(kReels); - al = data.byte(kRoomnum); - ah = 0; - cx = 144; - _mul(cx); - _add(bx, ax); - cx = pop(); - dl = 0; -pathloop: - al = es.byte(bx+6); - _cmp(al, 255); - if (!flags.z()) - goto flunkedit; - ax = es.word(bx+2); - _cmp(ax, 0x0ffff); - if (flags.z()) - goto flunkedit; - _cmp(cl, al); - if (flags.c()) - goto flunkedit; - _cmp(ch, ah); - if (flags.c()) - goto flunkedit; - ax = es.word(bx+4); - _cmp(cl, al); - if (!flags.c()) - goto flunkedit; - _cmp(ch, ah); - if (!flags.c()) - goto flunkedit; - return /* (gotvalidpath) */; -flunkedit: - _add(bx, 8); - _inc(dl); - _cmp(dl, 12); - if (!flags.z()) - goto pathloop; - dl = 255; -} - -void DreamGenContext::findFirstPath() { - STACK_CHECK; - push(ax); - bx = (0); - es = data.word(kReels); - al = data.byte(kRoomnum); - ah = 0; - cx = 144; - _mul(cx); - _add(bx, ax); - cx = pop(); - dl = 0; -fpathloop: - ax = es.word(bx+2); - _cmp(ax, 0x0ffff); - if (flags.z()) - goto nofirst; - _cmp(cl, al); - if (flags.c()) - goto nofirst; - _cmp(ch, ah); - if (flags.c()) - goto nofirst; - ax = es.word(bx+4); - _cmp(cl, al); - if (!flags.c()) - goto nofirst; - _cmp(ch, ah); - if (!flags.c()) - goto nofirst; - goto gotfirst; -nofirst: - _add(bx, 8); - _inc(dl); - _cmp(dl, 12); - if (!flags.z()) - goto fpathloop; - al = 0; - return; -gotfirst: - al = es.byte(bx+6); -} - -void DreamGenContext::printmessage2() { - STACK_CHECK; - push(dx); - push(bx); - push(di); - push(ax); - ah = 0; - _add(ax, ax); - bx = ax; - es = data.word(kCommandtext); - ax = es.word(bx); - _add(ax, (66*2)); - si = ax; - ax = pop(); -searchmess: - push(ax); - findNextColon(); - ax = pop(); - _dec(ah); - if (!flags.z()) - goto searchmess; - di = pop(); - bx = pop(); - dx = pop(); - al = 0; - ah = 0; - printDirect(); -} - -void DreamGenContext::__start() { - static const uint8 src[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x13, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0000: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, - //0x0010: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0020: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x00, 0x00, 0x00, 0xff, 0x00, - //0x0030: .... .... .... .... - 0xff, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x0d, 0x00, 0xb6, - //0x0040: ...0 .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0050: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0060: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0070: .... ...h .&.. .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0080: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0090: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x00a0: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x00b0: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x00c0: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x00d0: .... .... .... .... - 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x00e0: .. .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x00f0: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0100: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0110: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0120: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0130: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0140: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0150: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0160: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, - //0x0170: .... .... .... .... - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - //0x0180: .... .... .... .... - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - //0x0190: .... .... .... .... - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x01a0: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x01b0: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x01, 0x2c, 0x00, 0x14, 0x00, - //0x01c0: .... .... .... ,... - 0x02, 0x00, 0x01, 0x01, 0x37, 0x00, 0x00, 0x00, 0x32, 0x14, 0x00, 0x18, 0x16, 0x00, 0x4a, 0x00, - //0x01d0: .... 7... 2... ..J. - 0x01, 0x00, 0x00, 0x18, 0x21, 0x0a, 0x4b, 0x00, 0x01, 0x00, 0x01, 0x01, 0x2c, 0x00, 0x1b, 0x00, - //0x01e0: .... !.K. .... ,... - 0x02, 0x00, 0x02, 0x01, 0x2c, 0x00, 0x60, 0x00, 0x03, 0x00, 0x04, 0x01, 0x2c, 0x00, 0x76, 0x00, - //0x01f0: .... ,.`. .... ,.v. - 0x02, 0x00, 0x05, 0x01, 0x2c, 0x0a, 0x00, 0x00, 0x02, 0x00, 0x00, 0x05, 0x16, 0x14, 0x35, 0x00, - //0x0200: .... ,... .... ..5. - 0x03, 0x00, 0x00, 0x05, 0x16, 0x14, 0x28, 0x00, 0x01, 0x00, 0x02, 0x05, 0x16, 0x14, 0x32, 0x00, - //0x0210: .... ..(. .... ..2. - 0x01, 0x00, 0x03, 0x02, 0x0b, 0x0a, 0xc0, 0x00, 0x01, 0x00, 0x00, 0x02, 0x0b, 0x0a, 0xb6, 0x00, - //0x0220: .... .... .... .... - 0x02, 0x00, 0x01, 0x08, 0x0b, 0x0a, 0x00, 0x00, 0x02, 0x00, 0x01, 0x17, 0x00, 0x32, 0x00, 0x00, - //0x0230: .... .... .... .2.. - 0x03, 0x00, 0x00, 0x1c, 0x0b, 0x14, 0xfa, 0x00, 0x04, 0x00, 0x00, 0x17, 0x00, 0x32, 0x2b, 0x00, - //0x0240: .... .... .... .2+. - 0x02, 0x00, 0x08, 0x17, 0x0b, 0x28, 0x82, 0x00, 0x02, 0x00, 0x01, 0x17, 0x16, 0x28, 0x7a, 0x00, - //0x0250: .... .(.. .... .(z. - 0x02, 0x00, 0x02, 0x17, 0x16, 0x28, 0x69, 0x00, 0x02, 0x00, 0x03, 0x17, 0x16, 0x28, 0x51, 0x00, - //0x0260: .... .(i. .... .(Q. - 0x02, 0x00, 0x04, 0x17, 0x0b, 0x28, 0x87, 0x00, 0x02, 0x00, 0x05, 0x17, 0x16, 0x28, 0x91, 0x00, - //0x0270: .... .(.. .... .(.. - 0x02, 0x00, 0x06, 0x04, 0x16, 0x1e, 0x00, 0x00, 0x02, 0x00, 0x00, 0x2d, 0x16, 0x1e, 0xc8, 0x00, - //0x0280: .... .... ...- .... - 0x00, 0x00, 0x14, 0x2d, 0x16, 0x1e, 0x27, 0x00, 0x02, 0x00, 0x00, 0x2d, 0x16, 0x1e, 0x19, 0x00, - //0x0290: ...- ..'. ...- .... - 0x02, 0x00, 0x00, 0x08, 0x16, 0x28, 0x20, 0x00, 0x02, 0x00, 0x00, 0x07, 0x0b, 0x14, 0x40, 0x00, - //0x02a0: .... .( . .... ..@. - 0x02, 0x00, 0x00, 0x16, 0x16, 0x14, 0x52, 0x00, 0x02, 0x00, 0x00, 0x1b, 0x0b, 0x1e, 0x00, 0x00, - //0x02b0: .... ..R. .... .... - 0x02, 0x00, 0x00, 0x14, 0x00, 0x1e, 0x00, 0x00, 0x02, 0x00, 0x00, 0x0e, 0x21, 0x28, 0x15, 0x00, - //0x02c0: .... .... .... !(.. - 0x01, 0x00, 0x00, 0x1d, 0x0b, 0x0a, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x16, 0x00, 0x02, 0x00, - //0x02d0: .... .... .... .... - 0x02, 0x00, 0x00, 0x19, 0x00, 0x32, 0x04, 0x00, 0x02, 0x00, 0x00, 0x32, 0x16, 0x1e, 0x79, 0x00, - //0x02e0: .... .2.. ...2 ..y. - 0x02, 0x00, 0x00, 0x32, 0x16, 0x1e, 0x00, 0x00, 0x14, 0x00, 0x00, 0x34, 0x16, 0x1e, 0xc0, 0x00, - //0x02f0: ...2 .... ...4 .... - 0x02, 0x00, 0x00, 0x34, 0x16, 0x1e, 0xe9, 0x00, 0x02, 0x00, 0x00, 0x32, 0x16, 0x28, 0x68, 0x00, - //0x0300: ...4 .... ...2 .(h. - 0x37, 0x00, 0x00, 0x35, 0x21, 0x00, 0x63, 0x00, 0x02, 0x00, 0x00, 0x32, 0x16, 0x28, 0x00, 0x00, - //0x0310: 7..5 !.c. ...2 .(.. - 0x03, 0x00, 0x00, 0x32, 0x16, 0x1e, 0xa2, 0x00, 0x02, 0x00, 0x00, 0x34, 0x16, 0x1e, 0x39, 0x00, - //0x0320: ...2 .... ...4 ..9. - 0x02, 0x00, 0x00, 0x34, 0x16, 0x1e, 0x00, 0x00, 0x02, 0x00, 0x00, 0x36, 0x00, 0x00, 0x48, 0x00, - //0x0330: ...4 .... ...6 ..H. - 0x03, 0x00, 0x00, 0x37, 0x2c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, - //0x0340: ...7 ,... .... .... - 0x1c, 0x00, 0x00, 0x0e, 0x16, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x0e, 0x16, 0x00, 0x2c, 0x01, - //0x0350: .... .... .... ..,. - 0x01, 0x00, 0x00, 0x0a, 0x16, 0x1e, 0xae, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x16, 0x14, 0x00, 0x00, - //0x0360: .... .... .... .... - 0x01, 0x00, 0x00, 0x0b, 0x0b, 0x14, 0x00, 0x00, 0x32, 0x14, 0x00, 0x0b, 0x0b, 0x1e, 0x00, 0x00, - //0x0370: .... .... 2... .... - 0x32, 0x14, 0x00, 0x0b, 0x16, 0x14, 0x00, 0x00, 0x32, 0x14, 0x00, 0x0e, 0x21, 0x28, 0x00, 0x00, - //0x0380: 2... .... 2... !(.. - 0x32, 0x14, 0x00, 0xff, 0x44, 0x52, 0x45, 0x41, 0x4d, 0x57, 0x45, 0x42, 0x2e, 0x56, 0x39, 0x39, - //0x0390: 2... DREA MWEB .V99 - 0x00, 0x00, 0x01, 0x45, 0x58, 0x49, 0x54, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x48, 0x45, 0x4c, - //0x03a0: ...E XIT HEL - 0x50, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x4c, 0x49, 0x53, 0x54, 0x20, 0x20, 0x20, 0x20, 0x20, - //0x03b0: P L IST - 0x20, 0x52, 0x45, 0x41, 0x44, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x4c, 0x4f, 0x47, 0x4f, 0x4e, - //0x03c0: REA D L OGON - 0x20, 0x20, 0x20, 0x20, 0x20, 0x4b, 0x45, 0x59, 0x53, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, - //0x03d0: KEY S . - 0x00, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x50, 0x55, 0x42, - //0x03e0: .PUB LIC PUB - 0x4c, 0x49, 0x43, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x42, 0x4c, 0x41, 0x43, 0x4b, - //0x03f0: LIC ...B LACK - 0x44, 0x52, 0x41, 0x47, 0x4f, 0x4e, 0x20, 0x52, 0x59, 0x41, 0x4e, 0x20, 0x20, 0x20, 0x20, 0x20, - //0x0400: DRAG ON R YAN - 0x20, 0x20, 0x00, 0x00, 0x00, 0x48, 0x45, 0x4e, 0x44, 0x52, 0x49, 0x58, 0x20, 0x20, 0x20, 0x20, - //0x0410: .. .HEN DRIX - 0x20, 0x4c, 0x4f, 0x55, 0x49, 0x53, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x53, - //0x0420: LOU IS ...S - 0x45, 0x50, 0x54, 0x49, 0x4d, 0x55, 0x53, 0x20, 0x20, 0x20, 0x20, 0x42, 0x45, 0x43, 0x4b, 0x45, - //0x0430: EPTI MUS B ECKE - 0x54, 0x54, 0x20, 0x20, 0x20, 0x20, 0x00, 0xff, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - //0x0440: TT .. . - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x22, 0x52, 0x4f, 0x4f, 0x54, 0x20, 0x20, 0x20, 0x20, - //0x0450: ." ROOT - 0x20, 0x20, 0x20, 0x20, 0x00, 0x22, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - //0x0460: ." - 0x20, 0x20, 0x00, 0x30, 0x30, 0x30, 0x30, 0x00, 0x30, 0x30, 0x00, 0x0d, 0x0a, 0x0d, 0x0a, 0x24, - //0x0470: .0 000. 00.. ...$ - 0x4f, 0x42, 0x4a, 0x45, 0x43, 0x54, 0x20, 0x4e, 0x41, 0x4d, 0x45, 0x20, 0x4f, 0x4e, 0x45, 0x20, - //0x0480: OBJE CT N AME ONE - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - //0x0490: - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x10, 0x12, 0x12, 0x11, 0x10, 0x10, 0x10, - //0x04a0: .... .... - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - //0x04b0: .... .... .... .... - 0x02, 0x44, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x04c0: .D:. .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x04d0: .... .... .... .... - 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x04e0: .... .... .... .... - 0x00, 0x05, 0x00, 0x03, 0x02, 0x04, 0x01, 0x0a, 0x09, 0x08, 0x06, 0x0b, 0x04, 0x07, 0x07, 0x00, - //0x04f0: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0500: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0510: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0520: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0530: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0540: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0550: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0560: .... .... .... .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x0570: .... .... .... .... - 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, }; - ds.assign(src, src + sizeof(src)); - dreamweb(); -} - -} // End of namespace DreamGen diff --git a/engines/dreamweb/dreamgen.h b/engines/dreamweb/dreamgen.h deleted file mode 100644 index ae9bf3bb06..0000000000 --- a/engines/dreamweb/dreamgen.h +++ /dev/null @@ -1,617 +0,0 @@ -#ifndef TASMRECOVER_DREAMGEN_STUBS_H__ -#define TASMRECOVER_DREAMGEN_STUBS_H__ - -/* PLEASE DO NOT MODIFY THIS FILE. ALL CHANGES WILL BE LOST! LOOK FOR README FOR DETAILS */ - -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "dreamweb/runtime.h" - -#include "dreamweb/structs.h" -#include "dreamweb/dreambase.h" - -namespace DreamGen { - -static const uint16 offset_rootdir = 0x0457; -static const uint16 offset_money2poke = 0x0478; -static const uint16 offset_keys = 0x03df; -static const uint16 offset_money1poke = 0x0473; -static const uint16 offset_comlist = 0x03a3; -static const uint16 offset_openchangesize = 0x03a1; -static const uint16 offset_commandline = 0x0480; -static const uint16 offset_operand1 = 0x0449; -static const uint16 kStartvars = 0; -static const uint16 kProgresspoints = 1; -static const uint16 kWatchon = 2; -static const uint16 kShadeson = 3; -static const uint16 kSecondcount = 4; -static const uint16 kMinutecount = 5; -static const uint16 kHourcount = 6; -static const uint16 kZoomon = 7; -static const uint16 kLocation = 8; -static const uint16 kExpos = 9; -static const uint16 kExframepos = 10; -static const uint16 kExtextpos = 12; -static const uint16 kCard1money = 14; -static const uint16 kListpos = 16; -static const uint16 kRyanpage = 18; -static const uint16 kWatchingtime = 19; -static const uint16 kReeltowatch = 21; -static const uint16 kEndwatchreel = 23; -static const uint16 kSpeedcount = 25; -static const uint16 kWatchspeed = 26; -static const uint16 kReeltohold = 27; -static const uint16 kEndofholdreel = 29; -static const uint16 kWatchmode = 31; -static const uint16 kDestafterhold = 32; -static const uint16 kNewsitem = 33; -static const uint16 kLiftflag = 34; -static const uint16 kLiftpath = 35; -static const uint16 kLockstatus = 36; -static const uint16 kDoorpath = 37; -static const uint16 kCounttoopen = 38; -static const uint16 kCounttoclose = 39; -static const uint16 kRockstardead = 40; -static const uint16 kGeneraldead = 41; -static const uint16 kSartaindead = 42; -static const uint16 kAidedead = 43; -static const uint16 kBeenmugged = 44; -static const uint16 kGunpassflag = 45; -static const uint16 kCanmovealtar = 46; -static const uint16 kTalkedtoattendant = 47; -static const uint16 kTalkedtosparky = 48; -static const uint16 kTalkedtoboss = 49; -static const uint16 kTalkedtorecep = 50; -static const uint16 kCardpassflag = 51; -static const uint16 kMadmanflag = 52; -static const uint16 kKeeperflag = 53; -static const uint16 kLasttrigger = 54; -static const uint16 kMandead = 55; -static const uint16 kSeed = 56; -static const uint16 kNeedtotravel = 59; -static const uint16 kThroughdoor = 60; -static const uint16 kNewobs = 61; -static const uint16 kRyanon = 62; -static const uint16 kCombatcount = 63; -static const uint16 kLastweapon = 64; -static const uint16 kDreamnumber = 65; -static const uint16 kRoomafterdream = 66; -static const uint16 kShakecounter = 67; -static const uint16 kSpeechcount = 68; -static const uint16 kCharshift = 69; -static const uint16 kKerning = 71; -static const uint16 kBrightness = 72; -static const uint16 kRoomloaded = 73; -static const uint16 kDidzoom = 74; -static const uint16 kLinespacing = 75; -static const uint16 kTextaddressx = 77; -static const uint16 kTextaddressy = 79; -static const uint16 kTextlen = 81; -static const uint16 kLastxpos = 82; -static const uint16 kIcontop = 84; -static const uint16 kIconleft = 86; -static const uint16 kItemframe = 88; -static const uint16 kItemtotran = 89; -static const uint16 kRoomad = 90; -static const uint16 kOldsubject = 92; -static const uint16 kWithobject = 94; -static const uint16 kWithtype = 95; -static const uint16 kLookcounter = 96; -static const uint16 kCommand = 98; -static const uint16 kCommandtype = 99; -static const uint16 kOldcommandtype = 100; -static const uint16 kObjecttype = 101; -static const uint16 kGetback = 102; -static const uint16 kInvopen = 103; -static const uint16 kMainmode = 104; -static const uint16 kPickup = 105; -static const uint16 kLastinvpos = 106; -static const uint16 kExamagain = 107; -static const uint16 kNewtextline = 108; -static const uint16 kOpenedob = 109; -static const uint16 kOpenedtype = 110; -static const uint16 kOldmapadx = 111; -static const uint16 kOldmapady = 113; -static const uint16 kMapadx = 115; -static const uint16 kMapady = 117; -static const uint16 kMapoffsetx = 119; -static const uint16 kMapoffsety = 121; -static const uint16 kMapxstart = 123; -static const uint16 kMapystart = 125; -static const uint16 kMapxsize = 127; -static const uint16 kMapysize = 128; -static const uint16 kHavedoneobs = 129; -static const uint16 kManisoffscreen = 130; -static const uint16 kRainspace = 131; -static const uint16 kFacing = 132; -static const uint16 kLeavedirection = 133; -static const uint16 kTurntoface = 134; -static const uint16 kTurndirection = 135; -static const uint16 kMaintimer = 136; -static const uint16 kIntrocount = 138; -static const uint16 kArrowad = 139; -static const uint16 kCurrentkey = 141; -static const uint16 kOldkey = 142; -static const uint16 kUseddirection = 143; -static const uint16 kCurrentkey2 = 144; -static const uint16 kTimercount = 145; -static const uint16 kOldtimercount = 146; -static const uint16 kMapx = 147; -static const uint16 kMapy = 148; -static const uint16 kNewscreen = 149; -static const uint16 kRyanx = 150; -static const uint16 kRyany = 151; -static const uint16 kLastflag = 152; -static const uint16 kLastflagex = 153; -static const uint16 kFlagx = 154; -static const uint16 kFlagy = 155; -static const uint16 kCurrentex = 156; -static const uint16 kCurrentfree = 157; -static const uint16 kFramesad = 158; -static const uint16 kDataad = 160; -static const uint16 kFrsegment = 162; -static const uint16 kObjectx = 164; -static const uint16 kObjecty = 166; -static const uint16 kOffsetx = 168; -static const uint16 kOffsety = 170; -static const uint16 kSavesize = 172; -static const uint16 kSavesource = 174; -static const uint16 kSavex = 176; -static const uint16 kSavey = 177; -static const uint16 kCurrentob = 178; -static const uint16 kPrioritydep = 179; -static const uint16 kDestpos = 180; -static const uint16 kReallocation = 181; -static const uint16 kRoomnum = 182; -static const uint16 kNowinnewroom = 183; -static const uint16 kResetmanxy = 184; -static const uint16 kNewlocation = 185; -static const uint16 kAutolocation = 186; -static const uint16 kMustload = 187; -static const uint16 kAnswered = 188; -static const uint16 kSaidno = 189; -static const uint16 kDoorcheck1 = 190; -static const uint16 kDoorcheck2 = 191; -static const uint16 kDoorcheck3 = 192; -static const uint16 kDoorcheck4 = 193; -static const uint16 kMousex = 194; -static const uint16 kMousey = 196; -static const uint16 kMousebutton = 198; -static const uint16 kMousebutton1 = 200; -static const uint16 kMousebutton2 = 202; -static const uint16 kMousebutton3 = 204; -static const uint16 kMousebutton4 = 206; -static const uint16 kOldbutton = 208; -static const uint16 kOldx = 210; -static const uint16 kOldy = 212; -static const uint16 kLastbutton = 214; -static const uint16 kOldpointerx = 216; -static const uint16 kOldpointery = 218; -static const uint16 kDelherex = 220; -static const uint16 kDelherey = 222; -static const uint16 kPointerxs = 224; -static const uint16 kPointerys = 225; -static const uint16 kDelxs = 226; -static const uint16 kDelys = 227; -static const uint16 kPointerframe = 228; -static const uint16 kPointerpower = 229; -static const uint16 kAuxpointerframe = 230; -static const uint16 kPointermode = 231; -static const uint16 kPointerspeed = 232; -static const uint16 kPointercount = 233; -static const uint16 kInmaparea = 234; -static const uint16 kSlotdata = 235; -static const uint16 kThisslot = 236; -static const uint16 kSlotflags = 237; -static const uint16 kTalkmode = 238; -static const uint16 kTalkpos = 239; -static const uint16 kCharacter = 240; -static const uint16 kPersondata = 241; -static const uint16 kTalknum = 243; -static const uint16 kNumberinroom = 244; -static const uint16 kCurrentcel = 245; -static const uint16 kOldselection = 246; -static const uint16 kStopwalking = 247; -static const uint16 kMouseon = 248; -static const uint16 kPlayed = 249; -static const uint16 kTimer1 = 251; -static const uint16 kTimer2 = 252; -static const uint16 kTimer3 = 253; -static const uint16 kWholetimer = 254; -static const uint16 kTimer1to = 256; -static const uint16 kTimer2to = 257; -static const uint16 kTimer3to = 258; -static const uint16 kWatchdump = 259; -static const uint16 kLogonum = 260; -static const uint16 kOldlogonum = 261; -static const uint16 kNewlogonum = 262; -static const uint16 kNetseg = 263; -static const uint16 kNetpoint = 265; -static const uint16 kKeynum = 267; -static const uint16 kCursorstate = 268; -static const uint16 kPressed = 269; -static const uint16 kPresspointer = 270; -static const uint16 kGraphicpress = 272; -static const uint16 kPresscount = 273; -static const uint16 kKeypadax = 274; -static const uint16 kKeypadcx = 276; -static const uint16 kLightcount = 278; -static const uint16 kFolderpage = 279; -static const uint16 kDiarypage = 280; -static const uint16 kMenucount = 281; -static const uint16 kSymboltopx = 282; -static const uint16 kSymboltopnum = 283; -static const uint16 kSymboltopdir = 284; -static const uint16 kSymbolbotx = 285; -static const uint16 kSymbolbotnum = 286; -static const uint16 kSymbolbotdir = 287; -static const uint16 kSymboltolight = 288; -static const uint16 kSymbol1 = 289; -static const uint16 kSymbol2 = 290; -static const uint16 kSymbol3 = 291; -static const uint16 kSymbolnum = 292; -static const uint16 kDumpx = 293; -static const uint16 kDumpy = 295; -static const uint16 kWalkandexam = 297; -static const uint16 kWalkexamtype = 298; -static const uint16 kWalkexamnum = 299; -static const uint16 kCursloc = 300; -static const uint16 kCurslocx = 302; -static const uint16 kCurslocy = 304; -static const uint16 kCurpos = 306; -static const uint16 kMonadx = 308; -static const uint16 kMonady = 310; -static const uint16 kGotfrom = 312; -static const uint16 kMonsource = 314; -static const uint16 kNumtodo = 316; -static const uint16 kTimecount = 318; -static const uint16 kCounttotimed = 320; -static const uint16 kTimedseg = 322; -static const uint16 kTimedoffset = 324; -static const uint16 kTimedy = 326; -static const uint16 kTimedx = 327; -static const uint16 kNeedtodumptimed = 328; -static const uint16 kLoadingorsave = 329; -static const uint16 kCurrentslot = 330; -static const uint16 kCursorpos = 331; -static const uint16 kColourpos = 332; -static const uint16 kFadedirection = 333; -static const uint16 kNumtofade = 334; -static const uint16 kFadecount = 335; -static const uint16 kAddtogreen = 336; -static const uint16 kAddtored = 337; -static const uint16 kAddtoblue = 338; -static const uint16 kLastsoundreel = 339; -static const uint16 kSpeechloaded = 341; -static const uint16 kSpeechlength = 342; -static const uint16 kVolume = 344; -static const uint16 kVolumeto = 345; -static const uint16 kVolumedirection = 346; -static const uint16 kVolumecount = 347; -static const uint16 kPlayblock = 348; -static const uint16 kWongame = 349; -static const uint16 kLasthardkey = 350; -static const uint16 kBufferin = 351; -static const uint16 kBufferout = 353; -static const uint16 kExtras = 355; -static const uint16 kWorkspace = 357; -static const uint16 kMapstore = 359; -static const uint16 kCharset1 = 361; -static const uint16 kBuffers = 363; -static const uint16 kMainsprites = 365; -static const uint16 kBackdrop = 367; -static const uint16 kMapdata = 369; -static const uint16 kSounddata = 371; -static const uint16 kSounddata2 = 373; -static const uint16 kRecordspace = 375; -static const uint16 kFreedat = 377; -static const uint16 kSetdat = 379; -static const uint16 kReel1 = 381; -static const uint16 kReel2 = 383; -static const uint16 kReel3 = 385; -static const uint16 kRoomdesc = 387; -static const uint16 kFreedesc = 389; -static const uint16 kSetdesc = 391; -static const uint16 kBlockdesc = 393; -static const uint16 kSetframes = 395; -static const uint16 kFreeframes = 397; -static const uint16 kPeople = 399; -static const uint16 kReels = 401; -static const uint16 kCommandtext = 403; -static const uint16 kPuzzletext = 405; -static const uint16 kTraveltext = 407; -static const uint16 kTempgraphics = 409; -static const uint16 kTempgraphics2 = 411; -static const uint16 kTempgraphics3 = 413; -static const uint16 kTempsprites = 415; -static const uint16 kTextfile1 = 417; -static const uint16 kTextfile2 = 419; -static const uint16 kTextfile3 = 421; -static const uint16 kBlinkframe = 423; -static const uint16 kBlinkcount = 424; -static const uint16 kReasseschanges = 425; -static const uint16 kPointerspath = 426; -static const uint16 kManspath = 427; -static const uint16 kPointerfirstpath = 428; -static const uint16 kFinaldest = 429; -static const uint16 kDestination = 430; -static const uint16 kLinestartx = 431; -static const uint16 kLinestarty = 433; -static const uint16 kLineendx = 435; -static const uint16 kLineendy = 437; -static const uint16 kIncrement1 = 439; -static const uint16 kIncrement2 = 441; -static const uint16 kLineroutine = 443; -static const uint16 kLinepointer = 444; -static const uint16 kLinedirection = 445; -static const uint16 kLinelength = 446; -static const uint16 kLiftsoundcount = 447; -static const uint16 kCh0blockstocopy = 448; -static const uint16 kCh0playing = 450; -static const uint16 kCh0repeat = 451; -static const uint16 kCh1playing = 452; -static const uint16 kCh1blockstocopy = 453; -static const uint16 kSoundbufferwrite = 455; -static const uint16 kCurrentsample = 457; -static const uint16 kRoomssample = 458; -static const uint16 kReelroutines = 459; -static const uint16 kBasicsample = 916; -static const uint16 kCurrentfile = 1125; -static const uint16 kRoomscango = 1249; -static const uint16 kRoompics = 1265; -static const uint16 kOplist = 1280; -static const uint16 kInputline = 1283; -static const uint16 kPresslist = 1411; -static const uint16 kQuitrequested = 1417; -static const uint16 kSubtitles = 1418; -static const uint16 kForeignrelease = 1419; -static const uint16 kBlocktextdat = (0); -static const uint16 kPersonframes = (0); -static const uint16 kDebuglevel1 = (0); -static const uint16 kDebuglevel2 = (0); -static const uint16 kPlayback = (0); -static const uint16 kMap = (0); -static const uint16 kSettextdat = (0); -static const uint16 kSpanish = (0); -static const uint16 kFramedata = (0); -static const uint16 kRecording = (0); -static const uint16 kFlags = (0); -static const uint16 kGerman = (0); -static const uint16 kTextunder = (0); -static const uint16 kPathdata = (0); -static const uint16 kDemo = (0); -static const uint16 kExframedata = (0); -static const uint16 kIntextdat = (0); -static const uint16 kFreetextdat = (0); -static const uint16 kFrframedata = (0); -static const uint16 kSettext = (0+(130*2)); -static const uint16 kOpeninvlist = (0+(228*13)); -static const uint16 kRyaninvlist = (0+(228*13)+32); -static const uint16 kPointerback = (0+(228*13)+32+60); -static const uint16 kMapflags = (0+(228*13)+32+60+(32*32)); -static const uint16 kStartpal = (0+(228*13)+32+60+(32*32)+(11*10*3)); -static const uint16 kEndpal = (0+(228*13)+32+60+(32*32)+(11*10*3)+768); -static const uint16 kMaingamepal = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768); -static const uint16 kSpritetable = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768); -static const uint16 kSetlist = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)); -static const uint16 kFreelist = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)); -static const uint16 kExlist = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)); -static const uint16 kPeoplelist = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)); -static const uint16 kZoomspace = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)); -static const uint16 kPrintedlist = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)); -static const uint16 kListofchanges = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)+(5*80)); -static const uint16 kUndertimedtext = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)+(5*80)+(250*4)); -static const uint16 kRainlist = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)+(5*80)+(250*4)+(256*30)); -static const uint16 kInitialreelrouts = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)+(5*80)+(250*4)+(256*30)+(6*64)); -static const uint16 kInitialvars = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)+(5*80)+(250*4)+(256*30)+(6*64)+916-459); -static const uint16 kLengthofbuffer = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)+(5*80)+(250*4)+(256*30)+(6*64)+916-459+68-0); -static const uint16 kReellist = (0+(36*144)); -static const uint16 kIntext = (0+(38*2)); -static const uint16 kLengthofmap = (0+(66*60)); -static const uint16 kFreetext = (0+(82*2)); -static const uint16 kBlocktext = (0+(98*2)); -static const uint16 kBlocks = (0+192); -static const uint16 kFrframes = (0+2080); -static const uint16 kExframes = (0+2080); -static const uint16 kFrames = (0+2080); -static const uint16 kExdata = (0+2080+30000); -static const uint16 kExtextdat = (0+2080+30000+(16*114)); -static const uint16 kExtext = (0+2080+30000+(16*114)+((114+2)*2)); -static const uint16 kLengthofextra = (0+2080+30000+(16*114)+((114+2)*2)+18000); -static const uint16 kPersontxtdat = (0+24); -static const uint16 kPersontext = (0+24+(1026*2)); -static const uint16 kInputport = (0x63); -static const uint16 kForeign = (1); -static const uint16 kCd = (1); -static const uint16 kNumexobjects = (114); -static const uint16 kUndertextsizey = (13); -static const uint16 kZoomy = (132); -static const uint16 kFreedatlen = (16*80); -static const uint16 kExtextlen = (18000); -static const uint16 kLenofmapstore = (22*8*20*8); -static const uint16 kUndertextsizex = (228); -static const uint16 kNumchanges = (250); -static const uint16 kUndertimedysize = (30); -static const uint16 kExframeslen = (30000); -static const uint16 kTablesize = (32); -static const uint16 kScreenwidth = (320); -static const uint16 kKeypadx = (36+112); -static const uint16 kItempicsize = (44); -static const uint16 kDiaryy = (48+12); -static const uint16 kOpsy = (52); -static const uint16 kSymboly = (56); -static const uint16 kInventy = (58); -static const uint16 kMenuy = (60); -static const uint16 kOpsx = (60); -static const uint16 kMaplength = (60); -static const uint16 kSymbolx = (64); -static const uint16 kSetdatlen = (64*128); -static const uint16 kMapwidth = (66); -static const uint16 kTextstart = (66*2); -static const uint16 kMaplen = (66*60); -static const uint16 kDiaryx = (68+24); -static const uint16 kLengthofvars = (68-0); -static const uint16 kKeypady = (72); -static const uint16 kZoomx = (8); -static const uint16 kInventx = (80); -static const uint16 kMenux = (80+40); -static const uint16 kLenofreelrouts = (916-459); -static const uint16 kHeaderlen = (96); - - -class DreamGenContext : public DreamBase, public Context { -public: - DreamGenContext(DreamWeb::DreamWebEngine *en) : DreamBase(en), Context(this) {} - - void __start(); -#include "stubs.h" // Allow hand-reversed functions to have a signature different than void f() - - void identifyOb(); - void runEndSeq(); - void useOpenBox(); - void clearBuffers(); - void getObTextStart(); - void entryTexts(); - void putUnderCentre(); - void checkObjectSize(); - void findText1(); - void isRyanHolding(); - void showSlots(); - void useCashCard(); - void moneyPoke(); - void doSomeTalk(); - void resetLocation(); - void getOpenedSize(); - void adjustUp(); - void fadeScreenDownHalf(); - void fadeDownMon(); - void bartender(); - void outOfOpen(); - void dirCom(); - void endGameSeq(); - void findFirstPath(); - void useSLab(); - void useAltar(); - void startTalk(); - void getAnyAd(); - void usePipe(); - void reminders(); - void runTap(); - void dumpDiaryKeys(); - void checkForExit(); - void lookInInterface(); - void inToInv(); - void adjustLeft(); - void deleteExText(); - void entryAnims(); - void getFreeAd(); - void removeObFromInv(); - void heavy(); - void useKey(); - void dirFile(); - void pickupConts(); - void nextColon(); - void findInvPos(); - void getKeyAndLogo(); - void selectOb(); - void receptionist(); - void selectSlot(); - void fadeUpMon(); - void showDiaryPage(); - void reExFromInv(); - void businessMan(); - void outOfInv(); - void transferMap(); - void purgeAnItem(); - void purgeALocation(); - void notHeldError(); - void getSetAd(); - void getUnderCentre(); - void showKeys(); - void printmessage2(); - void findOpenPos(); - void describeOb(); - void deleteExFrame(); - void searchForSame(); - void rollEm(); - void poolGuard(); - void lookAtPlace(); - void useAxe(); - void findAllOpen(); - void fillOpen(); - void findSetObject(); - void deleteExObject(); - void removeFreeObject(); - void lookAtCard(); - void helicopter(); - void getEitherAd(); - void setPickup(); - void dropObject(); - void openOb(); - void drawItAll(); - void useStereo(); - void showDiaryKeys(); - void useOpened(); - void signOn(); - void locationPic(); - void triggerMessage(); - void swapWithOpen(); - void dreamweb(); - void checkInside(); - void findPathOfPoint(); - void getDestInfo(); - void setupTimedUse(); - void makeCaps(); - void read(); - void additionalText(); - void mugger(); - void searchForString(); - void selectOpenOb(); - void useGun(); - void useHandle(); - void incRyanPage(); - void findExObject(); - void clearChanges(); - void searchForFiles(); - void getExAd(); - void initialMonCols(); - void execCommand(); - void updateSymbolBot(); - void findPuzText(); - void swapWithInv(); - void useControl(); - void adjustRight(); - void transferToEx(); - void updateSymbolTop(); - void getPersonText(); - void parser(); - void emergencyPurge(); - void processTrigger(); - void transferConToEx(); - void adjustDown(); - void withWhat(); -}; - -} // End of namespace DreamGen - -#endif diff --git a/engines/dreamweb/dreamweb.cpp b/engines/dreamweb/dreamweb.cpp index b4fc1b7b77..af55d0c72c 100644 --- a/engines/dreamweb/dreamweb.cpp +++ b/engines/dreamweb/dreamweb.cpp @@ -30,16 +30,21 @@ #include "common/timer.h" #include "common/util.h" +#include "engines/advancedDetector.h" + #include "graphics/palette.h" #include "graphics/surface.h" #include "dreamweb/dreamweb.h" -#include "dreamweb/dreamgen.h" namespace DreamWeb { DreamWebEngine::DreamWebEngine(OSystem *syst, const DreamWebGameDescription *gameDesc) : - Engine(syst), _gameDescription(gameDesc), _rnd("dreamweb"), _context(this), _base(_context) { + Engine(syst), _gameDescription(gameDesc), _rnd("dreamweb"), + _exText(kNumExTexts), + _setDesc(kNumSetTexts), _blockDesc(kNumBlockTexts), + _roomDesc(kNumRoomTexts), _freeDesc(kNumFreeTexts), + _personText(kNumPersonTexts) { // Setup mixer _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); @@ -51,25 +56,176 @@ DreamWebEngine::DreamWebEngine(OSystem *syst, const DreamWebGameDescription *gam _console = 0; DebugMan.addDebugChannel(kDebugAnimation, "Animation", "Animation Debug Flag"); DebugMan.addDebugChannel(kDebugSaveLoad, "SaveLoad", "Track Save/Load Function"); - _inSaveFile = 0; _speed = 1; _turbo = false; _oldMouseState = 0; _channel0 = 0; _channel1 = 0; - _icons1 = NULL; - _icons2 = NULL; - _tempCharset = NULL; - - _language = gameDesc->desc.language; + _datafilePrefix = "DREAMWEB."; + + _openChangeSize = kInventx+(4*kItempicsize); + _quitRequested = false; + + _currentSample = 0xff; + _channel0Playing = 0; + _channel0Repeat = 0; + _channel1Playing = 0xff; + + _volume = 0; + _volumeTo = 0; + _volumeDirection = 0; + _volumeCount = 0; + + _speechLoaded = false; + + _backdropBlocks = 0; + _reelList = 0; + + _oldSubject._type = 0; + _oldSubject._index = 0; + + // misc variables + _speechCount = 0; + _charShift = 0; + _kerning = 0; + _brightPalette = false; + _roomLoaded = 0; + _didZoom = 0; + _lineSpacing = 10; + _textAddressX = 13; + _textAddressY = 182; + _textLen = 0; + _lastXPos = 0; + _itemFrame = 0; + _withObject = 0; + _withType = 0; + _lookCounter = 0; + _command = 0; + _commandType = 0; + _objectType = 0; + _getBack = 0; + _invOpen = 0; + _mainMode = 0; + _pickUp = 0; + _lastInvPos = 0; + _examAgain = 0; + _newTextLine = 0; + _openedOb = 0; + _openedType = 0; + _mapAdX = 0; + _mapAdY = 0; + _mapOffsetX = 104; + _mapOffsetY = 38; + _mapXStart = 0; + _mapYStart = 0; + _mapXSize = 0; + _mapYSize = 0; + _haveDoneObs = 0; + _manIsOffScreen = 0; + _facing = 0; + _leaveDirection = 0; + _turnToFace = 0; + _turnDirection = 0; + _mainTimer = 0; + _introCount = 0; + _currentKey = 0; + _timerCount = 0; + _mapX = 0; + _mapY = 0; + _ryanX = 0; + _ryanY = 0; + _lastFlag = 0; + _destPos = 0; + _realLocation = 0; + _roomNum = 0; + _nowInNewRoom = 0; + _resetManXY = 0; + _newLocation = 0xFF; + _autoLocation = 0xFF; + _mouseX = 0; + _mouseY = 0; + _mouseButton = 0; + _oldButton = 0; + _oldX = 0; + _oldY = 0; + _oldPointerX = 0; + _oldPointerY = 0; + _delHereX = 0; + _delHereY = 0; + _pointerXS = 32; + _pointerYS = 32; + _delXS = 0; + _delYS = 0; + _pointerFrame = 0; + _pointerPower = 0; + _pointerMode = 0; + _pointerSpeed = 0; + _pointerCount = 0; + _inMapArea = 0; + _talkMode = 0; + _talkPos = 0; + _character = 0; + _watchDump = 0; + _logoNum = 0; + _oldLogoNum = 0; + _pressed = 0; + _pressPointer = 0; + _graphicPress = 0; + _pressCount = 0; + _lightCount = 0; + _folderPage = 0; + _diaryPage = 0; + _menuCount = 0; + _symbolTopX = 0; + _symbolTopNum = 0; + _symbolTopDir = 0; + _symbolBotX = 0; + _symbolBotNum = 0; + _symbolBotDir = 0; + _walkAndExam = 0; + _walkExamType = 0; + _walkExamNum = 0; + _cursLocX = 0; + _cursLocY = 0; + _curPos = 0; + _monAdX = 0; + _monAdY = 0; + _timeCount = 0; + _needToDumpTimed = 0; + _loadingOrSave = 0; + _saveLoadPage = 0; + _currentSlot = 0; + _cursorPos = 0; + _colourPos = 0; + _fadeDirection = 0; + _numToFade = 0; + _fadeCount = 0; + _addToGreen = 0; + _addToRed = 0; + _addToBlue = 0; + _lastSoundReel = 0; + _lastHardKey = 0; + _bufferIn = 0; + _bufferOut = 0; + _blinkFrame = 23; + _blinkCount = 0; + _reAssesChanges = 0; + _pointersPath = 0; + _mansPath = 0; + _pointerFirstPath = 0; + _finalDest = 0; + _destination = 0; + _lineStartX = 0; + _lineStartY = 0; + _lineEndX = 0; + _lineEndY = 0; + _linePointer = 0; + _lineDirection = 0; + _lineLength = 0; } DreamWebEngine::~DreamWebEngine() { - assert(_icons1 == NULL); - assert(_icons2 == NULL); - assert(_tempCharset == NULL); - DebugMan.clearAllDebugChannels(); delete _console; } @@ -96,14 +252,14 @@ void DreamWebEngine::waitForVSync() { setVSyncInterrupt(false); } - _base.doShake(); - _base.doFade(); + doShake(); + doFade(); _system->updateScreen(); } void DreamWebEngine::quit() { - _base.data.byte(DreamGen::kQuitrequested) = 1; - _base.data.byte(DreamGen::kLasthardkey) = 1; + _quitRequested = true; + _lastHardKey = 1; } void DreamWebEngine::processEvents() { @@ -138,8 +294,8 @@ void DreamWebEngine::processEvents() { break; case Common::KEYCODE_c: //skip statue puzzle - _base.data.byte(DreamGen::kSymbolbotnum) = 3; - _base.data.byte(DreamGen::kSymboltopnum) = 5; + _symbolBotNum = 3; + _symbolTopNum = 5; break; default: @@ -169,7 +325,7 @@ void DreamWebEngine::processEvents() { break; } - _base.data.byte(DreamGen::kLasthardkey) = hardKey; + _lastHardKey = hardKey; // The rest of the keys are converted to ASCII. This // is fairly restrictive, and eventually we may want @@ -209,11 +365,15 @@ Common::Error DreamWebEngine::run() { syncSoundSettings(); _console = new DreamWebConsole(this); - ConfMan.registerDefault("dreamweb_originalsaveload", "true"); + ConfMan.registerDefault("dreamweb_originalsaveload", "false"); + ConfMan.registerDefault("bright_palette", true); + _hasSpeech = Common::File::exists("speech/r01c0000.raw") && !ConfMan.getBool("speech_mute"); + _brightPalette = ConfMan.getBool("bright_palette"); _timer->installTimerProc(vSyncInterrupt, 1000000 / 70, this, "dreamwebVSync"); - _context.__start(); - _base.data.byte(DreamGen::kQuitrequested) = 0; + dreamweb(); + dreamwebFinalize(); + _quitRequested = false; _timer->removeTimerProc(vSyncInterrupt); @@ -227,43 +387,6 @@ void DreamWebEngine::setSpeed(uint speed) { _timer->installTimerProc(vSyncInterrupt, 1000000 / 70 / speed, this, "dreamwebVSync"); } -void DreamWebEngine::openFile(const Common::String &name) { - processEvents(); - closeFile(); - if (_file.open(name)) - return; - // File not found? See if there is a save state with this name - // FIXME: Is this really needed? If yes, document why; if not, - // remove all traces of _inSaveFile. - _inSaveFile = _saveFileMan->openForLoading(name); - if (_inSaveFile) - return; - error("cannot open file %s", name.c_str()); -} - -uint32 DreamWebEngine::skipBytes(uint32 bytes) { - if (!_file.seek(bytes, SEEK_CUR)) - error("seek failed"); - return _file.pos(); -} - -uint32 DreamWebEngine::readFromFile(uint8 *dst, unsigned size) { - processEvents(); - if (_file.isOpen()) - return _file.read(dst, size); - if (_inSaveFile) - return _inSaveFile->read(dst, size); - error("file was not opened (read before open)"); -} - -void DreamWebEngine::closeFile() { - processEvents(); - if (_file.isOpen()) - _file.close(); - delete _inSaveFile; - _inSaveFile = 0; -} - Common::String DreamWebEngine::getSavegameFilename(int slot) const { // TODO: Are saves from all versions of Dreamweb compatible with each other? // Then we can can consider keeping the filenames as DREAMWEB.Dnn. @@ -275,14 +398,14 @@ Common::String DreamWebEngine::getSavegameFilename(int slot) const { void DreamWebEngine::keyPressed(uint16 ascii) { debug(2, "key pressed = %04x", ascii); - uint16 in = (_base.data.word(DreamGen::kBufferin) + 1) & 0x0f; - uint16 out = _base.data.word(DreamGen::kBufferout); + uint16 in = (_bufferIn + 1) & 0x0f; + uint16 out = _bufferOut; if (in == out) { warning("keyboard buffer is full"); return; } - _base.data.word(DreamGen::kBufferin) = in; - DreamGen::g_keyBuffer[in] = ascii; + _bufferIn = in; + DreamWeb::g_keyBuffer[in] = ascii; } void DreamWebEngine::mouseCall(uint16 *x, uint16 *y, uint16 *state) { @@ -330,7 +453,7 @@ void DreamWebEngine::blit(const uint8 *src, int pitch, int x, int y, int w, int } void DreamWebEngine::printUnderMonitor() { - uint8 *dst = _base._workspace + DreamGen::kScreenwidth * 43 + 76; + uint8 *dst = workspace() + kScreenwidth * 43 + 76; Graphics::Surface *s = _system->lockScreen(); if (!s) @@ -345,7 +468,7 @@ void DreamWebEngine::printUnderMonitor() { ++dst; ++src; } } - dst += DreamGen::kScreenwidth - 170; + dst += kScreenwidth - 170; } _system->unlockScreen(); } @@ -358,10 +481,9 @@ uint8 DreamWebEngine::modifyChar(uint8 c) const { if (c < 128) return c; - switch(_language) { + switch(getLanguage()) { case Common::DE_DEU: - switch(c) - { + switch(c) { case 129: return 'Z' + 3; case 132: @@ -409,4 +531,8 @@ uint8 DreamWebEngine::modifyChar(uint8 c) const { } } +bool DreamWebEngine::hasSpeech() { + return isCD() && _hasSpeech; +} + } // End of namespace DreamWeb diff --git a/engines/dreamweb/dreamweb.h b/engines/dreamweb/dreamweb.h index 7ff0005fa4..13a27449dc 100644 --- a/engines/dreamweb/dreamweb.h +++ b/engines/dreamweb/dreamweb.h @@ -34,37 +34,71 @@ #include "audio/audiostream.h" #include "audio/mixer.h" -#include "engines/advancedDetector.h" #include "engines/engine.h" -#include "dreamweb/dreamgen.h" #include "dreamweb/console.h" #include "dreamweb/structs.h" -namespace DreamGen { +#define SCUMMVM_HEADER MKTAG('S', 'C', 'V', 'M') +#define SCUMMVM_BLOCK_MAGIC_SIZE 0x1234 +#define SAVEGAME_VERSION 1 -// These are for ReelRoutine::reelPointer, which is a callback field. -const uint16 addr_backobject = 0xc170; -const uint16 addr_mainman = 0xc138; +namespace DreamWeb { + +const unsigned int kNumReelRoutines = 57; +const unsigned int kUnderTextSizeX = 180; +const unsigned int kUnderTextSizeY = 10; +const unsigned int kUnderTimedTextSizeY = 24; +const unsigned int kUnderTextSizeX_f = 228; // foreign version +const unsigned int kUnderTextSizeY_f = 13; // foreign version +const unsigned int kUnderTimedTextSizeY_f = 30; +const unsigned int kUnderTextBufSize = kUnderTextSizeX_f * kUnderTextSizeY_f; +const unsigned int kUnderTimedTextBufSize = 256 * kUnderTimedTextSizeY_f; +const unsigned int kLengthOfVars = 68; +const unsigned int kNumChanges = 250; +const unsigned int kLenOfMapStore = 22*8*20*8; +const unsigned int kMapWidth = 66; +const unsigned int kMapHeight = 60; +const unsigned int kLengthOfMap = kMapWidth * kMapHeight; +const unsigned int kNumExObjects = 114; +const unsigned int kScreenwidth = 320; +const unsigned int kDiaryx = (68+24); +const unsigned int kDiaryy = (48+12); +const unsigned int kInventx = 80; +const unsigned int kInventy = 58; +const unsigned int kMenux = (80+40); +const unsigned int kMenuy = 60; +const unsigned int kOpsx = 60; +const unsigned int kOpsy = 52; +const unsigned int kSymbolx = 64; +const unsigned int kSymboly = 56; +const unsigned int kLengthofvars = 68; +const unsigned int kFrameBlocksize = 2080; +const unsigned int kGraphicsFileFrameSize = 347; // ceil(2080 / sizeof(Frame)) +const unsigned int kNumexobjects = 114; +const unsigned int kNumExTexts = kNumexobjects + 2; +const uint16 kExtextlen = 18000; +const uint16 kExframeslen = 30000; +const unsigned int kLengthofextra = kFrameBlocksize + kExframeslen + sizeof(DynObject)*kNumexobjects + sizeof(uint16)*kNumExTexts + kExtextlen; +const unsigned int kItempicsize = 44; +const unsigned int kNumSetTexts = 130; +const unsigned int kNumBlockTexts = 98; +const unsigned int kNumRoomTexts = 38; +const unsigned int kNumFreeTexts = 82; +const unsigned int kNumPersonTexts = 1026; // Keyboard buffer. data.word(kBufferin) and data.word(kBufferout) are indexes // into this, making it a ring buffer extern uint8 g_keyBuffer[16]; -} - -namespace DreamWeb { - // Engine Debug Flags enum { kDebugAnimation = (1 << 0), kDebugSaveLoad = (1 << 1) }; -struct DreamWebGameDescription { - ADGameDescription desc; -}; +struct DreamWebGameDescription; class DreamWebEngine : public Engine { private: @@ -91,15 +125,12 @@ public: uint8 randomNumber() { return _rnd.getRandomNumber(255); } - void openFile(const Common::String &name); - uint32 readFromFile(uint8 *data, unsigned size); - uint32 skipBytes(uint32 bytes); - void closeFile(); - void mouseCall(uint16 *x, uint16 *y, uint16 *state); //fill mouse pos and button state void processEvents(); void blit(const uint8 *src, int pitch, int x, int y, int w, int h); void cls(); + bool isCD(); + bool hasSpeech(); void getPalette(uint8 *data, uint start, uint count); void setPalette(const uint8 *data, uint start, uint count); @@ -111,29 +142,17 @@ public: void quit(); - void loadSounds(uint bank, const Common::String &file); + void loadSounds(uint bank, const Common::String &suffix); bool loadSpeech(const Common::String &filename); void enableSavingOrLoading(bool enable = true) { _enableSavingOrLoading = enable; } - Common::Language getLanguage() const { return _language; } + Common::Language getLanguage() const; uint8 modifyChar(uint8 c) const; void stopSound(uint8 channel); - DreamGen::Frame *icons1() const { return (DreamGen::Frame *)_icons1; } - DreamGen::Frame *icons2() const { return (DreamGen::Frame *)_icons2; } - void setIcons1(void *frames) { assert(_icons1 == NULL); _icons1 = frames; } - void setIcons2(void *frames) { assert(_icons2 == NULL); _icons2 = frames; } - void freeIcons1() { free(_icons1); _icons1 = NULL; } - void freeIcons2() { free(_icons2); _icons2 = NULL; } - - DreamGen::Frame *tempCharset() const { return (DreamGen::Frame *)_tempCharset; } - void setTempCharset(void *frames) { assert(_tempCharset == NULL); _tempCharset = frames; } - void freeTempCharset() { free(_tempCharset); _tempCharset = NULL; } - - DreamGen::Frame *currentCharset() const { return _currentCharset; } - void setCurrentCharset(DreamGen::Frame *charset) { _currentCharset = charset; } + const Common::String& getDatafilePrefix() { return _datafilePrefix; }; private: void keyPressed(uint16 ascii); @@ -143,15 +162,12 @@ private: const DreamWebGameDescription *_gameDescription; Common::RandomSource _rnd; - - Common::File _file; - Common::InSaveFile *_inSaveFile; + Common::String _datafilePrefix; uint _speed; bool _turbo; uint _oldMouseState; bool _enableSavingOrLoading; - Common::Language _language; struct Sample { uint offset; @@ -169,13 +185,965 @@ private: Audio::SoundHandle _channelHandle[2]; uint8 _channel0, _channel1; - void *_icons1; - void *_icons2; - void *_tempCharset; - DreamGen::Frame *_currentCharset; +protected: + GameVars _vars; // saved variables + + // from backdrop.cpp + uint8 *_backdropBlocks; + BackdropMapFlag _backdropFlags[96]; + uint8 _mapData[kLengthOfMap + 32]; + + // from keypad.cpp + uint8 _pressList[6]; + uint8 _pressed; + uint16 _pressPointer; + uint8 _graphicPress; + uint8 _pressCount; + uint8 _lightCount; + uint8 _folderPage; + uint8 _diaryPage; + uint8 _menuCount; + uint8 _symbolTopX; + uint8 _symbolTopNum; + int8 _symbolTopDir; + uint8 _symbolBotX; + uint8 _symbolBotNum; + int8 _symbolBotDir; + + // from monitor.cpp + char _inputLine[64]; + char _operand1[14]; + char _currentFile[14]; + + // from newplace.cpp + uint8 _roomsCanGo[16]; + + // from object.cpp + uint16 _openChangeSize; + ObjectRef _oldSubject; + + // from pathfind.cpp + Common::Point _lineData[200]; // Output of Bresenham + + // from saveload.cpp + char _saveNames[17*21]; + char _saveNamesOld[17*21]; + + // from vgagrafx.cpp + uint8 _workspace[(0x1000 + 2) * 16]; + uint8 _mapStore[kLenOfMapStore + 32]; + + // from people.cpp + ReelRoutine _reelRoutines[kNumReelRoutines+1]; + ReelRoutine *_personData; + + // from Buffers + uint8 _textUnder[kUnderTextBufSize]; + ObjectRef _openInvList[16]; + ObjectRef _ryanInvList[30]; + uint8 _pointerBack[32*32]; + MapFlag _mapFlags[11*10]; + uint8 _startPal[3*256]; + uint8 _endPal[3*256]; + uint8 _mainPal[3*256]; + Common::List<Sprite> _spriteTable; + Common::List<ObjPos> _setList; + Common::List<ObjPos> _freeList; + Common::List<ObjPos> _exList; + Common::List<People> _peopleList; + uint8 _zoomSpace[46*40]; + // _printedList (unused?) + Change _listOfChanges[kNumChanges]; // Note: this array is saved + uint8 _underTimedText[kUnderTimedTextBufSize]; + Common::List<Rain> _rainList; + + // textfiles + TextFile _textFile1; + TextFile _textFile2; + TextFile _textFile3; + TextFile _travelText; + TextFile _puzzleText; + TextFile _commandText; + + // local graphics files + GraphicsFile _keypadGraphics; + GraphicsFile _menuGraphics; + GraphicsFile _menuGraphics2; + GraphicsFile _folderGraphics; + GraphicsFile _folderGraphics2; + GraphicsFile _folderGraphics3; + GraphicsFile _folderCharset; + GraphicsFile _symbolGraphics; + GraphicsFile _diaryGraphics; + GraphicsFile _diaryCharset; + GraphicsFile _monitorGraphics; + GraphicsFile _monitorCharset; + GraphicsFile _newplaceGraphics; + GraphicsFile _newplaceGraphics2; + GraphicsFile _newplaceGraphics3; + GraphicsFile _cityGraphics; + GraphicsFile _saveGraphics; + + // global graphics files + GraphicsFile _icons1; + GraphicsFile _icons2; + GraphicsFile _charset1; + GraphicsFile _mainSprites; + const GraphicsFile *_currentCharset; + + // room files + GraphicsFile _setFrames; + GraphicsFile _freeFrames; + GraphicsFile _reel1; + GraphicsFile _reel2; + GraphicsFile _reel3; + TextFile _setDesc; + TextFile _blockDesc; + TextFile _roomDesc; + TextFile _freeDesc; + TextFile _personText; + uint16 _personFramesLE[12]; + RoomPaths _pathData[36]; + Reel *_reelList; + SetObject _setDat[128]; + DynObject _freeDat[80]; + + // Extras segment (NB: this is saved) + GraphicsFile _exFrames; + DynObject _exData[kNumExObjects]; + TextFile _exText; + +public: + DreamWebEngine(/*DreamWeb::DreamWebEngine *en*/); + + bool _quitRequested; + bool _subtitles; + bool _foreignRelease; + + bool _wonGame; + bool _hasSpeech; + + // sound related + uint8 _roomsSample; + uint8 _currentSample; + uint8 _channel0Playing; + uint8 _channel0Repeat; + uint8 _channel1Playing; + + uint8 _volume; + uint8 _volumeTo; + int8 _volumeDirection; + uint8 _volumeCount; + + bool _speechLoaded; + + // misc variables + uint8 _speechCount; + uint16 _charShift; + uint8 _kerning; + bool _brightPalette; + uint8 _roomLoaded; + uint8 _didZoom; + uint16 _lineSpacing; + uint16 _textAddressX; + uint16 _textAddressY; + uint8 _textLen; + uint16 _lastXPos; + uint8 _itemFrame; + uint8 _withObject; + uint8 _withType; + uint16 _lookCounter; + uint8 _command; + uint8 _commandType; + uint8 _objectType; + uint8 _getBack; + uint8 _invOpen; + uint8 _mainMode; + uint8 _pickUp; + uint8 _lastInvPos; + uint8 _examAgain; + uint8 _newTextLine; + uint8 _openedOb; + uint8 _openedType; + uint16 _mapAdX; + uint16 _mapAdY; + uint16 _mapOffsetX; + uint16 _mapOffsetY; + uint16 _mapXStart; + uint16 _mapYStart; + uint8 _mapXSize; + uint8 _mapYSize; + uint8 _haveDoneObs; + uint8 _manIsOffScreen; + uint8 _facing; + uint8 _leaveDirection; + uint8 _turnToFace; + uint8 _turnDirection; + uint16 _mainTimer; + uint8 _introCount; + uint8 _currentKey; + uint8 _timerCount; + uint8 _mapX; + uint8 _mapY; + uint8 _ryanX; + uint8 _ryanY; + uint8 _lastFlag; + uint8 _destPos; + uint8 _realLocation; + uint8 _roomNum; + uint8 _nowInNewRoom; + uint8 _resetManXY; + uint8 _newLocation; + uint8 _autoLocation; + uint16 _mouseX; + uint16 _mouseY; + uint16 _mouseButton; + uint16 _oldButton; + uint16 _oldX; + uint16 _oldY; + uint16 _oldPointerX; + uint16 _oldPointerY; + uint16 _delHereX; + uint16 _delHereY; + uint8 _pointerXS; + uint8 _pointerYS; + uint8 _delXS; + uint8 _delYS; + uint8 _pointerFrame; + uint8 _pointerPower; + uint8 _pointerMode; + uint8 _pointerSpeed; + uint8 _pointerCount; + uint8 _inMapArea; + uint8 _talkMode; + uint8 _talkPos; + uint8 _character; + uint8 _watchDump; + uint8 _logoNum; + uint8 _oldLogoNum; + uint8 _walkAndExam; + uint8 _walkExamType; + uint8 _walkExamNum; + uint16 _cursLocX; + uint16 _cursLocY; + uint16 _curPos; + uint16 _monAdX; + uint16 _monAdY; + uint16 _timeCount; + uint8 _needToDumpTimed; + TimedTemp _previousTimedTemp; + TimedTemp _timedTemp; + uint8 _loadingOrSave; + uint8 _saveLoadPage; + uint8 _currentSlot; + uint8 _cursorPos; + uint8 _colourPos; + uint8 _fadeDirection; + uint8 _numToFade; + uint8 _fadeCount; + uint8 _addToGreen; + uint8 _addToRed; + uint8 _addToBlue; + uint16 _lastSoundReel; + uint8 _lastHardKey; + uint16 _bufferIn; + uint16 _bufferOut; + uint8 _blinkFrame; + uint8 _blinkCount; + uint8 _reAssesChanges; + uint8 _pointersPath; + uint8 _mansPath; + uint8 _pointerFirstPath; + uint8 _finalDest; + uint8 _destination; + uint16 _lineStartX; + uint16 _lineStartY; + uint16 _lineEndX; + uint16 _lineEndY; + uint8 _linePointer; + uint8 _lineDirection; + uint8 _lineLength; + + // from backdrop.cpp + void doBlocks(); + uint8 getXAd(const uint8 *setData, uint8 *result); + uint8 getYAd(const uint8 *setData, uint8 *result); + uint8 getMapAd(const uint8 *setData, uint16 *x, uint16 *y); + void calcFrFrame(const Frame &frame, uint8* width, uint8* height, uint16 x, uint16 y, ObjPos *objPos); + void makeBackOb(SetObject *objData, uint16 x, uint16 y); + void showAllObs(); + void getDimension(uint8 *mapXstart, uint8 *mapYstart, uint8 *mapXsize, uint8 *mapYsize); + void calcMapAd(); + void showAllFree(); + void drawFlags(); + void showAllEx(); + + // from keypad.cpp + void getUnderMenu(); + void putUnderMenu(); + void singleKey(uint8 key, uint16 x, uint16 y); + void loadKeypad(); + void showKeypad(); + bool isItRight(uint8 digit0, uint8 digit1, uint8 digit2, uint8 digit3); + void addToPressList(); + void buttonOne(); + void buttonTwo(); + void buttonThree(); + void buttonFour(); + void buttonFive(); + void buttonSix(); + void buttonSeven(); + void buttonEight(); + void buttonNine(); + void buttonNought(); + void buttonEnter(); + void buttonPress(uint8 buttonId); + void showOuterPad(); + void dumpKeypad(); + void dumpSymbol(); + void quitSymbol(); + void enterCode(uint8 digit0, uint8 digit1, uint8 digit2, uint8 digit3); + + // from monitor.cpp + void input(); + byte makeCaps(byte c); + void delChar(); + void monMessage(uint8 index); + void netError(); + void monitorLogo(); + void randomAccess(uint16 count); + void printOuterMon(); + void showCurrentFile(); + void accessLightOn(); + void accessLightOff(); + void turnOnPower(); + void powerLightOn(); + void powerLightOff(); + void printLogo(); + void scrollMonitor(); + const char *monPrint(const char *string); + void lockLightOn(); + void lockLightOff(); + void loadPersonal(); + void loadNews(); + void loadCart(); + void showKeys(); + const char *parser(); + const char *searchForString(const char *topic, const char *text); + const char *getKeyAndLogo(const char *foundString); + void read(); + void dirFile(const char *dirName); + void dirCom(); + void useMon(); + bool execCommand(); + + // from newplace.cpp + void getUnderCentre(); + void putUnderCentre(); + void showArrows(); + uint8 getLocation(uint8 index); + void setLocation(uint8 index); + void clearLocation(uint8 index); + void resetLocation(uint8 index); + void readCityPic(); + void readDestIcon(); + void showCity(); + void locationPic(); + void selectLocation(); + void newPlace(); + void nextDest(); + void lastDest(); + void destSelect(); + void lookAtPlace(); + + // from object.cpp + void obIcons(); + void fillRyan(); + void findAllRyan(); + void obToInv(uint8 index, uint8 flag, uint16 x, uint16 y); + void obPicture(); + void removeObFromInv(); + void deleteExObject(uint8 index); + void deleteExFrame(uint8 frameNum); + void deleteExText(uint8 textNum); + void purgeALocation(uint8 index); + const uint8 *getObTextStart(); + void wornError(); + void makeWorn(DynObject *object); + void dropObject(); + ObjectRef findOpenPos(); + byte getOpenedSlotSize(); + byte getOpenedSlotCount(); + void openOb(); + void findAllOpen(); + void fillOpen(); + ObjectRef findInvPos(); + void reExFromInv(); + void swapWithInv(); + void transferText(uint8 from, uint8 to); + void pickupConts(uint8 from, uint8 containerEx); + byte transferToEx(uint8 from); + void swapWithOpen(); + void outOfOpen(); + void inToInv(); + void outOfInv(); + bool checkObjectSize(); + void useOpened(); + void setPickup(); + void selectOpenOb(); + void examineOb(bool examineAgain = true); + void selectOb(); + void inventory(); + void identifyOb(); + + // from pathfind.cpp + void turnPathOn(uint8 param); + void turnPathOff(uint8 param); + void turnAnyPathOn(uint8 param, uint8 room); + void turnAnyPathOff(uint8 param, uint8 room); + RoomPaths *getRoomsPaths(); + void faceRightWay(); + void setWalk(); + void autoSetWalk(); + void checkDest(const RoomPaths *roomsPaths); + void findXYFromPath(); + bool checkIfPathIsOn(uint8 index); + void bresenhams(); + void workoutFrames(); + byte findFirstPath(byte x, byte y); + byte findPathOfPoint(byte x, byte y); + + // from people.cpp + void setupInitialReelRoutines(); + void updatePeople(); + void madmanText(); + void madman(ReelRoutine &routine); + void madMode(); + void addToPeopleList(ReelRoutine *routine); + bool checkSpeed(ReelRoutine &routine); + void sparkyDrip(ReelRoutine &routine); + void genericPerson(ReelRoutine &routine); + void gamer(ReelRoutine &routine); + void eden(ReelRoutine &routine); + void sparky(ReelRoutine &routine); + void rockstar(ReelRoutine &routine); + void madmansTelly(ReelRoutine &routine); + void smokeBloke(ReelRoutine &routine); + void manAsleep(ReelRoutine &routine); + void drunk(ReelRoutine &routine); + void introMagic1(ReelRoutine &routine); + void introMagic2(ReelRoutine &routine); + void introMagic3(ReelRoutine &routine); + void introMusic(ReelRoutine &routine); + void candles(ReelRoutine &routine); + void candles1(ReelRoutine &routine); + void candles2(ReelRoutine &routine); + void smallCandle(ReelRoutine &routine); + void gates(ReelRoutine &routine); + void security(ReelRoutine &routine); + void edenInBath(ReelRoutine &routine); + void louis(ReelRoutine &routine); + void handClap(ReelRoutine &routine); + void carParkDrip(ReelRoutine &routine); + void foghornSound(ReelRoutine &routine); + void train(ReelRoutine &routine); + void attendant(ReelRoutine &routine); + void keeper(ReelRoutine &routine); + void interviewer(ReelRoutine &routine); + void drinker(ReelRoutine &routine); + void alleyBarkSound(ReelRoutine &routine); + void louisChair(ReelRoutine &routine); + void bossMan(ReelRoutine &routine); + void priest(ReelRoutine &routine); + void monkAndRyan(ReelRoutine &routine); + void copper(ReelRoutine &routine); + void introMonks1(ReelRoutine &routine); + void introMonks2(ReelRoutine &routine); + void soldier1(ReelRoutine &routine); + void receptionist(ReelRoutine &routine); + void bartender(ReelRoutine &routine); + void heavy(ReelRoutine &routine); + void helicopter(ReelRoutine &routine); + void mugger(ReelRoutine &routine); + void businessMan(ReelRoutine &routine); + void endGameSeq(ReelRoutine &routine); + void poolGuard(ReelRoutine &routine); + + // from print.cpp + uint8 getNextWord(const GraphicsFile &charSet, const uint8 *string, uint8 *totalWidth, uint8 *charCount); + void printChar(const GraphicsFile &charSet, uint16 *x, uint16 y, uint8 c, uint8 nextChar, uint8 *width, uint8 *height); + void printChar(const GraphicsFile &charSet, uint16 x, uint16 y, uint8 c, uint8 nextChar, uint8 *width, uint8 *height); + void printBoth(const GraphicsFile &charSet, uint16 *x, uint16 y, uint8 c, uint8 nextChar); + uint8 printDirect(const uint8** string, uint16 x, uint16 *y, uint8 maxWidth, bool centered); + uint8 printDirect(const uint8* string, uint16 x, uint16 y, uint8 maxWidth, bool centered); + uint8 getNumber(const GraphicsFile &charSet, const uint8 *string, uint16 maxWidth, bool centered, uint16 *offset); + uint8 kernChars(uint8 firstChar, uint8 secondChar, uint8 width); + uint8 printSlow(const uint8 *string, uint16 x, uint16 y, uint8 maxWidth, bool centered); + uint16 waitFrames(); + void printCurs(); + void delCurs(); + void rollEndCreditsGameWon(); + void rollEndCreditsGameLost(); + + // from saveload.cpp + void loadGame(); + void doLoad(int slot); + void saveGame(); + void namesToOld(); + void oldToNames(); + void saveLoad(); + void doSaveLoad(); + void showMainOps(); + void showDiscOps(); + void discOps(); + void actualSave(); + void actualLoad(); + void loadPosition(unsigned int slot); + void savePosition(unsigned int slot, const char *descbuf); + uint scanForNames(); + void loadOld(); + void showDecisions(); + void loadSaveBox(); + void showNames(); + void checkInput(); + void selectSaveLoadPage(); + void selectSlot(); + void showSlots(); + void showOpBox(); + void showSaveOps(); + void showLoadOps(); + + // from sound.cpp + bool loadSpeech(byte type1, int idx1, byte type2, int idx2); + void volumeAdjust(); + void cancelCh0(); + void cancelCh1(); + void loadRoomsSample(); + void playChannel0(uint8 index, uint8 repeat); + void playChannel1(uint8 index); + + // from sprite.cpp + void printSprites(); + void printASprite(const Sprite *sprite); + void clearSprites(); + Sprite *makeSprite(uint8 x, uint8 y, bool _mainManCallback, const GraphicsFile *frameData); + void initMan(); + void walking(Sprite *sprite); + void aboutTurn(Sprite *sprite); + void backObject(Sprite *sprite); + void constant(Sprite *sprite, SetObject *objData); + void randomSprite(Sprite *sprite, SetObject *objData); + void doorway(Sprite *sprite, SetObject *objData); + void wideDoor(Sprite *sprite, SetObject *objData); + void doDoor(Sprite *sprite, SetObject *objData, Common::Rect check); + void steady(Sprite *sprite, SetObject *objData); + void lockedDoorway(Sprite *sprite, SetObject *objData); + void liftSprite(Sprite *sprite, SetObject *objData); + + Reel *getReelStart(uint16 reelPointer); + const GraphicsFile *findSource(uint16 &frame); + void showReelFrame(Reel *reel); + void showGameReel(ReelRoutine *routine); + const Frame *getReelFrameAX(uint16 frame); + void moveMap(uint8 param); + void checkOne(uint8 x, uint8 y, uint8 *flag, uint8 *flagEx, uint8 *type, uint8 *flagX, uint8 *flagY); + + uint8 getBlockOfPixel(uint8 x, uint8 y); + void splitIntoLines(uint8 x, uint8 y); + void initRain(); + + void intro1Text(); + void intro2Text(uint16 nextReelPointer); + void intro3Text(uint16 nextReelPointer); + + void monks2text(); + void textForEnd(); + void textForMonkHelper(uint8 textIndex, uint8 voiceIndex, uint8 x, uint8 y, uint16 countToTimed, uint16 timeCount); + void textForMonk(); + void priestText(ReelRoutine &routine); + void soundOnReels(uint16 reelPointer); + void clearBeforeLoad(); + void clearReels(); + void getRidOfReels(); + void liftNoise(uint8 index); + void checkForExit(Sprite *sprite); + void mainMan(Sprite *sprite); + void spriteUpdate(); + void showRain(); + void reconstruct(); + void reelsOnScreen(); + + // from stubs.cpp + void setupInitialVars(); + void crosshair(); + void delTextLine(); + void showBlink(); + void dumpBlink(); + void dumpPointer(); + void showPointer(); + void delPointer(); + void showRyanPage(); + void switchRyanOn(); + void switchRyanOff(); + void middlePanel(); + void showDiary(); + void readMouse(); + uint16 readMouseState(); + void hangOn(uint16 frameCount); + void lockMon(); + uint8 *textUnder(); + void readKey(); + void findOrMake(uint8 index, uint8 value, uint8 type); + DynObject *getFreeAd(uint8 index); + DynObject *getExAd(uint8 index); + DynObject *getEitherAd(); + void *getAnyAdDir(uint8 index, uint8 flag); + void showWatch(); + void showTime(); + void showExit(); + void showMan(); + void panelIcons1(); + SetObject *getSetAd(uint8 index); + void *getAnyAd(uint8 *slotSize, uint8 *slotCount); + const uint8 *getTextInFile1(uint16 index); + uint8 findNextColon(const uint8 **string); + void allocateBuffers(); + void loadTextFile(TextFile &file, const char *suffix); + void loadGraphicsFile(GraphicsFile &file, const char *suffix); + void loadGraphicsSegment(GraphicsFile &file, Common::File &inFile, unsigned int len); + void loadTextSegment(TextFile &file, Common::File &inFile, unsigned int len); + void loadTravelText(); + void loadTempText(const char *suffix); + void sortOutMap(); + void loadRoomData(const Room &room, bool skipDat); + void useTempCharset(GraphicsFile *charset); + void useCharset1(); + void printMessage(uint16 x, uint16 y, uint8 index, uint8 maxWidth, bool centered); + void printMessage2(uint16 x, uint16 y, uint8 index, uint8 maxWidth, bool centered, uint8 count); + bool isItDescribed(const ObjPos *objPos); + void zoomIcon(); + void roomName(); + void showIcon(); + void eraseOldObs(); + void commandOnlyCond(uint8 command, uint8 commandType); + void commandOnly(uint8 command); + void commandWithOb(uint8 command, uint8 type, uint8 index); + void blank(); + void setTopLeft(); + void setTopRight(); + void setBotLeft(); + void setBotRight(); + void examIcon(); + void animPointer(); + void getFlagUnderP(uint8 *flag, uint8 *flagEx); + void workToScreenM(); + void quitKey(); + void restoreReels(); + void loadFolder(); + void folderHints(); + void folderExit(); + void showFolder(); + void showLeftPage(); + void showRightPage(); + void underTextLine(); + void hangOnP(uint16 count); + void getUnderZoom(); + void putUnderZoom(); + void examineInventory(); + void openInv(); + void getBack1(); + void getBackFromOb(); + void getBackFromOps(); + void getBackToOps(); + void DOSReturn(); + bool isItWorn(const DynObject *object); + bool compare(uint8 index, uint8 flag, const char id[4]); + void hangOnW(uint16 frameCount); + void getRidOfTempText(); + void getRidOfAll(); + void placeSetObject(uint8 index); + void removeSetObject(uint8 index); + bool isSetObOnMap(uint8 index); + void dumpZoom(); + void diaryKeyP(); + void diaryKeyN(); + void findRoomInLoc(); + void loadMenu(); + void showMenu(); + void dumpMenu(); + void dealWithSpecial(uint8 firstParam, uint8 secondParam); + void plotReel(uint16 &reelPointer); + void setupTimedTemp(uint8 textIndex, uint8 voiceIndex, uint8 x, uint8 y, uint16 countToTimed, uint16 timeCount); + void getUnderTimed(); + void putUnderTimed(); + void dumpTextLine(); + void useTimedText(); + void dumpTimedText(); + void getTime(); + void doChange(uint8 index, uint8 value, uint8 type); + bool isRyanHolding(const char *id); + void clearBuffers(); + void clearChanges(); + void drawFloor(); + uint16 findSetObject(const char *id); + void hangOnCurs(uint16 frameCount); + const uint8 *findObName(uint8 type, uint8 index); + void copyName(uint8 type, uint8 index, uint8 *dst); + uint16 findExObject(const char *id); + void makeMainScreen(); + void showWatchReel(); + void watchReel(); + void examineObText(); + void blockNameText(); + void personNameText(); + void walkToText(); + void entryTexts(); + void setAllChanges(); + void restoreAll(); + void redrawMainScrn(); + void checkCoords(const RectWithCallback *rectWithCallbacks); + void newGame(); + void deleteTaken(); + void autoAppear(); + void loadRoom(); + void startLoading(const Room &room); + void startup(); + void atmospheres(); + bool objectMatches(void *object, const char *id); + void checkFolderCoords(); + void nextFolder(); + void lastFolder(); + void lookAtCard(); + void obsThatDoThings(); + void describeOb(); + void putBackObStuff(); + void reExFromOpen(); + void showDiaryPage(); + void showDiaryKeys(); + void dumpDiaryKeys(); + void useMenu(); + void incRyanPage(); + void edensFlatReminders(); + void dropError(); + void cantDrop(); + void entryAnims(); + bool finishedWalking(); + void emergencyPurge(); + void purgeAnItem(); + uint8 nextSymbol(uint8 symbol); + void enterSymbol(); + void showSymbol(); + void updateSymbolTop(); + void updateSymbolBot(); + void pickupOb(uint8 command, uint8 pos); + void errorMessage1(); + void errorMessage2(); + void errorMessage3(); + void decide(); + void allPointer(); + void dumpWatch(); + void watchCount(); + void signOn(); + void searchForFiles(const char *filesString); + void triggerMessage(uint16 index); + void processTrigger(); + void dreamwebFinalize(); + void dreamweb(); + void screenUpdate(); + void startup1(); + void readOneBlock(); + bool checkIfPerson(uint8 x, uint8 y); + bool checkIfFree(uint8 x, uint8 y); + bool checkIfEx(uint8 x, uint8 y); + void walkAndExamine(); + void obName(uint8 command, uint8 commandType); + bool checkIfSet(uint8 x, uint8 y); + void readSetData(); + void look(); + void autoLook(); + void doLook(); + void mainScreen(); + void zoomOnOff(); + void initialInv(); + void walkIntoRoom(); + void afterNewRoom(); + void madmanRun(); + void showGun(); + + // from talk.cpp + void talk(); + void convIcons(); + uint16 getPersFrame(uint8 index); + const uint8 *getPersonText(uint8 index, uint8 talkPos); + void startTalk(); + void moreTalk(); + void doSomeTalk(); + bool hangOnPQ(); + void redes(); + + // from titles.cpp + void endGame(); + void monkSpeaking(); + void gettingShot(); + void bibleQuote(); + void hangOne(uint16 delay); + void intro(); + void runIntroSeq(); + void runEndSeq(); + void loadIntroRoom(); + void set16ColPalette(); + void realCredits(); + uint8 getExPos(); + + // from use.cpp + void useRoutine(); + void useObject(); + void placeFreeObject(uint8 index); + void removeFreeObject(uint8 index); + void setupTimedUse(uint16 offset, uint16 countToTimed, uint16 timeCount, byte x, byte y); + void withWhat(); + uint16 checkInside(uint16 command, uint16 type); + void showPuzText(uint16 command, uint16 count); + void useText(const uint8 *string); + void showFirstUse(); + void showSecondUse(); + void viewFolder(); + void edensCDPlayer(); + void hotelBell(); + void playGuitar(); + void useElevator1(); + void useElevator2(); + void useElevator3(); + void useElevator4(); + void useElevator5(); + void useHatch(); + void wheelSound(); + void callHotelLift(); + void useShield(); + void useCoveredBox(); + void useRailing(); + void useChurchHole(); + void sitDownInBar(); + void useBalcony(); + void useWindow(); + void trapDoor(); + void useDryer(); + void callEdensDLift(); + void callEdensLift(); + void openYourNeighbour(); + void openRyan(); + void openPoolBoss(); + void openEden(); + void openSarters(); + void openLouis(); + void useWall(); + void useChurchGate(); + void useLadder(); + void useLadderB(); + bool defaultUseHandler(const char *id); + void slabDoorA(); + void slabDoorB(); + void slabDoorC(); + void slabDoorE(); + void slabDoorD(); + void slabDoorF(); + void useGun(); + void useFullCart(); + void useClearBox(); + void openTVDoor(); + void usePlate(); + void usePlinth(); + void useElvDoor(); + void useWinch(); + void useCart(); + void useHole(); + void openHotelDoor(); + void openHotelDoor2(); + void grafittiDoor(); + void useCardReader1(); + void useCardReader2(); + void useCardReader3(); + void usePoolReader(); + void useLighter(); + void useWire(); + void openTomb(); + void hotelControl(); + void useCooker(); + void useDiary(); + void useControl(); + void useSlab(); + void usePipe(); + void useOpenBox(); + void runTap(); + void useAxe(); + void useHandle(); + void useAltar(); + void notHeldError(); + void useCashCard(); + void useButtonA(); + void wearWatch(); + void wearShades(); + void useTrainer(); + void useStereo(); + void chewy(); + void delEverything(); + void afterIntroRoom(); + + // from vgafades.cpp + void clearStartPal(); + void clearEndPal(); + void palToStartPal(); + void endPalToStart(); + void startPalToEnd(); + void palToEndPal(); + void fadeDOS(); + void doFade(); + void fadeCalculation(); + void fadeUpYellows(); + void fadeUpMonFirst(); + void fadeUpMon(); + void fadeDownMon(); + void initialMonCols(); + void fadeScreenUp(); + void fadeScreenUps(); + void fadeScreenUpHalf(); + void fadeScreenDown(); + void fadeScreenDowns(); + void fadeScreenDownHalf(); + void clearPalette(); + void greyscaleSum(); + void allPalette(); + void dumpCurrent(); + + // from vgagrafx.cpp + inline uint8 *workspace() { return _workspace; } + void clearWork(); - DreamGen::DreamGenContext _context; - DreamGen::DreamBase &_base; + void panelToMap(); + void mapToPanel(); + void dumpMap(); + void transferFrame(uint8 from, uint8 to, uint8 offset); + void zoom(); + void multiGet(uint8 *dst, uint16 x, uint16 y, uint8 width, uint8 height); + void multiPut(const uint8 *src, uint16 x, uint16 y, uint8 width, uint8 height); + void multiDump(uint16 x, uint16 y, uint8 width, uint8 height); + void workToScreen(); + void frameOutV(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, int16 x, int16 y); + void frameOutNm(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y); + void frameOutBh(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y); + void frameOutFx(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y); + void doShake(); + void vSync(); + void setMode(); + void showPCX(const Common::String &suffix); + void showFrameInternal(const uint8 *pSrc, uint16 x, uint16 y, uint8 effectsFlag, uint8 width, uint8 height); + void showFrame(const GraphicsFile &frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag, uint8 *width, uint8 *height); + void showFrame(const GraphicsFile &frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag); + bool pixelCheckSet(const ObjPos *pos, uint8 x, uint8 y); + void loadPalFromIFF(); + void createPanel(); + void createPanel2(); + void showPanel(); }; } // End of namespace DreamWeb diff --git a/engines/dreamweb/keypad.cpp b/engines/dreamweb/keypad.cpp index 09bdcb837b..2ab5835997 100644 --- a/engines/dreamweb/keypad.cpp +++ b/engines/dreamweb/keypad.cpp @@ -22,91 +22,26 @@ #include "dreamweb/dreamweb.h" -namespace DreamGen { +namespace DreamWeb { -void DreamGenContext::getUnderMenu() { - multiGet(getSegment(data.word(kBuffers)).ptr(kUndertimedtext, 0), kMenux, kMenuy, 48, 48); -} - -void DreamGenContext::putUnderMenu() { - multiPut(getSegment(data.word(kBuffers)).ptr(kUndertimedtext, 0), kMenux, kMenuy, 48, 48); -} - -void DreamGenContext::singleKey(uint8 key, uint16 x, uint16 y) { - if (key == data.byte(kGraphicpress)) { - key += 11; - if (data.byte(kPresscount) < 8) - key -= 11; - } - key -= 20; - showFrame(tempGraphics(), x, y, key, 0); -} +const uint16 kKeypadx = 36+112; +const uint16 kKeypady = 72; -void DreamGenContext::loadKeypad() { - loadIntoTemp("DREAMWEB.G02"); -} - -void DreamGenContext::showKeypad() { - singleKey(22, kKeypadx+9, kKeypady+5); - singleKey(23, kKeypadx+31, kKeypady+5); - singleKey(24, kKeypadx+53, kKeypady+5); - singleKey(25, kKeypadx+9, kKeypady+23); - singleKey(26, kKeypadx+31, kKeypady+23); - singleKey(27, kKeypadx+53, kKeypady+23); - singleKey(28, kKeypadx+9, kKeypady+41); - singleKey(29, kKeypadx+31, kKeypady+41); - singleKey(30, kKeypadx+53, kKeypady+41); - singleKey(31, kKeypadx+9, kKeypady+59); - singleKey(32, kKeypadx+31, kKeypady+59); - if (data.byte(kLightcount)) { - --data.byte(kLightcount); - uint8 frameIndex; - uint16 y; - if (data.byte(kLockstatus)) { - frameIndex = 36; - y = kKeypady-1+63; - } else { - frameIndex = 41; - y = kKeypady+4+63; - } - if ((data.byte(kLightcount) >= 60) && (data.byte(kLightcount) < 100)) - --frameIndex; - showFrame(tempGraphics(), kKeypadx+60, y, frameIndex, 0); - } -} - -bool DreamGenContext::isItRight(uint8 digit0, uint8 digit1, uint8 digit2, uint8 digit3) { - - return digit0 == data.byte(kPresslist+0) && digit1 == data.byte(kPresslist+1) - && digit2 == data.byte(kPresslist+2) && digit3 == data.byte(kPresslist+3); -} - -void DreamGenContext::addToPressList() { - if (data.word(kPresspointer) == 5) - return; - uint8 pressed = data.byte(kPressed); - if (pressed == 10) - pressed = 0; - - data.byte(kPresslist + data.word(kPresspointer)) = pressed; - ++data.word(kPresspointer); -} - -void DreamGenContext::enterCode(uint8 digit0, uint8 digit1, uint8 digit2, uint8 digit3) { +void DreamWebEngine::enterCode(uint8 digit0, uint8 digit1, uint8 digit2, uint8 digit3) { RectWithCallback keypadList[] = { - { kKeypadx+9,kKeypadx+30,kKeypady+9,kKeypady+22,&DreamGenContext::buttonOne }, - { kKeypadx+31,kKeypadx+52,kKeypady+9,kKeypady+22,&DreamGenContext::buttonTwo }, - { kKeypadx+53,kKeypadx+74,kKeypady+9,kKeypady+22,&DreamGenContext::buttonThree }, - { kKeypadx+9,kKeypadx+30,kKeypady+23,kKeypady+40,&DreamGenContext::buttonFour }, - { kKeypadx+31,kKeypadx+52,kKeypady+23,kKeypady+40,&DreamGenContext::buttonFive }, - { kKeypadx+53,kKeypadx+74,kKeypady+23,kKeypady+40,&DreamGenContext::buttonSix }, - { kKeypadx+9,kKeypadx+30,kKeypady+41,kKeypady+58,&DreamGenContext::buttonSeven }, - { kKeypadx+31,kKeypadx+52,kKeypady+41,kKeypady+58,&DreamGenContext::buttonEight }, - { kKeypadx+53,kKeypadx+74,kKeypady+41,kKeypady+58,&DreamGenContext::buttonNine }, - { kKeypadx+9,kKeypadx+30,kKeypady+59,kKeypady+73,&DreamGenContext::buttonNought }, - { kKeypadx+31,kKeypadx+74,kKeypady+59,kKeypady+73,&DreamGenContext::buttonEnter }, - { kKeypadx+72,kKeypadx+86,kKeypady+80,kKeypady+94,&DreamGenContext::quitKey }, - { 0,320,0,200,&DreamGenContext::blank }, + { kKeypadx+9,kKeypadx+30,kKeypady+9,kKeypady+22,&DreamWebEngine::buttonOne }, + { kKeypadx+31,kKeypadx+52,kKeypady+9,kKeypady+22,&DreamWebEngine::buttonTwo }, + { kKeypadx+53,kKeypadx+74,kKeypady+9,kKeypady+22,&DreamWebEngine::buttonThree }, + { kKeypadx+9,kKeypadx+30,kKeypady+23,kKeypady+40,&DreamWebEngine::buttonFour }, + { kKeypadx+31,kKeypadx+52,kKeypady+23,kKeypady+40,&DreamWebEngine::buttonFive }, + { kKeypadx+53,kKeypadx+74,kKeypady+23,kKeypady+40,&DreamWebEngine::buttonSix }, + { kKeypadx+9,kKeypadx+30,kKeypady+41,kKeypady+58,&DreamWebEngine::buttonSeven }, + { kKeypadx+31,kKeypadx+52,kKeypady+41,kKeypady+58,&DreamWebEngine::buttonEight }, + { kKeypadx+53,kKeypadx+74,kKeypady+41,kKeypady+58,&DreamWebEngine::buttonNine }, + { kKeypadx+9,kKeypadx+30,kKeypady+59,kKeypady+73,&DreamWebEngine::buttonNought }, + { kKeypadx+31,kKeypadx+74,kKeypady+59,kKeypady+73,&DreamWebEngine::buttonEnter }, + { kKeypadx+72,kKeypadx+86,kKeypady+80,kKeypady+94,&DreamWebEngine::quitKey }, + { 0,320,0,200,&DreamWebEngine::blank }, { 0xFFFF,0,0,0,0 } }; @@ -118,150 +53,814 @@ void DreamGenContext::enterCode(uint8 digit0, uint8 digit1, uint8 digit2, uint8 showKeypad(); readMouse(); showPointer(); - workToScreenCPP(); + workToScreen(); delPointer(); - data.word(kPresspointer) = 0; - data.byte(kGetback) = 0; + _pressPointer = 0; + _getBack = 0; while (true) { delPointer(); readMouse(); showKeypad(); showPointer(); vSync(); - if (data.byte(kPresscount) == 0) { - data.byte(kPressed) = 255; - data.byte(kGraphicpress) = 255; + if (_pressCount == 0) { + _pressed = 255; + _graphicPress = 255; vSync(); } else - --data.byte(kPresscount); + --_pressCount; dumpPointer(); dumpKeypad(); dumpTextLine(); checkCoords(keypadList); - if (quitRequested() || (data.byte(kGetback) == 1)) + if (_quitRequested || (_getBack == 1)) break; - if (data.byte(kLightcount) == 1) { - if (data.byte(kLockstatus) == 0) + if (_lightCount == 1) { + if (_vars._lockStatus == 0) break; } else { - if (data.byte(kPresscount) == 40) { + if (_pressCount == 40) { addToPressList(); - if (data.byte(kPressed) == 11) { + if (_pressed == 11) { if (isItRight(digit0, digit1, digit2, digit3)) - data.byte(kLockstatus) = 0; + _vars._lockStatus = 0; playChannel1(11); - data.byte(kLightcount) = 120; - data.word(kPresspointer) = 0; + _lightCount = 120; + _pressPointer = 0; } } } } - data.byte(kManisoffscreen) = 0; - getRidOfTemp(); + _manIsOffScreen = 0; + _keypadGraphics.clear(); restoreReels(); redrawMainScrn(); workToScreenM(); } -void DreamGenContext::buttonOne() { +// Note: isItRight comes from use.asm, but is only used by enterCode(), +// so we place it here. +bool DreamWebEngine::isItRight(uint8 digit0, uint8 digit1, uint8 digit2, uint8 digit3) { + + return digit0 == _pressList[0] && digit1 == _pressList[1] + && digit2 == _pressList[2] && digit3 == _pressList[3]; +} + +void DreamWebEngine::loadKeypad() { + loadGraphicsFile(_keypadGraphics, "G02"); +} + +void DreamWebEngine::quitKey() { + commandOnlyCond(4, 222); + + if (_mouseButton != _oldButton && (_mouseButton & 1)) + _getBack = 1; +} + +void DreamWebEngine::addToPressList() { + if (_pressPointer == 5) + return; + uint8 pressed = _pressed; + if (pressed == 10) + pressed = 0; + + _pressList[_pressPointer] = pressed; + ++_pressPointer; +} + +void DreamWebEngine::buttonOne() { buttonPress(1); } -void DreamGenContext::buttonTwo() { +void DreamWebEngine::buttonTwo() { buttonPress(2); } -void DreamGenContext::buttonThree() { +void DreamWebEngine::buttonThree() { buttonPress(3); } -void DreamGenContext::buttonFour() { +void DreamWebEngine::buttonFour() { buttonPress(4); } -void DreamGenContext::buttonFive() { +void DreamWebEngine::buttonFive() { buttonPress(5); } -void DreamGenContext::buttonSix() { +void DreamWebEngine::buttonSix() { buttonPress(6); } -void DreamGenContext::buttonSeven() { +void DreamWebEngine::buttonSeven() { buttonPress(7); } -void DreamGenContext::buttonEight() { +void DreamWebEngine::buttonEight() { buttonPress(8); } -void DreamGenContext::buttonNine() { +void DreamWebEngine::buttonNine() { buttonPress(9); } -void DreamGenContext::buttonNought() { +void DreamWebEngine::buttonNought() { buttonPress(10); } -void DreamGenContext::buttonEnter() { +void DreamWebEngine::buttonEnter() { buttonPress(11); } -void DreamGenContext::buttonPress(uint8 buttonId) { - uint8 commandType = 100 + buttonId; - if (data.byte(kCommandtype) != commandType) { - data.byte(kCommandtype) = commandType; - commandOnly(buttonId + 4); - } - if ((data.word(kMousebutton) & 1) && (data.word(kMousebutton) != data.word(kOldbutton))) { - data.byte(kPressed) = buttonId; - data.byte(kGraphicpress) = buttonId + 21; - data.byte(kPresscount) = 40; +void DreamWebEngine::buttonPress(uint8 buttonId) { + commandOnlyCond(buttonId + 4, buttonId + 100); + if ((_mouseButton & 1) && (_mouseButton != _oldButton)) { + _pressed = buttonId; + _graphicPress = buttonId + 21; + _pressCount = 40; if (buttonId != 11) playChannel1(10); } } -void DreamGenContext::showOuterPad() { - showFrame(tempGraphics(), kKeypadx-3, kKeypady-4, 1, 0); - showFrame(tempGraphics(), kKeypadx+74, kKeypady+76, 37, 0); +void DreamWebEngine::showOuterPad() { + showFrame(_keypadGraphics, kKeypadx-3, kKeypady-4, 1, 0); + showFrame(_keypadGraphics, kKeypadx+74, kKeypady+76, 37, 0); } -void DreamGenContext::dumpKeypad() { +void DreamWebEngine::showKeypad() { + singleKey(22, kKeypadx+9, kKeypady+5); + singleKey(23, kKeypadx+31, kKeypady+5); + singleKey(24, kKeypadx+53, kKeypady+5); + singleKey(25, kKeypadx+9, kKeypady+23); + singleKey(26, kKeypadx+31, kKeypady+23); + singleKey(27, kKeypadx+53, kKeypady+23); + singleKey(28, kKeypadx+9, kKeypady+41); + singleKey(29, kKeypadx+31, kKeypady+41); + singleKey(30, kKeypadx+53, kKeypady+41); + singleKey(31, kKeypadx+9, kKeypady+59); + singleKey(32, kKeypadx+31, kKeypady+59); + if (_lightCount) { + --_lightCount; + uint8 frameIndex; + uint16 y; + if (_vars._lockStatus) { + frameIndex = 36; + y = kKeypady-1+63; + } else { + frameIndex = 41; + y = kKeypady+4+63; + } + if ((_lightCount >= 60) && (_lightCount < 100)) + --frameIndex; + showFrame(_keypadGraphics, kKeypadx+60, y, frameIndex, 0); + } +} + +void DreamWebEngine::singleKey(uint8 key, uint16 x, uint16 y) { + if (key == _graphicPress) { + key += 11; + if (_pressCount < 8) + key -= 11; + } + key -= 20; + showFrame(_keypadGraphics, x, y, key, 0); +} + +void DreamWebEngine::dumpKeypad() { multiDump(kKeypadx - 3, kKeypady - 4, 120, 90); } -void DreamGenContext::dumpSymbol() { - data.byte(kNewtextline) = 0; - multiDump(kSymbolx, kSymboly + 20, 104, 60); +void DreamWebEngine::useMenu() { + getRidOfReels(); + loadMenu(); + createPanel(); + showPanel(); + showIcon(); + _vars._newObs = 0; + drawFloor(); + printSprites(); + showFrame(_menuGraphics2, kMenux-48, kMenuy-4, 4, 0); + getUnderMenu(); + showFrame(_menuGraphics2, kMenux+54, kMenuy+72, 5, 0); + workToScreenM(); + _getBack = 0; + do { + delPointer(); + putUnderMenu(); + showMenu(); + readMouse(); + showPointer(); + vSync(); + dumpPointer(); + dumpMenu(); + dumpTextLine(); + RectWithCallback menuList[] = { + { kMenux+54,kMenux+68,kMenuy+72,kMenuy+88,&DreamWebEngine::quitKey }, + { 0,320,0,200,&DreamWebEngine::blank }, + { 0xFFFF,0,0,0,0 } + }; + checkCoords(menuList); + } while ((_getBack != 1) && !_quitRequested); + _manIsOffScreen = 0; + redrawMainScrn(); + _menuGraphics.clear(); + _menuGraphics2.clear(); + restoreReels(); + workToScreenM(); +} + +void DreamWebEngine::dumpMenu() { + multiDump(kMenux, kMenuy, 48, 48); +} + +void DreamWebEngine::getUnderMenu() { + multiGet(_underTimedText, kMenux, kMenuy, 48, 48); +} + +void DreamWebEngine::putUnderMenu() { + multiPut(_underTimedText, kMenux, kMenuy, 48, 48); +} + +// Note: showoutermenu from the asm version was unused and thus not placed here + +void DreamWebEngine::showMenu() { + ++_menuCount; + if (_menuCount == 37*2) + _menuCount = 0; + showFrame(_menuGraphics, kMenux, kMenuy, _menuCount / 2, 0); +} + +void DreamWebEngine::loadMenu() { + loadGraphicsFile(_menuGraphics, "S02"); // sprite name 3 + loadGraphicsFile(_menuGraphics2, "G07"); // mon. graphics 2 +} + +void DreamWebEngine::viewFolder() { + _manIsOffScreen = 1; + getRidOfAll(); + loadFolder(); + _folderPage = 0; + showFolder(); + workToScreenM(); + _getBack = 0; + do { + if (_quitRequested) + break; + delPointer(); + readMouse(); + showPointer(); + vSync(); + dumpPointer(); + dumpTextLine(); + checkFolderCoords(); + } while (_getBack == 0); + _manIsOffScreen = 0; + _folderGraphics.clear(); + _folderGraphics2.clear(); + _folderGraphics3.clear(); + _folderCharset.clear(); + restoreAll(); + redrawMainScrn(); + workToScreenM(); } -void DreamGenContext::dumpSymBox() { - if (data.word(kDumpx) != 0xFFFF) { - multiDump(data.word(kDumpx), data.word(kDumpy), 30, 77); - data.word(kDumpx) = 0xFFFF; +void DreamWebEngine::nextFolder() { + if (_folderPage == 12) { + blank(); + return; + } + commandOnlyCond(16, 201); + if ((_mouseButton == 1) && (_mouseButton != _oldButton)) { + ++_folderPage; + folderHints(); + delPointer(); + showFolder(); + _mouseButton = 0; + checkFolderCoords(); + workToScreenM(); } } -void DreamGenContext::quitSymbol() { - if (data.byte(kSymboltopx) != 24 || data.byte(kSymbolbotx) != 24) { +void DreamWebEngine::folderHints() { + if (_folderPage == 5) { + if ((_vars._aideDead != 1) && (getLocation(13) != 1)) { + setLocation(13); + showFolder(); + const uint8 *string = getTextInFile1(30); + printDirect(string, 0, 86, 141, true); + workToScreenM(); + hangOnP(200); + } + } else if (_folderPage == 9) { + if (getLocation(7) != 1) { + setLocation(7); + showFolder(); + const uint8 *string = getTextInFile1(31); + printDirect(string, 0, 86, 141, true); + workToScreenM(); + hangOnP(200); + } + } +} + +void DreamWebEngine::lastFolder() { + if (_folderPage == 0) { blank(); return; + } + commandOnlyCond(17, 202); + + if ((_mouseButton == 1) && (_mouseButton != _oldButton)) { + --_folderPage; + delPointer(); + showFolder(); + _mouseButton = 0; + checkFolderCoords(); + workToScreenM(); + } +} + +void DreamWebEngine::checkFolderCoords() { + RectWithCallback folderList[] = { + { 280,320,160,200, &DreamWebEngine::quitKey }, + { 143,300,6,194, &DreamWebEngine::nextFolder }, + { 0,143,6,194, &DreamWebEngine::lastFolder }, + { 0,320,0,200, &DreamWebEngine::blank }, + { 0xFFFF,0,0,0, 0 } }; + checkCoords(folderList); +} + +void DreamWebEngine::loadFolder() { + loadGraphicsFile(_folderGraphics, "G09"); // folder graphics 1 + loadGraphicsFile(_folderGraphics2, "G10"); // folder graphics 2 + loadGraphicsFile(_folderGraphics3, "G11"); // folder graphics 3 + loadGraphicsFile(_folderCharset, "C02"); // character set 3 + loadTempText("T50"); // folder text +} + +void DreamWebEngine::showFolder() { + _commandType = 255; + if (_folderPage) { + useTempCharset(&_folderCharset); + createPanel2(); + showFrame(_folderGraphics, 0, 0, 0, 0); + showFrame(_folderGraphics, 143, 0, 1, 0); + showFrame(_folderGraphics, 0, 92, 2, 0); + showFrame(_folderGraphics, 143, 92, 3, 0); + folderExit(); + if (_folderPage != 1) + showLeftPage(); + if (_folderPage != 12) + showRightPage(); + useCharset1(); + underTextLine(); + } else { + createPanel2(); + showFrame(_folderGraphics3, 143-28, 0, 0, 0); + showFrame(_folderGraphics3, 143-28, 92, 1, 0); + folderExit(); + underTextLine(); + } +} + +void DreamWebEngine::folderExit() { + showFrame(_folderGraphics2, 296, 178, 6, 0); +} + +void DreamWebEngine::showLeftPage() { + showFrame(_folderGraphics2, 0, 12, 3, 0); + uint16 y = 12+5; + for (size_t i = 0; i < 9; ++i) { + showFrame(_folderGraphics2, 0, y, 4, 0); + y += 16; + } + showFrame(_folderGraphics2, 0, y, 5, 0); + _lineSpacing = 8; + _charShift = 91; + _kerning = 1; + uint8 pageIndex = _folderPage - 2; + const uint8 *string = getTextInFile1(pageIndex * 2); + y = 48; + for (size_t i = 0; i < 2; ++i) { + uint8 lastChar; + do { + lastChar = printDirect(&string, 2, &y, 140, false); + y += _lineSpacing; + } while (lastChar != '\0'); + } + _kerning = 0; + _charShift = 0; + _lineSpacing = 10; + uint8 *bufferToSwap = workspace() + (48*320)+2; + for (size_t i = 0; i < 120; ++i) { + for (size_t j = 0; j < 65; ++j) { + SWAP(bufferToSwap[j], bufferToSwap[130 - j]); + } + bufferToSwap += 320; + } +} + +void DreamWebEngine::showRightPage() { + showFrame(_folderGraphics2, 143, 12, 0, 0); + uint16 y = 12+37; + for (size_t i = 0; i < 7; ++i) { + showFrame(_folderGraphics2, 143, y, 1, 0); + y += 16; + } - if (data.byte(kCommandtype) != 222) { - data.byte(kCommandtype) = 222; - commandOnly(18); + showFrame(_folderGraphics2, 143, y, 2, 0); + _lineSpacing = 8; + _kerning = 1; + uint8 pageIndex = _folderPage - 1; + const uint8 *string = getTextInFile1(pageIndex * 2); + y = 48; + for (size_t i = 0; i < 2; ++i) { + uint8 lastChar; + do { + lastChar = printDirect(&string, 152, &y, 140, false); + y += _lineSpacing; + } while (lastChar != '\0'); } + _kerning = 0; + _lineSpacing = 10; +} + +void DreamWebEngine::enterSymbol() { + _manIsOffScreen = 1; + getRidOfReels(); + loadGraphicsFile(_symbolGraphics, "G12"); // symbol graphics + _symbolTopX = 24; + _symbolTopDir = 0; + _symbolBotX = 24; + _symbolBotDir = 0; + redrawMainScrn(); + showSymbol(); + underTextLine(); + workToScreenM(); + _getBack = 0; + do { + delPointer(); + updateSymbolTop(); + updateSymbolBot(); + showSymbol(); + readMouse(); + showPointer(); + vSync(); + dumpPointer(); + dumpTextLine(); + dumpSymbol(); + RectWithCallback symbolList[] = { + { kSymbolx+40,kSymbolx+64,kSymboly+2,kSymboly+16,&DreamWebEngine::quitSymbol }, + { kSymbolx,kSymbolx+52,kSymboly+20,kSymboly+50,&DreamWebEngine::setTopLeft }, + { kSymbolx+52,kSymbolx+104,kSymboly+20,kSymboly+50,&DreamWebEngine::setTopRight }, + { kSymbolx,kSymbolx+52,kSymboly+50,kSymboly+80,&DreamWebEngine::setBotLeft }, + { kSymbolx+52,kSymbolx+104,kSymboly+50,kSymboly+80,&DreamWebEngine::setBotRight }, + { 0,320,0,200,&DreamWebEngine::blank }, + { 0xFFFF,0,0,0,0 } + }; + checkCoords(symbolList); + } while ((_getBack == 0) && !_quitRequested); + if ((_symbolBotNum == 3) && (_symbolTopNum == 5)) { + removeSetObject(43); + placeSetObject(46); + turnAnyPathOn(0, _roomNum + 12); + _manIsOffScreen = 0; + redrawMainScrn(); + _symbolGraphics.clear(); + restoreReels(); + workToScreenM(); + playChannel1(13); + } else { + removeSetObject(46); + placeSetObject(43); + turnAnyPathOff(0, _roomNum + 12); + _manIsOffScreen = 0; + redrawMainScrn(); + _symbolGraphics.clear(); + restoreReels(); + workToScreenM(); + } +} + +void DreamWebEngine::quitSymbol() { + if (_symbolTopX != 24 || _symbolBotX != 24) { + blank(); + return; + }; - if (data.word(kMousebutton) == data.word(kOldbutton)) + commandOnlyCond(18, 222); + + if (_mouseButton == _oldButton) return; // notqs - if (!(data.word(kMousebutton) & 1)) + if (!(_mouseButton & 1)) + return; + + _getBack = 1; +} + +void DreamWebEngine::setTopLeft() { + if (_symbolTopDir != 0) { + blank(); + return; + } + + commandOnlyCond(19, 210); + + if (_mouseButton != 0) + _symbolTopDir = -1; +} + +void DreamWebEngine::setTopRight() { + if (_symbolTopDir != 0) { + blank(); + return; + } + + commandOnlyCond(20, 211); + + if (_mouseButton != 0) + _symbolTopDir = +1; +} + +void DreamWebEngine::setBotLeft() { + if (_symbolBotDir != 0) { + blank(); return; + } + + commandOnlyCond(21, 212); + + if (_mouseButton != 0) + _symbolBotDir = -1; +} + +void DreamWebEngine::setBotRight() { + if (_symbolBotDir != 0) { + blank(); + return; + } + + commandOnlyCond(22, 213); + + if (_mouseButton != 0) + _symbolBotDir = +1; +} + +void DreamWebEngine::dumpSymbol() { + _newTextLine = 0; + multiDump(kSymbolx, kSymboly + 20, 104, 60); +} + +void DreamWebEngine::showSymbol() { + showFrame(_symbolGraphics, kSymbolx, kSymboly, 12, 0); + + showFrame(_symbolGraphics, _symbolTopX + kSymbolx-44, kSymboly+20, _symbolTopNum, 32); + uint8 nextTopSymbol = nextSymbol(_symbolTopNum); + showFrame(_symbolGraphics, _symbolTopX + kSymbolx+5, kSymboly+20, nextTopSymbol, 32); + uint8 nextNextTopSymbol = nextSymbol(nextTopSymbol); + showFrame(_symbolGraphics, _symbolTopX + kSymbolx+54, kSymboly+20, nextNextTopSymbol, 32); + + showFrame(_symbolGraphics, _symbolBotX + kSymbolx-44, kSymboly+49, 6 + _symbolBotNum, 32); + uint8 nextBotSymbol = nextSymbol(_symbolBotNum); + showFrame(_symbolGraphics, _symbolBotX + kSymbolx+5, kSymboly+49, 6 + nextBotSymbol, 32); + uint8 nextNextBotSymbol = nextSymbol(nextBotSymbol); + showFrame(_symbolGraphics, _symbolBotX + kSymbolx+54, kSymboly+49, 6 + nextNextBotSymbol, 32); +} + +uint8 DreamWebEngine::nextSymbol(uint8 symbol) { + uint8 result = symbol + 1; + if (result == 6) + return 0; + if (result == 12) + return 6; + return result; +} + +void DreamWebEngine::updateSymbolTop() { + if (!_symbolTopDir) + return; // topfinished + + if (_symbolTopDir == -1) { + // Backward + _symbolTopX--; + if (_symbolTopX != (byte)-1) { + // Not wrapping + if (_symbolTopX != 24) + return; // topfinished + _symbolTopDir = 0; + } else { + _symbolTopX = 48; + _symbolTopNum++; + if (_symbolTopNum != 6) + return; // topfinished + _symbolTopNum = 0; + } + } else { + // Forward + _symbolTopX++; + if (_symbolTopX != 49) { + // Not wrapping + if (_symbolTopX != 24) + return; // topfinished + _symbolTopDir = 0; + } else { + _symbolTopX = 0; + _symbolTopNum--; + if (_symbolTopNum != (byte)-1) + return; // topfinished + _symbolTopNum = 5; + } + } +} + +void DreamWebEngine::updateSymbolBot() { + if (!_symbolBotDir) + return; // botfinished + + if (_symbolBotDir == -1) { + // Backward + _symbolBotX--; + if (_symbolBotX != (byte)-1) { + // Not wrapping + if (_symbolBotX != 24) + return; // botfinished + _symbolBotDir = 0; + } else { + _symbolBotX = 48; + _symbolBotNum++; + if (_symbolBotNum != 6) + return; // botfinished + _symbolBotNum = 0; + } + } else { + // Forward + _symbolBotX++; + if (_symbolBotX != 49) { + // Not wrapping + if (_symbolBotX != 24) + return; // botfinished + _symbolBotDir = 0; + } else { + _symbolBotX = 0; + _symbolBotNum--; + if (_symbolBotNum != (byte)-1) + return; // botfinished + _symbolBotNum = 5; + } + } +} + +void DreamWebEngine::useDiary() { + getRidOfReels(); + loadGraphicsFile(_diaryGraphics, "G14"); + loadTempText("T51"); + loadGraphicsFile(_diaryCharset, "C02"); + createPanel(); + showIcon(); + showDiary(); + underTextLine(); + showDiaryPage(); + readMouse(); + showPointer(); + workToScreen(); + delPointer(); + _getBack = 0; + + RectWithCallback diaryList[] = { + { kDiaryx+94,kDiaryx+110,kDiaryy+97,kDiaryy+113,&DreamWebEngine::diaryKeyN }, + { kDiaryx+151,kDiaryx+167,kDiaryy+71,kDiaryy+87,&DreamWebEngine::diaryKeyP }, + { kDiaryx+176,kDiaryx+192,kDiaryy+108,kDiaryy+124,&DreamWebEngine::quitKey }, + { 0,320,0,200,&DreamWebEngine::blank }, + { 0xFFFF,0,0,0,0 } + }; + + do { + delPointer(); + readMouse(); + showDiaryKeys(); + showPointer(); + vSync(); + dumpPointer(); + dumpDiaryKeys(); + dumpTextLine(); + checkCoords(diaryList); + } while (!_getBack && !_quitRequested); + + + _diaryGraphics.clear(); + getRidOfTempText(); + _diaryCharset.clear(); + restoreReels(); + _manIsOffScreen = 0; + redrawMainScrn(); + workToScreenM(); +} + +void DreamWebEngine::showDiary() { + showFrame(_diaryGraphics, kDiaryx, kDiaryy + 37, 1, 0); + showFrame(_diaryGraphics, kDiaryx + 176, kDiaryy + 108, 2, 0); +} + +void DreamWebEngine::showDiaryKeys() { + if (!_pressCount) + return; // nokeyatall + + _pressCount--; + + if (!_pressCount) + return; // nokeyatall + + if (_pressed == 'N') { + byte frame = (_pressCount == 1) ? 3 : 4; + showFrame(_diaryGraphics, kDiaryx + 94, kDiaryy + 97, frame, 0); + } else { + byte frame = (_pressCount == 1) ? 5 : 6; + showFrame(_diaryGraphics, kDiaryx + 151, kDiaryy + 71, frame, 0); + } + + if (_pressCount == 1) + showDiaryPage(); +} + +void DreamWebEngine::dumpDiaryKeys() { + if (_pressCount == 1) { + if (_vars._sartainDead != 1 && _diaryPage == 5 && getLocation(6) != 1) { + // Add Sartain Industries note + setLocation(6); + delPointer(); + const uint8 *string = getTextInFile1(12); + printDirect(string, 70, 106, 241, 241 & 1); + workToScreenM(); + hangOnP(200); + createPanel(); + showIcon(); + showDiary(); + showDiaryPage(); + workToScreenM(); + showPointer(); + return; + } else { + multiDump(kDiaryx + 48, kDiaryy + 15, 200, 16); + } + } + + multiDump(kDiaryx + 94, kDiaryy + 97, 16, 16); + multiDump(kDiaryx + 151, kDiaryy + 71, 16, 16); +} + +void DreamWebEngine::diaryKeyP() { + commandOnlyCond(23, 214); + + if (!_mouseButton || + _oldButton == _mouseButton || + _pressCount) + return; // notkeyp + + playChannel1(16); + _pressCount = 12; + _pressed = 'P'; + _diaryPage--; + + if (_diaryPage == 0xFF) + _diaryPage = 11; +} + +void DreamWebEngine::diaryKeyN() { + commandOnlyCond(23, 213); + + if (!_mouseButton || + _oldButton == _mouseButton || + _pressCount) + return; // notkeyn + + playChannel1(16); + _pressCount = 12; + _pressed = 'N'; + _diaryPage++; + + if (_diaryPage == 12) + _diaryPage = 0; +} - data.byte(kGetback) = 1; +void DreamWebEngine::showDiaryPage() { + showFrame(_diaryGraphics, kDiaryx, kDiaryy, 0, 0); + _kerning = 1; + useTempCharset(&_diaryCharset); + _charShift = 91+91; + const uint8 *string = getTextInFile1(_diaryPage); + uint16 y = kDiaryy + 16; + printDirect(&string, kDiaryx + 48, &y, 240, 240 & 1); + y = kDiaryy + 16; + printDirect(&string, kDiaryx + 129, &y, 240, 240 & 1); + y = kDiaryy + 23; + printDirect(&string, kDiaryx + 48, &y, 240, 240 & 1); + _kerning = 0; + _charShift = 0; + useCharset1(); } -} // End of namespace DreamGen +} // End of namespace DreamWeb diff --git a/engines/dreamweb/module.mk b/engines/dreamweb/module.mk index 398f0b8db0..6bc4f8728e 100644 --- a/engines/dreamweb/module.mk +++ b/engines/dreamweb/module.mk @@ -5,18 +5,20 @@ MODULE_OBJS := \ console.o \ detection.o \ dreamweb.o \ - dreamgen.o \ keypad.o \ monitor.o \ + newplace.o \ object.o \ pathfind.o \ people.o \ print.o \ + rain.o \ saveload.o \ sound.o \ sprite.o \ stubs.o \ talk.o \ + titles.o \ use.o \ vgafades.o \ vgagrafx.o diff --git a/engines/dreamweb/monitor.cpp b/engines/dreamweb/monitor.cpp index f01664632a..95aa400c3a 100644 --- a/engines/dreamweb/monitor.cpp +++ b/engines/dreamweb/monitor.cpp @@ -22,44 +22,52 @@ #include "dreamweb/dreamweb.h" -namespace DreamGen { +namespace DreamWeb { struct MonitorKeyEntry { - uint8 b0; - uint8 b1; - char b2[24]; + uint8 keyAssigned; + char username[12]; + char password[12]; }; -void DreamGenContext::useMon() { - data.byte(kLasttrigger) = 0; - memset(data.ptr(kCurrentfile+1, 0), ' ', 12); - memset(data.ptr(offset_operand1+1, 0), ' ', 12); +// New monitor key list +static MonitorKeyEntry monitorKeyEntries[4] = { + { 1, "PUBLIC", "PUBLIC" }, + { 0, "RYAN", "BLACKDRAGON" }, + { 0, "LOUIS", "HENDRIX" }, + { 0, "BECKETT", "SEPTIMUS" } +}; + +void DreamWebEngine::useMon() { + _vars._lastTrigger = 0; + _currentFile[0] = 34; + memset(_currentFile+1, ' ', 12); + _currentFile[13] = 0; - MonitorKeyEntry *monitorKeyEntries = (MonitorKeyEntry *)data.ptr(offset_keys, 0); - monitorKeyEntries[0].b0 = 1; - monitorKeyEntries[1].b0 = 0; - monitorKeyEntries[2].b0 = 0; - monitorKeyEntries[3].b0 = 0; + monitorKeyEntries[0].keyAssigned = 1; + monitorKeyEntries[1].keyAssigned = 0; + monitorKeyEntries[2].keyAssigned = 0; + monitorKeyEntries[3].keyAssigned = 0; createPanel(); showPanel(); showIcon(); drawFloor(); getRidOfAll(); - loadIntoTemp("DREAMWEB.G03"); // mon. graphic name + loadGraphicsFile(_monitorGraphics, "G03"); // mon. graphic name loadPersonal(); loadNews(); loadCart(); - loadTempCharset("DREAMWEB.C01"); // character set 2 + loadGraphicsFile(_monitorCharset, "C01"); // character set 2 printOuterMon(); initialMonCols(); printLogo(); - workToScreenCPP(); + workToScreen(); turnOnPower(); - fadeupYellows(); - fadeupMonFirst(); - data.word(kMonadx) = 76; - data.word(kMonady) = 141; + fadeUpYellows(); + fadeUpMonFirst(); + _monAdX = 76; + _monAdY = 141; monMessage(1); hangOnCurs(120); monMessage(2); @@ -68,42 +76,109 @@ void DreamGenContext::useMon() { hangOnCurs(100); printLogo(); scrollMonitor(); - data.word(kBufferin) = 0; - data.word(kBufferout) = 0; + _bufferIn = 0; + _bufferOut = 0; + bool stop = false; do { - di = data.word(kMonadx); - bx = data.word(kMonady); - push(di); - push(bx); + uint16 oldMonadx = _monAdX; + uint16 oldMonady = _monAdY; input(); - bx = pop(); - di = pop(); - data.word(kMonadx) = di; - data.word(kMonady) = bx; - execCommand(); - if (quitRequested()) //TODO : Check why it crashes when put before the execcommand + _monAdX = oldMonadx; + _monAdY = oldMonady; + stop = execCommand(); + if (_quitRequested) //TODO : Check why it crashes when put before the execcommand break; - } while (al == 0); - getRidOfTemp(); - getRidOfTempCharset(); - deallocateMem(data.word(kTextfile1)); - deallocateMem(data.word(kTextfile2)); - deallocateMem(data.word(kTextfile3)); - data.byte(kGetback) = 1; + } while (!stop); + _monitorGraphics.clear(); + _monitorCharset.clear(); + + _textFile1.clear(); + _textFile2.clear(); + _textFile3.clear(); + + _getBack = 1; playChannel1(26); - data.byte(kManisoffscreen) = 0; + _manIsOffScreen = 0; restoreAll(); redrawMainScrn(); workToScreenM(); } -void DreamGenContext::monitorLogo() { - if (data.byte(kLogonum) != data.byte(kOldlogonum)) { - data.byte(kOldlogonum) = data.byte(kLogonum); +bool DreamWebEngine::execCommand() { + static const char *comlist[] = { + "EXIT", + "HELP", + "LIST", + "READ", + "LOGON", + "KEYS" + }; + + if (_inputLine[0] == 0) { + // No input + scrollMonitor(); + return false; + } + + int cmd; + bool done = false; + // Loop over all commands in the list and see if we get a match + for (cmd = 0; cmd < ARRAYSIZE(comlist); ++cmd) { + const char *cmdStr = comlist[cmd]; + const char *inputStr = _inputLine; + // Compare the command, char by char, to see if we get a match. + // We only care about the prefix matching, though. + char inputChar, cmdChar; + do { + inputChar = *inputStr; inputStr += 2; + cmdChar = *cmdStr++; + if (cmdChar == 0) { + done = true; + break; + } + } while (inputChar == cmdChar); + + if (done) + break; + } + + // Execute the selected command + switch (cmd) { + case 0: + return true; + case 1: + monMessage(6); + break; + case 2: + dirCom(); + break; + case 3: + read(); + break; + case 4: + signOn(); + break; + case 5: + showKeys(); + break; + default: + netError(); + break; + } + return false; +} + + + +void DreamWebEngine::monitorLogo() { + if (_logoNum != _oldLogoNum) { + _oldLogoNum = _logoNum; + //fadeDownMon(); // FIXME: Commented out in ASM printLogo(); - printUnderMon(); - workToScreenCPP(); + printUnderMonitor(); + workToScreen(); printLogo(); + //fadeUpMon(); // FIXME: Commented out in ASM printLogo(); playChannel1(26); randomAccess(20); @@ -112,140 +187,140 @@ void DreamGenContext::monitorLogo() { } } -void DreamBase::printLogo() { - showFrame(tempGraphics(), 56, 32, 0, 0); +void DreamWebEngine::printLogo() { + showFrame(_monitorGraphics, 56, 32, 0, 0); showCurrentFile(); } -void DreamGenContext::input() { - char *inputLine = (char *)data.ptr(kInputline, 64); - memset(inputLine, 0, 64); - data.word(kCurpos) = 0; - printChar(engine->tempCharset(), data.word(kMonadx), data.word(kMonady), '>', 0, NULL, NULL); - multiDump(data.word(kMonadx), data.word(kMonady), 6, 8); - data.word(kMonadx) += 6; - data.word(kCurslocx) = data.word(kMonadx); - data.word(kCurslocy) = data.word(kMonady); +void DreamWebEngine::input() { + memset(_inputLine, 0, 64); + _curPos = 0; + printChar(_monitorCharset, _monAdX, _monAdY, '>', 0, NULL, NULL); + multiDump(_monAdX, _monAdY, 6, 8); + _monAdX += 6; + _cursLocX = _monAdX; + _cursLocY = _monAdY; while (true) { printCurs(); vSync(); delCurs(); readKey(); - if (quitRequested()) + if (_quitRequested) return; - uint8 currentKey = data.byte(kCurrentkey); + uint8 currentKey = _currentKey; if (currentKey == 0) continue; if (currentKey == 13) return; if (currentKey == 8) { - if (data.word(kCurpos) > 0) + if (_curPos > 0) delChar(); continue; } - if (data.word(kCurpos) == 28) + if (_curPos == 28) continue; - if ((currentKey == 32) && (data.word(kCurpos) == 0)) + if ((currentKey == 32) && (_curPos == 0)) continue; - al = currentKey; - makeCaps(); - currentKey = al; - inputLine[data.word(kCurpos) * 2 + 0] = currentKey; + currentKey = makeCaps(currentKey); + _inputLine[_curPos * 2 + 0] = currentKey; if (currentKey > 'Z') continue; - multiGet(mapStore() + data.word(kCurpos) * 256, data.word(kMonadx), data.word(kMonady), 8, 8); + multiGet(_mapStore + _curPos * 256, _monAdX, _monAdY, 8, 8); uint8 charWidth; - printChar(engine->tempCharset(), data.word(kMonadx), data.word(kMonady), currentKey, 0, &charWidth, NULL); - inputLine[data.word(kCurpos) * 2 + 1] = charWidth; - data.word(kMonadx) += charWidth; - ++data.word(kCurpos); - data.word(kCurslocx) += charWidth; + printChar(_monitorCharset, _monAdX, _monAdY, currentKey, 0, &charWidth, NULL); + _inputLine[_curPos * 2 + 1] = charWidth; + _monAdX += charWidth; + ++_curPos; + _cursLocX += charWidth; } } -void DreamGenContext::delChar() { - char *inputLine = (char *)data.ptr(kInputline, 0); - --data.word(kCurpos); - inputLine[data.word(kCurpos) * 2] = 0; - uint8 width = inputLine[data.word(kCurpos) * 2 + 1]; - data.word(kMonadx) -= width; - data.word(kCurslocx) -= width; - uint16 offset = data.word(kCurpos); +byte DreamWebEngine::makeCaps(byte c) { + // TODO: Replace calls to this by toupper() ? + if (c >= 'a') + c -= 'a' - 'A'; // = 32 + return c; +} + +void DreamWebEngine::delChar() { + --_curPos; + _inputLine[_curPos * 2] = 0; + uint8 width = _inputLine[_curPos * 2 + 1]; + _monAdX -= width; + _cursLocX -= width; + uint16 offset = _curPos; offset = ((offset & 0x00ff) << 8) | ((offset & 0xff00) >> 8); - multiPut(mapStore() + offset, data.word(kMonadx), data.word(kMonady), 8, 8); - multiDump(data.word(kMonadx), data.word(kMonady), al, 8); + multiPut(_mapStore + offset, _monAdX, _monAdY, 8, 8); + multiDump(_monAdX, _monAdY, 8, 8); } -void DreamBase::printCurs() { - uint16 x = data.word(kCurslocx); - uint16 y = data.word(kCurslocy); +void DreamWebEngine::printCurs() { + uint16 x = _cursLocX; + uint16 y = _cursLocY; uint16 height; - if (data.byte(kForeignrelease)) { + if (_foreignRelease) { y -= 3; height = 11; } else height = 8; - multiGet(textUnder(), x, y, 6, height); - ++data.word(kMaintimer); - if ((data.word(kMaintimer) & 16) == 0) - showFrame(engine->tempCharset(), x, y, '/' - 32, 0); + multiGet(_textUnder, x, y, 6, height); + ++_mainTimer; + if ((_mainTimer & 16) == 0) + showFrame(_monitorCharset, x, y, '/' - 32, 0); multiDump(x - 6, y, 12, height); } -void DreamBase::delCurs() { - uint16 x = data.word(kCurslocx); - uint16 y = data.word(kCurslocy); +void DreamWebEngine::delCurs() { + uint16 x = _cursLocX; + uint16 y = _cursLocY; uint16 width = 6; uint16 height; - if (data.byte(kForeignrelease)) { + if (_foreignRelease) { y -= 3; height = 11; } else height = 8; - multiPut(textUnder(), x, y, width, height); + multiPut(_textUnder, x, y, width, height); multiDump(x, y, width, height); } -void DreamGenContext::hangOnCurs() { - hangOnCurs(cx); -} - -void DreamBase::scrollMonitor() { +void DreamWebEngine::scrollMonitor() { printLogo(); - printUnderMon(); - workToScreenCPP(); + printUnderMonitor(); + workToScreen(); playChannel1(25); } -void DreamBase::showCurrentFile() { - uint16 x = 178; // TODO: Looks like this hardcoded constant in the asm doesn't match the frame - const char *currentFile = (const char *)data.ptr(kCurrentfile+1, 0); +void DreamWebEngine::showCurrentFile() { + uint16 x; + // Monitor Frame position differs between Floppy and CD version + if (isCD()) + x = 178; + else + x = 199; + const char *currentFile = _currentFile + 1; while (*currentFile) { char c = *currentFile++; - c = engine->modifyChar(c); - printChar(engine->tempCharset(), &x, 37, c, 0, NULL, NULL); + c = modifyChar(c); + printChar(_monitorCharset, &x, 37, c, 0, NULL, NULL); } } -void DreamBase::accessLightOn() { - showFrame(tempGraphics(), 74, 182, 8, 0); +void DreamWebEngine::accessLightOn() { + showFrame(_monitorGraphics, 74, 182, 8, 0); multiDump(74, 182, 12, 8); } -void DreamBase::accessLightOff() { - showFrame(tempGraphics(), 74, 182, 7, 0); +void DreamWebEngine::accessLightOff() { + showFrame(_monitorGraphics, 74, 182, 7, 0); multiDump(74, 182, 12, 8); } -void DreamGenContext::randomAccess() { - randomAccess(cx); -} - -void DreamGenContext::randomAccess(uint16 count) { +void DreamWebEngine::randomAccess(uint16 count) { for (uint16 i = 0; i < count; ++i) { vSync(); vSync(); - uint16 v = engine->randomNumber() & 15; + uint16 v = _rnd.getRandomNumber(15); if (v < 10) accessLightOff(); else @@ -254,13 +329,9 @@ void DreamGenContext::randomAccess(uint16 count) { accessLightOff(); } -void DreamGenContext::monMessage() { - monMessage(al); -} - -void DreamGenContext::monMessage(uint8 index) { +void DreamWebEngine::monMessage(uint8 index) { assert(index > 0); - const char *string = (const char *)getSegment(data.word(kTextfile1)).ptr(kTextstart, 0); + const char *string = _textFile1._text; for (uint8 i = 0; i < index; ++i) { while (*string++ != '+') { } @@ -268,32 +339,32 @@ void DreamGenContext::monMessage(uint8 index) { monPrint(string); } -void DreamGenContext::netError() { +void DreamWebEngine::netError() { monMessage(5); scrollMonitor(); } -void DreamBase::powerLightOn() { - showFrame(tempGraphics(), 257+4, 182, 6, 0); +void DreamWebEngine::powerLightOn() { + showFrame(_monitorGraphics, 257+4, 182, 6, 0); multiDump(257+4, 182, 12, 8); } -void DreamBase::powerLightOff() { - showFrame(tempGraphics(), 257+4, 182, 5, 0); +void DreamWebEngine::powerLightOff() { + showFrame(_monitorGraphics, 257+4, 182, 5, 0); multiDump(257+4, 182, 12, 8); } -void DreamBase::lockLightOn() { - showFrame(tempGraphics(), 56, 182, 10, 0); +void DreamWebEngine::lockLightOn() { + showFrame(_monitorGraphics, 56, 182, 10, 0); multiDump(58, 182, 12, 8); } -void DreamBase::lockLightOff() { - showFrame(tempGraphics(), 56, 182, 9, 0); +void DreamWebEngine::lockLightOff() { + showFrame(_monitorGraphics, 56, 182, 9, 0); multiDump(58, 182, 12, 8); } -void DreamBase::turnOnPower() { +void DreamWebEngine::turnOnPower() { for (size_t i = 0; i < 3; ++i) { powerLightOn(); hangOn(30); @@ -303,45 +374,332 @@ void DreamBase::turnOnPower() { powerLightOn(); } -void DreamBase::printOuterMon() { - showFrame(tempGraphics(), 40, 32, 1, 0); - showFrame(tempGraphics(), 264, 32, 2, 0); - showFrame(tempGraphics(), 40, 12, 3, 0); - showFrame(tempGraphics(), 40, 164, 4, 0); +void DreamWebEngine::printOuterMon() { + showFrame(_monitorGraphics, 40, 32, 1, 0); + showFrame(_monitorGraphics, 264, 32, 2, 0); + showFrame(_monitorGraphics, 40, 12, 3, 0); + showFrame(_monitorGraphics, 40, 164, 4, 0); } -void DreamGenContext::loadPersonal() { - if (data.byte(kLocation) == 0 || data.byte(kLocation) == 42) - data.word(kTextfile1) = standardLoad("DREAMWEB.T01"); // monitor file 1 +void DreamWebEngine::loadPersonal() { + if (_vars._location == 0 || _vars._location == 42) + loadTextFile(_textFile1, "T01"); // monitor file 1 else - data.word(kTextfile1) = standardLoad("DREAMWEB.T02"); // monitor file 2 + loadTextFile(_textFile1, "T02"); // monitor file 2 } -void DreamGenContext::loadNews() { +void DreamWebEngine::loadNews() { // textfile2 holds information accessible by anyone - if (data.byte(kNewsitem) == 0) - data.word(kTextfile2) = standardLoad("DREAMWEB.T10"); // monitor file 10 - else if (data.byte(kNewsitem) == 1) - data.word(kTextfile2) = standardLoad("DREAMWEB.T11"); // monitor file 11 - else if (data.byte(kNewsitem) == 2) - data.word(kTextfile2) = standardLoad("DREAMWEB.T12"); // monitor file 12 + if (_vars._newsItem == 0) + loadTextFile(_textFile2, "T10"); // monitor file 10 + else if (_vars._newsItem == 1) + loadTextFile(_textFile2, "T11"); // monitor file 11 + else if (_vars._newsItem == 2) + loadTextFile(_textFile2, "T12"); // monitor file 12 else - data.word(kTextfile2) = standardLoad("DREAMWEB.T13"); // monitor file 13 + loadTextFile(_textFile2, "T13"); // monitor file 13 } -void DreamGenContext::loadCart() { - lookInInterface(); - - if (al == 0) - data.word(kTextfile3) = standardLoad("DREAMWEB.T20"); // monitor file 20 - else if (al == 1) - data.word(kTextfile3) = standardLoad("DREAMWEB.T21"); // monitor file 21 - else if (al == 2) - data.word(kTextfile3) = standardLoad("DREAMWEB.T22"); // monitor file 22 - else if (al == 3) - data.word(kTextfile3) = standardLoad("DREAMWEB.T23"); // monitor file 23 +void DreamWebEngine::loadCart() { + byte cartridgeId = 0; + uint16 objectIndex = findSetObject("INTF"); + uint16 cartridgeIndex = checkInside(objectIndex, 1); + if (cartridgeIndex != kNumexobjects) + cartridgeId = getExAd(cartridgeIndex)->objId[3] + 1; + + if (cartridgeId == 0) + loadTextFile(_textFile3, "T20"); // monitor file 20 + else if (cartridgeId == 1) + loadTextFile(_textFile3, "T21"); // monitor file 21 + else if (cartridgeId == 2) + loadTextFile(_textFile3, "T22"); // monitor file 22 + else if (cartridgeId == 3) + loadTextFile(_textFile3, "T23"); // monitor file 23 else - data.word(kTextfile3) = standardLoad("DREAMWEB.T24"); // monitor file 24 + loadTextFile(_textFile3, "T24"); // monitor file 24 +} + +void DreamWebEngine::showKeys() { + randomAccess(10); + scrollMonitor(); + monMessage(18); + + for (int i = 0; i < 4; i++) { + if (monitorKeyEntries[i].keyAssigned) + monPrint(monitorKeyEntries[i].username); + } + + scrollMonitor(); +} + +const char *DreamWebEngine::getKeyAndLogo(const char *foundString) { + byte newLogo = foundString[1] - 48; + byte keyNum = foundString[3] - 48; + + if (monitorKeyEntries[keyNum].keyAssigned == 1) { + // Key OK + _logoNum = newLogo; + return foundString + 4; + } else { + monMessage(12); // "Access denied, key required -" + monPrint(monitorKeyEntries[keyNum].username); + scrollMonitor(); + return 0; + } +} + +const char *DreamWebEngine::searchForString(const char *topic, const char *text) { + char delim = *topic; + + while (true) { + const char *s = topic; + int delimCount = 0; + + char c; + do { + c = makeCaps(*text++); + + if (c == '*' || (delim == '=' && c == 34)) + return 0; + + if (c == delim) { + delimCount++; + if (delimCount == 2) + return text; + } + + } while (c == *s++); + } +} + +void DreamWebEngine::dirCom() { + randomAccess(30); + + const char *dirname = parser(); + if (dirname[1]) { + dirFile(dirname); + return; + } + + _logoNum = 0; + memcpy(_currentFile+1, "ROOT ", 12); + monitorLogo(); + scrollMonitor(); + monMessage(9); + searchForFiles(_textFile1._text); + searchForFiles(_textFile2._text); + searchForFiles(_textFile3._text); + scrollMonitor(); +} + +void DreamWebEngine::dirFile(const char *dirName) { + char topic[14]; + + memcpy(topic, dirName, 14); + topic[0] = 34; + + const char *text = _textFile1._text; + const char *found = searchForString(topic, text); + if (!found) { + text = _textFile2._text; + found = searchForString(topic, text); + if (!found) { + text = _textFile3._text; + found = searchForString(topic, text); + } + } + + if (found) { + found = getKeyAndLogo(found); + if (!found) + return; // not logged in + } else { + monMessage(7); + return; + } + + // "keyok2" + memcpy(_currentFile+1, dirName+1, 12); + monitorLogo(); + scrollMonitor(); + monMessage(10); + + while (true) { + byte curChar = *found++; + if (curChar == 34 || curChar == '*') { + // "endofdir2" + scrollMonitor(); + return; + } + + if (curChar == '=') + found = monPrint(found); + } +} + +void DreamWebEngine::read() { + randomAccess(40); + const char *name = parser(); + if (name[1] == 0) { + netError(); + return; + } + + const char *topic = _currentFile; + + const char *text = _textFile1._text; + const char *found = searchForString(topic, text); + if (!found) { + text = _textFile2._text; + found = searchForString(topic, text); + if (!found) { + text = _textFile3._text; + found = searchForString(topic, text); + } + } + + if (found) { + if (!getKeyAndLogo(found)) + return; + } else { + monMessage(7); + return; + } + + // "keyok1" + found = searchForString(name, found); + if (!found) { + _logoNum = _oldLogoNum; + monMessage(11); + return; + } + + // "findtopictext" + monitorLogo(); + scrollMonitor(); + + found++; + + while (true) { + found = monPrint(found); + if (found[0] == 34 || found[0] == '=' || found[0] == '*') { + // "endoftopic" + scrollMonitor(); + return; + } + + processTrigger(); + randomAccess(24); + } +} + +void DreamWebEngine::signOn() { + const char *name = parser(); + + int8 foundIndex = -1; + Common::String inputLine = name + 1; + inputLine.trim(); + + for (byte i = 0; i < 4; i++) { + if (inputLine.equalsIgnoreCase(monitorKeyEntries[i].username)) { + // Check if the key has already been assigned + if (monitorKeyEntries[i].keyAssigned) { + monMessage(17); + return; + } else { + foundIndex = i; + break; + } + } + } + + if (foundIndex == -1) { + monMessage(13); + return; + } + + monMessage(15); + + uint16 prevX = _monAdX; + uint16 prevY = _monAdY; + input(); // password input + _monAdX = prevX; + _monAdY = prevY; + + inputLine = (const char *)_inputLine; + inputLine.toUppercase(); + + // The entered line has zeroes in-between each character + uint32 len = strlen(monitorKeyEntries[foundIndex].password); + bool found = true; + + for (uint32 i = 0; i < len; i++) { + if (monitorKeyEntries[foundIndex].password[i] != inputLine[i * 2]) { + found = false; + break; + } + } + + if (!found) { + scrollMonitor(); + monMessage(16); + } else { + monMessage(14); + monPrint(monitorKeyEntries[foundIndex].username); + scrollMonitor(); + monitorKeyEntries[foundIndex].keyAssigned = 1; + } +} + +void DreamWebEngine::searchForFiles(const char *filesString) { + byte curChar; + + while (true) { + curChar = filesString[0]; + filesString++; + if (curChar == '*') + return; // "endofdir" + if (curChar == 34) + filesString = monPrint(filesString); + } +} + +const char *DreamWebEngine::parser() { + char *output = _operand1; + + memset(output, 0, 14); + + *output++ = '='; + + const char *in = _inputLine; + + uint8 c; + + // skip command + do { + c = *in++; + in++; + + if (!c) + return output; + } while (c != 32); + + // skip spaces between command and operand + do { + c = *in++; + in++; + } while (c == 32); + + // copy first operand + do { + *output++ = c; + c = *in++; + in++; + if (!c) + return _operand1; + } while (c != 32); + + return _operand1; } -} // End of namespace DreamGen +} // End of namespace DreamWeb diff --git a/engines/dreamweb/newplace.cpp b/engines/dreamweb/newplace.cpp new file mode 100644 index 0000000000..529c45bd4a --- /dev/null +++ b/engines/dreamweb/newplace.cpp @@ -0,0 +1,271 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "dreamweb/dreamweb.h" + +namespace DreamWeb { + +void DreamWebEngine::newPlace() { + if (_vars._needToTravel == 1) { + _vars._needToTravel = 0; + selectLocation(); + } else if (_autoLocation != 0xFF) { + _newLocation = _autoLocation; + _autoLocation = 0xFF; + } +} + +void DreamWebEngine::selectLocation() { + _inMapArea = 0; + clearBeforeLoad(); + _getBack = 0; + _pointerFrame = 22; + readCityPic(); + showCity(); + _cityGraphics.clear(); + readDestIcon(); + loadTravelText(); + showPanel(); + showMan(); + showArrows(); + showExit(); + locationPic(); + underTextLine(); + _commandType = 255; + readMouse(); + _pointerFrame = 0; + showPointer(); + workToScreen(); + playChannel0(9, 255); + _newLocation = 255; + + while (_newLocation == 255) { + if (_quitRequested) + break; + + delPointer(); + readMouse(); + showPointer(); + vSync(); + dumpPointer(); + dumpTextLine(); + + if (_getBack == 1) + break; + + RectWithCallback destList[] = { + { 238,258,4,44,&DreamWebEngine::nextDest }, + { 104,124,4,44,&DreamWebEngine::lastDest }, + { 280,308,4,44,&DreamWebEngine::lookAtPlace }, + { 104,216,138,192,&DreamWebEngine::destSelect }, + { 273,320,157,198,&DreamWebEngine::getBack1 }, + { 0,320,0,200,&DreamWebEngine::blank }, + { 0xFFFF,0,0,0,0 } + }; + checkCoords(destList); + } + + if (_quitRequested || _getBack == 1 || _newLocation == _vars._location) { + _newLocation = _realLocation; + _getBack = 0; + } + + _newplaceGraphics.clear(); + _newplaceGraphics2.clear(); + _newplaceGraphics3.clear(); + + _travelText.clear(); +} + +void DreamWebEngine::showCity() { + clearWork(); + showFrame(_cityGraphics, 57, 32, 0, 0); + showFrame(_cityGraphics, 120+57, 32, 1, 0); +} + +void DreamWebEngine::lookAtPlace() { + commandOnlyCond(27, 224); + + if (!(_mouseButton & 1) || + _mouseButton == _oldButton || + _destPos >= 15) + return; // noinfo + + delPointer(); + delTextLine(); + getUnderCentre(); + showFrame(_newplaceGraphics3, 60, 72, 0, 0); + showFrame(_newplaceGraphics3, 60, 72 + 55, 4, 0); + if (_foreignRelease) + showFrame(_newplaceGraphics3, 60, 72+55+21, 4, 0); + + const uint8 *string = (const uint8 *)_travelText.getString(_destPos); + findNextColon(&string); + uint16 y = (_foreignRelease) ? 84 + 4 : 84; + printDirect(&string, 63, &y, 191, 191 & 1); + workToScreenM(); + hangOnP(500); + _pointerMode = 0; + _pointerFrame = 0; + putUnderCentre(); + workToScreenM(); +} + +void DreamWebEngine::getUnderCentre() { + multiGet(_mapStore, 58, 72, 254, 110); +} + +void DreamWebEngine::putUnderCentre() { + multiPut(_mapStore, 58, 72, 254, 110); +} + +void DreamWebEngine::locationPic() { + const int roomPics[] = { 5, 0, 3, 2, 4, 1, 10, 9, 8, 6, 11, 4, 7, 7, 0 }; + byte picture = roomPics[_destPos]; + + if (picture >= 6) + showFrame(_newplaceGraphics2, 104, 138 + 14, picture - 6, 0); // Second slot + else + showFrame(_newplaceGraphics, 104, 138 + 14, picture + 4, 0); + + if (_destPos == _realLocation) + showFrame(_newplaceGraphics, 104, 140 + 14, 3, 0); // Currently in this location + + const uint8 *string = (const uint8 *)_travelText.getString(_destPos); + printDirect(string, 50, 20, 241, 241 & 1); +} + +void DreamWebEngine::showArrows() { + showFrame(_newplaceGraphics, 116 - 12, 16, 0, 0); + showFrame(_newplaceGraphics, 226 + 12, 16, 1, 0); + showFrame(_newplaceGraphics, 280, 14, 2, 0); +} + +void DreamWebEngine::nextDest() { + commandOnlyCond(28, 218); + + if (!(_mouseButton & 1) || _oldButton == 1) + return; // nodu + + do { + _destPos++; + if (_destPos == 15) + _destPos = 0; // last destination + } while (!getLocation(_destPos)); + + _newTextLine = 1; + delTextLine(); + delPointer(); + showPanel(); + showMan(); + showArrows(); + locationPic(); + underTextLine(); + readMouse(); + showPointer(); + workToScreen(); + delPointer(); +} + +void DreamWebEngine::lastDest() { + commandOnlyCond(29, 219); + + if (!(_mouseButton & 1) || _oldButton == 1) + return; // nodd + + do { + _destPos--; + if (_destPos == 0xFF) + _destPos = 15; // first destination + } while (!getLocation(_destPos)); + + _newTextLine = 1; + delTextLine(); + delPointer(); + showPanel(); + showMan(); + showArrows(); + locationPic(); + underTextLine(); + readMouse(); + showPointer(); + workToScreen(); + delPointer(); +} + +void DreamWebEngine::destSelect() { + commandOnlyCond(30, 222); + + if (!(_mouseButton & 1) || _oldButton == 1) + return; // notrav + + _newLocation = _destPos; +} + +uint8 DreamWebEngine::getLocation(uint8 index) { + return _roomsCanGo[index]; +} + +void DreamWebEngine::setLocation(uint8 index) { + _roomsCanGo[index] = 1; +} + +void DreamWebEngine::clearLocation(uint8 index) { + _roomsCanGo[index] = 0; +} + +void DreamWebEngine::resetLocation(uint8 index) { + if (index == 5) { + // delete hotel + purgeALocation(5); + purgeALocation(21); + purgeALocation(22); + purgeALocation(27); + } else if (index == 8) { + // delete TV studio + purgeALocation(8); + purgeALocation(28); + } else if (index == 6) { + // delete sarters + purgeALocation(6); + purgeALocation(20); + purgeALocation(25); + } else if (index == 13) { + // delete boathouse + purgeALocation(13); + purgeALocation(29); + } + + clearLocation(index); +} + +void DreamWebEngine::readDestIcon() { + loadGraphicsFile(_newplaceGraphics, "G05"); + loadGraphicsFile(_newplaceGraphics2, "G06"); + loadGraphicsFile(_newplaceGraphics3, "G08"); +} + +void DreamWebEngine::readCityPic() { + loadGraphicsFile(_cityGraphics, "G04"); +} + +} // End of namespace DreamWeb diff --git a/engines/dreamweb/object.cpp b/engines/dreamweb/object.cpp index 53d834e74c..443366561a 100644 --- a/engines/dreamweb/object.cpp +++ b/engines/dreamweb/object.cpp @@ -22,32 +22,46 @@ #include "dreamweb/dreamweb.h" -namespace DreamGen { +namespace DreamWeb { -void DreamGenContext::fillRyan() { - uint8 *inv = getSegment(data.word(kBuffers)).ptr(kRyaninvlist, 60); - findAllRyan(inv); - inv += data.byte(kRyanpage) * 2 * 10; +void DreamWebEngine::showRyanPage() { + showFrame(_icons1, kInventx + 167, kInventy - 12, 12, 0); + showFrame(_icons1, kInventx + 167 + 18 * _vars._ryanPage, kInventy - 12, 13 + _vars._ryanPage, 0); +} + +void DreamWebEngine::findAllRyan() { + memset(_ryanInvList, 0xff, sizeof(_ryanInvList)); + for (size_t i = 0; i < kNumexobjects; ++i) { + const DynObject *extra = getExAd(i); + if (extra->mapad[0] != kExObjectType) + continue; + if (extra->mapad[1] != 0xff) + continue; + uint8 slot = extra->mapad[2]; + assert(slot < 30); + _ryanInvList[slot]._index = i; + _ryanInvList[slot]._type = kExObjectType; + } +} + +void DreamWebEngine::fillRyan() { + ObjectRef *inv = &_ryanInvList[_vars._ryanPage * 10]; + findAllRyan(); for (size_t i = 0; i < 2; ++i) { for (size_t j = 0; j < 5; ++j) { - uint8 objIndex = *inv++; - uint8 objType = *inv++; - obToInv(objIndex, objType, kInventx + j * kItempicsize, kInventy + i * kItempicsize); + obToInv(inv->_index, inv->_type, kInventx + j * kItempicsize, kInventy + i * kItempicsize); + ++inv; } } showRyanPage(); } -void DreamGenContext::isItWorn() { - flags._z = isItWorn((const DynObject *)es.ptr(bx, sizeof(DynObject))); +bool DreamWebEngine::isItWorn(const DynObject *object) { + return (object->objId[0] == 'W'-'A') && (object->objId[1] == 'E'-'A'); } -bool DreamGenContext::isItWorn(const DynObject *object) { - return (object->id[0] == 'W'-'A') && (object->id[1] == 'E'-'A'); -} - -void DreamGenContext::wornError() { - data.byte(kCommandtype) = 255; +void DreamWebEngine::wornError() { + _commandType = 255; delPointer(); printMessage(76, 21, 57, 240, false); workToScreenM(); @@ -55,75 +69,66 @@ void DreamGenContext::wornError() { showPanel(); showMan(); examIcon(); - data.byte(kCommandtype) = 255; + _commandType = 255; workToScreenM(); } -void DreamGenContext::makeWorn() { - makeWorn((DynObject *)es.ptr(bx, sizeof(DynObject))); -} - -void DreamGenContext::makeWorn(DynObject *object) { - object->id[0] = 'W'-'A'; - object->id[1] = 'E'-'A'; -} - -void DreamGenContext::obToInv() { - obToInv(al, ah, di, bx); +void DreamWebEngine::makeWorn(DynObject *object) { + object->objId[0] = 'W'-'A'; + object->objId[1] = 'E'-'A'; } -void DreamGenContext::obToInv(uint8 index, uint8 flag, uint16 x, uint16 y) { - showFrame(engine->icons1(), x - 2, y - 1, 10, 0); +void DreamWebEngine::obToInv(uint8 index, uint8 flag, uint16 x, uint16 y) { + showFrame(_icons1, x - 2, y - 1, 10, 0); if (index == 0xff) return; - Frame *extras = (Frame *)getSegment(data.word(kExtras)).ptr(0, 0); - Frame *frees = (Frame *)getSegment(data.word(kFreeframes)).ptr(0, 0); - Frame *frames = (flag == 4) ? extras : frees; - showFrame(frames, x + 18, y + 19, 3 * index + 1, 128); + if (flag == kExObjectType) + showFrame(_exFrames, x + 18, y + 19, 3 * index + 1, 128); + else + showFrame(_freeFrames, x + 18, y + 19, 3 * index + 1, 128); + const DynObject *object = (const DynObject *)getAnyAdDir(index, flag); bool worn = isItWorn(object); if (worn) - showFrame(engine->icons1(), x - 3, y - 2, 7, 0); + showFrame(_icons1, x - 3, y - 2, 7, 0); } -void DreamGenContext::obPicture() { - if (data.byte(kObjecttype) == 1) +void DreamWebEngine::obPicture() { + if (_objectType == kSetObjectType1) return; - Frame *frames; - if (data.byte(kObjecttype) == 4) - frames = (Frame *)getSegment(data.word(kExtras)).ptr(0, 0); + uint8 frame = 3 * _command + 1; + if (_objectType == kExObjectType) + showFrame(_exFrames, 160, 68, frame, 0x80); else - frames = (Frame *)getSegment(data.word(kFreeframes)).ptr(0, 0); - uint8 frame = 3 * data.byte(kCommand) + 1; - showFrame(frames, 160, 68, frame, 0x80); + showFrame(_freeFrames, 160, 68, frame, 0x80); } -void DreamBase::obIcons() { - uint8 value1, value2; - getAnyAd(&value1, &value2); - if (value1 != 0xff) { +void DreamWebEngine::obIcons() { + uint8 slotSize, slotCount; + getAnyAd(&slotSize, &slotCount); + if (slotSize != 0xff) { // can open it - showFrame(engine->icons2(), 210, 1, 4, 0); + showFrame(_icons2, 210, 1, 4, 0); } - showFrame(engine->icons2(), 260, 1, 1, 0); + showFrame(_icons2, 260, 1, 1, 0); } -void DreamGenContext::examineOb(bool examineAgain) { - data.byte(kPointermode) = 0; - data.word(kTimecount) = 0; +void DreamWebEngine::examineOb(bool examineAgain) { + _pointerMode = 0; + _timeCount = 0; + while (true) { if (examineAgain) { - data.byte(kInmaparea) = 0; - data.byte(kExamagain) = 0; - data.byte(kOpenedob) = 255; - data.byte(kOpenedtype) = 255; - data.byte(kInvopen) = 0; - al = data.byte(kCommandtype); - data.byte(kObjecttype) = al; - data.byte(kItemframe) = 0; - data.byte(kPointerframe) = 0; + _inMapArea = 0; + _examAgain = 0; + _openedOb = 255; + _openedType = 255; + _invOpen = 0; + _objectType = _commandType; + _itemFrame = 0; + _pointerFrame = 0; createPanel(); showPanel(); showMan(); @@ -132,10 +137,10 @@ void DreamGenContext::examineOb(bool examineAgain) { obPicture(); describeOb(); underTextLine(); - data.byte(kCommandtype) = 255; + _commandType = 255; readMouse(); showPointer(); - workToScreenCPP(); + workToScreen(); delPointer(); examineAgain = false; } @@ -146,30 +151,31 @@ void DreamGenContext::examineOb(bool examineAgain) { dumpPointer(); dumpTextLine(); delPointer(); - data.byte(kGetback) = 0; - switch (data.byte(kInvopen)) { + _getBack = 0; + + switch (_invOpen) { case 0: { RectWithCallback examList[] = { - { 273,320,157,198,&DreamGenContext::getBackFromOb }, - { 260,300,0,44,&DreamGenContext::useObject }, - { 210,254,0,44,&DreamGenContext::selectOpenOb }, - { 144,176,64,96,&DreamGenContext::setPickup }, - { 0,50,50,200,&DreamGenContext::examineInventory }, - { 0,320,0,200,&DreamGenContext::blank }, + { 273,320,157,198,&DreamWebEngine::getBackFromOb }, + { 260,300,0,44,&DreamWebEngine::useObject }, + { 210,254,0,44,&DreamWebEngine::selectOpenOb }, + { 144,176,64,96,&DreamWebEngine::setPickup }, + { 0,50,50,200,&DreamWebEngine::examineInventory }, + { 0,320,0,200,&DreamWebEngine::blank }, { 0xFFFF,0,0,0,0 } }; checkCoords(examList); break; } case 1: { - // NB: This table contains the non-constant openChangeSize! + // Note: This table contains the non-constant _openChangeSize! RectWithCallback invList1[] = { - { 273,320,157,198,&DreamGenContext::getBackFromOb }, - { 255,294,0,24,&DreamGenContext::dropObject }, - { kInventx+167,kInventx+167+(18*3),kInventy-18,kInventy-2,&DreamGenContext::incRyanPage }, - { kInventx, data.word(offset_openchangesize),kInventy+100,kInventy+100+kItempicsize,&DreamGenContext::useOpened }, - { kInventx,kInventx+(5*kItempicsize), kInventy,kInventy+(2*kItempicsize),&DreamGenContext::inToInv }, - { 0,320,0,200,&DreamGenContext::blank }, + { 273,320,157,198,&DreamWebEngine::getBackFromOb }, + { 255,294,0,24,&DreamWebEngine::dropObject }, + { kInventx+167,kInventx+167+(18*3),kInventy-18,kInventy-2,&DreamWebEngine::incRyanPage }, + { kInventx,_openChangeSize,kInventy+100,kInventy+100+kItempicsize,&DreamWebEngine::useOpened }, + { kInventx,kInventx+(5*kItempicsize),kInventy,kInventy+(2*kItempicsize),&DreamWebEngine::inToInv }, + { 0,320,0,200,&DreamWebEngine::blank }, { 0xFFFF,0,0,0,0 } }; checkCoords(invList1); @@ -177,55 +183,52 @@ void DreamGenContext::examineOb(bool examineAgain) { } default: { RectWithCallback withList1[] = { - { 273,320,157,198,&DreamGenContext::getBackFromOb }, - { kInventx+167,kInventx+167+(18*3),kInventy-18,kInventy-2,&DreamGenContext::incRyanPage }, - { kInventx,kInventx+(5*kItempicsize), kInventy,kInventy+(2*kItempicsize),&DreamGenContext::selectOb }, - { 0,320,0,200,&DreamGenContext::blank }, + { 273,320,157,198,&DreamWebEngine::getBackFromOb }, + { kInventx+167,kInventx+167+(18*3),kInventy-18,kInventy-2,&DreamWebEngine::incRyanPage }, + { kInventx,kInventx+(5*kItempicsize), kInventy,kInventy+(2*kItempicsize),&DreamWebEngine::selectOb }, + { 0,320,0,200,&DreamWebEngine::blank }, { 0xFFFF,0,0,0,0 } }; checkCoords(withList1); break; } } - if (data.byte(kQuitrequested) != 0) + + if (_quitRequested) break; - if (data.byte(kExamagain) != 0) + if (_examAgain != 0) examineAgain = true; - else if (data.byte(kGetback) != 0) + else if (_getBack != 0) break; } - data.byte(kPickup) = 0; - if (data.word(kWatchingtime) != 0 || data.byte(kNewlocation) == 255) { + _pickUp = 0; + if (_vars._watchingTime != 0 || _newLocation == 255) { // isWatching makeMainScreen(); } - data.byte(kInvopen) = 0; - data.byte(kOpenedob) = 255; + _invOpen = 0; + _openedOb = 255; } -void DreamGenContext::inventory() { - if (data.byte(kMandead) == 1 || data.word(kWatchingtime) != 0) { +void DreamWebEngine::inventory() { + if (_vars._manDead == 1 || _vars._watchingTime != 0) { blank(); return; } - if (data.byte(kCommandtype) != 239) { - data.byte(kCommandtype) = 239; - al = 32; - commandOnly(); - } + commandOnlyCond(32, 239); - if (data.word(kMousebutton) == data.word(kOldbutton)) + if (_mouseButton == _oldButton) return; - if (!(data.word(kMousebutton) & 1)) // only on left mouse button + if (!(_mouseButton & 1)) // only on left mouse button return; - data.word(kTimecount) = 0; - data.byte(kPointermode) = 0; - data.byte(kInmaparea) = 0; + _timeCount = 0; + _pointerMode = 0; + _inMapArea = 0; animPointer(); createPanel(); showPanel(); @@ -233,34 +236,870 @@ void DreamGenContext::inventory() { showMan(); showExit(); underTextLine(); - data.byte(kPickup) = 0; - data.byte(kInvopen) = 2; + _pickUp = 0; + _invOpen = 2; openInv(); readMouse(); showPointer(); - workToScreenCPP(); + workToScreen(); delPointer(); - data.byte(kOpenedob) = 255; + _openedOb = 255; examineOb(false); } -void DreamGenContext::transferText() { - getSegment(data.word(kExtras)).word(kExtextdat + data.byte(kExpos) * 2) = data.word(kExtextpos); - uint16 freeTextOffset = data.byte(kItemtotran) * 2; - uint16 srcOffset = getSegment(data.word(kFreedesc)).word(kFreetextdat + freeTextOffset); - const char *src = (const char *)getSegment(data.word(kFreedesc)).ptr(kFreetext + srcOffset, 0); - char *dst = (char *)getSegment(data.word(kExtras)).ptr(kExtext + data.word(kExtextpos), 0); +void DreamWebEngine::transferText(uint8 from, uint8 to) { + _exText.setOffset(to, _vars._exTextPos); + const char *src = _freeDesc.getString(from); + char *dst = _exText._text + _vars._exTextPos; size_t len = strlen(src); memcpy(dst, src, len + 1); - data.word(kExtextpos) += len + 1; + _vars._exTextPos += len + 1; } -void DreamGenContext::getBackFromOb() { - if (data.byte(kPickup) != 1) +void DreamWebEngine::getBackFromOb() { + if (_pickUp != 1) getBack1(); else blank(); } -} // End of namespace DreamGen +byte DreamWebEngine::getOpenedSlotCount() { + byte obj = _openedOb; + switch (_openedType) { + case kExObjectType: + return getExAd(obj)->slotCount; + case kFreeObjectType: + return getFreeAd(obj)->slotCount; + default: + return getSetAd(obj)->slotCount; + } +} + +byte DreamWebEngine::getOpenedSlotSize() { + byte obj = _openedOb; + switch (_openedType) { + case kExObjectType: + return getExAd(obj)->slotSize; + case kFreeObjectType: + return getFreeAd(obj)->slotSize; + default: + return getSetAd(obj)->slotSize; + } +} + +void DreamWebEngine::openOb() { + uint8 commandLine[64] = "OBJECT NAME ONE "; + + copyName(_openedType, _openedOb, commandLine); + + printMessage(kInventx, kInventy+86, 62, 240, false); + + printDirect(commandLine, _lastXPos + 5, kInventy+86, 220, false); + + fillOpen(); + _openChangeSize = getOpenedSlotCount() * kItempicsize + kInventx; +} + +void DreamWebEngine::identifyOb() { + if (_vars._watchingTime != 0) { + blank(); + return; + } + + uint16 initialX = _mouseX - _mapAdX; + uint16 initialY = _mouseY - _mapAdY; + + if (initialX >= 22 * 8 || initialY >= 20 * 8) { + blank(); + return; + } + + byte x = initialX & 0xFF; + byte y = initialY & 0xFF; + + _inMapArea = 1; + _pointersPath = findPathOfPoint(x, y); + _pointerFirstPath = findFirstPath(x, y); + + if (checkIfEx(x, y) || checkIfFree(x, y) || + checkIfPerson(x, y) || checkIfSet(x, y)) + return; // finishidentify + + x = (_mouseX - _mapAdX) & 0xFF; + y = (_mouseY - _mapAdY) & 0xFF; + byte flag, flagEx, type, flagX, flagY; + + checkOne(x, y, &flag, &flagEx, &type, &flagX, &flagY); + + if (type != 0 && _vars._manDead != 1) + obName(type, 3); + else + blank(); +} + +ObjectRef DreamWebEngine::findInvPos() { + uint16 x = _mouseX - kInventx; + uint16 y = _mouseY - kInventy; + uint8 pos = (x / kItempicsize) + (y / kItempicsize) * 5; + uint8 invPos = _vars._ryanPage * 10 + pos; + _lastInvPos = invPos; + return _ryanInvList[invPos]; +} + +void DreamWebEngine::selectOb() { + ObjectRef objectId = findInvPos(); + if (objectId._index == 255) { + blank(); + return; + } + + _withObject = objectId._index; + _withType = objectId._type; + + if (objectId != _oldSubject || _commandType != 221) { + if (objectId == _oldSubject) + _commandType = 221; + _oldSubject = objectId; + commandWithOb(0, objectId._type, objectId._index); + } + + if (_mouseButton == _oldButton || !(_mouseButton & 1)) + return; + + delPointer(); + _invOpen = 0; + useRoutine(); +} + +void DreamWebEngine::setPickup() { + if (_objectType != kSetObjectType1 && _objectType != kSetObjectType3) { + // Object types 1 and 3 are excluded, so the resulting object is a DynObject + uint8 dummy; + DynObject *object = (DynObject *)getAnyAd(&dummy, &dummy); + if (object->mapad[0] == 4) { + blank(); + return; + } + } else { + blank(); + return; + } + + if (_commandType != 209) { + _commandType = 209; + commandWithOb(33, _objectType, _command); + } + + if (_mouseButton != 1 || _mouseButton == _oldButton) + return; + + createPanel(); + showPanel(); + showMan(); + showExit(); + examIcon(); + _pickUp = 1; + _invOpen = 2; + + if (_objectType != kExObjectType) { + assert(_objectType == kFreeObjectType); + _openedOb = 255; + _itemFrame = transferToEx(_command); + _objectType = kExObjectType; + DynObject *object = getExAd(_itemFrame); + object->mapad[0] = 20; + object->mapad[1] = 255; + } else { + _itemFrame = _command; + _openedOb = 255; + } + + openInv(); + workToScreenM(); +} + +void DreamWebEngine::deleteExFrame(uint8 frameNum) { + Frame *frame = &_exFrames._frames[frameNum]; + + uint16 frameSize = frame->width * frame->height; + // Note: the original asm didn't subtract frameSize from remainder + uint16 remainder = kExframeslen - frame->ptr() - frameSize; + uint16 startOff = frame->ptr(); + uint16 endOff = startOff + frameSize; + + // Shift frame data after this one down + memmove(&_exFrames._data[startOff], &_exFrames._data[endOff], remainder); + + // Combined frame data is now frameSize smaller + _vars._exFramePos -= frameSize; + + // Adjust all frame pointers pointing into the shifted data + for (unsigned int i = 0; i < 3*kNumexobjects; ++i) { + frame = &_exFrames._frames[i]; + if (frame->ptr() >= startOff) + frame->setPtr(frame->ptr() - frameSize); + } +} + +void DreamWebEngine::deleteExText(uint8 textNum) { + uint16 offset = _exText.getOffset(textNum); + + uint16 startOff = offset; + uint16 textSize = strlen(_exText.getString(textNum)) + 1; + uint16 endOff = startOff + textSize; + uint16 remainder = kExtextlen - offset - textSize; + + // Shift text data after this one down + memmove(&_exText._text[startOff], &_exText._text[endOff], remainder); + + // Combined text data is now frameSize smaller + _vars._exTextPos -= textSize; + + // Adjust all text pointers pointing into the shifted data + for (unsigned int i = 0; i < kNumexobjects; ++i) { + uint16 t = _exText.getOffset(i); + if (t >= offset + textSize) + _exText.setOffset(i, t - textSize); + } +} + +void DreamWebEngine::deleteExObject(uint8 index) { + DynObject *obj = getExAd(index); + + memset(obj, 0xFF, sizeof(DynObject)); + + deleteExFrame(3*index); + deleteExFrame(3*index + 1); + + deleteExText(index); + + for (uint8 i = 0; i < kNumexobjects; ++i) { + DynObject *t = getExAd(i); + // Is this object contained in the one we've just deleted? + if (t->mapad[0] == 4 && t->mapad[1] == index) + deleteExObject(i); + } +} + +void DreamWebEngine::removeObFromInv() { + if (_command == 100) + return; // object doesn't exist + + assert(_objectType == kExObjectType); + + deleteExObject(_command); +} + +void DreamWebEngine::inToInv() { + if (!_pickUp) { + outOfInv(); + return; + } + + ObjectRef subject = findInvPos(); + + if (subject._index != 255) { + swapWithInv(); + return; + } + + subject._type = _objectType; + subject._index = _itemFrame; + + if (subject != _oldSubject || _commandType != 220) { + if (subject == _oldSubject) + _commandType = 220; + _oldSubject = subject; + commandWithOb(35, subject._type, subject._index); + } + + if (_mouseButton == _oldButton || !(_mouseButton & 1)) + return; // notletgo2 + + delPointer(); + DynObject *object = getExAd(_itemFrame); + object->mapad[0] = 4; + object->mapad[1] = 255; + object->mapad[2] = _lastInvPos; + _pickUp = 0; + fillRyan(); + readMouse(); + showPointer(); + outOfInv(); + workToScreen(); + delPointer(); +} + +void DreamWebEngine::outOfInv() { + ObjectRef subject = findInvPos(); + + if (subject._index == 255) { + blank(); + return; + } + + if (_mouseButton == 2) { + reExFromInv(); + return; + } + + if (subject != _oldSubject || _commandType != 221) { + if (subject == _oldSubject) + _commandType = 221; + _oldSubject = subject; + commandWithOb(36, subject._type, subject._index); + } + + if (_mouseButton == _oldButton || !(_mouseButton & 1)) + return; + + delPointer(); + _pickUp = 1; + subject = findInvPos(); + _objectType = subject._type; + _itemFrame = subject._index; + assert(subject._type == kExObjectType); + DynObject *object = getExAd(subject._index); + object->mapad[0] = 20; + object->mapad[1] = 255; + fillRyan(); + readMouse(); + showPointer(); + inToInv(); + workToScreen(); + delPointer(); +} + +void DreamWebEngine::purgeALocation(uint8 index) { + // index == al + for (uint8 i = 0; i < kNumexobjects; ++i) { + DynObject *t = getExAd(i); + if (t->currentLocation == index && t->mapad[0] == 0) { + deleteExObject(i); + } + } +} + +const uint8 *DreamWebEngine::getObTextStart() { + const uint8 *textBase = 0; + const uint8 *text; + uint16 textOff = 0; + if (_objectType == kFreeObjectType) { + text = (const uint8 *)_freeDesc.getString(_command); + } else if (_objectType == kSetObjectType1) { + textBase = (const uint8 *)_setDesc._text; + textOff = kNumSetTexts * 2; + text = (const uint8 *)_setDesc.getString(_command); + } else { + text = (const uint8 *)_exText.getString(_command); + } + + if (_objectType != kSetObjectType1) + return text; + + const uint8 *obname = text; + while (true) { + const uint8 *start = text; + findNextColon(&text); + + // Not an empty description string? + if (*text != 0 && *text != ':') + return start; + + // If the description string (of a SetObjectType1 object) is empty, + // look for an object with the same name. + // Example: Eden's garage door outside has two parts. The right part + // has no description of its own but uses that of the left part. + + bool found = false; + do { + text++; + uint8 c = *obname; + + // scan for matching first character + while (*text != c) { + text++; + + // arbitrary give-up counter + // FIXME: Make this more precise to avoid reading out of bounds + if (text - (textBase - textOff) >= 8000) { + warning("Object description for %d/%d not found", _objectType, _command); + return obname; + } + } + + // found matching first character, so match the rest + const uint8 *s1 = obname; + const uint8 *s2 = text; + do { + s1++; + s2++; + } while (*s1 != ':' && *s1 != 0 && *s1 == *s2); + + if (*s1 == ':' || *s1 == 0) + found = true; // (prefix) matched the entire object name + } while (!found); + + // We found an object with the same name. The next loop iteration + // will check if this one again has an empty description. + } +} + +void DreamWebEngine::dropObject() { + if (_commandType != 223) { + _commandType = 223; + if (!_pickUp) { + blank(); + return; + } + commandWithOb(37, _objectType, _itemFrame); + } + + if (_mouseButton == _oldButton || !(_mouseButton & 1)) + return; + + if (isItWorn(getEitherAd())) { + wornError(); + return; + } + + if (_realLocation != 47) { + byte flag, flagEx, type, flagX, flagY; + checkOne(_ryanX + 12, _ryanY + 12, &flag, &flagEx, &type, &flagX, &flagY); + + if (flag >= 2) { + dropError(); + return; + } + } else { + dropError(); + return; + } + + if (_mapXSize == 64 && _mapYSize == 64) { + // Inside lift + dropError(); + return; + } + + if (compare(_itemFrame, kExObjectType, "GUNA") || compare(_itemFrame, kExObjectType, "SHLD")) { + cantDrop(); + return; + } + + _objectType = kExObjectType; + DynObject *object = getExAd(_itemFrame); + object->mapad[0] = 0; + object->mapad[1] = ((_ryanX + 4) >> 4) + _mapX; + object->mapad[2] = (_ryanX + 4) & 0xF; + object->mapad[3] = ((_ryanY + 8) >> 4) + _mapY; + object->mapad[4] = (_ryanY + 8) & 0xF; + _pickUp = 0; + object->currentLocation = _realLocation; +} + +bool DreamWebEngine::checkObjectSize() { + byte containerSize = getOpenedSlotSize(); + DynObject *object = getEitherAd(); + // If there is no size defined for the object in the editor, set its size + // to 6. This could be a bad idea, according to the original source. + byte objectSize = (object->objectSize != 255) ? object->objectSize : 6; + + if (containerSize >= 100) { + // Special type of container: only objects of the same special type fit. + if (containerSize == objectSize) + return true; + + errorMessage3(); + return false; + } + + if (objectSize >= 100) { + // Special type of object, but a regular container. + // Subtract 100 from the size to get its regular size. + objectSize -= 100; + } + + if (containerSize >= objectSize) + return true; + + errorMessage2(); + return false; +} + +void DreamWebEngine::selectOpenOb() { + uint8 slotSize, slotCount; + getAnyAd(&slotSize, &slotCount); + if (slotCount == 255) { + // Can't open the object + blank(); + return; + } + + if (_commandType != 224) { + _commandType = 224; + commandWithOb(38, _objectType, _command); + } + + if (_mouseButton == _oldButton || !(_mouseButton & 1)) + return; + + _openedOb = _command; + _openedType = _objectType; + createPanel(); + showPanel(); + showMan(); + examIcon(); + showExit(); + openInv(); + openOb(); + underTextLine(); + readMouse(); + showPointer(); + workToScreen(); + delPointer(); +} + +void DreamWebEngine::reExFromInv() { + ObjectRef objectId = findInvPos(); + _commandType = objectId._type; + _command = objectId._index; + _examAgain = 1; + _pointerMode = 0; +} + +void DreamWebEngine::swapWithInv() { + ObjectRef subject; + subject._type = _objectType; + subject._index = _itemFrame; + if (subject != _oldSubject || _commandType != 243) { + if (subject == _oldSubject) + _commandType = 243; + _oldSubject = subject; + commandWithOb(34, subject._type, subject._index); + } + + if (_mouseButton == _oldButton || !(_mouseButton & 1)) + return; + + byte prevType = _objectType; + byte prevFrame = _itemFrame; + ObjectRef objectId = findInvPos(); + _itemFrame = objectId._index; + _objectType = objectId._type; + DynObject *object = getEitherAd(); + object->mapad[0] = 20; + object->mapad[1] = 255; + byte prevType2 = _objectType; + byte prevFrame2 = _itemFrame; + _objectType = prevType; + _itemFrame = prevFrame; + delPointer(); + object = getEitherAd(); + object->mapad[0] = 4; + object->mapad[1] = 255; + object->mapad[2] = _lastInvPos; + _objectType = prevType2; + _itemFrame = prevFrame2; + fillRyan(); + readMouse(); + showPointer(); + workToScreen(); + delPointer(); +} + +void DreamWebEngine::useOpened() { + if (_openedOb == 255) + return; // cannot use opened object + + if (!_pickUp) { + outOfOpen(); + return; + } + + ObjectRef objectId = findOpenPos(); + + if (objectId._index != 255) { + swapWithOpen(); + return; + } + + if (_pickUp != 1) { + blank(); + return; + } + + objectId._type = _objectType; + objectId._index = _itemFrame; + if (objectId != _oldSubject || _commandType != 227) { + if (objectId == _oldSubject) + _commandType = 227; + _oldSubject = objectId; + commandWithOb(35, objectId._type, objectId._index); + } + + if (_mouseButton == _oldButton || !(_mouseButton & 1)) + return; + + if (isItWorn(getEitherAd())) { + wornError(); + return; + } + + delPointer(); + + if (_itemFrame == _openedOb && + _objectType == _openedType) { + errorMessage1(); + return; + } + + if (!checkObjectSize()) + return; + + _pickUp = 0; + DynObject *object = getEitherAd(); + object->mapad[0] = _openedType; + object->mapad[1] = _openedOb; + object->mapad[2] = _lastInvPos; + object->mapad[3] = _realLocation; + fillOpen(); + underTextLine(); + readMouse(); + useOpened(); + showPointer(); + workToScreen(); + delPointer(); +} + +void DreamWebEngine::outOfOpen() { + if (_openedOb == 255) + return; // cannot use opened object + + ObjectRef objectId = findOpenPos(); + + if (objectId._index == 255) { + blank(); + return; + } + + if (objectId != _oldSubject || _commandType != 228) { + if (objectId == _oldSubject) + _commandType = 228; + _oldSubject = objectId; + commandWithOb(36, objectId._type, objectId._index); + } + + if (_mouseButton == _oldButton) + return; // notletgo4 + + if (_mouseButton != 1) { + if (_mouseButton == 2) + reExFromOpen(); + return; + } + + delPointer(); + _pickUp = 1; + objectId = findOpenPos(); + _objectType = objectId._type; + _itemFrame = objectId._index; + + if (_objectType != kExObjectType) { + assert(objectId._type == kFreeObjectType); + _itemFrame = transferToEx(objectId._index); + _objectType = kExObjectType; + } + + DynObject *object = getEitherAd(); + object->mapad[0] = 20; + object->mapad[1] = 255; + + fillOpen(); + underTextLine(); + readMouse(); + useOpened(); + showPointer(); + workToScreen(); + delPointer(); +} + +void DreamWebEngine::swapWithOpen() { + ObjectRef subject; + subject._type = _objectType; + subject._index = _itemFrame; + if (subject != _oldSubject || _commandType != 242) { + if (subject == _oldSubject) + _commandType = 242; + _oldSubject = subject; + commandWithOb(34, subject._type, subject._index); + } + + if (_mouseButton == _oldButton || !(_mouseButton & 1)) + return; + + if (isItWorn(getEitherAd())) { + wornError(); + return; + } + + delPointer(); + + if (_itemFrame == _openedOb && + _objectType == _openedType) { + errorMessage1(); + return; + } + + if (!checkObjectSize()) + return; + + byte prevType = _objectType; + byte prevFrame = _itemFrame; + ObjectRef objectId = findOpenPos(); + _objectType = objectId._type; + _itemFrame = objectId._index; + + if (_objectType != kExObjectType) { + assert(objectId._type == kFreeObjectType); + _itemFrame = transferToEx(objectId._index); + _objectType = kExObjectType; + } + + DynObject *object = getEitherAd(); + object->mapad[0] = 20; + object->mapad[1] = 255; + + byte prevType2 = _objectType; + byte prevFrame2 = _itemFrame; + _objectType = prevType; + _itemFrame = prevFrame; + object = getEitherAd(); + object->mapad[0] = _openedType; + object->mapad[1] = _openedOb; + object->mapad[2] = _lastInvPos; + object->mapad[3] = _realLocation; + _objectType = prevType2; + _itemFrame = prevFrame2; + fillOpen(); + fillRyan(); + underTextLine(); + readMouse(); + useOpened(); + showPointer(); + workToScreen(); + delPointer(); +} + +ObjectRef DreamWebEngine::findOpenPos() { + uint8 pos = (_mouseX - kInventx) / kItempicsize; + _lastInvPos = pos; + + return _openInvList[pos]; +} + +byte DreamWebEngine::transferToEx(uint8 from) { + emergencyPurge(); + + byte pos = getExPos(); + DynObject *exObject = getExAd(pos); + + DynObject *freeObject = getFreeAd(from); + + memcpy(exObject, freeObject, sizeof(DynObject)); + + exObject->currentLocation = _realLocation; + exObject->initialLocation = _realLocation; + exObject->index = from; + exObject->mapad[0] = 4; + exObject->mapad[1] = 255; + exObject->mapad[2] = _lastInvPos; + + transferFrame(from, pos, 0); + transferFrame(from, pos, 1); + transferText(from, pos); + + freeObject->mapad[0] = 254; + + pickupConts(from, pos); + + return pos; +} + +void DreamWebEngine::fillOpen() { + delTextLine(); + uint8 size = getOpenedSlotCount(); + if (size > 4) + size = 4; + findAllOpen(); + for (uint8 i = 0; i < size; ++i) { + uint8 index = _openInvList[i]._index; + uint8 type = _openInvList[i]._type; + obToInv(index, type, kInventx + i * kItempicsize, kInventy + 96); + } + underTextLine(); +} + +void DreamWebEngine::findAllOpen() { + memset(_openInvList, 0xFF, 32); + + for (uint8 i = 0; i < kNumexobjects; ++i) { + const DynObject *obj = getExAd(i); + if (obj->mapad[1] != _openedOb) + continue; + if (obj->mapad[0] != _openedType) + continue; + if (_openedType != kExObjectType && obj->mapad[3] != _realLocation) + continue; + uint8 slot = obj->mapad[2]; + assert(slot < 16); + _openInvList[slot]._index = i; + _openInvList[slot]._type = kExObjectType; + } + + for (uint8 i = 0; i < 80; ++i) { + const DynObject *obj = getFreeAd(i); + if (obj->mapad[1] != _openedOb) + continue; + if (obj->mapad[0] != _openedType) + continue; + uint8 slot = obj->mapad[2]; + _openInvList[slot]._index = i; + _openInvList[slot]._type = kFreeObjectType; + } +} + +void DreamWebEngine::pickupConts(uint8 from, uint8 containerEx) { + const DynObject *obj = getFreeAd(from); + + if (obj->slotCount == 255) + return; // not openable + + for (uint8 index = 0; index < 80; ++index) { + DynObject *freeObj = getFreeAd(index); + + if (freeObj->mapad[0] != kFreeObjectType) + continue; + if (freeObj->mapad[1] != from) + continue; + + uint8 pos = getExPos(); + DynObject *exObj = getExAd(pos); + + memcpy(exObj, freeObj, sizeof(DynObject)); + exObj->currentLocation = _realLocation; + exObj->initialLocation = _realLocation; + exObj->index = index; + exObj->mapad[0] = 4; // kExObjectType? + exObj->mapad[1] = containerEx; + + transferFrame(index, pos, 0); + transferFrame(index, pos, 1); + transferText(index, pos); + + freeObj->mapad[0] = 0xFF; + } +} + +} // End of namespace DreamWeb diff --git a/engines/dreamweb/pathfind.cpp b/engines/dreamweb/pathfind.cpp index f6591d4666..c39070532c 100644 --- a/engines/dreamweb/pathfind.cpp +++ b/engines/dreamweb/pathfind.cpp @@ -22,151 +22,128 @@ #include "dreamweb/dreamweb.h" -namespace DreamGen { +namespace DreamWeb { -void DreamGenContext::turnPathOn() { - turnPathOn(al); -} - -void DreamGenContext::turnPathOn(uint8 param) { - findOrMake(param, 0xff, data.byte(kRoomnum) + 100); +void DreamWebEngine::turnPathOn(uint8 param) { + findOrMake(param, 0xff, _roomNum + 100); PathNode *roomsPaths = getRoomsPaths()->nodes; if (param == 0xff) return; roomsPaths[param].on = 0xff; } -void DreamGenContext::turnPathOff() { - turnPathOff(al); -} - -void DreamGenContext::turnPathOff(uint8 param) { - findOrMake(param, 0x00, data.byte(kRoomnum) + 100); +void DreamWebEngine::turnPathOff(uint8 param) { + findOrMake(param, 0x00, _roomNum + 100); PathNode *roomsPaths = getRoomsPaths()->nodes; if (param == 0xff) return; roomsPaths[param].on = 0x00; } -void DreamGenContext::turnAnyPathOn(uint8 param, uint8 room) { +void DreamWebEngine::turnAnyPathOn(uint8 param, uint8 room) { findOrMake(param, 0xff, room + 100); - PathNode *paths = (PathNode *)getSegment(data.word(kReels)).ptr(kPathdata + 144 * room, 0); - paths[param].on = 0xff; + _pathData[room].nodes[param].on = 0xff; } -void DreamGenContext::turnAnyPathOn() { - turnAnyPathOn(al, ah); -} - -void DreamGenContext::turnAnyPathOff(uint8 param, uint8 room) { +void DreamWebEngine::turnAnyPathOff(uint8 param, uint8 room) { findOrMake(param, 0x00, room + 100); - PathNode *paths = (PathNode *)getSegment(data.word(kReels)).ptr(kPathdata + 144 * room, 0); - paths[param].on = 0x00; -} - -void DreamGenContext::turnAnyPathOff() { - turnAnyPathOff(al, ah); + _pathData[room].nodes[param].on = 0x00; } -RoomPaths *DreamBase::getRoomsPaths() { - void *result = getSegment(data.word(kReels)).ptr(data.byte(kRoomnum) * 144, 144); - return (RoomPaths *)result; +RoomPaths *DreamWebEngine::getRoomsPaths() { + return &_pathData[_roomNum]; } -void DreamBase::faceRightWay() { +void DreamWebEngine::faceRightWay() { PathNode *paths = getRoomsPaths()->nodes; - uint8 dir = paths[data.byte(kManspath)].dir; - data.byte(kTurntoface) = dir; - data.byte(kLeavedirection) = dir; + uint8 dir = paths[_mansPath].dir; + _turnToFace = dir; + _leaveDirection = dir; } -void DreamBase::setWalk() { - if (data.byte(kLinepointer) != 254) { +void DreamWebEngine::setWalk() { + if (_linePointer != 254) { // Already walking - data.byte(kFinaldest) = data.byte(kPointerspath); - } else if (data.byte(kPointerspath) == data.byte(kManspath)) { + _finalDest = _pointersPath; + } else if (_pointersPath == _mansPath) { // Can't walk faceRightWay(); - } else if (data.byte(kWatchmode) == 1) { + } else if (_vars._watchMode == 1) { // Holding reel - data.byte(kDestafterhold) = data.byte(kPointerspath); - data.byte(kWatchmode) = 2; - } else if (data.byte(kWatchmode) == 2) { + _vars._destAfterHold = _pointersPath; + _vars._watchMode = 2; + } else if (_vars._watchMode == 2) { // Can't walk } else { - data.byte(kDestination) = data.byte(kPointerspath); - data.byte(kFinaldest) = data.byte(kPointerspath); - if (data.word(kMousebutton) != 2 || data.word(kCommandtype) == 3) { + _destination = _pointersPath; + _finalDest = _pointersPath; + if (_mouseButton != 2 || _commandType == 3) { autoSetWalk(); } else { - data.byte(kWalkandexam) = 1; - data.byte(kWalkexamtype) = data.byte(kCommandtype); - data.byte(kWalkexamnum) = data.byte(kCommand); + _walkAndExam = 1; + _walkExamType = _commandType; + _walkExamNum = _command; autoSetWalk(); } } } -void DreamBase::autoSetWalk() { - if (data.byte(kFinaldest) == data.byte(kManspath)) +void DreamWebEngine::autoSetWalk() { + if (_finalDest == _mansPath) return; const RoomPaths *roomsPaths = getRoomsPaths(); checkDest(roomsPaths); - data.word(kLinestartx) = roomsPaths->nodes[data.byte(kManspath)].x - 12; - data.word(kLinestarty) = roomsPaths->nodes[data.byte(kManspath)].y - 12; - data.word(kLineendx) = roomsPaths->nodes[data.byte(kDestination)].x - 12; - data.word(kLineendy) = roomsPaths->nodes[data.byte(kDestination)].y - 12; + _lineStartX = roomsPaths->nodes[_mansPath].x - 12; + _lineStartY = roomsPaths->nodes[_mansPath].y - 12; + _lineEndX = roomsPaths->nodes[_destination].x - 12; + _lineEndY = roomsPaths->nodes[_destination].y - 12; bresenhams(); - if (data.byte(kLinedirection) != 0) { - data.byte(kLinepointer) = data.byte(kLinelength) - 1; - data.byte(kLinedirection) = 1; + if (_lineDirection != 0) { + _linePointer = _lineLength - 1; + _lineDirection = 1; return; } - data.byte(kLinepointer) = 0; + _linePointer = 0; } -void DreamBase::checkDest(const RoomPaths *roomsPaths) { +void DreamWebEngine::checkDest(const RoomPaths *roomsPaths) { const PathSegment *segments = roomsPaths->segments; - const uint8 tmp = data.byte(kManspath) << 4; - uint8 destination = data.byte(kDestination); + const uint8 tmp = _mansPath << 4; + uint8 destination = _destination; for (size_t i = 0; i < 24; ++i) { if ((segments[i].b0 & 0xf0) == tmp && - (segments[i].b0 & 0x0f) == data.byte(kDestination)) { - data.byte(kDestination) = segments[i].b1 & 0x0f; + (segments[i].b0 & 0x0f) == _destination) { + _destination = segments[i].b1 & 0x0f; return; } if (((segments[i].b0 & 0x0f) << 4) == tmp && - ((segments[i].b0 & 0xf0) >> 4) == data.byte(kDestination)) { + ((segments[i].b0 & 0xf0) >> 4) == _destination) { destination = segments[i].b1 & 0x0f; } } - data.byte(kDestination) = destination; + _destination = destination; } -void DreamBase::findXYFromPath() { +void DreamWebEngine::findXYFromPath() { const PathNode *roomsPaths = getRoomsPaths()->nodes; - data.byte(kRyanx) = roomsPaths[data.byte(kManspath)].x - 12; - data.byte(kRyany) = roomsPaths[data.byte(kManspath)].y - 12; -} - -void DreamGenContext::checkIfPathIsOn() { - flags._z = checkIfPathIsOn(al); + _ryanX = roomsPaths[_mansPath].x - 12; + _ryanY = roomsPaths[_mansPath].y - 12; } -bool DreamGenContext::checkIfPathIsOn(uint8 index) { +bool DreamWebEngine::checkIfPathIsOn(uint8 index) { RoomPaths *roomsPaths = getRoomsPaths(); uint8 pathOn = roomsPaths->nodes[index].on; return pathOn == 0xff; } -void DreamBase::bresenhams() { +void DreamWebEngine::bresenhams() { workoutFrames(); Common::Point *lineData = &_lineData[0]; - int16 startX = (int16)data.word(kLinestartx); - int16 startY = (int16)data.word(kLinestarty); - int16 endX = (int16)data.word(kLineendx); - int16 endY = (int16)data.word(kLineendy); + int16 startX = (int16)_lineStartX; + int16 startY = (int16)_lineStartY; + int16 endX = (int16)_lineEndX; + int16 endY = (int16)_lineEndY; if (endX == startX) { uint16 deltaY; @@ -174,15 +151,15 @@ void DreamBase::bresenhams() { if (endY < startY) { deltaY = startY - endY; y = (int8)endY; - data.byte(kLinedirection) = 1; + _lineDirection = 1; } else { deltaY = endY - startY; y = (int8)startY; - data.byte(kLinedirection) = 0; + _lineDirection = 0; } ++deltaY; int8 x = (int8)startX; - data.byte(kLinelength) = deltaY; + _lineLength = deltaY; for (; deltaY; --deltaY) { lineData->x = x; lineData->y = y; @@ -196,14 +173,14 @@ void DreamBase::bresenhams() { deltaX = startX - endX; SWAP(startX, endX); SWAP(startY, endY); - data.word(kLinestartx) = (uint16)startX; - data.word(kLinestarty) = (uint16)startY; - data.word(kLineendx) = (uint16)endX; - data.word(kLineendy) = (uint16)endY; - data.byte(kLinedirection) = 1; + _lineStartX = (uint16)startX; + _lineStartY = (uint16)startY; + _lineEndX = (uint16)endX; + _lineEndY = (uint16)endY; + _lineDirection = 1; } else { deltaX = endX - startX; - data.byte(kLinedirection) = 0; + _lineDirection = 0; } int16 increment; @@ -211,7 +188,7 @@ void DreamBase::bresenhams() { int8 x = (int8)startX; int8 y = (int8)startY; ++deltaX; - data.byte(kLinelength) = deltaX; + _lineLength = deltaX; for (; deltaX; --deltaX) { lineData->x = x; lineData->y = y; @@ -230,33 +207,35 @@ void DreamBase::bresenhams() { } uint16 delta1, delta2; + byte lineRoutine; + if (deltaY > deltaX) { - data.byte(kLineroutine) = 1; + lineRoutine = 1; delta1 = deltaY; delta2 = deltaX; } else { - data.byte(kLineroutine) = 0; + lineRoutine = 0; delta1 = deltaX; delta2 = deltaY; } - data.word(kIncrement1) = delta2 * 2; + uint16 increment1 = delta2 * 2; + uint16 increment2 = delta2 * 2 - delta1 * 2; int16 remainder = delta2 * 2 - delta1; - data.word(kIncrement2) = delta2 * 2 - delta1 * 2; ++delta1; int8 x = (int8)startX; int8 y = (int8)startY; - data.byte(kLinelength) = delta1; - if (data.byte(kLineroutine) != 1) { + _lineLength = delta1; + if (lineRoutine != 1) { for (; delta1; --delta1) { lineData->x = x; lineData->y = y; ++lineData; ++x; if (remainder < 0) { - remainder += data.word(kIncrement1); + remainder += increment1; } else { - remainder += data.word(kIncrement2); + remainder += increment2; y += increment; } } @@ -267,25 +246,25 @@ void DreamBase::bresenhams() { ++lineData; y += increment; if (remainder < 0) { - remainder += data.word(kIncrement1); + remainder += increment1; } else { - remainder += data.word(kIncrement2); + remainder += increment2; ++x; } } } } -void DreamBase::workoutFrames() { +void DreamWebEngine::workoutFrames() { byte tmp; int diffx, diffy; // We have to use signed arithmetic here because these values can // be slightly negative when walking off-screen - int lineStartX = (int16)data.word(kLinestartx); - int lineStartY = (int16)data.word(kLinestarty); - int lineEndX = (int16)data.word(kLineendx); - int lineEndY = (int16)data.word(kLineendy); + int lineStartX = (int16)_lineStartX; + int lineStartY = (int16)_lineStartY; + int lineEndX = (int16)_lineEndX; + int lineEndY = (int16)_lineEndY; diffx = ABS(lineStartX - lineEndX); @@ -323,8 +302,49 @@ void DreamBase::workoutFrames() { } } - data.byte(kTurntoface) = tmp & 7; - data.byte(kTurndirection) = 0; + _turnToFace = tmp & 7; + _turnDirection = 0; +} + +byte DreamWebEngine::findFirstPath(byte x, byte y) { + PathNode *paths = _pathData[_roomNum].nodes; + + for (uint8 index = 0; index < 12; index++) { + if (paths[index].x1 == 0xff && paths[index].y1 == 0xff) + continue; // "nofirst" + + if (x < paths[index].x1 || y < paths[index].y1) + continue; // "nofirst" + + if (x >= paths[index].x2 || y >= paths[index].y2) + continue; // "nofirst" + + return paths[index].on; // "gotfirst" + } + + return 0; +} + +byte DreamWebEngine::findPathOfPoint(byte x, byte y) { + PathNode *paths = _pathData[_roomNum].nodes; + + for (uint8 index = 0; index < 12; index++) { + if (paths[index].on != 0xff) + continue; // "flunkedit" + + if (paths[index].x1 == 0xff && paths[index].y1 == 0xff) + continue; // "flunkedit" + + if (x < paths[index].x1 || y < paths[index].y1) + continue; // "flunkedit" + + if (x >= paths[index].x2 || y >= paths[index].y2) + continue; // "flunkedit" + + return index; // "gotvalidpath" + } + + return 0xff; } -} // End of namespace DreamGen +} // End of namespace DreamWeb diff --git a/engines/dreamweb/people.cpp b/engines/dreamweb/people.cpp index 889a430a22..dfb5c62618 100644 --- a/engines/dreamweb/people.cpp +++ b/engines/dreamweb/people.cpp @@ -22,153 +22,191 @@ #include "dreamweb/dreamweb.h" -namespace DreamGen { - -static void (DreamGenContext::*reelCallbacks[57])() = { - NULL, NULL, - NULL, NULL, - NULL, NULL, - NULL, NULL, - &DreamGenContext::receptionist, NULL, - NULL, NULL, - NULL, NULL, - NULL, NULL, - &DreamGenContext::heavy, NULL, - NULL, NULL, - &DreamGenContext::bartender, NULL, - NULL, NULL, - NULL, NULL, - NULL, NULL, - NULL, &DreamGenContext::poolGuard, - NULL, &DreamGenContext::businessMan, - NULL, NULL, - &DreamGenContext::mugger, &DreamGenContext::helicopter, - NULL, NULL, - NULL, NULL, - NULL, NULL, - NULL, NULL, - NULL, NULL, - NULL, &DreamGenContext::endGameSeq, - NULL, NULL, - NULL, NULL, - NULL, NULL, - NULL, NULL, - NULL +namespace DreamWeb { + +static void (DreamWebEngine::*reelCallbacks[57])(ReelRoutine &) = { + &DreamWebEngine::gamer, &DreamWebEngine::sparkyDrip, + &DreamWebEngine::eden, &DreamWebEngine::edenInBath, + &DreamWebEngine::sparky, &DreamWebEngine::smokeBloke, + &DreamWebEngine::manAsleep, &DreamWebEngine::drunk, + &DreamWebEngine::receptionist, &DreamWebEngine::genericPerson /*maleFan*/, + &DreamWebEngine::genericPerson /*femaleFan*/, &DreamWebEngine::louis, + &DreamWebEngine::louisChair, &DreamWebEngine::soldier1, + &DreamWebEngine::bossMan, &DreamWebEngine::interviewer, + &DreamWebEngine::heavy, &DreamWebEngine::manAsleep /*manAsleep2*/, + &DreamWebEngine::genericPerson /*manSatStill*/, &DreamWebEngine::drinker, + &DreamWebEngine::bartender, &DreamWebEngine::genericPerson /*otherSmoker*/, + &DreamWebEngine::genericPerson /*tattooMan*/, &DreamWebEngine::attendant, + &DreamWebEngine::keeper, &DreamWebEngine::candles1, + &DreamWebEngine::smallCandle, &DreamWebEngine::security, + &DreamWebEngine::copper, &DreamWebEngine::poolGuard, + &DreamWebEngine::rockstar, &DreamWebEngine::businessMan, + &DreamWebEngine::train, &DreamWebEngine::genericPerson /*aide*/, + &DreamWebEngine::mugger, &DreamWebEngine::helicopter, + &DreamWebEngine::introMagic1, &DreamWebEngine::introMusic, + &DreamWebEngine::introMagic2, &DreamWebEngine::candles2, + &DreamWebEngine::gates, &DreamWebEngine::introMagic3, + &DreamWebEngine::introMonks1, &DreamWebEngine::candles, + &DreamWebEngine::introMonks2, &DreamWebEngine::handClap, + &DreamWebEngine::monkAndRyan, &DreamWebEngine::endGameSeq, + &DreamWebEngine::priest, &DreamWebEngine::madman, + &DreamWebEngine::madmansTelly, &DreamWebEngine::alleyBarkSound, + &DreamWebEngine::foghornSound, &DreamWebEngine::carParkDrip, + &DreamWebEngine::carParkDrip, &DreamWebEngine::carParkDrip, + &DreamWebEngine::carParkDrip }; -static void (DreamGenContext::*reelCallbacksCPP[57])(ReelRoutine &) = { - &DreamGenContext::gamer, &DreamGenContext::sparkyDrip, - &DreamGenContext::eden, &DreamGenContext::edenInBath, - &DreamGenContext::sparky, &DreamGenContext::smokeBloke, - &DreamGenContext::manAsleep, &DreamGenContext::drunk, - /*&DreamGenContext::receptionist*/NULL, &DreamGenContext::genericPerson /*maleFan*/, - &DreamGenContext::genericPerson /*femaleFan*/, &DreamGenContext::louis, - &DreamGenContext::louisChair, &DreamGenContext::soldier1, - &DreamGenContext::bossMan, &DreamGenContext::interviewer, - /*&DreamGenContext::heavy*/NULL, &DreamGenContext::manAsleep /*manAsleep2*/, - &DreamGenContext::genericPerson /*manSatStill*/, &DreamGenContext::drinker, - /*&DreamGenContext::bartender*/NULL, &DreamGenContext::genericPerson /*otherSmoker*/, - &DreamGenContext::genericPerson /*tattooMan*/, &DreamGenContext::attendant, - &DreamGenContext::keeper, &DreamGenContext::candles1, - &DreamGenContext::smallCandle, &DreamGenContext::security, - &DreamGenContext::copper, /*&DreamGenContext::poolGuard*/NULL, - &DreamGenContext::rockstar, /*&DreamGenContext::businessMan*/NULL, - &DreamGenContext::train, &DreamGenContext::genericPerson /*aide*/, - /*&DreamGenContext::mugger*/NULL, /*&DreamGenContext::helicopter*/NULL, - &DreamGenContext::introMagic1, &DreamGenContext::introMusic, - &DreamGenContext::introMagic2, &DreamGenContext::candles2, - &DreamGenContext::gates, &DreamGenContext::introMagic3, - &DreamGenContext::introMonks1, &DreamGenContext::candles, - &DreamGenContext::introMonks2, &DreamGenContext::handClap, - &DreamGenContext::monkAndRyan, /*&DreamGenContext::endGameSeq*/NULL, - &DreamGenContext::priest, &DreamGenContext::madman, - &DreamGenContext::madmansTelly, &DreamGenContext::alleyBarkSound, - &DreamGenContext::foghornSound, &DreamGenContext::carParkDrip, - &DreamGenContext::carParkDrip, &DreamGenContext::carParkDrip, - &DreamGenContext::carParkDrip +static const ReelRoutine g_initialReelRoutines[] = { +// Room number and x,y +// reel pointer +// speed,speed count,convers. no. + { 1,44,0, 20, 2,0,1 }, + { 1,55,0, 0, 50,20,0 }, + { 24,22,0, 74, 1,0,0 }, + { 24,33,10, 75, 1,0,1 }, + { 1,44,0, 27, 2,0,2 }, + { 1,44,0, 96, 3,0,4 }, + { 1,44,0, 118, 2,0,5 }, + { 1,44,10, 0, 2,0,0 }, + { 5,22,20, 53, 3,0,0 }, + { 5,22,20, 40, 1,0,2 }, + { 5,22,20, 50, 1,0,3 }, + { 2,11,10, 192, 1,0,0 }, + { 2,11,10, 182, 2,0,1 }, + { 8,11,10, 0, 2,0,1 }, + { 23,0,50, 0, 3,0,0 }, + { 28,11,20, 250, 4,0,0 }, + { 23,0,50, 43, 2,0,8 }, + { 23,11,40, 130, 2,0,1 }, + { 23,22,40, 122, 2,0,2 }, + { 23,22,40, 105, 2,0,3 }, + { 23,22,40, 81, 2,0,4 }, + { 23,11,40, 135, 2,0,5 }, + { 23,22,40, 145, 2,0,6 }, + { 4,22,30, 0, 2,0,0 }, + { 45,22,30, 200, 0,0,20 }, + { 45,22,30, 39, 2,0,0 }, + { 45,22,30, 25, 2,0,0 }, + { 8,22,40, 32, 2,0,0 }, + { 7,11,20, 64, 2,0,0 }, + { 22,22,20, 82, 2,0,0 }, + { 27,11,30, 0, 2,0,0 }, + { 20,0,30, 0, 2,0,0 }, + { 14,33,40, 21, 1,0,0 }, + { 29,11,10, 0, 1,0,0 }, + { 2,22,0, 2, 2,0,0 }, + { 25,0,50, 4, 2,0,0 }, + { 50,22,30, 121, 2,0,0 }, + { 50,22,30, 0, 20,0,0 }, + { 52,22,30, 192, 2,0,0 }, + { 52,22,30, 233, 2,0,0 }, + { 50,22,40, 104, 55,0,0 }, // ...., 65,0,0 for German CD + { 53,33,0, 99, 2,0,0 }, + { 50,22,40, 0, 3,0,0 }, + { 50,22,30, 162, 2,0,0 }, + { 52,22,30, 57, 2,0,0 }, + { 52,22,30, 0, 2,0,0 }, + { 54,0,0, 72, 3,0,0 }, + { 55,44,0, 0, 2,0,0 }, + { 19,0,0, 0, 28,0,0 }, + { 14,22,0, 2, 2,0,0 }, + { 14,22,0, 300, 1,0,0 }, + { 10,22,30, 174, 0,0,0 }, + { 12,22,20, 0, 1,0,0 }, + { 11,11,20, 0, 50,20,0 }, + { 11,11,30, 0, 50,20,0 }, + { 11,22,20, 0, 50,20,0 }, + { 14,33,40, 0, 50,20,0 }, + { 255,0,0, 0, 0,0,0 } }; -void DreamGenContext::updatePeople() { - data.word(kListpos) = kPeoplelist; - memset(getSegment(data.word(kBuffers)).ptr(kPeoplelist, 12 * sizeof(People)), 0xff, 12 * sizeof(People)); - ++data.word(kMaintimer); - - // The original callbacks are called with es:bx pointing to their reelRoutine entry. - // The new callbacks take a mutable ReelRoutine parameter. - - es = data; - ReelRoutine *r = (ReelRoutine *)data.ptr(kReelroutines, 0); - - for (int i = 0; r[i].reallocation != 255; ++i) { - bx = kReelroutines + 8*i; - if (r[i].reallocation == data.byte(kReallocation) && - r[i].mapX == data.byte(kMapx) && - r[i].mapY == data.byte(kMapy)) { - if (reelCallbacks[i]) { - assert(!reelCallbacksCPP[i]); - (this->*(reelCallbacks[i]))(); - } else { - assert(reelCallbacksCPP[i]); - (this->*(reelCallbacksCPP[i]))(r[i]); - } +void DreamWebEngine::setupInitialReelRoutines() { + for (unsigned int i = 0; i < kNumReelRoutines + 1; ++i) { + _reelRoutines[i] = g_initialReelRoutines[i]; + if (_reelRoutines[i].period == 55 && hasSpeech() && getLanguage() == Common::DE_DEU) + _reelRoutines[i].period = 65; + } +} + +void DreamWebEngine::updatePeople() { + _peopleList.clear(); + ++_mainTimer; + + for (int i = 0; _reelRoutines[i].reallocation != 255; ++i) { + if (_reelRoutines[i].reallocation == _realLocation && + _reelRoutines[i].mapX == _mapX && + _reelRoutines[i].mapY == _mapY) { + assert(reelCallbacks[i]); + (this->*(reelCallbacks[i]))(_reelRoutines[i]); } } } -void DreamGenContext::madmanText() { - if (isCD()) { - if (data.byte(kSpeechcount) >= 63) +void DreamWebEngine::madmanText() { + byte origCount; + + uint16 length = 90; + if (hasSpeech()) { + if (_speechCount > 15) return; - if (data.byte(kCh1playing) != 255) + if (_channel1Playing != 255) return; - al = data.byte(kSpeechcount); - ++data.byte(kSpeechcount); + origCount = _speechCount; + ++_speechCount; + + if (origCount != 15) + length = 32000; // Set subtitle time very high to make it + // always wait for the next line, except for the + // last one, when there is no next line. } else { - if (data.byte(kCombatcount) >= 61) + if (_vars._combatCount >= 61) return; - al = data.byte(kCombatcount); - _and(al, 3); - if (!flags.z()) + if (_vars._combatCount & 3) return; - al = data.byte(kCombatcount) / 4; + origCount = _vars._combatCount / 4; } - setupTimedTemp(47 + al, 82, 72, 80, 90, 1); + setupTimedTemp(47 + origCount, 82, 72, 80, length, 1); } -void DreamGenContext::madman(ReelRoutine &routine) { - data.word(kWatchingtime) = 2; +void DreamWebEngine::madman(ReelRoutine &routine) { + _vars._watchingTime = 2; if (checkSpeed(routine)) { uint16 newReelPointer = routine.reelPointer(); if (newReelPointer >= 364) { - data.byte(kMandead) = 2; + _vars._manDead = 2; showGameReel(&routine); return; } if (newReelPointer == 10) { - loadTempText("DREAMWEB.T82"); - data.byte(kCombatcount) = (uint8)-1; - data.byte(kSpeechcount) = 0; + loadTempText("T82"); + _vars._combatCount = (uint8)-1; + _speechCount = 0; } ++newReelPointer; if (newReelPointer == 294) { - if (data.byte(kWongame) != 1) { - data.byte(kWongame) = 1; + if (!_wonGame) { + _wonGame = true; getRidOfTempText(); } return; } if (newReelPointer == 66) { - ++data.byte(kCombatcount); + ++_vars._combatCount; + + if (_lastHardKey == 1) // ESC pressed, skip the mad man's speech + _vars._combatCount = _speechCount = (hasSpeech() ? 65 : 63); + madmanText(); newReelPointer = 53; - if (data.byte(kCombatcount) >= (isCD() ? 64 : 62)) { - if (data.byte(kCombatcount) == (isCD() ? 70 : 68)) + + if (_vars._combatCount >= (hasSpeech() ? 64 : 62)) { + if (_vars._combatCount == (hasSpeech() ? 70 : 68)) newReelPointer = 310; else { - if (data.byte(kLastweapon) == 8) { - data.byte(kCombatcount) = isCD() ? 72 : 70; - data.byte(kLastweapon) = (uint8)-1; - data.byte(kMadmanflag) = 1; + if (_vars._lastWeapon == 8) { + _vars._combatCount = hasSpeech() ? 72 : 70; + _vars._lastWeapon = (uint8)-1; + _vars._madmanFlag = 1; newReelPointer = 67; } } @@ -177,41 +215,31 @@ void DreamGenContext::madman(ReelRoutine &routine) { routine.setReelPointer(newReelPointer); } showGameReel(&routine); - routine.mapX = data.byte(kMapx); + routine.mapX = _mapX; madMode(); } -void DreamGenContext::madMode() { - data.word(kWatchingtime) = 2; - data.byte(kPointermode) = 0; - if (data.byte(kCombatcount) < (isCD() ? 65 : 63)) +void DreamWebEngine::madMode() { + _vars._watchingTime = 2; + _pointerMode = 0; + if (_vars._combatCount < (hasSpeech() ? 65 : 63)) return; - if (data.byte(kCombatcount) >= (isCD() ? 70 : 68)) + if (_vars._combatCount >= (hasSpeech() ? 70 : 68)) return; - data.byte(kPointermode) = 2; + _pointerMode = 2; } -void DreamGenContext::addToPeopleList() { - addToPeopleList((ReelRoutine *)es.ptr(bx, sizeof(ReelRoutine))); -} +void DreamWebEngine::addToPeopleList(ReelRoutine *routine) { + People people; + people._reelPointer = routine->reelPointer(); + people._routinePointer = routine; + people.b4 = routine->b7; -void DreamGenContext::addToPeopleList(ReelRoutine *routine) { - uint16 routinePointer = (const uint8 *)routine - data.ptr(0, 0); - - People *people = (People *)getSegment(data.word(kBuffers)).ptr(data.word(kListpos), sizeof(People)); - people->setReelPointer(routine->reelPointer()); - people->setRoutinePointer(routinePointer); - people->b4 = routine->b7; - data.word(kListpos) += sizeof(People); + _peopleList.push_back(people); } -void DreamGenContext::checkSpeed() { - ReelRoutine *routine = (ReelRoutine *)es.ptr(bx, sizeof(ReelRoutine)); - flags._z = checkSpeed(*routine); -} - -bool DreamGenContext::checkSpeed(ReelRoutine &routine) { - if (data.byte(kLastweapon) != (uint8)-1) +bool DreamWebEngine::checkSpeed(ReelRoutine &routine) { + if (_vars._lastWeapon != (uint8)-1) return true; ++routine.counter; if (routine.counter != routine.period) @@ -220,21 +248,21 @@ bool DreamGenContext::checkSpeed(ReelRoutine &routine) { return true; } -void DreamGenContext::sparkyDrip(ReelRoutine &routine) { +void DreamWebEngine::sparkyDrip(ReelRoutine &routine) { if (checkSpeed(routine)) playChannel0(14, 0); } -void DreamGenContext::genericPerson(ReelRoutine &routine) { +void DreamWebEngine::genericPerson(ReelRoutine &routine) { showGameReel(&routine); addToPeopleList(&routine); } -void DreamGenContext::gamer(ReelRoutine &routine) { +void DreamWebEngine::gamer(ReelRoutine &routine) { if (checkSpeed(routine)) { uint8 v; do { - v = 20 + engine->randomNumber() % 5; + v = _rnd.getRandomNumberRng(20, 24); } while (v == routine.reelPointer()); routine.setReelPointer(v); } @@ -243,19 +271,19 @@ void DreamGenContext::gamer(ReelRoutine &routine) { addToPeopleList(&routine); } -void DreamGenContext::eden(ReelRoutine &routine) { - if (data.byte(kGeneraldead)) +void DreamWebEngine::eden(ReelRoutine &routine) { + if (_vars._generalDead) return; showGameReel(&routine); addToPeopleList(&routine); } -void DreamGenContext::sparky(ReelRoutine &routine) { - if (data.word(kCard1money)) +void DreamWebEngine::sparky(ReelRoutine &routine) { + if (_vars._card1Money) routine.b7 = 3; if (checkSpeed(routine)) { - if (routine.reelPointer() != 34) { - if (engine->randomNumber() < 30) + if (routine.reelPointer() == 34) { + if (randomNumber() < 30) routine.incReelPointer(); else routine.setReelPointer(27); @@ -269,29 +297,29 @@ void DreamGenContext::sparky(ReelRoutine &routine) { showGameReel(&routine); addToPeopleList(&routine); if (routine.b7 & 128) - data.byte(kTalkedtosparky) = 1; + _vars._talkedToSparky = 1; } -void DreamGenContext::rockstar(ReelRoutine &routine) { +void DreamWebEngine::rockstar(ReelRoutine &routine) { if ((routine.reelPointer() == 303) || (routine.reelPointer() == 118)) { - data.byte(kNewlocation) = 45; + _newLocation = 45; showGameReel(&routine); return; } if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 118) { - data.byte(kMandead) = 2; + _vars._manDead = 2; } else if (nextReelPointer == 79) { --nextReelPointer; - if (data.byte(kLastweapon) != 1) { - ++data.byte(kCombatcount); - if (data.byte(kCombatcount) == 40) { - data.byte(kCombatcount) = 0; + if (_vars._lastWeapon != 1) { + ++_vars._combatCount; + if (_vars._combatCount == 40) { + _vars._combatCount = 0; nextReelPointer = 79; } } else { - data.byte(kLastweapon) = (uint8)-1; + _vars._lastWeapon = (uint8)-1; nextReelPointer = 123; } } @@ -300,16 +328,16 @@ void DreamGenContext::rockstar(ReelRoutine &routine) { showGameReel(&routine); if (routine.reelPointer() == 78) { addToPeopleList(&routine); - data.byte(kPointermode) = 2; - data.word(kWatchingtime) = 0; + _pointerMode = 2; + _vars._watchingTime = 0; } else { - data.word(kWatchingtime) = 2; - data.byte(kPointermode) = 0; - routine.mapY = data.byte(kMapy); + _vars._watchingTime = 2; + _pointerMode = 0; + routine.mapY = _mapY; } } -void DreamGenContext::madmansTelly(ReelRoutine &routine) { +void DreamWebEngine::madmansTelly(ReelRoutine &routine) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 307) nextReelPointer = 300; @@ -318,14 +346,14 @@ void DreamGenContext::madmansTelly(ReelRoutine &routine) { } -void DreamGenContext::smokeBloke(ReelRoutine &routine) { - if (data.byte(kRockstardead) == 0) { +void DreamWebEngine::smokeBloke(ReelRoutine &routine) { + if (_vars._rockstarDead == 0) { if (routine.b7 & 128) setLocation(5); } if (checkSpeed(routine)) { if (routine.reelPointer() == 100) { - if (engine->randomNumber() < 30) + if (randomNumber() < 30) routine.incReelPointer(); else routine.setReelPointer(96); @@ -338,46 +366,46 @@ void DreamGenContext::smokeBloke(ReelRoutine &routine) { addToPeopleList(&routine); } -void DreamGenContext::manAsleep(ReelRoutine &routine) { +void DreamWebEngine::manAsleep(ReelRoutine &routine) { routine.b7 &= 127; showGameReel(&routine); addToPeopleList(&routine); } -void DreamGenContext::attendant(ReelRoutine &routine) { +void DreamWebEngine::attendant(ReelRoutine &routine) { showGameReel(&routine); addToPeopleList(&routine); if (routine.b7 & 128) - data.byte(kTalkedtoattendant) = 1; + _vars._talkedToAttendant = 1; } -void DreamGenContext::keeper(ReelRoutine &routine) { - if (data.byte(kKeeperflag) != 0) { +void DreamWebEngine::keeper(ReelRoutine &routine) { + if (_vars._keeperFlag != 0) { // Not waiting addToPeopleList(&routine); showGameReel(&routine); return; } - if (data.word(kReeltowatch) < 190) + if (_vars._reelToWatch < 190) return; // waiting - data.byte(kKeeperflag)++; + _vars._keeperFlag++; - if ((routine.b7 & 127) != data.byte(kDreamnumber)) - routine.b7 = data.byte(kDreamnumber); + if ((routine.b7 & 127) != _vars._dreamNumber) + routine.b7 = _vars._dreamNumber; } -void DreamGenContext::drunk(ReelRoutine &routine) { - if (data.byte(kGeneraldead)) +void DreamWebEngine::drunk(ReelRoutine &routine) { + if (_vars._generalDead) return; routine.b7 &= 127; showGameReel(&routine); addToPeopleList(&routine); } -void DreamGenContext::interviewer(ReelRoutine &routine) { - if (data.word(kReeltowatch) == 68) +void DreamWebEngine::interviewer(ReelRoutine &routine) { + if (_vars._reelToWatch == 68) routine.incReelPointer(); if (routine.reelPointer() != 250 && routine.reelPointer() != 259 && checkSpeed(routine)) @@ -386,12 +414,12 @@ void DreamGenContext::interviewer(ReelRoutine &routine) { showGameReel(&routine); } -void DreamGenContext::drinker(ReelRoutine &routine) { +void DreamWebEngine::drinker(ReelRoutine &routine) { if (checkSpeed(routine)) { routine.incReelPointer(); if ( routine.reelPointer() == 115 || - (routine.reelPointer() == 106 && engine->randomNumber() >= 3)) + (routine.reelPointer() == 106 && randomNumber() >= 3)) routine.setReelPointer(105); } @@ -399,7 +427,7 @@ void DreamGenContext::drinker(ReelRoutine &routine) { addToPeopleList(&routine); } -void DreamGenContext::alleyBarkSound(ReelRoutine &routine) { +void DreamWebEngine::alleyBarkSound(ReelRoutine &routine) { uint16 prevReelPointer = routine.reelPointer() - 1; if (prevReelPointer == 0) { playChannel1(14); @@ -409,29 +437,25 @@ void DreamGenContext::alleyBarkSound(ReelRoutine &routine) { } } -void DreamGenContext::introMagic1(ReelRoutine &routine) { +void DreamWebEngine::introMagic1(ReelRoutine &routine) { if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 145) nextReelPointer = 121; routine.setReelPointer(nextReelPointer); if (nextReelPointer == 121) { - ++data.byte(kIntrocount); - push(es); - push(bx); + ++_introCount; intro1Text(); - bx = pop(); - es = pop(); - if (data.byte(kIntrocount) == 8) { - data.byte(kMapy) += 10; - data.byte(kNowinnewroom) = 1; + if (_introCount == 8) { + _mapY += 10; + _nowInNewRoom = 1; } } } showGameReel(&routine); } -void DreamGenContext::introMagic2(ReelRoutine &routine) { +void DreamWebEngine::introMagic2(ReelRoutine &routine) { if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 216) @@ -441,18 +465,18 @@ void DreamGenContext::introMagic2(ReelRoutine &routine) { showGameReel(&routine); } -void DreamGenContext::introMagic3(ReelRoutine &routine) { +void DreamWebEngine::introMagic3(ReelRoutine &routine) { if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 218) - data.byte(kGetback) = 1; + _getBack = 1; routine.setReelPointer(nextReelPointer); } showGameReel(&routine); - routine.mapX = data.byte(kMapx); + routine.mapX = _mapX; } -void DreamGenContext::candles1(ReelRoutine &routine) { +void DreamWebEngine::candles1(ReelRoutine &routine) { if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 44) @@ -462,7 +486,7 @@ void DreamGenContext::candles1(ReelRoutine &routine) { showGameReel(&routine); } -void DreamGenContext::candles2(ReelRoutine &routine) { +void DreamWebEngine::candles2(ReelRoutine &routine) { if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 238) @@ -472,7 +496,7 @@ void DreamGenContext::candles2(ReelRoutine &routine) { showGameReel(&routine); } -void DreamGenContext::smallCandle(ReelRoutine &routine) { +void DreamWebEngine::smallCandle(ReelRoutine &routine) { if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 37) @@ -482,10 +506,10 @@ void DreamGenContext::smallCandle(ReelRoutine &routine) { showGameReel(&routine); } -void DreamGenContext::introMusic(ReelRoutine &routine) { +void DreamWebEngine::introMusic(ReelRoutine &routine) { } -void DreamGenContext::candles(ReelRoutine &routine) { +void DreamWebEngine::candles(ReelRoutine &routine) { if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 167) @@ -495,7 +519,7 @@ void DreamGenContext::candles(ReelRoutine &routine) { showGameReel(&routine); } -void DreamGenContext::gates(ReelRoutine &routine) { +void DreamWebEngine::gates(ReelRoutine &routine) { if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 116) @@ -503,33 +527,28 @@ void DreamGenContext::gates(ReelRoutine &routine) { if (nextReelPointer >= 110) routine.period = 2; if (nextReelPointer == 120) { - data.byte(kGetback) = 1; + _getBack = 1; nextReelPointer = 119; } routine.setReelPointer(nextReelPointer); - push(es); - push(bx); - ax = nextReelPointer; - intro3Text(); - bx = pop(); - es = pop(); + intro3Text(nextReelPointer); } showGameReel(&routine); } -void DreamGenContext::security(ReelRoutine &routine) { +void DreamWebEngine::security(ReelRoutine &routine) { if (routine.reelPointer() == 32) { - if (data.byte(kLastweapon) == 1) { - data.word(kWatchingtime) = 10; - if ((data.byte(kManspath) == 9) && (data.byte(kFacing) == 0)) { - data.byte(kLastweapon) = (uint8)-1; + if (_vars._lastWeapon == 1) { + _vars._watchingTime = 10; + if ((_mansPath == 9) && (_facing == 0)) { + _vars._lastWeapon = (uint8)-1; routine.incReelPointer(); } } } else if (routine.reelPointer() == 69) return; else { - data.word(kWatchingtime) = 10; + _vars._watchingTime = 10; if (checkSpeed(routine)) routine.incReelPointer(); } @@ -537,43 +556,43 @@ void DreamGenContext::security(ReelRoutine &routine) { addToPeopleList(&routine); } -void DreamGenContext::edenInBath(ReelRoutine &routine) { - if (data.byte(kGeneraldead) == 0 || data.byte(kSartaindead) != 0) +void DreamWebEngine::edenInBath(ReelRoutine &routine) { + if (_vars._generalDead == 0 || _vars._sartainDead != 0) return; showGameReel(&routine); addToPeopleList(&routine); } -void DreamGenContext::louis(ReelRoutine &routine) { - if (data.byte(kRockstardead) != 0) +void DreamWebEngine::louis(ReelRoutine &routine) { + if (_vars._rockstarDead != 0) return; showGameReel(&routine); addToPeopleList(&routine); } -void DreamGenContext::handClap(ReelRoutine &routine) { +void DreamWebEngine::handClap(ReelRoutine &routine) { } -void DreamGenContext::carParkDrip(ReelRoutine &routine) { +void DreamWebEngine::carParkDrip(ReelRoutine &routine) { if (!checkSpeed(routine)) return; // cantdrip2 playChannel1(14); } -void DreamGenContext::foghornSound(ReelRoutine &routine) { - if (engine->randomNumber() == 198) +void DreamWebEngine::foghornSound(ReelRoutine &routine) { + if (randomNumber() == 198) playChannel1(13); } -void DreamGenContext::train(ReelRoutine &routine) { +void DreamWebEngine::train(ReelRoutine &routine) { // The original code has logic for this, but it is disabled } -void DreamGenContext::louisChair(ReelRoutine &routine) { - if (data.byte(kRockstardead) == 0) +void DreamWebEngine::louisChair(ReelRoutine &routine) { + if (_vars._rockstarDead == 0) return; // notlouis2 if (checkSpeed(routine)) { @@ -583,7 +602,7 @@ void DreamGenContext::louisChair(ReelRoutine &routine) { } else if (nextReelPointer != 185) { routine.setReelPointer(nextReelPointer); } else { - if (engine->randomNumber() < 245) + if (randomNumber() < 245) routine.setReelPointer(182); // Restart Louis else routine.setReelPointer(nextReelPointer); @@ -594,19 +613,19 @@ void DreamGenContext::louisChair(ReelRoutine &routine) { addToPeopleList(&routine); } -void DreamGenContext::bossMan(ReelRoutine &routine) { +void DreamWebEngine::bossMan(ReelRoutine &routine) { if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 4) { - if (data.byte(kGunpassflag) != 1 && engine->randomNumber() >= 10) + if (_vars._gunPassFlag != 1 && randomNumber() >= 10) nextReelPointer = 0; } else if (nextReelPointer == 20) { - if (data.byte(kGunpassflag) != 1) + if (_vars._gunPassFlag != 1) nextReelPointer = 0; } else if (nextReelPointer == 41) { nextReelPointer = 0; - data.byte(kGunpassflag)++; + _vars._gunPassFlag++; routine.b7 = 10; } @@ -617,49 +636,40 @@ void DreamGenContext::bossMan(ReelRoutine &routine) { addToPeopleList(&routine); if (routine.b7 & 128) - data.byte(kTalkedtoboss) = 1; + _vars._talkedToBoss = 1; } -void DreamGenContext::priest(ReelRoutine &routine) { +void DreamWebEngine::priest(ReelRoutine &routine) { if (routine.reelPointer() == 8) return; // priestspoken - data.byte(kPointermode) = 0; - data.word(kWatchingtime) = 2; + _pointerMode = 0; + _vars._watchingTime = 2; if (checkSpeed(routine)) { routine.incReelPointer(); - push(es); - push(bx); priestText(routine); - bx = pop(); - es = pop(); } } -void DreamGenContext::priestText(ReelRoutine &routine) { +void DreamWebEngine::priestText(ReelRoutine &routine) { uint16 reel = routine.reelPointer(); if (reel < 2 || reel >= 7 || (reel & 1)) return; // nopriesttext - al = ((reel & 0xFF) >> 1) + 50; - bl = 72; - bh = 80; - cx = 54; - dx = 1; - setupTimedUse(); + setupTimedUse((reel >> 1) + 50, 54, 1, 72, 80); } -void DreamGenContext::monkAndRyan(ReelRoutine &routine) { +void DreamWebEngine::monkAndRyan(ReelRoutine &routine) { if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 83) { - data.byte(kIntrocount)++; + _introCount++; textForMonk(); nextReelPointer = 77; - if (data.byte(kIntrocount) == 57) { - data.byte(kGetback) = 1; + if (_introCount == 57) { + _getBack = 1; return; } } @@ -670,14 +680,14 @@ void DreamGenContext::monkAndRyan(ReelRoutine &routine) { showGameReel(&routine); } -void DreamGenContext::copper(ReelRoutine &routine) { +void DreamWebEngine::copper(ReelRoutine &routine) { if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 94) { nextReelPointer = 64; } else if (nextReelPointer == 81 || nextReelPointer == 66) { // Might wait - if (engine->randomNumber() >= 7) + if (randomNumber() >= 7) nextReelPointer--; } @@ -688,18 +698,18 @@ void DreamGenContext::copper(ReelRoutine &routine) { addToPeopleList(&routine); } -void DreamGenContext::introMonks1(ReelRoutine &routine) { +void DreamWebEngine::introMonks1(ReelRoutine &routine) { if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 80) { - data.byte(kMapy) += 10; - data.byte(kNowinnewroom) = 1; + _mapY += 10; + _nowInNewRoom = 1; showGameReel(&routine); return; } else if (nextReelPointer == 30) { - data.byte(kMapy) -= 10; - data.byte(kNowinnewroom) = 1; + _mapY -= 10; + _nowInNewRoom = 1; nextReelPointer = 51; } @@ -709,50 +719,38 @@ void DreamGenContext::introMonks1(ReelRoutine &routine) { nextReelPointer == 25 || nextReelPointer == 61 || nextReelPointer == 71) { // Wait step - push(es); - push(bx); - intro2Text(); - bx = pop(); - es = pop(); + intro2Text(nextReelPointer); routine.counter = (uint8)-20; } } showGameReel(&routine); - routine.mapY = data.byte(kMapy); + routine.mapY = _mapY; } -void DreamGenContext::introMonks2(ReelRoutine &routine) { +void DreamWebEngine::introMonks2(ReelRoutine &routine) { if (checkSpeed(routine)) { uint16 nextReelPointer = routine.reelPointer() + 1; if (nextReelPointer == 87) { - data.byte(kIntrocount)++; - push(es); - push(bx); + _introCount++; monks2text(); - bx = pop(); - es = pop(); - if (data.byte(kIntrocount), 19) + if (_introCount == 19) nextReelPointer = 87; else nextReelPointer = 74; } if (nextReelPointer == 110) { - data.byte(kIntrocount)++; - push(es); - push(bx); + _introCount++; monks2text(); - bx = pop(); - es = pop(); - if (data.byte(kIntrocount) == 35) + if (_introCount == 35) nextReelPointer = 111; else nextReelPointer = 98; } else if (nextReelPointer == 176) { - data.byte(kGetback) = 1; + _getBack = 1; } else if (nextReelPointer == 125) { nextReelPointer = 140; } @@ -763,27 +761,361 @@ void DreamGenContext::introMonks2(ReelRoutine &routine) { showGameReel(&routine); } -void DreamGenContext::soldier1(ReelRoutine &routine) { +void DreamWebEngine::soldier1(ReelRoutine &routine) { if (routine.reelPointer() != 0) { - data.word(kWatchingtime) = 10; + _vars._watchingTime = 10; if (routine.reelPointer() == 30) { - data.byte(kCombatcount)++; - if (data.byte(kCombatcount) == 40) - data.byte(kMandead) = 2; + _vars._combatCount++; + if (_vars._combatCount == 40) + _vars._manDead = 2; } else if (checkSpeed(routine)) { // Not after shot routine.incReelPointer(); } - } else if (data.byte(kLastweapon) == 1) { - data.word(kWatchingtime) = 10; - if (data.byte(kManspath) == 2 && data.byte(kFacing) == 4) + } else if (_vars._lastWeapon == 1) { + _vars._watchingTime = 10; + if (_mansPath == 2 && _facing == 4) routine.incReelPointer(); - data.byte(kLastweapon) = 0xFF; - data.byte(kCombatcount) = 0; + _vars._lastWeapon = 0xFF; + _vars._combatCount = 0; + } + + showGameReel(&routine); + addToPeopleList(&routine); +} + +void DreamWebEngine::receptionist(ReelRoutine &routine) { + if (checkSpeed(routine)) { + if (_vars._cardPassFlag == 1) { + // Set card + _vars._cardPassFlag++; + routine.b7 = 1; + routine.setReelPointer(64); + } + + if (routine.reelPointer() != 58) { + // notdes1 + if (routine.reelPointer() != 60) { + // notdes2 + if (routine.reelPointer() != 88) + routine.incReelPointer(); // not end card + else + routine.setReelPointer(53); + } else if (randomNumber() >= 240) { + routine.setReelPointer(53); + } + } else if (randomNumber() >= 30) { + routine.setReelPointer(55); + } else { + // notdes2 + if (routine.reelPointer() != 88) + routine.incReelPointer(); // not end card + else + routine.setReelPointer(53); + } } showGameReel(&routine); addToPeopleList(&routine); + if (routine.b7 & 128) + _vars._talkedToRecep = 1; +} + +void DreamWebEngine::bartender(ReelRoutine &routine) { + if (checkSpeed(routine)) { + if (routine.reelPointer() == 86) { + if (randomNumber() >= 18) + routine.setReelPointer(81); + else + routine.incReelPointer(); // notsmoket2 + } else if (routine.reelPointer() == 103) { + routine.setReelPointer(81); // notsmoket1 + } else { + routine.incReelPointer(); // notsmoket2 + } + } + + showGameReel(&routine); + if (_vars._gunPassFlag == 1) + routine.b7 = 9; // got gun + + addToPeopleList(&routine); +} + +void DreamWebEngine::heavy(ReelRoutine &routine) { + routine.b7 &= 127; + if (routine.reelPointer() != 43) { + _vars._watchingTime = 10; + if (routine.reelPointer() == 70) { + // After shot + _vars._combatCount++; + if (_vars._combatCount == 80) + _vars._manDead = 2; + } else { + if (checkSpeed(routine)) + routine.incReelPointer(); + } + } else if (_vars._lastWeapon == 1 && _mansPath == 5 && _facing == 4) { + // Heavy wait + _vars._lastWeapon = (byte)-1; + routine.incReelPointer(); + _vars._combatCount = 0; + } + + showGameReel(&routine); + addToPeopleList(&routine); +} + +void DreamWebEngine::helicopter(ReelRoutine &routine) { + if (routine.reelPointer() == 203) { + // Won helicopter + _pointerMode = 0; + return; + } + + if (checkSpeed(routine)) { + uint16 nextReelPointer = routine.reelPointer() + 1; + if (nextReelPointer == 53) { + // Before killing helicopter + _vars._combatCount++; + if (_vars._combatCount >= 8) + _vars._manDead = 2; + nextReelPointer = 49; + } else if (nextReelPointer == 9) { + nextReelPointer--; + if (_vars._lastWeapon == 1) { + _vars._lastWeapon = (byte)-1; + nextReelPointer = 55; + } else { + nextReelPointer = 5; + _vars._combatCount++; + if (_vars._combatCount == 20) { + _vars._combatCount = 0; + nextReelPointer = 9; + } + } + } + + routine.setReelPointer(nextReelPointer); + } + + showGameReel(&routine); + routine.mapX = _mapX; + if (routine.reelPointer() < 9 && _vars._combatCount >= 7) { + _pointerMode = 2; + _vars._watchingTime = 0; + } else { + // Not waiting helicopter + _pointerMode = 0; + _vars._watchingTime = 2; + } +} + +void DreamWebEngine::mugger(ReelRoutine &routine) { + if (routine.reelPointer() != 138) { + if (routine.reelPointer() == 176) + return; // endmugger2 + + if (routine.reelPointer() == 2) + _vars._watchingTime = 175 * 2; // set watch + + if (checkSpeed(routine)) + routine.incReelPointer(); + + showGameReel(&routine); + routine.mapX = _mapX; + } else { + createPanel2(); + showIcon(); + + const uint8 *string = (const uint8 *)_puzzleText.getString(41); + uint16 y = 104; + printDirect(&string, 33 + 20, &y, 241, 241 & 1); + workToScreen(); + hangOn(300); + routine.setReelPointer(140); + _mansPath = 2; + _finalDest = 2; + findXYFromPath(); + _resetManXY = 1; + _command = findExObject("WETA"); + _objectType = kExObjectType; + removeObFromInv(); + _command = findExObject("WETB"); + _objectType = kExObjectType; + removeObFromInv(); + makeMainScreen(); + setupTimedUse(48, 70, 10, 68 - 32, 54 + 64); + _vars._beenMugged = 1; + } +} + +// Exiting the elevator of Sartain's industries, Sartain (the businessman) and +// two bodyguards are expecting Ryan. +void DreamWebEngine::businessMan(ReelRoutine &routine) { + _pointerMode = 0; + _vars._watchingTime = 2; + if (routine.reelPointer() == 2) + setupTimedUse(49, 30, 1, 68, 174); // First + + if (routine.reelPointer() == 95) { + // Businessman combat won - end + _pointerMode = 0; + _vars._watchingTime = 0; + return; + } + + if (routine.reelPointer() == 49) + return; // Businessman combat end + + if (checkSpeed(routine)) { + uint16 nextReelPointer = routine.reelPointer() + 1; + if (nextReelPointer == 48) { + _vars._manDead = 2; // before dead body + } else if (nextReelPointer == 15) { + nextReelPointer--; + if (_vars._lastWeapon == 3) { + // Shield on bus + _vars._lastWeapon = (byte)-1; + _vars._combatCount = 0; + nextReelPointer = 51; + } else { + // No shield on businessman + _vars._combatCount++; + if (_vars._combatCount == 20) { + _vars._combatCount = 0; + nextReelPointer = 15; + } + } + } else { + // Businessman combat won + if (nextReelPointer == 91) { + turnPathOn(0); + turnPathOn(1); + turnPathOn(2); + turnPathOff(3); + _mansPath = 5; + _finalDest = 5; + findXYFromPath(); + _resetManXY = 1; + nextReelPointer = 92; + } + } + + routine.setReelPointer(nextReelPointer); + } + + showGameReel(&routine); + routine.mapY = _mapY; + if (routine.reelPointer() == 14) { + _vars._watchingTime = 0; + _pointerMode = 2; + } +} + +void DreamWebEngine::endGameSeq(ReelRoutine &routine) { + if (checkSpeed(routine)) { + uint16 nextReelPointer = routine.reelPointer() + 1; + if (nextReelPointer == 51 && _introCount != 140) { + _introCount++; + textForEnd(); + nextReelPointer = 50; + } + + routine.setReelPointer(nextReelPointer); + if (nextReelPointer == 134) { + fadeScreenDownHalf(); + } else if (nextReelPointer == 324) { + fadeScreenDowns(); + _volumeTo = 7; + _volumeDirection = 1; + } + + if (nextReelPointer == 340) + _getBack = 1; + } + + showGameReel(&routine); + routine.mapY = _mapY; + + if (routine.reelPointer() == 145) { + routine.setReelPointer(146); + rollEndCreditsGameWon(); + } +} + +void DreamWebEngine::poolGuard(ReelRoutine &routine) { + if (routine.reelPointer() == 214 || routine.reelPointer() == 258) { + // Combat over 2 + showGameReel(&routine); + _vars._watchingTime = 2; + _pointerMode = 0; + _vars._combatCount++; + if (_vars._combatCount < 100) + return; // doneover2 + _vars._watchingTime = 0; + _vars._manDead = 2; + return; + } else if (routine.reelPointer() == 185) { + // Combat over 1 + _vars._watchingTime = 0; + _pointerMode = 0; + turnPathOn(0); + turnPathOff(1); + return; + } + + if (routine.reelPointer() == 0) + turnPathOn(0); // first pool + + if (checkSpeed(routine)) { + uint16 nextReelPointer = routine.reelPointer() + 1; + + if (nextReelPointer != 122) { + // Not end guard 1 + if (nextReelPointer == 147) { + nextReelPointer--; + if (_vars._lastWeapon == 1) { + // Gun on pool + _vars._lastWeapon = (byte)-1; + nextReelPointer = 147; + } else { + // Gun not on pool + _vars._combatCount++; + if (_vars._combatCount == 40) { + _vars._combatCount = 0; + nextReelPointer = 220; + } + } + } + } else { + nextReelPointer--; + + if (_vars._lastWeapon == 2) { + // Axe on pool + _vars._lastWeapon = (byte)-1; + nextReelPointer = 122; + } else { + _vars._combatCount++; + if (_vars._combatCount == 40) { + _vars._combatCount = 0; + nextReelPointer = 195; + } + } + } + + routine.setReelPointer(nextReelPointer); + } + + showGameReel(&routine); + + if (routine.reelPointer() != 121 && routine.reelPointer() != 146) { + _pointerMode = 0; + _vars._watchingTime = 2; + } else { + _pointerMode = 2; + _vars._watchingTime = 0; + } } -} // End of namespace DreamGen +} // End of namespace DreamWeb diff --git a/engines/dreamweb/print.cpp b/engines/dreamweb/print.cpp index 0fd596ceac..a6b93a5590 100644 --- a/engines/dreamweb/print.cpp +++ b/engines/dreamweb/print.cpp @@ -22,9 +22,9 @@ #include "dreamweb/dreamweb.h" -namespace DreamGen { +namespace DreamWeb { -void DreamBase::printBoth(const Frame *charSet, uint16 *x, uint16 y, uint8 c, uint8 nextChar) { +void DreamWebEngine::printBoth(const GraphicsFile &charSet, uint16 *x, uint16 y, uint8 c, uint8 nextChar) { uint16 newX = *x; uint8 width, height; printChar(charSet, &newX, y, c, nextChar, &width, &height); @@ -32,7 +32,7 @@ void DreamBase::printBoth(const Frame *charSet, uint16 *x, uint16 y, uint8 c, ui *x = newX; } -uint8 DreamBase::getNextWord(const Frame *charSet, const uint8 *string, uint8 *totalWidth, uint8 *charCount) { +uint8 DreamWebEngine::getNextWord(const GraphicsFile &charSet, const uint8 *string, uint8 *totalWidth, uint8 *charCount) { *totalWidth = 0; *charCount = 0; while (true) { @@ -47,17 +47,17 @@ uint8 DreamBase::getNextWord(const Frame *charSet, const uint8 *string, uint8 *t *totalWidth += 6; return 0; } - firstChar = engine->modifyChar(firstChar); + firstChar = modifyChar(firstChar); if (firstChar != 255) { uint8 secondChar = *string; - uint8 width = charSet[firstChar - 32 + data.word(kCharshift)].width; + uint8 width = charSet._frames[firstChar - 32 + _charShift].width; width = kernChars(firstChar, secondChar, width); *totalWidth += width; } } } -void DreamBase::printChar(const Frame *charSet, uint16* x, uint16 y, uint8 c, uint8 nextChar, uint8 *width, uint8 *height) { +void DreamWebEngine::printChar(const GraphicsFile &charSet, uint16* x, uint16 y, uint8 c, uint8 nextChar, uint8 *width, uint8 *height) { if (c == 255) return; @@ -66,48 +66,47 @@ void DreamBase::printChar(const Frame *charSet, uint16* x, uint16 y, uint8 c, ui width = &dummyWidth; if (height == NULL) height = &dummyHeight; - if (data.byte(kForeignrelease)) + if (_foreignRelease) y -= 3; - uint16 tmp = c - 32 + data.word(kCharshift); + uint16 tmp = c - 32 + _charShift; showFrame(charSet, *x, y, tmp & 0x1ff, (tmp >> 8) & 0xfe, width, height); - if (data.byte(kKerning), 0) + if (_kerning == 0) *width = kernChars(c, nextChar, *width); (*x) += *width; } -void DreamBase::printChar(const Frame *charSet, uint16 x, uint16 y, uint8 c, uint8 nextChar, uint8 *width, uint8 *height) { +void DreamWebEngine::printChar(const GraphicsFile &charSet, uint16 x, uint16 y, uint8 c, uint8 nextChar, uint8 *width, uint8 *height) { printChar(charSet, &x, y, c, nextChar, width, height); } -uint8 DreamBase::printSlow(const uint8 *string, uint16 x, uint16 y, uint8 maxWidth, bool centered) { - data.byte(kPointerframe) = 1; - data.byte(kPointermode) = 3; - const Frame* charSet = (const Frame *)getSegment(data.word(kCharset1)).ptr(0, 0); +uint8 DreamWebEngine::printSlow(const uint8 *string, uint16 x, uint16 y, uint8 maxWidth, bool centered) { + _pointerFrame = 1; + _pointerMode = 3; do { uint16 offset = x; - uint16 charCount = getNumber(charSet, string, maxWidth, centered, &offset); + uint16 charCount = getNumber(_charset1, string, maxWidth, centered, &offset); do { uint8 c0 = string[0]; uint8 c1 = string[1]; uint8 c2 = string[2]; - c0 = engine->modifyChar(c0); - printBoth(charSet, &offset, y, c0, c1); + c0 = modifyChar(c0); + printBoth(_charset1, &offset, y, c0, c1); if ((c1 == 0) || (c1 == ':')) { return 0; } if (charCount != 1) { - c1 = engine->modifyChar(c1); - data.word(kCharshift) = 91; + c1 = modifyChar(c1); + _charShift = 91; uint16 offset2 = offset; - printBoth(charSet, &offset2, y, c1, c2); - data.word(kCharshift) = 0; + printBoth(_charset1, &offset2, y, c1, c2); + _charShift = 0; for (int i=0; i<2; ++i) { uint16 mouseState = waitFrames(); - if (data.byte(kQuitrequested)) + if (_quitRequested) return 0; if (mouseState == 0) continue; - if (mouseState != data.word(kOldbutton)) { + if (mouseState != _oldButton) { return 1; } } @@ -120,22 +119,13 @@ uint8 DreamBase::printSlow(const uint8 *string, uint16 x, uint16 y, uint8 maxWid } while (true); } -void DreamGenContext::printDirect() { - uint16 y = bx; - const uint8 *initialString = es.ptr(si, 0); - const uint8 *string = initialString; - al = DreamBase::printDirect(&string, di, &y, dl, (bool)(dl & 1)); - si += (string - initialString); - bx = y; -} - -uint8 DreamBase::printDirect(const uint8* string, uint16 x, uint16 y, uint8 maxWidth, bool centered) { +uint8 DreamWebEngine::printDirect(const uint8* string, uint16 x, uint16 y, uint8 maxWidth, bool centered) { return printDirect(&string, x, &y, maxWidth, centered); } -uint8 DreamBase::printDirect(const uint8** string, uint16 x, uint16 *y, uint8 maxWidth, bool centered) { - data.word(kLastxpos) = x; - const Frame *charSet = engine->currentCharset(); +uint8 DreamWebEngine::printDirect(const uint8** string, uint16 x, uint16 *y, uint8 maxWidth, bool centered) { + _lastXPos = x; + const GraphicsFile &charSet = *_currentCharset; while (true) { uint16 offset = x; uint8 charCount = getNumber(charSet, *string, maxWidth, centered, &offset); @@ -147,17 +137,17 @@ uint8 DreamBase::printDirect(const uint8** string, uint16 x, uint16 *y, uint8 ma if ((c == 0) || (c == ':')) { return c; } - c = engine->modifyChar(c); + c = modifyChar(c); uint8 width, height; printChar(charSet, &i, *y, c, nextChar, &width, &height); - data.word(kLastxpos) = i; + _lastXPos = i; --charCount; } while (charCount); - *y += data.word(kLinespacing); + *y += _lineSpacing; } } -uint8 DreamBase::getNumber(const Frame *charSet, const uint8 *string, uint16 maxWidth, bool centered, uint16* offset) { +uint8 DreamWebEngine::getNumber(const GraphicsFile &charSet, const uint8 *string, uint16 maxWidth, bool centered, uint16* offset) { uint8 totalWidth = 0; uint8 charCount = 0; while (true) { @@ -196,7 +186,7 @@ uint8 DreamBase::getNumber(const Frame *charSet, const uint8 *string, uint16 max } } -uint8 DreamBase::kernChars(uint8 firstChar, uint8 secondChar, uint8 width) { +uint8 DreamWebEngine::kernChars(uint8 firstChar, uint8 secondChar, uint8 width) { if ((firstChar == 'a') || (firstChar == 'u')) { if ((secondChar == 'n') || (secondChar == 't') || (secondChar == 'r') || (secondChar == 'i') || (secondChar == 'l')) return width-1; @@ -204,31 +194,23 @@ uint8 DreamBase::kernChars(uint8 firstChar, uint8 secondChar, uint8 width) { return width; } -uint16 DreamBase::waitFrames() { +uint16 DreamWebEngine::waitFrames() { readMouse(); showPointer(); vSync(); dumpPointer(); delPointer(); - return data.word(kMousebutton); + return _mouseButton; } -void DreamGenContext::monPrint() { - uint16 originalBx = bx; - const char *string = (const char *)es.ptr(bx, 0); - const char *nextString = monPrint(string); - bx = originalBx + (nextString - string); -} - -const char *DreamBase::monPrint(const char *string) { - data.byte(kKerning) = 1; - uint16 x = data.word(kMonadx); - Frame *charset = engine->tempCharset(); +const char *DreamWebEngine::monPrint(const char *string) { + _kerning = 1; + uint16 x = _monAdX; const char *iterator = string; bool done = false; while (!done) { - uint16 count = getNumber(charset, (const uint8 *)iterator, 166, false, &x); + uint16 count = getNumber(_monitorCharset, (const uint8 *)iterator, 166, false, &x); do { char c = *iterator++; if (c == ':') @@ -238,29 +220,116 @@ const char *DreamBase::monPrint(const char *string) { break; } if (c == '%') { - data.byte(kLasttrigger) = *iterator; + _vars._lastTrigger = *iterator; iterator += 2; done = true; break; } - c = engine->modifyChar(c); - printChar(charset, &x, data.word(kMonady), c, 0, NULL, NULL); - data.word(kCurslocx) = x; - data.word(kCurslocy) = data.word(kMonady); - data.word(kMaintimer) = 1; + c = modifyChar(c); + printChar(_monitorCharset, &x, _monAdY, c, 0, NULL, NULL); + _cursLocX = x; + _cursLocY = _monAdY; + _mainTimer = 1; printCurs(); vSync(); lockMon(); delCurs(); } while (--count); - x = data.word(kMonadx); + x = _monAdX; scrollMonitor(); - data.word(kCurslocx) = data.word(kMonadx); + _cursLocX = _monAdX; } - data.byte(kKerning) = 0; + _kerning = 0; return iterator; } -} // End of namespace DreamGen +void DreamWebEngine::rollEndCreditsGameWon() { + playChannel0(16, 255); + _volume = 7; + _volumeTo = 0; + _volumeDirection = -1; + + multiGet(_mapStore, 75, 20, 160, 160); + + const uint8 *string = getTextInFile1(3); + const int linespacing = _lineSpacing; + + for (int i = 0; i < 254; ++i) { + // Output the text, initially with an offset of 10 pixels, + // then move it up one pixel until we shifted it by a complete + // line of text. + for (int j = 0; j < linespacing; ++j) { + vSync(); + multiPut(_mapStore, 75, 20, 160, 160); + vSync(); + + // Output up to 18 lines of text + uint16 y = 10 - j; + const uint8 *tmp_str = string; + for (int k = 0; k < 18; ++k) { + printDirect(&tmp_str, 75, &y, 160 + 1, true); + y += linespacing; + } + + vSync(); + multiDump(75, 20, 160, 160); + } + + // Skip to the next text line + byte c; + do { + c = *string++; + } while (c != ':' && c != 0); + } + + hangOn(100); + panelToMap(); + fadeScreenUpHalf(); +} + +void DreamWebEngine::rollEndCreditsGameLost() { + multiGet(_mapStore, 25, 20, 160, 160); + + const uint8 *string = getTextInFile1(49); + const int linespacing = _lineSpacing; + + for (int i = 0; i < 80; ++i) { + // Output the text, initially with an offset of 10 pixels, + // then move it up one pixel until we shifted it by a complete + // line of text. + for (int j = 0; j < linespacing; ++j) { + vSync(); + multiPut(_mapStore, 25, 20, 160, 160); + vSync(); + + // Output up to 18 lines of text + uint16 y = 10 - j; + const uint8 *tmp_str = string; + for (int k = 0; k < 18; ++k) { + printDirect(&tmp_str, 25, &y, 160 + 1, true); + y += linespacing; + } + + vSync(); + multiDump(25, 20, 160, 160); + + if (_lastHardKey == 1) + return; + } + + // Skip to the next text line + byte c; + do { + c = *string++; + } while (c != ':' && c != 0); + + if (_lastHardKey == 1) + return; + } + + hangOne(120); +} + +} // End of namespace DreamWeb diff --git a/engines/dreamweb/rain.cpp b/engines/dreamweb/rain.cpp new file mode 100644 index 0000000000..7db4744cbf --- /dev/null +++ b/engines/dreamweb/rain.cpp @@ -0,0 +1,194 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "dreamweb/dreamweb.h" + +namespace DreamWeb { + +void DreamWebEngine::showRain() { + Common::List<Rain>::iterator i; + + // Do nothing if there's no rain at all + if (_rainList.empty()) + return; + + const uint8 *frameData = _mainSprites.getFrameData(58); + + for (i = _rainList.begin(); i != _rainList.end(); ++i) { + Rain &rain = *i; + uint16 y = rain.y + _mapAdY + _mapYStart; + uint16 x = rain.x + _mapAdX + _mapXStart; + uint16 size = rain.size; + uint16 offset = (rain.w3 - rain.b5) & 511; + rain.w3 = offset; + const uint8 *src = frameData + offset; + uint8 *dst = workspace() + y * 320 + x; + for (uint16 j = 0; j < size; ++j) { + uint8 v = src[j]; + if (v != 0) + *dst = v; + dst += 320-1; // advance diagonally + } + } + + if (_channel1Playing != 255) + return; + if (_realLocation == 2 && _vars._beenMugged != 1) + return; + if (_realLocation == 55) + return; + + if (randomNumber() >= 1) // play thunder with 1 in 256 chance + return; + + uint8 soundIndex; + if (_channel0Playing != 6) + soundIndex = 4; + else + soundIndex = 7; + playChannel1(soundIndex); +} + +uint8 DreamWebEngine::getBlockOfPixel(uint8 x, uint8 y) { + uint8 flag, flagEx, type, flagX, flagY; + checkOne(x + _mapXStart, y + _mapYStart, &flag, &flagEx, &type, &flagX, &flagY); + if (flag & 1) + return 0; + else + return type; +} + +void DreamWebEngine::splitIntoLines(uint8 x, uint8 y) { + do { + Rain rain; + + // Look for line start + while (!getBlockOfPixel(x, y)) { + --x; + ++y; + if (x == 0 || y >= _mapYSize) + return; + } + + rain.x = x; + rain.y = y; + + uint8 length = 1; + + // Look for line end + while (getBlockOfPixel(x, y)) { + --x; + ++y; + if (x == 0 || y >= _mapYSize) + break; + ++length; + } + + rain.size = length; + rain.w3 = _rnd.getRandomNumber(65535); + rain.b5 = _rnd.getRandomNumberRng(4, 7); + _rainList.push_back(rain); + } while (x > 0 && y < _mapYSize); +} + +struct RainLocation { + uint8 location; + uint8 x, y; + uint8 rainSpacing; +}; + +static const RainLocation rainLocationList[] = { + { 1,44,10,16 }, + { 4,11,30,14 }, + { 4,22,30,14 }, + { 3,33,10,14 }, + { 10,33,30,14 }, + { 10,22,30,24 }, + { 9,22,10,14 }, + { 2,33,0,14 }, + { 2,22,0,14 }, + { 6,11,30,14 }, + { 7,11,20,18 }, + { 7,0,20,18 }, + { 7,0,30,18 }, + { 55,44,0,14 }, + { 5,22,30,14 }, + + { 8,0,10,18 }, + { 8,11,10,18 }, + { 8,22,10,18 }, + { 8,33,10,18 }, + { 8,33,20,18 }, + { 8,33,30,18 }, + { 8,33,40,18 }, + { 8,22,40,18 }, + { 8,11,40,18 }, + + { 21,44,20,18 }, + { 255,0,0,0 } +}; + +void DreamWebEngine::initRain() { + const RainLocation *r = rainLocationList; + _rainList.clear(); + + uint8 rainSpacing = 0; + + // look up location in rainLocationList to determine rainSpacing + for (r = rainLocationList; r->location != 0xff; ++r) { + if (r->location == _realLocation && + r->x == _mapX && r->y == _mapY) { + rainSpacing = r->rainSpacing; + break; + } + } + + if (rainSpacing == 0) { + // location not found in rainLocationList: no rain + return; + } + + // start lines of rain from top of screen + uint8 x = 4; + do { + uint8 delta = _rnd.getRandomNumberRng(3, rainSpacing - 1); + x += delta; + if (x >= _mapXSize) + break; + + splitIntoLines(x, 0); + } while (true); + + // start lines of rain from side of screen + uint8 y = 0; + do { + uint8 delta = _rnd.getRandomNumberRng(3, rainSpacing - 1); + y += delta; + if (y >= _mapYSize) + break; + + splitIntoLines(_mapXSize - 1, y); + } while (true); +} + +} // End of namespace DreamWeb + diff --git a/engines/dreamweb/runtime.h b/engines/dreamweb/runtime.h deleted file mode 100644 index 9b70d164a6..0000000000 --- a/engines/dreamweb/runtime.h +++ /dev/null @@ -1,418 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef DREAMGEN_RUNTIME_H -#define DREAMGEN_RUNTIME_H - -#include <assert.h> -#include "common/scummsys.h" -#include "common/array.h" -#include "common/debug.h" - -#include "dreamweb/segment.h" - -namespace DreamGen { - -struct Register { - union { - uint16 _value; - uint8 _part[2]; - }; - inline Register(): _value() {} - inline Register& operator=(uint16 v) { _value = v; return *this; } - inline operator uint16&() { return _value; } -}; - -template<int kIndex> //from low to high -struct RegisterPart { - uint8 &_value; - - explicit inline RegisterPart(Register ®) : _value(reg._part[kIndex]) {} - - inline operator uint8&() { - return _value; - } - - inline RegisterPart& operator=(const RegisterPart& o) { - _value = o._value; - return *this; - } - - inline RegisterPart& operator=(uint8 v) { - _value = v; - return *this; - } -}; - -#ifdef SCUMM_LITTLE_ENDIAN - typedef RegisterPart<0> LowPartOfRegister; - typedef RegisterPart<1> HighPartOfRegister; -#else - typedef RegisterPart<1> LowPartOfRegister; - typedef RegisterPart<0> HighPartOfRegister; -#endif - -struct Flags { - bool _z, _c, _s, _o; - inline Flags(): _z(true), _c(false), _s(false), _o(false) {} - - inline bool z() const { return _z; } - inline bool c() const { return _c; } - inline bool s() const { return _s; } - - inline bool l() const { return _o != _s; } - inline bool le() const { return _o != _s|| _z; } - - inline void update_zs(uint8 v) { - _s = v & 0x80; - _z = v == 0; - } - - inline void update_zs(uint16 v) { - _s = v & 0x8000; - _z = v == 0; - } - - inline void update_o(uint8 v, uint8 a, uint8 b) { - uint8 s1 = a & 0x80, s2 = b & 0x80; - _o = (s1 == s2) && (v & 0x80) != s1; - } - - inline void update_o(uint16 v, uint16 a, uint16 b) { - uint16 s1 = a & 0x8000, s2 = b & 0x8000; - _o = (s1 == s2) && (v & 0x8000) != s1; - } -}; - -class Context { -public: - Register ax, dx, bx, cx, si, di; - LowPartOfRegister al; - HighPartOfRegister ah; - LowPartOfRegister bl; - HighPartOfRegister bh; - LowPartOfRegister cl; - HighPartOfRegister ch; - LowPartOfRegister dl; - HighPartOfRegister dh; - - SegmentRef cs; - MutableSegmentRef ds; - MutableSegmentRef es; - Flags flags; - - Context(SegmentManager *segMan): al(ax), ah(ax), bl(bx), bh(bx), cl(cx), ch(cx), dl(dx), dh(dx), - cs(segMan->data), - ds(segMan, segMan->data), - es(segMan, segMan->data) { - - } - - inline void _cmp(uint8 a, uint8 b) { - _sub(a, b); - } - - inline void _cmp(uint16 a, uint16 b) { - _sub(a, b); - } - - inline void _test(uint8 a, uint8 b) { - _and(a, b); - } - - inline void _test(uint16 a, uint16 b) { - _and(a, b); - } - - inline void _add(uint8 &dst, uint8 src) { - unsigned r = (unsigned)dst + src; - flags.update_o((uint8)r, dst, src); - flags._c = r >= 0x100; - dst = r; - flags.update_zs(dst); - } - - inline void _add(uint16 &dst, uint16 src) { - unsigned r = (unsigned)dst + src; - flags.update_o((uint16)r, dst, src); - flags._c = r >= 0x10000; - dst = r; - flags.update_zs(dst); - } - - inline void _sub(uint8 &dst, uint8 src) { - flags.update_o(uint8(dst - src), dst, (uint8)-src); - flags._c = dst < src; - dst -= src; - flags.update_zs(dst); - } - - inline void _sub(uint16 &dst, uint16 src) { - flags.update_o(uint16(dst - src), dst, (uint16)-src); - flags._c = dst < src; - dst -= src; - flags.update_zs(dst); - } - - inline void _inc(uint8 &dst) { - flags.update_o((uint8)(dst + 1), dst, 1); - ++dst; - flags.update_zs(dst); - } - - inline void _inc(uint16 &dst) { - flags.update_o((uint16)(dst + 1), dst, 1); - ++dst; - flags.update_zs(dst); - } - - inline void _dec(uint8 &dst) { - flags.update_o(uint8(dst - 1), dst, 1); - --dst; - flags.update_zs(dst); - } - - inline void _dec(uint16 &dst) { - flags.update_o(uint16(dst - 1), dst, 1); - --dst; - flags.update_zs(dst); - } - - inline void _and(uint8 &dst, uint8 src) { - dst &= src; - flags.update_zs(dst); - flags._c = flags._o = false; - } - - inline void _and(uint16 &dst, uint16 src) { - dst &= src; - flags.update_zs(dst); - flags._c = flags._o = false; - } - - inline void _or(uint8 &dst, uint8 src) { - dst |= src; - flags.update_zs(dst); - flags._c = flags._o = false; - } - - inline void _or(uint16 &dst, uint16 src) { - dst |= src; - flags.update_zs(dst); - flags._c = flags._o = false; - } - - inline void _xor(uint8 &dst, uint8 src) { - dst ^= src; - flags.update_zs(dst); - flags._c = flags._o = false; - } - - inline void _xor(uint16 &dst, uint16 src) { - dst ^= src; - flags.update_zs(dst); - flags._c = flags._o = false; - } - - inline void _shr(uint8 &dst, uint8 src) { - src &= 0x1f; - if (src > 0) { - dst >>= (src - 1); - flags._c = dst & 1; - dst >>= 1; - flags.update_zs(dst); - } - if (src == 1) - flags._o = dst & 0x80; - } - - inline void _shr(uint16 &dst, uint8 src) { - src &= 0x1f; - if (src > 0) { - dst >>= (src - 1); - flags._c = dst & 1; - dst >>= 1; - flags.update_zs(dst); - } - if (src == 1) - flags._o = dst & 0x8000; - } - - inline void _shl(uint8 &dst, uint8 src) { - src &= 0x1f; - if (src > 0) { - dst <<= (src - 1); - flags._c = dst & 0x80; - dst <<= 1; - flags.update_zs(dst); - } - if (src == 1) - flags._o = ((dst & 0x80) != 0) == flags._c; - } - inline void _shl(uint16 &dst, uint8 src) { - src &= 0x1f; - if (src > 0) { - dst <<= (src - 1); - flags._c = dst & 0x8000; - dst <<= 1; - flags.update_zs(dst); - } - if (src == 1) - flags._o = ((dst & 0x8000) != 0) == flags._c; - } - - inline void _mul(uint8 src) { - unsigned r = unsigned(al) * src; - ax = (uint16)r; - flags._c = r >= 0x10000; - flags._z = r == 0; - flags._s = r & 0x8000; - flags._o = ah != 0; - } - - inline void _mul(uint16 src) { - unsigned r = unsigned(ax) * src; //assuming here that we have at least 32 bits - dx = (r >> 16) & 0xffff; - ax = r & 0xffff; - flags._c = false; - flags._z = r == 0; - flags._s = r & 0x80000000; - flags._o = dx != 0; - } - - inline void _neg(uint8 &src) { - uint8 r = 0; - _sub(r, src); - src = r; - } - - inline void _neg(uint16 &src) { - uint16 r = 0; - _sub(r, src); - src = r; - } - - inline void _lodsb() { - al = ds.byte(si++); - } - - inline void _lodsw() { - ax = ds.word(si); - si += 2; - } - - inline void _movsb() { - es.byte(di++) = ds.byte(si++); - } - - inline void _movsb(uint size, bool clear_cx = false) { - assert(size != 0xffff); - //fixme: add overlap and segment boundary check and rewrite - while (size--) - _movsb(); - if (clear_cx) - cx = 0; - } - - inline void _movsw() { - _movsb(); - _movsb(); - } - - inline void _movsw(uint size, bool clear_cx = false) { - assert(size != 0xffff); - _movsb(size * 2, clear_cx); - } - - inline void _stosb() { - es.byte(di++) = al; - } - - inline void _stosb(uint size, bool clear_cx = false) { - assert(size != 0xffff); - uint8 *dst = es.ptr(di, size); - memset(dst, al, size); - di += size; - if (clear_cx) - cx = 0; - } - - inline void _stosw() { - es.byte(di++) = al; - es.byte(di++) = ah; - } - - inline void _stosw(uint size, bool clear_cx = false) { - assert(size != 0xffff); - uint8 *dst = es.ptr(di, size * 2); - di += 2 * size; - while (size--) { - *dst++ = al; - *dst++ = ah; - } - if (clear_cx) - cx = 0; - } - - inline void _xchg(uint16 &a, uint16 &b) { - uint16 x = a; - a = b; - b = x; - } - - inline void _xchg(uint8 &a, uint8 &b) { - uint8 t = a; - a = b; - b = t; - } - - Common::Array<uint16> stack; - inline void push(uint16 v) { - stack.push_back(v); - } - - inline uint16 pop() { - assert(!stack.empty()); - uint16 v = stack.back(); - stack.pop_back(); - return v; - } -}; - -class StackChecker { - const Context &_context; - const uint _stackDepth; - -public: - StackChecker(const Context &context): _context(context), _stackDepth(context.stack.size()) {} - ~StackChecker() { assert(_context.stack.size() == _stackDepth); } -}; - -#ifndef NDEBUG -# define STACK_CHECK StackChecker checker(*this) -#else -# define STACK_CHECK do {} while (0) -#endif - -} // End of namespace DreamGen - -#endif diff --git a/engines/dreamweb/saveload.cpp b/engines/dreamweb/saveload.cpp index f0fd477ec1..a526c8a3bc 100644 --- a/engines/dreamweb/saveload.cpp +++ b/engines/dreamweb/saveload.cpp @@ -22,44 +22,116 @@ #include "dreamweb/dreamweb.h" #include "engines/metaengine.h" +#include "graphics/thumbnail.h" #include "gui/saveload.h" #include "common/config-manager.h" #include "common/translation.h" +#include "common/serializer.h" -namespace DreamGen { +namespace DreamWeb { // Temporary storage for loading the room from a savegame Room g_madeUpRoomDat; -void DreamGenContext::loadGame() { - if (data.byte(kCommandtype) != 246) { - data.byte(kCommandtype) = 246; - commandOnly(41); - } - if (data.word(kMousebutton) == data.word(kOldbutton)) + +void syncReelRoutine(Common::Serializer &s, ReelRoutine *reel) { + s.syncAsByte(reel->reallocation); + s.syncAsByte(reel->mapX); + s.syncAsByte(reel->mapY); + s.syncAsUint16LE(reel->_reelPointer); + s.syncAsByte(reel->period); + s.syncAsByte(reel->counter); + s.syncAsByte(reel->b7); +} + +void syncGameVars(Common::Serializer &s, GameVars &vars) { + s.syncAsByte(vars._startVars); + s.syncAsByte(vars._progressPoints); + s.syncAsByte(vars._watchOn); + s.syncAsByte(vars._shadesOn); + s.syncAsByte(vars._secondCount); + s.syncAsByte(vars._minuteCount); + s.syncAsByte(vars._hourCount); + s.syncAsByte(vars._zoomOn); + s.syncAsByte(vars._location); + s.syncAsByte(vars._exPos); + s.syncAsUint16LE(vars._exFramePos); + s.syncAsUint16LE(vars._exTextPos); + s.syncAsUint16LE(vars._card1Money); + s.syncAsUint16LE(vars._listPos); + s.syncAsByte(vars._ryanPage); + s.syncAsUint16LE(vars._watchingTime); + s.syncAsUint16LE(vars._reelToWatch); + s.syncAsUint16LE(vars._endWatchReel); + s.syncAsByte(vars._speedCount); + s.syncAsByte(vars._watchSpeed); + s.syncAsUint16LE(vars._reelToHold); + s.syncAsUint16LE(vars._endOfHoldReel); + s.syncAsByte(vars._watchMode); + s.syncAsByte(vars._destAfterHold); + s.syncAsByte(vars._newsItem); + s.syncAsByte(vars._liftFlag); + s.syncAsByte(vars._liftPath); + s.syncAsByte(vars._lockStatus); + s.syncAsByte(vars._doorPath); + s.syncAsByte(vars._countToOpen); + s.syncAsByte(vars._countToClose); + s.syncAsByte(vars._rockstarDead); + s.syncAsByte(vars._generalDead); + s.syncAsByte(vars._sartainDead); + s.syncAsByte(vars._aideDead); + s.syncAsByte(vars._beenMugged); + s.syncAsByte(vars._gunPassFlag); + s.syncAsByte(vars._canMoveAltar); + s.syncAsByte(vars._talkedToAttendant); + s.syncAsByte(vars._talkedToSparky); + s.syncAsByte(vars._talkedToBoss); + s.syncAsByte(vars._talkedToRecep); + s.syncAsByte(vars._cardPassFlag); + s.syncAsByte(vars._madmanFlag); + s.syncAsByte(vars._keeperFlag); + s.syncAsByte(vars._lastTrigger); + s.syncAsByte(vars._manDead); + s.syncAsByte(vars._seed1); + s.syncAsByte(vars._seed2); + s.syncAsByte(vars._seed3); + s.syncAsByte(vars._needToTravel); + s.syncAsByte(vars._throughDoor); + s.syncAsByte(vars._newObs); + s.syncAsByte(vars._ryanOn); + s.syncAsByte(vars._combatCount); + s.syncAsByte(vars._lastWeapon); + s.syncAsByte(vars._dreamNumber); + s.syncAsByte(vars._roomAfterDream); + s.syncAsByte(vars._shakeCounter); +} + +void DreamWebEngine::loadGame() { + commandOnlyCond(41, 246); + if (_mouseButton == _oldButton) return; // "noload" - if (data.word(kMousebutton) == 1) + if (_mouseButton == 1) doLoad(-1); } // if -1, open menu to ask for slot to load // if >= 0, directly load from that slot -void DreamGenContext::doLoad(int savegameId) { - data.byte(kLoadingorsave) = 1; +void DreamWebEngine::doLoad(int savegameId) { + _loadingOrSave = 1; if (ConfMan.getBool("dreamweb_originalsaveload") && savegameId == -1) { showOpBox(); showLoadOps(); - data.byte(kCurrentslot) = 0; + _currentSlot = 0; showSlots(); showNames(); - data.byte(kPointerframe) = 0; + _pointerFrame = 0; workToScreenM(); namesToOld(); - data.byte(kGetback) = 0; + _getBack = 0; - while (data.byte(kGetback) == 0) { - if (quitRequested()) + while (_getBack == 0) { + if (_quitRequested) return; delPointer(); readMouse(); @@ -68,14 +140,15 @@ void DreamGenContext::doLoad(int savegameId) { dumpPointer(); dumpTextLine(); RectWithCallback loadlist[] = { - { kOpsx+176,kOpsx+192,kOpsy+60,kOpsy+76,&DreamGenContext::getBackToOps }, - { kOpsx+128,kOpsx+190,kOpsy+12,kOpsy+100,&DreamGenContext::actualLoad }, - { kOpsx+2,kOpsx+92,kOpsy+4,kOpsy+81,&DreamGenContext::selectSlot }, - { 0,320,0,200,&DreamGenContext::blank }, + { kOpsx+176,kOpsx+192,kOpsy+60,kOpsy+76,&DreamWebEngine::getBackToOps }, + { kOpsx+128,kOpsx+190,kOpsy+12,kOpsy+100,&DreamWebEngine::actualLoad }, + { kOpsx+2,kOpsx+92,kOpsy+4,kOpsy+81,&DreamWebEngine::selectSlot }, + { kOpsx+158,kOpsx+158+(18*3),kOpsy-17,kOpsy-1,&DreamWebEngine::selectSaveLoadPage }, + { 0,320,0,200,&DreamWebEngine::blank }, { 0xFFFF,0,0,0,0 } }; checkCoords(loadlist); - if (data.byte(kGetback) == 2) + if (_getBack == 2) return; // "quitloaded" } } else { @@ -93,67 +166,62 @@ void DreamGenContext::doLoad(int savegameId) { } if (savegameId < 0) { - data.byte(kGetback) = 0; + _getBack = 0; return; } loadPosition(savegameId); - data.byte(kGetback) = 1; + _getBack = 1; } // If we reach this point, loadPosition() has just been called. // Among other things, it will have filled g_MadeUpRoomDat. - // kTempgraphics might not have been allocated if we bypassed all menus - if (data.word(kTempgraphics) != 0xFFFF) - getRidOfTemp(); + _saveGraphics.clear(); startLoading(g_madeUpRoomDat); loadRoomsSample(); - data.byte(kRoomloaded) = 1; - data.byte(kNewlocation) = 255; + _roomLoaded = 1; + _newLocation = 255; clearSprites(); initMan(); initRain(); - data.word(kTextaddressx) = 13; - data.word(kTextaddressy) = 182; - data.byte(kTextlen) = 240; + _textAddressX = 13; + _textAddressY = 182; + _textLen = 240; startup(); - workToScreenCPP(); - data.byte(kGetback) = 4; + workToScreen(); + _getBack = 4; } -void DreamGenContext::saveGame() { - if (data.byte(kMandead) == 2) { +void DreamWebEngine::saveGame() { + if (_vars._manDead == 2) { blank(); return; } - if (data.byte(kCommandtype) != 247) { - data.byte(kCommandtype) = 247; - commandOnly(44); - } - if (data.word(kMousebutton) != 1) + commandOnlyCond(44, 247); + if (_mouseButton != 1) return; - data.byte(kLoadingorsave) = 2; + _loadingOrSave = 2; if (ConfMan.getBool("dreamweb_originalsaveload")) { showOpBox(); showSaveOps(); - data.byte(kCurrentslot) = 0; + _currentSlot = 0; showSlots(); showNames(); workToScreenM(); namesToOld(); - data.word(kBufferin) = 0; - data.word(kBufferout) = 0; - data.byte(kGetback) = 0; + _bufferIn = 0; + _bufferOut = 0; + _getBack = 0; - while (data.byte(kGetback) == 0) { - if (quitRequested()) + while (_getBack == 0) { + if (_quitRequested) return; delPointer(); checkInput(); @@ -164,10 +232,11 @@ void DreamGenContext::saveGame() { dumpTextLine(); RectWithCallback savelist[] = { - { kOpsx+176,kOpsx+192,kOpsy+60,kOpsy+76,&DreamGenContext::getBackToOps }, - { kOpsx+128,kOpsx+190,kOpsy+12,kOpsy+100,&DreamGenContext::actualSave }, - { kOpsx+2,kOpsx+92,kOpsy+4,kOpsy+81,&DreamGenContext::selectSlot }, - { 0,320,0,200,&DreamGenContext::blank }, + { kOpsx+176,kOpsx+192,kOpsy+60,kOpsy+76,&DreamWebEngine::getBackToOps }, + { kOpsx+128,kOpsx+190,kOpsy+12,kOpsy+100,&DreamWebEngine::actualSave }, + { kOpsx+2,kOpsx+92,kOpsy+4,kOpsy+81,&DreamWebEngine::selectSlot }, + { kOpsx+158,kOpsx+158+(18*3),kOpsy-17,kOpsy-1,&DreamWebEngine::selectSaveLoadPage }, + { 0,320,0,200,&DreamWebEngine::blank }, { 0xFFFF,0,0,0,0 } }; checkCoords(savelist); @@ -186,80 +255,194 @@ void DreamGenContext::saveGame() { delete dialog; if (savegameId < 0) { - data.byte(kGetback) = 0; + _getBack = 0; return; } char descbuf[17] = { 2, 0 }; - strncpy((char*)descbuf+1, game_description.c_str(), 16); + Common::strlcpy((char *)descbuf + 1, game_description.c_str(), 16); unsigned int desclen = game_description.size(); if (desclen > 15) desclen = 15; // zero terminate, and pad with ones descbuf[++desclen] = 0; - while (desclen < 17) + while (desclen < 16) descbuf[++desclen] = 1; - if (savegameId < 7) - memcpy(&_saveNames[17*savegameId], descbuf, 17); - - savePosition(savegameId, descbuf); // TODO: The below is copied from actualsave - getRidOfTemp(); + _saveGraphics.clear(); restoreAll(); // reels - data.word(kTextaddressx) = 13; - data.word(kTextaddressy) = 182; - data.byte(kTextlen) = 240; + _textAddressX = 13; + _textAddressY = 182; + _textLen = 240; redrawMainScrn(); + workToScreen(); // show the main screen without the mouse pointer + + // We need to save after the scene has been redrawn, to capture the + // correct screen thumbnail + savePosition(savegameId, descbuf); + workToScreenM(); - data.byte(kGetback) = 4; + _getBack = 4; } } -void DreamGenContext::namesToOld() { - memcpy(_saveNamesOld, _saveNames, 17*7); +void DreamWebEngine::namesToOld() { + memcpy(_saveNamesOld, _saveNames, 17*21); } -void DreamGenContext::oldToNames() { - memcpy(_saveNames, _saveNamesOld, 17*7); +void DreamWebEngine::oldToNames() { + memcpy(_saveNames, _saveNamesOld, 17*21); } -void DreamGenContext::saveLoad() { - if (data.word(kWatchingtime) || (data.byte(kPointermode) == 2)) { +void DreamWebEngine::saveLoad() { + if (_vars._watchingTime || (_pointerMode == 2)) { blank(); return; } - if (data.byte(kCommandtype) != 253) { - data.byte(kCommandtype) = 253; - commandOnly(43); - } - if ((data.word(kMousebutton) != data.word(kOldbutton)) && (data.word(kMousebutton) & 1)) + commandOnlyCond(43, 253); + if ((_mouseButton != _oldButton) && (_mouseButton & 1)) doSaveLoad(); } -void DreamGenContext::showMainOps() { - showFrame(tempGraphics(), kOpsx+10, kOpsy+10, 8, 0); - showFrame(tempGraphics(), kOpsx+59, kOpsy+30, 7, 0); - showFrame(tempGraphics(), kOpsx+128+4, kOpsy+12, 1, 0); +void DreamWebEngine::doSaveLoad() { + _pointerFrame = 0; + _textAddressX = 70; + _textAddressY = 182-8; + _textLen = 181; + _manIsOffScreen = 1; + clearWork(); + createPanel2(); + underTextLine(); + getRidOfAll(); + loadSaveBox(); + showOpBox(); + showMainOps(); + workToScreen(); + + RectWithCallback opsList[] = { + { kOpsx+59,kOpsx+114,kOpsy+30,kOpsy+76,&DreamWebEngine::getBackFromOps }, + { kOpsx+10,kOpsx+77,kOpsy+10,kOpsy+59,&DreamWebEngine::DOSReturn }, + { kOpsx+128,kOpsx+190,kOpsy+16,kOpsy+100,&DreamWebEngine::discOps }, + { 0,320,0,200,&DreamWebEngine::blank }, + { 0xFFFF,0,0,0,0 } + }; + + bool firstOps = true; + + do { // restart ops + if (firstOps) { + firstOps = false; + } else { + showOpBox(); + showMainOps(); + workToScreenM(); + } + _getBack = 0; + + do { // wait ops + if (_quitRequested) { + _manIsOffScreen = 0; + return; + } + + readMouse(); + showPointer(); + vSync(); + dumpPointer(); + dumpTextLine(); + delPointer(); + checkCoords(opsList); + } while (!_getBack); + } while (_getBack == 2); + + _textAddressX = 13; + _textAddressY = 182; + _textLen = 240; + if (_getBack != 4) { + _saveGraphics.clear(); + restoreAll(); + redrawMainScrn(); + workToScreenM(); + _commandType = 200; + } + _manIsOffScreen = 0; } -void DreamGenContext::showDiscOps() { - showFrame(tempGraphics(), kOpsx+128+4, kOpsy+12, 1, 0); - showFrame(tempGraphics(), kOpsx+10, kOpsy+10, 9, 0); - showFrame(tempGraphics(), kOpsx+59, kOpsy+30, 10, 0); - showFrame(tempGraphics(), kOpsx+176+2, kOpsy+60-4, 5, 0); +void DreamWebEngine::getBackFromOps() { + if (_vars._manDead == 2) + blank(); + else + getBack1(); } -void DreamGenContext::actualSave() { - if (data.byte(kCommandtype) != 222) { - data.byte(kCommandtype) = 222; - commandOnly(44); +void DreamWebEngine::getBackToOps() { + commandOnlyCond(42, 201); + + if (_mouseButton != _oldButton) { + if (_mouseButton & 1) { + oldToNames(); + _getBack = 2; + } } +} + +void DreamWebEngine::showMainOps() { + showFrame(_saveGraphics, kOpsx+10, kOpsy+10, 8, 0); + showFrame(_saveGraphics, kOpsx+59, kOpsy+30, 7, 0); + showFrame(_saveGraphics, kOpsx+128+4, kOpsy+12, 1, 0); +} + +void DreamWebEngine::showDiscOps() { + showFrame(_saveGraphics, kOpsx+128+4, kOpsy+12, 1, 0); + showFrame(_saveGraphics, kOpsx+10, kOpsy+10, 9, 0); + showFrame(_saveGraphics, kOpsx+59, kOpsy+30, 10, 0); + showFrame(_saveGraphics, kOpsx+176+2, kOpsy+60-4, 5, 0); +} - if (!(data.word(kMousebutton) & 1)) +void DreamWebEngine::discOps() { + commandOnlyCond(43, 249); + + if (_mouseButton == _oldButton || !(_mouseButton & 1)) return; - unsigned int slot = data.byte(kCurrentslot); + scanForNames(); + _loadingOrSave = 2; + showOpBox(); + showDiscOps(); + _currentSlot = 0; + workToScreenM(); + _getBack = 0; + + RectWithCallback discOpsList[] = { + { kOpsx+59,kOpsx+114,kOpsy+30,kOpsy+76,&DreamWebEngine::loadGame }, + { kOpsx+10,kOpsx+79,kOpsy+10,kOpsy+59,&DreamWebEngine::saveGame }, + { kOpsx+176,kOpsx+192,kOpsy+60,kOpsy+76,&DreamWebEngine::getBackToOps }, + { 0,320,0,200,&DreamWebEngine::blank }, + { 0xFFFF,0,0,0,0 } + }; + + do { + if (_quitRequested) + return; // quitdiscops + + delPointer(); + readMouse(); + showPointer(); + vSync(); + dumpPointer(); + dumpTextLine(); + checkCoords(discOpsList); + } while (!_getBack); +} + +void DreamWebEngine::actualSave() { + commandOnlyCond(44, 222); + + if (!(_mouseButton & 1)) + return; + + unsigned int slot = _currentSlot + 7 * _saveLoadPage; const char *desc = &_saveNames[17*slot]; if (desc[1] == 0) // The actual description string starts at desc[1] @@ -267,54 +450,48 @@ void DreamGenContext::actualSave() { savePosition(slot, desc); - getRidOfTemp(); + _saveGraphics.clear(); restoreAll(); // reels - data.word(kTextaddressx) = 13; - data.word(kTextaddressy) = 182; - data.byte(kTextlen) = 240; + _textAddressX = 13; + _textAddressY = 182; + _textLen = 240; redrawMainScrn(); workToScreenM(); - data.byte(kGetback) = 4; + _getBack = 4; } -void DreamGenContext::actualLoad() { - if (data.byte(kCommandtype) != 221) { - data.byte(kCommandtype) = 221; - commandOnly(41); - } +void DreamWebEngine::actualLoad() { + commandOnlyCond(41, 221); - if (data.word(kMousebutton) == data.word(kOldbutton) || data.word(kMousebutton) != 1) + if (_mouseButton == _oldButton || _mouseButton != 1) return; - unsigned int slot = data.byte(kCurrentslot); + unsigned int slot = _currentSlot + 7 * _saveLoadPage; const char *desc = &_saveNames[17*slot]; if (desc[1] == 0) // The actual description string starts at desc[1] return; - loadPosition(data.byte(kCurrentslot)); - data.byte(kGetback) = 1; + loadPosition(slot); + _getBack = 1; } -void DreamGenContext::savePosition(unsigned int slot, const char *descbuf) { +void DreamWebEngine::savePosition(unsigned int slot, const char *descbuf) { - const Room ¤tRoom = g_roomData[data.byte(kLocation)]; + const Room ¤tRoom = g_roomData[_vars._location]; Room madeUpRoom = currentRoom; - madeUpRoom.roomsSample = data.byte(kRoomssample); - madeUpRoom.mapX = data.byte(kMapx); - madeUpRoom.mapY = data.byte(kMapy); - madeUpRoom.liftFlag = data.byte(kLiftflag); - madeUpRoom.b21 = data.byte(kManspath); - madeUpRoom.facing = data.byte(kFacing); + madeUpRoom.roomsSample = _roomsSample; + madeUpRoom.mapX = _mapX; + madeUpRoom.mapY = _mapY; + madeUpRoom.liftFlag = _vars._liftFlag; + madeUpRoom.b21 = _mansPath; + madeUpRoom.facing = _facing; madeUpRoom.b27 = 255; - - engine->processEvents(); // TODO: Is this necessary? - - Common::String filename = engine->getSavegameFilename(slot); + Common::String filename = getSavegameFilename(slot); debug(1, "savePosition: slot %d filename %s", slot, filename.c_str()); - Common::OutSaveFile *outSaveFile = engine->getSaveFileManager()->openForSaving(filename); + Common::OutSaveFile *outSaveFile = getSaveFileManager()->openForSaving(filename); if (!outSaveFile) // TODO: Do proper error handling! error("save could not be opened for writing"); @@ -330,21 +507,52 @@ void DreamGenContext::savePosition(unsigned int slot, const char *descbuf) { // fill length fields in savegame file header uint16 len[6] = { 17, kLengthofvars, kLengthofextra, - 4*kNumchanges, 48, kLenofreelrouts }; + 4*kNumChanges, 48, kNumReelRoutines*8+1 }; for (int i = 0; i < 6; ++i) header.setLen(i, len[i]); + // Write a new section with data that we need for ScummVM (version, + // thumbnail, played time etc). We don't really care for its size, + // so we just set it to a magic number. + header.setLen(6, SCUMMVM_BLOCK_MAGIC_SIZE); + outSaveFile->write((const uint8 *)&header, sizeof(FileHeader)); outSaveFile->write(descbuf, len[0]); - outSaveFile->write(data.ptr(kStartvars, len[1]), len[1]); - outSaveFile->write(getSegment(data.word(kExtras)).ptr(kExframedata, len[2]), len[2]); - outSaveFile->write(getSegment(data.word(kBuffers)).ptr(kListofchanges, len[3]), len[3]); + // TODO: Convert more to serializer? + Common::Serializer s(0, outSaveFile); + syncGameVars(s, _vars); + + // the Extras segment: + outSaveFile->write((const uint8 *)_exFrames._frames, kFrameBlocksize); + outSaveFile->write((const uint8 *)_exFrames._data, kExframeslen); + outSaveFile->write((const uint8 *)_exData, sizeof(DynObject)*kNumexobjects); + outSaveFile->write((const uint8 *)_exText._offsetsLE, 2*(kNumExObjects+2)); + outSaveFile->write((const uint8 *)_exText._text, kExtextlen); + + outSaveFile->write(_listOfChanges, len[3]); // len[4] == 48, which is sizeof(Room) plus 16 for 'Roomscango' outSaveFile->write((const uint8 *)&madeUpRoom, sizeof(Room)); - outSaveFile->write(data.ptr(kRoomscango, 16), 16); + outSaveFile->write(_roomsCanGo, 16); - outSaveFile->write(data.ptr(kReelroutines, len[5]), len[5]); + for (unsigned int i = 0; i < kNumReelRoutines; ++i) { + syncReelRoutine(s, &_reelRoutines[i]); + } + // Terminator + s.syncAsByte(_reelRoutines[kNumReelRoutines].reallocation); + + // ScummVM data block + outSaveFile->writeUint32BE(SCUMMVM_HEADER); + outSaveFile->writeByte(SAVEGAME_VERSION); + TimeDate curTime; + g_system->getTimeAndDate(curTime); + uint32 saveDate = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF); + uint32 saveTime = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF); + uint32 playTime = g_engine->getTotalPlayTime() / 1000; + outSaveFile->writeUint32LE(saveDate); + outSaveFile->writeUint32LE(saveTime); + outSaveFile->writeUint32LE(playTime); + Graphics::saveThumbnail(*outSaveFile); outSaveFile->finalize(); if (outSaveFile->err()) { @@ -355,13 +563,13 @@ void DreamGenContext::savePosition(unsigned int slot, const char *descbuf) { delete outSaveFile; } -void DreamGenContext::loadPosition(unsigned int slot) { - data.word(kTimecount) = 0; +void DreamWebEngine::loadPosition(unsigned int slot) { + _timeCount = 0; clearChanges(); - Common::String filename = engine->getSavegameFilename(slot); + Common::String filename = getSavegameFilename(slot); debug(1, "loadPosition: slot %d filename %s", slot, filename.c_str()); - Common::InSaveFile *inSaveFile = engine->getSaveFileManager()->openForLoading(filename); + Common::InSaveFile *inSaveFile = getSaveFileManager()->openForLoading(filename); if (!inSaveFile) // TODO: Do proper error handling! error("save could not be opened for reading"); @@ -376,143 +584,188 @@ void DreamGenContext::loadPosition(unsigned int slot) { if (len[0] != 17) ::error("Error loading save: description buffer isn't 17 bytes"); - if (slot < 7) { + if (slot < 21) { inSaveFile->read(&_saveNames[17*slot], len[0]); } else { - // The savenames buffer only has room for 7 descriptions + // The savenames buffer only has room for 21 descriptions uint8 namebuf[17]; inSaveFile->read(namebuf, 17); } - inSaveFile->read(data.ptr(kStartvars, len[1]), len[1]); - inSaveFile->read(getSegment(data.word(kExtras)).ptr(kExframedata, len[2]), len[2]); - inSaveFile->read(getSegment(data.word(kBuffers)).ptr(kListofchanges, len[3]), len[3]); + + // TODO: Use serializer for more? + Common::Serializer s(inSaveFile, 0); + syncGameVars(s, _vars); + + // the Extras segment: + inSaveFile->read((uint8 *)_exFrames._frames, kFrameBlocksize); + inSaveFile->read((uint8 *)_exFrames._data, kExframeslen); + inSaveFile->read((uint8 *)_exData, sizeof(DynObject)*kNumexobjects); + inSaveFile->read((uint8 *)_exText._offsetsLE, 2*(kNumExObjects+2)); + inSaveFile->read((uint8 *)_exText._text, kExtextlen); + + inSaveFile->read(_listOfChanges, len[3]); // len[4] == 48, which is sizeof(Room) plus 16 for 'Roomscango' // Note: the values read into g_madeUpRoomDat are only used in actualLoad, // which is (almost) immediately called after this function inSaveFile->read((uint8 *)&g_madeUpRoomDat, sizeof(Room)); - inSaveFile->read(data.ptr(kRoomscango, 16), 16); + inSaveFile->read(_roomsCanGo, 16); - inSaveFile->read(data.ptr(kReelroutines, len[5]), len[5]); + for (unsigned int i = 0; i < kNumReelRoutines; ++i) { + syncReelRoutine(s, &_reelRoutines[i]); + } + // Terminator + s.syncAsByte(_reelRoutines[kNumReelRoutines].reallocation); + + // Check if there's a ScummVM data block + if (header.len(6) == SCUMMVM_BLOCK_MAGIC_SIZE) { + uint32 tag = inSaveFile->readUint32BE(); + if (tag != SCUMMVM_HEADER) { + warning("ScummVM data block found, but the block header is incorrect - skipping"); + delete inSaveFile; + return; + } + + byte version = inSaveFile->readByte(); + if (version > SAVEGAME_VERSION) { + warning("ScummVM data block found, but it has been saved with a newer version of ScummVM - skipping"); + delete inSaveFile; + return; + } + + inSaveFile->skip(4); // saveDate + inSaveFile->skip(4); // saveTime + uint32 playTime = inSaveFile->readUint32LE(); + g_engine->setTotalPlayTime(playTime * 1000); + + // The thumbnail data follows, but we don't need it here + } delete inSaveFile; } // Count number of save files, and load their descriptions into _saveNames -unsigned int DreamGenContext::scanForNames() { - unsigned int count = 0; - - FileHeader header; - - // TODO: Change this to use SaveFileManager::listSavefiles() - for (unsigned int slot = 0; slot < 7; ++slot) { - _saveNames[17*slot+0] = 2; - _saveNames[17*slot+1] = 0; +uint DreamWebEngine::scanForNames() { + // There are 21 save slots, each of which are 17 bytes. The first byte + // doesn't seem to be used. The name starts at the second byte. All the + // slots are initialized to be empty. + for (unsigned int slot = 0; slot < 21; ++slot) { + _saveNames[17 * slot + 0] = 2; + _saveNames[17 * slot + 1] = 0; for (int i = 2; i < 17; ++i) - _saveNames[17*slot+i] = 1; - - // Try opening savegame with the given slot id - Common::String filename = engine->getSavegameFilename(slot); - Common::InSaveFile *inSaveFile = engine->getSaveFileManager()->openForLoading(filename); - if (!inSaveFile) - continue; - - ++count; - - inSaveFile->read((uint8 *)&header, sizeof(FileHeader)); - - if (header.len(0) != 17) { - ::warning("Error loading save: description buffer isn't 17 bytes"); - delete inSaveFile; - continue; - } - - // NB: Only possible if slot < 7 - inSaveFile->read(&_saveNames[17*slot], 17); + _saveNames[17 * slot + i] = 1; // initialize with 1'sdrea + } - delete inSaveFile; + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::StringArray files = saveFileMan->listSavefiles("DREAMWEB.D??"); + Common::sort(files.begin(), files.end()); + + SaveStateList saveList; + for (uint i = 0; i < files.size(); ++i) { + const Common::String &file = files[i]; + Common::InSaveFile *stream = saveFileMan->openForLoading(file); + if (!stream) + error("cannot open save file %s", file.c_str()); + char name[17] = {}; + stream->seek(0x61); + stream->read(name, sizeof(name) - 1); + delete stream; + + int slotNum = atoi(file.c_str() + file.size() - 2); + SaveStateDescriptor sd(slotNum, name); + saveList.push_back(sd); + if (slotNum < 21) + Common::strlcpy(&_saveNames[17 * slotNum + 1], name, 16); // the first character is unused } - al = (uint8)count; + // FIXME: Can the following be safely removed? +// al = saveList.size() <= 7 ? (uint8)saveList.size() : 7; - return count; + return saveList.size(); } -void DreamGenContext::loadOld() { - if (data.byte(kCommandtype) != 252) { - data.byte(kCommandtype) = 252; - commandOnly(48); - } +void DreamWebEngine::loadOld() { + commandOnlyCond(48, 252); - if (!(data.word(kMousebutton) & 1)) + if (!(_mouseButton & 1)) return; doLoad(-1); - if (data.byte(kGetback) == 4 || quitRequested()) + if (_getBack == 4 || _quitRequested) return; showDecisions(); workToScreenM(); - data.byte(kGetback) = 0; + _getBack = 0; +} + +void DreamWebEngine::showDecisions() { + createPanel2(); + showOpBox(); + showFrame(_saveGraphics, kOpsx + 17, kOpsy + 13, 6, 0); + underTextLine(); } -void DreamGenContext::loadSaveBox() { - loadIntoTemp("DREAMWEB.G08"); +void DreamWebEngine::loadSaveBox() { + loadGraphicsFile(_saveGraphics, "G08"); } // show savegame names (original interface), and set kCursorpos -void DreamBase::showNames() { +void DreamWebEngine::showNames() { + unsigned int offset = 7 * _saveLoadPage; for (int slot = 0; slot < 7; ++slot) { // The first character of the savegame name is unused - Common::String name(&_saveNames[17*slot + 1]); + Common::String name(&_saveNames[17 * (slot + offset) + 1]); - if (slot != data.byte(kCurrentslot)) { + if (slot != _currentSlot) { printDirect((const uint8 *)name.c_str(), kOpsx + 21, kOpsy + 10*slot + 10, 200, false); continue; } - if (data.byte(kLoadingorsave) != 2) { - data.word(kCharshift) = 91; + if (_loadingOrSave != 2) { + _charShift = 91; printDirect((const uint8 *)name.c_str(), kOpsx + 21, kOpsy + 10*slot + 10, 200, false); - data.word(kCharshift) = 0; + _charShift = 0; continue; } int pos = name.size(); - data.byte(kCursorpos) = pos; + _cursorPos = pos; name += '/'; // cursor character printDirect((const uint8 *)name.c_str(), kOpsx + 21, kOpsy + 10*slot + 10, 200, false); } } -void DreamGenContext::checkInput() { - if (data.byte(kLoadingorsave) == 3) +void DreamWebEngine::checkInput() { + if (_loadingOrSave == 3) return; readKey(); + unsigned int slot = _currentSlot + 7 * _saveLoadPage; + // The first character of the savegame name is unused - char *name = &_saveNames[17*data.byte(kCurrentslot) + 1]; + char *name = &_saveNames[17*slot + 1]; - if (data.byte(kCurrentkey) == 0) { + if (_currentKey == 0) { return; - } else if (data.byte(kCurrentkey) == 13) { - data.byte(kLoadingorsave) = 3; - } else if (data.byte(kCurrentkey) == 8) { - if (data.byte(kCursorpos) == 0) + } else if (_currentKey == 13) { + _loadingOrSave = 3; + } else if (_currentKey == 8) { + if (_cursorPos == 0) return; - --data.byte(kCursorpos); - name[data.byte(kCursorpos)] = 0; - name[data.byte(kCursorpos)+1] = 1; + --_cursorPos; + name[_cursorPos] = 0; + name[_cursorPos+1] = 1; } else { - if (data.byte(kCursorpos) == 14) + if (_cursorPos == 14) return; - name[data.byte(kCursorpos)] = data.byte(kCurrentkey); - name[data.byte(kCursorpos)+1] = 0; - name[data.byte(kCursorpos)+2] = 1; - ++data.byte(kCursorpos); + name[_cursorPos] = _currentKey; + name[_cursorPos+1] = 0; + name[_cursorPos+2] = 1; + ++_cursorPos; } showOpBox(); @@ -522,5 +775,85 @@ void DreamGenContext::checkInput() { workToScreenM(); } +void DreamWebEngine::selectSaveLoadPage() { + commandOnlyCond(31, 254); + + if (_mouseButton != 1 || _mouseButton == _oldButton) + return; + uint saveLoadPage = (_mouseX - (kOpsx + 158)) / 18; + if (saveLoadPage != _saveLoadPage) { + _saveLoadPage = saveLoadPage; + // This will also make the first slot the selected one, based + // on the mouse Y position. I can't decide if this is a feature + // or not. + selectSlot(); + } +} + +void DreamWebEngine::selectSlot() { + commandOnlyCond(45, 244); + + if (_mouseButton != 1 || _mouseButton == _oldButton) + return; // noselslot + if (_loadingOrSave == 3) + _loadingOrSave--; + + oldToNames(); + int y = _mouseY - (kOpsy + 4); + if (y < 11) + _currentSlot = 0; + else + _currentSlot = y / 11; + + delPointer(); + showOpBox(); + showSlots(); + showNames(); + if (_loadingOrSave == 1) + showLoadOps(); + else + showSaveOps(); + readMouse(); + showPointer(); + workToScreen(); + delPointer(); +} + +void DreamWebEngine::showSlots() { + showFrame(_icons1, kOpsx + 158, kOpsy - 11, 12, 0); + showFrame(_icons1, kOpsx + 158 + 18 * _saveLoadPage, kOpsy - 11, 13 + _saveLoadPage, 0); + showFrame(_saveGraphics, kOpsx + 7, kOpsy + 8, 2, 0); + + uint16 y = kOpsy + 11; + + for (int slot = 0; slot < 7; slot++) { + if (slot == _currentSlot) + showFrame(_saveGraphics, kOpsx + 10, y, 3, 0); + + y += 10; + } +} + +void DreamWebEngine::showOpBox() { + showFrame(_saveGraphics, kOpsx, kOpsy, 0, 0); + + // This call displays half of the ops dialog in the CD version. It's not + // in the floppy version, and if it's called, a stray red dot is shown in + // the game dialogs. + if (isCD()) + showFrame(_saveGraphics, kOpsx, kOpsy + 55, 4, 0); +} + +void DreamWebEngine::showLoadOps() { + showFrame(_saveGraphics, kOpsx + 128 + 4, kOpsy + 12, 1, 0); + showFrame(_saveGraphics, kOpsx + 176 + 2, kOpsy + 60 - 4, 5, 0); + printMessage(kOpsx + 104, kOpsy + 14, 55, 101, (101 & 1)); +} + +void DreamWebEngine::showSaveOps() { + showFrame(_saveGraphics, kOpsx + 128 + 4, kOpsy + 12, 1, 0); + showFrame(_saveGraphics, kOpsx + 176 + 2, kOpsy + 60 - 4, 5, 0); + printMessage(kOpsx + 104, kOpsy + 14, 54, 101, (101 & 1)); +} -} // End of namespace DreamGen +} // End of namespace DreamWeb diff --git a/engines/dreamweb/segment.h b/engines/dreamweb/segment.h deleted file mode 100644 index 9464015478..0000000000 --- a/engines/dreamweb/segment.h +++ /dev/null @@ -1,227 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef DREAMGEN_SEGMENT_H -#define DREAMGEN_SEGMENT_H - -#include "common/array.h" -#include "common/ptr.h" -#include "common/hashmap.h" -#include "common/list.h" - -namespace DreamGen { - -class WordRef { - uint8 *_data; - unsigned _index; - uint16 _value; - -public: - inline WordRef(Common::Array<uint8> &data, unsigned index) : _data(data.begin() + index), _index(index) { - assert(index + 1 < data.size()); - _value = _data[0] | (_data[1] << 8); - } - - inline WordRef& operator=(const WordRef &ref) { - _value = ref._value; - return *this; - } - - inline WordRef& operator=(uint16 v) { - _value = v; - return *this; - } - - inline operator uint16&() { - return _value; - } - - inline ~WordRef() { - _data[0] = _value & 0xff; - _data[1] = _value >> 8; - _value = _data[0] | (_data[1] << 8); - } -}; - -class Segment { - Common::Array<uint8> data; - -public: - Segment(uint size = 0) { - if (size > 0) - data.resize(size); - } - - inline void assign(const uint8 *b, const uint8 *e) { - data.assign(b, e); - } - - inline uint8 &byte(unsigned index) { - assert(index < data.size()); - return data[index]; - } - - inline WordRef word(unsigned index) { - return WordRef(data, index); - } - - inline uint8 *ptr(unsigned index, unsigned size) { - assert(index + size <= data.size()); - return data.begin() + index; - } -}; - -typedef Common::SharedPtr<Segment> SegmentPtr; - -class SegmentRef { - uint16 _value; - SegmentPtr _segment; - -public: - SegmentRef(uint16 value = 0, SegmentPtr segment = SegmentPtr()) - : _value(value), _segment(segment) { - } - - inline operator uint16() const { - return _value; - } - - SegmentPtr getSegmentPtr() const { - return _segment; - } - - inline uint8 &byte(unsigned index) { - assert(_segment != 0); - return _segment->byte(index); - } - - inline WordRef word(unsigned index) { - //debug(1, "getting word ref for %04x:%d", _value, index); - assert(_segment != 0); - return _segment->word(index); - } - - inline void assign(const uint8 *b, const uint8 *e) { - assert(_segment != 0); - _segment->assign(b, e); - } - - inline uint8 *ptr(unsigned index, unsigned size) { - assert(_segment != 0); - return _segment->ptr(index, size); - } - -protected: - SegmentRef &operator=(const SegmentRef &seg) { - _value = seg._value; - _segment = seg._segment; - return *this; - } - -}; - -class SegmentManager; - -class MutableSegmentRef : public SegmentRef { -protected: - SegmentManager *_segMan; - -public: - MutableSegmentRef(SegmentManager *segMan, uint16 value = 0, SegmentPtr segment = SegmentPtr()) - : _segMan(segMan), SegmentRef(value, segment) { - } - - MutableSegmentRef(SegmentManager *segMan, SegmentRef seg) - : _segMan(segMan), SegmentRef(seg) { - } - - inline MutableSegmentRef& operator=(const uint16 id); - -}; - - -class SegmentManager { -private: - typedef Common::HashMap<uint16, SegmentPtr> SegmentMap; - SegmentMap _segments; - - typedef Common::List<uint16> FreeSegmentList; - FreeSegmentList _freeSegments; - - enum { kDefaultDataSegment = 0x1000 }; - -public: - - SegmentPtr _realData; ///< the primary data segment, points to a huge blob of binary data - SegmentRef data; ///< fake segment register always pointing to data segment - -public: - SegmentManager() : - _realData(new Segment()), - data(kDefaultDataSegment, _realData) { - - _segments[kDefaultDataSegment] = data.getSegmentPtr(); - } - - SegmentRef getSegment(uint16 value) { - SegmentMap::iterator i = _segments.find(value); - if (i != _segments.end()) - return SegmentRef(value, i->_value); - else - return SegmentRef(value); - } - - SegmentRef allocateSegment(uint size) { - unsigned id; - if (_freeSegments.empty()) - id = kDefaultDataSegment + _segments.size(); - else { - id = _freeSegments.front(); - _freeSegments.pop_front(); - } - assert(!_segments.contains(id)); - SegmentPtr seg(new Segment(size)); - _segments[id] = seg; - return SegmentRef(id, seg); - } - - void deallocateSegment(uint16 id) { - SegmentMap::iterator i = _segments.find(id); - if(i != _segments.end()) { - _segments.erase(i); - _freeSegments.push_back(id); - } else { - debug("Deallocating non existent segment! Client code should be fixed."); - } - } - -}; - - -inline MutableSegmentRef& MutableSegmentRef::operator=(const uint16 id) { - SegmentRef::operator=(_segMan->getSegment(id)); - return *this; -} - -} // End of namespace DreamGen - -#endif diff --git a/engines/dreamweb/sound.cpp b/engines/dreamweb/sound.cpp index 784a6d0d11..b51527a8cd 100644 --- a/engines/dreamweb/sound.cpp +++ b/engines/dreamweb/sound.cpp @@ -21,108 +21,87 @@ */ #include "dreamweb/dreamweb.h" -#include "dreamweb/dreamgen.h" #include "audio/mixer.h" #include "audio/decoders/raw.h" #include "common/config-manager.h" -namespace DreamGen { - -void DreamGenContext::loadSpeech() { - loadSpeech((uint8)dl, (uint8)dh, (uint8)cl, (uint16)ax); -} +namespace DreamWeb { -bool DreamBase::loadSpeech(byte type1, int idx1, byte type2, int idx2) { +bool DreamWebEngine::loadSpeech(byte type1, int idx1, byte type2, int idx2) { cancelCh1(); Common::String name = Common::String::format("%c%02d%c%04d.RAW", type1, idx1, type2, idx2); //debug("name = %s", name.c_str()); - bool result = engine->loadSpeech(name); + bool result = loadSpeech(name); - data.byte(kSpeechloaded) = result; + _speechLoaded = result; return result; } -void DreamBase::volumeAdjust() { - if (data.byte(kVolumedirection) == 0) +void DreamWebEngine::volumeAdjust() { + if (_volumeDirection == 0) return; - if (data.byte(kVolume) != data.byte(kVolumeto)) { - data.byte(kVolumecount) += 64; + if (_volume != _volumeTo) { + _volumeCount += 64; // Only modify the volume every 256/64 = 4th time around - if (data.byte(kVolumecount) == 0) - data.byte(kVolume) += data.byte(kVolumedirection); + if (_volumeCount == 0) + _volume += _volumeDirection; } else { - data.byte(kVolumedirection) = 0; + _volumeDirection = 0; } } -void DreamBase::playChannel0(uint8 index, uint8 repeat) { - data.byte(kCh0playing) = index; - Sound *soundBank; - if (index >= 12) { - soundBank = (Sound *)getSegment(data.word(kSounddata2)).ptr(0, 0); +void DreamWebEngine::playChannel0(uint8 index, uint8 repeat) { + _channel0Playing = index; + if (index >= 12) index -= 12; - } else - soundBank = (Sound *)getSegment(data.word(kSounddata)).ptr(0, 0); - data.byte(kCh0repeat) = repeat; - data.word(kCh0blockstocopy) = soundBank[index].blockCount(); + _channel0Repeat = repeat; } -void DreamBase::playChannel1(uint8 index) { - if (data.byte(kCh1playing) == 7) +void DreamWebEngine::playChannel1(uint8 index) { + if (_channel1Playing == 7) return; - data.byte(kCh1playing) = index; - Sound *soundBank; - if (index >= 12) { - soundBank = (Sound *)getSegment(data.word(kSounddata2)).ptr(0, 0); + _channel1Playing = index; + if (index >= 12) index -= 12; - } else - soundBank = (Sound *)getSegment(data.word(kSounddata)).ptr(0, 0); - - data.word(kCh1blockstocopy) = soundBank[index].blockCount(); -} - -void DreamGenContext::playChannel1() { - playChannel1(al); } -void DreamBase::cancelCh0() { - data.byte(kCh0repeat) = 0; - data.word(kCh0blockstocopy) = 0; - data.byte(kCh0playing) = 255; - engine->stopSound(0); +void DreamWebEngine::cancelCh0() { + _channel0Repeat = 0; + _channel0Playing = 255; + stopSound(0); } -void DreamBase::cancelCh1() { - data.word(kCh1blockstocopy) = 0; - data.byte(kCh1playing) = 255; - engine->stopSound(1); +void DreamWebEngine::cancelCh1() { + _channel1Playing = 255; + stopSound(1); } -void DreamBase::loadRoomsSample() { - uint8 sample = data.byte(kRoomssample); +void DreamWebEngine::loadRoomsSample() { + uint8 sample = _roomsSample; - if (sample == 255 || data.byte(kCurrentsample) == sample) + if (sample == 255 || _currentSample == sample) return; // loaded already assert(sample < 100); - Common::String sampleName = Common::String::format("DREAMWEB.V%02d", sample); + Common::String sampleSuffix = Common::String::format("V%02d", sample); + _currentSample = sample; - uint8 ch0 = data.byte(kCh0playing); + uint8 ch0 = _channel0Playing; if (ch0 >= 12 && ch0 != 255) cancelCh0(); - uint8 ch1 = data.byte(kCh1playing); + uint8 ch1 = _channel1Playing; if (ch1 >= 12) cancelCh1(); - engine->loadSounds(1, sampleName.c_str()); + loadSounds(1, sampleSuffix.c_str()); } -} // End of namespace DreamGen +} // End of namespace DreamWeb namespace DreamWeb { @@ -194,7 +173,7 @@ void DreamWebEngine::stopSound(uint8 channel) { } bool DreamWebEngine::loadSpeech(const Common::String &filename) { - if (ConfMan.getBool("speech_mute")) + if (!hasSpeech()) return false; Common::File file; @@ -211,10 +190,10 @@ bool DreamWebEngine::loadSpeech(const Common::String &filename) { } void DreamWebEngine::soundHandler() { - _base.data.byte(DreamGen::kSubtitles) = ConfMan.getBool("subtitles"); - _base.volumeAdjust(); + _subtitles = ConfMan.getBool("subtitles"); + volumeAdjust(); - uint volume = _base.data.byte(DreamGen::kVolume); + uint volume = _volume; //.vol file loaded into soundbuf:0x4000 //volume table at (volume * 0x100 + 0x3f00) //volume value could be from 1 to 7 @@ -230,13 +209,13 @@ void DreamWebEngine::soundHandler() { volume = (8 - volume) * Audio::Mixer::kMaxChannelVolume / 8; _mixer->setChannelVolume(_channelHandle[0], volume); - uint8 ch0 = _base.data.byte(DreamGen::kCh0playing); + uint8 ch0 = _channel0Playing; if (ch0 == 255) ch0 = 0; - uint8 ch1 = _base.data.byte(DreamGen::kCh1playing); + uint8 ch1 = _channel1Playing; if (ch1 == 255) ch1 = 0; - uint8 ch0loop = _base.data.byte(DreamGen::kCh0repeat); + uint8 ch0loop = _channel0Repeat; if (_channel0 != ch0) { _channel0 = ch0; @@ -251,17 +230,18 @@ void DreamWebEngine::soundHandler() { } } if (!_mixer->isSoundHandleActive(_channelHandle[0])) { - _base.data.byte(DreamGen::kCh0playing) = 255; + _channel0Playing = 255; _channel0 = 0; } if (!_mixer->isSoundHandleActive(_channelHandle[1])) { - _base.data.byte(DreamGen::kCh1playing) = 255; + _channel1Playing = 255; _channel1 = 0; } } -void DreamWebEngine::loadSounds(uint bank, const Common::String &filename) { +void DreamWebEngine::loadSounds(uint bank, const Common::String &suffix) { + Common::String filename = getDatafilePrefix() + suffix; debug(1, "loadSounds(%u, %s)", bank, filename.c_str()); Common::File file; if (!file.open(filename)) { diff --git a/engines/dreamweb/sprite.cpp b/engines/dreamweb/sprite.cpp index e93a77f3ff..3df324abe1 100644 --- a/engines/dreamweb/sprite.cpp +++ b/engines/dreamweb/sprite.cpp @@ -22,20 +22,13 @@ #include "dreamweb/dreamweb.h" -namespace DreamGen { +namespace DreamWeb { -Sprite *DreamBase::spriteTable() { - Sprite *sprite = (Sprite *)getSegment(data.word(kBuffers)).ptr(kSpritetable, 16 * sizeof(Sprite)); - return sprite; -} - -void DreamGenContext::printSprites() { +void DreamWebEngine::printSprites() { for (size_t priority = 0; priority < 7; ++priority) { - Sprite *sprites = spriteTable(); - for (size_t j = 0; j < 16; ++j) { - const Sprite &sprite = sprites[j]; - if (sprite.updateCallback() == 0x0ffff) - continue; + Common::List<Sprite>::const_iterator i; + for (i = _spriteTable.begin(); i != _spriteTable.end(); ++i) { + const Sprite &sprite = *i; if (priority != sprite.priority) continue; if (sprite.hidden == 1) @@ -45,18 +38,18 @@ void DreamGenContext::printSprites() { } } -void DreamGenContext::printASprite(const Sprite *sprite) { +void DreamWebEngine::printASprite(const Sprite *sprite) { uint16 x, y; if (sprite->y >= 220) { - y = data.word(kMapady) - (256 - sprite->y); + y = _mapAdY - (256 - sprite->y); } else { - y = sprite->y + data.word(kMapady); + y = sprite->y + _mapAdY; } if (sprite->x >= 220) { - x = data.word(kMapadx) - (256 - sprite->x); + x = _mapAdX - (256 - sprite->x); } else { - x = sprite->x + data.word(kMapadx); + x = sprite->x + _mapAdX; } uint8 c; @@ -64,173 +57,149 @@ void DreamGenContext::printASprite(const Sprite *sprite) { c = 8; else c = 0; - showFrame((const Frame *)getSegment(sprite->frameData()).ptr(0, 0), x, y, sprite->frameNumber, c); + showFrame(*sprite->_frameData, x, y, sprite->frameNumber, c); } -void DreamGenContext::clearSprites() { - memset(spriteTable(), 0xff, sizeof(Sprite) * 16); +void DreamWebEngine::clearSprites() { + _spriteTable.clear(); } -Sprite *DreamGenContext::makeSprite(uint8 x, uint8 y, uint16 updateCallback, uint16 frameData, uint16 somethingInDi) { - Sprite *sprite = spriteTable(); - while (sprite->frameNumber != 0xff) { // NB: No boundchecking in the original code either - ++sprite; - } +Sprite *DreamWebEngine::makeSprite(uint8 x, uint8 y, bool mainManCallback, const GraphicsFile *frameData) { + // Note: the original didn't append sprites here, but filled up the + // first unused entry. This can change the order of entries, but since they + // are drawn based on the priority field, this shouldn't matter. + _spriteTable.push_back(Sprite()); + Sprite *sprite = &_spriteTable.back(); + + memset(sprite, 0xff, sizeof(Sprite)); - sprite->setUpdateCallback(updateCallback); + sprite->_mainManCallback = mainManCallback; sprite->x = x; sprite->y = y; - sprite->setFrameData(frameData); - WRITE_LE_UINT16(&sprite->w8, somethingInDi); - sprite->w2 = 0xffff; + sprite->_frameData = frameData; sprite->frameNumber = 0; sprite->delay = 0; + sprite->_objData = 0; return sprite; } -void DreamGenContext::spriteUpdate() { - Sprite *sprites = spriteTable(); - sprites[0].hidden = data.byte(kRyanon); - - Sprite *sprite = sprites; - for (size_t i=0; i < 16; ++i) { - uint16 updateCallback = sprite->updateCallback(); - if (updateCallback != 0xffff) { - sprite->w24 = sprite->w2; - if (updateCallback == addr_mainman) // NB : Let's consider the callback as an enum while more code is not ported to C++ - mainMan(sprite); - else { - assert(updateCallback == addr_backobject); - backObject(sprite); - } +void DreamWebEngine::spriteUpdate() { + // During the intro the sprite table can be empty + if (!_spriteTable.empty()) + _spriteTable.front().hidden = _vars._ryanOn; + + Common::List<Sprite>::iterator i; + for (i = _spriteTable.begin(); i != _spriteTable.end(); ++i) { + Sprite &sprite = *i; + if (sprite._mainManCallback) + mainMan(&sprite); + else { + backObject(&sprite); } - if (data.byte(kNowinnewroom) == 1) + if (_nowInNewRoom == 1) break; - ++sprite; } } -void DreamGenContext::initMan() { - Sprite *sprite = makeSprite(data.byte(kRyanx), data.byte(kRyany), addr_mainman, data.word(kMainsprites), 0); +void DreamWebEngine::initMan() { + Sprite *sprite = makeSprite(_ryanX, _ryanY, true, &_mainSprites); sprite->priority = 4; sprite->speed = 0; sprite->walkFrame = 0; } -void DreamGenContext::mainMan() { - assert(false); -} - -void DreamGenContext::mainMan(Sprite *sprite) { - push(es); - push(ds); - - // Recover es:bx from sprite - es = data.word(kBuffers); - bx = kSpritetable; - Sprite *sprites = (Sprite *)es.ptr(bx, sizeof(Sprite) * 16); - bx += 32 * (sprite - sprites); - // - - if (data.byte(kResetmanxy) == 1) { - data.byte(kResetmanxy) = 0; - sprite->x = data.byte(kRyanx); - sprite->y = data.byte(kRyany); +void DreamWebEngine::mainMan(Sprite *sprite) { + if (_resetManXY == 1) { + _resetManXY = 0; + sprite->x = _ryanX; + sprite->y = _ryanY; sprite->walkFrame = 0; } + --sprite->speed; - if (sprite->speed != 0xff) { - ds = pop(); - es = pop(); + if (sprite->speed != 0xff) return; - } sprite->speed = 0; - if (data.byte(kTurntoface) != data.byte(kFacing)) { + + if (_turnToFace != _facing) { aboutTurn(sprite); } else { - if ((data.byte(kTurndirection) != 0) && (data.byte(kLinepointer) == 254)) { - data.byte(kReasseschanges) = 1; - if (data.byte(kFacing) == data.byte(kLeavedirection)) - checkForExit(); + if ((_turnDirection != 0) && (_linePointer == 254)) { + _reAssesChanges = 1; + if (_facing == _leaveDirection) + checkForExit(sprite); } - data.byte(kTurndirection) = 0; - if (data.byte(kLinepointer) == 254) { + _turnDirection = 0; + if (_linePointer == 254) { sprite->walkFrame = 0; } else { ++sprite->walkFrame; if (sprite->walkFrame == 11) sprite->walkFrame = 1; walking(sprite); - if (data.byte(kLinepointer) != 254) { - if ((data.byte(kFacing) & 1) == 0) + if (_linePointer != 254) { + if ((_facing & 1) == 0) walking(sprite); else if ((sprite->walkFrame != 2) && (sprite->walkFrame != 7)) walking(sprite); } - if (data.byte(kLinepointer) == 254) { - if (data.byte(kTurntoface) == data.byte(kFacing)) { - data.byte(kReasseschanges) = 1; - if (data.byte(kFacing) == data.byte(kLeavedirection)) - checkForExit(); + if (_linePointer == 254) { + if (_turnToFace == _facing) { + _reAssesChanges = 1; + if (_facing == _leaveDirection) + checkForExit(sprite); } } } } static const uint8 facelist[] = { 0,60,33,71,11,82,22,93 }; - sprite->frameNumber = sprite->walkFrame + facelist[data.byte(kFacing)]; - data.byte(kRyanx) = sprite->x; - data.byte(kRyany) = sprite->y; - - ds = pop(); - es = pop(); + sprite->frameNumber = sprite->walkFrame + facelist[_facing]; + _ryanX = sprite->x; + _ryanY = sprite->y; } -void DreamGenContext::walking(Sprite *sprite) { +void DreamWebEngine::walking(Sprite *sprite) { uint8 comp; - if (data.byte(kLinedirection) != 0) { - --data.byte(kLinepointer); + if (_lineDirection != 0) { + --_linePointer; comp = 200; } else { - ++data.byte(kLinepointer); - comp = data.byte(kLinelength); + ++_linePointer; + comp = _lineLength; } - if (data.byte(kLinepointer) < comp) { - sprite->x = (uint8)_lineData[data.byte(kLinepointer)].x; - sprite->y = (uint8)_lineData[data.byte(kLinepointer)].y; + if (_linePointer < comp) { + sprite->x = (uint8)_lineData[_linePointer].x; + sprite->y = (uint8)_lineData[_linePointer].y; return; } - data.byte(kLinepointer) = 254; - data.byte(kManspath) = data.byte(kDestination); - if (data.byte(kDestination) == data.byte(kFinaldest)) { + _linePointer = 254; + _mansPath = _destination; + if (_destination == _finalDest) { faceRightWay(); return; } - data.byte(kDestination) = data.byte(kFinaldest); - push(es); - push(bx); + _destination = _finalDest; autoSetWalk(); - bx = pop(); - es = pop(); } -void DreamGenContext::aboutTurn(Sprite *sprite) { +void DreamWebEngine::aboutTurn(Sprite *sprite) { bool incdir = true; - if (data.byte(kTurndirection) == 1) + if (_turnDirection == 1) incdir = true; - else if ((int8)data.byte(kTurndirection) == -1) + else if ((int8)_turnDirection == -1) incdir = false; else { - if (data.byte(kFacing) < data.byte(kTurntoface)) { - uint8 delta = data.byte(kTurntoface) - data.byte(kFacing); + if (_facing < _turnToFace) { + uint8 delta = _turnToFace - _facing; if (delta >= 4) incdir = false; else incdir = true; } else { - uint8 delta = data.byte(kFacing) - data.byte(kTurntoface); + uint8 delta = _facing - _turnToFace; if (delta >= 4) incdir = true; else @@ -239,22 +208,18 @@ void DreamGenContext::aboutTurn(Sprite *sprite) { } if (incdir) { - data.byte(kTurndirection) = 1; - data.byte(kFacing) = (data.byte(kFacing) + 1) & 7; + _turnDirection = 1; + _facing = (_facing + 1) & 7; sprite->walkFrame = 0; } else { - data.byte(kTurndirection) = (uint8)-1; - data.byte(kFacing) = (data.byte(kFacing) - 1) & 7; + _turnDirection = (uint8)-1; + _facing = (_facing - 1) & 7; sprite->walkFrame = 0; } } -void DreamGenContext::backObject() { - assert(false); -} - -void DreamGenContext::backObject(Sprite *sprite) { - SetObject *objData = (SetObject *)getSegment(data.word(kSetdat)).ptr(sprite->objData(), 0); +void DreamWebEngine::backObject(Sprite *sprite) { + SetObject *objData = sprite->_objData; if (sprite->delay != 0) { --sprite->delay; @@ -262,23 +227,32 @@ void DreamGenContext::backObject(Sprite *sprite) { } sprite->delay = objData->delay; - if (objData->type == 6) + switch (objData->type) { + case 6: wideDoor(sprite, objData); - else if (objData->type == 5) + break; + case 5: randomSprite(sprite, objData); - else if (objData->type == 4) + break; + case 4: lockedDoorway(sprite, objData); - else if (objData->type == 3) + break; + case 3: liftSprite(sprite, objData); - else if (objData->type == 2) + break; + case 2: doorway(sprite, objData); - else if (objData->type == 1) + break; + case 1: constant(sprite, objData); - else + break; + default: steady(sprite, objData); + break; + } } -void DreamGenContext::constant(Sprite *sprite, SetObject *objData) { +void DreamWebEngine::constant(Sprite *sprite, SetObject *objData) { ++sprite->animFrame; if (objData->frames[sprite->animFrame] == 255) { sprite->animFrame = 0; @@ -288,24 +262,24 @@ void DreamGenContext::constant(Sprite *sprite, SetObject *objData) { sprite->frameNumber = frame; } -void DreamGenContext::randomSprite(Sprite *sprite, SetObject *objData) { - uint8 r = engine->randomNumber(); - sprite->frameNumber = objData->frames[r&7]; +void DreamWebEngine::randomSprite(Sprite *sprite, SetObject *objData) { + uint8 r = _rnd.getRandomNumber(7); + sprite->frameNumber = objData->frames[r]; } -void DreamGenContext::doorway(Sprite *sprite, SetObject *objData) { +void DreamWebEngine::doorway(Sprite *sprite, SetObject *objData) { Common::Rect check(-24, -30, 10, 10); doDoor(sprite, objData, check); } -void DreamGenContext::wideDoor(Sprite *sprite, SetObject *objData) { +void DreamWebEngine::wideDoor(Sprite *sprite, SetObject *objData) { Common::Rect check(-24, -30, 24, 24); doDoor(sprite, objData, check); } -void DreamGenContext::doDoor(Sprite *sprite, SetObject *objData, Common::Rect check) { - int ryanx = data.byte(kRyanx); - int ryany = data.byte(kRyany); +void DreamWebEngine::doDoor(Sprite *sprite, SetObject *objData, Common::Rect check) { + int ryanx = _ryanX; + int ryany = _ryanY; // Automatically opening doors: check if Ryan is in range @@ -314,13 +288,13 @@ void DreamGenContext::doDoor(Sprite *sprite, SetObject *objData, Common::Rect ch if (openDoor) { - if ((data.byte(kThroughdoor) == 1) && (sprite->animFrame == 0)) + if ((_vars._throughDoor == 1) && (sprite->animFrame == 0)) sprite->animFrame = 6; ++sprite->animFrame; if (sprite->animFrame == 1) { // doorsound2 uint8 soundIndex; - if (data.byte(kReallocation) == 5) // hoteldoor2 + if (_realLocation == 5) // hoteldoor2 soundIndex = 13; else soundIndex = 0; @@ -330,14 +304,14 @@ void DreamGenContext::doDoor(Sprite *sprite, SetObject *objData, Common::Rect ch --sprite->animFrame; sprite->frameNumber = objData->index = objData->frames[sprite->animFrame]; - data.byte(kThroughdoor) = 1; + _vars._throughDoor = 1; } else { // shut door if (sprite->animFrame == 5) { // doorsound1; uint8 soundIndex; - if (data.byte(kReallocation) == 5) // hoteldoor1 + if (_realLocation == 5) // hoteldoor1 soundIndex = 13; else soundIndex = 1; @@ -348,25 +322,25 @@ void DreamGenContext::doDoor(Sprite *sprite, SetObject *objData, Common::Rect ch sprite->frameNumber = objData->index = objData->frames[sprite->animFrame]; if (sprite->animFrame == 5) // nearly - data.byte(kThroughdoor) = 0; + _vars._throughDoor = 0; } } -void DreamGenContext::steady(Sprite *sprite, SetObject *objData) { +void DreamWebEngine::steady(Sprite *sprite, SetObject *objData) { uint8 frame = objData->frames[0]; objData->index = frame; sprite->frameNumber = frame; } -void DreamGenContext::lockedDoorway(Sprite *sprite, SetObject *objData) { - int ryanx = data.byte(kRyanx); - int ryany = data.byte(kRyany); +void DreamWebEngine::lockedDoorway(Sprite *sprite, SetObject *objData) { + int ryanx = _ryanX; + int ryany = _ryanY; Common::Rect check(-24, -30, 10, 12); check.translate(sprite->x, sprite->y); bool openDoor = check.contains(ryanx, ryany); - if (data.byte(kThroughdoor) != 1 && data.byte(kLockstatus) == 1) + if (_vars._throughDoor != 1 && _vars._lockStatus == 1) openDoor = false; if (openDoor) { @@ -376,9 +350,9 @@ void DreamGenContext::lockedDoorway(Sprite *sprite, SetObject *objData) { } if (sprite->animFrame == 6) - turnPathOn(data.byte(kDoorpath)); + turnPathOn(_vars._doorPath); - if (data.byte(kThroughdoor) == 1 && sprite->animFrame == 0) + if (_vars._throughDoor == 1 && sprite->animFrame == 0) sprite->animFrame = 6; ++sprite->animFrame; @@ -387,7 +361,7 @@ void DreamGenContext::lockedDoorway(Sprite *sprite, SetObject *objData) { sprite->frameNumber = objData->index = objData->frames[sprite->animFrame]; if (sprite->animFrame == 5) - data.byte(kThroughdoor) = 1; + _vars._throughDoor = 1; } else { // shut door @@ -399,43 +373,43 @@ void DreamGenContext::lockedDoorway(Sprite *sprite, SetObject *objData) { if (sprite->animFrame != 0) --sprite->animFrame; - data.byte(kThroughdoor) = 0; + _vars._throughDoor = 0; sprite->frameNumber = objData->index = objData->frames[sprite->animFrame]; if (sprite->animFrame == 0) { - turnPathOff(data.byte(kDoorpath)); - data.byte(kLockstatus) = 1; + turnPathOff(_vars._doorPath); + _vars._lockStatus = 1; } } } -void DreamGenContext::liftSprite(Sprite *sprite, SetObject *objData) { - uint8 liftFlag = data.byte(kLiftflag); +void DreamWebEngine::liftSprite(Sprite *sprite, SetObject *objData) { + uint8 liftFlag = _vars._liftFlag; if (liftFlag == 0) { //liftclosed - turnPathOff(data.byte(kLiftpath)); + turnPathOff(_vars._liftPath); - if (data.byte(kCounttoopen) != 0) { - _dec(data.byte(kCounttoopen)); - if (data.byte(kCounttoopen) == 0) - data.byte(kLiftflag) = 3; + if (_vars._countToOpen != 0) { + _vars._countToOpen--; + if (_vars._countToOpen == 0) + _vars._liftFlag = 3; } sprite->animFrame = 0; sprite->frameNumber = objData->index = objData->frames[sprite->animFrame]; } else if (liftFlag == 1) { //liftopen - turnPathOn(data.byte(kLiftpath)); + turnPathOn(_vars._liftPath); - if (data.byte(kCounttoclose) != 0) { - _dec(data.byte(kCounttoclose)); - if (data.byte(kCounttoclose) == 0) - data.byte(kLiftflag) = 2; + if (_vars._countToClose != 0) { + _vars._countToClose--; + if (_vars._countToClose == 0) + _vars._liftFlag = 2; } sprite->animFrame = 12; sprite->frameNumber = objData->index = objData->frames[sprite->animFrame]; } else if (liftFlag == 3) { //openlift if (sprite->animFrame == 12) { - data.byte(kLiftflag) = 1; + _vars._liftFlag = 1; return; } ++sprite->animFrame; @@ -446,7 +420,7 @@ void DreamGenContext::liftSprite(Sprite *sprite, SetObject *objData) { } else { //closeLift assert(liftFlag == 2); if (sprite->animFrame == 0) { - data.byte(kLiftflag) = 0; + _vars._liftFlag = 0; return; } --sprite->animFrame; @@ -457,40 +431,34 @@ void DreamGenContext::liftSprite(Sprite *sprite, SetObject *objData) { } } -Reel *DreamBase::getReelStart(uint16 reelPointer) { - Reel *reel = (Reel *)getSegment(data.word(kReels)).ptr(kReellist + reelPointer * sizeof(Reel) * 8, sizeof(Reel)); +Reel *DreamWebEngine::getReelStart(uint16 reelPointer) { + Reel *reel = &_reelList[reelPointer * 8]; return reel; } // Locate the reel segment (reel1, reel2, reel3) this frame is stored in, // and adjust the frame number relative to this segment. -const Frame *DreamBase::findSource(uint16 &frame) { - uint16 base; +const GraphicsFile *DreamWebEngine::findSource(uint16 &frame) { if (frame < 160) { - base = data.word(kReel1); + return &_reel1; } else if (frame < 320) { frame -= 160; - base = data.word(kReel2); + return &_reel2; } else { frame -= 320; - base = data.word(kReel3); + return &_reel3; } - return (const Frame *)getSegment(base).ptr(0, (frame+1)*sizeof(Frame)); } -void DreamBase::showReelFrame(Reel *reel) { - uint16 x = reel->x + data.word(kMapadx); - uint16 y = reel->y + data.word(kMapady); +void DreamWebEngine::showReelFrame(Reel *reel) { + uint16 x = reel->x + _mapAdX; + uint16 y = reel->y + _mapAdY; uint16 frame = reel->frame(); - const Frame *base = findSource(frame); - showFrame(base, x, y, frame, 8); + const GraphicsFile *base = findSource(frame); + showFrame(*base, x, y, frame, 8); } -void DreamGenContext::showGameReel() { - showGameReel((ReelRoutine *)es.ptr(bx, sizeof(ReelRoutine))); -} - -void DreamGenContext::showGameReel(ReelRoutine *routine) { +void DreamWebEngine::showGameReel(ReelRoutine *routine) { uint16 reelPointer = routine->reelPointer(); if (reelPointer >= 512) return; @@ -498,401 +466,161 @@ void DreamGenContext::showGameReel(ReelRoutine *routine) { routine->setReelPointer(reelPointer); } -const Frame *DreamBase::getReelFrameAX(uint16 frame) { - const Frame *base = findSource(frame); - return base + frame; +const Frame *DreamWebEngine::getReelFrameAX(uint16 frame) { + const GraphicsFile *base = findSource(frame); + return &base->_frames[frame]; } -void DreamGenContext::showRain() { - Rain *rain = (Rain *)getSegment(data.word(kBuffers)).ptr(kRainlist, 0); - - // Do nothing if there's no rain at all - if (rain->x == 255) - return; - - ds = data.word(kMainsprites); - si = 6*58; // Frame 58 - ax = ds.word(si+2); // Frame::ptr - si = ax + 2080; - - for (; rain->x != 255; ++rain) { - uint16 y = rain->y + data.word(kMapady) + data.word(kMapystart); - uint16 x = rain->x + data.word(kMapadx) + data.word(kMapxstart); - uint16 size = rain->size; - ax = ((uint16)(rain->w3() - rain->b5)) & 511; - rain->setW3(ax); - const uint8 *src = ds.ptr(si, 0) + ax; - uint8 *dst = workspace() + y * 320 + x; - for (uint16 i = 0; i < size; ++i) { - uint8 v = src[i]; - if (v != 0) - *dst = v; - dst += 320-1; // advance diagonally - } - } - - if (data.word(kCh1blockstocopy) != 0) - return; - if (data.byte(kReallocation) == 2 && data.byte(kBeenmugged) != 1) - return; - if (data.byte(kReallocation) == 55) - return; - - if (engine->randomNumber() >= 1) // play thunder with 1 in 256 chance - return; - - uint8 soundIndex; - if (data.byte(kCh0playing) != 6) - soundIndex = 4; - else - soundIndex = 7; - playChannel1(soundIndex); -} - -void DreamGenContext::moveMap(uint8 param) { +void DreamWebEngine::moveMap(uint8 param) { switch (param) { case 32: - data.byte(kMapy) -= 20; + _mapY -= 20; break; case 16: - data.byte(kMapy) -= 10; + _mapY -= 10; break; case 8: - data.byte(kMapy) += 10; + _mapY += 10; break; case 2: - data.byte(kMapx) += 11; + _mapX += 11; break; default: - data.byte(kMapx) -= 11; + _mapX -= 11; break; } - data.byte(kNowinnewroom) = 1; + _nowInNewRoom = 1; } -void DreamGenContext::checkOne() { - uint8 flag, flagEx, type, flagX, flagY; - checkOne(cl, ch, &flag, &flagEx, &type, &flagX, &flagY); - - cl = flag; - ch = flagEx; - dl = flagX; - dh = flagY; - al = type; -} - -void DreamGenContext::checkOne(uint8 x, uint8 y, uint8 *flag, uint8 *flagEx, uint8 *type, uint8 *flagX, uint8 *flagY) { +void DreamWebEngine::checkOne(uint8 x, uint8 y, uint8 *flag, uint8 *flagEx, uint8 *type, uint8 *flagX, uint8 *flagY) { *flagX = x / 16; *flagY = y / 16; - const uint8 *tileData = getSegment(data.word(kBuffers)).ptr(kMapflags + (*flagY * 11 + *flagX) * 3, 3); - *flag = tileData[0]; - *flagEx = tileData[1]; - *type = tileData[2]; -} - -void DreamGenContext::getBlockOfPixel() { - al = getBlockOfPixel(cl, ch); -} - -uint8 DreamGenContext::getBlockOfPixel(uint8 x, uint8 y) { - uint8 flag, flagEx, type, flagX, flagY; - checkOne(x + data.word(kMapxstart), y + data.word(kMapystart), &flag, &flagEx, &type, &flagX, &flagY); - if (flag & 1) - return 0; - else - return type; + const MapFlag &tileData = _mapFlags[*flagY * 11 + *flagX]; + *flag = tileData._flag; + *flagEx = tileData._flagEx; + *type = tileData._type; } -Rain *DreamGenContext::splitIntoLines(uint8 x, uint8 y, Rain *rain) { - do { - // Look for line start - while (!getBlockOfPixel(x, y)) { - --x; - ++y; - if (x == 0 || y >= data.byte(kMapysize)) - return rain; - } - - rain->x = x; - rain->y = y; - - uint8 length = 1; - - // Look for line end - while (getBlockOfPixel(x, y)) { - --x; - ++y; - if (x == 0 || y >= data.byte(kMapysize)) - break; - ++length; - } - - rain->size = length; - rain->w3_lo = engine->randomNumber(); - rain->w3_hi = engine->randomNumber(); - rain->b5 = (engine->randomNumber() & 3) + 4; - ++rain; - } while (x > 0 && y < data.byte(kMapysize)); - - return rain; -} - -struct RainLocation { - uint8 location; - uint8 x, y; - uint8 rainSpacing; -}; - -static const RainLocation rainLocationList[] = { - { 1,44,10,16 }, - { 4,11,30,14 }, - { 4,22,30,14 }, - { 3,33,10,14 }, - { 10,33,30,14 }, - { 10,22,30,24 }, - { 9,22,10,14 }, - { 2,33,0,14 }, - { 2,22,0,14 }, - { 6,11,30,14 }, - { 7,11,20,18 }, - { 7,0,20,18 }, - { 7,0,30,18 }, - { 55,44,0,14 }, - { 5,22,30,14 }, - - { 8,0,10,18 }, - { 8,11,10,18 }, - { 8,22,10,18 }, - { 8,33,10,18 }, - { 8,33,20,18 }, - { 8,33,30,18 }, - { 8,33,40,18 }, - { 8,22,40,18 }, - { 8,11,40,18 }, - - { 21,44,20,18 }, - { 255,0,0,0 } -}; - -void DreamGenContext::initRain() { - const RainLocation *r = rainLocationList; - Rain *rainList = (Rain *)getSegment(data.word(kBuffers)).ptr(kRainlist, 0); - Rain *rain = rainList; - - uint8 rainSpacing = 0; - - // look up location in rainLocationList to determine rainSpacing - for (r = rainLocationList; r->location != 0xff; ++r) { - if (r->location == data.byte(kReallocation) && - r->x == data.byte(kMapx) && r->y == data.byte(kMapy)) { - rainSpacing = r->rainSpacing; - break; - } - } - - if (rainSpacing == 0) { - // location not found in rainLocationList: no rain - rain->x = 0xff; +void DreamWebEngine::intro1Text() { + if (_introCount != 2 && _introCount != 4 && _introCount != 6) return; - } - // start lines of rain from top of screen - uint8 x = 4; - do { - uint8 delta; - do { - delta = (engine->randomNumber() & 31) + 3; - } while (delta >= rainSpacing); - - x += delta; - if (x >= data.byte(kMapxsize)) - break; - - rain = splitIntoLines(x, 0, rain); - } while (true); - - // start lines of rain from side of screen - uint8 y = 0; - do { - uint8 delta; - do { - delta = (engine->randomNumber() & 31) + 3; - } while (delta >= rainSpacing); - - y += delta; - if (y >= data.byte(kMapysize)) - break; - - rain = splitIntoLines(data.byte(kMapxsize) - 1, y, rain); - } while (true); - - rain->x = 0xff; -} - -void DreamGenContext::intro1Text() { - if (data.byte(kIntrocount) != 2 && data.byte(kIntrocount) != 4 && data.byte(kIntrocount) != 6) - return; - - if (isCD() && data.byte(kCh1playing) != 255) { - data.byte(kIntrocount)--; + if (hasSpeech() && _channel1Playing != 255) { + _introCount--; } else { - if (data.byte(kIntrocount) == 2) + if (_introCount == 2) setupTimedTemp(40, 82, 34, 130, 90, 1); - else if (data.byte(kIntrocount) == 4) + else if (_introCount == 4) setupTimedTemp(41, 82, 34, 130, 90, 1); - else if (data.byte(kIntrocount) == 6) + else if (_introCount == 6) setupTimedTemp(42, 82, 34, 130, 90, 1); } } -void DreamGenContext::intro2Text() { - if (ax == 5) +void DreamWebEngine::intro2Text(uint16 nextReelPointer) { + if (nextReelPointer == 5) setupTimedTemp(43, 82, 34, 40, 90, 1); - else if (ax == 15) + else if (nextReelPointer == 15) setupTimedTemp(44, 82, 34, 40, 90, 1); } -void DreamGenContext::intro3Text() { - if (ax == 107) +void DreamWebEngine::intro3Text(uint16 nextReelPointer) { + if (nextReelPointer == 107) setupTimedTemp(45, 82, 36, 56, 100, 1); - else if (ax == (isCD() ? 108 : 109)) + else if (nextReelPointer == (hasSpeech() ? 108 : 109)) setupTimedTemp(46, 82, 36, 56, 100, 1); } -void DreamBase::rollEndCredits() { - playChannel0(16, 255); - data.byte(kVolume) = 7; - data.byte(kVolumeto) = 0; - data.byte(kVolumedirection) = 0xFF; - - multiGet(mapStore(), 75, 20, 160, 160); - - const uint8 *string = getTextInFile1(3); - const int linespacing = data.word(kLinespacing); - - for (int i = 0; i < 254; ++i) { - // Output the text, initially with an offset of 10 pixels, - // then move it up one pixel until we shifted it by a complete - // line of text. - for (int j = 0; j < linespacing; ++j) { - vSync(); - multiPut(mapStore(), 75, 20, 160, 160); - vSync(); - - // Output up to 18 lines of text - uint16 y = 10 - j; - const uint8 *tmp_str = string; - for (int k = 0; k < 18; ++k) { - DreamBase::printDirect(&tmp_str, 75, &y, 160 + 1, true); - y += linespacing; - } - - vSync(); - multiDump(75, 20, 160, 160); - } - - // Skip to the next text line - byte c; - do { - c = *string++; - } while (c != ':' && c != 0); - } - hangOn(100); - panelToMap(); - fadeScreenUpHalf(); -} - - -void DreamGenContext::monks2text() { - bool isGermanCD = isCD() && engine->getLanguage() == Common::DE_DEU; +void DreamWebEngine::monks2text() { + bool isGermanCD = hasSpeech() && getLanguage() == Common::DE_DEU; - if (data.byte(kIntrocount) == 1) + if (_introCount == 1) setupTimedTemp(8, 82, 36, 160, 120, 1); - else if (data.byte(kIntrocount) == (isGermanCD ? 5 : 4)) + else if (_introCount == (isGermanCD ? 5 : 4)) setupTimedTemp(9, 82, 36, 160, 120, 1); - else if (data.byte(kIntrocount) == (isGermanCD ? 9 : 7)) + else if (_introCount == (isGermanCD ? 9 : 7)) setupTimedTemp(10, 82, 36, 160, 120, 1); - else if (data.byte(kIntrocount) == 10 && !isGermanCD) { - if (isCD()) - data.byte(kIntrocount) = 12; + else if (_introCount == 10 && !isGermanCD) { + if (hasSpeech()) + _introCount = 12; setupTimedTemp(11, 82, 0, 105, 120, 1); - } else if (data.byte(kIntrocount) == 13 && isGermanCD) { - data.byte(kIntrocount) = 14; + } else if (_introCount == 13 && isGermanCD) { + _introCount = 14; setupTimedTemp(11, 82, 0, 105, 120, 1); - } else if (data.byte(kIntrocount) == 13 && !isGermanCD) { - if (isCD()) - data.byte(kIntrocount) = 17; + } else if (_introCount == 13 && !isGermanCD) { + if (hasSpeech()) + _introCount = 17; else setupTimedTemp(12, 82, 0, 120, 120, 1); - } else if (data.byte(kIntrocount) == 16 && !isGermanCD) + } else if (_introCount == 16 && !isGermanCD) setupTimedTemp(13, 82, 0, 135, 120, 1); - else if (data.byte(kIntrocount) == 19) + else if (_introCount == 19) setupTimedTemp(14, 82, 36, 160, 100, 1); - else if (data.byte(kIntrocount) == (isGermanCD ? 23 : 22)) + else if (_introCount == (isGermanCD ? 23 : 22)) setupTimedTemp(15, 82, 36, 160, 120, 1); - else if (data.byte(kIntrocount) == (isGermanCD ? 27 : 25)) + else if (_introCount == (isGermanCD ? 27 : 25)) setupTimedTemp(16, 82, 36, 160, 120, 1); - else if (data.byte(kIntrocount) == (isCD() ? 27 : 28) && !isGermanCD) + else if (_introCount == (hasSpeech() ? 27 : 28) && !isGermanCD) setupTimedTemp(17, 82, 36, 160, 120, 1); - else if (data.byte(kIntrocount) == 30 && isGermanCD) + else if (_introCount == 30 && isGermanCD) setupTimedTemp(17, 82, 36, 160, 120, 1); - else if (data.byte(kIntrocount) == (isGermanCD ? 35 : 31)) + else if (_introCount == (isGermanCD ? 35 : 31)) setupTimedTemp(18, 82, 36, 160, 120, 1); } -void DreamGenContext::textForEnd() { - if (data.byte(kIntrocount) == 20) +void DreamWebEngine::textForEnd() { + if (_introCount == 20) setupTimedTemp(0, 83, 34, 20, 60, 1); - else if (data.byte(kIntrocount) == (isCD() ? 50 : 65)) + else if (_introCount == (hasSpeech() ? 50 : 65)) setupTimedTemp(1, 83, 34, 20, 60, 1); - else if (data.byte(kIntrocount) == (isCD() ? 85 : 110)) + else if (_introCount == (hasSpeech() ? 85 : 110)) setupTimedTemp(2, 83, 34, 20, 60, 1); } -void DreamGenContext::textForMonkHelper(uint8 textIndex, uint8 voiceIndex, uint8 x, uint8 y, uint16 countToTimed, uint16 timeCount) { - if (isCD() && data.byte(kCh1playing) != 255) - data.byte(kIntrocount)--; +void DreamWebEngine::textForMonkHelper(uint8 textIndex, uint8 voiceIndex, uint8 x, uint8 y, uint16 countToTimed, uint16 timeCount) { + if (hasSpeech() && _channel1Playing != 255) + _introCount--; else setupTimedTemp(textIndex, voiceIndex, x, y, countToTimed, timeCount); } -void DreamGenContext::textForMonk() { - if (data.byte(kIntrocount) == 1) +void DreamWebEngine::textForMonk() { + if (_introCount == 1) textForMonkHelper(19, 82, 68, 154, 120, 1); - else if (data.byte(kIntrocount) == 5) + else if (_introCount == 5) textForMonkHelper(20, 82, 68, 38, 120, 1); - else if (data.byte(kIntrocount) == 9) + else if (_introCount == 9) textForMonkHelper(21, 82, 48, 154, 120, 1); - else if (data.byte(kIntrocount) == 13) + else if (_introCount == 13) textForMonkHelper(22, 82, 68, 38, 120, 1); - else if (data.byte(kIntrocount) == (isCD() ? 15 : 17)) + else if (_introCount == (hasSpeech() ? 15 : 17)) textForMonkHelper(23, 82, 68, 154, 120, 1); - else if (data.byte(kIntrocount) == 21) + else if (_introCount == 21) textForMonkHelper(24, 82, 68, 38, 120, 1); - else if (data.byte(kIntrocount) == 25) + else if (_introCount == 25) textForMonkHelper(25, 82, 68, 154, 120, 1); - else if (data.byte(kIntrocount) == 29) + else if (_introCount == 29) textForMonkHelper(26, 82, 68, 38, 120, 1); - else if (data.byte(kIntrocount) == 33) + else if (_introCount == 33) textForMonkHelper(27, 82, 68, 154, 120, 1); - else if (data.byte(kIntrocount) == 37) + else if (_introCount == 37) textForMonkHelper(28, 82, 68, 154, 120, 1); - else if (data.byte(kIntrocount) == 41) + else if (_introCount == 41) textForMonkHelper(29, 82, 68, 38, 120, 1); - else if (data.byte(kIntrocount) == 45) + else if (_introCount == 45) textForMonkHelper(30, 82, 68, 154, 120, 1); - else if (data.byte(kIntrocount) == (isCD() ? 52 : 49)) + else if (_introCount == (hasSpeech() ? 52 : 49)) textForMonkHelper(31, 82, 68, 154, 220, 1); - else if (data.byte(kIntrocount) == 53) { + else if (_introCount == 53) { fadeScreenDowns(); - if (isCD()) { - data.byte(kVolumeto) = 7; - data.byte(kVolumedirection) = 1; + if (hasSpeech()) { + _volumeTo = 7; + _volumeDirection = 1; } } } -void DreamGenContext::reelsOnScreen() { +void DreamWebEngine::reelsOnScreen() { reconstruct(); updatePeople(); watchReel(); @@ -900,16 +628,16 @@ void DreamGenContext::reelsOnScreen() { useTimedText(); } -void DreamGenContext::reconstruct() { - if (data.byte(kHavedoneobs) == 0) +void DreamWebEngine::reconstruct() { + if (_haveDoneObs == 0) return; - data.byte(kNewobs) = 1; + _vars._newObs = 1; drawFloor(); spriteUpdate(); printSprites(); - if ((data.byte(kForeignrelease) != 0) && (data.byte(kReallocation) == 20)) + if (_foreignRelease && (_realLocation == 20)) underTextLine(); - data.byte(kHavedoneobs) = 0; + _haveDoneObs = 0; } @@ -1164,18 +892,18 @@ static const ReelSound *g_roomByRoom[] = { }; -void DreamBase::soundOnReels(uint16 reelPointer) { - const ReelSound *r = g_roomByRoom[data.byte(kReallocation)]; +void DreamWebEngine::soundOnReels(uint16 reelPointer) { + const ReelSound *r = g_roomByRoom[_realLocation]; - if (engine->getLanguage() == Common::DE_DEU && r == g_roomSound29) + if (getLanguage() == Common::DE_DEU && r == g_roomSound29) r = g_roomSound29_German; for (; r->_sample != 255; ++r) { if (r->_reelPointer != reelPointer) continue; - if (r->_reelPointer == data.word(kLastsoundreel)) + if (r->_reelPointer == _lastSoundReel) continue; - data.word(kLastsoundreel) = r->_reelPointer; + _lastSoundReel = r->_reelPointer; if (r->_sample < 64) { playChannel1(r->_sample); return; @@ -1187,52 +915,107 @@ void DreamBase::soundOnReels(uint16 reelPointer) { playChannel0(r->_sample & 63, 255); } - if (data.word(kLastsoundreel) != reelPointer) - data.word(kLastsoundreel) = (uint16)-1; + if (_lastSoundReel != reelPointer) + _lastSoundReel = (uint16)-1; } -void DreamGenContext::clearBeforeLoad() { - if (data.byte(kRoomloaded) != 1) - return /* (noclear) */; +void DreamWebEngine::clearBeforeLoad() { + if (_roomLoaded != 1) + return; // noclear clearReels(); //clearRest - uint8 *dst = (uint8 *)getSegment(data.word(kMapdata)).ptr(0, 0); - memset(dst, 0, kMaplen); - deallocateMem(data.word(kBackdrop)); - deallocateMem(data.word(kSetframes)); - deallocateMem(data.word(kReels)); - deallocateMem(data.word(kPeople)); - deallocateMem(data.word(kSetdesc)); - deallocateMem(data.word(kBlockdesc)); - deallocateMem(data.word(kRoomdesc)); - deallocateMem(data.word(kFreeframes)); - deallocateMem(data.word(kFreedesc)); - - data.byte(kRoomloaded) = 0; -} + memset(_mapData, 0, kLengthOfMap); + delete[] _backdropBlocks; + _backdropBlocks = 0; + _setFrames.clear(); + delete[] _reelList; + _reelList = 0; + _personText.clear(); + _setDesc.clear(); + _blockDesc.clear(); + _roomDesc.clear(); + _freeFrames.clear(); + _freeDesc.clear(); -void DreamGenContext::clearReels() { - deallocateMem(data.word(kReel1)); - deallocateMem(data.word(kReel2)); - deallocateMem(data.word(kReel3)); + _roomLoaded = 0; } -void DreamGenContext::getRidOfReels() { - if (data.byte(kRoomloaded) == 0) - return /* (dontgetrid) */; +void DreamWebEngine::clearReels() { + _reel1.clear(); + _reel2.clear(); + _reel3.clear(); +} - deallocateMem(data.word(kReel1)); - deallocateMem(data.word(kReel2)); - deallocateMem(data.word(kReel3)); +void DreamWebEngine::getRidOfReels() { + if (_roomLoaded) + clearReels(); } -void DreamGenContext::liftNoise(uint8 index) { - if (data.byte(kReallocation) == 5 || data.byte(kReallocation) == 21) +void DreamWebEngine::liftNoise(uint8 index) { + if (_realLocation == 5 || _realLocation == 21) playChannel1(13); // hiss noise else playChannel1(index); } -} // End of namespace DreamGen +void DreamWebEngine::checkForExit(Sprite *sprite) { + uint8 flag, flagEx, type, flagX, flagY; + checkOne(_ryanX + 12, _ryanY + 12, &flag, &flagEx, &type, &flagX, &flagY); + _lastFlag = flag; + + if (flag & 64) { + _autoLocation = flagEx; + return; + } + + if (!(flag & 32)) { + if (flag & 4) { + // adjust left + _lastFlag = 0; + _mapX -= 11; + sprite->x = 16 * flagEx; + _nowInNewRoom = 1; + } else if (flag & 2) { + // adjust right + _mapX += 11; + sprite->x = 16 * flagEx - 2; + _nowInNewRoom = 1; + } else if (flag & 8) { + // adjust down + _mapY += 10; + sprite->y = 16 * flagEx; + _nowInNewRoom = 1; + } else if (flag & 16) { + // adjust up + _mapY -= 10; + sprite->y = 16 * flagEx; + _nowInNewRoom = 1; + } + + return; + } + + if (_realLocation == 2) { + // Can't leave Louis' until you found shoes + + int shoeCount = 0; + if (isRyanHolding("WETA")) shoeCount++; + if (isRyanHolding("WETB")) shoeCount++; + + if (shoeCount < 2) { + uint8 text = shoeCount ? 43 : 42; + setupTimedUse(text, 80, 10, 68, 64); + + _turnToFace = (_facing + 4) & 7; + return; + } + + } + + _vars._needToTravel = 1; +} + +} // End of namespace DreamWeb + diff --git a/engines/dreamweb/structs.h b/engines/dreamweb/structs.h index 30962a272c..24b67e317a 100644 --- a/engines/dreamweb/structs.h +++ b/engines/dreamweb/structs.h @@ -26,58 +26,47 @@ #include "common/endian.h" #include "common/rect.h" -namespace DreamGen { +namespace DreamWeb { + +struct GraphicsFile; +struct SetObject; struct Sprite { - uint16 _updateCallback; - uint16 updateCallback() const { return READ_LE_UINT16(&_updateCallback); } - void setUpdateCallback(uint16 v) { WRITE_LE_UINT16(&_updateCallback, v); } - uint16 w2; - uint16 w4; - uint16 _frameData; - uint16 frameData() const { return READ_LE_UINT16(&_frameData); } - void setFrameData(uint16 v) { WRITE_LE_UINT16(&_frameData, v); } - uint16 w8; + bool _mainManCallback; + const GraphicsFile *_frameData; uint8 x; uint8 y; - uint16 w12; - uint8 b14; uint8 frameNumber; - uint8 b16; - uint8 b17; uint8 delay; uint8 animFrame; // index into SetObject::frames - uint16 _objData; - uint16 objData() const { return READ_LE_UINT16(&_objData); } - void setObjData(uint16 v) { WRITE_LE_UINT16(&_objData, v); } + SetObject *_objData; uint8 speed; uint8 priority; - uint16 w24; - uint16 w26; - uint8 b28; uint8 walkFrame; uint8 type; uint8 hidden; }; -class DreamGenContext; - struct RectWithCallback { uint16 _xMin, _xMax; uint16 _yMin, _yMax; - void (DreamGenContext::*_callback)(); + void (DreamWebEngine::*_callback)(); bool contains(uint16 x, uint16 y) const { return (x >= _xMin) && (x < _xMax) && (y >= _yMin) && (y < _yMax); } }; + + +#include "common/pack-start.h" // START STRUCT PACKING + struct SetObject { uint8 b0; uint8 b1; uint8 b2; - uint8 b3; - uint8 b4; + uint8 slotSize; + uint8 slotCount; uint8 priority; uint8 b6; uint8 delay; @@ -85,7 +74,7 @@ struct SetObject { uint8 b9; uint8 b10; uint8 b11; - uint8 name[4]; + uint8 objId[4]; uint8 b16; uint8 index; uint8 frames[13]; // Table mapping animFrame to sprite frame number @@ -119,19 +108,19 @@ struct SetObject { uint8 b57; uint8 mapad[5]; uint8 b63; -}; +} PACKED_STRUCT; struct DynObject { uint8 currentLocation; uint8 index; uint8 mapad[5]; - uint8 b7; - uint8 b8; - uint8 b9; - uint8 b10; + uint8 slotSize; // the size of an object's slots + uint8 slotCount; // the number of slots of an object + uint8 objectSize; // the size of an object + uint8 turnedOn; uint8 initialLocation; - uint8 id[4]; -}; + uint8 objId[4]; +} PACKED_STRUCT; struct ObjPos { uint8 xMin; @@ -142,7 +131,7 @@ struct ObjPos { bool contains(uint8 x, uint8 y) const { return (x >= xMin) && (x < xMax) && (y >= yMin) && (y < yMax); } -}; +} PACKED_STRUCT; struct Frame { uint8 width; @@ -152,7 +141,7 @@ struct Frame { void setPtr(uint16 v) { WRITE_LE_UINT16(&_ptr, v); } uint8 x; uint8 y; -}; +} PACKED_STRUCT; struct Reel { uint8 frame_lo; @@ -162,35 +151,35 @@ struct Reel { uint8 x; uint8 y; uint8 b4; -}; +} PACKED_STRUCT; + +#include "common/pack-end.h" // END STRUCT PACKING + + struct ReelRoutine { uint8 reallocation; uint8 mapX; uint8 mapY; - uint8 b3; - uint8 b4; - uint16 reelPointer() const { return READ_LE_UINT16(&b3); } - void setReelPointer(uint16 v) { WRITE_LE_UINT16(&b3, v); } - void incReelPointer() { setReelPointer(reelPointer() + 1); } + uint16 _reelPointer; + uint16 reelPointer() const { return _reelPointer; } + void setReelPointer(uint16 v) { _reelPointer = v; } + void incReelPointer() { _reelPointer++; } uint8 period; uint8 counter; uint8 b7; }; struct People { - uint8 b0; - uint8 b1; - uint16 reelPointer() const { return READ_LE_UINT16(&b0); } - void setReelPointer(uint16 v) { WRITE_LE_UINT16(&b0, v); } - uint8 b2; - uint8 b3; - uint16 routinePointer() const { return READ_LE_UINT16(&b2); } - void setRoutinePointer(uint16 v) { WRITE_LE_UINT16(&b2, v); } + uint16 _reelPointer; + ReelRoutine *_routinePointer; uint8 b4; - }; + + +#include "common/pack-start.h" // START STRUCT PACKING + struct Room { char name[13]; uint8 roomsSample; @@ -212,59 +201,45 @@ struct Room { uint8 b29; uint8 b30; uint8 realLocation; -}; +} PACKED_STRUCT; + extern const Room g_roomData[]; struct Rain { uint8 x; uint8 y; uint8 size; - uint8 w3_lo; - uint8 w3_hi; - uint16 w3() const { return READ_LE_UINT16(&w3_lo); } - void setW3(uint16 v) { WRITE_LE_UINT16(&w3_lo, v); } + uint16 w3; uint8 b5; -}; +} PACKED_STRUCT; struct Change { uint8 index; uint8 location; uint8 value; uint8 type; -}; +} PACKED_STRUCT; struct PathNode { uint8 x; uint8 y; - uint8 b2; - uint8 b3; - uint8 b4; - uint8 b5; + uint8 x1; + uint8 y1; + uint8 x2; + uint8 y2; uint8 on; uint8 dir; -}; +} PACKED_STRUCT; struct PathSegment { uint8 b0; uint8 b1; -}; +} PACKED_STRUCT; struct RoomPaths { PathNode nodes[12]; PathSegment segments[24]; -}; - -struct Sound { - uint8 w1_lo; - uint8 w1_hi; - uint16 offset() const { return READ_LE_UINT16(&w1_lo); } - void setOffset(uint16 v) { WRITE_LE_UINT16(&w1_lo, v); } - uint8 w3_lo; - uint8 w3_hi; - uint16 blockCount() const { return READ_LE_UINT16(&w3_lo); } - void setBlockCount(uint16 v) { WRITE_LE_UINT16(&w3_lo, v); } - uint8 b5; -}; +} PACKED_STRUCT; struct FileHeader { char _desc[50]; @@ -279,7 +254,7 @@ struct FileHeader { assert(i < 20); WRITE_LE_UINT16(&_len[i], length); } -}; +} PACKED_STRUCT; struct Atmosphere { uint8 _location; @@ -287,6 +262,174 @@ struct Atmosphere { uint8 _mapY; uint8 _sound; uint8 _repeat; +} PACKED_STRUCT; + +#include "common/pack-end.h" // END STRUCT PACKING + + + +enum ObjectTypes { + kSetObjectType1 = 1, + kFreeObjectType = 2, + kSetObjectType3 = 3, + kExObjectType = 4 +}; + +struct ObjectRef { + uint8 _index; + uint8 _type; // enum ObjectTypes + + bool operator==(const ObjectRef &r) const { + return _index == r._index && _type == r._type; + } + bool operator!=(const ObjectRef &r) const { + return _index != r._index || _type != r._type; + } +}; + + + +#include "common/pack-start.h" // START STRUCT PACKING + +struct BackdropMapFlag { + uint8 _flag; + uint8 _flagEx; +} PACKED_STRUCT; + +struct MapFlag { + uint8 _flag; + uint8 _flagEx; + uint8 _type; +} PACKED_STRUCT; + +#include "common/pack-end.h" // END STRUCT PACKING + + + + + +struct TextFile { + TextFile(unsigned int size = 66) : _size(size), _text(0) { _offsetsLE = new uint16[_size]; } + + ~TextFile() { + delete[] _offsetsLE; + _offsetsLE = 0; + _size = 0; + clear(); + } + + uint16 *_offsetsLE; + unsigned int _size; + char *_text; + + const char *getString(unsigned int i) const { + assert(i < _size); + return _text + getOffset(i); + } + void setOffset(unsigned int i, uint16 offset) { + WRITE_LE_UINT16(&_offsetsLE[i], offset); + } + uint16 getOffset(unsigned int i) const { + return READ_LE_UINT16(&_offsetsLE[i]); + } + void clear() { + delete[] _text; + _text = 0; + } +}; + +struct GraphicsFile { + GraphicsFile() : _data(0), _frames(0) { } + + Frame *_frames; + uint8 *_data; + + const uint8 *getFrameData(unsigned int i) const { + // There is 2080 bytes of Frame data, but that is between 346 and 347 + // frames + assert(i < 346); + return _data + _frames[i].ptr(); + } + void clear() { + delete[] _frames; + _frames = 0; + delete[] _data; + _data = 0; + } +}; + +struct GameVars { + uint8 _startVars; + uint8 _progressPoints; + uint8 _watchOn; + uint8 _shadesOn; + uint8 _secondCount; + uint8 _minuteCount; + uint8 _hourCount; + uint8 _zoomOn; + uint8 _location; + uint8 _exPos; + uint16 _exFramePos; + uint16 _exTextPos; + uint16 _card1Money; + uint16 _listPos; + uint8 _ryanPage; + uint16 _watchingTime; + uint16 _reelToWatch; // reel plays from here in mode 0 + uint16 _endWatchReel; // and stops here. Mode set to 1 + uint8 _speedCount; + uint8 _watchSpeed; + uint16 _reelToHold; // if mode is 1 hold on this reel + uint16 _endOfHoldReel; // if mode is 2 then play to endOfHoldReel and reset mode to -1 + uint8 _watchMode; + uint8 _destAfterHold; // set walking destination + uint8 _newsItem; + uint8 _liftFlag; + uint8 _liftPath; + uint8 _lockStatus; + uint8 _doorPath; + uint8 _countToOpen; + uint8 _countToClose; + uint8 _rockstarDead; + uint8 _generalDead; + uint8 _sartainDead; + uint8 _aideDead; + uint8 _beenMugged; + uint8 _gunPassFlag; + uint8 _canMoveAltar; + uint8 _talkedToAttendant; + uint8 _talkedToSparky; + uint8 _talkedToBoss; + uint8 _talkedToRecep; + uint8 _cardPassFlag; + uint8 _madmanFlag; + uint8 _keeperFlag; + uint8 _lastTrigger; + uint8 _manDead; + uint8 _seed1; + uint8 _seed2; + uint8 _seed3; + uint8 _needToTravel; + uint8 _throughDoor; + uint8 _newObs; + uint8 _ryanOn; + uint8 _combatCount; + uint8 _lastWeapon; + uint8 _dreamNumber; + uint8 _roomAfterDream; + uint8 _shakeCounter; +}; + +struct TimedTemp { + TimedTemp() : _timeCount(0), _string(0) { } + + uint8 _x; + uint8 _y; + + uint16 _timeCount; + uint16 _countToTimed; + + const char *_string; }; } // End of namespace DreamWeb diff --git a/engines/dreamweb/stubs.cpp b/engines/dreamweb/stubs.cpp index 162152ccda..9789e20210 100644 --- a/engines/dreamweb/stubs.cpp +++ b/engines/dreamweb/stubs.cpp @@ -21,86 +21,100 @@ */ #include "dreamweb/dreamweb.h" -#include "engines/util.h" #include "common/config-manager.h" -namespace DreamGen { +namespace DreamWeb { -// Keyboard buffer. data.word(kBufferin) and data.word(kBufferout) are indexes +// Keyboard buffer. _bufferIn and _bufferOut are indexes // into this, making it a ring buffer uint8 g_keyBuffer[16]; const Room g_roomData[] = { + // location 0 { "DREAMWEB.R00", // Ryan's apartment 5,255,33,10, 255,255,255,0, 1,6,2,255,3,255,255,255,255,255,0 }, + // location 1 { "DREAMWEB.R01", 1,255,44,10, 255,255,255,0, 7,2,255,255,255,255,6,255,255,255,1 }, + // location 2: Louis' (?) { "DREAMWEB.R02", 2,255,33,0, 255,255,255,0, 1,0,255,255,1,255,3,255,255,255,2 }, + // location 3 { "DREAMWEB.R03", 5,255,33,10, 255,255,255,0, 2,2,0,2,4,255,0,255,255,255,3 }, + // location 4 { "DREAMWEB.R04", 23,255,11,30, 255,255,255,0, 1,4,0,5,255,255,3,255,255,255,4 }, + // location 5: In hotel, lift noise audible (?) { "DREAMWEB.R05", 5,255,22,30, // if demo: 22,255,22,30, 255,255,255,0, 1,2,0,4,255,255,3,255,255,255,5 }, + // location 6: sarters (?) { "DREAMWEB.R06", 5,255,11,30, 255,255,255,0, 1,0,0,1,2,255,0,255,255,255,6 }, + // location 7 { "DREAMWEB.R07", 255,255,0,20, 255,255,255,0, 2,2,255,255,255,255,0,255,255,255,7 }, + // location 8: TV studio (?) { "DREAMWEB.R08", 8,255,0,10, 255,255,255,0, 1,2,255,255,255,255,0,11,40,0,8 }, + // location 9 { "DREAMWEB.R09", 9,255,22,10, 255,255,255,0, 4,6,255,255,255,255,0,255,255,255,9 }, + // location 10 { "DREAMWEB.R10", 10,255,33,30, 255,255,255,0, 2,0,255,255,2,2,4,22,30,255,10 }, // 22,30,0 switches // off path 0 in skip + // location 11 { "DREAMWEB.R11", 11,255,11,20, 255,255,255,0, 0,4,255,255,255,255,255,255,255,255,11 }, + // location 12 { "DREAMWEB.R12", 12,255,22,20, 255,255,255,0, 1,4,255,255,255,255,255,255,255,255,12 }, + // location 13: boathouse (?) { "DREAMWEB.R13", 12,255,22,20, 255,255,255,0, 1,4,255,255,255,255,255,255,255,255,13 }, + // location 14 { "DREAMWEB.R14", 14,255,44,20, 255,255,255,0, @@ -111,166 +125,196 @@ const Room g_roomData[] = { { "", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { "", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, + // location 19 { "DREAMWEB.R19", 19,255,0,0, 255,255,255,0, 0,4,255,255,255,255,255,255,255,255,19 }, + // location 20: Sart room (?) { "DREAMWEB.R20", 22,255,0,20, 255,255,255,0, 1,4,2,15,255,255,255,255,255,255,20 }, + // location 21: lift noise audible (?) { "DREAMWEB.R21", 5,255,11,10, // if demo: 22,255,11,10, 255,255,255,0, 1,4,2,15,1,255,255,255,255,255,21 }, + // location 22: pool room (?) { "DREAMWEB.R22", 22,255,22,10, 255,255,255,0, 0,4,255,255,1,255,255,255,255,255,22 }, + // location 23 { "DREAMWEB.R23", 23,255,22,30, 255,255,255,0, 1,4,2,15,3,255,255,255,255,255,23 }, + // location 24: only room in which initialInv() is active, i.e. we get initial inventory here { "DREAMWEB.R24", 5,255,44,0, 255,255,255,0, 1,6,2,15,255,255,255,255,255,255,24 }, + // location 25: helicopter (?) { "DREAMWEB.R25", 22,255,11,40, 255,255,255,0, 1,0,255,255,255,255,255,255,255,255,25 }, + // location 26: reached via trap door (?) { "DREAMWEB.R26", 9,255,22,20, 255,255,255,0, 4,2,255,255,255,255,255,255,255,255,26 }, + // location 27: rock room (?) { "DREAMWEB.R27", 22,255,11,20, 255,255,255,0, 0,6,255,255,255,255,255,255,255,255,27 }, + // location 28: related to TV studiou (?), see resetLocation() { "DREAMWEB.R28", 5,255,11,30, 255,255,255,0, 0,0,255,255,2,255,255,255,255,255,28 }, + // location 29: aide (?) { "DREAMWEB.R29", 22,255,11,10, 255,255,255,0, 0,2,255,255,255,255,255,255,255,255,29 }, - + // location 30 { "DREAMWEB.R05", // Duplicate of hotel lobby, but emerging from the lift. 5,255,22,10, // if demo: 22,255,22,10 255,255,255,0, 1,4,1,15,255,255,255,255,255,255,5 }, + // location 31 { "DREAMWEB.R04", // Duplicate of pool hall lobby, 23,255,22,20, // but emerging from the lift. 255,255,255,0, 1,4,2,15,255,255,255,255,255,255,4 }, + // location 32 { "DREAMWEB.R10", // entering alley via skip 10,255,22,30, 255,255,255,0, 3,6,255,255,255,255,255,255,255,255,10 }, + // location 33 { "DREAMWEB.R12", // on the beach, getting up. 12,255,22,20, 255,255,255,0, 0,2,255,255,255,255,255,255,255,255,12 }, + // location 34 { "DREAMWEB.R03", // Duplicate of Eden's lobby 5,255,44,0, // but emerging from the lift 255,255,255,0, 1,6,2,255,4,255,255,255,255,255,3 }, + // location 35: Location when starting the game, after dream (?) { "DREAMWEB.R24", // Duplicate of Eden's flat 5,255,22,0, // but starting on the bed 255,255,255,0, 3,6,0,255,255,255,255,33,0,3,24 }, // 33,0,3 turns off path for lift + // location 36 { "DREAMWEB.R22", // Duplicate 22,255,22,20, // of hotel but in pool room 255,255,255,0, 1,4,255,255,255,255,255,255,255,255,22 }, + // location 37 { "DREAMWEB.R22", // Duplicate 22,255,22,20, // of hotel but in pool room 255,255,255,0, // coming out of bedroom 0,2,255,255,255,255,255,255,255,255,22 }, + // location 38 { "DREAMWEB.R11", // Duplicate 11,255,22,30, // of carpark but getting 255,255,255,0, // up off the floor 0,0,255,255,255,255,255,255,255,255,11 }, + // location 39 { "DREAMWEB.R28", 5,255,11,20, 255,255,255,0, 0,6,255,255,2,255,255,255,255,255,28 }, + // location 40 { "DREAMWEB.R21", 5,255,11,10, // if demo: 22,255,11,10 255,255,255,0, 1,4,2,15,1,255,255,255,255,255,21 }, + // location 41 { "DREAMWEB.R26", 9,255,0,40, 255,255,255,0, 0,0,255,255,255,255,255,255,255,255,26 }, + // location 42 { "DREAMWEB.R19", 19,255,0,0, 255,255,255,0, 2,2,255,255,255,255,255,255,255,255,19 }, + // location 43 { "DREAMWEB.R08", // leaving tvstudio into street 8,255,11,40, 255,255,255,0, 0,4,255,255,255,255,255,255,255,255,8 }, + // location 44 { "DREAMWEB.R01", 1,255,44,10, 255,255,255,0, 3,6,255,255,255,255,255,255,255,255,1 }, + // location 45 { "DREAMWEB.R45", // Dream room 35,255,22,30, 255,255,255,0, 0,6,255,255,255,255,255,255,255,255,45 }, + // location 46 { "DREAMWEB.R46", // Dream room 35,255,22,40, 255,255,255,0, 0,4,255,255,255,255,255,255,255,255,46 }, + // location 47 { "DREAMWEB.R47", // Dream room 35,255,0,0, 255,255,255,0, 0,0,255,255,255,255,255,255,255,255,47 }, + // location 48 { "DREAMWEB.R45", // Dream room 35,255,22,30, 255,255,255,0, 4,0,255,255,255,255,255,255,255,255,45 }, + // location 49 { "DREAMWEB.R46", // Dream room 35,255,22,50, 255,255,255,0, 0,4,255,255,255,255,255,255,255,255,46 }, - + // location 50 { "DREAMWEB.R50", // Intro sequence one 35,255,22,30, 255,255,255,0, @@ -329,23 +373,23 @@ static const Atmosphere g_atmosphereList[] = { { 10,33,30,6,255 }, { 10,22,30,6,255 }, - + { 9,22,10,6,255 }, { 9,22,20,16,255 }, { 9,22,30,16,255 }, { 9,22,40,16,255 }, { 9,22,50,16,255 }, - + { 6,11,30,6,255 }, { 6,0,10,15,255 }, { 6,0,20,15,255 }, { 6,11,20,15,255 }, { 6,22,20,15,255 }, - + { 7,11,20,6,255 }, { 7,0,20,6,255 }, { 7,0,30,6,255 }, - + { 55,44,0,5,255 }, { 55,44,10,5,255 }, @@ -367,12 +411,12 @@ static const Atmosphere g_atmosphereList[] = { { 8,33,40,6,255 }, { 8,22,40,6,255 }, { 8,11,40,6,255 }, - + { 11,11,20,12,255 }, { 11,11,30,12,255 }, { 11,22,20,12,255 }, { 11,22,30,12,255 }, - + { 12,22,20,12,255 }, { 13,22,20,12,255 }, { 13,33,20,12,255 }, @@ -384,7 +428,7 @@ static const Atmosphere g_atmosphereList[] = { { 14,33,30,12,255 }, { 14,33,40,12,255 }, { 14,22,0,16,255 }, - + { 19,0,0,12,255 }, { 20,0,20,16,255 }, @@ -457,27 +501,74 @@ static const Atmosphere g_atmosphereList[] = { }; -void DreamGenContext::dreamweb() { - STACK_CHECK; +void DreamWebEngine::dreamwebFinalize() { + // The engine will need some cleaner finalization (destructor?), let's put + // it here for now + + getRidOfAll(); - switch(engine->getLanguage()) { + _icons1.clear(); + _icons2.clear(); + _charset1.clear(); + _mainSprites.clear(); + + // clear local graphics, just in case + _keypadGraphics.clear(); + _menuGraphics.clear(); + _menuGraphics2.clear(); + _folderGraphics.clear(); + _folderGraphics2.clear(); + _folderGraphics3.clear(); + _folderCharset.clear(); + _symbolGraphics.clear(); + _diaryGraphics.clear(); + _diaryCharset.clear(); + _monitorGraphics.clear(); + _monitorCharset.clear(); + _newplaceGraphics.clear(); + _newplaceGraphics2.clear(); + _newplaceGraphics3.clear(); + _cityGraphics.clear(); + _saveGraphics.clear(); + + _exFrames.clear(); + _exText.clear(); + + _setFrames.clear(); + _freeFrames.clear(); + _reel1.clear(); + _reel2.clear(); + _reel3.clear(); + _setDesc.clear(); + _blockDesc.clear(); + _roomDesc.clear(); + _freeDesc.clear(); + _personText.clear(); + + _textFile1.clear(); + _textFile2.clear(); + _textFile3.clear(); + _travelText.clear(); + _puzzleText.clear(); + _commandText.clear(); +} + +void DreamWebEngine::dreamweb() { + switch(getLanguage()) { case Common::EN_ANY: case Common::EN_GRB: case Common::EN_USA: - // Implicit data.byte(kForeignrelease) = 0 + _foreignRelease = false; break; default: - data.byte(kForeignrelease) = 1; + _foreignRelease = true; break; } - seeCommandTail(); - // soundStartup used to be done here... - // setKeyboardInt used to be done here... allocateBuffers(); // setMouse - data.word(kOldpointerx) = 0xffff; + _oldPointerX = 0xffff; fadeDOS(); getTime(); @@ -485,22 +576,20 @@ void DreamGenContext::dreamweb() { clearPalette(); set16ColPalette(); readSetData(); - data.byte(kWongame) = 0; + _wonGame = false; - engine->loadSounds(0, "DREAMWEB.V99"); // basic sample + loadSounds(0, "V99"); // basic sample bool firstLoop = true; int savegameId = Common::ConfigManager::instance().getInt("save_slot"); while (true) { - - unsigned int count = scanForNames(); + uint count = scanForNames(); bool startNewGame = true; if (firstLoop && savegameId >= 0) { - // loading a savegame requested from launcher/command line cls(); @@ -509,7 +598,7 @@ void DreamGenContext::dreamweb() { clearPalette(); doLoad(savegameId); - workToScreenCPP(); + workToScreen(); fadeScreenUp(); startNewGame = false; @@ -530,12 +619,11 @@ void DreamGenContext::dreamweb() { cls(); setMode(); decide(); - if (quitRequested()) - goto done; + if (_quitRequested) + return; - if (data.byte(kGetback) == 4) + if (_getBack == 4) startNewGame = false; // savegame has been loaded - } firstLoop = false; @@ -544,79 +632,77 @@ void DreamGenContext::dreamweb() { // "playGame" // "titles" + // TODO: In the demo version, titles() did nothing clearPalette(); bibleQuote(); - if (!quitRequested()) // "titlesearly" + if (!_quitRequested) // "titlesearly" intro(); - if (quitRequested()) - goto done; + if (_quitRequested) + return; // "credits" clearPalette(); realCredits(); - if (quitRequested()) - goto done; + if (_quitRequested) + return; clearChanges(); setMode(); loadPalFromIFF(); - data.byte(kLocation) = 255; - data.byte(kRoomafterdream) = 1; - data.byte(kNewlocation) = 35; - data.byte(kVolume) = 7; + _vars._location = 255; + _vars._roomAfterDream = 1; + _newLocation = 35; + _volume = 7; loadRoom(); clearSprites(); initMan(); entryTexts(); entryAnims(); - data.byte(kDestpos) = 3; + _destPos = 3; initialInv(); - data.byte(kLastflag) = 32; + _lastFlag = 32; startup1(); - data.byte(kVolumeto) = 0; - data.byte(kVolumedirection) = (uint8)-1; - data.byte(kCommandtype) = 255; - + _volumeTo = 0; + _volumeDirection = -1; + _commandType = 255; } // main loop while (true) { - - if (quitRequested()) - goto done; + if (_quitRequested) + return; screenUpdate(); - if (quitRequested()) - goto done; + if (_quitRequested) + return; - if (data.byte(kWongame) != 0) { + if (_wonGame) { // "endofgame" clearBeforeLoad(); fadeScreenDowns(); hangOn(200); endGame(); - quickQuit2(); - goto done; + return; } - if (data.byte(kMandead) == 1 || data.byte(kMandead) == 2) + if (_vars._manDead == 1 || _vars._manDead == 2) break; - if (data.word(kWatchingtime) > 0) { - if (data.byte(kFinaldest) == data.byte(kManspath)) - data.word(kWatchingtime)--; + if (_vars._watchingTime > 0) { + if (_finalDest == _mansPath) + _vars._watchingTime--; } - if (data.word(kWatchingtime) == 0) { + if (_vars._watchingTime == 0) { // "notWatching" - if (data.byte(kMandead) == 4) + if (_vars._manDead == 4) break; - if (data.byte(kNewlocation) != 255) { + if (_newLocation != 255) { // "loadNew" clearBeforeLoad(); loadRoom(); @@ -624,9 +710,9 @@ void DreamGenContext::dreamweb() { initMan(); entryTexts(); entryAnims(); - data.byte(kNewlocation) = 255; + _newLocation = 255; startup(); - data.byte(kCommandtype) = 255; + _commandType = 255; workToScreenM(); } } @@ -639,27 +725,34 @@ void DreamGenContext::dreamweb() { hangOn(100); } -done: // The engine will need some cleaner finalization, let's put it here for now - // FIXME: This triggers "Deallocating non existent segment" errors when - // quitting from a menu. - getRidOfAll(); - engine->freeIcons1(); - engine->freeIcons2(); } -bool DreamBase::quitRequested() { - return data.byte(kQuitrequested); +void DreamWebEngine::loadTextFile(TextFile &file, const char *suffix) { + Common::String fileName = getDatafilePrefix() + suffix; + FileHeader header; + + Common::File f; + f.open(fileName); + f.read((uint8 *)&header, sizeof(FileHeader)); + uint16 sizeInBytes = header.len(0); + assert(sizeInBytes >= 2*66); + + delete[] file._text; + file._text = new char[sizeInBytes - 2*66]; + + f.read(file._offsetsLE, 2*66); + f.read(file._text, sizeInBytes - 2*66); } -void DreamGenContext::screenUpdate() { +void DreamWebEngine::screenUpdate() { newPlace(); mainScreen(); - if (quitRequested()) + if (_quitRequested) return; animPointer(); showPointer(); - if ((data.word(kWatchingtime) == 0) && (data.byte(kNewlocation) != 0xff)) + if ((_vars._watchingTime == 0) && (_newLocation != 0xff)) return; vSync(); uint16 mouseState = 0; @@ -674,7 +767,7 @@ void DreamGenContext::screenUpdate() { zoom(); showPointer(); - if (data.byte(kWongame)) + if (_wonGame) return; vSync(); mouseState |= readMouseState(); @@ -698,20 +791,20 @@ void DreamGenContext::screenUpdate() { showPointer(); vSync(); - data.word(kOldbutton) = data.word(kMousebutton); + _oldButton = _mouseButton; mouseState |= readMouseState(); - data.word(kMousebutton) = mouseState; + _mouseButton = mouseState; dumpPointer(); dumpWatch(); delPointer(); } -void DreamGenContext::startup() { - data.byte(kCurrentkey) = 0; - data.byte(kMainmode) = 0; +void DreamWebEngine::startup() { + _currentKey = 0; + _mainMode = 0; createPanel(); - data.byte(kNewobs) = 1; + _vars._newObs = 1; drawFloor(); showIcon(); getUnderZoom(); @@ -722,78 +815,60 @@ void DreamGenContext::startup() { atmospheres(); } -void DreamGenContext::startup1() { +void DreamWebEngine::startup1() { clearPalette(); - data.byte(kThroughdoor) = 0; + _vars._throughDoor = 0; startup(); - workToScreenCPP(); + workToScreen(); fadeScreenUp(); } -void DreamGenContext::switchRyanOn() { - data.byte(kRyanon) = 255; -} - -void DreamGenContext::switchRyanOff() { - data.byte(kRyanon) = 1; +void DreamWebEngine::switchRyanOn() { + _vars._ryanOn = 255; } -uint8 *DreamBase::textUnder() { - return getSegment(data.word(kBuffers)).ptr(kTextunder, 0); +void DreamWebEngine::switchRyanOff() { + _vars._ryanOn = 1; } -uint16 DreamGenContext::standardLoad(const char *fileName, uint16 *outSizeInBytes) { +void DreamWebEngine::loadGraphicsFile(GraphicsFile &file, const char *suffix) { + Common::String fileName = getDatafilePrefix() + suffix; FileHeader header; - Common::File file; - file.open(fileName); - file.read((uint8 *)&header, sizeof(FileHeader)); + Common::File f; + f.open(fileName); + f.read((uint8 *)&header, sizeof(FileHeader)); uint16 sizeInBytes = header.len(0); - if (outSizeInBytes) - *outSizeInBytes = sizeInBytes; - uint16 result = allocateMem((sizeInBytes + 15) / 16); - file.read(getSegment(result).ptr(0, 0), sizeInBytes); - return result; -} - -void *DreamGenContext::standardLoadCPP(const char *fileName, uint16 *outSizeInBytes) { - uint16 sizeInBytes; - uint16 seg = standardLoad(fileName, &sizeInBytes); - void *buffer = malloc(sizeInBytes); - memcpy(buffer, getSegment(seg).ptr(0, 0), sizeInBytes); - deallocateMem(seg); - if (outSizeInBytes) - *outSizeInBytes = sizeInBytes; - return buffer; -} - -void DreamGenContext::loadIntoTemp() { - loadIntoTemp((const char *)data.ptr(dx, 0)); -} - -void DreamGenContext::loadIntoTemp(const char *fileName) { - data.word(kTempgraphics) = standardLoad(fileName); -} -void DreamGenContext::loadIntoTemp2(const char *fileName) { - data.word(kTempgraphics2) = standardLoad(fileName); + assert(sizeInBytes >= kFrameBlocksize); + file.clear(); + file._data = new uint8[sizeInBytes - kFrameBlocksize]; + file._frames = new Frame[kGraphicsFileFrameSize]; + f.read((uint8 *)file._frames, kFrameBlocksize); + f.read(file._data, sizeInBytes - kFrameBlocksize); } -void DreamGenContext::loadIntoTemp3(const char *fileName) { - data.word(kTempgraphics3) = standardLoad(fileName); +void DreamWebEngine::loadGraphicsSegment(GraphicsFile &file, Common::File &inFile, unsigned int len) { + assert(len >= kFrameBlocksize); + file.clear(); + file._data = new uint8[len - kFrameBlocksize]; + file._frames = new Frame[kGraphicsFileFrameSize]; + inFile.read((uint8 *)file._frames, kFrameBlocksize); + inFile.read(file._data, len - kFrameBlocksize); } -void DreamGenContext::loadTempCharset() { - loadTempCharset((const char *)data.ptr(dx, 0)); +void DreamWebEngine::loadTextSegment(TextFile &file, Common::File &inFile, unsigned int len) { + const uint headerSize = 2 * file._size; + assert(len >= headerSize); + delete[] file._text; + file._text = new char[len - headerSize]; + inFile.read((uint8 *)file._offsetsLE, headerSize); + inFile.read((uint8 *)file._text, len - headerSize); } -void DreamGenContext::loadTempCharset(const char *fileName) { - engine->setTempCharset(standardLoadCPP(fileName)); -} - -void DreamGenContext::hangOnCurs(uint16 frameCount) { +void DreamWebEngine::hangOnCurs(uint16 frameCount) { for (uint16 i = 0; i < frameCount; ++i) { printCurs(); vSync(); @@ -801,283 +876,239 @@ void DreamGenContext::hangOnCurs(uint16 frameCount) { } } -void DreamGenContext::seeCommandTail() { - data.byte(kBrightness) = 1; -} - -void DreamGenContext::randomNumber() { - al = engine->randomNumber(); -} - -void DreamGenContext::quickQuit() { - engine->quit(); -} - -void DreamGenContext::quickQuit2() { - engine->quit(); -} - -void DreamBase::readMouse() { - data.word(kOldbutton) = data.word(kMousebutton); +void DreamWebEngine::readMouse() { + _oldButton = _mouseButton; uint16 state = readMouseState(); - data.word(kMousebutton) = state; + _mouseButton = state; } -uint16 DreamBase::readMouseState() { - data.word(kOldx) = data.word(kMousex); - data.word(kOldy) = data.word(kMousey); +uint16 DreamWebEngine::readMouseState() { + _oldX = _mouseX; + _oldY = _mouseY; uint16 x, y, state; - engine->mouseCall(&x, &y, &state); - data.word(kMousex) = x; - data.word(kMousey) = y; + mouseCall(&x, &y, &state); + _mouseX = x; + _mouseY = y; return state; } -void DreamGenContext::dumpTextLine() { - if (data.byte(kNewtextline) != 1) +void DreamWebEngine::dumpTextLine() { + if (_newTextLine != 1) return; - data.byte(kNewtextline) = 0; - uint16 x = data.word(kTextaddressx); - uint16 y = data.word(kTextaddressy); - if (data.byte(kForeignrelease) != 0) + _newTextLine = 0; + uint16 x = _textAddressX; + uint16 y = _textAddressY; + if (_foreignRelease) y -= 3; multiDump(x, y, 228, 13); } -void DreamGenContext::getUnderTimed() { - uint16 y = data.byte(kTimedy); - if (data.byte(kForeignrelease)) - y -= 3; - ds = data.word(kBuffers); - si = kUndertimedtext; - multiGet(ds.ptr(si, 0), data.byte(kTimedx), y, 240, kUndertimedysize); +void DreamWebEngine::getUnderTimed() { + if (_foreignRelease) + multiGet(_underTimedText, _timedTemp._x, _timedTemp._y - 3, 240, kUnderTimedTextSizeY_f); + else + multiGet(_underTimedText, _timedTemp._x, _timedTemp._y, 240, kUnderTimedTextSizeY); } -void DreamGenContext::putUnderTimed() { - uint16 y = data.byte(kTimedy); - if (data.byte(kForeignrelease)) - y -= 3; - ds = data.word(kBuffers); - si = kUndertimedtext; - multiPut(ds.ptr(si, 0), data.byte(kTimedx), y, 240, kUndertimedysize); +void DreamWebEngine::putUnderTimed() { + if (_foreignRelease) + multiPut(_underTimedText, _timedTemp._x, _timedTemp._y - 3, 240, kUnderTimedTextSizeY_f); + else + multiPut(_underTimedText, _timedTemp._x, _timedTemp._y, 240, kUnderTimedTextSizeY); +} + +void DreamWebEngine::triggerMessage(uint16 index) { + multiGet(_mapStore, 174, 153, 200, 63); + const uint8 *string = (const uint8 *)_puzzleText.getString(index); + uint16 y = 156; + printDirect(&string, 174, &y, 141, true); + hangOn(140); + workToScreen(); + hangOn(340); + multiPut(_mapStore, 174, 153, 200, 63); + workToScreen(); + _vars._lastTrigger = 0; +} + +void DreamWebEngine::processTrigger() { + if (_vars._lastTrigger == '1') { + setLocation(8); + triggerMessage(45); + } else if (_vars._lastTrigger == '2') { + setLocation(9); + triggerMessage(55); + } else if (_vars._lastTrigger == '3') { + setLocation(2); + triggerMessage(59); + } } -void DreamGenContext::useTimedText() { - if (data.word(kTimecount) == 0) +void DreamWebEngine::useTimedText() { + if (_previousTimedTemp._string) { + // TODO: It might be nice to make subtitles wait for the speech + // to finish (_channel1Playing) when we're in speech+subtitles mode, + // instead of waiting the pre-specified amount of time. + + + // Ugly... (Maybe make this an argument to putUnderTimed()?) + TimedTemp t = _timedTemp; + _timedTemp = _previousTimedTemp; + + // Force-reset the previous string to make room for the next one + putUnderTimed(); + + _timedTemp = t; return; - --data.word(kTimecount); - if (data.word(kTimecount) == 0) { + } + + if (_timeCount == 0) + return; + --_timeCount; + if (_timeCount == 0) { putUnderTimed(); - data.byte(kNeedtodumptimed) = 1; + _needToDumpTimed = 1; return; } - if (data.word(kTimecount) == data.word(kCounttotimed)) + if (_timeCount == _timedTemp._countToTimed) getUnderTimed(); - else if (data.word(kTimecount) > data.word(kCounttotimed)) + else if (_timeCount > _timedTemp._countToTimed) return; - es = data.word(kTimedseg); - si = data.word(kTimedoffset); - const uint8 *string = es.ptr(si, 0); - uint16 y = data.byte(kTimedy); - printDirect(&string, data.byte(kTimedx), &y, 237, true); - data.byte(kNeedtodumptimed) = 1; + const uint8 *string = (const uint8 *)_timedTemp._string; + printDirect(string, _timedTemp._x, _timedTemp._y, 237, true); + _needToDumpTimed = 1; } -void DreamGenContext::setupTimedTemp(uint8 textIndex, uint8 voiceIndex, uint8 x, uint8 y, uint16 countToTimed, uint16 timeCount) { -#if 1 // if cd - if (voiceIndex != 0) { +void DreamWebEngine::setupTimedTemp(uint8 textIndex, uint8 voiceIndex, uint8 x, uint8 y, uint16 countToTimed, uint16 timeCount) { + + if (hasSpeech() && voiceIndex != 0) { if (loadSpeech('T', voiceIndex, 'T', textIndex)) { playChannel1(50+12); } - // FIXME: This fallthrough does not properly support subtitles+speech - // mode. The parameters to setuptimedtemp() are sometimes different - // for speech and for subtitles. See e.g., madmantext() - if ((data.byte(kSpeechloaded) == 1) && (data.byte(kSubtitles) != 1)) + if (_speechLoaded && !_subtitles) return; + + if (_timeCount != 0) { + // store previous TimedTemp for deletion + _previousTimedTemp = _timedTemp; + _timeCount = 0; + } } -#endif - if (data.word(kTimecount) != 0) + if (_timeCount != 0) return; - data.byte(kTimedy) = y; - data.byte(kTimedx) = x; - data.word(kCounttotimed) = countToTimed; - data.word(kTimecount) = timeCount + countToTimed; - data.word(kTimedseg) = data.word(kTextfile1); - data.word(kTimedoffset) = kTextstart + getSegment(data.word(kTextfile1)).word(textIndex * 2); - const uint8 *string = getSegment(data.word(kTextfile1)).ptr(data.word(kTimedoffset), 0); - debug(1, "setupTimedTemp: (%d, %d) => '%s'", textIndex, voiceIndex, string); -} - -void DreamGenContext::dumpTimedText() { - if (data.byte(kNeedtodumptimed) != 1) + + _timedTemp._y = y; + _timedTemp._x = x; + _timedTemp._countToTimed = countToTimed; + _timeCount = _timedTemp._timeCount = timeCount + countToTimed; + _timedTemp._string = _textFile1.getString(textIndex); + debug(1, "setupTimedTemp: (%d, %d) => '%s'", textIndex, voiceIndex, _timedTemp._string); +} + +void DreamWebEngine::dumpTimedText() { + const TimedTemp *tt; + if (_previousTimedTemp._string) { + assert(!_needToDumpTimed); + + tt = &_previousTimedTemp; + _previousTimedTemp._string = 0; + _previousTimedTemp._timeCount = 0; + } else if (_needToDumpTimed != 1) { return; - uint8 y = data.byte(kTimedy); - if (data.byte(kForeignrelease) != 0) + } else { + tt = &_timedTemp; + _needToDumpTimed = 0; + } + + const uint16 kUndertimedysize = 30; + uint8 y = tt->_y; + if (_foreignRelease) y -= 3; - multiDump(data.byte(kTimedx), y, 240, kUndertimedysize); - data.byte(kNeedtodumptimed) = 0; + multiDump(tt->_x, y, 240, kUndertimedysize); } -void DreamGenContext::getTime() { +void DreamWebEngine::getTime() { TimeDate t; g_system->getTimeAndDate(t); debug(1, "\tgettime: %02d:%02d:%02d", t.tm_hour, t.tm_min, t.tm_sec); - ch = t.tm_hour; - cl = t.tm_min; - dh = t.tm_sec; - data.byte(kSecondcount) = dh; - data.byte(kMinutecount) = cl; - data.byte(kHourcount) = ch; -} - -uint16 DreamGenContext::allocateMem(uint16 paragraphs) { - uint size = (paragraphs + 2) * 16; - debug(1, "allocate mem, %u bytes", size); - flags._c = false; - SegmentRef seg = allocateSegment(size); - uint16 result = (uint16)seg; - debug(1, "\tsegment address -> %04x", result); - return result; -} - -void DreamGenContext::deallocateMem(uint16 segment) { - debug(1, "deallocating segment %04x", segment); - deallocateSegment(segment); - - //fixing invalid entries in the sprite table - es = data; - uint tsize = 16 * 32; - uint16 bseg = data.word(kBuffers); - if (!bseg) - return; - MutableSegmentRef buffers(this); - buffers = bseg; - uint8 *ptr = buffers.ptr(kSpritetable, tsize); - for (uint i = 0; i < tsize; i += 32) { - uint16 seg = READ_LE_UINT16(ptr + i + 6); - //debug(1, "sprite segment = %04x", seg); - if (seg == segment) - memset(ptr + i, 0xff, 32); - } + _vars._secondCount = t.tm_sec; + _vars._minuteCount = t.tm_min; + _vars._hourCount = t.tm_hour; } -void DreamGenContext::DOSReturn() { - if (data.byte(kCommandtype) != 250) { - data.byte(kCommandtype) = 250; - commandOnly(46); - } +void DreamWebEngine::DOSReturn() { + commandOnlyCond(46, 250); - if (data.word(kMousebutton) & 1) { - data.word(kMousebutton) = 0; - engine->quit(); + if (_mouseButton & 1) { + _mouseButton = 0; + quit(); } } -void DreamGenContext::set16ColPalette() { -} - -void DreamGenContext::eraseOldObs() { - if (data.byte(kNewobs) == 0) +void DreamWebEngine::eraseOldObs() { + if (_vars._newObs == 0) return; - Sprite *sprites = spriteTable(); - for (size_t i = 0; i < 16; ++i) { - Sprite &sprite = sprites[i]; - if (sprite.objData() != 0xffff) { - memset(&sprite, 0xff, sizeof(Sprite)); - } + // Note: the original didn't delete sprites here, but marked the + // entries as unused, to be filled again by makeSprite. This can + // change the order of entries, but since they are drawn based on the + // priority field, this shouldn't matter. + Common::List<Sprite>::iterator i; + for (i = _spriteTable.begin(); i != _spriteTable.end(); ) { + Sprite &sprite = *i; + if (sprite._objData) + i = _spriteTable.erase(i); + else + ++i; } } -void DreamBase::lockMon() { +void DreamWebEngine::lockMon() { // Pressing space pauses text output in the monitor. We use the "hard" // key because calling readkey() drains characters from the input // buffer, we we want the user to be able to type ahead while the text // is being printed. - if (data.byte(kLasthardkey) == 57) { + if (_lastHardKey == 57) { // Clear the keyboard buffer. Otherwise the space that caused // the pause will be read immediately unpause the game. do { readKey(); - } while (data.byte(kCurrentkey) != 0); + } while (_currentKey != 0); lockLightOn(); - while (!engine->shouldQuit()) { - engine->waitForVSync(); + while (!shouldQuit()) { + waitForVSync(); readKey(); - if (data.byte(kCurrentkey) == ' ') + if (_currentKey == ' ') break; } // Forget the last "hard" key, otherwise the space that caused // the unpausing will immediately re-pause the game. - data.byte(kLasthardkey) = 0; + _lastHardKey = 0; lockLightOff(); } } -void DreamGenContext::makeBackOb(SetObject *objData) { - if (data.byte(kNewobs) == 0) - return; - uint8 priority = objData->priority; - uint8 type = objData->type; - Sprite *sprite = makeSprite(data.word(kObjectx), data.word(kObjecty), addr_backobject, data.word(kSetframes), 0); - - uint16 objDataOffset = (uint8 *)objData - getSegment(data.word(kSetdat)).ptr(0, 0); - assert(objDataOffset % sizeof(SetObject) == 0); - assert(objDataOffset < 128 * sizeof(SetObject)); - sprite->setObjData(objDataOffset); - if (priority == 255) - priority = 0; - sprite->priority = priority; - sprite->type = type; - sprite->b16 = 0; - sprite->delay = 0; - sprite->animFrame = 0; -} - -uint16 DreamGenContext::allocateAndLoad(unsigned int size) { - // allocatemem adds 32 bytes, so it doesn't matter that size/16 rounds down - uint16 result = allocateMem(size / 16); - engine->readFromFile(getSegment(result).ptr(0, size), size); - return result; -} - -void DreamGenContext::clearAndLoad(uint8 *buf, uint8 c, - unsigned int size, unsigned int maxSize) { - assert(size <= maxSize); - memset(buf, c, maxSize); - engine->readFromFile(buf, size); -} - -void DreamGenContext::clearAndLoad(uint16 seg, uint8 c, - unsigned int size, unsigned int maxSize) { - assert(size <= maxSize); - uint8 *buf = getSegment(seg).ptr(0, maxSize); - clearAndLoad(buf, c, size, maxSize); -} - -void DreamGenContext::startLoading(const Room &room) { - data.byte(kCombatcount) = 0; - data.byte(kRoomssample) = room.roomsSample; - data.byte(kMapx) = room.mapX; - data.byte(kMapy) = room.mapY; - data.byte(kLiftflag) = room.liftFlag; - data.byte(kManspath) = room.b21; - data.byte(kDestination) = room.b21; - data.byte(kFinaldest) = room.b21; - data.byte(kFacing) = room.facing; - data.byte(kTurntoface) = room.facing; - data.byte(kCounttoopen) = room.countToOpen; - data.byte(kLiftpath) = room.liftPath; - data.byte(kDoorpath) = room.doorPath; - data.byte(kLastweapon) = (uint8)-1; - ah = data.byte(kReallocation); - data.byte(kReallocation) = room.realLocation; +void DreamWebEngine::startLoading(const Room &room) { + _vars._combatCount = 0; + _roomsSample = room.roomsSample; + _mapX = room.mapX; + _mapY = room.mapY; + _vars._liftFlag = room.liftFlag; + _mansPath = room.b21; + _destination = room.b21; + _finalDest = room.b21; + _facing = room.facing; + _turnToFace = room.facing; + _vars._countToOpen = room.countToOpen; + _vars._liftPath = room.liftPath; + _vars._doorPath = room.doorPath; + _vars._lastWeapon = (uint8)-1; + _realLocation = room.realLocation; loadRoomData(room, false); @@ -1085,53 +1116,47 @@ void DreamGenContext::startLoading(const Room &room) { deleteTaken(); setAllChanges(); autoAppear(); -// const Room &newRoom = g_roomData[data.byte(kNewlocation)]; - bx = 0x7fff; // TODO: bx used to be set to the offset of newRoom - // It seems to be unused (like newRoom itself), but set it - // to an invalid value to catch any missed use of it. - // (The push/pop of bx below is likely also unnecessary) - data.byte(kLastweapon) = (uint8)-1; - data.byte(kMandead) = 0; - data.word(kLookcounter) = 160; - data.byte(kNewlocation) = 255; - data.byte(kLinepointer) = 254; +// const Room &newRoom = g_roomData[_newLocation]; + _vars._lastWeapon = (uint8)-1; + _vars._manDead = 0; + _lookCounter = 160; + _newLocation = 255; + _linePointer = 254; if (room.b27 != 255) { - data.byte(kManspath) = room.b27; - push(bx); + _mansPath = room.b27; autoSetWalk(); - bx = pop(); } findXYFromPath(); } -void DreamGenContext::dealWithSpecial(uint8 firstParam, uint8 secondParam) { +void DreamWebEngine::dealWithSpecial(uint8 firstParam, uint8 secondParam) { uint8 type = firstParam - 220; if (type == 0) { placeSetObject(secondParam); - data.byte(kHavedoneobs) = 1; + _haveDoneObs = 1; } else if (type == 1) { removeSetObject(secondParam); - data.byte(kHavedoneobs) = 1; + _haveDoneObs = 1; } else if (type == 2) { placeFreeObject(secondParam); - data.byte(kHavedoneobs) = 1; + _haveDoneObs = 1; } else if (type == 3) { removeFreeObject(secondParam); - data.byte(kHavedoneobs) = 1; + _haveDoneObs = 1; } else if (type == 4) { switchRyanOff(); } else if (type == 5) { - data.byte(kTurntoface) = secondParam; - data.byte(kFacing) = secondParam; + _turnToFace = secondParam; + _facing = secondParam; switchRyanOn(); } else if (type == 6) { - data.byte(kNewlocation) = secondParam; + _newLocation = secondParam; } else { moveMap(secondParam); } } -void DreamGenContext::plotReel(uint16 &reelPointer) { +void DreamWebEngine::plotReel(uint16 &reelPointer) { Reel *reel = getReelStart(reelPointer); while (reel->x >= 220 && reel->x != 255) { dealWithSpecial(reel->x, reel->y); @@ -1147,49 +1172,32 @@ void DreamGenContext::plotReel(uint16 &reelPointer) { soundOnReels(reelPointer); } -void DreamBase::crosshair() { - uint8 frame; - if ((data.byte(kCommandtype) != 3) && (data.byte(kCommandtype) < 10)) { - frame = 9; - } else { - frame = 29; - } - showFrame(engine->icons1(), kZoomx + 24, kZoomy + 19, frame, 0); -} - -void DreamGenContext::delTextLine() { - uint16 x = data.word(kTextaddressx); - uint16 y = data.word(kTextaddressy); - if (data.byte(kForeignrelease) != 0) - y -= 3; - multiPut(textUnder(), x, y, kUndertextsizex, kUndertextsizey); +void DreamWebEngine::delTextLine() { + if (_foreignRelease) + multiPut(_textUnder, _textAddressX, _textAddressY - 3, kUnderTextSizeX_f, kUnderTextSizeY_f); + else + multiPut(_textUnder, _textAddressX, _textAddressY, kUnderTextSizeX, kUnderTextSizeY); } -void DreamGenContext::commandOnly() { - commandOnly(al); +void DreamWebEngine::commandOnlyCond(uint8 command, uint8 commandType) { + if (_commandType != commandType) { + _commandType = commandType; + commandOnly(command); + } } -void DreamGenContext::commandOnly(uint8 command) { +void DreamWebEngine::commandOnly(uint8 command) { delTextLine(); - uint16 index = command * 2; - uint16 offset = kTextstart + getSegment(data.word(kCommandtext)).word(index); - uint16 y = data.word(kTextaddressy); - const uint8 *string = getSegment(data.word(kCommandtext)).ptr(offset, 0); - printDirect(&string, data.word(kTextaddressx), &y, data.byte(kTextlen), (bool)(data.byte(kTextlen) & 1)); - data.byte(kNewtextline) = 1; -} - -void DreamGenContext::checkIfPerson() { - flags._z = !checkIfPerson(al, ah); + const uint8 *string = (const uint8 *)_commandText.getString(command); + printDirect(string, _textAddressX, _textAddressY, _textLen, (bool)(_textLen & 1)); + _newTextLine = 1; } -bool DreamGenContext::checkIfPerson(uint8 x, uint8 y) { - People *people = (People *)getSegment(data.word(kBuffers)).ptr(kPeoplelist, 0); - - for (size_t i = 0; i < 12; ++i, ++people) { - if (people->b4 == 255) - continue; - Reel *reel = getReelStart(people->reelPointer()); +bool DreamWebEngine::checkIfPerson(uint8 x, uint8 y) { + Common::List<People>::iterator i; + for (i = _peopleList.begin(); i != _peopleList.end(); ++i) { + People &people = *i; + Reel *reel = getReelStart(people._reelPointer); if (reel->frame() == 0xffff) ++reel; const Frame *frame = getReelFrameAX(reel->frame()); @@ -1205,73 +1213,58 @@ bool DreamGenContext::checkIfPerson(uint8 x, uint8 y) { continue; if (y >= ymax) continue; - data.word(kPersondata) = people->routinePointer(); - obName(people->b4, 5); + _personData = people._routinePointer; + obName(people.b4, 5); return true; } return false; } -void DreamGenContext::checkIfFree() { - flags._z = !checkIfFree(al, ah); -} - -bool DreamGenContext::checkIfFree(uint8 x, uint8 y) { - const ObjPos *freeList = (const ObjPos *)getSegment(data.word(kBuffers)).ptr(kFreelist, 80 * sizeof(ObjPos)); - for (size_t i = 0; i < 80; ++i) { - const ObjPos *objPos = freeList + 79 - i; - if (objPos->index == 0xff || !objPos->contains(x,y)) +bool DreamWebEngine::checkIfFree(uint8 x, uint8 y) { + Common::List<ObjPos>::const_iterator i; + for (i = _freeList.reverse_begin(); i != _freeList.end(); --i) { + const ObjPos &pos = *i; + assert(pos.index != 0xff); + if (!pos.contains(x,y)) continue; - obName(objPos->index, 2); + obName(pos.index, 2); return true; } return false; } -void DreamGenContext::checkIfEx() { - flags._z = !checkIfEx(al, ah); -} - -bool DreamGenContext::checkIfEx(uint8 x, uint8 y) { - const ObjPos *exList = (const ObjPos *)getSegment(data.word(kBuffers)).ptr(kExlist, 100 * sizeof(ObjPos)); - for (size_t i = 0; i < 100; ++i) { - const ObjPos *objPos = exList + 99 - i; - if (objPos->index == 0xff || !objPos->contains(x,y)) +bool DreamWebEngine::checkIfEx(uint8 x, uint8 y) { + Common::List<ObjPos>::const_iterator i; + for (i = _exList.reverse_begin(); i != _exList.end(); --i) { + const ObjPos &pos = *i; + assert(pos.index != 0xff); + if (!pos.contains(x,y)) continue; - obName(objPos->index, 4); + obName(pos.index, 4); return true; } return false; } -const uint8 *DreamGenContext::findObName(uint8 type, uint8 index) { - if (type == 5) { - uint16 i = 64 * 2 * (index & 127); - uint16 offset = getSegment(data.word(kPeople)).word(kPersontxtdat + i) + kPersontext; - return getSegment(data.word(kPeople)).ptr(offset, 0); - } else if (type == 4) { - uint16 offset = getSegment(data.word(kExtras)).word(kExtextdat + index * 2) + kExtext; - return getSegment(data.word(kExtras)).ptr(offset, 0); - } else if (type == 2) { - uint16 offset = getSegment(data.word(kFreedesc)).word(kFreetextdat + index * 2) + kFreetext; - return getSegment(data.word(kFreedesc)).ptr(offset, 0); - } else if (type == 1) { - uint16 offset = getSegment(data.word(kSetdesc)).word(kSettextdat + index * 2) + kSettext; - return getSegment(data.word(kSetdesc)).ptr(offset, 0); - } else { - uint16 offset = getSegment(data.word(kBlockdesc)).word(kBlocktextdat + index * 2) + kBlocktext; - return getSegment(data.word(kBlockdesc)).ptr(offset, 0); +const uint8 *DreamWebEngine::findObName(uint8 type, uint8 index) { + switch (type) { + case 5: + return (const uint8 *)_personText.getString(64 * (index & 127)); + case kExObjectType: + return (const uint8 *)_exText.getString(index); + case kFreeObjectType: + return (const uint8 *)_freeDesc.getString(index); + case kSetObjectType1: + return (const uint8 *)_setDesc.getString(index); + default: + return (const uint8 *)_blockDesc.getString(index); } } -void DreamGenContext::copyName() { - copyName(ah, al, data.ptr(di, 0)); -} - -void DreamGenContext::copyName(uint8 type, uint8 index, uint8 *dst) { +void DreamWebEngine::copyName(uint8 type, uint8 index, uint8 *dst) { const uint8 *src = findObName(type, index); size_t i; - for (i = 0; i < 28; ++i) { + for (i = 0; i < 28; ++i) { char c = src[i]; if (c == ':') break; @@ -1282,113 +1275,112 @@ void DreamGenContext::copyName(uint8 type, uint8 index, uint8 *dst) { dst[i] = 0; } -void DreamGenContext::commandWithOb() { - commandWithOb(al, bh, bl); -} - -void DreamGenContext::commandWithOb(uint8 command, uint8 type, uint8 index) { +void DreamWebEngine::commandWithOb(uint8 command, uint8 type, uint8 index) { uint8 commandLine[64] = "OBJECT NAME ONE "; delTextLine(); - uint16 commandText = kTextstart + getSegment(data.word(kCommandtext)).word(command * 2); - uint8 textLen = data.byte(kTextlen); - { - const uint8 *string = getSegment(data.word(kCommandtext)).ptr(commandText, 0); - printDirect(string, data.word(kTextaddressx), data.word(kTextaddressy), textLen, (bool)(textLen & 1)); - } + uint8 textLen = _textLen; + + const uint8 *string = (const uint8 *)_commandText.getString(command); + printDirect(string, _textAddressX, _textAddressY, textLen, (bool)(textLen & 1)); + copyName(type, index, commandLine); - uint16 x = data.word(kLastxpos); + uint16 x = _lastXPos; if (command != 0) x += 5; - printDirect(commandLine, x, data.word(kTextaddressy), textLen, (bool)(textLen & 1)); - data.byte(kNewtextline) = 1; + printDirect(commandLine, x, _textAddressY, textLen, (bool)(textLen & 1)); + _newTextLine = 1; } -void DreamGenContext::examineObText() { - commandWithOb(1, data.byte(kCommandtype), data.byte(kCommand)); +void DreamWebEngine::examineObText() { + commandWithOb(1, _commandType, _command); } -void DreamGenContext::blockNameText() { - commandWithOb(0, data.byte(kCommandtype), data.byte(kCommand)); +void DreamWebEngine::blockNameText() { + commandWithOb(0, _commandType, _command); } -void DreamGenContext::personNameText() { - commandWithOb(2, data.byte(kCommandtype), data.byte(kCommand) & 127); +void DreamWebEngine::personNameText() { + commandWithOb(2, _commandType, _command & 127); } -void DreamGenContext::walkToText() { - commandWithOb(3, data.byte(kCommandtype), data.byte(kCommand)); +void DreamWebEngine::walkToText() { + commandWithOb(3, _commandType, _command); } -void DreamBase::findOrMake(uint8 index, uint8 value, uint8 type) { - Change *change = (Change *)getSegment(data.word(kBuffers)).ptr(kListofchanges, sizeof(Change)); +void DreamWebEngine::findOrMake(uint8 index, uint8 value, uint8 type) { + Change *change = _listOfChanges; for (; change->index != 0xff; ++change) { - if (index == change->index && data.byte(kReallocation) == change->location && type == change->type) { + if (index == change->index && _realLocation == change->location && type == change->type) { change->value = value; return; } } change->index = index; - change->location = data.byte(kReallocation); + change->location = _realLocation; change->value = value; change->type = type; } -void DreamGenContext::setAllChanges() { - Change *change = (Change *)getSegment(data.word(kBuffers)).ptr(kListofchanges, sizeof(Change)); +void DreamWebEngine::setAllChanges() { + Change *change = _listOfChanges; for (; change->index != 0xff; ++change) - if (change->location == data.byte(kReallocation)) + if (change->location == _realLocation) doChange(change->index, change->value, change->type); } -DynObject *DreamBase::getFreeAd(uint8 index) { - return (DynObject *)getSegment(data.word(kFreedat)).ptr(0, 0) + index; +DynObject *DreamWebEngine::getFreeAd(uint8 index) { + return &_freeDat[index]; } -DynObject *DreamBase::getExAd(uint8 index) { - return (DynObject *)getSegment(data.word(kExtras)).ptr(kExdata, 0) + index; +DynObject *DreamWebEngine::getExAd(uint8 index) { + return &_exData[index]; } -DynObject *DreamBase::getEitherAdCPP() { - if (data.byte(kObjecttype) == 4) - return getExAd(data.byte(kItemframe)); +DynObject *DreamWebEngine::getEitherAd() { + if (_objectType == kExObjectType) + return getExAd(_itemFrame); else - return getFreeAd(data.byte(kItemframe)); + return getFreeAd(_itemFrame); } -void *DreamBase::getAnyAd(uint8 *value1, uint8 *value2) { - if (data.byte(kObjecttype) == 4) { - DynObject *exObject = getExAd(data.byte(kCommand)); - *value1 = exObject->b7; - *value2 = exObject->b8; +void *DreamWebEngine::getAnyAd(uint8 *slotSize, uint8 *slotCount) { + if (_objectType == kExObjectType) { + DynObject *exObject = getExAd(_command); + *slotSize = exObject->slotSize; + *slotCount = exObject->slotCount; return exObject; - } else if (data.byte(kObjecttype) == 2) { - DynObject *freeObject = getFreeAd(data.byte(kCommand)); - *value1 = freeObject->b7; - *value2 = freeObject->b8; + } else if (_objectType == kFreeObjectType) { + DynObject *freeObject = getFreeAd(_command); + *slotSize = freeObject->slotSize; + *slotCount = freeObject->slotCount; return freeObject; - } else { - SetObject *setObject = getSetAd(data.byte(kCommand)); - *value1 = setObject->b4; - *value2 = setObject->priority; + } else { // 1 or 3. 0 should never happen + SetObject *setObject = getSetAd(_command); + // Note: the original returned slotCount/priority (bytes 4 and 5) + // instead of slotSize/slotCount (bytes 3 and 4). + // Changed this for consistency with the Ex/Free cases, and also + // with getOpenedSize() + *slotSize = setObject->slotSize; + *slotCount = setObject->slotCount; return setObject; } } -void *DreamGenContext::getAnyAdDir(uint8 index, uint8 flag) { - if (flag == 4) +void *DreamWebEngine::getAnyAdDir(uint8 index, uint8 flag) { + if (flag == kExObjectType) return getExAd(index); - else if (flag == 2) + else if (flag == kFreeObjectType) return getFreeAd(index); else return getSetAd(index); } -SetObject *DreamBase::getSetAd(uint8 index) { - return (SetObject *)getSegment(data.word(kSetdat)).ptr(0, 0) + index; +SetObject *DreamWebEngine::getSetAd(uint8 index) { + return &_setDat[index]; } -void DreamGenContext::doChange(uint8 index, uint8 value, uint8 type) { +void DreamWebEngine::doChange(uint8 index, uint8 value, uint8 type) { if (type == 0) { //object getSetAd(index)->mapad[0] = value; } else if (type == 1) { //freeObject @@ -1396,134 +1388,101 @@ void DreamGenContext::doChange(uint8 index, uint8 value, uint8 type) { if (freeObject->mapad[0] == 0xff) freeObject->mapad[0] = value; } else { //path - bx = kPathdata + (type - 100) * 144 + index * 8; - es = data.word(kReels); - es.byte(bx+6) = value; + _pathData[type - 100].nodes[index].on = value; } } -void DreamGenContext::deleteTaken() { - const DynObject *extraObjects = (const DynObject *)getSegment(data.word(kExtras)).ptr(kExdata, 0); - DynObject *freeObjects = (DynObject *)getSegment(data.word(kFreedat)).ptr(0, 0); +void DreamWebEngine::deleteTaken() { for (size_t i = 0; i < kNumexobjects; ++i) { - uint8 location = extraObjects[i].initialLocation; - if (location == data.byte(kReallocation)) { - uint8 index = extraObjects[i].index; - freeObjects[index].mapad[0] = 0xfe; + uint8 location = _exData[i].initialLocation; + if (location == _realLocation) { + uint8 index = _exData[i].index; + _freeDat[index].mapad[0] = 0xfe; } } } -void DreamGenContext::getExPos() { - es = data.word(kExtras); - const DynObject *objects = (const DynObject *)getSegment(data.word(kExtras)).ptr(kExdata, sizeof(DynObject)); +uint8 DreamWebEngine::getExPos() { + DynObject *objects = _exData; for (size_t i = 0; i < kNumexobjects; ++i) { - if (objects[i].mapad[0] == 0xff) { - data.byte(kExpos) = i; - di = kExdata + i * sizeof(DynObject); - return; - } + if (objects[i].mapad[0] == 0xff) + return i; } - data.byte(kExpos) = kNumexobjects; - di = kExdata + kNumexobjects * sizeof(DynObject); + error("Out of Ex object positions"); } -void DreamGenContext::placeSetObject() { - placeSetObject(al); -} - -void DreamGenContext::placeSetObject(uint8 index) { +void DreamWebEngine::placeSetObject(uint8 index) { findOrMake(index, 0, 0); getSetAd(index)->mapad[0] = 0; } -void DreamGenContext::removeSetObject() { - removeSetObject(al); -} - -void DreamGenContext::removeSetObject(uint8 index) { +void DreamWebEngine::removeSetObject(uint8 index) { findOrMake(index, 0xff, 0); getSetAd(index)->mapad[0] = 0xff; } -void DreamGenContext::finishedWalking() { - flags._z = finishedWalkingCPP(); -} - -bool DreamGenContext::finishedWalkingCPP() { - return (data.byte(kLinepointer) == 254) && (data.byte(kFacing) == data.byte(kTurntoface)); -} - -void DreamGenContext::getFlagUnderP() { - uint8 flag, flagEx; - getFlagUnderP(&flag, &flagEx); - cl = flag; - ch = flagEx; +bool DreamWebEngine::finishedWalking() { + return (_linePointer == 254) && (_facing == _turnToFace); } -void DreamGenContext::getFlagUnderP(uint8 *flag, uint8 *flagEx) { +void DreamWebEngine::getFlagUnderP(uint8 *flag, uint8 *flagEx) { uint8 type, flagX, flagY; - checkOne(data.word(kMousex) - data.word(kMapadx), data.word(kMousey) - data.word(kMapady), flag, flagEx, &type, &flagX, &flagY); - cl = data.byte(kLastflag) = *flag; - ch = data.byte(kLastflagex) = *flagEx; + checkOne(_mouseX - _mapAdX, _mouseY - _mapAdY, flag, flagEx, &type, &flagX, &flagY); + _lastFlag = *flag; } -void DreamGenContext::walkAndExamine() { - if (!finishedWalkingCPP()) +void DreamWebEngine::walkAndExamine() { + if (!finishedWalking()) return; - data.byte(kCommandtype) = data.byte(kWalkexamtype); - data.byte(kCommand) = data.byte(kWalkexamnum); - data.byte(kWalkandexam) = 0; - if (data.byte(kCommandtype) != 5) + _commandType = _walkExamType; + _command = _walkExamNum; + _walkAndExam = 0; + if (_commandType != 5) examineOb(); } -void DreamGenContext::obName() { - obName(al, ah); -} - -void DreamGenContext::obName(uint8 command, uint8 commandType) { - if (data.byte(kReasseschanges) == 0) { - if ((commandType == data.byte(kCommandtype)) && (command == data.byte(kCommand))) { - if (data.byte(kWalkandexam) == 1) { +void DreamWebEngine::obName(uint8 command, uint8 commandType) { + if (_reAssesChanges == 0) { + if ((commandType == _commandType) && (command == _command)) { + if (_walkAndExam == 1) { walkAndExamine(); return; - } else if (data.word(kMousebutton) == 0) + } else if (_mouseButton == 0) return; - else if ((data.byte(kCommandtype) == 3) && (data.byte(kLastflag) < 2)) + else if ((_commandType == 3) && (_lastFlag < 2)) return; - else if ((data.byte(kManspath) != data.byte(kPointerspath)) || (data.byte(kCommandtype) == 3)) { + else if ((_mansPath != _pointersPath) || (_commandType == 3)) { setWalk(); - data.byte(kReasseschanges) = 1; + _reAssesChanges = 1; return; - } else if (! finishedWalkingCPP()) + } else if (!finishedWalking()) return; - else if (data.byte(kCommandtype) == 5) { - if (data.word(kWatchingtime) == 0) + else if (_commandType == 5) { + if (_vars._watchingTime == 0) talk(); return; } else { - if (data.word(kWatchingtime) == 0) + if (_vars._watchingTime == 0) examineOb(); return; } } } else - data.byte(kReasseschanges) = 0; + _reAssesChanges = 0; - data.byte(kCommand) = command; - data.byte(kCommandtype) = commandType; - if ((data.byte(kLinepointer) != 254) || (data.word(kWatchingtime) != 0) || (data.byte(kFacing) != data.byte(kTurntoface))) { + _command = command; + _commandType = commandType; + if ((_linePointer != 254) || (_vars._watchingTime != 0) || (_facing != _turnToFace)) { blockNameText(); return; - } else if (data.byte(kCommandtype) != 3) { - if (data.byte(kManspath) != data.byte(kPointerspath)) { + } else if (_commandType != 3) { + if (_mansPath != _pointersPath) { walkToText(); return; - } else if (data.byte(kCommandtype) == 3) { + } else if (_commandType == 3) { blockNameText(); return; - } else if (data.byte(kCommandtype) == 5) { + } else if (_commandType == 5) { personNameText(); return; } else { @@ -1531,20 +1490,21 @@ void DreamGenContext::obName(uint8 command, uint8 commandType) { return; } } - if (data.byte(kManspath) == data.byte(kPointerspath)) { + if (_mansPath == _pointersPath) { uint8 flag, flagEx, type, flagX, flagY; - checkOne(data.byte(kRyanx) + 12, data.byte(kRyany) + 12, &flag, &flagEx, &type, &flagX, &flagY); + checkOne(_ryanX + 12, _ryanY + 12, &flag, &flagEx, &type, &flagX, &flagY); if (flag < 2) { blockNameText(); return; } } - getFlagUnderP(); - if (data.byte(kLastflag) < 2) { + uint8 flag, flagEx; + getFlagUnderP(&flag, &flagEx); + if (_lastFlag < 2) { blockNameText(); return; - } else if (data.byte(kLastflag) >= 128) { + } else if (_lastFlag >= 128) { blockNameText(); return; } else { @@ -1553,138 +1513,126 @@ void DreamGenContext::obName(uint8 command, uint8 commandType) { } } -void DreamBase::delPointer() { - if (data.word(kOldpointerx) == 0xffff) +void DreamWebEngine::delPointer() { + if (_oldPointerX == 0xffff) return; - data.word(kDelherex) = data.word(kOldpointerx); - data.word(kDelherey) = data.word(kOldpointery); - data.byte(kDelxs) = data.byte(kPointerxs); - data.byte(kDelys) = data.byte(kPointerys); - multiPut(getSegment(data.word(kBuffers)).ptr(kPointerback, 0), data.word(kDelherex), data.word(kDelherey), data.byte(kPointerxs), data.byte(kPointerys)); + _delHereX = _oldPointerX; + _delHereY = _oldPointerY; + _delXS = _pointerXS; + _delYS = _pointerYS; + multiPut(_pointerBack, _delHereX, _delHereY, _pointerXS, _pointerYS); } -void DreamBase::showBlink() { - if (data.byte(kManisoffscreen) == 1) +void DreamWebEngine::showBlink() { + if (_manIsOffScreen == 1) return; - ++data.byte(kBlinkcount); - if (data.byte(kShadeson) != 0) + ++_blinkCount; + if (_vars._shadesOn != 0) return; - if (data.byte(kReallocation) >= 50) // eyesshut + if (_realLocation >= 50) // eyesshut return; - if (data.byte(kBlinkcount) != 3) + if (_blinkCount != 3) return; - data.byte(kBlinkcount) = 0; - uint8 blinkFrame = data.byte(kBlinkframe); + _blinkCount = 0; + uint8 blinkFrame = _blinkFrame; ++blinkFrame; // Implicit %256 - data.byte(kBlinkframe) = blinkFrame; + _blinkFrame = blinkFrame; if (blinkFrame > 6) blinkFrame = 6; static const uint8 blinkTab[] = { 16,18,18,17,16,16,16 }; uint8 width, height; - showFrame(engine->icons1(), 44, 32, blinkTab[blinkFrame], 0, &width, &height); + showFrame(_icons1, 44, 32, blinkTab[blinkFrame], 0, &width, &height); } -void DreamBase::dumpBlink() { - if (data.byte(kShadeson) != 0) +void DreamWebEngine::dumpBlink() { + if (_vars._shadesOn != 0) return; - if (data.byte(kBlinkcount) != 0) + if (_blinkCount != 0) return; - if (data.byte(kBlinkframe) >= 6) + if (_blinkFrame >= 6) return; multiDump(44, 32, 16, 12); } -void DreamBase::dumpPointer() { +void DreamWebEngine::dumpPointer() { dumpBlink(); - multiDump(data.word(kDelherex), data.word(kDelherey), data.byte(kDelxs), data.byte(kDelys)); - if ((data.word(kOldpointerx) != data.word(kDelherex)) || (data.word(kOldpointery) != data.word(kDelherey))) - multiDump(data.word(kOldpointerx), data.word(kOldpointery), data.byte(kPointerxs), data.byte(kPointerys)); + multiDump(_delHereX, _delHereY, _delXS, _delYS); + if ((_oldPointerX != _delHereX) || (_oldPointerY != _delHereY)) + multiDump(_oldPointerX, _oldPointerY, _pointerXS, _pointerYS); } -void DreamGenContext::checkCoords(const RectWithCallback *rectWithCallbacks) { - if (data.byte(kNewlocation) != 0xff) - return; - - const RectWithCallback *r; - for (r = rectWithCallbacks; r->_xMin != 0xffff; ++r) { - if (r->contains(data.word(kMousex), data.word(kMousey))) { - (this->*(r->_callback))(); - return; - } - } -} - -void DreamBase::showPointer() { +void DreamWebEngine::showPointer() { showBlink(); - uint16 x = data.word(kMousex); - data.word(kOldpointerx) = data.word(kMousex); - uint16 y = data.word(kMousey); - data.word(kOldpointery) = data.word(kMousey); - if (data.byte(kPickup) == 1) { - const Frame *frames; - if (data.byte(kObjecttype) != 4) - frames = (const Frame *)getSegment(data.word(kFreeframes)).ptr(0, 0); + uint16 x = _mouseX; + _oldPointerX = _mouseX; + uint16 y = _mouseY; + _oldPointerY = _mouseY; + if (_pickUp == 1) { + const GraphicsFile *frames; + if (_objectType != kExObjectType) + frames = &_freeFrames; else - frames = (const Frame *)getSegment(data.word(kExtras)).ptr(0, 0); - const Frame *frame = frames + (3 * data.byte(kItemframe) + 1); + frames = &_exFrames; + const Frame *frame = &frames->_frames[(3 * _itemFrame + 1)]; + uint8 width = frame->width; uint8 height = frame->height; if (width < 12) width = 12; if (height < 12) height = 12; - data.byte(kPointerxs) = width; - data.byte(kPointerys) = height; + _pointerXS = width; + _pointerYS = height; uint16 xMin = (x >= width / 2) ? x - width / 2 : 0; uint16 yMin = (y >= height / 2) ? y - height / 2 : 0; - data.word(kOldpointerx) = xMin; - data.word(kOldpointery) = yMin; - multiGet(getSegment(data.word(kBuffers)).ptr(kPointerback, 0), xMin, yMin, width, height); - showFrame(frames, x, y, 3 * data.byte(kItemframe) + 1, 128); - showFrame(engine->icons1(), x, y, 3, 128); + _oldPointerX = xMin; + _oldPointerY = yMin; + multiGet(_pointerBack, xMin, yMin, width, height); + showFrame(*frames, x, y, 3 * _itemFrame + 1, 128); + showFrame(_icons1, x, y, 3, 128); } else { - const Frame *frame = engine->icons1() + (data.byte(kPointerframe) + 20); + const Frame *frame = &_icons1._frames[_pointerFrame + 20]; uint8 width = frame->width; uint8 height = frame->height; if (width < 12) width = 12; if (height < 12) height = 12; - data.byte(kPointerxs) = width; - data.byte(kPointerys) = height; - multiGet(getSegment(data.word(kBuffers)).ptr(kPointerback, 0), x, y, width, height); - showFrame(engine->icons1(), x, y, data.byte(kPointerframe) + 20, 0); + _pointerXS = width; + _pointerYS = height; + multiGet(_pointerBack, x, y, width, height); + showFrame(_icons1, x, y, _pointerFrame + 20, 0); } } -void DreamGenContext::animPointer() { +void DreamWebEngine::animPointer() { - if (data.byte(kPointermode) == 2) { - data.byte(kPointerframe) = 0; - if ((data.byte(kReallocation) == 14) && (data.byte(kCommandtype) == 211)) - data.byte(kPointerframe) = 5; + if (_pointerMode == 2) { + _pointerFrame = 0; + if ((_realLocation == 14) && (_commandType == 211)) + _pointerFrame = 5; return; - } else if (data.byte(kPointermode) == 3) { - if (data.byte(kPointerspeed) != 0) { - --data.byte(kPointerspeed); + } else if (_pointerMode == 3) { + if (_pointerSpeed != 0) { + --_pointerSpeed; } else { - data.byte(kPointerspeed) = 5; - ++data.byte(kPointercount); - if (data.byte(kPointercount) == 16) - data.byte(kPointercount) = 0; + _pointerSpeed = 5; + ++_pointerCount; + if (_pointerCount == 16) + _pointerCount = 0; } static const uint8 flashMouseTab[] = { 1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2 }; - data.byte(kPointerframe) = flashMouseTab[data.byte(kPointercount)]; + _pointerFrame = flashMouseTab[_pointerCount]; return; } - if (data.word(kWatchingtime) != 0) { - data.byte(kPointerframe) = 11; + if (_vars._watchingTime != 0) { + _pointerFrame = 11; return; } - data.byte(kPointerframe) = 0; - if (data.byte(kInmaparea) == 0) + _pointerFrame = 0; + if (_inMapArea == 0) return; - if (data.byte(kPointerfirstpath) == 0) + if (_pointerFirstPath == 0) return; uint8 flag, flagEx; getFlagUnderP(&flag, &flagEx); @@ -1693,42 +1641,39 @@ void DreamGenContext::animPointer() { if (flag >= 128) return; if (flag & 4) { - data.byte(kPointerframe) = 3; + _pointerFrame = 3; return; } if (flag & 16) { - data.byte(kPointerframe) = 4; + _pointerFrame = 4; return; } if (flag & 2) { - data.byte(kPointerframe) = 5; + _pointerFrame = 5; return; } if (flag & 8) { - data.byte(kPointerframe) = 6; + _pointerFrame = 6; return; } - data.byte(kPointerframe) = 8; -} - -void DreamGenContext::printMessage() { - printMessage(di, bx, al, dl, (bool)(dl & 1)); + _pointerFrame = 8; } -void DreamGenContext::printMessage(uint16 x, uint16 y, uint8 index, uint8 maxWidth, bool centered) { - uint16 offset = kTextstart + getSegment(data.word(kCommandtext)).word(index * 2); - const uint8 *string = getSegment(data.word(kCommandtext)).ptr(offset, 0); - printDirect(&string, x, &y, maxWidth, centered); +void DreamWebEngine::printMessage(uint16 x, uint16 y, uint8 index, uint8 maxWidth, bool centered) { + const uint8 *string = (const uint8 *)_commandText.getString(index); + printDirect(string, x, y, maxWidth, centered); } -void DreamGenContext::compare() { - char id[4] = { cl, ch, dl, dh }; - flags._z = compare(al, ah, id); +void DreamWebEngine::printMessage2(uint16 x, uint16 y, uint8 index, uint8 maxWidth, bool centered, uint8 count) { + const uint8 *string = (const uint8 *)_commandText.getString(index); + while (count--) { + findNextColon(&string); + } + printDirect(string, x, y, maxWidth, centered); } -bool DreamGenContext::compare(uint8 index, uint8 flag, const char id[4]) { - void *ptr = getAnyAdDir(index, flag); - const char *objId = (const char *)(((const uint8 *)ptr) + 12); // whether it is a DynObject or a SetObject +bool DreamWebEngine::objectMatches(void *object, const char *id) { + const char *objId = (const char *)object + 12; // whether it is a DynObject or a SetObject for (size_t i = 0; i < 4; ++i) { if (id[i] != objId[i] + 'A') return false; @@ -1736,28 +1681,54 @@ bool DreamGenContext::compare(uint8 index, uint8 flag, const char id[4]) { return true; } -bool DreamGenContext::isItDescribed(const ObjPos *pos) { - uint16 offset = getSegment(data.word(kSetdesc)).word(kSettextdat + pos->index * 2); - uint8 result = getSegment(data.word(kSetdesc)).byte(kSettext + offset); - return result != 0; +bool DreamWebEngine::compare(uint8 index, uint8 flag, const char id[4]) { + return objectMatches(getAnyAdDir(index, flag), id); +} + +uint16 DreamWebEngine::findSetObject(const char *id) { + for (uint16 index = 0; index < 128; index++) { + if (objectMatches(getSetAd(index), id)) + return index; + } + + return 128; } -bool DreamGenContext::isCD() { - // The original sources has two codepaths depending if the game is 'if cd' or not - // This is a hack to guess which version to use with the assumption that if we have a cd version - // we managed to load the speech. At least it is isolated in this function and can be changed. - // Maybe detect the version during game id? - return (data.byte(kSpeechloaded) == 1); +uint16 DreamWebEngine::findExObject(const char *id) { + for (uint16 index = 0; index < kNumexobjects; index++) { + if (objectMatches(getExAd(index), id)) + return index; + } + + return kNumexobjects; } -void DreamGenContext::showIcon() { - if (data.byte(kReallocation) < 50) { +bool DreamWebEngine::isRyanHolding(const char *id) { + for (uint16 index = 0; index < kNumexobjects; index++) { + DynObject *object = getExAd(index); + if (object->mapad[0] == 4 && objectMatches(object, id)) + return true; + } + + return false; +} + +bool DreamWebEngine::isItDescribed(const ObjPos *pos) { + const char *string = _setDesc.getString(pos->index); + return string[0] != 0; +} + +void DreamWebEngine::showIcon() { + if (_realLocation < 50) { showPanel(); showMan(); roomName(); panelIcons1(); zoomIcon(); } else { + error("Unimplemented tempsprites code called"); + // the tempsprites segment is never initialized, but used here. +/* Frame *tempSprites = (Frame *)getSegment(data.word(kTempsprites)).ptr(0, 0); showFrame(tempSprites, 72, 2, 45, 0); showFrame(tempSprites, 72+47, 2, 46, 0); @@ -1765,72 +1736,43 @@ void DreamGenContext::showIcon() { showFrame(tempSprites, 160+88, 2, 45, 4 & 0xfe); showFrame(tempSprites, 160+43, 2, 46, 4 & 0xfe); showFrame(tempSprites, 160+101, 21, 49, 4 & 0xfe); - middlePanel(); - } -} -void DreamGenContext::checkIfSet() { - flags._z = !checkIfSet(al, ah); + // middle panel + showFrame(tempSprites, 72 + 47 + 20, 0, 48, 0); + showFrame(tempSprites, 72 + 19, 21, 47, 0); + showFrame(tempSprites, 160 + 23, 0, 48, 4); + showFrame(tempSprites, 160 + 71, 21, 47, 4); +*/ + } } -bool DreamGenContext::checkIfSet(uint8 x, uint8 y) { - const ObjPos *setList = (const ObjPos *)getSegment(data.word(kBuffers)).ptr(kSetlist, sizeof(ObjPos) * 128); - for (size_t i = 0; i < 128; ++i) { - const ObjPos *pos = setList + 127 - i; - if (pos->index == 0xff || !pos->contains(x,y)) +bool DreamWebEngine::checkIfSet(uint8 x, uint8 y) { + Common::List<ObjPos>::const_iterator i; + for (i = _setList.reverse_begin(); i != _setList.end(); --i) { + const ObjPos &pos = *i; + assert(pos.index != 0xff); + if (!pos.contains(x,y)) continue; - if (! pixelCheckSet(pos, x, y)) + if (!pixelCheckSet(&pos, x, y)) continue; - if (! isItDescribed(pos)) + if (!isItDescribed(&pos)) continue; - obName(pos->index, 1); + obName(pos.index, 1); return true; } return false; } -void DreamBase::showRyanPage() { - showFrame(engine->icons1(), kInventx + 167, kInventy - 12, 12, 0); - showFrame(engine->icons1(), kInventx + 167 + 18 * data.byte(kRyanpage), kInventy - 12, 13 + data.byte(kRyanpage), 0); -} - -void DreamGenContext::findAllRyan() { - findAllRyan(es.ptr(di, 60)); -} - -void DreamGenContext::findAllRyan(uint8 *inv) { - memset(inv, 0xff, 60); - for (size_t i = 0; i < kNumexobjects; ++i) { - DynObject *extra = getExAd(i); - if (extra->mapad[0] != 4) - continue; - if (extra->mapad[1] != 0xff) - continue; - uint8 slot = extra->mapad[2]; - assert(slot < 30); - inv[2 * slot + 0] = i; - inv[2 * slot + 1] = 4; - } -} - -void DreamGenContext::hangOn() { - hangOn(cx); -} - -void DreamBase::hangOn(uint16 frameCount) { +void DreamWebEngine::hangOn(uint16 frameCount) { while (frameCount) { vSync(); --frameCount; - if (quitRequested()) + if (_quitRequested) break; } } -void DreamGenContext::hangOnW() { - hangOnW(cx); -} - -void DreamGenContext::hangOnW(uint16 frameCount) { +void DreamWebEngine::hangOnW(uint16 frameCount) { while (frameCount) { delPointer(); readMouse(); @@ -1839,22 +1781,18 @@ void DreamGenContext::hangOnW(uint16 frameCount) { vSync(); dumpPointer(); --frameCount; - if (quitRequested()) + if (_quitRequested) break; } } -void DreamGenContext::hangOnP() { - hangOnP(cx); -} - -void DreamGenContext::hangOnP(uint16 count) { - data.word(kMaintimer) = 0; - uint8 pointerFrame = data.byte(kPointerframe); - uint8 pickup = data.byte(kPickup); - data.byte(kPointermode) = 3; - data.byte(kPickup) = 0; - data.byte(kCommandtype) = 255; +void DreamWebEngine::hangOnP(uint16 count) { + _mainTimer = 0; + uint8 pointerFrame = _pointerFrame; + uint8 pickup = _pickUp; + _pointerMode = 3; + _pickUp = 0; + _commandType = 255; readMouse(); animPointer(); showPointer(); @@ -1869,26 +1807,19 @@ void DreamGenContext::hangOnP(uint16 count) { showPointer(); vSync(); dumpPointer(); - if (quitRequested()) + if (_quitRequested) break; - if (data.word(kMousebutton) != 0 && data.word(kMousebutton) != data.word(kOldbutton)) + if (_mouseButton != 0 && _mouseButton != _oldButton) break; } delPointer(); - data.byte(kPointerframe) = pointerFrame; - data.byte(kPickup) = pickup; - data.byte(kPointermode) = 0; + _pointerFrame = pointerFrame; + _pickUp = pickup; + _pointerMode = 0; } -void DreamGenContext::findNextColon() { - uint8 *initialString = es.ptr(si, 0); - uint8 *string = initialString; - al = findNextColon(&string); - si += (string - initialString); -} - -uint8 DreamGenContext::findNextColon(uint8 **string) { +uint8 DreamWebEngine::findNextColon(const uint8 **string) { uint8 c; do { c = **string; @@ -1897,90 +1828,20 @@ uint8 DreamGenContext::findNextColon(uint8 **string) { return c; } -uint8 *DreamGenContext::getObTextStartCPP() { - push(es); - push(si); - getObTextStart(); - uint8 *result = es.ptr(si, 0); - si = pop(); - es = pop(); - return result; -} - -void DreamGenContext::enterSymbol() { - data.byte(kManisoffscreen) = 1; - getRidOfReels(); - loadIntoTemp("DREAMWEB.G12"); // symbol graphics - data.byte(kSymboltopx) = 24; - data.byte(kSymboltopdir) = 0; - data.byte(kSymbolbotx) = 24; - data.byte(kSymbolbotdir) = 0; - redrawMainScrn(); - showSymbol(); - underTextLine(); - workToScreenM(); - data.byte(kGetback) = 0; - do { - delPointer(); - updateSymbolTop(); - updateSymbolBot(); - showSymbol(); - readMouse(); - showPointer(); - vSync(); - dumpPointer(); - dumpTextLine(); - dumpSymbol(); - RectWithCallback symbolList[] = { - { kSymbolx+40,kSymbolx+64,kSymboly+2,kSymboly+16,&DreamGenContext::quitSymbol }, - { kSymbolx,kSymbolx+52,kSymboly+20,kSymboly+50,&DreamGenContext::setTopLeft }, - { kSymbolx+52,kSymbolx+104,kSymboly+20,kSymboly+50,&DreamGenContext::setTopRight }, - { kSymbolx,kSymbolx+52,kSymboly+50,kSymboly+80,&DreamGenContext::setBotLeft }, - { kSymbolx+52,kSymbolx+104,kSymboly+50,kSymboly+80,&DreamGenContext::setBotRight }, - { 0,320,0,200,&DreamGenContext::blank }, - { 0xFFFF,0,0,0,0 } - }; - checkCoords(symbolList); - } while ((data.byte(kGetback) == 0) && !quitRequested()); - if ((data.byte(kSymbolbotnum) == 3) && (data.byte(kSymboltopnum) == 5)) { - removeSetObject(43); - placeSetObject(46); - turnAnyPathOn(0, data.byte(kRoomnum) + 12); - data.byte(kManisoffscreen) = 0; - redrawMainScrn(); - getRidOfTemp(); - restoreReels(); - workToScreenM(); - playChannel1(13); - } else { - removeSetObject(46); - placeSetObject(43); - turnAnyPathOff(0, data.byte(kRoomnum) + 12); - data.byte(kManisoffscreen) = 0; - redrawMainScrn(); - getRidOfTemp(); - restoreReels(); - workToScreenM(); - } -} - -void DreamGenContext::zoomOnOff() { - if (data.word(kWatchingtime) != 0 || data.byte(kPointermode) == 2) { +void DreamWebEngine::zoomOnOff() { + if (_vars._watchingTime != 0 || _pointerMode == 2) { blank(); return; } - if (data.byte(kCommandtype) != 222) { - data.byte(kCommandtype) = 222; - commandOnly(39); - } + commandOnlyCond(39, 222); - if (!(data.word(kMousebutton) & 1) || (data.word(kMousebutton) == data.word(kOldbutton))) + if (!(_mouseButton & 1) || (_mouseButton == _oldButton)) return; - data.byte(kZoomon) ^= 1; + _vars._zoomOn ^= 1; createPanel(); - data.byte(kNewobs) = 0; + _vars._newObs = 0; drawFloor(); printSprites(); reelsOnScreen(); @@ -1992,593 +1853,392 @@ void DreamGenContext::zoomOnOff() { workToScreenM(); } -void DreamGenContext::sortOutMap() { +void DreamWebEngine::sortOutMap() { const uint8 *src = workspace(); - uint8 *dst = (uint8 *)getSegment(data.word(kMapdata)).ptr(0, 0); - for (uint16 y = 0; y < kMaplength; ++y) { - memcpy(dst, src, kMapwidth); - dst += kMapwidth; + uint8 *dst = _mapData; + for (uint16 y = 0; y < kMapHeight; ++y) { + memcpy(dst, src, kMapWidth); + dst += kMapWidth; src += 132; } } -void DreamGenContext::showCity() { - clearWork(); - showFrame(tempGraphics(), 57, 32, 0, 0); - showFrame(tempGraphics(), 120+57, 32, 1, 0); -} - -void DreamGenContext::mainScreen() { - data.byte(kInmaparea) = 0; - if (data.byte(kWatchon) == 1) { +void DreamWebEngine::mainScreen() { + _inMapArea = 0; + if (_vars._watchOn == 1) { RectWithCallback mainList[] = { - { 44,70,32,46,&DreamGenContext::look }, - { 0,50,0,180,&DreamGenContext::inventory }, - { 226,244,10,26,&DreamGenContext::zoomOnOff }, - { 226,244,26,40,&DreamGenContext::saveLoad }, - { 240,260,100,124,&DreamGenContext::madmanRun }, - { 0,320,0,200,&DreamGenContext::identifyOb }, + { 44,70,32,46,&DreamWebEngine::look }, + { 0,50,0,180,&DreamWebEngine::inventory }, + { 226,244,10,26,&DreamWebEngine::zoomOnOff }, + { 226,244,26,40,&DreamWebEngine::saveLoad }, + { 240,260,100,124,&DreamWebEngine::madmanRun }, + { 0,320,0,200,&DreamWebEngine::identifyOb }, { 0xFFFF,0,0,0,0 } }; checkCoords(mainList); } else { RectWithCallback mainList2[] = { - { 44,70,32,46,&DreamGenContext::look }, - { 0,50,0,180,&DreamGenContext::inventory }, - { 226+48,244+48,10,26,&DreamGenContext::zoomOnOff }, - { 226+48,244+48,26,40,&DreamGenContext::saveLoad }, - { 240,260,100,124,&DreamGenContext::madmanRun }, - { 0,320,0,200,&DreamGenContext::identifyOb }, + { 44,70,32,46,&DreamWebEngine::look }, + { 0,50,0,180,&DreamWebEngine::inventory }, + { 226+48,244+48,10,26,&DreamWebEngine::zoomOnOff }, + { 226+48,244+48,26,40,&DreamWebEngine::saveLoad }, + { 240,260,100,124,&DreamWebEngine::madmanRun }, + { 0,320,0,200,&DreamWebEngine::identifyOb }, { 0xFFFF,0,0,0,0 } }; checkCoords(mainList2); } - if (data.byte(kWalkandexam) != 0) + if (_walkAndExam != 0) walkAndExamine(); } -void DreamBase::showWatch() { - if (data.byte(kWatchon)) { - showFrame(engine->icons1(), 250, 1, 6, 0); +void DreamWebEngine::showWatch() { + if (_vars._watchOn) { + showFrame(_icons1, 250, 1, 6, 0); showTime(); } } -void DreamGenContext::dumpWatch() { - if (data.byte(kWatchdump) != 1) +void DreamWebEngine::dumpWatch() { + if (_watchDump != 1) return; multiDump(256, 21, 40, 12); - data.byte(kWatchdump) = 0; + _watchDump = 0; } -void DreamBase::showTime() { - if (data.byte(kWatchon) == 0) +void DreamWebEngine::showTime() { + if (_vars._watchOn == 0) return; - Frame *charset = (Frame *)getSegment(data.word(kCharset1)).ptr(0, 0); - int seconds = data.byte(kSecondcount); - int minutes = data.byte(kMinutecount); - int hours = data.byte(kHourcount); + int seconds = _vars._secondCount; + int minutes = _vars._minuteCount; + int hours = _vars._hourCount; - showFrame(charset, 282+5, 21, 91*3+10 + seconds / 10, 0); - showFrame(charset, 282+9, 21, 91*3+10 + seconds % 10, 0); + showFrame(_charset1, 282+5, 21, 91*3+10 + seconds / 10, 0); + showFrame(_charset1, 282+9, 21, 91*3+10 + seconds % 10, 0); - showFrame(charset, 270+5, 21, 91*3 + minutes / 10, 0); - showFrame(charset, 270+11, 21, 91*3 + minutes % 10, 0); + showFrame(_charset1, 270+5, 21, 91*3 + minutes / 10, 0); + showFrame(_charset1, 270+11, 21, 91*3 + minutes % 10, 0); - showFrame(charset, 256+5, 21, 91*3 + hours / 10, 0); - showFrame(charset, 256+11, 21, 91*3 + hours % 10, 0); + showFrame(_charset1, 256+5, 21, 91*3 + hours / 10, 0); + showFrame(_charset1, 256+11, 21, 91*3 + hours % 10, 0); - showFrame(charset, 267+5, 21, 91*3+20, 0); + showFrame(_charset1, 267+5, 21, 91*3+20, 0); } -void DreamGenContext::watchCount() { - if (data.byte(kWatchon) == 0) +void DreamWebEngine::watchCount() { + if (_vars._watchOn == 0) return; - ++data.byte(kTimercount); - if (data.byte(kTimercount) == 9) { - showFrame((Frame *)getSegment(data.word(kCharset1)).ptr(0, 0), 268+4, 21, 91*3+21, 0); - data.byte(kWatchdump) = 1; - } else if (data.byte(kTimercount) == 18) { - data.byte(kTimercount) = 0; - ++data.byte(kSecondcount); - if (data.byte(kSecondcount) == 60) { - data.byte(kSecondcount) = 0; - ++data.byte(kMinutecount); - if (data.byte(kMinutecount) == 60) { - data.byte(kMinutecount) = 0; - ++data.byte(kHourcount); - if (data.byte(kHourcount) == 24) - data.byte(kHourcount) = 0; + ++_timerCount; + if (_timerCount == 9) { + showFrame(_charset1, 268+4, 21, 91*3+21, 0); + _watchDump = 1; + } else if (_timerCount == 18) { + _timerCount = 0; + ++_vars._secondCount; + if (_vars._secondCount == 60) { + _vars._secondCount = 0; + ++_vars._minuteCount; + if (_vars._minuteCount == 60) { + _vars._minuteCount = 0; + ++_vars._hourCount; + if (_vars._hourCount == 24) + _vars._hourCount = 0; } } showTime(); - data.byte(kWatchdump) = 1; + _watchDump = 1; } } -void DreamGenContext::roomName() { +void DreamWebEngine::roomName() { printMessage(88, 18, 53, 240, false); - uint16 textIndex = data.byte(kRoomnum); + uint16 textIndex = _roomNum; if (textIndex >= 32) textIndex -= 32; - data.word(kLinespacing) = 7; - uint8 maxWidth = (data.byte(kWatchon) == 1) ? 120 : 160; - uint16 descOffset = getSegment(data.word(kRoomdesc)).word(kIntextdat + textIndex * 2); - const uint8 *string = getSegment(data.word(kRoomdesc)).ptr(kIntext + descOffset, 0); + _lineSpacing = 7; + uint8 maxWidth = (_vars._watchOn == 1) ? 120 : 160; + const uint8 *string = (const uint8 *)_roomDesc.getString(textIndex); printDirect(string, 88, 25, maxWidth, false); - data.word(kLinespacing) = 10; + _lineSpacing = 10; useCharset1(); } -void DreamGenContext::zoomIcon() { - if (data.byte(kZoomon) == 0) - return; - showFrame(engine->icons1(), kZoomx, kZoomy-1, 8, 0); -} - -void DreamGenContext::loadRoom() { - data.byte(kRoomloaded) = 1; - data.word(kTimecount) = 0; - data.word(kMaintimer) = 0; - data.word(kMapoffsetx) = 104; - data.word(kMapoffsety) = 38; - data.word(kTextaddressx) = 13; - data.word(kTextaddressy) = 182; - data.byte(kTextlen) = 240; - data.byte(kLocation) = data.byte(kNewlocation); - const Room &room = g_roomData[data.byte(kNewlocation)]; +void DreamWebEngine::loadRoom() { + _roomLoaded = 1; + _timeCount = 0; + _mainTimer = 0; + _mapOffsetX = 104; + _mapOffsetY = 38; + _textAddressX = 13; + _textAddressY = 182; + _textLen = 240; + _vars._location = _newLocation; + const Room &room = g_roomData[_newLocation]; startLoading(room); loadRoomsSample(); switchRyanOn(); drawFlags(); - getDimension(); -} - -void DreamGenContext::readSetData() { - data.word(kCharset1) = standardLoad("DREAMWEB.C00"); - void *icons1Buffer = standardLoadCPP("DREAMWEB.G00"); - engine->setIcons1(icons1Buffer); - void *icons2Buffer = standardLoadCPP("DREAMWEB.G01"); - engine->setIcons2(icons2Buffer); + uint8 mapXstart, mapYstart; + uint8 mapXsize, mapYsize; + getDimension(&mapXstart, &mapYstart, &mapXsize, &mapYsize); +} - data.word(kMainsprites) = standardLoad("DREAMWEB.S00"); - data.word(kPuzzletext) = standardLoad("DREAMWEB.T80"); - data.word(kCommandtext) = standardLoad("DREAMWEB.T84"); +void DreamWebEngine::readSetData() { + loadGraphicsFile(_charset1, "C00"); + loadGraphicsFile(_icons1, "G00"); + loadGraphicsFile(_icons2, "G01"); + loadGraphicsFile(_mainSprites, "S00"); + loadTextFile(_puzzleText, "T80"); + loadTextFile(_commandText, "T84"); useCharset1(); // FIXME: Why is this commented out? - //engine->openFile("DREAMWEB.VOL"); + //openFile(getDatafilePrefix() + "VOL"); //uint8 *volumeTab = getSegment(data.word(kSoundbuffer)).ptr(16384, 0); - //engine->readFromFile(volumeTab, 2048-256); - //engine->closeFile(); -} - -Frame * DreamBase::tempGraphics() { - return (Frame *)getSegment(data.word(kTempgraphics)).ptr(0, 0); -} - -Frame * DreamBase::tempGraphics2() { - return (Frame *)getSegment(data.word(kTempgraphics2)).ptr(0, 0); -} - -Frame * DreamBase::tempGraphics3() { - return (Frame *)getSegment(data.word(kTempgraphics3)).ptr(0, 0); + //readFromFile(volumeTab, 2048-256); + //closeFile(); } -void DreamGenContext::findRoomInLoc() { - uint8 x = data.byte(kMapx) / 11; - uint8 y = data.byte(kMapy) / 10; +void DreamWebEngine::findRoomInLoc() { + uint8 x = _mapX / 11; + uint8 y = _mapY / 10; uint8 roomNum = y * 6 + x; - data.byte(kRoomnum) = roomNum; + _roomNum = roomNum; } -void DreamGenContext::autoLook() { - if ((data.word(kMousex) != data.word(kOldx)) || (data.word(kMousey) != data.word(kOldy))) { - data.word(kLookcounter) = 1000; +void DreamWebEngine::autoLook() { + if ((_mouseX != _oldX) || (_mouseY != _oldY)) { + _lookCounter = 1000; return; } - --data.word(kLookcounter); - if (data.word(kLookcounter)) + --_lookCounter; + if (_lookCounter) return; - if (data.word(kWatchingtime)) + if (_vars._watchingTime) return; doLook(); } -void DreamGenContext::look() { - if (data.word(kWatchingtime) || (data.byte(kPointermode) == 2)) { +void DreamWebEngine::look() { + if (_vars._watchingTime || (_pointerMode == 2)) { blank(); return; } - if (data.byte(kCommandtype) != 241) { - data.byte(kCommandtype) = 241; - commandOnly(25); - } - if ((data.word(kMousebutton) == 1) && (data.word(kMousebutton) != data.word(kOldbutton))) + commandOnlyCond(25, 241); + if ((_mouseButton == 1) && (_mouseButton != _oldButton)) doLook(); } -void DreamGenContext::doLook() { +void DreamWebEngine::doLook() { createPanel(); showIcon(); underTextLine(); workToScreenM(); - data.byte(kCommandtype) = 255; + _commandType = 255; dumpTextLine(); - uint8 index = data.byte(kRoomnum) & 31; - uint16 offset = getSegment(data.word(kRoomdesc)).word(kIntextdat + index * 2); - uint8 *string = getSegment(data.word(kRoomdesc)).ptr(kIntext, 0) + offset; + uint8 index = _roomNum & 31; + const uint8 *string = (const uint8 *)_roomDesc.getString(index); findNextColon(&string); uint16 x; - if (data.byte(kReallocation) < 50) + if (_realLocation < 50) x = 66; else x = 40; if (printSlow(string, x, 80, 241, true) != 1) hangOnP(400); - data.byte(kPointermode) = 0; - data.byte(kCommandtype) = 0; + _pointerMode = 0; + _commandType = 0; redrawMainScrn(); workToScreenM(); } -void DreamGenContext::useCharset1() { - engine->setCurrentCharset((Frame *)getSegment(data.word(kCharset1)).ptr(0, 0)); -} - -void DreamGenContext::useTempCharset() { - engine->setCurrentCharset(engine->tempCharset()); -} - -void DreamGenContext::getRidOfTemp() { - deallocateMem(data.word(kTempgraphics)); -} - -void DreamGenContext::getRidOfTempText() { - deallocateMem(data.word(kTextfile1)); +void DreamWebEngine::useCharset1() { + _currentCharset = &_charset1; } -void DreamGenContext::getRidOfTemp2() { - deallocateMem(data.word(kTempgraphics2)); +void DreamWebEngine::useTempCharset(GraphicsFile *charset) { + _currentCharset = charset; } -void DreamGenContext::getRidOfTemp3() { - deallocateMem(data.word(kTempgraphics3)); +void DreamWebEngine::getRidOfTempText() { + _textFile1.clear(); } -void DreamGenContext::getRidOfTempCharset() { - engine->freeTempCharset(); -} - -void DreamGenContext::getRidOfTempsP() { - deallocateMem(data.word(kTempsprites)); -} +void DreamWebEngine::getRidOfAll() { + delete[] _backdropBlocks; + _backdropBlocks = 0; -void DreamGenContext::getRidOfAll() { - deallocateMem(data.word(kBackdrop)); - deallocateMem(data.word(kSetframes)); - deallocateMem(data.word(kReel1)); - deallocateMem(data.word(kReel2)); - deallocateMem(data.word(kReel3)); - deallocateMem(data.word(kReels)); - deallocateMem(data.word(kPeople)); - deallocateMem(data.word(kSetdesc)); - deallocateMem(data.word(kBlockdesc)); - deallocateMem(data.word(kRoomdesc)); - deallocateMem(data.word(kFreeframes)); - deallocateMem(data.word(kFreedesc)); + _setFrames.clear(); + _reel1.clear(); + _reel2.clear(); + _reel3.clear(); + delete[] _reelList; + _reelList = 0; + _personText.clear(); + _setDesc.clear(); + _blockDesc.clear(); + _roomDesc.clear(); + _freeFrames.clear(); + _freeDesc.clear(); } // if skipDat, skip clearing and loading Setdat and Freedat -void DreamGenContext::loadRoomData(const Room &room, bool skipDat) { - engine->openFile(room.name); +void DreamWebEngine::loadRoomData(const Room &room, bool skipDat) { + processEvents(); + Common::File file; + if (!file.open(room.name)) + error("cannot open file %s", room.name); FileHeader header; - engine->readFromFile((uint8 *)&header, sizeof(FileHeader)); + file.read((uint8 *)&header, sizeof(FileHeader)); // read segment lengths from room file header - int len[15]; + unsigned int len[15]; for (int i = 0; i < 15; ++i) len[i] = header.len(i); - data.word(kBackdrop) = allocateAndLoad(len[0]); - clearAndLoad(workspace(), 0, len[1], 132*66); // 132*66 = maplen + assert(len[0] >= 192); + _backdropBlocks = new uint8[len[0] - 192]; + file.read((uint8 *)_backdropFlags, 192); + file.read(_backdropBlocks, len[0] - 192); + + assert(len[1] <= 132*66); // 132*66 = maplen + memset(workspace(), 0, 132*66); + file.read(workspace(), len[1]); + sortOutMap(); - data.word(kSetframes) = allocateAndLoad(len[2]); - if (!skipDat) - clearAndLoad(data.word(kSetdat), 255, len[3], kSetdatlen); - else - engine->skipBytes(len[3]); + + loadGraphicsSegment(_setFrames, file, len[2]); + if (!skipDat) { + const uint16 kSetdatlen = 64*128; + assert(len[3] <= kSetdatlen); + memset(_setDat, 255, kSetdatlen); + file.read(_setDat, len[3]); + } else { + file.skip(len[3]); + } // NB: The skipDat version of this function as called by restoreall // had a 'call bloc' instead of 'call loadseg' for reel1, // but 'bloc' was not defined. - data.word(kReel1) = allocateAndLoad(len[4]); - data.word(kReel2) = allocateAndLoad(len[5]); - data.word(kReel3) = allocateAndLoad(len[6]); - data.word(kReels) = allocateAndLoad(len[7]); - data.word(kPeople) = allocateAndLoad(len[8]); - data.word(kSetdesc) = allocateAndLoad(len[9]); - data.word(kBlockdesc) = allocateAndLoad(len[10]); - data.word(kRoomdesc) = allocateAndLoad(len[11]); - data.word(kFreeframes) = allocateAndLoad(len[12]); - if (!skipDat) - clearAndLoad(data.word(kFreedat), 255, len[13], kFreedatlen); - else - engine->skipBytes(len[13]); - data.word(kFreedesc) = allocateAndLoad(len[14]); + loadGraphicsSegment(_reel1, file, len[4]); + loadGraphicsSegment(_reel2, file, len[5]); + loadGraphicsSegment(_reel3, file, len[6]); + + // segment 7 consists of 36 RoomPaths followed by 'reelList' + delete[] _reelList; + if (len[7] <= 36*sizeof(RoomPaths)) { + file.read((uint8 *)_pathData, len[7]); + _reelList = 0; + } else { + file.read((uint8 *)_pathData, 36*sizeof(RoomPaths)); + unsigned int reelLen = len[7] - 36*sizeof(RoomPaths); + unsigned int reelCount = (reelLen + sizeof(Reel) - 1) / sizeof(Reel); + _reelList = new Reel[reelCount]; + file.read((uint8 *)_reelList, reelLen); + } + + // segment 8 consists of 12 personFrames followed by a TextFile + file.read((uint8 *)_personFramesLE, 24); + loadTextSegment(_personText, file, len[8] - 24); + + loadTextSegment(_setDesc, file, len[9]); + loadTextSegment(_blockDesc, file, len[10]); + loadTextSegment(_roomDesc, file, len[11]); + loadGraphicsSegment(_freeFrames, file, len[12]); + if (!skipDat) { + const uint16 kFreedatlen = 16*80; + assert(len[13] <= kFreedatlen); + memset(_freeDat, 255, kFreedatlen); + file.read(_freeDat, len[13]); + } else { + file.skip(len[13]); + } + loadTextSegment(_freeDesc, file, len[14]); - engine->closeFile(); + processEvents(); } -void DreamGenContext::restoreAll() { - const Room &room = g_roomData[data.byte(kLocation)]; +void DreamWebEngine::restoreAll() { + const Room &room = g_roomData[_vars._location]; loadRoomData(room, true); setAllChanges(); } -void DreamGenContext::restoreReels() { - if (data.byte(kRoomloaded) == 0) +void DreamWebEngine::restoreReels() { + if (_roomLoaded == 0) return; - const Room &room = g_roomData[data.byte(kReallocation)]; + const Room &room = g_roomData[_realLocation]; - engine->openFile(room.name); + processEvents(); + Common::File file; + if (!file.open(room.name)) + error("cannot open file %s", room.name); FileHeader header; - engine->readFromFile((uint8 *)&header, sizeof(FileHeader)); + file.read((uint8 *)&header, sizeof(FileHeader)); // read segment lengths from room file header int len[15]; for (int i = 0; i < 15; ++i) len[i] = header.len(i); - engine->skipBytes(len[0]); - engine->skipBytes(len[1]); - engine->skipBytes(len[2]); - engine->skipBytes(len[3]); - data.word(kReel1) = allocateAndLoad(len[4]); - data.word(kReel2) = allocateAndLoad(len[5]); - data.word(kReel3) = allocateAndLoad(len[6]); - - engine->closeFile(); -} - -void DreamGenContext::loadFolder() { - loadIntoTemp("DREAMWEB.G09"); // folder graphics 1 - loadIntoTemp2("DREAMWEB.G10"); // folder graphics 2 - loadIntoTemp3("DREAMWEB.G11"); // folder graphics 3 - loadTempCharset("DREAMWEB.C02"); // character set 3 - loadTempText("DREAMWEB.T50"); // folder text -} - -void DreamGenContext::showFolder() { - data.byte(kCommandtype) = 255; - if (data.byte(kFolderpage)) { - useTempCharset(); - createPanel2(); - showFrame(tempGraphics(), 0, 0, 0, 0); - showFrame(tempGraphics(), 143, 0, 1, 0); - showFrame(tempGraphics(), 0, 92, 2, 0); - showFrame(tempGraphics(), 143, 92, 3, 0); - folderExit(); - if (data.byte(kFolderpage) != 1) - showLeftPage(); - if (data.byte(kFolderpage) != 12) - showRightPage(); - useCharset1(); - underTextLine(); - } else { - createPanel2(); - showFrame(tempGraphics3(), 143-28, 0, 0, 0); - showFrame(tempGraphics3(), 143-28, 92, 1, 0); - folderExit(); - underTextLine(); - } -} + file.skip(len[0]); + file.skip(len[1]); + file.skip(len[2]); + file.skip(len[3]); + loadGraphicsSegment(_reel1, file, len[4]); + loadGraphicsSegment(_reel2, file, len[5]); + loadGraphicsSegment(_reel3, file, len[6]); -void DreamGenContext::showLeftPage() { - showFrame(tempGraphics2(), 0, 12, 3, 0); - uint16 y = 12+5; - for (size_t i = 0; i < 9; ++i) { - showFrame(tempGraphics2(), 0, y, 4, 0); - y += 16; - } - showFrame(tempGraphics2(), 0, y, 5, 0); - data.word(kLinespacing) = 8; - data.word(kCharshift) = 91; - data.byte(kKerning) = 1; - uint8 pageIndex = data.byte(kFolderpage) - 2; - const uint8 *string = getTextInFile1(pageIndex * 2); - y = 48; - for (size_t i = 0; i < 2; ++i) { - uint8 lastChar; - do { - lastChar = printDirect(&string, 2, &y, 140, false); - y += data.word(kLinespacing); - } while (lastChar != '\0'); - } - data.byte(kKerning) = 0; - data.word(kCharshift) = 0; - data.word(kLinespacing) = 10; - uint8 *bufferToSwap = workspace() + (48*320)+2; - for (size_t i = 0; i < 120; ++i) { - for (size_t j = 0; j < 65; ++j) { - SWAP(bufferToSwap[j], bufferToSwap[130 - j]); - } - bufferToSwap += 320; - } + processEvents(); } -void DreamGenContext::showRightPage() { - showFrame(tempGraphics2(), 143, 12, 0, 0); - uint16 y = 12+37; - for (size_t i = 0; i < 7; ++i) { - showFrame(tempGraphics2(), 143, y, 1, 0); - y += 16; - } - - showFrame(tempGraphics2(), 143, y, 2, 0); - data.word(kLinespacing) = 8; - data.byte(kKerning) = 1; - uint8 pageIndex = data.byte(kFolderpage) - 1; - const uint8 *string = getTextInFile1(pageIndex * 2); - y = 48; - for (size_t i = 0; i < 2; ++i) { - uint8 lastChar; - do { - lastChar = printDirect(&string, 152, &y, 140, false); - y += data.word(kLinespacing); - } while (lastChar != '\0'); - } - data.byte(kKerning) = 0; - data.word(kLinespacing) = 10; +void DreamWebEngine::showExit() { + showFrame(_icons1, 274, 154, 11, 0); } -void DreamBase::showExit() { - showFrame(engine->icons1(), 274, 154, 11, 0); +void DreamWebEngine::showMan() { + showFrame(_icons1, 0, 0, 0, 0); + showFrame(_icons1, 0, 114, 1, 0); + if (_vars._shadesOn) + showFrame(_icons1, 28, 25, 2, 0); } -void DreamBase::showMan() { - showFrame(engine->icons1(), 0, 0, 0, 0); - showFrame(engine->icons1(), 0, 114, 1, 0); - if (data.byte(kShadeson)) - showFrame(engine->icons1(), 28, 25, 2, 0); -} - -void DreamBase::panelIcons1() { +void DreamWebEngine::panelIcons1() { uint16 x; - if (data.byte(kWatchon) != 1) + if (_vars._watchOn != 1) x = 48; else x = 0; - showFrame(engine->icons2(), 204 + x, 4, 2, 0); - if (data.byte(kZoomon) != 1) - showFrame(engine->icons1(), 228 + x, 8, 5, 0); + showFrame(_icons2, 204 + x, 4, 2, 0); + if (_vars._zoomOn != 1) + showFrame(_icons1, 228 + x, 8, 5, 0); showWatch(); } -void DreamGenContext::examIcon() { - showFrame(engine->icons2(), 254, 5, 3, 0); -} - -uint8 DreamGenContext::getLocation(uint8 index) { - return data.byte(kRoomscango + index); -} - -void DreamGenContext::getLocation() { - al = getLocation(al); -} - -void DreamGenContext::setLocation(uint8 index) { - data.byte(kRoomscango + index) = 1; -} - -void DreamGenContext::setLocation() { - setLocation(al); -} - -const uint8 *DreamBase::getTextInFile1(uint16 index) { - SegmentRef text = getSegment(data.word(kTextfile1)); - uint16 offset = text.word(index * 2) + kTextstart; - const uint8 *string = text.ptr(offset, 0); - return string; -} - -void DreamGenContext::checkFolderCoords() { - RectWithCallback folderList[] = { - { 280,320,160,200, &DreamGenContext::quitKey }, - { 143,300,6,194, &DreamGenContext::nextFolder }, - { 0,143,6,194, &DreamGenContext::lastFolder }, - { 0,320,0,200, &DreamGenContext::blank }, - { 0xFFFF,0,0,0, 0 } - }; - checkCoords(folderList); -} - -void DreamGenContext::nextFolder() { - if (data.byte(kFolderpage) == 12) { - blank(); - return; - } - if (data.byte(kCommandtype) != 201) { - data.byte(kCommandtype) = 201; - commandOnly(16); - } - if ((data.word(kMousebutton) == 1) && (data.word(kMousebutton) != data.word(kOldbutton))) { - ++data.byte(kFolderpage); - folderHints(); - delPointer(); - showFolder(); - data.word(kMousebutton) = 0; - checkFolderCoords(); - workToScreenM(); - } +void DreamWebEngine::examIcon() { + showFrame(_icons2, 254, 5, 3, 0); } -void DreamGenContext::lastFolder() { - if (data.byte(kFolderpage) == 0) { - blank(); - return; - } - if (data.byte(kCommandtype) != 202) { - data.byte(kCommandtype) = 202; - commandOnly(17); - } - - if ((data.word(kMousebutton) == 1) && (data.word(kMousebutton) != data.word(kOldbutton))) { - --data.byte(kFolderpage); - delPointer(); - showFolder(); - data.word(kMousebutton) = 0; - checkFolderCoords(); - workToScreenM(); - } +const uint8 *DreamWebEngine::getTextInFile1(uint16 index) { + return (const uint8 *)_textFile1.getString(index); } -void DreamGenContext::folderHints() { - if (data.byte(kFolderpage) == 5) { - if ((data.byte(kAidedead) != 1) && (getLocation(13) != 1)) { - setLocation(13); - showFolder(); - const uint8 *string = getTextInFile1(30); - printDirect(string, 0, 86, 141, true); - workToScreenM(); - hangOnP(200); - } - } else if (data.byte(kFolderpage) == 9) { - if (getLocation(7) != 1) { - setLocation(7); - showFolder(); - const uint8 *string = getTextInFile1(31); - printDirect(string, 0, 86, 141, true); - workToScreenM(); - hangOnP(200); - } - } -} - -void DreamGenContext::folderExit() { - showFrame(tempGraphics2(), 296, 178, 6, 0); -} - -void DreamGenContext::loadTravelText() { - data.word(kTraveltext) = standardLoad("DREAMWEB.T81"); // location descs +void DreamWebEngine::loadTravelText() { + loadTextFile(_travelText, "T81"); // location descs } -void DreamGenContext::loadTempText() { - loadTempText((const char *)data.ptr(dx, 0)); +void DreamWebEngine::loadTempText(const char *suffix) { + loadTextFile(_textFile1, suffix); } -void DreamGenContext::loadTempText(const char *fileName) { - data.word(kTextfile1) = standardLoad(fileName); -} - -void DreamGenContext::drawFloor() { +void DreamWebEngine::drawFloor() { eraseOldObs(); drawFlags(); calcMapAd(); @@ -2588,96 +2248,38 @@ void DreamGenContext::drawFloor() { showAllEx(); panelToMap(); initRain(); - data.byte(kNewobs) = 0; + _vars._newObs = 0; } -void DreamGenContext::allocateBuffers() { - data.word(kExtras) = allocateMem(kLengthofextra/16); - data.word(kMapdata) = allocateMem(kLengthofmap/16); - data.word(kBuffers) = allocateMem(kLengthofbuffer/16); - data.word(kFreedat) = allocateMem(kFreedatlen/16); - data.word(kSetdat) = allocateMem(kSetdatlen/16); - data.word(kMapstore) = allocateMem(kLenofmapstore/16); - data.word(kSounddata) = allocateMem(2048/16); - data.word(kSounddata2) = allocateMem(2048/16); +void DreamWebEngine::allocateBuffers() { + _exFrames.clear(); + _exFrames._data = new uint8[kExframeslen]; + _exFrames._frames = new Frame[kGraphicsFileFrameSize]; + _exText.clear(); + _exText._text = new char[kExtextlen]; } -void DreamGenContext::workToScreenM() { +void DreamWebEngine::workToScreenM() { animPointer(); readMouse(); showPointer(); vSync(); - workToScreenCPP(); + workToScreen(); delPointer(); } -void DreamGenContext::loadMenu() { - loadIntoTemp("DREAMWEB.S02"); // sprite name 3 - loadIntoTemp2("DREAMWEB.G07"); // mon. graphics 2 -} - -void DreamGenContext::showMenu() { - ++data.byte(kMenucount); - if (data.byte(kMenucount) == 37*2) - data.byte(kMenucount) = 0; - showFrame(tempGraphics(), kMenux, kMenuy, data.byte(kMenucount) / 2, 0); -} - -void DreamGenContext::dumpMenu() { - multiDump(kMenux, kMenuy, 48, 48); -} - -void DreamGenContext::useMenu() { - getRidOfReels(); - loadMenu(); - createPanel(); - showPanel(); - showIcon(); - data.byte(kNewobs) = 0; - drawFloor(); - printSprites(); - showFrame(tempGraphics2(), kMenux-48, kMenuy-4, 4, 0); - getUnderMenu(); - showFrame(tempGraphics2(), kMenux+54, kMenuy+72, 5, 0); - workToScreenM(); - data.byte(kGetback) = 0; - do { - delPointer(); - putUnderMenu(); - showMenu(); - readMouse(); - showPointer(); - vSync(); - dumpPointer(); - dumpMenu(); - dumpTextLine(); - RectWithCallback menuList[] = { - { kMenux+54,kMenux+68,kMenuy+72,kMenuy+88,&DreamGenContext::quitKey }, - { 0,320,0,200,&DreamGenContext::blank }, - { 0xFFFF,0,0,0,0 } - }; - checkCoords(menuList); - } while ((data.byte(kGetback) != 1) && !quitRequested()); - data.byte(kManisoffscreen) = 0; - redrawMainScrn(); - getRidOfTemp(); - getRidOfTemp2(); - restoreReels(); - workToScreenM(); -} - -void DreamGenContext::atmospheres() { +void DreamWebEngine::atmospheres() { const Atmosphere *a = &g_atmosphereList[0]; for (; a->_location != 255; ++a) { - if (a->_location != data.byte(kReallocation)) + if (a->_location != _realLocation) continue; - if (a->_mapX != data.byte(kMapx) || a->_mapY != data.byte(kMapy)) + if (a->_mapX != _mapX || a->_mapY != _mapY) continue; - if (a->_sound != data.byte(kCh0playing)) { + if (a->_sound != _channel0Playing) { - if (data.byte(kLocation) == 45 && data.word(kReeltowatch) == 45) + if (_vars._location == 45 && _vars._reelToWatch == 45) continue; // "web" playChannel0(a->_sound, a->_repeat); @@ -2689,36 +2291,36 @@ void DreamGenContext::atmospheres() { // jnz notlouisvol // I'm interpreting this as if the cmp reallocation is below the jz - if (data.byte(kMapy) == 0) { - data.byte(kVolume) = 0; // "fullvol" - return; + if (_mapY == 0) { + _volume = 0; // "fullvol" + return; } - if (data.byte(kReallocation) == 2 && data.byte(kMapx) == 22 && data.byte(kMapy) == 10) - data.byte(kVolume) = 5; // "louisvol" + if (_realLocation == 2 && _mapX == 22 && _mapY == 10) + _volume = 5; // "louisvol" - if (isCD() && data.byte(kReallocation) == 14) { - if (data.byte(kMapx) == 33) { - data.byte(kVolume) = 0; // "ismad2" + if (hasSpeech() && _realLocation == 14) { + if (_mapX == 33) { + _volume = 0; // "ismad2" return; } - if (data.byte(kMapx) == 22) { - data.byte(kVolume) = 5; + if (_mapX == 22) { + _volume = 5; return; } } } - if (data.byte(kReallocation) == 2) { - if (data.byte(kMapx) == 22) { - data.byte(kVolume) = 5; // "louisvol" + if (_realLocation == 2) { + if (_mapX == 22) { + _volume = 5; // "louisvol" return; } - if (data.byte(kMapx) == 11) { - data.byte(kVolume) = 0; // "fullvol" + if (_mapX == 11) { + _volume = 0; // "fullvol" return; } } @@ -2728,459 +2330,39 @@ void DreamGenContext::atmospheres() { cancelCh0(); } -void DreamGenContext::readCityPic() { - loadIntoTemp("DREAMWEB.G04"); -} - -void DreamGenContext::readDestIcon() { - loadIntoTemp("DREAMWEB.G05"); - loadIntoTemp2("DREAMWEB.G06"); - loadIntoTemp3("DREAMWEB.G08"); -} - -uint8 DreamGenContext::nextSymbol(uint8 symbol) { - uint8 result = symbol + 1; - if (result == 6) - return 0; - if (result == 12) - return 6; - return result; -} - -void DreamGenContext::showSymbol() { - showFrame(tempGraphics(), kSymbolx, kSymboly, 12, 0); - - showFrame(tempGraphics(), data.byte(kSymboltopx) + kSymbolx-44, kSymboly+20, data.byte(kSymboltopnum), 32); - uint8 nextTopSymbol = nextSymbol(data.byte(kSymboltopnum)); - showFrame(tempGraphics(), data.byte(kSymboltopx) + kSymbolx+5, kSymboly+20, nextTopSymbol, 32); - uint8 nextNextTopSymbol = nextSymbol(nextTopSymbol); - showFrame(tempGraphics(), data.byte(kSymboltopx) + kSymbolx+54, kSymboly+20, nextNextTopSymbol, 32); +void DreamWebEngine::readKey() { + uint16 bufOut = _bufferOut; - showFrame(tempGraphics(), data.byte(kSymbolbotx) + kSymbolx-44, kSymboly+49, 6 + data.byte(kSymbolbotnum), 32); - uint8 nextBotSymbol = nextSymbol(data.byte(kSymbolbotnum)); - showFrame(tempGraphics(), data.byte(kSymbolbotx) + kSymbolx+5, kSymboly+49, 6 + nextBotSymbol, 32); - uint8 nextNextBotSymbol = nextSymbol(nextBotSymbol); - showFrame(tempGraphics(), data.byte(kSymbolbotx) + kSymbolx+54, kSymboly+49, 6 + nextNextBotSymbol, 32); -} - -void DreamBase::readKey() { - uint16 bufOut = data.word(kBufferout); - - if (bufOut == data.word(kBufferin)) { + if (bufOut == _bufferIn) { // empty buffer - data.byte(kCurrentkey) = 0; + _currentKey = 0; return; } bufOut = (bufOut + 1) & 15; // The buffer has size 16 - data.byte(kCurrentkey) = g_keyBuffer[bufOut]; - data.word(kBufferout) = bufOut; -} - -void DreamGenContext::hangOne(uint16 delay) { - do { - vSync(); - if (data.byte(kLasthardkey) == 1) - return; // "hangonearly" - } while (--delay); -} - -void DreamGenContext::hangOne() { - hangOne(cx); -} - -void DreamGenContext::bibleQuote() { - initGraphics(640, 480, true); - - showPCX("DREAMWEB.I00"); - fadeScreenUps(); - - hangOne(80); - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "biblequotearly" - } - - hangOne(560); - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "biblequotearly" - } - - fadeScreenDowns(); - - hangOne(200); - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "biblequotearly" - } - - cancelCh0(); - - data.byte(kLasthardkey) = 0; -} - -void DreamGenContext::realCredits() { - data.byte(kRoomssample) = 33; - loadRoomsSample(); - data.byte(kVolume) = 0; - - initGraphics(640, 480, true); - hangOn(35); - - showPCX("DREAMWEB.I01"); - playChannel0(12, 0); - - hangOne(2); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - allPalette(); - hangOne(80); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - fadeScreenDowns(); - hangOne(256); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - showPCX("DREAMWEB.I02"); - playChannel0(12, 0); - hangOne(2); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - allPalette(); - hangOne(80); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - fadeScreenDowns(); - hangOne(256); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - showPCX("DREAMWEB.I03"); - playChannel0(12, 0); - hangOne(2); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - allPalette(); - hangOne(80); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - fadeScreenDowns(); - hangOne(256); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - showPCX("DREAMWEB.I04"); - playChannel0(12, 0); - hangOne(2); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - allPalette(); - hangOne(80); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - fadeScreenDowns(); - hangOne(256); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - showPCX("DREAMWEB.I05"); - playChannel0(12, 0); - hangOne(2); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - allPalette(); - hangOne(80); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - fadeScreenDowns(); - hangOne(256); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - showPCX("DREAMWEB.I06"); - fadeScreenUps(); - hangOne(60); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - playChannel0(13, 0); - hangOne(350); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "realcreditsearly" - } - - fadeScreenDowns(); - hangOne(256); - - data.byte(kLasthardkey) = 0; -} - -void DreamGenContext::runIntroSeq() { - data.byte(kGetback) = 0; - - do { - vSync(); - - if (data.byte(kLasthardkey) == 1) - break; - - spriteUpdate(); - vSync(); - - if (data.byte(kLasthardkey) == 1) - break; - - delEverything(); - printSprites(); - reelsOnScreen(); - afterIntroRoom(); - useTimedText(); - vSync(); - - if (data.byte(kLasthardkey) == 1) - break; - - dumpMap(); - dumpTimedText(); - vSync(); - - if (data.byte(kLasthardkey) == 1) - break; - - } while (data.byte(kGetback) != 1); - - - if (data.byte(kLasthardkey) == 1) { - getRidOfTempText(); - clearBeforeLoad(); - } - - // These were not called in this program arc - // in the original code.. Bug? - //getRidOfTempText(); - //clearBeforeLoad(); -} - -void DreamGenContext::intro() { - loadTempText("DREAMWEB.T82"); - loadPalFromIFF(); - setMode(); - data.byte(kNewlocation) = 50; - clearPalette(); - loadIntroRoom(); - data.byte(kVolume) = 7; - data.byte(kVolumedirection) = (uint8)-1; - data.byte(kVolumeto) = 4; - playChannel0(12, 255); - fadeScreenUps(); - runIntroSeq(); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "introearly" - } - - clearBeforeLoad(); - data.byte(kNewlocation) = 52; - loadIntroRoom(); - runIntroSeq(); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "introearly" - } - - clearBeforeLoad(); - data.byte(kNewlocation) = 53; - loadIntroRoom(); - runIntroSeq(); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "introearly" - } - - clearBeforeLoad(); - allPalette(); - data.byte(kNewlocation) = 54; - loadIntroRoom(); - runIntroSeq(); - - if (data.byte(kLasthardkey) == 1) { - data.byte(kLasthardkey) = 0; - return; // "introearly" - } - - getRidOfTempText(); - clearBeforeLoad(); - - data.byte(kLasthardkey) = 0; -} - -void DreamGenContext::setTopLeft() { - if (data.byte(kSymboltopdir) != 0) { - blank(); - return; - } - - if (data.byte(kCommandtype) != 210) { - data.byte(kCommandtype) = 210; - commandOnly(19); - } - - if (data.word(kMousebutton) != 0) - data.byte(kSymboltopdir) = 0xFF; -} - -void DreamGenContext::setTopRight() { - if (data.byte(kSymboltopdir) != 0) { - blank(); - return; - } - - if (data.byte(kCommandtype) != 211) { - data.byte(kCommandtype) = 211; - commandOnly(20); - } - - if (data.word(kMousebutton) != 0) - data.byte(kSymboltopdir) = 1; -} - -void DreamGenContext::setBotLeft() { - if (data.byte(kSymbolbotdir) != 0) { - blank(); - return; - } - - if (data.byte(kCommandtype) != 212) { - data.byte(kCommandtype) = 212; - commandOnly(21); - } - - if (data.word(kMousebutton) != 0) - data.byte(kSymbolbotdir) = 0xFF; -} - -void DreamGenContext::setBotRight() { - if (data.byte(kSymbolbotdir) != 0) { - blank(); - return; - } - - if (data.byte(kCommandtype) != 213) { - data.byte(kCommandtype) = 213; - commandOnly(22); - } - - if (data.word(kMousebutton) != 0) - data.byte(kSymbolbotdir) = 1; + _currentKey = g_keyBuffer[bufOut]; + _bufferOut = bufOut; } -void DreamGenContext::newGame() { - if (data.byte(kCommandtype) != 251) { - data.byte(kCommandtype) = 251; - commandOnly(47); - } +void DreamWebEngine::newGame() { + commandOnlyCond(47, 251); - if (data.word(kMousebutton) == 1) - data.byte(kGetback) = 3; + if (_mouseButton == 1) + _getBack = 3; } -void DreamGenContext::getBackFromOps() { - if (data.byte(kMandead) == 2) - blank(); - else - getBack1(); +void DreamWebEngine::pickupOb(uint8 command, uint8 pos) { + _lastInvPos = pos; + _objectType = kFreeObjectType; + _itemFrame = command; + _command = command; + //uint8 dummy; + //getAnyAd(&dummy, &dummy); // was in the original source, seems useless here + transferToEx(command); } -void DreamGenContext::getBackToOps() { - if (data.byte(kCommandtype) != 201) { - data.byte(kCommandtype) = 201; - commandOnly(42); - } - - if (data.word(kMousebutton) != data.word(kOldbutton)) { - if (data.word(kMousebutton) & 1) { - oldToNames(); - data.byte(kGetback) = 2; - } - } -} - -void DreamGenContext::pickupOb(uint8 command, uint8 pos) { - data.byte(kLastinvpos) = pos; - data.byte(kObjecttype) = 2; - data.byte(kItemframe) = command; - data.byte(kCommand) = command; - getAnyAd(); - transferToEx(); -} - -void DreamGenContext::initialInv() { - if (data.byte(kReallocation) != 24) +void DreamWebEngine::initialInv() { + if (_realLocation != 24) return; pickupOb(11, 5); @@ -3191,71 +2373,41 @@ void DreamGenContext::initialInv() { pickupOb(19, 1); pickupOb(20, 9); pickupOb(16, 2); - data.byte(kWatchmode) = 1; - data.word(kReeltohold) = 0; - data.word(kEndofholdreel) = 6; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; + _vars._watchMode = 1; + _vars._reelToHold = 0; + _vars._endOfHoldReel = 6; + _vars._watchSpeed = 1; + _vars._speedCount = 1; switchRyanOff(); } -void DreamGenContext::walkIntoRoom() { - if (data.byte(kLocation) == 14 && data.byte(kMapx) == 22) { - data.byte(kDestination) = 1; - data.byte(kFinaldest) = 1; +void DreamWebEngine::walkIntoRoom() { + if (_vars._location == 14 && _mapX == 22) { + _destination = 1; + _finalDest = 1; autoSetWalk(); } } -void DreamGenContext::loadIntroRoom() { - data.byte(kIntrocount) = 0; - data.byte(kLocation) = 255; - loadRoom(); - data.word(kMapoffsetx) = 72; - data.word(kMapoffsety) = 16; - clearSprites(); - data.byte(kThroughdoor) = 0; - data.byte(kCurrentkey) = '0'; - data.byte(kMainmode) = 0; - clearWork(); - data.byte(kNewobs) = 1; - drawFloor(); - reelsOnScreen(); - spriteUpdate(); - printSprites(); - workToScreenCPP(); -} - -void DreamGenContext::afterIntroRoom() { - if (data.byte(kNowinnewroom) == 0) +void DreamWebEngine::afterIntroRoom() { + if (_nowInNewRoom == 0) return; // notnewintro clearWork(); findRoomInLoc(); - data.byte(kNewobs) = 1; + _vars._newObs = 1; drawFloor(); reelsOnScreen(); spriteUpdate(); printSprites(); - workToScreenCPP(); - data.byte(kNowinnewroom) = 0; -} - -void DreamGenContext::gettingShot() { - data.byte(kNewlocation) = 55; - clearPalette(); - loadIntroRoom(); - fadeScreenUps(); - data.byte(kVolumeto) = 0; - data.byte(kVolumedirection) = 0xFF; - runEndSeq(); - clearBeforeLoad(); + workToScreen(); + _nowInNewRoom = 0; } -void DreamGenContext::redrawMainScrn() { - data.word(kTimecount) = 0; +void DreamWebEngine::redrawMainScrn() { + _timeCount = 0; createPanel(); - data.byte(kNewobs) = 0; + _vars._newObs = 0; drawFloor(); printSprites(); reelsOnScreen(); @@ -3263,31 +2415,22 @@ void DreamGenContext::redrawMainScrn() { getUnderZoom(); underTextLine(); readMouse(); - data.byte(kCommandtype) = 255; + _commandType = 255; } -void DreamGenContext::selectSlot2() { - if (data.word(kMousebutton)) - data.byte(kLoadingorsave) = 2; - selectSlot(); -} - -void DreamGenContext::blank() { - if (data.byte(kCommandtype) != 199) { - data.byte(kCommandtype) = 199; - commandOnly(0); - } +void DreamWebEngine::blank() { + commandOnlyCond(0, 199); } -void DreamGenContext::allPointer() { +void DreamWebEngine::allPointer() { readMouse(); showPointer(); dumpPointer(); } -void DreamGenContext::makeMainScreen() { +void DreamWebEngine::makeMainScreen() { createPanel(); - data.byte(kNewobs) = 1; + _vars._newObs = 1; drawFloor(); spriteUpdate(); printSprites(); @@ -3295,23 +2438,22 @@ void DreamGenContext::makeMainScreen() { showIcon(); getUnderZoom(); underTextLine(); - data.byte(kCommandtype) = 255; + _commandType = 255; animPointer(); workToScreenM(); - data.byte(kCommandtype) = 200; - data.byte(kManisoffscreen) = 0; + _commandType = 200; + _manIsOffScreen = 0; } -void DreamGenContext::openInv() { - data.byte(kInvopen) = 1; +void DreamWebEngine::openInv() { + _invOpen = 1; printMessage(80, 58 - 10, 61, 240, (240 & 1)); fillRyan(); - data.byte(kCommandtype) = 255; + _commandType = 255; } -void DreamGenContext::obsThatDoThings() { - char id[4] = { 'M', 'E', 'M', 'B' }; // TODO: convert to string with trailing zero - if (!compare(data.byte(kCommand), data.byte(kObjecttype), id)) +void DreamWebEngine::obsThatDoThings() { + if (!compare(_command, _objectType, "MEMB")) return; // notlouiscard if (getLocation(4) != 1) { @@ -3320,23 +2462,49 @@ void DreamGenContext::obsThatDoThings() { } } -void DreamGenContext::delEverything() { - if (data.byte(kMapysize) + data.word(kMapoffsety) < 182) { +void DreamWebEngine::describeOb() { + const uint8 *obText = getObTextStart(); + uint16 y = 92; + if (_foreignRelease && _objectType == kSetObjectType1) + y = 82; + _charShift = 91 + 91; + printDirect(&obText, 33, &y, 241, 241 & 1); + _charShift = 0; + y = 104; + if (_foreignRelease && _objectType == kSetObjectType1) + y = 94; + printDirect(&obText, 36, &y, 241, 241 & 1); + obsThatDoThings(); + + // Additional text + if (compare(_command, _objectType, "CUPE")) { + // Empty cup + const uint8 *string = (const uint8 *)_puzzleText.getString(40); + printDirect(string, 36, y + 10, 241, 241 & 1); + } else if (compare(_command, _objectType, "CUPF")) { + // Full cup + const uint8 *string = (const uint8 *)_puzzleText.getString(39); + printDirect(string, 36, y + 10, 241, 241 & 1); + } +} + +void DreamWebEngine::delEverything() { + if (_mapYSize + _mapOffsetY < 182) { mapToPanel(); } else { // Big room - data.byte(kMapysize) -= 8; + _mapYSize -= 8; mapToPanel(); - data.byte(kMapysize) += 8; + _mapYSize += 8; } } -void DreamGenContext::errorMessage1() { +void DreamWebEngine::errorMessage1() { delPointer(); printMessage(76, 21, 58, 240, (240 & 1)); readMouse(); showPointer(); - workToScreenCPP(); + workToScreen(); delPointer(); hangOnP(50); showPanel(); @@ -3345,17 +2513,17 @@ void DreamGenContext::errorMessage1() { readMouse(); useOpened(); showPointer(); - workToScreenCPP(); + workToScreen(); delPointer(); } -void DreamGenContext::errorMessage2() { - data.byte(kCommandtype) = 255; +void DreamWebEngine::errorMessage2() { + _commandType = 255; delPointer(); printMessage(76, 21, 59, 240, (240 & 1)); readMouse(); showPointer(); - workToScreenCPP(); + workToScreen(); delPointer(); hangOnP(50); showPanel(); @@ -3364,11 +2532,11 @@ void DreamGenContext::errorMessage2() { readMouse(); useOpened(); showPointer(); - workToScreenCPP(); + workToScreen(); delPointer(); } -void DreamGenContext::errorMessage3() { +void DreamWebEngine::errorMessage3() { delPointer(); printMessage(76, 21, 60, 240, (240 & 1)); workToScreenM(); @@ -3379,90 +2547,15 @@ void DreamGenContext::errorMessage3() { readMouse(); useOpened(); showPointer(); - workToScreenCPP(); - delPointer(); -} - -void DreamGenContext::reExFromOpen() { - -} - -void DreamGenContext::nextDest() { - if (data.byte(kCommandtype) != 218) { - data.byte(kCommandtype) = 218; - commandOnly(28); - } - - if (!(data.word(kMousebutton) & 1) || data.word(kOldbutton) == 1) - return; // nodu - - do { - data.byte(kDestpos)++; - if (data.byte(kDestpos) == 15) - data.byte(kDestpos) = 0; // last destination - - getDestInfo(); - } while (al == 0); - - data.byte(kNewtextline) = 1; - delTextLine(); - delPointer(); - showPanel(); - showMan(); - showArrows(); - locationPic(); - underTextLine(); - readMouse(); - showPointer(); - workToScreenCPP(); - delPointer(); -} - -void DreamGenContext::lastDest() { - if (data.byte(kCommandtype) != 219) { - data.byte(kCommandtype) = 219; - commandOnly(29); - } - - if (!(data.word(kMousebutton) & 1) || data.word(kOldbutton) == 1) - return; // nodd - - do { - data.byte(kDestpos)--; - if (data.byte(kDestpos) == 0xFF) - data.byte(kDestpos) = 15; // first destination - - getDestInfo(); - } while (al == 0); - - data.byte(kNewtextline) = 1; - delTextLine(); - delPointer(); - showPanel(); - showMan(); - showArrows(); - locationPic(); - underTextLine(); - readMouse(); - showPointer(); - workToScreenCPP(); + workToScreen(); delPointer(); } -void DreamGenContext::destSelect() { - if (data.byte(kCommandtype) != 222) { - data.byte(kCommandtype) = 222; - commandOnly(30); - } - - if (!(data.word(kMousebutton) & 1) || data.word(kOldbutton) == 1) - return; // notrav +void DreamWebEngine::reExFromOpen() { - getDestInfo(); - data.byte(kNewlocation) = data.byte(kDestpos); } -void DreamGenContext::putBackObStuff() { +void DreamWebEngine::putBackObStuff() { createPanel(); showPanel(); showMan(); @@ -3471,147 +2564,21 @@ void DreamGenContext::putBackObStuff() { obPicture(); describeOb(); underTextLine(); - data.byte(kCommandtype) = 255; + _commandType = 255; readMouse(); showPointer(); - workToScreenCPP(); - delPointer(); -} - -void DreamGenContext::redes() { - if (data.byte(kCh1playing) != 255 || data.byte(kTalkmode) != 2) { - blank(); - return; - } - - if (data.byte(kCommandtype) != 217) { - data.byte(kCommandtype) = 217; - commandOnly(50); - } - - if (!(data.word(kMousebutton) & 1)) - return; - - delPointer(); - createPanel(); - showPanel(); - showMan(); - showExit(); - convIcons(); - startTalk(); - readMouse(); - showPointer(); - workToScreenCPP(); + workToScreen(); delPointer(); } -void DreamGenContext::moreTalk() { - if (data.byte(kTalkmode) != 0) { - redes(); - return; - } - - if (data.byte(kCommandtype) != 215) { - data.byte(kCommandtype) = 215; - commandOnly(49); - } - - if (data.word(kMousebutton) == data.word(kOldbutton)) - return; // nomore - - if (!(data.word(kMousebutton) & 1)) - return; - - data.byte(kTalkmode) = 2; - data.byte(kTalkpos) = 4; - - if (data.byte(kCharacter) >= 100) - data.byte(kTalkpos) = 48; // second part - doSomeTalk(); -} - -bool DreamGenContext::isSetObOnMap(uint8 index) { +bool DreamWebEngine::isSetObOnMap(uint8 index) { return (getSetAd(index)->mapad[0] == 0); } -void DreamGenContext::isSetObOnMap() { - flags._z = isSetObOnMap(al); -} - -void DreamGenContext::dumpZoom() { - if (data.byte(kZoomon) == 1) - multiDump(kZoomx + 5, kZoomy + 4, 46, 40); -} - -void DreamGenContext::selectLocation() { - data.byte(kInmaparea) = 0; - clearBeforeLoad(); - data.byte(kGetback) = 0; - data.byte(kPointerframe) = 22; - readCityPic(); - showCity(); - getRidOfTemp(); - readDestIcon(); - loadTravelText(); - showPanel(); - showMan(); - showArrows(); - showExit(); - locationPic(); - underTextLine(); - data.byte(kCommandtype) = 255; - readMouse(); - data.byte(kPointerframe) = 0; - showPointer(); - workToScreenCPP(); - playChannel0(9, 255); - data.byte(kNewlocation) = 255; - - while (data.byte(kNewlocation) == 255) { - if (quitRequested()) - break; - - delPointer(); - readMouse(); - showPointer(); - vSync(); - dumpPointer(); - dumpTextLine(); - - if (data.byte(kGetback) == 1) - break; - - RectWithCallback destList[] = { - { 238,258,4,44,&DreamGenContext::nextDest }, - { 104,124,4,44,&DreamGenContext::lastDest }, - { 280,308,4,44,&DreamGenContext::lookAtPlace }, - { 104,216,138,192,&DreamGenContext::destSelect }, - { 273,320,157,198,&DreamGenContext::getBack1 }, - { 0,320,0,200,&DreamGenContext::blank }, - { 0xFFFF,0,0,0,0 } - }; - checkCoords(destList); - } +void DreamWebEngine::examineInventory() { + commandOnlyCond(32, 249); - if (quitRequested() || data.byte(kGetback) == 1 || data.byte(kNewlocation) == data.byte(kLocation)) { - data.byte(kNewlocation) = data.byte(kReallocation); - data.byte(kGetback) = 0; - } - - getRidOfTemp(); - getRidOfTemp2(); - getRidOfTemp3(); - deallocateMem(data.word(kTraveltext)); -} - - -void DreamGenContext::examineInventory() { - if (data.byte(kCommandtype) != 249) { - data.byte(kCommandtype) = 249; - commandOnly(32); - } - - if (!(data.word(kMousebutton) & 1)) + if (!(_mouseButton & 1)) return; createPanel(); @@ -3619,156 +2586,96 @@ void DreamGenContext::examineInventory() { showMan(); showExit(); examIcon(); - data.byte(kPickup) = 0; - data.byte(kInvopen) = 2; + _pickUp = 0; + _invOpen = 2; openInv(); workToScreenM(); } -void DreamBase::showArrows() { - showFrame(tempGraphics(), 116 - 12, 16, 0, 0); - showFrame(tempGraphics(), 226 + 12, 16, 1, 0); - showFrame(tempGraphics(), 280, 14, 2, 0); -} - -void DreamBase::showOpBox() { - showFrame(tempGraphics(), kOpsx, kOpsy, 0, 0); - - // CHECKME: There seem to be versions of dreamweb in which this call - // should be removed. It displays a red dot on the ops dialogs if left in. - showFrame(tempGraphics(), kOpsx, kOpsy + 55, 4, 0); -} - -void DreamGenContext::showLoadOps() { - showFrame(tempGraphics(), kOpsx + 128 + 4, kOpsy + 12, 1, 0); - showFrame(tempGraphics(), kOpsx + 176 + 2, kOpsy + 60 - 4, 5, 0); - printMessage(kOpsx + 104, kOpsy + 14, 55, 101, (101 & 1)); -} - -void DreamGenContext::showSaveOps() { - showFrame(tempGraphics(), kOpsx + 128 + 4, kOpsy + 12, 1, 0); - showFrame(tempGraphics(), kOpsx + 176 + 2, kOpsy + 60 - 4, 5, 0); - printMessage(kOpsx + 104, kOpsy + 14, 54, 101, (101 & 1)); -} - -void DreamBase::middlePanel() { - Frame *tempSprites = (Frame *)getSegment(data.word(kTempsprites)).ptr(0, 0); - showFrame(tempSprites, 72 + 47 + 20, 0, 48, 0); - showFrame(tempSprites, 72 + 19, 21, 47, 0); - showFrame(tempSprites, 160 + 23, 0, 48, 4); - showFrame(tempSprites, 160 + 71, 21, 47, 4); +void DreamWebEngine::middlePanel() { } -void DreamBase::showDiary() { - showFrame(tempGraphics(), kDiaryx, kDiaryy + 37, 1, 0); - showFrame(tempGraphics(), kDiaryx + 176, kDiaryy + 108, 2, 0); -} - -void DreamGenContext::underTextLine() { - uint16 y = data.word(kTextaddressy); - if (data.byte(kForeignrelease)) - y -= 3; - ds = data.word(kBuffers); - si = kTextunder; - multiGet(ds.ptr(si, 0), data.byte(kTextaddressx), y, kUndertextsizex, kUndertextsizey); -} - -void DreamGenContext::showDecisions() { - createPanel2(); - showOpBox(); - showFrame(tempGraphics(), kOpsx + 17, kOpsy + 13, 6, 0); - underTextLine(); -} - -void DreamGenContext::getUnderZoom() { - ds = data.word(kBuffers); - si = kZoomspace; - multiGet(ds.ptr(si, 0), kZoomx + 5, kZoomy + 4, 46, 40); -} - -void DreamGenContext::putUnderZoom() { - ds = data.word(kBuffers); - si = kZoomspace; - multiPut(ds.ptr(si, 0), kZoomx + 5, kZoomy + 4, 46, 40); +void DreamWebEngine::underTextLine() { + if (_foreignRelease) + multiGet(_textUnder, _textAddressX, _textAddressY - 3, kUnderTextSizeX_f, kUnderTextSizeY_f); + else + multiGet(_textUnder, _textAddressX, _textAddressY, kUnderTextSizeX, kUnderTextSizeY); } -void DreamGenContext::showWatchReel() { - uint16 reelPointer = data.word(kReeltowatch); +void DreamWebEngine::showWatchReel() { + uint16 reelPointer = _vars._reelToWatch; plotReel(reelPointer); - data.word(kReeltowatch) = reelPointer; + _vars._reelToWatch = reelPointer; // check for shake - if (data.byte(kReallocation) == 26 && reelPointer == 104) - data.byte(kShakecounter) = 0xFF; + if (_realLocation == 26 && reelPointer == 104) + _vars._shakeCounter = 0xFF; } -void DreamGenContext::watchReel() { - if (data.word(kReeltowatch) != 0xFFFF) { - if (data.byte(kManspath) != data.byte(kFinaldest)) +void DreamWebEngine::watchReel() { + if (_vars._reelToWatch != 0xFFFF) { + if (_mansPath != _finalDest) return; // Wait until stopped walking - if (data.byte(kTurntoface) != data.byte(kFacing)) + if (_turnToFace != _facing) return; - if (--data.byte(kSpeedcount) != 0xFF) { + if (--_vars._speedCount != 0xFF) { showWatchReel(); return; } - data.byte(kSpeedcount) = data.byte(kWatchspeed); - if (data.word(kReeltowatch) != data.word(kEndwatchreel)) { - ++data.word(kReeltowatch); + _vars._speedCount = _vars._watchSpeed; + if (_vars._reelToWatch != _vars._endWatchReel) { + ++_vars._reelToWatch; showWatchReel(); return; } - if (data.word(kWatchingtime)) { + if (_vars._watchingTime) { showWatchReel(); return; } - data.word(kReeltowatch) = 0xFFFF; - data.byte(kWatchmode) = 0xFF; - if (data.word(kReeltohold) == 0xFFFF) + _vars._reelToWatch = 0xFFFF; + _vars._watchMode = 0xFF; + if (_vars._reelToHold == 0xFFFF) return; // No more reel - data.byte(kWatchmode) = 1; - } else if (data.byte(kWatchmode) != 1) { - if (data.byte(kWatchmode) != 2) + _vars._watchMode = 1; + } else if (_vars._watchMode != 1) { + if (_vars._watchMode != 2) return; // "notreleasehold" - if (--data.byte(kSpeedcount) == 0xFF) { - data.byte(kSpeedcount) = data.byte(kWatchspeed); - ++data.word(kReeltohold); + if (--_vars._speedCount == 0xFF) { + _vars._speedCount = _vars._watchSpeed; + ++_vars._reelToHold; } - if (data.word(kReeltohold) == data.word(kEndofholdreel)) { - data.word(kReeltohold) = 0xFFFF; - data.byte(kWatchmode) = 0xFF; - data.byte(kDestination) = data.byte(kDestafterhold); - data.byte(kFinaldest) = data.byte(kDestafterhold); + if (_vars._reelToHold == _vars._endOfHoldReel) { + _vars._reelToHold = 0xFFFF; + _vars._watchMode = 0xFF; + _destination = _vars._destAfterHold; + _finalDest = _vars._destAfterHold; autoSetWalk(); return; } } - uint16 reelPointer = data.word(kReeltohold); + uint16 reelPointer = _vars._reelToHold; plotReel(reelPointer); } -void DreamGenContext::afterNewRoom() { - if (data.byte(kNowinnewroom) == 0) +void DreamWebEngine::afterNewRoom() { + if (_nowInNewRoom == 0) return; // notnew - data.word(kTimecount) = 0; + _timeCount = 0; createPanel(); - data.byte(kCommandtype) = 0; + _commandType = 0; findRoomInLoc(); - if (data.byte(kRyanon) != 1) { - al = data.byte(kRyanx) + 12; - ah = data.byte(kRyany) + 12; - findPathOfPoint(); - data.byte(kManspath) = dl; + if (_vars._ryanOn != 1) { + _mansPath = findPathOfPoint(_ryanX + 12, _ryanY + 12); findXYFromPath(); - data.byte(kResetmanxy) = 1; + _resetManXY = 1; } - data.byte(kNewobs) = 1; + _vars._newObs = 1; drawFloor(); - data.word(kLookcounter) = 160; - data.byte(kNowinnewroom) = 0; + _lookCounter = 160; + _nowInNewRoom = 0; showIcon(); spriteUpdate(); printSprites(); @@ -3779,57 +2686,54 @@ void DreamGenContext::afterNewRoom() { zoom(); workToScreenM(); walkIntoRoom(); - reminders(); + edensFlatReminders(); atmospheres(); } -void DreamGenContext::madmanRun() { - if (data.byte(kLocation) != 14 || - data.byte(kMapx) != 22 || - data.byte(kPointermode) != 2 || - data.byte(kMadmanflag) != 0) { +void DreamWebEngine::madmanRun() { + if (_vars._location != 14 || + _mapX != 22 || + _pointerMode != 2 || + _vars._madmanFlag != 0) { identifyOb(); return; } - if (data.byte(kCommandtype) != 211) { - data.byte(kCommandtype) = 211; - commandOnly(52); - } + commandOnlyCond(52, 211); - if (data.word(kMousebutton) == 1 && - data.word(kMousebutton) != data.word(kOldbutton)) - data.byte(kLastweapon) = 8; + if (_mouseButton == 1 && + _mouseButton != _oldButton) + _vars._lastWeapon = 8; } -void DreamGenContext::decide() { +void DreamWebEngine::decide() { setMode(); loadPalFromIFF(); clearPalette(); - data.byte(kPointermode) = 0; - data.word(kWatchingtime) = 0; - data.byte(kPointerframe) = 0; - data.word(kTextaddressx) = 70; - data.word(kTextaddressy) = 182 - 8; - data.byte(kTextlen) = 181; - data.byte(kManisoffscreen) = 1; + _pointerMode = 0; + _vars._watchingTime = 0; + _pointerFrame = 0; + _textAddressX = 70; + _textAddressY = 182 - 8; + _textLen = 181; + _manIsOffScreen = 1; loadSaveBox(); showDecisions(); - workToScreenCPP(); + workToScreen(); fadeScreenUp(); - data.byte(kGetback) = 0; + _getBack = 0; RectWithCallback decideList[] = { - { kOpsx+69,kOpsx+124,kOpsy+30,kOpsy+76,&DreamGenContext::newGame }, - { kOpsx+20,kOpsx+87,kOpsy+10,kOpsy+59,&DreamGenContext::DOSReturn }, - { kOpsx+123,kOpsx+190,kOpsy+10,kOpsy+59,&DreamGenContext::loadOld }, - { 0,320,0,200,&DreamGenContext::blank }, + { kOpsx+69,kOpsx+124,kOpsy+30,kOpsy+76,&DreamWebEngine::newGame }, + { kOpsx+20,kOpsx+87,kOpsy+10,kOpsy+59,&DreamWebEngine::DOSReturn }, + { kOpsx+123,kOpsx+190,kOpsy+10,kOpsy+59,&DreamWebEngine::loadOld }, + { 0,320,0,200,&DreamWebEngine::blank }, { 0xFFFF,0,0,0,0 } }; do { - if (data.byte(kQuitrequested) != 0) + if (_quitRequested) return; readMouse(); @@ -3839,302 +2743,55 @@ void DreamGenContext::decide() { dumpTextLine(); delPointer(); checkCoords(decideList); - } while (!data.byte(kGetback)); - - if (data.byte(kGetback) != 4) - getRidOfTemp(); // room not loaded - - data.word(kTextaddressx) = 13; - data.word(kTextaddressy) = 182; - data.byte(kTextlen) = 240; -} - -void DreamGenContext::talk() { - data.byte(kTalkpos) = 0; - data.byte(kInmaparea) = 0; - data.byte(kCharacter) = data.byte(kCommand); - createPanel(); - showPanel(); - showMan(); - showExit(); - underTextLine(); - convIcons(); - startTalk(); - data.byte(kCommandtype) = 255; - readMouse(); - showPointer(); - workToScreenCPP(); - - RectWithCallback talkList[] = { - { 273,320,157,198,&DreamGenContext::getBack1 }, - { 240,290,2,44,&DreamGenContext::moreTalk }, - { 0,320,0,200,&DreamGenContext::blank }, - { 0xFFFF,0,0,0,0 } - }; - - do { - delPointer(); - readMouse(); - animPointer(); - showPointer(); - vSync(); - dumpPointer(); - dumpTextLine(); - data.byte(kGetback) = 0; - checkCoords(talkList); - if (data.byte(kQuitrequested)) - break; - } while (!data.byte(kGetback)); - - bx = data.word(kPersondata); - es = cs; - - if (data.byte(kTalkpos) >= 4) - es.byte(bx+7) |= 128; - - redrawMainScrn(); - workToScreenM(); - if (data.byte(kSpeechloaded) == 1) { - cancelCh1(); - data.byte(kVolumedirection) = 0xFF; - data.byte(kVolumeto) = 0; - } -} - - -void DreamGenContext::discOps() { - if (data.byte(kCommandtype) != 249) { - data.byte(kCommandtype) = 249; - commandOnly(43); - } - - if (data.word(kMousebutton) == data.word(kOldbutton) || !(data.word(kMousebutton) & 1)) - return; - - scanForNames(); - data.byte(kLoadingorsave) = 2; - showOpBox(); - showDiscOps(); - data.byte(kCurrentslot) = 0; - workToScreenM(); - data.byte(kGetback) = 0; - - RectWithCallback discOpsList[] = { - { kOpsx+59,kOpsx+114,kOpsy+30,kOpsy+76,&DreamGenContext::loadGame }, - { kOpsx+10,kOpsx+79,kOpsy+10,kOpsy+59,&DreamGenContext::saveGame }, - { kOpsx+176,kOpsx+192,kOpsy+60,kOpsy+76,&DreamGenContext::getBackToOps }, - { 0,320,0,200,&DreamGenContext::blank }, - { 0xFFFF,0,0,0,0 } - }; - - do { - if (data.byte(kQuitrequested) != 0) - return; // quitdiscops - - delPointer(); - readMouse(); - showPointer(); - vSync(); - dumpPointer(); - dumpTextLine(); - checkCoords(discOpsList); - } while (!data.byte(kGetback)); -} - -void DreamGenContext::doSaveLoad() { - data.byte(kPointerframe) = 0; - data.word(kTextaddressx) = 70; - data.word(kTextaddressy) = 182-8; - data.byte(kTextlen) = 181; - data.byte(kManisoffscreen) = 1; - clearWork(); - createPanel2(); - underTextLine(); - getRidOfAll(); - loadSaveBox(); - showOpBox(); - showMainOps(); - workToScreenCPP(); - - RectWithCallback opsList[] = { - { kOpsx+59,kOpsx+114,kOpsy+30,kOpsy+76,&DreamGenContext::getBackFromOps }, - { kOpsx+10,kOpsx+77,kOpsy+10,kOpsy+59,&DreamGenContext::DOSReturn }, - { kOpsx+128,kOpsx+190,kOpsy+16,kOpsy+100,&DreamGenContext::discOps }, - { 0,320,0,200,&DreamGenContext::blank }, - { 0xFFFF,0,0,0,0 } - }; + } while (!_getBack); - bool firstOps = true; + if (_getBack != 4) + _saveGraphics.clear(); // room not loaded - do { // restart ops - if (firstOps) { - firstOps = false; - } else { - showOpBox(); - showMainOps(); - workToScreenM(); - } - data.byte(kGetback) = 0; - - do { // wait ops - if (data.byte(kQuitrequested)) { - data.byte(kManisoffscreen) = 0; - return; - } - - readMouse(); - showPointer(); - vSync(); - dumpPointer(); - dumpTextLine(); - delPointer(); - checkCoords(opsList); - } while (!data.byte(kGetback)); - } while (data.byte(kGetback) == 2); - - data.word(kTextaddressx) = 13; - data.word(kTextaddressy) = 182; - data.byte(kTextlen) = 240; - if (data.byte(kGetback) != 4) { - getRidOfTemp(); - restoreAll(); - redrawMainScrn(); - workToScreenM(); - data.byte(kCommandtype) = 200; - } - data.byte(kManisoffscreen) = 0; + _textAddressX = 13; + _textAddressY = 182; + _textLen = 240; } -void DreamGenContext::hangOnPQ() { - data.byte(kGetback) = 0; - - RectWithCallback quitList[] = { - { 273,320,157,198,&DreamGenContext::getBack1 }, - { 0,320,0,200,&DreamGenContext::blank }, - { 0xFFFF,0,0,0,0 } - }; - - uint16 speechFlag = 0; - - do { - delPointer(); - readMouse(); - animPointer(); - showPointer(); - vSync(); - dumpPointer(); - dumpTextLine(); - checkCoords(quitList); - - if (data.byte(kGetback) == 1 || data.byte(kQuitrequested)) { - // Quit conversation - delPointer(); - data.byte(kPointermode) = 0; - cancelCh1(); - flags._c = true; - return; - } - - if (data.byte(kSpeechloaded) == 1 && data.byte(kCh1playing) == 255) { - speechFlag++; - if (speechFlag == 40) - break; - } - } while (!data.word(kMousebutton) || data.word(kOldbutton)); - - delPointer(); - data.byte(kPointermode) = 0; - flags._c = false; - } - -void DreamGenContext::endGame() { - loadTempText("DREAMWEB.T83"); - monkSpeaking(); - gettingShot(); - getRidOfTempText(); - data.byte(kVolumeto) = 7; - data.byte(kVolumedirection) = 1; - hangOn(200); -} - -void DreamGenContext::showGun() { - data.byte(kAddtored) = 0; - data.byte(kAddtogreen) = 0; - data.byte(kAddtoblue) = 0; +void DreamWebEngine::showGun() { + _addToRed = 0; + _addToGreen = 0; + _addToBlue = 0; palToStartPal(); palToEndPal(); greyscaleSum(); - data.byte(kFadedirection) = 1; - data.byte(kFadecount) = 63; - data.byte(kColourpos) = 0; - data.byte(kNumtofade) = 128; + _fadeDirection = 1; + _fadeCount = 63; + _colourPos = 0; + _numToFade = 128; hangOn(130); endPalToStart(); clearEndPal(); - data.byte(kFadedirection) = 1; - data.byte(kFadecount) = 63; - data.byte(kColourpos) = 0; - data.byte(kNumtofade) = 128; + _fadeDirection = 1; + _fadeCount = 63; + _colourPos = 0; + _numToFade = 128; hangOn(200); - data.byte(kRoomssample) = 34; + _roomsSample = 34; loadRoomsSample(); - data.byte(kVolume) = 0; - loadIntoTemp("DREAMWEB.G13"); + _volume = 0; + GraphicsFile graphics; + loadGraphicsFile(graphics, "G13"); createPanel2(); - showFrame(tempGraphics(), 100, 4, 0, 0); - showFrame(tempGraphics(), 158, 106, 1, 0); - workToScreenCPP(); - getRidOfTemp(); + showFrame(graphics, 100, 4, 0, 0); + showFrame(graphics, 158, 106, 1, 0); + workToScreen(); + graphics.clear(); fadeScreenUp(); hangOn(160); playChannel0(12, 0); - loadTempText("DREAMWEB.T83"); - rollEndCredits2(); + loadTempText("T83"); + rollEndCreditsGameLost(); getRidOfTempText(); } -void DreamGenContext::diaryKeyP() { - if (data.byte(kCommandtype) != 214) { - data.byte(kCommandtype) = 214; - commandOnly(23); - } - - if (!data.word(kMousebutton) || - data.word(kOldbutton) == data.word(kMousebutton) || - data.byte(kPresscount)) - return; // notkeyp - - playChannel1(16); - data.byte(kPresscount) = 12; - data.byte(kPressed) = 'P'; - data.byte(kDiarypage)--; - - if (data.byte(kDiarypage) == 0xFF) - data.byte(kDiarypage) = 11; -} - -void DreamGenContext::diaryKeyN() { - if (data.byte(kCommandtype) != 213) { - data.byte(kCommandtype) = 213; - commandOnly(23); - } - - if (!data.word(kMousebutton) || - data.word(kOldbutton) == data.word(kMousebutton) || - data.byte(kPresscount)) - return; // notkeyn - - playChannel1(16); - data.byte(kPresscount) = 12; - data.byte(kPressed) = 'N'; - data.byte(kDiarypage)++; - - if (data.byte(kDiarypage) == 12) - data.byte(kDiarypage) = 0; -} - -void DreamGenContext::dropError() { - data.byte(kCommandtype) = 255; +void DreamWebEngine::dropError() { + _commandType = 255; delPointer(); printMessage(76, 21, 56, 240, 240 & 1); workToScreenM(); @@ -4142,12 +2799,12 @@ void DreamGenContext::dropError() { showPanel(); showMan(); examIcon(); - data.byte(kCommandtype) = 255; + _commandType = 255; workToScreenM(); } -void DreamGenContext::cantDrop() { - data.byte(kCommandtype) = 255; +void DreamWebEngine::cantDrop() { + _commandType = 255; delPointer(); printMessage(76, 21, 24, 240, 240 & 1); workToScreenM(); @@ -4155,127 +2812,42 @@ void DreamGenContext::cantDrop() { showPanel(); showMan(); examIcon(); - data.byte(kCommandtype) = 255; + _commandType = 255; workToScreenM(); } -void DreamGenContext::getBack1() { - if (data.byte(kPickup) != 0) { +void DreamWebEngine::getBack1() { + if (_pickUp != 0) { blank(); return; } - if (data.byte(kCommandtype) != 202) { - data.byte(kCommandtype) = 202; - commandOnly(26); - } + commandOnlyCond(26, 202); - if (data.word(kMousebutton) == data.word(kOldbutton)) + if (_mouseButton == _oldButton) return; - if (data.word(kMousebutton) & 1) { + if (_mouseButton & 1) { // Get back - data.byte(kGetback) = 1; - data.byte(kPickup) = 0; - } -} - -void DreamGenContext::newPlace() { - if (data.byte(kNeedtotravel) == 1) { - data.byte(kNeedtotravel) = 0; - selectLocation(); - } else if (data.byte(kAutolocation) != 0xFF) { - data.byte(kNewlocation) = data.byte(kAutolocation); - data.byte(kAutolocation) = 0xFF; - } -} - -void DreamGenContext::showPuzText() { - showPuzText(al, cx); -} - -void DreamGenContext::showPuzText(uint16 command, uint16 count) { - findPuzText(); // FIXME: Unnecessary? (Input: al, Output: es:si) - createPanel(); - showPanel(); - showMan(); - showExit(); - obIcons(); - uint16 offset = kTextstart + getSegment(data.word(kPuzzletext)).word(command * 2); - const uint8 *string = getSegment(data.word(kPuzzletext)).ptr(offset, 0); - printDirect(string, 36, 104, 241, 241 & 1); - workToScreenM(); - hangOnP(count); -} - -void DreamGenContext::monkSpeaking() { - // FIXME: This is the CD version only. - - data.byte(kRoomssample) = 35; - loadRoomsSample(); - loadIntoTemp("DREAMWEB.G15"); - clearWork(); - showFrame(tempGraphics(), 160, 72, 0, 128); // show monk - workToScreen(); - data.byte(kVolume) = 7; - data.byte(kVolumedirection) = 0xFF; - data.byte(kVolumeto) = 5; - playChannel0(12, 255); - fadeScreenUps(); - hangOn(300); - - for (int i = 40; i <= 48; i++) { - loadSpeech('T', 83, 'T', i); - - playChannel1(50 + 12); - - do { - engine->waitForVSync(); - } while (data.byte(kCh1playing) != 255); - } - - data.byte(kVolumedirection) = 1; - data.byte(kVolumeto) = 7; - fadeScreenDowns(); - hangOn(300); - getRidOfTemp(); -} - -void DreamGenContext::useButtonA() { - if (!isSetObOnMap(95)) { - showFirstUse(); - turnAnyPathOn(0, data.byte(kRoomnum) - 1); - removeSetObject(9); - placeSetObject(95); - data.word(kWatchingtime) = 15 * 2; - data.word(kReeltowatch) = 71; - data.word(kEndwatchreel) = 85; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; - data.byte(kProgresspoints)++; - } else { - // Done this bit - showSecondUse(); - putBackObStuff(); + _getBack = 1; + _pickUp = 0; } } -void DreamGenContext::autoAppear() { - if (data.byte(kLocation) == 32) { +void DreamWebEngine::autoAppear() { + if (_vars._location == 32) { // In alley - al = 5; - resetLocation(); + resetLocation(5); setLocation(10); - data.byte(kDestpos) = 10; + _destPos = 10; return; } - if (data.byte(kReallocation) == 24) { + if (_realLocation == 24) { // In Eden's apartment - if (data.byte(kGeneraldead) == 1) { - data.byte(kGeneraldead)++; + if (_vars._generalDead == 1) { + _vars._generalDead++; placeSetObject(44); placeSetObject(18); placeSetObject(93); @@ -4284,37 +2856,344 @@ void DreamGenContext::autoAppear() { removeSetObject(75); removeSetObject(84); removeSetObject(85); - } else if (data.byte(kSartaindead) == 1) { + } else if (_vars._sartainDead == 1) { // Eden's part 2 removeSetObject(44); removeSetObject(93); placeSetObject(55); - data.byte(kSartaindead)++; + _vars._sartainDead++; } } else { // Not in Eden's - if (data.byte(kReallocation) == 25) { + if (_realLocation == 25) { // Sart roof - data.byte(kNewsitem) = 3; - al = 6; - resetLocation(); + _vars._newsItem = 3; + resetLocation(6); setLocation(11); - data.byte(kDestpos) = 11; + _destPos = 11; } else { - if (data.byte(kReallocation) == 2 && data.byte(kRockstardead) != 0) + if (_realLocation == 2 && _vars._rockstarDead != 0) placeSetObject(23); } } } -void DreamGenContext::quitKey() { - if (data.byte(kCommandtype) != 222) { - data.byte(kCommandtype) = 222; - commandOnly(4); +void DreamWebEngine::setupTimedUse(uint16 textIndex, uint16 countToTimed, uint16 timeCount, byte x, byte y) { + if (_timeCount != 0) + return; // can't setup + + _timedTemp._y = y; + _timedTemp._x = x; + _timedTemp._countToTimed = countToTimed; + _timeCount = _timedTemp._timeCount = timeCount + countToTimed; + _timedTemp._string = _puzzleText.getString(textIndex); + debug(1, "setupTimedUse: %d => '%s'", textIndex, _timedTemp._string); +} + +void DreamWebEngine::entryTexts() { + switch (_vars._location) { + case 21: + setupTimedUse(28, 60, 11, 68, 64); + break; + case 30: + setupTimedUse(27, 60, 11, 68, 64); + break; + case 23: + setupTimedUse(29, 60, 11, 68, 64); + break; + case 31: + setupTimedUse(30, 60, 11, 68, 64); + break; + case 20: // Sarter's 2 + setupTimedUse(31, 60, 11, 68, 64); + break; + case 24: // Eden's lobby + setupTimedUse(32, 60, 3, 68, 64); + break; + case 34: // Eden 2 + setupTimedUse(33, 60, 3, 68, 64); + break; + default: + break; } +} - if (data.word(kMousebutton) != data.word(kOldbutton) && (data.word(kMousebutton) & 1)) - data.byte(kGetback) = 1; +void DreamWebEngine::entryAnims() { + _vars._reelToWatch = 0xFFFF; + _vars._watchMode = (byte)-1; + + switch (_vars._location) { + case 33: // beach + switchRyanOff(); + _vars._watchingTime = 76 * 2; + _vars._reelToWatch = 0; + _vars._endWatchReel = 76; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + break; + case 44: // Sparky's + resetLocation(8); + _vars._watchingTime = 50*2; + _vars._reelToWatch = 247; + _vars._endWatchReel = 297; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + switchRyanOff(); + break; + case 22: // lift + _vars._watchingTime = 31 * 2; + _vars._reelToWatch = 0; + _vars._endWatchReel = 30; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + switchRyanOff(); + break; + case 26: // under church + _symbolTopNum = 2; + _symbolBotNum = 1; + break; + case 45: // entered Dreamweb + _vars._keeperFlag = 0; + _vars._watchingTime = 296; + _vars._reelToWatch = 45; + _vars._endWatchReel = 198; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + switchRyanOff(); + break; + default: + if (_realLocation == 46 && _vars._sartainDead == 1) { // Crystal + removeFreeObject(0); + } else if (_vars._location == 9 && !checkIfPathIsOn(2) && _vars._aideDead != 0) { + // Top of church + if (checkIfPathIsOn(3)) + turnPathOn(2); + + // Make doors open + removeSetObject(4); + placeSetObject(5); + } else if (_vars._location == 47) { // Dream centre + placeSetObject(4); + placeSetObject(5); + } else if (_vars._location == 38) { // Car park + _vars._watchingTime = 57 * 2; + _vars._reelToWatch = 4; + _vars._endWatchReel = 57; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + switchRyanOff(); + } else if (_vars._location == 32) { // Alley + _vars._watchingTime = 66 * 2; + _vars._reelToWatch = 0; + _vars._endWatchReel = 66; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + switchRyanOff(); + } else if (_vars._location == 24) { // Eden's again + turnAnyPathOn(2, _roomNum - 1); + } + } +} + +void DreamWebEngine::lookAtCard() { + _manIsOffScreen = 1; + getRidOfReels(); + loadKeypad(); + createPanel2(); + showFrame(_keypadGraphics, 160, 80, 42, 128); + const uint8 *obText = getObTextStart(); + findNextColon(&obText); + findNextColon(&obText); + findNextColon(&obText); + uint16 y = 124; + printDirect(&obText, 36, &y, 241, 241 & 1); + workToScreenM(); + hangOnW(280); + createPanel2(); + showFrame(_keypadGraphics, 160, 80, 42, 128); + printDirect(obText, 36, 130, 241, 241 & 1); + workToScreenM(); + hangOnW(200); + _manIsOffScreen = 0; + _keypadGraphics.clear(); + restoreReels(); + putBackObStuff(); +} + +void DreamWebEngine::clearBuffers() { + clearChanges(); +} + +void DreamWebEngine::clearChanges() { + memset(_listOfChanges, 0xFF, sizeof(_listOfChanges)); + + setupInitialReelRoutines(); + + setupInitialVars(); + + _vars._exFramePos = 0; + _vars._exTextPos = 0; + + memset(_exFrames._frames, 0xFF, kFrameBlocksize); + memset(_exFrames._data, 0xFF, kExframeslen); + memset(_exData, 0xFF, sizeof(_exData)); + memset(_exText._offsetsLE, 0xFF, 2*(kNumexobjects+2)); + memset(_exText._text, 0xFF, kExtextlen); + + const uint8 initialRoomsCanGo[16] = { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + assert(sizeof(_roomsCanGo) == sizeof(initialRoomsCanGo)); + memcpy(_roomsCanGo, initialRoomsCanGo, sizeof(initialRoomsCanGo)); +} + +void DreamWebEngine::setupInitialVars() { + _vars._startVars = 0; + _vars._progressPoints = 0; + _vars._watchOn = 0; + _vars._shadesOn = 0; + _vars._secondCount = 0; + _vars._minuteCount = 30; + _vars._hourCount = 19; + _vars._zoomOn = 1; + _vars._location = 0; + _vars._exPos = 0; + _vars._exFramePos = 0; + _vars._exTextPos = 0; + _vars._card1Money = 0; + _vars._listPos = 0; + _vars._ryanPage = 0; + _vars._watchingTime = 0; + _vars._reelToWatch = (uint16)-1; + _vars._endWatchReel = 0; + _vars._speedCount = 0; + _vars._watchSpeed = 0; + _vars._reelToHold = (uint16)-1; + _vars._endOfHoldReel = (uint16)-1; + _vars._watchMode = (uint8)-1; + _vars._destAfterHold = 0; + _vars._newsItem = 0; + _vars._liftFlag = 0; + _vars._liftPath = 0; + _vars._lockStatus = 1; + _vars._doorPath = 0; + _vars._countToOpen = 0; + _vars._countToClose = 0; + _vars._rockstarDead = 0; + _vars._generalDead = 0; + _vars._sartainDead = 0; + _vars._aideDead = 0; + _vars._beenMugged = 0; + _vars._gunPassFlag = 0; + _vars._canMoveAltar = 0; + _vars._talkedToAttendant = 0; + _vars._talkedToSparky = 0; + _vars._talkedToBoss = 0; + _vars._talkedToRecep = 0; + _vars._cardPassFlag = 0; + _vars._madmanFlag = 0; + _vars._keeperFlag = 0; + _vars._lastTrigger = 0; + _vars._manDead = 0; + _vars._seed1 = 1; + _vars._seed2 = 2; + _vars._seed3 = 3; + _vars._needToTravel = 0; + _vars._throughDoor = 0; + _vars._newObs = 0; + _vars._ryanOn = 255; + _vars._combatCount = 0; + _vars._lastWeapon = (uint8)-1; + _vars._dreamNumber = 0; + _vars._roomAfterDream = 0; + _vars._shakeCounter = 48; +} + +void DreamWebEngine::edensFlatReminders() { + if (_realLocation != 24 || _mapX != 44) + return; // not in Eden's lift + + if (_vars._progressPoints) + return; // not the first time in Eden's apartment + + uint16 exObjextIndex = findExObject("CSHR"); + if (!isRyanHolding("DKEY") || exObjextIndex == kNumexobjects) { + setupTimedUse(50, 48, 8, 54, 70); // forgot something + return; + } + + DynObject *object = getExAd(exObjextIndex); + + if (object->mapad[0] != 4) { + setupTimedUse(50, 48, 8, 54, 70); // forgot something + return; + } else if (object->mapad[1] != 255) { + if (!compare(object->mapad[1], object->mapad[0], "PURS")) { + setupTimedUse(50, 48, 8, 54, 70); // forgot something + return; + } + } + + _vars._progressPoints++; // got card +} + +void DreamWebEngine::incRyanPage() { + commandOnlyCond(31, 222); + + if (_mouseButton == _oldButton || !(_mouseButton & 1)) + return; + + _vars._ryanPage = (_mouseX - (kInventx + 167)) / 18; + + delPointer(); + fillRyan(); + readMouse(); + showPointer(); + workToScreen(); + delPointer(); + +} + +void DreamWebEngine::emergencyPurge() { + while (true) { + if (_vars._exFramePos + 4000 < kExframeslen) { + // Not near frame end + if (_vars._exTextPos + 400 < kExtextlen) + return; // notneartextend + } + + purgeAnItem(); + } +} + +void DreamWebEngine::purgeAnItem() { + const DynObject *extraObjects = _exData; + + for (size_t i = 0; i < kNumexobjects; ++i) { + if (extraObjects[i].mapad[0] && extraObjects[i].objId[0] == 255 && + extraObjects[i].initialLocation != _realLocation) { + deleteExObject(i); + return; + } + } + + for (size_t i = 0; i < kNumexobjects; ++i) { + if (extraObjects[i].mapad[0] && extraObjects[i].objId[0] == 255) { + deleteExObject(i); + return; + } + } +} + +void DreamWebEngine::checkCoords(const RectWithCallback *rectWithCallbacks) { + if (_newLocation != 0xff) + return; + const RectWithCallback *r; + for (r = rectWithCallbacks; r->_xMin != 0xffff; ++r) { + if (r->contains(_mouseX, _mouseY)) { + (this->*(r->_callback))(); + return; + } + } } -} // End of namespace DreamGen +} // End of namespace DreamWeb diff --git a/engines/dreamweb/stubs.h b/engines/dreamweb/stubs.h deleted file mode 100644 index 4308bd54ea..0000000000 --- a/engines/dreamweb/stubs.h +++ /dev/null @@ -1,572 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ -#ifndef DREAMWEB_STUBS_H -#define DREAMWEB_STUBS_H - - void screenUpdate(); - void startup(); - void startup1(); - void switchRyanOn(); - void switchRyanOff(); - uint16 allocateMem(uint16 paragraphs); - void deallocateMem(uint16 segment); - uint16 standardLoad(const char *fileName, uint16 *outSizeInBytes = NULL); // Returns a segment handle which needs to be freed with deallocatemem for symmetry - void *standardLoadCPP(const char *fileName, uint16 *outSizeInBytes = NULL); // And this one should be 'free'd - void loadIntoTemp(); - void loadIntoTemp(const char *fileName); - void loadIntoTemp2(const char *fileName); - void loadIntoTemp3(const char *fileName); - void loadTempCharset(); - void loadTempCharset(const char *fileName); - void saveLoad(); - void delChar(); - void hangOnCurs(uint16 frameCount); - void hangOnCurs(); - void workToScreen(); - void multiGet(); - void multiGet(uint8 *dst, uint16 x, uint16 y, uint8 width, uint8 height) { - DreamBase::multiGet(dst, x, y, width, height); - } - void multiPut(); - void multiPut(const uint8 *src, uint16 x, uint16 y, uint8 width, uint8 height) { - DreamBase::multiPut(src, x, y, width, height); - } - void multiDump(); - void multiDump(uint16 x, uint16 y, uint8 width, uint8 height) { - DreamBase::multiDump(x, y, width, height); - } - void printSprites(); - void quickQuit(); - void readOneBlock(); - void readCityPic(); - void readDestIcon(); - void seeCommandTail(); - void randomNumber(); - void quickQuit2(); - void printDirect(); - uint8 printDirect(const uint8** string, uint16 x, uint16 *y, uint8 maxWidth, bool centered) { - return DreamBase::printDirect(string, x, y, maxWidth, centered); - } - uint8 printDirect(const uint8* string, uint16 x, uint16 y, uint8 maxWidth, bool centered) { - return DreamBase::printDirect(string, x, y, maxWidth, centered); - } - void printMessage(uint16 x, uint16 y, uint8 index, uint8 maxWidth, bool centered); - void printMessage(); - void useTimedText(); - void dumpTimedText(); - void setupTimedTemp(uint8 textIndex, uint8 voiceIndex, uint8 x, uint8 y, uint16 countToTimed, uint16 timeCount); - void getUnderTimed(); - void putUnderTimed(); - void dumpTextLine(); - void oldToNames(); - void namesToOld(); - void startLoading(const Room &room); - void showFrame(); - void showFrame(const Frame *frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag, uint8 *width, uint8 *height) { - DreamBase::showFrame(frameData, x, y, frameNumber, effectsFlag, width, height); - } - void showFrame(const Frame *frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag) { - DreamBase::showFrame(frameData, x, y, frameNumber, effectsFlag); - } - void printASprite(const Sprite *sprite); - void width160(); - void eraseOldObs(); - void clearSprites(); - Sprite *makeSprite(uint8 x, uint8 y, uint16 updateCallback, uint16 frameData, uint16 somethingInDi); - void spriteUpdate(); - void initMan(); - void mainMan(Sprite *sprite); - void mainMan(); - void walking(Sprite *sprite); - void aboutTurn(Sprite *sprite); - void backObject(Sprite *sprite); - void backObject(); - void constant(Sprite *sprite, SetObject *objData); - void steady(Sprite *sprite, SetObject *objData); - void randomSprite(Sprite *sprite, SetObject *objData); - void doDoor(Sprite *sprite, SetObject *objData, Common::Rect check); - void doorway(Sprite *sprite, SetObject *objData); - void wideDoor(Sprite *sprite, SetObject *objData); - void lockedDoorway(Sprite *sprite, SetObject *objData); - void liftSprite(Sprite *sprite, SetObject *objData); - void showGameReel(); - void showGameReel(ReelRoutine *routine); - void turnPathOn(uint8 param); - void turnPathOff(uint8 param); - void turnPathOn(); - void turnPathOff(); - void turnAnyPathOn(uint8 param, uint8 room); - void turnAnyPathOff(uint8 param, uint8 room); - void turnAnyPathOn(); - void turnAnyPathOff(); - void makeBackOb(SetObject *objData); - void dealWithSpecial(uint8 firstParam, uint8 secondParam); - void zoom(); - void showRain(); - void delTextLine(); - void commandOnly(); - void commandOnly(uint8 command); - void doBlocks(); - void checkIfPerson(); - bool checkIfPerson(uint8 x, uint8 y); - void checkIfFree(); - bool checkIfFree(uint8 x, uint8 y); - void checkIfEx(); - bool checkIfEx(uint8 x, uint8 y); - const uint8 *findObName(uint8 type, uint8 index); - void copyName(); - void copyName(uint8 type, uint8 index, uint8 *dst); - void commandWithOb(); - void commandWithOb(uint8 command, uint8 type, uint8 index); - void updatePeople(); - void madman(ReelRoutine &routine); - void madmanText(); - void madMode(); - void moveMap(uint8 param); - bool addAlong(const uint8 *mapFlags); - bool addLength(const uint8 *mapFlags); - void getDimension(); - void getDimension(uint8 *mapXstart, uint8 *mapYstart, uint8 *mapXsize, uint8 *mapYsize); - void getMapAd(); - void calcMapAd(); - uint8 getMapAd(const uint8 *setData); - uint8 getXAd(const uint8 *setData, uint8 *result); - uint8 getYAd(const uint8 *setData, uint8 *result); - void calcFrFrame(uint16 frame); - void calcFrFrame(uint16 frame, uint8* width, uint8* height); - void finalFrame(); - void finalFrame(uint16 *x, uint16 *y); - void showAllObs(); - void blockNameText(); - void walkToText(); - void personNameText(); - DynObject *getFreeAd(uint8 index) { - return DreamBase::getFreeAd(index); - } - DynObject *getExAd(uint8 index) { - return DreamBase::getExAd(index); - } - DynObject *getEitherAdCPP(); - void *getAnyAd(uint8 *value1, uint8 *value2) { - return DreamBase::getAnyAd(value1, value2); - } - SetObject *getSetAd(uint8 index) { - return DreamBase::getSetAd(index); - } - void *getAnyAdDir(uint8 index, uint8 flag); - void setAllChanges(); - void doChange(uint8 index, uint8 value, uint8 type); - void deleteTaken(); - bool isCD(); - void placeSetObject(); - void placeSetObject(uint8 index); - void removeSetObject(); - void removeSetObject(uint8 index); - void showAllFree(); - void showAllEx(); - bool finishedWalkingCPP(); - void finishedWalking(); - void checkOne(); - void checkOne(uint8 x, uint8 y, uint8 *flag, uint8 *flagEx, uint8 *type, uint8 *flagX, uint8 *flagY); - void getFlagUnderP(); - void getFlagUnderP(uint8 *flag, uint8 *flagEx); - void walkAndExamine(); - void obName(); - void obName(uint8 command, uint8 commandType); - void animPointer(); - void checkCoords(const RectWithCallback *rectWithCallbacks); - void drawFlags(); - void addToPeopleList(); - void addToPeopleList(ReelRoutine *routine); - void getExPos(); - void obPicture(); - void compare(); - bool compare(uint8 index, uint8 flag, const char id[4]); - bool pixelCheckSet(const ObjPos *pos, uint8 x, uint8 y); - bool isItDescribed(const ObjPos *objPos); - void checkIfSet(); - bool checkIfSet(uint8 x, uint8 y); - void checkIfPathIsOn(); - bool checkIfPathIsOn(uint8 index); - void isItWorn(); - bool isItWorn(const DynObject *object); - void wornError(); - void makeWorn(); - void makeWorn(DynObject *object); - void obToInv(); - void obToInv(uint8 index, uint8 flag, uint16 x, uint16 y); - void findAllRyan(); - void findAllRyan(uint8 *inv); - void fillRyan(); - void useRoutine(); - void hangOn(); - void hangOn(uint16 frameCount) { - DreamBase::hangOn(frameCount); - } - void hangOnW(); - void hangOnW(uint16 frameCount); - void hangOnP(); - void hangOnP(uint16 count); - void showIcon(); - uint8 findNextColon(uint8 **string); - void findNextColon(); - uint8 *getObTextStartCPP(); - void useText(const uint8 *string); - void useText(); - void getBlockOfPixel(); - uint8 getBlockOfPixel(uint8 x, uint8 y); - void examineObText(); - void sortOutMap(); - void showCity(); - uint16 getPersFrame(uint8 index); - void convIcons(); - void examineOb(bool examineAgain = true); - void dumpWatch(); - void roomName(); - void transferText(); - void initRain(); - Rain *splitIntoLines(uint8 x, uint8 y, Rain *rain); - void watchCount(); - void zoomIcon(); - void loadRoom(); - void getUnderMenu(); - void putUnderMenu(); - void textForMonk(); - void textForMonkHelper(uint8 textIndex, uint8 voiceIndex, uint8 x, uint8 y, uint16 countToTimed, uint16 timeCount); - void textForEnd(); - void monks2text(); - void intro1Text(); - void intro2Text(); - void intro3Text(); - void readSetData(); - void fadeupYellows(); - void fadeupMonFirst(); - void loadMenu(); - void showMenu(); - void dumpMenu(); - void useMenu(); - void useMon(); - void input(); - void monPrint(); - const char *monPrint(const char *string) { - return DreamBase::monPrint(string); - } - void randomAccess(uint16 count); - void randomAccess(); - void monMessage(uint8 index); - void monMessage(); - void netError(); - void playChannel1(); - void playChannel1(uint8 index) { - DreamBase::playChannel1(index); - } - void showMainOps(); - void showDiscOps(); - void findRoomInLoc(); - void reelsOnScreen(); - void reconstruct(); - void look(); - void autoLook(); - void doLook(); - void useTempCharset(); - void useCharset1(); - void getBackFromOb(); - void getRidOfAll(); - void getRidOfTemp(); - void getRidOfTempText(); - void getRidOfTemp2(); - void getRidOfTemp3(); - void getRidOfTempCharset(); - void getRidOfTempsP(); - void showFirstUse(); - void showSecondUse(); - void actualSave(); - void actualLoad(); - void loadPosition(unsigned int slot); - void savePosition(unsigned int slot, const char *descbuf); - uint16 allocateAndLoad(unsigned int size); - void clearAndLoad(uint8 *buf, uint8 c, unsigned int size, unsigned int maxSize); - void clearAndLoad(uint16 seg, uint8 c, unsigned int size, unsigned int maxSize); - void loadRoomData(const Room &room, bool skipDat); - void restoreAll(); - void restoreReels(); - void enterSymbol(); - void viewFolder(); - void edensCDPlayer(); - void hotelBell(); - void playGuitar(); - void callEdensDLift(); - void callEdensLift(); - void sitDownInBar(); - void trapDoor(); - void useBalcony(); - void useChurchHole(); - void useCoveredBox(); - void useElevator1(); - void useElevator2(); - void useElevator3(); - void useElevator4(); - void useElevator5(); - void useDryer(); - void useRailing(); - void useWindow(); - void useHatch(); - void useLighter(); - void wheelSound(); - void callHotelLift(); - void useShield(); - void useWall(); - void useChurchGate(); - void useFullCart(); - void useClearBox(); - void usePlate(); - void usePlinth(); - void useElvDoor(); - void useObject(); - void useWinch(); - void useCardReader1(); - void useCardReader2(); - void useCardReader3(); - void usePoolReader(); - void useCooker(); - void useWire(); - bool defaultUseHandler(const char *id); - void openTVDoor(); - void wearWatch(); - void wearShades(); - void checkFolderCoords(); - void loadFolder(); - void showFolder(); - void showLeftPage(); - void showRightPage(); - void nextFolder(); - void lastFolder(); - void folderHints(); - void folderExit(); - uint8 getLocation(uint8 index); - void getLocation(); - void setLocation(uint8 index); - void setLocation(); - void loadTempText(); - void loadTempText(const char *fileName); - void loadTravelText(); - void drawFloor(); - void allocateBuffers(); - void workToScreenM(); - bool checkSpeed(ReelRoutine &routine); - void checkSpeed(); - void sparkyDrip(ReelRoutine &routine); - void genericPerson(ReelRoutine &routine); - void gamer(ReelRoutine &routine); - void eden(ReelRoutine &routine); - void sparky(ReelRoutine &routine); - void rockstar(ReelRoutine &routine); - void madmansTelly(ReelRoutine &routine); - void smokeBloke(ReelRoutine &routine); - void manAsleep(ReelRoutine &routine); - void drunk(ReelRoutine &routine); - void introMagic1(ReelRoutine &routine); - void introMagic2(ReelRoutine &routine); - void introMagic3(ReelRoutine &routine); - void introMusic(ReelRoutine &routine); - void candles(ReelRoutine &routine); - void candles1(ReelRoutine &routine); - void candles2(ReelRoutine &routine); - void smallCandle(ReelRoutine &routine); - void gates(ReelRoutine &routine); - void security(ReelRoutine &routine); - void edenInBath(ReelRoutine &routine); - void louis(ReelRoutine &routine); - void handClap(ReelRoutine &routine); - void carParkDrip(ReelRoutine &routine); - void foghornSound(ReelRoutine &routine); - void train(ReelRoutine &routine); - void attendant(ReelRoutine &routine); - void keeper(ReelRoutine &routine); - void interviewer(ReelRoutine &routine); - void drinker(ReelRoutine &routine); - void alleyBarkSound(ReelRoutine &routine); - void louisChair(ReelRoutine &routine); - void bossMan(ReelRoutine &routine); - void priest(ReelRoutine &routine); - void priestText(ReelRoutine &routine); - void monkAndRyan(ReelRoutine &routine); - void copper(ReelRoutine &routine); - void introMonks1(ReelRoutine &routine); - void introMonks2(ReelRoutine &routine); - void soldier1(ReelRoutine &routine); - void singleKey(uint8 key, uint16 x, uint16 y); - void loadSaveBox(); - void loadKeypad(); - void showKeypad(); - void showOuterPad(); - uint8 nextSymbol(uint8 symbol); - void showSymbol(); - void examIcon(); - void buttonOne(); - void buttonTwo(); - void buttonThree(); - void buttonFour(); - void buttonFive(); - void buttonSix(); - void buttonSeven(); - void buttonEight(); - void buttonNine(); - void buttonNought(); - void buttonEnter(); - void buttonPress(uint8 buttonId); - void addToPressList(); - bool isItRight(uint8 digit0, uint8 digit1, uint8 digit2, uint8 digit3); - void enterCode(uint8 digit0, uint8 digit1, uint8 digit2, uint8 digit3); - unsigned int scanForNames(); - void doLoad(int slot); - void loadOld(); - void inventory(); - void mainScreen(); - void loadGame(); - void saveGame(); - void zoomOnOff(); - void atmospheres(); - void loadPersonal(); - void loadNews(); - void loadCart(); - void hangOne(uint16 delay); - void hangOne(); - void bibleQuote(); - void realCredits(); - void runIntroSeq(); - void intro(); - void clearBeforeLoad(); - void clearReels(); - void getRidOfReels(); - void liftNoise(uint8 index); - void setTopLeft(); - void setTopRight(); - void setBotLeft(); - void setBotRight(); - void newGame(); - void getBackFromOps(); - void getBackToOps(); - void pickupOb(uint8 command, uint8 pos); - void initialInv(); - void walkIntoRoom(); - void loadIntroRoom(); - void afterIntroRoom(); - void gettingShot(); - void redrawMainScrn(); - void selectSlot2(); - void blank(); - void allPointer(); - void openYourNeighbour(); - void openRyan(); - void openPoolBoss(); - void openEden(); - void openSarters(); - void openLouis(); - void DOSReturn(); - void useLadder(); - void useLadderB(); - void useCart(); - void useTrainer(); - void useHole(); - void chewy(); - void sLabDoorA(); - void sLabDoorB(); - void sLabDoorC(); - void sLabDoorE(); - void sLabDoorD(); - void sLabDoorF(); - void openHotelDoor(); - void openHotelDoor2(); - void grafittiDoor(); - void openTomb(); - void hotelControl(); - void obsThatDoThings(); - void makeMainScreen(); - void openInv(); - void delEverything(); - void clearPalette(); - void errorMessage1(); - void errorMessage2(); - void errorMessage3(); - void reExFromOpen(); - void nextDest(); - void lastDest(); - void destSelect(); - void putBackObStuff(); - void moreTalk(); - void redes(); - void isSetObOnMap(); - bool isSetObOnMap(uint8 index); - void dumpKeypad(); - void dumpSymbol(); - void dumpSymBox(); - void dumpZoom(); - void selectLocation(); - void showGroup(); - void loadSpeech(); - bool loadSpeech(byte type1, int idx1, byte type2, int idx2) { - return DreamBase::loadSpeech(type1, idx1, type2, idx2); - } - void getTime(); - void set16ColPalette(); - void examineInventory(); - void showSaveOps(); - void showLoadOps(); - void watchReel(); - void showWatchReel(); - void plotReel(uint16 &reelPointer); - void removeFreeObject(uint8 index) { - DreamBase::removeFreeObject(index); - } - void afterNewRoom(); - void madmanRun(); - void showDecisions(); - void underTextLine(); - void getUnderZoom(); - void putUnderZoom(); - void decide(); - void talk(); - void discOps(); - void doSaveLoad(); - void useDiary(); - void hangOnPQ(); - void showGun(); - void endGame(); - void monitorLogo(); - void quitSymbol(); - void diaryKeyP(); - void diaryKeyN(); - void checkInput(); - void dropError(); - void cantDrop(); - void getBack1(); - void newPlace(); - void showPuzText(uint16 command, uint16 count); - void showPuzText(); - void monkSpeaking(); - void rollEndCredits2(); - void useButtonA(); - void autoAppear(); - void quitKey(); - -#endif diff --git a/engines/dreamweb/talk.cpp b/engines/dreamweb/talk.cpp index 86d1b886ef..0f59cad895 100644 --- a/engines/dreamweb/talk.cpp +++ b/engines/dreamweb/talk.cpp @@ -22,17 +22,242 @@ #include "dreamweb/dreamweb.h" -namespace DreamGen { +namespace DreamWeb { -uint16 DreamGenContext::getPersFrame(uint8 index) { - return getSegment(data.word(kPeople)).word(kPersonframes + index * 2); +void DreamWebEngine::talk() { + _talkPos = 0; + _inMapArea = 0; + _character = _command; + createPanel(); + showPanel(); + showMan(); + showExit(); + underTextLine(); + convIcons(); + startTalk(); + _commandType = 255; + readMouse(); + showPointer(); + workToScreen(); + + RectWithCallback talkList[] = { + { 273,320,157,198,&DreamWebEngine::getBack1 }, + { 240,290,2,44,&DreamWebEngine::moreTalk }, + { 0,320,0,200,&DreamWebEngine::blank }, + { 0xFFFF,0,0,0,0 } + }; + + do { + delPointer(); + readMouse(); + animPointer(); + showPointer(); + vSync(); + dumpPointer(); + dumpTextLine(); + _getBack = 0; + checkCoords(talkList); + if (_quitRequested) + break; + } while (!_getBack); + + if (_talkPos >= 4) + _personData->b7 |= 128; + + redrawMainScrn(); + workToScreenM(); + if (_speechLoaded) { + cancelCh1(); + _volumeDirection = -1; + _volumeTo = 0; + } } -void DreamGenContext::convIcons() { - uint8 index = data.byte(kCharacter) & 127; +void DreamWebEngine::convIcons() { + uint8 index = _character & 127; uint16 frame = getPersFrame(index); - const Frame *base = findSource(frame); - showFrame(base, 234, 2, frame, 0); + const GraphicsFile *base = findSource(frame); + showFrame(*base, 234, 2, frame, 0); +} + +uint16 DreamWebEngine::getPersFrame(uint8 index) { + return READ_LE_UINT16(&_personFramesLE[index]); +} + +void DreamWebEngine::startTalk() { + _talkMode = 0; + + const uint8 *str = getPersonText(_character & 0x7F, 0); + uint16 y; + + _charShift = 91+91; + y = 64; + printDirect(&str, 66, &y, 241, true); + + _charShift = 0; + y = 80; + printDirect(&str, 66, &y, 241, true); + + if (hasSpeech()) { + _speechLoaded = false; + loadSpeech('R', _realLocation, 'C', 64*(_character & 0x7F)); + if (_speechLoaded) { + _volumeDirection = 1; + _volumeTo = 6; + playChannel1(50 + 12); + } + } +} + +const uint8 *DreamWebEngine::getPersonText(uint8 index, uint8 talkPos) { + return (const uint8 *)_personText.getString(index*64 + talkPos); +} + +void DreamWebEngine::moreTalk() { + if (_talkMode != 0) { + redes(); + return; + } + + commandOnlyCond(49, 215); + + if (_mouseButton == _oldButton) + return; // nomore + + if (!(_mouseButton & 1)) + return; + + _talkMode = 2; + _talkPos = 4; + + if (_character >= 100) + _talkPos = 48; // second part + doSomeTalk(); +} + +void DreamWebEngine::doSomeTalk() { + // FIXME: This is for the CD version only + + while (true) { + const uint8 *str = getPersonText(_character & 0x7F, _talkPos); + + if (*str == 0) { + // endheartalk + _pointerMode = 0; + return; + } + + createPanel(); + showPanel(); + showMan(); + showExit(); + convIcons(); + + printDirect(str, 164, 64, 144, false); + + loadSpeech('R', _realLocation, 'C', (64 * (_character & 0x7F)) + _talkPos); + if (_speechLoaded) + playChannel1(62); + + _pointerMode = 3; + workToScreenM(); + if (hangOnPQ()) + return; + + _talkPos++; + + str = getPersonText(_character & 0x7F, _talkPos); + if (*str == 0) { + // endheartalk + _pointerMode = 0; + return; + } + + if (*str != ':' && *str != 32) { + createPanel(); + showPanel(); + showMan(); + showExit(); + convIcons(); + printDirect(str, 48, 128, 144, false); + + loadSpeech('R', _realLocation, 'C', (64 * (_character & 0x7F)) + _talkPos); + if (_speechLoaded) + playChannel1(62); + + _pointerMode = 3; + workToScreenM(); + if (hangOnPQ()) + return; + } + + _talkPos++; + } +} + +bool DreamWebEngine::hangOnPQ() { + _getBack = 0; + + RectWithCallback quitList[] = { + { 273,320,157,198,&DreamWebEngine::getBack1 }, + { 0,320,0,200,&DreamWebEngine::blank }, + { 0xFFFF,0,0,0,0 } + }; + + uint16 speechFlag = 0; + + do { + delPointer(); + readMouse(); + animPointer(); + showPointer(); + vSync(); + dumpPointer(); + dumpTextLine(); + checkCoords(quitList); + + if (_getBack == 1 || _quitRequested) { + // Quit conversation + delPointer(); + _pointerMode = 0; + cancelCh1(); + return true; + } + + if (_speechLoaded && _channel1Playing == 255) { + speechFlag++; + if (speechFlag == 40) + break; + } + } while (!_mouseButton || _oldButton); + + delPointer(); + _pointerMode = 0; + return false; +} + +void DreamWebEngine::redes() { + if (_channel1Playing != 255 || _talkMode != 2) { + blank(); + return; + } + + commandOnlyCond(50, 217); + + if (!(_mouseButton & 1)) + return; + + delPointer(); + createPanel(); + showPanel(); + showMan(); + showExit(); + convIcons(); + startTalk(); + readMouse(); + showPointer(); + workToScreen(); + delPointer(); } -} // End of namespace DreamGen +} // End of namespace DreamWeb diff --git a/engines/dreamweb/titles.cpp b/engines/dreamweb/titles.cpp new file mode 100644 index 0000000000..f7486ce687 --- /dev/null +++ b/engines/dreamweb/titles.cpp @@ -0,0 +1,444 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "dreamweb/dreamweb.h" +#include "engines/util.h" + +namespace DreamWeb { + +void DreamWebEngine::endGame() { + loadTempText("T83"); + monkSpeaking(); + if (_quitRequested) + return; + gettingShot(); + getRidOfTempText(); + _volumeTo = 7; + _volumeDirection = 1; + hangOn(200); +} + +void DreamWebEngine::monkSpeaking() { + _roomsSample = 35; + loadRoomsSample(); + GraphicsFile graphics; + loadGraphicsFile(graphics, "G15"); + clearWork(); + showFrame(graphics, 160, 72, 0, 128); // show monk + workToScreen(); + _volume = 7; + _volumeDirection = -1; + _volumeTo = hasSpeech() ? 5 : 0; + playChannel0(12, 255); + fadeScreenUps(); + hangOn(300); + + // TODO: Subtitles+speech mode + if (hasSpeech()) { + for (int i = 40; i < 48; i++) { + loadSpeech('T', 83, 'T', i); + + playChannel1(50 + 12); + + do { + waitForVSync(); + if (_quitRequested) + return; + } while (_channel1Playing != 255); + } + } else { + for (int i = 40; i <= 44; i++) { + uint8 printResult = 0; + const uint8 *string = getTextInFile1(i); + + do { + uint16 y = 140; + printResult = printDirect(&string, 36, &y, 239, 239 & 1); + workToScreen(); + clearWork(); + showFrame(graphics, 160, 72, 0, 128); // show monk + hangOnP(240); + if (_quitRequested) + return; + } while (printResult != 0); + } + } + + _volumeDirection = 1; + _volumeTo = 7; + fadeScreenDowns(); + hangOn(300); + graphics.clear(); +} + +void DreamWebEngine::gettingShot() { + _newLocation = 55; + clearPalette(); + loadIntroRoom(); + fadeScreenUps(); + _volumeTo = 0; + _volumeDirection = -1; + runEndSeq(); + clearBeforeLoad(); +} + +void DreamWebEngine::bibleQuote() { + initGraphics(640, 480, true); + + showPCX("I00"); + fadeScreenUps(); + + hangOne(80); + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "biblequotearly" + } + + hangOne(560); + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "biblequotearly" + } + + fadeScreenDowns(); + + hangOne(200); + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "biblequotearly" + } + + cancelCh0(); + + _lastHardKey = 0; +} + +void DreamWebEngine::hangOne(uint16 delay) { + do { + vSync(); + if (_lastHardKey == 1) + return; // "hangonearly" + } while (--delay); +} + +void DreamWebEngine::intro() { + loadTempText("T82"); + loadPalFromIFF(); + setMode(); + _newLocation = 50; + clearPalette(); + loadIntroRoom(); + _volume = 7; + _volumeDirection = -1; + _volumeTo = hasSpeech() ? 4 : 0; + playChannel0(12, 255); + fadeScreenUps(); + runIntroSeq(); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "introearly" + } + + clearBeforeLoad(); + _newLocation = 52; + loadIntroRoom(); + runIntroSeq(); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "introearly" + } + + clearBeforeLoad(); + _newLocation = 53; + loadIntroRoom(); + runIntroSeq(); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "introearly" + } + + clearBeforeLoad(); + allPalette(); + _newLocation = 54; + loadIntroRoom(); + runIntroSeq(); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "introearly" + } + + getRidOfTempText(); + clearBeforeLoad(); + + _lastHardKey = 0; +} + +void DreamWebEngine::runIntroSeq() { + _getBack = 0; + + do { + vSync(); + + if (_lastHardKey == 1) + break; + + spriteUpdate(); + vSync(); + + if (_lastHardKey == 1) + break; + + delEverything(); + printSprites(); + reelsOnScreen(); + afterIntroRoom(); + useTimedText(); + vSync(); + + if (_lastHardKey == 1) + break; + + dumpMap(); + dumpTimedText(); + vSync(); + + if (_lastHardKey == 1) + break; + + } while (_getBack != 1); + + + if (_lastHardKey == 1) { + getRidOfTempText(); + clearBeforeLoad(); + } + + // These were not called in this program arc + // in the original code.. Bug? + //getRidOfTempText(); + //clearBeforeLoad(); +} + +void DreamWebEngine::runEndSeq() { + atmospheres(); + _getBack = 0; + + do { + vSync(); + spriteUpdate(); + vSync(); + delEverything(); + printSprites(); + reelsOnScreen(); + afterIntroRoom(); + useTimedText(); + vSync(); + dumpMap(); + dumpTimedText(); + vSync(); + } while (_getBack != 1 && !_quitRequested); +} + +void DreamWebEngine::loadIntroRoom() { + _introCount = 0; + _vars._location = 255; + loadRoom(); + _mapOffsetX = 72; + _mapOffsetY = 16; + clearSprites(); + _vars._throughDoor = 0; + _currentKey = '0'; + _mainMode = 0; + clearWork(); + _vars._newObs = 1; + drawFloor(); + reelsOnScreen(); + spriteUpdate(); + printSprites(); + workToScreen(); +} + +void DreamWebEngine::set16ColPalette() { +} + +void DreamWebEngine::realCredits() { + _roomsSample = 33; + loadRoomsSample(); + _volume = 0; + + initGraphics(640, 480, true); + hangOn(35); + + showPCX("I01"); + playChannel0(12, 0); + + hangOne(2); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + allPalette(); + hangOne(80); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + fadeScreenDowns(); + hangOne(256); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + showPCX("I02"); + playChannel0(12, 0); + hangOne(2); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + allPalette(); + hangOne(80); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + fadeScreenDowns(); + hangOne(256); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + showPCX("I03"); + playChannel0(12, 0); + hangOne(2); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + allPalette(); + hangOne(80); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + fadeScreenDowns(); + hangOne(256); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + showPCX("I04"); + playChannel0(12, 0); + hangOne(2); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + allPalette(); + hangOne(80); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + fadeScreenDowns(); + hangOne(256); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + showPCX("I05"); + playChannel0(12, 0); + hangOne(2); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + allPalette(); + hangOne(80); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + fadeScreenDowns(); + hangOne(256); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + showPCX("I06"); + fadeScreenUps(); + hangOne(60); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + playChannel0(13, 0); + hangOne(350); + + if (_lastHardKey == 1) { + _lastHardKey = 0; + return; // "realcreditsearly" + } + + fadeScreenDowns(); + hangOne(256); + + _lastHardKey = 0; +} + +} // End of namespace DreamWeb diff --git a/engines/dreamweb/use.cpp b/engines/dreamweb/use.cpp index 0990e5ba5e..e59843539f 100644 --- a/engines/dreamweb/use.cpp +++ b/engines/dreamweb/use.cpp @@ -22,10 +22,10 @@ #include "dreamweb/dreamweb.h" -namespace DreamGen { +namespace DreamWeb { -typedef void (DreamGenContext::*UseCallback)(void); +typedef void (DreamWebEngine::*UseCallback)(void); // Note: The callback pointer has been placed before the // ID to keep MSVC happy (otherwise, it throws warnings @@ -35,111 +35,111 @@ struct UseListEntry { const char *id; }; -void DreamGenContext::useRoutine() { +void DreamWebEngine::useRoutine() { static const UseListEntry kUseList[] = { - { &DreamGenContext::useMon, "NETW" }, - { &DreamGenContext::useElevator1, "ELVA" }, - { &DreamGenContext::useElevator2, "ELVB" }, - { &DreamGenContext::useElevator3, "ELVC" }, - { &DreamGenContext::useElevator4, "ELVE" }, - { &DreamGenContext::useElevator5, "ELVF" }, - { &DreamGenContext::useChurchGate, "CGAT" }, - { &DreamGenContext::useStereo, "REMO" }, - { &DreamGenContext::useButtonA, "BUTA" }, - { &DreamGenContext::useWinch, "CBOX" }, - { &DreamGenContext::useLighter, "LITE" }, - { &DreamGenContext::usePlate, "PLAT" }, - { &DreamGenContext::useControl, "LIFT" }, - { &DreamGenContext::useWire, "WIRE" }, - { &DreamGenContext::useHandle, "HNDL" }, - { &DreamGenContext::useHatch, "HACH" }, - { &DreamGenContext::useElvDoor, "DOOR" }, - { &DreamGenContext::useCashCard, "CSHR" }, - { &DreamGenContext::useGun, "GUNA" }, - { &DreamGenContext::useCardReader1, "CRAA" }, - { &DreamGenContext::useCardReader2, "CRBB" }, - { &DreamGenContext::useCardReader3, "CRCC" }, - { &DreamGenContext::sitDownInBar, "SEAT" }, - { &DreamGenContext::useMenu, "MENU" }, - { &DreamGenContext::useCooker, "COOK" }, - { &DreamGenContext::callHotelLift, "ELCA" }, - { &DreamGenContext::callEdensLift, "EDCA" }, - { &DreamGenContext::callEdensDLift, "DDCA" }, - { &DreamGenContext::useAltar, "ALTR" }, - { &DreamGenContext::openHotelDoor, "LOKA" }, - { &DreamGenContext::openHotelDoor2, "LOKB" }, - { &DreamGenContext::openLouis, "ENTA" }, - { &DreamGenContext::openRyan, "ENTB" }, - { &DreamGenContext::openPoolBoss, "ENTE" }, - { &DreamGenContext::openYourNeighbour, "ENTC" }, - { &DreamGenContext::openEden, "ENTD" }, - { &DreamGenContext::openSarters, "ENTH" }, - { &DreamGenContext::wearWatch, "WWAT" }, - { &DreamGenContext::usePoolReader, "POOL" }, - { &DreamGenContext::wearShades, "WSHD" }, - { &DreamGenContext::grafittiDoor, "GRAF" }, - { &DreamGenContext::trapDoor, "TRAP" }, - { &DreamGenContext::edensCDPlayer, "CDPE" }, - { &DreamGenContext::openTVDoor, "DLOK" }, - { &DreamGenContext::useHole, "HOLE" }, - { &DreamGenContext::useDryer, "DRYR" }, - { &DreamGenContext::useChurchHole, "HOLY" }, - { &DreamGenContext::useWall, "WALL" }, - { &DreamGenContext::useDiary, "BOOK" }, - { &DreamGenContext::useAxe, "AXED" }, - { &DreamGenContext::useShield, "SHLD" }, - { &DreamGenContext::useRailing, "BCNY" }, - { &DreamGenContext::useCoveredBox, "LIDC" }, - { &DreamGenContext::useClearBox, "LIDU" }, - { &DreamGenContext::useOpenBox, "LIDO" }, - { &DreamGenContext::usePipe, "PIPE" }, - { &DreamGenContext::useBalcony, "BALC" }, - { &DreamGenContext::useWindow, "WIND" }, - { &DreamGenContext::viewFolder, "PAPR" }, - { &DreamGenContext::useTrainer, "UWTA" }, - { &DreamGenContext::useTrainer, "UWTB" }, - { &DreamGenContext::enterSymbol, "STAT" }, - { &DreamGenContext::openTomb, "TLID" }, - { &DreamGenContext::useSLab, "SLAB" }, - { &DreamGenContext::useCart, "CART" }, - { &DreamGenContext::useFullCart, "FCAR" }, - { &DreamGenContext::sLabDoorA, "SLBA" }, - { &DreamGenContext::sLabDoorB, "SLBB" }, - { &DreamGenContext::sLabDoorC, "SLBC" }, - { &DreamGenContext::sLabDoorD, "SLBD" }, - { &DreamGenContext::sLabDoorE, "SLBE" }, - { &DreamGenContext::sLabDoorF, "SLBF" }, - { &DreamGenContext::usePlinth, "PLIN" }, - { &DreamGenContext::useLadder, "LADD" }, - { &DreamGenContext::useLadderB, "LADB" }, - { &DreamGenContext::chewy, "GUMA" }, - { &DreamGenContext::wheelSound, "SQEE" }, - { &DreamGenContext::runTap, "TAPP" }, - { &DreamGenContext::playGuitar, "GUIT" }, - { &DreamGenContext::hotelControl, "CONT" }, - { &DreamGenContext::hotelBell, "BELL" }, + { &DreamWebEngine::useMon, "NETW" }, + { &DreamWebEngine::useElevator1, "ELVA" }, + { &DreamWebEngine::useElevator2, "ELVB" }, + { &DreamWebEngine::useElevator3, "ELVC" }, + { &DreamWebEngine::useElevator4, "ELVE" }, + { &DreamWebEngine::useElevator5, "ELVF" }, + { &DreamWebEngine::useChurchGate, "CGAT" }, + { &DreamWebEngine::useStereo, "REMO" }, + { &DreamWebEngine::useButtonA, "BUTA" }, + { &DreamWebEngine::useWinch, "CBOX" }, + { &DreamWebEngine::useLighter, "LITE" }, + { &DreamWebEngine::usePlate, "PLAT" }, + { &DreamWebEngine::useControl, "LIFT" }, + { &DreamWebEngine::useWire, "WIRE" }, + { &DreamWebEngine::useHandle, "HNDL" }, + { &DreamWebEngine::useHatch, "HACH" }, + { &DreamWebEngine::useElvDoor, "DOOR" }, + { &DreamWebEngine::useCashCard, "CSHR" }, + { &DreamWebEngine::useGun, "GUNA" }, + { &DreamWebEngine::useCardReader1, "CRAA" }, + { &DreamWebEngine::useCardReader2, "CRBB" }, + { &DreamWebEngine::useCardReader3, "CRCC" }, + { &DreamWebEngine::sitDownInBar, "SEAT" }, + { &DreamWebEngine::useMenu, "MENU" }, + { &DreamWebEngine::useCooker, "COOK" }, + { &DreamWebEngine::callHotelLift, "ELCA" }, + { &DreamWebEngine::callEdensLift, "EDCA" }, + { &DreamWebEngine::callEdensDLift, "DDCA" }, + { &DreamWebEngine::useAltar, "ALTR" }, + { &DreamWebEngine::openHotelDoor, "LOKA" }, + { &DreamWebEngine::openHotelDoor2, "LOKB" }, + { &DreamWebEngine::openLouis, "ENTA" }, + { &DreamWebEngine::openRyan, "ENTB" }, + { &DreamWebEngine::openPoolBoss, "ENTE" }, + { &DreamWebEngine::openYourNeighbour, "ENTC" }, + { &DreamWebEngine::openEden, "ENTD" }, + { &DreamWebEngine::openSarters, "ENTH" }, + { &DreamWebEngine::wearWatch, "WWAT" }, + { &DreamWebEngine::usePoolReader, "POOL" }, + { &DreamWebEngine::wearShades, "WSHD" }, + { &DreamWebEngine::grafittiDoor, "GRAF" }, + { &DreamWebEngine::trapDoor, "TRAP" }, + { &DreamWebEngine::edensCDPlayer, "CDPE" }, + { &DreamWebEngine::openTVDoor, "DLOK" }, + { &DreamWebEngine::useHole, "HOLE" }, + { &DreamWebEngine::useDryer, "DRYR" }, + { &DreamWebEngine::useChurchHole, "HOLY" }, + { &DreamWebEngine::useWall, "WALL" }, + { &DreamWebEngine::useDiary, "BOOK" }, + { &DreamWebEngine::useAxe, "AXED" }, + { &DreamWebEngine::useShield, "SHLD" }, + { &DreamWebEngine::useRailing, "BCNY" }, + { &DreamWebEngine::useCoveredBox, "LIDC" }, + { &DreamWebEngine::useClearBox, "LIDU" }, + { &DreamWebEngine::useOpenBox, "LIDO" }, + { &DreamWebEngine::usePipe, "PIPE" }, + { &DreamWebEngine::useBalcony, "BALC" }, + { &DreamWebEngine::useWindow, "WIND" }, + { &DreamWebEngine::viewFolder, "PAPR" }, + { &DreamWebEngine::useTrainer, "UWTA" }, + { &DreamWebEngine::useTrainer, "UWTB" }, + { &DreamWebEngine::enterSymbol, "STAT" }, + { &DreamWebEngine::openTomb, "TLID" }, + { &DreamWebEngine::useSlab, "SLAB" }, + { &DreamWebEngine::useCart, "CART" }, + { &DreamWebEngine::useFullCart, "FCAR" }, + { &DreamWebEngine::slabDoorA, "SLBA" }, + { &DreamWebEngine::slabDoorB, "SLBB" }, + { &DreamWebEngine::slabDoorC, "SLBC" }, + { &DreamWebEngine::slabDoorD, "SLBD" }, + { &DreamWebEngine::slabDoorE, "SLBE" }, + { &DreamWebEngine::slabDoorF, "SLBF" }, + { &DreamWebEngine::usePlinth, "PLIN" }, + { &DreamWebEngine::useLadder, "LADD" }, + { &DreamWebEngine::useLadderB, "LADB" }, + { &DreamWebEngine::chewy, "GUMA" }, + { &DreamWebEngine::wheelSound, "SQEE" }, + { &DreamWebEngine::runTap, "TAPP" }, + { &DreamWebEngine::playGuitar, "GUIT" }, + { &DreamWebEngine::hotelControl, "CONT" }, + { &DreamWebEngine::hotelBell, "BELL" }, }; - if (data.byte(kReallocation) >= 50) { - if (data.byte(kPointerpower) == 0) + if (_realLocation >= 50) { + if (_pointerPower == 0) return; - data.byte(kPointerpower) = 0; + _pointerPower = 0; } - getAnyAd(); - const uint8 *id = es.ptr(bx + 12, 4); + uint8 dummy; + void *obj = getAnyAd(&dummy, &dummy); for (size_t i = 0; i < sizeof(kUseList)/sizeof(UseListEntry); ++i) { const UseListEntry &entry = kUseList[i]; - if (('A' + id[0] == entry.id[0]) && ('A' + id[1] == entry.id[1]) && ('A' + id[2] == entry.id[2]) && ('A' + id[3] == entry.id[3])) { + if (objectMatches(obj, entry.id)) { (this->*entry.callback)(); return; } } delPointer(); - uint8 *obText = getObTextStartCPP(); + const uint8 *obText = getObTextStart(); if (findNextColon(&obText) != 0) { if (findNextColon(&obText) != 0) { if (*obText != 0) { @@ -160,14 +160,10 @@ void DreamGenContext::useRoutine() { workToScreenM(); hangOnP(50); putBackObStuff(); - data.byte(kCommandtype) = 255; + _commandType = 255; } -void DreamGenContext::useText() { - useText(es.ptr(si, 0)); -} - -void DreamGenContext::useText(const uint8 *string) { +void DreamWebEngine::useText(const uint8 *string) { createPanel(); showPanel(); showMan(); @@ -177,16 +173,16 @@ void DreamGenContext::useText(const uint8 *string) { workToScreenM(); } -void DreamGenContext::showFirstUse() { - uint8 *obText = getObTextStartCPP(); +void DreamWebEngine::showFirstUse() { + const uint8 *obText = getObTextStart(); findNextColon(&obText); findNextColon(&obText); useText(obText); hangOnP(400); } -void DreamGenContext::showSecondUse() { - uint8 *obText = getObTextStartCPP(); +void DreamWebEngine::showSecondUse() { + const uint8 *obText = getObTextStart(); findNextColon(&obText); findNextColon(&obText); findNextColon(&obText); @@ -194,233 +190,204 @@ void DreamGenContext::showSecondUse() { hangOnP(400); } -void DreamGenContext::viewFolder() { - data.byte(kManisoffscreen) = 1; - getRidOfAll(); - loadFolder(); - data.byte(kFolderpage) = 0; - showFolder(); - workToScreenM(); - data.byte(kGetback) = 0; - do { - if (quitRequested()) - break; - delPointer(); - readMouse(); - showPointer(); - vSync(); - dumpPointer(); - dumpTextLine(); - checkFolderCoords(); - } while (data.byte(kGetback) == 0); - data.byte(kManisoffscreen) = 0; - getRidOfTemp(); - getRidOfTemp2(); - getRidOfTemp3(); - getRidOfTempCharset(); - restoreAll(); - redrawMainScrn(); - workToScreenM(); -} - -void DreamGenContext::edensCDPlayer() { +void DreamWebEngine::edensCDPlayer() { showFirstUse(); - data.word(kWatchingtime) = 18 * 2; - data.word(kReeltowatch) = 25; - data.word(kEndwatchreel) = 42; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; + _vars._watchingTime = 18 * 2; + _vars._reelToWatch = 25; + _vars._endWatchReel = 42; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; } -void DreamGenContext::hotelBell() { +void DreamWebEngine::hotelBell() { playChannel1(12); showFirstUse(); putBackObStuff(); } -void DreamGenContext::playGuitar() { +void DreamWebEngine::playGuitar() { playChannel1(14); showFirstUse(); putBackObStuff(); } -void DreamGenContext::useElevator1() { +void DreamWebEngine::useElevator1() { showFirstUse(); selectLocation(); - data.byte(kGetback) = 1; + _getBack = 1; } -void DreamGenContext::useElevator2() { +void DreamWebEngine::useElevator2() { showFirstUse(); - if (data.byte(kLocation) == 23) // In pool hall - data.byte(kNewlocation) = 31; + if (_vars._location == 23) // In pool hall + _newLocation = 31; else - data.byte(kNewlocation) = 23; + _newLocation = 23; - data.byte(kCounttoclose) = 20; - data.byte(kCounttoopen) = 0; - data.word(kWatchingtime) = 80; - data.byte(kGetback) = 1; + _vars._countToClose = 20; + _vars._countToOpen = 0; + _vars._watchingTime = 80; + _getBack = 1; } -void DreamGenContext::useElevator3() { +void DreamWebEngine::useElevator3() { showFirstUse(); - data.byte(kCounttoclose) = 20; - data.byte(kNewlocation) = 34; - data.word(kReeltowatch) = 46; - data.word(kEndwatchreel) = 63; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.word(kWatchingtime) = 80; - data.byte(kGetback) = 1; + _vars._countToClose = 20; + _newLocation = 34; + _vars._reelToWatch = 46; + _vars._endWatchReel = 63; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _vars._watchingTime = 80; + _getBack = 1; } -void DreamGenContext::useElevator4() { +void DreamWebEngine::useElevator4() { showFirstUse(); - data.word(kReeltowatch) = 0; - data.word(kEndwatchreel) = 11; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kCounttoclose) = 20; - data.word(kWatchingtime) = 80; - data.byte(kGetback) = 1; - data.byte(kNewlocation) = 24; + _vars._reelToWatch = 0; + _vars._endWatchReel = 11; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _vars._countToClose = 20; + _vars._watchingTime = 80; + _getBack = 1; + _newLocation = 24; } -void DreamGenContext::useElevator5() { +void DreamWebEngine::useElevator5() { placeSetObject(4); removeSetObject(0); - data.byte(kNewlocation) = 20; - data.word(kWatchingtime) = 80; - data.byte(kLiftflag) = 1; - data.byte(kCounttoclose) = 8; - data.byte(kGetback) = 1; + _newLocation = 20; + _vars._watchingTime = 80; + _vars._liftFlag = 1; + _vars._countToClose = 8; + _getBack = 1; } -void DreamGenContext::useHatch() { +void DreamWebEngine::useHatch() { showFirstUse(); - data.byte(kNewlocation) = 40; - data.byte(kGetback) = 1; + _newLocation = 40; + _getBack = 1; } -void DreamGenContext::wheelSound() { +void DreamWebEngine::wheelSound() { playChannel1(17); showFirstUse(); putBackObStuff(); } -void DreamGenContext::callHotelLift() { +void DreamWebEngine::callHotelLift() { playChannel1(12); showFirstUse(); - data.byte(kCounttoopen) = 8; - data.byte(kGetback) = 1; - data.byte(kDestination) = 5; - data.byte(kFinaldest) = 5; + _vars._countToOpen = 8; + _getBack = 1; + _destination = 5; + _finalDest = 5; autoSetWalk(); turnPathOn(4); } -void DreamGenContext::useShield() { - if (data.byte(kReallocation) != 20 || data.byte(kCombatcount) == 0) { +void DreamWebEngine::useShield() { + if (_realLocation != 20 || _vars._combatCount == 0) { // Not in Sart room showFirstUse(); putBackObStuff(); } else { - data.byte(kLastweapon) = 3; + _vars._lastWeapon = 3; showSecondUse(); - data.byte(kGetback) = 1; - data.byte(kProgresspoints)++; + _getBack = 1; + _vars._progressPoints++; removeObFromInv(); } } -void DreamGenContext::useCoveredBox() { - data.byte(kProgresspoints)++; +void DreamWebEngine::useCoveredBox() { + _vars._progressPoints++; showFirstUse(); - data.word(kWatchingtime) = 50; - data.word(kReeltowatch) = 41; - data.word(kEndwatchreel) = 66; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; + _vars._watchingTime = 50; + _vars._reelToWatch = 41; + _vars._endWatchReel = 66; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; } -void DreamGenContext::useRailing() { +void DreamWebEngine::useRailing() { showFirstUse(); - data.word(kWatchingtime) = 80; - data.word(kReeltowatch) = 0; - data.word(kEndwatchreel) = 30; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; - data.byte(kMandead) = 4; + _vars._watchingTime = 80; + _vars._reelToWatch = 0; + _vars._endWatchReel = 30; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; + _vars._manDead = 4; } -void DreamGenContext::wearWatch() { - if (data.byte(kWatchon) == 1) { +void DreamWebEngine::wearWatch() { + if (_vars._watchOn == 1) { // Already wearing watch showSecondUse(); putBackObStuff(); } else { showFirstUse(); - data.byte(kWatchon) = 1; - data.byte(kGetback) = 1; - getAnyAd(); - makeWorn(); + _vars._watchOn = 1; + _getBack = 1; + uint8 dummy; + makeWorn((DynObject *)getAnyAd(&dummy, &dummy)); } } -void DreamGenContext::wearShades() { - if (data.byte(kShadeson) == 1) { +void DreamWebEngine::wearShades() { + if (_vars._shadesOn == 1) { // Already wearing shades showSecondUse(); putBackObStuff(); } else { - data.byte(kShadeson) = 1; + _vars._shadesOn = 1; showFirstUse(); - data.byte(kGetback) = 1; - getAnyAd(); - makeWorn(); + _getBack = 1; + uint8 dummy; + makeWorn((DynObject *)getAnyAd(&dummy, &dummy)); } } -void DreamGenContext::useChurchHole() { +void DreamWebEngine::useChurchHole() { showFirstUse(); - data.byte(kGetback) = 1; - data.word(kWatchingtime) = 28; - data.word(kReeltowatch) = 13; - data.word(kEndwatchreel) = 26; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; + _getBack = 1; + _vars._watchingTime = 28; + _vars._reelToWatch = 13; + _vars._endWatchReel = 26; + _vars._watchSpeed = 1; + _vars._speedCount = 1; } -void DreamGenContext::sitDownInBar() { - if (data.byte(kWatchmode) != 0xFF) { +void DreamWebEngine::sitDownInBar() { + if (_vars._watchMode != 0xFF) { // Sat down showSecondUse(); putBackObStuff(); } else { showFirstUse(); - data.word(kWatchingtime) = 50; - data.word(kReeltowatch) = 55; - data.word(kEndwatchreel) = 71; - data.word(kReeltohold) = 73; - data.word(kEndofholdreel) = 83; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; + _vars._watchingTime = 50; + _vars._reelToWatch = 55; + _vars._endWatchReel = 71; + _vars._reelToHold = 73; + _vars._endOfHoldReel = 83; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; } } -void DreamGenContext::useDryer() { +void DreamWebEngine::useDryer() { playChannel1(12); showFirstUse(); - data.byte(kGetback) = 1; + _getBack = 1; } -void DreamGenContext::useBalcony() { +void DreamWebEngine::useBalcony() { showFirstUse(); turnPathOn(6); turnPathOff(0); @@ -429,314 +396,308 @@ void DreamGenContext::useBalcony() { turnPathOff(3); turnPathOff(4); turnPathOff(5); - data.byte(kProgresspoints)++; - data.byte(kManspath) = 6; - data.byte(kDestination) = 6; - data.byte(kFinaldest) = 6; + _vars._progressPoints++; + _mansPath = 6; + _destination = 6; + _finalDest = 6; findXYFromPath(); switchRyanOff(); - data.byte(kResetmanxy) = 1; - data.word(kWatchingtime) = 30 * 2; - data.word(kReeltowatch) = 183; - data.word(kEndwatchreel) = 212; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; + _resetManXY = 1; + _vars._watchingTime = 30 * 2; + _vars._reelToWatch = 183; + _vars._endWatchReel = 212; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; } -void DreamGenContext::useWindow() { - if (data.byte(kManspath) != 6) { +void DreamWebEngine::useWindow() { + if (_mansPath != 6) { // Not on balcony showSecondUse(); putBackObStuff(); } else { - data.byte(kProgresspoints)++; + _vars._progressPoints++; showFirstUse(); - data.byte(kNewlocation) = 29; - data.byte(kGetback) = 1; + _newLocation = 29; + _getBack = 1; } } -void DreamGenContext::trapDoor() { - data.byte(kProgresspoints)++; +void DreamWebEngine::trapDoor() { + _vars._progressPoints++; showFirstUse(); switchRyanOff(); - data.word(kWatchingtime) = 20 * 2; - data.word(kReeltowatch) = 181; - data.word(kEndwatchreel) = 197; - data.byte(kNewlocation) = 26; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; + _vars._watchingTime = 20 * 2; + _vars._reelToWatch = 181; + _vars._endWatchReel = 197; + _newLocation = 26; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; } -void DreamGenContext::callEdensLift() { +void DreamWebEngine::callEdensLift() { showFirstUse(); - data.byte(kCounttoopen) = 8; - data.byte(kGetback) = 1; + _vars._countToOpen = 8; + _getBack = 1; turnPathOn(2); } -void DreamGenContext::callEdensDLift() { - if (data.byte(kLiftflag) == 1) { +void DreamWebEngine::callEdensDLift() { + if (_vars._liftFlag == 1) { // Eden's D here showSecondUse(); putBackObStuff(); } else { showFirstUse(); - data.byte(kCounttoopen) = 8; - data.byte(kGetback) = 1; + _vars._countToOpen = 8; + _getBack = 1; turnPathOn(2); } } -void DreamGenContext::openYourNeighbour() { +void DreamWebEngine::openYourNeighbour() { enterCode(255, 255, 255, 255); - data.byte(kGetback) = 1; + _getBack = 1; } -void DreamGenContext::openRyan() { +void DreamWebEngine::openRyan() { enterCode(5, 1, 0, 6); - data.byte(kGetback) = 1; + _getBack = 1; } -void DreamGenContext::openPoolBoss() { +void DreamWebEngine::openPoolBoss() { enterCode(5, 2, 2, 2); - data.byte(kGetback) = 1; + _getBack = 1; } -void DreamGenContext::openEden() { +void DreamWebEngine::openEden() { enterCode(2, 8, 6, 5); - data.byte(kGetback) = 1; + _getBack = 1; } -void DreamGenContext::openSarters() { +void DreamWebEngine::openSarters() { enterCode(7, 8, 3, 3); - data.byte(kGetback) = 1; + _getBack = 1; } -void DreamGenContext::openLouis() { +void DreamWebEngine::openLouis() { enterCode(5, 2, 3, 8); - data.byte(kGetback) = 1; + _getBack = 1; } -void DreamGenContext::useWall() { +void DreamWebEngine::useWall() { showFirstUse(); - if (data.byte(kManspath) != 3) { - data.word(kWatchingtime) = 30*2; - data.word(kReeltowatch) = 2; - data.word(kEndwatchreel) = 31; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; + if (_mansPath != 3) { + _vars._watchingTime = 30*2; + _vars._reelToWatch = 2; + _vars._endWatchReel = 31; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; turnPathOn(3); turnPathOn(4); turnPathOff(0); turnPathOff(1); turnPathOff(2); turnPathOff(5); - data.byte(kManspath) = 3; - data.byte(kFinaldest) = 3; + _mansPath = 3; + _finalDest = 3; findXYFromPath(); - data.byte(kResetmanxy) = 1; + _resetManXY = 1; switchRyanOff(); } else { // Go back over - data.word(kWatchingtime) = 30 * 2; - data.word(kReeltowatch) = 34; - data.word(kEndwatchreel) = 60; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; + _vars._watchingTime = 30 * 2; + _vars._reelToWatch = 34; + _vars._endWatchReel = 60; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; turnPathOff(3); turnPathOff(4); turnPathOn(0); turnPathOn(1); turnPathOn(2); turnPathOn(5); - data.byte(kManspath) = 5; - data.byte(kFinaldest) = 5; + _mansPath = 5; + _finalDest = 5; findXYFromPath(); - data.byte(kResetmanxy) = 1; + _resetManXY = 1; switchRyanOff(); } } -void DreamGenContext::useLadder() { +void DreamWebEngine::useLadder() { showFirstUse(); - data.byte(kMapx) = data.byte(kMapx) - 11; + _mapX = _mapX - 11; findRoomInLoc(); - data.byte(kFacing) = 6; - data.byte(kTurntoface) = 6; - data.byte(kManspath) = 0; - data.byte(kDestination) = 0; - data.byte(kFinaldest) = 0; + _facing = 6; + _turnToFace = 6; + _mansPath = 0; + _destination = 0; + _finalDest = 0; findXYFromPath(); - data.byte(kResetmanxy) = 1; - data.byte(kGetback) = 1; + _resetManXY = 1; + _getBack = 1; } -void DreamGenContext::useLadderB() { +void DreamWebEngine::useLadderB() { showFirstUse(); - data.byte(kMapx) = data.byte(kMapx) + 11; + _mapX = _mapX + 11; findRoomInLoc(); - data.byte(kFacing) = 2; - data.byte(kTurntoface) = 2; - data.byte(kManspath) = 1; - data.byte(kDestination) = 1; - data.byte(kFinaldest) = 1; + _facing = 2; + _turnToFace = 2; + _mansPath = 1; + _destination = 1; + _finalDest = 1; findXYFromPath(); - data.byte(kResetmanxy) = 1; - data.byte(kGetback) = 1; + _resetManXY = 1; + _getBack = 1; } -void DreamGenContext::sLabDoorA() { +void DreamWebEngine::slabDoorA() { showFirstUse(); - data.byte(kGetback) = 1; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.word(kReeltowatch) = 13; - if (data.byte(kDreamnumber) != 3) { + _getBack = 1; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _vars._reelToWatch = 13; + if (_vars._dreamNumber != 3) { // Wrong - data.word(kWatchingtime) = 40; - data.word(kEndwatchreel) = 34; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; + _vars._watchingTime = 40; + _vars._endWatchReel = 34; + _vars._watchSpeed = 1; + _vars._speedCount = 1; } else { - data.byte(kProgresspoints)++; - data.word(kWatchingtime) = 60; - data.word(kEndwatchreel) = 42; - data.byte(kNewlocation) = 47; + _vars._progressPoints++; + _vars._watchingTime = 60; + _vars._endWatchReel = 42; + _newLocation = 47; } } -void DreamGenContext::sLabDoorB() { - if (data.byte(kDreamnumber) != 1) { +void DreamWebEngine::slabDoorB() { + if (_vars._dreamNumber != 1) { // Wrong showFirstUse(); - data.byte(kGetback) = 1; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.word(kReeltowatch) = 44; - data.word(kWatchingtime) = 40; - data.word(kEndwatchreel) = 63; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; + _getBack = 1; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _vars._reelToWatch = 44; + _vars._watchingTime = 40; + _vars._endWatchReel = 63; + _vars._watchSpeed = 1; + _vars._speedCount = 1; } else { - al = 'S'; - ah = 'H'; - cl = 'L'; - ch = 'D'; - isRyanHolding(); - - if (flags.z()) { + if (!isRyanHolding("SHLD")) { // No crystal showPuzText(44, 200); putBackObStuff(); } else { // Got crystal showFirstUse(); - data.byte(kProgresspoints)++; - data.byte(kGetback) = 1; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.word(kReeltowatch) = 44; - data.word(kWatchingtime) = 60; - data.word(kEndwatchreel) = 71; - data.byte(kNewlocation) = 47; + _vars._progressPoints++; + _getBack = 1; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _vars._reelToWatch = 44; + _vars._watchingTime = 60; + _vars._endWatchReel = 71; + _newLocation = 47; } } } -void DreamGenContext::sLabDoorC() { +void DreamWebEngine::slabDoorC() { showFirstUse(); - data.byte(kGetback) = 1; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.word(kReeltowatch) = 108; - if (data.byte(kDreamnumber) != 4) { + _getBack = 1; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _vars._reelToWatch = 108; + if (_vars._dreamNumber != 4) { // Wrong - data.word(kWatchingtime) = 40; - data.word(kEndwatchreel) = 127; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; + _vars._watchingTime = 40; + _vars._endWatchReel = 127; + _vars._watchSpeed = 1; + _vars._speedCount = 1; } else { - data.byte(kProgresspoints)++; - data.word(kWatchingtime) = 60; - data.word(kEndwatchreel) = 135; - data.byte(kNewlocation) = 47; + _vars._progressPoints++; + _vars._watchingTime = 60; + _vars._endWatchReel = 135; + _newLocation = 47; } } -void DreamGenContext::sLabDoorD() { +void DreamWebEngine::slabDoorD() { showFirstUse(); - data.byte(kGetback) = 1; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.word(kReeltowatch) = 75; - if (data.byte(kDreamnumber) != 0) { + _getBack = 1; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _vars._reelToWatch = 75; + if (_vars._dreamNumber != 0) { // Wrong - data.word(kWatchingtime) = 40; - data.word(kEndwatchreel) = 94; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; + _vars._watchingTime = 40; + _vars._endWatchReel = 94; + _vars._watchSpeed = 1; + _vars._speedCount = 1; } else { - data.byte(kProgresspoints)++; - data.word(kWatchingtime) = 60; - data.word(kEndwatchreel) = 102; - data.byte(kNewlocation) = 47; + _vars._progressPoints++; + _vars._watchingTime = 60; + _vars._endWatchReel = 102; + _newLocation = 47; } } -void DreamGenContext::sLabDoorE() { +void DreamWebEngine::slabDoorE() { showFirstUse(); - data.byte(kGetback) = 1; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.word(kReeltowatch) = 141; - if (data.byte(kDreamnumber) != 5) { + _getBack = 1; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _vars._reelToWatch = 141; + if (_vars._dreamNumber != 5) { // Wrong - data.word(kWatchingtime) = 40; - data.word(kEndwatchreel) = 160; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; + _vars._watchingTime = 40; + _vars._endWatchReel = 160; + _vars._watchSpeed = 1; + _vars._speedCount = 1; } else { - data.byte(kProgresspoints)++; - data.word(kWatchingtime) = 60; - data.word(kEndwatchreel) = 168; - data.byte(kNewlocation) = 47; + _vars._progressPoints++; + _vars._watchingTime = 60; + _vars._endWatchReel = 168; + _newLocation = 47; } } -void DreamGenContext::sLabDoorF() { +void DreamWebEngine::slabDoorF() { showFirstUse(); - data.byte(kGetback) = 1; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.word(kReeltowatch) = 171; - if (data.byte(kDreamnumber) != 2) { + _getBack = 1; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _vars._reelToWatch = 171; + if (_vars._dreamNumber != 2) { // Wrong - data.word(kWatchingtime) = 40; - data.word(kEndwatchreel) = 189; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; + _vars._watchingTime = 40; + _vars._endWatchReel = 189; + _vars._watchSpeed = 1; + _vars._speedCount = 1; } else { - data.byte(kProgresspoints)++; - data.word(kWatchingtime) = 60; - data.word(kEndwatchreel) = 197; - data.byte(kNewlocation) = 47; + _vars._progressPoints++; + _vars._watchingTime = 60; + _vars._endWatchReel = 197; + _newLocation = 47; } } -bool DreamGenContext::defaultUseHandler(const char *id) { - if (data.byte(kWithobject) == 255) { +bool DreamWebEngine::defaultUseHandler(const char *id) { + if (_withObject == 255) { withWhat(); return true; // event handled } - if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) { + if (!compare(_withObject, _withType, id)) { // Wrong item showPuzText(14, 300); putBackObStuff(); @@ -746,79 +707,185 @@ bool DreamGenContext::defaultUseHandler(const char *id) { return false; // continue with the original event } -void DreamGenContext::useChurchGate() { - char id[4] = { 'C', 'U', 'T', 'T' }; // TODO: convert to string with trailing zero - if (defaultUseHandler(id)) +void DreamWebEngine::useChurchGate() { + if (defaultUseHandler("CUTT")) return; // Cut gate showFirstUse(); - data.word(kWatchingtime) = 64 * 2; - data.word(kReeltowatch) = 4; - data.word(kEndwatchreel) = 70; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; - data.byte(kProgresspoints)++; + _vars._watchingTime = 64 * 2; + _vars._reelToWatch = 4; + _vars._endWatchReel = 70; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; + _vars._progressPoints++; turnPathOn(3); - if (data.byte(kAidedead) != 0) + if (_vars._aideDead != 0) turnPathOn(2); // Open church } -void DreamGenContext::useFullCart() { - data.byte(kProgresspoints)++; - turnAnyPathOn(2, data.byte(kRoomnum) + 6); - data.byte(kManspath) = 4; - data.byte(kFacing) = 4; - data.byte(kTurntoface) = 4; - data.byte(kFinaldest) = 4; +void DreamWebEngine::useGun() { + + if (_objectType != kExObjectType) { + // gun is not taken + showSecondUse(); + putBackObStuff(); + + } else if (_realLocation == 22) { + // in pool room + showPuzText(34, 300); + _vars._lastWeapon = 1; + _vars._combatCount = 39; + _getBack = 1; + _vars._progressPoints++; + + } else if (_realLocation == 25) { + // helicopter + showPuzText(34, 300); + _vars._lastWeapon = 1; + _vars._combatCount = 19; + _getBack = 1; + _vars._dreamNumber = 2; + _vars._roomAfterDream = 38; + _vars._sartainDead = 1; + _vars._progressPoints++; + + } else if (_realLocation == 27) { + // in rock room + showPuzText(46, 300); + _pointerMode = 2; + _vars._rockstarDead = 1; + _vars._lastWeapon = 1; + _vars._newsItem = 1; + _getBack = 1; + _vars._roomAfterDream = 32; + _vars._dreamNumber = 0; + _vars._progressPoints++; + + } else if (_realLocation == 8 && _mapX == 22 && _mapY == 40 + && !isSetObOnMap(92) && _mansPath != 9) { + // by studio + _destination = 9; + _finalDest = 9; + autoSetWalk(); + _vars._lastWeapon = 1; + _getBack = 1; + _vars._progressPoints++; + + } else if (_realLocation == 6 && _mapX == 11 && _mapY == 20 + && isSetObOnMap(5)) { + // sarters + _destination = 1; + _finalDest = 1; + autoSetWalk(); + removeSetObject(5); + placeSetObject(6); + turnAnyPathOn(1, _roomNum - 1); + _vars._liftFlag = 1; + _vars._watchingTime = 40*2; + _vars._reelToWatch = 4; + _vars._endWatchReel = 43; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; + _vars._progressPoints++; + + } else if (_realLocation == 29) { + // aide + _getBack = 1; + resetLocation(13); + setLocation(12); + _destPos = 12; + _destination = 2; + _finalDest = 2; + autoSetWalk(); + _vars._watchingTime = 164*2; + _vars._reelToWatch = 3; + _vars._endWatchReel = 164; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _vars._aideDead = 1; + _vars._dreamNumber = 3; + _vars._roomAfterDream = 33; + _vars._progressPoints++; + + } else if (_realLocation == 23 && _mapX == 0 && _mapY == 50) { + // with boss + if (_mansPath != 5) { + _destination = 5; + _finalDest = 5; + autoSetWalk(); + } + _vars._lastWeapon = 1; + _getBack = 1; + + } else if (_realLocation == 8 && _mapX == 11 && _mapY == 10) { + // tv soldier + if (_mansPath != 2) { + _destination = 2; + _finalDest = 2; + autoSetWalk(); + } + _vars._lastWeapon = 1; + _getBack = 1; + + } else { + showFirstUse(); + putBackObStuff(); + } +} + +void DreamWebEngine::useFullCart() { + _vars._progressPoints++; + turnAnyPathOn(2, _roomNum + 6); + _mansPath = 4; + _facing = 4; + _turnToFace = 4; + _finalDest = 4; findXYFromPath(); - data.byte(kResetmanxy) = 1; + _resetManXY = 1; showFirstUse(); - data.word(kWatchingtime) = 72 * 2; - data.word(kReeltowatch) = 58; - data.word(kEndwatchreel) = 142; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; + _vars._watchingTime = 72 * 2; + _vars._reelToWatch = 58; + _vars._endWatchReel = 142; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; } -void DreamGenContext::useClearBox() { - char id[4] = { 'R', 'A', 'I', 'L' }; // TODO: convert to string with trailing zero - if (defaultUseHandler(id)) +void DreamWebEngine::useClearBox() { + if (defaultUseHandler("RAIL")) return; // Open box - data.byte(kProgresspoints)++; + _vars._progressPoints++; showFirstUse(); - data.word(kWatchingtime) = 80; - data.word(kReeltowatch) = 67; - data.word(kEndwatchreel) = 105; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; + _vars._watchingTime = 80; + _vars._reelToWatch = 67; + _vars._endWatchReel = 105; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; } -void DreamGenContext::openTVDoor() { - char id[4] = { 'U', 'L', 'O', 'K' }; // TODO: convert to string with trailing zero - if (defaultUseHandler(id)) +void DreamWebEngine::openTVDoor() { + if (defaultUseHandler("ULOK")) return; // Key on TV showFirstUse(); - data.byte(kLockstatus) = 0; - data.byte(kGetback) = 1; + _vars._lockStatus = 0; + _getBack = 1; } -void DreamGenContext::usePlate() { - if (data.byte(kWithobject) == 255) { +void DreamWebEngine::usePlate() { + if (_withObject == 255) { withWhat(); return; } - char screw[4] = { 'S', 'C', 'R', 'W' }; // TODO: convert to string with trailing zero - char knife[4] = { 'K', 'N', 'F', 'E' }; // TODO: convert to string with trailing zero - if (compare(data.byte(kWithobject), data.byte(kWithtype), screw)) { + if (compare(_withObject, _withType, "SCRW")) { // Unscrew plate playChannel1(20); showFirstUse(); @@ -826,9 +893,9 @@ void DreamGenContext::usePlate() { placeSetObject(24); removeSetObject(25); placeFreeObject(0); - data.byte(kProgresspoints)++; - data.byte(kGetback) = 1; - } else if (compare(data.byte(kWithobject), data.byte(kWithtype), knife)) { + _vars._progressPoints++; + _getBack = 1; + } else if (compare(_withObject, _withType, "KNFE")) { // Tried knife showPuzText(54, 300); putBackObStuff(); @@ -839,152 +906,143 @@ void DreamGenContext::usePlate() { } } -void DreamGenContext::usePlinth() { - if (data.byte(kWithobject) == 255) { +void DreamWebEngine::usePlinth() { + if (_withObject == 255) { withWhat(); return; } - char id[4] = { 'D', 'K', 'E', 'Y' }; // TODO: convert to string with trailing zero - if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) { + if (!compare(_withObject, _withType, "DKEY")) { // Wrong key showFirstUse(); putBackObStuff(); } else { - data.byte(kProgresspoints)++; + _vars._progressPoints++; showSecondUse(); - data.word(kWatchingtime) = 220; - data.word(kReeltowatch) = 0; - data.word(kEndwatchreel) = 104; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; - data.byte(kNewlocation) = data.byte(kRoomafterdream); + _vars._watchingTime = 220; + _vars._reelToWatch = 0; + _vars._endWatchReel = 104; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; + _newLocation = _vars._roomAfterDream; } } -void DreamGenContext::useElvDoor() { - char id[4] = { 'A', 'X', 'E', 'D' }; // TODO: convert to string with trailing zero - if (defaultUseHandler(id)) +void DreamWebEngine::useElvDoor() { + if (defaultUseHandler("AXED")) return; // Axe on door showPuzText(15, 300); - _inc(data.byte(kProgresspoints)); - data.word(kWatchingtime) = 46 * 2; - data.word(kReeltowatch) = 31; - data.word(kEndwatchreel) = 77; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; + _vars._progressPoints++; + _vars._watchingTime = 46 * 2; + _vars._reelToWatch = 31; + _vars._endWatchReel = 77; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; } -void DreamGenContext::useObject() { - data.byte(kWithobject) = 255; +void DreamWebEngine::useObject() { + _withObject = 255; - if (data.byte(kCommandtype) != 229) { - data.byte(kCommandtype) = 229; - commandWithOb(51, data.byte(kObjecttype), data.byte(kCommand)); + if (_commandType != 229) { + _commandType = 229; + commandWithOb(51, _objectType, _command); } - if (data.word(kMousebutton) == data.word(kOldbutton)) + if (_mouseButton == _oldButton) return; // nouse - if (data.word(kMousebutton) & 1) + if (_mouseButton & 1) useRoutine(); } -void DreamGenContext::useWinch() { - al = 40; - ah = 1; - checkInside(); - - char id[4] = { 'F', 'U', 'S', 'E' }; // TODO: convert to string with trailing zero - if (cl == kNumexobjects || !compare(cl, 4, id)) { +void DreamWebEngine::useWinch() { + uint16 contentIndex = checkInside(40, 1); + if (contentIndex == kNumexobjects || !compare(contentIndex, kExObjectType, "FUSE")) { // No winch showFirstUse(); putBackObStuff(); return; } - data.word(kWatchingtime) = 217 * 2; - data.word(kReeltowatch) = 0; - data.word(kEndwatchreel) = 217; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kDestpos) = 1; - data.byte(kNewlocation) = 45; - data.byte(kDreamnumber) = 1; - data.byte(kRoomafterdream) = 44; - data.byte(kGeneraldead) = 1; - data.byte(kNewsitem) = 2; - data.byte(kGetback) = 1; - data.byte(kProgresspoints)++; -} - -void DreamGenContext::useCart() { - char id[4] = { 'R', 'O', 'C', 'K' }; // TODO: convert to string with trailing zero - if (defaultUseHandler(id)) + _vars._watchingTime = 217 * 2; + _vars._reelToWatch = 0; + _vars._endWatchReel = 217; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _destPos = 1; + _newLocation = 45; + _vars._dreamNumber = 1; + _vars._roomAfterDream = 44; + _vars._generalDead = 1; + _vars._newsItem = 2; + _getBack = 1; + _vars._progressPoints++; +} + +void DreamWebEngine::useCart() { + if (defaultUseHandler("ROCK")) return; - DynObject *exObject = getExAd(data.byte(kWithobject)); + DynObject *exObject = getExAd(_withObject); exObject->mapad[0] = 0; - removeSetObject(data.byte(kCommand)); - placeSetObject(data.byte(kCommand) + 1); - data.byte(kProgresspoints)++; + removeSetObject(_command); + placeSetObject(_command + 1); + _vars._progressPoints++; playChannel1(17); showFirstUse(); - data.byte(kGetback) = 1; + _getBack = 1; } -void DreamGenContext::useTrainer() { - // TODO: Use the C++ version of getAnyAd() - getAnyAd(); - if (es.byte(bx + 2) != 4) { +void DreamWebEngine::useTrainer() { + uint8 dummy; + DynObject *object = (DynObject *)getAnyAd(&dummy, &dummy); + if (object->mapad[0] != 4) { notHeldError(); } else { - data.byte(kProgresspoints)++; - makeWorn(); + _vars._progressPoints++; + makeWorn(object); showSecondUse(); putBackObStuff(); } } -void DreamGenContext::chewy() { +void DreamWebEngine::chewy() { + // Chewing a gum showFirstUse(); - // TODO: Use the C++ version of getAnyAd() - getAnyAd(); - es.byte(bx + 2) = 255; - data.byte(kGetback) = 1; + uint8 dummy; + DynObject *object = (DynObject *)getAnyAd(&dummy, &dummy); + object->mapad[0] = 255; + _getBack = 1; } -void DreamGenContext::useHole() { - char id[4] = { 'H', 'N', 'D', 'A' }; // TODO: convert to string with trailing zero - if (defaultUseHandler(id)) +void DreamWebEngine::useHole() { + if (defaultUseHandler("HNDA")) return; showFirstUse(); removeSetObject(86); - DynObject *exObject = getExAd(data.byte(kWithobject)); + DynObject *exObject = getExAd(_withObject); exObject->mapad[0] = 255; - data.byte(kCanmovealtar) = 1; - data.byte(kGetback) = 1; + _vars._canMoveAltar = 1; + _getBack = 1; } -void DreamGenContext::openHotelDoor() { - char id[4] = { 'K', 'E', 'Y', 'A' }; // TODO: convert to string with trailing zero - if (defaultUseHandler(id)) +void DreamWebEngine::openHotelDoor() { + if (defaultUseHandler("KEYA")) return; playChannel1(16); showFirstUse(); - data.byte(kLockstatus) = 0; - data.byte(kGetback) = 1; + _vars._lockStatus = 0; + _getBack = 1; } -void DreamGenContext::openHotelDoor2() { - char id[4] = { 'K', 'E', 'Y', 'A' }; // TODO: convert to string with trailing zero - if (defaultUseHandler(id)) +void DreamWebEngine::openHotelDoor2() { + if (defaultUseHandler("KEYA")) return; playChannel1(16); @@ -992,42 +1050,39 @@ void DreamGenContext::openHotelDoor2() { putBackObStuff(); } -void DreamGenContext::grafittiDoor() { - char id[4] = { 'A', 'P', 'E', 'N' }; // TODO: convert to string with trailing zero - if (defaultUseHandler(id)) +void DreamWebEngine::grafittiDoor() { + if (defaultUseHandler("APEN")) return; showFirstUse(); putBackObStuff(); } -void DreamGenContext::usePoolReader() { - char id[4] = { 'M', 'E', 'M', 'B' }; // TODO: convert to string with trailing zero - if (defaultUseHandler(id)) +void DreamWebEngine::usePoolReader() { + if (defaultUseHandler("MEMB")) return; - if (data.byte(kTalkedtoattendant) != 1) { + if (_vars._talkedToAttendant != 1) { // Can't open pool showSecondUse(); putBackObStuff(); } else { playChannel1(17); showFirstUse(); - data.byte(kCounttoopen) = 6; - data.byte(kGetback) = 1; + _vars._countToOpen = 6; + _getBack = 1; } } -void DreamGenContext::useCardReader1() { - char id[4] = { 'C', 'S', 'H', 'R' }; // TODO: convert to string with trailing zero - if (defaultUseHandler(id)) +void DreamWebEngine::useCardReader1() { + if (defaultUseHandler("CSHR")) return; - if (data.byte(kTalkedtosparky) == 0) { + if (_vars._talkedToSparky == 0) { // Not yet showFirstUse(); putBackObStuff(); - } else if (data.word(kCard1money) != 0) { + } else if (_vars._card1Money != 0) { // No cash showPuzText(17, 300); putBackObStuff(); @@ -1035,26 +1090,25 @@ void DreamGenContext::useCardReader1() { // Get cash playChannel1(16); showPuzText(18, 300); - data.byte(kProgresspoints)++; - data.word(kCard1money) = 12432; - data.byte(kGetback) = 1; + _vars._progressPoints++; + _vars._card1Money = 12432; + _getBack = 1; } } -void DreamGenContext::useCardReader2() { - char id[4] = { 'C', 'S', 'H', 'R' }; // TODO: convert to string with trailing zero - if (defaultUseHandler(id)) +void DreamWebEngine::useCardReader2() { + if (defaultUseHandler("CSHR")) return; - if (data.byte(kTalkedtoboss) == 0) { + if (_vars._talkedToBoss == 0) { // Haven't talked to boss showFirstUse(); putBackObStuff(); - } else if (data.byte(kCard1money) == 0) { + } else if (_vars._card1Money == 0) { // No cash showPuzText(20, 300); putBackObStuff(); - } else if (data.byte(kGunpassflag) == 2) { + } else if (_vars._gunPassFlag == 2) { // Already got new showPuzText(22, 300); putBackObStuff(); @@ -1062,72 +1116,68 @@ void DreamGenContext::useCardReader2() { playChannel1(18); showPuzText(19, 300); placeSetObject(94); - data.byte(kGunpassflag) = 1; - data.word(kCard1money) -= 2000; - data.byte(kProgresspoints)++; - data.byte(kGetback) = 1; + _vars._gunPassFlag = 1; + _vars._card1Money -= 2000; + _vars._progressPoints++; + _getBack = 1; } } -void DreamGenContext::useCardReader3() { - char id[4] = { 'C', 'S', 'H', 'R' }; // TODO: convert to string with trailing zero - if (defaultUseHandler(id)) +void DreamWebEngine::useCardReader3() { + if (defaultUseHandler("CSHR")) return; - if (data.byte(kTalkedtorecep) == 0) { + if (_vars._talkedToRecep == 0) { // Haven't talked to receptionist showFirstUse(); putBackObStuff(); - } else if (data.byte(kCardpassflag) != 0) { + } else if (_vars._cardPassFlag != 0) { // Already used it showPuzText(26, 300); putBackObStuff(); } else { playChannel1(16); showPuzText(25, 300); - data.byte(kProgresspoints)++; - data.word(kCard1money) -= 8300; - data.byte(kCardpassflag) = 1; - data.byte(kGetback) = 1; + _vars._progressPoints++; + _vars._card1Money -= 8300; + _vars._cardPassFlag = 1; + _getBack = 1; } } -void DreamGenContext::useLighter() { - if (data.byte(kWithobject) == 255) { +void DreamWebEngine::useLighter() { + if (_withObject == 255) { withWhat(); return; } - char id[4] = { 'S', 'M', 'K', 'E' }; // TODO: convert to string with trailing zero - if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) { + if (!compare(_withObject, _withType, "SMKE")) { showFirstUse(); putBackObStuff(); } else { showPuzText(9, 300); - DynObject *withObj = getExAd(data.byte(kWithobject)); + DynObject *withObj = getExAd(_withObject); withObj->mapad[0] = 255; - data.byte(kGetback) = 1; + _getBack = 1; } } -void DreamGenContext::useWire() { - if (data.byte(kWithobject) == 255) { +void DreamWebEngine::useWire() { + if (_withObject == 255) { withWhat(); return; } - char knife[4] = { 'K', 'N', 'F', 'E' }; // TODO: convert to string with trailing zero - if (compare(data.byte(kWithobject), data.byte(kWithtype), knife)) { + if (compare(_withObject, _withType, "KNFE")) { removeSetObject(51); placeSetObject(52); showPuzText(11, 300); - data.byte(kProgresspoints)++; - data.byte(kGetback) = 1; + _vars._progressPoints++; + _getBack = 1; return; } - char axe[4] = { 'A', 'X', 'E', 'D' }; // TODO: convert to string with trailing zero - if (compare(data.byte(kWithobject), data.byte(kWithtype), axe)) { + if (compare(_withObject, _withType, "AXED")) { showPuzText(16, 300); putBackObStuff(); return; @@ -1137,19 +1187,19 @@ void DreamGenContext::useWire() { putBackObStuff(); } -void DreamGenContext::openTomb() { - data.byte(kProgresspoints)++; +void DreamWebEngine::openTomb() { + _vars._progressPoints++; showFirstUse(); - data.word(kWatchingtime) = 35 * 2; - data.word(kReeltowatch) = 1; - data.word(kEndwatchreel) = 33; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; + _vars._watchingTime = 35 * 2; + _vars._reelToWatch = 1; + _vars._endWatchReel = 33; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; } -void DreamGenContext::hotelControl() { - if (data.byte(kReallocation) != 21 || data.byte(kMapx) != 33) +void DreamWebEngine::hotelControl() { + if (_realLocation != 21 || _mapX != 33) showSecondUse(); // Not right control else showFirstUse(); @@ -1157,71 +1207,393 @@ void DreamGenContext::hotelControl() { putBackObStuff(); } -void DreamGenContext::useCooker() { - al = data.byte(kCommand); - ah = data.byte(kObjecttype); - checkInside(); - - if (cl == 114) +void DreamWebEngine::useCooker() { + if (checkInside(_command, _objectType) == kNumexobjects) showFirstUse(); else showSecondUse(); // Food inside - + putBackObStuff(); } -void DreamBase::placeFreeObject(uint8 index) { +void DreamWebEngine::placeFreeObject(uint8 index) { findOrMake(index, 0, 1); getFreeAd(index)->mapad[0] = 0; } -void DreamBase::removeFreeObject(uint8 index) { +void DreamWebEngine::removeFreeObject(uint8 index) { getFreeAd(index)->mapad[0] = 0xFF; } -void DreamGenContext::useDiary() { - getRidOfReels(); - loadIntoTemp("DREAMWEB.G14"); - loadTempText("DREAMWEB.T51"); - loadTempCharset("DREAMWEB.C02"); +void DreamWebEngine::useControl() { + if (_withObject == 255) { + withWhat(); + return; + } + + if (compare(_withObject, _withType, "KEYA")) { // Right key + playChannel1(16); + if (_vars._location == 21) { // Going down + showPuzText(3, 300); + _newLocation = 30; + } else { + showPuzText(0, 300); + _newLocation = 21; + } + + _vars._countToClose = 8; + _vars._countToOpen = 0; + _vars._watchingTime = 80; + _getBack = 1; + return; + } + + if (_realLocation == 21) { + if (compare(_withObject, _withType, "KNFE")) { + // Jimmy controls + placeSetObject(50); + placeSetObject(51); + placeSetObject(26); + placeSetObject(30); + removeSetObject(16); + removeSetObject(17); + playChannel1(14); + showPuzText(10, 300); + _vars._progressPoints++; + _getBack = 1; + } else if (compare(_withObject, _withType, "AXED")) { + // Axe on controls + showPuzText(16, 300); + _vars._progressPoints++; + putBackObStuff(); + } else { + // Balls + showFirstUse(); + putBackObStuff(); + } + } else { + // Balls + showFirstUse(); + putBackObStuff(); + } +} + +void DreamWebEngine::useSlab() { + if (_withObject == 255) { + withWhat(); + return; + } + + if (!compare(_withObject, _withType, "JEWL")) { + showPuzText(14, 300); + putBackObStuff(); + return; + } + + DynObject *exObject = getExAd(_withObject); + exObject->mapad[0] = 0; + + removeSetObject(_command); + placeSetObject(_command + 1); + if (_command + 1 == 54) { + // Last slab + turnPathOn(0); + _vars._watchingTime = 22; + _vars._reelToWatch = 35; + _vars._endWatchReel = 48; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + } + + _vars._progressPoints++; + showFirstUse(); + _getBack = 1; +} + +void DreamWebEngine::usePipe() { + if (_withObject == 255) { + withWhat(); + return; + } + + if (compare(_withObject, _withType, "CUPE")) { + // Fill cup + showPuzText(36, 300); + putBackObStuff(); + DynObject *exObject = getExAd(_withObject); + exObject->objId[3] = 'F'-'A'; // CUPE (empty cup) -> CUPF (full cup) + return; + } else if (compare(_withObject, _withType, "CUPF")) { + // Already full + showPuzText(35, 300); + putBackObStuff(); + } else { + showPuzText(14, 300); + putBackObStuff(); + } +} + +void DreamWebEngine::useOpenBox() { + if (_withObject == 255) { + withWhat(); + return; + } + + if (compare(_withObject, _withType, "CUPF")) { + // Destroy open box + _vars._progressPoints++; + showPuzText(37, 300); + DynObject *exObject = getExAd(_withObject); + exObject->objId[3] = 'E'-'A'; // CUPF (full cup) -> CUPE (empty cup) + _vars._watchingTime = 140; + _vars._reelToWatch = 105; + _vars._endWatchReel = 181; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + turnPathOn(4); + _getBack = 1; + return; + } + + if (compare(_withObject, _withType, "CUPE")) { + // Open box wrong + showPuzText(38, 300); + putBackObStuff(); + return; + } + + showFirstUse(); +} + +void DreamWebEngine::runTap() { + if (_withObject == 255) { + withWhat(); + return; + } + + if (compare(_withObject, _withType, "CUPE")) { + // Fill cup from tap + DynObject *exObject = getExAd(_withObject); + exObject->objId[3] = 'F'-'A'; // CUPE (empty cup) -> CUPF (full cup) + playChannel1(8); + showPuzText(57, 300); + putBackObStuff(); + return; + } + + if (compare(_withObject, _withType, "CUPF")) { + // Cup from tap full + showPuzText(58, 300); + putBackObStuff(); + return; + } + + showPuzText(56, 300); + putBackObStuff(); +} + +void DreamWebEngine::useAxe() { + if (_realLocation != 22) { + // Not in pool + showFirstUse(); + return; + } + + if (_mapY == 10) { + // Axe on door + showPuzText(15, 300); + _vars._progressPoints++; + _vars._watchingTime = 46*2; + _vars._reelToWatch = 31; + _vars._endWatchReel = 77; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; + return; + } + + showSecondUse(); + _vars._progressPoints++; + _vars._lastWeapon = 2; + _getBack = 1; + removeObFromInv(); +} + +void DreamWebEngine::useHandle() { + SetObject *object = getSetAd(findSetObject("CUTW")); + if (object->mapad[0] == 255) { + // Wire not cut + showPuzText(12, 300); + } else { + // Wire has been cut + showPuzText(13, 300); + _newLocation = 22; + } + + _getBack = 1; +} + +void DreamWebEngine::useAltar() { + if (findExObject("CNDA") == 114 || findExObject("CNDB") == 114) { + // Things on altar + showFirstUse(); + _getBack = 1; + return; + } + + if (_vars._canMoveAltar == 1) { + // Move altar + _vars._progressPoints++; + showSecondUse(); + _vars._watchingTime = 160; + _vars._reelToWatch = 81; + _vars._endWatchReel = 174; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + setupTimedUse(47, 32, 98, 52, 76); + _getBack = 1; + } else { + showPuzText(23, 300); + _getBack = 1; + } +} + +void DreamWebEngine::withWhat() { + uint8 commandLine[64] = "OBJECT NAME ONE "; + createPanel(); - showIcon(); - showDiary(); - underTextLine(); - showDiaryPage(); + showPanel(); + showMan(); + showExit(); + + copyName(_objectType, _command, commandLine); + printMessage2(100, 21, 63, 200, false, 2); + uint16 x = _lastXPos + 5; + printDirect(commandLine, x, 21, 220, false); + printMessage2(_lastXPos + 5, 21, 63, 200, false, 3); + + fillRyan(); + _commandType = 255; readMouse(); showPointer(); - workToScreenCPP(); + workToScreen(); delPointer(); - data.byte(kGetback) = 0; - - RectWithCallback diaryList[] = { - { kDiaryx+94,kDiaryx+110,kDiaryy+97,kDiaryy+113,&DreamGenContext::diaryKeyN }, - { kDiaryx+151,kDiaryx+167,kDiaryy+71,kDiaryy+87,&DreamGenContext::diaryKeyP }, - { kDiaryx+176,kDiaryx+192,kDiaryy+108,kDiaryy+124,&DreamGenContext::quitKey }, - { 0,320,0,200,&DreamGenContext::blank }, - { 0xFFFF,0,0,0,0 } - }; - - do { - delPointer(); - readMouse(); - showDiaryKeys(); - showPointer(); - vSync(); - dumpPointer(); - dumpDiaryKeys(); - dumpTextLine(); - checkCoords(diaryList); - } while (!data.byte(kGetback)); - - getRidOfTemp(); - getRidOfTempText(); - getRidOfTempCharset(); + _invOpen = 2; +} + +void DreamWebEngine::notHeldError() { + createPanel(); + showPanel(); + showMan(); + showExit(); + obIcons(); + printMessage2(64, 100, 63, 200 + 1, true, 1); + workToScreenM(); + hangOnP(50); + putBackObStuff(); +} + +void DreamWebEngine::useCashCard() { + getRidOfReels(); + loadKeypad(); + createPanel(); + showPanel(); + showExit(); + showMan(); + uint16 y = (!_foreignRelease) ? 120 : 120 - 3; + showFrame(_keypadGraphics, 114, y, 39, 0); + const uint8 *obText = getObTextStart(); + findNextColon(&obText); + findNextColon(&obText); + y = 98; + printDirect(&obText, 36, &y, 36, 36 & 1); + char amountStr[10]; + sprintf(amountStr, "%04d", _vars._card1Money / 10); + _charShift = 91 * 2 + 75; + printDirect((const uint8 *)amountStr, 160, 155, 240, 240 & 1); + sprintf(amountStr, "%02d", (_vars._card1Money % 10) * 10); + _charShift = 91 * 2 + 85; + printDirect((const uint8 *)amountStr, 187, 155, 240, 240 & 1); + _charShift = 0; + workToScreenM(); + hangOnP(400); + _keypadGraphics.clear(); restoreReels(); - data.byte(kManisoffscreen) = 0; - redrawMainScrn(); + putBackObStuff(); +} + +void DreamWebEngine::useStereo() { + // Handles the stereo in Ryan's apartment (accessible from the remote on + // the couch) + + if (_vars._location != 0) { + showPuzText(4, 400); + putBackObStuff(); + } else if (_mapX != 11) { + showPuzText(5, 400); + putBackObStuff(); + } else if (checkInside(findSetObject("CDPL"), 1) == kNumexobjects) { + // No CD inside + showPuzText(6, 400); + putBackObStuff(); + uint8 dummy; + DynObject *object = (DynObject *)getAnyAd(&dummy, &dummy); + object->turnedOn = 255; + } else { + // CD inside + uint8 dummy; + DynObject *object = (DynObject *)getAnyAd(&dummy, &dummy); + object->turnedOn ^= 1; + if (object->turnedOn != 255) + showPuzText(7, 400); // Stereo off + else + showPuzText(8, 400); // Stereo on + + putBackObStuff(); + } +} + +uint16 DreamWebEngine::checkInside(uint16 command, uint16 type) { + for (uint16 index = 0; index < kNumexobjects; index++) { + DynObject *object = getExAd(index); + if (object->mapad[1] == command && object->mapad[0] == type) + return index; + } + + return kNumexobjects; +} + +void DreamWebEngine::showPuzText(uint16 command, uint16 count) { + createPanel(); + showPanel(); + showMan(); + showExit(); + obIcons(); + const uint8 *string = (const uint8 *)_puzzleText.getString(command); + printDirect(string, 36, 104, 241, 241 & 1); workToScreenM(); + hangOnP(count); } -} // End of namespace DreamGen +void DreamWebEngine::useButtonA() { + if (!isSetObOnMap(95)) { + showFirstUse(); + turnAnyPathOn(0, _roomNum - 1); + removeSetObject(9); + placeSetObject(95); + _vars._watchingTime = 15 * 2; + _vars._reelToWatch = 71; + _vars._endWatchReel = 85; + _vars._watchSpeed = 1; + _vars._speedCount = 1; + _getBack = 1; + _vars._progressPoints++; + } else { + // Done this bit + showSecondUse(); + putBackObStuff(); + } +} + + +} // End of namespace DreamWeb diff --git a/engines/dreamweb/vgafades.cpp b/engines/dreamweb/vgafades.cpp index ca63b7308c..e8999ab18c 100644 --- a/engines/dreamweb/vgafades.cpp +++ b/engines/dreamweb/vgafades.cpp @@ -22,83 +22,71 @@ #include "dreamweb/dreamweb.h" -namespace DreamGen { +namespace DreamWeb { -uint8 *DreamBase::mainPalette() { - return getSegment(data.word(kBuffers)).ptr(kMaingamepal, 256 * 3); +void DreamWebEngine::clearStartPal() { + memset(_startPal, 0, 256 * 3); } -uint8 *DreamBase::startPalette() { - return getSegment(data.word(kBuffers)).ptr(kStartpal, 256 * 3); +void DreamWebEngine::clearEndPal() { + memset(_endPal, 0, 256 * 3); } -uint8 *DreamBase::endPalette() { - return getSegment(data.word(kBuffers)).ptr(kEndpal, 256 * 3); +void DreamWebEngine::palToStartPal() { + memcpy(_startPal, _mainPal, 256 * 3); } -void DreamBase::clearStartPal() { - memset(startPalette(), 0, 256 * 3); +void DreamWebEngine::endPalToStart() { + memcpy(_startPal, _endPal, 256 * 3); } -void DreamBase::clearEndPal() { - memset(endPalette(), 0, 256 * 3); +void DreamWebEngine::startPalToEnd() { + memcpy(_endPal, _startPal, 256 * 3); } -void DreamBase::palToStartPal() { - memcpy(startPalette(), mainPalette(), 256 * 3); +void DreamWebEngine::palToEndPal() { + memcpy(_endPal, _mainPal, 256 * 3); } -void DreamBase::endPalToStart() { - memcpy(startPalette(), endPalette(), 256 * 3); -} - -void DreamBase::startPalToEnd() { - memcpy(endPalette(), startPalette(), 256 * 3); -} - -void DreamBase::palToEndPal() { - memcpy(endPalette(), mainPalette(), 256 * 3); -} - -void DreamBase::fadeDOS() { +void DreamWebEngine::fadeDOS() { return; // FIXME later - engine->waitForVSync(); + waitForVSync(); //processEvents will be called from vsync - uint8 *dst = startPalette(); - engine->getPalette(dst, 0, 64); + uint8 *dst = _startPal; + getPalette(dst, 0, 64); for (int fade = 0; fade < 64; ++fade) { for (int c = 0; c < 768; ++c) { //original sources decrement 768 values -> 256 colors if (dst[c]) { --dst[c]; } } - engine->setPalette(dst, 0, 64); - engine->waitForVSync(); + setPalette(dst, 0, 64); + waitForVSync(); } } -void DreamBase::doFade() { - if (data.byte(kFadedirection) == 0) +void DreamWebEngine::doFade() { + if (_fadeDirection == 0) return; - engine->processEvents(); - uint8 *src = startPalette() + 3 * data.byte(kColourpos); - engine->setPalette(src, data.byte(kColourpos), data.byte(kNumtofade)); + processEvents(); + uint8 *src = _startPal + 3 * _colourPos; + setPalette(src, _colourPos, _numToFade); - data.byte(kColourpos) += data.byte(kNumtofade); - if (data.byte(kColourpos) == 0) + _colourPos += _numToFade; + if (_colourPos == 0) fadeCalculation(); } -void DreamBase::fadeCalculation() { - if (data.byte(kFadecount) == 0) { - data.byte(kFadedirection) = 0; +void DreamWebEngine::fadeCalculation() { + if (_fadeCount == 0) { + _fadeDirection = 0; return; } - uint8 *startPal = startPalette(); - const uint8 *endPal = endPalette(); + uint8 *startPal = _startPal; + const uint8 *endPal = _endPal; for (size_t i = 0; i < 256 * 3; ++i) { uint8 s = startPal[i]; uint8 e = endPal[i]; @@ -107,94 +95,148 @@ void DreamBase::fadeCalculation() { else if (s > e) --startPal[i]; else { - if (data.byte(kFadecount) <= e) + if (_fadeCount <= e) ++startPal[i]; } } - --data.byte(kFadecount); + --_fadeCount; } -void DreamGenContext::fadeupYellows() { +void DreamWebEngine::fadeUpYellows() { palToEndPal(); - memset(endPalette() + 231 * 3, 0, 8 * 3); - memset(endPalette() + 246 * 3, 0, 1 * 3); - data.byte(kFadedirection) = 1; - data.byte(kFadecount) = 63; - data.byte(kColourpos) = 0; - data.byte(kNumtofade) = 128; + memset(_endPal + 231 * 3, 0, 8 * 3); + memset(_endPal + 246 * 3, 0, 1 * 3); + _fadeDirection = 1; + _fadeCount = 63; + _colourPos = 0; + _numToFade = 128; hangOn(128); } -void DreamGenContext::fadeupMonFirst() { +void DreamWebEngine::fadeUpMonFirst() { palToStartPal(); palToEndPal(); - memset(startPalette() + 231 * 3, 0, 8 * 3); - memset(startPalette() + 246 * 3, 0, 1 * 3); - data.byte(kFadedirection) = 1; - data.byte(kFadecount) = 63; - data.byte(kColourpos) = 0; - data.byte(kNumtofade) = 128; + memset(_startPal + 231 * 3, 0, 8 * 3); + memset(_startPal + 246 * 3, 0, 1 * 3); + _fadeDirection = 1; + _fadeCount = 63; + _colourPos = 0; + _numToFade = 128; hangOn(64); playChannel1(26); hangOn(64); } -void DreamBase::fadeScreenUp() { + +void DreamWebEngine::fadeDownMon() { + palToStartPal(); + palToEndPal(); + memset(_endPal + 231 * 3, 0, 8 * 3); + memset(_endPal + 246 * 3, 0, 1 * 3); + _fadeDirection = 1; + _fadeCount = 63; + _colourPos = 0; + _numToFade = 128; + hangOn(64); +} + +void DreamWebEngine::fadeUpMon() { + palToStartPal(); + palToEndPal(); + memset(_startPal + 231 * 3, 0, 8 * 3); + memset(_startPal + 246 * 3, 0, 1 * 3); + _fadeDirection = 1; + _fadeCount = 63; + _colourPos = 0; + _numToFade = 128; + hangOn(128); +} + +void DreamWebEngine::initialMonCols() { + palToStartPal(); + memset(_startPal + 230 * 3, 0, 9 * 3); + memset(_startPal + 246 * 3, 0, 1 * 3); + processEvents(); + setPalette(_startPal + 230 * 3, 230, 18); +} + +void DreamWebEngine::fadeScreenUp() { clearStartPal(); palToEndPal(); - data.byte(kFadedirection) = 1; - data.byte(kFadecount) = 63; - data.byte(kColourpos) = 0; - data.byte(kNumtofade) = 128; + _fadeDirection = 1; + _fadeCount = 63; + _colourPos = 0; + _numToFade = 128; } -void DreamBase::fadeScreenUps() { +void DreamWebEngine::fadeScreenUps() { clearStartPal(); palToEndPal(); - data.byte(kFadedirection) = 1; - data.byte(kFadecount) = 63; - data.byte(kColourpos) = 0; - data.byte(kNumtofade) = 64; + _fadeDirection = 1; + _fadeCount = 63; + _colourPos = 0; + _numToFade = 64; } -void DreamBase::fadeScreenUpHalf() { +void DreamWebEngine::fadeScreenUpHalf() { endPalToStart(); palToEndPal(); - data.byte(kFadedirection) = 1; - data.byte(kFadecount) = 31; - data.byte(kColourpos) = 0; - data.byte(kNumtofade) = 32; + _fadeDirection = 1; + _fadeCount = 31; + _colourPos = 0; + _numToFade = 32; } -void DreamBase::fadeScreenDown() { +void DreamWebEngine::fadeScreenDown() { palToStartPal(); clearEndPal(); - data.byte(kFadedirection) = 1; - data.byte(kFadecount) = 63; - data.byte(kColourpos) = 0; - data.byte(kNumtofade) = 128; + _fadeDirection = 1; + _fadeCount = 63; + _colourPos = 0; + _numToFade = 128; } -void DreamBase::fadeScreenDowns() { +void DreamWebEngine::fadeScreenDowns() { palToStartPal(); clearEndPal(); - data.byte(kFadedirection) = 1; - data.byte(kFadecount) = 63; - data.byte(kColourpos) = 0; - data.byte(kNumtofade) = 64; + _fadeDirection = 1; + _fadeCount = 63; + _colourPos = 0; + _numToFade = 64; +} + +void DreamWebEngine::fadeScreenDownHalf() { + palToStartPal(); + palToEndPal(); + + const uint8 *startPal = _startPal; + uint8 *endPal = _endPal; + for (int i = 0; i < 256 * 3; ++i) { + *endPal >>= 1; + endPal++; + } + + memcpy(endPal + (56*3), startPal + (56*3), 3*5); + memcpy(endPal + (77*3), startPal + (77*3), 3*2); + + _fadeDirection = 1; + _fadeCount = 31; + _colourPos = 0; + _numToFade = 32; } -void DreamGenContext::clearPalette() { - data.byte(kFadedirection) = 0; + +void DreamWebEngine::clearPalette() { + _fadeDirection = 0; clearStartPal(); dumpCurrent(); } // Converts palette to grey scale, summed using formula // .20xred + .59xGreen + .11xBlue -void DreamBase::greyscaleSum() { - byte *src = mainPalette(); - byte *dst = endPalette(); +void DreamWebEngine::greyscaleSum() { + byte *src = _mainPal; + byte *dst = _endPal; for (int i = 0; i < 256; ++i) { const unsigned int r = 20 * *src++; @@ -205,51 +247,38 @@ void DreamBase::greyscaleSum() { tmp = grey; //if (tmp != 0) // FIXME: The assembler code has this check commented out. Bug or feature? - tmp += data.byte(kAddtored); + tmp += _addToRed; *dst++ = tmp; tmp = grey; if (tmp != 0) - tmp += data.byte(kAddtogreen); + tmp += _addToGreen; *dst++ = tmp; tmp = grey; if (tmp != 0) - tmp += data.byte(kAddtoblue); + tmp += _addToBlue; *dst++ = tmp; } } -void DreamBase::allPalette() { - memcpy(startPalette(), mainPalette(), 3 * 256); +void DreamWebEngine::allPalette() { + memcpy(_startPal, _mainPal, 3 * 256); dumpCurrent(); } -void DreamBase::dumpCurrent() { - uint8 *pal = startPalette(); +void DreamWebEngine::dumpCurrent() { + uint8 *pal = _startPal; - engine->waitForVSync(); - engine->processEvents(); - engine->setPalette(pal, 0, 128); + waitForVSync(); + processEvents(); + setPalette(pal, 0, 128); pal += 128 * 3; - engine->waitForVSync(); - engine->processEvents(); - engine->setPalette(pal, 128, 128); -} - -void DreamGenContext::showGroup() { - engine->processEvents(); - unsigned n = (uint16)cx; - uint8 *src = ds.ptr(si, n * 3); - engine->setPalette(src, al, n); - si += n * 3; - cx = 0; -} - -void DreamGenContext::rollEndCredits2() { - rollEm(); + waitForVSync(); + processEvents(); + setPalette(pal, 128, 128); } -} // End of namespace DreamGen +} // End of namespace DreamWeb diff --git a/engines/dreamweb/vgagrafx.cpp b/engines/dreamweb/vgagrafx.cpp index cea9dbef8c..a66f156a1d 100644 --- a/engines/dreamweb/vgagrafx.cpp +++ b/engines/dreamweb/vgagrafx.cpp @@ -21,20 +21,15 @@ */ #include "dreamweb/dreamweb.h" -#include "dreamweb/stubs.h" #include "engines/util.h" #include "graphics/surface.h" -namespace DreamGen { +namespace DreamWeb { -void DreamGenContext::multiGet() { - multiGet(ds.ptr(si, 0), di, bx, cl, ch); - si += cl * ch; - di += bx * kScreenwidth + kScreenwidth * ch; - cx = 0; -} +const uint16 kZoomx = 8; +const uint16 kZoomy = 132; -void DreamBase::multiGet(uint8 *dst, uint16 x, uint16 y, uint8 w, uint8 h) { +void DreamWebEngine::multiGet(uint8 *dst, uint16 x, uint16 y, uint8 w, uint8 h) { assert(x < 320); assert(y < 200); const uint8 *src = workspace() + x + y * kScreenwidth; @@ -50,14 +45,7 @@ void DreamBase::multiGet(uint8 *dst, uint16 x, uint16 y, uint8 w, uint8 h) { } } -void DreamGenContext::multiPut() { - multiPut(ds.ptr(si, 0), di, bx, cl, ch); - si += cl * ch; - di += bx * kScreenwidth + kScreenwidth * ch; - cx = 0; -} - -void DreamBase::multiPut(const uint8 *src, uint16 x, uint16 y, uint8 w, uint8 h) { +void DreamWebEngine::multiPut(const uint8 *src, uint16 x, uint16 y, uint8 w, uint8 h) { assert(x < 320); assert(y < 200); uint8 *dst = workspace() + x + y * kScreenwidth; @@ -73,39 +61,17 @@ void DreamBase::multiPut(const uint8 *src, uint16 x, uint16 y, uint8 w, uint8 h) } } -void DreamGenContext::multiDump() { - multiDump(di, bx, cl, ch); - unsigned offset = di + bx * kScreenwidth; - si = di = offset + ch * kScreenwidth; - cx = 0; -} - -void DreamBase::multiDump(uint16 x, uint16 y, uint8 width, uint8 height) { +void DreamWebEngine::multiDump(uint16 x, uint16 y, uint8 width, uint8 height) { unsigned offset = x + y * kScreenwidth; //debug(1, "multiDump %ux%u(segment: %04x) -> %d,%d(address: %d)", w, h, (uint16)ds, x, y, offset); - engine->blit(workspace() + offset, kScreenwidth, x, y, width, height); -} - -void DreamBase::workToScreenCPP() { - engine->blit(workspace(), 320, 0, 0, 320, 200); -} - -void DreamGenContext::workToScreen() { - workToScreenCPP(); - uint size = 320 * 200; - di = si = size; - cx = 0; + blit(workspace() + offset, kScreenwidth, x, y, width, height); } -void DreamBase::printUnderMon() { - engine->printUnderMonitor(); +void DreamWebEngine::workToScreen() { + blit(workspace(), 320, 0, 0, 320, 200); } -void DreamBase::cls() { - engine->cls(); -} - -void DreamBase::frameOutNm(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y) { +void DreamWebEngine::frameOutNm(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y) { dst += pitch * y + x; for (uint16 j = 0; j < height; ++j) { @@ -115,7 +81,7 @@ void DreamBase::frameOutNm(uint8 *dst, const uint8 *src, uint16 pitch, uint16 wi } } -void DreamBase::frameOutBh(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y) { +void DreamWebEngine::frameOutBh(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y) { uint16 stride = pitch - width; dst += y * pitch + x; @@ -131,7 +97,7 @@ void DreamBase::frameOutBh(uint8 *dst, const uint8 *src, uint16 pitch, uint16 wi } } -void DreamBase::frameOutFx(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y) { +void DreamWebEngine::frameOutFx(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, uint16 x, uint16 y) { uint16 stride = pitch - width; dst += y * pitch + x; dst -= width; @@ -148,8 +114,8 @@ void DreamBase::frameOutFx(uint8 *dst, const uint8 *src, uint16 pitch, uint16 wi } } -void DreamBase::doShake() { - uint8 &counter = data.byte(kShakecounter); +void DreamWebEngine::doShake() { + uint8 &counter = _vars._shakeCounter; if (counter == 48) return; @@ -175,19 +141,20 @@ void DreamBase::doShake() { }; assert(counter < ARRAYSIZE(shakeTable)); int offset = shakeTable[counter]; - engine->setShakePos(offset >= 0 ? offset : -offset); + setShakePos(offset >= 0 ? offset : -offset); } -void DreamBase::vSync() { - engine->waitForVSync(); +void DreamWebEngine::vSync() { + waitForVSync(); } -void DreamBase::setMode() { - engine->waitForVSync(); +void DreamWebEngine::setMode() { + waitForVSync(); initGraphics(320, 200, false); } -void DreamBase::showPCX(const Common::String &name) { +void DreamWebEngine::showPCX(const Common::String &suffix) { + Common::String name = getDatafilePrefix() + suffix; Common::File pcxFile; if (!pcxFile.open(name)) { @@ -202,7 +169,7 @@ void DreamBase::showPCX(const Common::String &name) { // the color components have to be adjusted from 8 to 6 bits. pcxFile.seek(16, SEEK_SET); - mainGamePal = mainPalette(); + mainGamePal = _mainPal; pcxFile.read(mainGamePal, 48); memset(mainGamePal + 48, 0xff, 720); @@ -255,7 +222,7 @@ void DreamBase::showPCX(const Common::String &name) { pcxFile.close(); } -void DreamBase::frameOutV(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, int16 x, int16 y) { +void DreamWebEngine::frameOutV(uint8 *dst, const uint8 *src, uint16 pitch, uint16 width, uint16 height, int16 x, int16 y) { // NB : These resilience checks were not in the original engine, but did they result in undefined behaviour // or was something broken during porting to C++? assert(pitch == 320); @@ -297,90 +264,109 @@ void DreamBase::frameOutV(uint8 *dst, const uint8 *src, uint16 pitch, uint16 wid } } -void DreamBase::showFrame(const Frame *frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag) { +void DreamWebEngine::showFrame(const GraphicsFile &frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag) { uint8 width, height; showFrame(frameData, x, y, frameNumber, effectsFlag, &width, &height); } -void DreamBase::showFrame(const Frame *frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag, uint8 *width, uint8 *height) { - const Frame *frame = frameData + frameNumber; - if ((frame->width == 0) && (frame->height == 0)) { - *width = 0; - *height = 0; - return; - } - -//notBlankShow: - if ((effectsFlag & 128) == 0) { - x += frame->x; - y += frame->y; - } -//skipOffsets: - - *width = frame->width; - *height = frame->height; - const uint8 *pSrc = ((const uint8 *)frameData) + frame->ptr() + 2080; - +void DreamWebEngine::showFrameInternal(const uint8 *pSrc, uint16 x, uint16 y, uint8 effectsFlag, uint8 width, uint8 height) { if (effectsFlag) { if (effectsFlag & 128) { //centred - x -= *width / 2; - y -= *height / 2; + x -= width / 2; + y -= height / 2; } - if (effectsFlag & 64) { //diffDest - error("Unsupported DreamBase::showFrame effectsFlag %d", effectsFlag); + if (effectsFlag & 64) { // diffDest + error("Unsupported DreamWebEngine::showFrame effectsFlag %d", effectsFlag); /* frameOutFx(es.ptr(0, dx * *height), pSrc, dx, *width, *height, x, y); return; */ } - if (effectsFlag & 8) { //printList - /* - push(ax); - al = x - data.word(kMapadx); - ah = y - data.word(kMapady); - //addToPrintList(); // NB: Commented in the original asm - ax = pop(); - */ + if (effectsFlag & 8) { // printList + //addToPrintList(x - _mapAdX, y - _mapAdY); // NB: Commented in the original asm } - if (effectsFlag & 4) { //flippedX - frameOutFx(workspace(), pSrc, 320, *width, *height, x, y); + if (effectsFlag & 4) { // flippedX + frameOutFx(workspace(), pSrc, 320, width, height, x, y); return; } - if (effectsFlag & 2) { //noMask - frameOutNm(workspace(), pSrc, 320, *width, *height, x, y); + if (effectsFlag & 2) { // noMask + frameOutNm(workspace(), pSrc, 320, width, height, x, y); return; } if (effectsFlag & 32) { - frameOutBh(workspace(), pSrc, 320, *width, *height, x, y); + frameOutBh(workspace(), pSrc, 320, width, height, x, y); return; } } -//noEffects: - frameOutV(workspace(), pSrc, 320, *width, *height, x, y); - return; + // "noEffects" + frameOutV(workspace(), pSrc, 320, width, height, x, y); } -void DreamGenContext::showFrame() { - uint8 width, height; - showFrame((Frame *)ds.ptr(0, 0), di, bx, ax & 0x1ff, ah & 0xfe, &width, &height); - cl = width; - ch = height; +void DreamWebEngine::showFrame(const GraphicsFile &frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag, uint8 *width, uint8 *height) { + const Frame *frame = &frameData._frames[frameNumber]; + if ((frame->width == 0) && (frame->height == 0)) { + *width = 0; + *height = 0; + return; + } + + // "notBlankShow" + if ((effectsFlag & 128) == 0) { + x += frame->x; + y += frame->y; + } + + // "skipOffsets" + *width = frame->width; + *height = frame->height; + const uint8 *pSrc = frameData.getFrameData(frameNumber); + + showFrameInternal(pSrc, x, y, effectsFlag, *width, *height); } -void DreamBase::clearWork() { +void DreamWebEngine::clearWork() { memset(workspace(), 0, 320*200); } -void DreamGenContext::zoom() { - if (data.word(kWatchingtime) != 0) +void DreamWebEngine::dumpZoom() { + if (_vars._zoomOn == 1) + multiDump(kZoomx + 5, kZoomy + 4, 46, 40); +} + +void DreamWebEngine::crosshair() { + uint8 frame; + if ((_commandType != 3) && (_commandType < 10)) { + frame = 9; + } else { + frame = 29; + } + showFrame(_icons1, kZoomx + 24, kZoomy + 19, frame, 0); +} + +void DreamWebEngine::getUnderZoom() { + multiGet(_zoomSpace, kZoomx + 5, kZoomy + 4, 46, 40); +} + +void DreamWebEngine::putUnderZoom() { + multiPut(_zoomSpace, kZoomx + 5, kZoomy + 4, 46, 40); +} + +void DreamWebEngine::zoomIcon() { + if (_vars._zoomOn == 0) + return; + showFrame(_icons1, kZoomx, kZoomy-1, 8, 0); +} + +void DreamWebEngine::zoom() { + if (_vars._watchingTime != 0) return; - if (data.byte(kZoomon) != 1) + if (_vars._zoomOn != 1) return; - if (data.byte(kCommandtype) >= 199) { + if (_commandType >= 199) { putUnderZoom(); return; } - uint16 srcOffset = (data.word(kOldpointery) - 9) * 320 + (data.word(kOldpointerx) - 11); + uint16 srcOffset = (_oldPointerY - 9) * 320 + (_oldPointerX - 11); uint16 dstOffset = (kZoomy + 4) * 320 + (kZoomx + 5); const uint8 *src = workspace() + srcOffset; uint8 *dst = workspace() + dstOffset; @@ -396,62 +382,42 @@ void DreamGenContext::zoom() { dst += 320*2; } crosshair(); - data.byte(kDidzoom) = 1; -} - -uint8 *DreamBase::mapStore() { - return getSegment(data.word(kMapstore)).ptr(0, 0); -} - -void DreamBase::panelToMap() { - multiGet(mapStore(), data.word(kMapxstart) + data.word(kMapadx), data.word(kMapystart) + data.word(kMapady), data.byte(kMapxsize), data.byte(kMapysize)); + _didZoom = 1; } -void DreamBase::mapToPanel() { - multiPut(mapStore(), data.word(kMapxstart) + data.word(kMapadx), data.word(kMapystart) + data.word(kMapady), data.byte(kMapxsize), data.byte(kMapysize)); +void DreamWebEngine::panelToMap() { + multiGet(_mapStore, _mapXStart + _mapAdX, _mapYStart + _mapAdY, _mapXSize, _mapYSize); } -void DreamBase::dumpMap() { - multiDump(data.word(kMapxstart) + data.word(kMapadx), data.word(kMapystart) + data.word(kMapady), data.byte(kMapxsize), data.byte(kMapysize)); +void DreamWebEngine::mapToPanel() { + multiPut(_mapStore, _mapXStart + _mapAdX, _mapYStart + _mapAdY, _mapXSize, _mapYSize); } -void DreamBase::transferInv() { - const Frame *freeFrames = (const Frame *)getSegment(data.word(kFreeframes)).ptr(kFrframedata, 0); - const Frame *freeFrame = freeFrames + (3 * data.byte(kItemtotran) + 1); - Frame *exFrames = (Frame *)getSegment(data.word(kExtras)).ptr(kExframedata, 0); - Frame *exFrame = exFrames + (3 * data.byte(kExpos) + 1); - exFrame->width = freeFrame->width; - exFrame->height = freeFrame->height; - exFrame->x = freeFrame->x; - exFrame->y = freeFrame->y; - uint16 byteCount = freeFrame->width * freeFrame->height; - const uint8 *src = getSegment(data.word(kFreeframes)).ptr(kFrframes + freeFrame->ptr(), byteCount); - uint8 *dst = getSegment(data.word(kExtras)).ptr(kExframes + data.word(kExframepos), byteCount); - memcpy(dst, src, byteCount); - exFrame->setPtr(data.word(kExframepos)); - data.word(kExframepos) += byteCount; +void DreamWebEngine::dumpMap() { + multiDump(_mapXStart + _mapAdX, _mapYStart + _mapAdY, _mapXSize, _mapYSize); } -bool DreamGenContext::pixelCheckSet(const ObjPos *pos, uint8 x, uint8 y) { +bool DreamWebEngine::pixelCheckSet(const ObjPos *pos, uint8 x, uint8 y) { x -= pos->xMin; y -= pos->yMin; SetObject *setObject = getSetAd(pos->index); - Frame *frame = (Frame *)getSegment(data.word(kSetframes)).ptr(kFramedata, 0) + setObject->index; - const uint8 *ptr = getSegment(data.word(kSetframes)).ptr(kFrames, 0) + frame->ptr() + y * frame->width + x; + const Frame &frame = _setFrames._frames[setObject->index]; + const uint8 *ptr = _setFrames.getFrameData(setObject->index) + y * frame.width + x; return *ptr != 0; } -void DreamBase::loadPalFromIFF() { +void DreamWebEngine::loadPalFromIFF() { Common::File palFile; - palFile.open("DREAMWEB.PAL"); - palFile.read(mapStore(), 2000); + uint8* buf = new uint8[2000]; + palFile.open(getDatafilePrefix() + "PAL"); + palFile.read(buf, 2000); palFile.close(); - const uint8 *src = mapStore() + 0x30; - uint8 *dst = mainPalette(); + const uint8 *src = buf + 0x30; + uint8 *dst = _mainPal; for (size_t i = 0; i < 256*3; ++i) { uint8 c = src[i] / 4; - if (data.byte(kBrightness) == 1) { + if (_brightPalette) { if (c) { c = c + c / 2 + c / 4; if (c > 63) @@ -460,24 +426,44 @@ void DreamBase::loadPalFromIFF() { } dst[i] = c; } + + delete[] buf; } -void DreamBase::createPanel() { - showFrame(engine->icons2(), 0, 8, 0, 2); - showFrame(engine->icons2(), 160, 8, 0, 2); - showFrame(engine->icons2(), 0, 104, 0, 2); - showFrame(engine->icons2(), 160, 104, 0, 2); +void DreamWebEngine::createPanel() { + showFrame(_icons2, 0, 8, 0, 2); + showFrame(_icons2, 160, 8, 0, 2); + showFrame(_icons2, 0, 104, 0, 2); + showFrame(_icons2, 160, 104, 0, 2); } -void DreamBase::createPanel2() { +void DreamWebEngine::createPanel2() { createPanel(); - showFrame(engine->icons2(), 0, 0, 5, 2); - showFrame(engine->icons2(), 160, 0, 5, 2); + showFrame(_icons2, 0, 0, 5, 2); + showFrame(_icons2, 160, 0, 5, 2); +} + +void DreamWebEngine::showPanel() { + showFrame(_icons1, 72, 0, 19, 0); + showFrame(_icons1, 192, 0, 19, 0); } -void DreamBase::showPanel() { - showFrame(engine->icons1(), 72, 0, 19, 0); - showFrame(engine->icons1(), 192, 0, 19, 0); +void DreamWebEngine::transferFrame(uint8 from, uint8 to, uint8 offset) { + const Frame &freeFrame = _freeFrames._frames[3*from + offset]; + Frame &exFrame = _exFrames._frames[3*to + offset]; + + exFrame.width = freeFrame.width; + exFrame.height = freeFrame.height; + exFrame.x = freeFrame.x; + exFrame.y = freeFrame.y; + uint16 byteCount = freeFrame.width * freeFrame.height; + + const uint8 *src = _freeFrames.getFrameData(3*from + offset); + uint8 *dst = _exFrames._data + _vars._exFramePos; + memcpy(dst, src, byteCount); + + exFrame.setPtr(_vars._exFramePos); + _vars._exFramePos += byteCount; } -} // End of namespace DreamGen +} // End of namespace DreamWeb |