# VICE keyboard mapping file
#
# A Keyboard map is read in as patch to the current map.
#
# File format:
# - comment lines start with '#'
# - keyword lines start with '!keyword'
# - normal lines have 'keysym/scancode row column shiftflag'
#
# Keywords and their lines are:
# '!CLEAR'               clear whole table
# '!INCLUDE filename'    read file as mapping file
# '!LSHIFT row col'      left shift keyboard row/column
# '!RSHIFT row col'      right shift keyboard row/column
# '!VSHIFT shiftkey'     virtual shift key (RSHIFT or LSHIFT)
# '!SHIFTL shiftkey'     shift lock key (RSHIFT or LSHIFT)
#  for emulated keyboards that have only one shift key, set both LSHIFT
#  and RSHIFT to the same row/col and use RSHIFT for VSHIFT and SHIFTL.
# '!LCTRL row col'       left control keyboard row/column
# '!VCTRL ctrlkey'       virtual control key (LCTRL)
# '!LCBM row col'        left CBM keyboard row/column
# '!VCBM cbmkey'         virtual CBM key (LCBM)
# '!UNDEF keysym'        remove keysym from table
#
# Shiftflag can have these values, flags can be ORed to combine them:
# 0x0000      0  key is not shifted for this keysym/scancode
# 0x0001      1  key is combined with shift for this keysym/scancode
# 0x0002      2  key is left shift on emulated machine
# 0x0004      4  key is right shift on emulated machine (use only this one
#                for emulated keyboards that have only one shift key)
# 0x0008      8  key can be shifted or not with this keysym/scancode
# 0x0010     16  deshift key for this keysym/scancode
# 0x0020     32  another definition for this keysym/scancode follows
# 0x0040     64  key is shift-lock on emulated machine
# 0x0080    128  shift modifier required on host
# 0x0100    256  key is used for an alternative keyboard mapping, e.g. C64 mode in x128
# 0x0200    512  alt-r (alt-gr) modifier required on host
# 0x0400   1024  ctrl modifier required on host
# 0x0800   2048  key is combined with cbm for this keysym/scancode
# 0x1000   4096  key is combined with ctrl for this keysym/scancode
# 0x2000   8192  key is (left) cbm on emulated machine
# 0x4000  16384  key is (left) ctrl on emulated machine
#
# Negative row values:
# 'keysym -1 n' joystick keymap A, direction n
# 'keysym -2 n' joystick keymap B, direction n
# 'keysym -3 0' first RESTORE key
# 'keysym -3 1' second RESTORE key
# 'keysym -4 0' 40/80 column key (x128)
# 'keysym -4 1' CAPS (ASCII/DIN) key (x128)
# 'keysym -5 n' joyport keypad, key n (not supported in x128)
#
# Joystick direction values:
# 0      Fire
# 1      South/West
# 2      South
# 3      South/East
# 4      West
# 5      East
# 6      North/West
# 7      North
# 8      North/East
#
# Joyport keypad key layout:
# --------------------------
# |  0 |  1 |  2 |  3 |  4 |
# --------------------------
# |  5 |  6 |  7 |  8 |  9 |
# --------------------------
# | 10 | 11 | 12 | 13 | 14 |
# --------------------------
# | 15 | 16 | 17 | 18 | 19 |
# --------------------------
#
# When a bigger spaced key is used,
# it uses the upper left most key value.

# Symbolic Mapping, US Layout, CBM2, SDL

# note: For some reason SDL does not get keyboard events for "dead keys" at all,
#       so a "nodeadkeys" layout must be used. CAUTION: apparently SDL generates
#       some tables internally at startup - switching the host layout while
#       the emulator is running produces unpredictable results (broken keycodes)

