Skip to content

Commit 33d8718

Browse files
authored
sinclair/specnext.cpp: Added extra memory read wait state at 28MHz (#13869)
1 parent 25d6429 commit 33d8718

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/devices/machine/z80dma.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ void z80dma_device::device_start()
179179
save_item(NAME(m_rdy));
180180
save_item(NAME(m_force_ready));
181181
save_item(NAME(m_wait));
182+
save_item(NAME(m_waits_extra));
182183
save_item(NAME(m_busrq_ack));
183184
save_item(NAME(m_is_pulse));
184185
save_item(NAME(m_latch));
@@ -197,6 +198,7 @@ void z80dma_device::device_reset()
197198
m_rdy = 0;
198199
m_force_ready = 0;
199200
m_wait = 0;
201+
m_waits_extra = 0;
200202
m_num_follow = 0;
201203
m_read_num_follow = m_read_cur_follow = 0;
202204
m_reset_pointer = 0;
@@ -497,7 +499,8 @@ TIMER_CALLBACK_MEMBER(z80dma_device::clock_w)
497499
}
498500

499501
const attotime clock = clocks_to_attotime(1);
500-
const attotime next = clock * (3 - ((PORTA_IS_SOURCE ? PORTA_TIMING : PORTB_TIMING) & 0x03));
502+
const attotime next = clock * (3 - ((PORTA_IS_SOURCE ? PORTA_TIMING : PORTB_TIMING) & 0x03) + m_waits_extra);
503+
m_waits_extra = 0;
501504
m_timer->adjust(next, 0, clock);
502505

503506
m_dma_seq = SEQ_TRANS1_READ_SOURCE;
@@ -517,7 +520,8 @@ TIMER_CALLBACK_MEMBER(z80dma_device::clock_w)
517520
case SEQ_TRANS1_INC_DEC_DEST_ADDRESS:
518521
{
519522
const attotime clock = clocks_to_attotime(1);
520-
const attotime next = clock * (3 - ((PORTB_IS_SOURCE ? PORTA_TIMING : PORTB_TIMING) & 0x03));
523+
const attotime next = clock * (3 - ((PORTB_IS_SOURCE ? PORTA_TIMING : PORTB_TIMING) & 0x03) + m_waits_extra);
524+
m_waits_extra = 0;
521525
m_timer->adjust(next, 0, clock);
522526

523527
m_dma_seq = SEQ_TRANS1_WRITE_DEST;

src/devices/machine/z80dma.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class z80dma_device : public device_t,
6666
void iei_w(int state) { m_iei = state; interrupt_check(); }
6767
void rdy_w(int state);
6868
void wait_w(int state) { m_wait = state; }
69+
void adjust_wait(int count) { m_waits_extra += count; }
6970
void bai_w(int state);
7071

7172
protected:
@@ -154,6 +155,7 @@ class z80dma_device : public device_t,
154155
u8 m_reset_pointer;
155156

156157
int m_wait;
158+
int m_waits_extra;
157159
int m_busrq_ack;
158160
bool m_is_pulse;
159161
u8 m_latch;

src/mame/sinclair/specnext.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class specnext_state : public spectrum_128_state
123123
void mmu_x2_w(offs_t bank, u8 data);
124124
u8 dma_r(bool dma_mode);
125125
void dma_w(bool dma_mode, u8 data);
126+
u8 dma_mreq_r(offs_t offset);
126127
u8 spi_data_r();
127128
void spi_data_w(u8 data);
128129
void spi_miso_w(u8 data);
@@ -1155,6 +1156,15 @@ void specnext_state::dma_w(bool dma_mode, u8 data)
11551156
m_dma->write(data);
11561157
}
11571158

1159+
u8 specnext_state::dma_mreq_r(offs_t offset)
1160+
{
1161+
if (m_nr_07_cpu_speed == 0b11)
1162+
{
1163+
m_dma->adjust_wait(1);
1164+
}
1165+
return m_program.read_byte(offset);
1166+
}
1167+
11581168
u8 specnext_state::reg_r(offs_t nr_register)
11591169
{
11601170
u8 port_253b_dat;
@@ -2405,6 +2415,12 @@ void specnext_state::map_fetch(address_map &map)
24052415
approach gives better experience in debugger UI. */
24062416
do_m1(offset);
24072417
m_divmmc_delayed_check = 0;
2418+
2419+
// do_m1 performs read from m_program with waits, we need to take it back
2420+
if (!machine().side_effects_disabled() && (m_nr_07_cpu_speed == 0b11))
2421+
{
2422+
m_maincpu->adjust_icount(1);
2423+
}
24082424
}
24092425

24102426
return m_program.read_byte(offset);
@@ -3428,6 +3444,14 @@ void specnext_state::video_start()
34283444
to[offset & 0x1fff] = data;
34293445
}
34303446
});
3447+
prg.install_read_tap(0x0000, 0xffff, "mem_wait_r", [this](offs_t offset, u8 &data, u8 mem_mask)
3448+
{
3449+
// The 28MHz with core 3.0.5 is adding extra wait state to every instruction opcode fetch and memory read
3450+
if (!machine().side_effects_disabled() && (m_nr_07_cpu_speed == 0b11))
3451+
{
3452+
m_maincpu->adjust_icount(-1);
3453+
}
3454+
});
34313455
}
34323456

34333457
void specnext_state::tbblue(machine_config &config)
@@ -3456,7 +3480,7 @@ void specnext_state::tbblue(machine_config &config)
34563480
SPECNEXT_DMA(config, m_dma, 28_MHz_XTAL / 8);
34573481
m_dma->out_busreq_callback().set_inputline(m_maincpu, Z80_INPUT_LINE_BUSRQ);
34583482
m_dma->out_int_callback().set_inputline(m_maincpu, INPUT_LINE_IRQ0);
3459-
m_dma->in_mreq_callback().set([this](offs_t offset) { return m_program.read_byte(offset); });
3483+
m_dma->in_mreq_callback().set(FUNC(specnext_state::dma_mreq_r));
34603484
m_dma->out_mreq_callback().set([this](offs_t offset, u8 data) { m_program.write_byte(offset, data); });
34613485
m_dma->in_iorq_callback().set([this](offs_t offset) { return m_io.read_byte(offset); });
34623486
m_dma->out_iorq_callback().set([this](offs_t offset, u8 data) { m_io.write_byte(offset, data); });

0 commit comments

Comments
 (0)