kodi-game / game.libretro.cap32

Caprice32 for Kodi
1 stars 3 forks source link

typo and missing chars #7

Open ajbathe opened 1 year ago

ajbathe commented 1 year ago

discovered by not being able to type RUN for Amstrad - CPC (Caprice32) 4.5 HI: game.libretro.cap32/resources/buttonmap.xml

55c55
<     <feature name="u" mapto="RETROK_r"/>
---
>     <feature name="u" mapto="RETROK_u"/>

and many symbols are not reachable like ! or $ for example (also under DOSbox and caprice32 with LE nightly on an RPi4)

garbear commented 1 year ago

Thanks for catching the error - https://github.com/kodi-game/game.libretro.cap32/pull/8

cap32 uses the Amstrad Keyboard controller profile: https://github.com/kodi-game/controller-topology-project/blob/master/addons/game.controller.amstrad.keyboard/resources/layout.xml

The problem might show up in the debug log, if you're able to grab one.

ajbathe commented 1 year ago

yes, my research also led me to layout.xml of game.controller.amstrad.keyboard which is responsible for doing some key configurations with the GUI, but many keys are missing there

because I was not able to switch on the virtual keyboard with F9, for example, I had to include <feature name="f9" mapto="RETROK_F9"/> to buttonmap.xml of game.libretro.cap32 without <feature name="exclaim" mapto="RETROK_EXCLAIM"/> there, you won't see any information in the log, but with it you can see:

Apr 19 02:39:19 omega kodi.sh[1185]: [DEBUG] Controller "game.controller.keyboard" key "leftshift" (RETROK_LSHIFT) modifier 0x00000100: down
Apr 19 02:39:20 omega kodi.sh[1185]: [DEBUG] Controller "game.controller.keyboard" key "exclaim" (RETROK_EXCLAIM) modifier 0x00000100: down
Apr 19 02:39:21 omega kodi.sh[1185]: [DEBUG] Controller "game.controller.keyboard" key "exclaim" (RETROK_EXCLAIM) modifier 0x00000100: up
Apr 19 02:39:21 omega kodi.sh[1185]: [DEBUG] Controller "game.controller.keyboard" key "leftshift" (RETROK_LSHIFT) modifier 0x00000100: up

with journalctl -f but there is no ! on the CPC screen :( a try with <feature name="doublequote" mapto="RETROK_QUOTEDBL"/> is absolutely dead I guess there were many symbols not handled like dollar, exclaim, greater and less.

I managed to activate the right CTRL key with <feature name="rightctrl" mapto="RETROK_RCTRL"/> but there is some more work to do to have a fun experience with the Amstrad CPC emulator within Kodi or LE

my actual better working buttonmap.xml than the shipped version is attached - I would need some more information how exclaim, dollar, less and greater symbol can be made functioning - my goal is to use the emulator like a real programming cpc machine ;-) buttonmap.xml.txt

garbear commented 1 year ago

The missing keys will also have to be added to layout.xml so that they can be mapped in the GUI.

The source of truth for keys is https://github.com/libretro/libretro-cap32/blob/master/libretro/retro_events.c . For every key that cap32 supports, there should be an entry in layout.xml, and an entry in buttonmap.xml.

ajbathe commented 1 year ago

do I guess it right, that the problem is the missing SDL layer in LibreELEC? would explain that the mapping isn't done within DOSbox and cap32 ...

garbear commented 1 year ago

Unlikely. Keys come from the frontend. In the case of RetroArch, I think it uses SDL initially, but translates keys to the libretro API. With LE, it uses the native OS way of reading keys, and also translates them to the libretro API. Cores only see libretro keys.

garbear commented 1 year ago

@ajbathe We're getting closer to your dream of programming a cpc machine in kodi - https://github.com/kodi-game/controller-topology-project/pull/249

I tested input in all thee emulators (cap32, crocods and epu128) and all buttons are correctly sent to the core. Can you try and see if input is fixed for you?

If you follow the PR links in https://github.com/kodi-game/controller-topology-project/pull/249, you'll see all the XML files you need to copy/update.

ajbathe commented 1 year ago

I will happily test every button :) I hope I don't have to build it because I have no compiling environment for xmbc

garbear commented 1 year ago

Don't worry, you can just copy/paste all the XML files that were modified. Track down each PR to see which XML file should be updated.

If there's ever a change that needs to be compiled into Kodi, I'll do a round of test builds. What platform/device do you test on?

ajbathe commented 1 year ago

I test with RPi4.aarch64 and nightly-20230417-83ec8ac with a German keyboard, so I have to ask before testing: ! and " are now right, but I can see the ! symbol only when I push 1 and hold it down, and release left shift, the same with " - will sign that with T

