# 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.

# Positional Mapping, IT Layout, Plus4, GTK

# Commodore 16/116/Plus-4 keyboard matrix:
#
#       0        1        2        3       4         5        6        7
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 0 |INST/DEL|RETURN  |POUND   |F7/HELP |F4/F1   |F5/F2   |F6/F3   |@       |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 1 |3 #     |W       |A       |4 $     |Z       |S       |E       | SHIFTs |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 2 |5 %     |R       |D       |6 &     |C       |F       |T       |X       |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 3 |7 '     |Y       |G       |8 (     |B       |H       |U       |V       |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 4 |9 )     |I       |J       |0 ^     |M       |K       |O       |N       |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 5 |DOWN    |P       |L       |UP      |. >     |: [     |-       |, <     |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 6 |LEFT    |*       |; ]     |RIGHT   |ESC     |=       |+       |/ ?     |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 7 |1 !     |CLR/HOME| CTRLs  |2 "     |SPACE   |CBM     |Q       |RUN/STOP|
#   +--------+--------+--------+--------+--------+--------+--------+--------+

#   C16 keyboard layout:
#
#   ESC 1!  2"  3#  4$  5%  6&  7'  8(  9)  0^  left right up down del      f1/f4
#   CTRL  q   w   e   r   t   y   u   i   o   p   @   +   -   clr           f2/f5
#   r/s SL  a   s   d   f   g   h   j   k   l   :[  ;]  *   return          f3/f6
#   CBM LS    z   x   c   v   b   n   m   ,<  .>  /?  RS  pound =/pi        help/f7
#                           space
#
#   Plus4 keyboard layout:
#
#   F1/4 F2/5 F3/6 Help/F7
#
#   ESC 1!  2"  3#  4$  5%  6&  7'  8(  9)  0^  +   -   =/pi clr del
#   CTRL  q   w   e   r   t   y   u   i   o   p   @   pound * ctrl
#   r/s SL  a   s   d   f   g   h   j   k   l   :[  ;]  return
#   CBM LS    z   x   c   v   b   n   m   ,<  .>  /?  RS     up
#                           space                        left right
#                                                           down
#   C116 keyboard layout:
#
#   F1/4 F2/5 F3/6 Help/F7              home/clr del/inst
#
#   ESC 1!  2"  3#  4$  5%  6&  7'  8(  9)  0^  +   -   *
#   CTRL  q   w   e   r   t   y   u   i   o   p   @   return
#   r/s £   a   s   d   f   g   h   j   k   l   :[  ;]  =/pi   up
#   CBM LS    z   x   c   v   b   n   m   ,<  .>  /?  RS   left right
#                           space                             down
#

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

# Keys that can't be mapped positionally:
# equals sign (<- Insert)
# Clear/Home (<- Home)
# asterisk (<- Delete)
# Run/Stop (<- Esc)

# Extra keys :
# End -> Run/Stop
# Page_Up -> F1
# Page_Down -> Help
# ù, §, -> equal sign

# Other unused keys symbolically mapped:
# [, ], @, #, <, >
# Key NumPad (usable if Keysets joysticks is disabled)


#####################   Plus4, row 0
#   F1/4 F2/5 F3/6 Help/F7

F1            0 4 8
F4            0 4 1
F2            0 5 8
F5            0 5 1
F3            0 6 8
F6            0 6 1
F7            0 3 1
# F8 -> HELP
F8            0 3 8



#####################   Plus4, row 1
#   ESC 1!  2"  3#  4$  5%  6&  7'  8(  9)  0^  +   -   =/pi clr del

# \ -> esc
backslash     6 4 8

# | -> shift + esc
bar           6 4 8

# ! -> shift + 1 !
exclam        7 0 8

# " -> shift + 2 "
quotedbl        7 3 8

# £ -> shift + 3 #
sterling      1 0 8

# $ -> shift + 4 $
dollar          1 3 8

# % -> shift + 5 %
percent         2 0 8

# & -> shift + 6 &
ampersand       2 3 1

# / -> shift + 7 '
slash         3 0 1

# ( -> shift + 8 (
parenleft     3 3 1

# ) -> shift + 9 )
parenright    4 0 1

# ^ -> shift + 0 (arrow up)
equal         4 3 8


# ' -> plus sign +
apostrophe    6 6 8
# ? -> shift + plus sign
question      6 6 1


# ì -> minus sign -
igrave        5 6 8
# ^ -> shift + minus sign -
asciicircum   5 6 1

# Insert -> equal sign/pi
Insert        6 5 8

# Home -> Clear/Home
Home          7 1 8

# Backspace = Inst/Del
BackSpace     0 0 8



#####################   Plus4, row 2
#   CTRL  q   w   e   r   t   y   u   i   o   p   @   pound * ctrl

# Tab -> Control left
Tab           7 2 16392
# Shift + Tab -> Shift-Control
ISO_Left_Tab  7 2 16392

# è -> at @
egrave        0 7 8

# é -> shift + at @
eacute        0 7 1


