shithub: choc

Download patch

ref: c2af7bb926e4f7026347739e4a5a58a3bac51d0f
parent: b7906ef4baad9f3a2a7e1b32a9d739e29e001f79
author: Simon Howard <fraggle@gmail.com>
date: Thu Mar 15 14:38:55 EDT 2007

Use SDL for endianness byte swapping. m_swap.c removed; m_swap.h renamed
to i_swap.h.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 857

--- a/configure.in
+++ b/configure.in
@@ -60,8 +60,6 @@
 
 AC_SUBST(ac_aux_dir)
 
-AC_C_BIGENDIAN
-
 dnl Shut up the datarootdir warnings.
 AC_DEFUN([AC_DATAROOTDIR_CHECKED])
 
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -64,6 +64,7 @@
 i_scale.c            i_scale.h             \
 i_pcsound.c          i_pcsound.h           \
 i_sound.c            i_sound.h             \
+                     i_swap.h              \
 i_system.c           i_system.h            \
 i_timer.c            i_timer.h             \
 i_video.c            i_video.h             \
@@ -77,7 +78,6 @@
 memio.c              memio.h               \
 mus2mid.c            mus2mid.h             \
 m_random.c           m_random.h            \
-m_swap.c             m_swap.h              \
 net_client.c         net_client.h          \
 net_common.c         net_common.h          \
 net_dedicated.c      net_dedicated.h       \
--- a/src/f_finale.c
+++ b/src/f_finale.c
@@ -31,7 +31,7 @@
 // Functions.
 #include "deh_main.h"
 #include "i_system.h"
-#include "m_swap.h"
+#include "i_swap.h"
 #include "z_zone.h"
 #include "v_video.h"
 #include "w_wad.h"
--- a/src/hu_lib.c
+++ b/src/hu_lib.c
@@ -29,7 +29,7 @@
 #include "doomdef.h"
 
 #include "v_video.h"
-#include "m_swap.h"
+#include "i_swap.h"
 
 #include "hu_lib.h"
 #include "r_local.h"
--- a/src/hu_stuff.c
+++ b/src/hu_stuff.c
@@ -31,7 +31,7 @@
 #include "z_zone.h"
 
 #include "deh_main.h"
-#include "m_swap.h"
+#include "i_swap.h"
 
 #include "hu_stuff.h"
 #include "hu_lib.h"
--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -41,10 +41,10 @@
 #include "i_system.h"
 #include "i_pcsound.h"
 #include "i_sound.h"
+#include "i_swap.h"
 #include "deh_main.h"
 #include "m_argv.h"
 #include "m_misc.h"
-#include "m_swap.h"
 #include "w_wad.h"
 
 #include "doomdef.h"
--- /dev/null
+++ b/src/i_swap.h
@@ -1,0 +1,50 @@
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// Copyright(C) 1993-1996 Id Software, Inc.
+// Copyright(C) 2005,2006,2007 Simon Howard
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+// 02111-1307, USA.
+//
+// DESCRIPTION:
+//	Endianess handling, swapping 16bit and 32bit.
+//
+//-----------------------------------------------------------------------------
+
+
+#ifndef __I_SWAP__
+#define __I_SWAP__
+
+#include "SDL_endian.h"
+
+// Endianess handling.
+// WAD files are stored little endian.
+
+// Just use SDL's endianness swapping functions.
+
+#define SHORT(x)  SDL_SwapLE16(x)
+#define LONG(x)   SDL_SwapLE32(x)
+
+// Defines for checking the endianness of the system.
+
+#if SDL_BYTEORDER == SYS_LIL_ENDIAN
+#define SYS_LITTLE_ENDIAN
+#elif SDL_BYTEORDER == SYS_BIG_ENDIAN
+#define SYS_BIG_ENDIAN
+#endif
+
+#endif
+
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -39,9 +39,9 @@
 #include "d_main.h"
 #include "i_scale.h"
 #include "i_system.h"
+#include "i_swap.h"
 #include "i_timer.h"
 #include "m_argv.h"
-#include "m_swap.h"
 #include "s_sound.h"
 #include "sounds.h"
 #include "v_video.h"
