~ubuntu-branches/ubuntu/raring/powermanga/raring

« back to all changes in this revision

Viewing changes to src/sdl_tlk.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Gonéri Le Bouder, Cyril Brulebois, Barry deFreese
  • Date: 2008-03-19 21:32:41 UTC
  • mfrom: (1.2.4 upstream) (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080319213241-sn6w3z75uppm22eq
Tags: 0.90-dfsg-1
[ Gonéri Le Bouder ]
* add desktop file, thanks Adrien Cunin (Closes: #402168)
 - powermanga.xpm moved in /usr/share/pixmaps
* call dh_desktop to run update-desktop-database

[ Cyril Brulebois ]
* Added XS-Vcs-Svn and XS-Vcs-Browser fields in the control file.

[ Barry deFreese ]
* Bump debhelper build-dep version to match compat
* Fix substvar source:Version
* Make distclean not ignore errors
* Add watch file
* Add Homepage field in control
* Remove XS- from VCS fields in control
* New Upstream Release (Closes: #447415)
  + Should now be dfsg free
  + Adds joystick support (Closes: #442322)
  + STILL NOT SURE ABOUT tlk.fnt
* Revert patches except fixing scoredir path and copyright for manpage
* Remove deprecated Encoding tag from desktop file
* Remove file extension from icon tag in desktop file
* Replace evil 'pwd' with $(CURDIR)
* Removing config.log config.status in clean target
* Convert copyright to UTF-8.
* Remove order/ dir from upstream tarball.
* Remove empty dirs from powermanga package.
* Bump Standards Version to 3.7.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//*****************************************************************************
2
 
// copyright (c) 1998-2005 TLK Games all rights reserved
3
 
//-----------------------------------------------------------------------------
4
 
// file         : "sdl_tlk.cpp"
5
 
// created      : 2003-07-09
6
 
// updates      : 2005-01-26
7
 
// id           : %Id$
8
 
//-----------------------------------------------------------------------------
9
 
// This program is free software; you can redistribute it and/or modify it under
10
 
// the terms of the GNU General Public License as published by the Free Software
11
 
// Foundation; either version 2 of the License, or (at your option) any later
12
 
// version.t
13
 
//
14
 
// This program is distributed in the hope that it will be useful, but WITHOUT
15
 
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17
 
// details.
18
 
//
19
 
// You should have received a copy of the GNU General Public License along with
20
 
// this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21
 
// Place - Suite 330, Boston, MA  02111-1307, USA.
22
 
// Place - Suite 330, Boston, MA  02111-1307, USA.
23
 
//
24
 
//*****************************************************************************
25
 
#include "powermanga.hpp"
26
 
#ifdef SDL_TLK
27
 
//------------------------------------------------------------------------------
28
 
SDL_Surface           *pPowerMangaDisplay;
29
 
SDL_Surface            *pEcranXImage = 0;                      //(4 octets=pointeur) SDL_Surface de 512*440
30
 
SDL_Surface            *pEcranXImage640 = 0;                   //(4 octets=pointeur) SDL_Surface de 640*400
31
 
SDL_Surface            *pEcranOptXImage = 0;                   //(4 octets=pointeur) SDL_Surface de 64*184
32
 
SDL_Surface            *pEcranScrXImage = 0;                   //(4 octets=pointeur) SDL_Surface de 320*16
33
 
unsigned int            iOctetsParPixel = 0;                   //nombre d'octets par pixels (1=256 couleurs / 2=32768 couleurs)
34
 
unsigned char          *pal = 0;                               //palette de couleurs 24 bits (3 octets par couleur)
35
 
unsigned int           *pal32 = 0;                             //palette de couleurs 24 bits (4 octets par couleur)
36
 
unsigned short         *pal16 = 0;                             //palette de couleurs 16 bits (2 octets par couleur)
37
 
unsigned short         *pal16PlayAnim = 0;                     //palette de couleurs 16 bits (2 octets par couleur)
38
 
unsigned int           *pal32PlayAnim = 0;                     //palette de couleurs 16 bits (2 octets par couleur)
39
 
SDL_Surface            *pEcranPlayanim = 0;                    //(4 octets=pointeur) SDL_Surface de 320*200
40
 
const unsigned int      iXIMAGEMAX = 100;
41
 
unsigned int            iNombreXImage = 0;
42
 
SDL_Surface            *pListeXImage[iXIMAGEMAX];
43
 
 
44
 
//...............................................................................
45
 
unsigned int            iProfondeur = 0;                       //profondeur en bits de l'ecran
46
 
unsigned int            iProfondeur2 = 0;                      //profondeur en bits de l'ecran
47
 
unsigned int            iLargeurEcran = 0;                     //largeur de notre fenetre
48
 
unsigned int            iHauteurEcran = 0;                     //hauteur de notre fenetre
49
 
unsigned int            iLargeurEcranTotal = 0;                //taille d'une ligne du buffer 'ecran_ram'
50
 
int                     vmode = 1;                             //0=resolution de 320x200 / 1=640*400 / 2=640*400 (double pixels)
51
 
#ifdef WIN32
52
 
Sint32                  vmode2 = 1;                             // si vmode = 1 ==> 0 = 640x400 / 1 = 640x480
53
 
#else
54
 
Sint32                  vmode2 = 0;
55
 
#endif
56
 
 
57
 
//...............................................................................
58
 
char                   *ecran_playanim = 0;                    //memory buffer 320*200
59
 
char                   *ecran_ram640 = 0;                      //memory buffer 640*400
60
 
char                   *ecran_scr = 0;                         //memory buffer 320*016 (score bar-line)
61
 
char                   *ecran_opt = 0;                         //memory buffer 064*184 (option panel)
62
 
unsigned int            iAffiche = 0;                          //0=update display option panel and bareline's score
63
 
 
64
 
//..............................................................................
65
 
extern bool             bar_nrj_player;
66
 
extern char            *ecran_ram;                             //adresse du buffer de 512x440 (XImage)
67
 
extern short            touch[500];                            //tableau des flags de toutes les touches clavier
68
 
extern int              quit_game;                             //1=demande a quitter le jeu
69
 
extern unsigned int     iCodeTouche;                           // code touche pressee
70
 
 
71
 
//...............................................................................
72
 
 
73
 
//..............................................................................
74
 
void                    initialiseCurseurBlanc();
75
 
void                    affiche_ecran();
76
 
void                    afficheAnim();
77
 
 
78
 
void                    fenetre320x200();
79
 
void                    fenetre640x400();
80
 
 
81
 
void                    dga320x200();
82
 
void                    dga640x400();
83
 
 
84
 
SDL_Surface            *creeXImage(unsigned int _iLarge,
85
 
                                   unsigned int _iHaute);
86
 
void                    libereXImage(SDL_Surface *_pXImage);
87
 
void                    libereXImages();
88
 
void                    key_status(Uint8 *k);
89
 
 
90
 
//display optimisation for options .............................................
91
 
extern unsigned int     pOptionChange[22][2];                  //display options, positions in the window
92
 
extern int              iOptionIndex;                          //index to the "pOptionChange" table, display options
93
 
extern unsigned int     iBonusX2Affiche;                       //display bonusX2 in our window
94
 
extern unsigned int     iBonusX4Affiche;                       //display bonusX4 in out window
95
 
extern unsigned char   *image1;                                //pointer to the buffer for the full screen animations
96
 
extern unsigned int     iBarreNrjJoueurXWindow;                //1=update player's enerny bar-line
97
 
extern unsigned int     iBarreNrjGardienXWindow;               //1=update bigboss's energy bar-line
98
 
extern unsigned int     iScoreXWindow;                         //1=update player's score points
99
 
extern configfile*      power_conf;
100
 
 
101
 
//...............................................................................
102
 
SDL_Color              *pXColor = 0;                           //color table
103
 
 
104
 
//...............................................................................
105
 
char nomfenetre[] = "Powermanga by TLK Games (SDL version)\0";
106
 
 
107
 
 
108
 
 
109
 
//------------------------------------------------------------------------------
110
 
// SDL : initialise un affichage SDL / initialize SDL display
111
 
// sortie / output <= 0 : erreur
112
 
//------------------------------------------------------------------------------
113
 
int xw_init()
114
 
{
115
 
  for(unsigned int _iIndex = 0; _iIndex < iXIMAGEMAX; _iIndex++)
116
 
    pListeXImage[_iIndex] = 0;
117
 
 
118
 
//..............................................................................
119
 
  if(!vmode)
120
 
  { iLargeurEcran = LARG_ECRAN_PHY;
121
 
    iHauteurEcran = HAUT_ECRAN_PHY;
122
 
  }
123
 
  else
124
 
  { iLargeurEcran = LARG_ECRAN_PHY * 2;
125
 
    iHauteurEcran = HAUT_ECRAN_PHY * 2;
126
 
  }
127
 
 
128
 
 
129
 
 
130
 
  // initialize SDL screen .....................................................
131
 
  
132
 
  //if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE) <0 )
133
 
  if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
134
 
  { fprintf(stderr, "ecran_hard::ecran_init() : sdl_init: %s", SDL_GetError());
135
 
    return 0;
136
 
  }
137
 
 
138
 
  const SDL_VideoInfo *vi;
139
 
  vi = SDL_GetVideoInfo();
140
 
  iProfondeur = vi->vfmt->BitsPerPixel;
141
 
  iOctetsParPixel = vi->vfmt->BytesPerPixel;
142
 
  
143
 
  if(iProfondeur == 16) {
144
 
      iProfondeur = vi->vfmt->Rshift + vi->vfmt->Gshift + vi->vfmt->Bshift;
145
 
  }
146
 
  iProfondeur2 = iProfondeur;
147
 
  if(iProfondeur < 8)
148
 
  { afficheErreur("this game need 8 bits peer pixels minimum (256 colors)",
149
 
                  "sdl_tlk.cpp/xw_init()");
150
 
    return 0;
151
 
  }
152
 
#ifdef _VERBEUX_
153
 
  if(power_conf->verbose)
154
 
  { printf
155
 
      ("> sdl_tlk.cpp/xw_init(): depth of screen: %i; bytes per pixel: %i;\n",
156
 
       iProfondeur, iOctetsParPixel);
157
 
  }
158
 
#endif
159
 
  if(!init_video_mode())
160
 
    return 0;
161
 
 
162
 
  SDL_EnableUNICODE(1);
163
 
#ifdef _VERBEUX_
164
 
  if(power_conf->verbose)
165
 
    afficheMessage("> sdl_tlk.cpp/xw_init(): successful initialization!");
166
 
#endif
167
 
  return 1;
168
 
}
169
 
 
170
 
//------------------------------------------------------------------------------
171
 
// SDL: initialize video mode
172
 
// return: 0 = > error / 1 => no error
173
 
//------------------------------------------------------------------------------
174
 
int init_video_mode()
175
 
{
176
 
        Uint32 flag;
177
 
        Uint32 bpp;
178
 
 
179
 
        //##############################################################
180
 
        // 640x400 => 640x480 (win32 only)
181
 
        //##############################################################
182
 
        if ((vmode) && (vmode2)) {
183
 
                iHauteurEcran = 480;
184
 
        }
185
 
        
186
 
        //##############################################################
187
 
        // test video mode
188
 
        //##############################################################
189
 
        flag = SDL_ANYFORMAT;
190
 
        if(iOctetsParPixel == 1)
191
 
                flag = flag | SDL_HWPALETTE;
192
 
        if(power_conf->fullscreen > 0)
193
 
                flag = flag | SDL_FULLSCREEN; 
194
 
        bpp = SDL_VideoModeOK(iLargeurEcran, iHauteurEcran, iProfondeur2, flag);
195
 
        if(!bpp)
196
 
        {       if(!power_conf->fullscreen)
197
 
                {       fprintf(stderr,
198
 
                                "sdl_tlk.cpp/init_video_mode(): SDL_VideoModeOK() return: %s",
199
 
                                SDL_GetError());
200
 
                        return 0;
201
 
                }
202
 
                else 
203
 
                {
204
 
                        // fullscreen fail, try in window mode
205
 
                        power_conf->fullscreen = 0;
206
 
                        flag = SDL_ANYFORMAT;
207
 
                        if(iOctetsParPixel == 1)
208
 
                                flag = flag | SDL_HWPALETTE;
209
 
                        bpp = SDL_VideoModeOK(iLargeurEcran, iHauteurEcran, iProfondeur2, flag);
210
 
                        if(!bpp)
211
 
                        {       fprintf(stderr,
212
 
                                        "sdl_tlk.cpp/init_video_mode(): SDL_VideoModeOK() return: %s",
213
 
                                        SDL_GetError());
214
 
                                return 0;
215
 
                        }
216
 
                }
217
 
        }
218
 
 
219
 
  
220
 
        //##############################################################
221
 
        // initialize video mode
222
 
        //##############################################################
223
 
        pPowerMangaDisplay =
224
 
                SDL_SetVideoMode(iLargeurEcran, iHauteurEcran, iProfondeur2, flag);
225
 
        if(!pPowerMangaDisplay)
226
 
        {       fprintf(stderr,
227
 
                        "sdl_tlk.cpp/init_video_mode(): SDL_SetVideoMode() return %s\n",
228
 
                        SDL_GetError());
229
 
                return 0;
230
 
        }
231
 
  
232
 
        //##############################################################
233
 
        // restore valid height screen (win32 only)
234
 
        //##############################################################
235
 
        if ((vmode) && (vmode2)) {
236
 
                iHauteurEcran = HAUT_ECRAN_PHY * 2;
237
 
        }
238
 
 
239
 
        SDL_WM_SetCaption(nomfenetre, nomfenetre);
240
 
        iAffiche = 0; // force refresh all the screen
241
 
        if(power_conf->fullscreen > 0)
242
 
                SDL_ShowCursor(SDL_DISABLE);
243
 
        else 
244
 
                SDL_ShowCursor(SDL_ENABLE);  
245
 
        return 1;
246
 
}
247
 
 
248
 
//------------------------------------------------------------------------------
249
 
// SDL destroy surface / start anim and end anim / "playanim.cpp"
250
 
//------------------------------------------------------------------------------
251
 
void kill_ecranPlayanim()
252
 
{
253
 
  libereXImage(pEcranPlayanim);
254
 
  ecran_playanim = 0;
255
 
  pEcranPlayanim = 0;
256
 
}
257
 
 
258
 
//------------------------------------------------------------------------------
259
 
// SDL : create surface / start anim and end anim / "playanim.cpp"
260
 
//------------------------------------------------------------------------------
261
 
int reserve_ecranPlayanim()
262
 
{
263
 
  if(!(pEcranPlayanim = creeXImage(LARG_ECRAN_PHY, HAUT_ECRAN_PHY)))
264
 
    return 0;
265
 
  ecran_playanim = (char *)pEcranPlayanim->pixels;
266
 
  return 1;                                                    //no error
267
 
}
268
 
 
269
 
//------------------------------------------------------------------------------
270
 
// SDL : create 3 or 4 surfaces for the game
271
 
//------------------------------------------------------------------------------
272
 
int reserve_ecran_ram()
273
 
{
274
 
  //create surface "ecran_ram" 512*440
275
 
  if(!(pEcranXImage = creeXImage(LARG_ECR_RAM_TOT, HAUT_ECR_RAM_TOT)))
276
 
    return 0;
277
 
  ecran_ram = (char *)pEcranXImage->pixels;
278
 
  iLargeurEcranTotal = LARG_ECR_RAM_TOT * iOctetsParPixel;
279
 
 
280
 
  //create surface 640x400 (window 640x400)
281
 
  if(vmode == 1)
282
 
  {
283
 
    if(!(pEcranXImage640 = creeXImage(iLargeurEcran, iHauteurEcran)))
284
 
      return 0;
285
 
    ecran_ram640 = (char *)pEcranXImage640->pixels;
286
 
  }
287
 
  if(!(pEcranOptXImage = creeXImage(OPT_LARGE, OPT_HAUTE)))
288
 
    return 0;
289
 
  ecran_opt = (char *)pEcranOptXImage->pixels;
290
 
  if(!(pEcranScrXImage = creeXImage(SCR_LARGE, SCR_HAUTE)))
291
 
    return 0;
292
 
  ecran_scr = (char *)pEcranScrXImage->pixels;
293
 
  return 1;
294
 
}
295
 
 
296
 
//------------------------------------------------------------------------------
297
 
// SDL : create palette 16 bits and 24 bits
298
 
//       recopie la palette 24 bits et cree une palette 16 bits
299
 
// entree / input => _pNomFichier : filname's palette /  nom du fichier palette
300
 
//------------------------------------------------------------------------------
301
 
int charge_palette(char *_pNomFichier)
302
 
{
303
 
  unsigned int _iIndex;
304
 
  unsigned char *_pPal;
305
 
  if(!pal)
306
 
    pal = (unsigned char *)chargeFichier(_pNomFichier);
307
 
  if(!pal)
308
 
    return 0;
309
 
 
310
 
  //ecran 8 bits 256 couleurs  . . . . . . . . . . . . . . . . . . . . . . . . . .
311
 
  if(iOctetsParPixel == 1)
312
 
  { if(!pXColor)
313
 
      pXColor = (SDL_Color *) reserveMemoire(sizeof(SDL_Color) * 256);
314
 
    if(!pXColor)
315
 
    { afficheErreur("'pXColor' out of memory", "sdl_tlk.cpp/charge_palette()");
316
 
      return 0;
317
 
    }
318
 
    unsigned char *_p = (unsigned char *)pal;
319
 
    for(_iIndex = 0; _iIndex < 256; _iIndex++)
320
 
    { pXColor[_iIndex].r = _p[0] ;
321
 
      pXColor[_iIndex].g = _p[1] ;
322
 
      pXColor[_iIndex].b = _p[2] ;
323
 
      _p += 3;
324
 
    }
325
 
    SDL_SetPalette(pPowerMangaDisplay,
326
 
      SDL_PHYSPAL | SDL_LOGPAL, pXColor, 0, 256);
327
 
  }
328
 
  else
329
 
 
330
 
  //ecran 16 bits 65536 couleurs   . . . . . . . . . . . . . . . . . . . . . . . .
331
 
  { if(iOctetsParPixel == 2)
332
 
    { if(!pal16)
333
 
        pal16 = (unsigned short *)reserveMemoire(256 * 2);
334
 
      if(!pal16)
335
 
      { afficheErreur("'pal16' out of memory", "sdl_tlk.cpp/charge_palette()");
336
 
        return 0;
337
 
      }
338
 
      if(iProfondeur2 == 15)
339
 
        convertitPalette24_15(pal, pal16);
340
 
      else
341
 
        convertitPalette24_16(pal, pal16);
342
 
    }
343
 
    else
344
 
 
345
 
    //ecran 24 ou 32 bits  . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
346
 
    { if(iOctetsParPixel > 2)
347
 
      { if(!pal32)
348
 
          pal32 = (unsigned int *)reserveMemoire(256 * 4);
349
 
        if(!pal32)
350
 
        { afficheErreur("'pal32' out of memory", "sdl_tlk.cpp/charge_palette()");
351
 
          return 0;
352
 
        }
353
 
        unsigned char *_p = (unsigned char *)pal32;
354
 
        _pPal = pal;
355
 
        //_p[3]=? / _p[2]=red / _p[1]=green / _p[0]=blue
356
 
        for(_iIndex = 0; _iIndex < 256; _iIndex++)
357
 
        { _p[2] = _pPal[2];
358
 
          _p[1] = _pPal[1];
359
 
          _p[0] = _pPal[0];
360
 
          _p[3] = 0;          
361
 
          _p += 4;
362
 
          _pPal += 3;
363
 
        }
364
 
      }
365
 
    }
366
 
  }
367
 
  return 1;
368
 
}
369
 
 
370
 
 
371
 
//------------------------------------------------------------------------------
372
 
// SDL : gestion des evenements
373
 
//------------------------------------------------------------------------------
374
 
int xw_exec()
375
 
{
376
 
  SDL_Event event;
377
 
  SDL_KeyboardEvent *ke;
378
 
  //SDL_keysym *ks;
379
 
  while(SDL_PollEvent(&event) > 0)
380
 
  { switch (event.type)
381
 
    {
382
 
      // key down
383
 
      case SDL_KEYDOWN:
384
 
      { ke = (SDL_KeyboardEvent*) &event;
385
 
        //printf("sdl_tlk.cpp/xw_exec() SDL_KEYDOWN : %i %i %i %i\n",ke->type, ke->keysym.sym, ke->keysym.unicode, ke->state);
386
 
        Uint8 *keys;
387
 
        keys = SDL_GetKeyState(NULL);
388
 
        if ( keys[SDLK_F10] == SDL_PRESSED)
389
 
        { quit_game = 1;
390
 
        }
391
 
        key_status(keys);
392
 
        if(ke->keysym.unicode > 0)
393
 
          _chaine::setCodeTouchePressee(ke->keysym.unicode);
394
 
        else
395
 
          _chaine::setCodeTouchePressee(ke->keysym.sym); 
396
 
        iCodeTouche = ke->keysym.sym;                         //sauve le code touche
397
 
 
398
 
      }
399
 
      break;
400
 
 
401
 
      case SDL_KEYUP:
402
 
      { ke = (SDL_KeyboardEvent*) &event;
403
 
        //printf("sdl_tlk.cpp/xw_exec() SDL_KEYUP : %i %i %i %i\n",ke->type, ke->keysym.sym, ke->keysym.unicode, ke->state);
404
 
        Uint8 *keys;
405
 
        keys = SDL_GetKeyState(NULL);
406
 
        if(ke->keysym.unicode > 0)
407
 
          _chaine::setCodeToucheRelachee(ke->keysym.unicode);
408
 
        else
409
 
          _chaine::setCodeToucheRelachee(ke->keysym.sym);
410
 
        if((int)iCodeTouche == ke->keysym.sym) iCodeTouche = 0;    // remet a zero le code touche
411
 
        key_status(keys);
412
 
        
413
 
      }
414
 
      break;
415
 
      
416
 
      case SDL_QUIT:
417
 
      { quit_game = 1;
418
 
      }
419
 
      break ;
420
 
    }
421
 
  }
422
 
 
423
 
  affiche_ecran();
424
 
  return 0;
425
 
}
426
 
void key_status(Uint8 *k)
427
 
{
428
 
  touch[0]   = k[SDLK_ESCAPE];                                //ESC (ASCII=27)
429
 
  touch[88]  = k[SDLK_LCTRL];
430
 
  touch[88] |= k[SDLK_RCTRL];
431
 
  touch[50]  = k[SDLK_RETURN];                                //RETURN (ASCII=13)
432
 
  touch[150] = k[SDLK_PAUSE];
433
 
  touch[74]  = k[SDLK_LSHIFT];
434
 
  touch[74] |= k[SDLK_RSHIFT];
435
 
  touch[1]   = k[SDLK_F1];
436
 
  touch[2]   = k[SDLK_F2];
437
 
  touch[3]   = k[SDLK_F3];
438
 
  touch[4]   = k[SDLK_F4];
439
 
  touch[5]   = k[SDLK_F5];
440
 
  touch[6]   = k[SDLK_F6];
441
 
  touch[7]   = k[SDLK_F7];
442
 
  touch[8]   = k[SDLK_F8];
443
 
  touch[9]   = k[SDLK_F9];
444
 
  touch[10]  = k[SDLK_F10];
445
 
  touch[11]  = k[SDLK_F11];
446
 
  touch[12]  = k[SDLK_F12];
447
 
  touch[13]  = k[SDLK_INSERT];
448
 
  touch[90]  = k[SDLK_SPACE];
449
 
  touch[71]  = k[SDLK_LEFT];
450
 
  touch[73]  = k[SDLK_RIGHT];
451
 
  touch[55]  = k[SDLK_UP];
452
 
  touch[87]  = k[SDLK_DOWN];
453
 
  touch[38]  = k[SDLK_a];                 //A CTRL+A=ABOUT
454
 
  touch[39]  = k[SDLK_f];                 //F F=FULL SCREEN
455
 
  touch[79]  = k[SDLK_v];                 //V
456
 
  touch[80]  = k[SDLK_b];                 //B
457
 
  touch[47]  = k[SDLK_p];                 //P P=PAUSE
458
 
  touch[58]  = k[SDLK_q];                 //Q CTRL+Q gameover
459
 
  touch[60]  = k[SDLK_s];                 //S CTRL+S coupe la musique
460
 
 
461
 
  touch[73]  |= k[SDLK_KP6];              //right arrow 
462
 
  touch[71]  |= k[SDLK_KP4];              //left arrow
463
 
  touch[55]  |= k[SDLK_KP8];              //up arrow
464
 
  touch[87]  |= k[SDLK_KP5];              //down arrow
465
 
  touch[88]  |= k[SDLK_KP2];              //power-up (aka Ctrl key) 
466
 
  touch[90]  |= k[SDLK_KP0];              //fire (aka space bar)
467
 
}
468
 
 
469
 
 
470
 
//------------------------------------------------------------------------------
471
 
// SDL : display screen
472
 
//------------------------------------------------------------------------------
473
 
// joue animation / play compressed ani
474
 
void affiche_ecran()
475
 
{
476
 
  if(pEcranPlayanim)                                           // movie ?
477
 
  { iAffiche = 0;
478
 
    afficheAnim();                                             // movie player.
479
 
  }
480
 
  else
481
 
  { switch (vmode)
482
 
    { case 0:
483
 
        fenetre320x200();
484
 
        break;                                               // window 320*200
485
 
      case 1:
486
 
        fenetre640x400();
487
 
        break;                                               
488
 
    }
489
 
  }
490
 
}
491
 
 
492
 
//------------------------------------------------------------------------------
493
 
// SDL : affiche l'animation compactee / display start movie and end movie
494
 
//------------------------------------------------------------------------------
495
 
void afficheAnim()
496
 
{
497
 
  Uint32 v;
498
 
  SDL_Rect rsour;
499
 
  int i;
500
 
 
501
 
  switch (iOctetsParPixel)
502
 
  { case 1:
503
 
      for(i = 0; i < (LARG_ECRAN_PHY * HAUT_ECRAN_PHY); i++)
504
 
        ecran_playanim[i] = image1[i];
505
 
      break;
506
 
    case 2:
507
 
      conv8_16((char *)image1, ecran_playanim, pal16,
508
 
               LARG_ECRAN_PHY * HAUT_ECRAN_PHY);
509
 
      break;
510
 
    case 3:
511
 
      conv8_24((char *)image1, ecran_playanim, pal32PlayAnim,
512
 
               LARG_ECRAN_PHY * HAUT_ECRAN_PHY);
513
 
      break;
514
 
    case 4:
515
 
      conv8_32((char *)image1, ecran_playanim, pal32PlayAnim,
516
 
               LARG_ECRAN_PHY * HAUT_ECRAN_PHY);
517
 
      break;
518
 
  }
519
 
 
520
 
  //mode 320x200
521
 
  switch (vmode)
522
 
  { case 0:
523
 
    { rsour.x = 0; rsour.y = 0;
524
 
      rsour.w = LARG_ECRAN_PHY; rsour.h = HAUT_ECRAN_PHY;
525
 
      v = SDL_BlitSurface(pEcranPlayanim, &rsour, pPowerMangaDisplay, &rsour);
526
 
      if(v < 0)
527
 
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
528
 
      SDL_UpdateRect(pPowerMangaDisplay, 0, 0, 
529
 
                     pPowerMangaDisplay->w, pPowerMangaDisplay->h);
530
 
    }
531
 
    break;
532
 
    
533
 
    //mode 640x400    
534
 
    case 1:
535
 
      { copy2X(ecran_playanim, ecran_ram640, 320, 200, 0,
536
 
               iLargeurEcran * iOctetsParPixel * 2 -
537
 
               (iLargeurEcran * iOctetsParPixel));
538
 
      rsour.x = 0; 
539
 
          
540
 
          if (vmode2) 
541
 
         rsour.y = 40;
542
 
          else 
543
 
             rsour.y = 0;
544
 
 
545
 
      rsour.w = iLargeurEcran; rsour.h = iHauteurEcran;
546
 
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rsour);
547
 
      if(v < 0)
548
 
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
549
 
 
550
 
      }
551
 
          
552
 
            if (vmode2) 
553
 
                        SDL_UpdateRect(pPowerMangaDisplay, 0, 40, 
554
 
                     pPowerMangaDisplay->w, pPowerMangaDisplay->h - 40);
555
 
                else
556
 
                        SDL_UpdateRect(pPowerMangaDisplay, 0, 0, 
557
 
                     pPowerMangaDisplay->w, pPowerMangaDisplay->h);
558
 
          
559
 
 
560
 
        break;
561
 
    }
562
 
}
563
 
 
564
 
 
565
 
//------------------------------------------------------------------------------
566
 
// SDL : display window in 320*200
567
 
//------------------------------------------------------------------------------
568
 
void fenetre320x200()
569
 
{
570
 
  Uint32 v;
571
 
  SDL_Rect rdest;
572
 
  SDL_Rect rsour;
573
 
  rsour.x = BANDE_DE_CLIP;
574
 
  rsour.y = BANDE_DE_CLIP;
575
 
  rsour.w = LARG_ECR_RAM;
576
 
  rsour.h = HAUT_ECR_RAM;
577
 
  rdest.x = 0;
578
 
  rdest.y = 16;
579
 
  rdest.w = LARG_ECR_RAM;
580
 
  rdest.h = HAUT_ECR_RAM;
581
 
  v = SDL_BlitSurface(pEcranXImage, &rsour, pPowerMangaDisplay, &rdest);
582
 
  if(v < 0)
583
 
    fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
584
 
  if(!iAffiche)
585
 
  { rsour.x = 0;
586
 
    rsour.y = 0;
587
 
    rsour.w = OPT_LARGE;
588
 
    rsour.h = OPT_HAUTE;
589
 
    rdest.x = LARG_ECR_RAM;
590
 
    rdest.y = 16;
591
 
    rdest.w = OPT_LARGE;
592
 
    rdest.h = OPT_HAUTE;
593
 
    v = SDL_BlitSurface(pEcranOptXImage, &rsour, pPowerMangaDisplay, &rdest);
594
 
    if(v < 0)
595
 
      fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
596
 
  }
597
 
 
598
 
  //display score panel
599
 
  if(!iAffiche)
600
 
  { rsour.x = 0; rsour.y = 0; rsour.w = SCR_LARGE; rsour.h = SCR_HAUTE;
601
 
    rdest.x = 0; rdest.y = 0; rdest.w = SCR_LARGE; rdest.h = SCR_HAUTE;
602
 
    v = SDL_BlitSurface(pEcranScrXImage, &rsour, pPowerMangaDisplay, &rdest);
603
 
    if(v < 0)
604
 
      fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
605
 
  }
606
 
 
607
 
  //display options from option panel
608
 
  while (iOptionIndex >= 0)
609
 
  { int _iOptionX = pOptionChange[iOptionIndex][0];
610
 
    int _iOptionY = pOptionChange[iOptionIndex--][1];
611
 
    rsour.x = _iOptionX; rsour.y = _iOptionY;
612
 
    rsour.w = 28; rsour.h = 28;
613
 
    rdest.x = LARG_ECR_RAM + _iOptionX; rdest.y = 16 + _iOptionY;
614
 
    rdest.w = 28; rdest.h = 28;
615
 
    v = SDL_BlitSurface(pEcranOptXImage, &rsour, pPowerMangaDisplay, &rdest);
616
 
    if(v < 0)
617
 
      fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
618
 
  }
619
 
  if(iBonusX2Affiche || iAffiche)
620
 
  { rsour.x = 41;  rsour.y = 171; rsour.w = 14; rsour.h = 8;
621
 
    rdest.x = 297; rdest.y = 187; rdest.w = 14; rdest.h = 8;
622
 
    v = SDL_BlitSurface(pEcranOptXImage, &rsour, pPowerMangaDisplay, &rdest);
623
 
    if(v < 0)
624
 
      fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
625
 
    iBonusX2Affiche = 0;
626
 
  }
627
 
  if(iBonusX4Affiche || iAffiche)
628
 
  { rsour.x = 41;  rsour.y = 5;  rsour.w = 14; rsour.h = 8;
629
 
    rdest.x = 297; rdest.y = 21; rdest.w = 14; rdest.h = 8;
630
 
    v = SDL_BlitSurface(pEcranOptXImage, &rsour, pPowerMangaDisplay, &rdest);
631
 
    if(v < 0)
632
 
      fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
633
 
    iBonusX4Affiche = 0;
634
 
  }
635
 
  
636
 
  //display player's energy
637
 
  if(iBarreNrjJoueurXWindow)
638
 
  { rsour.x = 210; rsour.y = 3; rsour.w = 100; rsour.h = 9;
639
 
    v = SDL_BlitSurface(pEcranScrXImage, &rsour, pPowerMangaDisplay, &rsour);
640
 
    if(v < 0)
641
 
      fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
642
 
    iBarreNrjJoueurXWindow = 0;
643
 
  }
644
 
  
645
 
  //display big-boss's energy
646
 
  if(iBarreNrjGardienXWindow)
647
 
  { rsour.x = 10; rsour.y = 3; rsour.w = 45; rsour.h = 9;
648
 
    v = SDL_BlitSurface(pEcranScrXImage, &rsour, pPowerMangaDisplay, &rsour);
649
 
    if(v < 0)
650
 
      fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
651
 
    iBarreNrjGardienXWindow = 0;
652
 
  }
653
 
  
654
 
  //display score number
655
 
  if(iScoreXWindow)
656
 
  { rsour.x = 68; rsour.y = 0; rsour.w = 128; rsour.h = 16;
657
 
    v = SDL_BlitSurface(pEcranScrXImage, &rsour, pPowerMangaDisplay, &rsour);
658
 
    if(v < 0)
659
 
      fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
660
 
    iScoreXWindow = 0;
661
 
  }
662
 
  iOptionIndex = -1;
663
 
  iAffiche = 1;
664
 
  SDL_UpdateRect(pPowerMangaDisplay, 0, 0, 
665
 
                 pPowerMangaDisplay->w, pPowerMangaDisplay->h);
666
 
}
667
 
 
668
 
//------------------------------------------------------------------------------
669
 
// SDL : display window in 640*400
670
 
// playfield 512x440 ; score panel 320x16 ; option panel 64x184
671
 
// iAffiche=0 : display all window 640x400
672
 
//
673
 
//
674
 
//------------------------------------------------------------------------------
675
 
void fenetre640x400()
676
 
{
677
 
  Uint32 v;
678
 
  int           starty;
679
 
  SDL_Rect rdest;
680
 
  SDL_Rect rsour;
681
 
  char *_pSource =
682
 
    ecran_ram + (BANDE_DE_CLIP * iLargeurEcranTotal) +
683
 
    (BANDE_DE_CLIP * iOctetsParPixel);
684
 
    
685
 
  //recopie l'ecran de jeu en doublant / recopy the screen by it doubling
686
 
  //("assembler_opt.S" or "gfxroutine.cpp")
687
 
  copy2X_512x440(_pSource, 
688
 
                 ecran_ram640 + (iLargeurEcran * iOctetsParPixel * 32),
689
 
                 HAUT_ECR_RAM
690
 
  );
691
 
 
692
 
 
693
 
  // mode 640x480
694
 
  if (vmode2) 
695
 
          starty = 40;
696
 
  else 
697
 
          starty = 0;
698
 
 
699
 
 
700
 
 
701
 
  if(iAffiche)
702
 
  { rsour.x = 0; rsour.y = 32; 
703
 
    rsour.w = LARG_ECR_RAM * 2; rsour.h = HAUT_ECR_RAM * 2;
704
 
        rdest.x = 0; rdest.y = 32 + starty; 
705
 
    rdest.w = LARG_ECR_RAM * 2; rdest.h = HAUT_ECR_RAM * 2;
706
 
    v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
707
 
    if(v < 0)
708
 
      fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
709
 
 
710
 
    //display score number ?
711
 
    if(iScoreXWindow)
712
 
    {
713
 
      iScoreXWindow = 0;
714
 
      copy2X(ecran_scr + (68 * iOctetsParPixel),
715
 
             ecran_ram640 + (68 * iOctetsParPixel * 2), 128, 16,
716
 
             SCR_LARGE * iOctetsParPixel - 128 * iOctetsParPixel,
717
 
             (iLargeurEcran * 2 * iOctetsParPixel) -
718
 
             128 * iOctetsParPixel * 2);
719
 
      rsour.x = 68 * 2; rsour.y = 0; rsour.w = 128 * 2; rsour.h = 16 * 2;
720
 
      rdest.x = 68 * 2; rdest.y = starty; rdest.w = 128 * 2; rdest.h = 16 * 2;
721
 
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
722
 
      if(v < 0)
723
 
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
724
 
    }
725
 
    
726
 
    if(iBonusX2Affiche || iAffiche)
727
 
    {
728
 
      copy2X(ecran_opt + (41 * iOctetsParPixel) +
729
 
             (171 * OPT_LARGE * iOctetsParPixel),
730
 
             ecran_ram640 + ((LARG_ECR_RAM + 41) * iOctetsParPixel * 2) +
731
 
             ((SCR_HAUTE + 171) * iLargeurEcran * iOctetsParPixel * 2), 14, 8,
732
 
             OPT_LARGE * iOctetsParPixel - 14 * iOctetsParPixel,
733
 
             (iLargeurEcran * iOctetsParPixel * 2) -
734
 
             14 * iOctetsParPixel * 2);
735
 
      rsour.x = (LARG_ECR_RAM + 41) * 2; rsour.y = (SCR_HAUTE + 171) * 2;
736
 
      rsour.w = 14 * 2; rsour.h = 8 * 2;
737
 
          rdest.x = (LARG_ECR_RAM + 41) * 2; rdest.y = (SCR_HAUTE + 171) * 2 + starty;
738
 
      rdest.w = 14 * 2; rdest.h = 8 * 2;
739
 
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
740
 
      if(v < 0)
741
 
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
742
 
      iBonusX2Affiche = 0;
743
 
    }
744
 
 
745
 
    if(iBonusX4Affiche || iAffiche)
746
 
    {
747
 
      copy2X(ecran_opt + (41 * iOctetsParPixel) +
748
 
             (5 * OPT_LARGE * iOctetsParPixel),
749
 
             ecran_ram640 + ((LARG_ECR_RAM + 41) * iOctetsParPixel * 2) +
750
 
             ((SCR_HAUTE + 5) * iLargeurEcran * iOctetsParPixel * 2), 14, 8,
751
 
             OPT_LARGE * iOctetsParPixel - 14 * iOctetsParPixel,
752
 
             (iLargeurEcran * iOctetsParPixel * 2) -
753
 
             14 * iOctetsParPixel * 2);
754
 
      rsour.x = (LARG_ECR_RAM + 41) * 2; rsour.y = (SCR_HAUTE + 5) * 2;
755
 
      rsour.w = 14 * 2; rsour.h = 8 * 2;
756
 
          rdest.x = (LARG_ECR_RAM + 41) * 2; rdest.y = (SCR_HAUTE + 5) * 2 + starty;
757
 
      rdest.w = 14 * 2; rdest.h = 8 * 2;
758
 
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
759
 
      if(v < 0)
760
 
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
761
 
      iBonusX4Affiche = 0;
762
 
    }
763
 
 
764
 
    //display options from option panel
765
 
    while (iOptionIndex >= 0)
766
 
    { int  _iOptionX = pOptionChange[iOptionIndex][0];
767
 
      int  _iOptionY = pOptionChange[iOptionIndex--][1];
768
 
      copy2X(ecran_opt + (_iOptionX * iOctetsParPixel) +
769
 
             (_iOptionY * OPT_LARGE * iOctetsParPixel),
770
 
             ecran_ram640 +
771
 
             ((LARG_ECR_RAM + _iOptionX) * iOctetsParPixel * 2) +
772
 
             ((SCR_HAUTE + _iOptionY) * iLargeurEcran * iOctetsParPixel * 2),
773
 
             28, 28, OPT_LARGE * iOctetsParPixel - 28 * iOctetsParPixel,
774
 
             (iLargeurEcran * iOctetsParPixel * 2) -
775
 
             28 * iOctetsParPixel * 2);
776
 
      rsour.x = (LARG_ECR_RAM + _iOptionX) * 2; rsour.y = (SCR_HAUTE + _iOptionY) * 2;
777
 
      rsour.w = 28 * 2; rsour.h = 28 * 2;
778
 
          rdest.x = (LARG_ECR_RAM + _iOptionX) * 2; rdest.y = (SCR_HAUTE + _iOptionY) * 2 + starty;
779
 
      rdest.w = 28 * 2; rdest.h = 28 * 2;
780
 
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
781
 
      if(v < 0)
782
 
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
783
 
    }
784
 
 
785
 
    //display player's ernergy
786
 
    if(iBarreNrjJoueurXWindow)
787
 
    {
788
 
      iBarreNrjJoueurXWindow = 0;
789
 
      copy2X(ecran_scr + (210 * iOctetsParPixel) +
790
 
             (3 * SCR_LARGE * iOctetsParPixel),
791
 
             ecran_ram640 + (210 * iOctetsParPixel * 2) +
792
 
             (3 * iLargeurEcran * iOctetsParPixel * 2), 100, 9,
793
 
             SCR_LARGE * iOctetsParPixel - 100 * iOctetsParPixel,
794
 
             (iLargeurEcran * iOctetsParPixel * 2) -
795
 
             100 * iOctetsParPixel * 2);
796
 
      rsour.x = 210 * 2; rsour.y = 3 * 2;
797
 
      rsour.w = 100 * 2; rsour.h = 9 * 2;
798
 
          rdest.x = 210 * 2; rdest.y = 3 * 2 + starty;
799
 
      rdest.w = 100 * 2; rdest.h = 9 * 2;
800
 
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
801
 
      if(v < 0)
802
 
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
803
 
    }
804
 
    if(iBarreNrjGardienXWindow)                                //display bigboss's energy
805
 
    {
806
 
      iBarreNrjGardienXWindow = 0;
807
 
      copy2X(ecran_scr + (10 * iOctetsParPixel) +
808
 
             (3 * SCR_LARGE * iOctetsParPixel),
809
 
             ecran_ram640 + (10 * iOctetsParPixel * 2) +
810
 
             (3 * iLargeurEcran * iOctetsParPixel * 2), 45, 9,
811
 
             SCR_LARGE * iOctetsParPixel - 45 * iOctetsParPixel,
812
 
             (iLargeurEcran * iOctetsParPixel * 2) -
813
 
             45 * iOctetsParPixel * 2);
814
 
      rsour.x = 10 * 2; rsour.y = 3 * 2;
815
 
      rsour.w = 45 * 2; rsour.h = 9 * 2;
816
 
      rdest.x = 10 * 2; rdest.y = 3 * 2 + starty;
817
 
      rdest.w = 45 * 2; rdest.h = 9 * 2;
818
 
      v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
819
 
      if(v < 0)
820
 
        fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
821
 
      /*XPutImage(pPowerMangaDisplay, pFenetreJeu, pContexteGraphique,
822
 
                pEcranXImage640, 10 * 2, 3 * 2, 10 * 2, 3 * 2, 45 * 2, 9 * 2);*/
823
 
    }
824
 
    
825
 
    
826
 
  }
827
 
  else
828
 
  { copy2X(ecran_scr, ecran_ram640, SCR_LARGE, SCR_HAUTE, 0,
829
 
           iLargeurEcran * iOctetsParPixel * 2 -
830
 
           (SCR_LARGE * 2 * iOctetsParPixel));
831
 
    copy2X(ecran_opt,
832
 
           ecran_ram640 + (LARG_ECR_RAM * 2 * iOctetsParPixel) +
833
 
           (iLargeurEcran * iOctetsParPixel * 32), OPT_LARGE, OPT_HAUTE, 0,
834
 
           iLargeurEcran * iOctetsParPixel * 2 -
835
 
           (OPT_LARGE * 2 * iOctetsParPixel));
836
 
    rsour.x = 0; rsour.y = 0; rsour.w = iLargeurEcran; rsour.h = iHauteurEcran;
837
 
    rdest.x = 0; rdest.y = starty; rdest.w = iLargeurEcran; rdest.h = iHauteurEcran;
838
 
    v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rdest);
839
 
    if(v < 0)
840
 
      fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());     
841
 
    iAffiche = 1;
842
 
    iOptionIndex = -1;
843
 
  }     
844
 
 
845
 
  SDL_UpdateRect(pPowerMangaDisplay, 0, starty, pPowerMangaDisplay->w, pPowerMangaDisplay->h - starty);    
846
 
}
847
 
 
848
 
 
849
 
 
850
 
 
851
 
//------------------------------------------------------------------------------
852
 
// SDL : ferme l'affichage sous SDL
853
 
//------------------------------------------------------------------------------
854
 
int xw_kill()
855
 
{
856
 
  libereXImages();
857
 
  ecran_ram = 0;
858
 
  pEcranXImage = 0;
859
 
  ecran_ram640 = 0;
860
 
  pEcranXImage640 = 0;
861
 
  ecran_scr = 0;
862
 
  pEcranScrXImage = 0;
863
 
  ecran_opt = 0;
864
 
  pEcranOptXImage = 0;
865
 
  SDL_Quit();
866
 
#ifdef _VERBEUX_
867
 
  if(power_conf->verbose)
868
 
    afficheMessage("> sdl_tlk.cpp/xw_kill() / SDL_Quit");
869
 
#endif
870
 
  return 1;
871
 
}
872
 
 
873
 
 
874
 
//------------------------------------------------------------------------------
875
 
// decompress pcx file and convert to 8 bits (no change), or 16 bits or 24 bits
876
 
// input  => _pFichier      : filename
877
 
// output <= _pStructureGfx : pointer to the "sDescriptionGfx" structure / 0=error
878
 
//------------------------------------------------------------------------------
879
 
char *Xload_pcx(char *_pNomFichier)
880
 
{
881
 
  sDescriptionGfx *_pGfx = load_pcx(_pNomFichier);
882
 
  if(!_pGfx)
883
 
    return 0;
884
 
  if(iOctetsParPixel > 0)
885
 
  { if(!convertit_16ou24(_pGfx))
886
 
    { afficheErreur("convertit_16ou24() failed\n", "sdl_tlk.cpp/Xload_pcx()");
887
 
      return 0;
888
 
    }
889
 
  }
890
 
  char *_pMem = _pGfx->pAdresse;
891
 
  libereMemoire((char *)_pGfx);
892
 
  return _pMem;
893
 
}
894
 
 
895
 
//------------------------------------------------------------------------------
896
 
// decompress pcx file and convert to 8 bits (no change), or 16 bits or 24 bits
897
 
// input => _pFichier : filename
898
 
//       => _pMem     : memory (XImage)
899
 
// output <= _pStructureGfx : pointer to the "sDescriptionGfx" structure / 0=error
900
 
//------------------------------------------------------------------------------
901
 
int Xload_pcx(char *_pNomFichier, char *_pMem)
902
 
{
903
 
  sDescriptionGfx *_pGfx = load_pcx(_pNomFichier);
904
 
  if(!_pGfx)
905
 
    return 0;
906
 
  if(iOctetsParPixel > 0)
907
 
  { if(!convertit_16ou24(_pGfx))
908
 
    { afficheErreur("convertit_16ou24() failed\n", "sdl_tlk.cpp/Xload_pcx()");
909
 
      return 0;
910
 
    }
911
 
  }
912
 
  char *_pMemBase = _pGfx->pAdresse;
913
 
  for(unsigned _iIndex = 0; _iIndex < _pGfx->iTaille; _iIndex++)
914
 
    _pMem[_iIndex] = _pMemBase[_iIndex];
915
 
  libereMemoire(_pMemBase);
916
 
  libereMemoire((char *)_pGfx);
917
 
  return 1;
918
 
}
919
 
 
920
 
//------------------------------------------------------------------------------
921
 
// SDL : converti une image en 256 couleurs en millier ou millions
922
 
// entree       =>  sDescriptionGfx : description de l'image
923
 
//------------------------------------------------------------------------------
924
 
char *convertit_16ou24(sDescriptionGfx * _pSrc)
925
 
{
926
 
  if(iOctetsParPixel == 1)
927
 
    return _pSrc->pAdresse;
928
 
  unsigned int _iTaille = (_pSrc->iLargeur * _pSrc->iHauteur);
929
 
  char *_pBuffer =
930
 
    reserveMemoire(_iTaille * iOctetsParPixel);
931
 
  if(!_pBuffer)
932
 
  { afficheErreur("out of memory", "sdl_tlk.cpp/convertit_16ou24()");
933
 
    return 0;
934
 
  }
935
 
  switch (iOctetsParPixel)
936
 
  { case 2:
937
 
      conv8_16(_pSrc->pAdresse, _pBuffer, pal16, _iTaille);
938
 
      break;
939
 
    case 3:
940
 
      conv8_24(_pSrc->pAdresse, _pBuffer, pal32, _iTaille);
941
 
      break;
942
 
    case 4:
943
 
      conv8_32(_pSrc->pAdresse, _pBuffer, pal32, _iTaille);
944
 
      break;
945
 
  }
946
 
  libereMemoire(_pSrc->pAdresse);
947
 
  _pSrc->pAdresse = _pBuffer;
948
 
  _pSrc->iTaille = _iTaille * iOctetsParPixel;
949
 
  return _pBuffer;
950
 
}
951
 
 
952
 
//------------------------------------------------------------------------------
953
 
// SDL : create a SDL surface
954
 
//------------------------------------------------------------------------------
955
 
SDL_Surface *creeXImage(unsigned int _iLarge, unsigned int _iHaute)
956
 
{
957
 
  Uint32 rmask, gmask, bmask;
958
 
  int _iXimageLibre = -1;
959
 
  SDL_Surface *_pXImage;
960
 
  unsigned int _iIndex;
961
 
  for(_iIndex = 0; _iIndex < iXIMAGEMAX; _iIndex++)
962
 
  { if(pListeXImage[_iIndex] == 0)
963
 
    { _iXimageLibre = _iIndex;
964
 
      break;
965
 
    }
966
 
  }
967
 
  if(_iXimageLibre < 0)
968
 
  { afficheErreur("out of pListeXImage list", "sdl_tlk.cpp/creeXImage()");
969
 
    return 0;
970
 
  }
971
 
  switch(iProfondeur2)
972
 
  { case 15:
973
 
      rmask = 0x7c00;
974
 
      gmask = 0x03e0;
975
 
      bmask = 0x001f;
976
 
      break;
977
 
    case 16:
978
 
      rmask = 0xf800;
979
 
      gmask = 0x03e0;
980
 
      bmask = 0x001f;
981
 
      break;
982
 
    default:
983
 
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
984
 
      rmask = 0xff000000;
985
 
      gmask = 0x00ff0000;
986
 
      bmask = 0x0000ff00;
987
 
#else
988
 
      rmask = 0x000000ff;
989
 
      gmask = 0x0000ff00;
990
 
      bmask = 0x00ff0000;
991
 
#endif
992
 
      break;
993
 
  }
994
 
  _pXImage = SDL_CreateRGBSurface(
995
 
    SDL_ANYFORMAT, _iLarge, _iHaute, iProfondeur2, rmask, gmask, bmask, 0x00
996
 
  );
997
 
  if(!_pXImage)
998
 
  { fprintf(
999
 
      stderr, "! sdl_tlk.cpp/creeXImage() : SDL_CreateRGBSurface() %s\n",
1000
 
      SDL_GetError()
1001
 
    );
1002
 
    return 0;
1003
 
  }
1004
 
  if(iOctetsParPixel == 1)
1005
 
    SDL_SetPalette(_pXImage, SDL_PHYSPAL | SDL_LOGPAL, pXColor, 0, 256);  
1006
 
  pListeXImage[_iXimageLibre] = _pXImage;
1007
 
  iNombreXImage++;
1008
 
#ifdef _VERBEUX_
1009
 
  if(power_conf->verbose)
1010
 
    fprintf(stdout,
1011
 
      "> sdl_tlk.cpp/creeXImage(): SDL_CreateRGBSurface(%i,%i,%i)\n",
1012
 
      _iLarge,_iHaute,iProfondeur2);
1013
 
#endif
1014
 
  return _pXImage;
1015
 
}
1016
 
 
1017
 
//------------------------------------------------------------------------------
1018
 
// SDL : free a SDL surface
1019
 
//------------------------------------------------------------------------------
1020
 
void libereXImage(SDL_Surface *_pXImage)
1021
 
{
1022
 
  Uint32 w;
1023
 
  Uint32 h;
1024
 
  unsigned int _iIndex;
1025
 
  for(_iIndex = 0; _iIndex < iXIMAGEMAX; _iIndex++)
1026
 
  { if(pListeXImage[_iIndex] == _pXImage)
1027
 
    { w = _pXImage->w;
1028
 
      h = _pXImage->h;
1029
 
      SDL_FreeSurface(_pXImage);
1030
 
      pListeXImage[_iIndex] = 0;
1031
 
      iNombreXImage--;
1032
 
#ifdef _VERBEUX_
1033
 
      if(power_conf->verbose)
1034
 
        fprintf(stdout,
1035
 
          "> sdl_tlk.cpp/libereXImage(): SDL_FreeSurface; %i,%i\n", w, h);
1036
 
#endif
1037
 
      break;
1038
 
    }
1039
 
  }
1040
 
}
1041
 
 
1042
 
//------------------------------------------------------------------------------
1043
 
// SDL : free all surfaces
1044
 
//------------------------------------------------------------------------------
1045
 
void libereXImages()
1046
 
{
1047
 
  unsigned int _iIndex;
1048
 
  Uint32 w;
1049
 
  Uint32 h;
1050
 
  for(_iIndex = 0; _iIndex < iXIMAGEMAX; _iIndex++)
1051
 
  { SDL_Surface *_pXImage = pListeXImage[_iIndex];
1052
 
    if(_pXImage)
1053
 
    { w = _pXImage->w;
1054
 
      h = _pXImage->h;
1055
 
      SDL_FreeSurface(_pXImage);
1056
 
      pListeXImage[_iIndex] = 0;
1057
 
      iNombreXImage--;
1058
 
#ifdef _VERBEUX_
1059
 
      if(power_conf->verbose)
1060
 
        fprintf(stdout,
1061
 
          "> sdl_tlk.cpp/libereXImage(): SDL_FreeSurface; %i,%i\n", w, h);
1062
 
#endif
1063
 
    }
1064
 
  }
1065
 
}
1066
 
 
1067
 
void verouille()
1068
 
{ if(SDL_LockSurface(pEcranXImage))
1069
 
  { fprintf(stderr, "> sdl_tlk.cpp/verouiller(): Impossible de verouiller la surface  %s\n", SDL_GetError());
1070
 
  }
1071
 
}
1072
 
 
1073
 
void deverouille()
1074
 
{ SDL_UnlockSurface(pEcranXImage);
1075
 
}
1076
 
#endif