# + -> Pound £
plus          0 2 8

# * -> shift + Pound £
asterisk      0 2 1


# Delete -> asterisk *
Delete        6 1 8




#####################   Plus4, row 3
#   r/s SL  a   s   d   f   g   h   j   k   l   :[  ;]  return

# Esc -> Run/Stop
Escape        7 7 8
# Caps Lock -> Shift Lock
Caps_Lock     1 7 64

# ò -> colon :
ograve        5 5 8
# ç -> left square bracket [
ccedilla      5 5 1

# à -> semicolon ;
agrave        6 2 8
# ° -> right square bracket ]
degree        6 2 1

# ù -> equal sign =
ugrave        6 5 8
# § -> shift + equal sign =
section       6 5 1

Return 0 1 8


#####################   Plus4, row 4
#   CBM LS    z   x   c   v   b   n   m   ,<  .>  /?  RS     up


# Control_L -> CBM
Control_L 7 5 8200

Shift_L       1 7 4

comma         5 7 8
# ; -> less <
semicolon     5 7 1

period        5 4 8
# : -> greater >
colon         5 4 1

# - -> slash /
minus         6 7 8
# _ -> question ?
underscore    6 7 1

Shift_R       1 7 4





space         7 4 8



#####################
# letters and numbers

0 4 3 8
1 7 0 8
2 7 3 8
3 1 0 8
4 1 3 8
5 2 0 8
6 2 3 8
7 3 0 8
8 3 3 8
9 4 0 8
A 1 2 8
B 3 4 8
C 2 4 8
D 2 2 8
E 1 6 8
F 2 5 8
G 3 2 8
H 3 5 8
I 4 1 8
J 4 2 8
K 4 5 8
L 5 2 8
M 4 4 8
N 4 7 8
O 4 6 8
P 5 1 8
Q 7 6 8
R 2 1 8
S 1 5 8
T 2 6 8
U 3 6 8
V 3 7 8
W 1 1 8
X 2 7 8
Y 3 1 8
Z 1 4 8
a 1 2 8
b 3 4 8
c 2 4 8
d 2 2 8
e 1 6 8
f 2 5 8
g 3 2 8
h 3 5 8
i 4 1 8
j 4 2 8
k 4 5 8
l 5 2 8
m 4 4 8
n 4 7 8
o 4 6 8
p 5 1 8
q 7 6 8
r 2 1 8
s 1 5 8
t 2 6 8
u 3 6 8
v 3 7 8
w 1 1 8
x 2 7 8
y 3 1 8
z 1 4 8

# Cursor keys
Up            5 3 8
Down          5 0 8
Left          6 0 8
Right         6 3 8

# Restore-key mappings
#Page_Up -3 0
#Prior -3 1


# extra: End -> Run/Stop
End           7 7 8

# extra: Page_Up -> F1
Page_Up        0 4 8

# extra: Page_Down -> Help
Page_Down      0 3 8


#
# extra: unused keys symbolically mapped
#

# extra: [
bracketleft   5 5 1
# extra: ]
bracketright  6 2 1
# extra: @
at            0 7 16
# extra: #
numbersign    1 0 1
# extra: <
less          5 7 2064  #16 (deshift key) + 2048 (combined with cbm)
# extra: >
greater       5 4 8


# extra: * from Key NumPad
KP_Multiply     6 1 8

# extra: - from Key NumPad
KP_Subtract     5 6 8

# extra: - from Key NumPad
KP_Add          6 6 8

# extra: / from Key NumPad
KP_Divide       6 7 8

#
# extra: Key NumPad mapped if Keysets joysticks is disabled on Settings->Input devices->Joystick
#
# Use (Shift+Alt+J) to quickly enable (Joy_ON-KP_OFF) or disable (Joy_OFF-KP_ON)
#

KP_0            4 3 16
KP_1            7 0 16
KP_2            7 3 16
KP_3            1 0 16
KP_4            1 3 16
KP_5            2 0 16
KP_6            2 3 16
KP_7            3 0 16
KP_8            3 3 16
KP_9            4 0 16
KP_Decimal      5 7 16



#
# joyport attached keypad
#
Num_Lock    -5 0
KP_7        -5 1
KP_8        -5 2
KP_9        -5 3
KP_Divide   -5 4
Scroll_Lock -5 5
KP_4        -5 6
KP_5        -5 7
KP_6        -5 8
KP_Multiply -5 9
Sys_Req     -5 10
KP_1        -5 11
KP_2        -5 12
KP_3        -5 13
KP_Subtract -5 14
Print       -5 15
KP_0        -5 16
KP_Delete   -5 17
KP_Enter    -5 18
KP_Add      -5 19

#
# joystick keymap A
#
# Commented out: due to the keymap loading *after* vicerc any keyset settings
#                in vicerc are overruled by this.
#                see https://sourceforge.net/p/vice-emu/bugs/1797/
#                in vicerc are overruled by this.
#
# Up          -1 7
# Left        -1 4
# Right       -1 5
# Down        -1 2
# Control_R   -1 0
