2021-05-17 20:47:39 +02: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
|
|
|
|
* aint32 with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Based on the original sources
|
|
|
|
* Faery Tale II -- The Halls of the Dead
|
|
|
|
* (c) 1993-1996 The Wyrmkeep Entertainment Co.
|
|
|
|
*/
|
|
|
|
|
2021-06-01 23:47:48 +02:00
|
|
|
#include "common/debug.h"
|
2021-06-09 01:37:55 +09:00
|
|
|
#include "graphics/surface.h"
|
2021-06-01 23:47:48 +02:00
|
|
|
|
2021-05-17 20:47:39 +02:00
|
|
|
#include "saga2/std.h"
|
2021-06-01 23:47:48 +02:00
|
|
|
#include "saga2/gdraw.h"
|
2021-05-17 20:47:39 +02:00
|
|
|
|
|
|
|
namespace Saga2 {
|
|
|
|
|
|
|
|
void _BltPixels(uint8 *srcPtr, uint32 srcMod, uint8 *dstPtr, uint32 dstMod, uint32 width, uint32 height) {
|
2021-06-10 00:35:18 +02:00
|
|
|
uint8 *src, *dst;
|
|
|
|
for (uint y = 0; y < height; y++) {
|
|
|
|
src = srcPtr + srcMod * y;
|
|
|
|
dst = dstPtr + dstMod * y;
|
|
|
|
for (uint x = 0; x < width; x++) {
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
}
|
2021-05-17 20:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void _BltPixelsT(uint8 *srcPtr, uint32 srcMod, uint8 *dstPtr, uint32 dstMod, uint32 width, uint32 height) {
|
2021-06-10 00:35:18 +02:00
|
|
|
uint8 *src, *dst;
|
|
|
|
for (uint y = 0; y < height; y++) {
|
|
|
|
src = srcPtr + srcMod * y;
|
|
|
|
dst = dstPtr + dstMod * y;
|
|
|
|
for (uint x = 0; x < width; x++) {
|
|
|
|
byte c = *src++;
|
|
|
|
|
|
|
|
if (c == 0)
|
|
|
|
dst++;
|
|
|
|
else
|
|
|
|
*dst++ = c;
|
|
|
|
}
|
|
|
|
}
|
2021-05-17 20:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void _FillRect(uint8 *dstPtr, uint32 dstMod, uint32 width, uint32 height, uint32 color) {
|
2021-06-12 00:39:42 +02:00
|
|
|
for (uint y = 0; y < height; y++) {
|
|
|
|
memset(dstPtr, color, width);
|
|
|
|
|
|
|
|
dstPtr += dstMod;
|
|
|
|
}
|
2021-05-17 20:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void _HLine(uint8 *dstPtr, uint32 width, uint32 color) {
|
2021-06-12 00:39:42 +02:00
|
|
|
memset(dstPtr, color, width);
|
2021-05-17 20:47:39 +02:00
|
|
|
}
|
|
|
|
|
2021-05-27 18:00:10 +09:00
|
|
|
void unpackImage(gPixelMap &map, int16 width, int16 rowCount, int8 *srcData) {
|
2021-05-28 01:58:15 +09:00
|
|
|
int8 *dest = (int8 *)map.data;
|
|
|
|
int16 bytecount = (width + 1) & ~1;
|
|
|
|
int16 rowMod = map.size.x - bytecount;
|
2021-05-27 18:00:10 +09:00
|
|
|
|
2021-05-28 01:58:15 +09:00
|
|
|
while (rowCount--) {
|
|
|
|
for (int16 k = 0; k < bytecount;) {
|
|
|
|
int16 p = *srcData++;
|
2021-05-27 18:00:10 +09:00
|
|
|
|
2021-05-28 01:58:15 +09:00
|
|
|
if (p == -128)
|
|
|
|
continue;
|
|
|
|
else if (p >= 0) {
|
2021-05-27 18:00:10 +09:00
|
|
|
p++;
|
|
|
|
k += p;
|
2021-05-28 01:58:15 +09:00
|
|
|
while (p--)
|
|
|
|
*dest++ = *srcData++;
|
2021-05-28 02:07:56 +09:00
|
|
|
} else {
|
2021-05-27 18:00:10 +09:00
|
|
|
p = 1 - p;
|
|
|
|
k += p;
|
2021-05-28 01:58:15 +09:00
|
|
|
while (p--)
|
|
|
|
*dest++ = *srcData;
|
2021-05-27 18:00:10 +09:00
|
|
|
srcData++;
|
|
|
|
}
|
|
|
|
}
|
2021-05-26 19:02:35 +09:00
|
|
|
|
2021-05-28 01:58:15 +09:00
|
|
|
if (bytecount & 1)
|
|
|
|
srcData++;
|
2021-05-27 18:00:10 +09:00
|
|
|
dest += rowMod;
|
2021-05-26 19:02:35 +09:00
|
|
|
}
|
2021-05-27 18:00:10 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
void unpackImage(gPixelMap *map, int32 width, int32 rowCount, int8 *srcData) {
|
|
|
|
unpackImage(*map, (int16)width, (int16)rowCount, srcData);
|
2021-05-17 20:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void unpackSprite(gPixelMap *map, uint8 *sprData) {
|
|
|
|
warning("STUB: unpackSprite()");
|
|
|
|
}
|
|
|
|
|
2021-06-01 23:54:25 +09:00
|
|
|
//void drawTile(gPixelMap *map, int32 x, int32 y, int32 height, uint8 *srcData) {
|
|
|
|
// warning("STUB: drawTile()");
|
|
|
|
//}
|
|
|
|
|
2021-05-17 20:47:39 +02:00
|
|
|
void drawTile(gPixelMap *map, int32 x, int32 y, int32 height, uint8 *srcData) {
|
2021-06-01 23:54:25 +09:00
|
|
|
const byte *tilePointer;
|
|
|
|
const byte *readPointer;
|
|
|
|
byte *drawPointer;
|
|
|
|
Point32 drawPoint;
|
|
|
|
int widthCount = 0;
|
|
|
|
int row, col, count, lowBound;
|
|
|
|
int bgRunCount;
|
|
|
|
int fgRunCount;
|
2021-06-12 23:20:54 +02:00
|
|
|
const int32 SAGA_ISOTILE_WIDTH = 64;
|
2021-06-01 23:54:25 +09:00
|
|
|
Point16 point(x, y);
|
|
|
|
|
|
|
|
if (point.x + SAGA_ISOTILE_WIDTH < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (point.x - SAGA_ISOTILE_WIDTH >= map->size.x) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tilePointer = srcData;
|
|
|
|
|
|
|
|
drawPoint = point;
|
|
|
|
|
|
|
|
drawPoint.y -= height;
|
|
|
|
|
|
|
|
if (drawPoint.y >= map->size.y) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
readPointer = tilePointer;
|
|
|
|
lowBound = MIN((int)(drawPoint.y + height), (int)map->size.y);
|
|
|
|
for (row = drawPoint.y; row < lowBound; row++) {
|
|
|
|
widthCount = 0;
|
|
|
|
if (row >= 0) {
|
|
|
|
drawPointer = map->data + drawPoint.x + (row * map->size.x);
|
|
|
|
col = drawPoint.x;
|
|
|
|
for (;;) {
|
|
|
|
bgRunCount = *readPointer++;
|
|
|
|
widthCount += bgRunCount;
|
|
|
|
if (widthCount >= SAGA_ISOTILE_WIDTH) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
drawPointer += bgRunCount;
|
|
|
|
col += bgRunCount;
|
|
|
|
fgRunCount = *readPointer++;
|
|
|
|
widthCount += fgRunCount;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
int colDiff = - col;
|
|
|
|
if (colDiff > 0) {
|
|
|
|
if (colDiff > fgRunCount) {
|
|
|
|
colDiff = fgRunCount;
|
|
|
|
}
|
|
|
|
count = colDiff;
|
|
|
|
col += colDiff;
|
|
|
|
}
|
|
|
|
|
|
|
|
colDiff = map->size.x - col;
|
|
|
|
if (colDiff > 0) {
|
|
|
|
int countDiff = fgRunCount - count;
|
|
|
|
if (colDiff > countDiff) {
|
|
|
|
colDiff = countDiff;
|
|
|
|
}
|
|
|
|
if (colDiff > 0) {
|
|
|
|
byte *dst = (byte *)(drawPointer + count);
|
|
|
|
memcpy(dst, (readPointer + count), colDiff);
|
|
|
|
col += colDiff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
readPointer += fgRunCount;
|
|
|
|
drawPointer += fgRunCount;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (;;) {
|
|
|
|
bgRunCount = *readPointer++;
|
|
|
|
widthCount += bgRunCount;
|
|
|
|
if (widthCount >= SAGA_ISOTILE_WIDTH) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fgRunCount = *readPointer++;
|
|
|
|
widthCount += fgRunCount;
|
|
|
|
|
|
|
|
readPointer += fgRunCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-17 20:47:39 +02:00
|
|
|
}
|
|
|
|
|
2021-06-01 23:54:25 +09:00
|
|
|
|
2021-05-17 20:47:39 +02:00
|
|
|
void maskTile(gPixelMap *map, int32 x, int32 y, int32 height, uint8 *srcData) {
|
|
|
|
warning("STUB: maskTile()");
|
|
|
|
}
|
|
|
|
|
2021-06-10 00:20:33 +02:00
|
|
|
void TBlit(gPixelMap *dstMap, gPixelMap *srcMap, int xpos, int ypos) {
|
|
|
|
byte *srcPtr,
|
|
|
|
*dstPtr;
|
|
|
|
int16 srcMod,
|
|
|
|
dstMod;
|
|
|
|
int16 x, y, w, h;
|
|
|
|
int32 offset = 0;
|
|
|
|
|
|
|
|
w = srcMap->size.x;
|
|
|
|
h = srcMap->size.y;
|
|
|
|
|
|
|
|
if (ypos < 0) {
|
|
|
|
h += ypos;
|
|
|
|
offset -= (ypos * w);
|
|
|
|
ypos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xpos < 0) {
|
|
|
|
w += xpos;
|
|
|
|
offset -= xpos;
|
|
|
|
xpos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w > dstMap->size.x - xpos)
|
|
|
|
w = dstMap->size.x - xpos;
|
|
|
|
if (h > dstMap->size.y - ypos)
|
|
|
|
h = dstMap->size.y - ypos;
|
|
|
|
if (w < 0 || h < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dstMod = dstMap->size.x - w;
|
|
|
|
srcMod = srcMap->size.x - w;
|
|
|
|
|
|
|
|
srcPtr = srcMap->data + offset;
|
|
|
|
dstPtr = dstMap->data + xpos + ypos * dstMap->size.x;
|
|
|
|
|
|
|
|
for (y = 0; y < h; y++) {
|
|
|
|
for (x = 0; x < w; x++) {
|
|
|
|
byte c = *srcPtr++;
|
|
|
|
|
|
|
|
if (c == 0)
|
|
|
|
dstPtr++;
|
|
|
|
else
|
|
|
|
*dstPtr++ = c;
|
|
|
|
}
|
|
|
|
dstPtr += dstMod;
|
|
|
|
srcPtr += srcMod;
|
|
|
|
}
|
2021-05-17 20:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TBlit4(gPixelMap *d, gPixelMap *s, int32 x, int32 y) {
|
2021-06-10 00:20:33 +02:00
|
|
|
TBlit(d, s, x, y);
|
2021-05-17 20:47:39 +02:00
|
|
|
}
|
|
|
|
|
2021-06-10 00:20:33 +02:00
|
|
|
void compositePixels(gPixelMap *compMap, gPixelMap *sprMap, int xpos, int ypos, byte *lookup) {
|
|
|
|
byte *srcPtr,
|
|
|
|
*dstPtr;
|
|
|
|
int16 rowMod;
|
|
|
|
int16 x, y;
|
|
|
|
|
|
|
|
// Blit the temp map onto the composite map
|
|
|
|
|
|
|
|
srcPtr = sprMap->data;
|
|
|
|
dstPtr = compMap->data + xpos + ypos * compMap->size.x;
|
|
|
|
rowMod = compMap->size.x - sprMap->size.x;
|
|
|
|
|
|
|
|
for (y = 0; y < sprMap->size.y; y++) {
|
|
|
|
for (x = 0; x < sprMap->size.x; x++) {
|
|
|
|
byte c = *srcPtr++;
|
|
|
|
|
|
|
|
if (c == 0)
|
|
|
|
dstPtr++;
|
|
|
|
else
|
|
|
|
*dstPtr++ = lookup[ c ];
|
|
|
|
}
|
|
|
|
dstPtr += rowMod;
|
|
|
|
}
|
2021-05-17 20:47:39 +02:00
|
|
|
}
|
|
|
|
|
2021-06-10 00:20:33 +02:00
|
|
|
void compositePixelsRvs(gPixelMap *compMap, gPixelMap *sprMap, int xpos, int ypos, byte *lookup) {
|
|
|
|
byte *srcPtr,
|
|
|
|
*dstPtr;
|
|
|
|
int16 rowMod;
|
|
|
|
int16 x, y;
|
|
|
|
|
|
|
|
// Blit the temp map onto the composite map
|
|
|
|
|
|
|
|
srcPtr = sprMap->data + sprMap->bytes();
|
|
|
|
dstPtr = compMap->data + xpos + (ypos + sprMap->size.y) * compMap->size.x;
|
|
|
|
|
|
|
|
rowMod = compMap->size.x + sprMap->size.x;
|
|
|
|
|
|
|
|
for (y = 0; y < sprMap->size.y; y++) {
|
|
|
|
dstPtr -= rowMod;
|
|
|
|
|
|
|
|
for (x = 0; x < sprMap->size.x; x++) {
|
|
|
|
byte c = *--srcPtr;
|
|
|
|
|
|
|
|
if (c == 0)
|
|
|
|
dstPtr++;
|
|
|
|
else
|
|
|
|
*dstPtr++ = lookup[ c ];
|
|
|
|
}
|
|
|
|
}
|
2021-05-17 20:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool initGraphics(void) {
|
2021-05-26 19:02:35 +09:00
|
|
|
warning("STUB: initGraphics()");
|
|
|
|
return false;
|
2021-05-17 20:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool initProcessResources(void) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void termProcessResources(void) {
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end of namespace Saga2
|