# Commodore cbm2 keyboard matrix:
#
# references:
#  http://www.zimmers.net/anonftp/pub/cbm/b/documents/de/keyboard-matrix.gif
#  http://www.zimmers.net/anonftp/pub/cbm/b/documents/keymap-us.gif
#  http://www.zimmers.net/anonftp/pub/cbm/schematics/computers/b/p500-keyboard.txt
#  http://www.floodgap.com/retrobits/ckb/secret/cbm-610-keyboard.jpg
#
# Keys starting with 'KP' are on the number pad. Both shifts and shift lock
# are in parallel at one point in matrix.
#
#       0        1        2        3        4        5
#   +--------+--------+--------+--------+--------+--------+
# 0 |   F9   |  9  (  |   O    |   L    |  ;  :  |  /  ?  |
#   +--------+--------+--------+--------+--------+--------+
# 1 |  F10   |  0  )  |   -    |   P    |   [    |  '  "  |
#   +--------+--------+--------+--------+--------+--------+
# 2 | c.down |  =  +  |<- pound|   ]    | return |  pi    |
#   +--------+--------+--------+--------+--------+--------+
# 3 | c.up   | c.left | c.right|del ins | CBM    |########|
#   +--------+--------+--------+--------+--------+--------+
# 4 |home/clr|KP ?    |KP 7    |KP 4    |KP 1    |KP 0    |
#   +--------+--------+--------+--------+--------+--------+
# 5 |rvs/off |KP CE   |KP 8    |KP 5    |KP 2    |KP .    |
#   +--------+--------+--------+--------+--------+--------+
# 6 | graph  |KP *    |KP 9    |KP 6    |KP 3    |KP 00   |
#   +--------+--------+--------+--------+--------+--------+
# 7 |run/stop|KP /    |KP -    |KP +    |KP enter|########|
#   +--------+--------+--------+--------+--------+--------+
# 8 |   F1   | escape |  TAB   |########| Shift  | CTRL   |
#   +--------+--------+--------+--------+--------+--------+
# 9 |   F2   |  1  !  |   Q    |   A    |   Z    |########|
#   +--------+--------+--------+--------+--------+--------+
#10 |   F3   |  2  @  |   W    |   S    |   X    |   C    |
#   +--------+--------+--------+--------+--------+--------+
#11 |   F4   |  3  #  |   E    |   D    |   F    |   V    |
#   +--------+--------+--------+--------+--------+--------+
#12 |   F5   |  4  $  |   R    |   T    |   G    |   B    |
#   +--------+--------+--------+--------+--------+--------+
#13 |   F6   |  5  %  |  6  ^  |   Y    |   H    |   N    |
#   +--------+--------+--------+--------+--------+--------+
#14 |   F7   |  7  &  |   U    |   J    |   M    | space  |
#   +--------+--------+--------+--------+--------+--------+
#15 |   F8   |  8  *  |   I    |   K    |  ,  <  |  .  >  |
#   +--------+--------+--------+--------+--------+--------+

#   CBM2 Keyboard layout:
#
#   F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 down up left right clr rvs graph r/s
#
#   ESC 1!  2@  3#  4$  5%  6^  7&  8*  9(  0)  -   =+  arrow/pound del     ?   CE  *   /
#    TAB q   w   e   r   t   y   u   i   o   p   [   ]   return             7   8   9   -
#     SL  a   s   d   f   g   h   j   k   l   ;:  '"  pi                    4   5   6   +
#      LS  z   x   c   v   b   n   m   ,<  .>  /?  RS   CBM                 1   2   3
#       CTRL    SPACE                                                       0   .   00  enter

!CLEAR
!LSHIFT 8 4
!RSHIFT 8 4
!VSHIFT RSHIFT
!SHIFTL RSHIFT
!LCBM 3 4
!VCBM LCBM
!LCTRL 8 5
!VCTRL LCTRL

