# 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, C128, SDL

# C128 Keyboard matrix
#
#       +-----+-----+-----+-----+-----+-----+-----+-----+
#       |Bit 0|Bit 1|Bit 2|Bit 3|Bit 4|Bit 5|Bit 6|Bit 7|
# +-----+-----+-----+-----+-----+-----+-----+-----+-----+
# |Bit 0| DEL |Retrn|C_L/R|  F7 |  F1 |  F3 |  F5 |C_U/D|
# +-----+-----+-----+-----+-----+-----+-----+-----+-----+
# |Bit 1| 3 # |  W  |  A  | 4 $ |  Z  |  S  |  E  | S_L |
# +-----+-----+-----+-----+-----+-----+-----+-----+-----+
# |Bit 2| 5 % |  R  |  D  | 6 & |  C  |  F  |  T  |  X  |
# +-----+-----+-----+-----+-----+-----+-----+-----+-----+
# |Bit 3| 7 ' |  Y  |  G  | 8 ( |  B  |  H  |  U  |  V  |
# +-----+-----+-----+-----+-----+-----+-----+-----+-----+
# |Bit 4| 9 ) |  I  |  J  |  0  |  M  |  K  |  O  |  N  |
# +-----+-----+-----+-----+-----+-----+-----+-----+-----+
# |Bit 5|  +  |  P  |  L  |  -  | . > | : [ |  @  | , < |
# +-----+-----+-----+-----+-----+-----+-----+-----+-----+
# |Bit 6|POUND|  *  | ; ] | HOME| S_R |  =  | A_UP| / ? |
# +-----+-----+-----+-----+-----+-----+-----+-----+-----+
# |Bit 7| 1 ! |A_LFT| CTRL| 2 " |SPACE|  C= |  Q  | R/S |
# +-----+-----+-----+-----+-----+-----+-----+-----+-----+
#
#        +-----+-----+-----+-----+-----+-----+-----+-----+
#        |Bit 0|Bit 1|Bit 2|Bit 3|Bit 4|Bit 5|Bit 6|Bit 7|
# +------+-----+-----+-----+-----+-----+-----+-----+-----+
# |Bit 8 |HELP | KP 8| KP 5| TAB | KP 2| KP 4| KP 7| KP 1|
# +------+-----+-----+-----+-----+-----+-----+-----+-----+
# |Bit 9 | ESC | KP +| KP -| LF  |KP CR| KP 6| KP 9| KP 3|
# +------+-----+-----+-----+-----+-----+-----+-----+-----+
# |Bit 10| ALT | KP 0| KP .|A.UP |A.DWN|A.LFT|A.RGT|NOSCR|
# +------+-----+-----+-----+-----+-----+-----+-----+-----+

# C128 Keyboard layout:
#
#   ESC TAB ALT CAPS       HELP L/F 40/80 NOSCRL     up down left right  F1/2 F3/4 F5/6 F7/8
#
#   arrow 1!  2"  3#  4$  5%  6&  7'  8(  9)  0   +   -   pound clr del     7   8   9   +
#    ctrl   q   w   e   r   t   y   u   i   o   p   @   *   ^   restore     4   5   6   -
#   r/s SL    a   s   d   f   g   h   j   k   l   :[  ;]  =   return        1   2   3   enter
#   CBM LSHFT   z   x   c   v   b   n   m   ,<  .>  /?  RSHFT   u/d l/r     0       .
#                               SPACE

!CLEAR
!LSHIFT 1 7
!RSHIFT 6 4
!VSHIFT RSHIFT
!SHIFTL LSHIFT
!LCBM 7 5
!VCBM LCBM
!LCTRL 7 2
!VCTRL LCTRL

# keys that can't be mapped positionally are:
# (row0) pound (-> </>), clr/home (-> home)
# (row1) arrow up (-> end), restore (-> page up)
# (row2) run/stop (-> escape)
# (row3) commodore (-> control)

# extra keys are:
# clr/home (-> pos1)
# ins/del (-> delete)
# ins/del+shift (-> insert)
# arrow up (-> end)
# arrow up+shift (-> end+shift)


# keys that can't be mapped symbolically are:
# (row0) arrow left (-> end), pound (-> ß), clr/home (-> home)
# (row1) restore (-> page up)
# (row2) run/stop (-> escape)
# (row3) commodore (-> control)

