2009-10-03 20:49:18 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/timer.h"
|
|
|
|
#include "common/util.h"
|
2009-10-14 15:43:58 +00:00
|
|
|
#include "graphics/surface.h"
|
2009-10-03 20:49:18 +00:00
|
|
|
|
|
|
|
#include "sci/sci.h"
|
|
|
|
#include "sci/engine/state.h"
|
2010-01-05 01:37:57 +00:00
|
|
|
#include "sci/graphics/screen.h"
|
2009-10-03 20:49:18 +00:00
|
|
|
|
|
|
|
namespace Sci {
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
Screen::Screen(ResourceManager *resMan, int16 width, int16 height, bool upscaledHires) :
|
2009-10-31 14:38:25 +00:00
|
|
|
_resMan(resMan), _width(width), _height(height), _upscaledHires(upscaledHires) {
|
2009-10-03 20:49:18 +00:00
|
|
|
|
|
|
|
_pixels = _width * _height;
|
|
|
|
|
2009-10-31 14:38:25 +00:00
|
|
|
_displayWidth = _width;
|
|
|
|
_displayHeight = _height;
|
|
|
|
if (_upscaledHires) {
|
|
|
|
_displayWidth *= 2;
|
|
|
|
_displayHeight *= 2;
|
|
|
|
}
|
2009-10-03 20:49:18 +00:00
|
|
|
_displayPixels = _displayWidth * _displayHeight;
|
|
|
|
|
2009-10-07 22:53:32 +00:00
|
|
|
_visualScreen = (byte *)calloc(_pixels, 1);
|
|
|
|
_priorityScreen = (byte *)calloc(_pixels, 1);
|
|
|
|
_controlScreen = (byte *)calloc(_pixels, 1);
|
|
|
|
_displayScreen = (byte *)calloc(_displayPixels, 1);
|
2009-10-03 20:49:18 +00:00
|
|
|
|
2009-10-07 15:53:34 +00:00
|
|
|
// Sets display screen to be actually displayed
|
|
|
|
_activeScreen = _displayScreen;
|
|
|
|
|
2009-12-09 09:31:07 +00:00
|
|
|
_picNotValid = 0;
|
|
|
|
_picNotValidSci11 = 0;
|
2009-10-15 15:27:08 +00:00
|
|
|
_unditherState = true;
|
2009-10-29 14:16:20 +00:00
|
|
|
|
|
|
|
if (_resMan->isVGA()) {
|
|
|
|
_colorWhite = 255;
|
2009-10-29 20:32:55 +00:00
|
|
|
if (getSciVersion() >= SCI_VERSION_1_1)
|
2009-10-29 14:16:20 +00:00
|
|
|
_colorDefaultVectorData = 255;
|
2009-10-29 20:32:55 +00:00
|
|
|
else
|
2009-10-29 14:16:20 +00:00
|
|
|
_colorDefaultVectorData = 0;
|
|
|
|
} else {
|
|
|
|
_colorWhite = 15;
|
|
|
|
_colorDefaultVectorData = 0;
|
|
|
|
}
|
2009-10-31 10:54:19 +00:00
|
|
|
|
|
|
|
// Initialize the actual screen
|
|
|
|
initGraphics(_displayWidth, _displayHeight, _displayWidth > 320);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
Screen::~Screen() {
|
2009-10-06 12:26:13 +00:00
|
|
|
free(_visualScreen);
|
|
|
|
free(_priorityScreen);
|
|
|
|
free(_controlScreen);
|
|
|
|
free(_displayScreen);
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::copyToScreen() {
|
2009-10-07 15:53:34 +00:00
|
|
|
g_system->copyRectToScreen(_activeScreen, _displayWidth, 0, 0, _displayWidth, _displayHeight);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::copyFromScreen(byte *buffer) {
|
2009-10-14 15:43:58 +00:00
|
|
|
Graphics::Surface *screen;
|
|
|
|
screen = g_system->lockScreen();
|
|
|
|
memcpy(buffer, screen->pixels, _displayWidth * _displayHeight);
|
|
|
|
g_system->unlockScreen();
|
|
|
|
}
|
|
|
|
|
2010-01-06 18:59:39 +00:00
|
|
|
void Screen::syncWithFramebuffer() {
|
|
|
|
Graphics::Surface *screen = g_system->lockScreen();
|
|
|
|
|
|
|
|
memcpy(_displayScreen, screen->pixels, _displayPixels);
|
|
|
|
g_system->unlockScreen();
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::copyRectToScreen(const Common::Rect &rect) {
|
2009-10-31 14:38:25 +00:00
|
|
|
if (!_upscaledHires) {
|
|
|
|
g_system->copyRectToScreen(_activeScreen + rect.top * _displayWidth + rect.left, _displayWidth, rect.left, rect.top, rect.width(), rect.height());
|
|
|
|
} else {
|
|
|
|
g_system->copyRectToScreen(_activeScreen + rect.top * 2 * _displayWidth + rect.left * 2, _displayWidth, rect.left * 2, rect.top * 2, rect.width() * 2, rect.height() * 2);
|
|
|
|
}
|
2009-10-11 17:59:23 +00:00
|
|
|
}
|
|
|
|
|
2010-01-07 10:31:29 +00:00
|
|
|
// This copies a rect to screen w/o scaling adjustment and is only meant to be used on hires graphics used in upscaled hires mode
|
|
|
|
void Screen::copyDisplayRectToScreen(const Common::Rect &rect) {
|
|
|
|
if (!_upscaledHires)
|
|
|
|
error("copyDisplayRectToScreen: not in upscaled hires mode");
|
|
|
|
g_system->copyRectToScreen(_activeScreen + rect.top * _displayWidth + rect.left, _displayWidth, rect.left, rect.top, rect.width(), rect.height());
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::copyRectToScreen(const Common::Rect &rect, int16 x, int16 y) {
|
2009-10-31 14:38:25 +00:00
|
|
|
if (!_upscaledHires) {
|
|
|
|
g_system->copyRectToScreen(_activeScreen + rect.top * _displayWidth + rect.left, _displayWidth, x, y, rect.width(), rect.height());
|
|
|
|
} else {
|
|
|
|
g_system->copyRectToScreen(_activeScreen + rect.top * 2 * _displayWidth + rect.left * 2, _displayWidth, x * 2, y * 2, rect.width() * 2, rect.height() * 2);
|
|
|
|
}
|
2009-10-14 15:43:58 +00:00
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
byte Screen::getDrawingMask(byte color, byte prio, byte control) {
|
2009-10-03 20:49:18 +00:00
|
|
|
byte flag = 0;
|
|
|
|
if (color != 255)
|
|
|
|
flag |= SCI_SCREEN_MASK_VISUAL;
|
|
|
|
if (prio != 255)
|
|
|
|
flag |= SCI_SCREEN_MASK_PRIORITY;
|
|
|
|
if (control != 255)
|
|
|
|
flag |= SCI_SCREEN_MASK_CONTROL;
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::putPixel(int x, int y, byte drawMask, byte color, byte priority, byte control) {
|
2009-10-13 07:17:30 +00:00
|
|
|
int offset = y * _width + x;
|
2009-10-03 20:49:18 +00:00
|
|
|
|
|
|
|
if (drawMask & SCI_SCREEN_MASK_VISUAL) {
|
2009-10-12 10:32:44 +00:00
|
|
|
_visualScreen[offset] = color;
|
2009-10-31 14:38:25 +00:00
|
|
|
if (!_upscaledHires) {
|
2009-10-31 12:19:35 +00:00
|
|
|
_displayScreen[offset] = color;
|
|
|
|
} else {
|
2009-10-31 15:44:59 +00:00
|
|
|
int displayOffset = y * 2 * _displayWidth + x * 2;
|
2009-10-31 14:38:25 +00:00
|
|
|
_displayScreen[displayOffset] = color;
|
|
|
|
_displayScreen[displayOffset + 1] = color;
|
|
|
|
_displayScreen[displayOffset + _displayWidth] = color;
|
|
|
|
_displayScreen[displayOffset + _displayWidth + 1] = color;
|
2009-10-31 12:19:35 +00:00
|
|
|
}
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
if (drawMask & SCI_SCREEN_MASK_PRIORITY)
|
2009-10-12 10:32:44 +00:00
|
|
|
_priorityScreen[offset] = priority;
|
2009-10-03 20:49:18 +00:00
|
|
|
if (drawMask & SCI_SCREEN_MASK_CONTROL)
|
2009-10-12 10:32:44 +00:00
|
|
|
_controlScreen[offset] = control;
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
|
2009-10-31 14:38:25 +00:00
|
|
|
// This will just change a pixel directly on displayscreen. Its supposed to get only used on upscaled-Hires games where
|
|
|
|
// hires content needs to get drawn ONTO the upscaled display screen (like japanese fonts, hires portraits, etc.)
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::putPixelOnDisplay(int x, int y, byte color) {
|
2010-01-07 13:30:08 +00:00
|
|
|
int offset = y * _displayWidth + x;
|
2009-10-31 14:38:25 +00:00
|
|
|
_displayScreen[offset] = color;
|
|
|
|
}
|
|
|
|
|
2009-10-12 08:25:38 +00:00
|
|
|
// Sierra's Bresenham line drawing
|
|
|
|
// WARNING: Do not just blindly replace this with Graphics::drawLine(), as it seems to create issues with flood fill
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::drawLine(Common::Point startPoint, Common::Point endPoint, byte color, byte priority, byte control) {
|
2009-10-12 08:25:38 +00:00
|
|
|
int16 left = startPoint.x;
|
|
|
|
int16 top = startPoint.y;
|
|
|
|
int16 right = endPoint.x;
|
|
|
|
int16 bottom = endPoint.y;
|
|
|
|
|
|
|
|
//set_drawing_flag
|
|
|
|
byte drawMask = getDrawingMask(color, priority, control);
|
|
|
|
|
|
|
|
// horizontal line
|
|
|
|
if (top == bottom) {
|
|
|
|
if (right < left)
|
|
|
|
SWAP(right, left);
|
|
|
|
for (int i = left; i <= right; i++)
|
|
|
|
putPixel(i, top, drawMask, color, priority, control);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// vertical line
|
|
|
|
if (left == right) {
|
|
|
|
if (top > bottom)
|
|
|
|
SWAP(top, bottom);
|
|
|
|
for (int i = top; i <= bottom; i++)
|
|
|
|
putPixel(left, i, drawMask, color, priority, control);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// sloped line - draw with Bresenham algorithm
|
|
|
|
int dy = bottom - top;
|
|
|
|
int dx = right - left;
|
|
|
|
int stepy = dy < 0 ? -1 : 1;
|
|
|
|
int stepx = dx < 0 ? -1 : 1;
|
|
|
|
dy = ABS(dy) << 1;
|
|
|
|
dx = ABS(dx) << 1;
|
|
|
|
|
|
|
|
// setting the 1st and last pixel
|
|
|
|
putPixel(left, top, drawMask, color, priority, control);
|
|
|
|
putPixel(right, bottom, drawMask, color, priority, control);
|
|
|
|
// drawing the line
|
|
|
|
if (dx > dy) { // going horizontal
|
|
|
|
int fraction = dy - (dx >> 1);
|
|
|
|
while (left != right) {
|
|
|
|
if (fraction >= 0) {
|
|
|
|
top += stepy;
|
|
|
|
fraction -= dx;
|
|
|
|
}
|
|
|
|
left += stepx;
|
|
|
|
fraction += dy;
|
|
|
|
putPixel(left, top, drawMask, color, priority, control);
|
|
|
|
}
|
|
|
|
} else { // going vertical
|
|
|
|
int fraction = dx - (dy >> 1);
|
|
|
|
while (top != bottom) {
|
|
|
|
if (fraction >= 0) {
|
|
|
|
left += stepx;
|
|
|
|
fraction -= dy;
|
|
|
|
}
|
|
|
|
top += stepy;
|
|
|
|
fraction += dx;
|
|
|
|
putPixel(left, top, drawMask, color, priority, control);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
byte Screen::getVisual(int x, int y) {
|
2009-10-13 07:17:30 +00:00
|
|
|
return _visualScreen[y * _width + x];
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
byte Screen::getPriority(int x, int y) {
|
2009-10-13 07:17:30 +00:00
|
|
|
return _priorityScreen[y * _width + x];
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
byte Screen::getControl(int x, int y) {
|
2009-10-13 07:17:30 +00:00
|
|
|
return _controlScreen[y * _width + x];
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
byte Screen::isFillMatch(int16 x, int16 y, byte screenMask, byte t_color, byte t_pri, byte t_con) {
|
2009-10-13 07:17:30 +00:00
|
|
|
int offset = y * _width + x;
|
2009-10-03 20:49:18 +00:00
|
|
|
byte match = 0;
|
|
|
|
|
2009-10-13 07:17:30 +00:00
|
|
|
if (screenMask & SCI_SCREEN_MASK_VISUAL && *(_visualScreen + offset) == t_color)
|
2009-10-03 20:49:18 +00:00
|
|
|
match |= SCI_SCREEN_MASK_VISUAL;
|
2009-10-13 07:17:30 +00:00
|
|
|
if (screenMask & SCI_SCREEN_MASK_PRIORITY && *(_priorityScreen + offset) == t_pri)
|
2009-10-03 20:49:18 +00:00
|
|
|
match |= SCI_SCREEN_MASK_PRIORITY;
|
2009-10-13 07:17:30 +00:00
|
|
|
if (screenMask & SCI_SCREEN_MASK_CONTROL && *(_controlScreen + offset) == t_con)
|
2009-10-03 20:49:18 +00:00
|
|
|
match |= SCI_SCREEN_MASK_CONTROL;
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
int Screen::bitsGetDataSize(Common::Rect rect, byte mask) {
|
2009-10-03 20:49:18 +00:00
|
|
|
int byteCount = sizeof(rect) + sizeof(mask);
|
|
|
|
int pixels = rect.width() * rect.height();
|
2009-10-05 23:00:48 +00:00
|
|
|
if (mask & SCI_SCREEN_MASK_VISUAL) {
|
|
|
|
byteCount += pixels; // _visualScreen
|
2009-10-31 14:38:25 +00:00
|
|
|
if (!_upscaledHires) {
|
|
|
|
byteCount += pixels; // _displayScreen
|
|
|
|
} else {
|
|
|
|
byteCount += pixels * 4; // _displayScreen (upscaled hires)
|
|
|
|
}
|
2009-10-05 23:00:48 +00:00
|
|
|
}
|
|
|
|
if (mask & SCI_SCREEN_MASK_PRIORITY) {
|
|
|
|
byteCount += pixels; // _priorityScreen
|
|
|
|
}
|
|
|
|
if (mask & SCI_SCREEN_MASK_CONTROL) {
|
|
|
|
byteCount += pixels; // _controlScreen
|
|
|
|
}
|
2009-10-31 15:25:47 +00:00
|
|
|
if (mask & SCI_SCREEN_MASK_DISPLAY) {
|
|
|
|
if (!_upscaledHires)
|
|
|
|
error("bitsGetDataSize() called w/o being in upscaled hires mode");
|
|
|
|
byteCount += pixels; // _displayScreen (coordinates actually are given to us for hires displayScreen)
|
|
|
|
}
|
2009-10-05 07:51:31 +00:00
|
|
|
|
2009-10-03 20:49:18 +00:00
|
|
|
return byteCount;
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::bitsSave(Common::Rect rect, byte mask, byte *memoryPtr) {
|
2009-10-03 20:49:18 +00:00
|
|
|
memcpy(memoryPtr, (void *)&rect, sizeof(rect)); memoryPtr += sizeof(rect);
|
|
|
|
memcpy(memoryPtr, (void *)&mask, sizeof(mask)); memoryPtr += sizeof(mask);
|
|
|
|
|
|
|
|
if (mask & SCI_SCREEN_MASK_VISUAL) {
|
2010-01-07 15:50:58 +00:00
|
|
|
bitsSaveScreen(rect, _visualScreen, _width, memoryPtr);
|
2009-10-31 14:38:25 +00:00
|
|
|
bitsSaveDisplayScreen(rect, memoryPtr);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
if (mask & SCI_SCREEN_MASK_PRIORITY) {
|
2010-01-07 15:50:58 +00:00
|
|
|
bitsSaveScreen(rect, _priorityScreen, _width, memoryPtr);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
if (mask & SCI_SCREEN_MASK_CONTROL) {
|
2010-01-07 15:50:58 +00:00
|
|
|
bitsSaveScreen(rect, _controlScreen, _width, memoryPtr);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
2009-10-31 15:25:47 +00:00
|
|
|
if (mask & SCI_SCREEN_MASK_DISPLAY) {
|
|
|
|
if (!_upscaledHires)
|
|
|
|
error("bitsSave() called w/o being in upscaled hires mode");
|
2010-01-07 15:50:58 +00:00
|
|
|
bitsSaveScreen(rect, _displayScreen, _displayWidth, memoryPtr);
|
2009-10-31 15:25:47 +00:00
|
|
|
}
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-07 15:50:58 +00:00
|
|
|
void Screen::bitsSaveScreen(Common::Rect rect, byte *screen, uint16 screenWidth, byte *&memoryPtr) {
|
2009-10-03 20:49:18 +00:00
|
|
|
int width = rect.width();
|
|
|
|
int y;
|
|
|
|
|
2010-01-07 15:50:58 +00:00
|
|
|
screen += (rect.top * screenWidth) + rect.left;
|
2009-10-03 20:49:18 +00:00
|
|
|
|
2009-10-04 05:20:56 +00:00
|
|
|
for (y = rect.top; y < rect.bottom; y++) {
|
2009-10-03 20:49:18 +00:00
|
|
|
memcpy(memoryPtr, (void*)screen, width); memoryPtr += width;
|
2010-01-07 15:50:58 +00:00
|
|
|
screen += screenWidth;
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::bitsSaveDisplayScreen(Common::Rect rect, byte *&memoryPtr) {
|
2009-10-31 14:38:25 +00:00
|
|
|
byte *screen = _displayScreen;
|
|
|
|
int width = rect.width();
|
|
|
|
int y;
|
|
|
|
|
|
|
|
if (!_upscaledHires) {
|
|
|
|
screen += (rect.top * _displayWidth) + rect.left;
|
|
|
|
} else {
|
|
|
|
screen += (rect.top * 2 * _displayWidth) + rect.left * 2;
|
|
|
|
width *= 2;
|
|
|
|
rect.top *= 2; rect.bottom *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (y = rect.top; y < rect.bottom; y++) {
|
|
|
|
memcpy(memoryPtr, (void*)screen, width); memoryPtr += width;
|
|
|
|
screen += _displayWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::bitsGetRect(byte *memoryPtr, Common::Rect *destRect) {
|
2009-10-17 21:11:56 +00:00
|
|
|
memcpy((void *)destRect, memoryPtr, sizeof(Common::Rect));
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::bitsRestore(byte *memoryPtr) {
|
2009-10-03 20:49:18 +00:00
|
|
|
Common::Rect rect;
|
|
|
|
byte mask;
|
|
|
|
|
|
|
|
memcpy((void *)&rect, memoryPtr, sizeof(rect)); memoryPtr += sizeof(rect);
|
|
|
|
memcpy((void *)&mask, memoryPtr, sizeof(mask)); memoryPtr += sizeof(mask);
|
|
|
|
|
|
|
|
if (mask & SCI_SCREEN_MASK_VISUAL) {
|
2010-01-07 15:50:58 +00:00
|
|
|
bitsRestoreScreen(rect, memoryPtr, _visualScreen, _width);
|
2009-10-31 14:38:25 +00:00
|
|
|
bitsRestoreDisplayScreen(rect, memoryPtr);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
if (mask & SCI_SCREEN_MASK_PRIORITY) {
|
2010-01-07 15:50:58 +00:00
|
|
|
bitsRestoreScreen(rect, memoryPtr, _priorityScreen, _width);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
if (mask & SCI_SCREEN_MASK_CONTROL) {
|
2010-01-07 15:50:58 +00:00
|
|
|
bitsRestoreScreen(rect, memoryPtr, _controlScreen, _width);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
2009-10-31 15:25:47 +00:00
|
|
|
if (mask & SCI_SCREEN_MASK_DISPLAY) {
|
|
|
|
if (!_upscaledHires)
|
|
|
|
error("bitsRestore() called w/o being in upscaled hires mode");
|
2010-01-07 15:50:58 +00:00
|
|
|
bitsRestoreScreen(rect, memoryPtr, _displayScreen, _displayWidth);
|
2009-10-31 15:25:47 +00:00
|
|
|
}
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-07 15:50:58 +00:00
|
|
|
void Screen::bitsRestoreScreen(Common::Rect rect, byte *&memoryPtr, byte *screen, uint16 screenWidth) {
|
2009-10-03 20:49:18 +00:00
|
|
|
int width = rect.width();
|
|
|
|
int y;
|
|
|
|
|
2010-01-07 15:50:58 +00:00
|
|
|
screen += (rect.top * screenWidth) + rect.left;
|
2009-10-03 20:49:18 +00:00
|
|
|
|
2009-10-04 05:20:56 +00:00
|
|
|
for (y = rect.top; y < rect.bottom; y++) {
|
2009-10-03 20:49:18 +00:00
|
|
|
memcpy((void*) screen, memoryPtr, width); memoryPtr += width;
|
2010-01-07 15:50:58 +00:00
|
|
|
screen += screenWidth;
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::bitsRestoreDisplayScreen(Common::Rect rect, byte *&memoryPtr) {
|
2009-10-31 14:38:25 +00:00
|
|
|
byte *screen = _displayScreen;
|
|
|
|
int width = rect.width();
|
|
|
|
int y;
|
|
|
|
|
|
|
|
if (!_upscaledHires) {
|
|
|
|
screen += (rect.top * _displayWidth) + rect.left;
|
|
|
|
} else {
|
|
|
|
screen += (rect.top * 2 * _displayWidth) + rect.left * 2;
|
|
|
|
width *= 2;
|
|
|
|
rect.top *= 2; rect.bottom *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (y = rect.top; y < rect.bottom; y++) {
|
|
|
|
memcpy((void*) screen, memoryPtr, width); memoryPtr += width;
|
|
|
|
screen += _displayWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::setPalette(Palette*pal) {
|
2009-10-06 16:14:40 +00:00
|
|
|
// just copy palette to system
|
|
|
|
byte bpal[4 * 256];
|
|
|
|
// Get current palette, update it and put back
|
2009-10-07 12:52:21 +00:00
|
|
|
g_system->grabPalette(bpal, 0, 256);
|
2009-10-06 16:14:40 +00:00
|
|
|
for (int16 i = 0; i < 256; i++) {
|
|
|
|
if (!pal->colors[i].used)
|
|
|
|
continue;
|
|
|
|
bpal[i * 4] = pal->colors[i].r * pal->intensity[i] / 100;
|
|
|
|
bpal[i * 4 + 1] = pal->colors[i].g * pal->intensity[i] / 100;
|
|
|
|
bpal[i * 4 + 2] = pal->colors[i].b * pal->intensity[i] / 100;
|
|
|
|
bpal[i * 4 + 3] = 100;
|
|
|
|
}
|
2009-10-07 12:52:21 +00:00
|
|
|
g_system->setPalette(bpal, 0, 256);
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::setVerticalShakePos(uint16 shakePos) {
|
2009-10-31 14:38:25 +00:00
|
|
|
if (!_upscaledHires)
|
|
|
|
g_system->setShakePos(shakePos);
|
|
|
|
else
|
|
|
|
g_system->setShakePos(shakePos * 2);
|
2009-10-11 08:52:23 +00:00
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::dither(bool addToFlag) {
|
2009-10-05 21:38:51 +00:00
|
|
|
int y, x;
|
2009-10-31 14:38:25 +00:00
|
|
|
byte color, ditheredColor;
|
|
|
|
byte *visualPtr = _visualScreen;
|
2009-10-05 21:38:51 +00:00
|
|
|
byte *displayPtr = _displayScreen;
|
|
|
|
|
2009-10-09 20:21:21 +00:00
|
|
|
if (!_unditherState) {
|
|
|
|
// Do dithering on visual and display-screen
|
|
|
|
for (y = 0; y < _height; y++) {
|
|
|
|
for (x = 0; x < _width; x++) {
|
2009-10-31 14:38:25 +00:00
|
|
|
color = *visualPtr;
|
2009-10-09 20:21:21 +00:00
|
|
|
if (color & 0xF0) {
|
|
|
|
color ^= color << 4;
|
|
|
|
color = ((x^y) & 1) ? color >> 4 : color & 0x0F;
|
2009-10-31 14:38:25 +00:00
|
|
|
*displayPtr = color;
|
|
|
|
if (_upscaledHires) {
|
|
|
|
*(displayPtr + 1) = color;
|
|
|
|
*(displayPtr + _displayWidth) = color;
|
|
|
|
*(displayPtr + _displayWidth + 1) = color;
|
|
|
|
}
|
|
|
|
*visualPtr = color;
|
2009-10-09 20:21:21 +00:00
|
|
|
}
|
2009-10-31 14:38:25 +00:00
|
|
|
visualPtr++; displayPtr++;
|
|
|
|
if (_upscaledHires)
|
|
|
|
displayPtr++;
|
2009-10-09 20:21:21 +00:00
|
|
|
}
|
2009-10-31 14:38:25 +00:00
|
|
|
if (_upscaledHires)
|
|
|
|
displayPtr += _displayWidth;
|
2009-10-09 20:21:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-10-09 20:54:02 +00:00
|
|
|
if (!addToFlag)
|
|
|
|
memset(&_unditherMemorial, 0, sizeof(_unditherMemorial));
|
2009-10-09 20:21:21 +00:00
|
|
|
// Do dithering on visual screen and put decoded but undithered byte onto display-screen
|
|
|
|
for (y = 0; y < _height; y++) {
|
|
|
|
for (x = 0; x < _width; x++) {
|
2009-10-31 14:38:25 +00:00
|
|
|
color = *visualPtr;
|
2009-10-09 20:21:21 +00:00
|
|
|
if (color & 0xF0) {
|
|
|
|
color ^= color << 4;
|
2009-10-09 20:54:02 +00:00
|
|
|
// remember dither combination for cel-undithering
|
|
|
|
_unditherMemorial[color]++;
|
2009-10-09 20:21:21 +00:00
|
|
|
// if decoded color wants do dither with black on left side, we turn it around
|
|
|
|
// otherwise the normal ega color would get used for display
|
|
|
|
if (color & 0xF0) {
|
2009-10-31 14:38:25 +00:00
|
|
|
ditheredColor = color;
|
2009-10-09 20:21:21 +00:00
|
|
|
} else {
|
2009-10-31 14:38:25 +00:00
|
|
|
ditheredColor = color << 4;
|
|
|
|
}
|
|
|
|
*displayPtr = ditheredColor;
|
|
|
|
if (_upscaledHires) {
|
|
|
|
*(displayPtr + 1) = ditheredColor;
|
|
|
|
*(displayPtr + _displayWidth) = ditheredColor;
|
|
|
|
*(displayPtr + _displayWidth + 1) = ditheredColor;
|
2009-10-09 20:21:21 +00:00
|
|
|
}
|
|
|
|
color = ((x^y) & 1) ? color >> 4 : color & 0x0F;
|
2009-10-31 14:38:25 +00:00
|
|
|
*visualPtr = color;
|
2009-10-09 20:21:21 +00:00
|
|
|
}
|
2009-10-31 14:38:25 +00:00
|
|
|
visualPtr++; displayPtr++;
|
|
|
|
if (_upscaledHires)
|
|
|
|
displayPtr++;
|
2009-10-05 22:42:41 +00:00
|
|
|
}
|
2009-10-31 14:38:25 +00:00
|
|
|
if (_upscaledHires)
|
|
|
|
displayPtr += _displayWidth;
|
2009-10-05 21:38:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::unditherSetState(bool flag) {
|
2009-10-07 21:47:34 +00:00
|
|
|
_unditherState = flag;
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
int16 *Screen::unditherGetMemorial() {
|
2009-10-09 20:54:02 +00:00
|
|
|
if (_unditherState)
|
|
|
|
return (int16 *)&_unditherMemorial;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::debugShowMap(int mapNo) {
|
2009-10-31 14:38:25 +00:00
|
|
|
// We cannot really support changing maps when in upscaledHires mode
|
|
|
|
if (_upscaledHires)
|
|
|
|
return;
|
|
|
|
|
2009-10-07 15:53:34 +00:00
|
|
|
switch (mapNo) {
|
|
|
|
case 0:
|
|
|
|
_activeScreen = _visualScreen;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
_activeScreen = _priorityScreen;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
_activeScreen = _controlScreen;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
_activeScreen = _displayScreen;
|
|
|
|
break;
|
|
|
|
}
|
2009-10-28 15:18:22 +00:00
|
|
|
copyToScreen();
|
2009-10-07 15:53:34 +00:00
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
void Screen::scale2x(byte *src, byte *dst, int16 srcWidth, int16 srcHeight) {
|
2009-10-31 15:44:59 +00:00
|
|
|
int newWidth = srcWidth * 2;
|
2009-10-31 17:02:11 +00:00
|
|
|
byte *srcPtr = src;
|
2009-10-31 15:44:59 +00:00
|
|
|
|
|
|
|
for (int y = 0; y < srcHeight; y++) {
|
|
|
|
for (int x = 0; x < srcWidth; x++) {
|
|
|
|
int destOffset = y * 2 * newWidth + x * 2;
|
2009-10-31 17:02:11 +00:00
|
|
|
dst[destOffset] = *srcPtr;
|
|
|
|
dst[destOffset + 1] = *srcPtr;
|
|
|
|
dst[destOffset + newWidth] = *srcPtr;
|
|
|
|
dst[destOffset + newWidth + 1] = *srcPtr;
|
|
|
|
srcPtr++;
|
2009-10-31 15:44:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Sci
|