aboutsummaryrefslogtreecommitdiff
path: root/sky/screen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sky/screen.cpp')
-rw-r--r--sky/screen.cpp202
1 files changed, 148 insertions, 54 deletions
diff --git a/sky/screen.cpp b/sky/screen.cpp
index b3db1d4d9e..5acc188ad3 100644
--- a/sky/screen.cpp
+++ b/sky/screen.cpp
@@ -19,18 +19,9 @@
*
*/
-#include "stdafx.h"
-#include <string.h>
-#include "common/scummsys.h"
-#include "sky/skydefs.h"
-#include "sky/sky.h"
+#include "screen.h"
-#define SCROLL_JUMP 16
-
-#define VGA_COLOURS 256
-#define GAME_COLOURS 240
-
-uint8 top16Colours[] =
+uint8 SkyScreen::_top16Colours[16*3] =
{
0, 0, 0,
38, 38, 38,
@@ -50,39 +41,76 @@ uint8 top16Colours[] =
63, 63, 63
};
-void SkyState::initialiseScreen(void) {
-
+SkyScreen::SkyScreen(OSystem *pSystem, SkyDisk *pDisk) {
+
+ _system = pSystem;
+ _skyDisk = pDisk;
+
int i;
uint8 tmpPal[1024];
_system->init_size(FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);
- _backScreen = (uint8 *)malloc(FULL_SCREEN_WIDTH * FULL_SCREEN_HEIGHT);
- //_gameGrid = (uint8 *)malloc(GRID_X * GRID_Y * 2);
- _workPalette = (uint8 *)malloc(VGA_COLOURS * 3);
+ _gameGrid = (uint8 *)malloc(GRID_X * GRID_Y * 2);
+ _currentScreen = NULL;
//blank the first 240 colors of the palette
memset(tmpPal, 0, GAME_COLOURS * 4);
//set the remaining colors
for (i = 0; i < (VGA_COLOURS-GAME_COLOURS); i++) {
- tmpPal[4 * GAME_COLOURS + i * 4] = (top16Colours[i * 3] << 2) + (top16Colours[i * 3] & 3);
- tmpPal[4 * GAME_COLOURS + i * 4 + 1] = (top16Colours[i * 3 + 1] << 2) + (top16Colours[i * 3 + 1] & 3);
- tmpPal[4 * GAME_COLOURS + i * 4 + 2] = (top16Colours[i * 3 + 2] << 2) + (top16Colours[i * 3 + 2] & 3);
+ tmpPal[4 * GAME_COLOURS + i * 4] = (_top16Colours[i * 3] << 2) + (_top16Colours[i * 3] & 3);
+ tmpPal[4 * GAME_COLOURS + i * 4 + 1] = (_top16Colours[i * 3 + 1] << 2) + (_top16Colours[i * 3 + 1] & 3);
+ tmpPal[4 * GAME_COLOURS + i * 4 + 2] = (_top16Colours[i * 3 + 2] << 2) + (_top16Colours[i * 3 + 2] & 3);
tmpPal[4 * GAME_COLOURS + i * 4 + 3] = 0x00;
}
//set the palette
_system->set_palette(tmpPal, 0, VGA_COLOURS);
+
+ _seqInfo.framesLeft = 0;
+ _seqInfo.seqData = _seqInfo.seqDataPos = NULL;
+ _seqInfo.running = false;
+}
+
+SkyScreen::~SkyScreen(void) {
+
+ free(_gameGrid);
+ if (_currentScreen) free(_currentScreen);
}
//set a new palette, pal is a pointer to dos vga rgb components 0..63
-void SkyState::setPalette(uint8 *pal) {
+void SkyScreen::setPalette(uint8 *pal) {
convertPalette(pal, _palette);
_system->set_palette(_palette, 0, GAME_COLOURS);
+ _system->update_screen();
+}
+
+void SkyScreen::setPalette(uint16 fileNum) {
+
+ uint8 *tmpPal = _skyDisk->loadFile(fileNum, NULL);
+ if (tmpPal) {
+ setPalette(tmpPal);
+ free(tmpPal);
+ } else warning("SkyScreen::setPalette: can't load file nr. %d\n",fileNum);
+}
+
+void SkyScreen::showScreen(uint16 fileNum) {
+
+ if (_currentScreen) free(_currentScreen);
+ _currentScreen = _skyDisk->loadFile(fileNum, NULL);
+
+ if (_currentScreen) showScreen(_currentScreen);
+ else warning("SkyScreen::showScreen: can't load file nr. %d\n",fileNum);
+}
+
+void SkyScreen::showScreen(uint8 *pScreen) {
+
+ _system->copy_rect(pScreen, 320, 0, 0, GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT);
+ _system->update_screen();
}
-void SkyState::convertPalette(uint8 *inPal, uint8* outPal) { //convert 3 byte 0..63 rgb to 4byte 0..255 rgbx
+void SkyScreen::convertPalette(uint8 *inPal, uint8* outPal) { //convert 3 byte 0..63 rgb to 4byte 0..255 rgbx
int i;
@@ -97,30 +125,24 @@ void SkyState::convertPalette(uint8 *inPal, uint8* outPal) { //convert 3 byte 0.
//action = 0, simply fade out
//action = 1, scroll left
//action = 2, scroll right
-void SkyState::fnFadeDown(uint8 action) {
+void SkyScreen::fnFadeDown(uint8 action) {
if (action) {
//do scroll
+ warning("SkyScreen::fnFadeDown: Scrolling not yet implemented!\n");
} else {
-
- int i = 32;
-
- do {
+ for (uint8 cnt = 0; cnt < 32; cnt++) {
palette_fadedown_helper((uint32 *)_palette, GAME_COLOURS);
_system->set_palette(_palette, 0, GAME_COLOURS);
_system->update_screen();
- delay(10);
-
- } while (--i);
-
+ waitForTimer();
+ }
}
-
-
}
-void SkyState::palette_fadedown_helper(uint32 *pal, uint num) {
+void SkyScreen::palette_fadedown_helper(uint32 *pal, uint num) {
byte *p = (byte *)pal;
do {
@@ -140,42 +162,43 @@ void SkyState::palette_fadedown_helper(uint32 *pal, uint num) {
} while (--num);
}
-void SkyState::paletteFadeUp(uint8 *pal) {
+void SkyScreen::paletteFadeUp(uint16 fileNr) {
+
+ uint8 *pal = _skyDisk->loadFile(fileNr, NULL);
+ if (pal) {
+ paletteFadeUp(pal);
+ free(pal);
+ } else printf("SkyScreen::paletteFadeUp: Can't load palette #%d\n",fileNr);
+}
+
+void SkyScreen::paletteFadeUp(uint8 *pal) {
byte tmpPal[1024];
convertPalette(pal, tmpPal);
- int i = 32;
-
- do {
-
+ for (uint8 cnt = 0; cnt < 32; cnt++) {
palette_fadeup_helper((uint32 *)_palette, (uint32 *)tmpPal, GAME_COLOURS);
_system->set_palette(_palette, 0, GAME_COLOURS);
_system->update_screen();
- delay(10);
- } while (--i);
-
+ waitForTimer();
+ }
}
-void SkyState::palette_fadeup_helper(uint32 *realPal, uint32 *desiredPal, int num) {
+void SkyScreen::palette_fadeup_helper(uint32 *realPal, uint32 *desiredPal, int num) {
byte *r = (byte *)realPal;
byte *d = (byte *)desiredPal;
do {
- if (r[0] < d[0]-8)
- r[0] += 8;
- else
- r[0] = d[0];
- if (r[1] < d[1]-8)
- r[1] += 8;
- else
- r[1] = d[1];
- if (r[2] < d[2]-8)
- r[2] += 8;
- else
- r[2] = d[2];
+ if (r[0] < d[0]-8) r[0] += 8;
+ else r[0] = d[0];
+
+ if (r[1] < d[1]-8) r[1] += 8;
+ else r[1] = d[1];
+
+ if (r[2] < d[2]-8) r[2] += 8;
+ else r[2] = d[2];
r += sizeof(uint32);
d += sizeof(uint32);
@@ -183,3 +206,74 @@ void SkyState::palette_fadeup_helper(uint32 *realPal, uint32 *desiredPal, int nu
}
+void SkyScreen::waitForTimer(void) {
+
+ _gotTick = false;
+ while (!_gotTick)
+ _system->delay_msecs(10);
+}
+
+void SkyScreen::handleTimer(void) {
+
+ _gotTick = true;
+ if (_seqInfo.running) processSequence();
+}
+
+void SkyScreen::startSequence(uint16 fileNum) {
+
+ _seqInfo.seqData = _skyDisk->loadFile(fileNum, NULL);
+ _seqInfo.framesLeft = _seqInfo.seqData[0];
+ _seqInfo.seqDataPos = _seqInfo.seqData + 1;
+ _seqInfo.delay = SEQ_DELAY;
+ _seqInfo.running = true;
+}
+
+void SkyScreen::stopSequence() {
+
+ _seqInfo.running = false;
+ waitForTimer();
+ waitForTimer();
+ _seqInfo.framesLeft = 0;
+ free(_seqInfo.seqData);
+ _seqInfo.seqData = _seqInfo.seqDataPos = NULL;
+}
+
+void SkyScreen::processSequence(void) {
+
+ uint32 screenPos = 0;
+
+ _seqInfo.delay--;
+ if (_seqInfo.delay == 0) {
+ _seqInfo.delay = SEQ_DELAY;
+
+ uint8 nrToSkip, nrToDo, cnt;
+ do {
+ do {
+ nrToSkip = _seqInfo.seqDataPos[0];
+ _seqInfo.seqDataPos++;
+ screenPos += nrToSkip;
+ } while (nrToSkip == 0xFF);
+ do {
+ nrToDo = _seqInfo.seqDataPos[0];
+ _seqInfo.seqDataPos++;
+ for (cnt = 0; cnt < nrToDo; cnt++) {
+ _currentScreen[screenPos] = _seqInfo.seqDataPos[0];
+ _seqInfo.seqDataPos++;
+ screenPos++;
+ }
+ } while (nrToDo == 0xFF);
+ } while (screenPos < (GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT));
+ showScreen(_currentScreen);
+ _seqInfo.framesLeft--;
+ }
+ if (_seqInfo.framesLeft == 0) {
+ _seqInfo.running = false;
+ free(_seqInfo.seqData);
+ _seqInfo.seqData = _seqInfo.seqDataPos = NULL;
+ }
+}
+
+bool SkyScreen::sequenceRunning(void) {
+
+ return _seqInfo.running;
+}