Skip to content

Commit df8be62

Browse files
committed
h8_sci: add safety check in internal_update for possible negative ticks,
h8325: mask unused sci register bits
1 parent c60d4a0 commit df8be62

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/devices/cpu/h8/h8325.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
H8/325 family emulation
88
99
TODO:
10-
- serial controllers are slightly different, has 3 interrupt sources
11-
instead of 4
1210
- HCSR @ 0xfffe (port 3 handshake)
1311
- FNCR @ 0xffff (16-bit timer noise canceler)
1412
@@ -115,17 +113,24 @@ void h8325_device::map(address_map &map)
115113
map(0xffd2, 0xffd3).rw(m_timer8[1], FUNC(h8_timer8_channel_device::tcor_r), FUNC(h8_timer8_channel_device::tcor_w));
116114
map(0xffd4, 0xffd4).rw(m_timer8[1], FUNC(h8_timer8_channel_device::tcnt_r), FUNC(h8_timer8_channel_device::tcnt_w));
117115

118-
map(0xffd8, 0xffd8).rw(m_sci[0], FUNC(h8_sci_device::smr_r), FUNC(h8_sci_device::smr_w));
116+
map(0xffd8, 0xffd8).lr8(NAME([this]() { return m_sci[0]->smr_r() | 0x04; }));
117+
map(0xffd8, 0xffd8).lw8(NAME([this](u8 data) { m_sci[0]->smr_w(data & ~0x04); }));
119118
map(0xffd9, 0xffd9).rw(m_sci[0], FUNC(h8_sci_device::brr_r), FUNC(h8_sci_device::brr_w));
120-
map(0xffda, 0xffda).rw(m_sci[0], FUNC(h8_sci_device::scr_r), FUNC(h8_sci_device::scr_w));
119+
map(0xffda, 0xffda).lr8(NAME([this]() { return m_sci[0]->scr_r() | 0x0c; }));
120+
map(0xffda, 0xffda).lw8(NAME([this](u8 data) { m_sci[0]->scr_w(data & ~0x0c); }));
121121
map(0xffdb, 0xffdb).rw(m_sci[0], FUNC(h8_sci_device::tdr_r), FUNC(h8_sci_device::tdr_w));
122-
map(0xffdc, 0xffdc).rw(m_sci[0], FUNC(h8_sci_device::ssr_r), FUNC(h8_sci_device::ssr_w));
122+
map(0xffdc, 0xffdc).lr8(NAME([this]() { return m_sci[0]->ssr_r() | 0x07; }));
123+
map(0xffdc, 0xffdc).lw8(NAME([this](u8 data) { m_sci[0]->ssr_w(data & ~0x07); }));
123124
map(0xffdd, 0xffdd).r(m_sci[0], FUNC(h8_sci_device::rdr_r));
124-
map(0xffe0, 0xffe0).rw(m_sci[1], FUNC(h8_sci_device::smr_r), FUNC(h8_sci_device::smr_w));
125+
126+
map(0xffe0, 0xffe0).lr8(NAME([this]() { return m_sci[1]->smr_r() | 0x04; }));
127+
map(0xffe0, 0xffe0).lw8(NAME([this](u8 data) { m_sci[1]->smr_w(data & ~0x04); }));
125128
map(0xffe1, 0xffe1).rw(m_sci[1], FUNC(h8_sci_device::brr_r), FUNC(h8_sci_device::brr_w));
126-
map(0xffe2, 0xffe2).rw(m_sci[1], FUNC(h8_sci_device::scr_r), FUNC(h8_sci_device::scr_w));
129+
map(0xffe2, 0xffe2).lr8(NAME([this]() { return m_sci[1]->scr_r() | 0x0c; }));
130+
map(0xffe2, 0xffe2).lw8(NAME([this](u8 data) { m_sci[1]->scr_w(data & ~0x0c); }));
127131
map(0xffe3, 0xffe3).rw(m_sci[1], FUNC(h8_sci_device::tdr_r), FUNC(h8_sci_device::tdr_w));
128-
map(0xffe4, 0xffe4).rw(m_sci[1], FUNC(h8_sci_device::ssr_r), FUNC(h8_sci_device::ssr_w));
132+
map(0xffe4, 0xffe4).lr8(NAME([this]() { return m_sci[1]->ssr_r() | 0x07; }));
133+
map(0xffe4, 0xffe4).lw8(NAME([this](u8 data) { m_sci[1]->ssr_w(data & ~0x07); }));
129134
map(0xffe5, 0xffe5).r(m_sci[1], FUNC(h8_sci_device::rdr_r));
130135
}
131136

src/devices/cpu/h8/h8_sci.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ u64 h8_sci_device::internal_update(u64 current_time)
413413
m_clock_event = 0;
414414

415415
if(m_clock_event) {
416-
m_sync_timer->adjust(attotime::from_ticks(m_clock_event - m_cpu->now_as_cycles(), m_cpu->system_clock()));
416+
if(s64 ticks = m_clock_event - m_cpu->now_as_cycles(); ticks >= 0LL)
417+
m_sync_timer->adjust(attotime::from_ticks(ticks, m_cpu->system_clock()));
417418
m_cpu->internal_update();
418419
}
419420

0 commit comments

Comments
 (0)