1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef ADL_ADL_V4_H
24 #define ADL_ADL_V4_H
25 
26 #include "adl/adl_v3.h"
27 
28 namespace Adl {
29 
30 // Base track/sector for a region
31 struct RegionLocation {
32 	byte track;
33 	byte sector;
34 };
35 
36 // Location of the 7 initial data blocks, relative to RegionLocation
37 struct RegionInitDataOffset {
38 	byte track;
39 	byte sector;
40 	byte offset;
41 	byte volume;
42 };
43 
44 class AdlEngine_v4 : public AdlEngine_v3 {
45 public:
46 	~AdlEngine_v4() override;
47 
48 protected:
49 	AdlEngine_v4(OSystem *syst, const AdlGameDescription *gd);
50 
51 	// AdlEngine
52 	void setupOpcodeTables() override;
53 	void gameLoop() override;
54 	void loadState(Common::ReadStream &stream) override;
55 	void saveState(Common::WriteStream &stream) override;
56 	Common::String loadMessage(uint idx) const override;
57 	Common::String getItemDescription(const Item &item) const override;
58 	void switchRegion(byte region) override;
59 	void switchRoom(byte roomNr) override;
60 
61 	// AdlEngine_v2
62 	void adjustDataBlockPtr(byte &track, byte &sector, byte &offset, byte &size) const override;
63 
64 	enum RegionChunkType {
65 		kRegionChunkUnknown,
66 		kRegionChunkMessages,
67 		kRegionChunkGlobalPics,
68 		kRegionChunkVerbs,
69 		kRegionChunkNouns,
70 		kRegionChunkRooms,
71 		kRegionChunkRoomCmds,
72 		kRegionChunkGlobalCmds
73 	};
74 
75 	void loadRegionLocations(Common::ReadStream &stream, uint regions);
76 	void loadRegionInitDataOffsets(Common::ReadStream &stream, uint regions);
77 	void initRegions(const byte *roomsPerRegion, uint regions);
78 	void fixupDiskOffset(byte &track, byte &sector) const;
79 	virtual RegionChunkType getRegionChunkType(const uint16 addr) const;
80 	void loadRegion(byte region);
81 	void loadItemPicIndex(Common::ReadStream &stream, uint items);
82 	void backupRoomState(byte room);
83 	virtual void initRoomState(RoomState &roomState) const;
84 	virtual byte restoreRoomState(byte room);
85 	void backupVars();
86 	void restoreVars();
87 
88 	int o_isItemInRoom(ScriptEnv &e) override;
89 	virtual int o_isVarGT(ScriptEnv &e);
90 	int o_moveItem(ScriptEnv &e) override;
91 	virtual int o_setRegionToPrev(ScriptEnv &e);
92 	int o_moveAllItems(ScriptEnv &e) override;
93 	virtual int o_setRegion(ScriptEnv &e);
94 	int o_save(ScriptEnv &e) override;
95 	int o_restore(ScriptEnv &e) override;
96 	int o_restart(ScriptEnv &e) override;
97 	virtual int o_setRegionRoom(ScriptEnv &e);
98 	int o_setRoomPic(ScriptEnv &e) override;
99 
100 	Common::Array<RegionLocation> _regionLocations;
101 	Common::Array<RegionInitDataOffset> _regionInitDataOffsets;
102 	Common::SeekableReadStream *_itemPicIndex;
103 };
104 
105 } // End of namespace Adl
106 
107 #endif
108