NES to USB Keyboard interface?

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

Moderator: Moderators

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

Re: NES to USB Keyboard interface?

Post by Pokun »

bitcores wrote: Sun Jul 07, 2024 3:39 pm It's not that uncommon for Scroll Lock to be missing from keyboards these days, so shifting the default shortcut there could again result it someone getting stuck in the emulator.
I wouldn't worry too much about supporting non-standard keyboards, Scroll Lock is a standard key on both ANSI and ISO so I think it's safe to assume a keyboard has it in most cases, it's not like it will be deprecated. The main exception would be the numpad which is much more commonly missing.

I just noticed on the latest version of Mesen 2 that it is hard to map the pause hotkey to the Pause/Break key which I think is a better alternative to Escape as it doesn't exist on the Family BASIC keyboard (unless you count STOP but I have that mapped to the END key) now when hotkeys can be used at all times. It worked after pressing many times but there is something wrong with it. The Print Screen/SysReq key seems to have a similar problem.
creaothceann
Posts: 657
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: NES to USB Keyboard interface?

Post by creaothceann »

Pokun wrote: Mon Jul 08, 2024 8:42 am I just noticed on the latest version of Mesen 2 that it is hard to map the pause hotkey to the Pause/Break key [...] It worked after pressing many times but there is something wrong with it. The Print Screen/SysReq key seems to have a similar problem.
These keys are a bit special:
https://retrocomputing.stackexchange.co ... break-code
https://stackoverflow.com/questions/388 ... -break-key
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
User avatar
rainwarrior
Posts: 8755
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: NES to USB Keyboard interface?

Post by rainwarrior »

Pokun wrote: Mon Jul 08, 2024 8:42 am
bitcores wrote: Sun Jul 07, 2024 3:39 pm It's not that uncommon for Scroll Lock to be missing from keyboards these days, so shifting the default shortcut there could again result it someone getting stuck in the emulator.
I wouldn't worry too much about supporting non-standard keyboards, Scroll Lock is a standard key on both ANSI and ISO so I think it's safe to assume a keyboard has it in most cases, it's not like it will be deprecated. The main exception would be the numpad which is much more commonly missing.
A lot of laptop keyboards, if not most, don't have scroll lock. There is usually some secret Fn key combination to get it on those, but users don't know about it. It's extremely common not to be present as a dedicated key. Plenty of people do not use full set keyboards even for a desktop computer. Scroll Lock has zero use for 99.9% of computer users.

At any rate, it doesn't really matter. Mesen supports scroll lock just fine, and keys are remappable. It's just not a default mapping for anything (except in my fork above it's a default mapping for the scroll lock key on the emulated keyboard). Its current default for pause is both Escape and Pause keys, which I think is good.

I don't seem to have any trouble with the Pause key with Mesen (on my keyboards that actually have one) but I can confirm that Print Screen doesn't function. I cannot assign it, and even if manually assigned by editing the settings, it does not respond to it.
Pokun
Posts: 2807
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES to USB Keyboard interface?

Post by Pokun »

Well, in my experience with laptops these less used keys (and some often used keys such as Delete, Insert etc) are typically found in an Fn-combination which is clearly marked on the keyboard, but I guess that's not always the case (I'm confused why anyone would make a laptop keyboard without marking out all its unique Fn-key-combinations).

But it doesn't matter because I do think software should make use of these keys, at least partly to encourage the production of standard-compliant keyboards over these trendy minimalist keyboards. As you said the mentioned keys are used very seldomly, so I think it's up to software to make sure there are more use-cases for them that makes sense.
Scroll Lock makes double sense to use in emulators like Mame for this since it also uses an otherwise seldom-used LED to indicate the state of the UI toggle. But being seldomly used might also be a reason they are useful for these types of things since they tend not to conflict with more commonly used keys reserved for other things.

