From a1e5795e34b201210b00e90c8058fcd6dd1c544e Mon Sep 17 00:00:00 2001 From: hap Date: Sat, 10 Feb 2024 15:40:31 +0100 Subject: nvram: delete file on save if there's a write error or result file is 0 bytes --- src/devices/cpu/m6800/m6801.cpp | 21 ++++++++++----------- src/emu/machine.cpp | 9 +++++++++ src/mame/saitek/prisma.cpp | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/devices/cpu/m6800/m6801.cpp b/src/devices/cpu/m6800/m6801.cpp index 2cdc9386e10..d799d737c1b 100644 --- a/src/devices/cpu/m6800/m6801.cpp +++ b/src/devices/cpu/m6800/m6801.cpp @@ -1508,10 +1508,9 @@ 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 it's currently not battery-backed, don't save at all if (!m_nvram_battery) - nvram_default(); + return true; size_t actual; @@ -1568,6 +1567,10 @@ void m6801_cpu_device::nvram_default() bool hd6301_cpu_device::nvram_write(util::write_stream &file) { + // if it's currently not battery-backed, don't save at all + if (!m_nvram_battery) + return true; + if (!m6801_cpu_device::nvram_write(file)) return false; @@ -1586,10 +1589,6 @@ bool hd6301_cpu_device::nvram_write(util::write_stream &file) // port output latches buf.insert(buf.end(), m_port_data, m_port_data + sizeof(m_port_data)); - // zerofill if it's currently not battery-backed - if (!m_nvram_battery) - std::fill(buf.begin(), buf.end(), 0); - if (file.write(buf.data(), buf.size(), actual) || (buf.size() != actual)) return false; @@ -1598,6 +1597,10 @@ bool hd6301_cpu_device::nvram_write(util::write_stream &file) bool hd6301x_cpu_device::nvram_write(util::write_stream &file) { + // if it's currently not battery-backed, don't save at all + if (!m_nvram_battery) + return true; + if (!hd6301_cpu_device::nvram_write(file)) return false; @@ -1607,10 +1610,6 @@ bool hd6301x_cpu_device::nvram_write(util::write_stream &file) // port output latches buf.insert(buf.begin(), m_portx_data, m_portx_data + sizeof(m_portx_data)); - // zerofill if it's currently not battery-backed - if (!m_nvram_battery) - std::fill(buf.begin(), buf.end(), 0); - if (file.write(buf.data(), buf.size(), actual) || (buf.size() != actual)) return false; diff --git a/src/emu/machine.cpp b/src/emu/machine.cpp index 669f5fa27a5..fd321949327 100644 --- a/src/emu/machine.cpp +++ b/src/emu/machine.cpp @@ -1160,8 +1160,17 @@ void running_machine::nvram_save() emu_file file(options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); if (!file.open(nvram_filename(nvram.device()))) { + bool error = false; + if (!nvram.nvram_save(file)) + { + error = true; osd_printf_error("Error writing NVRAM file %s\n", file.filename()); + } + + // close and perhaps delete the file + if (error || file.size() == 0) + file.remove_on_close(); file.close(); } } diff --git a/src/mame/saitek/prisma.cpp b/src/mame/saitek/prisma.cpp index 7c2e877ce34..d3aae90a4a3 100644 --- a/src/mame/saitek/prisma.cpp +++ b/src/mame/saitek/prisma.cpp @@ -198,7 +198,7 @@ u8 prisma_state::p7_r() if (BIT(m_inp_mux, i)) data |= m_board->read_file(i); - return bitswap<8>(~data,1,7,6,0,5,4,2,3); + return bitswap<8>(~data,6,5,3,2,0,1,7,4); } -- cgit v1.2.3