From 729fc31c4a78644962920e7462107e505db2dac9 Mon Sep 17 00:00:00 2001 From: AJR Date: Sun, 22 May 2022 20:51:09 -0400 Subject: dvmemory.cpp: Small refactoring; verify that data written to memory spaces read back as the same values --- src/emu/debug/dvmemory.cpp | 47 ++++++++++++++++++++++++++++++++++++---------- src/emu/debug/dvmemory.h | 1 + 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/emu/debug/dvmemory.cpp b/src/emu/debug/dvmemory.cpp index 4831023d479..1f1adcb138d 100644 --- a/src/emu/debug/dvmemory.cpp +++ b/src/emu/debug/dvmemory.cpp @@ -540,16 +540,8 @@ void debug_view_memory::view_char(int chval) if (hexchar == nullptr || (m_shift_bits == 3 && chval >= '8')) break; - const debug_view_memory_source &source = downcast(*m_source); - offs_t address = (source.m_space != nullptr) ? source.m_space->byte_to_address(pos.m_address) : pos.m_address; - u64 data; - bool ismapped = read(m_bytes_per_chunk, address, data); - if (!ismapped) - break; - - data &= ~(util::make_bitmask(m_shift_bits) << pos.m_shift); - data |= u64(hexchar - hexvals) << pos.m_shift; - write(m_bytes_per_chunk, address, data); + if (!write_digit(pos.m_address, pos.m_shift, hexchar - hexvals)) + break; // TODO: alert OSD? } // fall through to the right-arrow press [[fallthrough]]; @@ -997,6 +989,41 @@ void debug_view_memory::write(u8 size, offs_t offs, u64 data) } +//------------------------------------------------- +// write_digit - write one hex or octal digit +// at the given address and bit position +//------------------------------------------------- + +bool debug_view_memory::write_digit(offs_t offs, u8 pos, u8 digit) +{ + const debug_view_memory_source &source = downcast(*m_source); + offs_t address = (source.m_space != nullptr) ? source.m_space->byte_to_address(offs) : offs; + u64 data; + bool ismapped = read(m_bytes_per_chunk, address, data); + if (!ismapped) + return false; + + // clamp to chunk size + if (m_bytes_per_chunk * 8 < pos + m_shift_bits) + { + assert(m_bytes_per_chunk * 8 > pos); + digit &= util::make_bitmask(m_bytes_per_chunk * 8 - pos); + } + + u64 write_data = (data & ~(util::make_bitmask(m_shift_bits) << pos)) | (u64(digit) << pos); + write(m_bytes_per_chunk, address, write_data); + + // verify that data reads back as it was written + if (source.m_space != nullptr) + { + read(m_bytes_per_chunk, address, data); + return data == write_data; + } + else + return true; +} + + //------------------------------------------------- // set_expression - set the expression string // describing the home address diff --git a/src/emu/debug/dvmemory.h b/src/emu/debug/dvmemory.h index f2c738a6ff4..6f1ffab4e9e 100644 --- a/src/emu/debug/dvmemory.h +++ b/src/emu/debug/dvmemory.h @@ -127,6 +127,7 @@ private: // memory access bool read(u8 size, offs_t offs, u64 &data); void write(u8 size, offs_t offs, u64 data); + bool write_digit(offs_t offs, u8 pos, u8 digit); bool read(u8 size, offs_t offs, extFloat80_t &data); bool read_chunk(offs_t address, int chunknum, u64 &chunkdata); void generate_row(debug_view_char *destmin, debug_view_char *destmax, debug_view_char *destrow, offs_t address); -- cgit v1.2.3