all repos — mgba @ 72ef1643c7807e222b1c82018179c10670d668e0

mGBA Game Boy Advance Emulator

Rotate 16-bit without using AND
Jeffrey Pfau jeffrey@endrift.com
Sat, 26 Oct 2013 16:40:31 -0700
commit

72ef1643c7807e222b1c82018179c10670d668e0

parent

0155d9c02899cd3f3ee1ade3c556ac061a7b01c4

1 files changed, 2 insertions(+), 2 deletions(-)

jump to
M src/gba/gba-memory.csrc/gba/gba-memory.c

@@ -194,7 +194,7 @@ }

int16_t GBALoad16(struct ARMMemory* memory, uint32_t address, int* cycleCounter) { struct GBAMemory* gbaMemory = (struct GBAMemory*) memory; - int16_t value = 0; + uint16_t value = 0; int wait = 0; switch (address & ~OFFSET_MASK) {

@@ -260,7 +260,7 @@ *cycleCounter += 2 + wait;

} // Unaligned 16-bit loads are "unpredictable", but the GBA rotates them, so we have to, too. int rotate = (address & 1) << 3; - return (value >> rotate) | ((value << rotate) & 0xFF00); + return (value >> rotate) | (value << (16 - rotate)); } uint8_t GBALoadU8(struct ARMMemory* memory, uint32_t address, int* cycleCounter) {