This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Communicating with the Miracle Piano

Communicating with the Miracle Piano
by on (#51005)
(Irrelevant?) background: I'm working on a project that makes NES peripherals and accessories USB plug-and-play capable out-of-the-box. Basically you plug your joypad / Power Pad / Power Glove / U-Force / Piano / whatever into one of the four ports on this little USB box, then bam, you instantly have a fully functioning and configured HID device available to your OS. It automagically detects what exactly you just plugged in (!), and it shows up on your computer in the appropriate device location, fully named and everything. The working prototype is sitting right here on a solderless breadboard, happily blinking away right next to my keyboard.

Anyway, I have come to the point where I'm looking at my old (NES-flavored) Miracle Piano Teaching System in an attempt to incorporate support in my code. The problem is that I can find very little information on the matter; see here and here. I'm attempting to reverse-engineer the details myself, but it's exceedingly difficult because: a.) my project itself lives on a rickety solderless breadboard, b.) my logic analyzer consists of the very basic 1 MHz 3-channel probe that comes built into the PICkit 2 (which is also extremely difficult to use for this purpose, hooking rigid little wires on small metal contacts inside an open NES chassis), and 3.) I'm starting to run into some time constraints / pressure to focus on other areas.

In a nutshell, I need to figure out how to at least read the MIDI data from the Miracle Piano in the same fashion as a genuine NES. Sending data back to it would be icing. If nothing else I've confirmed for myself that the bundled DB25 -> NES adapter plug only connects pins to clock, latch, and the D0 line. I assume it transmits and receives standard MIDI messages with the NES, and it's obviously bidirectional, so it remains to be seen what, if anything, this means special for the NES hardware. I just simply don't have the equipment I need to tackle this problem...

Yeah, so now that I'm reflecting on what it is that I'm actually attempting here, it's not surprising that there's so little Miracle info around. Figures I find literally the sole remaining niche purpose to hook up a really old keyboard using an even older interface when a completely perfect standard interface is literally built-in right next to it... haha. It makes zero sense, in every conceivable situation, except the one where I'm trying to provide universal NES interface support.

If anyone has hints, suggestions, or can point me in a better direction it would be super duper appreciated. And the practical upshot is that if I can get this done, then at the very least schematics and firmware and/or code for this bad boy will be available to the NESing community at large before long. :o

by on (#51007)
I was curious about that adapter cable. I found one (without the piano), and I could see a PCB in there through the little hole.

Seems like there'd be no better way to know than to disassemble the Miracle Piano NES ROM. Depends on how the code was written, there need not be more than a few subroutines in there to handle init/send/receive at least.

MIDI is asynchronous, so if it's using the NES clock line it has to be hooked up to some extra hardware in the piano or adapter cable with a synchronous interface.

If it's asychronous, of course then you may need to use real-time code to handle it, or an actual UART.

by on (#51011)
I have the SNES Miracle Piano, and it has jacks in the back where you can hook it up to a regular MIDI-capable computer, via the standard MIDI cables.

It's not GM though, so the instruments are all in a different order than they otherwise would be on a GM device, but none the less, the piano behaves just like any normal MIDI device would, at least when you hook it up to a computer. :P

by on (#51012)
If it's not GM compatible, maybe it is MT-32, the other popular standard back then ?

by on (#51017)
Miracle uses MIDI on channels 0-7, just with its own set of instruments. I can scan the page from the manual if you want to know what they are. It does not use any standard drum kits.
As far as I know, pressing B on player 1's controller tricks the Miracle NES game into endlessly polling for MIDI input events. My guess to how input works is it checks if it reads a 1 as the first bit (which is the B button on a normal controller), then reads 7 bits, then checks if it reads a 1 again. Or something like that. I think it sends strobes between polling. Output seems to work by just outputting 0s or 1s repeatedly in the strobe bit when writing to the controller 1 address.

This is just what I got from messing around in FCEU though.

by on (#51019)
Memblers wrote:
I was curious about that adapter cable. I found one (without the piano), and I could see a PCB in there through the little hole.

Hmm, well how do you like that... I've had that thing for all these years and never noticed / bothered to look. Actually I'd look right this minute except that whole mess is balancing precariously in the corner and I don't want to disturb it until I'm ready to unhook it all. I'll check later.

Memblers wrote:
Seems like there'd be no better way to know than to disassemble the Miracle Piano NES ROM. Depends on how the code was written, there need not be more than a few subroutines in there to handle init/send/receive at least.

Wow, where'd my brain go for two days. I initially thought I'd just try to observe the signals, figuring it would save some time over tracking down a couple routines ... And I got so wrapped up that I failed to realize I probably could have at least made a little dent disassembling it by now. I'll get crackin'.

Memblers wrote:
...if it's using the NES clock line...

It's either using the clock line asynchronously or I'm observing very bad sample aliasing. Or both. In any case it seems to be operating very different from a joypad read cycle, or even those employed by the U-Force or the Power Glove (the Miracle data looks nothing like the standard "read one NES serial byte" protocol).

For reference, here's a quick sample of a read from a standard NES joypad:

Key: red = latch line, green = clock line, blue = serial data (D0), 12.5us/maj. div.


And here's some data going between my Miracle and NES:


Obviously it uses the three lines in interesting ways. The best theory I came up with was that those three groups of pulses line up with maybe three average MIDI bytes. But that's a shot in the dark. So, I'll see about how much progress I can make disassembling the ROM.

by on (#51020)
Thank you everybody very much for the replies!

Alrighty... as Drag and Dwedit said, the Miracle does in fact use the MIDI protocol, but it has its own custom patch assignments. Drag pointed out that all Miracle Pianos have standard MIDI DIN jacks in the back, which I guess brings up the point that even though this thing communicates with MIDI devices, I don't actually know with certainty that it communicates raw unprocessed MIDI data to/from the NES. The Miracle Port in the back (where the PC/SNES/Genesis/NES cable goes) also sends out MIDI data, at the very least, for the PC software... But on different pins from the ones that connect up to the NES cable. So I guess I need to consider that possibility.

I'm not sure how I still have the manual, and in such good condition to boot, but:

The Miracle can be connected via MIDI (Musical Instrument Digital Interface) to a standalone or computer-driven sequencer that can digitally record your performances, as well as letting you edit, merge and play back these performances through the Miracle. Through MIDI, the Miracle can also be used as a keyboard input device for another synthesizer.


The Miracle Keyboard always sends MIDI information on MIDI Channel 1 and receives on MIDI channels 1 through 8.

However... That information implies nothing about what kind of data goes to/from the NES, so. Again, I need to keep that in mind.

by on (#51037)
"MIDI channel" is the low nibble of the "status" byte of each MIDI message that's assigned to a channel. For example, channel 4 would use message $93 kk vv for start note k with velocity v, $A3 kk vv for pressure of a held note, $B3 cc vv for controller value, $C3 ii for instrument change, $D3 vv for pressure of all held notes on this channel, and $E3 ll hh to set pitch bend to h*128+l, where $2000 is center. Channel 6 would use $95, $A5, $B5, $C5, $D5, and $E5 instead.

by on (#51050)
it would be awesome to make an adapter to plug general midi devices into a NES

by on (#51051)
frantik wrote:
it would be awesome to make an adapter to plug general midi devices into a NES

The early prototype of MidiNES used the controller port, but later moved all the hardware to the cartridge.

At the most basic level all you'd need for the controller port is a PIC (w/ UART) and an opto-isolator.

by on (#51053)
let me rephrase that

it would be awesome if Memblers made an adapter to plug general midi devices into a NES


midines seems cool but i want to write my own software to use with midi, like a 7bit pcm rompler or drum machine.. or even a midi sequencer would be awesome.

i always thought the miracle plugged midi right into a controller port, but i guess not :(
Re: Communicating with the Miracle Piano
by on (#132959)
This thread... it does not fill me with confidence...
I finally got my hands on a Miracle (sans power supply, serial cable, and foot pedal, but all of those are trivially replaced). I have hoped perhaps against hope that the serial comm would be as simple as latching and then reading a series of 1 bit per key.

I still hold out a vague glimmer that sir_cuitous was simply seeing some bad aliasing on account of really really rapid polling, otherwise this thing may be even more of a monster than the Glove was to crack >_<

Still, between the graphs and Dwedit's observation about polling, there may be some hope here. And as I did on the Glove, if I can get the Miracle working and patched into some actual homebrew on an actual NES, I may be able to sidestep some of the overspecification and overgeneralization that other sources came up with testing black-box-style with raw leads against raw traces.

If I succeed at anything, I'll be sure to leave notes here.

Edit: In fact, just some hunches to throw off the bat:

Think about the functions of the lines. The only communication from the NES to the Miracle must occur in some combination of the red and green lines; the only return communication can occur on the blue line.

Further, the green signal is a very specific animal- it can't be held high or low manually, it can merely be pulsed by a register read. So its value as a communication tool is inherently limited.

But the blue data line value is completely irrelevant except for when a clock pulse occurs- the NES game code has no way of accessing its value save through the clock strobe. This very cleanly narrows our search space for meaning: when the clock triggers, the game must know what it's looking for.

So. I see two possible interpretations (apart from the aliasing theory):

A) the clock, latch, and data lines are actually being used in a reasonable traditional manner, but in slow motion. It only pulses a clock infrequently because either the game code or the piano hardware can only prepare data infrequently. But if communication was observed over, say, the length of a musical beat rather than the typical length of a frame, that might be enough to transmit a meaningful number of keys at one key per clock pulse. The software, after all, only needs enough information to determine whether someone hit a particular note in a particular span of wallclock time.

B) It's a time-sensitive signal. It's a fixed blobby implicit time sensitive signal. And eff you very much, Software Toolworks and your blobby horse-drawn 5.25" floppies. Basically, from the point the latch falls, the piano starts an internal timer and waits for the latch to rise, with different meanings for different delays. And the protocol is to dial the correct number on a rotary phone using the latch line (and a gratuitous amount of throwaway instructions for sub-second timing on the NES) to invoke certain functions on the piano. One can only hope that the simplest form of the protocol is 1 latch drop followed by a series of invisible time windows in which popping a clock will return the value of a specific key, and re-twiddling the latch will tell the keyboard to play a note on its own. Because if it's anything more complex than that, we're throwing darts blindfolded.

I'll spend a bit more time musing over the traces, but if anyone else can capture and post similar records of the lines and what the game is doing at the time (I don't have sufficient equipment to do so), it would greatly help me narrow my hypotheses.

Edit 2: The lack of the dog barking in the night
Anyone else notice how in the familiar use case, the clock line is steady low and pulsed high, whereas in the Miracle case, it appears to be held high and pulsed low? That is immensely intriguing to me, and potentially profoundly significant. I'll need to go back over my notes, but I'm pretty sure my assertion in the first edit is correct: you as the NES programmer don't get to directly control the clock line. Even if you want to. You can directly write the latch, and you can directly read the data, but the clock is an autonomous entity which occurs automagically when you read the data. So if the default state of the clock is low and it only pulses high automatically on a read, I see no explanation for the Miracle trace other than aliasing error. The NES is flipping that line like mad, one can only hope in the process of reading 49 keys and 1 pedal per frame (plus possible status bits), and the capture was merely hitting it high every time save when some amount of processing caused a slight delay.

Edit 3: disregard the above. Looks like sir_cuitous was on the right track from the start, and Dwedit's already solved the problem. First post, second link - viewtopic.php?t=300
Figured it out... At least output anyway.
First the game writes 00 to $4016 for the start bit
Then does this 8 times:
* Writes a byte out to $4016, only the least significant bit is received
* Dummy Read from $4016 for some reason (why?)
Writes a 00 to $4016 for the stop bit

The bit order (after the start bit) is least significant bit first. The 8 sent bits form a byte.

The data itself is pure MIDI. Looks like it could be easily integrated into any emulator. It will probably need a special patch map, since the Miracle does not use general midi instruments.

I'll bet MIDI input is very similar, start bit, 8 data bits, stop bit.

So that's where I'll begin, and I can test whether reading is just as simple. I suspect it is, modulo suspicions already voiced that the first read will return 1 if data is available and 0 otherwise.
Re: Communicating with the Miracle Piano
by on (#132975)
One quick unrelated update: as tangentially suggested in ... 52&t=36962 , I have found that the enercell / RadioShack part number 273-0328 AT&T multi-voltage 9.10.2/13/13VAC 800mA adapter is sufficient for the Miracle, and it's barrel is even the right size. If you're making your own, the M-size barrel seems to be a good fit, although after finding the AT&T adapter, I didn't actually need to test an a-la-carte configuration.

I still would not as a general recommendation advise using a lower-amperage adapter than specified- put too much current load on a given rated voltage potential and the adapter will have a hard time maintaining that voltage potential. But since this one advertises sustaining a top-end 13V potential at 0.8A for a total of 10.4W power load, it's not beyond reason to think it can hold 10.4W total at its 12V setting, equivalent to 867mA current draw which, allowing for safety tolerances on both ends, seems to be "close enough" to 1000mA; also keeping in mind that the original supply and power architecture anticipated a worst-case driving not just the piano guts but likely the headphones, speakers, serial port and MIDI-out all at once. I would not try running this thing at full load on less than a 1000mA (12W) supply, and I'll definitely look for a more robust solution if the AT&T adapter starts heating up or cutting out, but fingers-crossed it will hold for just running the piano, headphones, and the chipset driving the NES connector pins (which in grand theory ought not to be a power draw at all since there's already a power line from the NES that any connecting hardware would normally be expected to get its logic-power from. Indeed, if the piano is trying to push its own voltage and ground to the NES, I could see some ugly current leakage going on that could damage both systems :P )
Re: Communicating with the Miracle Piano
by on (#133124)
Update: upon conversing with one of the original development engineers, more light is shed:
The interface to the Nintendo uses a clocked shift register. There are three signals, two are generated by the Nintendo itself (clock and load), and the third is data input to the Nintendo.
Normally, these signals make it easy to read the button controller using very simple hardware consisting of a shift register IC and some switches. As I remember, MIDI data was sent to the Nintendo without much, if any, modification, just conversion from the asynchronous serial format to this synchronous clocked format. MIDI data FROM the Nintendo to the Miracle was more complicated, and I believe it required use of the clock and load signals to carry data in the reverse direction. This required special software on both sides.

The Miracle data connector (a DB-25 connector), has both a standard serial MIDI interface, as well as the three-wire Nintendo interface on different pins. If you're interested, I still have schematics for the Miracle showing the connections. The data is standard MIDI over the serial port, though the baud rate may be non-MIDI standard when communicating to a PC serial port, which doesn't support the standard MIDI baud rate.

Miracle schematics

Nintendo Weird Box schematic and source code

The power supply does not have to be AC, as I recall. There is a bridge rectifier on the Miracle board to convert the AC to DC, and DC (or either polarity) would work as well.

I'll probably get these re-hosed on my own site by the time I have any of my own work to show, but if you have better hosting locations, by all means grab copies.
Re: Communicating with the Miracle Piano
by on (#133133)
I'm far more amused by that 8031schematic than I probably should be. Kinda delightful seeing how minimally they'd used it: the entire data bus (/RD) just can read from the funny latch ('595./G) that's used to receive data from the NES. The 8031's port 1 and one bit of port 3 is used to transmit 9-bit symbols to the NES, while the '393 automatically counts bits (and the '595 remembers them) so that the 8031can know when the NES has shifted in 8 bits.

It looks like in the keyboard itself there should be another 8032 microcontroller—fortunately both the 8031 and 8032 are ROMless versions, so they can't be hiding anything extra outside of the two 27C 'PROMs. Might be interesting to take a look at that.
Re: Communicating with the Miracle Piano
by on (#133171)
Also check out what Martin Korth wrote about the miracle piano: ... rollerport
Re: Communicating with the Miracle Piano
by on (#133185)
Thanks, Dwedit- that's perfect! Although I still don't regret doing my own research given what it led to on the PowerGlove front :D
Re: Communicating with the Miracle Piano
by on (#133186)
(repeating myself, because I think I phrased it poorly) If you have access to a ROM reader and are willing to take your miracle piano apart, dumping its firmware might be informative. There's definitely a 'PROM for the code (U17, 27C256P), and probably a ROM for wavetable data (U12, S631001-200).

Many of nocash's notes come from reverse engineering existing software, so his comments there, such as the bit:
  10th..12th  Unknown
  13th..16th  Unknown (would be ID Bit3..0 on other SNES controllers)
  17th and up Unknown
we now know (thanks to the firmware and schematic) don't do anything, even though it looks like the host side reads a bunch of extra times
Re: Communicating with the Miracle Piano
by on (#141112)
lidnariq wrote:
Many of nocash's notes come from reverse engineering existing software, so his comments there, such as the bit:
  10th..12th  Unknown
  13th..16th  Unknown (would be ID Bit3..0 on other SNES controllers)
  17th and up Unknown
we now know (thanks to the firmware and schematic) don't do anything, even though it looks like the host side reads a bunch of extra times

Please don't say that you want me to replace "Unknown" by "Don't do anything"!
What I was hoping for would be something like "Nth bit is always 1=Low" (or whatever stable/unstable results are returned by the hardware).
But what firmware/schematic are you referring to? If you meant these....

LoneKiltedNinja wrote:
Update: upon conversing with one of the original development engineers, more light is shed:
Nintendo Weird Box schematic and source code

Okay, that's interesting. But what is it?
Looks like a NES or SNES to MIDI adpator. It's not related to the miracle piano hardware.
Either it's some completely different product, or it's intended for using the miracle piano software with 3rd-party keyboards.

Searching for "Nintendo Weird Box" doesn't give any hits. Neither does searching "MIDI to Nintendo Converter" (the name used in the schematic), nor "AS-ST-000X" nor "NWB-II" nor "NWB100" (some of names used in the asm file).

Was that thing ever produced? Did anybody ever see it for real, or see any adverts mentioning it?
Re: Communicating with the Miracle Piano
by on (#141113)
Isn't the 'weird box' just the conversion cable that comes with the Miracle to connect it to the NES controller port?
Re: Communicating with the Miracle Piano
by on (#141116)
The piano cable is 7pin NES to 25pin piano.
The weird box is 7pin NES to 5pin MIDI.

EDIT: And weirder, it's supporting only one-way direction:
RXD is used for MIDI to NES.
TXD is just going to a LED.
Re: Communicating with the Miracle Piano
by on (#224919)
Here's an NT computer compatible version of the Miracle Piano Serial Port Driver. It is made by a modified Kawai GMegaRSNT serial driver with baud rate set to 9600 which is the only rate compatible with Miracle Piano.
BTW, The Miracle Piano Serial Driver that came with the Windows software is hard to find a download for it. The serial driver by Voyetra is only intended for Windows 3.1/95.
Re: Communicating with the Miracle Piano
by on (#224946)
From an old post of mine:

I had some official source code (printed, on paper) given to me for what appears to be the Genesis Miracle Piano software, back in 1997 or so. It's in C, and I think it's just an instrument/sample table (basically a big struct), but I'm not completely sure. I could provide a picture/scan of one of the pages (and all the rest if someone wanted) if anyone found it useful.

(It looks like it was developed for or on the Macintosh, which is no surprise considering it's a 68K system as well)

But then this:
I've discussed the contents with someone else -- it's not relevant to the actual reverse-engineering of the Miracle Piano itself, and doesn't have anything ultimately useful or definitive in it.