Most of the keyboard-related bugs should have gone away. Hope I didn't
introduce too many new ones (-:
Keyboard emulation should be more accurate now; some keys are supported
that weren't before, e.g. Pause.

The X { keycode } option is now obsolete. This was basically a bad hack
to make things work, and was incompatible to X servers other than XFree86.

To the dosemu hacker:

While the old code already claimed to be "client-server" (and was, to
some extent), the new code introduces a clean, well-defined interface
between the `server', which is the interface to DOS (int9, bios etc.),
and the `clients', which are the interfaces to the user frontends supported
by dosemu. Currently, clients are `raw', `slang' (i.e. terminal), and `X'.

Clients send keystrokes to the server through the interface mentioned
above (which is defined in "keyboard.h"), the most important functions being
`putkey()' and `putrawkey()'.

The keyboard server was rewritten from scratch, the clients were heavily
modified.

There is now general and efficient support for pasting large text objects.
Simply call paste_text().

The keyboard-related code is now largely confined to base/keyboard,
rather than scattered around in various files.

There is a compile-time option NEW_KBD_CODE (on by default) to activate the
new keyboard code. The old stuff is still in there, but I haven't recently checked
whether it still works, or even compiles. Once the new code is reasonably well tested
I'll remove it.
( *HH: the old code is made workeable and remains ON per default, it will
stay maintained for a while, so we can easily check where the bugs come
from )

Just like the old keyboard code, we still have the rawkeyboard=on/off and
keybint=on/off modes.

This is all you should need to know if you just want to send keystrokes
to DOS.

Use the functions

putrawkey(t_rawkeycode code);

putkey(Boolean make, t_keysym key)

putkey_shift(Boolean make, t_keysym key, t_shiftstate shiftstate)

You may also read (but not write!) the variable 'shiftstate' if necessary.

ehm... see the DANG comments in base/newkbd-server.c for more information...

NOTE: the server's queue is limited to a relatively small number of keyboard
events (currently 15). IMO, it is not a good idea to let the queue be
arbitrarily long, as this would render the behaviour more incontrollable
if the user typed a lot of mad things while a dos program wasn't polling the
keyboard.

For pasting, there is special support in base/keyboard/keyb_clients.c which
runs on top of the server.

[NOTE: you won't need to read this unless you actually want to modify
the keyboard server code. In that case, however, you MUST read it!]

[Note: I'll have to update this. The queue backend works somewhat different
now.]

The central data structure of the keyboard server is the dosemu keyboard
queue (to be distinguished from the bios keyboard buffer, which is run
by int09 and int16).

The keyboard server code can be largely divided into the `queue frontend'
(serv_xlat.c, serv_maps.c), which does keycode translation, and the
`queue backend' (serv_backend.c, serv_8042.c), which does the interfacing
to DOS. The two sides communicate only through the queue.

Each queue entry holds a data structure corresponding to (mostly)
one keypress or release event. [The exception are the braindead
0xe02a / 0xe0aa shift key emulation codes the keyboard processor
`decorates' some kinds of keyboard events with, which for convenience
are treated as seperate events.]

Each queue entry holds a up to 4 bytes of raw keycodes for the
port 60h emulation, along with a 2-byte translated int16h keycode
and the shift state after this event was processed.
Note that the bios_key field can be empty (=0), e.g. for shift keys,
while the raw field should always contain something.

Transfer of the keyboard events from the dosemu queue to DOS is done in
two completely different ways, depending on the keybint setting in
dosemu.conf:

keybint=off

kbd_process() simply reads the queue until it finds a bios keycode
(as we're not interested in raw scancodes without int9 emulation),
which it stores in the bios keyboard buffer, while also copying
the shift state to the appropriate bios variables.

keybint=on

As soon as a key is stored into the empty queue, kbd_process() triggers
IRQ1 through the PIC emulation, which some time later will call do_irq1().

do_irq1() will prepare for the interrupt execution by reading from
the queue and storing the values in the variables raw_buffer,
shiftstate_buffer, and bios_buffer, and then call run_irq() to
run the actual DOS interrupt handler.

again, there are two cases:

the default int09 handler in the dosemu bios (base/bios_emu.S)
will call the helper function get_bios_key(), which returns
the translated bios keycode from bios_buffer and copies the
shiftstate from shiftstate_buffer. The raw keycodes are not used.
get_bios_key() may also return 0 if no translated keycode is
ready.

The int9 handler will also call the `keyboard hook' int15h, ax=????.

if a dos application or TSR has redirected the keyboard interrupt,
its handler might read from port 60h to get raw scancodes.
Port 60h is of course virtualized, and the read returns the value
from raw_buffer.

Note that a mix between the two cases is also possible, e.g. a
TSR's int9 handler first reads port 60h to check if a particular
key was pressed, then gives over to the default int9 handler.
Even these cases should be (and are, I think) handled properly.

Note also that in any case, int9 is called once for each raw scancode
byte. Eg.,suppose the user pressed the PgDn key, whose raw
scancode is E0 51: