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

# this is a PET graphics keyboard mapping (Positional, US Layout, PET, GTK)

# 2001, 3032 and 4032 use graphics keyboard
# 4032B, 8032 and up use business keyboard
#
# http://www.6502.org/users/andre/petindex/keyboards.html

# Graphics keyboard matrix:
#
#       0        1        2        3        4        5        6        7
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 0 |   !    |   #    |   %    |   &    |   (    |  <--   |  home  |crsr rgt|
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 1 |   "    |   $    |   '    |   \    |   )    |--------|crsr dwn|  del   |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 2 |   q    |   e    |   t    |   u    |   o    |   ^    |   7    |   9    |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 3 |   w    |   r    |   y    |   i    |   p    |--------|   8    |   /    |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 4 |   a    |   d    |   g    |   j    |   l    |--------|   4    |   6    |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 5 |   s    |   f    |   h    |   k    |   :    |--------|   5    |   *    |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 6 |   z    |   c    |   b    |   m    |   ;    | return |   1    |   3    |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 7 |   x    |   v    |   n    |   ,    |   ?    |--------|   2    |   +    |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 8 |l shift |   @    |   ]    |--------|   >    |r shift |   0    |   -    |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
# 9 | rvs on |   [    | space  |   <    |  stop  |--------|   .    |   =    |
#   +--------+--------+--------+--------+--------+--------+--------+--------+
#
# The original gfx keyboard reflects the matrix perfectly:
#
#         @ !  "  #  $  %  '  &  \  (  )  <- [  ]    clr  u/d  l/r  ins/del
#       RVS  q  w  e  r  t  y  u  i  o  p  ^  <  >    7    8    9    /
#         SL  a  s  d  f  g  h  j  k  l  : r/s ret    4    5    6    *
#          LS  z  x  c  v  b  n  m  ,  ;  ?  RS       1    2    3    +
#                 SPACE                               0    .    -    =
#
# Chiclet Keyboard:
#
#       !  "  #  $  %  '  &  \  (  )  <-    clr  u/d  l/r  ins/del
#       q  w  e  r  t  y  u  i  o  p  ^     7    8    9    /
#       a  s  d  f  g  h  j  k  l  :  ret   4    5    6    *
#       z  x  c  v  b  n  m  ,  ;  ?  ret   1    2    3    +
#      SL RVS @  [  ]  space <  > r/s SR    0    .    -    =
#
# http://www.6502.org/users/andre/petindex/keyboards.html

!CLEAR
!LSHIFT 8 0
!RSHIFT 8 5
!VSHIFT LSHIFT
!SHIFTL LSHIFT
#!LCBM 0 0
#!VCBM LCBM
#!LCTRL 0 0
#!VCTRL LCTRL

Return       6 5 8
Down         1 6 8
Right        0 7 8
Home         0 6 8
Delete       1 7 0  # DEL
Tab          9 0 8  # RVS
KP_Tab       9 0 8  # OFF
ISO_Left_Tab 9 0 1  # OFF
Escape       9 4 8  # Stop
Control_L    -1 -1 0
Find         0 6 0
# left shift
# key is left shift
Shift_L          8 0 2
# shift lock
# key is (left) shift-lock
Caps_Lock        8 0 64

Shift_R      8 5 4

a            4 0 0
b            6 2 0
c            6 1 0
d            4 1 0
e            2 1 0
f            5 1 0
g            4 2 0
h            5 2 0
i            3 3 0
j            4 3 0
k            5 3 0
l            4 4 0
m            6 3 0
n            7 2 0
o            2 4 0
p            3 4 0
q            2 0 0
r            3 1 0
s            5 0 0
t            2 2 0
u            2 3 0
v            7 1 0
w            3 0 0
x            7 0 0
y            3 2 0
z            6 0 0

