diff --git a/src/emu/cpu/drcfe.c b/src/emu/cpu/drcfe.c index aaa8ae50d1d..456a1dce401 100644 --- a/src/emu/cpu/drcfe.c +++ b/src/emu/cpu/drcfe.c @@ -148,11 +148,7 @@ drcfe_state *drcfe_init(const device_config *cpu, const drcfe_config *config, vo drcfe->program = memory_find_address_space(cpu, ADDRESS_SPACE_PROGRAM); drcfe->pageshift = cpu_get_page_shift(cpu, ADDRESS_SPACE_PROGRAM); drcfe->translate = (cpu_translate_func)device_get_info_fct(cpu, CPUINFO_FCT_TRANSLATE); -#ifdef LSB_FIRST - if (cpu_get_endianness(cpu) == ENDIANNESS_BIG) -#else - if (cpu_get_endianness(cpu) == ENDIANNESS_LITTLE) -#endif + if (cpu_get_endianness(cpu) != ENDIANNESS_NATIVE) drcfe->codexor = (cpu_get_databus_width(cpu, ADDRESS_SPACE_PROGRAM) / 8 / cpu_get_min_opcode_bytes(cpu) - 1) * cpu_get_min_opcode_bytes(cpu); return drcfe; diff --git a/src/emu/cpu/mips/mips3drc.c b/src/emu/cpu/mips/mips3drc.c index 00285a4ab70..e2872d73c6b 100644 --- a/src/emu/cpu/mips/mips3drc.c +++ b/src/emu/cpu/mips/mips3drc.c @@ -91,11 +91,7 @@ extern unsigned dasmmips3(char *buffer, unsigned pc, UINT32 op); MACROS ***************************************************************************/ -#ifdef LSB_FIRST -#define LOPTR(x) ((UINT32 *)(x)) -#else -#define LOPTR(x) ((UINT32 *)(x) + 1) -#endif +#define LOPTR(x) ((UINT32 *)(x) + NATIVE_ENDIAN_VALUE_LE_BE(0,1)) #define R32(reg) mips3->impstate->regmaplo[reg].type, mips3->impstate->regmaplo[reg].value #define LO32 R32(REG_LO) diff --git a/src/emu/cpu/z8000/z8000cpu.h b/src/emu/cpu/z8000/z8000cpu.h index fd63e4d8794..39e4c550987 100644 --- a/src/emu/cpu/z8000/z8000cpu.h +++ b/src/emu/cpu/z8000/z8000cpu.h @@ -49,17 +49,10 @@ * higher bit positions. * That's the reason for the ordering in the following pointer table. **************************************************************************/ -#ifdef LSB_FIRST -#define RB(n) regs.B[((((n) & 7) << 1) | (((n) & 8) >> 3)) ^ 7] -#define RW(n) regs.W[(n) ^ 3] -#define RL(n) regs.L[((n) >> 1) ^ 1] -#define RQ(n) regs.Q[((n) >> 2)] -#else -#define RB(n) regs.B[(((n) & 7) << 1) | (((n) & 8) >> 3)] -#define RW(n) regs.W[(n)] -#define RL(n) regs.L[((n) >> 1)] -#define RQ(n) regs.Q[((n) >> 2)] -#endif +#define RB(n) regs.B[BYTE8_XOR_BE((((n) & 7) << 1) | (((n) & 8) >> 3))] +#define RW(n) regs.W[BYTE4_XOR_BE(n)] +#define RL(n) regs.L[BYTE_XOR_BE((n) >> 1)] +#define RQ(n) regs.Q[(n) >> 2] /* the register used as stack pointer */ #define SP 15 diff --git a/src/emu/debug/debugvw.c b/src/emu/debug/debugvw.c index 8bf08eb023f..042c42d5404 100644 --- a/src/emu/debug/debugvw.c +++ b/src/emu/debug/debugvw.c @@ -2467,11 +2467,7 @@ static const memory_subview_item *memory_view_enumerate_subviews(running_machine subview->index = curindex++; subview->base = memory_region(machine, rgntag); subview->length = memory_region_length(machine, rgntag); -#ifdef LSB_FIRST - subview->offsetxor = width - 1; -#else - subview->offsetxor = 0; -#endif + subview->offsetxor = NATIVE_ENDIAN_VALUE_LE_BE(width - 1, 0); subview->endianness = little_endian ? ENDIANNESS_LITTLE : ENDIANNESS_BIG; subview->prefsize = MIN(width, 8); strcpy(subview->name, astring_c(tempstring)); @@ -2510,11 +2506,7 @@ static const memory_subview_item *memory_view_enumerate_subviews(running_machine subview->base = base; subview->length = valcount * valsize; subview->offsetxor = 0; -#ifdef LSB_FIRST - subview->endianness = ENDIANNESS_LITTLE; -#else - subview->endianness = ENDIANNESS_BIG; -#endif + subview->endianness = ENDIANNESS_NATIVE; subview->prefsize = MIN(valsize, 8); strcpy(subview->name, astring_c(tempstring)); diff --git a/src/emu/mamecore.h b/src/emu/mamecore.h index 347e84e8598..c05689a5921 100644 --- a/src/emu/mamecore.h +++ b/src/emu/mamecore.h @@ -138,15 +138,22 @@ typedef union #endif - /* Endianness constants */ enum { - ENDIANNESS_LITTLE = 0, /* emulated CPU is little endian */ - ENDIANNESS_BIG /* emulated CPU is big endian */ + ENDIANNESS_LITTLE = 0, + ENDIANNESS_BIG }; +/* Native endianness */ +#ifdef LSB_FIRST +#define ENDIANNESS_NATIVE ENDIANNESS_LITTLE +#else +#define ENDIANNESS_NATIVE ENDIANNESS_BIG +#endif + + /* orientation of bitmaps */ #define ORIENTATION_FLIP_X 0x0001 /* mirror everything in the X direction */ #define ORIENTATION_FLIP_Y 0x0002 /* mirror everything in the Y direction */ @@ -196,6 +203,15 @@ enum #define DEGREE_TO_RADIAN(x) ((M_PI / 180.0) * (x)) +/* endian-based value: first value is if 'endian' is little-endian, second is if 'endian' is big-endian */ +#define ENDIAN_VALUE_LE_BE(endian,leval,beval) (((endian) == ENDIANNESS_LITTLE) ? (leval) : (beval)) + +/* endian-based value: first value is if native endianness is little-endian, second is if native is big-endian */ +#define NATIVE_ENDIAN_VALUE_LE_BE(leval,beval) ((ENDIANNESS_NATIVE == ENDIANNESS_LITTLE) ? (leval) : (beval)) + +/* endian-based value: first value is if 'endian' matches native, second is if 'endian' doesn't match native */ +#define ENDIAN_VALUE_NE_NNE(endian,leval,beval) (((endian) == ENDIANNESS_NATIVE) ? (neval) : (nneval)) + /* Useful macros to deal with bit shuffling encryptions */ #define BIT(x,n) (((x)>>(n))&1) diff --git a/src/emu/memory.h b/src/emu/memory.h index fceb8e14a18..ebb079e83ac 100644 --- a/src/emu/memory.h +++ b/src/emu/memory.h @@ -582,37 +582,30 @@ union _addrmap64_token /* macros for accessing bytes and words within larger chunks */ -#ifdef LSB_FIRST -#define BYTE_XOR_BE(a) ((a) ^ 1) /* read/write a byte to a 16-bit space */ -#define BYTE_XOR_LE(a) (a) -#define BYTE4_XOR_BE(a) ((a) ^ 3) /* read/write a byte to a 32-bit space */ -#define BYTE4_XOR_LE(a) (a) -#define WORD_XOR_BE(a) ((a) ^ 2) /* read/write a word to a 32-bit space */ -#define WORD_XOR_LE(a) (a) -#define BYTE8_XOR_BE(a) ((a) ^ 7) /* read/write a byte to a 64-bit space */ -#define BYTE8_XOR_LE(a) (a) -#define WORD2_XOR_BE(a) ((a) ^ 6) /* read/write a word to a 64-bit space */ -#define WORD2_XOR_LE(a) (a) -#define DWORD_XOR_BE(a) ((a) ^ 4) /* read/write a dword to a 64-bit space */ -#define DWORD_XOR_LE(a) (a) +/* read/write a byte to a 16-bit space */ +#define BYTE_XOR_BE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(1,0)) +#define BYTE_XOR_LE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(0,1)) -#else +/* read/write a byte to a 32-bit space */ +#define BYTE4_XOR_BE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(3,0)) +#define BYTE4_XOR_LE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(0,3)) -#define BYTE_XOR_BE(a) (a) -#define BYTE_XOR_LE(a) ((a) ^ 1) /* read/write a byte to a 16-bit space */ -#define BYTE4_XOR_BE(a) (a) -#define BYTE4_XOR_LE(a) ((a) ^ 3) /* read/write a byte to a 32-bit space */ -#define WORD_XOR_BE(a) (a) -#define WORD_XOR_LE(a) ((a) ^ 2) /* read/write a word to a 32-bit space */ -#define BYTE8_XOR_BE(a) (a) -#define BYTE8_XOR_LE(a) ((a) ^ 7) /* read/write a byte to a 64-bit space */ -#define WORD2_XOR_BE(a) (a) -#define WORD2_XOR_LE(a) ((a) ^ 6) /* read/write a word to a 64-bit space */ -#define DWORD_XOR_BE(a) (a) -#define DWORD_XOR_LE(a) ((a) ^ 4) /* read/write a dword to a 64-bit space */ +/* read/write a word to a 32-bit space */ +#define WORD_XOR_BE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(2,0)) +#define WORD_XOR_LE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(0,2)) -#endif +/* read/write a byte to a 64-bit space */ +#define BYTE8_XOR_BE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(7,0)) +#define BYTE8_XOR_LE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(0,7)) + +/* read/write a word to a 64-bit space */ +#define WORD2_XOR_BE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(6,0)) +#define WORD2_XOR_LE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(0,6)) + +/* read/write a dword to a 64-bit space */ +#define DWORD_XOR_BE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(4,0)) +#define DWORD_XOR_LE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(0,4)) diff --git a/src/emu/romload.c b/src/emu/romload.c index b2d8f457f36..1e49104f1a1 100644 --- a/src/emu/romload.c +++ b/src/emu/romload.c @@ -613,12 +613,12 @@ static void region_post_process(rom_load_data *romdata, const char *rgntag) UINT32 regionlength = memory_region_length(romdata->machine, rgntag); UINT32 regionflags = memory_region_flags(romdata->machine, rgntag); UINT8 *regionbase = memory_region(romdata->machine, rgntag); - int littleendian = ((regionflags & ROMREGION_ENDIANMASK) == ROMREGION_LE); + int endianness = ((regionflags & ROMREGION_ENDIANMASK) == ROMREGION_LE) ? ENDIANNESS_LITTLE : ENDIANNESS_BIG; int datawidth = 1 << ((regionflags & ROMREGION_WIDTHMASK) >> 8); UINT8 *base; int i, j; - LOG(("+ datawidth=%d little=%d\n", datawidth, littleendian)); + LOG(("+ datawidth=%d little=%d\n", datawidth, endianness == ENDIANNESS_LITTLE)); /* if the region is inverted, do that now */ if (regionflags & ROMREGION_INVERTMASK) @@ -629,11 +629,7 @@ static void region_post_process(rom_load_data *romdata, const char *rgntag) } /* swap the endianness if we need to */ -#ifdef LSB_FIRST - if (datawidth > 1 && !littleendian) -#else - if (datawidth > 1 && littleendian) -#endif + if (datawidth > 1 && endianness != ENDIANNESS_NATIVE) { LOG(("+ Byte swapping region\n")); for (i = 0, base = regionbase; i < regionlength; i += datawidth) diff --git a/src/emu/sound/cdda.c b/src/emu/sound/cdda.c index 04ee0a9185a..a864af63af7 100644 --- a/src/emu/sound/cdda.c +++ b/src/emu/sound/cdda.c @@ -280,12 +280,13 @@ static void get_audio_data(cdda_info *info, stream_sample_t *bufL, stream_sample info->audio_length -= sectoread; /* CD-DA data on the disc is big-endian, flip if we're not */ - #ifdef LSB_FIRST - for( i = 0; i < info->audio_samples * 2; i++ ) + if (ENDIANNESS_NATIVE == ENDIANNESS_LITTLE) { - audio_cache[ i ] = BIG_ENDIANIZE_INT16( audio_cache[ i ] ); + for( i = 0; i < info->audio_samples * 2; i++ ) + { + audio_cache[ i ] = BIG_ENDIANIZE_INT16( audio_cache[ i ] ); + } } - #endif /* reset feedout ptr */ info->audio_bptr = 0; diff --git a/src/emu/sound/samples.c b/src/emu/sound/samples.c index 499f7351c51..16345de00ea 100644 --- a/src/emu/sound/samples.c +++ b/src/emu/sound/samples.c @@ -37,21 +37,13 @@ struct samples_info read_wav_sample - read a WAV file as a sample -------------------------------------------------*/ -#ifdef LSB_FIRST -#define intelLong(x) (x) -#else -#define intelLong(x) (((x << 24) | (((unsigned long) x) >> 24) | (( x & 0x0000ff00) << 8) | (( x & 0x00ff0000) >> 8))) -#endif - static int read_wav_sample(mame_file *f, struct loaded_sample *sample) { unsigned long offset = 0; UINT32 length, rate, filesize; UINT16 bits, temp16; char buf[32]; - #ifndef LSB_FIRST UINT32 sindex; - #endif /* read the core header and make sure it's a WAVE file */ offset += mame_fread(f, buf, 4); @@ -64,7 +56,7 @@ static int read_wav_sample(mame_file *f, struct loaded_sample *sample) offset += mame_fread(f, &filesize, 4); if (offset < 8) return 0; - filesize = intelLong(filesize); + filesize = LITTLE_ENDIANIZE_INT32(filesize); /* read the RIFF file type and make sure it's a WAVE file */ offset += mame_fread(f, buf, 4); @@ -78,7 +70,7 @@ static int read_wav_sample(mame_file *f, struct loaded_sample *sample) { offset += mame_fread(f, buf, 4); offset += mame_fread(f, &length, 4); - length = intelLong(length); + length = LITTLE_ENDIANIZE_INT32(length); if (memcmp(&buf[0], "fmt ", 4) == 0) break; @@ -103,7 +95,7 @@ static int read_wav_sample(mame_file *f, struct loaded_sample *sample) /* sample rate */ offset += mame_fread(f, &rate, 4); - rate = intelLong(rate); + rate = LITTLE_ENDIANIZE_INT32(rate); /* bytes/second and block alignment are ignored */ offset += mame_fread(f, buf, 6); @@ -123,7 +115,7 @@ static int read_wav_sample(mame_file *f, struct loaded_sample *sample) { offset += mame_fread(f, buf, 4); offset += mame_fread(f, &length, 4); - length = intelLong(length); + length = LITTLE_ENDIANIZE_INT32(length); if (memcmp(&buf[0], "data", 4) == 0) break; @@ -162,10 +154,9 @@ static int read_wav_sample(mame_file *f, struct loaded_sample *sample) sample->data = auto_malloc(sizeof(*sample->data) * (length/2)); mame_fread(f, sample->data, length); sample->length /= 2; -#ifndef LSB_FIRST - for (sindex = 0; sindex < sample->length; sindex++) - sample->data[sindex] = LITTLE_ENDIANIZE_INT16(sample->data[sindex]); -#endif + if (ENDIANNESS_NATIVE != ENDIANNESS_LITTLE) + for (sindex = 0; sindex < sample->length; sindex++) + sample->data[sindex] = LITTLE_ENDIANIZE_INT16(sample->data[sindex]); } return 1; } diff --git a/src/emu/sound/wavwrite.c b/src/emu/sound/wavwrite.c index 47fa9a8a02b..91de42ef3fc 100644 --- a/src/emu/sound/wavwrite.c +++ b/src/emu/sound/wavwrite.c @@ -8,13 +8,6 @@ struct _wav_file UINT32 data_offs; }; -#ifdef LSB_FIRST -#define intel_long(x) (x) -#define intel_short(x) (x) -#else -#define intel_long(x) (((x << 24) | (((unsigned long) x) >> 24) | (( x & 0x0000ff00) << 8) | (( x & 0x00ff0000) >> 8))) -#define intel_short(x) (((x) << 8) | ((x) >> 8)) -#endif wav_file *wav_open(const char *filename, int sample_rate, int channels) { @@ -50,33 +43,33 @@ wav_file *wav_open(const char *filename, int sample_rate, int channels) fwrite("fmt ", 1, 4, wav->file); /* write the format length */ - temp32 = intel_long(16); + temp32 = LITTLE_ENDIANIZE_INT32(16); fwrite(&temp32, 1, 4, wav->file); /* write the format (PCM) */ - temp16 = intel_short(1); + temp16 = LITTLE_ENDIANIZE_INT16(1); fwrite(&temp16, 1, 2, wav->file); /* write the channels */ - temp16 = intel_short(channels); + temp16 = LITTLE_ENDIANIZE_INT16(channels); fwrite(&temp16, 1, 2, wav->file); /* write the sample rate */ - temp32 = intel_long(sample_rate); + temp32 = LITTLE_ENDIANIZE_INT32(sample_rate); fwrite(&temp32, 1, 4, wav->file); /* write the bytes/second */ bps = sample_rate * 2 * channels; - temp32 = intel_long(bps); + temp32 = LITTLE_ENDIANIZE_INT32(bps); fwrite(&temp32, 1, 4, wav->file); /* write the block align */ align = 2 * channels; - temp16 = intel_short(align); + temp16 = LITTLE_ENDIANIZE_INT16(align); fwrite(&temp16, 1, 2, wav->file); /* write the bits/sample */ - temp16 = intel_short(16); + temp16 = LITTLE_ENDIANIZE_INT16(16); fwrite(&temp16, 1, 2, wav->file); /* write the 'data' tag */ @@ -101,13 +94,13 @@ void wav_close(wav_file *wav) /* update the total file size */ fseek(wav->file, wav->total_offs, SEEK_SET); temp32 = total - (wav->total_offs + 4); - temp32 = intel_long(temp32); + temp32 = LITTLE_ENDIANIZE_INT32(temp32); fwrite(&temp32, 1, 4, wav->file); /* update the data size */ fseek(wav->file, wav->data_offs, SEEK_SET); temp32 = total - (wav->data_offs + 4); - temp32 = intel_long(temp32); + temp32 = LITTLE_ENDIANIZE_INT32(temp32); fwrite(&temp32, 1, 4, wav->file); fclose(wav->file); diff --git a/src/emu/state.c b/src/emu/state.c index e9454d5fa77..1bd237f9e3a 100644 --- a/src/emu/state.c +++ b/src/emu/state.c @@ -569,11 +569,7 @@ state_save_error state_save_write_file(running_machine *machine, mame_file *file /* generate the header */ memcpy(&header[0], ss_magic_num, 8); header[8] = SAVE_VERSION; -#ifdef LSB_FIRST - header[9] = 0; -#else - header[9] = SS_MSB_FIRST; -#endif + header[9] = NATIVE_ENDIAN_VALUE_LE_BE(0, SS_MSB_FIRST); strncpy((char *)&header[0x0a], machine->gamedrv->name, 0x1c - 0x0a); *(UINT32 *)&header[0x1c] = LITTLE_ENDIANIZE_INT32(signature); @@ -629,11 +625,7 @@ state_save_error state_save_read_file(running_machine *machine, mame_file *file) return STATERR_INVALID_HEADER; /* determine whether or not to flip the data when done */ -#ifdef LSB_FIRST - flip = ((header[9] & SS_MSB_FIRST) != 0); -#else - flip = ((header[9] & SS_MSB_FIRST) == 0); -#endif + flip = NATIVE_ENDIAN_VALUE_LE_BE((header[9] & SS_MSB_FIRST) != 0, (header[9] & SS_MSB_FIRST) == 0); /* read all the data, flipping if necessary */ for (entry = global->entrylist; entry != NULL; entry = entry->next) diff --git a/src/mame/drivers/cps3.c b/src/mame/drivers/cps3.c index 28e93b71aaf..f2cc95b5d72 100644 --- a/src/mame/drivers/cps3.c +++ b/src/mame/drivers/cps3.c @@ -330,11 +330,7 @@ Notes: #define LOAD_CD_CONTENT 1 #define DEBUG_PRINTF 0 -#ifdef LSB_FIRST - #define DMA_XOR(a) ((a) ^ 1) -#else - #define DMA_XOR(a) ((a) ^ 2) -#endif +#define DMA_XOR(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(1,2)) static UINT32* decrypted_bios; diff --git a/src/mame/drivers/genesis.c b/src/mame/drivers/genesis.c index 8fa7010b52e..954196956b4 100644 --- a/src/mame/drivers/genesis.c +++ b/src/mame/drivers/genesis.c @@ -501,13 +501,6 @@ ADDRESS_MAP_END /* Z80 Sound Hardware - based on MESS code, to be improved, it can do some strange things */ -#ifdef LSB_FIRST - #define BYTE_XOR(a) ((a) ^ 1) -#else - #define BYTE_XOR(a) (a) -#endif - - static WRITE8_HANDLER ( genesis_bank_select_w ) /* note value will be meaningless unless all bits are correctly set in */ { @@ -613,9 +606,9 @@ READ8_HANDLER ( genesis_z80_bank_r ) logerror("z80 read from address %x\n", address); /* Read the data out of the 68k ROM */ - if (base != NULL && address < 0x400000) return base[BYTE_XOR(address)]; + if (base != NULL && address < 0x400000) return base[BYTE_XOR_BE(address)]; /* else read the data out of the 68k RAM */ -// else if (address > 0xff0000) return genesis_68k_ram[BYTE_XOR(offset)]; +// else if (address > 0xff0000) return genesis_68k_ram[BYTE_XOR_BE(offset)]; return -1; } diff --git a/src/mame/drivers/nemesis.c b/src/mame/drivers/nemesis.c index 497cbafbe8e..b93a335ec4b 100644 --- a/src/mame/drivers/nemesis.c +++ b/src/mame/drivers/nemesis.c @@ -1909,11 +1909,7 @@ INPUT_PORTS_END /******************************************************************************/ -#ifdef LSB_FIRST -#define XOR(x) ((x)^8) -#else -#define XOR(x) (x) -#endif +#define XOR(x) ((x)^NATIVE_ENDIAN_VALUE_LE_BE(8,0)) static const gfx_layout charlayout = { diff --git a/src/mame/includes/cvs.h b/src/mame/includes/cvs.h index 1a3b3356d7b..9315f7926e5 100644 --- a/src/mame/includes/cvs.h +++ b/src/mame/includes/cvs.h @@ -15,7 +15,6 @@ extern UINT8 *cvs_color_ram; extern UINT8 *cvs_video_ram; extern UINT8 *cvs_bullet_ram; extern UINT8 *cvs_palette_ram; -extern UINT8 *cvs_character_ram; extern UINT8 *cvs_s2636_0_ram; extern UINT8 *cvs_s2636_1_ram; extern UINT8 *cvs_s2636_2_ram; diff --git a/src/mame/machine/decocrpt.c b/src/mame/machine/decocrpt.c index 2368cfc37ce..248cbcd2ac5 100644 --- a/src/mame/machine/decocrpt.c +++ b/src/mame/machine/decocrpt.c @@ -605,13 +605,10 @@ static void deco_decrypt(running_machine *machine,const char *rgntag,const UINT8 UINT16 *buffer = malloc_or_die(len*2); int i; -#ifdef LSB_FIRST /* we work on 16-bit words but data is loaded as 8-bit, so swap bytes on LSB machines */ - for (i = 0;i < len;i++) - { - rom[i] = (rom[i] >> 8) | (rom[i] << 8); - } -#endif + if (ENDIANNESS_NATIVE == ENDIANNESS_LITTLE) + for (i = 0;i < len;i++) + rom[i] = BIG_ENDIANIZE_INT16(rom[i]); memcpy(buffer,rom,len*2); @@ -644,13 +641,10 @@ static void deco_decrypt(running_machine *machine,const char *rgntag,const UINT8 free(buffer); -#ifdef LSB_FIRST /* we work on 16-bit words but data is loaded as 8-bit, so swap bytes on LSB machines */ - for (i = 0;i < len;i++) - { - rom[i] = (rom[i] >> 8) | (rom[i] << 8); - } -#endif + if (ENDIANNESS_NATIVE == ENDIANNESS_LITTLE) + for (i = 0;i < len;i++) + rom[i] = BIG_ENDIANIZE_INT16(rom[i]); } void deco56_decrypt_gfx(running_machine *machine, const char *tag) diff --git a/src/mame/machine/n64.c b/src/mame/machine/n64.c index 7ca0909ad06..89b9701a91b 100644 --- a/src/mame/machine/n64.c +++ b/src/mame/machine/n64.c @@ -7,14 +7,6 @@ #include "includes/n64.h" #include "sound/dmadac.h" -#ifdef LSB_FIRST - #define BYTE_ADDR_XOR 3 - #define WORD_ADDR_XOR 1 -#else - #define BYTE_ADDR_XOR 0 - #define WORD_ADDR_XOR 0 -#endif - UINT32 *rdram; UINT32 *rsp_imem; UINT32 *rsp_dmem; diff --git a/src/mame/video/atari.c b/src/mame/video/atari.c index 5ad7ea3af4c..6fdff8b0fcb 100644 --- a/src/mame/video/atari.c +++ b/src/mame/video/atari.c @@ -10,12 +10,6 @@ #include "includes/atari.h" #include "video/gtia.h" -#ifdef LSB_FIRST -#define BYTE_XOR(n) (n) -#else -#define BYTE_XOR(n) ((n)^1) -#endif - #define VERBOSE 0 #define LOG(x) do { if (VERBOSE) logerror x; } while (0) @@ -990,16 +984,16 @@ static void antic_linerefresh(running_machine *machine) if ( (antic.cmd & ANTIC_HSCR) == 0 || (antic.pfwidth == 48) || (antic.pfwidth == 32)) { /* no hscroll */ - dst[3] = antic.color_lookup[src[BYTE_XOR(0)]] | antic.color_lookup[src[BYTE_XOR(1)]] << 16; + dst[3] = antic.color_lookup[src[BYTE_XOR_LE(0)]] | antic.color_lookup[src[BYTE_XOR_LE(1)]] << 16; src += 2; dst += 4; for( x = 1; x < HCHARS-1; x++ ) { - *dst++ = antic.color_lookup[src[BYTE_XOR(0)]] | antic.color_lookup[src[BYTE_XOR(1)]] << 16; - *dst++ = antic.color_lookup[src[BYTE_XOR(2)]] | antic.color_lookup[src[BYTE_XOR(3)]] << 16; + *dst++ = antic.color_lookup[src[BYTE_XOR_LE(0)]] | antic.color_lookup[src[BYTE_XOR_LE(1)]] << 16; + *dst++ = antic.color_lookup[src[BYTE_XOR_LE(2)]] | antic.color_lookup[src[BYTE_XOR_LE(3)]] << 16; src += 4; } - dst[0] = antic.color_lookup[src[BYTE_XOR(0)]] | antic.color_lookup[src[BYTE_XOR(1)]] << 16; + dst[0] = antic.color_lookup[src[BYTE_XOR_LE(0)]] | antic.color_lookup[src[BYTE_XOR_LE(1)]] << 16; } else { @@ -1032,9 +1026,9 @@ static void antic_linerefresh(running_machine *machine) } else { - *dst++ = antic.color_lookup[src[BYTE_XOR(0)]] | antic.color_lookup[src[BYTE_XOR(1)]] << 16; + *dst++ = antic.color_lookup[src[BYTE_XOR_LE(0)]] | antic.color_lookup[src[BYTE_XOR_LE(1)]] << 16; } - *dst++ = antic.color_lookup[src[BYTE_XOR(2)]] | antic.color_lookup[src[BYTE_XOR(3)]] << 16; + *dst++ = antic.color_lookup[src[BYTE_XOR_LE(2)]] | antic.color_lookup[src[BYTE_XOR_LE(3)]] << 16; src += 4; } for ( ; x < HCHARS-1; x++ ) diff --git a/src/mame/video/genesis.c b/src/mame/video/genesis.c index c67f24a12a2..584f459b0a7 100644 --- a/src/mame/video/genesis.c +++ b/src/mame/video/genesis.c @@ -36,11 +36,7 @@ static const device_config *genesis_screen; #define VDP_VRAM_WORD(x) ((VDP_VRAM_BYTE(x) << 8) | VDP_VRAM_BYTE((x) + 1)) #define VDP_VSRAM_WORD(x) ((VDP_VSRAM_BYTE(x) << 8) | VDP_VSRAM_BYTE((x) + 1)) -#ifdef LSB_FIRST -#define EXTRACT_PIXEL(x,i) (((x) >> (((i) ^ 1) * 4)) & 0x0f) -#else -#define EXTRACT_PIXEL(x,i) (((x) >> (((i) ^ 7) * 4)) & 0x0f) -#endif +#define EXTRACT_PIXEL(x,i) (((x) >> (((i) ^ NATIVE_ENDIAN_VALUE_LE_BE(1,7)) * 4)) & 0x0f) diff --git a/src/mame/video/harddriv.c b/src/mame/video/harddriv.c index bca6b7e75de..1e98a2f55ed 100644 --- a/src/mame/video/harddriv.c +++ b/src/mame/video/harddriv.c @@ -18,11 +18,8 @@ #define DISPLAY_SPEEDUPS 0 -#ifdef LSB_FIRST -#define MASK(n) (0x000000ffUL << ((n) * 8)) -#else -#define MASK(n) (0xff000000UL >> (((n) ^ 1) * 8)) -#endif +#define MASK(n) NATIVE_ENDIAN_VALUE_LE_BE(0x000000ffUL << ((n) * 8), 0xff000000UL >> (((n) ^ 1) * 8)) + /************************************* diff --git a/src/mame/video/namcona1.c b/src/mame/video/namcona1.c index 04bd2b39dd9..301285c04b6 100644 --- a/src/mame/video/namcona1.c +++ b/src/mame/video/namcona1.c @@ -35,10 +35,8 @@ static void tilemap_get_info( int tilemap_color, int use_4bpp_gfx ) { -#ifdef LSB_FIRST UINT16 *source; static UINT8 mask_data[8]; -#endif int data = tilemap_videoram[tile_index]; int tile = data&0xfff; @@ -62,20 +60,21 @@ static void tilemap_get_info( else { SET_TILE_INFO( gfx,tile,tilemap_color,0 ); -#ifdef LSB_FIRST - source = shaperam+4*tile; - mask_data[0] = source[0]>>8; - mask_data[1] = source[0]&0xff; - mask_data[2] = source[1]>>8; - mask_data[3] = source[1]&0xff; - mask_data[4] = source[2]>>8; - mask_data[5] = source[2]&0xff; - mask_data[6] = source[3]>>8; - mask_data[7] = source[3]&0xff; - tileinfo->mask_data = mask_data; -#else - tileinfo->mask_data = (UINT8 *)(shaperam+4*tile); -#endif + if (ENDIANNESS_NATIVE == ENDIANNESS_BIG) + tileinfo->mask_data = (UINT8 *)(shaperam+4*tile); + else + { + source = shaperam+4*tile; + mask_data[0] = source[0]>>8; + mask_data[1] = source[0]&0xff; + mask_data[2] = source[1]>>8; + mask_data[3] = source[1]&0xff; + mask_data[4] = source[2]>>8; + mask_data[5] = source[2]&0xff; + mask_data[6] = source[3]>>8; + mask_data[7] = source[3]&0xff; + tileinfo->mask_data = mask_data; + } } } /* tilemap_get_info */ @@ -105,21 +104,22 @@ static TILE_GET_INFO( roz_get_info ) } else { -#ifdef LSB_FIRST - UINT16 *source; - static UINT8 mask_data[8]; - source = shaperam+4*tile; - mask_data[0] = source[0]>>8; - mask_data[1] = source[0]&0xff; - mask_data[2] = source[1]>>8; - mask_data[3] = source[1]&0xff; - mask_data[4] = source[2]>>8; - mask_data[5] = source[2]&0xff; - mask_data[6] = source[3]>>8; - mask_data[7] = source[3]&0xff; -#else UINT8 *mask_data = (UINT8 *)(shaperam+4*tile); -#endif + + if (ENDIANNESS_NATIVE == ENDIANNESS_LITTLE) + { + UINT16 *source = (UINT16 *)mask_data; + static UINT8 conv_data[9]; + conv_data[0] = source[0]>>8; + conv_data[1] = source[0]&0xff; + conv_data[2] = source[1]>>8; + conv_data[3] = source[1]&0xff; + conv_data[4] = source[2]>>8; + conv_data[5] = source[2]&0xff; + conv_data[6] = source[3]>>8; + conv_data[7] = source[3]&0xff; + mask_data = conv_data; + } SET_TILE_INFO( gfx,tile,tilemap_color,0 ); tileinfo->mask_data = mask_data; } diff --git a/src/mame/video/namcos22.c b/src/mame/video/namcos22.c index b0cd3093e50..4e19a913c85 100644 --- a/src/mame/video/namcos22.c +++ b/src/mame/video/namcos22.c @@ -612,11 +612,7 @@ ApplyGamma( running_machine *machine, bitmap_t *bitmap ) int x,y; if( mbSuperSystem22 ) { /* super system 22 */ -#ifdef LSB_FIRST -#define XORPAT 0x3 -#else -#define XORPAT 0x0 -#endif +#define XORPAT NATIVE_ENDIAN_VALUE_LE_BE(3,0) const UINT8 *rlut = (const UINT8 *)&namcos22_gamma[0x100/4]; const UINT8 *glut = (const UINT8 *)&namcos22_gamma[0x200/4]; const UINT8 *blut = (const UINT8 *)&namcos22_gamma[0x300/4]; diff --git a/src/mame/video/segas32.c b/src/mame/video/segas32.c index 315d3924394..405486b05b9 100644 --- a/src/mame/video/segas32.c +++ b/src/mame/video/segas32.c @@ -189,11 +189,7 @@ * *************************************/ -#ifdef LSB_FIRST -#define SWAP_HALVES(x) (x) -#else -#define SWAP_HALVES(x) (((x) >> 16) | ((x) << 16)) -#endif +#define SWAP_HALVES(x) NATIVE_ENDIAN_VALUE_LE_BE(x, ((x) >> 16) | ((x) << 16)) diff --git a/src/mame/video/taito_f3.c b/src/mame/video/taito_f3.c index 4be4402e95f..2b2da8aa973 100644 --- a/src/mame/video/taito_f3.c +++ b/src/mame/video/taito_f3.c @@ -937,15 +937,9 @@ INLINE void f3_alpha_set_level(void) /*============================================================================*/ -#ifdef LSB_FIRST -#define COLOR1 0 -#define COLOR2 1 -#define COLOR3 2 -#else -#define COLOR1 3 -#define COLOR2 2 -#define COLOR3 1 -#endif +#define COLOR1 BYTE4_XOR_LE(0) +#define COLOR2 BYTE4_XOR_LE(1) +#define COLOR3 BYTE4_XOR_LE(2)