Keyboard layout

User avatar
gunrock
Posts: 245
Joined: 28 Oct 2020 21:17

Keyboard layout

Post by gunrock »

Is it possible to detect the keyboard layout via code? There might be a section in The Source, from the index Chapter 10 might cover it.
Steve G
Danish Memotech MTX 512, MFX and loving it
Bill B
Posts: 593
Joined: 26 Jan 2014 16:31

Re: Keyboard layout

Post by Bill B »

Bits 2 & 3 of input port 0x06 are supposed to return a Country Code, one of four values.

However, I am not sure exactly how these bits are set. The circuit diagram in the user manual shows a switch (SWA). However I don't think there is a switch, probably just some links.

Also, the connections for these bits do not go through the keyboard cable, so there is nothing to ensure that the setting of these bits corresponds to the keyboard that is actually attached.
User avatar
Dave
Posts: 1280
Joined: 11 Aug 2012 18:16
Contact:

Re: Keyboard layout

Post by Dave »

http://www.primrosebank.net/computers/ ... 0_crop.jpg

You can see the links in the attached photo, they are just below the Ear and Mic connectors. They are sprung wire staples that can be latched by hooking under the vertical part.

As well as the link selection and any code that might be in the ROM to switch character sets to, for example, German, the Scandinavian countries also had a ROM piggy backed on one of the existing OS ROM, and addressed as ROM7 to provide additional language support.

http://www.primrosebank.net/computers/ ... us_DK2.jpg
Bill B
Posts: 593
Joined: 26 Jan 2014 16:31

Re: Keyboard layout

Post by Bill B »

Memotech actually missed a trick here. The 8 x 10 keyboard matrix has three positions without any keys. By inserting or omitting wire links (or better diodes) in the position of those missing keys, they could have identified up to eight different keyboard layouts. And because the links would be on the keyboard PCB, not the main board, it would always be consistent.

However it is fortunate for us that they did not do this. The missing key positions are used by MEMU and the PC keyboard interface to resolve the problems caused by some characters having different shift states on the MTX and PC keyboards.
User avatar
gunrock
Posts: 245
Joined: 28 Oct 2020 21:17

Re: Keyboard layout

Post by gunrock »

Thanks guys, I have an interest as I have a Danish keyboard layout MTX 500 and in CP/M the keyboard follows the standard UK MTX layout, therefore I was searching for a command that might remap the layout, but I haven't used CP/M since the 80s (when I had to provide occasional IT support to a couple of Amstrad PCW machines).

Seems there isn't one in CP/M 2.2.
Steve G
Danish Memotech MTX 512, MFX and loving it
Martin A
Posts: 799
Joined: 09 Nov 2013 21:03

Re: Keyboard layout

Post by Martin A »

CPM runs with the keyboard tables in RAM so theoretically, a small COM file run at start up could poke in some alternatate codes.

It can even be tweaked with a small BBC basic program, the memory's not protected so the values can be tweaked with the BBC quivalent of poke. And will be retained when the program exits.

The eaxct position will vary a llttle depending on what the CPM hardware is. The keyboard is the "first" driver in the high memory area at F000. So won't move a lot.

I've just had a quick look at the assembler output, unshifted keys are at F1A2 to F1F2 and upper case F1F3 to F244 in recent CFX and CFX-2 builds.
User avatar
gunrock
Posts: 245
Joined: 28 Oct 2020 21:17

Re: Keyboard layout

Post by gunrock »

So apart from the obvious, can you tell me if this code is wrong?

On my machine, this code outputs 0. If it is working as I intend, I'm surprised as I have a Danish keyboard and ROM. I'd expect something other than zero.
20210404_005009.jpg
20210404_005009.jpg (145.94 KiB) Viewed 5710 times
Last edited by gunrock on 27 Oct 2021 11:08, edited 1 time in total.
Steve G
Danish Memotech MTX 512, MFX and loving it
User avatar
Dave
Posts: 1280
Joined: 11 Aug 2012 18:16
Contact:

Re: Keyboard layout

Post by Dave »

Assembler is not my thing, I'm sure that one of the experts will reply, but . . . . . FWIW . . . .

The behavior of the piggy back language ROMs is undocumented, but I think that for the languages that were supported by the standard ROM, e.g., German, then the switch position probably selected the special characters that were part of the standard ROM.

When there was a piggy back ROM such as yours, the extra ROM was probably switched in without any consideration of the keyboard selector switch, so it's probably not a surprise that the readback value of the DIP switch is different to what you might expect.

You could check your code by setting the switch position to different values and see if there is any change.
Bill B
Posts: 593
Joined: 26 Jan 2014 16:31

Re: Keyboard layout

Post by Bill B »

If you look at Dave's site here you will find at the bottom of the page a download link for "kbdfixup.zip". This is a small COM program for modifying the keyboard tables.

It is intended to add support for the phantom keys used by the PC keyboard interface, however the source code is included, and it should not be too difficult to modify it to set the tables appropriately for your keyboard.

It works by knowing what the default keyboard tables look like and searching for that pattern in memory before modifying them, so it should be independent of the exact CP?M hardware being used.
User avatar
gunrock
Posts: 245
Joined: 28 Oct 2020 21:17

Re: Keyboard layout

Post by gunrock »

Thanks for both of your replies, Dave and Bill.

@Dave, this seems to line up with my findings, as yesterday I experimented with the ESC codes defined in the manual in Appendix 2, to set my keyboard to other languages and tested various keys. Seems that the Nordics outside of Sweden (and maybe Italy. Wasn't there an Italian Business/2?) were an afterthought. Makes sense as Denmark, Norway and Finland are small markets.

@Bill, that's very helpful. The search for the tables was the logic I was thinking of, rather than just poking blindly into the memory addresses for the current CFX rom. I'll take a look.
Steve G
Danish Memotech MTX 512, MFX and loving it
Post Reply