summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame
diff options
context:
space:
mode:
authorGravatarGravatar cracyc <cracyc@users.noreply.github.com>2020-11-22 15:15:45 -0600
committerGravatarGravatar cracyc <cracyc@users.noreply.github.com>2020-11-22 15:15:45 -0600
commit12e934c86627930f4ca6cf06da9af25175c0f5f2 (patch)
tree3091692aebd285e0dc1d428830ef5736f9098749 /src/mame
parent6b41ddd4f3ddd6c9e5d17383ccc0f2811d4a1b95 (diff)
fmtowns: don't overrun nvram buffer
Diffstat (limited to 'src/mame')
-rw-r--r--src/mame/drivers/fmtowns.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/mame/drivers/fmtowns.cpp b/src/mame/drivers/fmtowns.cpp
index 4a0f1629860..fa2029b6c3d 100644
--- a/src/mame/drivers/fmtowns.cpp
+++ b/src/mame/drivers/fmtowns.cpp
@@ -1204,9 +1204,9 @@ uint8_t towns_state::towns_cmos_low_r(offs_t offset)
return m_ram->pointer()[offset + 0xd8000];
if(m_nvram)
- return m_nvram[offset];
+ return m_nvram[offset >> 2] >> ((offset & 3) << 3);
else
- return m_nvram16[offset];
+ return m_nvram16[offset >> 1] >> ((offset & 1) << 3);
}
void towns_state::towns_cmos_low_w(offs_t offset, uint8_t data)
@@ -1215,25 +1215,41 @@ void towns_state::towns_cmos_low_w(offs_t offset, uint8_t data)
m_ram->pointer()[offset+0xd8000] = data;
else
if(m_nvram)
- m_nvram[offset] = data;
+ {
+ uint8_t shift = (offset & 3) << 3;
+ m_nvram[offset >> 2] &= ~(0xff << shift);
+ m_nvram[offset >> 2] |= (uint32_t)data << shift;
+ }
else
- m_nvram16[offset] = data;
+ {
+ uint8_t shift = (offset & 1) << 3;
+ m_nvram16[offset >> 1] &= ~(0xff << shift);
+ m_nvram16[offset >> 1] |= (uint16_t)data << shift;
+ }
}
uint8_t towns_state::towns_cmos_r(offs_t offset)
{
if(m_nvram)
- return m_nvram[offset];
+ return m_nvram[offset >> 2] >> ((offset & 3) << 3);
else
- return m_nvram16[offset];
+ return m_nvram16[offset >> 1] >> ((offset & 1) << 3);
}
void towns_state::towns_cmos_w(offs_t offset, uint8_t data)
{
if(m_nvram)
- m_nvram[offset] = data;
+ {
+ uint8_t shift = (offset & 3) << 3;
+ m_nvram[offset >> 2] &= ~(0xff << shift);
+ m_nvram[offset >> 2] |= (uint32_t)data << shift;
+ }
else
- m_nvram16[offset] = data;
+ {
+ uint8_t shift = (offset & 1) << 3;
+ m_nvram16[offset >> 1] &= ~(0xff << shift);
+ m_nvram16[offset >> 1] |= (uint16_t)data << shift;
+ }
}
void towns_state::towns_update_video_banks()