To have a good basis on what keylayout should I look, the German keys (or English Keyboard position) or the Amstrad English layout of the virtual keyboard?

for German with 6128: first line: ^° dead - 1! Tok - 2" Tok - SHIFT 3 dead - 4$ Tok - 5% Tok - 6& Tok - 7(should be /) - 8( Tok - 9) Tok - 0 POUND (on Geman keylayout would be =) - [ß?\] dead - [´] dead - backspace OK

  1. line from [TAB QWERTZUIOP] OK - Ü dead - + calls VolumeUP now
  2. line capslock [ASDFGHJKL} OK - Ö dead - # is dead, ' with leftshift gives + and with rightshift ;
  3. [<> | ] dead - [YXCVBNM] OK - [ , ; ] comma OK, but leftshift * and rightshift : [ . : ] period OK, semicolon is dead - minus OK but underscore dead hope it helps
garbear commented 1 year ago

Open the in-game OSD and go to settings and then Controls. You should be able to map the Amstrad keyboard profile to your German layout. I'm interested in seeing the map that you generate.

ajbathe commented 1 year ago

in-game OSD in caprice32 under LibreELEC? how can I open that?

garbear commented 1 year ago

There currently isn't a hotkey for the keyboard, so you'll need to connect controller and press Select + X. Alternatively, remove the mouse profile from topology.xml and then moving the mouse in-game will bring up the OSD.

ajbathe commented 1 year ago

I only get the Kodi menu with Continue, reset, exit and so on, also with the mouse, so I guess u mean that. Was a misunderstanding - with that menu I started to fill my first Keyboard.xml within the directory peripheral.joystick/resources/buttonmaps/xml/application - I thought there is an OSD more, sorry

that freshly created Keyboard.xml: Keyboard.xml.txt

garbear commented 1 year ago

In the menu with Continue, reset and exit, there's a button called "Settings". In that menu is a button called "Controls". This opens the controller mapper dialog that will generate a Keyboard.xml file in your userdata folder.

By viewing the auto-generated file, we can see what keycodes the German layout is sending.

ajbathe commented 1 year ago

this is exactly above your last comment ;-)

garbear commented 1 year ago

I've created a diff of your keymap:

--- a/peripheral.joystick/resources/buttonmaps/xml/application/Keyboard.xml
+++ b/peripheral.joystick/resources/buttonmaps/xml/application/Keyboard.xml
@@ -13,7 +13,7 @@
             <feature name="8" key="8" />
             <feature name="9" key="9" />
             <feature name="a" key="a" />
-            <feature name="at" key="leftbracket" />
+            <feature name="at" key="at" />
             <feature name="b" key="b" />
             <feature name="backslash" key="grave" />
             <feature name="c" key="c" />
@@ -57,7 +57,7 @@
             <feature name="mousetoggle" key="insert" />
             <feature name="n" key="n" />
             <feature name="o" key="o" />
-            <feature name="openbracket" key="rightbracket" />
+            <feature name="openbracket" key="leftbracket" />
             <feature name="p" key="p" />
             <feature name="play" key="home" />
             <feature name="q" key="q" />
@@ -66,7 +66,7 @@
             <feature name="rewind" key="pageup" />
             <feature name="right" key="right" />
             <feature name="s" key="s" />
-            <feature name="semicolon" key="quote" />
+            <feature name="semicolon" key="semicolon" />
             <feature name="shift" key="leftshift" />
             <feature name="slash" key="slash" />
             <feature name="space" key="space" />

The goal of libretro is to preserve the "ergonomic" mapping. As you can see,

Amstrad CPC

"@" and "[" are next to each other, matching the "[" and "]" positions on a US keyboard layout, hence the mapping I've created.

Also, because all the artwork I've done may include idiosyncratics or be low resolution, and I'm often not familiar with the platforms, we base the ergonomic mapping on the core's libretro source code instead images. In this case it's https://github.com/libretro/libretro-cap32/blob/master/libretro/retro_events.c. I've matched the layout in layout.xml of https://github.com/kodi-game/controller-topology-project/pull/249 and Keyboard.xml of https://github.com/xbmc/peripheral.joystick/pull/270. I'm open for fixes but I don't think this patch follows the ergonomic mapping in the source.

That said, international keyboard layouts like German complicate things. Instead of having layout-specific button maps for all cores (an "N x M" problem), we can just have ergonomic button maps from English to all other languages. What do you think of this approach?

ajbathe commented 1 year ago

I have to admit that although I have a good understanding of how software works, it's not very clear to me how to achieve the goal with a perfect keyboard mapping.

I see it this way: We have a ground libretro-symbol set definded with all RETROK-tokens. And there should be some mechanism that when the user pushed ! for example - when the emulated machine has this symbol on the original keyboard, it should handle this symbol when it is pressed on any kind of keyboard, German or English version. That a user should know the original position of the emulated keyboard, even me - I had an Amstrad CPC 6128 when I was young :) - don't know that keyboard position in mind.

