summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/memory.h
diff options
context:
space:
mode:
author Alex W. Jackson <alex.w.jackson@gmail.com>2014-11-17 17:03:54 -0500
committer Alex W. Jackson <alex.w.jackson@gmail.com>2014-11-17 17:03:54 -0500
commitd68a3a45b3dfc13f92096c0b7d58a49a2ef75f68 (patch)
tree056e3d80e0d9c2b018909468a7ace963e231e707 /src/emu/memory.h
parenta6d9826322d00e9f55c02d6ee378c0f9bbbf5aed (diff)
Touching all the candy again: [Alex Jackson]
Fixed an annoying inconsistency between memory_share and memory_region: the width() method of the former returned the width in bits (8, 16, 32 or 64) while the width() method of the latter returned the width in bytes (1, 2, 4 or 8). Now both classes have a bitwidth() method and a bytewidth() method. Updated all callers to use whichever one was more appropriate. Removed the implicit-cast-to-any-integer-pointer ability of memory_regions, which was rather unsafe (if you weren't careful with your * operators and casts it was easy to accidentally get a pointer to the memory_region object itself instead of to the data, with no warning from the compiler... or at least I kept doing it) Updated all devices and drivers that were accessing regions that way to use a region_ptr_finder when possible, and otherwise to call base() explicitly.
Diffstat (limited to 'src/emu/memory.h')
-rw-r--r--src/emu/memory.h30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/emu/memory.h b/src/emu/memory.h
index 765c00bd086..b433baa541a 100644
--- a/src/emu/memory.h
+++ b/src/emu/memory.h
@@ -646,15 +646,18 @@ public:
: m_next(NULL),
m_ptr(ptr),
m_bytes(bytes),
- m_width(width),
- m_endianness(endianness) { }
+ m_endianness(endianness),
+ m_bitwidth(width),
+ m_bytewidth(width <= 8 ? 1 : width <= 16 ? 2 : width <= 32 ? 4 : 8)
+ { }
// getters
memory_share *next() const { return m_next; }
void *ptr() const { if (this == NULL) return NULL; return m_ptr; }
size_t bytes() const { return m_bytes; }
- UINT8 width() const { return m_width; }
endianness_t endianness() const { return m_endianness; }
+ UINT8 bitwidth() const { return m_bitwidth; }
+ UINT8 bytewidth() const { return m_bytewidth; }
// setters
void set_ptr(void *ptr) { m_ptr = ptr; }
@@ -664,8 +667,10 @@ private:
memory_share * m_next; // next share in the list
void * m_ptr; // pointer to the memory backing the region
size_t m_bytes; // size of the shared region in bytes
- UINT8 m_width; // width of the shared region
endianness_t m_endianness; // endianness of the memory
+ UINT8 m_bitwidth; // width of the shared region in bits
+ UINT8 m_bytewidth; // width in bytes, rounded up to a power of 2
+
};
@@ -694,7 +699,8 @@ public:
// flag expansion
endianness_t endianness() const { return m_endianness; }
- UINT8 width() const { return m_width; }
+ UINT8 bitwidth() const { return m_bitwidth; }
+ UINT8 bytewidth() const { return m_bytewidth; }
// data access
UINT8 &u8(offs_t offset = 0) { return m_buffer[offset]; }
@@ -702,25 +708,15 @@ public:
UINT32 &u32(offs_t offset = 0) { return reinterpret_cast<UINT32 *>(base())[offset]; }
UINT64 &u64(offs_t offset = 0) { return reinterpret_cast<UINT64 *>(base())[offset]; }
- // allow passing a region for any common pointer
- operator void *() { return (this != NULL) ? reinterpret_cast<void *>(base()) : NULL; }
- operator INT8 *() { return (this != NULL) ? reinterpret_cast<INT8 *>(base()) : NULL; }
- operator UINT8 *() { return (this != NULL) ? reinterpret_cast<UINT8 *>(base()) : NULL; }
- operator INT16 *() { return (this != NULL) ? reinterpret_cast<INT16 *>(base()) : NULL; }
- operator UINT16 *() { return (this != NULL) ? reinterpret_cast<UINT16 *>(base()) : NULL; }
- operator INT32 *() { return (this != NULL) ? reinterpret_cast<INT32 *>(base()) : NULL; }
- operator UINT32 *() { return (this != NULL) ? reinterpret_cast<UINT32 *>(base()) : NULL; }
- operator INT64 *() { return (this != NULL) ? reinterpret_cast<INT64 *>(base()) : NULL; }
- operator UINT64 *() { return (this != NULL) ? reinterpret_cast<UINT64 *>(base()) : NULL; }
-
private:
// internal data
running_machine & m_machine;
memory_region * m_next;
astring m_name;
dynamic_buffer m_buffer;
- UINT8 m_width;
endianness_t m_endianness;
+ UINT8 m_bitwidth;
+ UINT8 m_bytewidth;
};