From 916aaee5b6557b0949a544ad6751ff3efb6b5a45 Mon Sep 17 00:00:00 2001 From: arbee Date: Wed, 28 Jan 2015 23:53:51 -0500 Subject: (MESS) nes: MIDI In support for Miracle Piano [R. Belmont] --- src/emu/bus/nes_ctrl/ctrl.c | 2 +- src/emu/bus/nes_ctrl/miracle.c | 45 ++++++++++++++++++++++++++++++++++++------ src/emu/bus/nes_ctrl/miracle.h | 6 ++++-- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/emu/bus/nes_ctrl/ctrl.c b/src/emu/bus/nes_ctrl/ctrl.c index 9e81d228f6a..ea41b6285bc 100644 --- a/src/emu/bus/nes_ctrl/ctrl.c +++ b/src/emu/bus/nes_ctrl/ctrl.c @@ -168,7 +168,7 @@ SLOT_INTERFACE_START( nes_control_port1_devices ) SLOT_INTERFACE("joypad", NES_JOYPAD) SLOT_INTERFACE("zapper", NES_ZAPPER) SLOT_INTERFACE("4score_p1p3", NES_4SCORE_P1P3) -// SLOT_INTERFACE("miracle_piano", NES_MIRACLE) + SLOT_INTERFACE("miracle_piano", NES_MIRACLE) SLOT_INTERFACE_END SLOT_INTERFACE_START( nes_control_port2_devices ) diff --git a/src/emu/bus/nes_ctrl/miracle.c b/src/emu/bus/nes_ctrl/miracle.c index 00b70cd3e2d..bcf596b8d72 100644 --- a/src/emu/bus/nes_ctrl/miracle.c +++ b/src/emu/bus/nes_ctrl/miracle.c @@ -24,6 +24,8 @@ const device_type NES_MIRACLE = &device_creator; MACHINE_CONFIG_FRAGMENT( nes_miracle ) MCFG_MIDI_PORT_ADD("mdin", midiin_slot, "midiin") + MCFG_MIDI_RX_HANDLER(WRITELINE(nes_miracle_device, rx_w)) + MCFG_MIDI_PORT_ADD("mdout", midiout_slot, "midiout") MACHINE_CONFIG_END @@ -99,6 +101,8 @@ void nes_miracle_device::device_reset() set_tra_rate(31250); m_xmit_read = m_xmit_write = 0; + m_recv_read = m_recv_write = 0; + m_read_status = m_status_bit = false; m_tx_busy = false; } @@ -107,16 +111,22 @@ void nes_miracle_device::device_reset() // read //------------------------------------------------- -// TODO: here, reads from serial midi in bit0, when in MIDI_SEND mode - UINT8 nes_miracle_device::read_bit0() { UINT8 ret = 0; if (m_midi_mode == MIRACLE_MIDI_RECEIVE) { - //NES reads from Miracle Piano! - // ret |= ... + if (m_status_bit) + { + m_status_bit = false; + ret = (m_read_status) ? 1 : 0; + } + else + { + ret = (m_data_sent & 0x80) ? 0 : 1; + m_data_sent <<= 1; + } } return ret; @@ -126,7 +136,6 @@ UINT8 nes_miracle_device::read_bit0() // write //------------------------------------------------- -// TODO: here, writes to serial midi in bit0, when in MIDI_RECEIVE mode // c4fc = start of recv routine // c53a = start of send routine @@ -175,6 +184,23 @@ void nes_miracle_device::write(UINT8 data) strobe_timer->reset(); m_strobe_on = 0; m_strobe_clock = 0; + + m_status_bit = true; + if (m_recv_read != m_recv_write) + { +// printf("Getting %02x from Miracle[%d]\n", m_recvring[m_recv_read], m_recv_read); + m_data_sent = m_recvring[m_recv_read++]; + if (m_recv_read >= RECV_RING_SIZE) + { + m_recv_read = 0; + } + m_read_status = true; + } + else + { + m_read_status = false; +// printf("Miracle has no data\n"); + } return; } else if (m_strobe_clock >= 66) @@ -202,7 +228,14 @@ void nes_miracle_device::write(UINT8 data) void nes_miracle_device::rcv_complete() // Rx completed receiving byte { receive_register_extract(); -// UINT8 rcv = get_received_char(); + UINT8 rcv = get_received_char(); + +// printf("Got %02x -> [%d]\n", rcv, m_recv_write); + m_recvring[m_recv_write++] = rcv; + if (m_recv_write >= RECV_RING_SIZE) + { + m_recv_write = 0; + } } void nes_miracle_device::tra_complete() // Tx completed sending byte diff --git a/src/emu/bus/nes_ctrl/miracle.h b/src/emu/bus/nes_ctrl/miracle.h index 1ea7580bc40..5763f0d6059 100644 --- a/src/emu/bus/nes_ctrl/miracle.h +++ b/src/emu/bus/nes_ctrl/miracle.h @@ -29,6 +29,7 @@ class nes_miracle_device : public device_t, { public: static const int XMIT_RING_SIZE = 64; + static const int RECV_RING_SIZE = 64; // construction/destruction nes_miracle_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); @@ -59,9 +60,10 @@ protected: int m_strobe_on, m_midi_mode, m_sent_bits; UINT32 m_strobe_clock; UINT8 m_data_sent; - UINT8 m_xmitring[XMIT_RING_SIZE]; + UINT8 m_xmitring[XMIT_RING_SIZE], m_recvring[RECV_RING_SIZE]; int m_xmit_read, m_xmit_write; - bool m_tx_busy; + int m_recv_read, m_recv_write; + bool m_tx_busy, m_read_status, m_status_bit; }; // device type definition -- cgit v1.2.3