Cheapest bidirectional interface?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Cheapest bidirectional interface?
by on (#120777)
As a side project to dumping the weird cart, I have been thinking in creating a simple bidirectional PC-NES interface that would let me peek and poke values from CPU memory space to, for example, see how does the mapper works.

I know that there's already something that would let me do this, a CopyNES, but that requires modifying a NES and its case, and it doesn't work as-is of a Famicom or a Famiclone.

Therefore a simple bitbanged protocol using the lines available on a NES controller port would be better. One would plug in a cartridge containing a bootloader that would load into RAM, and then you can swap the cartridge with the one you want to dump.

I would like also to keep the hardware to a minium, using as few parts as posible. My initial idea was, using a single 7474 and a 7400, build a two bit serial FIFO, whose clock would be NES controller CLK anded with the inversion of the last bit from the FIFO, and whose input data would be OUT0.

The NES will wait until the PC sets the second (last) latch from the 7474 to one, and keeps polling the read line until this goes low. The bits in the FIFO would not shift as the last bit is one.

When the PC wants to starts a transfer, it would set first latch to the bit it wants to send, and then it clears the second (last) latch. The NES while polling this register, will detect that it now reads as zero, and the next read would be pushed on the bit buffer.

To reply, the NES will wait until the FIFO is clear, and will then send a 1, and then the bit it wants to transfer. Therefore, if the FIFO is "10", the bit is a 0, and if it is "11", then the bit is a 1. As upper bit is 1, the NES can read the FIFO last bit without rotating the bits on the buffer. The PC will read this, and then it will clear the buffer, and wait for the next bit.

I have no CAD software right now, so I can't provide a schematic.

Another approach I though about was bitbanging SPI through the controller port, because there are enough signals to communicate with a SPI device, which could be a SRAM the PC could fetch at any time. However, SPI buses aren't multimaster, so we would have to add "busy" control signal, but the NES only has a single input.
Re: Cheapest bidirectional interface?
by on (#120782)
Here's what I've used with great success: Disable CIC. Connect PC to NES via controller port. Put bootloader on EPROM/whatever cart. Boot with cart. Run "hotswap" program (does continual sprite DMA for several seconds to reduce chance of crash) and remove cart. Insert one to be probed. Send test program via PC. Have each program end by re-running bootloader so you can send a new program.

You can just get a cheap PL2303-based USB-5V RS-232 converter off eBay for a few dollars and bit-bang it from the NES. 57600 bps is very reliable, and 115200 works decently. If you want a synchronous interface, a $16 Teensy would do well, with built-in USB, SPI, USART, etc. hardware and good example code.
Re: Cheapest bidirectional interface?
by on (#120809)
Bitbanging serial is OK if you know beforehand the CPU speed, but I have PAL (~26.6/16 MHz), Dendy (~26.6/15 MHz) and NTSC (~21/12 MHz) consoles, that's why I were looking for a synchronous interface, though I might end up using this if I have no better option.
Re: Cheapest bidirectional interface?
by on (#120814)
I've written some serial code for the NES that measures the serial speed then adjusts the bit timing to this. It could handle a wide range of rates without needing to know the NES clock frequency or comm rate. One version handles 9600 to 28800 bps, another version handles about 50000-62000 bps (nominal 57600).

Synchronous OTOH is nice because the NES can accept things however slowly it wants.
Re: Cheapest bidirectional interface?
by on (#120815)
It's really quite easy to detect which machine you're running on: http://wiki.nesdev.com/w/index.php/Detect_TV_system

The math works out that the Dendy and NTSC use the same asynchronous timing; they're only 1% off from each other. 8N1 asynchronous serial is robust up with to about 3-5% baud rate error.

If you really want a USB SPI slave, it'll be easiest to use a USB-enabled microcontroller.
Re: Cheapest bidirectional interface?
by on (#120881)
lidnariq wrote:
The math works out that the Dendy and NTSC use the same asynchronous timing; they're only 1% off from each other. 8N1 asynchronous serial is robust up with to about 3-5% baud rate error.

Good point. In that case, the bootloader I've posted about a while back handles this clock selection.

Quote:
If you really want a USB SPI slave, it'll be easiest to use a USB-enabled microcontroller.

Yep. The hardware is so cheap and available these days, and it makes your design usable by almost anyone (including you at some later date when you don't have a PC with a parallel port anymore).
Re: Cheapest bidirectional interface?
by on (#120884)
In CopyFamiClone I used FT245B.