2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2005-04-05 15:53:16 +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
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-04-05 15:53:16 +00:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2005-04-09 19:19:54 +00:00
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-04-05 15:53:16 +00:00
|
|
|
*
|
2006-02-11 10:11:37 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2005-04-05 15:53:16 +00:00
|
|
|
*
|
|
|
|
*/
|
2006-03-29 15:59:37 +00:00
|
|
|
|
|
|
|
#include "common/endian.h"
|
2005-06-06 20:42:44 +00:00
|
|
|
#include "graphics/primitives.h"
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
#include "gob/driver_vga.h"
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
namespace Gob {
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
static void plotPixel(int x, int y, int color, void *data) {
|
|
|
|
SurfaceDesc *dest = (SurfaceDesc *)data;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
if ((x >= 0) && (x < dest->getWidth()) &&
|
|
|
|
(y >= 0) && (y < dest->getHeight()))
|
|
|
|
dest->getVidMem()[(y * dest->getWidth()) + x] = color;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
void VGAVideoDriver::putPixel(int16 x, int16 y, byte color, SurfaceDesc &dest) {
|
|
|
|
if ((x >= 0) && (x < dest.getWidth()) &&
|
|
|
|
(y >= 0) && (y < dest.getHeight()))
|
|
|
|
dest.getVidMem()[(y * dest.getWidth()) + x] = color;
|
2007-03-20 14:51:57 +00:00
|
|
|
}
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
void VGAVideoDriver::drawLine(SurfaceDesc &dest, int16 x0, int16 y0, int16 x1,
|
2007-03-20 14:51:57 +00:00
|
|
|
int16 y1, byte color) {
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
Graphics::drawLine(x0, y0, x1, y1, color, &plotPixel, &dest);
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
void VGAVideoDriver::fillRect(SurfaceDesc &dest, int16 left, int16 top,
|
2007-03-20 14:51:57 +00:00
|
|
|
int16 right, int16 bottom, byte color) {
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
if ((left >= dest.getWidth()) || (right >= dest.getWidth()) ||
|
|
|
|
(top >= dest.getHeight()) || (bottom >= dest.getHeight()))
|
2007-03-20 14:51:57 +00:00
|
|
|
return;
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
byte *pos = dest.getVidMem() + (top * dest.getWidth()) + left;
|
2007-03-20 14:51:57 +00:00
|
|
|
int16 width = (right - left) + 1;
|
|
|
|
int16 height = (bottom - top) + 1;
|
|
|
|
|
|
|
|
while (height--) {
|
|
|
|
for (int16 i = 0; i < width; ++i)
|
|
|
|
pos[i] = color;
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
pos += dest.getWidth();
|
2007-03-20 14:51:57 +00:00
|
|
|
}
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
void VGAVideoDriver::drawLetter(unsigned char item, int16 x, int16 y,
|
|
|
|
Video::FontDesc *fontDesc, byte color1, byte color2,
|
2009-06-06 20:03:13 +00:00
|
|
|
byte transp, SurfaceDesc &dest) {
|
2005-04-06 14:33:31 +00:00
|
|
|
byte *src, *dst;
|
|
|
|
uint16 data;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-04-02 11:05:09 +00:00
|
|
|
src = fontDesc->dataPtr +
|
2007-03-20 14:51:57 +00:00
|
|
|
(item - fontDesc->startItem) * (fontDesc->itemSize & 0xFF);
|
2009-06-06 20:03:13 +00:00
|
|
|
dst = dest.getVidMem() + x + dest.getWidth() * y;
|
2005-04-06 14:33:31 +00:00
|
|
|
|
2008-12-12 04:31:01 +00:00
|
|
|
int nWidth = fontDesc->itemWidth;
|
|
|
|
|
|
|
|
if (nWidth & 7)
|
|
|
|
nWidth = (nWidth & 0xF8) + 8;
|
|
|
|
|
|
|
|
nWidth >>= 3;
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
for (int i = 0; i < fontDesc->itemHeight; i++) {
|
2008-12-12 04:31:01 +00:00
|
|
|
int width = fontDesc->itemWidth;
|
|
|
|
|
|
|
|
for (int k = 0; k < nWidth; k++) {
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-12-12 04:31:01 +00:00
|
|
|
data = *src++;
|
|
|
|
for (int j = 0; j < MIN(8, width); j++) {
|
|
|
|
if (data & 0x80)
|
|
|
|
*dst = color2;
|
|
|
|
else if (color1 == 0)
|
|
|
|
*dst = transp;
|
|
|
|
|
|
|
|
dst++;
|
|
|
|
data <<= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
width -= 8;
|
|
|
|
|
2005-04-06 14:33:31 +00:00
|
|
|
}
|
2008-12-12 04:31:01 +00:00
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
dst += dest.getWidth() - fontDesc->itemWidth;
|
2005-04-06 14:33:31 +00:00
|
|
|
}
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
void VGAVideoDriver::drawSprite(SurfaceDesc &source, SurfaceDesc &dest,
|
2007-03-20 14:51:57 +00:00
|
|
|
int16 left, int16 top, int16 right, int16 bottom,
|
|
|
|
int16 x, int16 y, int16 transp) {
|
2005-06-06 20:42:44 +00:00
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
if ((x >= dest.getWidth()) || (x < 0) ||
|
|
|
|
(y >= dest.getHeight()) || (y < 0))
|
2007-03-20 14:51:57 +00:00
|
|
|
return;
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
int16 width = MIN((right - left) + 1, (int) dest.getWidth());
|
|
|
|
int16 height = MIN((bottom - top) + 1, (int) dest.getHeight());
|
2007-03-20 14:51:57 +00:00
|
|
|
|
2008-05-26 21:07:49 +00:00
|
|
|
if ((width < 1) || (height < 1))
|
|
|
|
return;
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
const byte *srcPos = source.getVidMem() + (top * source.getWidth()) + left;
|
|
|
|
byte *destPos = dest.getVidMem() + (y * dest.getWidth()) + x;
|
2007-03-20 14:51:57 +00:00
|
|
|
|
2008-05-26 21:07:49 +00:00
|
|
|
uint32 size = width * height;
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2007-08-19 18:39:49 +00:00
|
|
|
if (transp) {
|
2008-05-26 21:07:49 +00:00
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
while (height--) {
|
2007-03-20 14:51:57 +00:00
|
|
|
for (int16 i = 0; i < width; ++i) {
|
|
|
|
if (srcPos[i])
|
|
|
|
destPos[i] = srcPos[i];
|
2007-09-19 08:40:12 +00:00
|
|
|
}
|
2007-03-20 14:51:57 +00:00
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
srcPos += source.getWidth();
|
|
|
|
destPos += dest.getWidth();
|
2007-08-19 17:26:06 +00:00
|
|
|
}
|
2008-05-26 21:07:49 +00:00
|
|
|
|
|
|
|
} else if (((srcPos >= destPos) && (srcPos <= (destPos + size))) ||
|
|
|
|
((destPos >= srcPos) && (destPos <= (srcPos + size)))) {
|
|
|
|
|
|
|
|
while (height--) {
|
|
|
|
memmove(destPos, srcPos, width);
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
srcPos += source.getWidth();
|
|
|
|
destPos += dest.getWidth();
|
2008-05-26 21:07:49 +00:00
|
|
|
}
|
|
|
|
|
2007-08-19 18:39:49 +00:00
|
|
|
} else {
|
2008-05-26 21:07:49 +00:00
|
|
|
|
2007-08-19 17:26:06 +00:00
|
|
|
while (height--) {
|
|
|
|
memcpy(destPos, srcPos, width);
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
srcPos += source.getWidth();
|
|
|
|
destPos += dest.getWidth();
|
2007-09-19 08:40:12 +00:00
|
|
|
}
|
2008-05-26 21:07:49 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
}
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
void VGAVideoDriver::drawSpriteDouble(SurfaceDesc &source, SurfaceDesc &dest,
|
2009-04-29 19:58:43 +00:00
|
|
|
int16 left, int16 top, int16 right, int16 bottom,
|
|
|
|
int16 x, int16 y, int16 transp) {
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
if ((x >= dest.getWidth()) || (x < 0) ||
|
|
|
|
(y >= dest.getHeight()) || (y < 0))
|
2009-04-29 19:58:43 +00:00
|
|
|
return;
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
int16 width = MIN<int>((right - left) + 1, dest.getWidth() / 2);
|
|
|
|
int16 height = MIN<int>((bottom - top) + 1, dest.getHeight() / 2);
|
2009-04-29 19:58:43 +00:00
|
|
|
|
|
|
|
if ((width < 1) || (height < 1))
|
|
|
|
return;
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
const byte *srcPos = source.getVidMem() + (top * source.getWidth()) + left;
|
|
|
|
byte *destPos = dest.getVidMem() + ((y * 2) * dest.getWidth()) + (x * 2);
|
2009-04-29 19:58:43 +00:00
|
|
|
|
|
|
|
while (height--) {
|
|
|
|
const byte *srcBak = srcPos;
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
srcPos = srcBak;
|
|
|
|
|
|
|
|
for (int16 j = 0; j < width; j++) {
|
|
|
|
if (!transp || srcPos[i]) {
|
|
|
|
destPos[2 * j + 0] = srcPos[j];
|
|
|
|
destPos[2 * j + 1] = srcPos[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
destPos += dest.getWidth();
|
2009-04-29 19:58:43 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
srcPos = srcBak + source.getWidth();
|
2009-04-29 19:58:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
void VGAVideoDriver::drawPackedSprite(byte *sprBuf, int16 width, int16 height,
|
2009-06-06 20:03:13 +00:00
|
|
|
int16 x, int16 y, byte transp, SurfaceDesc &dest) {
|
2005-04-11 21:44:08 +00:00
|
|
|
int destRight = x + width;
|
|
|
|
int destBottom = y + height;
|
|
|
|
|
2009-06-06 20:03:13 +00:00
|
|
|
byte *dst = dest.getVidMem() + x + dest.getWidth() * y;
|
2005-04-11 21:44:08 +00:00
|
|
|
|
|
|
|
int curx = x;
|
|
|
|
int cury = y;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
uint8 val = *sprBuf++;
|
|
|
|
unsigned int repeat = val & 7;
|
|
|
|
val &= 0xF8;
|
2007-03-20 14:51:57 +00:00
|
|
|
|
2005-04-11 21:44:08 +00:00
|
|
|
if (!(val & 8)) {
|
|
|
|
repeat <<= 8;
|
|
|
|
repeat |= *sprBuf++;
|
|
|
|
}
|
|
|
|
repeat++;
|
|
|
|
val >>= 4;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < repeat; ++i) {
|
2009-06-06 20:03:13 +00:00
|
|
|
if (curx < dest.getWidth() && cury < dest.getHeight())
|
2005-04-11 21:44:08 +00:00
|
|
|
if (!transp || val)
|
|
|
|
*dst = val;
|
|
|
|
|
|
|
|
dst++;
|
|
|
|
curx++;
|
|
|
|
if (curx == destRight) {
|
2009-06-06 20:03:13 +00:00
|
|
|
dst += dest.getWidth() + x - curx;
|
2005-04-11 21:44:08 +00:00
|
|
|
curx = x;
|
|
|
|
cury++;
|
|
|
|
if (cury == destBottom)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-03-20 14:51:57 +00:00
|
|
|
|
2005-04-11 21:44:08 +00:00
|
|
|
}
|
|
|
|
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|