diff --git a/core/bitops.h b/core/bitops.h index a4c34d0..0025017 100644 --- a/core/bitops.h +++ b/core/bitops.h @@ -88,4 +88,9 @@ inline void set_bit(T &val, const int bit_num) { val |= ((T)1 << bit_num); } +static inline uint32_t extract_with_wrap_around(uint32_t val, int pos, int size) { + return (uint32_t)((((uint64_t)val << 32) | val) >> ((8 - (pos & 3) - size) << 3)) & + ((1LL << (size << 3)) - 1); +} + #endif // BIT_OPS_H diff --git a/devices/memctrl/platinum.cpp b/devices/memctrl/platinum.cpp index 24d3379..3eb1484 100644 --- a/devices/memctrl/platinum.cpp +++ b/devices/memctrl/platinum.cpp @@ -101,6 +101,8 @@ int PlatinumCtrl::device_postinit() { } uint32_t PlatinumCtrl::read(uint32_t rgn_start, uint32_t offset, int size) { + uint32_t value; + if (rgn_start == VRAM_REGION_BASE) { if (offset < this->vram_size) { // HACK: half bank configurations should return invalid data @@ -117,8 +119,6 @@ uint32_t PlatinumCtrl::read(uint32_t rgn_start, uint32_t offset, int size) { } } - uint32_t value; - switch (offset >> 4) { case PlatinumReg::CPU_ID: value = this->cpu_id; @@ -195,9 +195,10 @@ uint32_t PlatinumCtrl::read(uint32_t rgn_start, uint32_t offset, int size) { value = 0; } - uint32_t result = (uint32_t)( (((uint64_t)value << 32) | value) >> ((8 - (offset & 3) - size) << 3)) & ( (1LL << (size << 3)) - 1 ); - - return result; + if (size == 4) + return value; + else + return extract_with_wrap_around(value, offset, size); } void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)