dbalsom / martypc

An IBM PC/XT emulator written in Rust.
Other
578 stars 19 forks source link

Can't type any shifted non-letter characters #32

Closed chungy closed 6 months ago

chungy commented 1 year ago

Host: Arch Linux, Rust 1.70

Guest: have tried PC-DOS 3.30, MS-DOS 6.22, IBM BASIC

I can use shifted characters, but only if they are letters. Unshifted a and shifted A works and all the other letters, but trying to type characters like :, ?, or * doesn't work. It just does nothing.

graphixillusion commented 1 year ago

Yep i have the same issue on Windows

dbalsom commented 1 year ago

A few questions for you both, if you will:

  1. what kind of keyboard layout? US or some other layout?
  2. Which BIOS are you both using?
  3. is this a laptop keyboard or desktop/external keyboard?
  4. does the web player work? https://dbalsom.github.io/martypc/web/player.html?title=freedos
chungy commented 1 year ago

what kind of keyboard layout? US or some other layout?

US international with AltGr dead keys. Same issues persist if I switch to standard US layout.

Which BIOS are you both using?

Tried copying the "preferred" 5160 ROM files from the MAME set, didn't work, the second set listed in the roms.txt file worked to boot. I have all four files in the directory with the same names the txt file specifies. (Separate issue, I suppose)

is this a laptop keyboard or desktop/external keyboard?

Desktop.

does the web player work? https://dbalsom.github.io/martypc/web/player.html?title=freedos

Yes, it does.

dbalsom commented 1 year ago

Tried copying the "preferred" 5160 ROM files from the MAME set, didn't work, the second set listed in the roms.txt file worked to boot. I have all four files in the directory with the same names the txt file specifies. (Separate issue, I suppose)

the names are ignored really, only the md5sum matches; is the md5 the same as what's listed here? https://github.com/dbalsom/martypc/wiki/ROMs

chungy commented 1 year ago

Yes, they're the same, but the emulator doesn't accept them.

graphixillusion commented 1 year ago

A few questions for you both, if you will:

  1. what kind of keyboard layout? US or some other layout?
  2. Which BIOS are you both using?
  3. is this a laptop keyboard or desktop/external keyboard?
  4. does the web player work? https://dbalsom.github.io/martypc/web/player.html?title=freedos
  1. I'm using IT layout;
  2. I'm using the preferred bios in the wiki page:

    BIOS_5160_09MAY86_U19_62X0819_68X4370_27256_F000.BIN  **** preferred ****
    32,768 bytes
    md5sum: f051b4bbc3b60c3a14df94a0e4ee720f
    -- and --
    
    BIOS_5160_09MAY86_U18_59X7268_62X0890_27256_F800.BIN  **** preferred ****
    32,768 bytes
    md5sum: 9696472098999c02217bf922786c1f4a
  3. It's a laptop keyboard, integrated one
  4. yep, the web player works, for my layout is shift+ò to make ":"
dbalsom commented 1 year ago

After consulting the Rust discord it looks like this is a bug in a dependency (winit), which has been fixed in a later version (0.29). This version includes a complete re-write of the library's keyboard handling. I am going to work on upgrading the dependency today; there are a few breaking changes with the keyboard interface, but if it works I will make a new release along with the new composite stuff.

dbalsom commented 1 year ago

Unfortunately the egui binding for winit is still stuck at 0.28, and would need to be updated for the new keyboard events in 0.29. Maybe theres some other workaround.

I tried to reproduce by adding the Italian keyboard layout to Windows but I can still use the shift key and type characters on the number row...

dbalsom commented 1 year ago

I don't want people to have to wait for egui to update to winit 0.29, especially since it's in beta and I haven't seen a pull request to even start on it yet. So I forked egui and I will update it myself.

edit: Good news is that it appears the main bug is fixed, bad news is that there are some brand new bugs now. I'm still learning how the new keyboard system in 0.29 works. You can get physical or logical keyboard events, and logical events return strings now instead of characters.

dbalsom commented 1 year ago

Could either of you build branch 0_1_3 and tell me if the issue is fixed?

graphixillusion commented 1 year ago

Could either of you build branch 0_1_3 and tell me if the issue is fixed?

It requires the rust msvc toolchain ?

dbalsom commented 1 year ago

