trunk/src/mess/machine/a2midi.c
| r0 | r20597 | |
| 1 | /********************************************************************* |
| 2 | |
| 3 | a2midi.c |
| 4 | |
| 5 | Apple II 6850 MIDI card, as made by Passport, Yamaha, and others. |
| 6 | |
| 7 | *********************************************************************/ |
| 8 | |
| 9 | #include "emu.h" |
| 10 | #include "includes/apple2.h" |
| 11 | #include "machine/a2midi.h" |
| 12 | |
| 13 | |
| 14 | /*************************************************************************** |
| 15 | PARAMETERS |
| 16 | ***************************************************************************/ |
| 17 | |
| 18 | //************************************************************************** |
| 19 | // GLOBAL VARIABLES |
| 20 | //************************************************************************** |
| 21 | |
| 22 | const device_type A2BUS_MIDI = &device_creator<a2bus_midi_device>; |
| 23 | |
| 24 | #define MIDI_PTM_TAG "midi_ptm" |
| 25 | #define MIDI_ACIA_TAG "midi_acia" |
| 26 | |
| 27 | static struct ptm6840_interface ptm_interface = |
| 28 | { |
| 29 | 1021800.0f, |
| 30 | { 1021800.0f, 1021800.0f, 1021800.0f }, |
| 31 | { DEVCB_NULL, DEVCB_NULL, DEVCB_NULL }, |
| 32 | DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, a2bus_midi_device, ptm_irq_w) |
| 33 | }; |
| 34 | |
| 35 | static struct acia6850_interface acia_interface = |
| 36 | { |
| 37 | 31250*16, // tx clock |
| 38 | 0, // rx clock (we manually clock rx) |
| 39 | DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, a2bus_midi_device, rx_in), // rx in |
| 40 | DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, a2bus_midi_device, tx_out), // tx out |
| 41 | DEVCB_NULL, // cts in |
| 42 | DEVCB_NULL, // rts out |
| 43 | DEVCB_NULL, // dcd in |
| 44 | DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, a2bus_midi_device, acia_irq_w) |
| 45 | }; |
| 46 | |
| 47 | static SLOT_INTERFACE_START(midiin_slot) |
| 48 | SLOT_INTERFACE("midiin", MIDIIN_PORT) |
| 49 | SLOT_INTERFACE_END |
| 50 | |
| 51 | static const serial_port_interface midiin_intf = |
| 52 | { |
| 53 | DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, a2bus_midi_device, midi_rx_w) |
| 54 | }; |
| 55 | |
| 56 | static SLOT_INTERFACE_START(midiout_slot) |
| 57 | SLOT_INTERFACE("midiout", MIDIOUT_PORT) |
| 58 | SLOT_INTERFACE_END |
| 59 | |
| 60 | static const serial_port_interface midiout_intf = |
| 61 | { |
| 62 | DEVCB_NULL // midi out ports don't transmit inward |
| 63 | }; |
| 64 | |
| 65 | MACHINE_CONFIG_FRAGMENT( midi ) |
| 66 | MCFG_PTM6840_ADD(MIDI_PTM_TAG, ptm_interface) |
| 67 | MCFG_ACIA6850_ADD(MIDI_ACIA_TAG, acia_interface) |
| 68 | MCFG_SERIAL_PORT_ADD("mdin", midiin_intf, midiin_slot, "midiin", NULL) |
| 69 | MCFG_SERIAL_PORT_ADD("mdout", midiout_intf, midiout_slot, "midiout", NULL) |
| 70 | MACHINE_CONFIG_END |
| 71 | |
| 72 | //------------------------------------------------- |
| 73 | // machine_config_additions - device-specific |
| 74 | // machine configurations |
| 75 | //------------------------------------------------- |
| 76 | |
| 77 | machine_config_constructor a2bus_midi_device::device_mconfig_additions() const |
| 78 | { |
| 79 | return MACHINE_CONFIG_NAME( midi ); |
| 80 | } |
| 81 | |
| 82 | //************************************************************************** |
| 83 | // LIVE DEVICE |
| 84 | //************************************************************************** |
| 85 | |
| 86 | a2bus_midi_device::a2bus_midi_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 87 | device_t(mconfig, A2BUS_MIDI, "6850 MIDI card", tag, owner, clock), |
| 88 | device_a2bus_card_interface(mconfig, *this), |
| 89 | m_ptm(*this, MIDI_PTM_TAG), |
| 90 | m_acia(*this, MIDI_ACIA_TAG), |
| 91 | m_mdout(*this, "mdout") |
| 92 | { |
| 93 | m_shortname = "a2midi"; |
| 94 | } |
| 95 | |
| 96 | a2bus_midi_device::a2bus_midi_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock) : |
| 97 | device_t(mconfig, type, name, tag, owner, clock), |
| 98 | device_a2bus_card_interface(mconfig, *this), |
| 99 | m_ptm(*this, MIDI_PTM_TAG), |
| 100 | m_acia(*this, MIDI_ACIA_TAG), |
| 101 | m_mdout(*this, "mdout") |
| 102 | { |
| 103 | m_shortname = "a2midi"; |
| 104 | } |
| 105 | |
| 106 | //------------------------------------------------- |
| 107 | // device_start - device-specific startup |
| 108 | //------------------------------------------------- |
| 109 | |
| 110 | void a2bus_midi_device::device_start() |
| 111 | { |
| 112 | // set_a2bus_device makes m_slot valid |
| 113 | set_a2bus_device(); |
| 114 | } |
| 115 | |
| 116 | void a2bus_midi_device::device_reset() |
| 117 | { |
| 118 | m_acia_irq = m_ptm_irq = false; |
| 119 | m_rx_state = 0; |
| 120 | } |
| 121 | |
| 122 | /*------------------------------------------------- |
| 123 | read_c0nx - called for reads from this card's c0nx space |
| 124 | -------------------------------------------------*/ |
| 125 | |
| 126 | UINT8 a2bus_midi_device::read_c0nx(address_space &space, UINT8 offset) |
| 127 | { |
| 128 | // PTM at C0n0-C0n7, ACIA at C0n8-C0n9, drum sync (?) at C0nA-C0nB |
| 129 | |
| 130 | if (offset < 8) |
| 131 | { |
| 132 | return m_ptm->read(space, offset & 7); |
| 133 | } |
| 134 | else if (offset == 8) |
| 135 | { |
| 136 | return m_acia->status_read(space, 0); |
| 137 | } |
| 138 | else if (offset == 9) |
| 139 | { |
| 140 | UINT8 ret = m_acia->data_read(space, 0); |
| 141 | return ret; |
| 142 | } |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | /*------------------------------------------------- |
| 148 | write_c0nx - called for writes to this card's c0nx space |
| 149 | -------------------------------------------------*/ |
| 150 | |
| 151 | void a2bus_midi_device::write_c0nx(address_space &space, UINT8 offset, UINT8 data) |
| 152 | { |
| 153 | if (offset < 8) |
| 154 | { |
| 155 | m_ptm->write(space, offset & 7, data); |
| 156 | } |
| 157 | else if (offset == 8) |
| 158 | { |
| 159 | m_acia->control_write(space, 0, data); |
| 160 | } |
| 161 | else if (offset == 9) |
| 162 | { |
| 163 | m_acia->data_write(space, 0, data); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | WRITE_LINE_MEMBER( a2bus_midi_device::acia_irq_w ) |
| 168 | { |
| 169 | m_acia_irq = state ? true : false; |
| 170 | |
| 171 | if (m_acia_irq || m_ptm_irq) |
| 172 | { |
| 173 | raise_slot_irq(); |
| 174 | } |
| 175 | else |
| 176 | { |
| 177 | lower_slot_irq(); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | WRITE_LINE_MEMBER( a2bus_midi_device::ptm_irq_w ) |
| 182 | { |
| 183 | m_acia_irq = state ? true : false; |
| 184 | |
| 185 | if (m_acia_irq || m_ptm_irq) |
| 186 | { |
| 187 | raise_slot_irq(); |
| 188 | } |
| 189 | else |
| 190 | { |
| 191 | lower_slot_irq(); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | WRITE_LINE_MEMBER( a2bus_midi_device::midi_rx_w ) |
| 196 | { |
| 197 | m_rx_state = state; |
| 198 | for (int i = 0; i < 16; i++) // divider is set to 16 |
| 199 | { |
| 200 | m_acia->rx_clock_in(); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | READ_LINE_MEMBER( a2bus_midi_device::rx_in ) |
| 205 | { |
| 206 | return m_rx_state; |
| 207 | } |
| 208 | |
| 209 | WRITE_LINE_MEMBER( a2bus_midi_device::tx_out ) |
| 210 | { |
| 211 | m_mdout->tx(state); |
| 212 | } |
| 213 | |
trunk/src/mess/machine/a2midi.h
| r0 | r20597 | |
| 1 | /********************************************************************* |
| 2 | |
| 3 | a2midi.h |
| 4 | |
| 5 | Apple II 6850 MIDI card, as made by Passport, Yamaha, and others. |
| 6 | |
| 7 | *********************************************************************/ |
| 8 | |
| 9 | #ifndef __A2BUS_MIDI__ |
| 10 | #define __A2BUS_MIDI__ |
| 11 | |
| 12 | #include "emu.h" |
| 13 | #include "machine/a2bus.h" |
| 14 | #include "machine/6840ptm.h" |
| 15 | #include "machine/6850acia.h" |
| 16 | #include "machine/serial.h" |
| 17 | #include "machine/midiinport.h" |
| 18 | #include "machine/midioutport.h" |
| 19 | |
| 20 | //************************************************************************** |
| 21 | // TYPE DEFINITIONS |
| 22 | //************************************************************************** |
| 23 | |
| 24 | class a2bus_midi_device: |
| 25 | public device_t, |
| 26 | public device_a2bus_card_interface |
| 27 | { |
| 28 | public: |
| 29 | // construction/destruction |
| 30 | a2bus_midi_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 31 | a2bus_midi_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock); |
| 32 | |
| 33 | // optional information overrides |
| 34 | virtual machine_config_constructor device_mconfig_additions() const; |
| 35 | |
| 36 | DECLARE_WRITE_LINE_MEMBER( acia_irq_w ); |
| 37 | DECLARE_WRITE_LINE_MEMBER( ptm_irq_w ); |
| 38 | DECLARE_WRITE_LINE_MEMBER( midi_rx_w ); |
| 39 | DECLARE_READ_LINE_MEMBER( rx_in ); |
| 40 | DECLARE_WRITE_LINE_MEMBER( tx_out ); |
| 41 | |
| 42 | protected: |
| 43 | virtual void device_start(); |
| 44 | virtual void device_reset(); |
| 45 | |
| 46 | virtual UINT8 read_c0nx(address_space &space, UINT8 offset); |
| 47 | virtual void write_c0nx(address_space &space, UINT8 offset, UINT8 data); |
| 48 | |
| 49 | required_device<ptm6840_device> m_ptm; |
| 50 | required_device<acia6850_device> m_acia; |
| 51 | required_device<serial_port_device> m_mdout; |
| 52 | |
| 53 | private: |
| 54 | bool m_acia_irq, m_ptm_irq; |
| 55 | int m_rx_state; |
| 56 | }; |
| 57 | |
| 58 | // device type definition |
| 59 | extern const device_type A2BUS_MIDI; |
| 60 | |
| 61 | #endif /* __A2BUS_MIDI__ */ |