Programs which I wrote

This is a game called X Labyrinth - the aMAZEment: it works under any UNIX system with X windows (at least, I have tested it under Linux and SunOS). The goal of the game is to solve a maze with your mouse; but the fun part is that the walls of the maze actually block the mouse. It is distributed under the terms of the GNU General Public License.

I have also written a program called SIMPLE - Simple Is a Macro Processing Language Element. You can learn more about SIMPLE here.

Apart from that, the only thing I have are two programs, called record.c and playback.c which will record and play raw sound files through /dev/dsp.

For my other programs, check my programs page.

Setup and all that

Keyboard questions

(This should answer in particular the following VFAQ: my backspace and delete keys don't work the way I want them to, why is that?)

To summarize: when the key is pressed, the keyboard sends a scan code on one of the ports, and the CPU receives an interruption (IRQ1 I think). The linux kernel receives the interruption, reads the scan code, and converts it to a key code. Finally, this key code is turned to an ascii character which is read by whatever process is running. Unfortunately, thins aren't that simple. First of all, the keyboard knows three different ways of converting keys to scan codes, called scan tables 1, 2 and 3. Scan table 3 is the most logical one (well... sort of), and it has many advantages (for example, every key has programmable auto-repeat, which is not the case for the other scan tables, and also every key sends one and exactly one byte of scan code); however, this is NOT the table used by the linux kernel: it uses scan table 2. Second, the keyboard can be used in four modes: raw mode (in which /dev/console returns scan codes), semi-raw mode (in which key codes are returned), and translated mode (in which ascii characters are produced). [Note that this has nothing to do with the "raw" and "cooked" modes which refer to the way a process will receive control characters.] The keyboard mode can be read and modified using kbd_mode. Third, X sets the keyboard in raw mode, and does its own three-step translation: from scan codes to key codes, from key codes to keysyms and from keysyms to ascii characters. To make things simpler, the key codes produced by X are NOT the same as those produced by the linux kernel when keyboard is in semi-raw mode (and this is not for compatibility with other X platforms since the keycodes are also different, e.g., on a sun keyboard). Keysyms, however, are universal. The key "a" will have the same keysym on a QWERTY or AZERTY keyboard (if the xmodmap is correctly set, that is...). The list of supported keysyms (16-bit integers) can be found in one of the X11 include files, I never know which. The translation from keysyms to ascii codes is done by XLookupString, but I never understood how this one works. So we can summarize all this with the following picture:

key pressed
    | [Inside keyboard; 3 possible tables]
    v
scan code [Stops here if keyboard mode is raw]
    |
    +----------------------------+
    | [Linux kernel]             | [X11]
    v                            v
linux keycode                 X11 keycode
    | [loadkeys]                 | [xmodmap]
    v                            v
ascii character(s)/action     keysym
    | [running process]          | [wm might intercept]
    v                            v
whatever                      keysym if not intercepted by wm
                                 | [program]
                                 v
                              whatever
Not very clear, but that's the best I managed to do.

Concerning backspace and delete

For historical reasons, I guess, there are two control characters which mean "erase the last character": ^H (ascii character 0x08=8) and ^? (ascii character 0x7f=127). There is no control character which says "erase the next character", because erasing the next character (the one under the cursor) implies you were able to move the cursor, so you must have very sophisticated line-editing capabilities, so if you have a convention for sending the arrow keys you can probably use that convention for the delete key too. The VT escape sequence for "delete next char" is ^[[3~ (escape (0x1b) open bracket three tilde). When there are no line editing capabilites, foe example in the primitive shells like the original sh and csh, the only possible action is "erase the character on the left". Exactly which control character will do that is specified using stty (for example stty erase "^H" specifies that ^H should be used). This is not always correctly set: sometimes the backspace key sends ^H whereas the last-character-correction key is ^? (the converse is less frequent). This should be corrected with stty. Unfortunately, some X11 systems correct this by using xmodmap instead, thus assigning the BackSpace keysym to the delete key, and the Delete keysym to the backspace key. Since X-oriented programs like netscape read keysyms and not ascii characters (and even less pay attention to the state of stty), this has the pernicious effect of inverting the backspace and delete keys under these programs. I suggest using ^H for backspace (that is, putting a line like

keycode  14 = BackSpace        BackSpace
in the keyboard map file used, which is generally found in /usr/lib/kbd/keytables/something.map), specifying it with stty in the /etc/profile (or /etc/zprofile), or whatever file is used), and making sure X is getting all that right with a line like
keycode 22 = BackSpace
in the .xmodmaprc file (the .xmodmaprc file should be loaded by the .xinitrc or .Xclients file with something like
if [ -f .xmodmaprc ]; then
        xmodmap .xmodmaprc &
fi
). And all should be for the best in the best of all possible worlds.

Table of (some) keys found on (some) keyboards

Key engraving/name Scan 1 Scan 2 Scan 3 Linux keycode X keycode
Escape0x760x010x0811
F10x050x3b0x075967
F20x060x3c0x0f6068
F30x040x3d0x176169
F40x0c0x3e0x1f6270
F50x030x3f0x276371
F60x0b0x400x2f6472
F70x830x410x376573
F80x0a0x420x3f6674
F90x010x430x476775
F100x090x440x4f6876
F110x780x570x568795
F120x070x580x5e8896
Print Screen0xe0 0x12 0xe0 0x7c0xe0 0x2a 0xe0 0x370x5799111
Scroll Lock0x7e0x460x5f7078
Pause0xe1 0x14 0x77 0xe10xe1 0x1d 0x45 0xe10x62119/101110
`~0x0e0x290x0e4149
1!0x160x020x16210
2@0x1e0x030x1e311
2@0x1e0x030x1e311
3#0x260x040x26412
4$0x250x050x25513
5%0x2e0x060x2e614
=+0x550x0d0x551321
Backspace0x660x0e0x661422
Tab0x0d0x0f0x0d1523
Q0x150x100x151624
W0x1d0x110x1d1725
]}0x5b0x1b0x5b2735
\|0x5d0x2b0x5c4351
Caps lock0x580x3a0x145866
A0x1c0x1e0x1c3038
'"0x520x280x524048
Enter0x5a0x1c0x5a2836
Shift (left)0x120x2a0x124250
Z0x1a0x2c0x1a8694
Shift (right)0x590x360x595462
Control (l)0x140x1d0x112937
Winlogo (l)???125115
Alt (l)0x110x380x195664
Space bar0x290x390x295765
Alt (r)0xe0 0x110xe0 0x380x39100113
Winlogo (r)???126116
Winmenu???127117
Control (r)0xe0 0x140xe0 0x1d0x5897109

Configuration files

I reinstalled Linux on both of my computers recently (I have a PPro200 called ``pleiades'' and a 486DX33 called ``sirius'', connected by a local ethernet - the modem is on sirius and that is its main use). I have kept a log of everything I did as root, and here it is if it can be of use to anyone:

Coming soon on this page: a tar.gz archive of my /etc directories (minus a few confidential files, of course).