aboutsummaryrefslogtreecommitdiff
path: root/engines/adl/adl_v5.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/adl/adl_v5.cpp')
-rw-r--r--engines/adl/adl_v5.cpp141
1 files changed, 57 insertions, 84 deletions
diff --git a/engines/adl/adl_v5.cpp b/engines/adl/adl_v5.cpp
index 795899c070..929ffff7f4 100644
--- a/engines/adl/adl_v5.cpp
+++ b/engines/adl/adl_v5.cpp
@@ -33,6 +33,27 @@ AdlEngine_v5::AdlEngine_v5(OSystem *syst, const AdlGameDescription *gd) :
AdlEngine_v4(syst, gd) {
}
+void AdlEngine_v5::initRoomState(RoomState &roomState) const {
+ roomState.picture = 0xff;
+ roomState.isFirstTime = 0xff;
+}
+
+byte AdlEngine_v5::restoreRoomState(byte room) {
+ const RoomState &backup = getCurRegion().rooms[room - 1];
+
+ if (backup.isFirstTime != 0xff) {
+ getRoom(room).curPicture = getRoom(room).picture = backup.picture;
+
+ // CHECKME: Why doesn't this just copy the flag unconditionally?
+ if (backup.isFirstTime != 1) {
+ getRoom(room).isFirstTime = false;
+ return 0;
+ }
+ }
+
+ return backup.isFirstTime;
+}
+
AdlEngine_v5::RegionChunkType AdlEngine_v5::getRegionChunkType(const uint16 addr) const {
switch (addr) {
case 0x7b00:
@@ -44,75 +65,6 @@ AdlEngine_v5::RegionChunkType AdlEngine_v5::getRegionChunkType(const uint16 addr
}
}
-typedef Common::Functor1Mem<ScriptEnv &, int, AdlEngine_v5> OpcodeV5;
-#define SetOpcodeTable(x) table = &x;
-#define Opcode(x) table->push_back(new OpcodeV5(this, &AdlEngine_v5::x))
-#define OpcodeUnImpl() table->push_back(new OpcodeV5(this, 0))
-
-void AdlEngine_v5::setupOpcodeTables() {
- Common::Array<const Opcode *> *table = 0;
-
- SetOpcodeTable(_condOpcodes);
- // 0x00
- OpcodeUnImpl();
- Opcode(o2_isFirstTime);
- Opcode(o2_isRandomGT);
- Opcode(o4_isItemInRoom);
- // 0x04
- Opcode(o5_isNounNotInRoom);
- Opcode(o1_isMovesGT);
- Opcode(o1_isVarEQ);
- Opcode(o2_isCarryingSomething);
- // 0x08
- Opcode(o4_isVarGT);
- Opcode(o1_isCurPicEQ);
- Opcode(o5_skipOneCommand);
-
- SetOpcodeTable(_actOpcodes);
- // 0x00
- OpcodeUnImpl();
- Opcode(o1_varAdd);
- Opcode(o1_varSub);
- Opcode(o1_varSet);
- // 0x04
- Opcode(o1_listInv);
- Opcode(o4_moveItem);
- Opcode(o1_setRoom);
- Opcode(o2_setCurPic);
- // 0x08
- Opcode(o2_setPic);
- Opcode(o1_printMsg);
- Opcode(o5_dummy);
- Opcode(o5_setTextMode);
- // 0x0c
- Opcode(o2_moveAllItems);
- Opcode(o1_quit);
- Opcode(o5_dummy);
- Opcode(o2_save);
- // 0x10
- Opcode(o2_restore);
- Opcode(o1_restart);
- Opcode(o5_setRegionRoom);
- Opcode(o5_dummy);
- // 0x14
- Opcode(o1_resetPic);
- Opcode(o1_goDirection<IDI_DIR_NORTH>);
- Opcode(o1_goDirection<IDI_DIR_SOUTH>);
- Opcode(o1_goDirection<IDI_DIR_EAST>);
- // 0x18
- Opcode(o1_goDirection<IDI_DIR_WEST>);
- Opcode(o1_goDirection<IDI_DIR_UP>);
- Opcode(o1_goDirection<IDI_DIR_DOWN>);
- Opcode(o1_takeItem);
- // 0x1c
- Opcode(o1_dropItem);
- Opcode(o1_setRoomPic);
- Opcode(o_winGame);
- OpcodeUnImpl();
- // 0x20
- Opcode(o2_initDisk);
-}
-
int AdlEngine_v5::o5_isNounNotInRoom(ScriptEnv &e) {
OP_DEBUG_1("\t&& NO_SUCH_ITEMS_IN_ROOM(%s)", itemRoomStr(e.arg(1)).c_str());
@@ -131,10 +83,10 @@ int AdlEngine_v5::o5_isNounNotInRoom(ScriptEnv &e) {
return 1;
}
-int AdlEngine_v5::o5_skipOneCommand(ScriptEnv &e) {
- OP_DEBUG_0("\t&& SKIP_ONE_COMMAND()");
+int AdlEngine_v5::o5_abortScript(ScriptEnv &e) {
+ OP_DEBUG_0("\t&& ABORT_SCRIPT()");
- _skipOneCommand = true;
+ _abortScript = true;
setVar(2, 0);
return -1;
@@ -149,33 +101,54 @@ int AdlEngine_v5::o5_dummy(ScriptEnv &e) {
int AdlEngine_v5::o5_setTextMode(ScriptEnv &e) {
OP_DEBUG_1("\tSET_TEXT_MODE(%d)", e.arg(1));
- // TODO
- // 1: 4-line mode
- // 2: 24-line mode
-
switch (e.arg(1)) {
+ case 1:
+ if (_linesPrinted != 0) {
+ _display->printChar(APPLECHAR(' '));
+ handleTextOverflow();
+ _display->moveCursorTo(Common::Point(0, 23));
+ _maxLines = 4;
+ }
+ return 1;
+ case 2:
+ _textMode = true;
+ _display->setMode(DISPLAY_MODE_TEXT);
+ _display->home();
+ _maxLines = 24;
+ _linesPrinted = 0;
+ return 1;
case 3:
// We re-use the restarting flag here, to simulate a long jump
_isRestarting = true;
return -1;
+ default:
+ error("Invalid text mode %d", e.arg(1));
}
-
- return 1;
}
int AdlEngine_v5::o5_setRegionRoom(ScriptEnv &e) {
OP_DEBUG_2("\tSET_REGION_ROOM(%d, %d)", e.arg(1), e.arg(2));
- // TODO
- return 2;
+ getCurRoom().curPicture = getCurRoom().picture;
+ getCurRoom().isFirstTime = false;
+ switchRegion(e.arg(1));
+ _state.room = e.arg(2);
+ restoreRoomState(_state.room);
+ return -1;
}
-int AdlEngine_v5::o_winGame(ScriptEnv &e) {
- OP_DEBUG_0("\tWIN_GAME()");
+int AdlEngine_v5::o5_setRoomPic(ScriptEnv &e) {
+ const byte isFirstTime = restoreRoomState(e.arg(1));
- // TODO
+ // CHECKME: More peculiar isFirstTime handling (see also restoreRoomState).
+ // Is this here to prevent changing the backed up flag from 1 to 0? Since
+ // that could only happen if the room isFirstTime is 0 while the backed up flag
+ // is 1, is this scenario even possible?
+ if (isFirstTime != 0xff)
+ getRoom(e.arg(1)).isFirstTime = isFirstTime;
- return 0;
+ o4_setRoomPic(e);
+ return 2;
}
} // End of namespace Adl