That means: When a user pushes the hash key on an English or German IBM-compatible keyboard, the emulator system should map that to handle to print the HASH symbol. It doesn't care where the HASH key on the original Amstrad keyboard was. That's my intention.

The only problem I see how to handle keys on the emulated machine (like POUND) what my PC keyboard does not have.

And to conclude: I really don't understand the complicated key mapping mechanism of libretro for DOSbox and Caprice32 till today. There are definitions on so many places. It is really complicated. What I can offer is testing.

ajbathe commented 1 year ago

within your last new version (PR) there was <feature name="at" key="leftbracket" /> when I start to create a virgin version (deleted Keyboard.xml) with the Kodi-GUI, we already have <feature name="at" key="at" /> the same to the other two changes of your suggestion above of your diff comment - the changes are for the PR version I guess

garbear commented 1 year ago

When a user pushes the hash key on an English or German IBM-compatible keyboard, the emulator system should map that to handle to print the HASH symbol. It doesn't care where the HASH key on the original Amstrad keyboard was.

I faced the same problem with the face buttons on SNES controllers. The A/B and X/Y buttons are reversed compared to the Xbox controller. The reason is because there are two primary layouts for controllers: Western and Japanese.

There are two ways to map buttons: ergonomically and logically. I prefer the logical mapping: When I press A on an Xbox controller, the emulator should map that to A on the SNES controller to mirror the game logic. It doesn't care where the A button on the original SNES controller was.

However, we never really settled on a mapping type and ended up with inconsistentences. We decided to use the ergonomic mapping for everything in https://github.com/kodi-game/game.libretro/pull/105.

Of course, the argument for logical vs. ergonomic can be different for controllers and keyboards. We could decide on ergonomic mappings for controllers, and logical mappings for keyboards. What do you think of this?

The only problem I see how to handle keys on the emulated machine (like POUND) what my PC keyboard does not have.

Well, going from ergonomic to logical is a permutation, right? Shuffle the keys correctly as best as possible, and you end up with the unhandled keys mapped to a "good enough" key.

ajbathe commented 1 year ago

Of course, the argument for logical vs. ergonomic can be different for controllers and keyboards. We could decide on ergonomic mappings for controllers, and logical mappings for keyboards. What do you think of this?

This makes sense to me: It is easier to NOT look on the joystick buttons because your brain learnt that the A button on the trained controller of company X is not A, but B, just for example. I don't look on that. But optionally it should be possible, to change that by an GUI option.

So my suggestion: an GUI option for tiny keyboards called joysticks with "logical" (better "real") or "ergonomic" layout.

It's not with keyboard that way because our brains can't learn that many keyboard variants completly: We know e.g. that Y and Z are changed between an English and German keyboard, but please don't ask me where the < or > is! Here people look on the keyboard, I am sure ;-)

So your suggestion is fine to me. I guess, it will be a longer way to see me programming my CPC in libretro emulation, right?

ajbathe commented 1 year ago

a "good enough" key for POUND could be EURO :)

garbear commented 1 year ago

But optionally it should be possible, to change that by an GUI option. So my suggestion: an GUI option for tiny keyboards called joysticks with "logical" (better "real") or "ergonomic" layout.

Auto-switching between Western and Japanese layouts is a feature I'd like to add, but haven't had the time.

It's not with keyboard that way because our brains can't learn that many keyboard variants completly

Another good point. Keyboards are different from controllers, because people have likely only been using a single keyboard layout their entire life and are very familiar with it, without being able to easily change. I'll update the PR to use a logical mapping.

ajbathe commented 1 year ago

Yes, also an good argument. Have success with your PR to use a logical mapping for keyboards.

ajbathe commented 1 year ago

OK, before we see the PR successfully passing, I would suggest to start with a freshly created Keyboard.xml of my German PC-keyboard. There are many more keys working but some not. You will see that what's missing within the XML-file:

game.controller.keyboard.xml.txt

Please insert the XML-file here for reading, I had to give an .txt extension to upload it here.

garbear commented 1 year ago

If I understand correctly, you mapped your german layout to the IBM Model M keyboard (default keyboard) profile, right?

Here's the diff:

--- a/peripheral.joystick/resources/buttonmaps/xml/application/Keyboard.xml
+++ b/peripheral.joystick/resources/buttonmaps/xml/application/Keyboard.xml
@@ -173,14 +173,10 @@
             <feature name="backslash" key="backslash" />
             <feature name="backspace" key="backspace" />
             <feature name="bar" key="bar" />
-            <feature name="break" key="break" />
             <feature name="c" key="c" />
             <feature name="capslock" key="capslock" />
