2001-10-09 14:30:12 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2004-01-06 12:45:34 +00:00
|
|
|
* Copyright (C) 2001-2004 The ScummVM project
|
2001-10-09 14:30:12 +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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
2001-11-06 20:00:47 +00:00
|
|
|
* $Header$
|
2001-10-09 14:30:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2003-10-03 18:33:57 +00:00
|
|
|
#include "scumm/scumm.h"
|
|
|
|
#include "scumm/actor.h"
|
|
|
|
#include "scumm/charset.h"
|
|
|
|
#include "scumm/resource.h"
|
|
|
|
#include "scumm/usage_bits.h"
|
|
|
|
|
|
|
|
namespace Scumm {
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2004-01-03 22:45:23 +00:00
|
|
|
struct StripTable {
|
|
|
|
int offsets[160];
|
|
|
|
int run[160];
|
|
|
|
int color[160];
|
|
|
|
int zoffsets[120]; // FIXME: Why only 120 here?
|
|
|
|
int zrun[120]; // FIXME: Why only 120 here?
|
|
|
|
};
|
|
|
|
|
2002-09-09 11:15:12 +00:00
|
|
|
enum {
|
|
|
|
kScrolltime = 500, // ms scrolling is supposed to take
|
|
|
|
kPictureDelay = 20
|
|
|
|
};
|
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
#define NUM_SHAKE_POSITIONS 8
|
|
|
|
static const int8 shake_positions[NUM_SHAKE_POSITIONS] = {
|
|
|
|
0, 1 * 2, 2 * 2, 1 * 2, 0 * 2, 2 * 2, 3 * 2, 1 * 2
|
|
|
|
};
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/**
|
2003-01-05 21:18:53 +00:00
|
|
|
* The following structs define four basic fades/transitions used by
|
|
|
|
* transitionEffect(), each looking differently to the user.
|
|
|
|
* Note that the stripTables contain strip numbers, and they assume
|
|
|
|
* that the screen has 40 vertical strips (i.e. 320 pixel), and 25 horizontal
|
|
|
|
* strips (i.e. 200 pixel). There is a hack in transitionEffect that
|
|
|
|
* makes it work correctly in games which have a different screen height
|
|
|
|
* (for example, 240 pixel), but nothing is done regarding the width, so this
|
|
|
|
* code won't work correctly in COMI. Also, the number of iteration depends
|
|
|
|
* on min(vertStrips, horizStrips}. So the 13 is derived from 25/2, rounded up.
|
|
|
|
* And the 25 = min(25,40). Hence for Zak256 instead of 13 and 25, the values
|
|
|
|
* 15 and 30 should be used, and for COMI probably 30 and 60.
|
|
|
|
*/
|
|
|
|
struct TransitionEffect {
|
|
|
|
byte numOfIterations;
|
|
|
|
int8 deltaTable[16]; // four times l / t / r / b
|
|
|
|
byte stripTable[16]; // ditto
|
2002-12-15 23:40:37 +00:00
|
|
|
};
|
2003-05-30 20:13:29 +00:00
|
|
|
|
2003-04-30 13:23:31 +00:00
|
|
|
#ifdef __PALM_OS__
|
|
|
|
static const TransitionEffect *transitionEffects;
|
|
|
|
#else
|
2003-06-05 18:30:29 +00:00
|
|
|
static const TransitionEffect transitionEffects[5] = {
|
2003-01-05 21:18:53 +00:00
|
|
|
// Iris effect (looks like an opening/closing camera iris)
|
|
|
|
{
|
|
|
|
13, // Number of iterations
|
|
|
|
{
|
|
|
|
1, 1, -1, 1,
|
|
|
|
-1, 1, -1, -1,
|
|
|
|
1, -1, -1, -1,
|
|
|
|
1, 1, 1, -1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0, 0, 39, 0,
|
|
|
|
39, 0, 39, 24,
|
|
|
|
0, 24, 39, 24,
|
|
|
|
0, 0, 0, 24
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Box wipe (a box expands from the upper-left corner to the lower-right corner)
|
|
|
|
{
|
|
|
|
25, // Number of iterations
|
|
|
|
{
|
|
|
|
0, 1, 2, 1,
|
|
|
|
2, 0, 2, 1,
|
|
|
|
2, 0, 2, 1,
|
|
|
|
0, 0, 0, 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
1, 0, 1, 0,
|
|
|
|
255, 0, 0, 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Box wipe (a box expands from the lower-right corner to the upper-left corner)
|
|
|
|
{
|
|
|
|
25, // Number of iterations
|
|
|
|
{
|
|
|
|
-2, -1, 0, -1,
|
|
|
|
-2, -1, -2, 0,
|
|
|
|
-2, -1, -2, 0,
|
|
|
|
0, 0, 0, 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
39, 24, 39, 24,
|
|
|
|
39, 24, 39, 24,
|
|
|
|
38, 24, 38, 24,
|
|
|
|
255, 0, 0, 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Inverse box wipe
|
|
|
|
{
|
|
|
|
25, // Number of iterations
|
|
|
|
{
|
|
|
|
0, -1, -2, -1,
|
|
|
|
-2, 0, -2, -1,
|
|
|
|
-2, 0, -2, -1,
|
|
|
|
0, 0, 0, 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0, 24, 39, 24,
|
|
|
|
39, 0, 39, 24,
|
|
|
|
38, 0, 38, 24,
|
|
|
|
255, 0, 0, 0
|
|
|
|
}
|
2003-06-06 12:27:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Inverse iris effect, specially tailored for V1/V2 games
|
|
|
|
{
|
2004-01-05 00:45:17 +00:00
|
|
|
9, // Number of iterations
|
2003-06-06 12:27:33 +00:00
|
|
|
{
|
|
|
|
-1, -1, 1, -1,
|
|
|
|
-1, 1, 1, 1,
|
|
|
|
-1, -1, -1, 1,
|
|
|
|
1, -1, 1, 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
7, 7, 32, 7,
|
|
|
|
7, 8, 32, 8,
|
|
|
|
7, 8, 7, 8,
|
|
|
|
32, 7, 32, 8
|
|
|
|
}
|
2003-01-05 21:18:53 +00:00
|
|
|
}
|
2002-12-15 23:40:37 +00:00
|
|
|
};
|
2003-04-30 13:23:31 +00:00
|
|
|
#endif
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2004-04-08 23:43:30 +00:00
|
|
|
static inline void copy8PixelsWithMasking(byte *dst, const byte *src, byte maskbits) {
|
|
|
|
if (!(maskbits & 0x80))
|
|
|
|
dst[0] = src[0];
|
|
|
|
if (!(maskbits & 0x40))
|
|
|
|
dst[1] = src[1];
|
|
|
|
if (!(maskbits & 0x20))
|
|
|
|
dst[2] = src[2];
|
|
|
|
if (!(maskbits & 0x10))
|
|
|
|
dst[3] = src[3];
|
|
|
|
if (!(maskbits & 0x08))
|
|
|
|
dst[4] = src[4];
|
|
|
|
if (!(maskbits & 0x04))
|
|
|
|
dst[5] = src[5];
|
|
|
|
if (!(maskbits & 0x02))
|
|
|
|
dst[6] = src[6];
|
|
|
|
if (!(maskbits & 0x01))
|
|
|
|
dst[7] = src[7];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void clear8PixelsWithMasking(byte *dst, const byte color, byte maskbits) {
|
|
|
|
if (!(maskbits & 0x80))
|
|
|
|
dst[0] = color;
|
|
|
|
if (!(maskbits & 0x40))
|
|
|
|
dst[1] = color;
|
|
|
|
if (!(maskbits & 0x20))
|
|
|
|
dst[2] = color;
|
|
|
|
if (!(maskbits & 0x10))
|
|
|
|
dst[3] = color;
|
|
|
|
if (!(maskbits & 0x08))
|
|
|
|
dst[4] = color;
|
|
|
|
if (!(maskbits & 0x04))
|
|
|
|
dst[5] = color;
|
|
|
|
if (!(maskbits & 0x02))
|
|
|
|
dst[6] = color;
|
|
|
|
if (!(maskbits & 0x01))
|
|
|
|
dst[7] = color;
|
|
|
|
}
|
|
|
|
|
2003-10-13 12:56:53 +00:00
|
|
|
#pragma mark -
|
2004-01-04 13:49:03 +00:00
|
|
|
#pragma mark --- Virtual Screens ---
|
2003-10-13 12:56:53 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
2004-01-04 13:49:03 +00:00
|
|
|
|
2003-10-13 12:56:53 +00:00
|
|
|
Gdi::Gdi(ScummEngine *vm) {
|
|
|
|
memset(this, 0, sizeof(*this));
|
|
|
|
_vm = vm;
|
|
|
|
_roomPalette = vm->_roomPalette;
|
2003-10-13 22:48:45 +00:00
|
|
|
if ((vm->_features & GF_AMIGA) && (vm->_version >= 4))
|
2003-10-13 12:56:53 +00:00
|
|
|
_roomPalette += 16;
|
|
|
|
}
|
|
|
|
|
2004-01-04 14:49:14 +00:00
|
|
|
void ScummEngine::initScreens(int b, int h) {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2002-07-07 20:32:26 +00:00
|
|
|
nukeResource(rtBuffer, i + 1);
|
2002-04-11 17:19:16 +00:00
|
|
|
nukeResource(rtBuffer, i + 5);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!getResourceAddress(rtBuffer, 4)) {
|
2004-01-04 13:09:02 +00:00
|
|
|
// Since the size of screen 3 is fixed, there is no need to reallocate
|
|
|
|
// it if its size changed.
|
|
|
|
// Not sure what it is good for, though. I think it may have been used
|
|
|
|
// in pre-V7 for the games messages (like 'Pause', Yes/No dialogs,
|
|
|
|
// version display, etc.). I don't know about V7, maybe the same is the
|
|
|
|
// case there. If so, we could probably just remove it completely.
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version >= 7) {
|
2004-01-03 22:45:23 +00:00
|
|
|
initVirtScreen(kUnkVirtScreen, 0, (_screenHeight / 2) - 10, _screenWidth, 13, false, false);
|
2002-10-27 18:41:27 +00:00
|
|
|
} else {
|
2004-01-03 22:45:23 +00:00
|
|
|
initVirtScreen(kUnkVirtScreen, 0, 80, _screenWidth, 13, false, false);
|
2002-10-27 18:41:27 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2004-01-03 21:22:07 +00:00
|
|
|
initVirtScreen(kMainVirtScreen, 0, b, _screenWidth, h - b, true, true);
|
|
|
|
initVirtScreen(kTextVirtScreen, 0, 0, _screenWidth, b, false, false);
|
|
|
|
initVirtScreen(kVerbVirtScreen, 0, h, _screenWidth, _screenHeight - h, false, false);
|
2001-10-10 10:02:33 +00:00
|
|
|
|
|
|
|
_screenB = b;
|
|
|
|
_screenH = h;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 22:45:23 +00:00
|
|
|
void ScummEngine::initVirtScreen(VirtScreenNumber slot, int number, int top, int width, int height, bool twobufs,
|
2003-03-06 17:58:13 +00:00
|
|
|
bool scrollable) {
|
2001-10-09 14:30:12 +00:00
|
|
|
VirtScreen *vs = &virtscr[slot];
|
|
|
|
int size;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
assert(height >= 0);
|
|
|
|
assert(slot >= 0 && slot < 4);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version >= 7) {
|
|
|
|
if (slot == 0 && (_roomHeight != 0))
|
2003-05-10 21:49:59 +00:00
|
|
|
height = _roomHeight;
|
2002-10-13 11:28:39 +00:00
|
|
|
}
|
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
vs->number = slot;
|
2004-01-04 13:09:02 +00:00
|
|
|
vs->width = width;
|
2001-10-09 14:30:12 +00:00
|
|
|
vs->topline = top;
|
|
|
|
vs->height = height;
|
2004-01-06 11:47:34 +00:00
|
|
|
vs->hasTwoBuffers = twobufs;
|
2001-10-09 14:30:12 +00:00
|
|
|
vs->xstart = 0;
|
2002-03-20 22:58:41 +00:00
|
|
|
vs->backBuf = NULL;
|
2002-03-14 13:57:28 +00:00
|
|
|
|
2004-01-03 22:21:56 +00:00
|
|
|
size = vs->width * vs->height;
|
2004-01-06 12:16:28 +00:00
|
|
|
if (scrollable) {
|
2004-01-04 13:09:02 +00:00
|
|
|
// Allow enough spaces so that rooms can be up to 4 resp. 8 screens
|
|
|
|
// wide. To achieve (horizontal!) scrolling, we use a neat trick:
|
|
|
|
// only the offset into the screen buffer (xstart) is changed. That way
|
|
|
|
// very little of the screen has to be redrawn, and we have a very low
|
|
|
|
// memory overhead (namely for every pixel we want to scroll, we need
|
|
|
|
// one additional byte in the buffer).
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version >= 7) {
|
2004-01-04 13:09:02 +00:00
|
|
|
size += width * 8;
|
2002-12-21 01:11:42 +00:00
|
|
|
} else {
|
2004-01-04 13:09:02 +00:00
|
|
|
size += width * 4;
|
2002-12-21 01:11:42 +00:00
|
|
|
}
|
2002-10-27 10:31:07 +00:00
|
|
|
}
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
createResource(rtBuffer, slot + 1, size);
|
|
|
|
vs->screenPtr = getResourceAddress(rtBuffer, slot + 1);
|
2002-12-21 01:11:42 +00:00
|
|
|
memset(vs->screenPtr, 0, size); // reset background
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
if (twobufs) {
|
2004-01-04 13:49:03 +00:00
|
|
|
vs->backBuf = createResource(rtBuffer, slot + 5, size);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (slot != 3) {
|
2003-10-13 12:56:53 +00:00
|
|
|
vs->setDirtyRange(0, height);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
VirtScreen *ScummEngine::findVirtScreen(int y) {
|
2002-12-15 23:40:37 +00:00
|
|
|
VirtScreen *vs = virtscr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++, vs++) {
|
|
|
|
if (y >= vs->topline && y < vs->topline + vs->height) {
|
2002-12-21 01:11:42 +00:00
|
|
|
return vs;
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-21 01:11:42 +00:00
|
|
|
return NULL;
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 22:45:23 +00:00
|
|
|
void ScummEngine::markRectAsDirty(VirtScreenNumber virt, int left, int right, int top, int bottom, int dirtybit) {
|
2002-12-15 23:40:37 +00:00
|
|
|
VirtScreen *vs = &virtscr[virt];
|
|
|
|
int lp, rp;
|
|
|
|
|
2003-05-30 02:01:45 +00:00
|
|
|
if (left > right || top > bottom)
|
|
|
|
return;
|
|
|
|
if (top > vs->height || bottom < 0)
|
2002-12-15 23:40:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (top < 0)
|
|
|
|
top = 0;
|
|
|
|
if (bottom > vs->height)
|
|
|
|
bottom = vs->height;
|
|
|
|
|
2004-01-03 22:45:23 +00:00
|
|
|
if (virt == kMainVirtScreen && dirtybit) {
|
2003-11-16 20:52:57 +00:00
|
|
|
lp = left / 8 + _screenStartStrip;
|
2002-12-15 23:40:37 +00:00
|
|
|
if (lp < 0)
|
|
|
|
lp = 0;
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version >= 7) {
|
2002-12-21 01:11:42 +00:00
|
|
|
#ifdef V7_SMOOTH_SCROLLING_HACK
|
2003-11-16 20:52:57 +00:00
|
|
|
rp = (right + vs->xstart) / 8;
|
2002-12-21 01:11:42 +00:00
|
|
|
#else
|
2003-11-16 20:52:57 +00:00
|
|
|
rp = right / 8 + _screenStartStrip;
|
2002-12-21 01:11:42 +00:00
|
|
|
#endif
|
2002-12-15 23:40:37 +00:00
|
|
|
if (rp > 409)
|
|
|
|
rp = 409;
|
|
|
|
} else {
|
2003-11-16 20:52:57 +00:00
|
|
|
rp = right / 8 + _screenStartStrip;
|
2002-12-15 23:40:37 +00:00
|
|
|
if (rp >= 200)
|
|
|
|
rp = 200;
|
|
|
|
}
|
2003-01-14 10:06:56 +00:00
|
|
|
for (; lp <= rp; lp++)
|
|
|
|
setGfxUsageBit(lp, dirtybit);
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
|
2003-11-07 02:11:41 +00:00
|
|
|
// The following code used to be in the separate method setVirtscreenDirty
|
2003-11-16 20:52:57 +00:00
|
|
|
lp = left / 8;
|
|
|
|
rp = right / 8;
|
2002-12-15 23:40:37 +00:00
|
|
|
|
|
|
|
if ((lp >= gdi._numStrips) || (rp < 0))
|
|
|
|
return;
|
|
|
|
if (lp < 0)
|
|
|
|
lp = 0;
|
|
|
|
if (rp >= gdi._numStrips)
|
|
|
|
rp = gdi._numStrips - 1;
|
|
|
|
|
|
|
|
while (lp <= rp) {
|
|
|
|
if (top < vs->tdirty[lp])
|
|
|
|
vs->tdirty[lp] = top;
|
|
|
|
if (bottom > vs->bdirty[lp])
|
|
|
|
vs->bdirty[lp] = bottom;
|
|
|
|
lp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-03 21:22:07 +00:00
|
|
|
/**
|
|
|
|
* Update all dirty screen areas. This method blits all of the internal engine
|
|
|
|
* graphics to the actual display, as needed. In addition, the 'shaking'
|
|
|
|
* code in the backend is controlled from here.
|
|
|
|
*/
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::drawDirtyScreenParts() {
|
2004-01-03 21:22:07 +00:00
|
|
|
// Update verbs
|
|
|
|
updateDirtyScreen(kVerbVirtScreen);
|
|
|
|
|
2004-01-06 12:08:35 +00:00
|
|
|
// Update the conversation area (at the top of the screen)
|
|
|
|
updateDirtyScreen(kTextVirtScreen);
|
2004-01-03 21:22:07 +00:00
|
|
|
|
|
|
|
// Update game area ("stage")
|
|
|
|
if (camera._last.x != camera._cur.x || (_features & GF_NEW_CAMERA && (camera._cur.y != camera._last.y))) {
|
|
|
|
// Camera moved: redraw everything
|
|
|
|
// Small side note: most of our GFX code relies on this identity:
|
|
|
|
// gdi._numStrips * 8 == _screenWidth == vs->width
|
|
|
|
VirtScreen *vs = &virtscr[kMainVirtScreen];
|
|
|
|
gdi.drawStripToScreen(vs, 0, vs->width, 0, vs->height);
|
|
|
|
vs->setDirtyRange(vs->height, 0);
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2004-01-03 21:22:07 +00:00
|
|
|
updateDirtyScreen(kMainVirtScreen);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2001-12-28 15:26:28 +00:00
|
|
|
|
2004-01-03 21:22:07 +00:00
|
|
|
// Handle shaking
|
2002-12-25 21:04:47 +00:00
|
|
|
if (_shakeEnabled) {
|
2004-01-03 21:22:07 +00:00
|
|
|
_shakeFrame = (_shakeFrame + 1) % NUM_SHAKE_POSITIONS;
|
2002-04-12 21:26:59 +00:00
|
|
|
_system->set_shake_pos(shake_positions[_shakeFrame]);
|
2002-07-28 15:39:44 +00:00
|
|
|
} else if (!_shakeEnabled &&_shakeFrame != 0) {
|
|
|
|
_shakeFrame = 0;
|
|
|
|
_system->set_shake_pos(shake_positions[_shakeFrame]);
|
2001-12-28 15:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2004-01-03 22:45:23 +00:00
|
|
|
void ScummEngine::updateDirtyScreen(VirtScreenNumber slot) {
|
2001-10-26 17:34:50 +00:00
|
|
|
gdi.updateDirtyScreen(&virtscr[slot]);
|
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/**
|
2004-01-03 21:22:07 +00:00
|
|
|
* Blit the dirty data from the given VirtScreen to the display. If the camera moved,
|
2003-05-30 20:13:29 +00:00
|
|
|
* a full blit is done, otherwise only the visible dirty areas are updated.
|
|
|
|
*/
|
2003-03-06 17:58:13 +00:00
|
|
|
void Gdi::updateDirtyScreen(VirtScreen *vs) {
|
2004-01-03 21:22:07 +00:00
|
|
|
// Do nothing for unused virtual screens
|
2002-04-11 17:19:16 +00:00
|
|
|
if (vs->height == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2004-01-03 21:22:07 +00:00
|
|
|
int i;
|
|
|
|
int w = 8;
|
|
|
|
int start = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < _numStrips; i++) {
|
|
|
|
if (vs->bdirty[i]) {
|
|
|
|
const int top = vs->tdirty[i];
|
2004-01-05 00:45:17 +00:00
|
|
|
const int bottom = vs->bdirty[i];
|
2004-01-03 21:22:07 +00:00
|
|
|
vs->tdirty[i] = vs->height;
|
|
|
|
vs->bdirty[i] = 0;
|
|
|
|
if (i != (_numStrips - 1) && vs->bdirty[i + 1] == bottom && vs->tdirty[i + 1] == top) {
|
2004-01-08 00:48:37 +00:00
|
|
|
// Simple optimizations: if two or more neighbouring strips
|
|
|
|
// form one bigger rectangle, coalesce them.
|
2004-01-03 21:22:07 +00:00
|
|
|
w += 8;
|
|
|
|
continue;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2004-01-08 00:48:37 +00:00
|
|
|
drawStripToScreen(vs, start * 8, w, top, bottom);
|
2004-01-03 21:22:07 +00:00
|
|
|
w = 8;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2004-01-03 21:22:07 +00:00
|
|
|
start = i + 1;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/**
|
|
|
|
* Blit the specified rectangle from the given virtual screen to the display.
|
2004-01-08 00:48:37 +00:00
|
|
|
* Note: t and b are in *virtual screen* coordinates, while x is relative to
|
|
|
|
* the *real screen*. This is due to the way tdirty/vdirty work: they are
|
|
|
|
* arrays which map 'strips' (sections of the real screen) to dirty areas as
|
|
|
|
* specified by top/bottom coordinate in the virtual screen.
|
2003-05-30 20:13:29 +00:00
|
|
|
*/
|
2004-01-08 00:48:37 +00:00
|
|
|
void Gdi::drawStripToScreen(VirtScreen *vs, int x, int width, int top, int bottom) {
|
2001-10-26 17:34:50 +00:00
|
|
|
byte *ptr;
|
2002-04-23 23:58:31 +00:00
|
|
|
int height;
|
|
|
|
|
2004-01-08 00:48:37 +00:00
|
|
|
if (bottom <= top)
|
2001-10-26 17:34:50 +00:00
|
|
|
return;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2004-01-08 00:48:37 +00:00
|
|
|
if (top >= vs->height)
|
|
|
|
return;
|
2002-05-14 21:55:17 +00:00
|
|
|
|
2004-01-08 00:48:37 +00:00
|
|
|
assert(top >= 0 && bottom <= vs->height); // Paranoia checks
|
2002-04-23 23:58:31 +00:00
|
|
|
|
2004-01-08 00:48:37 +00:00
|
|
|
height = bottom - top;
|
|
|
|
// We don't clip height and width here, rather we rely on the backend to
|
|
|
|
// perform any needed clipping.
|
|
|
|
ptr = vs->screenPtr + (x + vs->xstart) + top * vs->width;
|
2004-03-28 16:30:50 +00:00
|
|
|
_vm->_system->copyRectToScreen(ptr, vs->width, x, vs->topline + top - _vm->_screenTop, width, height);
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
2004-01-04 14:35:46 +00:00
|
|
|
#pragma mark --- Background buffers & charset mask ---
|
|
|
|
#pragma mark -
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::initBGBuffers(int height) {
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *ptr;
|
2002-12-15 23:40:37 +00:00
|
|
|
int size, itemsize, i;
|
|
|
|
byte *room;
|
2002-12-09 01:27:40 +00:00
|
|
|
|
2004-01-05 00:03:18 +00:00
|
|
|
if (_version >= 7) {
|
|
|
|
// Resize main virtual screen in V7 games. This is necessary
|
|
|
|
// because in V7, rooms may be higher than one screen, so we have
|
|
|
|
// to accomodate for that.
|
|
|
|
initVirtScreen(kMainVirtScreen, 0, virtscr[0].topline, _screenWidth, height, 1, 1);
|
|
|
|
}
|
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
room = getResourceAddress(rtRoom, _roomResource);
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version <= 3) {
|
2002-12-15 23:40:37 +00:00
|
|
|
gdi._numZBuffer = 2;
|
|
|
|
} else if (_features & GF_SMALL_HEADER) {
|
|
|
|
int off;
|
|
|
|
ptr = findResourceData(MKID('SMAP'), room);
|
|
|
|
gdi._numZBuffer = 0;
|
2003-04-24 18:53:21 +00:00
|
|
|
|
2003-08-13 02:21:36 +00:00
|
|
|
if (_gameId == GID_MONKEY_EGA || _gameId == GID_PASS)
|
2003-04-24 18:53:21 +00:00
|
|
|
off = READ_LE_UINT16(ptr);
|
|
|
|
else
|
2003-04-09 19:14:05 +00:00
|
|
|
off = READ_LE_UINT32(ptr);
|
2003-04-24 18:53:21 +00:00
|
|
|
|
|
|
|
while (off && gdi._numZBuffer < 4) {
|
|
|
|
gdi._numZBuffer++;
|
|
|
|
ptr += off;
|
|
|
|
off = READ_LE_UINT16(ptr);
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
2003-06-07 00:13:26 +00:00
|
|
|
} else if (_version == 8) {
|
2002-12-24 07:53:29 +00:00
|
|
|
// in V8 there is no RMIH and num z buffers is in RMHD
|
|
|
|
ptr = findResource(MKID('RMHD'), room);
|
|
|
|
gdi._numZBuffer = READ_LE_UINT32(ptr + 24) + 1;
|
2002-12-15 23:40:37 +00:00
|
|
|
} else {
|
|
|
|
ptr = findResource(MKID('RMIH'), findResource(MKID('RMIM'), room));
|
|
|
|
gdi._numZBuffer = READ_LE_UINT16(ptr + 8) + 1;
|
|
|
|
}
|
2002-12-26 18:10:14 +00:00
|
|
|
assert(gdi._numZBuffer >= 1 && gdi._numZBuffer <= 8);
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version >= 7)
|
2003-05-10 21:49:59 +00:00
|
|
|
itemsize = (_roomHeight + 10) * gdi._numStrips;
|
2002-12-15 23:40:37 +00:00
|
|
|
else
|
2003-05-10 21:49:59 +00:00
|
|
|
itemsize = (_roomHeight + 4) * gdi._numStrips;
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
size = itemsize * gdi._numZBuffer;
|
|
|
|
memset(createResource(rtBuffer, 9, size), 0, size);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
for (i = 0; i < (int)ARRAYSIZE(gdi._imgBufOffs); i++) {
|
|
|
|
if (i < gdi._numZBuffer)
|
|
|
|
gdi._imgBufOffs[i] = i * itemsize;
|
|
|
|
else
|
|
|
|
gdi._imgBufOffs[i] = (gdi._numZBuffer - 1) * itemsize;
|
|
|
|
}
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/**
|
|
|
|
* Redraw background as needed, i.e. the left/right sides if scrolling took place etc.
|
|
|
|
* Note that this only updated the virtual screen, not the actual display.
|
|
|
|
*/
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::redrawBGAreas() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
int val;
|
2002-03-06 12:24:56 +00:00
|
|
|
int diff;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (!(_features & GF_NEW_CAMERA))
|
2004-01-06 13:28:19 +00:00
|
|
|
if (camera._cur.x != camera._last.x && _charset->_hasMask && (_version > 3 && _gameId != GID_PASS))
|
2002-03-05 23:41:41 +00:00
|
|
|
stopTalk();
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
val = 0;
|
|
|
|
|
2002-12-21 01:11:42 +00:00
|
|
|
// Redraw parts of the background which are marked as dirty.
|
2001-11-26 19:57:57 +00:00
|
|
|
if (!_fullRedraw && _BgNeedsRedraw) {
|
2002-10-24 06:28:54 +00:00
|
|
|
for (i = 0; i != gdi._numStrips; i++) {
|
2003-01-14 10:06:56 +00:00
|
|
|
if (testGfxUsageBit(_screenStartStrip + i, USAGE_BIT_DIRTY)) {
|
2001-10-09 14:30:12 +00:00
|
|
|
redrawBGStrip(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_features & GF_NEW_CAMERA) {
|
2003-11-16 20:52:57 +00:00
|
|
|
diff = camera._cur.x / 8 - camera._last.x / 8;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_fullRedraw == 0 && diff == 1) {
|
2002-03-05 23:41:41 +00:00
|
|
|
val = 2;
|
2002-10-24 06:28:54 +00:00
|
|
|
redrawBGStrip(gdi._numStrips - 1, 1);
|
2002-04-11 17:19:16 +00:00
|
|
|
} else if (_fullRedraw == 0 && diff == -1) {
|
2002-03-05 23:41:41 +00:00
|
|
|
val = 1;
|
|
|
|
redrawBGStrip(0, 1);
|
2002-04-11 17:19:16 +00:00
|
|
|
} else if (_fullRedraw != 0 || diff != 0) {
|
2002-03-05 23:41:41 +00:00
|
|
|
_BgNeedsRedraw = false;
|
2002-10-24 06:28:54 +00:00
|
|
|
redrawBGStrip(0, gdi._numStrips);
|
2002-03-05 23:41:41 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-08-15 20:12:15 +00:00
|
|
|
if (_fullRedraw == 0 && camera._cur.x - camera._last.x == 8) {
|
2002-03-05 23:41:41 +00:00
|
|
|
val = 2;
|
2002-10-24 06:28:54 +00:00
|
|
|
redrawBGStrip(gdi._numStrips - 1, 1);
|
2002-08-15 20:12:15 +00:00
|
|
|
} else if (_fullRedraw == 0 && camera._cur.x - camera._last.x == -8) {
|
2002-03-05 23:41:41 +00:00
|
|
|
val = 1;
|
|
|
|
redrawBGStrip(0, 1);
|
2002-08-15 20:12:15 +00:00
|
|
|
} else if (_fullRedraw != 0 || camera._cur.x != camera._last.x) {
|
2002-03-05 23:41:41 +00:00
|
|
|
_BgNeedsRedraw = false;
|
2003-05-15 22:48:06 +00:00
|
|
|
_flashlight.isDrawn = false;
|
2002-10-24 06:28:54 +00:00
|
|
|
redrawBGStrip(0, gdi._numStrips);
|
2002-03-05 23:41:41 +00:00
|
|
|
}
|
2001-12-27 17:51:58 +00:00
|
|
|
}
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
drawRoomObjects(val);
|
2001-11-26 19:57:57 +00:00
|
|
|
_BgNeedsRedraw = false;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::redrawBGStrip(int start, int num) {
|
2002-12-15 23:40:37 +00:00
|
|
|
int s = _screenStartStrip + start;
|
|
|
|
|
2003-01-14 10:06:56 +00:00
|
|
|
assert(s >= 0 && (size_t) s < sizeof(gfxUsageBits) / (3 * sizeof(gfxUsageBits[0])));
|
2002-12-15 23:40:37 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < num; i++)
|
2003-01-14 10:06:56 +00:00
|
|
|
setGfxUsageBit(s + i, USAGE_BIT_DIRTY);
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 1) {
|
2003-06-06 05:27:45 +00:00
|
|
|
gdi._C64ObjectMode = false;
|
|
|
|
}
|
2002-12-15 23:40:37 +00:00
|
|
|
gdi.drawBitmap(getResourceAddress(rtRoom, _roomResource) + _IM00_offs,
|
2003-11-08 21:59:32 +00:00
|
|
|
&virtscr[0], s, 0, _roomWidth, virtscr[0].height, s, num, 0, _roomStrips);
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::restoreBG(Common::Rect rect, byte backColor) {
|
2002-12-15 23:40:37 +00:00
|
|
|
VirtScreen *vs;
|
2004-04-08 23:43:30 +00:00
|
|
|
byte *screenBuf;
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2003-05-15 22:30:32 +00:00
|
|
|
if (rect.top < 0)
|
|
|
|
rect.top = 0;
|
2003-06-08 15:17:14 +00:00
|
|
|
if (rect.left >= rect.right || rect.top >= rect.bottom)
|
|
|
|
return;
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2003-05-15 22:30:32 +00:00
|
|
|
if ((vs = findVirtScreen(rect.top)) == NULL)
|
2002-12-15 23:40:37 +00:00
|
|
|
return;
|
|
|
|
|
2004-01-08 03:24:41 +00:00
|
|
|
if (rect.left > vs->width)
|
|
|
|
return;
|
|
|
|
|
2004-04-08 23:43:30 +00:00
|
|
|
// Convert 'rect' to local (virtual screen) coordinates
|
|
|
|
rect.top -= vs->topline;
|
|
|
|
rect.bottom -= vs->topline;
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2004-01-08 03:24:41 +00:00
|
|
|
rect.clip(vs->width, vs->height);
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2004-01-08 03:24:41 +00:00
|
|
|
markRectAsDirty(vs->number, rect, USAGE_BIT_RESTORED);
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2004-04-08 23:43:30 +00:00
|
|
|
const int offset = rect.top * vs->width + vs->xstart + rect.left;
|
|
|
|
screenBuf = vs->screenPtr + offset;
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2004-01-08 21:58:46 +00:00
|
|
|
int height = rect.height();
|
|
|
|
int width = rect.width();
|
2004-04-08 23:43:30 +00:00
|
|
|
|
|
|
|
if (!height)
|
|
|
|
return;
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2004-01-08 21:44:03 +00:00
|
|
|
if (vs->hasTwoBuffers && _currentRoom != 0 && isLightOn()) {
|
2004-04-08 23:43:30 +00:00
|
|
|
blit(screenBuf, vs->backBuf + offset, width, height);
|
|
|
|
if (vs->number == kMainVirtScreen && _charset->_hasMask) {
|
2003-05-27 23:23:26 +00:00
|
|
|
// Note: At first sight it may look as if this could
|
2003-11-16 20:52:57 +00:00
|
|
|
// be optimized to (rect.right - rect.left) / 8 and
|
2003-11-16 21:26:10 +00:00
|
|
|
// thus to width / 8, but that's not the case since
|
2003-05-27 23:23:26 +00:00
|
|
|
// we are dealing with integer math here.
|
2004-04-08 23:43:30 +00:00
|
|
|
const int mask_width = ((rect.right + 7) / 8) - (rect.left / 8);
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2004-04-08 23:43:30 +00:00
|
|
|
byte *mask = getMaskBuffer(rect.left, rect.top, 0);
|
2002-12-15 23:40:37 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
memset(mask, 0, mask_width);
|
|
|
|
mask += gdi._numStrips;
|
|
|
|
} while (--height);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (height--) {
|
2004-04-08 23:43:30 +00:00
|
|
|
memset(screenBuf, backColor, width);
|
|
|
|
screenBuf += vs->width;
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-08 21:21:40 +00:00
|
|
|
void CharsetRenderer::restoreCharsetBg() {
|
2004-04-08 23:43:30 +00:00
|
|
|
_nextLeft = _vm->_string[0].xpos;
|
|
|
|
_nextTop = _vm->_string[0].ypos;
|
|
|
|
|
2004-01-08 21:21:40 +00:00
|
|
|
if (_hasMask) {
|
|
|
|
_hasMask = false;
|
|
|
|
_str.left = -1;
|
|
|
|
_left = -1;
|
|
|
|
|
2004-04-08 23:43:30 +00:00
|
|
|
// Restore background on the whole text area. This code is based on
|
|
|
|
// restoreBG(), but was changed to only restore those parts which are
|
|
|
|
// currently covered by the charset mask.
|
|
|
|
|
|
|
|
// Loop over first three virtual screens
|
|
|
|
VirtScreen *vs = &_vm->virtscr[_textScreenID];
|
|
|
|
|
|
|
|
if (!vs->height)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_vm->markRectAsDirty(vs->number, Common::Rect(vs->width, vs->height), USAGE_BIT_RESTORED);
|
|
|
|
|
|
|
|
byte *screenBuf = vs->screenPtr + vs->xstart;
|
|
|
|
|
|
|
|
if (vs->hasTwoBuffers && _vm->_currentRoom != 0 && _vm->isLightOn()) {
|
|
|
|
const byte *backBuf = vs->backBuf + vs->xstart;
|
|
|
|
|
|
|
|
if (vs->number == kMainVirtScreen) {
|
|
|
|
// Restore from back buffer, but only those parts which are
|
|
|
|
// currently covered by the charset mask. In addition, we
|
|
|
|
// clean out the charset mask
|
|
|
|
|
|
|
|
const int mask_width = _vm->gdi._numStrips;
|
2004-06-14 07:23:59 +00:00
|
|
|
byte *mask = _vm->getMaskBuffer(0, 0, 0);
|
2004-04-08 23:43:30 +00:00
|
|
|
assert(vs->width == 8 * _vm->gdi._numStrips);
|
|
|
|
|
|
|
|
int height = vs->height;
|
|
|
|
while (height--) {
|
|
|
|
for (int w = 0; w < mask_width; ++w) {
|
|
|
|
const byte maskbits = mask[w];
|
|
|
|
if (maskbits) {
|
|
|
|
copy8PixelsWithMasking(screenBuf + w*8, backBuf + w*8, ~maskbits);
|
|
|
|
mask[w] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
screenBuf += vs->width;
|
|
|
|
backBuf += vs->width;
|
|
|
|
mask += _vm->gdi._numStrips;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Restore from back buffer
|
|
|
|
_vm->blit(screenBuf, backBuf, vs->width, vs->height);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Clear area
|
|
|
|
memset(screenBuf, 0, vs->height * vs->width);
|
|
|
|
}
|
|
|
|
}
|
2004-01-08 21:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CharsetRenderer::clearCharsetMask() {
|
|
|
|
memset(_vm->getResourceAddress(rtBuffer, 9), 0, _vm->gdi._imgBufOffs[1]);
|
2004-01-03 22:45:23 +00:00
|
|
|
}
|
|
|
|
|
2004-01-08 21:21:40 +00:00
|
|
|
bool CharsetRenderer::hasCharsetMask(int left, int top, int right, int bottom) {
|
2004-04-04 20:20:09 +00:00
|
|
|
return _hasMask;
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
byte *ScummEngine::getMaskBuffer(int x, int y, int z) {
|
2004-04-08 23:43:30 +00:00
|
|
|
return gdi.getMaskBuffer(x / 8, y, z) + _screenStartStrip;
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2004-01-04 13:49:03 +00:00
|
|
|
byte *Gdi::getMaskBuffer(int x, int y, int z) {
|
|
|
|
return _vm->getResourceAddress(rtBuffer, 9)
|
|
|
|
+ x + y * _numStrips + _imgBufOffs[z];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark --- Misc ---
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
void ScummEngine::blit(byte *dst, const byte *src, int w, int h) {
|
|
|
|
assert(h > 0);
|
|
|
|
assert(src != NULL);
|
|
|
|
assert(dst != NULL);
|
|
|
|
|
|
|
|
// TODO: This function currently always assumes that srcPitch == dstPitch
|
|
|
|
// and furthermore that both equal _screenWidth.
|
|
|
|
|
|
|
|
if (w==_screenWidth)
|
|
|
|
memcpy (dst, src, w*h);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
memcpy(dst, src, w);
|
|
|
|
dst += _screenWidth;
|
|
|
|
src += _screenWidth;
|
|
|
|
} while (--h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScummEngine::drawBox(int x, int y, int x2, int y2, int color) {
|
|
|
|
int width, height;
|
|
|
|
VirtScreen *vs;
|
|
|
|
byte *backbuff, *bgbuff;
|
|
|
|
|
|
|
|
if ((vs = findVirtScreen(y)) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (x > x2)
|
|
|
|
SWAP(x, x2);
|
|
|
|
|
|
|
|
if (y > y2)
|
|
|
|
SWAP(y, y2);
|
|
|
|
|
|
|
|
x2++;
|
|
|
|
y2++;
|
|
|
|
|
|
|
|
// Adjust for the topline of the VirtScreen
|
|
|
|
y -= vs->topline;
|
|
|
|
y2 -= vs->topline;
|
|
|
|
|
|
|
|
// Clip the coordinates
|
|
|
|
if (x < 0)
|
|
|
|
x = 0;
|
|
|
|
else if (x >= vs->width)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (x2 < 0)
|
|
|
|
return;
|
|
|
|
else if (x2 > vs->width)
|
|
|
|
x2 = vs->width;
|
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
y = 0;
|
|
|
|
else if (y > vs->height)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (y2 < 0)
|
|
|
|
return;
|
|
|
|
else if (y2 > vs->height)
|
|
|
|
y2 = vs->height;
|
|
|
|
|
2004-01-08 03:24:41 +00:00
|
|
|
markRectAsDirty(vs->number, x, x2, y, y2);
|
2004-01-04 13:49:03 +00:00
|
|
|
|
|
|
|
backbuff = vs->screenPtr + vs->xstart + y * vs->width + x;
|
|
|
|
|
|
|
|
width = x2 - x;
|
|
|
|
height = y2 - y;
|
|
|
|
if (color == -1) {
|
|
|
|
if (vs->number != kMainVirtScreen)
|
|
|
|
error("can only copy bg to main window");
|
|
|
|
bgbuff = vs->backBuf + vs->xstart + y * vs->width + x;
|
|
|
|
blit(backbuff, bgbuff, width, height);
|
|
|
|
} else {
|
|
|
|
while (height--) {
|
|
|
|
memset(backbuff, color, width);
|
|
|
|
backbuff += vs->width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScummEngine::drawFlashlight() {
|
|
|
|
int i, j, offset, x, y;
|
|
|
|
VirtScreen *vs = &virtscr[kMainVirtScreen];
|
|
|
|
|
|
|
|
// Remove the flash light first if it was previously drawn
|
|
|
|
if (_flashlight.isDrawn) {
|
|
|
|
markRectAsDirty(kMainVirtScreen, _flashlight.x, _flashlight.x + _flashlight.w,
|
|
|
|
_flashlight.y, _flashlight.y + _flashlight.h, USAGE_BIT_DIRTY);
|
|
|
|
|
|
|
|
if (_flashlight.buffer) {
|
|
|
|
i = _flashlight.h;
|
|
|
|
do {
|
|
|
|
memset(_flashlight.buffer, 0, _flashlight.w);
|
|
|
|
_flashlight.buffer += vs->width;
|
|
|
|
} while (--i);
|
|
|
|
}
|
|
|
|
_flashlight.isDrawn = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_flashlight.xStrips == 0 || _flashlight.yStrips == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Calculate the area of the flashlight
|
|
|
|
if (_gameId == GID_ZAK256 || _version <= 2) {
|
|
|
|
x = _mouse.x + vs->xstart;
|
|
|
|
y = _mouse.y - vs->topline;
|
|
|
|
} else {
|
|
|
|
Actor *a = derefActor(VAR(VAR_EGO), "drawFlashlight");
|
|
|
|
x = a->_pos.x;
|
|
|
|
y = a->_pos.y;
|
|
|
|
}
|
|
|
|
_flashlight.w = _flashlight.xStrips * 8;
|
|
|
|
_flashlight.h = _flashlight.yStrips * 8;
|
|
|
|
_flashlight.x = x - _flashlight.w / 2 - _screenStartStrip * 8;
|
|
|
|
_flashlight.y = y - _flashlight.h / 2;
|
|
|
|
|
|
|
|
if (_gameId == GID_LOOM || _gameId == GID_LOOM256)
|
|
|
|
_flashlight.y -= 12;
|
|
|
|
|
|
|
|
// Clip the flashlight at the borders
|
|
|
|
if (_flashlight.x < 0)
|
|
|
|
_flashlight.x = 0;
|
|
|
|
else if (_flashlight.x + _flashlight.w > gdi._numStrips * 8)
|
|
|
|
_flashlight.x = gdi._numStrips * 8 - _flashlight.w;
|
|
|
|
if (_flashlight.y < 0)
|
|
|
|
_flashlight.y = 0;
|
|
|
|
else if (_flashlight.y + _flashlight.h> vs->height)
|
|
|
|
_flashlight.y = vs->height - _flashlight.h;
|
|
|
|
|
|
|
|
// Redraw any actors "under" the flashlight
|
|
|
|
for (i = _flashlight.x / 8; i < (_flashlight.x + _flashlight.w) / 8; i++) {
|
|
|
|
assert(0 <= i && i < gdi._numStrips);
|
|
|
|
setGfxUsageBit(_screenStartStrip + i, USAGE_BIT_DIRTY);
|
|
|
|
vs->tdirty[i] = 0;
|
|
|
|
vs->bdirty[i] = vs->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *bgbak;
|
|
|
|
offset = _flashlight.y * vs->width + vs->xstart + _flashlight.x;
|
|
|
|
_flashlight.buffer = vs->screenPtr + offset;
|
|
|
|
bgbak = vs->backBuf + offset;
|
|
|
|
|
|
|
|
blit(_flashlight.buffer, bgbak, _flashlight.w, _flashlight.h);
|
|
|
|
|
|
|
|
// Round the corners. To do so, we simply hard-code a set of nicely
|
|
|
|
// rounded corners.
|
|
|
|
int corner_data[] = { 8, 6, 4, 3, 2, 2, 1, 1 };
|
|
|
|
int minrow = 0;
|
|
|
|
int maxcol = _flashlight.w - 1;
|
|
|
|
int maxrow = (_flashlight.h - 1) * vs->width;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++, minrow += vs->width, maxrow -= vs->width) {
|
|
|
|
int d = corner_data[i];
|
|
|
|
|
|
|
|
for (j = 0; j < d; j++) {
|
|
|
|
_flashlight.buffer[minrow + j] = 0;
|
|
|
|
_flashlight.buffer[minrow + maxcol - j] = 0;
|
|
|
|
_flashlight.buffer[maxrow + j] = 0;
|
|
|
|
_flashlight.buffer[maxrow + maxcol - j] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_flashlight.isDrawn = true;
|
|
|
|
}
|
2003-06-01 14:30:26 +00:00
|
|
|
|
2004-01-08 21:21:40 +00:00
|
|
|
bool ScummEngine::isLightOn() const {
|
|
|
|
return (VAR_CURRENT_LIGHTS == 0xFF) || (VAR(VAR_CURRENT_LIGHTS) & LIGHTMODE_screen);
|
|
|
|
}
|
|
|
|
|
2003-05-15 23:50:16 +00:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark --- Image drawing ---
|
|
|
|
#pragma mark -
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/**
|
|
|
|
* Draw a bitmap onto a virtual screen. This is main drawing method for room backgrounds
|
|
|
|
* and objects, used throughout all SCUMM versions.
|
|
|
|
*/
|
2003-05-28 20:01:47 +00:00
|
|
|
void Gdi::drawBitmap(const byte *ptr, VirtScreen *vs, int x, int y, const int width, const int height,
|
2003-11-08 21:59:32 +00:00
|
|
|
int stripnr, int numstrip, byte flag, StripTable *table) {
|
2003-03-04 02:43:43 +00:00
|
|
|
assert(ptr);
|
2003-05-10 12:59:32 +00:00
|
|
|
assert(height > 0);
|
2003-05-28 20:01:47 +00:00
|
|
|
byte *backbuff_ptr, *bgbak_ptr;
|
|
|
|
const byte *smap_ptr;
|
|
|
|
const byte *z_plane_ptr;
|
2003-05-11 00:28:43 +00:00
|
|
|
byte *mask_ptr;
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *zplane_list[9];
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
int bottom;
|
|
|
|
int numzbuf;
|
|
|
|
int sx;
|
2002-08-19 17:52:26 +00:00
|
|
|
bool lightsOn;
|
2003-05-04 03:27:55 +00:00
|
|
|
bool useOrDecompress = false;
|
2002-02-12 18:20:37 +00:00
|
|
|
|
2002-08-19 17:52:26 +00:00
|
|
|
// Check whether lights are turned on or not
|
2004-01-08 21:21:40 +00:00
|
|
|
lightsOn = _vm->isLightOn();
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2002-04-17 16:02:29 +00:00
|
|
|
CHECK_HEAP;
|
|
|
|
if (_vm->_features & GF_SMALL_HEADER)
|
2002-12-16 01:25:21 +00:00
|
|
|
smap_ptr = ptr;
|
2003-06-07 00:13:26 +00:00
|
|
|
else if (_vm->_version == 8)
|
2002-12-31 03:26:02 +00:00
|
|
|
smap_ptr = ptr;
|
2002-04-11 17:19:16 +00:00
|
|
|
else
|
|
|
|
smap_ptr = findResource(MKID('SMAP'), ptr);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-11-11 16:54:45 +00:00
|
|
|
assert(smap_ptr);
|
|
|
|
|
2003-04-24 18:53:21 +00:00
|
|
|
zplane_list[0] = smap_ptr;
|
|
|
|
|
2003-05-15 21:31:03 +00:00
|
|
|
if (_zbufferDisabled)
|
2003-04-24 14:33:31 +00:00
|
|
|
numzbuf = 0;
|
2003-06-07 00:13:26 +00:00
|
|
|
else if (_numZBuffer <= 1 || (_vm->_version <= 2))
|
2003-04-26 10:43:59 +00:00
|
|
|
numzbuf = _numZBuffer;
|
2003-04-24 18:53:21 +00:00
|
|
|
else {
|
|
|
|
numzbuf = _numZBuffer;
|
2003-08-25 20:18:44 +00:00
|
|
|
assert(numzbuf <= ARRAYSIZE(zplane_list));
|
2003-04-30 13:23:31 +00:00
|
|
|
|
2003-09-27 20:31:19 +00:00
|
|
|
if (_vm->_features & GF_SMALL_HEADER) {
|
2003-04-25 00:03:06 +00:00
|
|
|
if (_vm->_features & GF_16COLOR)
|
2003-04-24 18:53:21 +00:00
|
|
|
zplane_list[1] = smap_ptr + READ_LE_UINT16(smap_ptr);
|
|
|
|
else
|
|
|
|
zplane_list[1] = smap_ptr + READ_LE_UINT32(smap_ptr);
|
2003-09-27 20:31:19 +00:00
|
|
|
if (_vm->_features & GF_OLD256) {
|
|
|
|
if (0 == READ_LE_UINT32(zplane_list[1]))
|
|
|
|
zplane_list[1] = 0;
|
|
|
|
}
|
2003-04-24 18:53:21 +00:00
|
|
|
for (i = 2; i < numzbuf; i++) {
|
|
|
|
zplane_list[i] = zplane_list[i-1] + READ_LE_UINT16(zplane_list[i-1]);
|
2003-04-10 19:30:01 +00:00
|
|
|
}
|
2003-06-07 00:13:26 +00:00
|
|
|
} else if (_vm->_version == 8) {
|
2003-04-24 18:53:21 +00:00
|
|
|
// Find the OFFS chunk of the ZPLN chunk
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *zplnOffsChunkStart = smap_ptr + READ_BE_UINT32(smap_ptr + 12) + 24;
|
2003-04-24 18:53:21 +00:00
|
|
|
|
|
|
|
// Each ZPLN contains a WRAP chunk, which has (as always) an OFFS subchunk pointing
|
|
|
|
// at ZSTR chunks. These once more contain a WRAP chunk which contains nothing but
|
|
|
|
// an OFFS chunk. The content of this OFFS chunk contains the offsets to the
|
|
|
|
// Z-planes.
|
|
|
|
// We do not directly make use of this, but rather hard code offsets (like we do
|
|
|
|
// for all other Scumm-versions, too). Clearly this is a bit hackish, but works
|
|
|
|
// well enough, and there is no reason to assume that there are any cases where it
|
|
|
|
// might fail. Still, doing this properly would have the advantage of catching
|
|
|
|
// invalid/damaged data files, and allow us to exit gracefully instead of segfaulting.
|
|
|
|
for (i = 1; i < numzbuf; i++) {
|
|
|
|
zplane_list[i] = zplnOffsChunkStart + READ_LE_UINT32(zplnOffsChunkStart + 4 + i*4) + 16;
|
2002-07-28 12:43:35 +00:00
|
|
|
}
|
2002-04-17 16:02:29 +00:00
|
|
|
} else {
|
2003-04-24 18:53:21 +00:00
|
|
|
const uint32 zplane_tags[] = {
|
|
|
|
MKID('ZP00'),
|
|
|
|
MKID('ZP01'),
|
|
|
|
MKID('ZP02'),
|
|
|
|
MKID('ZP03'),
|
|
|
|
MKID('ZP04')
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 1; i < numzbuf; i++) {
|
|
|
|
zplane_list[i] = findResource(zplane_tags[i], ptr);
|
|
|
|
}
|
2002-04-17 16:02:29 +00:00
|
|
|
}
|
2001-10-26 17:34:50 +00:00
|
|
|
}
|
2003-04-26 10:43:59 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_vm->_version == 8) {
|
2003-04-26 10:43:59 +00:00
|
|
|
// A small hack to skip to the BSTR->WRAP->OFFS chunk. Note: order matters, we do this
|
|
|
|
// *after* the Z buffer code because that assumes' the orginal value of smap_ptr.
|
|
|
|
smap_ptr += 24;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-10 12:59:32 +00:00
|
|
|
bottom = y + height;
|
2001-10-26 17:34:50 +00:00
|
|
|
if (bottom > vs->height) {
|
2002-07-07 20:32:26 +00:00
|
|
|
warning("Gdi::drawBitmap, strip drawn to %d below window bottom %d", bottom, vs->height);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2004-01-04 13:09:02 +00:00
|
|
|
_vertStripNextInc = height * vs->width - 1;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2004-01-06 12:16:28 +00:00
|
|
|
sx = x - vs->xstart / 8;
|
2003-05-10 12:23:02 +00:00
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
//
|
|
|
|
// Since V3, all graphics data was encoded in strips, which is very efficient
|
|
|
|
// for redrawing only parts of the screen. However, V2 is different: here
|
|
|
|
// the whole graphics are encoded as one big chunk. That makes it rather
|
|
|
|
// dificult to draw only parts of a room/object. We handle the V2 graphics
|
|
|
|
// differently from all other (newer) graphic formats for this reason.
|
|
|
|
//
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_vm->_version == 2) {
|
2003-05-10 12:59:32 +00:00
|
|
|
|
2004-01-06 11:47:34 +00:00
|
|
|
if (vs->hasTwoBuffers)
|
2004-01-04 13:49:03 +00:00
|
|
|
bgbak_ptr = vs->backBuf + (y * _numStrips + x) * 8;
|
2003-05-10 14:30:58 +00:00
|
|
|
else
|
2003-05-11 00:28:43 +00:00
|
|
|
bgbak_ptr = vs->screenPtr + (y * _numStrips + x) * 8;
|
2003-05-10 14:30:58 +00:00
|
|
|
|
2004-01-04 13:49:03 +00:00
|
|
|
mask_ptr = getMaskBuffer(x, y, 1);
|
2003-05-10 14:30:58 +00:00
|
|
|
|
2003-11-16 20:52:57 +00:00
|
|
|
const int left = (stripnr * 8);
|
|
|
|
const int right = left + (numstrip * 8);
|
2003-05-10 14:30:58 +00:00
|
|
|
byte *dst = bgbak_ptr;
|
2003-06-04 21:45:29 +00:00
|
|
|
const byte *src;
|
2003-06-05 00:18:15 +00:00
|
|
|
byte color, data = 0;
|
|
|
|
int run;
|
2003-05-10 14:30:58 +00:00
|
|
|
bool dither = false;
|
|
|
|
byte dither_table[128];
|
|
|
|
byte *ptr_dither_table;
|
|
|
|
memset(dither_table, 0, sizeof(dither_table));
|
2003-06-05 00:12:23 +00:00
|
|
|
int theX, theY, maxX;
|
2003-05-10 14:30:58 +00:00
|
|
|
|
2003-06-04 21:45:29 +00:00
|
|
|
if (table) {
|
2003-06-05 00:18:15 +00:00
|
|
|
run = table->run[stripnr];
|
|
|
|
color = table->color[stripnr];
|
2003-06-04 21:45:29 +00:00
|
|
|
src = smap_ptr + table->offsets[stripnr];
|
|
|
|
theX = left;
|
2003-06-05 00:12:23 +00:00
|
|
|
maxX = right;
|
2003-06-04 21:45:29 +00:00
|
|
|
} else {
|
2003-06-05 00:18:15 +00:00
|
|
|
run = 1;
|
|
|
|
color = 0;
|
2003-06-04 21:45:29 +00:00
|
|
|
src = smap_ptr;
|
|
|
|
theX = 0;
|
2003-06-05 00:12:23 +00:00
|
|
|
maxX = width;
|
2003-06-04 21:45:29 +00:00
|
|
|
}
|
|
|
|
|
2003-05-10 14:30:58 +00:00
|
|
|
// Draw image data. To do this, we decode the full RLE graphics data,
|
|
|
|
// but only draw those parts we actually want to display.
|
|
|
|
assert(height <= 128);
|
2003-06-05 00:12:23 +00:00
|
|
|
for (; theX < maxX; theX++) {
|
2003-05-10 14:30:58 +00:00
|
|
|
ptr_dither_table = dither_table;
|
|
|
|
for (theY = 0; theY < height; theY++) {
|
|
|
|
if (--run == 0) {
|
|
|
|
data = *src++;
|
|
|
|
if (data & 0x80) {
|
|
|
|
run = data & 0x7f;
|
|
|
|
dither = true;
|
|
|
|
} else {
|
|
|
|
run = data >> 4;
|
|
|
|
dither = false;
|
|
|
|
}
|
2003-10-13 12:56:53 +00:00
|
|
|
color = _roomPalette[data & 0x0f];
|
2003-05-10 14:30:58 +00:00
|
|
|
if (run == 0) {
|
|
|
|
run = *src++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!dither) {
|
|
|
|
*ptr_dither_table = color;
|
|
|
|
}
|
|
|
|
if (left <= theX && theX < right) {
|
|
|
|
*dst = *ptr_dither_table++;
|
2004-01-04 13:09:02 +00:00
|
|
|
dst += vs->width;
|
2003-05-10 14:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (left <= theX && theX < right) {
|
2003-06-05 23:55:57 +00:00
|
|
|
dst -= _vertStripNextInc;
|
2003-05-10 14:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-04 21:45:29 +00:00
|
|
|
|
2003-05-10 14:30:58 +00:00
|
|
|
// Draw mask (zplane) data
|
|
|
|
theY = 0;
|
2003-06-04 21:45:29 +00:00
|
|
|
|
|
|
|
if (table) {
|
|
|
|
src = smap_ptr + table->zoffsets[stripnr];
|
|
|
|
run = table->zrun[stripnr];
|
|
|
|
theX = left;
|
|
|
|
} else {
|
2003-05-10 14:30:58 +00:00
|
|
|
run = *src++;
|
2003-06-04 21:45:29 +00:00
|
|
|
theX = 0;
|
|
|
|
}
|
2003-06-05 00:12:23 +00:00
|
|
|
while (theX < right) {
|
2003-06-05 23:55:57 +00:00
|
|
|
const byte runFlag = run & 0x80;
|
|
|
|
if (runFlag) {
|
2003-05-10 14:30:58 +00:00
|
|
|
run &= 0x7f;
|
|
|
|
data = *src++;
|
2003-06-05 23:55:57 +00:00
|
|
|
}
|
|
|
|
do {
|
|
|
|
if (!runFlag)
|
2003-05-10 14:30:58 +00:00
|
|
|
data = *src++;
|
2003-06-05 23:55:57 +00:00
|
|
|
|
|
|
|
if (left <= theX) {
|
|
|
|
*mask_ptr = data;
|
|
|
|
mask_ptr += _numStrips;
|
|
|
|
}
|
|
|
|
theY++;
|
|
|
|
if (theY >= height) {
|
2003-06-05 00:12:23 +00:00
|
|
|
if (left <= theX) {
|
2003-06-05 23:55:57 +00:00
|
|
|
mask_ptr -= _numStrips * height - 1;
|
2003-05-10 14:30:58 +00:00
|
|
|
}
|
2003-06-05 23:55:57 +00:00
|
|
|
theY = 0;
|
|
|
|
theX += 8;
|
|
|
|
if (theX >= right)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (--run);
|
2003-06-04 21:45:29 +00:00
|
|
|
run = *src++;
|
2003-05-10 14:30:58 +00:00
|
|
|
}
|
2003-05-10 12:59:32 +00:00
|
|
|
}
|
2003-05-10 14:30:58 +00:00
|
|
|
|
2003-05-10 12:59:32 +00:00
|
|
|
while (numstrip--) {
|
2002-04-17 16:02:29 +00:00
|
|
|
CHECK_HEAP;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-10-27 15:16:49 +00:00
|
|
|
if (sx < 0)
|
|
|
|
goto next_iter;
|
|
|
|
|
2002-10-24 06:28:54 +00:00
|
|
|
if (sx >= _numStrips)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
if (y < vs->tdirty[sx])
|
2002-04-11 17:19:16 +00:00
|
|
|
vs->tdirty[sx] = y;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
if (bottom > vs->bdirty[sx])
|
|
|
|
vs->bdirty[sx] = bottom;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-16 01:25:21 +00:00
|
|
|
backbuff_ptr = vs->screenPtr + (y * _numStrips + x) * 8;
|
2004-01-06 11:47:34 +00:00
|
|
|
if (vs->hasTwoBuffers)
|
2004-01-04 13:49:03 +00:00
|
|
|
bgbak_ptr = vs->backBuf + (y * _numStrips + x) * 8;
|
2002-08-20 02:20:40 +00:00
|
|
|
else
|
2002-12-16 01:25:21 +00:00
|
|
|
bgbak_ptr = backbuff_ptr;
|
2002-08-20 02:20:40 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_vm->_version == 1) {
|
2003-06-06 05:27:45 +00:00
|
|
|
if (_C64ObjectMode)
|
|
|
|
drawStripC64Object(bgbak_ptr, stripnr, width, height);
|
|
|
|
else
|
|
|
|
drawStripC64Background(bgbak_ptr, stripnr, height);
|
2003-06-07 00:13:26 +00:00
|
|
|
} else if (_vm->_version > 2) {
|
2003-05-10 17:09:21 +00:00
|
|
|
if (_vm->_features & GF_16COLOR) {
|
|
|
|
decodeStripEGA(bgbak_ptr, smap_ptr + READ_LE_UINT16(smap_ptr + stripnr * 2 + 2), height);
|
|
|
|
} else if (_vm->_features & GF_SMALL_HEADER) {
|
|
|
|
useOrDecompress = decompressBitmap(bgbak_ptr, smap_ptr + READ_LE_UINT32(smap_ptr + stripnr * 4 + 4), height);
|
|
|
|
} else {
|
|
|
|
useOrDecompress = decompressBitmap(bgbak_ptr, smap_ptr + READ_LE_UINT32(smap_ptr + stripnr * 4 + 8), height);
|
|
|
|
}
|
2003-04-09 19:14:05 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2004-01-04 13:49:03 +00:00
|
|
|
mask_ptr = getMaskBuffer(x, y);
|
2003-05-11 11:13:24 +00:00
|
|
|
|
2002-04-17 16:02:29 +00:00
|
|
|
CHECK_HEAP;
|
2004-01-06 11:47:34 +00:00
|
|
|
if (vs->hasTwoBuffers) {
|
2004-01-08 21:21:40 +00:00
|
|
|
if (_vm->_charset->hasCharsetMask(sx * 8, y, (sx + 1) * 8, bottom)) {
|
2002-08-20 02:20:40 +00:00
|
|
|
if (flag & dbClear || !lightsOn)
|
2003-05-11 00:28:43 +00:00
|
|
|
clear8ColWithMasking(backbuff_ptr, height, mask_ptr);
|
2001-10-09 14:30:12 +00:00
|
|
|
else
|
2003-05-11 00:28:43 +00:00
|
|
|
draw8ColWithMasking(backbuff_ptr, bgbak_ptr, height, mask_ptr);
|
2001-11-26 19:57:57 +00:00
|
|
|
} else {
|
2002-08-20 02:20:40 +00:00
|
|
|
if (flag & dbClear || !lightsOn)
|
2003-05-10 12:59:32 +00:00
|
|
|
clear8Col(backbuff_ptr, height);
|
2001-11-26 19:57:57 +00:00
|
|
|
else
|
2003-05-10 12:59:32 +00:00
|
|
|
draw8Col(backbuff_ptr, bgbak_ptr, height);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-17 16:02:29 +00:00
|
|
|
CHECK_HEAP;
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_vm->_version == 1) {
|
2004-01-04 13:49:03 +00:00
|
|
|
mask_ptr = getMaskBuffer(x, y, 1);
|
2003-08-25 14:27:29 +00:00
|
|
|
drawStripC64Mask(mask_ptr, stripnr, width, height);
|
2003-06-07 00:13:26 +00:00
|
|
|
} else if (_vm->_version == 2) {
|
2003-05-10 17:09:21 +00:00
|
|
|
// Do nothing here for V2 games - zplane was handled already.
|
|
|
|
} else if (flag & dbDrawMaskOnAll) {
|
|
|
|
// Sam & Max uses dbDrawMaskOnAll for things like the inventory
|
|
|
|
// box and the speech icons. While these objects only have one
|
|
|
|
// mask, it should be applied to all the Z-planes in the room,
|
|
|
|
// i.e. they should mask every actor.
|
|
|
|
//
|
|
|
|
// This flag used to be called dbDrawMaskOnBoth, and all it
|
|
|
|
// would do was to mask Z-plane 0. (Z-plane 1 would also be
|
|
|
|
// masked, because what is now the else-clause used to be run
|
|
|
|
// always.) While this seems to be the only way there is to
|
|
|
|
// mask Z-plane 0, this wasn't good enough since actors in
|
|
|
|
// Z-planes >= 2 would not be masked.
|
|
|
|
//
|
|
|
|
// The flag is also used by The Dig and Full Throttle, but I
|
|
|
|
// don't know what for. At the time of writing, these games
|
|
|
|
// are still too unstable for me to investigate.
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_vm->_version == 8)
|
2002-12-30 13:15:08 +00:00
|
|
|
z_plane_ptr = zplane_list[1] + READ_LE_UINT32(zplane_list[1] + stripnr * 4 + 8);
|
|
|
|
else
|
|
|
|
z_plane_ptr = zplane_list[1] + READ_LE_UINT16(zplane_list[1] + stripnr * 2 + 8);
|
2002-09-29 15:20:02 +00:00
|
|
|
for (i = 0; i < numzbuf; i++) {
|
2004-01-04 13:49:03 +00:00
|
|
|
mask_ptr = getMaskBuffer(x, y, i);
|
2002-12-31 14:59:06 +00:00
|
|
|
if (useOrDecompress && (flag & dbAllowMaskOr))
|
2003-05-11 00:28:43 +00:00
|
|
|
decompressMaskImgOr(mask_ptr, z_plane_ptr, height);
|
2002-04-17 16:02:29 +00:00
|
|
|
else
|
2003-05-11 00:28:43 +00:00
|
|
|
decompressMaskImg(mask_ptr, z_plane_ptr, height);
|
2002-09-29 15:20:02 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 1; i < numzbuf; i++) {
|
2003-09-27 20:31:19 +00:00
|
|
|
uint32 offs;
|
2002-09-29 15:20:02 +00:00
|
|
|
|
|
|
|
if (!zplane_list[i])
|
|
|
|
continue;
|
|
|
|
|
2003-05-10 18:33:04 +00:00
|
|
|
if (_vm->_features & GF_OLD_BUNDLE)
|
2003-04-24 18:53:21 +00:00
|
|
|
offs = READ_LE_UINT16(zplane_list[i] + stripnr * 2);
|
|
|
|
else if (_vm->_features & GF_OLD256)
|
2002-12-30 14:04:46 +00:00
|
|
|
offs = READ_LE_UINT16(zplane_list[i] + stripnr * 2 + 4);
|
|
|
|
else if (_vm->_features & GF_SMALL_HEADER)
|
|
|
|
offs = READ_LE_UINT16(zplane_list[i] + stripnr * 2 + 2);
|
2003-06-07 00:13:26 +00:00
|
|
|
else if (_vm->_version == 8)
|
2003-09-27 20:31:19 +00:00
|
|
|
offs = READ_LE_UINT32(zplane_list[i] + stripnr * 4 + 8);
|
2002-12-30 13:15:08 +00:00
|
|
|
else
|
2002-09-29 15:20:02 +00:00
|
|
|
offs = READ_LE_UINT16(zplane_list[i] + stripnr * 2 + 8);
|
|
|
|
|
2004-01-04 13:49:03 +00:00
|
|
|
mask_ptr = getMaskBuffer(x, y, i);
|
2002-09-29 15:20:02 +00:00
|
|
|
|
|
|
|
if (offs) {
|
2003-05-28 20:01:47 +00:00
|
|
|
z_plane_ptr = zplane_list[i] + offs;
|
2002-09-29 15:20:02 +00:00
|
|
|
|
2003-05-10 17:09:21 +00:00
|
|
|
if (useOrDecompress && (flag & dbAllowMaskOr)) {
|
2003-05-11 00:28:43 +00:00
|
|
|
decompressMaskImgOr(mask_ptr, z_plane_ptr, height);
|
2002-12-31 04:19:46 +00:00
|
|
|
} else {
|
2003-05-11 00:28:43 +00:00
|
|
|
decompressMaskImg(mask_ptr, z_plane_ptr, height);
|
2002-12-31 04:19:46 +00:00
|
|
|
}
|
2002-12-31 16:44:55 +00:00
|
|
|
|
2002-09-29 15:20:02 +00:00
|
|
|
} else {
|
2002-12-31 14:59:06 +00:00
|
|
|
if (!(useOrDecompress && (flag & dbAllowMaskOr)))
|
2003-05-10 12:59:32 +00:00
|
|
|
for (int h = 0; h < height; h++)
|
2003-05-11 00:28:43 +00:00
|
|
|
mask_ptr[h * _numStrips] = 0;
|
2003-05-10 12:59:32 +00:00
|
|
|
// FIXME: needs better abstraction
|
2002-09-29 15:20:02 +00:00
|
|
|
}
|
2002-04-17 16:02:29 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2003-05-12 20:33:47 +00:00
|
|
|
|
2003-08-18 20:32:51 +00:00
|
|
|
#if 0
|
2003-05-12 20:33:47 +00:00
|
|
|
// HACK: blit mask(s) onto normal screen. Useful to debug masking
|
|
|
|
for (i = 0; i < numzbuf; i++) {
|
2004-01-04 13:49:03 +00:00
|
|
|
mask_ptr = getMaskBuffer(x, y, i);
|
2003-05-12 20:33:47 +00:00
|
|
|
byte *dst = backbuff_ptr;
|
|
|
|
byte *dst2 = bgbak_ptr;
|
|
|
|
for (int h = 0; h < height; h++) {
|
|
|
|
int maskbits = *mask_ptr;
|
|
|
|
for (int j = 0; j < 8; j++) {
|
|
|
|
if (maskbits & 0x80)
|
|
|
|
dst[j] = dst2[j] = 12+i;
|
|
|
|
maskbits <<= 1;
|
|
|
|
}
|
2004-01-04 13:09:02 +00:00
|
|
|
dst += vs->width;
|
|
|
|
dst2 += vs->width;
|
2003-05-12 20:33:47 +00:00
|
|
|
mask_ptr += _numStrips;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2002-10-27 15:16:49 +00:00
|
|
|
|
|
|
|
next_iter:
|
2002-04-17 16:02:29 +00:00
|
|
|
CHECK_HEAP;
|
|
|
|
x++;
|
2003-05-10 12:23:02 +00:00
|
|
|
sx++;
|
2001-10-26 17:34:50 +00:00
|
|
|
stripnr++;
|
2003-05-10 12:59:32 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2004-01-04 14:35:46 +00:00
|
|
|
/**
|
|
|
|
* Reset the background behind an actor or blast object.
|
|
|
|
*/
|
|
|
|
void Gdi::resetBackground(int top, int bottom, int strip) {
|
|
|
|
VirtScreen *vs = &_vm->virtscr[0];
|
|
|
|
byte *backbuff_ptr, *bgbak_ptr;
|
|
|
|
int offs, numLinesToProcess;
|
|
|
|
|
|
|
|
assert(0 <= strip && strip < _numStrips);
|
|
|
|
|
|
|
|
if (top < vs->tdirty[strip])
|
|
|
|
vs->tdirty[strip] = top;
|
|
|
|
|
|
|
|
if (bottom > vs->bdirty[strip])
|
|
|
|
vs->bdirty[strip] = bottom;
|
|
|
|
|
2004-01-08 00:48:37 +00:00
|
|
|
offs = top * vs->width + vs->xstart + strip * 8;
|
2004-01-04 14:35:46 +00:00
|
|
|
byte *mask_ptr = _vm->getMaskBuffer(strip * 8, top, 0);
|
|
|
|
bgbak_ptr = vs->backBuf + offs;
|
|
|
|
backbuff_ptr = vs->screenPtr + offs;
|
|
|
|
|
|
|
|
numLinesToProcess = bottom - top;
|
|
|
|
if (numLinesToProcess) {
|
2004-01-08 21:21:40 +00:00
|
|
|
if (_vm->isLightOn()) {
|
|
|
|
if (_vm->_charset->hasCharsetMask(strip * 8, top, (strip + 1) * 8, bottom))
|
2004-01-04 14:35:46 +00:00
|
|
|
draw8ColWithMasking(backbuff_ptr, bgbak_ptr, numLinesToProcess, mask_ptr);
|
|
|
|
else
|
|
|
|
draw8Col(backbuff_ptr, bgbak_ptr, numLinesToProcess);
|
|
|
|
} else {
|
|
|
|
clear8Col(backbuff_ptr, numLinesToProcess);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-04 21:45:29 +00:00
|
|
|
/**
|
|
|
|
* Create and fill a table with offsets to the graphic and mask strips in the
|
|
|
|
* given V2 EGA bitmap.
|
|
|
|
* @param src the V2 EGA bitmap
|
|
|
|
* @param width the width of the bitmap
|
|
|
|
* @param height the height of the bitmap
|
|
|
|
* @param table the strip table to fill
|
|
|
|
* @return filled strip table
|
|
|
|
*/
|
|
|
|
StripTable *Gdi::generateStripTable(const byte *src, int width, int height, StripTable *table) {
|
|
|
|
|
|
|
|
// If no strip table was given to use, allocate a new one
|
|
|
|
if (table == 0)
|
|
|
|
table = (StripTable *)calloc(1, sizeof(StripTable));
|
|
|
|
|
|
|
|
const byte *bitmapStart = src;
|
|
|
|
byte color = 0, data = 0;
|
|
|
|
int x, y, length = 0;
|
|
|
|
byte run = 1;
|
|
|
|
|
2003-08-25 20:18:44 +00:00
|
|
|
// Decode the graphics strips, and memorize the run/color values
|
|
|
|
// as well as the byte offset.
|
2003-06-04 21:45:29 +00:00
|
|
|
for (x = 0 ; x < width; x++) {
|
|
|
|
|
|
|
|
if ((x % 8) == 0) {
|
2003-11-08 21:59:32 +00:00
|
|
|
assert(x / 8 < 160);
|
|
|
|
table->run[x / 8] = run;
|
|
|
|
table->color[x / 8] = color;
|
|
|
|
table->offsets[x / 8] = src - bitmapStart;
|
2003-06-04 21:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
if (--run == 0) {
|
|
|
|
data = *src++;
|
|
|
|
if (data & 0x80) {
|
|
|
|
run = data & 0x7f;
|
|
|
|
} else {
|
|
|
|
run = data >> 4;
|
|
|
|
}
|
|
|
|
if (run == 0) {
|
|
|
|
run = *src++;
|
|
|
|
}
|
|
|
|
color = data & 0x0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-25 20:18:44 +00:00
|
|
|
// The mask data follows immediately after the graphics.
|
2003-06-04 21:45:29 +00:00
|
|
|
x = 0;
|
|
|
|
y = height;
|
|
|
|
width /= 8;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
length = *src++;
|
2003-06-05 23:55:57 +00:00
|
|
|
const byte runFlag = length & 0x80;
|
|
|
|
if (runFlag) {
|
2003-06-04 21:45:29 +00:00
|
|
|
length &= 0x7f;
|
|
|
|
data = *src++;
|
|
|
|
}
|
2003-06-05 23:55:57 +00:00
|
|
|
do {
|
|
|
|
if (!runFlag)
|
|
|
|
data = *src++;
|
|
|
|
if (y == height) {
|
|
|
|
assert(x < 120);
|
|
|
|
table->zoffsets[x] = src - bitmapStart - 1;
|
|
|
|
table->zrun[x] = length | runFlag;
|
|
|
|
}
|
|
|
|
if (--y == 0) {
|
|
|
|
if (--width == 0)
|
|
|
|
return table;
|
|
|
|
x++;
|
|
|
|
y = height;
|
|
|
|
}
|
|
|
|
} while (--length);
|
2003-06-04 21:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2003-06-05 17:22:15 +00:00
|
|
|
void Gdi::drawStripC64Background(byte *dst, int stripnr, int height) {
|
2003-08-25 14:27:29 +00:00
|
|
|
int charIdx;
|
2003-11-16 20:52:57 +00:00
|
|
|
height /= 8;
|
2003-06-06 20:55:39 +00:00
|
|
|
for (int y = 0; y < height; y++) {
|
2003-06-06 00:16:34 +00:00
|
|
|
_C64Colors[3] = (_C64ColorMap[y + stripnr * height] & 7);
|
2003-08-29 06:46:12 +00:00
|
|
|
// Check for room color change in V1 zak
|
2003-10-13 12:56:53 +00:00
|
|
|
if (_roomPalette[0] == 255) {
|
|
|
|
_C64Colors[2] = _roomPalette[2];
|
|
|
|
_C64Colors[1] = _roomPalette[1];
|
2003-08-26 15:56:37 +00:00
|
|
|
}
|
2003-08-29 06:46:12 +00:00
|
|
|
|
2003-08-25 14:27:29 +00:00
|
|
|
charIdx = _C64PicMap[y + stripnr * height] * 8;
|
2003-06-06 20:55:39 +00:00
|
|
|
for (int i = 0; i < 8; i++) {
|
2003-08-25 14:27:29 +00:00
|
|
|
byte c = _C64CharMap[charIdx + i];
|
2003-06-06 20:55:39 +00:00
|
|
|
dst[0] = dst[1] = _C64Colors[(c >> 6) & 3];
|
|
|
|
dst[2] = dst[3] = _C64Colors[(c >> 4) & 3];
|
|
|
|
dst[4] = dst[5] = _C64Colors[(c >> 2) & 3];
|
|
|
|
dst[6] = dst[7] = _C64Colors[(c >> 0) & 3];
|
2003-06-06 00:16:34 +00:00
|
|
|
dst += _vm->_screenWidth;
|
2003-06-05 17:22:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-06 05:27:45 +00:00
|
|
|
void Gdi::drawStripC64Object(byte *dst, int stripnr, int width, int height) {
|
2003-08-25 14:27:29 +00:00
|
|
|
int charIdx;
|
2003-11-16 20:52:57 +00:00
|
|
|
height /= 8;
|
|
|
|
width /= 8;
|
2003-06-06 20:55:39 +00:00
|
|
|
for (int y = 0; y < height; y++) {
|
2003-08-25 14:27:29 +00:00
|
|
|
_C64Colors[3] = (_C64ObjectMap[(y + height) * width + stripnr] & 7);
|
|
|
|
charIdx = _C64ObjectMap[y * width + stripnr] * 8;
|
2003-06-06 20:55:39 +00:00
|
|
|
for (int i = 0; i < 8; i++) {
|
2003-08-25 14:27:29 +00:00
|
|
|
byte c = _C64CharMap[charIdx + i];
|
2003-06-06 20:55:39 +00:00
|
|
|
dst[0] = dst[1] = _C64Colors[(c >> 6) & 3];
|
|
|
|
dst[2] = dst[3] = _C64Colors[(c >> 4) & 3];
|
|
|
|
dst[4] = dst[5] = _C64Colors[(c >> 2) & 3];
|
|
|
|
dst[6] = dst[7] = _C64Colors[(c >> 0) & 3];
|
2003-06-06 05:27:45 +00:00
|
|
|
dst += _vm->_screenWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-25 14:27:29 +00:00
|
|
|
void Gdi::drawStripC64Mask(byte *dst, int stripnr, int width, int height) {
|
|
|
|
int maskIdx;
|
2003-11-16 20:52:57 +00:00
|
|
|
height /= 8;
|
|
|
|
width /= 8;
|
2003-06-06 20:55:39 +00:00
|
|
|
for (int y = 0; y < height; y++) {
|
2003-08-25 14:27:29 +00:00
|
|
|
if (_C64ObjectMode)
|
|
|
|
maskIdx = _C64ObjectMap[(y + 2 * height) * width + stripnr] * 8;
|
|
|
|
else
|
|
|
|
maskIdx = _C64MaskMap[y + stripnr * height] * 8;
|
2003-06-06 20:55:39 +00:00
|
|
|
for (int i = 0; i < 8; i++) {
|
2003-08-25 14:27:29 +00:00
|
|
|
byte c = _C64MaskChar[maskIdx + i];
|
|
|
|
|
2003-08-25 20:18:44 +00:00
|
|
|
// V1/C64 masks are inverted compared to what ScummVM expects
|
|
|
|
*dst = c ^ 0xFF;
|
2003-08-18 15:10:22 +00:00
|
|
|
dst += _numStrips;
|
2003-06-05 17:22:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-06 05:27:45 +00:00
|
|
|
void Gdi::decodeC64Gfx(const byte *src, byte *dst, int size) {
|
2003-06-05 17:22:15 +00:00
|
|
|
int x, z;
|
|
|
|
byte color, run, common[4];
|
|
|
|
|
2003-06-07 00:49:36 +00:00
|
|
|
for (z = 0; z < 4; z++) {
|
2003-06-05 17:22:15 +00:00
|
|
|
common[z] = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = 0;
|
2003-08-25 20:18:44 +00:00
|
|
|
while (x < size) {
|
|
|
|
run = *src++;
|
|
|
|
if (run & 0x80) {
|
|
|
|
color = common[(run >> 5) & 3];
|
|
|
|
run &= 0x1F;
|
|
|
|
for (z = 0; z <= run; z++) {
|
|
|
|
dst[x++] = color;
|
2003-06-05 17:22:15 +00:00
|
|
|
}
|
2003-08-25 20:18:44 +00:00
|
|
|
} else if (run & 0x40) {
|
|
|
|
run &= 0x3F;
|
|
|
|
color = *src++;
|
|
|
|
for (z = 0; z <= run; z++) {
|
|
|
|
dst[x++] = color;
|
2003-06-05 17:22:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-08-25 20:18:44 +00:00
|
|
|
for (z = 0; z <= run; z++) {
|
|
|
|
dst[x++] = *src++;
|
2003-06-05 17:22:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-06-04 21:45:29 +00:00
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::decodeStripEGA(byte *dst, const byte *src, int height) {
|
2003-04-10 11:34:51 +00:00
|
|
|
byte color = 0;
|
2003-04-12 11:44:15 +00:00
|
|
|
int run = 0, x = 0, y = 0, z;
|
2003-04-10 11:34:51 +00:00
|
|
|
|
2003-06-07 00:49:36 +00:00
|
|
|
while (x < 8) {
|
2003-04-10 11:34:51 +00:00
|
|
|
color = *src++;
|
|
|
|
|
2003-06-07 00:49:36 +00:00
|
|
|
if (color & 0x80) {
|
2003-04-10 11:34:51 +00:00
|
|
|
run = color & 0x3f;
|
|
|
|
|
2003-06-07 00:49:36 +00:00
|
|
|
if (color & 0x40) {
|
2003-04-10 11:34:51 +00:00
|
|
|
color = *src++;
|
|
|
|
|
2003-06-07 00:49:36 +00:00
|
|
|
if (run == 0) {
|
2003-04-10 11:34:51 +00:00
|
|
|
run = *src++;
|
|
|
|
}
|
2003-06-07 00:49:36 +00:00
|
|
|
for (z = 0; z < run; z++) {
|
2003-11-16 20:52:57 +00:00
|
|
|
*(dst + y * _vm->_screenWidth + x) = (z & 1) ? _roomPalette[color & 0xf] : _roomPalette[color >> 4];
|
2003-04-10 11:34:51 +00:00
|
|
|
|
|
|
|
y++;
|
2003-06-07 00:49:36 +00:00
|
|
|
if (y >= height) {
|
2003-04-10 11:34:51 +00:00
|
|
|
y = 0;
|
|
|
|
x++;
|
2003-04-09 19:14:05 +00:00
|
|
|
}
|
|
|
|
}
|
2003-04-12 11:44:15 +00:00
|
|
|
} else {
|
2003-06-07 00:49:36 +00:00
|
|
|
if (run == 0) {
|
2003-04-09 19:14:05 +00:00
|
|
|
run = *src++;
|
|
|
|
}
|
2003-04-10 11:34:51 +00:00
|
|
|
|
2003-06-07 00:49:36 +00:00
|
|
|
for (z = 0; z < run; z++) {
|
2003-05-10 21:49:59 +00:00
|
|
|
*(dst + y * _vm->_screenWidth + x) = *(dst + y * _vm->_screenWidth + x - 1);
|
2003-04-12 11:44:15 +00:00
|
|
|
|
2003-04-10 11:34:51 +00:00
|
|
|
y++;
|
2003-06-07 00:49:36 +00:00
|
|
|
if (y >= height) {
|
2003-04-10 11:34:51 +00:00
|
|
|
y = 0;
|
|
|
|
x++;
|
|
|
|
}
|
2003-04-12 11:44:15 +00:00
|
|
|
}
|
2003-04-09 19:14:05 +00:00
|
|
|
}
|
2003-04-12 11:44:15 +00:00
|
|
|
} else {
|
2003-04-10 11:34:51 +00:00
|
|
|
run = color >> 4;
|
2003-06-07 00:49:36 +00:00
|
|
|
if (run == 0) {
|
2003-04-10 11:34:51 +00:00
|
|
|
run = *src++;
|
|
|
|
}
|
|
|
|
|
2003-06-07 00:49:36 +00:00
|
|
|
for (z = 0; z < run; z++) {
|
2003-10-13 12:56:53 +00:00
|
|
|
*(dst + y * _vm->_screenWidth + x) = _roomPalette[color & 0xf];
|
2003-04-10 11:34:51 +00:00
|
|
|
|
2003-04-12 11:44:15 +00:00
|
|
|
y++;
|
2003-06-07 00:49:36 +00:00
|
|
|
if (y >= height) {
|
2003-04-10 11:34:51 +00:00
|
|
|
y = 0;
|
|
|
|
x++;
|
|
|
|
}
|
2003-04-09 19:14:05 +00:00
|
|
|
}
|
2003-04-10 11:34:51 +00:00
|
|
|
}
|
2003-04-09 19:14:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
bool Gdi::decompressBitmap(byte *bgbak_ptr, const byte *src, int numLinesToProcess) {
|
2003-04-30 05:48:55 +00:00
|
|
|
assert(numLinesToProcess);
|
2003-04-09 19:14:05 +00:00
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
byte code = *src++;
|
2003-04-10 11:34:51 +00:00
|
|
|
|
2002-12-31 14:59:06 +00:00
|
|
|
bool useOrDecompress = false;
|
2002-12-31 04:19:46 +00:00
|
|
|
_decomp_shr = code % 10;
|
|
|
|
_decomp_mask = 0xFF >> (8 - _decomp_shr);
|
2002-12-31 04:36:14 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (code) {
|
2001-10-09 14:30:12 +00:00
|
|
|
case 1:
|
2003-05-28 20:01:47 +00:00
|
|
|
unkDecode7(bgbak_ptr, src, numLinesToProcess);
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
2002-02-12 18:20:37 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
case 2:
|
2003-05-28 20:01:47 +00:00
|
|
|
unkDecode8(bgbak_ptr, src, numLinesToProcess); /* Ender - Zak256/Indy256 */
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
2002-02-12 18:20:37 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
case 3:
|
2003-05-28 20:01:47 +00:00
|
|
|
unkDecode9(bgbak_ptr, src, numLinesToProcess); /* Ender - Zak256/Indy256 */
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2003-05-28 20:01:47 +00:00
|
|
|
unkDecode10(bgbak_ptr, src, numLinesToProcess); /* Ender - Zak256/Indy256 */
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
2002-02-12 18:20:37 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
case 7:
|
2003-05-28 20:01:47 +00:00
|
|
|
unkDecode11(bgbak_ptr, src, numLinesToProcess); /* Ender - Zak256/Indy256 */
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
2004-02-24 04:45:50 +00:00
|
|
|
|
2003-06-25 03:24:02 +00:00
|
|
|
// 8/9 used in 3do version of puttputt joins the parade maybe others
|
|
|
|
case 8:
|
2004-02-24 04:51:02 +00:00
|
|
|
useOrDecompress = true;
|
2004-02-24 04:45:50 +00:00
|
|
|
unkDecode12(bgbak_ptr, src, numLinesToProcess);
|
|
|
|
break;
|
|
|
|
|
2003-06-25 03:24:02 +00:00
|
|
|
case 9:
|
2004-02-24 04:45:50 +00:00
|
|
|
unkDecode13(bgbak_ptr, src, numLinesToProcess);
|
|
|
|
break;
|
|
|
|
|
2003-06-25 03:24:02 +00:00
|
|
|
// used in amiga version of Monkey Island
|
|
|
|
case 10:
|
2003-07-06 06:19:52 +00:00
|
|
|
decodeStripEGA(bgbak_ptr, src, numLinesToProcess);
|
2003-06-25 03:24:02 +00:00
|
|
|
break;
|
2002-02-12 18:20:37 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
case 14:
|
|
|
|
case 15:
|
|
|
|
case 16:
|
|
|
|
case 17:
|
|
|
|
case 18:
|
2003-05-28 20:01:47 +00:00
|
|
|
unkDecodeC(bgbak_ptr, src, numLinesToProcess);
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
case 24:
|
|
|
|
case 25:
|
|
|
|
case 26:
|
|
|
|
case 27:
|
|
|
|
case 28:
|
2003-05-28 20:01:47 +00:00
|
|
|
unkDecodeB(bgbak_ptr, src, numLinesToProcess);
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
case 34:
|
|
|
|
case 35:
|
|
|
|
case 36:
|
|
|
|
case 37:
|
|
|
|
case 38:
|
2002-12-31 14:59:06 +00:00
|
|
|
useOrDecompress = true;
|
2003-05-28 20:01:47 +00:00
|
|
|
unkDecodeC_trans(bgbak_ptr, src, numLinesToProcess);
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
case 44:
|
|
|
|
case 45:
|
|
|
|
case 46:
|
|
|
|
case 47:
|
|
|
|
case 48:
|
2002-12-31 14:59:06 +00:00
|
|
|
useOrDecompress = true;
|
2003-05-28 20:01:47 +00:00
|
|
|
unkDecodeB_trans(bgbak_ptr, src, numLinesToProcess);
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
case 64:
|
|
|
|
case 65:
|
|
|
|
case 66:
|
|
|
|
case 67:
|
|
|
|
case 68:
|
|
|
|
case 104:
|
|
|
|
case 105:
|
|
|
|
case 106:
|
|
|
|
case 107:
|
|
|
|
case 108:
|
2003-05-28 20:01:47 +00:00
|
|
|
unkDecodeA(bgbak_ptr, src, numLinesToProcess);
|
2001-10-16 10:01:48 +00:00
|
|
|
break;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-31 04:36:14 +00:00
|
|
|
case 84:
|
|
|
|
case 85:
|
|
|
|
case 86:
|
|
|
|
case 87:
|
|
|
|
case 88:
|
2002-04-11 17:19:16 +00:00
|
|
|
case 124:
|
|
|
|
case 125:
|
|
|
|
case 126:
|
|
|
|
case 127:
|
|
|
|
case 128:
|
2002-12-31 14:59:06 +00:00
|
|
|
useOrDecompress = true;
|
2003-05-28 20:01:47 +00:00
|
|
|
unkDecodeA_trans(bgbak_ptr, src, numLinesToProcess);
|
2001-10-16 10:01:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-10-26 17:34:50 +00:00
|
|
|
error("Gdi::decompressBitmap: default case %d", code);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-12-31 14:59:06 +00:00
|
|
|
|
|
|
|
return useOrDecompress;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::draw8ColWithMasking(byte *dst, const byte *src, int height, byte *mask) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte maskbits;
|
|
|
|
|
|
|
|
do {
|
|
|
|
maskbits = *mask;
|
|
|
|
if (maskbits) {
|
2004-04-08 23:43:30 +00:00
|
|
|
copy8PixelsWithMasking(dst, src, maskbits);
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2002-11-27 22:45:36 +00:00
|
|
|
#if defined(SCUMM_NEED_ALIGNMENT)
|
2002-12-04 13:36:27 +00:00
|
|
|
memcpy(dst, src, 8);
|
2002-11-27 22:45:36 +00:00
|
|
|
#else
|
2003-05-26 13:14:57 +00:00
|
|
|
((uint32 *)dst)[0] = ((const uint32 *)src)[0];
|
|
|
|
((uint32 *)dst)[1] = ((const uint32 *)src)[1];
|
2002-11-27 22:45:36 +00:00
|
|
|
#endif
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2003-05-10 21:49:59 +00:00
|
|
|
src += _vm->_screenWidth;
|
|
|
|
dst += _vm->_screenWidth;
|
2002-10-24 06:28:54 +00:00
|
|
|
mask += _numStrips;
|
2001-10-09 14:30:12 +00:00
|
|
|
} while (--height);
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Gdi::clear8ColWithMasking(byte *dst, int height, byte *mask) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte maskbits;
|
|
|
|
|
|
|
|
do {
|
|
|
|
maskbits = *mask;
|
2002-08-20 02:20:40 +00:00
|
|
|
if (maskbits) {
|
2004-04-08 23:43:30 +00:00
|
|
|
clear8PixelsWithMasking(dst, 0, maskbits);
|
2002-08-20 02:20:40 +00:00
|
|
|
} else {
|
2002-11-27 22:45:36 +00:00
|
|
|
#if defined(SCUMM_NEED_ALIGNMENT)
|
2002-12-04 13:36:27 +00:00
|
|
|
memset(dst, 0, 8);
|
2002-11-27 22:45:36 +00:00
|
|
|
#else
|
2002-08-20 02:20:40 +00:00
|
|
|
((uint32 *)dst)[0] = 0;
|
|
|
|
((uint32 *)dst)[1] = 0;
|
2002-11-27 22:45:36 +00:00
|
|
|
#endif
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth;
|
2002-12-15 23:40:37 +00:00
|
|
|
mask += _numStrips;
|
2001-10-09 14:30:12 +00:00
|
|
|
} while (--height);
|
|
|
|
}
|
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::draw8Col(byte *dst, const byte *src, int height) {
|
2002-12-04 13:36:27 +00:00
|
|
|
do {
|
|
|
|
#if defined(SCUMM_NEED_ALIGNMENT)
|
|
|
|
memcpy(dst, src, 8);
|
|
|
|
#else
|
2003-05-26 13:14:57 +00:00
|
|
|
((uint32 *)dst)[0] = ((const uint32 *)src)[0];
|
|
|
|
((uint32 *)dst)[1] = ((const uint32 *)src)[1];
|
2002-12-04 13:36:27 +00:00
|
|
|
#endif
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth;
|
|
|
|
src += _vm->_screenWidth;
|
2002-12-04 13:36:27 +00:00
|
|
|
} while (--height);
|
|
|
|
}
|
2004-04-04 20:20:09 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
void Gdi::clear8Col(byte *dst, int height)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
#if defined(SCUMM_NEED_ALIGNMENT)
|
|
|
|
memset(dst, 0, 8);
|
|
|
|
#else
|
|
|
|
((uint32 *)dst)[0] = 0;
|
|
|
|
((uint32 *)dst)[1] = 0;
|
|
|
|
#endif
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth;
|
2002-12-15 23:40:37 +00:00
|
|
|
} while (--height);
|
|
|
|
}
|
2002-12-04 13:36:27 +00:00
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::decompressMaskImg(byte *dst, const byte *src, int height) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte b, c;
|
2002-12-31 16:44:55 +00:00
|
|
|
|
|
|
|
while (height) {
|
2001-10-09 14:30:12 +00:00
|
|
|
b = *src++;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (b & 0x80) {
|
|
|
|
b &= 0x7F;
|
2001-10-09 14:30:12 +00:00
|
|
|
c = *src++;
|
|
|
|
|
|
|
|
do {
|
|
|
|
*dst = c;
|
2002-10-24 06:28:54 +00:00
|
|
|
dst += _numStrips;
|
2002-12-31 16:44:55 +00:00
|
|
|
--height;
|
|
|
|
} while (--b && height);
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
*dst = *src++;
|
2002-10-24 06:28:54 +00:00
|
|
|
dst += _numStrips;
|
2002-12-31 16:44:55 +00:00
|
|
|
--height;
|
|
|
|
} while (--b && height);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::decompressMaskImgOr(byte *dst, const byte *src, int height) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte b, c;
|
|
|
|
|
2002-12-31 16:44:55 +00:00
|
|
|
while (height) {
|
2001-10-09 14:30:12 +00:00
|
|
|
b = *src++;
|
2002-12-04 13:36:27 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (b & 0x80) {
|
|
|
|
b &= 0x7F;
|
2001-10-09 14:30:12 +00:00
|
|
|
c = *src++;
|
|
|
|
|
|
|
|
do {
|
|
|
|
*dst |= c;
|
2002-10-24 06:28:54 +00:00
|
|
|
dst += _numStrips;
|
2002-12-31 16:44:55 +00:00
|
|
|
--height;
|
|
|
|
} while (--b && height);
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
*dst |= *src++;
|
2002-10-24 06:28:54 +00:00
|
|
|
dst += _numStrips;
|
2002-12-31 16:44:55 +00:00
|
|
|
--height;
|
|
|
|
} while (--b && height);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-08 21:59:32 +00:00
|
|
|
#define READ_BIT (cl--, bit = bits & 1, bits >>= 1, bit)
|
|
|
|
#define FILL_BITS do { \
|
|
|
|
if (cl <= 8) { \
|
|
|
|
bits |= (*src++ << cl); \
|
|
|
|
cl += 8; \
|
|
|
|
} \
|
2003-10-13 11:59:48 +00:00
|
|
|
} while (0)
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::unkDecodeA(byte *dst, const byte *src, int height) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte color = *src++;
|
|
|
|
uint bits = *src++;
|
|
|
|
byte cl = 8;
|
|
|
|
byte bit;
|
2002-04-11 17:19:16 +00:00
|
|
|
byte incm, reps;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
do {
|
2002-12-31 04:45:21 +00:00
|
|
|
int x = 8;
|
2001-10-09 14:30:12 +00:00
|
|
|
do {
|
2002-12-16 01:25:21 +00:00
|
|
|
FILL_BITS;
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst++ = _roomPalette[color];
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-12-31 04:36:14 +00:00
|
|
|
againPos:
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!READ_BIT) {
|
2002-12-31 04:59:23 +00:00
|
|
|
} else if (!READ_BIT) {
|
|
|
|
FILL_BITS;
|
|
|
|
color = bits & _decomp_mask;
|
|
|
|
bits >>= _decomp_shr;
|
|
|
|
cl -= _decomp_shr;
|
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
incm = (bits & 7) - 4;
|
|
|
|
cl -= 3;
|
|
|
|
bits >>= 3;
|
2002-12-31 04:36:14 +00:00
|
|
|
if (incm) {
|
2004-01-04 12:35:51 +00:00
|
|
|
color += incm;
|
2002-12-31 04:36:14 +00:00
|
|
|
} else {
|
2002-12-16 01:25:21 +00:00
|
|
|
FILL_BITS;
|
|
|
|
reps = bits & 0xFF;
|
2001-10-16 10:01:48 +00:00
|
|
|
do {
|
2002-12-31 04:45:21 +00:00
|
|
|
if (!--x) {
|
|
|
|
x = 8;
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth - 8;
|
2002-12-16 01:25:21 +00:00
|
|
|
if (!--height)
|
2001-10-16 10:01:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst++ = _roomPalette[color];
|
2001-10-16 10:01:48 +00:00
|
|
|
} while (--reps);
|
2002-04-11 17:19:16 +00:00
|
|
|
bits >>= 8;
|
|
|
|
bits |= (*src++) << (cl - 8);
|
2001-10-16 10:01:48 +00:00
|
|
|
goto againPos;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-12-31 04:45:21 +00:00
|
|
|
} while (--x);
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth - 8;
|
2002-12-16 01:25:21 +00:00
|
|
|
} while (--height);
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
2001-10-23 19:51:50 +00:00
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::unkDecodeA_trans(byte *dst, const byte *src, int height) {
|
2001-10-16 10:01:48 +00:00
|
|
|
byte color = *src++;
|
|
|
|
uint bits = *src++;
|
|
|
|
byte cl = 8;
|
|
|
|
byte bit;
|
2002-04-11 17:19:16 +00:00
|
|
|
byte incm, reps;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
do {
|
2002-12-31 04:45:21 +00:00
|
|
|
int x = 8;
|
2001-10-16 10:01:48 +00:00
|
|
|
do {
|
2002-12-16 01:25:21 +00:00
|
|
|
FILL_BITS;
|
2002-12-31 14:59:06 +00:00
|
|
|
if (color != _transparentColor)
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst = _roomPalette[color];
|
2001-10-16 10:01:48 +00:00
|
|
|
dst++;
|
|
|
|
|
2002-12-31 04:36:14 +00:00
|
|
|
againPos:
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!READ_BIT) {
|
2002-12-31 04:59:23 +00:00
|
|
|
} else if (!READ_BIT) {
|
|
|
|
FILL_BITS;
|
|
|
|
color = bits & _decomp_mask;
|
|
|
|
bits >>= _decomp_shr;
|
|
|
|
cl -= _decomp_shr;
|
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
incm = (bits & 7) - 4;
|
|
|
|
cl -= 3;
|
|
|
|
bits >>= 3;
|
2001-10-16 10:01:48 +00:00
|
|
|
if (incm) {
|
|
|
|
color += incm;
|
|
|
|
} else {
|
2002-12-16 01:25:21 +00:00
|
|
|
FILL_BITS;
|
|
|
|
reps = bits & 0xFF;
|
2002-12-31 04:19:46 +00:00
|
|
|
do {
|
2002-12-31 04:45:21 +00:00
|
|
|
if (!--x) {
|
|
|
|
x = 8;
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth - 8;
|
2002-12-31 04:19:46 +00:00
|
|
|
if (!--height)
|
|
|
|
return;
|
|
|
|
}
|
2002-12-31 14:59:06 +00:00
|
|
|
if (color != _transparentColor)
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst = _roomPalette[color];
|
2002-12-31 04:19:46 +00:00
|
|
|
dst++;
|
|
|
|
} while (--reps);
|
2002-04-11 17:19:16 +00:00
|
|
|
bits >>= 8;
|
|
|
|
bits |= (*src++) << (cl - 8);
|
2001-10-16 10:01:48 +00:00
|
|
|
goto againPos;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-12-31 04:45:21 +00:00
|
|
|
} while (--x);
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth - 8;
|
2002-12-16 01:25:21 +00:00
|
|
|
} while (--height);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::unkDecodeB(byte *dst, const byte *src, int height) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte color = *src++;
|
|
|
|
uint bits = *src++;
|
|
|
|
byte cl = 8;
|
|
|
|
byte bit;
|
2002-12-31 04:59:23 +00:00
|
|
|
int8 inc = -1;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
do {
|
2002-12-31 14:59:06 +00:00
|
|
|
int x = 8;
|
2001-10-09 14:30:12 +00:00
|
|
|
do {
|
2002-12-16 01:25:21 +00:00
|
|
|
FILL_BITS;
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst++ = _roomPalette[color];
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!READ_BIT) {
|
|
|
|
} else if (!READ_BIT) {
|
2002-12-16 01:25:21 +00:00
|
|
|
FILL_BITS;
|
|
|
|
color = bits & _decomp_mask;
|
2001-10-26 17:34:50 +00:00
|
|
|
bits >>= _decomp_shr;
|
|
|
|
cl -= _decomp_shr;
|
2001-10-09 14:30:12 +00:00
|
|
|
inc = -1;
|
|
|
|
} else if (!READ_BIT) {
|
|
|
|
color += inc;
|
|
|
|
} else {
|
|
|
|
inc = -inc;
|
|
|
|
color += inc;
|
|
|
|
}
|
2002-12-31 14:59:06 +00:00
|
|
|
} while (--x);
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth - 8;
|
2002-12-31 14:59:06 +00:00
|
|
|
} while (--height);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::unkDecodeB_trans(byte *dst, const byte *src, int height) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte color = *src++;
|
|
|
|
uint bits = *src++;
|
|
|
|
byte cl = 8;
|
|
|
|
byte bit;
|
2002-12-31 04:59:23 +00:00
|
|
|
int8 inc = -1;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
do {
|
2002-12-31 04:45:21 +00:00
|
|
|
int x = 8;
|
2001-10-09 14:30:12 +00:00
|
|
|
do {
|
2002-12-16 01:25:21 +00:00
|
|
|
FILL_BITS;
|
2002-12-31 14:59:06 +00:00
|
|
|
if (color != _transparentColor)
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst = _roomPalette[color];
|
2002-12-31 14:59:06 +00:00
|
|
|
dst++;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!READ_BIT) {
|
|
|
|
} else if (!READ_BIT) {
|
2002-12-16 01:25:21 +00:00
|
|
|
FILL_BITS;
|
|
|
|
color = bits & _decomp_mask;
|
2001-10-26 17:34:50 +00:00
|
|
|
bits >>= _decomp_shr;
|
|
|
|
cl -= _decomp_shr;
|
2001-10-09 14:30:12 +00:00
|
|
|
inc = -1;
|
|
|
|
} else if (!READ_BIT) {
|
|
|
|
color += inc;
|
|
|
|
} else {
|
|
|
|
inc = -inc;
|
|
|
|
color += inc;
|
|
|
|
}
|
2002-12-31 04:45:21 +00:00
|
|
|
} while (--x);
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth - 8;
|
2002-12-16 01:25:21 +00:00
|
|
|
} while (--height);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::unkDecodeC(byte *dst, const byte *src, int height) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte color = *src++;
|
|
|
|
uint bits = *src++;
|
|
|
|
byte cl = 8;
|
|
|
|
byte bit;
|
2002-12-31 04:59:23 +00:00
|
|
|
int8 inc = -1;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-31 04:45:21 +00:00
|
|
|
int x = 8;
|
2002-04-11 17:19:16 +00:00
|
|
|
do {
|
2002-12-16 01:25:21 +00:00
|
|
|
int h = height;
|
2001-10-09 14:30:12 +00:00
|
|
|
do {
|
2002-12-16 01:25:21 +00:00
|
|
|
FILL_BITS;
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst = _roomPalette[color];
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!READ_BIT) {
|
|
|
|
} else if (!READ_BIT) {
|
2002-12-16 01:25:21 +00:00
|
|
|
FILL_BITS;
|
|
|
|
color = bits & _decomp_mask;
|
2001-10-26 17:34:50 +00:00
|
|
|
bits >>= _decomp_shr;
|
|
|
|
cl -= _decomp_shr;
|
2001-10-09 14:30:12 +00:00
|
|
|
inc = -1;
|
|
|
|
} else if (!READ_BIT) {
|
|
|
|
color += inc;
|
|
|
|
} else {
|
|
|
|
inc = -inc;
|
|
|
|
color += inc;
|
|
|
|
}
|
2002-12-16 01:25:21 +00:00
|
|
|
} while (--h);
|
2001-10-26 17:34:50 +00:00
|
|
|
dst -= _vertStripNextInc;
|
2002-12-31 04:45:21 +00:00
|
|
|
} while (--x);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::unkDecodeC_trans(byte *dst, const byte *src, int height) {
|
2002-12-31 14:59:06 +00:00
|
|
|
byte color = *src++;
|
|
|
|
uint bits = *src++;
|
|
|
|
byte cl = 8;
|
|
|
|
byte bit;
|
|
|
|
int8 inc = -1;
|
|
|
|
|
|
|
|
int x = 8;
|
|
|
|
do {
|
|
|
|
int h = height;
|
|
|
|
do {
|
|
|
|
FILL_BITS;
|
|
|
|
if (color != _transparentColor)
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst = _roomPalette[color];
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth;
|
2002-12-31 14:59:06 +00:00
|
|
|
if (!READ_BIT) {
|
|
|
|
} else if (!READ_BIT) {
|
|
|
|
FILL_BITS;
|
|
|
|
color = bits & _decomp_mask;
|
|
|
|
bits >>= _decomp_shr;
|
|
|
|
cl -= _decomp_shr;
|
|
|
|
inc = -1;
|
|
|
|
} else if (!READ_BIT) {
|
|
|
|
color += inc;
|
|
|
|
} else {
|
|
|
|
inc = -inc;
|
|
|
|
color += inc;
|
|
|
|
}
|
|
|
|
} while (--h);
|
|
|
|
dst -= _vertStripNextInc;
|
|
|
|
} while (--x);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef READ_BIT
|
|
|
|
#undef FILL_BITS
|
|
|
|
|
2002-03-09 09:15:34 +00:00
|
|
|
/* Ender - Zak256/Indy256 decoders */
|
2003-09-05 22:53:25 +00:00
|
|
|
#define READ_256BIT \
|
|
|
|
do { \
|
|
|
|
if ((mask <<= 1) == 256) { \
|
|
|
|
buffer = *src++; \
|
|
|
|
mask = 1; \
|
|
|
|
} \
|
|
|
|
bits = ((buffer & mask) != 0); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define NEXT_ROW \
|
|
|
|
do { \
|
|
|
|
dst += _vm->_screenWidth; \
|
|
|
|
if (--h == 0) { \
|
|
|
|
if (!--x) \
|
|
|
|
return; \
|
|
|
|
dst -= _vertStripNextInc; \
|
|
|
|
h = height; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2002-03-09 09:15:34 +00:00
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::unkDecode7(byte *dst, const byte *src, int height) {
|
2002-12-16 01:25:21 +00:00
|
|
|
uint h = height;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
if (_vm->_features & GF_OLD256) {
|
2002-12-31 04:45:21 +00:00
|
|
|
int x = 8;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (;;) {
|
2002-12-31 04:36:14 +00:00
|
|
|
*dst = *src++;
|
2003-09-05 22:53:25 +00:00
|
|
|
NEXT_ROW;
|
2002-12-16 01:25:21 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
return;
|
2002-03-09 09:15:34 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
do {
|
|
|
|
#if defined(SCUMM_NEED_ALIGNMENT)
|
2002-12-04 13:36:27 +00:00
|
|
|
memcpy(dst, src, 8);
|
2001-10-09 14:30:12 +00:00
|
|
|
#else
|
2003-05-26 13:14:57 +00:00
|
|
|
((uint32 *)dst)[0] = ((const uint32 *)src)[0];
|
|
|
|
((uint32 *)dst)[1] = ((const uint32 *)src)[1];
|
2001-10-09 14:30:12 +00:00
|
|
|
#endif
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth;
|
2001-10-10 12:52:21 +00:00
|
|
|
src += 8;
|
2001-10-09 14:30:12 +00:00
|
|
|
} while (--height);
|
|
|
|
}
|
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::unkDecode8(byte *dst, const byte *src, int height) {
|
2002-12-16 01:25:21 +00:00
|
|
|
uint h = height;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-31 04:45:21 +00:00
|
|
|
int x = 8;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (;;) {
|
|
|
|
uint run = (*src++) + 1;
|
|
|
|
byte color = *src++;
|
|
|
|
|
|
|
|
do {
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst = _roomPalette[color];
|
2003-09-05 22:53:25 +00:00
|
|
|
NEXT_ROW;
|
2002-12-16 01:25:21 +00:00
|
|
|
} while (--run);
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::unkDecode9(byte *dst, const byte *src, int height) {
|
2002-04-11 17:19:16 +00:00
|
|
|
unsigned char c, bits, color, run;
|
2002-12-31 04:45:21 +00:00
|
|
|
int i, j;
|
2002-04-11 17:19:16 +00:00
|
|
|
uint buffer = 0, mask = 128;
|
2002-12-16 01:25:21 +00:00
|
|
|
int h = height;
|
2002-12-31 04:45:21 +00:00
|
|
|
i = j = run = 0;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-31 04:45:21 +00:00
|
|
|
int x = 8;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (;;) {
|
|
|
|
c = 0;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
READ_256BIT;
|
|
|
|
c += (bits << i);
|
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
switch (c >> 2) {
|
2002-04-11 17:19:16 +00:00
|
|
|
case 0:
|
|
|
|
color = 0;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
READ_256BIT;
|
|
|
|
color += bits << i;
|
|
|
|
}
|
|
|
|
for (i = 0; i < ((c & 3) + 2); i++) {
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst = _roomPalette[run * 16 + color];
|
2003-09-05 22:53:25 +00:00
|
|
|
NEXT_ROW;
|
2002-12-16 01:25:21 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
for (i = 0; i < ((c & 3) + 1); i++) {
|
|
|
|
color = 0;
|
2002-12-31 04:45:21 +00:00
|
|
|
for (j = 0; j < 4; j++) {
|
2002-04-11 17:19:16 +00:00
|
|
|
READ_256BIT;
|
2002-12-31 04:45:21 +00:00
|
|
|
color += bits << j;
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst = _roomPalette[run * 16 + color];
|
2003-09-05 22:53:25 +00:00
|
|
|
NEXT_ROW;
|
2002-12-16 01:25:21 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
run = 0;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
READ_256BIT;
|
|
|
|
run += bits << i;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::unkDecode10(byte *dst, const byte *src, int height) {
|
2002-04-11 17:19:16 +00:00
|
|
|
int i;
|
|
|
|
unsigned char local_palette[256], numcolors = *src++;
|
2002-12-16 01:25:21 +00:00
|
|
|
uint h = height;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
for (i = 0; i < numcolors; i++)
|
|
|
|
local_palette[i] = *src++;
|
|
|
|
|
2002-12-31 04:45:21 +00:00
|
|
|
int x = 8;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
byte color = *src++;
|
|
|
|
if (color < numcolors) {
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst = _roomPalette[local_palette[color]];
|
2003-09-05 22:53:25 +00:00
|
|
|
NEXT_ROW;
|
2002-12-16 01:25:21 +00:00
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
uint run = color - numcolors + 1;
|
|
|
|
color = *src++;
|
|
|
|
do {
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst = _roomPalette[color];
|
2003-09-05 22:53:25 +00:00
|
|
|
NEXT_ROW;
|
2002-12-16 01:25:21 +00:00
|
|
|
} while (--run);
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Gdi::unkDecode11(byte *dst, const byte *src, int height) {
|
2002-04-11 17:19:16 +00:00
|
|
|
int bits, i;
|
|
|
|
uint buffer = 0, mask = 128;
|
|
|
|
unsigned char inc = 1, color = *src++;
|
|
|
|
|
2002-12-31 04:45:21 +00:00
|
|
|
int x = 8;
|
2002-04-11 17:19:16 +00:00
|
|
|
do {
|
2002-12-16 01:25:21 +00:00
|
|
|
int h = height;
|
2002-04-11 17:19:16 +00:00
|
|
|
do {
|
2003-10-13 12:56:53 +00:00
|
|
|
*dst = _roomPalette[color];
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2003-09-05 22:53:25 +00:00
|
|
|
READ_256BIT;
|
2002-12-16 01:25:21 +00:00
|
|
|
if (!bits)
|
|
|
|
break;
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
|
|
|
switch (i) {
|
|
|
|
case 1:
|
|
|
|
inc = -inc;
|
|
|
|
color -= inc;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
color -= inc;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
color = 0;
|
|
|
|
inc = 1;
|
|
|
|
for (i = 0; i < 8; i++) {
|
2003-09-05 22:53:25 +00:00
|
|
|
READ_256BIT;
|
2002-12-16 01:25:21 +00:00
|
|
|
color += bits << i;
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-12-16 01:25:21 +00:00
|
|
|
} while (--h);
|
2002-04-11 17:19:16 +00:00
|
|
|
dst -= _vertStripNextInc;
|
2002-12-31 04:45:21 +00:00
|
|
|
} while (--x);
|
2002-02-12 18:20:37 +00:00
|
|
|
}
|
|
|
|
|
2004-02-24 04:45:50 +00:00
|
|
|
|
|
|
|
// TODO: C'ify it
|
|
|
|
void Gdi::unkDecode12(byte *dst, const byte *src, int height) {
|
|
|
|
int var_8, di, var_6;
|
|
|
|
const byte *bx;
|
|
|
|
byte si, var_4;
|
|
|
|
|
|
|
|
var_8 = 0;
|
|
|
|
|
|
|
|
di = height << 3;
|
|
|
|
|
|
|
|
if (!height)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_cont1:
|
|
|
|
bx = src;
|
|
|
|
src++;
|
|
|
|
si = *bx;
|
|
|
|
|
|
|
|
if (!(si & 1)) {
|
|
|
|
si >>= 1;
|
|
|
|
si++;
|
|
|
|
di -= si;
|
|
|
|
if (di < 0)
|
|
|
|
si += di;
|
|
|
|
|
|
|
|
var_6 = di;
|
|
|
|
di = var_8;
|
|
|
|
|
|
|
|
do {
|
|
|
|
bx = src;
|
|
|
|
src++;
|
|
|
|
|
|
|
|
if (*bx != _transparentColor)
|
|
|
|
*dst = *bx;
|
|
|
|
|
|
|
|
dst++;
|
|
|
|
di++;
|
|
|
|
if (!(di & 7))
|
|
|
|
dst += 312;
|
|
|
|
|
|
|
|
si--;
|
|
|
|
} while (si);
|
|
|
|
var_8 = di;
|
|
|
|
if (var_6 > 0) {
|
|
|
|
di = var_6;
|
|
|
|
goto _cont1;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
si >>= 1;
|
|
|
|
bx = src;
|
|
|
|
src++;
|
|
|
|
var_4 = *bx;
|
|
|
|
si++;
|
|
|
|
di -= si;
|
|
|
|
if (di < 0)
|
|
|
|
si += di;
|
|
|
|
var_6 = di;
|
|
|
|
di = var_8;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (var_4 != _transparentColor)
|
|
|
|
*dst = var_4;
|
|
|
|
dst++;
|
|
|
|
di++;
|
|
|
|
if (!(di & 7))
|
|
|
|
dst += 312;
|
|
|
|
si--;
|
|
|
|
} while (si);
|
|
|
|
var_8 = di;
|
|
|
|
if (var_6 > 0) {
|
|
|
|
di = var_6;
|
|
|
|
goto _cont1;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: C'ify it
|
|
|
|
void Gdi::unkDecode13(byte *dst, const byte *src, int height) {
|
|
|
|
int var_8, di, var_6;
|
|
|
|
const byte *bx;
|
|
|
|
byte si, var_4;
|
|
|
|
|
|
|
|
var_8 = 0;
|
|
|
|
|
|
|
|
di = height << 3;
|
|
|
|
|
|
|
|
if (!height)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_cont1:
|
|
|
|
bx = src;
|
|
|
|
src++;
|
|
|
|
si = *bx;
|
|
|
|
|
|
|
|
if (!(si & 1)) {
|
|
|
|
si >>= 1;
|
|
|
|
si++;
|
|
|
|
di -= si;
|
|
|
|
if (di < 0)
|
|
|
|
si += di;
|
|
|
|
|
|
|
|
var_6 = di;
|
|
|
|
di = var_8;
|
|
|
|
|
|
|
|
do {
|
|
|
|
bx = src;
|
|
|
|
src++;
|
|
|
|
|
|
|
|
*dst = *bx;
|
|
|
|
|
|
|
|
dst++;
|
|
|
|
di++;
|
|
|
|
if (!(di & 7))
|
|
|
|
dst += 312;
|
|
|
|
|
|
|
|
si--;
|
|
|
|
} while (si);
|
|
|
|
var_8 = di;
|
|
|
|
if (var_6 > 0) {
|
|
|
|
di = var_6;
|
|
|
|
goto _cont1;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
si >>= 1;
|
|
|
|
bx = src;
|
|
|
|
src++;
|
|
|
|
var_4 = *bx;
|
|
|
|
si++;
|
|
|
|
di -= si;
|
|
|
|
if (di < 0)
|
|
|
|
si += di;
|
|
|
|
var_6 = di;
|
|
|
|
di = var_8;
|
|
|
|
|
|
|
|
do {
|
|
|
|
*dst = var_4;
|
|
|
|
dst++;
|
|
|
|
di++;
|
|
|
|
if (!(di & 7))
|
|
|
|
dst += 312;
|
|
|
|
si--;
|
|
|
|
} while (si);
|
|
|
|
var_8 = di;
|
|
|
|
if (var_6 > 0) {
|
|
|
|
di = var_6;
|
|
|
|
goto _cont1;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-12 18:20:37 +00:00
|
|
|
#undef NEXT_ROW
|
|
|
|
#undef READ_256BIT
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
#pragma mark -
|
2002-12-16 19:53:41 +00:00
|
|
|
#pragma mark --- Transition effects ---
|
2002-12-15 23:40:37 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::fadeIn(int effect) {
|
2003-04-02 15:23:36 +00:00
|
|
|
updatePalette();
|
2003-05-24 16:11:47 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
switch (effect) {
|
2003-08-21 13:39:21 +00:00
|
|
|
case 0:
|
|
|
|
// seems to do nothing
|
|
|
|
break;
|
2002-12-15 23:40:37 +00:00
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
2003-06-05 18:30:29 +00:00
|
|
|
case 5:
|
2003-06-07 22:56:47 +00:00
|
|
|
// Some of the transition effects won't work properly unless
|
|
|
|
// the screen is marked as clean first. At first I thought I
|
|
|
|
// could safely do this every time fadeIn() was called, but
|
|
|
|
// that broke the FOA intro. Probably other things as well.
|
|
|
|
//
|
|
|
|
// Hopefully it's safe to do it at this point, at least.
|
2003-06-05 18:30:29 +00:00
|
|
|
virtscr[0].setDirtyRange(0, 0);
|
|
|
|
transitionEffect(effect - 1);
|
2002-12-15 23:40:37 +00:00
|
|
|
break;
|
|
|
|
case 128:
|
|
|
|
unkScreenEffect6();
|
|
|
|
break;
|
2003-08-21 13:39:21 +00:00
|
|
|
case 129:
|
|
|
|
break;
|
2002-12-15 23:40:37 +00:00
|
|
|
case 130:
|
|
|
|
case 131:
|
|
|
|
case 132:
|
|
|
|
case 133:
|
|
|
|
scrollEffect(133 - effect);
|
|
|
|
break;
|
|
|
|
case 134:
|
|
|
|
dissolveEffect(1, 1);
|
|
|
|
break;
|
|
|
|
case 135:
|
|
|
|
unkScreenEffect5(1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
warning("Unknown screen effect, %d", effect);
|
|
|
|
}
|
|
|
|
_screenEffectFlag = true;
|
2001-10-17 10:07:40 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::fadeOut(int effect) {
|
2003-06-07 22:56:47 +00:00
|
|
|
VirtScreen *vs = &virtscr[0];
|
2001-10-17 10:07:40 +00:00
|
|
|
|
2003-06-07 22:56:47 +00:00
|
|
|
vs->setDirtyRange(0, 0);
|
2003-06-07 00:13:26 +00:00
|
|
|
if (!(_features & GF_NEW_CAMERA))
|
2002-12-15 23:40:37 +00:00
|
|
|
camera._last.x = camera._cur.x;
|
2002-07-07 20:32:26 +00:00
|
|
|
|
2003-05-24 16:11:47 +00:00
|
|
|
if (_screenEffectFlag && effect != 0) {
|
|
|
|
|
|
|
|
// Fill screen 0 with black
|
2003-06-07 22:56:47 +00:00
|
|
|
|
2004-01-03 22:21:56 +00:00
|
|
|
memset(vs->screenPtr + vs->xstart, 0, vs->width * vs->height);
|
2003-05-24 16:11:47 +00:00
|
|
|
|
|
|
|
// Fade to black with the specified effect, if any.
|
|
|
|
switch (effect) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
2003-06-05 18:30:29 +00:00
|
|
|
case 5:
|
2003-05-24 16:11:47 +00:00
|
|
|
transitionEffect(effect - 1);
|
|
|
|
break;
|
|
|
|
case 128:
|
|
|
|
unkScreenEffect6();
|
|
|
|
break;
|
|
|
|
case 129:
|
|
|
|
// Just blit screen 0 to the display (i.e. display will be black)
|
2003-06-07 22:56:47 +00:00
|
|
|
vs->setDirtyRange(0, vs->height);
|
2004-01-03 21:22:07 +00:00
|
|
|
updateDirtyScreen(kMainVirtScreen);
|
2003-05-24 16:11:47 +00:00
|
|
|
break;
|
|
|
|
case 134:
|
|
|
|
dissolveEffect(1, 1);
|
|
|
|
break;
|
|
|
|
case 135:
|
|
|
|
unkScreenEffect5(1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
warning("fadeOut: default case %d", effect);
|
|
|
|
}
|
|
|
|
}
|
2001-10-17 10:07:40 +00:00
|
|
|
|
2003-05-24 16:11:47 +00:00
|
|
|
// Update the palette at the end (once we faded to black) to avoid
|
|
|
|
// some nasty effects when the palette is changed
|
|
|
|
updatePalette();
|
2001-10-17 10:07:40 +00:00
|
|
|
|
2003-05-24 16:11:47 +00:00
|
|
|
_screenEffectFlag = false;
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
2002-07-07 20:32:26 +00:00
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/**
|
|
|
|
* Perform a transition effect. There are four different effects possible:
|
2002-05-22 22:36:58 +00:00
|
|
|
* 0: Iris effect
|
2003-01-05 21:18:53 +00:00
|
|
|
* 1: Box wipe (a black box expands from the upper-left corner to the lower-right corner)
|
|
|
|
* 2: Box wipe (a black box expands from the lower-right corner to the upper-left corner)
|
|
|
|
* 3: Inverse box wipe
|
|
|
|
* All effects operate on 8x8 blocks of the screen. These blocks are updated
|
|
|
|
* in a certain order; the exact order determines how the effect appears to the user.
|
2003-05-30 20:13:29 +00:00
|
|
|
* @param a the transition effect to perform
|
2002-05-22 22:36:58 +00:00
|
|
|
*/
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::transitionEffect(int a) {
|
2002-07-07 20:32:26 +00:00
|
|
|
int delta[16]; // Offset applied during each iteration
|
2001-10-17 10:07:40 +00:00
|
|
|
int tab_2[16];
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, j;
|
2001-10-17 10:07:40 +00:00
|
|
|
int bottom;
|
2002-04-11 17:19:16 +00:00
|
|
|
int l, t, r, b;
|
2004-01-08 00:48:37 +00:00
|
|
|
const int height = MIN((int)virtscr[0].height, _screenHeight);
|
2001-10-17 10:07:40 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < 16; i++) {
|
2003-01-05 21:18:53 +00:00
|
|
|
delta[i] = transitionEffects[a].deltaTable[i];
|
|
|
|
j = transitionEffects[a].stripTable[i];
|
2002-04-11 17:19:16 +00:00
|
|
|
if (j == 24)
|
2004-01-08 00:48:37 +00:00
|
|
|
j = height / 8 - 1;
|
2001-10-17 10:07:40 +00:00
|
|
|
tab_2[i] = j;
|
|
|
|
}
|
|
|
|
|
2004-01-08 00:48:37 +00:00
|
|
|
bottom = height / 8;
|
2003-01-05 21:18:53 +00:00
|
|
|
for (j = 0; j < transitionEffects[a].numOfIterations; j++) {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
l = tab_2[i * 4];
|
|
|
|
t = tab_2[i * 4 + 1];
|
|
|
|
r = tab_2[i * 4 + 2];
|
|
|
|
b = tab_2[i * 4 + 3];
|
|
|
|
if (t == b) {
|
2001-10-17 10:07:40 +00:00
|
|
|
while (l <= r) {
|
2004-01-04 14:49:14 +00:00
|
|
|
if (l >= 0 && l < gdi._numStrips && t < bottom) {
|
2003-11-16 20:52:57 +00:00
|
|
|
virtscr[0].tdirty[l] = t * 8;
|
2004-01-05 00:45:17 +00:00
|
|
|
virtscr[0].bdirty[l] = (b + 1) * 8;
|
2001-10-17 10:07:40 +00:00
|
|
|
}
|
|
|
|
l++;
|
|
|
|
}
|
|
|
|
} else {
|
2002-10-24 06:28:54 +00:00
|
|
|
if (l < 0 || l >= gdi._numStrips || b <= t)
|
2001-10-17 10:07:40 +00:00
|
|
|
continue;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (b > bottom)
|
|
|
|
b = bottom;
|
2003-06-05 18:30:29 +00:00
|
|
|
if (t < 0)
|
|
|
|
t = 0;
|
2003-11-16 20:52:57 +00:00
|
|
|
virtscr[0].tdirty[l] = t * 8;
|
2004-01-05 00:45:17 +00:00
|
|
|
virtscr[0].bdirty[l] = (b + 1) * 8;
|
2001-10-17 10:07:40 +00:00
|
|
|
}
|
2004-01-03 21:22:07 +00:00
|
|
|
updateDirtyScreen(kMainVirtScreen);
|
2001-10-17 10:07:40 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < 16; i++)
|
2002-05-22 22:36:58 +00:00
|
|
|
tab_2[i] += delta[i];
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-05-22 22:36:58 +00:00
|
|
|
// Draw the current state to the screen and wait half a sec so the user
|
|
|
|
// can watch the effect taking place.
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->updateScreen();
|
2002-04-12 21:26:59 +00:00
|
|
|
waitForTimer(30);
|
2001-10-17 10:07:40 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/**
|
|
|
|
* Update width*height areas of the screen, in random order, until the whole
|
|
|
|
* screen has been updated. For instance:
|
|
|
|
*
|
|
|
|
* dissolveEffect(1, 1) produces a pixel-by-pixel dissolve
|
|
|
|
* dissolveEffect(8, 8) produces a square-by-square dissolve
|
|
|
|
* dissolveEffect(virtsrc[0].width, 1) produces a line-by-line dissolve
|
|
|
|
*/
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::dissolveEffect(int width, int height) {
|
2002-08-25 18:40:23 +00:00
|
|
|
VirtScreen *vs = &virtscr[0];
|
|
|
|
int *offsets;
|
|
|
|
int blits_before_refresh, blits;
|
|
|
|
int x, y;
|
|
|
|
int w, h;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// There's probably some less memory-hungry way of doing this. But
|
|
|
|
// since we're only dealing with relatively small images, it shouldn't
|
|
|
|
// be too bad.
|
|
|
|
|
|
|
|
w = vs->width / width;
|
|
|
|
h = vs->height / height;
|
|
|
|
|
2003-06-09 01:32:36 +00:00
|
|
|
// When used correctly, vs->width % width and vs->height % height
|
2002-08-25 18:40:23 +00:00
|
|
|
// should both be zero, but just to be safe...
|
|
|
|
|
|
|
|
if (vs->width % width)
|
|
|
|
w++;
|
|
|
|
|
|
|
|
if (vs->height % height)
|
|
|
|
h++;
|
|
|
|
|
|
|
|
offsets = (int *) malloc(w * h * sizeof(int));
|
|
|
|
if (offsets == NULL) {
|
|
|
|
warning("dissolveEffect: out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a permutation of offsets into the frame buffer
|
|
|
|
|
|
|
|
if (width == 1 && height == 1) {
|
|
|
|
// Optimized case for pixel-by-pixel dissolve
|
|
|
|
|
2004-01-03 22:21:56 +00:00
|
|
|
for (i = 0; i < vs->width * vs->height; i++)
|
2002-08-25 18:40:23 +00:00
|
|
|
offsets[i] = i;
|
|
|
|
|
|
|
|
for (i = 1; i < w * h; i++) {
|
|
|
|
int j;
|
|
|
|
|
2002-12-01 14:57:50 +00:00
|
|
|
j = _rnd.getRandomNumber(i - 1);
|
2002-08-25 18:40:23 +00:00
|
|
|
offsets[i] = offsets[j];
|
|
|
|
offsets[j] = i;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int *offsets2;
|
|
|
|
|
|
|
|
for (i = 0, x = 0; x < vs->width; x += width)
|
|
|
|
for (y = 0; y < vs->height; y += height)
|
|
|
|
offsets[i++] = y * vs->width + x;
|
|
|
|
|
|
|
|
offsets2 = (int *) malloc(w * h * sizeof(int));
|
|
|
|
if (offsets2 == NULL) {
|
|
|
|
warning("dissolveEffect: out of memory");
|
|
|
|
free(offsets);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(offsets2, offsets, w * h * sizeof(int));
|
|
|
|
|
|
|
|
for (i = 1; i < w * h; i++) {
|
|
|
|
int j;
|
|
|
|
|
2002-12-01 14:57:50 +00:00
|
|
|
j = _rnd.getRandomNumber(i - 1);
|
2002-08-25 18:40:23 +00:00
|
|
|
offsets[i] = offsets[j];
|
|
|
|
offsets[j] = offsets2[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
free(offsets2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Blit the image piece by piece to the screen. The idea here is that
|
|
|
|
// the whole update should take about a quarter of a second, assuming
|
|
|
|
// most of the time is spent in waitForTimer(). It looks good to me,
|
|
|
|
// but might still need some tuning.
|
|
|
|
|
|
|
|
blits = 0;
|
|
|
|
blits_before_refresh = (3 * w * h) / 25;
|
2002-11-27 14:39:48 +00:00
|
|
|
|
2003-06-07 11:59:56 +00:00
|
|
|
// Speed up the effect for CD Loom since it uses it so often. I don't
|
|
|
|
// think the original had any delay at all, so on modern hardware it
|
|
|
|
// wasn't even noticeable.
|
|
|
|
if (_gameId == GID_LOOM256)
|
|
|
|
blits_before_refresh *= 2;
|
2002-08-25 18:40:23 +00:00
|
|
|
|
|
|
|
for (i = 0; i < w * h; i++) {
|
|
|
|
x = offsets[i] % vs->width;
|
|
|
|
y = offsets[i] / vs->width;
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->copyRectToScreen(vs->screenPtr + vs->xstart + y * vs->width + x, vs->width, x, y + vs->topline, width, height);
|
2002-08-25 18:40:23 +00:00
|
|
|
|
|
|
|
if (++blits >= blits_before_refresh) {
|
|
|
|
blits = 0;
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->updateScreen();
|
2002-08-25 18:40:23 +00:00
|
|
|
waitForTimer(30);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(offsets);
|
|
|
|
|
|
|
|
if (blits != 0) {
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->updateScreen();
|
2002-08-25 18:40:23 +00:00
|
|
|
waitForTimer(30);
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::scrollEffect(int dir) {
|
2002-12-15 23:40:37 +00:00
|
|
|
VirtScreen *vs = &virtscr[0];
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
int x, y;
|
|
|
|
int step;
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
if ((dir == 0) || (dir == 1))
|
|
|
|
step = vs->height;
|
|
|
|
else
|
|
|
|
step = vs->width;
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
step = (step * kPictureDelay) / kScrolltime;
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
switch (dir) {
|
|
|
|
case 0:
|
|
|
|
//up
|
|
|
|
y = 1 + step;
|
|
|
|
while (y < vs->height) {
|
|
|
|
_system->move_screen(0, -step, vs->height);
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->copyRectToScreen(vs->screenPtr + vs->xstart + (y - step) * vs->width,
|
2002-12-15 23:40:37 +00:00
|
|
|
vs->width,
|
|
|
|
0, vs->height - step,
|
|
|
|
vs->width, step);
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->updateScreen();
|
2002-12-15 23:40:37 +00:00
|
|
|
waitForTimer(kPictureDelay);
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
y += step;
|
2002-03-05 23:05:55 +00:00
|
|
|
}
|
2002-12-15 23:40:37 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
// down
|
|
|
|
y = 1 + step;
|
|
|
|
while (y < vs->height) {
|
|
|
|
_system->move_screen(0, step, vs->height);
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->copyRectToScreen(vs->screenPtr + vs->xstart + vs->width * (vs->height-y),
|
2002-12-15 23:40:37 +00:00
|
|
|
vs->width,
|
|
|
|
0, 0,
|
|
|
|
vs->width, step);
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->updateScreen();
|
2002-12-15 23:40:37 +00:00
|
|
|
waitForTimer(kPictureDelay);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
y += step;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// left
|
|
|
|
x = 1 + step;
|
|
|
|
while (x < vs->width) {
|
|
|
|
_system->move_screen(-step, 0, vs->height);
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->copyRectToScreen(vs->screenPtr + vs->xstart + x - step,
|
2002-12-15 23:40:37 +00:00
|
|
|
vs->width,
|
|
|
|
vs->width - step, 0,
|
|
|
|
step, vs->height);
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->updateScreen();
|
2002-12-15 23:40:37 +00:00
|
|
|
waitForTimer(kPictureDelay);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
x += step;
|
2002-03-05 23:05:55 +00:00
|
|
|
}
|
2002-12-15 23:40:37 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
// right
|
|
|
|
x = 1 + step;
|
|
|
|
while (x < vs->width) {
|
|
|
|
_system->move_screen(step, 0, vs->height);
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->copyRectToScreen(vs->screenPtr + vs->xstart + vs->width - x,
|
2002-12-15 23:40:37 +00:00
|
|
|
vs->width,
|
|
|
|
0, 0,
|
|
|
|
step, vs->height);
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->updateScreen();
|
2002-12-15 23:40:37 +00:00
|
|
|
waitForTimer(kPictureDelay);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
x += step;
|
2002-03-05 23:05:55 +00:00
|
|
|
}
|
2002-12-15 23:40:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::unkScreenEffect6() {
|
2003-06-07 11:59:56 +00:00
|
|
|
// CD Loom (but not EGA Loom!) uses a more fine-grained dissolve
|
|
|
|
if (_gameId == GID_LOOM256)
|
2002-12-15 23:40:37 +00:00
|
|
|
dissolveEffect(1, 1);
|
|
|
|
else
|
|
|
|
dissolveEffect(8, 4);
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::unkScreenEffect5(int a) {
|
2002-12-15 23:40:37 +00:00
|
|
|
// unkScreenEffect5(0), which is used by FOA during the opening
|
|
|
|
// cutscene when Indy opens the small statue, has been replaced by
|
|
|
|
// dissolveEffect(1, 1).
|
|
|
|
//
|
|
|
|
// I still don't know what unkScreenEffect5(1) is supposed to do.
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2004-01-04 14:35:46 +00:00
|
|
|
// FIXME: not implemented
|
2002-12-15 23:40:37 +00:00
|
|
|
warning("stub unkScreenEffect(%d)", a);
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::setShake(int mode) {
|
2002-12-15 23:40:37 +00:00
|
|
|
if (_shakeEnabled != (mode != 0))
|
|
|
|
_fullRedraw = true;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
_shakeEnabled = mode != 0;
|
|
|
|
_shakeFrame = 0;
|
|
|
|
_system->set_shake_pos(0);
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-10-09 14:17:06 +00:00
|
|
|
} // End of namespace Scumm
|
2003-04-30 13:23:31 +00:00
|
|
|
|
|
|
|
#ifdef __PALM_OS__
|
2003-08-18 10:59:21 +00:00
|
|
|
#include "scumm_globals.h"
|
|
|
|
|
|
|
|
_GINIT(Gfx)
|
2003-10-09 14:17:06 +00:00
|
|
|
_GSETPTR(Scumm::transitionEffects, GBVARS_TRANSITIONEFFECTS_INDEX, Scumm::TransitionEffect, GBVARS_SCUMM)
|
2003-08-18 10:59:21 +00:00
|
|
|
_GEND
|
|
|
|
|
|
|
|
_GRELEASE(Gfx)
|
|
|
|
_GRELEASEPTR(GBVARS_TRANSITIONEFFECTS_INDEX, GBVARS_SCUMM)
|
|
|
|
_GEND
|
|
|
|
|
2003-04-30 13:23:31 +00:00
|
|
|
#endif
|