NES to USB Keyboard interface?

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

Moderators: B00daW, Moderators

lidnariq
Posts: 9700
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: NES to USB Keyboard interface?

Post by lidnariq » Fri Apr 03, 2020 2:33 pm

It sounds to me like it's one of those situations where it doesn't matter what the choice is, just that there was a specification at all.

I was going to suggest a possible hardware implementation, but unfortunately what I was thinking of (74HCT595s) won't allow more than 8 bits per serial line output, and you specified more.

calima
Posts: 1194
Joined: Tue Oct 06, 2015 10:16 am

Re: NES to USB Keyboard interface?

Post by calima » Sat Apr 04, 2020 3:36 am

Memblers, you may want to look deeper at cc65. It has a loadable drivers model for the platforms that can have many input devices.

User avatar
Memblers
Site Admin
Posts: 3884
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: NES to USB Keyboard interface?

Post by Memblers » Mon Apr 06, 2020 5:28 am

Looking into the USB specs, USB returns those scancodes as an array of currently pressed keys, it must be the USB host driver and OS generating press and release events (along with key repeats, sticky keys, etc.). It seems best to maybe take this USB scancode set and customize it into a synchronous PS/2-like interface. See the attached file for what I'm thinking. One byte per key press, using D7 to select press/release for up to 127 keys.
NES keyboard DRAFT.txt
(6.25 KiB) Downloaded 54 times
I cut out stuff that one wouldn't see on most keyboards, like F12-F24 keys, copy, paste, help, find, power, etc. I kept some of the media controls because there was going to be a little room left over, and those seem to be the only "extra" keys I use sometimes. I'm open to changing it, if it can be improved. I have some other projects to complete first, but after that I'd like to work on keyboard support.
calima wrote:
Sat Apr 04, 2020 3:36 am
Memblers, you may want to look deeper at cc65. It has a loadable drivers model for the platforms that can have many input devices.
Thanks, I kept running into the o65 format document, but I've been looking at it from the wrong end, and wasn't clear on where it's used in cc65. I see it now in those input drivers, that helps. I've been using cc65 forever, and there's still new stuff to find in it.

nocash
Posts: 1231
Joined: Fri Feb 24, 2012 12:09 pm
Contact:

Re: NES to USB Keyboard interface?

Post by nocash » Mon Apr 06, 2020 2:03 pm

I am really wondering if this will end up anywhere. The PSX, for example, does have at least 8 different keyboard adaptors, without anyone using them.
It is probably not so easy to make something that will convince users, game devrs, emu devrs, and hardware devrs to use and support that kind of adaptor.
Or to convince anyone that they need a keyboard at all ; )

Code: Select all

#define KEY_1 0x1e // Keyboard 1 and !
#define KEY_2 0x1f // Keyboard 2 and @
#define KEY_3 0x20 // Keyboard 3 and #
Yeah, that would be nice and simple, but the punctuation marks are all different in other countries (not to mention stuff like qwerty, qwertz, azerty keyboards).
Best would be having an option that allows to switch between receiving scancodes or characters (or both at once).
An emulator could automatically use the characters from the OS, and an USB adaptor could be somehow configured accordingly, so that games won't have to deal with country specific differences.
homepage - patreon - you can think of a bit as a bottle that is either half full or half empty

Pokun
Posts: 1512
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES to USB Keyboard interface?

Post by Pokun » Tue Apr 07, 2020 2:35 am

Exactly! At least it would need to be compatible with the existing Family BASIC keyboard (as opposed to inventing a totally new device incompatible with anything that already exists). I've made homebrew for the keyboard and I have plans to use the tape recording feature as one of several alternative ways to transfer data between cartridges in another homebrew project. It would be great if there was an easy way to hook up a USB keyboard to work as a Family BASIC keyboard.

tepples
Posts: 22055
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: NES to USB Keyboard interface?

Post by tepples » Tue Apr 07, 2020 6:55 am

That keyboard connects through player 2 D4-D1, but only D4, D3, and D0 are available at the controller port. Thus any compatible adapter would need to connect to the NES through the expansion connector on the bottom of an NES-001. This is not a standard connector.

User avatar
rainwarrior
Posts: 7843
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: NES to USB Keyboard interface?

Post by rainwarrior » Tue Apr 07, 2020 10:07 am

Pokun wrote:
Tue Apr 07, 2020 2:35 am
At least it would need to be compatible with the existing Family BASIC keyboard (as opposed to inventing a totally new device incompatible with anything that already exists).
Creating a clone replacement for the Family BASIC keyboard is a much different goal, IMO. That's one that doesn't need a whole lot of discussion or spec, either. If you want to make one, I'm all for it, but if it already solved my problem I wouldn't have started this thread.

As far as this purpose goes, it's just barely functional and has a lot of problems. Tepples mentioned what is probably the most crucial one. Trying to continue building on that would make implementation of just about everything more difficult.

When you say "incompatible with anything that already exists", what Family BASIC keyboard supporting software are you talking about? Is there a list of games that actually support it somewhere? I know of a few games that use the data recorder (which really has very little to do with the keyboard itself, a wholly separate component in everything but physical package), but what actually uses the keyboard?

