Skip to content

Commit

Permalink
cosmac: add pull callbacks for int/dmain/out
Browse files Browse the repository at this point in the history
  • Loading branch information
happppp committed Feb 5, 2025
1 parent 40ba93e commit 4edf86f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
37 changes: 36 additions & 1 deletion src/devices/cpu/cosmac/cosmac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ cosmac_device::cosmac_device(const machine_config &mconfig, device_type type, co
m_io_config("io", ENDIANNESS_LITTLE, 8, 3),
m_read_wait(*this, 0),
m_read_clear(*this, 0),
m_read_int(*this, 0),
m_read_dma_in(*this, 0),
m_read_dma_out(*this, 0),
m_read_ef(*this, 0),
m_write_q(*this),
m_read_dma(*this, 0),
Expand Down Expand Up @@ -929,6 +932,28 @@ inline void cosmac_device::sample_wait_clear()
}


//-------------------------------------------------
// sample_interrupt - sample interrupt line
//-------------------------------------------------

bool cosmac_device::sample_interrupt()
{
if (!m_read_int.isunset()) m_irq = m_read_int();
return bool(m_irq);
}


//-------------------------------------------------
// sample_dma_io - sample dma in/out lines
//-------------------------------------------------

inline void cosmac_device::sample_dma_io()
{
if (!m_read_dma_in.isunset()) m_dmain = m_read_dma_in();
if (!m_read_dma_out.isunset()) m_dmaout = m_read_dma_out();
}


//-------------------------------------------------
// sample_ef_lines - sample EF input lines
//-------------------------------------------------
Expand Down Expand Up @@ -1102,6 +1127,8 @@ inline void cosmac_device::initialize()

m_icount -= CLOCKS_INIT;

sample_dma_io();

