2007-05-30 21:56:52 +00:00
|
|
|
/* 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.
|
2003-07-28 01:44:38 +00:00
|
|
|
*
|
2007-05-31 20:28:29 +00:00
|
|
|
* Additional copyright for this file:
|
|
|
|
* Copyright (C) 1994-1998 Revolution Software Ltd.
|
|
|
|
*
|
2003-07-28 01:44:38 +00:00
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-07-28 01:44:38 +00:00
|
|
|
*/
|
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
#include "common/file.h"
|
|
|
|
#include "common/endian.h"
|
2006-02-17 15:07:36 +00:00
|
|
|
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/sword2.h"
|
2006-02-17 15:07:36 +00:00
|
|
|
#include "sword2/header.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/resman.h"
|
2009-04-07 19:52:46 +00:00
|
|
|
#include "sword2/logic.h"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the first palette entry, given the pointer to the start
|
|
|
|
* of the screen file.
|
|
|
|
*/
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2011-02-15 21:52:15 +00:00
|
|
|
void Sword2Engine::fetchPalette(byte *screenFile, byte *palBuffer) {
|
2009-04-07 19:52:46 +00:00
|
|
|
byte *palette;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2009-09-30 16:16:53 +00:00
|
|
|
if (isPsx()) { // PSX version doesn't have a "MultiScreenHeader", instead there's a ScreenHeader and a tag
|
2009-04-07 19:52:46 +00:00
|
|
|
palette = screenFile + ResHeader::size() + ScreenHeader::size() + 2;
|
|
|
|
} else {
|
|
|
|
MultiScreenHeader mscreenHeader;
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
mscreenHeader.read(screenFile + ResHeader::size());
|
|
|
|
palette = screenFile + ResHeader::size() + mscreenHeader.palette;
|
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2011-04-14 12:12:27 +00:00
|
|
|
// Always set color 0 to black, because while most background screen
|
|
|
|
// palettes have a bright color 0 it should come out as black in the
|
2003-09-19 13:55:19 +00:00
|
|
|
// game.
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2011-02-15 21:52:15 +00:00
|
|
|
palBuffer[0] = 0;
|
|
|
|
palBuffer[1] = 0;
|
|
|
|
palBuffer[2] = 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2011-02-15 21:52:15 +00:00
|
|
|
for (uint i = 4, j = 3; i < 4 * 256; i += 4, j += 3) {
|
|
|
|
palBuffer[j + 0] = palette[i + 0];
|
|
|
|
palBuffer[j + 1] = palette[i + 1];
|
|
|
|
palBuffer[j + 2] = palette[i + 2];
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the start of the palette match table, given the pointer
|
|
|
|
* to the start of the screen file.
|
2009-04-07 19:52:46 +00:00
|
|
|
* It returns NULL when used with PSX version, as there are no palette match tables in
|
|
|
|
* the resource files.
|
2003-11-03 07:47:42 +00:00
|
|
|
*/
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *Sword2Engine::fetchPaletteMatchTable(byte *screenFile) {
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
if (isPsx()) return NULL;
|
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
MultiScreenHeader mscreenHeader;
|
|
|
|
|
|
|
|
mscreenHeader.read(screenFile + ResHeader::size());
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
return screenFile + ResHeader::size() + mscreenHeader.paletteTable;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the screen header, given the pointer to the start of
|
|
|
|
* the screen file.
|
|
|
|
*/
|
2003-09-19 13:55:19 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
byte *Sword2Engine::fetchScreenHeader(byte *screenFile) {
|
2009-04-07 19:52:46 +00:00
|
|
|
if (isPsx()) { // In PSX version there's no MultiScreenHeader, so just skip resource header
|
|
|
|
return screenFile + ResHeader::size();
|
2009-05-24 15:17:42 +00:00
|
|
|
} else {
|
2009-04-07 19:52:46 +00:00
|
|
|
MultiScreenHeader mscreenHeader;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
mscreenHeader.read(screenFile + ResHeader::size());
|
|
|
|
return screenFile + ResHeader::size() + mscreenHeader.screen;
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the requested layer header, given the pointer to the
|
|
|
|
* start of the screen file. Drops out if the requested layer number exceeds
|
|
|
|
* the number of layers on this screen.
|
|
|
|
*/
|
2003-09-19 13:55:19 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
byte *Sword2Engine::fetchLayerHeader(byte *screenFile, uint16 layerNo) {
|
2004-11-16 09:15:25 +00:00
|
|
|
#ifdef SWORD2_DEBUG
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
ScreenHeader screenHead;
|
2003-09-07 03:18:27 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
screenHead.read(fetchScreenHeader(screenFile));
|
|
|
|
assert(layerNo < screenHead.noLayers);
|
2003-07-28 01:44:38 +00:00
|
|
|
#endif
|
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
if (isPsx()) {
|
|
|
|
return screenFile + ResHeader::size() + ScreenHeader::size() + 2 + 0x400 + layerNo * LayerHeader::size();
|
|
|
|
} else {
|
|
|
|
MultiScreenHeader mscreenHeader;
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
mscreenHeader.read(screenFile + ResHeader::size());
|
|
|
|
return screenFile + ResHeader::size() + mscreenHeader.layers + layerNo * LayerHeader::size();
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the start of the shading mask, given the pointer to the
|
|
|
|
* start of the screen file.
|
2009-04-07 19:52:46 +00:00
|
|
|
* If we are non PSX, this will return NULL, as we don't have shading masks.
|
2003-11-03 07:47:42 +00:00
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *Sword2Engine::fetchShadingMask(byte *screenFile) {
|
2009-04-07 19:52:46 +00:00
|
|
|
if (isPsx()) return NULL;
|
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
MultiScreenHeader mscreenHeader;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
mscreenHeader.read(screenFile + ResHeader::size());
|
|
|
|
|
|
|
|
return screenFile + ResHeader::size() + mscreenHeader.maskOffset;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the anim header, given the pointer to the start of the
|
|
|
|
* anim file.
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
byte *Sword2Engine::fetchAnimHeader(byte *animFile) {
|
|
|
|
return animFile + ResHeader::size();
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the requested frame number's cdtEntry, given the
|
|
|
|
* pointer to the start of the anim file. Drops out if the requested frame
|
|
|
|
* number exceeds the number of frames in this anim.
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
byte *Sword2Engine::fetchCdtEntry(byte *animFile, uint16 frameNo) {
|
2004-11-16 09:15:25 +00:00
|
|
|
#ifdef SWORD2_DEBUG
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
AnimHeader animHead;
|
|
|
|
|
|
|
|
animHead.read(fetchAnimHeader(animFile));
|
|
|
|
|
2003-09-19 13:55:19 +00:00
|
|
|
if (frameNo > animHead->noAnimFrames - 1)
|
2009-04-07 19:52:46 +00:00
|
|
|
error("fetchCdtEntry(animFile,%d) - anim only %d frames", frameNo, animHead->noAnimFrames);
|
2003-07-28 01:44:38 +00:00
|
|
|
#endif
|
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
return fetchAnimHeader(animFile) + AnimHeader::size() + frameNo * CdtEntry::size();
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-07 03:18:27 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the requested frame number's header, given the pointer
|
|
|
|
* to the start of the anim file. Drops out if the requested frame number
|
|
|
|
* exceeds the number of frames in this anim
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
byte *Sword2Engine::fetchFrameHeader(byte *animFile, uint16 frameNo) {
|
2003-07-28 01:44:38 +00:00
|
|
|
// required address = (address of the start of the anim header) + frameOffset
|
2009-05-24 15:17:42 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
CdtEntry cdt;
|
|
|
|
|
|
|
|
cdt.read(fetchCdtEntry(animFile, frameNo));
|
|
|
|
|
|
|
|
return animFile + ResHeader::size() + cdt.frameOffset;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the requested parallax layer data.
|
|
|
|
*/
|
2003-09-19 13:55:19 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
byte *Sword2Engine::fetchBackgroundParallaxLayer(byte *screenFile, int layer) {
|
2009-04-07 19:52:46 +00:00
|
|
|
if (isPsx()) {
|
|
|
|
byte *psxParallax = _screen->getPsxScrCache(0);
|
|
|
|
|
|
|
|
// Manage cache for background psx parallaxes
|
|
|
|
if (!_screen->getPsxScrCacheStatus(0)) { // This parallax layer is not present
|
|
|
|
return NULL;
|
|
|
|
} else if (psxParallax != NULL) { // Parallax layer present, and already in cache
|
|
|
|
return psxParallax;
|
|
|
|
} else { // Present, but not cached
|
|
|
|
uint32 locNo = _logic->getLocationNum();
|
|
|
|
|
|
|
|
// At game startup, we have a wrong location number stored
|
|
|
|
// in game vars (0, instead of 3), work around this.
|
|
|
|
locNo = (locNo == 0) ? 3 : locNo;
|
|
|
|
|
|
|
|
psxParallax = fetchPsxParallax(locNo, 0);
|
|
|
|
_screen->setPsxScrCache(psxParallax, 0);
|
|
|
|
return psxParallax;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MultiScreenHeader mscreenHeader;
|
|
|
|
|
|
|
|
mscreenHeader.read(screenFile + ResHeader::size());
|
|
|
|
assert(mscreenHeader.bg_parallax[layer]);
|
|
|
|
return screenFile + ResHeader::size() + mscreenHeader.bg_parallax[layer];
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
byte *Sword2Engine::fetchBackgroundLayer(byte *screenFile) {
|
2009-04-07 19:52:46 +00:00
|
|
|
if (isPsx()) {
|
|
|
|
byte *psxBackground = _screen->getPsxScrCache(1);
|
|
|
|
|
|
|
|
// Manage cache for psx backgrounds
|
|
|
|
if (psxBackground) { // Background is cached
|
|
|
|
return psxBackground;
|
|
|
|
} else { // Background not cached
|
|
|
|
uint32 locNo = _logic->getLocationNum();
|
|
|
|
|
|
|
|
// We have a wrong location number at start, fix that
|
|
|
|
locNo = (locNo == 0) ? 3 : locNo;
|
|
|
|
|
|
|
|
psxBackground = fetchPsxBackground(locNo);
|
|
|
|
_screen->setPsxScrCache(psxBackground, 1);
|
|
|
|
return psxBackground;
|
2009-05-24 15:17:42 +00:00
|
|
|
}
|
2009-04-07 19:52:46 +00:00
|
|
|
} else {
|
|
|
|
MultiScreenHeader mscreenHeader;
|
|
|
|
|
|
|
|
mscreenHeader.read(screenFile + ResHeader::size());
|
|
|
|
assert(mscreenHeader.screen);
|
|
|
|
return screenFile + ResHeader::size() + mscreenHeader.screen + ScreenHeader::size();
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
byte *Sword2Engine::fetchForegroundParallaxLayer(byte *screenFile, int layer) {
|
2009-04-07 19:52:46 +00:00
|
|
|
if (isPsx()) {
|
|
|
|
byte *psxParallax = _screen->getPsxScrCache(2);
|
|
|
|
|
|
|
|
// Manage cache for psx parallaxes
|
|
|
|
if (!_screen->getPsxScrCacheStatus(2)) { // This parallax layer is not present
|
|
|
|
return NULL;
|
|
|
|
} else if (psxParallax) { // Parallax layer present and cached
|
|
|
|
return psxParallax;
|
|
|
|
} else { // Present, but still not cached
|
|
|
|
uint32 locNo = _logic->getLocationNum();
|
|
|
|
|
|
|
|
// We have a wrong location number at start, fix that
|
|
|
|
locNo = (locNo == 0) ? 3 : locNo;
|
|
|
|
|
|
|
|
psxParallax = fetchPsxParallax(locNo, 1);
|
|
|
|
_screen->setPsxScrCache(psxParallax, 2);
|
|
|
|
return psxParallax;
|
2009-05-24 15:17:42 +00:00
|
|
|
}
|
2009-04-07 19:52:46 +00:00
|
|
|
} else {
|
|
|
|
MultiScreenHeader mscreenHeader;
|
|
|
|
|
|
|
|
mscreenHeader.read(screenFile + ResHeader::size());
|
|
|
|
assert(mscreenHeader.fg_parallax[layer]);
|
|
|
|
return screenFile + ResHeader::size() + mscreenHeader.fg_parallax[layer];
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *Sword2Engine::fetchTextLine(byte *file, uint32 text_line) {
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
TextHeader text_header;
|
|
|
|
static byte errorLine[128];
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
text_header.read(file + ResHeader::size());
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
if (text_line >= text_header.noOfLines) {
|
|
|
|
sprintf((char *)errorLine, "xxMissing line %d of %s (only 0..%d)", text_line, _resman->fetchName(file), text_header.noOfLines - 1);
|
2003-09-19 13:55:19 +00:00
|
|
|
|
|
|
|
// first 2 chars are NULL so that actor-number comes out as '0'
|
|
|
|
errorLine[0] = 0;
|
|
|
|
errorLine[1] = 0;
|
|
|
|
return errorLine;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
// The "number of lines" field is followed by a lookup table
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
return file + READ_LE_UINT32(file + ResHeader::size() + 4 + 4 * text_line);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to psx background data for passed location number
|
|
|
|
* At the beginning of the passed data there's an artificial header composed by
|
|
|
|
* uint16: background X resolution
|
|
|
|
* uint16: background Y resolution
|
|
|
|
* uint32: offset to subtract from offset table entries
|
|
|
|
*/
|
|
|
|
|
|
|
|
byte *Sword2Engine::fetchPsxBackground(uint32 location) {
|
|
|
|
Common::File file;
|
|
|
|
PSXScreensEntry header;
|
|
|
|
uint32 screenOffset, dataOffset;
|
|
|
|
uint32 totSize; // Total size of background, counting data, offset table and additional header
|
|
|
|
byte *buffer;
|
|
|
|
|
|
|
|
if (!file.open("screens.clu")) {
|
2010-01-03 21:20:05 +00:00
|
|
|
GUIErrorMessage("Broken Sword II: Cannot open screens.clu");
|
2009-04-07 19:52:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
file.seek(location * 4, SEEK_SET);
|
2009-05-24 15:17:42 +00:00
|
|
|
screenOffset = file.readUint32LE();
|
2009-04-07 19:52:46 +00:00
|
|
|
|
|
|
|
if (screenOffset == 0) { // We don't have screen data for this location number.
|
|
|
|
file.close();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get to the beginning of PSXScreensEntry
|
|
|
|
file.seek(screenOffset + ResHeader::size(), SEEK_SET);
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
buffer = (byte *)malloc(PSXScreensEntry::size());
|
|
|
|
file.read(buffer, PSXScreensEntry::size());
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
// Prepare the header
|
|
|
|
header.read(buffer);
|
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
file.seek(screenOffset + header.bgOffset + 4, SEEK_SET);
|
|
|
|
dataOffset = file.readUint32LE();
|
|
|
|
|
|
|
|
file.seek(screenOffset + header.bgOffset, SEEK_SET);
|
|
|
|
|
|
|
|
totSize = header.bgSize + (dataOffset - header.bgOffset) + 8;
|
|
|
|
buffer = (byte *)malloc(totSize);
|
|
|
|
|
|
|
|
// Write some informations before background data
|
2009-05-24 15:17:42 +00:00
|
|
|
WRITE_LE_UINT16(buffer, header.bgXres);
|
2009-04-07 19:52:46 +00:00
|
|
|
WRITE_LE_UINT16(buffer + 2, header.bgYres);
|
|
|
|
WRITE_LE_UINT32(buffer + 4, header.bgOffset);
|
|
|
|
|
|
|
|
file.read(buffer + 8, totSize - 8); // Do not write on the header
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a pointer to selected psx parallax data for passed location number
|
|
|
|
* At the beginning of the passed data there's an artificial header composed by
|
|
|
|
* uint16: parallax X resolution
|
|
|
|
* uint16: parallax Y resolution
|
|
|
|
* uint16: width in 64x16 tiles of parallax
|
|
|
|
* uint16: height in 64x16 tiles of parallax
|
|
|
|
*/
|
|
|
|
|
|
|
|
byte *Sword2Engine::fetchPsxParallax(uint32 location, uint8 level) {
|
|
|
|
Common::File file;
|
|
|
|
PSXScreensEntry header;
|
|
|
|
uint32 screenOffset;
|
|
|
|
uint16 horTiles; // Number of horizontal tiles in the parallax grid
|
|
|
|
uint16 verTiles; // Number of vertical tiles in parallax grid
|
|
|
|
uint32 totSize; // Total size of parallax, counting data, grid, and additional header
|
|
|
|
byte *buffer;
|
|
|
|
|
|
|
|
uint16 plxXres;
|
|
|
|
uint16 plxYres;
|
|
|
|
uint32 plxOffset;
|
|
|
|
uint32 plxSize;
|
|
|
|
|
|
|
|
if (level > 1)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!file.open("screens.clu")) {
|
2010-01-03 21:20:05 +00:00
|
|
|
GUIErrorMessage("Broken Sword II: Cannot open screens.clu");
|
2009-04-07 19:52:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
file.seek(location * 4, SEEK_SET);
|
2009-05-24 15:17:42 +00:00
|
|
|
screenOffset = file.readUint32LE();
|
2009-04-07 19:52:46 +00:00
|
|
|
|
|
|
|
if (screenOffset == 0) // There is no screen here
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// Get to the beginning of PSXScreensEntry
|
|
|
|
file.seek(screenOffset + ResHeader::size(), SEEK_SET);
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
buffer = (byte *)malloc(PSXScreensEntry::size());
|
|
|
|
file.read(buffer, PSXScreensEntry::size());
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
// Initialize the header
|
|
|
|
header.read(buffer);
|
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
// We are fetching...
|
|
|
|
if (level == 0) { // a background parallax
|
|
|
|
plxXres = header.bgPlxXres;
|
|
|
|
plxYres = header.bgPlxYres;
|
|
|
|
plxOffset = header.bgPlxOffset;
|
|
|
|
plxSize = header.bgPlxSize;
|
|
|
|
} else { // a foreground parallax
|
|
|
|
plxXres = header.fgPlxXres;
|
|
|
|
plxYres = header.fgPlxYres;
|
|
|
|
plxOffset = header.fgPlxOffset;
|
|
|
|
plxSize = header.fgPlxSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plxXres == 0 || plxYres == 0 || plxSize == 0) // This screen has no parallax data.
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
debug(2, "fetchPsxParallax() -> %s parallax, xRes: %u, yRes: %u", (level == 0) ? "Background" : "Foreground", plxXres, plxYres);
|
|
|
|
|
|
|
|
// Calculate the number of tiles which compose the parallax grid.
|
2010-10-15 06:12:23 +00:00
|
|
|
horTiles = (plxXres % 64) ? (plxXres / 64) + 1 : plxXres / 64;
|
|
|
|
verTiles = (plxYres % 16) ? (plxYres / 16) + 1 : plxYres / 16;
|
2009-04-07 19:52:46 +00:00
|
|
|
|
|
|
|
totSize = plxSize + horTiles * verTiles * 4 + 8;
|
|
|
|
|
|
|
|
file.seek(screenOffset + plxOffset, SEEK_SET);
|
|
|
|
buffer = (byte *)malloc(totSize);
|
|
|
|
|
|
|
|
// Insert parallax resolution information in the buffer,
|
|
|
|
// preceding parallax data.
|
2009-05-24 15:17:42 +00:00
|
|
|
WRITE_LE_UINT16(buffer, plxXres);
|
2009-04-07 19:52:46 +00:00
|
|
|
WRITE_LE_UINT16(buffer + 2, plxYres);
|
2009-05-24 15:17:42 +00:00
|
|
|
WRITE_LE_UINT16(buffer + 4, horTiles);
|
2009-04-07 19:52:46 +00:00
|
|
|
WRITE_LE_UINT16(buffer + 6, verTiles);
|
|
|
|
|
|
|
|
// Read parallax data from file and store it inside the buffer,
|
|
|
|
// skipping the generated header.
|
2009-05-24 15:17:42 +00:00
|
|
|
file.read(buffer + 8, totSize - 8);
|
2009-04-07 19:52:46 +00:00
|
|
|
file.close();
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
// Used for testing text & speech (see fnISpeak in speech.cpp)
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
bool Sword2Engine::checkTextLine(byte *file, uint32 text_line) {
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
TextHeader text_header;
|
2003-09-19 13:55:19 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
text_header.read(file + ResHeader::size());
|
2003-09-19 13:55:19 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
return text_line < text_header.noOfLines;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
} // End of namespace Sword2
|