summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/debug
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2021-08-16 14:04:29 -0400
committer AJR <ajrhacker@users.noreply.github.com>2021-08-16 14:05:22 -0400
commita77adf33c78b888f3d7ea9ac476f79c8717c7281 (patch)
tree1ebe37ef6390478a4935e9e35291fbed88a69cc2 /src/emu/debug
parentf0e85a6e54f8c049509c2d5d9e7652564456c4a2 (diff)
dvmemory: Substitute strongly typed enum for magic numbers specifying data format
Diffstat (limited to 'src/emu/debug')
-rw-r--r--src/emu/debug/dvmemory.cpp104
-rw-r--r--src/emu/debug/dvmemory.h29
2 files changed, 79 insertions, 54 deletions
diff --git a/src/emu/debug/dvmemory.cpp b/src/emu/debug/dvmemory.cpp
index 3ae8008f0a2..299e4c1e439 100644
--- a/src/emu/debug/dvmemory.cpp
+++ b/src/emu/debug/dvmemory.cpp
@@ -25,22 +25,21 @@
const debug_view_memory::memory_view_pos debug_view_memory::s_memory_pos_table[12] =
{
- /* 0 bytes per chunk: */ { 0, { 0 } },
- /* 1 byte per chunk: 00 11 22 33 44 55 66 77 */ { 3, { 0x04, 0x00, 0x80 } },
- /* 2 bytes per chunk: 0011 2233 4455 6677 */ { 6, { 0x8c, 0x0c, 0x08, 0x04, 0x00, 0x80 } },
- /* 3 bytes per chunk: */ { 0, { 0 } },
- /* 4 bytes per chunk: 00112233 44556677 */ { 12, { 0x9c, 0x9c, 0x1c, 0x18, 0x14, 0x10, 0x0c, 0x08, 0x04, 0x00, 0x80, 0x80 } },
- /* 5 bytes per chunk: */ { 0, { 0 } },
- /* 6 bytes per chunk: */ { 0, { 0 } },
- /* 7 bytes per chunk: */ { 0, { 0 } },
- /* 8 bytes per chunk: 0011223344556677 */ { 24, { 0xbc, 0xbc, 0xbc, 0xbc, 0x3c, 0x38, 0x34, 0x30, 0x2c, 0x28, 0x24, 0x20, 0x1c, 0x18, 0x14, 0x10, 0x0c, 0x08, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80 } },
- /* 32 bit floating point: */ { 16, { 0 } },
- /* 64 bit floating point: */ { 32, { 0 } },
- /* 80 bit floating point: */ { 32, { 0 } },
+ /* 0 bytes per chunk: */ { 0, 0, { 0 } },
+ /* 1 byte per chunk: 00 11 22 33 44 55 66 77 */ { 1, 3, { 0x04, 0x00, 0x80 } },
+ /* 2 bytes per chunk: 0011 2233 4455 6677 */ { 2, 6, { 0x8c, 0x0c, 0x08, 0x04, 0x00, 0x80 } },
+ /* 3 bytes per chunk: */ { 0, 0, { 0 } },
+ /* 4 bytes per chunk: 00112233 44556677 */ { 4, 12, { 0x9c, 0x9c, 0x1c, 0x18, 0x14, 0x10, 0x0c, 0x08, 0x04, 0x00, 0x80, 0x80 } },
+ /* 5 bytes per chunk: */ { 0, 0, { 0 } },
+ /* 6 bytes per chunk: */ { 0, 0, { 0 } },
+ /* 7 bytes per chunk: */ { 0, 0, { 0 } },
+ /* 8 bytes per chunk: 0011223344556677 */ { 8, 24, { 0xbc, 0xbc, 0xbc, 0xbc, 0x3c, 0x38, 0x34, 0x30, 0x2c, 0x28, 0x24, 0x20, 0x1c, 0x18, 0x14, 0x10, 0x0c, 0x08, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80 } },
+ /* 32 bit floating point: */ { 4, 16, { 0 } },
+ /* 64 bit floating point: */ { 8, 32, { 0 } },
+ /* 80 bit floating point: */ { 10, 32, { 0 } },
};
-
//**************************************************************************
// DEBUG VIEW MEMORY SOURCE
//**************************************************************************
@@ -107,7 +106,7 @@ debug_view_memory::debug_view_memory(running_machine &machine, debug_view_osd_up
m_chunks_per_row(16),
m_bytes_per_chunk(1),
m_steps_per_chunk(1),
- m_data_format(1),
+ m_data_format(data_format::HEX_8BIT),
m_reverse_view(false),
m_ascii_view(true),
m_no_translation(false),
@@ -214,7 +213,24 @@ void debug_view_memory::view_notify(debug_view_notification type)
m_bytes_per_chunk = source.m_prefsize;
if (m_bytes_per_chunk > 8)
m_bytes_per_chunk = 8;
- m_data_format = m_bytes_per_chunk;
+ switch (m_bytes_per_chunk)
+ {
+ case 1:
+ m_data_format = data_format::HEX_8BIT;
+ break;
+
+ case 2:
+ m_data_format = data_format::HEX_16BIT;
+ break;
+
+ case 4:
+ m_data_format = data_format::HEX_32BIT;
+ break;
+
+ case 8:
+ m_data_format = data_format::HEX_64BIT;
+ break;
+ }
m_steps_per_chunk = source.m_space ? source.m_space->byte_to_address(m_bytes_per_chunk) : m_bytes_per_chunk;
if (source.m_space != nullptr)
m_expression.set_context(&source.m_space->device().debug()->symtable());
@@ -264,7 +280,7 @@ static inline float u64_to_double(u64 value)
void debug_view_memory::generate_row(debug_view_char *destmin, debug_view_char *destmax, debug_view_char *destrow, offs_t address)
{
// get positional data
- const memory_view_pos &posdata = s_memory_pos_table[m_data_format];
+ const memory_view_pos &posdata = get_posdata(m_data_format);
int spacing = posdata.m_spacing;
// generate the address
@@ -277,7 +293,7 @@ void debug_view_memory::generate_row(debug_view_char *destmin, debug_view_char *
// generate the data and the ascii string
std::string chunkascii;
- if (m_data_format <= 8)
+ if (is_hex_format(m_data_format))
{
for (int chunknum = 0; chunknum < m_chunks_per_row; chunknum++)
{
@@ -310,7 +326,7 @@ void debug_view_memory::generate_row(debug_view_char *destmin, debug_view_char *
extFloat80_t chunkdata80 = { 0, 0 };
bool ismapped;
- if (m_data_format != 11)
+ if (m_data_format != data_format::FLOAT_80BIT)
ismapped = read(m_bytes_per_chunk, address + chunknum * m_steps_per_chunk, chunkdata);
else
ismapped = read(m_bytes_per_chunk, address + chunknum * m_steps_per_chunk, chunkdata80);
@@ -318,17 +334,21 @@ void debug_view_memory::generate_row(debug_view_char *destmin, debug_view_char *
if (ismapped)
switch (m_data_format)
{
- case 9:
+ case data_format::FLOAT_32BIT:
sprintf(valuetext, "%.8g", u32_to_float(u32(chunkdata)));
break;
- case 10:
+ case data_format::FLOAT_64BIT:
sprintf(valuetext, "%.24g", u64_to_double(chunkdata));
break;
- case 11:
+ case data_format::FLOAT_80BIT:
+ {
float64_t f64 = extF80M_to_f64(&chunkdata80);
sprintf(valuetext, "%.24g", u64_to_double(f64.v));
break;
}
+ default:
+ break;
+ }
else
{
valuetext[0] = '*';
@@ -621,10 +641,10 @@ void debug_view_memory::recompute()
// compute the section widths
m_section[0].m_width = 1 + 8 + 1;
- if (m_data_format <= 8)
+ if (is_hex_format(m_data_format))
m_section[1].m_width = 1 + 3 * m_bytes_per_row + 1;
else {
- const memory_view_pos &posdata = s_memory_pos_table[m_data_format];
+ const memory_view_pos &posdata = get_posdata(m_data_format);
m_section[1].m_width = 1 + posdata.m_spacing * m_chunks_per_row + 1;
}
@@ -693,11 +713,11 @@ debug_view_memory::cursor_pos debug_view_memory::get_cursor_pos(const debug_view
{
// start with the base address for this row
cursor_pos pos;
- const memory_view_pos &posdata = s_memory_pos_table[m_data_format];
+ const memory_view_pos &posdata = get_posdata(m_data_format);
pos.m_address = m_byte_offset + cursor.y * m_bytes_per_chunk * m_chunks_per_row;
// determine the X position within the middle section, clamping as necessary
- if (m_data_format <= 8) {
+ if (is_hex_format(m_data_format)) {
int xposition = cursor.x - m_section[1].m_pos - 1;
if (xposition < 0)
xposition = 0;
@@ -744,7 +764,7 @@ debug_view_memory::cursor_pos debug_view_memory::get_cursor_pos(const debug_view
void debug_view_memory::set_cursor_pos(cursor_pos pos)
{
- const memory_view_pos &posdata = s_memory_pos_table[m_data_format];
+ const memory_view_pos &posdata = get_posdata(m_data_format);
// offset the address by the byte offset
if (pos.m_address < m_byte_offset)
@@ -759,7 +779,7 @@ void debug_view_memory::set_cursor_pos(cursor_pos pos)
if (m_reverse_view)
chunknum = m_chunks_per_row - 1 - chunknum;
- if (m_data_format <= 8) {
+ if (is_hex_format(m_data_format)) {
// scan within the chunk to find the shift
for (m_cursor.x = 0; m_cursor.x < posdata.m_spacing; m_cursor.x++)
if (posdata.m_shift[m_cursor.x] == pos.m_shift)
@@ -968,12 +988,12 @@ void debug_view_memory::set_chunks_per_row(u32 rowchunks)
// are shown, 1-8 8-64 bits, 9 32bit floating point
//-------------------------------------------------
-void debug_view_memory::set_data_format(int format)
+void debug_view_memory::set_data_format(data_format format)
{
cursor_pos pos;
// should never be
- if ((format <= 0) || (format > 11))
+ if (!is_valid_format(format))
return;
// no need to change
if (format == m_data_format)
@@ -981,44 +1001,30 @@ void debug_view_memory::set_data_format(int format)
pos = begin_update_and_get_cursor_pos();
const debug_view_memory_source &source = downcast<const debug_view_memory_source &>(*m_source);
- if ((format <= 8) && (m_data_format <= 8)) {
-
+ if (is_hex_format(format) && is_hex_format(m_data_format)) {
pos.m_address += (pos.m_shift / 8) ^ ((source.m_endianness == ENDIANNESS_LITTLE) ? 0 : (m_bytes_per_chunk - 1));
pos.m_shift %= 8;
- m_bytes_per_chunk = format;
+ m_bytes_per_chunk = get_posdata(format).m_bytes;
m_steps_per_chunk = source.m_space ? source.m_space->byte_to_address(m_bytes_per_chunk) : m_bytes_per_chunk;
- m_chunks_per_row = m_bytes_per_row / format;
+ m_chunks_per_row = m_bytes_per_row / m_bytes_per_chunk;
if (m_chunks_per_row < 1)
m_chunks_per_row = 1;
pos.m_shift += 8 * ((pos.m_address % m_bytes_per_chunk) ^ ((source.m_endianness == ENDIANNESS_LITTLE) ? 0 : (m_bytes_per_chunk - 1)));
pos.m_address -= pos.m_address % m_bytes_per_chunk;
} else {
- if (format <= 8) {
+ if (is_hex_format(format)) {
m_supports_cursor = true;
m_edit_enabled = true;
-
- m_bytes_per_chunk = format;
}
else {
m_supports_cursor = false;
m_edit_enabled = false;
m_cursor_visible = false;
-
- switch (format)
- {
- case 9:
- m_bytes_per_chunk = 4;
- break;
- case 10:
- m_bytes_per_chunk = 8;
- break;
- case 11:
- m_bytes_per_chunk = 10;
- break;
- }
}
+
+ m_bytes_per_chunk = get_posdata(format).m_bytes;
m_chunks_per_row = m_bytes_per_row / m_bytes_per_chunk;
m_steps_per_chunk = source.m_space ? source.m_space->byte_to_address(m_bytes_per_chunk) : m_bytes_per_chunk;
pos.m_shift = 0;
diff --git a/src/emu/debug/dvmemory.h b/src/emu/debug/dvmemory.h
index 8aa5df7cbeb..da92ae43bf7 100644
--- a/src/emu/debug/dvmemory.h
+++ b/src/emu/debug/dvmemory.h
@@ -55,10 +55,24 @@ class debug_view_memory : public debug_view
// construction/destruction
debug_view_memory(running_machine &machine, debug_view_osd_update_func osdupdate, void *osdprivate);
+ struct memory_view_pos;
+
public:
+ enum class data_format
+ {
+ HEX_8BIT = 1,
+ HEX_16BIT = 2,
+ HEX_32BIT = 4,
+ HEX_64BIT = 8,
+ FLOAT_32BIT = 9,
+ FLOAT_64BIT = 10,
+ FLOAT_80BIT = 11
+ };
+ static bool is_valid_format(data_format format) { return int(format) >= 0 && int(format) < std::size(s_memory_pos_table) && get_posdata(format).m_bytes != 0; }
+
// getters
const char *expression() const { return m_expression.string(); }
- int get_data_format() { flush_updates(); return m_data_format; }
+ data_format get_data_format() { flush_updates(); return m_data_format; }
u32 chunks_per_row() { flush_updates(); return m_chunks_per_row; }
bool reverse() const { return m_reverse_view; }
bool ascii() const { return m_ascii_view; }
@@ -68,7 +82,7 @@ public:
// setters
void set_expression(const std::string &expression);
void set_chunks_per_row(u32 rowchunks);
- void set_data_format(int format); // 1-8 current values 9 32bit floating point
+ void set_data_format(data_format format);
void set_reverse(bool reverse);
void set_ascii(bool reverse);
void set_physical(bool physical);
@@ -88,6 +102,10 @@ private:
u8 m_shift;
};
+ // data format helpers
+ static bool is_hex_format(data_format format) { return int(format) <= 8; }
+ static const memory_view_pos &get_posdata(data_format format) { return s_memory_pos_table[int(format)]; }
+
// internal helpers
void enumerate_sources();
void recompute();
@@ -111,7 +129,7 @@ private:
u32 m_chunks_per_row; // number of chunks displayed per line
u8 m_bytes_per_chunk; // bytes per chunk
u8 m_steps_per_chunk; // bytes per chunk
- int m_data_format; // 1-8 current values 9 32bit floating point
+ data_format m_data_format; // 1-8 current values 9 32bit floating point
bool m_reverse_view; // reverse-endian view?
bool m_ascii_view; // display ASCII characters?
bool m_no_translation; // don't run addresses through the cpu translation hook
@@ -131,8 +149,9 @@ private:
struct memory_view_pos
{
- u8 m_spacing; /* spacing between each entry */
- u8 m_shift[24]; /* shift for each character */
+ u8 m_bytes; // bytes per entry
+ u8 m_spacing; // spacing between each entry
+ u8 m_shift[24]; // shift for each character
};
static const memory_view_pos s_memory_pos_table[12]; // table for rendering at different data formats