2001-10-09 14:30:12 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2003-03-06 21:46:56 +00:00
|
|
|
* Copyright (C) 2001-2003 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"
|
|
|
|
#include "scumm.h"
|
2002-05-14 23:32:34 +00:00
|
|
|
#include "actor.h"
|
2003-05-30 19:00:33 +00:00
|
|
|
#include "bomp.h"
|
2002-12-25 21:04:47 +00:00
|
|
|
#include "charset.h"
|
2002-07-16 21:03:14 +00:00
|
|
|
#include "resource.h"
|
2003-01-14 10:06:56 +00:00
|
|
|
#include "usage_bits.h"
|
2002-09-16 15:53:52 +00:00
|
|
|
#include "util.h"
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning( disable : 4068 ) // turn off "unknown pragma" warning
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
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-01-05 21:18:53 +00:00
|
|
|
static const TransitionEffect transitionEffects[4] = {
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2003-01-05 21:18:53 +00:00
|
|
|
/*
|
|
|
|
* Mouse cursor cycle colors (for the default crosshair).
|
|
|
|
*/
|
2002-12-15 23:40:37 +00:00
|
|
|
static const byte default_cursor_colors[4] = {
|
|
|
|
15, 15, 7, 8
|
|
|
|
};
|
|
|
|
|
2003-04-30 13:23:31 +00:00
|
|
|
static const uint16 default_cursor_images[5][16] = {
|
2002-12-15 23:40:37 +00:00
|
|
|
/* cross-hair */
|
|
|
|
{ 0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0000, 0x7e3f,
|
|
|
|
0x0000, 0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0080, 0x0000 },
|
|
|
|
/* hourglass */
|
|
|
|
{ 0x0000, 0x7ffe, 0x6006, 0x300c, 0x1818, 0x0c30, 0x0660, 0x03c0,
|
|
|
|
0x0660, 0x0c30, 0x1998, 0x33cc, 0x67e6, 0x7ffe, 0x0000, 0x0000 },
|
|
|
|
/* arrow */
|
|
|
|
{ 0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x7f00,
|
|
|
|
0x7f80, 0x78c0, 0x7c00, 0x4600, 0x0600, 0x0300, 0x0300, 0x0180 },
|
|
|
|
/* hand */
|
|
|
|
{ 0x1e00, 0x1200, 0x1200, 0x1200, 0x1200, 0x13ff, 0x1249, 0x1249,
|
|
|
|
0xf249, 0x9001, 0x9001, 0x9001, 0x8001, 0x8001, 0x8001, 0xffff },
|
2003-04-30 13:23:31 +00:00
|
|
|
/* cross-hair zak256 - chrilith palmos */
|
|
|
|
/*
|
|
|
|
{ 0x0080, 0x0080, 0x02a0, 0x01c0, 0x0080, 0x1004, 0x0808, 0x7c1f,
|
|
|
|
0x0808, 0x1004, 0x0080, 0x01c0, 0x02a0, 0x0080, 0x0080, 0x0000 },
|
|
|
|
*/
|
|
|
|
{ 0x0080, 0x02a0, 0x01c0, 0x0080, 0x0000, 0x2002, 0x1004, 0x780f,
|
|
|
|
0x1004, 0x2002, 0x0000, 0x0080, 0x01c0, 0x02a0, 0x0080, 0x0000 },
|
2002-12-15 23:40:37 +00:00
|
|
|
};
|
|
|
|
|
2003-04-30 13:23:31 +00:00
|
|
|
static const byte default_cursor_hotspots[10] = {
|
|
|
|
8, 7, 8, 7, 1, 1, 5, 0,
|
|
|
|
8, 7, //zak256
|
2002-12-15 23:40:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
static inline uint colorWeight(int red, int green, int blue) {
|
2002-12-15 23:40:37 +00:00
|
|
|
return 3 * red * red + 6 * green * green + 2 * blue * blue;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::getGraphicsPerformance() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 10; i != 0; i--) {
|
2003-05-10 21:49:59 +00:00
|
|
|
initScreens(0, 0, _screenWidth, _screenHeight);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-14 09:47:53 +00:00
|
|
|
if (VAR_PERFORMANCE_1 != 0xFF) // Variable is reserved for game scripts in earlier games
|
2003-05-08 15:48:50 +00:00
|
|
|
VAR(VAR_PERFORMANCE_1) = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 10; i != 0; i--) {
|
2003-06-01 14:30:26 +00:00
|
|
|
virtscr[0].setDirtyRange(0, _screenHeight); //ender
|
2001-11-09 18:54:15 +00:00
|
|
|
drawDirtyScreenParts();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-14 09:47:53 +00:00
|
|
|
if (VAR_PERFORMANCE_2 != 0xFF) // Variable is reserved for game scripts in earlier games
|
2003-05-08 15:48:50 +00:00
|
|
|
VAR(VAR_PERFORMANCE_2) = 0;
|
2002-03-06 09:40:21 +00:00
|
|
|
|
2002-10-27 10:31:07 +00:00
|
|
|
if (_features & GF_AFTER_V7)
|
2003-05-10 21:49:59 +00:00
|
|
|
initScreens(0, 0, _screenWidth, _screenHeight);
|
2002-03-06 09:40:21 +00:00
|
|
|
else
|
2003-05-10 21:49:59 +00:00
|
|
|
initScreens(0, 16, _screenWidth, 144);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::initScreens(int a, int b, int w, 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)) {
|
2002-10-27 18:41:27 +00:00
|
|
|
if (_features & GF_AFTER_V7) {
|
2003-05-10 21:49:59 +00:00
|
|
|
initVirtScreen(3, 0, (_screenHeight / 2) - 10, _screenWidth, 13, false, false);
|
2002-10-27 18:41:27 +00:00
|
|
|
} else {
|
2003-05-10 21:49:59 +00:00
|
|
|
initVirtScreen(3, 0, 80, _screenWidth, 13, false, false);
|
2002-10-27 18:41:27 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2003-05-10 21:49:59 +00:00
|
|
|
initVirtScreen(0, 0, b, _screenWidth, h - b, true, true);
|
|
|
|
initVirtScreen(1, 0, 0, _screenWidth, b, false, false);
|
|
|
|
initVirtScreen(2, 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
|
|
|
}
|
|
|
|
|
2002-04-23 23:58:31 +00:00
|
|
|
void Scumm::initVirtScreen(int 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
|
|
|
|
2002-10-27 10:31:07 +00:00
|
|
|
if (_features & GF_AFTER_V7) {
|
2003-05-10 21:49:59 +00:00
|
|
|
if ((!slot) && (_roomHeight != 0))
|
|
|
|
height = _roomHeight;
|
2002-10-13 11:28:39 +00:00
|
|
|
}
|
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
vs->number = slot;
|
2003-05-10 21:49:59 +00:00
|
|
|
vs->width = _screenWidth;
|
2001-10-09 14:30:12 +00:00
|
|
|
vs->topline = top;
|
|
|
|
vs->height = height;
|
|
|
|
vs->alloctwobuffers = twobufs;
|
2002-10-20 01:02:52 +00:00
|
|
|
vs->scrollable = scrollable;
|
2001-10-09 14:30:12 +00:00
|
|
|
vs->xstart = 0;
|
|
|
|
size = vs->width * vs->height;
|
|
|
|
vs->size = size;
|
2002-03-20 22:58:41 +00:00
|
|
|
vs->backBuf = NULL;
|
2002-03-14 13:57:28 +00:00
|
|
|
|
2002-12-21 01:11:42 +00:00
|
|
|
if (vs->scrollable) {
|
|
|
|
if (_features & GF_AFTER_V7) {
|
2003-05-10 21:49:59 +00:00
|
|
|
size += _screenWidth * 8;
|
2002-12-21 01:11:42 +00:00
|
|
|
} else {
|
2003-05-10 21:49:59 +00:00
|
|
|
size += _screenWidth * 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) {
|
2002-04-11 17:19:16 +00:00
|
|
|
createResource(rtBuffer, slot + 5, size);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (slot != 3) {
|
2003-06-01 14:30:26 +00:00
|
|
|
virtscr[slot].setDirtyRange(0, height);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
VirtScreen *Scumm::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
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::updateDirtyRect(int 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;
|
|
|
|
|
2003-01-14 10:06:56 +00:00
|
|
|
if (virt == 0 && dirtybit) {
|
2002-12-15 23:40:37 +00:00
|
|
|
lp = (left >> 3) + _screenStartStrip;
|
|
|
|
if (lp < 0)
|
|
|
|
lp = 0;
|
|
|
|
if (_features & GF_AFTER_V7) {
|
2002-12-21 01:11:42 +00:00
|
|
|
#ifdef V7_SMOOTH_SCROLLING_HACK
|
|
|
|
rp = (right + vs->xstart) >> 3;
|
|
|
|
#else
|
|
|
|
rp = (right >> 3) + _screenStartStrip;
|
|
|
|
#endif
|
2002-12-15 23:40:37 +00:00
|
|
|
if (rp > 409)
|
|
|
|
rp = 409;
|
|
|
|
} else {
|
2002-12-21 01:11:42 +00:00
|
|
|
rp = (right >> 3) + _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-06-01 14:30:26 +00:00
|
|
|
// The following code used to be in the seperate method setVirtscreenDirty
|
|
|
|
lp = left >> 3;
|
|
|
|
rp = right >> 3;
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::drawDirtyScreenParts() {
|
2001-10-26 17:34:50 +00:00
|
|
|
int i;
|
|
|
|
VirtScreen *vs;
|
2002-07-07 20:32:26 +00:00
|
|
|
byte *src;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
updateDirtyScreen(2);
|
2003-05-14 13:30:52 +00:00
|
|
|
if (_features & GF_AFTER_V2 || _features & GF_AFTER_V3)
|
2002-02-17 18:55:46 +00:00
|
|
|
updateDirtyScreen(1);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-12-15 21:59:59 +00:00
|
|
|
if (camera._last.x == camera._cur.x && (camera._last.y == camera._cur.y || !(_features & GF_AFTER_V7))) {
|
2001-10-09 14:30:12 +00:00
|
|
|
updateDirtyScreen(0);
|
|
|
|
} else {
|
2001-10-26 17:34:50 +00:00
|
|
|
vs = &virtscr[0];
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2003-05-10 21:49:59 +00:00
|
|
|
src = vs->screenPtr + vs->xstart + _screenTop * _screenWidth;
|
|
|
|
_system->copy_rect(src, _screenWidth, 0, vs->topline, _screenWidth, vs->height - _screenTop);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-10-24 06:28:54 +00:00
|
|
|
for (i = 0; i < gdi._numStrips; i++) {
|
2002-12-25 20:07:09 +00:00
|
|
|
vs->tdirty[i] = vs->height;
|
2001-10-26 17:34:50 +00:00
|
|
|
vs->bdirty[i] = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-28 15:26:28 +00:00
|
|
|
|
|
|
|
/* Handle shaking */
|
2002-12-25 21:04:47 +00:00
|
|
|
if (_shakeEnabled) {
|
2002-04-11 17:19:16 +00:00
|
|
|
_shakeFrame = (_shakeFrame + 1) & (NUM_SHAKE_POSITIONS - 1);
|
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
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::updateDirtyScreen(int slot) {
|
2001-10-26 17:34:50 +00:00
|
|
|
gdi.updateDirtyScreen(&virtscr[slot]);
|
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/**
|
|
|
|
* Blit the data from the given VirtScreen to the display. If the camera moved,
|
|
|
|
* 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) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (vs->height == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2002-12-21 01:11:42 +00:00
|
|
|
if (_vm->_features & GF_AFTER_V7 && (_vm->camera._cur.y != _vm->camera._last.y)) {
|
2002-10-24 06:28:54 +00:00
|
|
|
drawStripToScreen(vs, 0, _numStrips << 3, 0, vs->height);
|
2002-12-21 01:11:42 +00:00
|
|
|
} else {
|
2002-10-20 01:02:52 +00:00
|
|
|
int i;
|
|
|
|
int start, w, top, bottom;
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2002-10-20 01:02:52 +00:00
|
|
|
w = 8;
|
|
|
|
start = 0;
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2002-10-24 06:28:54 +00:00
|
|
|
for (i = 0; i < _numStrips; i++) {
|
2002-10-20 01:02:52 +00:00
|
|
|
bottom = vs->bdirty[i];
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2002-10-20 01:02:52 +00:00
|
|
|
if (bottom) {
|
|
|
|
top = vs->tdirty[i];
|
2002-12-25 20:07:09 +00:00
|
|
|
vs->tdirty[i] = vs->height;
|
2002-10-20 01:02:52 +00:00
|
|
|
vs->bdirty[i] = 0;
|
2002-12-25 20:07:09 +00:00
|
|
|
if (i != (_numStrips - 1) && vs->bdirty[i + 1] == bottom && vs->tdirty[i + 1] == top) {
|
2002-12-21 01:11:42 +00:00
|
|
|
// Simple optimizations: if two or more neighbouring strips form one bigger rectangle,
|
|
|
|
// blit them all at once.
|
2002-10-20 01:02:52 +00:00
|
|
|
w += 8;
|
|
|
|
continue;
|
|
|
|
}
|
2003-01-28 00:42:32 +00:00
|
|
|
// handle vertically scrolling rooms
|
|
|
|
if (_vm->_features & GF_AFTER_V7)
|
|
|
|
drawStripToScreen(vs, start * 8, w, 0, vs->height);
|
|
|
|
else
|
2002-12-15 23:40:37 +00:00
|
|
|
drawStripToScreen(vs, start * 8, w, top, bottom);
|
2002-10-20 01:02:52 +00:00
|
|
|
w = 8;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-10-20 01:02:52 +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.
|
|
|
|
*/
|
2003-03-06 17:58:13 +00:00
|
|
|
void Gdi::drawStripToScreen(VirtScreen *vs, int x, int w, int t, int b) {
|
2001-10-26 17:34:50 +00:00
|
|
|
byte *ptr;
|
2002-04-23 23:58:31 +00:00
|
|
|
int height;
|
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
if (b <= t)
|
|
|
|
return;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
if (t > vs->height)
|
|
|
|
t = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
if (b > vs->height)
|
|
|
|
b = vs->height;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-05-14 21:55:17 +00:00
|
|
|
height = b - t;
|
2003-05-10 21:49:59 +00:00
|
|
|
if (height > _vm->_screenHeight)
|
|
|
|
height = _vm->_screenHeight;
|
2002-05-14 21:55:17 +00:00
|
|
|
|
2002-12-21 12:34:17 +00:00
|
|
|
// Normally, _vm->_screenTop should always be >= 0, but for some old save games
|
|
|
|
// it is not, hence we check & correct it here.
|
|
|
|
if (_vm->_screenTop < 0)
|
|
|
|
_vm->_screenTop = 0;
|
2002-04-23 23:58:31 +00:00
|
|
|
|
2003-05-10 21:49:59 +00:00
|
|
|
ptr = vs->screenPtr + (x + vs->xstart) + (_vm->_screenTop + t) * _vm->_screenWidth;
|
|
|
|
_vm->_system->copy_rect(ptr, _vm->_screenWidth, x, vs->topline + t, w, height);
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 01:02:35 +00:00
|
|
|
void Gdi::clearCharsetMask() {
|
|
|
|
memset(_vm->getResourceAddress(rtBuffer, 9), 0, _imgBufOffs[1]);
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/**
|
|
|
|
* Reset the background behind an actor or blast object.
|
|
|
|
*/
|
2003-03-06 17:58:13 +00:00
|
|
|
void Gdi::resetBackground(int top, int bottom, int strip) {
|
2002-12-15 23:40:37 +00:00
|
|
|
VirtScreen *vs = &_vm->virtscr[0];
|
2002-12-16 01:25:21 +00:00
|
|
|
byte *backbuff_ptr, *bgbak_ptr;
|
|
|
|
int offs, numLinesToProcess;
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2003-05-15 17:53:23 +00:00
|
|
|
assert(0 <= strip && strip < _numStrips);
|
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
if (top < vs->tdirty[strip])
|
|
|
|
vs->tdirty[strip] = top;
|
|
|
|
|
|
|
|
if (bottom > vs->bdirty[strip])
|
|
|
|
vs->bdirty[strip] = bottom;
|
|
|
|
|
2003-06-01 14:30:26 +00:00
|
|
|
offs = (top * _numStrips + _vm->_screenStartStrip + strip) << 3;
|
|
|
|
byte *mask_ptr = _vm->getMaskBuffer(strip * 8, top, 0);
|
|
|
|
bgbak_ptr = _vm->getResourceAddress(rtBuffer, 5) + offs;
|
|
|
|
backbuff_ptr = vs->screenPtr + offs;
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2002-12-16 01:25:21 +00:00
|
|
|
numLinesToProcess = bottom - top;
|
|
|
|
if (numLinesToProcess) {
|
2003-05-08 15:48:50 +00:00
|
|
|
if ((_vm->_features & GF_AFTER_V6) || (_vm->VAR(_vm->VAR_CURRENT_LIGHTS) & LIGHTMODE_screen)) {
|
2002-12-15 23:40:37 +00:00
|
|
|
if (_vm->hasCharsetMask(strip << 3, top, (strip + 1) << 3, bottom))
|
2003-05-11 00:28:43 +00:00
|
|
|
draw8ColWithMasking(backbuff_ptr, bgbak_ptr, numLinesToProcess, mask_ptr);
|
2002-12-15 23:40:37 +00:00
|
|
|
else
|
2002-12-16 01:25:21 +00:00
|
|
|
draw8Col(backbuff_ptr, bgbak_ptr, numLinesToProcess);
|
2002-12-15 23:40:37 +00:00
|
|
|
} else {
|
2002-12-16 01:25:21 +00:00
|
|
|
clear8Col(backbuff_ptr, numLinesToProcess);
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Scumm::blit(byte *dst, const byte *src, int w, int h) {
|
2002-04-11 17:19:16 +00:00
|
|
|
assert(h > 0);
|
2002-08-30 20:47:48 +00:00
|
|
|
assert(src != NULL);
|
|
|
|
assert(dst != NULL);
|
2002-04-23 23:58:31 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
do {
|
|
|
|
memcpy(dst, src, w);
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _screenWidth;
|
|
|
|
src += _screenWidth;
|
2001-10-09 14:30:12 +00:00
|
|
|
} while (--h);
|
|
|
|
}
|
|
|
|
|
2003-05-15 23:50:16 +00:00
|
|
|
void Scumm::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;
|
|
|
|
|
|
|
|
updateDirtyRect(vs->number, x, x2, y, y2, 0);
|
|
|
|
|
|
|
|
backbuff = vs->screenPtr + vs->xstart + y * _screenWidth + x;
|
|
|
|
|
|
|
|
width = x2 - x;
|
|
|
|
height = y2 - y;
|
|
|
|
if (color == -1) {
|
|
|
|
if (vs->number != 0)
|
|
|
|
error("can only copy bg to main window");
|
|
|
|
bgbuff = getResourceAddress(rtBuffer, vs->number + 5) + vs->xstart + y * _screenWidth + x;
|
|
|
|
blit(backbuff, bgbuff, width, height);
|
|
|
|
} else {
|
|
|
|
while (height--) {
|
|
|
|
memset(backbuff, color, width);
|
|
|
|
backbuff += _screenWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
#pragma mark -
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::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
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_features & GF_AFTER_V7) {
|
2003-05-10 21:49:59 +00:00
|
|
|
initVirtScreen(0, 0, virtscr[0].topline, _screenWidth, height, 1, 1);
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
room = getResourceAddress(rtRoom, _roomResource);
|
2003-04-12 09:31:00 +00:00
|
|
|
if ((_features & GF_AFTER_V2) || (_features & GF_AFTER_V3)) {
|
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
|
|
|
|
|
|
|
if (_gameId == GID_MONKEY_EGA)
|
|
|
|
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
|
|
|
}
|
2002-12-24 07:53:29 +00:00
|
|
|
} else if (_features & GF_AFTER_V8) {
|
|
|
|
// 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
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
if (_features & GF_AFTER_V7)
|
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-03-06 17:58:13 +00:00
|
|
|
void Scumm::drawFlashlight() {
|
2002-11-10 19:00:28 +00:00
|
|
|
int i, j, offset, x, y;
|
2002-08-20 02:20:40 +00:00
|
|
|
|
|
|
|
// Remove the flash light first if it was previously drawn
|
2003-05-15 22:48:06 +00:00
|
|
|
if (_flashlight.isDrawn) {
|
2002-11-10 19:00:28 +00:00
|
|
|
updateDirtyRect(0, _flashlight.x, _flashlight.x + _flashlight.w,
|
2003-03-06 17:58:13 +00:00
|
|
|
_flashlight.y, _flashlight.y + _flashlight.h, USAGE_BIT_DIRTY);
|
2002-08-20 02:20:40 +00:00
|
|
|
|
2002-11-10 17:19:43 +00:00
|
|
|
if (_flashlight.buffer) {
|
|
|
|
i = _flashlight.h;
|
2002-08-20 02:20:40 +00:00
|
|
|
do {
|
2002-11-28 03:08:35 +00:00
|
|
|
memset(_flashlight.buffer, 0, _flashlight.w);
|
2003-05-10 21:49:59 +00:00
|
|
|
_flashlight.buffer += _screenWidth;
|
2002-08-20 02:20:40 +00:00
|
|
|
} while (--i);
|
|
|
|
}
|
2003-05-15 22:48:06 +00:00
|
|
|
_flashlight.isDrawn = false;
|
2002-08-20 02:20:40 +00:00
|
|
|
}
|
|
|
|
|
2003-05-15 22:48:06 +00:00
|
|
|
if (_flashlight.xStrips == 0 || _flashlight.yStrips == 0)
|
2002-08-20 02:20:40 +00:00
|
|
|
return;
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2002-08-20 02:20:40 +00:00
|
|
|
// Calculate the area of the flashlight
|
2003-05-24 21:33:54 +00:00
|
|
|
if (_gameId == GID_ZAK256 || _gameId == GID_ZAK) {
|
|
|
|
x = _mouse.x + virtscr[0].xstart;
|
|
|
|
y = _mouse.y - virtscr[0].topline;
|
2002-11-10 19:00:28 +00:00
|
|
|
} else {
|
2003-05-23 13:24:41 +00:00
|
|
|
Actor *a = derefActor(VAR(VAR_EGO), "drawFlashlight");
|
2002-11-10 19:00:28 +00:00
|
|
|
x = a->x;
|
|
|
|
y = a->y;
|
|
|
|
}
|
2003-05-15 22:48:06 +00:00
|
|
|
_flashlight.w = _flashlight.xStrips * 8;
|
|
|
|
_flashlight.h = _flashlight.yStrips * 8;
|
2003-03-06 17:58:13 +00:00
|
|
|
_flashlight.x = x - _flashlight.w / 2 - _screenStartStrip * 8;
|
|
|
|
_flashlight.y = y - _flashlight.h / 2;
|
|
|
|
|
2003-04-30 21:30:59 +00:00
|
|
|
if (_gameId == GID_LOOM || _gameId == GID_LOOM256)
|
|
|
|
_flashlight.y -= 12;
|
|
|
|
|
2002-08-20 02:20:40 +00:00
|
|
|
// Clip the flashlight at the borders
|
2002-11-10 17:19:43 +00:00
|
|
|
if (_flashlight.x < 0)
|
|
|
|
_flashlight.x = 0;
|
2002-12-15 23:40:37 +00:00
|
|
|
else if (_flashlight.x + _flashlight.w > gdi._numStrips * 8)
|
|
|
|
_flashlight.x = gdi._numStrips * 8 - _flashlight.w;
|
2002-11-10 17:19:43 +00:00
|
|
|
if (_flashlight.y < 0)
|
|
|
|
_flashlight.y = 0;
|
2002-11-10 19:00:28 +00:00
|
|
|
else if (_flashlight.y + _flashlight.h> virtscr[0].height)
|
2002-11-10 17:19:43 +00:00
|
|
|
_flashlight.y = virtscr[0].height - _flashlight.h;
|
2002-08-20 02:20:40 +00:00
|
|
|
|
|
|
|
// Redraw any actors "under" the flashlight
|
2003-03-06 17:58:13 +00:00
|
|
|
for (i = _flashlight.x / 8; i < (_flashlight.x + _flashlight.w) / 8; i++) {
|
2003-05-15 17:53:23 +00:00
|
|
|
assert(0 <= i && i < gdi._numStrips);
|
2003-01-14 10:06:56 +00:00
|
|
|
setGfxUsageBit(_screenStartStrip + i, USAGE_BIT_DIRTY);
|
2002-08-20 02:20:40 +00:00
|
|
|
virtscr[0].tdirty[i] = 0;
|
|
|
|
virtscr[0].bdirty[i] = virtscr[0].height;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *bgbak;
|
2003-05-10 21:49:59 +00:00
|
|
|
offset = _flashlight.y * _screenWidth + virtscr[0].xstart + _flashlight.x;
|
2002-11-10 17:19:43 +00:00
|
|
|
_flashlight.buffer = virtscr[0].screenPtr + offset;
|
2002-08-20 02:20:40 +00:00
|
|
|
bgbak = getResourceAddress(rtBuffer, 5) + offset;
|
|
|
|
|
2002-11-10 19:00:28 +00:00
|
|
|
blit(_flashlight.buffer, bgbak, _flashlight.w, _flashlight.h);
|
2002-08-20 02:20:40 +00:00
|
|
|
|
2002-08-23 23:16:39 +00:00
|
|
|
// 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;
|
2002-11-10 19:00:28 +00:00
|
|
|
int maxcol = _flashlight.w - 1;
|
2003-05-10 21:49:59 +00:00
|
|
|
int maxrow = (_flashlight.h - 1) * _screenWidth;
|
2002-08-23 23:16:39 +00:00
|
|
|
|
2003-05-10 21:49:59 +00:00
|
|
|
for (i = 0; i < 8; i++, minrow += _screenWidth, maxrow -= _screenWidth) {
|
2002-08-23 23:16:39 +00:00
|
|
|
int d = corner_data[i];
|
|
|
|
|
|
|
|
for (j = 0; j < d; j++) {
|
2002-11-10 17:19:43 +00:00
|
|
|
_flashlight.buffer[minrow + j] = 0;
|
|
|
|
_flashlight.buffer[minrow + maxcol - j] = 0;
|
|
|
|
_flashlight.buffer[maxrow + j] = 0;
|
|
|
|
_flashlight.buffer[maxrow + maxcol - j] = 0;
|
2002-08-23 23:16:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-15 22:48:06 +00:00
|
|
|
_flashlight.isDrawn = true;
|
2002-08-19 17:23:48 +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-03-06 17:58:13 +00:00
|
|
|
void Scumm::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
|
|
|
|
2002-03-05 23:41:41 +00:00
|
|
|
if (!(_features & GF_AFTER_V7))
|
2002-12-25 21:04:47 +00:00
|
|
|
if (camera._cur.x != camera._last.x && _charset->_hasMask)
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_features & GF_AFTER_V7) {
|
2002-08-15 20:12:15 +00:00
|
|
|
diff = (camera._cur.x >> 3) - (camera._last.x >> 3);
|
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-03-06 17:58:13 +00:00
|
|
|
void Scumm::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
|
|
|
|
|
|
|
gdi.drawBitmap(getResourceAddress(rtRoom, _roomResource) + _IM00_offs,
|
2003-05-10 21:49:59 +00:00
|
|
|
&virtscr[0], s, 0, _roomWidth, virtscr[0].height, s, num, 0);
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::restoreCharsetBg() {
|
2003-05-15 22:30:32 +00:00
|
|
|
if (gdi._mask.left != -1) {
|
|
|
|
restoreBG(gdi._mask);
|
2002-12-25 21:04:47 +00:00
|
|
|
_charset->_hasMask = false;
|
2003-05-15 22:30:32 +00:00
|
|
|
gdi._mask.left = -1;
|
|
|
|
_charset->_str.left = -1;
|
2002-12-25 21:04:47 +00:00
|
|
|
_charset->_left = -1;
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
|
2002-12-25 21:04:47 +00:00
|
|
|
_charset->_nextLeft = _string[0].xpos;
|
|
|
|
_charset->_nextTop = _string[0].ypos;
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
|
2003-05-15 22:30:32 +00:00
|
|
|
void Scumm::restoreBG(ScummVM::Rect rect, byte backColor) {
|
2002-12-15 23:40:37 +00:00
|
|
|
VirtScreen *vs;
|
|
|
|
int topline, height, width;
|
|
|
|
byte *backbuff, *bgbak;
|
2003-04-30 21:30:59 +00:00
|
|
|
bool lightsOn;
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2003-05-15 22:30:32 +00:00
|
|
|
if (rect.left == rect.right || rect.top == rect.bottom)
|
2002-12-15 23:40:37 +00:00
|
|
|
return;
|
2003-05-15 22:30:32 +00:00
|
|
|
if (rect.top < 0)
|
|
|
|
rect.top = 0;
|
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;
|
|
|
|
|
|
|
|
topline = vs->topline;
|
|
|
|
height = topline + vs->height;
|
|
|
|
|
2003-05-15 22:30:32 +00:00
|
|
|
if (rect.left < 0)
|
|
|
|
rect.left = 0;
|
|
|
|
if (rect.right < 0)
|
|
|
|
rect.right = 0;
|
|
|
|
if (rect.left > _screenWidth)
|
2002-12-15 23:40:37 +00:00
|
|
|
return;
|
2003-05-15 22:30:32 +00:00
|
|
|
if (rect.right > _screenWidth)
|
|
|
|
rect.right = _screenWidth;
|
|
|
|
if (rect.bottom >= height)
|
|
|
|
rect.bottom = height;
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2003-05-15 22:30:32 +00:00
|
|
|
updateDirtyRect(vs->number, rect.left, rect.right, rect.top - topline, rect.bottom - topline, USAGE_BIT_RESTORED);
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2003-05-15 22:30:32 +00:00
|
|
|
int offset = (rect.top - topline) * _screenWidth + vs->xstart + rect.left;
|
2002-12-15 23:40:37 +00:00
|
|
|
backbuff = vs->screenPtr + offset;
|
|
|
|
bgbak = getResourceAddress(rtBuffer, vs->number + 5) + offset;
|
|
|
|
|
2003-05-15 22:30:32 +00:00
|
|
|
height = rect.height();
|
|
|
|
width = rect.width();
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2003-04-30 21:30:59 +00:00
|
|
|
// Check whether lights are turned on or not
|
2003-05-08 15:48:50 +00:00
|
|
|
lightsOn = (_features & GF_AFTER_V6) || (vs->number != 0) || (VAR(VAR_CURRENT_LIGHTS) & LIGHTMODE_screen);
|
2003-04-30 21:30:59 +00:00
|
|
|
|
|
|
|
if (vs->alloctwobuffers && _currentRoom != 0 && lightsOn ) {
|
2002-12-15 23:40:37 +00:00
|
|
|
blit(backbuff, bgbak, width, height);
|
2002-12-25 21:04:47 +00:00
|
|
|
if (vs->number == 0 && _charset->_hasMask && height) {
|
2002-12-15 23:40:37 +00:00
|
|
|
byte *mask;
|
2003-05-27 23:23:26 +00:00
|
|
|
// Note: At first sight it may look as if this could
|
|
|
|
// be optimized to (rect.right - rect.left) >> 3 and
|
|
|
|
// thus to width >> 3, but that's not the case since
|
|
|
|
// we are dealing with integer math here.
|
|
|
|
int mask_width = (rect.right >> 3) - (rect.left >> 3);
|
2002-12-15 23:40:37 +00:00
|
|
|
|
2003-05-27 23:23:26 +00:00
|
|
|
if (rect.right & 0x07)
|
2002-12-15 23:40:37 +00:00
|
|
|
mask_width++;
|
|
|
|
|
2003-06-01 14:30:26 +00:00
|
|
|
mask = getMaskBuffer(rect.left, rect.top, 0);
|
2002-12-15 23:40:37 +00:00
|
|
|
if (vs->number == 0)
|
|
|
|
mask += vs->topline * gdi._numStrips;
|
|
|
|
|
|
|
|
do {
|
|
|
|
memset(mask, 0, mask_width);
|
|
|
|
mask += gdi._numStrips;
|
|
|
|
} while (--height);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (height--) {
|
|
|
|
memset(backbuff, backColor, width);
|
2003-05-10 21:49:59 +00:00
|
|
|
backbuff += _screenWidth;
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-15 21:09:55 +00:00
|
|
|
bool Scumm::hasCharsetMask(int left, int top, int right, int bottom) {
|
|
|
|
// FIXME: I wonder if the <= / >= here shouldn't be replaced by < / >
|
|
|
|
// After all, right/bottom are not actually part of the rects.
|
|
|
|
// That is, the pixels part of the rect range from x = left .. right-1
|
|
|
|
// and y = top .. bottom-1. The 'equal' / '=' cases in the check
|
|
|
|
// would mean that the rects are touching on their borders, but not
|
|
|
|
// actually overlapping.
|
|
|
|
return _charset->_hasMask
|
2003-05-15 22:30:32 +00:00
|
|
|
&& top <= gdi._mask.bottom
|
|
|
|
&& left <= gdi._mask.right
|
|
|
|
&& bottom >= gdi._mask.top
|
|
|
|
&& right >= gdi._mask.left;
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 14:30:26 +00:00
|
|
|
byte *Scumm::getMaskBuffer(int x, int y, int z) {
|
|
|
|
return getResourceAddress(rtBuffer, 9)
|
|
|
|
+ _screenStartStrip + (x / 8) + y * gdi._numStrips + gdi._imgBufOffs[z];
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-06-01 14:30:26 +00:00
|
|
|
|
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-05-10 12:59:32 +00:00
|
|
|
int stripnr, int numstrip, byte flag) {
|
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
|
2003-05-08 15:48:50 +00:00
|
|
|
lightsOn = (_vm->_features & GF_AFTER_V6) || (vs->number != 0) || (_vm->VAR(_vm->VAR_CURRENT_LIGHTS) & LIGHTMODE_screen);
|
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;
|
2002-12-31 03:26:02 +00:00
|
|
|
else if (_vm->_features & GF_AFTER_V8)
|
|
|
|
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-05-11 11:13:24 +00:00
|
|
|
else if (_numZBuffer <= 1 || (_vm->_features & GF_AFTER_V2))
|
2003-04-26 10:43:59 +00:00
|
|
|
numzbuf = _numZBuffer;
|
2003-04-24 18:53:21 +00:00
|
|
|
else {
|
|
|
|
numzbuf = _numZBuffer;
|
|
|
|
assert(numzbuf <= (int)ARRAYSIZE(zplane_list));
|
2003-04-30 13:23:31 +00:00
|
|
|
|
2003-04-25 00:03:06 +00:00
|
|
|
if (_vm->_features & GF_OLD256) {
|
2003-04-25 10:57:12 +00:00
|
|
|
zplane_list[1] = smap_ptr + READ_LE_UINT32(smap_ptr);
|
2003-04-25 00:03:06 +00:00
|
|
|
if (0 == READ_LE_UINT32(zplane_list[1]))
|
|
|
|
zplane_list[1] = 0;
|
|
|
|
} else if (_vm->_features & GF_SMALL_HEADER) {
|
|
|
|
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);
|
|
|
|
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-04-24 18:53:21 +00:00
|
|
|
} else if (_vm->_features & GF_AFTER_V8) {
|
|
|
|
// 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
|
|
|
|
|
|
|
if (_vm->_features & GF_AFTER_V8) {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2003-05-10 21:49:59 +00:00
|
|
|
_vertStripNextInc = height * _vm->_screenWidth - 1;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-10 12:23:02 +00:00
|
|
|
sx = x;
|
|
|
|
if (vs->scrollable)
|
|
|
|
sx -= vs->xstart >> 3;
|
|
|
|
|
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-05-10 12:59:32 +00:00
|
|
|
if (_vm->_features & GF_AFTER_V2) {
|
|
|
|
|
2003-05-10 14:30:58 +00:00
|
|
|
if (vs->alloctwobuffers)
|
|
|
|
bgbak_ptr = _vm->getResourceAddress(rtBuffer, vs->number + 5) + (y * _numStrips + x) * 8;
|
|
|
|
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
|
|
|
|
2003-05-11 11:13:24 +00:00
|
|
|
mask_ptr = _vm->getResourceAddress(rtBuffer, 9) + (y * _numStrips + x) + _imgBufOffs[1];
|
2003-05-10 14:30:58 +00:00
|
|
|
|
2003-05-10 21:23:17 +00:00
|
|
|
const int left = (stripnr << 3);
|
|
|
|
const int right = left + (numstrip << 3);
|
2003-05-10 14:30:58 +00:00
|
|
|
byte *dst = bgbak_ptr;
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *src = smap_ptr;
|
2003-05-10 14:30:58 +00:00
|
|
|
byte color = 0, data = 0;
|
|
|
|
int run = 1;
|
|
|
|
bool dither = false;
|
|
|
|
byte dither_table[128];
|
|
|
|
byte *ptr_dither_table;
|
|
|
|
memset(dither_table, 0, sizeof(dither_table));
|
|
|
|
int theX, theY;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
for (theX = 0; theX < width; theX++) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if (run == 0) {
|
|
|
|
run = *src++;
|
|
|
|
}
|
|
|
|
color = data & 0x0f;
|
|
|
|
}
|
|
|
|
if (!dither) {
|
|
|
|
*ptr_dither_table = color;
|
|
|
|
}
|
|
|
|
if (left <= theX && theX < right) {
|
|
|
|
*dst = *ptr_dither_table++;
|
2003-05-10 21:49:59 +00:00
|
|
|
dst += _vm->_screenWidth;
|
2003-05-10 14:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (left <= theX && theX < right) {
|
2003-05-11 11:27:19 +00:00
|
|
|
dst -= height * _vm->_screenWidth - 1;
|
2003-05-10 14:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw mask (zplane) data
|
|
|
|
theY = 0;
|
|
|
|
theX = 0;
|
2003-05-10 17:09:21 +00:00
|
|
|
while (theX < width) {
|
2003-05-10 14:30:58 +00:00
|
|
|
run = *src++;
|
|
|
|
if (run & 0x80) {
|
|
|
|
run &= 0x7f;
|
|
|
|
data = *src++;
|
|
|
|
do {
|
|
|
|
if (left <= theX && theX < right) {
|
2003-05-11 00:28:43 +00:00
|
|
|
*mask_ptr = data;
|
|
|
|
mask_ptr += _numStrips;
|
2003-05-10 14:30:58 +00:00
|
|
|
}
|
|
|
|
theY++;
|
|
|
|
if (theY >= height) {
|
2003-05-10 16:57:04 +00:00
|
|
|
if (left <= theX && theX < right) {
|
2003-05-11 11:27:19 +00:00
|
|
|
mask_ptr -= height * _numStrips - 1;
|
2003-05-10 16:57:04 +00:00
|
|
|
}
|
2003-05-10 14:30:58 +00:00
|
|
|
theY = 0;
|
2003-05-10 16:57:04 +00:00
|
|
|
theX += 8;
|
|
|
|
if (theX >= width)
|
2003-05-10 17:09:21 +00:00
|
|
|
break;
|
2003-05-10 14:30:58 +00:00
|
|
|
}
|
|
|
|
} while (--run);
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
data = *src++;
|
|
|
|
|
|
|
|
if (left <= theX && theX < right) {
|
2003-05-11 00:28:43 +00:00
|
|
|
*mask_ptr = data;
|
|
|
|
mask_ptr += _numStrips;
|
2003-05-10 14:30:58 +00:00
|
|
|
}
|
|
|
|
theY++;
|
|
|
|
if (theY >= height) {
|
2003-05-10 16:57:04 +00:00
|
|
|
if (left <= theX && theX < right) {
|
2003-05-11 11:13:24 +00:00
|
|
|
mask_ptr -= _numStrips * height - 1;
|
2003-05-10 16:57:04 +00:00
|
|
|
}
|
|
|
|
theY = 0;
|
|
|
|
theX += 8;
|
2003-05-10 14:30:58 +00:00
|
|
|
if (theX >= width)
|
2003-05-10 17:09:21 +00:00
|
|
|
break;
|
2003-05-10 14:30:58 +00:00
|
|
|
}
|
|
|
|
} while (--run);
|
|
|
|
}
|
|
|
|
}
|
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;
|
2002-12-21 01:11:42 +00:00
|
|
|
if (vs->alloctwobuffers)
|
2002-12-16 01:25:21 +00:00
|
|
|
bgbak_ptr = _vm->getResourceAddress(rtBuffer, vs->number + 5) + (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-05-10 17:09:21 +00:00
|
|
|
if (!(_vm->_features & GF_AFTER_V2)) {
|
|
|
|
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
|
|
|
|
2003-05-11 11:13:24 +00:00
|
|
|
mask_ptr = _vm->getResourceAddress(rtBuffer, 9) + (y * _numStrips + x);
|
|
|
|
|
2002-04-17 16:02:29 +00:00
|
|
|
CHECK_HEAP;
|
2002-12-21 01:11:42 +00:00
|
|
|
if (vs->alloctwobuffers) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_vm->hasCharsetMask(sx << 3, y, (sx + 1) << 3, 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-05-10 18:31:00 +00:00
|
|
|
if (_vm->_features & GF_AFTER_V2) {
|
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.
|
|
|
|
|
2002-12-30 13:15:08 +00:00
|
|
|
if (_vm->_features & GF_AFTER_V8)
|
|
|
|
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++) {
|
2003-05-11 00:28:43 +00:00
|
|
|
mask_ptr = _vm->getResourceAddress(rtBuffer, 9) + y * _numStrips + x + _imgBufOffs[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++) {
|
|
|
|
uint16 offs;
|
|
|
|
|
|
|
|
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);
|
|
|
|
else if (_vm->_features & GF_AFTER_V8)
|
2002-12-30 14:22:23 +00:00
|
|
|
offs = (uint16) 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);
|
|
|
|
|
2003-05-11 00:28:43 +00:00
|
|
|
mask_ptr = _vm->getResourceAddress(rtBuffer, 9) + y * _numStrips + x + _imgBufOffs[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
|
|
|
|
|
|
|
#if 0
|
|
|
|
// HACK: blit mask(s) onto normal screen. Useful to debug masking
|
|
|
|
for (i = 0; i < numzbuf; i++) {
|
2003-06-01 14:30:26 +00:00
|
|
|
mask_ptr = _vm->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;
|
|
|
|
}
|
|
|
|
dst += _vm->_screenWidth;
|
|
|
|
dst2 += _vm->_screenWidth;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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-04-12 11:44:15 +00:00
|
|
|
while(x < 8) {
|
2003-04-10 11:34:51 +00:00
|
|
|
color = *src++;
|
|
|
|
|
2003-04-12 11:44:15 +00:00
|
|
|
if(color & 0x80) {
|
2003-04-10 11:34:51 +00:00
|
|
|
run = color & 0x3f;
|
|
|
|
|
|
|
|
if(color & 0x40) {
|
|
|
|
color = *src++;
|
|
|
|
|
|
|
|
if(run == 0) {
|
|
|
|
run = *src++;
|
|
|
|
}
|
2003-04-12 11:44:15 +00:00
|
|
|
for(z = 0; z < run; z++) {
|
2003-05-21 18:09:49 +00:00
|
|
|
*(dst + y * _vm->_screenWidth + x) = (z&1) ? (color & 0xf) : (color >> 4);
|
2003-04-10 11:34:51 +00:00
|
|
|
|
|
|
|
y++;
|
2003-04-12 11:44:15 +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-04-10 11:34:51 +00:00
|
|
|
if(run == 0) {
|
2003-04-09 19:14:05 +00:00
|
|
|
run = *src++;
|
|
|
|
}
|
2003-04-10 11:34:51 +00:00
|
|
|
|
2003-04-12 11:44:15 +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-04-12 11:44:15 +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;
|
|
|
|
if(run == 0) {
|
|
|
|
run = *src++;
|
|
|
|
}
|
|
|
|
|
2003-04-12 11:44:15 +00:00
|
|
|
for(z = 0; z < run; z++) {
|
2003-05-10 21:49:59 +00:00
|
|
|
*(dst + y * _vm->_screenWidth + x) = color & 0xf;
|
2003-04-10 11:34:51 +00:00
|
|
|
|
2003-04-12 11:44:15 +00:00
|
|
|
y++;
|
|
|
|
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
|
|
|
|
2003-04-09 19:14:05 +00:00
|
|
|
if (_vm->_features & GF_AMIGA)
|
2002-04-17 03:11:37 +00:00
|
|
|
_palette_mod = 16;
|
|
|
|
else
|
|
|
|
_palette_mod = 0;
|
2002-07-07 20:32:26 +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;
|
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) {
|
2002-04-11 17:19:16 +00:00
|
|
|
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];
|
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) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!(maskbits & 0x80))
|
|
|
|
dst[0] = 0;
|
|
|
|
if (!(maskbits & 0x40))
|
|
|
|
dst[1] = 0;
|
|
|
|
if (!(maskbits & 0x20))
|
|
|
|
dst[2] = 0;
|
|
|
|
if (!(maskbits & 0x10))
|
|
|
|
dst[3] = 0;
|
|
|
|
if (!(maskbits & 0x08))
|
|
|
|
dst[4] = 0;
|
|
|
|
if (!(maskbits & 0x04))
|
|
|
|
dst[5] = 0;
|
|
|
|
if (!(maskbits & 0x02))
|
|
|
|
dst[6] = 0;
|
|
|
|
if (!(maskbits & 0x01))
|
|
|
|
dst[7] = 0;
|
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);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-16 01:25:21 +00:00
|
|
|
#define READ_BIT (cl--, bit = bits&1, bits>>=1,bit)
|
2003-03-06 17:58:13 +00:00
|
|
|
#define FILL_BITS do { \
|
|
|
|
if (cl <= 8) { \
|
|
|
|
bits |= (*src++ << cl); \
|
|
|
|
cl += 8; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
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;
|
|
|
|
*dst++ = color + _palette_mod;
|
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) {
|
|
|
|
color += incm;
|
|
|
|
} 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;
|
|
|
|
}
|
2002-04-17 03:11:37 +00:00
|
|
|
*dst++ = color + _palette_mod;
|
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)
|
2002-12-16 01:25:21 +00:00
|
|
|
*dst = color + _palette_mod;
|
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)
|
2002-12-31 04:19:46 +00:00
|
|
|
*dst = color + _palette_mod;
|
|
|
|
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;
|
2002-12-31 14:59:06 +00:00
|
|
|
*dst++ = color + _palette_mod;
|
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)
|
|
|
|
*dst = color + _palette_mod;
|
|
|
|
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;
|
|
|
|
*dst = color + _palette_mod;
|
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)
|
|
|
|
*dst = color + _palette_mod;
|
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-05-30 20:13:29 +00:00
|
|
|
#define READ_256BIT \
|
|
|
|
if ((mask <<= 1) == 256) { \
|
|
|
|
buffer = *src++; \
|
|
|
|
mask = 1; \
|
|
|
|
} \
|
|
|
|
bits = ((buffer & mask) != 0);
|
|
|
|
|
|
|
|
#define NEXT_ROW \
|
|
|
|
dst += _vm->_screenWidth; \
|
|
|
|
if (--h == 0) { \
|
|
|
|
if (!--x) \
|
|
|
|
return; \
|
|
|
|
dst -= _vertStripNextInc; \
|
|
|
|
h = height; \
|
|
|
|
}
|
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++;
|
2002-12-16 01:25:21 +00:00
|
|
|
NEXT_ROW
|
|
|
|
}
|
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 {
|
|
|
|
*dst = color;
|
2002-12-16 01:25:21 +00:00
|
|
|
NEXT_ROW
|
|
|
|
} 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++) {
|
|
|
|
*dst = (run * 16 + color);
|
2002-12-16 01:25:21 +00:00
|
|
|
NEXT_ROW
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
*dst = (run * 16 + color);
|
2002-12-16 01:25:21 +00:00
|
|
|
NEXT_ROW
|
|
|
|
}
|
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) {
|
|
|
|
*dst = local_palette[color];
|
2002-12-16 01:25:21 +00:00
|
|
|
NEXT_ROW
|
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
uint run = color - numcolors + 1;
|
|
|
|
color = *src++;
|
|
|
|
do {
|
|
|
|
*dst = color;
|
2002-12-16 01:25:21 +00:00
|
|
|
NEXT_ROW
|
|
|
|
} 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 {
|
|
|
|
*dst = 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++) {
|
2002-12-16 01:25:21 +00:00
|
|
|
READ_256BIT
|
|
|
|
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++) {
|
2002-12-16 01:25:21 +00:00
|
|
|
READ_256BIT
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#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-03-06 17:58:13 +00:00
|
|
|
void Scumm::fadeIn(int effect) {
|
2003-05-24 16:11:47 +00:00
|
|
|
|
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) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
transitionEffect(effect - 1);
|
|
|
|
break;
|
|
|
|
case 128:
|
|
|
|
unkScreenEffect6();
|
|
|
|
break;
|
|
|
|
case 130:
|
|
|
|
case 131:
|
|
|
|
case 132:
|
|
|
|
case 133:
|
|
|
|
scrollEffect(133 - effect);
|
|
|
|
break;
|
|
|
|
case 134:
|
|
|
|
dissolveEffect(1, 1);
|
|
|
|
break;
|
|
|
|
case 135:
|
|
|
|
unkScreenEffect5(1);
|
|
|
|
break;
|
|
|
|
case 129:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
warning("Unknown screen effect, %d", effect);
|
|
|
|
}
|
|
|
|
_screenEffectFlag = true;
|
2001-10-17 10:07:40 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::fadeOut(int effect) {
|
2002-12-15 23:40:37 +00:00
|
|
|
VirtScreen *vs;
|
2001-10-17 10:07:40 +00:00
|
|
|
|
2003-06-01 14:30:26 +00:00
|
|
|
virtscr[0].setDirtyRange(0, 0);
|
2002-12-15 23:40:37 +00:00
|
|
|
if (!(_features & GF_AFTER_V7))
|
|
|
|
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
|
|
|
|
vs = &virtscr[0];
|
|
|
|
memset(vs->screenPtr + vs->xstart, 0, vs->size);
|
|
|
|
|
|
|
|
// Fade to black with the specified effect, if any.
|
|
|
|
switch (effect) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
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-01 14:30:26 +00:00
|
|
|
virtscr[0].setDirtyRange(0, vs->height);
|
2003-05-24 16:11:47 +00:00
|
|
|
updateDirtyScreen(0);
|
|
|
|
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-03-06 17:58:13 +00:00
|
|
|
void Scumm::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;
|
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)
|
|
|
|
j = (virtscr[0].height >> 3) - 1;
|
2001-10-17 10:07:40 +00:00
|
|
|
tab_2[i] = j;
|
|
|
|
}
|
|
|
|
|
|
|
|
bottom = virtscr[0].height >> 3;
|
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) {
|
2002-10-24 06:28:54 +00:00
|
|
|
if (l >= 0 && l < gdi._numStrips && (uint) t < (uint) bottom) {
|
2002-04-11 17:19:16 +00:00
|
|
|
virtscr[0].tdirty[l] = t << 3;
|
|
|
|
virtscr[0].bdirty[l] = (t + 1) << 3;
|
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;
|
|
|
|
virtscr[0].tdirty[l] = t << 3;
|
|
|
|
virtscr[0].bdirty[l] = (b + 1) << 3;
|
2001-10-17 10:07:40 +00:00
|
|
|
}
|
|
|
|
updateDirtyScreen(0);
|
|
|
|
}
|
|
|
|
|
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.
|
2002-04-12 21:26:59 +00:00
|
|
|
_system->update_screen();
|
|
|
|
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
|
|
|
|
*/
|
2002-08-25 18:40:23 +00:00
|
|
|
void Scumm::dissolveEffect(int width, int height) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
// When used used correctly, vs->width % width and vs->height % height
|
|
|
|
// 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
|
|
|
|
|
|
|
|
for (i = 0; i < vs->size; i++)
|
|
|
|
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
|
|
|
|
|
|
|
// Speed up the effect for Loom
|
|
|
|
if (_gameId == GID_LOOM256)
|
|
|
|
blits_before_refresh *= 4;
|
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;
|
2002-08-31 14:27:33 +00:00
|
|
|
_system->copy_rect(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;
|
|
|
|
_system->update_screen();
|
|
|
|
waitForTimer(30);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(offsets);
|
|
|
|
|
|
|
|
if (blits != 0) {
|
|
|
|
_system->update_screen();
|
|
|
|
waitForTimer(30);
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
void Scumm::scrollEffect(int dir) {
|
|
|
|
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);
|
|
|
|
_system->copy_rect(vs->screenPtr + vs->xstart + (y - step) * vs->width,
|
|
|
|
vs->width,
|
|
|
|
0, vs->height - step,
|
|
|
|
vs->width, step);
|
|
|
|
_system->update_screen();
|
|
|
|
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);
|
|
|
|
_system->copy_rect(vs->screenPtr + vs->xstart + vs->width * (vs->height-y),
|
|
|
|
vs->width,
|
|
|
|
0, 0,
|
|
|
|
vs->width, step);
|
|
|
|
_system->update_screen();
|
|
|
|
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);
|
|
|
|
_system->copy_rect(vs->screenPtr + vs->xstart + x - step,
|
|
|
|
vs->width,
|
|
|
|
vs->width - step, 0,
|
|
|
|
step, vs->height);
|
|
|
|
_system->update_screen();
|
|
|
|
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);
|
|
|
|
_system->copy_rect(vs->screenPtr + vs->xstart + vs->width - x,
|
|
|
|
vs->width,
|
|
|
|
0, 0,
|
|
|
|
step, vs->height);
|
|
|
|
_system->update_screen();
|
|
|
|
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
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
void Scumm::unkScreenEffect6() {
|
|
|
|
if (_gameId == GID_LOOM256)
|
|
|
|
dissolveEffect(1, 1);
|
|
|
|
else
|
|
|
|
dissolveEffect(8, 4);
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
void Scumm::unkScreenEffect5(int a) {
|
|
|
|
// 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
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
/* XXX: not implemented */
|
|
|
|
warning("stub unkScreenEffect(%d)", a);
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::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
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
#pragma mark -
|
2002-12-16 19:53:41 +00:00
|
|
|
#pragma mark --- Palette ---
|
2002-12-15 23:40:37 +00:00
|
|
|
#pragma mark -
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-05-03 20:49:53 +00:00
|
|
|
void Scumm::setupEGAPalette() {
|
|
|
|
setPalColor( 0, 0, 0, 0);
|
|
|
|
setPalColor( 1, 0, 0, 168);
|
|
|
|
setPalColor( 2, 0, 168, 0);
|
|
|
|
setPalColor( 3, 0, 168, 168);
|
|
|
|
setPalColor( 4, 168, 0, 0);
|
|
|
|
setPalColor( 5, 168, 0, 168);
|
|
|
|
setPalColor( 6, 168, 84, 0);
|
|
|
|
setPalColor( 7, 168, 168, 168);
|
|
|
|
setPalColor( 8, 84, 84, 84);
|
2003-05-14 14:07:11 +00:00
|
|
|
setPalColor( 9, 84, 84, 252);
|
2003-05-03 20:49:53 +00:00
|
|
|
setPalColor(10, 0, 252, 0);
|
|
|
|
setPalColor(11, 0, 252, 252);
|
|
|
|
setPalColor(12, 252, 84, 84);
|
|
|
|
setPalColor(13, 252, 0, 252);
|
|
|
|
setPalColor(14, 252, 252, 0);
|
|
|
|
setPalColor(15, 252, 252, 252);
|
|
|
|
}
|
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
void Scumm::setPaletteFromPtr(const byte *ptr) {
|
2002-12-15 23:40:37 +00:00
|
|
|
int i;
|
|
|
|
byte *dest, r, g, b;
|
|
|
|
int numcolor;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
if (_features & GF_SMALL_HEADER) {
|
|
|
|
if (_features & GF_OLD256)
|
|
|
|
numcolor = 256;
|
|
|
|
else
|
|
|
|
numcolor = READ_LE_UINT16(ptr + 6) / 3;
|
|
|
|
ptr += 8;
|
|
|
|
} else {
|
|
|
|
numcolor = getResourceDataSize(ptr) / 3;
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
checkRange(256, 0, numcolor, "Too many colors (%d) in Palette");
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
dest = _currentPalette;
|
|
|
|
|
|
|
|
for (i = 0; i < numcolor; i++) {
|
|
|
|
r = *ptr++;
|
|
|
|
g = *ptr++;
|
|
|
|
b = *ptr++;
|
|
|
|
|
|
|
|
// This comparison might look wierd, but it's what the disassembly (DOTT) says!
|
|
|
|
// FIXME: Fingolfin still thinks it looks weird: the value 252 = 4*63 clearly comes from
|
|
|
|
// the days 6/6/6 palettes were used, OK. But it breaks MonkeyVGA, so I had to add a
|
|
|
|
// check for that. And somebody before me added a check for V7 games, turning this
|
|
|
|
// off there, too... I wonder if it hurts other games, too? What exactly is broken
|
|
|
|
// if we remove this patch?
|
|
|
|
if ((_gameId == GID_MONKEY_VGA) || (_features & GF_AFTER_V7) || (i <= 15 || r < 252 || g < 252 || b < 252)) {
|
|
|
|
*dest++ = r;
|
|
|
|
*dest++ = g;
|
|
|
|
*dest++ = b;
|
|
|
|
} else {
|
|
|
|
dest += 3;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-15 23:40:37 +00:00
|
|
|
setDirtyColors(0, numcolor - 1);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::setPaletteFromRes() {
|
2002-12-15 23:40:37 +00:00
|
|
|
byte *ptr;
|
|
|
|
ptr = getResourceAddress(rtRoom, _roomResource) + _CLUT_offs;
|
|
|
|
setPaletteFromPtr(ptr);
|
|
|
|
}
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::setDirtyColors(int min, int max) {
|
2002-12-15 23:40:37 +00:00
|
|
|
if (_palDirtyMin > min)
|
|
|
|
_palDirtyMin = min;
|
|
|
|
if (_palDirtyMax < max)
|
|
|
|
_palDirtyMax = max;
|
|
|
|
}
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
void Scumm::initCycl(const byte *ptr) {
|
2002-12-15 23:40:37 +00:00
|
|
|
int j;
|
|
|
|
ColorCycle *cycl;
|
|
|
|
|
|
|
|
memset(_colorCycle, 0, sizeof(_colorCycle));
|
|
|
|
|
|
|
|
while ((j = *ptr++) != 0) {
|
|
|
|
if (j < 1 || j > 16) {
|
|
|
|
error("Invalid color cycle index %d", j);
|
2002-03-05 23:41:41 +00:00
|
|
|
}
|
2002-12-15 23:40:37 +00:00
|
|
|
cycl = &_colorCycle[j - 1];
|
|
|
|
|
|
|
|
ptr += 2;
|
|
|
|
cycl->counter = 0;
|
|
|
|
cycl->delay = 16384 / READ_BE_UINT16_UNALIGNED(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
cycl->flags = READ_BE_UINT16_UNALIGNED(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
cycl->start = *ptr++;
|
|
|
|
cycl->end = *ptr++;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
2002-10-24 13:18:28 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::stopCycle(int i) {
|
2002-12-15 23:40:37 +00:00
|
|
|
ColorCycle *cycl;
|
|
|
|
|
|
|
|
checkRange(16, 0, i, "Stop Cycle %d Out Of Range");
|
|
|
|
if (i != 0) {
|
|
|
|
_colorCycle[i - 1].delay = 0;
|
|
|
|
return;
|
|
|
|
}
|
2002-12-15 21:59:59 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
for (i = 0, cycl = _colorCycle; i < 16; i++, cycl++)
|
|
|
|
cycl->delay = 0;
|
|
|
|
}
|
2002-12-15 21:59:59 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::cyclePalette() {
|
2002-12-15 23:40:37 +00:00
|
|
|
ColorCycle *cycl;
|
|
|
|
int valueToAdd;
|
|
|
|
int i, num;
|
|
|
|
byte *start, *end;
|
|
|
|
byte tmp[3];
|
2002-12-15 21:59:59 +00:00
|
|
|
|
2003-05-10 22:35:12 +00:00
|
|
|
if (VAR_TIMER == 0xFF) {
|
2003-05-08 20:37:06 +00:00
|
|
|
// FIXME - no idea if this is right :-/
|
2003-05-10 22:35:12 +00:00
|
|
|
// Needed for both V2 and V8 at this time
|
2003-05-08 15:48:50 +00:00
|
|
|
valueToAdd = VAR(VAR_TIMER_NEXT);
|
2003-05-08 20:37:06 +00:00
|
|
|
} else {
|
|
|
|
valueToAdd = VAR(VAR_TIMER);
|
|
|
|
if (valueToAdd < VAR(VAR_TIMER_NEXT))
|
|
|
|
valueToAdd = VAR(VAR_TIMER_NEXT);
|
|
|
|
}
|
2002-12-15 21:59:59 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
if (!_colorCycle) // FIXME
|
|
|
|
return;
|
2002-12-15 21:59:59 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
for (i = 0, cycl = _colorCycle; i < 16; i++, cycl++) {
|
|
|
|
if (cycl->delay && (cycl->counter += valueToAdd) >= cycl->delay) {
|
|
|
|
do {
|
|
|
|
cycl->counter -= cycl->delay;
|
|
|
|
} while (cycl->delay <= cycl->counter);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
setDirtyColors(cycl->start, cycl->end);
|
|
|
|
moveMemInPalRes(cycl->start, cycl->end, cycl->flags & 2);
|
|
|
|
start = &_currentPalette[cycl->start * 3];
|
|
|
|
end = &_currentPalette[cycl->end * 3];
|
2002-08-15 20:12:15 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
num = cycl->end - cycl->start;
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
if (!(cycl->flags & 2)) {
|
|
|
|
memmove(tmp, end, 3);
|
|
|
|
memmove(start + 3, start, num * 3);
|
|
|
|
memmove(start, tmp, 3);
|
|
|
|
} else {
|
|
|
|
memmove(tmp, start, 3);
|
|
|
|
memmove(start, start + 3, num * 3);
|
|
|
|
memmove(end, tmp, 3);
|
|
|
|
}
|
|
|
|
}
|
2002-03-05 23:41:41 +00:00
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/**
|
|
|
|
* Perform color cycling on the palManipulate data, too, otherwise
|
|
|
|
* color cycling will be disturbed by the palette fade.
|
|
|
|
*/
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::moveMemInPalRes(int start, int end, byte direction) {
|
2002-12-15 23:40:37 +00:00
|
|
|
byte *startptr, *endptr;
|
|
|
|
byte *startptr2, *endptr2;
|
|
|
|
int num;
|
|
|
|
byte tmp[6];
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
if (!_palManipCounter)
|
|
|
|
return;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
startptr = _palManipPalette + start * 3;
|
|
|
|
endptr = _palManipPalette + end * 3;
|
|
|
|
startptr2 = _palManipIntermediatePal + start * 6;
|
|
|
|
endptr2 = _palManipIntermediatePal + end * 6;
|
|
|
|
num = end - start;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
if (!endptr) {
|
2003-05-18 21:14:50 +00:00
|
|
|
warning("moveMemInPalRes(%d,%d): Bad end pointer", start, end);
|
2002-12-15 23:40:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!direction) {
|
|
|
|
memmove(tmp, endptr, 3);
|
|
|
|
memmove(startptr + 3, startptr, num * 3);
|
|
|
|
memmove(startptr, tmp, 3);
|
|
|
|
memmove(tmp, endptr2, 6);
|
|
|
|
memmove(startptr2 + 6, startptr2, num * 6);
|
|
|
|
memmove(startptr2, tmp, 6);
|
|
|
|
} else {
|
|
|
|
memmove(tmp, startptr, 3);
|
|
|
|
memmove(startptr, startptr + 3, num * 3);
|
|
|
|
memmove(endptr, tmp, 3);
|
|
|
|
memmove(tmp, startptr2, 6);
|
|
|
|
memmove(startptr2, startptr2 + 6, num * 6);
|
|
|
|
memmove(endptr2, tmp, 6);
|
2002-03-05 23:41:41 +00:00
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::palManipulateInit(int start, int end, int string_id, int time) {
|
2002-09-24 15:46:09 +00:00
|
|
|
byte *pal, *target, *between;
|
|
|
|
byte *string1, *string2, *string3;
|
|
|
|
int i;
|
|
|
|
|
2002-10-01 16:58:26 +00:00
|
|
|
string1 = getStringAddress(string_id);
|
|
|
|
string2 = getStringAddress(string_id + 1);
|
|
|
|
string3 = getStringAddress(string_id + 2);
|
|
|
|
if (!string1 || !string2 || !string3) {
|
2003-05-18 21:14:50 +00:00
|
|
|
warning("palManipulateInit(%d,%d,%d,%d): Cannot obtain string resources %d, %d and %d",
|
2002-10-01 16:58:26 +00:00
|
|
|
start, end, string_id, time, string_id, string_id + 1, string_id + 2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
string1+=start;
|
|
|
|
string2+=start;
|
|
|
|
string3+=start;
|
|
|
|
|
2002-08-29 20:01:27 +00:00
|
|
|
_palManipStart = start;
|
|
|
|
_palManipEnd = end;
|
2002-09-13 11:54:59 +00:00
|
|
|
_palManipCounter = 0;
|
2002-09-24 15:46:09 +00:00
|
|
|
|
|
|
|
if (!_palManipPalette)
|
|
|
|
_palManipPalette = (byte *)calloc(0x300, 1);
|
|
|
|
if (!_palManipIntermediatePal)
|
|
|
|
_palManipIntermediatePal = (byte *)calloc(0x600, 1);
|
|
|
|
|
|
|
|
pal = _currentPalette + start * 3;
|
|
|
|
target = _palManipPalette + start * 3;
|
|
|
|
between = _palManipIntermediatePal + start * 6;
|
|
|
|
|
|
|
|
for (i = start; i < end; ++i) {
|
|
|
|
*target++ = *string1++;
|
|
|
|
*target++ = *string2++;
|
|
|
|
*target++ = *string3++;
|
2003-03-06 17:58:13 +00:00
|
|
|
*(uint16 *)between = ((uint16) *pal++) << 8;
|
2002-09-24 15:46:09 +00:00
|
|
|
between += 2;
|
2003-03-06 17:58:13 +00:00
|
|
|
*(uint16 *)between = ((uint16) *pal++) << 8;
|
2002-09-24 15:46:09 +00:00
|
|
|
between += 2;
|
2003-03-06 17:58:13 +00:00
|
|
|
*(uint16 *)between = ((uint16) *pal++) << 8;
|
2002-09-24 15:46:09 +00:00
|
|
|
between += 2;
|
2002-09-13 11:54:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_palManipCounter = time;
|
2002-08-29 20:01:27 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::palManipulate() {
|
2002-09-24 15:46:09 +00:00
|
|
|
byte *target, *pal, *between;
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, j;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-09-24 15:46:09 +00:00
|
|
|
if (!_palManipCounter || !_palManipPalette || !_palManipIntermediatePal)
|
2002-08-29 20:01:27 +00:00
|
|
|
return;
|
|
|
|
|
2002-09-24 15:46:09 +00:00
|
|
|
target = _palManipPalette + _palManipStart * 3;
|
2001-10-09 14:30:12 +00:00
|
|
|
pal = _currentPalette + _palManipStart * 3;
|
2002-09-24 15:46:09 +00:00
|
|
|
between = _palManipIntermediatePal + _palManipStart * 6;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-09-24 15:46:09 +00:00
|
|
|
for (i = _palManipStart; i < _palManipEnd; ++i) {
|
|
|
|
j = (*((uint16 *)between) += ((*target++ << 8) - *((uint16 *)between)) / _palManipCounter);
|
2002-04-11 17:19:16 +00:00
|
|
|
*pal++ = j >> 8;
|
2002-09-24 15:46:09 +00:00
|
|
|
between += 2;
|
|
|
|
j = (*((uint16 *)between) += ((*target++ << 8) - *((uint16 *)between)) / _palManipCounter);
|
2002-04-11 17:19:16 +00:00
|
|
|
*pal++ = j >> 8;
|
2002-09-24 15:46:09 +00:00
|
|
|
between += 2;
|
|
|
|
j = (*((uint16 *)between) += ((*target++ << 8) - *((uint16 *)between)) / _palManipCounter);
|
2002-04-11 17:19:16 +00:00
|
|
|
*pal++ = j >> 8;
|
2002-09-24 15:46:09 +00:00
|
|
|
between += 2;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
setDirtyColors(_palManipStart, _palManipEnd);
|
2002-08-29 20:01:27 +00:00
|
|
|
_palManipCounter--;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::setupShadowPalette(int slot, int redScale, int greenScale, int blueScale, int startColor, int endColor) {
|
2002-12-09 02:14:17 +00:00
|
|
|
byte *table;
|
|
|
|
int i;
|
|
|
|
byte *curpal;
|
|
|
|
|
|
|
|
if (slot < 0 || slot > 7)
|
|
|
|
error("setupShadowPalette: invalid slot %d", slot);
|
|
|
|
|
|
|
|
if (startColor < 0 || startColor > 255 || endColor < 0 || startColor > 255 || endColor < startColor)
|
|
|
|
error("setupShadowPalette: invalid range from %d to %d", startColor, endColor);
|
|
|
|
|
|
|
|
table = _shadowPalette + slot * 256;
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
table[i] = i;
|
|
|
|
|
|
|
|
table += startColor;
|
|
|
|
curpal = _currentPalette + startColor * 3;
|
|
|
|
for (i = startColor; i <= endColor; i++) {
|
|
|
|
*table++ = remapPaletteColor((curpal[0] * redScale) >> 8,
|
2002-12-27 14:04:25 +00:00
|
|
|
(curpal[1] * greenScale) >> 8,
|
|
|
|
(curpal[2] * blueScale) >> 8,
|
|
|
|
(uint) - 1);
|
2002-12-09 02:14:17 +00:00
|
|
|
curpal += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::setupShadowPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor) {
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *basepal = getPalettePtr();
|
|
|
|
const byte *pal = basepal;
|
|
|
|
const byte *compareptr;
|
2002-08-29 20:01:27 +00:00
|
|
|
byte *table = _shadowPalette;
|
|
|
|
int i;
|
|
|
|
|
2002-09-13 23:37:22 +00:00
|
|
|
// This is a correction of the patch supplied for BUG #588501.
|
|
|
|
// It has been tested in all four known rooms where unkRoomFunc3 is used:
|
2002-08-29 20:01:27 +00:00
|
|
|
//
|
2002-09-13 23:37:22 +00:00
|
|
|
// 1) FOA Room 53: subway departing Knossos for Atlantis.
|
|
|
|
// 2) FOA Room 48: subway crashing into the Atlantis entrance area
|
|
|
|
// 3) FOA Room 82: boat/sub shadows while diving near Thera
|
|
|
|
// 4) FOA Room 23: the big machine room inside Atlantis
|
2002-08-29 20:01:27 +00:00
|
|
|
//
|
2002-09-13 23:37:22 +00:00
|
|
|
// The implementation behaves well in all tests.
|
|
|
|
// Pixel comparisons show that the resulting palette entries being
|
|
|
|
// derived from the shadow palette generated here occassionally differ
|
|
|
|
// slightly from the ones derived in the LEC executable.
|
|
|
|
// Not sure yet why, but the differences are VERY minor.
|
2002-08-29 20:01:27 +00:00
|
|
|
//
|
2002-09-13 23:37:22 +00:00
|
|
|
// There seems to be no explanation for why this function is called
|
|
|
|
// from within Room 23 (the big machine), as it has no shadow effects
|
|
|
|
// and thus doesn't result in any visual differences.
|
|
|
|
|
2002-08-29 20:01:27 +00:00
|
|
|
for (i = 0; i <= 255; i++) {
|
2002-12-09 02:14:17 +00:00
|
|
|
int r = (int) (*pal++ * redScale) >> 8;
|
|
|
|
int g = (int) (*pal++ * greenScale) >> 8;
|
|
|
|
int b = (int) (*pal++ * blueScale) >> 8;
|
2002-08-29 20:01:27 +00:00
|
|
|
|
2002-09-13 23:37:22 +00:00
|
|
|
// The following functionality is similar to remapPaletteColor, except
|
|
|
|
// 1) we have to work off the original CLUT rather than the current palette, and
|
|
|
|
// 2) the target shadow palette entries must be bounded to the upper and lower
|
|
|
|
// bounds provided by the opcode. (This becomes significant in Room 48, but
|
|
|
|
// is not an issue in all other known case studies.)
|
|
|
|
int j;
|
|
|
|
int ar, ag, ab;
|
2002-12-10 23:44:59 +00:00
|
|
|
uint sum, bestsum, bestitem = 0;
|
2002-09-13 23:37:22 +00:00
|
|
|
|
|
|
|
if (r > 255)
|
|
|
|
r = 255;
|
|
|
|
if (g > 255)
|
|
|
|
g = 255;
|
|
|
|
if (b > 255)
|
|
|
|
b = 255;
|
|
|
|
|
2002-12-09 02:14:17 +00:00
|
|
|
bestsum = (uint)-1;
|
2002-09-13 23:37:22 +00:00
|
|
|
|
|
|
|
r &= ~3;
|
|
|
|
g &= ~3;
|
|
|
|
b &= ~3;
|
|
|
|
|
2002-12-09 02:14:17 +00:00
|
|
|
compareptr = basepal + startColor * 3;
|
|
|
|
for (j = startColor; j <= endColor; j++, compareptr += 3) {
|
2002-09-13 23:37:22 +00:00
|
|
|
ar = compareptr[0] & ~3;
|
|
|
|
ag = compareptr[1] & ~3;
|
|
|
|
ab = compareptr[2] & ~3;
|
|
|
|
if (ar == r && ag == g && ab == b) {
|
|
|
|
bestitem = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-12-10 23:44:59 +00:00
|
|
|
sum = colorWeight(ar - r, ag - g, ab - b);
|
2002-09-13 23:37:22 +00:00
|
|
|
|
|
|
|
if (sum < bestsum) {
|
|
|
|
bestsum = sum;
|
|
|
|
bestitem = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*table++ = bestitem;
|
2002-08-29 20:01:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/** This function create the specialPalette used for semi-transparency in SamnMax */
|
2002-12-09 02:14:17 +00:00
|
|
|
void Scumm::createSpecialPalette(int16 from, int16 to, int16 redScale, int16 greenScale, int16 blueScale,
|
2003-03-06 17:58:13 +00:00
|
|
|
int16 startColor, int16 endColor) {
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *palPtr, *curPtr;
|
|
|
|
const byte *searchPtr;
|
2002-12-09 02:14:17 +00:00
|
|
|
|
|
|
|
uint bestResult;
|
|
|
|
uint currentResult;
|
|
|
|
|
|
|
|
byte currentIndex;
|
|
|
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
palPtr = getPalettePtr();
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
_proc_special_palette[i] = i;
|
|
|
|
|
|
|
|
curPtr = palPtr + startColor * 3;
|
|
|
|
|
|
|
|
for (i = startColor; i < endColor; i++) {
|
|
|
|
int r = (int) (*curPtr++ * redScale) >> 8;
|
|
|
|
int g = (int) (*curPtr++ * greenScale) >> 8;
|
|
|
|
int b = (int) (*curPtr++ * blueScale) >> 8;
|
|
|
|
|
2003-05-19 11:34:13 +00:00
|
|
|
if (r > 255)
|
|
|
|
r = 255;
|
|
|
|
if (g > 255)
|
|
|
|
g = 255;
|
|
|
|
if (b > 255)
|
|
|
|
b = 255;
|
|
|
|
|
2003-05-18 19:51:50 +00:00
|
|
|
searchPtr = palPtr + from * 3;
|
2003-05-19 11:34:13 +00:00
|
|
|
bestResult = (uint)-1;
|
2003-05-18 23:45:34 +00:00
|
|
|
currentIndex = (byte) from;
|
2002-12-09 02:14:17 +00:00
|
|
|
|
2003-05-19 11:34:13 +00:00
|
|
|
for (j = from; j <= to; j++) {
|
2002-12-09 02:14:17 +00:00
|
|
|
int ar = (*searchPtr++);
|
|
|
|
int ag = (*searchPtr++);
|
|
|
|
int ab = (*searchPtr++);
|
|
|
|
|
2002-12-10 23:44:59 +00:00
|
|
|
currentResult = colorWeight(ar - r, ag - g, ab - b);
|
2002-12-09 02:14:17 +00:00
|
|
|
|
|
|
|
if (currentResult < bestResult) {
|
|
|
|
_proc_special_palette[i] = currentIndex;
|
|
|
|
bestResult = currentResult;
|
|
|
|
}
|
|
|
|
currentIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::darkenPalette(int redScale, int greenScale, int blueScale, int startColor, int endColor) {
|
2003-03-04 02:43:43 +00:00
|
|
|
if (_roomResource == 0) // FIXME - HACK to get COMI demo working
|
|
|
|
return;
|
|
|
|
|
2002-12-09 02:14:17 +00:00
|
|
|
if (startColor <= endColor) {
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *cptr;
|
|
|
|
byte *cur;
|
2002-12-09 02:14:17 +00:00
|
|
|
int j;
|
|
|
|
int color;
|
|
|
|
|
|
|
|
cptr = getPalettePtr() + startColor * 3;
|
|
|
|
cur = _currentPalette + startColor * 3;
|
|
|
|
|
|
|
|
for (j = startColor; j <= endColor; j++) {
|
|
|
|
color = *cptr++;
|
|
|
|
color = color * redScale / 0xFF;
|
|
|
|
if (color > 255)
|
|
|
|
color = 255;
|
|
|
|
*cur++ = color;
|
|
|
|
|
|
|
|
color = *cptr++;
|
|
|
|
color = color * greenScale / 0xFF;
|
|
|
|
if (color > 255)
|
|
|
|
color = 255;
|
|
|
|
*cur++ = color;
|
|
|
|
|
|
|
|
color = *cptr++;
|
|
|
|
color = color * blueScale / 0xFF;
|
|
|
|
if (color > 255)
|
|
|
|
color = 255;
|
|
|
|
*cur++ = color;
|
|
|
|
}
|
|
|
|
setDirtyColors(startColor, endColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-13 02:23:55 +00:00
|
|
|
static double value(double n1, double n2, double hue)
|
|
|
|
{
|
|
|
|
if (hue > 360.0)
|
|
|
|
hue = hue - 360.0;
|
|
|
|
else if (hue < 0.0)
|
|
|
|
hue = hue + 360.0;
|
|
|
|
|
|
|
|
if (hue < 60.0)
|
|
|
|
return n1 + (n2 - n1) * hue / 60.0;
|
|
|
|
if (hue < 180.0)
|
|
|
|
return n2;
|
|
|
|
if (hue < 240.0)
|
|
|
|
return n1 + (n2 - n1) * (240.0 - hue) / 60.0;
|
|
|
|
return n1;
|
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/**
|
|
|
|
* This function scales the HSL (Hue, Saturation and Lightness)
|
|
|
|
* components of the palette colours. It's used in CMI when Guybrush
|
|
|
|
* walks from the beach towards the swamp.
|
|
|
|
*
|
|
|
|
* I don't know if this function is correct, but the output seems to
|
|
|
|
* match the original fairly closely.
|
|
|
|
*
|
|
|
|
* @todo Rewrite desaturatePalette using integer arithmetics only?
|
|
|
|
*/
|
2003-03-13 02:23:55 +00:00
|
|
|
void Scumm::desaturatePalette(int hueScale, int satScale, int lightScale, int startColor, int endColor)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (startColor <= endColor) {
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *cptr;
|
|
|
|
byte *cur;
|
2003-03-13 02:23:55 +00:00
|
|
|
int j;
|
|
|
|
|
|
|
|
cptr = getPalettePtr() + startColor * 3;
|
|
|
|
cur = _currentPalette + startColor * 3;
|
|
|
|
|
|
|
|
for (j = startColor; j <= endColor; j++) {
|
|
|
|
double R, G, B;
|
|
|
|
double H, S, L;
|
|
|
|
double min, max;
|
|
|
|
int red, green, blue;
|
|
|
|
|
|
|
|
R = ((double) *cptr++) / 255.0;
|
|
|
|
G = ((double) *cptr++) / 255.0;
|
|
|
|
B = ((double) *cptr++) / 255.0;
|
|
|
|
|
|
|
|
// RGB to HLS (Foley and VanDam)
|
|
|
|
|
|
|
|
min = MIN(R, MIN(G, B));
|
|
|
|
max = MAX(R, MAX(G, B));
|
|
|
|
|
|
|
|
L = (max + min) / 2.0;
|
|
|
|
|
|
|
|
if (max != min) {
|
|
|
|
if (L <= 0.5)
|
|
|
|
S = (max - min) / (max + min);
|
|
|
|
else
|
|
|
|
S = (max - min) / (2.0 - max - min);
|
|
|
|
|
|
|
|
if (R == max)
|
|
|
|
H = (G - B) / (max - min);
|
|
|
|
else if (G == max)
|
|
|
|
H = 2.0 + (B - R) / (max - min);
|
|
|
|
else
|
|
|
|
H = 4.0 + (R - G) / (max - min);
|
|
|
|
|
|
|
|
H = H * 60.0;
|
|
|
|
if (H < 0.0)
|
|
|
|
H = H + 360.0;
|
|
|
|
} else {
|
|
|
|
S = 0.0;
|
|
|
|
H = 0.0; // undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scale the result
|
|
|
|
|
|
|
|
H = (H * hueScale) / 255.0;
|
|
|
|
S = (S * satScale) / 255.0;
|
|
|
|
L = (L * lightScale) / 255.0;
|
|
|
|
|
|
|
|
// HLS to RGB (Foley and VanDam)
|
|
|
|
|
|
|
|
double m1, m2;
|
|
|
|
|
|
|
|
if (min != max) {
|
|
|
|
if (L <= 0.5)
|
|
|
|
m2 = L * (1 + S);
|
|
|
|
else
|
|
|
|
m2 = L + S - L * S;
|
|
|
|
|
|
|
|
m1 = 2.0 * L - m2;
|
|
|
|
|
|
|
|
R = value(m1, m2, H + 120);
|
|
|
|
G = value(m1, m2, H);
|
|
|
|
B = value(m1, m2, H - 120);
|
|
|
|
} else {
|
|
|
|
R = L;
|
|
|
|
G = L;
|
|
|
|
B = L;
|
|
|
|
}
|
|
|
|
|
|
|
|
red = (int) (255.0 * R + 0.5);
|
|
|
|
green = (int) (255.0 * G + 0.5);
|
|
|
|
blue = (int) (255.0 * B + 0.5);
|
|
|
|
|
|
|
|
*cur++ = red;
|
|
|
|
*cur++ = green;
|
|
|
|
*cur++ = blue;
|
|
|
|
}
|
|
|
|
|
|
|
|
setDirtyColors(startColor, endColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::remapPaletteColor(int r, int g, int b, uint threshold) {
|
2002-12-10 23:44:59 +00:00
|
|
|
int i;
|
|
|
|
int ar, ag, ab;
|
|
|
|
uint sum, bestsum, bestitem = 0;
|
|
|
|
byte *pal = _currentPalette;
|
|
|
|
|
|
|
|
if (r > 255)
|
|
|
|
r = 255;
|
|
|
|
if (g > 255)
|
|
|
|
g = 255;
|
|
|
|
if (b > 255)
|
|
|
|
b = 255;
|
|
|
|
|
|
|
|
bestsum = (uint) - 1;
|
|
|
|
|
|
|
|
r &= ~3;
|
|
|
|
g &= ~3;
|
|
|
|
b &= ~3;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++, pal += 3) {
|
|
|
|
ar = pal[0] & ~3;
|
|
|
|
ag = pal[1] & ~3;
|
|
|
|
ab = pal[2] & ~3;
|
|
|
|
if (ar == r && ag == g && ab == b)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
sum = colorWeight(ar - r, ag - g, ab - b);
|
|
|
|
|
|
|
|
if (sum < bestsum) {
|
|
|
|
bestsum = sum;
|
|
|
|
bestitem = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (threshold != (uint) - 1 && bestsum > colorWeight(threshold, threshold, threshold)) {
|
|
|
|
// Best match exceeded threshold. Try to find an unused palette entry and
|
|
|
|
// use it for our purpose.
|
|
|
|
pal = _currentPalette + (256 - 2) * 3;
|
|
|
|
for (i = 254; i > 48; i--, pal -= 3) {
|
|
|
|
if (pal[0] >= 252 && pal[1] >= 252 && pal[2] >= 252) {
|
|
|
|
setPalColor(i, r, g, b);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bestitem;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::swapPalColors(int a, int b) {
|
2002-04-11 17:19:16 +00:00
|
|
|
byte *ap, *bp;
|
2001-11-11 16:54:45 +00:00
|
|
|
byte t;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if ((uint) a >= 256 || (uint) b >= 256)
|
2001-11-11 16:54:45 +00:00
|
|
|
error("swapPalColors: invalid values, %d, %d", a, b);
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
ap = &_currentPalette[a * 3];
|
|
|
|
bp = &_currentPalette[b * 3];
|
|
|
|
|
|
|
|
t = ap[0];
|
|
|
|
ap[0] = bp[0];
|
|
|
|
bp[0] = t;
|
|
|
|
t = ap[1];
|
|
|
|
ap[1] = bp[1];
|
|
|
|
bp[1] = t;
|
|
|
|
t = ap[2];
|
|
|
|
ap[2] = bp[2];
|
|
|
|
bp[2] = t;
|
2001-11-11 16:54:45 +00:00
|
|
|
|
2002-09-23 15:43:29 +00:00
|
|
|
setDirtyColors(a, a);
|
|
|
|
setDirtyColors(b, b);
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::copyPalColor(int dst, int src) {
|
2002-09-23 15:43:29 +00:00
|
|
|
byte *dp, *sp;
|
|
|
|
|
|
|
|
if ((uint) dst >= 256 || (uint) src >= 256)
|
|
|
|
error("copyPalColor: invalid values, %d, %d", dst, src);
|
|
|
|
|
|
|
|
dp = &_currentPalette[dst * 3];
|
|
|
|
sp = &_currentPalette[src * 3];
|
|
|
|
|
|
|
|
dp[0] = sp[0];
|
|
|
|
dp[1] = sp[1];
|
|
|
|
dp[2] = sp[2];
|
|
|
|
|
|
|
|
setDirtyColors(dst, dst);
|
2001-11-11 16:54:45 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::setPalColor(int idx, int r, int g, int b) {
|
2002-04-11 17:19:16 +00:00
|
|
|
_currentPalette[idx * 3 + 0] = r;
|
|
|
|
_currentPalette[idx * 3 + 1] = g;
|
|
|
|
_currentPalette[idx * 3 + 2] = b;
|
|
|
|
setDirtyColors(idx, idx);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::setPalette(int palindex) {
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *pals;
|
2001-10-26 17:34:50 +00:00
|
|
|
|
|
|
|
_curPalIndex = palindex;
|
|
|
|
pals = getPalettePtr();
|
|
|
|
setPaletteFromPtr(pals);
|
|
|
|
}
|
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *Scumm::findPalInPals(const byte *pal, int idx) {
|
|
|
|
const byte *offs;
|
2002-04-11 17:19:16 +00:00
|
|
|
uint32 size;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
pal = findResource(MKID('WRAP'), pal);
|
2002-04-11 17:19:16 +00:00
|
|
|
if (pal == NULL)
|
2001-10-16 10:01:48 +00:00
|
|
|
return NULL;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
offs = findResourceData(MKID('OFFS'), pal);
|
|
|
|
if (offs == NULL)
|
2001-10-16 10:01:48 +00:00
|
|
|
return NULL;
|
|
|
|
|
2001-12-27 17:51:58 +00:00
|
|
|
size = getResourceDataSize(offs) >> 2;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-03-08 08:42:11 +00:00
|
|
|
if ((uint32)idx >= (uint32)size)
|
2001-10-16 10:01:48 +00:00
|
|
|
return NULL;
|
|
|
|
|
2002-03-08 08:42:11 +00:00
|
|
|
return offs + READ_LE_UINT32(offs + idx * sizeof(uint32));
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *Scumm::getPalettePtr() {
|
|
|
|
const byte *cptr;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
cptr = getResourceAddress(rtRoom, _roomResource);
|
2003-03-04 02:43:43 +00:00
|
|
|
assert(cptr);
|
2001-10-26 17:34:50 +00:00
|
|
|
if (_CLUT_offs) {
|
|
|
|
cptr += _CLUT_offs;
|
|
|
|
} else {
|
|
|
|
cptr = findPalInPals(cptr + _PALS_offs, _curPalIndex);
|
|
|
|
}
|
2003-03-04 02:43:43 +00:00
|
|
|
assert(cptr);
|
2001-10-26 17:34:50 +00:00
|
|
|
return cptr;
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2002-12-15 23:40:37 +00:00
|
|
|
#pragma mark -
|
2002-12-16 19:53:41 +00:00
|
|
|
#pragma mark --- Cursor ---
|
2002-12-15 23:40:37 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::grabCursor(int x, int y, int w, int h) {
|
2001-11-06 20:00:47 +00:00
|
|
|
VirtScreen *vs = findVirtScreen(y);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (vs == NULL) {
|
2001-11-06 20:00:47 +00:00
|
|
|
warning("grabCursor: invalid Y %d", y);
|
2001-10-26 17:34:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-10 21:49:59 +00:00
|
|
|
grabCursor(vs->screenPtr + (y - vs->topline) * _screenWidth + x, w, h);
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2001-11-06 20:00:47 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::grabCursor(byte *ptr, int width, int height) {
|
2001-11-06 20:00:47 +00:00
|
|
|
uint size;
|
|
|
|
byte *dst;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
size = width * height;
|
2001-11-06 20:00:47 +00:00
|
|
|
if (size > sizeof(_grabbedCursor))
|
2001-11-05 19:21:49 +00:00
|
|
|
error("grabCursor: grabbed cursor too big");
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2002-12-04 22:31:36 +00:00
|
|
|
_cursor.width = width;
|
|
|
|
_cursor.height = height;
|
|
|
|
_cursor.animate = 0;
|
2001-11-06 20:00:47 +00:00
|
|
|
|
|
|
|
dst = _grabbedCursor;
|
2002-04-11 17:19:16 +00:00
|
|
|
for (; height; height--) {
|
2001-11-06 20:00:47 +00:00
|
|
|
memcpy(dst, ptr, width);
|
|
|
|
dst += width;
|
2003-05-10 21:49:59 +00:00
|
|
|
ptr += _screenWidth;
|
2001-11-06 20:00:47 +00:00
|
|
|
}
|
2002-07-07 20:32:26 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
updateCursor();
|
2001-11-06 20:00:47 +00:00
|
|
|
}
|
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
void Scumm::useIm01Cursor(const byte *im, int w, int h) {
|
2001-11-06 20:00:47 +00:00
|
|
|
VirtScreen *vs = &virtscr[0];
|
2003-05-28 20:01:47 +00:00
|
|
|
byte *buf, *dst;
|
|
|
|
const byte *src;
|
2003-05-15 21:09:55 +00:00
|
|
|
int i;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
w <<= 3;
|
|
|
|
h <<= 3;
|
|
|
|
|
2003-05-15 21:09:55 +00:00
|
|
|
dst = buf = (byte *) malloc(w * h);
|
|
|
|
src = vs->screenPtr + vs->xstart;
|
|
|
|
|
|
|
|
for (i = 0; i < h; i++) {
|
|
|
|
memcpy(dst, src, w);
|
|
|
|
dst += w;
|
|
|
|
src += _screenWidth;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
drawBox(0, 0, w - 1, h - 1, 0xFF);
|
2001-11-06 20:00:47 +00:00
|
|
|
|
|
|
|
vs->alloctwobuffers = false;
|
2003-05-15 21:31:03 +00:00
|
|
|
gdi.disableZBuffer();
|
2003-05-10 12:59:32 +00:00
|
|
|
gdi.drawBitmap(im, vs, _screenStartStrip, 0, w, h, 0, w >> 3, 0);
|
2001-11-06 20:00:47 +00:00
|
|
|
vs->alloctwobuffers = true;
|
2003-05-15 21:31:03 +00:00
|
|
|
gdi.enableZBuffer();
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2002-03-20 22:58:41 +00:00
|
|
|
grabCursor(vs->screenPtr + vs->xstart, w, h);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-05-15 21:09:55 +00:00
|
|
|
src = buf;
|
|
|
|
dst = vs->screenPtr + vs->xstart;
|
|
|
|
|
|
|
|
for (i = 0; i < h; i++) {
|
|
|
|
memcpy(dst, src, w);
|
|
|
|
dst += _screenWidth;
|
|
|
|
src += w;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(buf);
|
2001-11-06 20:00:47 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::setCursor(int cursor) {
|
2002-12-15 23:40:37 +00:00
|
|
|
if (cursor >= 0 && cursor <= 3)
|
|
|
|
_currentCursor = cursor;
|
|
|
|
else
|
|
|
|
warning("setCursor(%d)", cursor);
|
|
|
|
}
|
|
|
|
|
2003-04-26 13:28:34 +00:00
|
|
|
void Scumm::setCursorHotspot(int x, int y) {
|
2002-12-15 23:40:37 +00:00
|
|
|
_cursor.hotspotX = x;
|
|
|
|
_cursor.hotspotY = y;
|
2003-03-03 01:53:18 +00:00
|
|
|
// FIXME this hacks around offset cursor in the humongous games
|
|
|
|
if (_features & GF_HUMONGOUS) {
|
|
|
|
_cursor.hotspotX += 15;
|
|
|
|
_cursor.hotspotY += 15;
|
|
|
|
}
|
2002-12-15 23:40:37 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::updateCursor() {
|
2002-12-04 22:31:36 +00:00
|
|
|
_system->set_mouse_cursor(_grabbedCursor, _cursor.width, _cursor.height,
|
2003-04-26 13:28:34 +00:00
|
|
|
_cursor.hotspotX, _cursor.hotspotY);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::animateCursor() {
|
2002-12-04 22:31:36 +00:00
|
|
|
if (_cursor.animate) {
|
|
|
|
if (!(_cursor.animateIndex & 0x3)) {
|
|
|
|
decompressDefaultCursor((_cursor.animateIndex >> 2) & 3);
|
2002-04-15 17:45:52 +00:00
|
|
|
}
|
2002-12-04 22:31:36 +00:00
|
|
|
_cursor.animateIndex++;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
void Scumm::useBompCursor(const byte *im, int width, int height) {
|
2001-11-06 20:00:47 +00:00
|
|
|
uint size;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
width <<= 3;
|
|
|
|
height <<= 3;
|
|
|
|
|
2001-11-06 20:00:47 +00:00
|
|
|
size = width * height;
|
|
|
|
if (size > sizeof(_grabbedCursor))
|
2002-12-25 03:48:27 +00:00
|
|
|
error("useBompCursor: cursor too big (%d)", size);
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2002-12-04 22:31:36 +00:00
|
|
|
_cursor.width = width;
|
|
|
|
_cursor.height = height;
|
|
|
|
_cursor.animate = 0;
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2003-05-30 17:52:17 +00:00
|
|
|
// Skip the header
|
|
|
|
if (_features & GF_AFTER_V8) {
|
|
|
|
im += 16;
|
|
|
|
} else {
|
|
|
|
im += 18;
|
|
|
|
}
|
2002-12-25 12:41:41 +00:00
|
|
|
decompressBomp(_grabbedCursor, im, width, height);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
updateCursor();
|
2001-11-06 20:00:47 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::decompressDefaultCursor(int idx) {
|
2002-09-21 14:17:13 +00:00
|
|
|
int i, j;
|
2001-11-06 20:00:47 +00:00
|
|
|
byte color;
|
|
|
|
|
|
|
|
memset(_grabbedCursor, 0xFF, sizeof(_grabbedCursor));
|
|
|
|
|
2002-03-08 08:42:11 +00:00
|
|
|
color = default_cursor_colors[idx];
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-09-21 14:17:13 +00:00
|
|
|
// FIXME: None of the stock cursors are right for Loom. Why is that?
|
|
|
|
|
2003-04-18 20:16:32 +00:00
|
|
|
if ((_gameId == GID_LOOM256) || (_gameId == GID_LOOM)) {
|
2003-04-26 13:28:34 +00:00
|
|
|
int w = 0;
|
2002-09-21 14:17:13 +00:00
|
|
|
|
2002-12-04 22:31:36 +00:00
|
|
|
_cursor.width = 8;
|
|
|
|
_cursor.height = 8;
|
|
|
|
_cursor.hotspotX = 0;
|
|
|
|
_cursor.hotspotY = 0;
|
2003-04-26 13:28:34 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
2002-09-21 14:17:13 +00:00
|
|
|
w += (i >= 6) ? -2 : 1;
|
|
|
|
for (j = 0; j < w; j++)
|
|
|
|
_grabbedCursor[i * 8 + j] = color;
|
|
|
|
}
|
|
|
|
} else {
|
2003-04-30 13:23:31 +00:00
|
|
|
byte currentCursor = _currentCursor;
|
|
|
|
|
|
|
|
#ifdef __PALM_OS__
|
|
|
|
if (_gameId == GID_ZAK256 && currentCursor == 0)
|
|
|
|
currentCursor = 4;
|
|
|
|
#endif
|
|
|
|
|
2002-12-04 22:31:36 +00:00
|
|
|
_cursor.width = 16;
|
|
|
|
_cursor.height = 16;
|
2003-04-30 13:23:31 +00:00
|
|
|
_cursor.hotspotX = default_cursor_hotspots[2 * currentCursor];
|
|
|
|
_cursor.hotspotY = default_cursor_hotspots[2 * currentCursor + 1];
|
2002-09-21 14:17:13 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
for (j = 0; j < 16; j++) {
|
2003-04-30 13:23:31 +00:00
|
|
|
if (default_cursor_images[currentCursor][i] & (1 << j))
|
2002-09-21 14:17:13 +00:00
|
|
|
_grabbedCursor[16 * i + 15 - j] = color;
|
|
|
|
}
|
2002-06-29 10:28:43 +00:00
|
|
|
}
|
2001-11-06 20:00:47 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
updateCursor();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::makeCursorColorTransparent(int a) {
|
2002-09-19 23:06:54 +00:00
|
|
|
int i, size;
|
|
|
|
|
2002-12-04 22:31:36 +00:00
|
|
|
size = _cursor.width * _cursor.height;
|
2002-09-19 23:06:54 +00:00
|
|
|
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
if (_grabbedCursor[i] == (byte)a)
|
|
|
|
_grabbedCursor[i] = 0xFF;
|
|
|
|
|
|
|
|
updateCursor();
|
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-04-30 13:23:31 +00:00
|
|
|
|
|
|
|
#ifdef __PALM_OS__
|
|
|
|
#include "scumm_globals.h" // init globals
|
|
|
|
void Gfx_initGlobals() {
|
|
|
|
GSETPTR(transitionEffects, GBVARS_TRANSITIONEFFECTS_INDEX, TransitionEffect, GBVARS_SCUMM)
|
|
|
|
}
|
|
|
|
void Gfx_releaseGlobals() { GRELEASEPTR(GBVARS_TRANSITIONEFFECTS_INDEX, GBVARS_SCUMM)}
|
|
|
|
#endif
|