aboutsummaryrefslogtreecommitdiff
path: root/sky/screen.cpp
blob: 8e8c15b1bab9b2f46321d1845125e4bbdefa9da1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2003 The ScummVM project
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 *
 */

#include "stdafx.h"
#include <string.h>
#include "common/scummsys.h"
#include "sky/skydefs.h"
#include "sky/sky.h"

#define SCROLL_JUMP		16

#define VGA_COLOURS		256
#define GAME_COLOURS		240

uint8 top16Colours[] =
{
	0, 0, 0,
	38, 38, 38,
	63, 63, 63,
	0, 0, 0,
	0, 0, 0,
	0, 0, 0,
	0, 0, 0,
	54, 54, 54,
	45, 47, 49,
	32, 31, 41,
	29, 23, 37,
	23, 18, 30,
	49, 11, 11,
	39, 5, 5,
	29, 1, 1,
	63, 63, 63
};

void SkyState::initialiseScreen(void) {
	
	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);

	//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[GAME_COLOURS + i * 4] = (top16Colours[i * 3] << 2) + (top16Colours[i * 3] & 3);
		tmpPal[GAME_COLOURS + i * 4 + 1] = (top16Colours[i * 3 + 1] << 2) + (top16Colours[i * 3 + 1] & 3);
		tmpPal[GAME_COLOURS + i * 4 + 2] = (top16Colours[i * 3 + 2] << 2) + (top16Colours[i * 3 + 2] & 3);
		tmpPal[GAME_COLOURS + i * 4 + 3] = 0x00; 
	}

	//set the palette
	_system->set_palette(tmpPal, 0, 256);
}

//set a new palette, pal is a pointer to dos vga rgb components 0..63
void SkyState::setPalette(uint8 *pal) {
	
	convertPalette(pal, _palette);
	_system->set_palette(_palette, 0, 256);
}

void SkyState::convertPalette(uint8 *inPal, uint8* outPal) { //convert 3 byte 0..63 rgb to 4byte 0..255 rgbx
	
	int i;

	for (i = 0; i < VGA_COLOURS; i++) {
		outPal[4 * i] = (inPal[3 * i] << 2) + (inPal[3 * i] & 3);
		outPal[4 * i + 1] = (inPal[3 * i + 1] << 2) + (inPal[3 * i + 1] & 3);
		outPal[4 * i + 2] = (inPal[3 * i + 2] << 2) + (inPal[3 * i + 2] & 3);
		outPal[4 * i + 3] = 0x00;
	}
}

//action = 0, simply fade out
//action = 1, scroll left
//action = 2, scroll right
void SkyState::fnFadeDown(uint8 action) {

	if (action) {
	
		//do scroll

	} else {
	
		int i = 32;

		do {
			palette_fadedown_helper((uint32 *)_palette, 256);
			_system->set_palette(_palette, 0, 256);
			_system->update_screen();
			delay(10);
			
		} while (--i);
	
	}

	
}

void SkyState::palette_fadedown_helper(uint32 *pal, uint num) {
	byte *p = (byte *)pal;

	do {
		if (p[0] >= 8)
			p[0] -= 8;
		else
			p[0] = 0;
		if (p[1] >= 8)
			p[1] -= 8;
		else
			p[1] = 0;
		if (p[2] >= 8)
			p[2] -= 8;
		else
			p[2] = 0;
		p += sizeof(uint32);
	} while (--num);
}

void SkyState::paletteFadeUp(uint8 *pal) {

	byte tmpPal[1024];
	
	convertPalette(pal, tmpPal);

	int i = 32;

	do {

		palette_fadeup_helper((uint32 *)_palette, (uint32 *)tmpPal, 256);
		_system->set_palette(_palette, 0, 256);
		_system->update_screen();
		delay(10);	
	} while (--i);
	
}

void SkyState::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];
				
		r += sizeof(uint32);
		d += sizeof(uint32);
	} while (--num);
	
}