From 092aef477b77120ed9d464ec4a9463ef24a8642a Mon Sep 17 00:00:00 2001 From: tigital Date: Fri, 11 Jun 2004 02:07:39 +0000 Subject: [PATCH] byte-swapping changes for bigendian systems --- src/parse/encrypt.cpp | 9 +++++++ src/pcxutils/pcxutils.cpp | 55 +++++++++++++++++++++++++++++++++++++++ src/sound/ds.cpp | 42 ++++++++++++++++++++++-------- src/starfield/nebula.cpp | 12 +++++++++ 4 files changed, 107 insertions(+), 11 deletions(-) diff --git a/src/parse/encrypt.cpp b/src/parse/encrypt.cpp index b1be834..e2daeef 100644 --- a/src/parse/encrypt.cpp +++ b/src/parse/encrypt.cpp @@ -15,6 +15,9 @@ * Module for encryption code common to FreeSpace and related tools * * $Log$ + * Revision 1.5 2004/06/11 02:04:35 tigital + * byte-swapping changes for bigendian systems + * * Revision 1.4 2003/05/25 02:30:43 taylor * Freespace 1 support * @@ -71,9 +74,15 @@ #include "pstypes.h" #include "encrypt.h" +#if SDL_BYTEORDER != SDL_BIG_ENDIAN const uint Encrypt_new_signature = 0x5c331a55; // new encrpytion const uint Encrypt_signature = 0xdeadbeef; // full encryption const uint Encrypt_signature_8bit = 0xcacacaca; // light encryption - doesn't use 7bit chars +#else +const uint Encrypt_new_signature = 0x551a335c; // new encrpytion +const uint Encrypt_signature = 0xefbeadde; // full encryption +const uint Encrypt_signature_8bit = 0xcacacaca; // light encryption - doesn't use 7bit chars +#endif int Encrypt_inited = 0; diff --git a/src/pcxutils/pcxutils.cpp b/src/pcxutils/pcxutils.cpp index 3bd28f8..cc2c4d6 100644 --- a/src/pcxutils/pcxutils.cpp +++ b/src/pcxutils/pcxutils.cpp @@ -15,6 +15,9 @@ * code to deal with pcx files * * $Log$ + * Revision 1.4 2004/06/11 02:05:16 tigital + * byte-swapping changes for bigendian systems + * * Revision 1.3 2002/06/09 04:41:25 relnev * added copyright header * @@ -146,6 +149,21 @@ int pcx_read_header(char *real_filename, int *w, int *h, ubyte *pal ) cfclose( PCXfile ); return PCX_ERROR_NO_HEADER; } + header.Xmin = INTEL_SHORT( header.Xmin ); + header.Ymin = INTEL_SHORT( header.Ymin ); + header.Xmax = INTEL_SHORT( header.Xmax ); + header.Ymax = INTEL_SHORT( header.Ymax ); + header.Hdpi = INTEL_SHORT( header.Hdpi ); + header.Vdpi = INTEL_SHORT( header.Vdpi ); + for ( int i=0; i<16; i++ ){ + for ( int j=0; j<3; j++){ + header.ColorMap[i][j] = INTEL_INT( header.ColorMap[i][j] ); + } + } + header.BytesPerLine = INTEL_SHORT( header.BytesPerLine ); + for ( int i=0; i<60; i++ ){ + header.filler[i] = INTEL_INT( header.filler[i] ); + } // Is it a 256 color PCX file? if ((header.Manufacturer != 10)||(header.Encoding != 1)||(header.Nplanes != 1)||(header.BitsPerPixel != 8)||(header.Version != 5)) { @@ -195,6 +213,14 @@ int pcx_read_bitmap_8bpp( char * real_filename, ubyte *org_data, ubyte *palette cfclose( PCXfile ); return PCX_ERROR_NO_HEADER; } + header.Xmin = INTEL_SHORT( header.Xmin ); + header.Ymin = INTEL_SHORT( header.Ymin ); + header.Xmax = INTEL_SHORT( header.Xmax ); + header.Ymax = INTEL_SHORT( header.Ymax ); + header.Hdpi = INTEL_SHORT( header.Hdpi ); + header.Vdpi = INTEL_SHORT( header.Vdpi ); + + header.BytesPerLine = INTEL_SHORT( header.BytesPerLine ); // Is it a 256 color PCX file? if ((header.Manufacturer != 10)||(header.Encoding != 1)||(header.Nplanes != 1)||(header.BitsPerPixel != 8)||(header.Version != 5)) { @@ -211,6 +237,10 @@ int pcx_read_bitmap_8bpp( char * real_filename, ubyte *org_data, ubyte *palette cfseek( PCXfile, -768, CF_SEEK_END ); cfread( palette, 3, 256, PCXfile ); + + for ( int i=0; i<256; i++ ){ //tigital + palette[i] = INTEL_INT( palette[i] ); + } cfseek( PCXfile, sizeof(PCXHeader), CF_SEEK_SET ); buffer_size = 1024; @@ -283,6 +313,15 @@ int pcx_read_bitmap_16bpp( char * real_filename, ubyte *org_data ) return PCX_ERROR_NO_HEADER; } + header.Xmin = INTEL_SHORT( header.Xmin ); + header.Ymin = INTEL_SHORT( header.Ymin ); + header.Xmax = INTEL_SHORT( header.Xmax ); + header.Ymax = INTEL_SHORT( header.Ymax ); + header.Hdpi = INTEL_SHORT( header.Hdpi ); + header.Vdpi = INTEL_SHORT( header.Vdpi ); + + header.BytesPerLine = INTEL_SHORT( header.BytesPerLine ); + // Is it a 256 color PCX file? if ((header.Manufacturer != 10)||(header.Encoding != 1)||(header.Nplanes != 1)||(header.BitsPerPixel != 8)||(header.Version != 5)) { cfclose( PCXfile ); @@ -393,6 +432,15 @@ int pcx_read_bitmap_16bpp_aabitmap( char * real_filename, ubyte *org_data ) return PCX_ERROR_NO_HEADER; } + header.Xmin = INTEL_SHORT( header.Xmin ); + header.Ymin = INTEL_SHORT( header.Ymin ); + header.Xmax = INTEL_SHORT( header.Xmax ); + header.Ymax = INTEL_SHORT( header.Ymax ); + header.Hdpi = INTEL_SHORT( header.Hdpi ); + header.Vdpi = INTEL_SHORT( header.Vdpi ); + + header.BytesPerLine = INTEL_SHORT( header.BytesPerLine ); + // Is it a 256 color PCX file? if ((header.Manufacturer != 10)||(header.Encoding != 1)||(header.Nplanes != 1)||(header.BitsPerPixel != 8)||(header.Version != 5)) { cfclose( PCXfile ); @@ -486,6 +534,13 @@ int pcx_read_bitmap_16bpp_nondark( char * real_filename, ubyte *org_data ) cfclose( PCXfile ); return PCX_ERROR_NO_HEADER; } + header.Xmin = INTEL_SHORT( header.Xmin ); + header.Ymin = INTEL_SHORT( header.Ymin ); + header.Xmax = INTEL_SHORT( header.Xmax ); + header.Ymax = INTEL_SHORT( header.Ymax ); + header.Hdpi = INTEL_SHORT( header.Hdpi ); + header.Vdpi = INTEL_SHORT( header.Vdpi ); + header.BytesPerLine = INTEL_SHORT( header.BytesPerLine ); // Is it a 256 color PCX file? if ((header.Manufacturer != 10)||(header.Encoding != 1)||(header.Nplanes != 1)||(header.BitsPerPixel != 8)||(header.Version != 5)) { diff --git a/src/sound/ds.cpp b/src/sound/ds.cpp index 17b0b5f..4a93bf9 100644 --- a/src/sound/ds.cpp +++ b/src/sound/ds.cpp @@ -15,6 +15,9 @@ * C file for interface to DirectSound * * $Log$ + * Revision 1.18 2004/06/11 02:07:01 tigital + * byte-swapping changes for bigendian systems + * * Revision 1.17 2003/12/02 03:24:47 taylor * MS-ADPCM support, fix file parser with OSX support * @@ -383,11 +386,18 @@ #include #include #else +#ifdef __APPLE__ +#include +#include +#include +#include +#else #include #include #include #include #endif +#endif #ifndef PLAT_UNIX // Pointers to functions contained in DSOUND.dll @@ -713,9 +723,11 @@ int ds_parse_wave(char *filename, ubyte **dest, uint *dest_size, WAVEFORMATEX ** while(1) { if ( cfread( &tag, sizeof(uint), 1, fp ) != 1 ) break; + tag = INTEL_INT( tag ); if ( cfread( &size, sizeof(uint), 1, fp ) != 1 ) break; + size = INTEL_INT( size ); next_chunk = cftell(fp) + size; @@ -831,12 +843,12 @@ int ds_get_hid() // // // parameters: -// sid => pointer to software id for sound ( output parm) -// hid => pointer to hardware id for sound ( output parm) -// final_size => pointer to storage to receive uncompressed sound size (output parm) +// sid => pointer to software id for sound ( output parm) +// hid => pointer to hardware id for sound ( output parm) +// final_size => pointer to storage to receive uncompressed sound size (output parm) // header => pointer to a WAVEFORMATEX structure -// si => sound_info structure, contains details on the sound format -// flags => buffer properties ( DS_HARDWARE , DS_3D ) +// si => sound_info structure, contains details on the sound format +// flags => buffer properties ( DS_HARDWARE , DS_3D ) // // returns: -1 => sound effect could not loaded into a secondary buffer // 0 => sound effect successfully loaded into a secondary buffer @@ -886,6 +898,15 @@ int ds_load_buffer(int *sid, int *hid, int *final_size, void *header, sound_info bits = si->bits; bps = si->avg_bytes_per_sec; size = si->size; + + if(bits == 16){ + ushort *swap_tmp; + for (uint i=0; idata+i); + *swap_tmp = INTEL_SHORT(*swap_tmp); + } + } data = si->data; break; case WAVE_FORMAT_ADPCM: @@ -948,7 +969,6 @@ int ds_load_buffer(int *sid, int *hid, int *final_size, void *header, sound_info sound_buffers[*sid].nseconds = size / bps; sound_buffers[*sid].nbytes = size; - OpenAL_ErrorCheck(); if ( convert_buffer ) @@ -956,7 +976,7 @@ int ds_load_buffer(int *sid, int *hid, int *final_size, void *header, sound_info return 0; -#else +#else // !PLAT_UNIX Assert( final_size != NULL ); Assert( header != NULL ); Assert( si != NULL ); @@ -1439,7 +1459,7 @@ int ds_init(int use_a3d, int use_eax) { #ifdef PLAT_UNIX // NOTE: A3D and EAX are unused in OpenAL - const ALubyte *initStr = (const ALubyte *)"\'( (sampling-rate 22050 ))"; + ALCubyte *initStr = (ubyte *)"\'( (sampling-rate 22050 ))"; int attr[] = { ALC_FREQUENCY, 22050, ALC_SYNC, AL_FALSE, 0 }; Ds_use_a3d = 0; @@ -2504,7 +2524,7 @@ int ds_play_easy(int sid, int volume) int ds_play(int sid, int hid, int snd_id, int priority, int volume, int pan, int looping, bool is_voice_msg) { #ifdef PLAT_UNIX - int channel; + int channel; if (!ds_initialized) return -1; @@ -2597,7 +2617,7 @@ int ds_play(int sid, int hid, int snd_id, int priority, int volume, int pan, int DWORD current_position = ds_get_play_position(i); if (current_position != 0) { - if (current_position < Channels[i].last_position) { + if (current_position < (DWORD)Channels[i].last_position) { ds_stop_channel(i); } else { Channels[i].last_position = current_position; @@ -3763,7 +3783,7 @@ void ds_do_frame() DWORD current_position = ds_get_play_position(i); if (current_position != 0) { - if (current_position < cp->last_position) { + if (current_position < (DWORD)cp->last_position) { #ifdef PLAT_UNIX ds_stop_channel(i); #else diff --git a/src/starfield/nebula.cpp b/src/starfield/nebula.cpp index 05bc3ca..68f8ce1 100644 --- a/src/starfield/nebula.cpp +++ b/src/starfield/nebula.cpp @@ -15,6 +15,9 @@ * Code to load & display nebulas * * $Log$ + * Revision 1.8 2004/06/11 02:07:39 tigital + * byte-swapping changes for bigendian systems + * * Revision 1.7 2003/05/25 02:30:44 taylor * Freespace 1 support * @@ -230,6 +233,7 @@ int load_nebula_sub(char *filename) return 0; } cfread( &version, sizeof(int), 1, fp ); + version = INTEL_INT(version); major = version / 100; minor = version % 100; @@ -239,8 +243,10 @@ int load_nebula_sub(char *filename) } cfread( &num_pts, sizeof(int), 1, fp ); + num_pts = INTEL_INT(num_pts); Assert( num_pts < MAX_POINTS ); cfread( &num_tris, sizeof(int), 1, fp ); + num_tris = INTEL_INT(num_tris); Assert( num_tris < MAX_TRIS ); for (int i=0; i