2014-08-02 14:07:54 +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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/algorithm.h"
|
2014-08-04 13:21:39 +00:00
|
|
|
#include "common/endian.h"
|
|
|
|
#include "common/rect.h"
|
2014-08-02 14:07:54 +00:00
|
|
|
#include "common/textconsole.h"
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "graphics/palette.h"
|
2014-08-07 02:43:40 +00:00
|
|
|
#include "access/access.h"
|
2014-08-02 14:07:54 +00:00
|
|
|
#include "access/screen.h"
|
|
|
|
#include "access/resources.h"
|
|
|
|
|
|
|
|
namespace Access {
|
|
|
|
|
2014-08-10 23:42:33 +00:00
|
|
|
#define VGA_COLOR_TRANS(x) ((x) * 255 / 63)
|
|
|
|
|
2014-08-02 14:07:54 +00:00
|
|
|
Screen::Screen(AccessEngine *vm) : _vm(vm) {
|
2014-08-19 00:15:43 +00:00
|
|
|
create(320, 200);
|
2014-08-02 14:07:54 +00:00
|
|
|
Common::fill(&_tempPalette[0], &_tempPalette[PALETTE_SIZE], 0);
|
2014-08-10 02:07:28 +00:00
|
|
|
Common::fill(&_manPal[0], &_manPal[0x60], 0);
|
|
|
|
Common::fill(&_scaleTable1[0], &_scaleTable1[256], 0);
|
|
|
|
Common::fill(&_scaleTable2[0], &_scaleTable2[256], 0);
|
2014-08-14 02:23:08 +00:00
|
|
|
_savedPaletteCount = 0;
|
2014-08-28 00:01:33 +00:00
|
|
|
if (_vm->isCD())
|
|
|
|
_vesaMode = 0;
|
|
|
|
else
|
|
|
|
_vesaMode = 1;
|
|
|
|
|
2014-08-05 01:35:49 +00:00
|
|
|
_vesaCurrentWin = 0;
|
|
|
|
_currentPanel = 0;
|
|
|
|
_hideFlag = true;
|
2014-08-02 21:09:28 +00:00
|
|
|
_loadPalFlag = false;
|
2014-08-07 02:43:40 +00:00
|
|
|
_startColor = _numColors = 0;
|
2014-08-07 13:23:31 +00:00
|
|
|
_scrollCol = _scrollRow = 0;
|
2014-08-10 15:47:15 +00:00
|
|
|
_windowXAdd = _windowYAdd = 0;
|
|
|
|
_screenYOff = 0;
|
2014-08-16 13:35:38 +00:00
|
|
|
_screenChangeFlag = false;
|
2014-08-13 01:12:11 +00:00
|
|
|
|
2014-08-13 03:34:23 +00:00
|
|
|
_bufferBytesWide = _vWindowBytesWide = this->w;
|
|
|
|
_vWindowLinesTall = this->h;
|
|
|
|
_clipWidth = _vWindowBytesWide - 1;
|
|
|
|
_clipHeight = _vWindowLinesTall - 1;
|
2014-08-02 14:07:54 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 21:55:17 +00:00
|
|
|
void Screen::clearScreen() {
|
|
|
|
clearBuffer();
|
|
|
|
if (_vesaMode)
|
|
|
|
_vm->_clearSummaryFlag = true;
|
|
|
|
}
|
|
|
|
|
2014-08-02 14:07:54 +00:00
|
|
|
void Screen::setDisplayScan() {
|
2014-08-13 01:12:11 +00:00
|
|
|
_clipWidth = this->w - 1;
|
|
|
|
_clipHeight = this->h - 1;
|
|
|
|
_windowXAdd = _windowYAdd = 0;
|
|
|
|
_scrollX = _scrollY = 0;
|
|
|
|
_scrollCol = _scrollRow = 0;
|
|
|
|
_bufferStart.x = _bufferStart.y = 0;
|
|
|
|
_screenYOff = 0;
|
2014-08-02 14:07:54 +00:00
|
|
|
}
|
|
|
|
|
2014-08-05 01:35:49 +00:00
|
|
|
void Screen::setPanel(int num) {
|
|
|
|
assert(num < 4);
|
|
|
|
_currentPanel = num;
|
|
|
|
_msVirtualOffset = _virtualOffsetsTable[num];
|
|
|
|
}
|
|
|
|
|
2014-08-02 14:07:54 +00:00
|
|
|
void Screen::updateScreen() {
|
2014-08-12 13:16:14 +00:00
|
|
|
g_system->copyRectToScreen((byte *)getPixels(), this->pitch, 0, 0,
|
|
|
|
this->w, this->h);
|
2014-08-02 14:07:54 +00:00
|
|
|
g_system->updateScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::setInitialPalettte() {
|
|
|
|
Common::copy(&INITIAL_PALETTE[0], &INITIAL_PALETTE[18 * 3], _rawPalette);
|
|
|
|
Common::fill(&_rawPalette[18 * 3], &_rawPalette[PALETTE_SIZE], 0);
|
|
|
|
|
|
|
|
g_system->getPaletteManager()->setPalette(INITIAL_PALETTE, 0, 18);
|
|
|
|
}
|
|
|
|
|
2014-08-02 21:09:28 +00:00
|
|
|
void Screen::loadPalette(Common::SeekableReadStream *stream) {
|
2014-08-10 22:36:34 +00:00
|
|
|
loadRawPalette(stream);
|
2014-08-02 21:09:28 +00:00
|
|
|
setPalette();
|
|
|
|
_loadPalFlag = true;
|
|
|
|
}
|
|
|
|
|
2014-08-07 02:43:40 +00:00
|
|
|
void Screen::loadPalette(int fileNum, int subfile) {
|
|
|
|
byte *palette = _vm->_files->loadFile(fileNum, subfile);
|
|
|
|
Common::copy(palette, palette + (_numColors * 3), &_rawPalette[_startColor * 3]);
|
|
|
|
delete[] palette;
|
|
|
|
}
|
|
|
|
|
2014-08-02 21:09:28 +00:00
|
|
|
void Screen::setPalette() {
|
|
|
|
g_system->getPaletteManager()->setPalette(&_rawPalette[0], 0, PALETTE_COUNT);
|
|
|
|
}
|
|
|
|
|
2014-08-10 22:36:34 +00:00
|
|
|
void Screen::loadRawPalette(Common::SeekableReadStream *stream) {
|
|
|
|
stream->read(&_rawPalette[0], PALETTE_SIZE);
|
2014-08-10 23:42:33 +00:00
|
|
|
for (byte *p = &_rawPalette[0]; p < &_rawPalette[PALETTE_SIZE]; ++p)
|
|
|
|
*p = VGA_COLOR_TRANS(*p);
|
2014-08-10 22:36:34 +00:00
|
|
|
}
|
|
|
|
|
2014-08-02 14:07:54 +00:00
|
|
|
void Screen::updatePalette() {
|
|
|
|
g_system->getPaletteManager()->setPalette(&_tempPalette[0], 0, PALETTE_COUNT);
|
|
|
|
updateScreen();
|
|
|
|
}
|
|
|
|
|
2014-08-14 02:23:08 +00:00
|
|
|
void Screen::savePalette() {
|
|
|
|
Common::copy(&_rawPalette[0], &_rawPalette[PALETTE_SIZE],
|
|
|
|
&_savedPalettes[_savedPaletteCount][0]);
|
|
|
|
|
|
|
|
if (++_savedPaletteCount == 2)
|
|
|
|
_savedPaletteCount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::restorePalette() {
|
|
|
|
if (--_savedPaletteCount < 0)
|
|
|
|
_savedPaletteCount = 0;
|
|
|
|
|
|
|
|
Common::copy(&_savedPalettes[_savedPaletteCount][0],
|
|
|
|
&_savedPalettes[_savedPaletteCount][PALETTE_SIZE], &_rawPalette[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-02 14:07:54 +00:00
|
|
|
void Screen::forceFadeOut() {
|
|
|
|
const int FADE_AMOUNT = 2;
|
|
|
|
bool repeatFlag;
|
|
|
|
byte *srcP;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
do {
|
|
|
|
repeatFlag = false;
|
2014-08-23 18:28:07 +00:00
|
|
|
for (srcP = &_tempPalette[0], count = 0; count < PALETTE_SIZE; ++count, ++srcP) {
|
2014-08-02 14:07:54 +00:00
|
|
|
int v = *srcP;
|
|
|
|
if (v) {
|
|
|
|
repeatFlag = true;
|
|
|
|
*srcP = MAX(*srcP - FADE_AMOUNT, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updatePalette();
|
|
|
|
g_system->delayMillis(10);
|
2014-08-23 18:28:07 +00:00
|
|
|
} while (repeatFlag && !_vm->shouldQuit());
|
2014-08-02 14:07:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::forceFadeIn() {
|
|
|
|
Common::fill(&_tempPalette[0], &_tempPalette[PALETTE_SIZE], 0);
|
|
|
|
|
|
|
|
const int FADE_AMOUNT = 2;
|
|
|
|
bool repeatFlag;
|
|
|
|
do {
|
|
|
|
repeatFlag = false;
|
|
|
|
const byte *srcP = &_rawPalette[0];
|
|
|
|
byte *destP = &_tempPalette[0];
|
|
|
|
|
|
|
|
for (int idx = 0; idx < PALETTE_SIZE; ++idx, ++srcP, ++destP) {
|
|
|
|
if (*destP != *srcP) {
|
|
|
|
repeatFlag = true;
|
|
|
|
*destP = MAX((int)*destP + FADE_AMOUNT, (int)*srcP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updatePalette();
|
|
|
|
g_system->delayMillis(10);
|
|
|
|
} while (repeatFlag);
|
|
|
|
}
|
|
|
|
|
2014-08-02 21:09:28 +00:00
|
|
|
void Screen::copyBuffer(const byte *data) {
|
|
|
|
byte *destP = (byte *)getPixels();
|
|
|
|
Common::copy(data, data + (h * w), destP);
|
|
|
|
g_system->copyRectToScreen(destP, w, 0, 0, w, h);
|
|
|
|
}
|
|
|
|
|
2014-08-06 03:23:49 +00:00
|
|
|
void Screen::setBufferScan() {
|
2014-08-13 03:34:23 +00:00
|
|
|
_clipWidth = _vWindowBytesWide - 1;
|
2014-08-13 01:40:14 +00:00
|
|
|
_windowXAdd = (320 - _clipWidth) >> 1;
|
2014-08-13 03:34:23 +00:00
|
|
|
_clipHeight = _vWindowLinesTall - 1;
|
2014-08-13 01:40:14 +00:00
|
|
|
_windowYAdd = (176 - _clipHeight) >> 1;
|
2014-08-10 02:24:35 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 02:07:28 +00:00
|
|
|
void Screen::setScaleTable(int scale) {
|
|
|
|
int total = 0;
|
|
|
|
for (int idx = 0; idx < 256; ++idx) {
|
|
|
|
_scaleTable1[idx] = total >> 8;
|
|
|
|
_scaleTable2[idx] = total & 0xff;
|
|
|
|
total += scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-10 02:24:35 +00:00
|
|
|
void Screen::saveScreen() {
|
2014-08-10 15:47:15 +00:00
|
|
|
_screenSave._clipWidth = _clipWidth;
|
|
|
|
_screenSave._clipHeight = _clipHeight;
|
|
|
|
_screenSave._windowXAdd = _windowXAdd;
|
|
|
|
_screenSave._windowYAdd = _windowYAdd;
|
|
|
|
_screenSave._scroll.x = _scrollX;
|
|
|
|
_screenSave._scroll.y = _scrollY;
|
|
|
|
_screenSave._scrollCol = _scrollCol;
|
|
|
|
_screenSave._scrollRow = _scrollRow;
|
|
|
|
_screenSave._bufferStart.x = _bufferStart.x;
|
|
|
|
_screenSave._bufferStart.y = _bufferStart.y;
|
|
|
|
_screenSave._screenYOff = _screenYOff;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::restoreScreen() {
|
|
|
|
_clipWidth = _screenSave._clipWidth;
|
|
|
|
_clipHeight = _screenSave._clipHeight;
|
|
|
|
_windowXAdd = _screenSave._windowXAdd;
|
|
|
|
_windowYAdd = _screenSave._windowYAdd;
|
|
|
|
_scrollX = _screenSave._scroll.x;
|
|
|
|
_scrollY = _screenSave._scroll.y;
|
|
|
|
_scrollCol = _screenSave._scrollCol;
|
|
|
|
_scrollRow = _screenSave._scrollRow;
|
|
|
|
_bufferStart.x = _screenSave._bufferStart.x;
|
|
|
|
_bufferStart.y = _screenSave._bufferStart.y;
|
|
|
|
_screenYOff = _screenSave._screenYOff;
|
2014-08-10 02:24:35 +00:00
|
|
|
}
|
|
|
|
|
2014-08-23 02:55:17 +00:00
|
|
|
void Screen::copyBlock(ASurface *src, const Common::Rect &bounds) {
|
|
|
|
Common::Rect destBounds = bounds;
|
|
|
|
destBounds.translate(_windowXAdd, _windowYAdd + _screenYOff);
|
|
|
|
|
|
|
|
copyRectToSurface(*src, destBounds.left, destBounds.top, bounds);
|
|
|
|
}
|
|
|
|
|
2014-08-02 14:07:54 +00:00
|
|
|
} // End of namespace Access
|