2008-07-23 09:02:47 +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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Low level graphics interface.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tinsel/graphics.h"
|
|
|
|
#include "tinsel/handle.h" // LockMem()
|
|
|
|
#include "tinsel/object.h"
|
|
|
|
#include "tinsel/palette.h"
|
2008-12-01 20:35:36 +00:00
|
|
|
#include "tinsel/scene.h"
|
2008-07-23 09:02:47 +00:00
|
|
|
#include "tinsel/tinsel.h"
|
2009-05-15 12:46:53 +00:00
|
|
|
#include "tinsel/scn.h"
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/textconsole.h"
|
|
|
|
|
2008-07-23 09:02:47 +00:00
|
|
|
namespace Tinsel {
|
|
|
|
|
|
|
|
//----------------- LOCAL DEFINES --------------------
|
|
|
|
|
|
|
|
// Defines used in graphic drawing
|
|
|
|
#define CHARPTR_OFFSET 16
|
|
|
|
#define CHAR_WIDTH 4
|
|
|
|
#define CHAR_HEIGHT 4
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
extern uint8 g_transPalette[MAX_COLORS];
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
//----------------- SUPPORT FUNCTIONS ---------------------
|
|
|
|
|
2009-04-23 15:29:34 +00:00
|
|
|
/**
|
|
|
|
* PSX Block list unwinder.
|
2009-05-15 12:46:53 +00:00
|
|
|
* Chunk type 0x0003 (CHUNK_CHARPTR) in PSX version of DW 1 & 2 is compressed (original code
|
|
|
|
* calls the compression PJCRLE), thus we need to decompress it before passing data to drawing functions
|
2009-04-23 15:29:34 +00:00
|
|
|
*/
|
2009-05-15 12:46:53 +00:00
|
|
|
uint8* psxPJCRLEUnwinder(uint16 imageWidth, uint16 imageHeight, uint8 *srcIdx) {
|
2009-04-23 15:29:34 +00:00
|
|
|
uint32 remainingBlocks = 0;
|
|
|
|
|
2009-05-24 15:17:42 +00:00
|
|
|
uint16 compressionType = 0; // Kind of decompression to apply
|
2009-04-23 15:29:34 +00:00
|
|
|
uint16 controlBits = 0; // Control bits used to calculate the number of decompressed indexes
|
|
|
|
uint16 baseIndex = 0; // Base index to be repeated / incremented.
|
|
|
|
|
|
|
|
uint16 controlData;
|
|
|
|
|
|
|
|
uint8* dstIdx = NULL;
|
2009-04-23 16:17:22 +00:00
|
|
|
uint8* destinationBuffer = NULL;
|
2009-04-23 15:29:34 +00:00
|
|
|
|
|
|
|
if (!imageWidth || !imageHeight)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// Calculate needed index numbers, align width and height not next multiple of four
|
2010-10-15 08:52:22 +00:00
|
|
|
imageWidth = (imageWidth % 4) ? ((imageWidth / 4) + 1) * 4 : imageWidth;
|
|
|
|
imageHeight = (imageHeight % 4) ? ((imageHeight / 4) + 1) * 4 : imageHeight;
|
2012-02-15 15:53:31 +00:00
|
|
|
destinationBuffer = (uint8 *)malloc((imageWidth * imageHeight) / 8);
|
2009-04-23 16:17:22 +00:00
|
|
|
dstIdx = destinationBuffer;
|
2009-04-23 15:29:34 +00:00
|
|
|
remainingBlocks = (imageWidth * imageHeight) / 16;
|
|
|
|
|
|
|
|
while (remainingBlocks) { // Repeat until all blocks are decompressed
|
|
|
|
if (!controlBits) {
|
2012-12-11 00:56:48 +00:00
|
|
|
controlData = READ_16(srcIdx);
|
2009-04-23 15:29:34 +00:00
|
|
|
srcIdx += 2;
|
|
|
|
|
|
|
|
// If bit 15 of controlData is enabled, compression data is type 1.
|
|
|
|
// else if controlData has bit 16 enabled, compression type is 2,
|
|
|
|
// else there is no compression.
|
|
|
|
if (controlData & 0x4000)
|
|
|
|
compressionType = 2;
|
2009-05-24 15:17:42 +00:00
|
|
|
else if (controlData & 0x8000)
|
2009-04-23 15:29:34 +00:00
|
|
|
compressionType = 1;
|
|
|
|
else
|
|
|
|
compressionType = 0;
|
|
|
|
|
|
|
|
// Fetch control bits from controlData
|
|
|
|
controlBits = controlData & 0x3FFF;
|
|
|
|
|
|
|
|
// If there is compression, we need to fetch an index
|
|
|
|
// to be treated as "base" for compression.
|
|
|
|
if (compressionType != 0) {
|
2012-12-11 00:56:48 +00:00
|
|
|
controlData = READ_16(srcIdx);
|
2009-04-23 15:29:34 +00:00
|
|
|
srcIdx += 2;
|
|
|
|
baseIndex = controlData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 decremTiles; // Number of blocks that will be decompressed
|
|
|
|
if (remainingBlocks < controlBits) {
|
|
|
|
controlBits = controlBits - remainingBlocks;
|
|
|
|
decremTiles = remainingBlocks;
|
|
|
|
} else {
|
|
|
|
decremTiles = controlBits;
|
|
|
|
controlBits = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decrement remaining blocks
|
|
|
|
remainingBlocks -= decremTiles;
|
|
|
|
|
|
|
|
// Manage different compressions
|
|
|
|
switch (compressionType) {
|
|
|
|
case 0: // No compression, plain copy of indexes
|
|
|
|
while (decremTiles) {
|
2012-12-11 00:56:48 +00:00
|
|
|
WRITE_LE_UINT16(dstIdx, READ_16(srcIdx));
|
2009-04-23 15:29:34 +00:00
|
|
|
srcIdx += 2;
|
|
|
|
dstIdx += 2;
|
|
|
|
decremTiles--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: // Compression type 1, repeat a base index
|
|
|
|
while (decremTiles) {
|
|
|
|
WRITE_LE_UINT16(dstIdx, baseIndex);
|
|
|
|
dstIdx += 2;
|
|
|
|
decremTiles--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2: // Compression type 2, increment a base index
|
|
|
|
while (decremTiles) {
|
|
|
|
WRITE_LE_UINT16(dstIdx, baseIndex);
|
|
|
|
baseIndex++;
|
|
|
|
dstIdx += 2;
|
|
|
|
decremTiles--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// End.
|
2009-04-23 16:17:22 +00:00
|
|
|
return destinationBuffer;
|
2009-04-23 15:29:34 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 11:36:15 +00:00
|
|
|
/**
|
|
|
|
* Straight rendering of uncompressed data
|
|
|
|
*/
|
|
|
|
static void t0WrtNonZero(DRAWOBJECT *pObj, uint8 *srcP, uint8 *destP, bool applyClipping) {
|
|
|
|
int yClip = 0;
|
|
|
|
|
|
|
|
if (applyClipping) {
|
|
|
|
// Adjust the height down to skip any bottom clipping
|
|
|
|
pObj->height -= pObj->botClip;
|
|
|
|
yClip = pObj->topClip;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vertical loop
|
|
|
|
for (int y = 0; y < pObj->height; ++y) {
|
|
|
|
// Get the start of the next line output
|
|
|
|
uint8 *tempDest = destP;
|
|
|
|
|
|
|
|
int leftClip = applyClipping ? pObj->leftClip : 0;
|
|
|
|
int rightClip = applyClipping ? pObj->rightClip : 0;
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-12-06 11:36:15 +00:00
|
|
|
// Horizontal loop
|
|
|
|
for (int x = 0; x < pObj->width; ) {
|
|
|
|
uint32 numBytes = READ_UINT32(srcP);
|
|
|
|
srcP += sizeof(uint32);
|
|
|
|
bool repeatFlag = (numBytes & 0x80000000L) != 0;
|
|
|
|
numBytes &= 0x7fffffff;
|
|
|
|
|
|
|
|
uint clipAmount = MIN((int)numBytes & 0xff, leftClip);
|
|
|
|
leftClip -= clipAmount;
|
|
|
|
x += clipAmount;
|
|
|
|
|
|
|
|
if (repeatFlag) {
|
2011-04-14 12:12:27 +00:00
|
|
|
// Repeat of a given color
|
|
|
|
uint8 color = (numBytes >> 8) & 0xff;
|
2008-12-06 11:36:15 +00:00
|
|
|
int runLength = (numBytes & 0xff) - clipAmount;
|
|
|
|
|
|
|
|
int rptLength = MAX(MIN(runLength, pObj->width - rightClip - x), 0);
|
|
|
|
if (yClip == 0) {
|
2011-04-14 12:12:27 +00:00
|
|
|
if (color != 0)
|
|
|
|
memset(tempDest, color, rptLength);
|
2008-12-06 11:36:15 +00:00
|
|
|
tempDest += rptLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
x += runLength;
|
|
|
|
} else {
|
|
|
|
// Copy a specified sequence length of pixels
|
|
|
|
srcP += clipAmount;
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-12-06 11:36:15 +00:00
|
|
|
int runLength = numBytes - clipAmount;
|
|
|
|
int rptLength = MAX(MIN(runLength, pObj->width - rightClip - x), 0);
|
|
|
|
if (yClip == 0) {
|
|
|
|
memmove(tempDest, srcP, rptLength);
|
|
|
|
tempDest += rptLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
int overflow = (numBytes % 4) == 0 ? 0 : 4 - (numBytes % 4);
|
|
|
|
x += runLength;
|
|
|
|
srcP += runLength + overflow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move to next line
|
|
|
|
if (yClip > 0)
|
|
|
|
--yClip;
|
|
|
|
else
|
|
|
|
destP += SCREEN_WIDTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-23 16:17:22 +00:00
|
|
|
/**
|
|
|
|
* Straight rendering with transparency support, PSX variant supporting also 4-BIT clut data
|
|
|
|
*/
|
2009-05-24 22:10:12 +00:00
|
|
|
static void PsxDrawTiles(DRAWOBJECT *pObj, uint8 *srcP, uint8 *destP, bool applyClipping, bool fourBitClut, uint32 psxSkipBytes, byte *psxMapperTable, bool transparency) {
|
2009-04-23 16:17:22 +00:00
|
|
|
// Set up the offset between destination blocks
|
|
|
|
int rightClip = applyClipping ? pObj->rightClip : 0;
|
|
|
|
Common::Rect boxBounds;
|
|
|
|
|
|
|
|
if (applyClipping) {
|
|
|
|
// Adjust the height down to skip any bottom clipping
|
|
|
|
pObj->height -= pObj->botClip;
|
|
|
|
|
|
|
|
// Make adjustment for the top clipping row
|
|
|
|
srcP += sizeof(uint16) * ((pObj->width + 3) >> 2) * (pObj->topClip >> 2);
|
|
|
|
pObj->height -= pObj->topClip;
|
|
|
|
pObj->topClip %= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vertical loop
|
|
|
|
while (pObj->height > 0) {
|
|
|
|
// Get the start of the next line output
|
|
|
|
uint8 *tempDest = destP;
|
|
|
|
|
|
|
|
// Get the line width, and figure out which row range within the 4 row high blocks
|
|
|
|
// will be displayed if clipping is to be taken into account
|
|
|
|
int width = pObj->width;
|
|
|
|
|
|
|
|
if (!applyClipping) {
|
|
|
|
// No clipping, so so set box bounding area for drawing full 4x4 pixel blocks
|
|
|
|
boxBounds.top = 0;
|
|
|
|
boxBounds.bottom = 3;
|
|
|
|
boxBounds.left = 0;
|
|
|
|
} else {
|
|
|
|
// Handle any possible clipping at the top of the char block.
|
|
|
|
// We already handled topClip partially at the beginning of this function.
|
|
|
|
// Hence the only non-zero values it can assume at this point are 1,2,3,
|
|
|
|
// and that only during the very first iteration (i.e. when the top char
|
|
|
|
// block is drawn only partially). In particular, we set topClip to zero,
|
|
|
|
// as all following blocks are not to be top clipped.
|
|
|
|
boxBounds.top = pObj->topClip;
|
|
|
|
pObj->topClip = 0;
|
|
|
|
|
|
|
|
boxBounds.bottom = MIN(boxBounds.top + pObj->height - 1, 3);
|
|
|
|
|
|
|
|
// Handle any possible clipping at the start of the line
|
|
|
|
boxBounds.left = pObj->leftClip;
|
|
|
|
if (boxBounds.left >= 4) {
|
|
|
|
srcP += sizeof(uint16) * (boxBounds.left >> 2);
|
|
|
|
width -= boxBounds.left & 0xfffc;
|
|
|
|
boxBounds.left %= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
width -= boxBounds.left;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Horizontal loop
|
|
|
|
while (width > rightClip) {
|
|
|
|
boxBounds.right = MIN(boxBounds.left + width - rightClip - 1, 3);
|
|
|
|
assert(boxBounds.bottom >= boxBounds.top);
|
|
|
|
assert(boxBounds.right >= boxBounds.left);
|
|
|
|
|
2012-12-11 00:56:48 +00:00
|
|
|
int16 indexVal = READ_16(srcP);
|
2009-04-23 16:17:22 +00:00
|
|
|
srcP += sizeof(uint16);
|
|
|
|
|
2009-05-18 19:56:54 +00:00
|
|
|
// Draw a 4x4 block based on the opcode as in index into the block list
|
2009-05-24 14:37:53 +00:00
|
|
|
// In case we have a 4-bit CLUT image, blocks are 2x4 bytes, then expanded into 4x4
|
2009-05-18 19:56:54 +00:00
|
|
|
const uint8 *p;
|
|
|
|
if (fourBitClut)
|
|
|
|
p = (uint8 *)pObj->charBase + psxSkipBytes + (indexVal << 3);
|
|
|
|
else
|
|
|
|
p = (uint8 *)pObj->charBase + psxSkipBytes + (indexVal << 4);
|
2009-04-23 16:17:22 +00:00
|
|
|
|
2009-05-18 19:56:54 +00:00
|
|
|
p += boxBounds.top * (fourBitClut ? sizeof(uint16) : sizeof(uint32));
|
|
|
|
for (int yp = boxBounds.top; yp <= boxBounds.bottom; ++yp, p += (fourBitClut ? sizeof(uint16) : sizeof(uint32))) {
|
2009-09-30 16:16:53 +00:00
|
|
|
if (!fourBitClut) {
|
2009-05-18 19:56:54 +00:00
|
|
|
if (!transparency)
|
2009-04-23 16:17:22 +00:00
|
|
|
Common::copy(p + boxBounds.left, p + boxBounds.right + 1, tempDest + (SCREEN_WIDTH * (yp - boxBounds.top)));
|
2009-05-18 19:56:54 +00:00
|
|
|
else
|
|
|
|
for (int xp = boxBounds.left; xp <= boxBounds.right; ++xp) {
|
2009-05-24 14:37:53 +00:00
|
|
|
if (*(p + xp))
|
|
|
|
*(tempDest + SCREEN_WIDTH * (yp - boxBounds.top) + (xp - boxBounds.left)) = *(p + xp);
|
2009-05-18 19:56:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-05-24 13:59:47 +00:00
|
|
|
for (int xp = boxBounds.left; xp <= boxBounds.right; ++xp) {
|
|
|
|
// Extract pixel value from byte
|
2010-10-15 08:52:22 +00:00
|
|
|
byte pixValue = (*(p + (xp / 2)) & ((xp % 2) ? 0xf0 : 0x0f)) >> ((xp % 2) ? 4 : 0);
|
2009-05-24 13:59:47 +00:00
|
|
|
if (pixValue || !transparency)
|
2009-05-24 22:10:12 +00:00
|
|
|
*(tempDest + SCREEN_WIDTH * (yp - boxBounds.top) + (xp - boxBounds.left)) = psxMapperTable[pixValue];
|
2009-05-24 13:59:47 +00:00
|
|
|
}
|
2009-04-23 16:17:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tempDest += boxBounds.right - boxBounds.left + 1;
|
|
|
|
width -= 3 - boxBounds.left + 1;
|
|
|
|
|
|
|
|
// None of the remaining horizontal blocks should be left clipped
|
|
|
|
boxBounds.left = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is any width remaining, there must be a right edge clipping
|
|
|
|
if (width >= 0)
|
|
|
|
srcP += sizeof(uint16) * ((width + 3) >> 2);
|
|
|
|
|
|
|
|
// Move to next line line
|
|
|
|
pObj->height -= boxBounds.bottom - boxBounds.top + 1;
|
|
|
|
destP += (boxBounds.bottom - boxBounds.top + 1) * SCREEN_WIDTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-23 09:02:47 +00:00
|
|
|
/**
|
|
|
|
* Straight rendering with transparency support
|
|
|
|
*/
|
|
|
|
static void WrtNonZero(DRAWOBJECT *pObj, uint8 *srcP, uint8 *destP, bool applyClipping) {
|
|
|
|
// Set up the offset between destination blocks
|
|
|
|
int rightClip = applyClipping ? pObj->rightClip : 0;
|
|
|
|
Common::Rect boxBounds;
|
|
|
|
|
|
|
|
if (applyClipping) {
|
|
|
|
// Adjust the height down to skip any bottom clipping
|
|
|
|
pObj->height -= pObj->botClip;
|
|
|
|
|
|
|
|
// Make adjustment for the top clipping row
|
|
|
|
srcP += sizeof(uint16) * ((pObj->width + 3) >> 2) * (pObj->topClip >> 2);
|
|
|
|
pObj->height -= pObj->topClip;
|
|
|
|
pObj->topClip %= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vertical loop
|
|
|
|
while (pObj->height > 0) {
|
|
|
|
// Get the start of the next line output
|
|
|
|
uint8 *tempDest = destP;
|
|
|
|
|
|
|
|
// Get the line width, and figure out which row range within the 4 row high blocks
|
|
|
|
// will be displayed if clipping is to be taken into account
|
|
|
|
int width = pObj->width;
|
|
|
|
|
|
|
|
if (!applyClipping) {
|
|
|
|
// No clipping, so so set box bounding area for drawing full 4x4 pixel blocks
|
|
|
|
boxBounds.top = 0;
|
|
|
|
boxBounds.bottom = 3;
|
|
|
|
boxBounds.left = 0;
|
|
|
|
} else {
|
|
|
|
// Handle any possible clipping at the top of the char block.
|
|
|
|
// We already handled topClip partially at the beginning of this function.
|
|
|
|
// Hence the only non-zero values it can assume at this point are 1,2,3,
|
|
|
|
// and that only during the very first iteration (i.e. when the top char
|
|
|
|
// block is drawn only partially). In particular, we set topClip to zero,
|
|
|
|
// as all following blocks are not to be top clipped.
|
|
|
|
boxBounds.top = pObj->topClip;
|
|
|
|
pObj->topClip = 0;
|
|
|
|
|
|
|
|
boxBounds.bottom = MIN(boxBounds.top + pObj->height - 1, 3);
|
|
|
|
|
|
|
|
// Handle any possible clipping at the start of the line
|
|
|
|
boxBounds.left = pObj->leftClip;
|
|
|
|
if (boxBounds.left >= 4) {
|
|
|
|
srcP += sizeof(uint16) * (boxBounds.left >> 2);
|
|
|
|
width -= boxBounds.left & 0xfffc;
|
|
|
|
boxBounds.left %= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
width -= boxBounds.left;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Horizontal loop
|
|
|
|
while (width > rightClip) {
|
|
|
|
boxBounds.right = MIN(boxBounds.left + width - rightClip - 1, 3);
|
|
|
|
assert(boxBounds.bottom >= boxBounds.top);
|
|
|
|
assert(boxBounds.right >= boxBounds.left);
|
|
|
|
|
2012-12-11 00:56:48 +00:00
|
|
|
int16 indexVal = READ_16(srcP);
|
2008-07-23 09:02:47 +00:00
|
|
|
srcP += sizeof(uint16);
|
|
|
|
|
|
|
|
if (indexVal >= 0) {
|
|
|
|
// Draw a 4x4 block based on the opcode as in index into the block list
|
|
|
|
const uint8 *p = (uint8 *)pObj->charBase + (indexVal << 4);
|
|
|
|
p += boxBounds.top * sizeof(uint32);
|
|
|
|
for (int yp = boxBounds.top; yp <= boxBounds.bottom; ++yp, p += sizeof(uint32)) {
|
|
|
|
Common::copy(p + boxBounds.left, p + boxBounds.right + 1, tempDest + (SCREEN_WIDTH * (yp - boxBounds.top)));
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Draw a 4x4 block with transparency support
|
|
|
|
indexVal &= 0x7fff;
|
|
|
|
|
|
|
|
// If index is zero, then skip drawing the block completely
|
|
|
|
if (indexVal > 0) {
|
|
|
|
// Use the index along with the object's translation offset
|
|
|
|
const uint8 *p = (uint8 *)pObj->charBase + ((pObj->transOffset + indexVal) << 4);
|
|
|
|
|
|
|
|
// Loop through each pixel - only draw a pixel if it's non-zero
|
|
|
|
p += boxBounds.top * sizeof(uint32);
|
|
|
|
for (int yp = boxBounds.top; yp <= boxBounds.bottom; ++yp) {
|
|
|
|
p += boxBounds.left;
|
|
|
|
for (int xp = boxBounds.left; xp <= boxBounds.right; ++xp, ++p) {
|
|
|
|
if (*p)
|
|
|
|
*(tempDest + SCREEN_WIDTH * (yp - boxBounds.top) + (xp - boxBounds.left)) = *p;
|
|
|
|
}
|
|
|
|
p += 3 - boxBounds.right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tempDest += boxBounds.right - boxBounds.left + 1;
|
|
|
|
width -= 3 - boxBounds.left + 1;
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-07-23 09:02:47 +00:00
|
|
|
// None of the remaining horizontal blocks should be left clipped
|
|
|
|
boxBounds.left = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is any width remaining, there must be a right edge clipping
|
|
|
|
if (width >= 0)
|
|
|
|
srcP += sizeof(uint16) * ((width + 3) >> 2);
|
|
|
|
|
|
|
|
// Move to next line line
|
|
|
|
pObj->height -= boxBounds.bottom - boxBounds.top + 1;
|
|
|
|
destP += (boxBounds.bottom - boxBounds.top + 1) * SCREEN_WIDTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-01 20:35:36 +00:00
|
|
|
* Tinsel 2 Straight rendering with transparency support
|
2008-07-23 09:02:47 +00:00
|
|
|
*/
|
2008-12-01 20:35:36 +00:00
|
|
|
static void t2WrtNonZero(DRAWOBJECT *pObj, uint8 *srcP, uint8 *destP, bool applyClipping, bool horizFlipped) {
|
|
|
|
// Setup for correct clipping of object edges
|
|
|
|
int yClip = applyClipping ? pObj->topClip : 0;
|
|
|
|
if (applyClipping)
|
|
|
|
pObj->height -= pObj->botClip;
|
|
|
|
int numBytes;
|
|
|
|
int clipAmount;
|
|
|
|
|
2010-06-27 11:16:49 +00:00
|
|
|
// WORKAROUND: One of the mortician frames has several corrupt bytes in the Russian version
|
2010-06-27 17:06:26 +00:00
|
|
|
if ((pObj->hBits == 2517583660UL) && (_vm->getLanguage() == Common::RU_RUS)) {
|
2010-06-27 11:16:49 +00:00
|
|
|
uint8 correctBytes[5] = {0xA3, 0x00, 0x89, 0xC0, 0xA6};
|
|
|
|
Common::copy(&correctBytes[0], &correctBytes[5], srcP);
|
|
|
|
}
|
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
for (int y = 0; y < pObj->height; ++y) {
|
|
|
|
// Get the position to start writing out from
|
|
|
|
uint8 *tempP = !horizFlipped ? destP :
|
|
|
|
destP + (pObj->width - pObj->leftClip - pObj->rightClip) - 1;
|
|
|
|
int leftClip = applyClipping ? pObj->leftClip : 0;
|
|
|
|
int rightClip = applyClipping ? pObj->rightClip : 0;
|
|
|
|
if (horizFlipped)
|
|
|
|
SWAP(leftClip, rightClip);
|
|
|
|
|
|
|
|
int x = 0;
|
|
|
|
while (x < pObj->width) {
|
|
|
|
// Get the next opcode
|
|
|
|
numBytes = *srcP++;
|
|
|
|
if (numBytes & 0x80) {
|
|
|
|
// Run length following
|
|
|
|
numBytes &= 0x7f;
|
|
|
|
clipAmount = MIN(numBytes, leftClip);
|
|
|
|
leftClip -= clipAmount;
|
|
|
|
x+= clipAmount;
|
|
|
|
|
|
|
|
int runLength = numBytes - clipAmount;
|
2011-04-14 12:12:27 +00:00
|
|
|
uint8 color = *srcP++;
|
2008-12-01 20:35:36 +00:00
|
|
|
|
2011-04-14 12:12:27 +00:00
|
|
|
if ((yClip == 0) && (runLength > 0) && (color != 0)) {
|
2008-12-01 20:35:36 +00:00
|
|
|
runLength = MIN(runLength, pObj->width - rightClip - x);
|
|
|
|
|
|
|
|
if (runLength > 0) {
|
|
|
|
// Non-transparent run length
|
2011-04-14 12:12:27 +00:00
|
|
|
color += pObj->constant;
|
2008-12-01 20:35:36 +00:00
|
|
|
if (horizFlipped)
|
2011-11-16 17:06:30 +00:00
|
|
|
Common::fill(tempP - runLength + 1, tempP + 1, color);
|
2008-12-01 20:35:36 +00:00
|
|
|
else
|
2011-11-16 17:06:30 +00:00
|
|
|
Common::fill(tempP, tempP + runLength, color);
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (horizFlipped)
|
|
|
|
tempP -= runLength;
|
|
|
|
else
|
|
|
|
tempP += runLength;
|
|
|
|
|
|
|
|
x += numBytes - clipAmount;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Dump a length of pixels
|
|
|
|
clipAmount = MIN(numBytes, leftClip);
|
|
|
|
leftClip -= clipAmount;
|
|
|
|
srcP += clipAmount;
|
|
|
|
int runLength = numBytes - clipAmount;
|
|
|
|
x += numBytes - runLength;
|
|
|
|
|
|
|
|
for (int xp = 0; xp < runLength; ++xp) {
|
|
|
|
if ((yClip > 0) || (x >= (pObj->width - rightClip)))
|
|
|
|
++srcP;
|
|
|
|
else if (horizFlipped)
|
|
|
|
*tempP-- = pObj->constant + *srcP++;
|
|
|
|
else
|
|
|
|
*tempP++ = pObj->constant + *srcP++;
|
|
|
|
++x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(x == pObj->width);
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
if (yClip > 0)
|
|
|
|
--yClip;
|
|
|
|
else
|
|
|
|
destP += SCREEN_WIDTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-14 12:12:27 +00:00
|
|
|
* Fill the destination area with a constant color
|
2008-12-01 20:35:36 +00:00
|
|
|
*/
|
2008-07-23 09:02:47 +00:00
|
|
|
static void WrtConst(DRAWOBJECT *pObj, uint8 *destP, bool applyClipping) {
|
|
|
|
if (applyClipping) {
|
|
|
|
pObj->height -= pObj->topClip + pObj->botClip;
|
|
|
|
pObj->width -= pObj->leftClip + pObj->rightClip;
|
|
|
|
|
|
|
|
if (pObj->width <= 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop through any remaining lines
|
|
|
|
while (pObj->height > 0) {
|
2011-11-16 17:06:30 +00:00
|
|
|
Common::fill(destP, destP + pObj->width, pObj->constant);
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
--pObj->height;
|
|
|
|
destP += SCREEN_WIDTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Translates the destination surface within the object's bounds using the transparency
|
|
|
|
* lookup table from transpal.cpp (the contents of which have been moved into palette.cpp)
|
|
|
|
*/
|
|
|
|
static void WrtTrans(DRAWOBJECT *pObj, uint8 *destP, bool applyClipping) {
|
|
|
|
if (applyClipping) {
|
|
|
|
pObj->height -= pObj->topClip + pObj->botClip;
|
|
|
|
pObj->width -= pObj->leftClip + pObj->rightClip;
|
|
|
|
|
|
|
|
if (pObj->width <= 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-01 15:06:43 +00:00
|
|
|
// Set up the offset between destination lines
|
2008-07-23 09:02:47 +00:00
|
|
|
int lineOffset = SCREEN_WIDTH - pObj->width;
|
|
|
|
|
|
|
|
// Loop through any remaining lines
|
|
|
|
while (pObj->height > 0) {
|
|
|
|
for (int i = 0; i < pObj->width; ++i, ++destP)
|
2012-02-22 22:14:29 +00:00
|
|
|
*destP = g_transPalette[*destP];
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
--pObj->height;
|
|
|
|
destP += lineOffset;
|
2009-01-01 15:06:43 +00:00
|
|
|
}
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-01 20:35:36 +00:00
|
|
|
* Copies an uncompressed block of data straight to the screen
|
2008-07-23 09:02:47 +00:00
|
|
|
*/
|
2008-12-01 20:35:36 +00:00
|
|
|
static void WrtAll(DRAWOBJECT *pObj, uint8 *srcP, uint8 *destP, bool applyClipping) {
|
|
|
|
int objWidth = pObj->width;
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
if (applyClipping) {
|
|
|
|
srcP += (pObj->topClip * pObj->width) + pObj->leftClip;
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
pObj->height -= pObj->topClip + pObj->botClip;
|
|
|
|
pObj->width -= pObj->leftClip + pObj->rightClip;
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
if (pObj->width <= 0)
|
|
|
|
return;
|
|
|
|
}
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
for (int y = 0; y < pObj->height; ++y) {
|
|
|
|
Common::copy(srcP, srcP + pObj->width, destP);
|
|
|
|
srcP += objWidth;
|
|
|
|
destP += SCREEN_WIDTH;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
/**
|
|
|
|
* Renders a packed data stream with a variable sized palette
|
|
|
|
*/
|
|
|
|
static void PackedWrtNonZero(DRAWOBJECT *pObj, uint8 *srcP, uint8 *destP,
|
|
|
|
bool applyClipping, bool horizFlipped, int packingType) {
|
2011-04-14 12:12:27 +00:00
|
|
|
uint8 numColors = 0;
|
|
|
|
uint8 *colorTable = NULL;
|
2008-12-01 20:35:36 +00:00
|
|
|
int topClip = 0;
|
|
|
|
int xOffset = 0;
|
2011-04-14 12:12:27 +00:00
|
|
|
int numBytes, color;
|
2008-12-01 20:35:36 +00:00
|
|
|
int v;
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2010-06-27 11:16:49 +00:00
|
|
|
if (_vm->getLanguage() == Common::RU_RUS) {
|
|
|
|
// WORKAROUND: One of the mortician frames has several corrupt bytes in the Russian version
|
2010-06-27 17:06:26 +00:00
|
|
|
if (pObj->hBits == 2517583393UL) {
|
2010-06-27 11:16:49 +00:00
|
|
|
uint8 correctBytes[5] = {0x00, 0x00, 0x17, 0x01, 0x00};
|
|
|
|
Common::copy(&correctBytes[0], &correctBytes[5], srcP + 267);
|
|
|
|
}
|
|
|
|
// WORKAROUND: One of Dibbler's frames in the end sequence has corrupt bytes in the Russian version
|
|
|
|
if (pObj->hBits == 33651742) {
|
|
|
|
uint8 correctBytes[40] = {
|
|
|
|
0x06, 0xc0, 0xd6, 0xc1, 0x09, 0xce, 0x0d, 0x24, 0x02, 0x12, 0x01, 0x00, 0x00, 0x23, 0x21, 0x32,
|
|
|
|
0x12, 0x00, 0x00, 0x20, 0x01, 0x11, 0x32, 0x12, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x11, 0x34, 0x11,
|
|
|
|
0x00, 0x00, 0x18, 0x01, 0x11, 0x35, 0x21, 0x01
|
|
|
|
};
|
|
|
|
Common::copy(&correctBytes[0], &correctBytes[40], srcP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
if (applyClipping) {
|
|
|
|
pObj->height -= pObj->botClip;
|
|
|
|
topClip = pObj->topClip;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (packingType == 3) {
|
2011-04-14 12:12:27 +00:00
|
|
|
// Variable colors
|
|
|
|
numColors = *srcP++;
|
|
|
|
colorTable = srcP;
|
|
|
|
srcP += numColors;
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int y = 0; y < pObj->height; ++y) {
|
|
|
|
// Get the position to start writing out from
|
|
|
|
uint8 *tempP = !horizFlipped ? destP :
|
|
|
|
destP + (pObj->width - pObj->leftClip - pObj->rightClip) - 1;
|
|
|
|
int leftClip = applyClipping ? pObj->leftClip : 0;
|
|
|
|
int rightClip = applyClipping ? pObj->rightClip : 0;
|
|
|
|
if (horizFlipped)
|
|
|
|
SWAP(leftClip, rightClip);
|
|
|
|
bool eolFlag = false;
|
|
|
|
|
|
|
|
// Get offset for first pixels in next line
|
|
|
|
xOffset = *srcP++;
|
|
|
|
|
|
|
|
int x = 0;
|
|
|
|
while (x < pObj->width) {
|
2011-04-14 12:12:27 +00:00
|
|
|
// Get next run size and color to use
|
2008-12-01 20:35:36 +00:00
|
|
|
for (;;) {
|
|
|
|
if (xOffset > 0) {
|
|
|
|
x += xOffset;
|
|
|
|
|
|
|
|
// Reduce offset amount by any remaining left clipping
|
|
|
|
v = MIN(xOffset, leftClip);
|
|
|
|
xOffset -= v;
|
|
|
|
leftClip -= v;
|
|
|
|
|
|
|
|
if (horizFlipped) tempP -= xOffset; else tempP += xOffset;
|
|
|
|
xOffset = 0;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
v = *srcP++;
|
|
|
|
numBytes = v & 0xf; // No. bytes 1-15
|
|
|
|
if (packingType == 3)
|
2011-04-14 12:12:27 +00:00
|
|
|
color = colorTable[v >> 4];
|
2008-12-01 20:35:36 +00:00
|
|
|
else
|
2011-04-14 12:12:27 +00:00
|
|
|
color = pObj->baseCol + (v >> 4);
|
2008-12-01 20:35:36 +00:00
|
|
|
|
|
|
|
if (numBytes != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
numBytes = *srcP++;
|
|
|
|
if (numBytes >= 16)
|
|
|
|
break;
|
|
|
|
|
|
|
|
xOffset = numBytes + v;
|
|
|
|
if (xOffset == 0) {
|
|
|
|
// End of line encountered
|
|
|
|
eolFlag = true;
|
|
|
|
break;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
if (eolFlag)
|
|
|
|
break;
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
// Apply clipping on byte sequence
|
|
|
|
v = MIN(numBytes, leftClip);
|
|
|
|
leftClip -= v;
|
|
|
|
numBytes -= v;
|
|
|
|
x += v;
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
while (numBytes-- > 0) {
|
|
|
|
if ((topClip == 0) && (x < (pObj->width - rightClip))) {
|
2011-04-14 12:12:27 +00:00
|
|
|
*tempP = color;
|
2008-12-01 20:35:36 +00:00
|
|
|
if (horizFlipped) --tempP; else ++tempP;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
2008-12-01 20:35:36 +00:00
|
|
|
++x;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-01 20:35:36 +00:00
|
|
|
assert(x <= pObj->width);
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
if (!eolFlag) {
|
|
|
|
// Assert that the next bytes signal a line end
|
2008-12-17 19:25:54 +00:00
|
|
|
uint8 d = *srcP++;
|
|
|
|
assert((d & 0xf) == 0);
|
|
|
|
d = *srcP++;
|
|
|
|
assert(d == 0);
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
if (topClip > 0)
|
|
|
|
--topClip;
|
|
|
|
else
|
|
|
|
destP += SCREEN_WIDTH;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------- MAIN FUNCTIONS ---------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears both the screen surface buffer and screen to the specified value
|
|
|
|
*/
|
2008-07-25 09:12:03 +00:00
|
|
|
void ClearScreen() {
|
|
|
|
void *pDest = _vm->screen().getBasePtr(0, 0);
|
|
|
|
memset(pDest, 0, SCREEN_WIDTH * SCREEN_HEIGHT);
|
2009-02-15 21:20:21 +00:00
|
|
|
g_system->fillScreen(0);
|
2009-01-01 15:06:43 +00:00
|
|
|
g_system->updateScreen();
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the screen surface within the following rectangle
|
|
|
|
*/
|
|
|
|
void UpdateScreenRect(const Common::Rect &pClip) {
|
2009-03-01 21:03:46 +00:00
|
|
|
int yOffset = TinselV2 ? (g_system->getHeight() - SCREEN_HEIGHT) / 2 : 0;
|
2008-12-01 20:35:36 +00:00
|
|
|
byte *pSrc = (byte *)_vm->screen().getBasePtr(pClip.left, pClip.top);
|
|
|
|
g_system->copyRectToScreen(pSrc, _vm->screen().pitch, pClip.left, pClip.top + yOffset,
|
|
|
|
pClip.width(), pClip.height());
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the specified object onto the screen surface buffer
|
|
|
|
*/
|
|
|
|
void DrawObject(DRAWOBJECT *pObj) {
|
|
|
|
uint8 *srcPtr = NULL;
|
|
|
|
uint8 *destPtr;
|
2009-05-24 22:10:12 +00:00
|
|
|
byte psxMapperTable[16];
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2009-06-03 14:03:05 +00:00
|
|
|
bool psxFourBitClut = false; // Used by Tinsel PSX, true if an image using a 4bit CLUT is rendered
|
2009-05-24 23:06:39 +00:00
|
|
|
bool psxRLEindex = false; // Used by Tinsel PSX, true if an image is using PJCRLE compressed indexes
|
2009-06-03 14:03:05 +00:00
|
|
|
uint32 psxSkipBytes = 0; // Used by Tinsel PSX, number of bytes to skip before counting indexes for image tiles
|
2009-04-23 16:17:22 +00:00
|
|
|
|
2009-01-01 15:06:43 +00:00
|
|
|
if ((pObj->width <= 0) || (pObj->height <= 0))
|
2008-07-23 09:02:47 +00:00
|
|
|
// Empty image, so return immediately
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If writing constant data, don't bother locking the data pointer and reading src details
|
|
|
|
if ((pObj->flags & DMA_CONST) == 0) {
|
2008-12-01 20:35:36 +00:00
|
|
|
if (TinselV2) {
|
|
|
|
srcPtr = (byte *)LockMem(pObj->hBits);
|
|
|
|
pObj->charBase = NULL;
|
|
|
|
pObj->transOffset = 0;
|
|
|
|
} else {
|
|
|
|
byte *p = (byte *)LockMem(pObj->hBits & HANDLEMASK);
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
srcPtr = p + (pObj->hBits & OFFSETMASK);
|
2012-12-11 00:56:48 +00:00
|
|
|
pObj->charBase = (char *)p + READ_32(p + 0x10);
|
|
|
|
pObj->transOffset = READ_32(p + 0x14);
|
2009-05-15 12:46:53 +00:00
|
|
|
|
2009-04-23 16:17:22 +00:00
|
|
|
// Decompress block indexes for Discworld PSX
|
|
|
|
if (TinselV1PSX) {
|
2009-05-15 12:46:53 +00:00
|
|
|
uint8 paletteType = *(srcPtr); // if 0x88 we are using an 8bit palette type, if 0x44 we are using a 4 bit PSX CLUT
|
|
|
|
uint8 indexType = *(srcPtr + 1); // if 0xCC indexes for this image are compressed with PCJRLE, if 0xDD indexes are not compressed
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-05-15 12:46:53 +00:00
|
|
|
switch (paletteType) {
|
|
|
|
case 0x88: // Normal 8-bit palette
|
2009-05-24 15:17:42 +00:00
|
|
|
psxFourBitClut = false;
|
2009-05-15 12:46:53 +00:00
|
|
|
psxSkipBytes = 0;
|
|
|
|
switch (indexType) {
|
|
|
|
case 0xDD: // Normal uncompressed indexes
|
|
|
|
psxRLEindex = false;
|
|
|
|
srcPtr += sizeof(uint16); // Get to the beginning of index data
|
|
|
|
break;
|
|
|
|
case 0xCC: // PJCRLE compressed indexes
|
|
|
|
psxRLEindex = true;
|
|
|
|
srcPtr = psxPJCRLEUnwinder(pObj->width, pObj->height, srcPtr + sizeof(uint16));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Unknown PSX index type 0x%.2X", indexType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x44: // PSX 4-bit CLUT
|
2009-05-25 06:09:48 +00:00
|
|
|
psxPaletteMapper(pObj->pPal, srcPtr + sizeof(uint16), psxMapperTable);
|
2009-05-24 22:10:12 +00:00
|
|
|
|
2009-05-15 12:46:53 +00:00
|
|
|
psxFourBitClut = true;
|
2012-12-11 00:56:48 +00:00
|
|
|
psxSkipBytes = READ_32(p + sizeof(uint32) * 5) << 4; // Fetch number of bytes we have to skip
|
2009-05-15 12:46:53 +00:00
|
|
|
switch (indexType) {
|
|
|
|
case 0xDD: // Normal uncompressed indexes
|
|
|
|
psxRLEindex = false;
|
|
|
|
srcPtr += sizeof(uint16) * 17; // Skip image type and clut, and get to beginning of index data
|
|
|
|
break;
|
|
|
|
case 0xCC: // PJCRLE compressed indexes
|
|
|
|
psxRLEindex = true;
|
|
|
|
srcPtr = psxPJCRLEUnwinder(pObj->width, pObj->height, srcPtr + sizeof(uint16) * 17);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Unknown PSX index type 0x%.2X", indexType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Unknown PSX palette type 0x%.2X", paletteType);
|
|
|
|
break;
|
|
|
|
}
|
2009-04-23 16:17:22 +00:00
|
|
|
}
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
2009-04-23 16:17:22 +00:00
|
|
|
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get destination starting point
|
2008-07-25 09:12:03 +00:00
|
|
|
destPtr = (byte *)_vm->screen().getBasePtr(pObj->xPos, pObj->yPos);
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-07-23 09:02:47 +00:00
|
|
|
// Handle various draw types
|
|
|
|
uint8 typeId = pObj->flags & 0xff;
|
2008-12-01 20:35:36 +00:00
|
|
|
|
|
|
|
if (TinselV2) {
|
|
|
|
// Tinsel v2 decoders
|
|
|
|
// Initial switch statement for the different bit packing types
|
|
|
|
int packType = pObj->flags >> 14;
|
|
|
|
|
|
|
|
if (packType == 0) {
|
2011-04-14 12:12:27 +00:00
|
|
|
// No color packing
|
2008-12-01 20:35:36 +00:00
|
|
|
switch (typeId) {
|
|
|
|
case 0x01:
|
|
|
|
case 0x11:
|
|
|
|
case 0x41:
|
|
|
|
case 0x51:
|
|
|
|
case 0x81:
|
|
|
|
case 0xC1:
|
|
|
|
t2WrtNonZero(pObj, srcPtr, destPtr, typeId >= 0x40, (typeId & 0x10) != 0);
|
|
|
|
break;
|
|
|
|
case 0x02:
|
|
|
|
case 0x42:
|
|
|
|
// This renderer called 'RlWrtAll', but is the same as t2WrtNonZero
|
|
|
|
t2WrtNonZero(pObj, srcPtr, destPtr, typeId >= 0x40, false);
|
|
|
|
break;
|
|
|
|
case 0x04:
|
|
|
|
case 0x44:
|
|
|
|
// WrtConst with/without clipping
|
|
|
|
WrtConst(pObj, destPtr, typeId == 0x44);
|
|
|
|
break;
|
|
|
|
case 0x08:
|
|
|
|
case 0x48:
|
|
|
|
WrtAll(pObj, srcPtr, destPtr, typeId >= 0x40);
|
|
|
|
break;
|
|
|
|
case 0x84:
|
|
|
|
case 0xC4:
|
|
|
|
// WrtTrans with/without clipping
|
|
|
|
WrtTrans(pObj, destPtr, typeId == 0xC4);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Unknown drawing type %d", typeId);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 1 = 16 from 240
|
|
|
|
// 2 = 16 from 224
|
2011-04-14 12:12:27 +00:00
|
|
|
// 3 = variable color
|
2008-12-01 20:35:36 +00:00
|
|
|
if (packType == 1) pObj->baseCol = 0xF0;
|
|
|
|
else if (packType == 2) pObj->baseCol = 0xE0;
|
|
|
|
|
|
|
|
PackedWrtNonZero(pObj, srcPtr, destPtr, (pObj->flags & DMA_CLIP) != 0,
|
|
|
|
(pObj->flags & DMA_FLIPH), packType);
|
|
|
|
}
|
|
|
|
|
2009-04-23 16:17:22 +00:00
|
|
|
} else if (TinselV1PSX) {
|
|
|
|
// Tinsel v1 decoders, PSX specific variants
|
|
|
|
switch (typeId) {
|
|
|
|
case 0x01:
|
|
|
|
case 0x41:
|
2009-05-24 22:10:12 +00:00
|
|
|
PsxDrawTiles(pObj, srcPtr, destPtr, typeId >= 0x40, psxFourBitClut, psxSkipBytes, psxMapperTable, true);
|
2009-04-23 16:17:22 +00:00
|
|
|
break;
|
2009-05-18 19:56:54 +00:00
|
|
|
case 0x08:
|
|
|
|
case 0x48:
|
2009-05-24 22:10:12 +00:00
|
|
|
PsxDrawTiles(pObj, srcPtr, destPtr, typeId >= 0x40, psxFourBitClut, psxSkipBytes, psxMapperTable, false);
|
2009-04-23 16:17:22 +00:00
|
|
|
break;
|
2009-05-18 20:05:30 +00:00
|
|
|
case 0x84:
|
|
|
|
case 0xC4:
|
|
|
|
// WrtTrans with/without clipping
|
|
|
|
WrtTrans(pObj, destPtr, typeId == 0xC4);
|
|
|
|
break;
|
2009-05-24 13:59:47 +00:00
|
|
|
case 0x04:
|
|
|
|
case 0x44:
|
|
|
|
// WrtConst with/without clipping
|
|
|
|
WrtConst(pObj, destPtr, typeId == 0x44);
|
|
|
|
break;
|
2009-04-23 16:17:22 +00:00
|
|
|
default:
|
|
|
|
error("Unknown drawing type %d", typeId);
|
|
|
|
}
|
2012-12-11 01:06:50 +00:00
|
|
|
} else if (TinselV1Mac) {
|
|
|
|
// Tinsel v1 Mac decoders
|
|
|
|
// TODO: Finish this
|
|
|
|
switch (typeId) {
|
|
|
|
case 0x01:
|
|
|
|
case 0x41:
|
|
|
|
// TODO
|
|
|
|
break;
|
|
|
|
case 0x08:
|
|
|
|
case 0x48:
|
|
|
|
WrtAll(pObj, srcPtr, destPtr, typeId >= 0x40);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Unknown drawing type %d", typeId);
|
|
|
|
}
|
2008-12-06 11:36:15 +00:00
|
|
|
} else if (TinselV1) {
|
2008-12-01 20:35:36 +00:00
|
|
|
// Tinsel v1 decoders
|
|
|
|
switch (typeId) {
|
|
|
|
case 0x01:
|
|
|
|
case 0x08:
|
|
|
|
case 0x41:
|
|
|
|
case 0x48:
|
|
|
|
WrtNonZero(pObj, srcPtr, destPtr, typeId >= 0x40);
|
|
|
|
break;
|
|
|
|
case 0x04:
|
|
|
|
case 0x44:
|
|
|
|
// WrtConst with/without clipping
|
2009-04-23 16:17:22 +00:00
|
|
|
WrtConst(pObj, destPtr, typeId == 0x44);
|
2008-12-01 20:35:36 +00:00
|
|
|
break;
|
|
|
|
case 0x84:
|
|
|
|
case 0xC4:
|
|
|
|
// WrtTrans with/without clipping
|
|
|
|
WrtTrans(pObj, destPtr, typeId == 0xC4);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Unknown drawing type %d", typeId);
|
2008-12-06 11:36:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Tinsel v0 decoders
|
|
|
|
switch (typeId) {
|
|
|
|
case 0x01:
|
|
|
|
case 0x41:
|
|
|
|
t0WrtNonZero(pObj, srcPtr, destPtr, typeId >= 0x40);
|
2008-12-01 20:35:36 +00:00
|
|
|
break;
|
2008-12-06 11:36:15 +00:00
|
|
|
case 0x08:
|
|
|
|
case 0x48:
|
|
|
|
WrtAll(pObj, srcPtr, destPtr, typeId >= 0x40);
|
|
|
|
break;
|
2008-12-07 07:44:52 +00:00
|
|
|
case 0x84:
|
|
|
|
case 0xC4:
|
|
|
|
WrtTrans(pObj, destPtr, (typeId & 0x40) != 0);
|
|
|
|
break;
|
2008-12-06 11:36:15 +00:00
|
|
|
default:
|
|
|
|
error("Unknown drawing type %d", typeId);
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
2009-04-23 16:17:22 +00:00
|
|
|
|
|
|
|
// If we were using Discworld PSX, free the memory allocated
|
|
|
|
// for decompressed block indexes.
|
2009-05-15 12:46:53 +00:00
|
|
|
if (TinselV1PSX && psxRLEindex)
|
2009-04-23 16:17:22 +00:00
|
|
|
free(srcPtr);
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Tinsel
|