Could either of you build branch 0_1_3 and tell me if the issue is fixed?

It requires the rust msvc toolchain ?

yeah building on windows is a bit of a pain, you'd need to install msvc/visual studio... I can make a 'test release' here in a bit for you to try

edit: https://github.com/dbalsom/martypc/releases/tag/0.1.3_testing Drop the executable over the 0.1.2 release

graphixillusion commented 1 year ago

@dbalsom crash upon start:

Failed to parse configuration file. There may be a typo or otherwise invalid toml: missing field composite for key machine at line 176 column 1

dbalsom commented 1 year ago

sorry, just add a line composite=false to the martypc.toml file under video="CGA"

that's from the new composite code in 0.1.3 :)

graphixillusion commented 1 year ago

@dbalsom Yep now it works, but it still keeping US layout. Is it possible to add an option to set key to IT? By the way now the shift key works

dbalsom commented 1 year ago

the new keyboard system is based on physical scancode, so in theory, you would need to set the keyboard layout in the emulated machine and it should work.

If you have DOS 3.30 or later loaded, try typing

KEYB IT,850 C:\DOS\KEYBOARD.SYS

more info: http://info.wsisiz.edu.pl/~bse26236/batutil/help/KEYB_S.HTM

dbalsom commented 1 year ago

can you check too that you can copy and paste to and from the breakpoint fields in CPU control?

graphixillusion commented 1 year ago

can you check too that you can copy and paste to and from the breakpoint fields in CPU control?

yep, copy and paste works in breakpoint filed under cpu control

dbalsom commented 1 year ago

Just want to make sure nothing is remaining before I close this and work on putting out the new release. Everything good now?

graphixillusion commented 1 year ago

For now seems so... Sorry for the little OT but i have searched around but still can't understand how to manually boot to the basic rom...

dbalsom commented 1 year ago

to get into ROM basic you can't have a hard disk installed or a floppy disk inserted. so make sure your hdc="None"

to expand on this some, it was expected for most users to use the BASICA interpreter once DOS was installed. This actualy uses the ROM basic and extends it, adding disk support and other things.

graphixillusion commented 1 year ago

@dbalsom I don't know if this is a dos issue or it's some sort of bug but even if i set the keyboard to italian into the dos, some keys are wrong, for example if i press the esc key it does the esc function + print the \ char. If i press the |\ key which is under the esc key in my layout, dos will print ù <> key (which is next to the left shift) doesn't do anything ù key ---> < char

dbalsom commented 1 year ago

there are some different options we could try with the KEYB utility... i wonder though could you send me a picture of your keyboard or link me to a picture online of a keyboard that matches your layout

graphixillusion commented 1 year ago

@dbalsom here: https://i.postimg.cc/nhcPY2Pq/keyboard.jpg

dbalsom commented 1 year ago

now all i have to do is try to find a picture of an ancient 83 key italian keyboard... it's possible the layout has changed since the 80's. Obviously we added the euro symbol

when i added mappings from modern scancodes to XT scancodes I am afraid i was a bit US-centric; obviously i was only aware of the keys that I have on my keyboard, other layouts may have entirely new keys that generate different scancodes...

edit: the 'esc' issue happens on a US keyboard too. Whoops...

graphixillusion commented 1 year ago

@dbalsom the layouts of the keyboards are in this manual i've found:

http://messui.polygonal-moogle.com/training/MSDOS_330.pdf

(page 325)

dbalsom commented 1 year ago

@dbalsom the layouts of the keyboards are in this manual i've found:

oh wow this is great! thanks!

dbalsom commented 1 year ago

image

I think i see the problem. compared to the 80's IT layout we have a few problems: >< key had \ on it originally, but this was split off to two new keys, >< and |. Not sure why ESC would map to either... But in either case the >< has no equivalent on the US layout, so I don't have a scancode mapping for it. There's probably a lot of keys like this on different layouts, and I am not sure how I'd handle them all. Handling all these keyboards properly is going to be some work.

I think what might be necessary is that I have keyboard-translation files, and rely on contributors to help me make them. In next build i will have a debug_keyboard flag that will print all the scancode/keycode information to the console when you press a key. I'll get a test build up this weekend.

edit: on keys that have 3 symbols, how do you type the 3rd?

graphixillusion commented 1 year ago

