r6609 - packages/trunk/biniax2/debian/patches
Miriam Ruiz
baby-guest at alioth.debian.org
Thu Apr 17 16:13:31 UTC 2008
Author: baby-guest
Date: 2008-04-17 16:13:31 +0000 (Thu, 17 Apr 2008)
New Revision: 6609
Modified:
packages/trunk/biniax2/debian/patches/endianess.patch
Log:
Save game data in an endianess-independent way
Modified: packages/trunk/biniax2/debian/patches/endianess.patch
===================================================================
--- packages/trunk/biniax2/debian/patches/endianess.patch 2008-04-17 15:03:56 UTC (rev 6608)
+++ packages/trunk/biniax2/debian/patches/endianess.patch 2008-04-17 16:13:31 UTC (rev 6609)
@@ -3,111 +3,143 @@
Index: biniax2/biniax.c
===================================================================
---- biniax2.orig/biniax.c 2008-04-17 14:39:51.000000000 +0000
-+++ biniax2/biniax.c 2008-04-17 14:42:13.000000000 +0000
-@@ -63,6 +63,8 @@
+--- biniax2.orig/biniax.c 2008-04-17 16:13:52.000000000 +0000
++++ biniax2/biniax.c 2008-04-17 16:14:11.000000000 +0000
+@@ -61,6 +61,7 @@
+ #include <fcntl.h>
+ #include <sys/stat.h>
#include <sys/types.h>
++#include <stdint.h>
#endif
-+#include <stdint.h>
-+
/* Global instance of GAME structure */
- BNX_GAME Game;
-
-@@ -1219,6 +1221,92 @@
+@@ -1219,6 +1220,117 @@
#endif
}
-+static uint16_t GetInt16B(FILE *fp)
++#ifndef _WIN32
++static uint16_t GetInt16(FILE *fp)
+{
+ uint16_t i = (uint16_t) (fgetc(fp) & 0xFF);
-+ i = ((uint16_t) (fgetc(fp) & 0xFF)) | (i << 0x08);
-+ return i;
-+}
-+
-+static uint16_t GetInt16L(FILE *fp)
-+{
-+ uint16_t i = (uint16_t) (fgetc(fp) & 0xFF);
+ i |= ((uint16_t) (fgetc(fp) & 0xFF) << 0x08);
+ return i;
+}
+
-+static uint32_t GetInt32B(FILE *fp)
++static uint32_t GetInt32(FILE *fp)
+{
+ uint32_t i = (uint32_t) (fgetc(fp) & 0xFF);
-+ i = ((uint32_t) (fgetc(fp) & 0xFF)) | (i << 0x08);
-+ i = ((uint32_t) (fgetc(fp) & 0xFF)) | (i << 0x08);
-+ i = ((uint32_t) (fgetc(fp) & 0xFF)) | (i << 0x08);
-+ return i;
-+}
-+
-+static uint32_t GetInt32L(FILE *fp)
-+{
-+ uint32_t i = (uint32_t) (fgetc(fp) & 0xFF);
+ i |= ((uint32_t) (fgetc(fp) & 0xFF) << 0x08);
+ i |= ((uint32_t) (fgetc(fp) & 0xFF) << 0x10);
+ i |= ((uint32_t) (fgetc(fp) & 0xFF) << 0x18);
+ return i;
+}
+
-+static uint64_t GetInt64B(FILE *fp)
++static void PutInt16(uint16_t i, FILE *fp)
+{
-+ uint64_t i = (uint64_t) GetInt32B(fp);
-+ i = ((uint64_t) GetInt32B(fp)) | (i << 0x20);
-+ return i;
-+}
-+
-+static uint64_t GetInt64L(FILE *fp)
-+{
-+ uint64_t i = (uint64_t) GetInt32L(fp);
-+ i |= ((uint64_t) GetInt32L(fp) << 0x20);
-+ return i;
-+}
-+
-+static void PutInt16B(uint16_t i, FILE *fp)
-+{
-+ fputc((i >> 0x08) & 0xFF, fp);
+ fputc(i & 0xFF, fp);
-+}
-+
-+static void PutInt16L(uint16_t i, FILE *fp)
-+{
-+ fputc(i & 0xFF, fp);
+ fputc((i >> 0x08) & 0xFF, fp);
+}
+
-+static void PutInt32B(uint32_t i, FILE *fp)
++static void PutInt32(uint32_t i, FILE *fp)
+{
-+ fputc((i >> 0x18) & 0xFF, fp);
-+ fputc((i >> 0x10) & 0xFF, fp);
-+ fputc((i >> 0x08) & 0xFF, fp);
+ fputc(i & 0xFF, fp);
-+}
-+
-+static void PutInt32L(uint32_t i, FILE *fp)
-+{
-+ fputc(i & 0xFF, fp);
+ fputc((i >> 0x08) & 0xFF, fp);
+ fputc((i >> 0x10) & 0xFF, fp);
+ fputc((i >> 0x18) & 0xFF, fp);
+}
+
-+static void PutInt64B(uint64_t i, FILE *fp)
++BNX_BOOL saveGame( BNX_GAME *game )
+{
-+ PutInt32B((i >> 0x20) & 0x00000000FFFFFFFF, fp);
-+ PutInt32B(i & 0x00000000FFFFFFFF, fp);
++ FILE *file;
++ int i, j;
++
++ file = fopen( saveFileName(), "wb" );
++ if ( file == (FILE *) NULL )
++ return BNX_FALSE;
++
++ PutInt16( 0xB201 , file );
++
++ PutInt32( game->moment , file );
++ PutInt16( game->mode , file );
++ PutInt16( game->scroll , file );
++ PutInt16( game->speed , file );
++ PutInt16( game->moves , file );
++ PutInt16( game->clears , file );
++ fputc( game->ingame , file );
++ PutInt32( game->sounds , file );
++ fputc( game->message , file );
++ PutInt32( game->lines , file );
++ PutInt16( game->level , file );
++ PutInt16( game->level_count , file );
++
++ PutInt16( cMaxPlayers , file );
++
++ for (i = 0; i < cMaxPlayers; i++)
++ {
++ fputc( game->player[i].x , file );
++ fputc( game->player[i].y , file );
++ fputc( game->player[i].e , file );
++ PutInt32( game->score[i] , file );
++ PutInt32( game->wins[i] , file );
++ PutInt32( game->best[i] , file );
++ }
++
++ PutInt32( cGridX , file );
++ PutInt32( cGridY , file );
++
++ for (j = 0; j < cGridY; j++)
++ for (i = 0; i < cGridX; i++)
++ fputc( game->grid[i][j] , file );
++
++ fclose( file );
++ return BNX_TRUE;
+}
+
-+static void PutInt64L(uint64_t i, FILE *fp)
++BNX_BOOL loadGame( BNX_GAME *game )
+{
-+ PutInt32L(i & 0x00000000FFFFFFFF, fp);
-+ PutInt32L((i >> 0x20) & 0x00000000FFFFFFFF, fp);
++ FILE *file;
++ uint16_t id, mp;
++ uint32_t mx, my;
++
++ file = fopen( saveFileName(), "rb" );
++ if ( file == (FILE *) NULL )
++ return BNX_FALSE;
++
++ id = GetInt16(file);
++ if (id != 0xB201)
++ return BNX_FALSE;
++ game->moment = GetInt32(file);
++ game->mode = GetInt16(file);
++ game->scroll = GetInt16(file);
++ game->speed = GetInt16(file);
++ game->moves = GetInt16(file);
++ game->clears = GetInt16(file);
++ game->ingame = fgetc(file);
++ game->sounds = GetInt32(file);
++ game->message = fgetc(file);
++ game->lines = GetInt32(file);
++ game->level = GetInt16(file);
++ game->level_count = GetInt16(file);
++
++// fread( game, 1, sizeof( BNX_GAME ), file );
++
++ fclose( file );
++ return BNX_TRUE;
+}
+
++#else /* WIN 32 */
BNX_BOOL saveGame( BNX_GAME *game )
{
FILE *file;
-@@ -1257,4 +1345,3 @@
+@@ -1250,6 +1362,7 @@
+
+ return BNX_TRUE;
+ }
++#endif
+
+ BNX_BOOL loadHiScore( BNX_GAME *game )
+ {
+@@ -1257,4 +1370,3 @@
game->best[ cModeTurn ] = hofGet()->tactic[ 0 ].score;
return BNX_TRUE;
}
More information about the Pkg-games-commits
mailing list