# extra keys are:
# ins/del (-> delete)
# ins/del+shift (-> insert)
# arrow left (-> underscore, ssharp, altgr+~)
# arrow up+shift (-> altgr+m)
# f1 (-> page up)
# f7 (-> page down)
# : (-> oe)
# :+shift (-> OE, altgr+[)
# ; (-> ae)
# ;+shift (-> AE, altgr+])
# @ (-> ue, altgr+Q)
# @+shift (-> UE)

#####################
# Special cases where a key code is duplicated because SDL does not supply a
# separate code, it just gives you the shifted version of the base key
# 32 another definition of the same code follows
# 33=32+1 another definition of the same code follows, shifted on host
# 129=128+1 shifted on host, shifted on c64
# 144=128+16 shifted on host, NOT shifted on c64
# SPECIAL CASE ' "
39 3 0 33              /*            ' -> '            */
39 7 3 129             /*            " -> "            */
# SPECIAL CASE - _
45 5 3 32              /*            - -> -            */
45 7 1 144             /*            _ -> Left Arrow   */
# SPECIAL CASE 2 @
50 7 3 32              /*            2 -> 2            */
50 5 6 144             /*            @ -> @            */
50 7 3 8	       /*            2 -> 2            */  2/" key (from nl symbolic keymap)
# SPECIAL CASE 6 ^ (up arrow)
54 2 3 32              /*            6 -> 6            */
54 6 6 144             /*            ^ -> ^            */
# SPECIAL CASE 7 &
55 3 0 32              /*            7 -> 7            */
55 2 3 129             /*            & -> &            */
# SPECIAL CASE 8 *
56 3 3 32              /*            8 -> 8            */
56 6 1 144             /*            * -> *            */
# SPECIAL CASE 9 (
57 4 0 32              /*            9 -> 9            */
57 3 3 129             /*            ( -> (            */
# SPECIAL CASE 0 )
48 4 3 32              /*            0 -> 0            */
48 4 0 129             /*            ) -> )            */
# SPECIAL CASE : ;
59 6 2 32              /*            ; -> ;            */
59 5 5 144             /*            : -> :            */
# SPECIAL CASE = +
61 6 5 32              /*            = -> =            */
61 5 0 144             /*            + -> +            */
# SPECIAL CASE ` ~
96 3 0 33              /*            ` -> `            */
96 6 6 129             /*            ~ -> Pi           */

#####################
# |Bit 0| DEL |Retrn|C_L/R|  F7 |  F1 |  F3 |  F5 |C_U/D|

# INST/DEL (all 3 below)
8 0 0 8                /*    Backspace -> Del          */
277 0 0 1              /*          Ins -> Ins          */
127 0 0 16             /*          Del -> Del          */
13 0 1 8               /*       Return -> Return       */
275 0 2 8              /*        Right -> CRSR RIGHT   */
276 0 2 1              /*         Left -> CRSR LEFT    */
288 0 3 8              /*           F7 -> F7           */
289 0 3 1              /*           F8 -> F8           */
282 0 4 8              /*           F1 -> F1           */
283 0 4 1              /*           F2 -> F2           */
284 0 5 8              /*           F3 -> F3           */
285 0 5 1              /*           F4 -> F4           */
286 0 6 8              /*           F5 -> F5           */
287 0 6 1              /*           F6 -> F6           */
274 0 7 8              /*         Down -> CRSR DOWN    */
273 0 7 1              /*           Up -> CRSR UP      */

#####################
# |Bit 1| 3 # |  W  |  A  | 4 $ |  Z  |  S  |  E  | S_L |

35 1 0 1               /*            # -> #            */
36 1 3 1               /*            $ -> $            */
304 1 7 2              /*   Left Shift -> Left Shift   */
# key is shift lock
301 1 7 64             /*    Caps Lock -> Shift Lock   */

#####################
# |Bit 2| 5 % |  R  |  D  | 6 & |  C  |  F  |  T  |  X  |

37 2 0 1               /*            % -> %            */

#####################
# |Bit 3| 7 ' |  Y  |  G  | 8 ( |  B  |  H  |  U  |  V  |

#####################
# |Bit 4| 9 ) |  I  |  J  |  0  |  M  |  K  |  O  |  N  |

#####################
# |Bit 5|  +  |  P  |  L  |  -  | . > | : [ |  @  | , < |

46 5 4 0               /*            . -> .            */
60 5 4 1               /*            > -> >            */
91 5 5 1               /*            [ -> [            */
44 5 7 0               /*            , -> ,            */
60 5 7 1               /*            < -> <            */

#####################
# |Bit 6|POUND|  *  | ; ] | HOME| S_R |  =  | A_UP| / ? |