OK I now understand what Bitcore meant by getting stuck, since it locks you out of the UI and prevents you from remapping it. That may indeed be a problem with Mame and possibly Mesen in fullscreen mode when the GUI is hidden and inaccessible.



Regarding mapping the Pause key, AFAIK there are 3 sets of scancodes that may be used by PS/2 keyboards (sometimes 2 or all 3 are usable) while USB keyboards uses a unique 4th set, and modern OSes supports them all. The first two sets originates from PC/XT and PC/AT respectively and both has a scancode for pressing Pause but not for the release which is why this key is special. But I had no idea that Print Screen is also special like that, and I can't find information about it.
The 3rd scancode set and the USB scancode set however do both have a scancode for Pause release (I'm using a PS/2 keyboard BTW, no idea which scancode sets it can use).

I guess it might be a bug or limitation in whatever input API is used with Mesen 2 rather than with Mesen 2 itself though. I remember old Mesen had something similar in that it couldn't distinguish between Alt and Alt Gr or left and right Shift or something like that and it was not Mesen's fault.
Bavi_H
Posts: 199
Joined: Sun Mar 03, 2013 1:52 am
Location: Texas, USA
Contact:

Re: NES to USB Keyboard interface?

Post by Bavi_H »

Pokun wrote: Tue Jul 09, 2024 6:32 amI had no idea that Print Screen is also special like that, and I can't find information about it.
(Take a look at the pictures in the Wikipedia article on IBM PC keyboard and at the recent answer I wrote Re: Can someone explain the logic behind Pause and Print Screen modifiers?.

You can see some of the reasoning behind the unusual scancodes by looking at the keycap legends on old keyboards. On the original IBM PC, the Print Screen function was accessed by pressing Shift and PrtSc*

On the later model keyboards that rearranged things like moving Print Screen and Pause to their own keys and providing a dedicated set of cursor keys, the new keys used scancodes that would appear as if they were the original keystokes for the same functions when the special "extended" bytes were ignored by older software.)
User avatar
rainwarrior
Posts: 8755
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: NES to USB Keyboard interface?

Post by rainwarrior »

The convoluted scancodes are probably only the indirect source of the problem in Mesen 2, as it's the OS's job to translate those. My guess is that because Print Screen (and possibly sometimes Pause) does not have a break code, it gets both a make and break event immediately when pushed down, and Mesen probably works based on collecting a state once per frame, so it will process the release event before it ever runs a frame to see it pressed?

Edit: Following up on that idea, I did some debugging and found that, at least on my system, Mesen 2 gets a KeyUp event but no KeyDown for Print Screen. Pause, however, had a normal down-repeat-up like other keys, though that may not be consistent across systems, since Pokun mentioned that not working.

Anyway, I made this test modification of the key mapping window to account for these two keys having momentary/incomplete events like this, which does fix the problem for the setup UI. However, it would need to do something similar at both the keyboard shortcuts layer, and the emulated input layer, to make them actually function after being mapped via the setup UI.

GitHub: momentary-key-test (code changes)

Even with the OS helping out a little, these keys are still annoying. ;)

I also discovered, one of my keyboards has a volume wheel on the side. It actually gives both a down+up immediately, which also bypasses Mesen because it is only polling state to check (just adding these to the momentaries list in my code above solves it in the same way).

Edit: also went through some international key testing. At least using my Windows 10 onscreen keyboard, the "Kana" key (International2) seems to have a down+repeat but no up, for some reason. The "Han/Zen" (LANG5) key seems to act as a toggle for two separate keys, giving both a down and up on those two opposing virtual keys every time it is pressed down. Probably neither of these is useful for the sake of emulation, they both seem entangled with the OS language input to me.
Pokun
Posts: 2807
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES to USB Keyboard interface?

Post by Pokun »

OK so only Pause is missing the release-code. Print Screen should have a release-code, but it is special in other ways as it supposedly has the scancode for Shift + * on 101+ keyboards according to Bavi_H above.

