From f3b69dac21827a81f843dc767fb8b5979cb5feda Mon Sep 17 00:00:00 2001 From: AJR Date: Sun, 16 Feb 2020 00:17:37 -0500 Subject: upd78k3: Include IRAM in program space; clean up code using shared pointer finder and helpers (nw) --- src/devices/cpu/upd78k/upd78k3.cpp | 83 +++++++++++++++++++++----------------- src/devices/cpu/upd78k/upd78k3.h | 5 +++ 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/src/devices/cpu/upd78k/upd78k3.cpp b/src/devices/cpu/upd78k/upd78k3.cpp index 473d8a9fb9c..c22fd2ee674 100644 --- a/src/devices/cpu/upd78k/upd78k3.cpp +++ b/src/devices/cpu/upd78k/upd78k3.cpp @@ -30,6 +30,7 @@ upd78k3_device::upd78k3_device(const machine_config &mconfig, device_type type, , m_sfr_config("SFR", ENDIANNESS_LITTLE, 16, 8, 0, sfr_map) , m_program_space(nullptr) , m_program_cache(nullptr) + , m_iram(*this, "iram") , m_iram_cache(nullptr) , m_sfr_space(nullptr) , m_pc(0) @@ -51,6 +52,32 @@ void upd78k3_device::iram_map(address_map &map) } +//------------------------------------------------- +// iram_byte_r - read one byte from IRAM +//------------------------------------------------- + +u8 upd78k3_device::iram_byte_r(offs_t offset) +{ + if (BIT(offset, 0)) + return (m_iram[offset >> 1] & 0xff00) >> 8; + else + return m_iram[offset >> 1] & 0x00ff; +} + + +//------------------------------------------------- +// iram_byte_w - write one byte to IRAM +//------------------------------------------------- + +void upd78k3_device::iram_byte_w(offs_t offset, u8 data) +{ + if (BIT(offset, 0)) + m_iram[offset >> 1] = (m_iram[offset >> 1] & 0x00ff) | u16(data) << 8; + else + m_iram[offset >> 1] = (m_iram[offset >> 1] & 0xff00) | data; +} + + //------------------------------------------------- // memory_space_config - return a vector of // address space configurations for this device @@ -121,42 +148,41 @@ void upd78k3_device::device_start() [this](u8 data) { m_psw = (m_psw & 0x8fff) | u16(data) << 12; } ).mask(7).noshow(); state_add(UPD78K3_SP, "SP", m_sp); - void *iram = memshare("iram")->ptr(); for (int n = 0; n < 4; n++) state_add(UPD78K3_RP0 + n, string_format("RP%d", n).c_str(), - [this, iram, n]() { return static_cast(iram)[register_base() >> 1 | n]; }, - [this, iram, n](u16 data) { static_cast(iram)[register_base() >> 1 | n] = data; } + [this, n]() { return m_iram[register_base() >> 1 | n]; }, + [this, n](u16 data) { m_iram[register_base() >> 1 | n] = data; } ).formatstr("%9s"); for (int n = 0; n < 2; n++) state_add(UPD78K3_AX + n, std::array{{"AX", "BC"}}[n], - [this, iram, n]() { return static_cast(iram)[register_base() >> 1 | (m_psw & 0x0020) >> 4 | n]; }, - [this, iram, n](u16 data) { static_cast(iram)[register_base() >> 1 | (m_psw & 0x0020) >> 4 | n] = data; } + [this, n]() { return m_iram[register_base() >> 1 | (m_psw & 0x0020) >> 4 | n]; }, + [this, n](u16 data) { m_iram[register_base() >> 1 | (m_psw & 0x0020) >> 4 | n] = data; } ).noshow(); for (int n = 0; n < 4; n++) { state_add(UPD78K3_VP + n, std::array{{"VP", "UP", "DE", "HL"}}[n], - [this, iram, n]() { return static_cast(iram)[register_base() >> 1 | 0x04 | n]; }, - [this, iram, n](u16 data) { static_cast(iram)[register_base() >> 1 | 0x04 | n] = data; } + [this, n]() { return m_iram[register_base() >> 1 | 0x04 | n]; }, + [this, n](u16 data) { m_iram[register_base() >> 1 | 0x04 | n] = data; } ); state_add(UPD78K3_RP4 + n, string_format("RP%d", 4 + n).c_str(), - [this, iram, n]() { return static_cast(iram)[register_base() >> 1 | 0x04 | n]; }, - [this, iram, n](u16 data) { static_cast(iram)[register_base() >> 1 | 0x04 | n] = data; } + [this, n]() { return m_iram[register_base() >> 1 | 0x04 | n]; }, + [this, n](u16 data) { m_iram[register_base() >> 1 | 0x04 | n] = data; } ).noshow(); } for (int n = 0; n < 16; n++) state_add(UPD78K3_R0 + n, string_format("R%d", n).c_str(), - [this, iram, n]() { return static_cast(iram)[BYTE_XOR_LE(register_base() | n)]; }, - [this, iram, n](u8 data) { static_cast(iram)[BYTE_XOR_LE(register_base() | n)] = data; } + [this, n]() { return iram_byte_r(register_base() | n); }, + [this, n](u8 data) { iram_byte_w(register_base() | n, data); } ).noshow(); for (int n = 0; n < 4; n++) state_add(UPD78K3_X + n, std::array{{"X", "A", "C", "B"}}[n], - [this, iram, n]() { return static_cast(iram)[BYTE_XOR_LE(register_base() | (m_psw & 0x0020) >> 3 | n)]; }, - [this, iram, n](u8 data) { static_cast(iram)[BYTE_XOR_LE(register_base() | (m_psw & 0x0020) >> 3 | n)] = data; } + [this, n]() { return iram_byte_r(register_base() | (m_psw & 0x0020) >> 3 | n); }, + [this, n](u8 data) { iram_byte_w(register_base() | (m_psw & 0x0020) >> 3 | n, data); } ).noshow(); for (int n = 0; n < 8; n++) state_add(UPD78K3_VPL + n, std::array{{"VPL", "VPH", "UPL", "UPH", "E", "D", "L", "H"}}[n], - [this, iram, n]() { return static_cast(iram)[BYTE_XOR_LE(register_base() | 0x08 | n)]; }, - [this, iram, n](u8 data) { static_cast(iram)[BYTE_XOR_LE(register_base() | 0x08 | n)] = data; } + [this, n]() { return iram_byte_r(register_base() | 0x08 | n); }, + [this, n](u8 data) { iram_byte_w(register_base() | 0x08 | n, data); } ).noshow(); // save state @@ -214,39 +240,21 @@ void upd78k3_device::state_string_export(const device_state_entry &entry, std::s BIT(m_psw, 0) ? 'C' : '.'); break; -#if 0 // doesn't compile because value() is protected - case UPD78K3_RP0: - str = string_format("%04X %s", entry.value(), BIT(m_psw, 5) ? " " : "(AX)"); - break; - - case UPD78K3_RP1: - str = string_format("%04X %s", entry.value(), BIT(m_psw, 5) ? " " : "(BC)"); - break; - - case UPD78K3_RP2: - str = string_format("%04X %s", entry.value(), BIT(m_psw, 5) ? "(AX)" : " "); - break; - - case UPD78K3_RP3: - str = string_format("%04X %s", entry.value(), BIT(m_psw, 5) ? "(BC)" : " "); - break; -#else // nasty and inefficient workaround case UPD78K3_RP0: - str = string_format("%04X %s", const_cast(*this).state_int(UPD78K3_RP0), BIT(m_psw, 5) ? " " : "(AX)"); + str = string_format("%04X %s", m_iram[register_base() >> 1], BIT(m_psw, 5) ? " " : "(AX)"); break; case UPD78K3_RP1: - str = string_format("%04X %s", const_cast(*this).state_int(UPD78K3_RP1), BIT(m_psw, 5) ? " " : "(BC)"); + str = string_format("%04X %s", m_iram[register_base() >> 1 | 1], BIT(m_psw, 5) ? " " : "(BC)"); break; case UPD78K3_RP2: - str = string_format("%04X %s", const_cast(*this).state_int(UPD78K3_RP2), BIT(m_psw, 5) ? "(AX)" : " "); + str = string_format("%04X %s", m_iram[register_base() >> 1 | 2], BIT(m_psw, 5) ? "(AX)" : " "); break; case UPD78K3_RP3: - str = string_format("%04X %s", const_cast(*this).state_int(UPD78K3_RP3), BIT(m_psw, 5) ? "(BC)" : " "); + str = string_format("%04X %s", m_iram[register_base() >> 1 | 3], BIT(m_psw, 5) ? "(BC)" : " "); break; -#endif } } @@ -285,6 +293,7 @@ std::unique_ptr upd78312_device::create_disassembler() void upd78312_device::mem_map(address_map &map) { map(0x0000, 0x1fff).rom().region(DEVICE_SELF, 0); // 8K mask ROM + map(0xfe00, 0xfeff).rw(FUNC(upd78312_device::iram_byte_r), FUNC(upd78312_device::iram_byte_w)); } diff --git a/src/devices/cpu/upd78k/upd78k3.h b/src/devices/cpu/upd78k/upd78k3.h index 6625bb50474..1b7d9d663d5 100644 --- a/src/devices/cpu/upd78k/upd78k3.h +++ b/src/devices/cpu/upd78k/upd78k3.h @@ -64,13 +64,18 @@ private: // internal helpers inline u8 register_base() const noexcept; +protected: + u8 iram_byte_r(offs_t offset); + void iram_byte_w(offs_t offset, u8 data); +private: // address spaces, caches & configuration address_space_config m_program_config; address_space_config m_iram_config; address_space_config m_sfr_config; address_space *m_program_space; memory_access_cache<0, 0, ENDIANNESS_LITTLE> *m_program_cache; + required_shared_ptr m_iram; memory_access_cache<1, 0, ENDIANNESS_LITTLE> *m_iram_cache; address_space *m_sfr_space; -- cgit v1.2.3