Previous 199869 Revisions Next

r34675 Wednesday 28th January, 2015 at 04:39:50 UTC by R. Belmont
(MESS) More flesh on Miracle skeleton (nw)
[src/emu/bus/nes_ctrl]miracle.c miracle.h

trunk/src/emu/bus/nes_ctrl/miracle.c
r243186r243187
1111**********************************************************************/
1212
1313#include "miracle.h"
14#include "bus/midi/midi.h"
1514
1615#define MIRACLE_MIDI_WAITING 0
17#define MIRACLE_MIDI_RECEIVE 1
18#define MIRACLE_MIDI_SEND 2
16#define MIRACLE_MIDI_RECEIVE 1      // receive byte from piano
17#define MIRACLE_MIDI_SEND 2         // send byte to piano
1918
2019//**************************************************************************
2120//  DEVICE DEFINITIONS
r243186r243187
2524
2625
2726MACHINE_CONFIG_FRAGMENT( nes_miracle )
28//   MCFG_CPU_ADD("piano_cpu", I8051, XTAL_11_0592MHz)   // xtal to be verified
29
3027   MCFG_MIDI_PORT_ADD("mdin", midiin_slot, "midiin")
3128   MCFG_MIDI_PORT_ADD("mdout", midiout_slot, "midiout")
3229MACHINE_CONFIG_END
r243186r243187
5855//-------------------------------------------------
5956
6057nes_miracle_device::nes_miracle_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
61               device_t(mconfig, NES_MIRACLE, "Miracle Piano Controller", tag, owner, clock, "nes_miracle", __FILE__)
62               , device_nes_control_port_interface(mconfig, *this)
63//               , m_cpu(*this, "piano_cpu")
58               device_t(mconfig, NES_MIRACLE, "Miracle Piano Controller", tag, owner, clock, "nes_miracle", __FILE__),
59               device_serial_interface(mconfig, *this),
60               device_nes_control_port_interface(mconfig, *this),
61               m_midiin(*this, "mdin"),
62               m_midiout(*this, "mdout")
6463{
6564}
6665
r243186r243187
9089   m_sent_bits = 0;
9190   m_strobe_clock = 0;
9291   m_midi_mode = MIRACLE_MIDI_WAITING;
92
93   // set standard MIDI parameters
94   set_data_frame(1, 8, PARITY_NONE, STOP_BITS_1);
95   set_rcv_rate(31250);
96   set_tra_rate(31250);
97
98   m_xmit_read = m_xmit_write = 0;
99   m_tx_busy = false;
93100}
94101
95102
r243186r243187
102109UINT8 nes_miracle_device::read_bit0()
103110{
104111   UINT8 ret = 0;
105   if (m_strobe_clock >= 66)
106   {
107      // more than 66 clocks since strobe on write means send mode
108      m_midi_mode = MIRACLE_MIDI_SEND;
109      strobe_timer->reset();
110      m_strobe_on = 0;
111      m_strobe_clock = 0;
112//      printf("send start\n");
113   }
114112
115   if (m_midi_mode == MIRACLE_MIDI_SEND)
113   if (m_midi_mode == MIRACLE_MIDI_RECEIVE)
116114   {
117115      //NES reads from Miracle Piano!
118116      // ret |= ...
r243186r243187
126124//-------------------------------------------------
127125
128126// TODO: here, writes to serial midi in bit0, when in MIDI_RECEIVE mode
127// c4fc = start of recv routine
128// c53a = start of send routine
129129
130130void nes_miracle_device::write(UINT8 data)
131131{
132//   printf("write: %d (%d %02x %d)\n", data & 1, m_sent_bits, m_data_sent, m_midi_mode);
133
134   if (m_midi_mode == MIRACLE_MIDI_SEND)
135   {
136      //NES writes (data & 1) to Miracle Piano!
137      // 1st write is data present flag (1=data present)
138      // next 8 writes are actual data bits (with ^1)
139      m_sent_bits++;
140      m_data_sent <<= 1;
141      m_data_sent |= (data & 1);
142      // then we go back to waiting
143      if (m_sent_bits == 8)
144      {
145//         printf("xmit MIDI byte %02x\n", m_data_sent);
146         xmit_char(m_data_sent);
147         m_midi_mode = MIRACLE_MIDI_WAITING;
148         m_sent_bits = 0;
149      }
150
151      return;
152   }
153
132154   if (data == 1 && !m_strobe_on)
133155   {
134156      strobe_timer->adjust(attotime::zero, 0, machine().device<cpu_device>("maincpu")->cycles_to_attotime(1));
r243186r243187
141163      // was timer running?
142164      if (m_strobe_clock > 0)
143165      {
166//         printf("got strobe at %d clocks\n", m_strobe_clock);
167
144168         if (m_strobe_clock < 66 && data == 0)
145169         {
146            // less than 66 clocks before new write means receive mode
170            // short delay is recieve mode
147171            m_midi_mode = MIRACLE_MIDI_RECEIVE;
148//            printf("receive start\n");
149172            strobe_timer->reset();
150173            m_strobe_on = 0;
151174            m_strobe_clock = 0;
152175            return;
153176         }
177         else if (m_strobe_clock >= 66)
178         {
179            // more than 66 clocks since strobe on write means send mode
180            m_midi_mode = MIRACLE_MIDI_SEND;
181            strobe_timer->reset();
182            m_strobe_on = 0;
183            m_strobe_clock = 0;
184            m_sent_bits = 1;
185            m_data_sent <<= 1;
186            m_data_sent |= (data & 1);
187            return;
188         }
154189      }
155190
156191      if (m_midi_mode == MIRACLE_MIDI_SEND &&  data == 0)
157192      {
158193         // strobe off after the end of a byte
159194         m_midi_mode = MIRACLE_MIDI_WAITING;
160//         printf("send end\n");
161195      }
162196   }
197}
163198
164   if (m_midi_mode == MIRACLE_MIDI_RECEIVE)
199void nes_miracle_device::rcv_complete()    // Rx completed receiving byte
200{
201   receive_register_extract();
202//   UINT8 rcv = get_received_char();
203}
204
205void nes_miracle_device::tra_complete()    // Tx completed sending byte
206{
207//  printf("Tx complete\n");
208   // is there more waiting to send?
209   if (m_xmit_read != m_xmit_write)
165210   {
166      //NES writes (data & 1) to Miracle Piano!
167      // 1st write is data present flag (1=data present)
168      // next 8 writes are actual data bits (with ^1)
169      m_sent_bits++;
170      // then we go back to waiting
171      if (m_sent_bits == 9)
211      transmit_register_setup(m_xmitring[m_xmit_read++]);
212      if (m_xmit_read >= XMIT_RING_SIZE)
172213      {
173//         printf("receive end\n");
174         m_midi_mode = MIRACLE_MIDI_WAITING;
175         m_sent_bits = 0;
214         m_xmit_read = 0;
176215      }
177216   }
217   else
218   {
219      m_tx_busy = false;
220   }
178221}
222
223void nes_miracle_device::tra_callback()    // Tx send bit
224{
225   // send this to midi out
226   m_midiout->write_txd(transmit_register_get_data_bit());
227}
228
229void nes_miracle_device::xmit_char(UINT8 data)
230{
231//  printf("xmit %02x\n", data);
232
233   // if tx is busy it'll pick this up automatically when it completes
234   // if not, send now!
235   if (!m_tx_busy)
236   {
237      m_tx_busy = true;
238      transmit_register_setup(data);
239   }
240   else
241   {
242      // tx is busy, it'll pick this up next time
243      m_xmitring[m_xmit_write++] = data;
244      if (m_xmit_write >= XMIT_RING_SIZE)
245      {
246         m_xmit_write = 0;
247      }
248   }
249}
250
trunk/src/emu/bus/nes_ctrl/miracle.h
r243186r243187
1515
1616#include "emu.h"
1717#include "ctrl.h"
18//#include "cpu/mcs51/mcs51.h"
18#include "bus/midi/midi.h"
1919
2020//**************************************************************************
2121//  TYPE DEFINITIONS
r243186r243187
2424// ======================> nes_miracle_device
2525
2626class nes_miracle_device : public device_t,
27                     public device_serial_interface,
2728                     public device_nes_control_port_interface
2829{
2930public:
31   static const int XMIT_RING_SIZE = 16;
32
3033   // construction/destruction
3134   nes_miracle_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
3235
3336   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
3437   virtual machine_config_constructor device_mconfig_additions() const;
3538
39   // serial overrides
40   virtual void rcv_complete();    // Rx completed receiving byte
41   virtual void tra_complete();    // Tx completed sending byte
42   virtual void tra_callback();    // Tx send bit
43
44   void xmit_char(UINT8 data);
45
46   required_device<midi_port_device> m_midiin, m_midiout;
47
3648protected:
3749   // device-level overrides
3850   virtual void device_start();
r243186r243187
4456   static const device_timer_id TIMER_STROBE_ON = 0;
4557   emu_timer *strobe_timer;
4658
47   //required_device<i8051_device> m_cpu;
4859   int m_strobe_on, m_midi_mode, m_sent_bits;
4960   UINT32 m_strobe_clock;
61   UINT8 m_data_sent;
62   UINT8 m_xmitring[XMIT_RING_SIZE];
63   int m_xmit_read, m_xmit_write;
64   bool m_tx_busy;
5065};
5166
5267// device type definition


Previous 199869 Revisions Next


© 1997-2024 The MAME Team