/*
ENDIANAC.h
Copyright (C) 2006 Bernd Schmidt, Paul C. Pratt
You can redistribute this file and/or modify it under the terms
of version 2 of the GNU General Public License as published by
the Free Software Foundation. You should have received a copy
of the license along with this file; see the file COPYING.
This file 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
license for more details.
*//*
ENDIAN ACcess
Deals with endian issues in memory access.
This code is adapted from code in the Un*x Amiga Emulator by
Bernd Schmidt, as found in vMac by Philip Cummins.
*/#ifdef ENDIANAC_H#ifndef AllFiles#error "header already included"#endif#else#define ENDIANAC_H#endif#define do_get_mem_byte(a) ((ui3r)*((ui3b *)(a)))#if BigEndianUnaligned#define do_get_mem_word(a) ((ui4r)*((ui4b *)(a)))#elseLOCALINLINEFUNCui4rdo_get_mem_word(ui3pa){#if LittleEndianUnalignedui4bb=(*((ui4b*)(a)));return((b&0x00FF)<<8)|((b>>8)&0x00FF);#elsereturn(((ui4r)*a)<<8)|((ui4r)*(a+1));#endif}#endif#if BigEndianUnaligned#define do_get_mem_long(a) ((ui5r)*((ui5b *)(a)))#elif HaveMySwapUi5r && LittleEndianUnaligned#define do_get_mem_long(a) (MySwapUi5r((ui5r)*((ui5b *)(a))))#elseLOCALINLINEFUNCui5rdo_get_mem_long(ui3pa){#if LittleEndianUnaligned#if 0 ui5b b = (*((ui5b *)(a)));
return ((b & 0x000000FF) << 24)
| ((b & 0x0000FF00) << 8)
| ((b & 0x00FF0000) >> 8)
| ((b & 0xFF000000) >> 24);
#endif
#if 0 ui5b b = (*((ui5b *)(a)));
return ((b << 24) & 0xFF000000)
| ((b << 8) & 0x00FF0000)
| ((b >> 8) & 0x0000FF00)
| ((b >> 24) & 0x000000FF);
/*
no, this doesn't do well with apple tools,
instead try combining two 16 bit swaps.
*/
#endif
ui5bb=(*((ui5b*)(a)));ui4bb1=b;ui4bb2=b>>16;ui4bc1=((b1&0x00FF)<<8)|((b1>>8)&0x00FF);ui4bc2=((b2&0x00FF)<<8)|((b2>>8)&0x00FF);return(((ui5r)c1)<<16)|((ui5r)c2);/*
better, though still doesn't use BSWAP
instruction with apple tools for intel.
*/#elsereturn(((ui5r)*a)<<24)|(((ui5r)*(a+1))<<16)|(((ui5r)*(a+2))<<8)|((ui5r)*(a+3));#endif}#endif#define do_put_mem_byte(a, v) ((*((ui3b *)(a))) = (v))#if BigEndianUnaligned#define do_put_mem_word(a, v) ((*((ui4b *)(a))) = (v))#elseLOCALINLINEFUNCvoiddo_put_mem_word(ui3pa,ui4rv){#if LittleEndianUnalignedui4bb=((v&0x00FF)<<8)|((v>>8)&0x00FF);*(ui4b*)a=b;#else*a=v>>8;*(a+1)=v;#endif}#endif#if BigEndianUnaligned#define do_put_mem_long(a, v) ((*((ui5b *)(a))) = (v))#elif HaveMySwapUi5r && LittleEndianUnaligned#define do_put_mem_long(a, v) ((*((ui5b *)(a))) = MySwapUi5r(v))#elseLOCALINLINEFUNCvoiddo_put_mem_long(ui3pa,ui5rv){#if LittleEndianUnalignedui4bb1=v;ui4bb2=v>>16;ui4bc1=((b1&0x00FF)<<8)|((b1>>8)&0x00FF);ui4bc2=((b2&0x00FF)<<8)|((b2>>8)&0x00FF);*(ui5b*)a=(c1<<16)|c2;#else*a=v>>24;*(a+1)=v>>16;*(a+2)=v>>8;*(a+3)=v;#endif}#endif