--- a/src/m_menu.c
+++ b/src/m_menu.c
@@ -36,6 +36,7 @@
 #include "d_main.h"
 #include "deh_main.h"
 
+#include "i_swap.h"
 #include "i_system.h"
 #include "i_timer.h"
 #include "i_video.h"
@@ -51,7 +52,6 @@
 #include "g_game.h"
 
 #include "m_argv.h"
-#include "m_swap.h"
 #include "p_saveg.h"
 
 #include "s_sound.h"
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -49,12 +49,12 @@
 #include "z_zone.h"
 
 #include "m_menu.h"
-#include "m_swap.h"
 #include "m_argv.h"
 #include "net_client.h"
 
 #include "w_wad.h"
 
+#include "i_swap.h"
 #include "i_system.h"
 #include "i_video.h"
 #include "v_video.h"
--- a/src/m_swap.c
+++ /dev/null
@@ -1,54 +1,0 @@
-// Emacs style mode select   -*- C++ -*- 
-//-----------------------------------------------------------------------------
-//
-// Copyright(C) 1993-1996 Id Software, Inc.
-// Copyright(C) 2005 Simon Howard
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-//
-// DESCRIPTION:
-//	Endianess handling, swapping 16bit and 32bit.
-//
-//-----------------------------------------------------------------------------
-
-
-
-#include "m_swap.h"
-
-
-#ifdef WORDS_BIGENDIAN
-
-// Swap 16bit, that is, MSB and LSB byte.
-unsigned short SwapSHORT(unsigned short x)
-{
-    // No masking with 0xFF should be necessary. 
-    return (x>>8) | (x<<8);
-}
-
-// Swapping 32bit.
-unsigned int SwapLONG( unsigned int x)
-{
-    return
-	(x>>24)
-	| ((x>>8) & 0xff00)
-	| ((x<<8) & 0xff0000)
-	| (x<<24);
-}
-
-
-#endif
-
-
--- a/src/m_swap.h
+++ /dev/null
@@ -1,50 +1,0 @@
-// Emacs style mode select   -*- C++ -*- 
-//-----------------------------------------------------------------------------
-//
-// Copyright(C) 1993-1996 Id Software, Inc.
-// Copyright(C) 2005 Simon Howard
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-//
-// DESCRIPTION:
-//	Endianess handling, swapping 16bit and 32bit.
-//
-//-----------------------------------------------------------------------------
-
-
-#ifndef __M_SWAP__
-#define __M_SWAP__
-
-
-#include "config.h"
-
-
-// Endianess handling.
-// WAD files are stored little endian.
-#ifdef WORDS_BIGENDIAN
-extern unsigned short	SwapSHORT(unsigned short);
-extern unsigned int	SwapLONG(unsigned int);
-#define SHORT(x)	((short)SwapSHORT((unsigned short) (x)))
-#define LONG(x)         ((int)SwapLONG((unsigned int) (x)))
-#else
-#define SHORT(x)	(x)
-#define LONG(x)         (x)
-#endif
-
-
-
-
-#endif
--- a/src/md5.c
+++ b/src/md5.c
@@ -19,16 +19,23 @@
  *  - Ian Jackson <ian@chiark.greenend.org.uk>.
  * Still in the public domain.
  */
-#include "config.h"
 
+#include "i_swap.h"
+
 #include <string.h>             /* for memcpy() */
 #include <sys/types.h>          /* for stupid systems */
 
 #include "md5.h"
 
-#ifdef WORDS_BIGENDIAN
-void
-byteSwap(UWORD32 *buf, unsigned words)
+#ifdef SYS_LITTLE_ENDIAN
+
+// Little endian system - no byte swapping required
+
+#define ByteSwapBlock(x)
+
+#else
+
+void ByteSwapBlock(UWORD32 *buf, unsigned words)
 {
         md5byte *p = (md5byte *)buf;
 
@@ -38,10 +45,9 @@
                 p += 4;
         } while (--words);
 }
-#else
-#define byteSwap(buf,words)
-#endif
 
