-
Notifications
You must be signed in to change notification settings - Fork 0
/
PAL.C
224 lines (196 loc) · 5.75 KB
/
PAL.C
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*******************************************************************************
PAL.C
These routines are used to manipulate a palette.
Routines to fade in and out, set R,G,B palettes.
********************************************************************************/
#include <mem.h> // for memset
#include "game386.h" //needed for SetPal
#include "sound.h"
static char far Pal[768];
/*******************************************************************************
Sets the active palette to all black. Useful for drawing a screen and then
fading in later.
*******************************************************************************/
void far Black_Pal( void )
{
memset( Pal, 0, 768 ); // sets all of temp Pal = 0 (black)
SetPal( Pal ); // set palette using temp Pal (black)
}
/*******************************************************************************
Fades in from black to the specified palette.
*******************************************************************************/
void far FadeIn( char far * palette , int speed )
{
int i, j, v;
for( i = 0; i < 32; i++ )
{
msdelay( speed );
for( j = 0; j < 768; j++ )
Pal[j] = (i * (unsigned)palette[j]) >> 5;
SetPal( Pal );
}
}
/*******************************************************************************
Fades to black from a specified palette.
*******************************************************************************/
void far FadeOut( char far * palette , int speed )
{
int i, j, v;
for( i = 31; i >= 0; i-- )
{
msdelay( speed );
for( j = 0; j < 768; j++ )
Pal[j] = (i * (unsigned)palette[j]) >> 5;
SetPal( Pal );
}
}
/*******************************************************************************
Fades to Red and back again from a specified palette.
*******************************************************************************/
void FadeToRed( char far * palette, int speed )
{
int j, i;
for( i=31; i>=0; i--)
{
for( j=0; j < 768; j+=3 )
{
Pal[j+1] = (i * (unsigned)palette[j+1]) >> 5;
Pal[j+2] = (i * (unsigned)palette[j+2]) >> 5;
}
SetPal( Pal );
}
for( i=0; i<32; i++)
{
msdelay( speed+15 );
for( j=0; j < 768; j+=3 )
{
Pal[j+1] = (i * (unsigned)palette[j+1]) >> 5;
Pal[j+2] = (i * (unsigned)palette[j+2]) >> 5;
}
SetPal( Pal );
}
}
/*
//***************************************************************************
// Changes palette to RED.
//***************************************************************************
void RGB2Red( char * palette )
{
int j;
for( j = 0; j < 768; j+=3 )
{
Pal[j+1] = ((unsigned)palette[j]) >> 5;
Pal[j+2] = ((unsigned)palette[j]) >> 5;
}
SetPal( Pal );
}
//***************************************************************************
// Changes palette to GREEN.
//***************************************************************************
void RGB2Green( char * palette )
{
int j;
for( j = 0; j < 768; j+=3 )
{
Pal[j] = ((unsigned)palette[j]) >> 5;
Pal[j+2] = ((unsigned)palette[j]) >> 5;
}
SetPal( Pal );
}
//***************************************************************************
// Changes palette to Blue.
//***************************************************************************
void RGB2Blue( char * palette )
{
int j;
for( j = 0; j < 768; j+=3 )
{
Pal[j] = ((unsigned)palette[j]) >> 5;
Pal[j+1] = ((unsigned)palette[j]) >> 5;
}
SetPal( Pal );
}
//***************************************************************************
// Fades specified palette darker.
//***************************************************************************
void Fade_Darker( char * palette , int amount , int speed)
{
int i, j;
int v = 0;
if( amount>31 ) v = 31;
v=31-amount;
for( i = 31; i >= v; i-- )
{
msdelay( speed );
for( j = 0; j < 768; j++ )
Pal[j] = (i * (unsigned)palette[j]) >> 5;
SetPal( Pal );
}
}
/*******************************************************************************
Fades in only a part of the palette.
*******************************************************************************
PartFadeIn( int first, int num, char far* palette )
{
int i, j, v;
for( i = 0; i < 32; i++ )
{
for( j = 0; j < num * 3; j++ )
Pal[j] = (i * (unsigned)palette[j]) >> 5;
SetPartPal( first, num, Pal );
}
return;
}
/*******************************************************************************
Fades out only a part of the palette.
*******************************************************************************
PartFadeOut( int first, int num, char far* palette )
{
int i, j, v;
for( i = 31; i >= 0; i-- )
{
for( j = 0; j < num * 3; j++ )
Pal[j] = (i * (unsigned)palette[j]) >> 5;
SetPartPal( first, num, Pal );
}
return;
}
/*******************************************************************************
Cycles 'num' palette entries, starting at the 'first' entry. Entries are
cycled to the "left".
*******************************************************************************
PartCycleL( int first, int num, char far* palette )
{
int i, a, b, c;
num--;
a = palette[0];
b = palette[1];
c = palette[2];
for( i = 0; i < num * 3; i++ )
palette[i] = palette[i + 3];
palette[i] = a;
palette[i + 1] = b;
palette[i + 2] = c;
SetPartPal( first, num + 1, palette );
return;
}
/*******************************************************************************
Cycles 'num' palette entries, starting at the 'first' entry. Entries are
cycled to the "right".
*******************************************************************************
PartCycleR( int first, int num, char far* palette )
{
int i, a, b, c;
i = (num * 3) - 1;
a = palette[i - 2];
b = palette[i - 1];
c = palette[i];
for( ; i >= 3; i-- )
palette[i] = palette[i - 3];
palette[0] = a;
palette[1] = b;
palette[2] = c;
SetPartPal( first, num, palette );
return;
}
*/