Skip to content

Specific keyboard mapping issues

Emerson José Silveira da Costa edited this page Jan 6, 2014 · 6 revisions

CCE MC-1000

Tried using the MC-1000 emulation — http://jsmess.textfiles.com/messloader.html?module=mc1000&scale=2 — on the notebooks I have at home:

And in both I had keyboard mapping issues.

MC-1000's keyboard is this: http://www.ricbit.com/mundobizarro/brmc1000.1.png (Note, there's one mistake in this image. SHIFT+S gives "STEP", not "STOP".)

Some mappings (as defined in the MESS MC-1000 device source code) didn't work at all:

PC → MC-1000 key mapping Result in MacBook Keycode in MacBook Result in Vostro/ABNT-2 Keycode in Vostro/ABNT-2
- _- = Nothing 189 Nothing 189
= +@ Nothing 187 Nothing 187
[ { Nothing 219 Nothing 221
; :; + Nothing 186 / ? 191
' ": * Nothing 222 : * (OK!) 192
/ ?/ ? / ? (OK!) 191 Nothing 193

Some mappings worked in unexpected locations:

PC key Result in MacBook Keycode in MacBook Result in Vostro/ABNT-2 Keycode in Vostro/ABNT-2
Insert N/A N/A - = 45
Command ⌘ 91 N/A N/A
Windows N/A N/A 91
` ~ : * 192 N/A N/A

Additional info on MC-1000 keyboard and its emulation in MESS:

  • MC-1000 has no lowercase characters. So the combinations SHIFT+letter were used to fast-type some of the BASIC commands.
  • RETURN = Enter/Return. RUBOUT = Backspace. SHIFT+RESET resets the MC-1000 (not currently implemented in the emulation) (RESET alone does nothing).
  • is an ordinary character, and it is used in BASIC as the exponentiation operator. It was used in an old version of ASCII where today we have the ^ caracter.
  • The emulation has a menu "Keyboard Mode" with two options: "Emulated" and "Natural". In "Emulated" mode we have a one-to-one mapping between PC and MC-1000 keys. = is used for @, [ is used for , SHIFT+2 gives ", SHIFT+; gives +. In "Natural" mode, you type observing the PC keyboard labels, and that is translated to the corresponding key combinations in MC-1000 keyboard. You type SHIFT+2 to get @ (it is translated to a MC-1000 @ key press without SHIFT), you type = to get = (it is translated to a MC-1000 - key press with SHIFT) and so on.

Chat at EFNet IRC channel #jsmess:

ensjo: "natural" mode is good for ordinary typing. the "emulated" may be required for some programs, where the position of the keys is meaningful.

vito: so it sounds like natural mode, maybe an on-screen button for SHIFT+RESET, and either on-screen buttons or defining the special BASIC shortcuts and showing an illustration for them, would be a reasonable way to go

ensjo: it seems so. but if one uses a tablet or similar device without keyboard, the "emulated" mode, showing a full (touchable) image of the original keyboard, seems fitter.

Incomplete keycode translation?

I (ensjo) tried the emulation of CoCo2 — http://jsmess.textfiles.com/messloader.html?module=coco2 —, and observed that the same problems I reported for MC-1000: Not getting all the keys CoCo has, getting - by pressing PC Insert etc.

Back to the MC-1000 emulation, I used Chrome's Developer Tools and managed to pause the emulation and view a big JavaScript piece of code starting with:

if(!window.console){ window.console = {log: function(){} }; }
var JSMESS = JSMESS || {};
JSMESS.MESS_BUILD_VERSION = " 0.151 (commit 9ab93dedec570abc22e640434eb6e81912f8854f)";
JSMESS.EMCC_VERSION = "emcc (Emscripten GCC-like replacement) 1.8.2 (commit c0beb1cff3a831039884f90ef2978e2345610992)";
JSMESS.EMCC_FLAGS = "  -O2 -s DISABLE_EXCEPTION_CATCHING=0 -s ALIASING_FUNCTION_POINTERS=1 -s OUTLINING_LIMIT=20000 -s TOTAL_MEMORY=33554432 -s EXPORTED_FUNCTIONS=\"[_main, _malloc, __Z15ui_set_show_fpsi, __Z15ui_get_show_fpsv]\"";
JSMESS.MESS_FLAGS = "  OSD=sdl        NOWERROR=1     TARGET=mess SUBTARGET=mc1000 SYSTEM=mc1000 VERBOSE=1   CROSS_BUILD=1 NATIVE_OBJ=\"/1/JSMESS/jsmess/jsmess/third_party/mame/obj/nativesdl64\" TARGETOS=emscripten PTR64=0 OPTIMIZE=2";
console.log("MESS BUILD_VERSION == " + JSMESS.MESS_BUILD_VERSION);
console.log("EMCC VERSION == " + JSMESS.EMCC_VERSION);
console.log("EMCC_FLAGS == " + JSMESS.EMCC_FLAGS);
console.log("MESS_FLAGS == " + JSMESS.MESS_FLAGS);
// Note: Some Emscripten settings will significantly limit the speed of the generated code.

and so on.

I searched for "keycode" and found this point where a translation was being made:

        switch (event.type) {
          case 'keydown': case 'keyup': {
            var down = event.type === 'keydown';
            var code = event.keyCode;
            if (code >= 65 && code <= 90) {
              code += 32; // make lowercase for SDL
            } else {
              code = SDL.keyCodes[event.keyCode] || event.keyCode;
            }

The variable code will receive the value of event.keyCode, OR the value in the corresponding position in the SDL.keyCodes array, if it contains any value.

Searching for "keycodes" I found where the array is defined:

      }};var SDL={ ... keyCodes:{16:1249,17:1248,18:1250,33:1099,34:1102,37:1104,38:1106,39:1103,40:1105,46:127,96:1112,97:1113,98:1114,99:1115,100:1116,101:1117,102:1118,103:1119,104:1120,105:1121,112:1082,113:1083,114:1084,115:1085,116:1086,117:1087,118:1088,119:1089,120:1090,121:1091,122:1092,123:1093,173:45,188:44,190:46,191:47,192:96}, ...

That array maps event.keyCode values to other values that I don't recognize (a code used internally by SDL?). 16 (Shift) is translated to 1249, and so on. At the end of the array we see keys corresponding to characters being translated to the ASCII codes of those characters. But the list seems to be incomplete:

  • 173 (unknown keyCode) → 45 (ASCII -)
  • 188 (, keyCode) → 44 (ASCII ,)
  • 190 (. keyCode) → 46 (ASCII .)
  • 191 (/ keyCode) → 47 (ASCII /)
  • 192 (` keyCode) → 96 (ASCII `)

Note that there's no translation for the Insert keyCode (45). That explains why we get - (ASCII 45) by pressing Insert! Insert (and probably other special key codes) should have a translation too, but I don't know what number they should be translated to.

Obviously there should also be:

  • 219 ([ keyCode) → 91 (ASCII [)
  • 220 (\ keyCode) → 92 (ASCII \)
  • 221 (] keyCode) → 93 (ASCII ])
  • 222 (' keyCode) → 39 (ASCII ')

;, = and - are tricky, because their keyCodes vary across browsers, as one can see here: http://www.javascripter.net/faq/keycodes.htm . Assuming the codes common to MSIE, Safari and Chrome we should have:

  • 186 (; keyCode) → 59 (ASCII ;)
  • 187 (= keyCode) → 61 (ASCII =)
  • 189 (- keyCode) → 45 (ASCII -) (The translation from 173 in the current array seems to be wrong.)

(Now, where is that correction supposed to be done?)