isotherm / betawise

Tools to create applets for the AlphaSmart NEO / NEO2.
MIT License
39 stars 4 forks source link

Custom keyboard layouts (saving data; hooking system calls) #10

Open NicolasMacon opened 1 year ago

NicolasMacon commented 1 year ago

Hello Team, thanks to your tool I started to write an applet with FRench Keyboard Layout. I am able to enter data on NEO screen but how to save data in NEO? I did not find any functions in library.

Thanks a lot

isotherm commented 1 year ago

Hello! We do not have functions to access the files fully documented quite yet. The file functions are syscalls 102 to 115 and you can see very brief comments about them in syscall.c. If you are interested in using Debugging Tool to help discover and document more, then that would be one option.

However, the Alphasmart supports alternative keyboard layouts (see syscalls 90 to 92). I would have to verify, but I think it may be possible to simply create an applet that installs an alternative keyboard layout that works across all apps in the system. I will try to investigate that option as I have time...

NicolasMacon commented 1 year ago

Thank you for your answer ) . I will check syscall.c on my side also. Yes you're right the idea is no install an alternative keyboard. Thanks again!

isotherm commented 1 year ago

The Alphasmart supports 4 keyboard layouts: QWERTY, DVORAK, left-hand, right-hand. After a quick look, I see that unfortunately the keyboard layout support uses a set of hard-coded tables in the ROM. A few options there:

NicolasMacon commented 1 year ago

Thanks a lot. I think First option is the best yes) If you have table format and address I am intersested)

isotherm commented 1 year ago

Ok, I looked at how this works some more. It works like this:

  1. Keyboard layouts provide for shuffling of the same keys, translating one key code to another key code. We cannot use this except for layouts like DVORAK, which just shuffle keys. French or other keyboard layouts redefine the meaning of some keys.
  2. After this, there is a routine (syscall 89) which translates key code into a character. However, it makes many assumptions, for example, that Shift key should always capitalize a letter. This is not true on the French or other keyboard layouts.

So we would have to write some new code to replace this subroutine if we are going to provide a patch. This is doable but more complicated than just changing some table values.

The hooks as mentioned above can be an option. So, I am renaming this issue to give a better description. There are a lot of useful features that can be created if we provide a method to install hooks.

Note that others have solved this problem by making a custom font. I believe that pushing Send on Alphasmart still types properly, since the computer interprets the keys as from a French keyboard; or if transferring text files back and forth, a program on the computer could perform the translation.

NicolasMacon commented 1 year ago

Ok I see! Thanks for clarification. I would be intersted to see table you mentionned just ba curiosity. ( I understood this is not a satisfying solution) Yes Custom is as I though at first. (Needs as you said to translate in computer). I found on github a program called NEOFONT manager but it works on mac, and I struggled to install MACOS on virtualbox so I did not go further.

isotherm commented 1 year ago

You can create fonts with Betawise, as long as they are fixed width; see the NeoFontTerminal in this repo. (Well, you can make variable width fonts too, but I don't have any documentation or generation code for it.) So you could just rearrange the glyphs in the image in NeoFontTerminal and regenerate a new font for French.

In latest Neo US ROM, the keyboard layout translation tables are at 0x44C3FB. (ROM origin is 0x410000 so this is offset 0x3C3FB in the ROM file.) The table should begin 0x25 0x25 0x25 0x01 0x01 0x01 etc. It is 3 sequential bytes for each key code, with each byte telling what key code to translate to for layout 2, 3, and 4.

So, for example, key code 0x00 (KEY_RIGHTBRACE) is to translate to key code 0x25 (KEY_EQUAL) in all 3 layouts; key code 0x01 (KEY_FILE_7) remains the same; key code 0x02 (KEY_LEFTBRACE) translates to different key codes in each layout: 0x47 (KEY_SLASH), 0x2F (KEY_5), 0x14 (KEY_SEMICOLON) respectively.

There are also lookup tables that help the Neo enter the foreign characters the way it currently does (i.e. Cmd+E E to give E with acute accent), but unfortunately this is only used if Ctrl or Cmd are held down, so it is not useful for making new layouts easily.

NicolasMacon commented 1 year ago

Thanks for this explanation, I will check this asap! Just one last question: Where did you get rom Dump? (maybe it's possible to dump and re upload through neo manager? )