96 1 5 32       /*            ' -> '            */
96 2 2 0x90     /*            ~ -> arrow left   */
27 8 1 8        /*          ESC -> ESC          */
49 9 1 8        /*            1 -> 1            */
50 10 1 8       /*            2 -> 2            */
51 11 1 8       /*            3 -> 3            */
52 12 1 8       /*            4 -> 4            */
53 13 1 8       /*            5 -> 5            */
54 13 2 8       /*            6 -> 6            */
55 14 1 8       /*            7 -> 7            */
56 15 1 8       /*            8 -> 8            */
57 0 1 8        /*            9 -> 9            */
48 1 1 8        /*            0 -> 0            */
92 2 2 8        /*    backslash -> left arrow   */
45 1 2 0x20     /*        Minus -> Minus        */
45 2 2 0x90     /*  shift+Minus -> left arrow   */
61 2 1 8        /*        Equal -> Equal        */
8 3 3 8         /*    Backspace -> Del          */
9 8 2 8         /*          TAB -> TAB          */
113 9 2 8       /*            Q -> Q            */
119 10 2 8      /*            W -> W            */
101 11 2 8      /*            E -> E            */
114 12 2 8      /*            R -> R            */
116 12 3 8      /*            T -> T            */
121 13 3 8      /*            Y -> Y            */
117 14 2 8      /*            U -> U            */
105 15 2 8      /*            I -> I            */
111 0 2 8       /*            O -> O            */
112 1 3 8       /*            P -> P            */
91 1 4 8        /*            [ -> [            */
93 2 3 8        /*            ] -> ]            */
13 2 4 8        /*       Return -> Return       */
306 8 5 0x4008  /*    Left Ctrl -> CTRL         */
97 9 3 8        /*            A -> A            */
115 10 3 8      /*            S -> S            */
100 11 3 8      /*            D -> D            */
102 11 4 8      /*            F -> F            */
103 12 4 8      /*            G -> G            */
104 13 4 8      /*            H -> H            */
106 14 3 8      /*            J -> J            */
107 15 3 8      /*            K -> K            */
108 0 3 8       /*            L -> L            */
59 0 4 8        /*            ; -> ;            */
39 1 5 8        /*            ' -> '            */
304 8 4 4       /*   Left Shift -> Shift        */
301 8 4 64      /*    Caps Lock -> Shift Lock   */
122 9 4 8       /*            Z -> Z            */
120 10 4 8      /*            X -> X            */
99 10 5 8       /*            C -> C            */
118 11 5 8      /*            V -> V            */
98 12 5 8       /*            B -> B            */
110 13 5 8      /*            N -> N            */
109 14 4 8      /*            M -> M            */
44 15 4 8       /*            , -> ,            */
46 15 5 8       /*            . -> .            */

47 0 5 0x28     /*            / -> /            */
47 4 1 0x201    /*     ctrl   / -> /            */

303 8 4 4       /*  Right Shift -> Shift        */
32 14 5 8       /*        Space -> Space        */

282 8 0 8       /*           F1 -> F1           */
283 9 0 8       /*           F2 -> F2           */
284 10 0 8      /*           F3 -> F3           */
285 11 0 8      /*           F4 -> F4           */
286 12 0 8      /*           F5 -> F5           */
287 13 0 8      /*           F6 -> F6           */
288 14 0 8      /*           F7 -> F7           */
289 15 0 8      /*           F8 -> F8           */
290 0 0 8       /*           F9 -> F9           */
291 1 0 8       /*          F10 -> F10          */
292 2 5 8       /*          F11 -> pi           */
#293 1 0 8       /*          F12 -> run/stop     */


273 3 0 8       /*           Up -> CRSR UP      */
276 3 1 8       /*         Left -> CRSR LEFT    */
275 3 2 8       /*        Right -> CRSR RIGHT   */
274 2 0 8       /*         Down -> CRSR DOWN    */

277 6 5 8       /*          Ins -> KP 00        */
127 5 1 8       /*          Del -> KP CE        */
278 4 0 8       /*         Home -> CLR/HOME     */
279 5 0 8       /*          End -> Rev/Off      */
280 7 0 8       /*         PgUp -> Run/Stop     */
281 6 0 8       /*       PgDown -> Norm/Graph   */

305 3 4 0x2008  /*   Right Ctrl -> C=           */

271 7 4 8       /* Numpad Enter -> Numpad Enter */
267 7 1 8       /*     Numpad / -> Numpad /     */
268 6 1 8       /*     Numpad * -> Numpad *     */
263 4 2 8       /*     Numpad 7 -> Numpad 7     */
264 5 2 8       /*     Numpad 8 -> Numpad 8     */
265 6 2 8       /*     Numpad 9 -> Numpad 9     */
269 7 2 8       /*     Numpad - -> Numpad -     */
260 4 3 8       /*     Numpad 4 -> Numpad 4     */
261 5 3 8       /*     Numpad 5 -> Numpad 5     */
262 6 3 8       /*     Numpad 6 -> Numpad 6     */
270 7 3 8       /*     Numpad + -> Numpad +     */
257 4 4 8       /*     Numpad 1 -> Numpad 1     */
258 5 4 8       /*     Numpad 2 -> Numpad 2     */
259 6 4 8       /*     Numpad 3 -> Numpad 3     */
256 4 5 8       /*     Numpad 0 -> Numpad 0     */
266 5 5 8       /*     Numpad . -> Numpad .     */