But yeah the OS is handling the raw scancodes and may hide them from the software. I know Windows is converting the scancodes to one of those that lacks a release-code for Pause, so it shouldn't matter if you use a USB or PS/2 keyboard, software can simply never know when Pause is released under Windows. At least on my system, I remember playing around with it in SDL 2.0's keyboard I/O years ago and I could not read the release of Pause.
But you said Pause got a release event in Mesen for you?
User avatar
rainwarrior
Posts: 8755
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: NES to USB Keyboard interface?

Post by rainwarrior »

On my machine, Mesen sees only a release for Print Screen, but Pause acts like a normal key with down, repeat, release.
khari
Posts: 11
Joined: Sat Feb 17, 2024 10:45 pm
Location: USA - Eastern Time

Re: NES to USB Keyboard interface?

Post by khari »

Is this mouse interface getting completely made from scratch? I don't remember seeing a mouse accessory ever being released for the NES
User avatar
rainwarrior
Posts: 8755
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: NES to USB Keyboard interface?

Post by rainwarrior »

Yes, that's the idea.

Though as prior accessories, there is both the SNES Mouse which several homebrew games support via a SNES to NES adapter, and there was a Subor Famiclone which had a keyboard and mouse.
Pokun
Posts: 2807
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES to USB Keyboard interface?

Post by Pokun »

And of course the Hori Track used by a few Famicom sports games. It's the only official trackball/mouse for the Famicom AFAIK.

rainwarrior wrote: Thu Jul 11, 2024 7:49 pm On my machine, Mesen sees only a release for Print Screen, but Pause acts like a normal key with down, repeat, release.
I see, maybe the type of keyboard matters after all. Which interface were your keyboard using?
bitcores
Posts: 35
Joined: Thu Apr 20, 2023 3:09 am
Location: Japan

Re: NES to USB Keyboard interface?

Post by bitcores »

Pokun wrote: Sun Jul 14, 2024 6:17 am And of course the Hori Track used by a few Famicom sports games. It's the only official trackball/mouse for the Famicom AFAIK.
This looks like a great fourth mode to have on my interface.
And seeing it is on D0 it could be used concurrently with the Family Basic Keyboard.
Pokun
Posts: 2807
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: NES to USB Keyboard interface?

Post by Pokun »

Yes, I thought that was the plan all along, or I think at least it was mentioned in this thread way back.

Since the Hori Track connects to the 15P expansion port it should be D1. The wiki doesn't say if it's input port 0 ($4016) or 1 ($4017) though. Hopefully it's port 0 which the keyboard doesn't use.
Though since it seems to work like a normal expansion controller with extra reports, I guess it needs the strobe which is D0 of the output port and which IS used by the keyboard to reset to first row. :(


The modes mentioned in the wiki are about the two latching switches on the underside of the trackball.
Hori Track bottom
Hori Track bottom
The wiki is a bit confusing here but it seems to say that one switch swaps the two axes on both the d-pad and the trackball (so the whole controller can be rotated 45 degrees) and the other filters the trackball output to modify speed.
Fiskbit
Site Admin
Posts: 973
Joined: Sat Nov 18, 2017 9:15 pm

Re: NES to USB Keyboard interface?

Post by Fiskbit »

I've posted some additional information about the Hori Track here, in case it's helpful.
User avatar
rainwarrior
Posts: 8755
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: NES to USB Keyboard interface?

Post by rainwarrior »

Pokun wrote: Sun Jul 14, 2024 6:17 am
rainwarrior wrote: Thu Jul 11, 2024 7:49 pm On my machine, Mesen sees only a release for Print Screen, but Pause acts like a normal key with down, repeat, release.
I see, maybe the type of keyboard matters after all. Which interface were your keyboard using?
Several different keyboards (USB or built-in laptop which is probably secretly USB), mapped by Windows 10 to the US input set, on a couple different machines. I've not yet found one where Pause doesn't act like this.
Post Reply