1 //*****************************************************************************
2 // copyright (c) 1998-2003 TLK Games all rights reserved
3 //-----------------------------------------------------------------------------
4 // file : "linuxroutines.cpp"
5 // created : 1999-08-19
6 // updates : 2004-08-01
7 //------------------------------------------------------------------------------
8 // functions : int mem_initialise(unsigned int _iNombreZones)
9 // char* reserveMemoire(unsigned int _iTailleMemoire)
10 // void libereMemoire(char* _pMemoire)
11 // void mem_libereTous()
12 // int load_pcx(char*, char*) ;
13 // sDescriptionGfx* load_pcx(char*) ;
14 // unsigned int littleWord(char* _pMem) ;
15 // short litMot16bits(short* _pMem) ;
16 // int litMot32bits(int* _pMem) ;
17 // int chaine_cmp(char* _pChaine1, char* _pChaine2, unsigned int _iTaille) ;
18 // char* chargeFichier(char* _pNomFichier)
19 // char* chargeFichier(char* _pNomFichier, unsigned int* pTaille)
20 // int chargeFichier(char* _pNomFichier, char* _pMemoire)
23 // void afficheErreur(char* _pErreur1, char* _pErreur2)
24 // int synchro_processusPause(int _iTemps)
25 // int synchro_CalculDifference()
26 // int synchro_CalculDifference2()
27 //-----------------------------------------------------------------------------
28 // This program is free software; you can redistribute it and/or modify it under
29 // the terms of the GNU General Public License as published by the Free Software
30 // Foundation; either version 2 of the License, or (at your option) any later
33 // This program is distributed in the hope that it will be useful, but WITHOUT
34 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
35 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
38 // You should have received a copy of the GNU General Public License along with
39 // this program; if not, write to the Free Software Foundation, Inc., 59 Temple
40 // Place - Suite 330, Boston, MA 02111-1307, USA.
42 //*****************************************************************************
44 #include "powermanga.hpp"
48 #include <sys/types.h>
52 //..............................................................................
53 extern unsigned int iVerbeux; //1=affiche les arguments / 1=verbose mode
55 //gestion de la memoire .........................................................
57 { char *pMemoire; //pointeur sur la zone memoire / pointer to memory zone
58 int iTailleMemoire; //taille de la zone en octets / size of memory zone in bytes
61 char *pZoneListeMemoire;
62 sListeMemoire *pZoneListeBase;
63 sListeMemoire *pZoneListeLibre;
64 unsigned int iTailleListe; //taille de la liste memoire / size of memory table
65 unsigned int iNombreZonesMaximum; //nombre de zones memoires maxi / number maximum of memory zone
66 unsigned int iNombreZones; //nombre de zone actuelle / number of memroy zone
67 unsigned int iOctetsTotal; //taille prise en octets / total memory size allocated
68 unsigned int iNombreZonesMax; //nombre maximum de zones reserves
70 //..............................................................................
71 unsigned int iCompteurBoucle;
79 static struct timeval time_begin;
80 static struct timeval temps_actuel;
81 static struct timeval temps_sauve;
82 static struct timeval temps_actuel2;
83 static struct timeval temps_sauve2;
86 //..............................................................................
87 short litMot16bitsBig(short *_pMem);
88 unsigned short litMot16bits(unsigned short *_pMem);
89 extern const char nomprefix[];
90 extern unsigned int iFrame3;
91 //------------------------------------------------------------------------------
92 // initialise la liste memoire / initialise memory table
93 // input => _iNombreZones : nombre de zones memoire possibles au maximum / number maximum of memory zone
94 // ouput <= 0=erreur / 0=error
95 //------------------------------------------------------------------------------
96 int mem_initialise(unsigned int _iNombreZones)
99 iNombreZones = 0; // nombre de zones reservees a zero
100 pZoneListeMemoire = 0;
101 iNombreZonesMaximum = _iNombreZones; // nombre maximum de zones pouvant etre reservees
103 iTailleListe = iNombreZonesMaximum * sizeof(sListeMemoire);
104 iOctetsTotal = iTailleListe;
105 pZoneListeMemoire = (char *)malloc(iTailleListe);
106 if(!pZoneListeMemoire)
107 { afficheErreur("malloc() failed", "linuxroutines/mem_initialise()");
110 pZoneListeBase = (sListeMemoire *) pZoneListeMemoire;
111 pZoneListeLibre = pZoneListeBase;
112 sListeMemoire *_pMem = pZoneListeBase;
114 for(_iIndex = 0; _iIndex < iNombreZonesMaximum; _iIndex++, _pMem++) //clean memory table
115 { _pMem->pMemoire = 0x0;
116 _pMem->iTailleMemoire = 0x0;
121 //------------------------------------------------------------------------------
122 // reserve une zone memoire / allocate memory
123 // input => _iTailleMemoire : taille memoire en octets souhaitee / size of bytes
124 // output <= _pMem : adresse memoire (0=erreur) / pointer to memory
125 //------------------------------------------------------------------------------
126 char *reserveMemoire(unsigned int _iTailleMemoire)
129 char *_pMemoire = 0x0;
131 unsigned int _iIndex;
132 if(iNombreZones >= iNombreZonesMaximum)
133 { printf ("linuxroutines.cpp/reserveMemoire(unsigned int) : table overflow ; size request %i bytes ; total allocate : % i in %i zones\n", _iTailleMemoire, iOctetsTotal, iNombreZones);
136 _pMem = (char *)malloc(_iTailleMemoire);
138 { printf ("linuxroutines.cpp/reserveMemoire(unsigned int) : malloc(int) return 0 ; size request %i bytes ; total allocate : % i in %i zones\n", _iTailleMemoire, iOctetsTotal, iNombreZones);
141 iOctetsTotal += _iTailleMemoire;
142 pZoneListeLibre->pMemoire = _pMem; //pointeur memoire
143 pZoneListeLibre->iTailleMemoire = _iTailleMemoire; //taille en octets
144 pZoneListeLibre += 1;
146 if(iNombreZones > iNombreZonesMax)
147 iNombreZonesMax = iNombreZones;
149 for(_iIndex = 0; _iIndex < _iTailleMemoire; _iIndex++)
150 *(_pMemoire++) = _cZero; //efface memoire
154 //------------------------------------------------------------------------------
155 // liberation d'une zone memoire / free memory
156 // input => _pMemoire : adresse de la zone a liberer / pointer to memory
157 //------------------------------------------------------------------------------
158 void libereMemoire(char *_pMemoire)
160 sListeMemoire *_pListeMem;
161 sListeMemoire *_pListeMemSource;
162 unsigned int _iCompteur;
164 { _pListeMem = pZoneListeBase;
165 for(_iCompteur = 0; _iCompteur < iNombreZones; _iCompteur++, _pListeMem++)
166 { if(_pListeMem->pMemoire == _pMemoire) //on a trouve l'adresse dans la table ?
167 { free(_pMemoire); //oui, libere la memoire
168 _pListeMemSource = _pListeMem + 1;
169 iOctetsTotal -= _pListeMem->iTailleMemoire;
172 while (_iCompteur < iNombreZones)
173 { _pListeMem->pMemoire = _pListeMemSource->pMemoire;
174 _pListeMem->iTailleMemoire = _pListeMemSource->iTailleMemoire;
179 _pListeMem->pMemoire = 0x0;
180 _pListeMem->iTailleMemoire = 0x0;
186 { fprintf(stderr, "libereMemoire() : can't release the address %x\n", (int)_pMemoire);
190 { fprintf(stderr, "libereMemoire() : try to release a null address!\n");
194 //------------------------------------------------------------------------------
195 // retourne la taille d'une adresse memoire reservee / get memory zone's size
196 // input => _pMem : pointeur sur une zone memoire / pointer to memory
197 //------------------------------------------------------------------------------
198 int mem_retourneTaille(char *_pMem)
200 unsigned int _iCompteur;
201 sListeMemoire *_pListeMem = pZoneListeBase;
203 { for(_iCompteur = 0; _iCompteur < iNombreZones; _iCompteur++, _pListeMem++)
204 { if(_pListeMem->pMemoire == _pMem)
205 return _pListeMem->iTailleMemoire;
211 //------------------------------------------------------------------------------
212 // libere toutes les zones memoires / free all memory
213 //------------------------------------------------------------------------------
214 void mem_libereTous()
216 unsigned int _iCompteur;
218 sListeMemoire *_pListeMem = pZoneListeBase;
221 fprintf(stdout, "> linuxroutines.cpp/mem_libereTous(): maximum of memory which were allocated during the game : %i\n", iNombreZonesMax);
227 fprintf(stdout, "> linuxroutines.cpp/mem_libereTous() : %i zones were not released.\n", iNombreZones);
229 for(_iCompteur = 0; _iCompteur < iNombreZones; _iCompteur++, _pListeMem++)
230 { _pMemoire = _pListeMem->pMemoire;
232 { /* fprintf(stderr, "mem_libereTous: adresseMem =%x ; taille_mem=%ld\n",
233 (int)_pListeMem->pMemoire, _pListeMem->iTailleMemoire); */
234 free(_pMemoire); //libere la memoire
235 _pListeMem->pMemoire = 0;
236 _pListeMem->iTailleMemoire = 0;
239 if(pZoneListeMemoire)
240 { free(pZoneListeMemoire);
241 pZoneListeMemoire = 0x0;
247 //------------------------------------------------------------------------------
248 // decompress pcx file
249 // input => _pFichier : filename
250 // output <= _pStructureGfx : pointer to the "sDescriptionGfx" structure / 0=error
251 //------------------------------------------------------------------------------
252 sDescriptionGfx *load_pcx(char *_pNomFichier)
254 unsigned int iLongeur;
255 unsigned int ptr = 128;
256 unsigned char nbr_bytes;
258 unsigned int i1, i, total;
259 unsigned char *_pFichier, *_pAdresseMem;
260 sDescriptionGfx *_pDescripGfx = 0x0;
261 _pFichier = (unsigned char *)chargeFichier(_pNomFichier, &iLongeur); //load file in memory
262 if(!_pFichier) return 0;
263 unsigned short *_p16 = (unsigned short *)_pFichier;
264 unsigned int _iLarge = (litMot16bits(_p16 + 4) - litMot16bits(_p16 + 2)) + 1; //image width
265 unsigned int _iHaut = (litMot16bits(_p16 + 5) - litMot16bits(_p16 + 3)) + 1; //image height
266 unsigned int _iProfondeur = _pFichier[3]; //bits per pixel
268 _pDescripGfx = (sDescriptionGfx *) reserveMemoire(sizeof(sDescriptionGfx)); //allocate structure memory
270 { afficheErreur("_pDescripGfx out of memory", "linuxroutines.cpp/load_pcx()");
273 _pDescripGfx->iLargeur = _iLarge;
274 _pDescripGfx->iHauteur = _iHaut;
275 _pDescripGfx->iProfond = _iProfondeur;
276 _pDescripGfx->iTaille = _iLarge * _iHaut * (_iProfondeur >> 3);
277 _pDescripGfx->pAdresse = reserveMemoire(_pDescripGfx->iTaille); //allocate image memory
278 if(!_pDescripGfx->pAdresse)
279 { libereMemoire((char *)_pDescripGfx);
280 printf("linuxroutines.cpp/load_pcx() : height=%i / width=%i \n", _iLarge, _iHaut);
281 afficheErreur("_pDescripGfx->iTaille : out of memory\n", "linuxroutines.cpp/reserveMemoire()");
285 _pAdresseMem = (unsigned char *)_pDescripGfx->pAdresse;
289 { if((_pFichier[ptr] & 0xC0) == 0xC0)
290 { nbr_bytes = _pFichier[ptr] & 0x3F;
295 val = _pFichier[ptr];
296 total += nbr_bytes; // Samuel Hocevar
297 if(total >= _pDescripGfx->iTaille)
299 for(i1 = 0; i1 < nbr_bytes; i1++)
300 { *_pAdresseMem = val;
305 libereMemoire((char *)_pFichier);
310 "> linuxroutines.cpp/load_pcx(): \"%s\"; height=%i; width=%i; size=%i\n",
314 _pDescripGfx->iTaille);
319 //------------------------------------------------------------------------------
320 // lecture d'un mot de 16 bits code en memoire en little-endian
321 // input => _pMem : pointeur sur le mot en memoire
322 // output <= _iValeur : valeur utilisale
323 //------------------------------------------------------------------------------
324 unsigned int littleWord(char *_pMem)
326 unsigned short *t = (unsigned short *)_pMem;
330 //------------------------------------------------------------------------------
331 // lecture d'un long mot signe de 16 bits little-endian (compatible little-endian/big-endian)
332 // input => _pMem : pointeur sur le mot en memoire
333 // output <= _iValeur : valeur utilisale
334 //------------------------------------------------------------------------------
335 short litMot16bits(short *_pMem)
338 unsigned char *_pMemoire = (unsigned char *)_pMem;
339 _iValeur = _pMemoire[1]; //lit du little endian pour un powerpc
341 _iValeur += _pMemoire[0];
345 //------------------------------------------------------------------------------
346 // lecture d'un long mot signe de 16 bits little-endian (compatible little-endian/big-endian)
347 // input => _pMem : pointeur sur le mot en memoire
348 // output <= _iValeur : valeur utilisale
349 //------------------------------------------------------------------------------
350 unsigned short litMot16bits(unsigned short *_pMem)
352 unsigned short _iValeur = 0;
353 unsigned char *_pMemoire = (unsigned char *)_pMem;
354 _iValeur = _pMemoire[1]; //lit du little endian pour un powerpc
356 _iValeur += _pMemoire[0];
360 //------------------------------------------------------------------------------
361 // lecture d'un long mot signe de 16 bits big-endian (compatible little-endian/big-endian)
362 // input => _pMem : pointeur sur le mot en memoire
363 // output <= _iValeur : valeur utilisale
364 //------------------------------------------------------------------------------
365 short litMot16bitsBig(short *_pMem)
368 unsigned char *_pMemoire = (unsigned char *)_pMem;
369 _iValeur = _pMemoire[0]; //lit du big endian pour un 80x86
371 _iValeur += _pMemoire[1];
375 //------------------------------------------------------------------------------
376 //lecture d'un long mot signe de 32 bits little-endian(compatible little-endian/big-endian)
377 // input => _pMem : pointeur sur le mot 32 bits en memoire
378 // output <= _iValeur : valeur utilisale
379 //------------------------------------------------------------------------------
380 int litMot32bits(int *_pMem)
383 unsigned char *_pMemoire = (unsigned char *)_pMem;
384 _iValeur = _pMemoire[3];
386 _iValeur += _pMemoire[2];
388 _iValeur = _pMemoire[1];
390 _iValeur += _pMemoire[0];
394 //------------------------------------------------------------------------------
395 // convertit un long mot de 32 bits en memoire little-endian => big-endian
396 //------------------------------------------------------------------------------
397 void convert32bits_2bigendian (unsigned char* memory)
398 { unsigned char b0, b1, b2, b3;
409 //------------------------------------------------------------------------------
410 //comparaison de deux chaines de caracteres
411 // input => _pChaine1 : pointeur sur la premiere chaine
412 // => _pChaine1 : pointeur sur la deuxieme chaine
413 // => _iTaille : longeurs en octets de chaines
414 // output <= 0les chaines ont au moins une difference / 1=les chaines sont identiques
415 //------------------------------------------------------------------------------
416 int chaine_cmp(char *_pChaine1, char *_pChaine2, unsigned int _iTaille)
418 unsigned int _iLongeur = _iTaille;
419 char *_pMem1 = _pChaine1;
420 char *_pMem2 = _pChaine2;
421 unsigned int _iIndex;
422 char _cOctet1, _cOctet2;
423 for(_iIndex = 0; _iIndex < _iLongeur; _iIndex++)
424 { _cOctet1 = _pMem1[_iIndex];
425 _cOctet2 = _pMem2[_iIndex];
426 if(_cOctet2 != _cOctet1)
432 //------------------------------------------------------------------------------
433 // locate a file under one of the data directories (thanx to Andre Majorel :-)
434 // input => name : name of file relative to data directory
435 // output <= 0 : could not locate file (not found, or not enough
436 // memory, or the name given was absolute)
437 // other : pointer to a malloc'd buffer containing the name
438 // under which the file was found. free()-ing the
439 // buffer is the responsibility of the caller.
440 //------------------------------------------------------------------------------
441 static const char *data_directories[]=
442 { ".", // Normally unused, except when running from the source directory...
443 "/opt/QtPalmtop/share/games/powermanga/",
444 0 // Special value meaning "$(PREFIX)/share/games/powermanga/"
445 // Also marks end of list
447 static char pathstring[256];
449 char *locate_data_file(const char *const name)
452 for(int i = 0; i < 256; i++)
455 if(name == 0) return 0;
456 if(*name == '/') return strdup(name); // Guillaume Cottenceau (2001-03-15) replace "return 0;" by "strdup(name);"
457 // En effet, nous sommes dans le cas ou le programme recherche dans /usr/share/games/powermanga
458 for(const char **p = data_directories;; p++)
461 { const char *subdir = "/share/games/powermanga/";
462 pathname = &pathstring[0];
463 /*pathname=(char *)malloc(strlen(nomprefix) + strlen(subdir) + strlen(name) + 1);
466 fprintf(stderr, "powermanga: not enough memory\n");
469 strcpy(pathname, nomprefix);
470 strcat(pathname, subdir);
471 strcat(pathname, name);
473 else if(**p == '~') // Not used anymore
474 { static const char bogus = '\0';
475 static const char *home_dir = &bogus;
476 if(home_dir == &bogus) home_dir = getenv("HOME");
477 if(home_dir == 0) continue; // $HOME not set. Skip this directory.
478 pathname = &pathstring[0];
480 /*pathname = (char *)malloc(strlen(home_dir) + 1 + strlen(*p + 1) + 1 + strlen(name) + 1);
483 fprintf(stderr, "powermanga: not enough memory\n");
486 strcpy(pathname, home_dir);
487 strcat(pathname, *p + 1);
488 strcat(pathname, "/");
489 strcat(pathname, name);
493 pathname = &pathstring[0];
494 /*pathname = (char *)malloc(strlen(*p) + 1 + strlen(name) + 1);
497 fprintf(stderr, "powermanga: not enough memory\n");
500 strcpy(pathname, *p);
501 strcat(pathname, "/");
502 strcat(pathname, name);
504 //puts(pathname); // DEBUG
507 if(_stat(pathname, &s) == 0 && !_S_ISDIR(s.st_mode))
511 if(stat(pathname, &s) == 0 && !S_ISDIR(s.st_mode))
517 return 0; // Not found.
520 //------------------------------------------------------------------------------
521 // load a file in memory / charge un fichier en memoire
522 // input => _pNomFichier : nom du fichier
523 // _pAdresse : adresse de chargemebt
524 // _iTaille : taille a lire
525 // output <= 1 : tout c'est bien passe
527 //------------------------------------------------------------------------------
528 char *chargeFichier(char *_pNomFichier)
530 unsigned int _pTaille;
531 return chargeFichier(_pNomFichier, &_pTaille);
534 //------------------------------------------------------------------------------
535 // load a file in memory
536 // input => _pNomFichier : filename
537 // sortie <= _pMemoire : ptr/integer
538 //------------------------------------------------------------------------------
539 char *chargeFichier(char *_pNomFichier, unsigned int *pTaille)
543 struct stat sDescriptionFichier;
544 char *pathname = locate_data_file(_pNomFichier);
546 { printf("linuxroutines/chargeFichier() : can't locate file : %s\n\n", _pNomFichier);
550 _iHandle = open(pathname, O_RDONLY | O_BINARY, 0);
552 _iHandle = open(pathname, O_RDONLY, 0);
555 { printf("linuxroutines/chargeFichier() : can't open file : %s (%s)\n\n", pathname, strerror(errno));
559 if(fstat(_iHandle, &sDescriptionFichier))
560 { printf("linuxroutines/chargeFichier() : can't stat file : %s (%s)\n\n", pathname, strerror(errno));
565 (*pTaille) = sDescriptionFichier.st_size; //sauve taille
566 _pMemoire = reserveMemoire(sDescriptionFichier.st_size); //reserve la place en memoire pour lire le fichier
568 { printf("linuxroutines/chargeFichier() %s : out of memory\n\n", pathname);
573 if(read(_iHandle, _pMemoire, sDescriptionFichier.st_size) != sDescriptionFichier.st_size)
574 { libereMemoire(_pMemoire);
575 printf("linuxroutines/chargeFichier() can't read file %s (%s)\n\n", pathname, strerror(errno));
583 printf("linuxroutines/chargeFichier : file %s was loaded in memory\n", pathname);
589 //------------------------------------------------------------------------------
590 // load a file in memory / charge un fichier en memoire
591 // input => _pNomFichier : filename / nom du fichier
592 // => _pMemoire : pointer to memory / pointeur sur la memoire
593 // output <= 1 : 0 error/erreur
594 //------------------------------------------------------------------------------
595 int chargeFichier(char *_pNomFichier, char *_pMemoire)
598 struct stat sDescriptionFichier;
599 char *pathname = locate_data_file(_pNomFichier);
601 { printf("linuxroutines/chargeFichier() : can't locate file : %s\n\n", _pNomFichier);
605 _iHandle = open(pathname, O_RDONLY | O_BINARY, 0);
607 _iHandle = open(pathname, O_RDONLY, 0);
610 { printf ("linuxroutines.cpp/chargeFichier() : can't open file : %s (%s)\n\n", pathname, strerror(errno));
614 if(fstat(_iHandle, &sDescriptionFichier))
615 { printf ("linuxroutines.cpp/chargeFichier() : can't stat file : %s (%s)\n\n", pathname, strerror(errno));
620 if(read(_iHandle, _pMemoire, sDescriptionFichier.st_size) != sDescriptionFichier.st_size)
621 { printf("linuxroutines.cpp/chargeFichier() can't read file %s (%s)\n\n", pathname, strerror(errno));
628 if(iVerbeux > 1) printf("linuxroutines/chargeFichier : file %s was loaded in memory\n", pathname);
634 //------------------------------------------------------------------------------
635 // initialise le compteur de boucle et l'heure de depart du programme
636 //------------------------------------------------------------------------------
640 time_begin = SDL_GetTicks();
641 temps_sauve = SDL_GetTicks();
642 temps_sauve2 = SDL_GetTicks();
644 gettimeofday(&time_begin, NULL);
645 gettimeofday(&temps_sauve, NULL);
646 gettimeofday(&temps_sauve2, NULL);
651 //------------------------------------------------------------------------------
652 // affiche information sur le systeme
653 //------------------------------------------------------------------------------
659 unsigned long duration;
661 time_end = SDL_GetTicks();
662 duration = time_end - time_begin;
663 fps = (1000.0 * iCompteurBoucle) / duration;
665 { printf("> linuxroutines.cpp/number of loops : %i\n", iCompteurBoucle);
666 printf("> linuxroutines.cpp/running time : %li\n", duration);
667 printf("> linuxroutines.cpp/fps_affiche() : frames per seconde : %g \n", fps);
670 struct utsname kernel;
672 unsigned long duration;
681 static struct timeval time_end;
683 //calcul le temps total d'execution ............................................
684 gettimeofday(&time_end, NULL);
685 duration = (time_end.tv_sec - time_begin.tv_sec) * 1000 + (time_end.tv_usec - time_begin.tv_usec) / 1000;
686 fps = (1000.0 * iCompteurBoucle) / duration;
688 //version du systeme d'exploitation ............................................
689 if(uname(&kernel) < 0)
690 { strcpy(os_name, "?");
694 { strncpy(os_name, kernel.sysname, 32);
695 strncpy(os_vers, kernel.release, 32);
697 //processeur & memoire physique du systeme .....................................
698 stat("/proc/kcore", &statmem);
699 mem = ((float)statmem.st_size) / 1024 / 1024;
700 strcpy(cpu, "Unknown");
701 strcpy(freq, "Unknown");
702 cpuinfo = fopen("/proc/cpuinfo", "r");
704 { while (fgets(txt, 255, cpuinfo))
705 { if(!strncmp(txt, "model", 5))
707 while (txt[i] != ':') i++;
709 for(int j = 0; j < 64;)
710 { if(txt[i++] != '\n') cpu[j++] = txt[i - 1];
713 if(!strncmp(txt, "cpu MHz", 7))
715 while (txt[i] != ':') i++;
717 sprintf(freq, "%d", atoi(txt + i));
721 //processeur & memoire physique du systeme .....................................
723 { printf("operating system : %s %s\n", os_name, os_vers);
724 printf("processor : %s at %s Mhz with %.0f RAM\n", cpu, freq, mem);
725 printf("number of loops : %i\n", iCompteurBoucle);
726 printf("running time : %li\n", duration);
727 printf("frames per seconde : %g \n", fps);
728 //printf ( "Compilateur : %s\n" , COMPILO );
733 //------------------------------------------------------------------------------
734 // display error message
735 // input => _Message : message
736 //------------------------------------------------------------------------------
737 void afficheMessage(char *_Message)
739 printf("%s\n", _Message);
742 //------------------------------------------------------------------------------
743 // display error message
744 // input => _Message1 : message 1
745 // => _Message2 : message 2
746 //------------------------------------------------------------------------------
747 void afficheMessage(char *_Message1, char *_Message2)
749 printf("%s %s\n", _Message1, _Message2);
752 //------------------------------------------------------------------------------
753 // display error message
754 // input => _pErreur1 : error message
755 // => _pErreur2 : title error
756 //------------------------------------------------------------------------------
757 void afficheErreur(char *_pErreur1, char *_pErreur2)
759 printf("%s %s\n", _pErreur2, _pErreur1);
762 //------------------------------------------------------------------------------
763 // display error message
764 // input => _pErreur1 : error message
765 // => _pErreur2 : title error
766 // => _pErreur3 : error message
767 //------------------------------------------------------------------------------
768 void afficheErreur(char *_pErreur1, char *_pErreur2, char *_pErreur3)
770 printf("%s %s %s\n", _pErreur2, _pErreur1, _pErreur3);
773 //------------------------------------------------------------------------------
774 // display error message
775 // input => _pErreur1 : error message
776 // => _pErreur2 : title error
777 // => _iErreur : error number
778 //------------------------------------------------------------------------------
779 void afficheErreur(char *_pErreur1, char *_pErreur2, int _iErreur)
781 printf("%s %s error=%i\n", _pErreur2, _pErreur1, _iErreur);
784 //------------------------------------------------------------------------------
787 //------------------------------------------------------------------------------
788 int synchro_processusPause(int _iTemps)
791 if(_iTemps > (int)iFrame3)
795 return (_iTemps > 0 ? _iTemps : 0);
797 struct timeval temps;
798 if(_iTemps > (int)iFrame3)
801 { temps.tv_usec = _iTemps % (unsigned long)1000000;
802 temps.tv_sec = _iTemps / (unsigned long)1000000;
803 //sleep for a time interval
804 select(0, NULL, NULL, NULL, &temps);
806 return (_iTemps > 0 ? _iTemps : 0);
811 int synchro_CalculDifference()
814 temps_actuel = SDL_GetTicks();
815 _iDifference = temps_actuel - temps_sauve;
816 temps_sauve = temps_actuel;
820 //------------------------------------------------------------------------------
821 // calcul la difference entre deux heure differentes
822 // sortie <= : _iDifference
823 //------------------------------------------------------------------------------
824 int synchro_CalculDifference()
827 gettimeofday(&temps_actuel, NULL);
828 _iDifference = (1000000 * (temps_actuel.tv_sec - temps_sauve.tv_sec)) + (temps_actuel.tv_usec - temps_sauve.tv_usec);
829 temps_sauve = temps_actuel;
833 //------------------------------------------------------------------------------
834 // calcul la difference entre deux heure differentes
835 // sortie <= : _iDifference
836 //------------------------------------------------------------------------------
837 int synchro_CalculDifference2()
840 gettimeofday(&temps_actuel2, NULL);
841 _iDifference = (1000000 * (temps_actuel2.tv_sec - temps_sauve2.tv_sec)) + (temps_actuel2.tv_usec - temps_sauve2.tv_usec);
842 temps_sauve2 = temps_actuel2;