If you're writing new software you can support more than one keyboard protocol if you want. I think in the project that the spec I wrote was intended for, I'll probably end up writing Family BASIC keyboard support as well (and SNES mouse), but I want to have a more suitable keyboard and mouse interface available.

User avatar
rainwarrior
Posts: 7843
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: NES to USB Keyboard interface?

Post by rainwarrior » Tue Apr 07, 2020 2:31 pm

Memblers wrote:
Mon Apr 06, 2020 5:28 am
Looking into the USB specs, USB returns those scancodes as an array of currently pressed keys, it must be the USB host driver and OS generating press and release events (along with key repeats, sticky keys, etc.). It seems best to maybe take this USB scancode set and customize it into a synchronous PS/2-like interface. See the attached file for what I'm thinking. One byte per key press, using D7 to select press/release for up to 127 keys.

NES keyboard DRAFT.txt

I cut out stuff that one wouldn't see on most keyboards, like F12-F24 keys, copy, paste, help, find, power, etc. I kept some of the media controls because there was going to be a little room left over, and those seem to be the only "extra" keys I use sometimes. I'm open to changing it, if it can be improved. I have some other projects to complete first, but after that I'd like to work on keyboard support.
This looks sensible to me. A slight adaptation of the USB set to keep it under $80 allowing make/break codes. I don't have any commentary on the arbitrary "extra" collection at $66+... I don't have any need or plans to use any keys in that range anyway.

Edit: Actually, I'm realizing that I intentionally didn't include the modifier keys in my spec, expecting them to have make/break codes, so those are important to me, but you did relocate those to the end, which does feel like the least arbitrary place to put them. ;)

Pokun
Posts: 1512
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES to USB Keyboard interface?

Post by Pokun » Wed Apr 08, 2020 2:47 am

rainwarrior wrote:
Tue Apr 07, 2020 10:07 am
Pokun wrote:
Tue Apr 07, 2020 2:35 am
At least it would need to be compatible with the existing Family BASIC keyboard (as opposed to inventing a totally new device incompatible with anything that already exists).
Creating a clone replacement for the Family BASIC keyboard is a much different goal, IMO. That's one that doesn't need a whole lot of discussion or spec, either. If you want to make one, I'm all for it, but if it already solved my problem I wouldn't have started this thread.

As far as this purpose goes, it's just barely functional and has a lot of problems. Tepples mentioned what is probably the most crucial one. Trying to continue building on that would make implementation of just about everything more difficult.

When you say "incompatible with anything that already exists", what Family BASIC keyboard supporting software are you talking about? Is there a list of games that actually support it somewhere? I know of a few games that use the data recorder (which really has very little to do with the keyboard itself, a wholly separate component in everything but physical package), but what actually uses the keyboard?

If you're writing new software you can support more than one keyboard protocol if you want. I think in the project that the spec I wrote was intended for, I'll probably end up writing Family BASIC keyboard support as well (and SNES mouse), but I want to have a more suitable keyboard and mouse interface available.
I see, so you are speculating about making a keyboard and mouse interface for a specific purpose. Possibly as an aid in making homebrew somehow?

As you most likely already know, there is only one official keyboard for the Famicom and the licensed games that support the keys are the various versions of Playbox/Family BASIC and those built-in BIOS calls in the FDS RAM Adapter (which no FDS games uses AFAIK). The known games to use the tape recorder part are:
Family Basic
Excitebike
Wrecking Crew
Mach Rider
Loderunner (only works if keyboard is detected)
Castle Excellent (also supports Turbo File)
Arkanoid II
There is also a rumour that Nuts & Milk supports it, but it's probably false.
As you say the tape recorder is really another device and there are a number of non-keyboard peripherals that comes with it, including the S.D. Station I think. I don't know for sure but these might not work with Loderunner though, since the save/load menu only appears if it detects a keyboard, and I don't know if all these are detected as such.
I've also seen a few homebrew that supports the keys and at least one that uses the tape recorder for saving.

I started making a text input system for the keyboard myself and I've played with the thought of an assembler, so you could program in 6502 on the NES natively. It's not something I'm working on now or anything though.

User avatar
rainwarrior
Posts: 7843
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: NES to USB Keyboard interface?

Post by rainwarrior » Wed Apr 08, 2020 11:22 am

Pokun wrote:
Wed Apr 08, 2020 2:47 am
I see, so you are speculating about making a keyboard and mouse interface for a specific purpose. Possibly as an aid in making homebrew somehow?
I have one main project in mind, and a few others it could apply to. I don't really want to lay out my plans here, but here's some goals:

1. Relatively easy to build with inexpensive and currently available electronics. USB keyboard and mouse are ubiquitously available and still made. Family BASIC keyboards are not. I think you could adapt a USB Keyboard to be Family BASIC compatible perhaps, but I think translating to a matrix interface like that is a lot less straightforward than what I'm proposing.

2. Plug into an unmodified NES. (Critical fail for Family BASIC keyboard.)

