NES to USB Keyboard interface?

Discuss hardware-related topics, such as development cartridges, CopyNES, PowerPak, EPROMs, or whatever.
User avatar
bitcores
Posts: 65
Joined: Thu Apr 20, 2023 3:09 am
Location: Japan

Re: NES to USB Keyboard interface?

Post by bitcores »

I really wanted to avoid making a fourth consecutive post, but this update is kinda necessary.

I did find a library that enabled a USB host port on the PIO interface (don't know how I missed it earlier) so I scrapped the whole PS/2 thing and went with a USB port. It even supports USB hubs.
I have also made a "reference" PCB design and have finished testing it. It seems to be working fine, aside from USB3 hubs causing overly high power draw when plugged in.
DSC_2294.JPG
All four of the modes I planned to implement are working; Keyboard Mouse Host, Family Keyboard emulation, Subor emulation (KB and M), Family Keyboard + Hori Track (I'm getting better at U.S. Championship V'ball).
But I have a lot of refactoring of the code to do. It's more about cleaning up now than implementation.

The BOM cost of building it is quite low, so I'd be interested to see if anyone else puts one together and tests it out.
DSC_2293.JPG
If someone wants one aimed more directly at NES, we could discuss what features need to be available on it, how it would connect to the console (using a connector or just soldering wires from an extension cable onto it), etc

And once again, everything is in my github https://github.com/bitcores/pico-ps2famikb/
You do not have the required permissions to view the files attached to this post.
Pokun
Posts: 3442
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES to USB Keyboard interface?

Post by Pokun »

That's pretty exciting, although I'm sad to see PS/2 go.


bitcores wrote: Tue Oct 22, 2024 4:16 am I really wanted to avoid making a fourth consecutive post, but this update is kinda necessary.
Please keep posting, I'm reading everything even if I'm not posting every time.
Besides there are several days between the posts so it doesn't really count as double-posting.
k6lcm
Posts: 3
Joined: Tue Nov 26, 2024 2:57 pm

Re: NES to USB Keyboard interface?

Post by k6lcm »

This looks awesome @bitcores. Do you have a gerber file for the custom PCB? I didn't see it in the repo.
bitcores wrote: Tue Oct 22, 2024 4:16 am I really wanted to avoid making a fourth consecutive post, but this update is kinda necessary.

I did find a library that enabled a USB host port on the PIO interface (don't know how I missed it earlier) so I scrapped the whole PS/2 thing and went with a USB port. It even supports USB hubs.
I have also made a "reference" PCB design and have finished testing it. It seems to be working fine, aside from USB3 hubs causing overly high power draw when plugged in.
DSC_2294.JPG
All four of the modes I planned to implement are working; Keyboard Mouse Host, Family Keyboard emulation, Subor emulation (KB and M), Family Keyboard + Hori Track (I'm getting better at U.S. Championship V'ball).
But I have a lot of refactoring of the code to do. It's more about cleaning up now than implementation.

The BOM cost of building it is quite low, so I'd be interested to see if anyone else puts one together and tests it out.
DSC_2293.JPG
If someone wants one aimed more directly at NES, we could discuss what features need to be available on it, how it would connect to the console (using a connector or just soldering wires from an extension cable onto it), etc

And once again, everything is in my github https://github.com/bitcores/pico-ps2famikb/
bixxewoscht
Posts: 4
Joined: Fri Oct 11, 2024 5:53 am

Re: NES to USB Keyboard interface?

Post by bixxewoscht »

Great work!
I guess it would also be possible to incorporate USB Controller support through this?

Also this would make for a nice Addon for the NES Hub, unfortunately the OUT1-3 signals are on another Addon connector than the D1-4 signals, so it would require 2 cables and thus become clunky.
User avatar
rainwarrior
Posts: 8764
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada

Re: NES to USB Keyboard interface?

Post by rainwarrior »

Is there a cost effective place to have a PCB of this size made? (Is there a trick to getting a cheaper price from PCBWays? There are so many options and I have no idea if there's something I'm missing.) Though, I guess I could just build it on breadboard instead if not.
User avatar
bitcores
Posts: 65
Joined: Thu Apr 20, 2023 3:09 am
Location: Japan

Re: NES to USB Keyboard interface?

Post by bitcores »

k6lcm wrote: Tue Nov 26, 2024 2:58 pm This looks awesome @bitcores. Do you have a gerber file for the custom PCB? I didn't see it in the repo.
The gerber files are inside the zip archive in the referencepcb directory. I should have named it clearer, my bad.
bixxewoscht wrote: Wed Nov 27, 2024 4:46 am Great work!
I guess it would also be possible to incorporate USB Controller support through this?

Also this would make for a nice Addon for the NES Hub, unfortunately the OUT1-3 signals are on another Addon connector than the D1-4 signals, so it would require 2 cables and thus become clunky.
I don't see why it wouldn't be possible to add USB Controller support to it, but I don't know the extent to which the Pico_PIO_USB library may need changes to ease the support in.
Considering the NES Hub already has support for input devices and communicating with the NES sorted, I think that adding a USB host port to it would probably be simpler than connecting my interface to it through the Addon connectors it has.
rainwarrior wrote: Wed Nov 27, 2024 10:23 pm Is there a cost effective place to have a PCB of this size made? (Is there a trick to getting a cheaper price from PCBWays? There are so many options and I have no idea if there's something I'm missing.) Though, I guess I could just build it on breadboard instead if not.
I thought PCBWay had a similar pricing structure to JLCPCB, but maybe I was wrong. I printed mine with JLCPCB, you can just drag and drop the zip file onto the "Upload gerber file" box and with the default options (perhaps just removing the order number) it's $2 for 5 pieces. Shipping options depend on the destination, but there should be some cheap options available (I always go with something cheap and it arrives in Japan within a week).
I realize I haven't really marked on the PCB the pins of the expansion port (the little arrow points to Pin 1 which is GND and the pinout matches the Famicom Expansion Port), nor the orientation of the Logic Level Converters (High side 5V is facing Expansion Port, Low side 3.3V is facing the Pico) but the rest should be OK, I think.
I'm still new at this.
k6lcm
Posts: 3
Joined: Tue Nov 26, 2024 2:57 pm

Re: NES to USB Keyboard interface?

Post by k6lcm »

@bitcores, thanks! I found it shortly after I posted so it was probably more me just missing it. However, am I still missing the wiring between the VGA connector and the NES expansion port pins? I don't seem to see that described in any of the readme files. Or do I understand correctly that I could actually wire it up to the Player 2 controller port on the North American NES and get full keyboard compatibility and bypass the finicky nature of trying to tap into the bottom side expansion port altogether?
User avatar
rainwarrior
Posts: 8764
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada

Re: NES to USB Keyboard interface?

Post by rainwarrior »

bitcores wrote: Fri Nov 29, 2024 2:23 am
rainwarrior wrote: Wed Nov 27, 2024 10:23 pm Is there a cost effective place to have a PCB of this size made? (Is there a trick to getting a cheaper price from PCBWays? There are so many options and I have no idea if there's something I'm missing.) Though, I guess I could just build it on breadboard instead if not.
I thought PCBWay had a similar pricing structure to JLCPCB, but maybe I was wrong. I printed mine with JLCPCB, you can just drag and drop the zip file onto the "Upload gerber file" box and with the default options (perhaps just removing the order number) it's $2 for 5 pieces. Shipping options depend on the destination, but there should be some cheap options available (I always go with something cheap and it arrives in Japan within a week).
Thanks for the recommendation, JLCPCB does seem to have a substantially better price for a PCB of this size. I'll probably try to build this myself sometime next month.
User avatar
bitcores
Posts: 65
Joined: Thu Apr 20, 2023 3:09 am
Location: Japan

Re: NES to USB Keyboard interface?

Post by bitcores »

I come with a gift.
example.png
I ported wozmon to NES quite some time ago, and even hacked in the keyboard support but I have reverted most of the code to the original wozmon code and tried to build a helper to handle the keyboard input for both Family Basic Keyboard and Keyboard Mouse Host, and the conversions to ASCII format.
I still have to do some SHIFT handling (currently ; works as : on Keyboard Mouse Host) but it is functional at least. Code and ROM in github. I have built it for a one chip cartridge, but should still work in flash carts, I think.

https://github.com/bitcores/nesmon
You do not have the required permissions to view the files attached to this post.
Pokun
Posts: 3442
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES to USB Keyboard interface?

Post by Pokun »

A fantastic present!
Does it work on hardware though? Mesen seem to suggest that there is problems with OAM DMA (diagonal sprites all over).
User avatar
bitcores
Posts: 65
Joined: Thu Apr 20, 2023 3:09 am
Location: Japan

Re: NES to USB Keyboard interface?

Post by bitcores »

Pokun wrote: Sun Jan 05, 2025 7:31 am A fantastic present!
Does it work on hardware though? Mesen seem to suggest that there is problems with OAM DMA (diagonal sprites all over).
It works on my FC, at least. I actually don't use OAM DMA for it, it's all background tile updates because there are so many characters per line.
I have Mesen configured to match what my FC does, so if it is borked with your Mesen settings or on hardware, let me know and I'll see if I can fix it up to make it more compatible.
Pokun
Posts: 3442
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES to USB Keyboard interface?

Post by Pokun »

It seems to be: Settings -> NES -> Emulation -> Enable PPU OAM Decay

Enable it and the sprites should be lined up diagonally over screen if there is some problem with OAM DMA. Not using OAM DMA might be the problem here as that means garbage sprites can show up anywhere as OAM decays. On real hardware it won't be so noticeable, Mesen is aggressive using this setting to allow us to detect such bugs right away.

I think you just need to clear your OAM buffer (normally RAM page 2: $0200 to $02FF) by setting all Y-coordinates to any value between $F0 and $FF and then run OAM DMA on RAM page 2 each vblank to make sure sprites stays off-screen. Or do you need all the RAM for the monitor?
Fiskbit
Site Admin
Posts: 1380
Joined: Sat Nov 18, 2017 9:15 pm

Re: NES to USB Keyboard interface?

Post by Fiskbit »

If you're not using sprites at all, you either need to do OAM DMA to clear OAM or just turn off sprite rendering; otherwise, you'll have some decayed analog state. The diagonal line in Mesen is supposed to be a tell-tale sign that OAM has decayed, rather than 'accurate' emulation of decay (which would be hard to do realistically). It's overly aggressive in that the row pointed at by $2003 shouldn't be able to decay but does in Mesen, but it's otherwise great for development.
User avatar
bitcores
Posts: 65
Joined: Thu Apr 20, 2023 3:09 am
Location: Japan

Re: NES to USB Keyboard interface?

Post by bitcores »

Thanks guys. I really haven't done enough research into coding for NES so no doubt I'm making all sorts of mistakes.
I elected to just disable sprite rendering seeing I'm not using it.

--edit--
Actually, I just noticed that someone forked it a couple weeks ago and fixed that along with other things I was doing wrong.
I'm going to merge what I can.
Pokun
Posts: 3442
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES to USB Keyboard interface?

Post by Pokun »

Ah right, turning off sprite rendering is the way to go if not using sprites of course, didn't think about that.