New approach to the fabled NES ethernet adapter

Discuss hardware-related topics, such as development cartridges, CopyNES, PowerPak, EPROMs, or whatever.

Moderators: B00daW, Moderators

User avatar
Wookie
Posts: 76
Joined: Sat Mar 01, 2008 5:06 pm
Location: Seattle, WA
Contact:

Post by Wookie »

Here are some extra credit points:

1. Figure out a good source for an 8x8 matrix keyboard.
2. Figure out if it is possible for us to hook up some 8-bit latches to the keyboard and then what it will take to hook it to the second controller port so that when the 2A03 reads the status of the controllers, the first 8-bit latch comes in as the button states for controller 2 and the second 8-bit latch comes in as the button states for controller 4.

I've seen several sources on the web for NES male connectors. Combine the ingredients and we'd have a simple keyboard for the NES that only takes up a single controller port. I'm thinking a keyboard is going to be something we'll want once the EtherNES is working. (IRC anyone?, In-game chat? Smack talking in a game lobby? You get the point.)
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

But watch out for DPCM double clocks. With a report that long (64 bits), the repeat-and-compare method might not work so well. So the keyboard's circuitry itself would have to smooth out double clocks. I seem to remember MMC3 doing the same thing for PPU A12, which cycles rapidly at the end of each scanline, before it hits the scanline counter.

An authentic controller reading loop, even an unrolled one, won't clock faster than more than once every 11 CPU cycles, or 163 kHz:

Code: Select all

.repeat 8
  lda $4017
  lsr a
  rol 0
.endrepeat
Anything faster than that is probably a double clock.
User avatar
B00daW
Posts: 586
Joined: Thu Jan 03, 2008 1:48 pm

Post by B00daW »

I know SLIP to work fairly well on Linux but have had no success making it work via Windows XP. Could that be an easier alternative than CAT5?
User avatar
Wookie
Posts: 76
Joined: Sat Mar 01, 2008 5:06 pm
Location: Seattle, WA
Contact:

Post by Wookie »

Regarding the keyboard, I'm thinking it would probably be cheaper and easier just to use a PIC 16F84 to power a PS/2 keyboard dongle. The PIC would interface with the PS/2 keyboard and then send the scan codes when the 2A03 clocks in the button states. Since there are 8 buttons, that would mean that the dongle could support up to 255 scan codes. The PIC wouldn't need to translate the PS/2 protocol at all, it would just read in the scan code from the PS/2 keyboard and pass that along as the button states to the 2A03.

The PIC would be responsible for sending commands to the keyboard to set the indicator lights and stuff so it would have to be smart enough to maintain the keyboard state.

The real trick would be to figure out a way to detect the presence of a the keyboard adapter from the 2A03. Maybe there is something we could do with pins 6 and 7 on the controller port to signal that the device plugged into a given controller port is a PS/2 keyboard adapter. Do any of the other NES peripherals like Rob, power pad, or light gun use those pins?

We'd need to be able to detect the presence of the keyboard adapter so that we can decide whether to use a controller based character entry scheme common to old NES games or to expect the user to type in the text using their keyboard. Or make it a selectable option where if they select the keyboard and we don't detect a keyboard plugged in, we can put up a message that says, "please plug in your keyboard."

Ok, so again, this is possible but the biggest hurdle will be finding the connectors. I've found a source for the male connectors: http://www.parallax.com/Store/Component ... fault.aspx but that is not what we need. We actually need the female connector--the one on the end of the controller cord. I know that there are companies that make them because the same source for the male connectors also sells a retro game pad with the female connector on the end: http://www.parallax.com/Store/Accessori ... fault.aspx They must be getting them from somewhere, the only question is where.

I'm working on the expansion port connector with the Sullins connector people, but I'm now shining the bat light and asking for help on finding a source for the female NES connector.
User avatar
Wookie
Posts: 76
Joined: Sat Mar 01, 2008 5:06 pm
Location: Seattle, WA
Contact:

Post by Wookie »

Whoa, I just realized that there may be an even easier solution for the EtherNES than the PIC. Check this chip out: http://www.wiznet.co.kr/en/pro02.php?&page=1&num=25