3. Enter text easily. Family BASIC is OK at this, but it's missing a lot of useful common keys. Might be possible to extend its report, but not sure it's practical (won't the existing keyboard loop after 1 more row?).

4. Have a mouse as well. Here the SNES mouse is available and functional, but has a number of issues similar to the Family BASIC keyboard.

5. When emulated, be able to integrate nicely with the host environment, allowing a suite of tools to operate from outside the emulated ROM and augment its capabilities. This is the big reason I want absolute mouse, so the emulated ROM can operate like another window and not demand exclusive access to the mouse or have to know exactly how the hosted software keeps track of its mouse pointer to make this work.

Family BASIC keyboard and SNES mouse both have an advantage that they're available in a few emulators already, and some people already have them to use, but I'd rather have something I think is better suited.
Pokun wrote:
Wed Apr 08, 2020 2:47 am
I've also seen a few homebrew that supports the keys
I'd be interested in knowing which homebrew.

The data recorder, on the other hand, isn't important to me here. It's a possible way to save data, I guess, but that's pretty much entirely orthogonal to the user interface device problem. Doesn't really help or conflict with that.

lidnariq
Posts: 9700
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: NES to USB Keyboard interface?

Post by lidnariq » Wed Apr 08, 2020 11:42 am

rainwarrior wrote:
Wed Apr 08, 2020 11:22 am
I think you could adapt a USB Keyboard to be Family BASIC compatible perhaps, but I think translating to a matrix interface like that is a lot less straightforward than what I'm proposing.
If the existing matrix doesn't exactly agree with the matrix implied by how one reads the Family BASIC keyboard, it'd be a ridiculous amount of rework. May as well build the keyboard from scratch at the point. (There are internet communities about building keyboards from scratch, so it's not an outlandish proposition )
won't the existing keyboard loop after 1 more row?).
The existing hardware has only ten rows, but I guess one could replace the CD4017 with something else. There isn't a single IC that would permit this, but the hardware to extend it to 16 or 24 rows would be simple enough.

User avatar
rainwarrior
Posts: 7843
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: NES to USB Keyboard interface?

Post by rainwarrior » Wed Apr 08, 2020 12:13 pm

lidnariq wrote:
Wed Apr 08, 2020 11:42 am
If the existing matrix doesn't exactly agree with the matrix implied by how one reads the Family BASIC keyboard, it'd be a ridiculous amount of rework.
I was thinking that you could have a host device store a matrix in dual ported RAM or something like that which could be read back asynchronously... but I don't really want to spend too much mental effort figuring out a solution to a problem I don't want to solve. :P
lidnariq wrote:
Wed Apr 08, 2020 11:42 am
The existing hardware has only ten rows, but I guess one could replace the CD4017 with something else. There isn't a single IC that would permit this, but the hardware to extend it to 16 or 24 rows would be simple enough.
What I mean is that even if you extended it, I assume the original hardware will start having conflicting keys after the 10th row because it would wrap back to row 0? I think the 10th row being absent gives just enough wiggle room to throw a signature in there to indicate an extended report, though. (Or if it doesn't wrap, this is a non-issue.)

lidnariq
Posts: 9700
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: NES to USB Keyboard interface?

Post by lidnariq » Wed Apr 08, 2020 1:02 pm

rainwarrior wrote:
Wed Apr 08, 2020 12:13 pm
What I mean is that even if you extended it, I assume the original hardware will start having conflicting keys after the 10th row because it would wrap back to row 0? I think the 10th row being absent gives just enough wiggle room to throw a signature in there to indicate an extended report, though. (Or if it doesn't wrap, this is a non-issue.)
Oh. Yes, it does wrap.

kygsmsc
Posts: 1
Joined: Mon Apr 13, 2020 6:52 pm

Re: NES to USB Keyboard interface?

Post by kygsmsc » Mon Apr 13, 2020 7:46 pm

I come from China and can basically read English,but I can't write,I can only reply in Chinese.在我认识的网友中,有一位技术能人有做过类似的产品,但不同的是用PS/2的键盘实现的,PS/2键盘通过一片IC直接到FC的15针扩展接口上,因为IC的标识被擦除了,所以不知道IC型号了。Image

Pokun
Posts: 1512
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES to USB Keyboard interface?

Post by Pokun » Tue Apr 14, 2020 2:45 am

Is it compatible with Family BASIC like Emerson's PS/2 adapter further up in this thread or any other existing hardware? It appears that the image is not working.

rainwarrior wrote:
Wed Apr 08, 2020 11:22 am
Pokun wrote:
Wed Apr 08, 2020 2:47 am
I've also seen a few homebrew that supports the keys
I'd be interested in knowing which homebrew.

The data recorder, on the other hand, isn't important to me here. It's a possible way to save data, I guess, but that's pretty much entirely orthogonal to the user interface device problem. Doesn't really help or conflict with that.
Found it! Attribute Zone, it supposedly uses both the keys and the tape recorder feature, but it looks like it wasn't finished. Other than that, I can only remember some test programs for the keys, like Makimura's two test programs, and then my own stuff which I haven't released and is also unfinished.

Post Reply