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 
24 #include "scumm/scumm_v3.h"
25 #include "scumm/file.h"
26 #include "scumm/resource.h"
27 #include "scumm/util.h"
28 
29 namespace Scumm {
30 
31 extern const char *nameOfResType(ResType type);
32 
readResTypeList(ResType type)33 int ScummEngine_v3old::readResTypeList(ResType type) {
34 	uint num;
35 	ResId idx;
36 
37 	debug(9, "readResTypeList(%s)", nameOfResType(type));
38 
39 	num = _fileHandle->readByte();
40 
41 	if (num >= 0xFF) {
42 		error("Too many %ss (%d) in directory", nameOfResType(type), num);
43 	}
44 
45 	if (type == rtRoom) {
46 		for (idx = 0; idx < num; idx++)
47 			_res->_types[type][idx]._roomno = idx;
48 		_fileHandle->seek(num, SEEK_CUR);
49 	} else {
50 		for (idx = 0; idx < num; idx++)
51 			_res->_types[type][idx]._roomno = _fileHandle->readByte();
52 	}
53 	for (idx = 0; idx < num; idx++) {
54 		_res->_types[type][idx]._roomoffs = _fileHandle->readUint16LE();
55 		if (_res->_types[type][idx]._roomoffs == 0xFFFF)
56 			_res->_types[type][idx]._roomoffs = (uint32)RES_INVALID_OFFSET;
57 	}
58 
59 	return num;
60 }
61 
readIndexFile()62 void ScummEngine_v3old::readIndexFile() {
63 	int magic = 0;
64 	debug(9, "readIndexFile()");
65 
66 	closeRoom();
67 	openRoom(0);
68 
69 	magic = _fileHandle->readUint16LE();
70 	if (magic != 0x0100)
71 		error("The magic id doesn't match (0x%X)", magic);
72 
73 	_numGlobalObjects = _fileHandle->readUint16LE();
74 	_fileHandle->seek(_numGlobalObjects * 4, SEEK_CUR);
75 	_numRooms = _fileHandle->readByte();
76 	_fileHandle->seek(_numRooms * 3, SEEK_CUR);
77 	_numCostumes = _fileHandle->readByte();
78 	_fileHandle->seek(_numCostumes * 3, SEEK_CUR);
79 	_numScripts = _fileHandle->readByte();
80 	_fileHandle->seek(_numScripts * 3, SEEK_CUR);
81 	_numSounds = _fileHandle->readByte();
82 
83 	_fileHandle->clearErr();
84 	_fileHandle->seek(0, SEEK_SET);
85 
86 	readMAXS(0);
87 	allocateArrays();
88 
89 	_fileHandle->readUint16LE(); /* version magic number */
90 	readGlobalObjects();
91 	readResTypeList(rtRoom);
92 	readResTypeList(rtCostume);
93 	readResTypeList(rtScript);
94 	readResTypeList(rtSound);
95 
96 	closeRoom();
97 }
98 
readRoomsOffsets()99 void ScummEngine_v3::readRoomsOffsets() {
100 }
101 
loadCharset(int no)102 void ScummEngine_v3::loadCharset(int no) {
103 	uint32 size;
104 	memset(_charsetData, 0, sizeof(_charsetData));
105 
106 	assertRange(0, no, 2, "charset");
107 	closeRoom();
108 
109 	Common::File file;
110 	char buf[20];
111 
112 	sprintf(buf, "%02d.LFL", 99 - no);
113 	file.open(buf);
114 
115 	if (file.isOpen() == false) {
116 		error("loadCharset(%d): Missing file charset: %s", no, buf);
117 	}
118 
119 	size = file.readUint16LE();
120 	file.read(_res->createResource(rtCharset, no, size), size);
121 }
122 
123 } // End of namespace Scumm
124