@dbalsom

  1. normal press = first char
  2. shift + key = second char
  3. altgr + key = third char

(altgr key == ctrl+alt)

dbalsom commented 1 year ago

hitting ctrl-alt-< on one hand on that 80's keyboard must have been uncomfortable. were you supposed to reach over with your right?

dbalsom commented 1 year ago

@graphixillusion can you run this program and hit that >< key and tell me what it reports https://lateralus138.github.io/Key-ScanCode/

graphixillusion commented 1 year ago

@dbalsom

KEY: <
SC: 056
VK: 0xE2

KEY: \
SC: 029
VK: 0xDC
dbalsom commented 1 year ago

well I missed the absolute most obvious way to debug this. I added the Italian keyboard layout to windows, and now when I switch to it the Windows OSD switches to Italian layout:

image

dbalsom commented 1 year ago

Thanks for being patient; I'm working on an all-new keyboard system for 0.1.4. It's a big change, but it lays the groundwork for supporting additional keyboard types, like the Model M enhanced keyboard. Now we ignore the host typematic repeat rate, and run the keyboard along with other devices so we have a configurable typematic delay and repeat rate for the emulated machine.

This should improve compatibility in certain titles when the host has a fast typematic repeat rate set that was filling the keyboard buffer too quickly.

In addition, the new keyboard system supports keyboard translation files, so that we can synthesize scancodes based on modifier state, this should assist in mapping modern International keyboard layouts to their 1980's equivalents, based on the emulated keyboard model. This system is pretty flexible, and you can add arbitrary keys to it, so if you want to map say, the "volume up" multimedia key on your keyboard (which obviously has no 1980's equivalent) to an arbitrary series of scancodes to effectively make a custom macro, you can do so.

I am working on a translation file for the Italian layout, and I suppose I will try to cover most of the major European countries, but I may need help from my users to contribute new translation files.

dbalsom commented 1 year ago

Turns out that wasn't the original, original, italian IBM model F keyboard layout. The Model F was originally produced in French, German, Italian, Spanish, UK and of course, US layouts. Correspondingly, those will be my initial targets for translation files.

Here's the original Italian layout: image