The Wiznet 5100 has it's own internal TCP/IP stack, 16 kb of transmit memory, and integrated ethernet MAC/PHY. The best part is that it is designed to work with old 5V logic as well as 3.3V logic. If we run the Wiznet 5100 in "indirect addressing" mode, then we only need two address lines, /CS, /WR, /RD, /INT, and D0-D7 data lines which is exactly what we have worked out already. That means we'd only need to route one address line and the R/W from the CPU to the expansion port through the cart.

The Wiznet W5100 is a $5 part from here: http://www.ewiznet.com/goods_detail.php?goodsIdx=104 and the external components are minimal. There just needs to be a 25 MHz crystal and some filtering capacitors and some resistors plus the RJ-45 MagJack, which we were already planning to use.

The biggest benefit of going with the Wiznet part instead of the PIC is that we don't have to write any code other than 2A03 code. With the PIC, we were going to have to write code that interfaced with the 2A03 and the TCP/IP stack implementation from Microchip.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Wookie wrote:The real trick would be to figure out a way to detect the presence of a the keyboard adapter from the 2A03. Maybe there is something we could do with pins 6 and 7 on the controller port to signal that the device plugged into a given controller port is a PS/2 keyboard adapter. Do any of the other NES peripherals like Rob, power pad, or light gun use those pins?
Seven signals are present on the controller port: 0 V, 5 V, clock, strobe out, data in D0, data in D3, and data in D4. The Zapper uses D3 and D4 for the button state and the photodiode state. The Power Pad uses D3 and D4 much as the standard controller uses D0.
User avatar
Wookie
Posts: 76
Joined: Sat Mar 01, 2008 5:06 pm
Location: Seattle, WA
Contact:

Post by Wookie »

So I guess, the easiest way would be to make D3 or D4 just return a well know bit sequence over and over again. We could hook it up so that subsequent reads to D3 always return 11110000 or something. The code could read from the register a bunch of times and if it gets 11110000 on D3 for each set of 8 reads, then it can safely assume the keyboard adapter is plugged in.
User avatar
Memblers
Site Admin
Posts: 3901
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers »

B00daW wrote:I know SLIP to work fairly well on Linux but have had no success making it work via Windows XP. Could that be an easier alternative than CAT5?
I couldn't get SLIP to work in XP either. I wanted to run Contiki on Squeedo using SLIP.

If there's a reasonable way to get SLIP working on XP it would be much easier, mostly because the hardware I've had for years would already work.

Contiki works well with CC65 (but the NES libraries are faulty somewhere). This may be worth another look with any working network access.
User avatar
Memblers
Site Admin
Posts: 3901
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers »

Wookie wrote: The Wiznet 5100 has it's own internal TCP/IP stack, 16 kb of transmit memory, and integrated ethernet MAC/PHY.
Nice, I remember looking at that chip before, but it never looked better than now. That's a huge buffer.

The biggest benefit of going with the Wiznet part instead of the PIC is that we don't have to write any code other than 2A03 code. With the PIC, we were going to have to write code that interfaced with the 2A03 and the TCP/IP stack implementation from Microchip.
Is there any potential downside to it? It'd be really bad if the NES could somehow get slammed with a bunch of IRQs because of random connection attempts (internet background noise, or whatever it'd be called). I'm mostly a newb at this, so I don't know if that's a problem left up to the chip or the NES to handle (or if it even is a problem).
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Memblers wrote:Is there any potential downside to it? It'd be really bad if the NES could somehow get slammed with a bunch of IRQs because of random connection attempts (internet background noise, or whatever it'd be called). I'm mostly a newb at this, so I don't know if that's a problem left up to the chip or the NES to handle (or if it even is a problem).
Don't forward any ports from your NAT gateway to the NES, and none of the background noise will reach the NES.
User avatar
Jon
Posts: 47
Joined: Fri Apr 03, 2009 10:55 pm
Contact:

Post by Jon »

