Use separate variable, bitwise op does not guarantee evaluation order

(#316)
This commit is contained in:
OV2 2018-05-31 12:39:45 +02:00
parent d7ff305c96
commit f9a659d951
1 changed files with 8 additions and 7 deletions

View File

@ -345,35 +345,36 @@ inline uint8 S9xGetByte (uint32 Address)
inline uint16 S9xGetWord (uint32 Address, enum s9xwrap_t w = WRAP_NONE) inline uint16 S9xGetWord (uint32 Address, enum s9xwrap_t w = WRAP_NONE)
{ {
uint16 word;
uint32 mask = MEMMAP_MASK & (w == WRAP_PAGE ? 0xff : (w == WRAP_BANK ? 0xffff : 0xffffff)); uint32 mask = MEMMAP_MASK & (w == WRAP_PAGE ? 0xff : (w == WRAP_BANK ? 0xffff : 0xffffff));
if ((Address & mask) == mask) if ((Address & mask) == mask)
{ {
PC_t a; PC_t a;
OpenBus = S9xGetByte(Address); word = OpenBus = S9xGetByte(Address);
switch (w) switch (w)
{ {
case WRAP_PAGE: case WRAP_PAGE:
a.xPBPC = Address; a.xPBPC = Address;
a.B.xPCl++; a.B.xPCl++;
return (OpenBus | (S9xGetByte(a.xPBPC) << 8)); return (word | (S9xGetByte(a.xPBPC) << 8));
case WRAP_BANK: case WRAP_BANK:
a.xPBPC = Address; a.xPBPC = Address;
a.W.xPC++; a.W.xPC++;
return (OpenBus | (S9xGetByte(a.xPBPC) << 8)); return (word | (S9xGetByte(a.xPBPC) << 8));
case WRAP_NONE: case WRAP_NONE:
default: default:
return (OpenBus | (S9xGetByte(Address + 1) << 8)); return (word | (S9xGetByte(Address + 1) << 8));
} }
} }
int block = (Address & 0xffffff) >> MEMMAP_SHIFT; int block = (Address & 0xffffff) >> MEMMAP_SHIFT;
uint8 *GetAddress = Memory.Map[block]; uint8 *GetAddress = Memory.Map[block];
int32 speed = memory_speed(Address); int32 speed = memory_speed(Address);
uint16 word;
if (GetAddress >= (uint8 *) CMemory::MAP_LAST) if (GetAddress >= (uint8 *) CMemory::MAP_LAST)
{ {
@ -394,8 +395,8 @@ inline uint16 S9xGetWord (uint32 Address, enum s9xwrap_t w = WRAP_NONE)
case CMemory::MAP_PPU: case CMemory::MAP_PPU:
if (CPU.InDMAorHDMA) if (CPU.InDMAorHDMA)
{ {
OpenBus = S9xGetByte(Address); word = OpenBus = S9xGetByte(Address);
return (OpenBus | (S9xGetByte(Address + 1) << 8)); return (word | (S9xGetByte(Address + 1) << 8));
} }
word = S9xGetPPU(Address & 0xffff); word = S9xGetPPU(Address & 0xffff);