-            <feature name="caret" key="caret" />
-            <feature name="clear" key="clear" />
             <feature name="colon" key="colon" />
             <feature name="comma" key="comma" />
-            <feature name="compose" key="compose" />
             <feature name="d" key="d" />
             <feature name="delete" key="delete" />
             <feature name="dollar" key="dollar" />
@@ -191,16 +187,17 @@
             <feature name="enter" key="enter" />
             <feature name="equals" key="equals" />
             <feature name="escape" key="escape" />
-            <feature name="euro" key="euro" />
             <feature name="exclaim" key="exclaim" />
             <feature name="f" key="f" />
             <feature name="f1" key="f1" />
             <feature name="f10" key="f10" />
             <feature name="f11" key="f11" />
             <feature name="f12" key="f12" />
+            <!-- start of manually added keys F13, F14 and F15 -->
             <feature name="f13" key="f13" />
             <feature name="f14" key="f14" />
             <feature name="f15" key="f15" />
+            <!-- end of manually added keys -->
             <feature name="f2" key="f2" />
             <feature name="f3" key="f3" />
             <feature name="f4" key="f4" />
@@ -210,11 +207,9 @@
             <feature name="f8" key="f8" />
             <feature name="f9" key="f9" />
             <feature name="g" key="g" />
-            <feature name="grave" key="grave" />
             <feature name="greater" key="greater" />
             <feature name="h" key="h" />
             <feature name="hash" key="hash" />
-            <feature name="help" key="help" />
             <feature name="home" key="home" />
             <feature name="i" key="i" />
             <feature name="insert" key="insert" />
@@ -232,10 +227,8 @@
             <feature name="kp9" key="kp9" />
             <feature name="kpdivide" key="kpdivide" />
             <feature name="kpenter" key="kpenter" />
-            <feature name="kpequals" key="kpequals" />
             <feature name="kpminus" key="kpminus" />
             <feature name="kpmultiply" key="kpmultiply" />
-            <feature name="kpperiod" key="kpperiod" />
             <feature name="kpplus" key="kpplus" />
             <feature name="l" key="l" />
             <feature name="left" key="left" />
@@ -243,7 +236,6 @@
             <feature name="leftbrace" key="leftbrace" />
             <feature name="leftbracket" key="leftbracket" />
             <feature name="leftctrl" key="leftctrl" />
-            <feature name="leftmeta" key="leftmeta" />
             <feature name="leftparen" key="leftparen" />
             <feature name="leftshift" key="leftshift" />
             <feature name="leftsuper" key="leftsuper" />
@@ -251,7 +243,6 @@
             <feature name="m" key="m" />
             <feature name="menu" key="menu" />
             <feature name="minus" key="minus" />
-            <feature name="mode" key="mode" />
             <feature name="n" key="n" />
             <feature name="numlock" key="numlock" />
             <feature name="o" key="o" />
@@ -261,18 +252,15 @@
             <feature name="pause" key="pause" />
             <feature name="period" key="period" />
             <feature name="plus" key="plus" />
-            <feature name="power" key="power" />
             <feature name="printscreen" key="printscreen" />
             <feature name="q" key="q" />
             <feature name="question" key="question" />
             <feature name="quote" key="quote" />
             <feature name="r" key="r" />
             <feature name="right" key="right" />
-            <feature name="rightalt" key="rightalt" />
             <feature name="rightbrace" key="rightbrace" />
             <feature name="rightbracket" key="rightbracket" />
             <feature name="rightctrl" key="rightctrl" />
-            <feature name="rightmeta" key="rightmeta" />
             <feature name="rightparen" key="rightparen" />
             <feature name="rightshift" key="rightshift" />
             <feature name="rightsuper" key="rightsuper" />
@@ -281,19 +269,32 @@
             <feature name="semicolon" key="semicolon" />
             <feature name="slash" key="slash" />
             <feature name="space" key="space" />
-            <feature name="sysreq" key="sysreq" />
             <feature name="t" key="t" />
             <feature name="tab" key="tab" />
             <feature name="tilde" key="tilde" />
             <feature name="u" key="u" />
             <feature name="underscore" key="underscore" />
-            <feature name="undo" key="undo" />
             <feature name="up" key="up" />
             <feature name="v" key="v" />
             <feature name="w" key="w" />
             <feature name="x" key="x" />
             <feature name="y" key="y" />
             <feature name="z" key="z" />