#?? 6 0 0               /* Sterling/Pound -> Pound      */
92 6 0 0               /*            \ -> Pound        */
1073742025 6 0 8       /*            | -> Pound        */
93 6 2 1               /*            ] -> ]            */
278 6 3 8              /*         HOME -> CLR/HOME     */
303 6 4 4              /*  Right Shift -> Right Shift  */
58 6 7 0               /*            / -> /            */
63 6 7 1               /*            ? -> ?            */
42 6 1 8               /*            * -> *            */  asterisk/pipe key (from nl symbolic keymap)
36 6 0 8               /*            $ -> Pound        */  $ key (near enter without shift)

#####################
# |Bit 7| 1 ! |A_LFT| CTRL| 2 " |SPACE|  C= |  Q  | R/S |

33 7 0 1               /*         ! -> !               */
306 7 2 16384          /*        LCTRL -> Ctrl         */
32 7 4 8               /*        Space -> Space        */
9 7 5 8200             /*          TAB -> CBM          */
27 7 7 8               /*          ESC -> Run/Stop     */

#####################
# Numbers, letters

49 7 0 8               /*            1 -> 1            */
51 1 0 8               /*            3 -> 3            */
52 1 3 8               /*            4 -> 4            */
53 2 0 8               /*            5 -> 5            */

97 1 2 8               /*            A -> A            */
98 3 4 8               /*            B -> B            */
99 2 4 8               /*            C -> C            */
100 2 2 8              /*            D -> D            */
101 1 6 8              /*            E -> E            */
102 2 5 8              /*            F -> F            */
103 3 2 8              /*            G -> G            */
104 3 5 8              /*            H -> H            */
105 4 1 8              /*            I -> I            */
106 4 2 8              /*            J -> J            */
107 4 5 8              /*            K -> K            */
108 5 2 8              /*            L -> L            */
109 4 4 8              /*            M -> M            */
110 4 7 8              /*            N -> N            */
111 4 6 8              /*            O -> O            */
112 5 1 8              /*            P -> P            */
113 7 6 8              /*            Q -> Q            */
114 2 1 8              /*            R -> R            */
115 1 5 8              /*            S -> S            */
116 2 6 8              /*            T -> T            */
117 3 6 8              /*            U -> U            */
118 3 7 8              /*            V -> V            */
119 1 1 8              /*            W -> W            */
120 2 7 8              /*            X -> X            */
121 3 1 8              /*            Y -> Y            */
122 1 4 8              /*            Z -> Z            */

# Numeric keypad
256 10 1 8             /*     NumPad 0 -> NP 0         */
257 8 7 8              /*     NumPad 1 -> NP 1         */
258 8 4 8              /*     NumPad 2 -> NP 2         */
259 9 7 8              /*     NumPad 3 -> NP 3         */
260 8 5 8              /*     NumPad 4 -> NP 4         */
261 8 2 8              /*     NumPad 5 -> NP 5         */
262 9 5 8              /*     NumPad 6 -> NP 6         */
263 8 6 8              /*     NumPad 7 -> NP 7         */
264 8 1 8              /*     NumPad 8 -> NP 8         */
265 9 6 8              /*     NumPad 9 -> NP 9         */
266 10 2 8             /*     NumPad . -> NP .         */
269 9 2 8              /*     NumPad - -> NP -         */
270 9 1 8              /*     NumPad + -> NP +         */
271 9 4 8              /*    NP Return -> NP Return    */

# escape - tab - alt - (caps lock)
# help - linefeed - (40/80) - no scroll

# note: its really hard to map all these keys reasonable without sacrificing
#       the symbolic mapping of f1-f7 keys. the above keys are mapped to
# first block:   f9, f10, f11, Pause/Break (was f12 but that's menu)
# second block: end, page down, kp /, kp *

# escape
290 9 0 8              /*           F9 -> ESCAPE       */
# tab
291 8 3 8              /*          F10 -> TAB          */
# alt
292 10 0 8             /*          F11 -> ALT          */
# CAPS (ASCII/DIN) key - We can't map this to F12 because F12 is SDL MENU key
#293 -4 1               /*          F11 -> CAPS         */
# So mapped to pause/break key for now until some better idea comes along
19 -4 1                /*  Pause/Break -> CAPS         */

# help
279 8 0 8              /*          END -> HELP         */
# lf
281 9 3 8              /*      PG DOWN -> LINE FEED    */
# 40/80 column key
267 -4 0               /*     NumPad / -> 40/80        */
# no scroll
268 10 7 8             /*     NumPad * -> NO SCROLL    */

# Restore key mappings
280 -3 0               /*      Page Up -> RESTORE      */