The Microchip ENC28J60 is a SPI-based Ethernet chip (no processor), if you don't mind serial-port like throughput to the NES by bit-banging SPI through an I/O pin then you could do all the TCP/IP stuff in 2A03-land instead of PIC-land. Or a 4-bit counter (reset on 8 to make it a 3-bit counter) could be attached to a clock and serial-parallel shift register to latch onto the SPI data through an I/O port instead. At that point that WIZnes WS5100 or the PIC would be less complicated than doing SPI to parallel conversion in hardware. It would also be pretty straight forward to attach a CS8900A ethernet chip (Cirrus Crystal LAN) on there, that supports an 8-bit I/O mode and you would just do the TCP/IP in 6502-land (uIP from Contiki works)

But I would almost recommend using the cartridge slot instead of expansion port for all of this. Sure it's a semi-custom mapper, just modify an existing mapper to give you some space for Ethernet I/O. But it's not like the firmware to use the Ethernet isn't going to be custom anyways. Being able to play unmodified Contra/Zelda/etc and use Ethernet is not going to happen if you use the expansion port anyways.
User avatar
Wookie
Posts: 76
Joined: Sat Mar 01, 2008 5:06 pm
Location: Seattle, WA
Contact:

Post by Wookie »

I was reading through the wiznet data sheet and the interrupt thing won't be a problem unless it listening on an open port that is being flooded with connection requests, but that is a problem on regular PC's too.

The wiznet part only yanks on the interrupt pin when a packet is received on an already established and connected socket, so no worries. The 2A03 will only be interrupted when we want it to be interrupted.
User avatar
Wookie
Posts: 76
Joined: Sat Mar 01, 2008 5:06 pm
Location: Seattle, WA
Contact:

Post by Wookie »

I have a plane trip tomorrow and then again on Friday. I'll take along data sheet print outs and see if I can bang out an initial schematic for the EtherNES. Even if the connector takes more time and effort, I'll be able to at least build an initial batch of 4 EtherNES peripherals out of the parts I have. I have a handful of 48 pin female edge connectors that I can cut in two and glue in spacers to give them the correct opening size. I already have one built that correctly mates with the expansion port.

Oddly enough, it is looking like the EtherNES will be pretty "cheap". The wiznet chip is $5. The magjack is $2 and the rest of the components can't be more that $10 total. With $10 for each PCB in small quantities, we're looking at $30 in parts depending on the cost of the connector.
User avatar
Wookie
Posts: 76
Joined: Sat Mar 01, 2008 5:06 pm
Location: Seattle, WA
Contact:

Post by Wookie »

Alright, I just had time to desolder the expansion port connector from my spare NES and I'll be FedEx'ing it to the Sullins' engineering department to get a quote for custom connectors that mate with it. Cross your fingers that the quote will be reasonable.

I just emailed Sullins to get an address to mail the expansion port connector to. I sure hope this works out.
User avatar
Wookie
Posts: 76
Joined: Sat Mar 01, 2008 5:06 pm
Location: Seattle, WA
Contact:

Post by Wookie »

Jon wrote: But I would almost recommend using the cartridge slot instead of expansion port for all of this. Sure it's a semi-custom mapper, just modify an existing mapper to give you some space for Ethernet I/O. But it's not like the firmware to use the Ethernet isn't going to be custom anyways. Being able to play unmodified Contra/Zelda/etc and use Ethernet is not going to happen if you use the expansion port anyways.
I'm not trying to make old games use ethernet. And using the cart slot is not an option. I want to build a legitimate expansion device for the NES that can be used by multiple games. The Wiznet part is by far the easiest way to go if we can get a part that mates with the expansion port. The Wiznet part has an "indirect addressing" mode that only needs two address lines and eight data lines in addition to the RD, /WR, /INT, power and ground. I've already got a schematic.

The firmware to use a Wiznet based ethernet adapter would be fairly simple and small. It could easily be implemented as a library that game developers could use. Any game that wants to use the ethernet device would have to route a couple address lines to the expansion port pins in the cart slot and that's it. Since the Wiznet handles all of the TCP/IP internally, there's only a bunch of registers the 6502 firmware would have to set up and interact with. The Wiznet chip is also 5V capable even though it is a 3.3V device so there is no 5V->3.3V stuff needed.

I just emailed Sullins about designing an expansion port adapter connector part. They have a few connectors that are extremely close to what is needed. I am ordering the parts needed to put together a prototype using my hacked connector and some proto boards. I just got a new job though so things will likely slow down but I'm going to try hard to keep things rolling.
Post Reply