+            <!-- dead keys means no key handling for
+            for symbol ^ - left of key 1
+            for symbol ° - left of SHIFT key 1 = !
+            for symbol § - SHIFT key 3
+            for symbol % - SHIFT key 5
+            for symbols Ä and ä
+            for symbols Ö and ö
+            for symbols Ü and ü
+            for symbol ² - AltGR 2
+            for symbol ³ - AltGR 3
+            for symbol ´ - dead key left oft BACKSPACE
+            for symbol ` - dead key SHIFT left of BACKSPACE
+            for symbol € - AltGR E
+            for symbol µ - AltGR M
+            -- end of dead keys -->
         </controller>
     </device>
 </buttonmap>

I see that some keys don't have a map here, which makes sense because the default keyboard keys are based on operating system scancodes, and not all scancodes have a dedicated key (such as the shifted numbers).

For example, see how the RETROK_* constants are all uppercase, except for a-z. This is because we explicitly use the scancodes of lower-case characters. That is, RETROK_a corresponds to the ASCII 'a' (value of 0x61), and if RETROK_A were defined it would equal 0x41. But there's no A key, so there's not RETROK_* constant.

Similarly, there's no key for a lot of RETROK_* constants, because these are scancodes, not physical keys. Scancodes are the same for both English and German keyboards (because they're defined by the OS), which is why your buttonmap here only has omissions, not any changes.

If you have dead keys, that's a deeper code problem, not a buttonmap problem. But what do you mean by "dead"? What happens when you use the "Select Key" button in the controller mapper dialog?

garbear commented 1 year ago

I updated https://github.com/kodi-game/controller-topology-project/pull/249 to use QWERTY keys. I sorted the keys to match the ergonomic positions on a regular keyboard, which greatly helps map the "weird" keys.

I also updated https://github.com/xbmc/peripheral.joystick/pull/270 to use QWERTY keys. Here's the diff:

--- a/peripheral.joystick/resources/buttonmaps/xml/application/Keyboard.xml
+++ b/peripheral.joystick/resources/buttonmaps/xml/application/Keyboard.xml
@@ -13,14 +13,14 @@
             <feature name="8" key="8" />
             <feature name="9" key="9" />
             <feature name="a" key="a" />
-            <feature name="at" key="leftbracket" />
+            <feature name="at" key="grave" />
             <feature name="b" key="b" />
-            <feature name="backslash" key="grave" />
+            <feature name="backslash" key="backslash" />
             <feature name="c" key="c" />
             <feature name="capslock" key="capslock" />
-            <feature name="closebracket" key="backslash" />
+            <feature name="closebracket" key="rightbracket" />
             <feature name="clr" key="delete" />
-            <feature name="colon" key="semicolon" />
+            <feature name="colon" key="quote" />
             <feature name="comma" key="comma" />
             <feature name="control" key="leftctrl" />
             <feature name="copy" key="leftalt" />
@@ -57,7 +57,7 @@
             <feature name="mousetoggle" key="insert" />
             <feature name="n" key="n" />
             <feature name="o" key="o" />
-            <feature name="openbracket" key="rightbracket" />
+            <feature name="openbracket" key="leftbracket" />
             <feature name="p" key="p" />
             <feature name="play" key="home" />
             <feature name="q" key="q" />
@@ -66,7 +66,7 @@
             <feature name="rewind" key="pageup" />
             <feature name="right" key="right" />
             <feature name="s" key="s" />
-            <feature name="semicolon" key="quote" />
+            <feature name="semicolon" key="semicolon" />
             <feature name="shift" key="leftshift" />
             <feature name="slash" key="slash" />
             <feature name="space" key="space" />
ajbathe commented 1 year ago

I created the last PC Keyboard.xml with Settings -> System -> Input -> Configure attached controllers -> (under Controller profiles) Keyboard.

The last buttons in the list are Power, € and Undo. Hardware keyboard layouts is defined with German.

With dead I mean there is no output in the emulator. Sometimes I can see (with debugging on) key messages within kodi.log or with journalctl -f

Within DOSbox e.g. I push "<" and get (within kodi.log)

2023-04-25 19:46:42.109 T:1140    debug <general>: CLibInputKeyboard::ProcessKey - using delay: 500ms repeat: 33ms
2023-04-25 19:46:42.109 T:1905    debug <general>: Thread Timer start, auto delete: false
2023-04-25 19:46:42.111 T:1135    debug <general>: Keyboard: scancode: 0x1c, sym: 0x0d, unicode: 0x0d, modifier: 0x0
2023-04-25 19:46:42.213 T:1905    debug <general>: Thread Timer 547599871808 terminating
2023-04-25 19:46:42.231 T:1135    debug <general>: Keyboard: scancode: 0x1c, sym: 0x0d, unicode: 0x0d, modifier: 0x0

and with journalctl -f nothing. Here I can see

Apr 25 19:48:53 omega kodi.sh[1135]: [DEBUG] Controller "game.controller.keyboard" key "a" (RETROK_a) modifier 0x00000000: down
Apr 25 19:48:53 omega kodi.sh[1135]: [DEBUG] Controller "game.controller.keyboard" key "a" (RETROK_a) modifier 0x00000000: up

when I push "a". Hope this answered your questions.

garbear commented 1 year ago

Are the keys recognized by Kodi? Can you use the "Select Key" button to map these? Can you post a debug log segment showing the keys being pressed?

ajbathe commented 1 year ago

key "<" gives that, so answer is YES :)

2023-04-25 19:56:15.122 T:1140    debug <general>: CLibInputKeyboard::ProcessKey - using delay: 500ms repeat: 33ms
2023-04-25 19:56:15.122 T:1975    debug <general>: Thread Timer start, auto delete: false
2023-04-25 19:56:15.127 T:1135    debug <general>: Keyboard: scancode: 0x1c, sym: 0x0d, unicode: 0x0d, modifier: 0x0
2023-04-25 19:56:15.127 T:1135    debug <general>: HandleKey: return (0xf00d) pressed, window 10820, action is Select
2023-04-25 19:56:15.127 T:1976    debug <general>: Thread GUIConfigurationWizard start, auto delete: false
2023-04-25 19:56:15.127 T:1976    debug <general>: Starting configuration wizard
2023-04-25 19:56:15.132 T:1976    debug <general>: AddOnLog: peripheral.joystick: Loaded device "Microsoft X-Box 360 pad" with 1 controller profiles and 19 total features
2023-04-25 19:56:15.136 T:1976    debug <general>: Failed to load button map for "peripheral.joystick/0"
2023-04-25 19:56:15.141 T:1976    debug <general>: AddOnLog: peripheral.joystick: Loaded device "Keyboard" with 1 controller profiles and 1 total features
2023-04-25 19:56:15.145 T:1976    debug <general>: AddOnLog: peripheral.joystick: Loaded device "Keyboard" with 2 controller profiles and 209 total features
2023-04-25 19:56:15.160 T:1976    debug <general>: AddOnLog: peripheral.joystick: Loaded device "Mouse" with 1 controller profiles and 10 total features
2023-04-25 19:56:15.169 T:1976    debug <general>: Failed to load button map for "mouse"
2023-04-25 19:56:15.169 T:1976    debug <general>: game.controller.keyboard: Waiting for input
2023-04-25 19:56:15.330 T:1975    debug <general>: Thread Timer 547599871808 terminating
2023-04-25 19:56:15.347 T:1135    debug <general>: Keyboard: scancode: 0x1c, sym: 0x0d, unicode: 0x0d, modifier: 0x0
2023-04-25 19:56:16.234 T:1140    debug <general>: CLibInputKeyboard::ProcessKey - using delay: 500ms repeat: 33ms
2023-04-25 19:56:16.234 T:1977    debug <general>: Thread Timer start, auto delete: false
2023-04-25 19:56:16.247 T:1135    debug <general>: Keyboard: scancode: 0x56, sym: 0x3c, unicode: 0x3c, modifier: 0x0
2023-04-25 19:56:16.247 T:1976    debug <general>: game.controller.keyboard: Waiting for input for feature "less"
2023-04-25 19:56:16.458 T:1977    debug <general>: Thread Timer 547599871808 terminating
2023-04-25 19:56:16.487 T:1135    debug <general>: Keyboard: scancode: 0x56, sym: 0x3c, unicode: 0x3c, modifier: 0x0
2023-04-25 19:56:17.138 T:1140    debug <general>: CLibInputKeyboard::ProcessKey - using delay: 500ms repeat: 33ms
2023-04-25 19:56:17.139 T:1978    debug <general>: Thread Timer start, auto delete: false
2023-04-25 19:56:17.147 T:1135    debug <general>: Keyboard: scancode: 0x56, sym: 0x3c, unicode: 0x3c, modifier: 0x0
2023-04-25 19:56:17.147 T:1135    debug <general>: game.controller.keyboard: mapping feature "less" for device keyboard
2023-04-25 19:56:17.157 T:1976    debug <general>: AddOnLog: peripheral.joystick: Loaded device "Keyboard" with 2 controller profiles and 209 total features
2023-04-25 19:56:17.173 T:1976    debug <general>: AddOnLog: peripheral.joystick: Loaded device "Mouse" with 1 controller profiles and 10 total features
2023-04-25 19:56:17.181 T:1976    debug <general>: Failed to load button map for "mouse"
2023-04-25 19:56:17.189 T:1976    debug <general>: AddOnLog: peripheral.joystick: Loaded device "Microsoft X-Box 360 pad" with 1 controller profiles and 19 total features
2023-04-25 19:56:17.230 T:1976    debug <general>: Failed to load button map for "peripheral.joystick/0"
2023-04-25 19:56:17.230 T:1976    debug <general>: Configuration wizard: waiting 5000ms for axes to neutralize
2023-04-25 19:56:17.274 T:1978    debug <general>: Thread Timer 547599871808 terminating
2023-04-25 19:56:17.307 T:1135    debug <general>: Keyboard: scancode: 0x56, sym: 0x3c, unicode: 0x3c, modifier: 0x0
2023-04-25 19:56:22.230 T:1976    debug <general>: Configuration wizard ended
2023-04-25 19:56:22.230 T:1976    debug <general>: Thread GUIConfigurationWizard 545691266880 terminating
garbear commented 1 year ago

Within DOSbox e.g. I push "<" and get (within kodi.log)

The reason why you get nothing in DOSBox with < is because it maps to RETROK_LESS which isn't defined by dosbox: https://github.com/libretro/dosbox-libretro/blob/master/libretro/mapper.cpp#L56.

If you map < to a different key from the list of supported keys, does that work in dosbox?

ajbathe commented 1 year ago

No. I mapped "<" to "a":

<?xml version="1.0" ?>
<buttonmap>
    <device name="Keyboard" provider="application">
        <controller id="game.controller.keyboard">
            <feature name="less" key="a" />
        </controller>
    </device>
</buttonmap>

Pushing "<" within DOSbox gives:

2023-04-26 12:31:01.518 T:1135    debug <general>: CLibInputKeyboard::ProcessKey - using delay: 500ms repeat: 33ms
2023-04-26 12:31:01.536 T:1130    debug <general>: Keyboard: scancode: 0x56, sym: 0x3c, unicode: 0x3c, modifier: 0x0
2023-04-26 12:31:01.536 T:1130    debug <general>: HandleKey: lessthan (0xf03c) pressed, window 12906, action is 
2023-04-26 12:31:01.636 T:1130    debug <general>: Keyboard: scancode: 0x56, sym: 0x3c, unicode: 0x3c, modifier: 0x0

Pushing "a" within DOSbox gives:

2023-04-26 12:31:49.932 T:1135    debug <general>: CLibInputKeyboard::ProcessKey - using delay: 500ms repeat: 33ms
2023-04-26 12:31:49.936 T:1130    debug <general>: Keyboard: scancode: 0x1e, sym: 0x61, unicode: 0x61, modifier: 0x0
2023-04-26 12:31:49.936 T:1130    debug <general>: HandleKey: a (0xf041) pressed, window 12906, action is 
2023-04-26 12:31:50.036 T:1130    debug <general>: Keyboard: scancode: 0x1e, sym: 0x61, unicode: 0x61, modifier: 0x0
garbear commented 1 year ago

No. I mapped "<" to "a":

<?xml version="1.0" ?>
<buttonmap>
    <device name="Keyboard" provider="application">
        <controller id="game.controller.keyboard">
            <feature name="less" key="a" />
        </controller>
    </device>
</buttonmap>

You mapped physical < with virtual a? Because this xml shows physical a mapped to virtual <. Virtual < isn't accepted by dosbox, so pressing physical a will fall through and output HandleKey: a (0xf041) pressed, window 12906, action is (no action is mapped in keyboard.xml).

Pressing physical < will of course also fall through and do nothing in Kodi because it's not mapped to anything.

garbear commented 1 year ago
<?xml version="1.0" ?>
<buttonmap>
    <device name="Keyboard" provider="application">
        <controller id="game.controller.keyboard">
            <feature name="less" key="a" />
        </controller>
    </device>
</buttonmap>

"key" is the keyboard scancode. It looks like you physically pressed A.

"name" is the key name defined in layout.xml. "name" is also the lookup value in buttonmap.xml.

It looks like you did the "Select Key" button and pressed < then A. Can you try in reverse?

ajbathe commented 1 year ago

Sure, reversing:

<?xml version="1.0" ?>
<buttonmap>
    <device name="Keyboard" provider="application">
        <controller id="game.controller.keyboard">
            <feature name="a" key="less" />
        </controller>
    </device>
</buttonmap>
2023-04-27 12:56:50.255 T:1091    debug <general>: CLibInputKeyboard::ProcessKey - using delay: 500ms repeat: 33ms
2023-04-27 12:56:50.255 T:1086    debug <general>: Keyboard: scancode: 0x1e, sym: 0x61, unicode: 0x61, modifier: 0x0
2023-04-27 12:56:50.255 T:1086    debug <general>: HandleKey: a (0xf041) pressed, window 12906, action is 
2023-04-27 12:56:50.415 T:1086    debug <general>: Keyboard: scancode: 0x1e, sym: 0x61, unicode: 0x61, modifier: 0x0

Pushing key "<" prints now the "a" within DOSbox.

garbear commented 1 year ago

Does that address the remaining issues? What's left to merge https://github.com/kodi-game/controller-topology-project/pull/249 and https://github.com/kodi-game/game.libretro.dosbox/pull/14? What still doesn't work for you?

ajbathe commented 1 year ago

As I wrote it above (see https://github.com/kodi-game/game.libretro.cap32/issues/7#issuecomment-1515754850 ) there is a problem with SHIFT 1 and higher.

Please let's concentrate on the CPC emulator now, otherwise I start to get confused ;-)

I can't get the EXCLAIM symbol with a short SHIFT and 1. But when I push 1 (also 2,3,4,5 and 6) and wait till the 1 starts to run (many 1s are printed now), then I can get the EXCLAIM symbol by pushing SHIFT. The same with the other symbols on the numeric line till 6. So I get 1 and ! 2 and " 3 and HASHMARK 4 and $ 5 and % 6 and & SHIFT 7 works, but I get a backtick (⸜); when I let it run and using SHIFT (on and off), I also see the other tick - this is weird SHIFT 8 opens GUI (info) and shifting ( SHIFT 9 opens GUI (menu) and shifting ) SHIFT 0 opens GUI (volumeUP) and shifting UNDERSCORE (shifting = pressing and releasing shift sometimes)

also still weird are COMMA and PERIOD. SHIFT COMMA (";") gives PLUS SHIFT PERIOAD (":") gives *

But when I hold down COMMA till it runs, and press SHIFT, I see LESS, and it continues running although I release all keys.

The same with the neighbor: Holding down PERIOD for a while, and pressing SHIFT, I see greater, releasing all buttons, PERIOSs are running.

The last is MINUS, short with SHIFT gives nothing. Holding down and SHIFT gives ======== releasing .......... till end of line.

It looks like the release of some keys are not handled right enough.

I guess, like it is, it could make people mad ;-)

PS: PERIOD on the numeric part, should it COMMA or PERIOD? Right now, it is COMMA. And the rest is functional as expected :)

ajbathe commented 1 year ago

Were you able to reproduce the keyboard behaviour which I described a week ago?

garbear commented 1 year ago

Sorry, some work stuff came up and Kodi time went to zero. Not sure when I get a chance next, but I'll try to reproduce your keypresses when I'm able to.

garbear commented 1 year ago

I had some time for kodi this last week (if you've seen) but unfortunately didn't get Amstrad working yet.

I put some thought into it. Could it be that the weird shifting behavior is because libretro doesn't send keyboard modifiers (e.g. shift & x) but instead two separate key presses (one shift press and one x press)?

Of course, it's virtually impossible to map a libretro button map that works for both English and German. However, I found this in the codebase: https://github.com/xbmc/xbmc/tree/master/system/keyboardlayouts

Now, theoretically, if you were to write an XML file that supported both Kodi keyboard layouts and past historical emulator layouts, how would that XML look? Because we have accurate physical and symbol information it should be possible of solving any keyboard to any other keyboard, similar to how we correctly solve any controller to any other controller.

ajbathe commented 1 year ago

I just looked at https://github.com/xbmc/xbmc/blob/master/system/keyboardlayouts/german.xml and see that this keyboard layout is not quite right:

https://en.wikipedia.org/wiki/German_keyboard_layout#/media/File:KB_Germany.svg

Could this be the reason that some keys are not working properly with some emulators (dosbox and caprice32) ?

When I push all keys (under Ubuntu 20.04.6 LTS) I get this german.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
Please use English language names instead.
Default font lacks support for all characters
-->
<keyboardlayouts>
  <layout language="German" layout="QWERTZ">
    <keyboard>
      <row>^1234567890ß´</row>
      <row>qwertzuiopü+</row>
      <row>asdfghjklöä#</row>
      <row>&lt;yxcvbnm,.-</row>
    </keyboard>
    <keyboard modifiers="shift">
      <row>°!"§$%&amp;/()=?`</row>
      <row>QWERTZUIOPÜ*</row>
      <row>ASDFGHJKLÖÄ'</row>
      <row>&gt;YXCVBNM;:_</row>
    </keyboard>
    <keyboard modifiers="symbol">
      <row>′¹²³¼½¬{[]}\¸</row>
      <row>@ł€¶ŧ←↓→øþ¨~</row>
      <row>æſðđŋħ̣̣ ĸł˝^’</row>
      <row>|»«¢„“”µ·…–</row>
    </keyboard>
    <keyboard modifiers="shift+symbol">
      <row>″¡⅛£¤⅜⅝⅞™±°¿˛</row>
      <row>ΩŁ€®Ŧ¥↑ıØÞ°¯</row>
      <row>ÆẞЪŊĦ˙&Ł ˇ˘</row>
      <row>DEADKEY›‹©‚‘’º×÷—</row>
    </keyboard>
  </layout>
</keyboardlayouts>

german.xml.txt