# Numeric pad keys:
KP_Decimal   9 6 8  # .
KP_Separator 9 6 8  # KP , (thousands separator, if present)
KP_0         8 6 0  # 0
KP_1         6 6 0  # 1
KP_2         7 6 0  # 2
KP_3         6 7 0  # 3
KP_4         4 6 0  # 4
KP_5         5 6 0  # 5
KP_6         4 7 0  # 6
KP_7         2 6 0  # 7
KP_8         3 6 0  # 8
KP_9         2 7 0  # 9

KP_Delete    9 6 1  # . + SHIFT
KP_Insert    8 6 1  # 0 + SHIFT
KP_End       6 6 1  # 1 + SHIFT
KP_Down      7 6 1  # 2 + SHIFT
KP_Next      6 7 1  # 3 + SHIFT
KP_Left      4 6 1  # 4 + SHIFT
KP_Begin     5 6 1  # 5 + SHIFT
KP_Right     4 7 1  # 6 + SHIFT
KP_Home      2 6 1  # 7 + SHIFT
KP_Up        3 6 1  # 8 + SHIFT
KP_Page_Up   2 7 1  # 9 + SHIFT

# Note: Num Lock can be mapped, but still the OS will change the meaning of the
# numblock depending on numblock state, so its not very useful
Num_Lock     0 6 8  # clr+home
KP_Divide    1 6 8  #   crsr up/down
KP_Multiply  0 7 8  #   crsr left/right
KP_Subtract  1 7 8  #   inst/del

KP_Add       7 7 8  # KP +
KP_Enter     9 7 8  # KP =

# These keys should be on the numeric pad, but because of some double-size
# keys, they don't fit and are relocated.
End          8 7 8  # -
Page_Up      3 7 8  # /
Page_Down    5 7 8  # *

grave        8 1 0  # ` -> @
1            0 0 0  # !
2            1 0 0  # "
3            0 1 0  # #
4            1 1 0  # $
5            0 2 0  # %
6            1 2 0  # '
7            0 3 0  # &
8            1 3 0  # \ 
9            0 4 0  # (
0            1 4 0  # )
minus        0 5 0  # <- left arrow
equal        9 1 0  # [
BackSpace    8 2 8  # ]

# The above row with shift:
asciitilde   8 1 1  # ~ -> shift+@
exclam       0 0 1
at           1 0 1
numbersign   0 1 1
dollar       1 1 1
percent      0 2 1
asciicircum  1 2 1
ampersand    0 3 1
asterisk     1 3 1
parenleft    0 4 1
parenright   1 4 1
underscore   0 5 1  # shift+left-arrow
plus         9 1 1  # shift+[
#BackSpace   8 2 8  # shift+] because of flag 8

# The 3 keys to the right of yuiop:
bracketleft  2 5 0  # [ -> arrow up
bracketright 9 3 0  # ] -> <
backslash    8 4 0  # \ -> >
# and with shift:
braceleft    2 5 1  # shift+arrow up = pi
braceright   9 3 1  # shift+<
bar          8 4 1  # shift+>

semicolon    5 4 0  # :
colon        5 4 1

apostrophe   9 4 0  # runstop
quotedbl     9 4 8  # runstop+shift

sterling     1 3 0
space        9 2 8

# The 3 keys right of vbnm
comma        7 3 0  # ,
period       6 4 0  # ;
slash        7 4 0  # ?
# and with shift:
less         7 3 1
greater      6 4 1
question     7 4 1

Up           1 6 1
Left         0 7 1
Insert       1 7 1  # INST
Clear        0 6 1

A            4 0 1
B            6 2 1
C            6 1 1
D            4 1 1
E            2 1 1
F            5 1 1
G            4 2 1
H            5 2 1
I            3 3 1
J            4 3 1
K            5 3 1
L            4 4 1
M            6 3 1
N            7 2 1
O            2 4 1
P            3 4 1
Q            2 0 1
R            3 1 1
S            5 0 1
T            2 2 1
U            2 3 1
V            7 1 1
W            3 0 1
X            7 0 1
Y            3 2 1
Z            6 0 1 
