Fix vram 16/32 bit unaligned reads(backport 7f18771165)

This commit is contained in:
negativeExponent 2020-08-11 20:29:28 +08:00
parent f4891b6504
commit c07d5b658b
1 changed files with 18 additions and 17 deletions

View File

@ -103,16 +103,17 @@ static inline uint32_t CPUReadMemory(uint32_t address)
case 5: case 5:
value = READ32LE(((uint32_t*)&paletteRAM[address & 0x3fC])); value = READ32LE(((uint32_t*)&paletteRAM[address & 0x3fC]));
break; break;
case 6: case 6: {
address = (address & 0x1fffc); unsigned addr = (address & 0x1fffc);
if (((DISPCNT & 7) > 2) && ((address & 0x1C000) == 0x18000)) { if (((DISPCNT & 7) > 2) && ((addr & 0x1C000) == 0x18000)) {
value = 0; value = 0;
break; break;
} }
if ((address & 0x18000) == 0x18000) if ((addr & 0x18000) == 0x18000)
address &= 0x17fff; addr &= 0x17fff;
value = READ32LE(((uint32_t*)&vram[address])); value = READ32LE(((uint32_t*)&vram[addr]));
break; break;
}
case 7: case 7:
value = READ32LE(((uint32_t*)&oam[address & 0x3FC])); value = READ32LE(((uint32_t*)&oam[address & 0x3FC]));
break; break;
@ -253,16 +254,17 @@ static inline uint32_t CPUReadHalfWord(uint32_t address)
case 5: case 5:
value = READ16LE(((uint16_t*)&paletteRAM[address & 0x3fe])); value = READ16LE(((uint16_t*)&paletteRAM[address & 0x3fe]));
break; break;
case 6: case 6: {
address = (address & 0x1fffe); unsigned addr = (address & 0x1fffe);
if (((DISPCNT & 7) > 2) && ((address & 0x1C000) == 0x18000)) { if (((DISPCNT & 7) > 2) && ((addr & 0x1C000) == 0x18000)) {
value = 0; value = 0;
break; break;
} }
if ((address & 0x18000) == 0x18000) if ((addr & 0x18000) == 0x18000)
address &= 0x17fff; addr &= 0x17fff;
value = READ16LE(((uint16_t*)&vram[address])); value = READ16LE(((uint16_t*)&vram[addr]));
break; break;
}
case 7: case 7:
value = READ16LE(((uint16_t*)&oam[address & 0x3fe])); value = READ16LE(((uint16_t*)&oam[address & 0x3fe]));
break; break;
@ -293,11 +295,10 @@ static inline uint32_t CPUReadHalfWord(uint32_t address)
if (cpuDmaHack) { if (cpuDmaHack) {
value = cpuDmaLast & 0xFFFF; value = cpuDmaLast & 0xFFFF;
} else { } else {
if (armState) { int param = reg[15].I;
value = CPUReadHalfWordQuick(reg[15].I + (address & 2)); if (armState)
} else { param += (address & 2)
value = CPUReadHalfWordQuick(reg[15].I); value = CPUReadHalfWordQuick(param);
}
} }
#ifdef GBA_LOGGING #ifdef GBA_LOGGING
if (systemVerbose & VERBOSE_ILLEGAL_READ) { if (systemVerbose & VERBOSE_ILLEGAL_READ) {