dvmemory.cpp: Small refactoring; verify that data written to memory spaces read back as the same values

This commit is contained in:
AJR 2022-05-22 20:51:09 -04:00
parent 1939fc2ffe
commit 729fc31c4a
2 changed files with 38 additions and 10 deletions

View File

@ -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<const debug_view_memory_source &>(*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<u64>(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<const debug_view_memory_source &>(*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<u8>(m_bytes_per_chunk * 8 - pos);
}
u64 write_data = (data & ~(util::make_bitmask<u64>(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

View File

@ -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);