if (m_dmain)
{
m_state = cosmac_state::STATE_2_DMA_IN;
Expand Down Expand Up @@ -1130,6 +1157,8 @@ inline void cosmac_device::execute_instruction()

m_icount -= CLOCKS_EXECUTE;

sample_dma_io();

if (m_state == cosmac_state::STATE_1_EXECUTE && (m_op >> 4) == 0xc) // "long" opcodes
{
m_state = cosmac_state::STATE_1_EXECUTE_2ND;
Expand Down Expand Up @@ -1166,6 +1195,8 @@ inline void cosmac_device::dma_input()

m_icount -= CLOCKS_DMA;

sample_dma_io();

if (m_dmain)
{
m_state = cosmac_state::STATE_2_DMA_IN;
Expand Down Expand Up @@ -1202,6 +1233,8 @@ inline void cosmac_device::dma_output()

m_icount -= CLOCKS_DMA;

sample_dma_io();

if (m_dmain)
{
m_state = cosmac_state::STATE_2_DMA_IN;
Expand Down Expand Up @@ -1239,6 +1272,8 @@ inline void cosmac_device::interrupt()

m_icount -= CLOCKS_INTERRUPT;

sample_dma_io();

if (m_dmain)
{
m_state = cosmac_state::STATE_2_DMA_IN;
Expand Down Expand Up @@ -1470,7 +1505,7 @@ void cosmac_device::rsxd() { RAM_W(R[X], R[N] & 0xff); R[X]--; RAM_W(R[X], R[N]
void cosmac_device::rnx() { R[X] = R[N]; }

void cosmac_device::bci() { short_branch(m_cil); m_cil = 0; }
void cosmac_device::bxi() { short_branch(m_irq); }
void cosmac_device::bxi() { short_branch(sample_interrupt()); }

void cosmac_device::xie() { m_xie = 1; }
void cosmac_device::xid() { m_xie = 0; }
Expand Down
12 changes: 10 additions & 2 deletions src/devices/cpu/cosmac/cosmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ class cosmac_device : public cpu_device, public cosmac_disassembler::config

auto wait_cb() { return m_read_wait.bind(); }
auto clear_cb() { return m_read_clear.bind(); }
auto int_cb() { return m_read_int.bind(); }
auto dma_in_cb() { return m_read_dma_in.bind(); }
auto dma_out_cb() { return m_read_dma_out.bind(); }
auto ef1_cb() { return m_read_ef[0].bind(); }
auto ef2_cb() { return m_read_ef[1].bind(); }
auto ef3_cb() { return m_read_ef[2].bind(); }
Expand Down Expand Up @@ -224,8 +227,10 @@ class cosmac_device : public cpu_device, public cosmac_disassembler::config
inline void dma_input();
inline void dma_output();
inline void interrupt();
virtual bool check_irq() { return m_ie && m_irq; }
virtual bool check_irq() { return m_ie && sample_interrupt(); }
inline void sample_wait_clear();
bool sample_interrupt();
inline void sample_dma_io();
inline void sample_ef_lines();
virtual void output_state_code();
inline void set_q_flag(int state);
Expand Down Expand Up @@ -366,6 +371,9 @@ class cosmac_device : public cpu_device, public cosmac_disassembler::config
// device callbacks
devcb_read_line m_read_wait;
devcb_read_line m_read_clear;
devcb_read_line m_read_int;
devcb_read_line m_read_dma_in;
devcb_read_line m_read_dma_out;
devcb_read_line::array<4> m_read_ef;
devcb_write_line m_write_q;
devcb_read8 m_read_dma;
Expand Down Expand Up @@ -505,7 +513,7 @@ class cdp1804_device : public cdp1802_device

virtual cosmac_device::ophandler get_ophandler(uint16_t opcode) const override;
virtual bool has_extended_opcodes() override { return true; }
virtual bool check_irq() override { return m_ie && ((m_irq && m_xie) || (m_cil && m_cie)); }
virtual bool check_irq() override { return m_ie && ((sample_interrupt() && m_xie) || (m_cil && m_cie)); }
virtual void reset_state() override;

private:
Expand Down
18 changes: 6 additions & 12 deletions src/mame/netronics/elf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
/*
TODO:
- Problem with DMA: open MAME debugger to see RAM, set LOAD, input a value,
and it will write twice. It is because set_input_line is delayed until
the CPU finished execute_run after sc_w.
- proper layout
- add cassette I/O
Expand Down Expand Up @@ -93,14 +90,14 @@ INPUT_CHANGED_MEMBER(elf2_state::load_w)
{
/* DMAIN is reset while LOAD is off */
if (!newval)
m_maincpu->set_input_line(COSMAC_INPUT_LINE_DMAIN, CLEAR_LINE);
m_dmain = 0;
}

INPUT_CHANGED_MEMBER(elf2_state::input_w)
{
/* assert DMAIN */
if (LOAD && !newval && ~m_sc & 2)
m_maincpu->set_input_line(COSMAC_INPUT_LINE_DMAIN, ASSERT_LINE);
m_dmain = 1;
}

static INPUT_PORTS_START( elf2 )
Expand Down Expand Up @@ -141,16 +138,11 @@ INPUT_PORTS_END

/* CDP1802 Configuration */

uint8_t elf2_state::dma_r()
{
return m_data;
}

void elf2_state::sc_w(uint8_t data)
{
/* DMAIN is reset while SC1 is high */
if (data & 2)
m_maincpu->set_input_line(COSMAC_INPUT_LINE_DMAIN, CLEAR_LINE);
m_dmain = 0;

m_sc = data;
}
Expand Down Expand Up @@ -187,6 +179,7 @@ void elf2_state::machine_start()
/* register for state saving */
save_item(NAME(m_data));
save_item(NAME(m_sc));
save_item(NAME(m_dmain));
}

/* Machine Driver */
Expand All @@ -213,9 +206,10 @@ void elf2_state::elf2(machine_config &config)
m_maincpu->set_addrmap(AS_IO, &elf2_state::elf2_io);
m_maincpu->wait_cb().set_ioport("SPECIAL").bit(1).invert();
m_maincpu->clear_cb().set_ioport("SPECIAL").bit(0);
m_maincpu->dma_in_cb().set([this]() { return m_dmain; });
m_maincpu->ef4_cb().set_ioport("SPECIAL").bit(3);
m_maincpu->q_cb().set_output("led0");
m_maincpu->dma_rd_cb().set(FUNC(elf2_state::dma_r));
m_maincpu->dma_rd_cb().set(FUNC(elf2_state::data_r));
m_maincpu->dma_wr_cb().set(m_vdc, FUNC(cdp1861_device::dma_w));
m_maincpu->sc_cb().set(FUNC(elf2_state::sc_w));

Expand Down
2 changes: 1 addition & 1 deletion src/mame/netronics/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class elf2_state : public driver_device
uint8_t data_r();
void data_w(uint8_t data);
void memory_w(offs_t offset, uint8_t data);
uint8_t dma_r();
void sc_w(uint8_t data);
void da_w(int state);

Expand All @@ -70,6 +69,7 @@ class elf2_state : public driver_device
// internal state
uint8_t m_data = 0;
uint8_t m_sc = 0;
uint8_t m_dmain = 0;
};

#endif // MAME_NETRONICS_ELF_H

0 comments on commit 4edf86f

Please sign in to comment.