You can see the modern backslash key is actually the escape key here (by the way, hitting escape at the dos prompt does produce a backslash, even on a US keyboard on a real IBM 5150, not sure why I didn't notice that before)

I assume that is the backslash symbol lurking under the key face on the >< key, but I am at a loss for how you would generate a | character here, I don't see it anywhere.

Given the macro support I have, I could have the | character generate the requisite ALT+numpad ascii escape sequence, if necessary, but that may not work in all applications.

graphixillusion commented 1 year ago

yep, infact the | key is the problem...

dbalsom commented 1 year ago

Ok, got a little demo of the remapping system in action. https://www.youtube.com/watch?v=qEV8z-4kGV8

For something so simple, this was surprisingly complicated, but I think the remapping system will be quite flexible.

You can see the last three shift-keys did not produce the same characters on a modern keyboard. This could be addressed too, I just mainly made mappings for the three problematic keys so far. You'll be able to toggle mapping off as well if you want to have a raw 1980's keyboard experience.

I'll try to put up a test build soon so you can try it out.

dbalsom commented 6 months ago

0.2.0 is finally out with keyboard translation support. I have some documentation to update, but hopefully this takes care of things. Feel free to open a new issue if you're still having problems in 0.2.0.

graphixillusion commented 6 months ago

A little update: i've tried the version 0.2.0 and now almost all key works.

  1. The <> key which is between the left shift and the Z doesn't work.
  2. The ù key prints < and shift +ù prints >.
  3. \ key (under the esc and left to the 1) prints ù char
  4. left ctrl + left alt + ù prints the \
  5. the only way to do the | is to left alt + the sequence 1,2,4 on the numpad.

I saw the new keyboard_IT.toml config but i think this config is not reflecting the actual behaviour.

keycode_mappings = [
    # Map the '<>' key to IntlBackslash. 
    {keycode="IntlBackslash", modifiers=["any"], key_macro=[], macro_translate=false, scancodes=[0x2B]},      
    # Map the ù key to Backquote
    {keycode="Backslash", modifiers=["any"], key_macro=[], macro_translate=false, scancodes=[0x29]},   
    # Generate a backslash.
    {keycode="Backquote", modifiers=["any"], key_macro=["+ControlLeft", "+AltLeft", "+IntlBackslash", "-ControlLeft", "-AltLeft", "-IntlBackslash"], macro_translate=false, scancodes=[]},
    # Generate a pipe character. There is no equivalent on the italian model F.
    {keycode="Backquote", modifiers=["shift"], key_macro=["+AltLeft", "+Numpad1", "+Numpad2", "+Numpad4", "-AltLeft",  "-Numpad1", "-Numpad2", "-Numpad4"], macro_translate=false, scancodes=[]},      
]
dbalsom commented 6 months ago

i cannot reproduce. did you select keyboard_layout="IT" in martypc.toml and load KEYB IT,850 C:\DOS\KEYBOARD.SYS ?

graphixillusion commented 6 months ago

During my first try i didn't set the it layout in the toml but inside the dos the keyb was already set to keyb it 850. Now i tried again with the toml setting and load that line in autoexec.bat but nothing changed

dbalsom commented 6 months ago

can you set this environment variable RUST_LOG=debug,naga=error,wgpu_core=error,wgpu_hal=error

and then set the debug_keyboard=true value in martypc.toml ( under [emulator.input])

when you hit some keys it will print some debugs. can you try a few of the problem keys and share the output please?

graphixillusion commented 6 months ago

Sure, here we are and sorry for late answer:

<> key:

KeyEvent { physical_key: Code(IntlBackslash), logical_key: Character("<"), text: Some("<"), location: Standard, state: Pressed, repeat: false, platform_specific: KeyEventExtra { text_with_all_modifers: Some("<"), key_without_modifiers: Character("<") } }
Window: WindowId(WindowId(199582)) Key pressed: IntlBackslash
[2024-04-04T23:12:47Z WARN  marty_core::devices::keyboard] key_down(): Got no scancode translation for key: IntlBackslash
KeyEvent { physical_key: Code(IntlBackslash), logical_key: Character("<"), text: None, location: Standard, state: Released, repeat: false, platform_specific: KeyEventExtra { text_with_all_modifers: None, key_without_modifiers: Character("<") } }
Window: WindowId(WindowId(199582)) Key released: IntlBackslash

\| key:

KeyEvent { physical_key: Code(Backquote), logical_key: Character("\\"), text: Some("\\"), location: Standard, state: Pressed, repeat: false, platform_specific: KeyEventExtra { text_with_all_modifers: Some("\\"), key_without_modifiers: Character("\\") } }
Window: WindowId(WindowId(199582)) Key pressed: Backquote
KeyEvent { physical_key: Code(Backquote), logical_key: Character("\\"), text: None, location: Standard, state: Released, repeat: false, platform_specific: KeyEventExtra { text_with_all_modifers: None, key_without_modifiers: Character("\\") } }
Window: WindowId(WindowId(199582)) Key released: Backquote

ù key:

KeyEvent { physical_key: Code(Backslash), logical_key: Character("ù"), text: Some("ù"), location: Standard, state: Pressed, repeat: false, platform_specific: KeyEventExtra { text_with_all_modifers: Some("ù"), key_without_modifiers: Character("ù") } }
Window: WindowId(WindowId(199582)) Key pressed: Backslash
KeyEvent { physical_key: Code(Backslash), logical_key: Character("ù"), text: None, location: Standard, state: Released, repeat: false, platform_specific: KeyEventExtra { text_with_all_modifers: None, key_without_modifiers: Character("ù") } }
Window: WindowId(WindowId(199582)) Key released: Backslash
dbalsom commented 6 months ago

I found the problem... I missed a line in the config in the release :P

add this line to the paths array under [emulator]

{ resource = "keyboard_layout", path = "$basedir$/configs/keyboard_layouts", create = false },

if successful you should see this printed out as one of the last lines when starting martypc from console:

Loaded keyboard mapping file: ./configs/keyboard_layouts\keyboard_IT.toml

graphixillusion commented 6 months ago

I confirm, with this line everything works! Thank you very much for the super support!

dbalsom commented 6 months ago

Awesome! I even bought an italian keyboard on ebay so I wanted to make sure it worked. Still have to make mappings for other layouts. I think we also have to add altgr scancodes.