aboutsummaryrefslogtreecommitdiff
path: root/engines/agi/loader_preagi.cpp
blob: 7d155b961f0084c80b489df715da8abea1dffbda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/* 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.
 *
 * $URL$
 * $Id$
 *
 */

#include "common/stdafx.h"

#include "agi/agi.h"
#include "agi/lzw.h"
#include "agi/preagi_mickey.h"

#include "common/config-manager.h"
#include "common/fs.h"

namespace Agi {

int AgiLoader_preagi::version() {
	return 0;
}

void AgiLoader_preagi::setIntVersion(int ver) {
	_intVersion = ver;
}

int AgiLoader_preagi::getIntVersion() {
	return _intVersion;
}

int AgiLoader_preagi::detectGame() {
	// TODO: Only Mickey/Winnie are detected for now
	if (!(Common::File::exists("1.pic") || Common::File::exists("title.pic")))
		return errInvalidAGIFile;

	_intVersion = 0x0000;
	return errOK;
}

int AgiLoader_preagi::loadDir(struct AgiDir *agid, Common::File *fp,
						   uint32 offs, uint32 len) {
	int ec = errOK;
/*	uint8 *mem;
	unsigned int i;

	fp->seek(offs, SEEK_SET);
	if ((mem = (uint8 *)malloc(len + 32)) != NULL) {
		fp->read(mem, len);

		// set all directory resources to gone
		for (i = 0; i < MAX_DIRS; i++) {
			agid[i].volume = 0xff;
			agid[i].offset = _EMPTY;
		}

		// build directory entries
		for (i = 0; i < len; i += 3) {
			agid[i / 3].volume = *(mem + i) >> 4;
			agid[i / 3].offset = READ_BE_UINT24(mem + i) & (uint32) _EMPTY;
		}

		free(mem);
	} else {
		ec = errNotEnoughMemory;
	}
*/
	return ec;
}

int AgiLoader_preagi::init() {
	int ec = errOK;
	//int i;
	//uint16 xd[4];
	Common::File fp;
	Common::String path;

	// TODO : load all preagi resources here

	return ec;
}

int AgiLoader_preagi::deinit() {
	int ec = errOK;
	return ec;
}

int AgiLoader_preagi::unloadResource(int t, int n) {
	switch (t) {
	case rPICTURE:
		_vm->_picture->unloadPicture(n);
		break;
	case rVIEW:
		//_vm->unloadView(n);
		break;
	case rSOUND:
		//_vm->_sound->unloadSound(n);
		break;
	}

	return errOK;
}

/*
 * This function does noting but load a raw resource into memory.
 * If further decoding is required, it must be done by another
 * routine.
 *
 * NULL is returned if unsucsessful.
 */
uint8 *AgiLoader_preagi::loadVolRes(AgiDir *agid) {

	return NULL;
}

/*
 * Loads a resource into memory, a raw resource is loaded in
 * with above routine, then further decoded here.
 */
int AgiLoader_preagi::loadResource(int t, int n) {
	int ec = errOK;
	uint8 *data = NULL;
	char szFile[255] = {0};
	Common::File infile;

	if (n > MAX_DIRS)
		return errBadResource;

	switch (t) {
	case rPICTURE:
		/* if picture is currently NOT loaded *OR* cacheing is off,
		 * unload the resource (caching==off) and reload it
		 */
		if (~_vm->_game.dirPic[n].flags & RES_LOADED) {
			unloadResource(rPICTURE, n);

			data = new uint8[4096];

			sprintf(szFile, IDS_MSA_PATH_PIC, n);
			if (!infile.open(szFile))
				return errBadResource;
			infile.read(data, infile.size());

			if (data != NULL) {
				_vm->_game.pictures[n].rdata = data;
				_vm->_game.dirPic[n].len = infile.size();
				_vm->_game.dirPic[n].flags |= RES_LOADED;
			} else {
				ec = errBadResource;
			}

			infile.close();
		}
		break;
	case rSOUND:
		/*
		if (_vm->_game.dirSound[n].flags & RES_LOADED)
			break;

		data = loadVolRes(&_vm->_game.dirSound[n]);
		if (data != NULL) {
			// Freeing of the raw resource from memory is delegated to the createFromRawResource-function
			_vm->_game.sounds[n] = AgiSound::createFromRawResource(data, _vm->_game.dirSound[n].len, n, *_vm->_sound);
			_vm->_game.dirSound[n].flags |= RES_LOADED;
		} else {
			ec = errBadResource;
		}
		*/
		break;
	case rVIEW:
			data = new uint8[4096];

			sprintf(szFile, IDS_MSA_PATH_OBJ, IDS_MSA_NAME_OBJ[n]);

			if (!infile.open(szFile))
				return errBadResource;
			infile.read(data, infile.size());

			if (data != NULL) {
				_vm->_game.pictures[n].rdata = data;
				_vm->_game.dirPic[n].len = infile.size();
				_vm->_game.dirPic[n].flags |= RES_LOADED;
			} else {
				ec = errBadResource;
			}

			infile.close();
		break;
	default:
		ec = errBadResource;
		break;
	}

	return ec;
}

/*
 * Loads a resource into memory, a raw resource is loaded in
 * with above routine, then further decoded here.
 */
int AgiLoader_preagi::loadResource(int t, const char* n) {
	int ec = errOK;
	uint8 *data = NULL;
	Common::File infile;

	switch (t) {
	case rPICTURE:
		/* if picture is currently NOT loaded *OR* cacheing is off,
		 * unload the resource (caching==off) and reload it
		 */
		if (~_vm->_game.dirPic[0].flags & RES_LOADED)
			unloadResource(rPICTURE, 0);

		data = new uint8[4096];

		if (!infile.open(n))
			return errBadResource;
		infile.read(data, infile.size());

		if (data != NULL) {
			_vm->_game.pictures[0].rdata = data;
			_vm->_game.dirPic[0].len = infile.size();
			_vm->_game.dirPic[0].flags |= RES_LOADED;
		} else {
			ec = errBadResource;
		}

		infile.close();
		break;
	case rSOUND:
		break;
	case rVIEW:
		break;
	default:
		ec = errBadResource;
		break;
	}

	return ec;
}

/*
 * Loads a resource into memory, a raw resource is loaded in
 * with above routine, then further decoded here.
 */
int AgiLoader_preagi::loadResource(int t, byte* n) {
	int ec = errOK;

	switch (t) {
	case rPICTURE:
		/* if picture is currently NOT loaded *OR* cacheing is off,
		 * unload the resource (caching==off) and reload it
		 */
		if (~_vm->_game.dirPic[0].flags & RES_LOADED)
			unloadResource(rPICTURE, 0);

		if (n != NULL) {
			_vm->_game.pictures[0].rdata = n;
			// FIXME: Fingolfin asks: why is there a FIXME here? Please either clarify what
			// needs fixing, or remove it!
			_vm->_game.dirPic[0].len = 4096;		//FIXME
			_vm->_game.dirPic[0].flags |= RES_LOADED;
		} else {
			ec = errBadResource;
		}
		break;
	case rSOUND:
		break;
	case rVIEW:
		break;
	default:
		ec = errBadResource;
		break;
	}

	return ec;
}

int AgiLoader_preagi::loadObjects(const char *fname) {
	return 0;
	//return _vm->loadObjects(fname);
}

int AgiLoader_preagi::loadWords(const char *fname) {
	return 0;
	//return _vm->loadWords(fname);
}

} // End of namespace Agi