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
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
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
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.
24
//*****************************************************************************
25
#include "powermanga.hpp"
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];
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)
52
Sint32 vmode2 = 1; // si vmode = 1 ==> 0 = 640x400 / 1 = 640x480
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
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
71
//...............................................................................
73
//..............................................................................
74
void initialiseCurseurBlanc();
78
void fenetre320x200();
79
void fenetre640x400();
84
SDL_Surface *creeXImage(unsigned int _iLarge,
85
unsigned int _iHaute);
86
void libereXImage(SDL_Surface *_pXImage);
88
void key_status(Uint8 *k);
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;
101
//...............................................................................
102
SDL_Color *pXColor = 0; //color table
104
//...............................................................................
105
char nomfenetre[] = "Powermanga by TLK Games (SDL version)\0";
109
//------------------------------------------------------------------------------
110
// SDL : initialise un affichage SDL / initialize SDL display
111
// sortie / output <= 0 : erreur
112
//------------------------------------------------------------------------------
115
for(unsigned int _iIndex = 0; _iIndex < iXIMAGEMAX; _iIndex++)
116
pListeXImage[_iIndex] = 0;
118
//..............................................................................
120
{ iLargeurEcran = LARG_ECRAN_PHY;
121
iHauteurEcran = HAUT_ECRAN_PHY;
124
{ iLargeurEcran = LARG_ECRAN_PHY * 2;
125
iHauteurEcran = HAUT_ECRAN_PHY * 2;
130
// initialize SDL screen .....................................................
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());
138
const SDL_VideoInfo *vi;
139
vi = SDL_GetVideoInfo();
140
iProfondeur = vi->vfmt->BitsPerPixel;
141
iOctetsParPixel = vi->vfmt->BytesPerPixel;
143
if(iProfondeur == 16) {
144
iProfondeur = vi->vfmt->Rshift + vi->vfmt->Gshift + vi->vfmt->Bshift;
146
iProfondeur2 = iProfondeur;
148
{ afficheErreur("this game need 8 bits peer pixels minimum (256 colors)",
149
"sdl_tlk.cpp/xw_init()");
153
if(power_conf->verbose)
155
("> sdl_tlk.cpp/xw_init(): depth of screen: %i; bytes per pixel: %i;\n",
156
iProfondeur, iOctetsParPixel);
159
if(!init_video_mode())
162
SDL_EnableUNICODE(1);
164
if(power_conf->verbose)
165
afficheMessage("> sdl_tlk.cpp/xw_init(): successful initialization!");
170
//------------------------------------------------------------------------------
171
// SDL: initialize video mode
172
// return: 0 = > error / 1 => no error
173
//------------------------------------------------------------------------------
174
int init_video_mode()
179
//##############################################################
180
// 640x400 => 640x480 (win32 only)
181
//##############################################################
182
if ((vmode) && (vmode2)) {
186
//##############################################################
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);
196
{ if(!power_conf->fullscreen)
198
"sdl_tlk.cpp/init_video_mode(): SDL_VideoModeOK() return: %s",
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);
212
"sdl_tlk.cpp/init_video_mode(): SDL_VideoModeOK() return: %s",
220
//##############################################################
221
// initialize video mode
222
//##############################################################
224
SDL_SetVideoMode(iLargeurEcran, iHauteurEcran, iProfondeur2, flag);
225
if(!pPowerMangaDisplay)
227
"sdl_tlk.cpp/init_video_mode(): SDL_SetVideoMode() return %s\n",
232
//##############################################################
233
// restore valid height screen (win32 only)
234
//##############################################################
235
if ((vmode) && (vmode2)) {
236
iHauteurEcran = HAUT_ECRAN_PHY * 2;
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);
244
SDL_ShowCursor(SDL_ENABLE);
248
//------------------------------------------------------------------------------
249
// SDL destroy surface / start anim and end anim / "playanim.cpp"
250
//------------------------------------------------------------------------------
251
void kill_ecranPlayanim()
253
libereXImage(pEcranPlayanim);
258
//------------------------------------------------------------------------------
259
// SDL : create surface / start anim and end anim / "playanim.cpp"
260
//------------------------------------------------------------------------------
261
int reserve_ecranPlayanim()
263
if(!(pEcranPlayanim = creeXImage(LARG_ECRAN_PHY, HAUT_ECRAN_PHY)))
265
ecran_playanim = (char *)pEcranPlayanim->pixels;
269
//------------------------------------------------------------------------------
270
// SDL : create 3 or 4 surfaces for the game
271
//------------------------------------------------------------------------------
272
int reserve_ecran_ram()
274
//create surface "ecran_ram" 512*440
275
if(!(pEcranXImage = creeXImage(LARG_ECR_RAM_TOT, HAUT_ECR_RAM_TOT)))
277
ecran_ram = (char *)pEcranXImage->pixels;
278
iLargeurEcranTotal = LARG_ECR_RAM_TOT * iOctetsParPixel;
280
//create surface 640x400 (window 640x400)
283
if(!(pEcranXImage640 = creeXImage(iLargeurEcran, iHauteurEcran)))
285
ecran_ram640 = (char *)pEcranXImage640->pixels;
287
if(!(pEcranOptXImage = creeXImage(OPT_LARGE, OPT_HAUTE)))
289
ecran_opt = (char *)pEcranOptXImage->pixels;
290
if(!(pEcranScrXImage = creeXImage(SCR_LARGE, SCR_HAUTE)))
292
ecran_scr = (char *)pEcranScrXImage->pixels;
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)
303
unsigned int _iIndex;
304
unsigned char *_pPal;
306
pal = (unsigned char *)chargeFichier(_pNomFichier);
310
//ecran 8 bits 256 couleurs . . . . . . . . . . . . . . . . . . . . . . . . . .
311
if(iOctetsParPixel == 1)
313
pXColor = (SDL_Color *) reserveMemoire(sizeof(SDL_Color) * 256);
315
{ afficheErreur("'pXColor' out of memory", "sdl_tlk.cpp/charge_palette()");
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] ;
325
SDL_SetPalette(pPowerMangaDisplay,
326
SDL_PHYSPAL | SDL_LOGPAL, pXColor, 0, 256);
330
//ecran 16 bits 65536 couleurs . . . . . . . . . . . . . . . . . . . . . . . .
331
{ if(iOctetsParPixel == 2)
333
pal16 = (unsigned short *)reserveMemoire(256 * 2);
335
{ afficheErreur("'pal16' out of memory", "sdl_tlk.cpp/charge_palette()");
338
if(iProfondeur2 == 15)
339
convertitPalette24_15(pal, pal16);
341
convertitPalette24_16(pal, pal16);
345
//ecran 24 ou 32 bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
346
{ if(iOctetsParPixel > 2)
348
pal32 = (unsigned int *)reserveMemoire(256 * 4);
350
{ afficheErreur("'pal32' out of memory", "sdl_tlk.cpp/charge_palette()");
353
unsigned char *_p = (unsigned char *)pal32;
355
//_p[3]=? / _p[2]=red / _p[1]=green / _p[0]=blue
356
for(_iIndex = 0; _iIndex < 256; _iIndex++)
371
//------------------------------------------------------------------------------
372
// SDL : gestion des evenements
373
//------------------------------------------------------------------------------
377
SDL_KeyboardEvent *ke;
379
while(SDL_PollEvent(&event) > 0)
380
{ switch (event.type)
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);
387
keys = SDL_GetKeyState(NULL);
388
if ( keys[SDLK_F10] == SDL_PRESSED)
392
if(ke->keysym.unicode > 0)
393
_chaine::setCodeTouchePressee(ke->keysym.unicode);
395
_chaine::setCodeTouchePressee(ke->keysym.sym);
396
iCodeTouche = ke->keysym.sym; //sauve le code touche
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);
405
keys = SDL_GetKeyState(NULL);
406
if(ke->keysym.unicode > 0)
407
_chaine::setCodeToucheRelachee(ke->keysym.unicode);
409
_chaine::setCodeToucheRelachee(ke->keysym.sym);
410
if((int)iCodeTouche == ke->keysym.sym) iCodeTouche = 0; // remet a zero le code touche
426
void key_status(Uint8 *k)
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
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)
470
//------------------------------------------------------------------------------
471
// SDL : display screen
472
//------------------------------------------------------------------------------
473
// joue animation / play compressed ani
476
if(pEcranPlayanim) // movie ?
478
afficheAnim(); // movie player.
484
break; // window 320*200
492
//------------------------------------------------------------------------------
493
// SDL : affiche l'animation compactee / display start movie and end movie
494
//------------------------------------------------------------------------------
501
switch (iOctetsParPixel)
503
for(i = 0; i < (LARG_ECRAN_PHY * HAUT_ECRAN_PHY); i++)
504
ecran_playanim[i] = image1[i];
507
conv8_16((char *)image1, ecran_playanim, pal16,
508
LARG_ECRAN_PHY * HAUT_ECRAN_PHY);
511
conv8_24((char *)image1, ecran_playanim, pal32PlayAnim,
512
LARG_ECRAN_PHY * HAUT_ECRAN_PHY);
515
conv8_32((char *)image1, ecran_playanim, pal32PlayAnim,
516
LARG_ECRAN_PHY * HAUT_ECRAN_PHY);
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);
527
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
528
SDL_UpdateRect(pPowerMangaDisplay, 0, 0,
529
pPowerMangaDisplay->w, pPowerMangaDisplay->h);
535
{ copy2X(ecran_playanim, ecran_ram640, 320, 200, 0,
536
iLargeurEcran * iOctetsParPixel * 2 -
537
(iLargeurEcran * iOctetsParPixel));
545
rsour.w = iLargeurEcran; rsour.h = iHauteurEcran;
546
v = SDL_BlitSurface(pEcranXImage640, &rsour, pPowerMangaDisplay, &rsour);
548
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
553
SDL_UpdateRect(pPowerMangaDisplay, 0, 40,
554
pPowerMangaDisplay->w, pPowerMangaDisplay->h - 40);
556
SDL_UpdateRect(pPowerMangaDisplay, 0, 0,
557
pPowerMangaDisplay->w, pPowerMangaDisplay->h);
565
//------------------------------------------------------------------------------
566
// SDL : display window in 320*200
567
//------------------------------------------------------------------------------
568
void fenetre320x200()
573
rsour.x = BANDE_DE_CLIP;
574
rsour.y = BANDE_DE_CLIP;
575
rsour.w = LARG_ECR_RAM;
576
rsour.h = HAUT_ECR_RAM;
579
rdest.w = LARG_ECR_RAM;
580
rdest.h = HAUT_ECR_RAM;
581
v = SDL_BlitSurface(pEcranXImage, &rsour, pPowerMangaDisplay, &rdest);
583
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
589
rdest.x = LARG_ECR_RAM;
593
v = SDL_BlitSurface(pEcranOptXImage, &rsour, pPowerMangaDisplay, &rdest);
595
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
598
//display score panel
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);
604
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
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);
617
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
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);
624
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
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);
632
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
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);
641
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
642
iBarreNrjJoueurXWindow = 0;
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);
650
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
651
iBarreNrjGardienXWindow = 0;
654
//display score number
656
{ rsour.x = 68; rsour.y = 0; rsour.w = 128; rsour.h = 16;
657
v = SDL_BlitSurface(pEcranScrXImage, &rsour, pPowerMangaDisplay, &rsour);
659
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
664
SDL_UpdateRect(pPowerMangaDisplay, 0, 0,
665
pPowerMangaDisplay->w, pPowerMangaDisplay->h);
668
//------------------------------------------------------------------------------
669
// SDL : display window in 640*400
670
// playfield 512x440 ; score panel 320x16 ; option panel 64x184
671
// iAffiche=0 : display all window 640x400
674
//------------------------------------------------------------------------------
675
void fenetre640x400()
682
ecran_ram + (BANDE_DE_CLIP * iLargeurEcranTotal) +
683
(BANDE_DE_CLIP * iOctetsParPixel);
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),
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);
708
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
710
//display score number ?
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);
723
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
726
if(iBonusX2Affiche || iAffiche)
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);
741
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
745
if(iBonusX4Affiche || iAffiche)
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);
760
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
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),
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);
782
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
785
//display player's ernergy
786
if(iBarreNrjJoueurXWindow)
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);
802
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
804
if(iBarreNrjGardienXWindow) //display bigboss's energy
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);
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);*/
828
{ copy2X(ecran_scr, ecran_ram640, SCR_LARGE, SCR_HAUTE, 0,
829
iLargeurEcran * iOctetsParPixel * 2 -
830
(SCR_LARGE * 2 * iOctetsParPixel));
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);
840
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
845
SDL_UpdateRect(pPowerMangaDisplay, 0, starty, pPowerMangaDisplay->w, pPowerMangaDisplay->h - starty);
851
//------------------------------------------------------------------------------
852
// SDL : ferme l'affichage sous SDL
853
//------------------------------------------------------------------------------
867
if(power_conf->verbose)
868
afficheMessage("> sdl_tlk.cpp/xw_kill() / SDL_Quit");
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)
881
sDescriptionGfx *_pGfx = load_pcx(_pNomFichier);
884
if(iOctetsParPixel > 0)
885
{ if(!convertit_16ou24(_pGfx))
886
{ afficheErreur("convertit_16ou24() failed\n", "sdl_tlk.cpp/Xload_pcx()");
890
char *_pMem = _pGfx->pAdresse;
891
libereMemoire((char *)_pGfx);
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)
903
sDescriptionGfx *_pGfx = load_pcx(_pNomFichier);
906
if(iOctetsParPixel > 0)
907
{ if(!convertit_16ou24(_pGfx))
908
{ afficheErreur("convertit_16ou24() failed\n", "sdl_tlk.cpp/Xload_pcx()");
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);
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)
926
if(iOctetsParPixel == 1)
927
return _pSrc->pAdresse;
928
unsigned int _iTaille = (_pSrc->iLargeur * _pSrc->iHauteur);
930
reserveMemoire(_iTaille * iOctetsParPixel);
932
{ afficheErreur("out of memory", "sdl_tlk.cpp/convertit_16ou24()");
935
switch (iOctetsParPixel)
937
conv8_16(_pSrc->pAdresse, _pBuffer, pal16, _iTaille);
940
conv8_24(_pSrc->pAdresse, _pBuffer, pal32, _iTaille);
943
conv8_32(_pSrc->pAdresse, _pBuffer, pal32, _iTaille);
946
libereMemoire(_pSrc->pAdresse);
947
_pSrc->pAdresse = _pBuffer;
948
_pSrc->iTaille = _iTaille * iOctetsParPixel;
952
//------------------------------------------------------------------------------
953
// SDL : create a SDL surface
954
//------------------------------------------------------------------------------
955
SDL_Surface *creeXImage(unsigned int _iLarge, unsigned int _iHaute)
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;
967
if(_iXimageLibre < 0)
968
{ afficheErreur("out of pListeXImage list", "sdl_tlk.cpp/creeXImage()");
983
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
994
_pXImage = SDL_CreateRGBSurface(
995
SDL_ANYFORMAT, _iLarge, _iHaute, iProfondeur2, rmask, gmask, bmask, 0x00
999
stderr, "! sdl_tlk.cpp/creeXImage() : SDL_CreateRGBSurface() %s\n",
1004
if(iOctetsParPixel == 1)
1005
SDL_SetPalette(_pXImage, SDL_PHYSPAL | SDL_LOGPAL, pXColor, 0, 256);
1006
pListeXImage[_iXimageLibre] = _pXImage;
1009
if(power_conf->verbose)
1011
"> sdl_tlk.cpp/creeXImage(): SDL_CreateRGBSurface(%i,%i,%i)\n",
1012
_iLarge,_iHaute,iProfondeur2);
1017
//------------------------------------------------------------------------------
1018
// SDL : free a SDL surface
1019
//------------------------------------------------------------------------------
1020
void libereXImage(SDL_Surface *_pXImage)
1024
unsigned int _iIndex;
1025
for(_iIndex = 0; _iIndex < iXIMAGEMAX; _iIndex++)
1026
{ if(pListeXImage[_iIndex] == _pXImage)
1029
SDL_FreeSurface(_pXImage);
1030
pListeXImage[_iIndex] = 0;
1033
if(power_conf->verbose)
1035
"> sdl_tlk.cpp/libereXImage(): SDL_FreeSurface; %i,%i\n", w, h);
1042
//------------------------------------------------------------------------------
1043
// SDL : free all surfaces
1044
//------------------------------------------------------------------------------
1045
void libereXImages()
1047
unsigned int _iIndex;
1050
for(_iIndex = 0; _iIndex < iXIMAGEMAX; _iIndex++)
1051
{ SDL_Surface *_pXImage = pListeXImage[_iIndex];
1055
SDL_FreeSurface(_pXImage);
1056
pListeXImage[_iIndex] = 0;
1059
if(power_conf->verbose)
1061
"> sdl_tlk.cpp/libereXImage(): SDL_FreeSurface; %i,%i\n", w, h);
1068
{ if(SDL_LockSurface(pEcranXImage))
1069
{ fprintf(stderr, "> sdl_tlk.cpp/verouiller(): Impossible de verouiller la surface %s\n", SDL_GetError());
1074
{ SDL_UnlockSurface(pEcranXImage);