+#endif /* #ifndef SYS_LITTLE_ENDIAN */
+
 /*
  * Start MD5 accumulation.  Set bit count to 0 and buffer to mysterious
  * initialization constants.
@@ -80,7 +86,7 @@
         }
         /* First chunk is an odd size */
         memcpy((md5byte *)ctx->in + 64 - t, buf, t);
-        byteSwap(ctx->in, 16);
+        ByteSwapBlock(ctx->in, 16);
         MD5_Transform(ctx->buf, ctx->in);
         buf += t;
         len -= t;
@@ -88,7 +94,7 @@
         /* Process data in 64-byte chunks */
         while (len >= 64) {
                 memcpy(ctx->in, buf, 64);
-                byteSwap(ctx->in, 16);
+                ByteSwapBlock(ctx->in, 16);
                 MD5_Transform(ctx->buf, ctx->in);
                 buf += 64;
                 len -= 64;
@@ -133,13 +139,13 @@
 
         if (count < 0) {        /* Padding forces an extra block */
                 memset(p, 0, count + 8);
-                byteSwap(ctx->in, 16);
+                ByteSwapBlock(ctx->in, 16);
                 MD5_Transform(ctx->buf, ctx->in);
                 p = (md5byte *)ctx->in;
                 count = 56;
         }
         memset(p, 0, count);
-        byteSwap(ctx->in, 14);
+        ByteSwapBlock(ctx->in, 14);
 
         /* Append length in bits and transform */
         ctx->in[14] = ctx->bytes[0] << 3;
@@ -146,7 +152,7 @@
         ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
         MD5_Transform(ctx->buf, ctx->in);
 
-        byteSwap(ctx->buf, 4);
+        ByteSwapBlock(ctx->buf, 4);
         memcpy(digest, ctx->buf, 16);
         memset(ctx, 0, sizeof(ctx));    /* In case it's sensitive */
 }
@@ -255,3 +261,4 @@
 }
 
 #endif
+
--- a/src/mus2mid.c
+++ b/src/mus2mid.c
@@ -26,7 +26,7 @@
 #include <stdio.h>
 
 #include "doomtype.h"
-#include "m_swap.h"
+#include "i_swap.h"
 
 #include "memio.h"
 #include "mus2mid.h"
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -32,7 +32,7 @@
 #include "z_zone.h"
 
 #include "deh_main.h"
-#include "m_swap.h"
+#include "i_swap.h"
 #include "m_bbox.h"
 
 #include "g_game.h"
--- a/src/r_data.c
+++ b/src/r_data.c
@@ -28,10 +28,10 @@
 
 
 #include "deh_main.h"
+#include "i_swap.h"
 #include "i_system.h"
 #include "z_zone.h"
 
-#include "m_swap.h"
 
 #include "w_wad.h"
 
--- a/src/r_things.c
+++ b/src/r_things.c
@@ -33,8 +33,8 @@
 
 #include "deh_main.h"
 #include "doomdef.h"
-#include "m_swap.h"
 
+#include "i_swap.h"
 #include "i_system.h"
 #include "z_zone.h"
 #include "w_wad.h"
--- a/src/st_lib.c
+++ b/src/st_lib.c
@@ -34,8 +34,7 @@
 #include "z_zone.h"
 #include "v_video.h"
 
-#include "m_swap.h"
-
+#include "i_swap.h"
 #include "i_system.h"
 
 #include "w_wad.h"
--- a/src/v_video.c
+++ b/src/v_video.c
@@ -36,7 +36,7 @@
 #include "doomdata.h"
 
 #include "m_bbox.h"
-#include "m_swap.h"
+#include "i_swap.h"
 
 #include "v_video.h"
 
--- a/src/w_wad.c
+++ b/src/w_wad.c
@@ -33,7 +33,7 @@
 #include <string.h>
 
 #include "doomtype.h"
-#include "m_swap.h"
+#include "i_swap.h"
 #include "i_system.h"
 #include "i_video.h"
 #include "z_zone.h"
--- a/src/wi_stuff.c
+++ b/src/wi_stuff.c
@@ -30,9 +30,9 @@
 #include "z_zone.h"
 
 #include "m_random.h"
-#include "m_swap.h"
 
 #include "deh_main.h"
+#include "i_swap.h"
 #include "i_system.h"
 
 #include "w_wad.h"