From 3d948cabf270dad85bbfa6e398caa193cc0b479b Mon Sep 17 00:00:00 2001 From: ekeeke Date: Tue, 14 Jul 2026 00:06:46 +0200 Subject: [PATCH] [Core/CPU] fixed 16-bit reads/writes access address mask (fixes potential undefined memory access in case of out of bound reads/writes with address error emulation disabled) --- core/m68k/m68kcpu.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/m68k/m68kcpu.h b/core/m68k/m68kcpu.h index b702173a..3bf06e83 100644 --- a/core/m68k/m68kcpu.h +++ b/core/m68k/m68kcpu.h @@ -526,7 +526,7 @@ /* ----------------------------- Read / Write ----------------------------- */ /* Read data immediately following the PC */ -#define m68k_read_immediate_16(address) *(uint16 *)(m68ki_cpu.memory_map[((address)>>16)&0xff].base + ((address) & 0xffff)) +#define m68k_read_immediate_16(address) *(uint16 *)(m68ki_cpu.memory_map[((address)>>16)&0xff].base + ((address) & 0xfffe)) #define m68k_read_immediate_32(address) (m68k_read_immediate_16(address) << 16) | (m68k_read_immediate_16(address+2)) /* Read data relative to the PC */ @@ -879,7 +879,7 @@ INLINE uint m68ki_read_16(uint address) temp = &m68ki_cpu.memory_map[((address)>>16)&0xff]; if (temp->read16) val = (*temp->read16)(ADDRESS_68K(address)); - else val = *(uint16 *)(temp->base + ((address) & 0xffff)); + else val = *(uint16 *)(temp->base + ((address) & 0xfffe)); #ifdef HOOK_CPU if (UNLIKELY(cpu_hook)) @@ -899,11 +899,11 @@ INLINE uint m68ki_read_32(uint address) temp = &m68ki_cpu.memory_map[((address)>>16)&0xff]; if (temp->read16) val = (*temp->read16)(ADDRESS_68K(address)) << 16; - else val = m68k_read_immediate_16(address) << 16; + else val = *(uint16 *)(temp->base + ((address) & 0xfffe)) << 16; temp = &m68ki_cpu.memory_map[((address+2)>>16)&0xff]; if (temp->read16) val |= (*temp->read16)(ADDRESS_68K(address+2)); - else val |= m68k_read_immediate_16(address+2); + else val |= *(uint16 *)(temp->base + ((address+2) & 0xfffe)); #ifdef HOOK_CPU if (UNLIKELY(cpu_hook)) @@ -943,7 +943,7 @@ INLINE void m68ki_write_16(uint address, uint value) temp = &m68ki_cpu.memory_map[((address)>>16)&0xff]; if (temp->write16) (*temp->write16)(ADDRESS_68K(address),value); - else *(uint16 *)(temp->base + ((address) & 0xffff)) = value; + else *(uint16 *)(temp->base + ((address) & 0xfffe)) = value; } INLINE void m68ki_write_32(uint address, uint value) @@ -960,11 +960,11 @@ INLINE void m68ki_write_32(uint address, uint value) temp = &m68ki_cpu.memory_map[((address)>>16)&0xff]; if (temp->write16) (*temp->write16)(ADDRESS_68K(address),value>>16); - else *(uint16 *)(temp->base + ((address) & 0xffff)) = value >> 16; + else *(uint16 *)(temp->base + ((address) & 0xfffe)) = value >> 16; temp = &m68ki_cpu.memory_map[((address + 2)>>16)&0xff]; if (temp->write16) (*temp->write16)(ADDRESS_68K(address+2),value&0xffff); - else *(uint16 *)(temp->base + ((address + 2) & 0xffff)) = value; + else *(uint16 *)(temp->base + ((address + 2) & 0xfffe)) = value; }