From f356a3b65a0684e290b481ba1991fb8e489ed89e Mon Sep 17 00:00:00 2001 From: hap Date: Tue, 21 Nov 2023 16:47:33 +0100 Subject: m6801: add setter for nvram battery status --- src/devices/cpu/m6800/m6801.cpp | 13 +++++++++++-- src/devices/cpu/m6800/m6801.h | 2 ++ src/mame/novag/snova.cpp | 3 ++- src/mame/saitek/companion2.cpp | 10 ++-------- src/mame/saitek/leonardo.cpp | 10 ++-------- src/mame/saitek/renaissance.cpp | 3 ++- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/devices/cpu/m6800/m6801.cpp b/src/devices/cpu/m6800/m6801.cpp index 4ff7398e3e7..adc3fd17440 100644 --- a/src/devices/cpu/m6800/m6801.cpp +++ b/src/devices/cpu/m6800/m6801.cpp @@ -390,6 +390,7 @@ m6801_cpu_device::m6801_cpu_device(const machine_config &mconfig, device_type ty , m_internal_ram(*this, "internal") , m_nvram_bytes(nvram_bytes) , m_nvram_defval(0) + , m_nvram_battery(true) , m_sclk_divider(8) { // disable nvram by default (set to true if MCU is battery-backed when in standby mode) @@ -1321,6 +1322,11 @@ void mc68120_device::dpram_w(offs_t offset, uint8_t data) bool m6801_cpu_device::nvram_write(util::write_stream &file) { + // if it's currently not battery-backed, reinitialize nvram + // so it won't load the previous nvram file on the next boot + if (!m_nvram_battery) + nvram_default(); + size_t actual; if (file.write(&m_internal_ram[0], m_nvram_bytes, actual) || m_nvram_bytes != actual) @@ -1355,8 +1361,6 @@ void m6801_cpu_device::nvram_default() if (!nvram_backup_enabled() || m_nvram_bytes == 0) return; - std::fill_n(&m_internal_ram[0], m_nvram_bytes, m_nvram_defval); - // default nvram from mytag:nvram region if it exists memory_region *region = memregion("nvram"); if (region != nullptr) @@ -1367,6 +1371,11 @@ void m6801_cpu_device::nvram_default() std::copy_n(®ion->as_u8(), m_nvram_bytes, &m_internal_ram[0]); m_ram_ctrl |= 0x80; } + else + { + std::fill_n(&m_internal_ram[0], m_nvram_bytes, m_nvram_defval); + m_ram_ctrl &= 0x3f; + } } diff --git a/src/devices/cpu/m6800/m6801.h b/src/devices/cpu/m6800/m6801.h index 7edb31a844d..2e47107f306 100644 --- a/src/devices/cpu/m6800/m6801.h +++ b/src/devices/cpu/m6800/m6801.h @@ -58,6 +58,7 @@ public: auto out_sc2_cb() { return m_out_sc2_func.bind(); } auto out_ser_tx_cb() { return m_out_sertx_func.bind(); } + void nvram_set_battery(int state) { m_nvram_battery = bool(state); } // default is 1 (nvram_enable_backup needs to be true) void nvram_set_default_value(uint8_t val) { m_nvram_defval = val; } // default is 0 auto standby_cb() { return m_standby_func.bind(); } // notifier (not an output pin) bool standby() { return suspended(SUSPEND_REASON_CLOCK); } @@ -141,6 +142,7 @@ protected: required_shared_ptr m_internal_ram; const int m_nvram_bytes; uint8_t m_nvram_defval; + bool m_nvram_battery; int m_sclk_divider; /* internal registers */ diff --git a/src/mame/novag/snova.cpp b/src/mame/novag/snova.cpp index 7e7c1c27490..6c4250aa7fb 100644 --- a/src/mame/novag/snova.cpp +++ b/src/mame/novag/snova.cpp @@ -348,7 +348,8 @@ void snova_state::snova(machine_config &config) m_maincpu->set_clock(16_MHz_XTAL); m_maincpu->set_addrmap(AS_PROGRAM, &snova_state::snova_map); m_maincpu->nvram_enable_backup(true); - m_maincpu->standby_cb().set(FUNC(snova_state::standby)); + m_maincpu->standby_cb().set(m_maincpu, FUNC(hd6303y_cpu_device::nvram_set_battery)); + m_maincpu->standby_cb().append(FUNC(snova_state::standby)); NVRAM(config, "nvram", nvram_device::DEFAULT_ALL_0); m_board->set_nvram_enable(true); diff --git a/src/mame/saitek/companion2.cpp b/src/mame/saitek/companion2.cpp index 9d48eaf4204..057849cda0e 100644 --- a/src/mame/saitek/companion2.cpp +++ b/src/mame/saitek/companion2.cpp @@ -107,7 +107,6 @@ private: void set_cpu_freq(); TIMER_CALLBACK_MEMBER(set_pin); - void standby(int state); emu_timer *m_standbytimer; emu_timer *m_nmitimer; @@ -145,12 +144,6 @@ void compan2_state::machine_reset() m_maincpu->set_input_line(M6801_STBY_LINE, CLEAR_LINE); } -void compan2_state::standby(int state) -{ - if (state) - m_display->clear(); -} - TIMER_CALLBACK_MEMBER(compan2_state::set_pin) { m_maincpu->set_input_line(param, ASSERT_LINE); @@ -299,7 +292,8 @@ void compan2_state::expchess(machine_config &config) // basic machine hardware HD6301V1(config, m_maincpu, 4000000); // approximation, no XTAL m_maincpu->nvram_enable_backup(true); - m_maincpu->standby_cb().set(FUNC(compan2_state::standby)); + m_maincpu->standby_cb().set(m_maincpu, FUNC(hd6301v1_cpu_device::nvram_set_battery)); + m_maincpu->standby_cb().append([this](int state) { if (state) m_display->clear(); }); m_maincpu->in_p1_cb().set(FUNC(compan2_state::input1_r)); m_maincpu->in_p2_cb().set(FUNC(compan2_state::input2_r)); m_maincpu->out_p2_cb().set("dac", FUNC(dac_1bit_device::write)).bit(0); diff --git a/src/mame/saitek/leonardo.cpp b/src/mame/saitek/leonardo.cpp index 88b4df9243e..4e4c2fdfb4b 100644 --- a/src/mame/saitek/leonardo.cpp +++ b/src/mame/saitek/leonardo.cpp @@ -113,7 +113,6 @@ private: void main_map(address_map &map); - void standby(int state); void update_display(); void mux_w(u8 data); void leds_w(u8 data); @@ -155,12 +154,6 @@ void leo_state::machine_reset() m_stb->in_clear<0>(); } -void leo_state::standby(int state) -{ - if (state) - m_display->clear(); -} - INPUT_CHANGED_MEMBER(leo_state::go_button) { if (newval && m_maincpu->standby()) @@ -400,7 +393,8 @@ void leo_state::leonardo(machine_config &config) HD6303Y(config, m_maincpu, 12_MHz_XTAL); m_maincpu->set_addrmap(AS_PROGRAM, &leo_state::main_map); m_maincpu->nvram_enable_backup(true); - m_maincpu->standby_cb().set(FUNC(leo_state::standby)); + m_maincpu->standby_cb().set(m_maincpu, FUNC(hd6303y_cpu_device::nvram_set_battery)); + m_maincpu->standby_cb().append([this](int state) { if (state) m_display->clear(); }); m_maincpu->in_p2_cb().set(FUNC(leo_state::p2_r)); m_maincpu->out_p2_cb().set(FUNC(leo_state::p2_w)); m_maincpu->in_p5_cb().set(FUNC(leo_state::p5_r)); diff --git a/src/mame/saitek/renaissance.cpp b/src/mame/saitek/renaissance.cpp index f7fdaf2f042..c880d617d6f 100644 --- a/src/mame/saitek/renaissance.cpp +++ b/src/mame/saitek/renaissance.cpp @@ -389,7 +389,8 @@ void ren_state::ren(machine_config &config) HD6303Y(config, m_maincpu, 10_MHz_XTAL); m_maincpu->set_addrmap(AS_PROGRAM, &ren_state::main_map); m_maincpu->nvram_enable_backup(true); - m_maincpu->standby_cb().set(FUNC(ren_state::standby)); + m_maincpu->standby_cb().set(m_maincpu, FUNC(hd6303y_cpu_device::nvram_set_battery)); + m_maincpu->standby_cb().append(FUNC(ren_state::standby)); m_maincpu->in_p2_cb().set(FUNC(ren_state::p2_r)); m_maincpu->out_p2_cb().set(FUNC(ren_state::p2_w)); m_maincpu->in_p5_cb().set(FUNC(ren_state::p5_r)); -- cgit v1.2.3