1
//*****************************************************************************
2
// copyright (c) 1998-2003 TLK Games all rights reserved
3
//-----------------------------------------------------------------------------
4
// file : "playanim.cpp"
6
// updates : 2003-07-20
7
//-----------------------------------------------------------------------------
8
// functions : int joueAnimation()
9
// int InitAnim(char *)
12
// unsigned char* PlayAnim(int);
13
// unsigned char* decompress(unsigned char*, unsigned char*,unsigned char*);
14
//-----------------------------------------------------------------------------
15
// descriptions : play animation /
16
//-----------------------------------------------------------------------------
17
// This program is free software; you can redistribute it and/or modify it under
18
// the terms of the GNU General Public License as published by the Free Software
19
// Foundation; either version 2 of the License, or (at your option) any later
22
// This program is distributed in the hope that it will be useful, but WITHOUT
23
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
24
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
27
// You should have received a copy of the GNU General Public License along with
28
// this program; if not, write to the Free Software Foundation, Inc., 59 Temple
29
// Place - Suite 330, Boston, MA 02111-1307, USA.
31
//*****************************************************************************
32
#include "powermanga.hpp"
33
//..............................................................................
34
unsigned char *image1 = 0;
35
static unsigned char *image2 = 0;
36
static unsigned char *icmpr = 0;
37
static unsigned char *smage1 = 0;
38
static unsigned char *smage2 = 0;
39
static unsigned char *scmpr = 0;
40
static unsigned char *pFichier = 0; //pointer to the file in memory
42
//..............................................................................
43
static unsigned char *pcxpal = 0; //pointer to the colormap in the file
45
static int images = 0;
47
//..............................................................................
48
extern unsigned int iOctetsParPixel; //bytes per pixel "xwindow.cpp"
49
extern unsigned int iCodeTouche; //key code pressed)
50
extern unsigned int iJoueIntro; //(1=intro / 2=congratulation)
51
extern unsigned short *pal16PlayAnim; //16 bits colormap (2 bytes par color)
52
extern unsigned int *pal32PlayAnim; //32 bits colormap (4 bytes par color)
54
//locals functions .............................................................
58
unsigned char *PlayAnim(int);
59
unsigned char *decompress(unsigned char *, unsigned char *, unsigned char *);
61
//------------------------------------------------------------------------------
62
// play animation compressed
63
//------------------------------------------------------------------------------
67
{ //introduction animation
69
if(InitAnim("graphics/deb.gca"))
73
afficheErreur("InitAnim(\"graphics/deb.gca\")", "playanim.cpp/joueAnimation()");
77
//congratulation animation
79
if(InitAnim("graphics/fin.gca"))
83
afficheErreur("InitAnim(\"graphics/fin.gca\")", "playanim.cpp/joueAnimation()");
87
//play animation compressed
89
{ unsigned char *_pScreen = PlayAnim(0);
90
if(_pScreen != NULL && iCodeTouche == 0)
103
//------------------------------------------------------------------------------
104
// initialize animation
105
// input => _pFileName : filename
106
//------------------------------------------------------------------------------
107
int InitAnim(char *_pFileName)
110
smage1 = smage2 = scmpr = 0;
111
smage1 = ((unsigned char *)reserveMemoire(64000));
113
{ afficheErreur("'smage1' out of memory", "playanim.cpp/InitAnim()");
116
smage2 = ((unsigned char *)reserveMemoire(64000));
118
{ afficheErreur("'smage2' out of memory", "playanim.cpp/InitAnim()");
121
pFichier = ((unsigned char *)reserveMemoire((1024 * 1024 * 4)));
123
{ afficheErreur("'pFichier' out of memory", "playanim.cpp/InitAnim");
126
for(i = 0; i < 64000; i++)
130
if(!ainit(_pFileName))
131
{ afficheErreur("ainit() failed !", "playanim.cpp/InitAnim()");
138
if(!reserve_ecranPlayanim())
139
{afficheErreur("reserve_ecranPlayanim() failed !", "playanim.cpp/InitAnim()");
145
//------------------------------------------------------------------------------
146
// initialize animation
147
// input => _pFileName : filename
148
//------------------------------------------------------------------------------
149
int ainit(char *_pFileName)
154
if(!chargeFichier(_pFileName, (char *)pFichier))
156
_p32 = (int *)pFichier;
157
images = litMot32bits(_p32++);
158
_p8 = (unsigned char *)_p32;
161
if(iOctetsParPixel == 2)
164
pal16PlayAnim = (unsigned short *)reserveMemoire(256 * 2);
167
afficheErreur("'pal16PlayAnim' out of memory", "playanim.cpp/InitAnim()");
170
convertitPalette24_16(pcxpal, pal16PlayAnim); //"assembler.S"
172
if(iOctetsParPixel > 2)
175
pal32PlayAnim = (unsigned int *)reserveMemoire(256 * 4);
178
afficheErreur("'pal32PlayAnim' out of memory", "playanim.cpp/InitAnim()");
181
unsigned char *_p = (unsigned char *)pal32PlayAnim;
182
unsigned char *_pPal = pcxpal;
183
for(int _iIndex = 0; _iIndex < 256; _iIndex++)
185
#if __BYTE_ORDER == __BIG_ENDIAN
217
//------------------------------------------------------------------------------
218
// playanim : free memory
219
//------------------------------------------------------------------------------
223
{ libereMemoire((char *)smage1);
227
{ libereMemoire((char *)smage2);
231
{ libereMemoire((char *)pal16PlayAnim);
234
kill_ecranPlayanim(); // "xwindow.cpp" free XImage
237
//------------------------------------------------------------------------------
238
// playanim : run-time
239
//------------------------------------------------------------------------------
240
unsigned char *PlayAnim(int bcl)
243
unsigned char *tmp; //images=64+16+2+1+1 ;
251
for(i = 0; i < 64000; i++)
256
icmpr = decompress(icmpr, image1, image2);
263
//------------------------------------------------------------------------------
264
// playanim : decompress
265
//------------------------------------------------------------------------------
266
unsigned char *decompress(unsigned char *wsc, unsigned char *im1, unsigned char *im2)
280
c = *wsc++; //read a byte
287
else if((c & 0xc0) == 0)
288
{ unsigned int wr = 0;
293
position = (wr >> 6) & 65535;
296
else if((c & 0xc0) == 0x40)
297
{ unsigned int wr = 0;
299
wr += (*wsc++) << 16;
302
longueur = wr & 16383;
303
position = (wr >> 14) & 65535;
306
else if((c & 0xe0) == 0x80)
307
{ unsigned int wr = 0;
311
retour = (wr >> 6) & 255;
314
else if((c & 0xe0) == 0xa0)
315
{ unsigned int wr = 0;
320
retour = (wr >> 8) & 8191;
323
else if((c & 0xe0) == 0xc0)
324
{ unsigned int wr = 0;
326
wr += (*wsc++) << 16;
329
longueur = wr & 8191;
330
position = (wr >> 13) & 65535;
333
if(i + longueur > 64000)
334
{ longueur = 64000 - i;
337
{ for(j = 0; j < longueur; j++)
338
*idec++ = im1[position + j];
342
{ wdec = idec - retour;
343
for(j = 0; j < longueur; j++)
348
{ for(j = 0; j < longueur; j++)
349
*idec++ = im2[position + j];