import logging

import fsemu_c  # type: ignore

logger = logging.getLogger(__name__)


def post(action: int) -> None:
    logger.debug("fsemu.post %d", action)
    fsemu_c.post(action)


def set(name: str, value: str) -> None:
    logger.debug("fsemu.set %s %s", name, value)
    fsemu_c.set_option(name, value)


# --------

# ACTION_BEFORE_FIRST_EMU = 0x1000
ACTION_SOFTRESET = 0x1001
ACTION_HARDRESET = 0x1002

ACTION_DRIVE0EJECT = 0x1100
ACTION_DRIVE1EJECT = 0x1101
ACTION_DRIVE2EJECT = 0x1102
ACTION_DRIVE3EJECT = 0x1103
ACTION_DRIVE4EJECT = 0x1104
ACTION_DRIVE5EJECT = 0x1105
ACTION_DRIVE6EJECT = 0x1106
ACTION_DRIVE7EJECT = 0x1107

ACTION_DRIVE0INSERT0 = 0x1200

ACTION_DRIVE1INSERT0 = 0x1300

ACTION_DRIVE2INSERT0 = 0x1400


ACTION_DRIVE3INSERT0 = 0x1500

ACTION_DRIVE4INSERT0 = 0x1600

ACTION_DRIVE5INSERT0 = 0x1700

ACTION_DRIVE6INSERT0 = 0x1800

ACTION_DRIVE7INSERT0 = 0x1900
ACTION_DRIVE7INSERT255 = 0x19FF

ACTION_PORT0TYPE0 = 0x1A00
ACTION_PORT0TYPE1 = 0x1A01
ACTION_PORT0TYPE2 = 0x1A02

ACTION_PORT1TYPE0 = 0x1B00
ACTION_PORT1TYPE1 = 0x1B01
ACTION_PORT1TYPE2 = 0x1B02

ACTION_PORT2TYPE0 = 0x1C00

ACTION_PORT3TYPE0 = 0x1D00
ACTION_PORT3TYPE255 = 0x1DFF

# ----------------

INPUTDEVICE_TYPE_GAMEPAD = 99  # 'c' (FIXME: 103 g?)
INPUTDEVICE_TYPE_KEYBOARD = 107  # 'k'
INPUTDEVICE_TYPE_MOUSE = 109  # 'm'
INPUTDEVICE_TYPE_JOYSTICK = 106  # 'j'

# ----------------

INPUTDEVICE_KEYBOARD_OFFSET = 0

# -----------------------------------------------------------------------------

INPUTDEVICE_KEY_A = 4
INPUTDEVICE_KEY_B = 5
INPUTDEVICE_KEY_C = 6
INPUTDEVICE_KEY_D = 7
INPUTDEVICE_KEY_E = 8
INPUTDEVICE_KEY_F = 9
INPUTDEVICE_KEY_G = 10
INPUTDEVICE_KEY_H = 11
INPUTDEVICE_KEY_I = 12
INPUTDEVICE_KEY_J = 13
INPUTDEVICE_KEY_K = 14
INPUTDEVICE_KEY_L = 15
INPUTDEVICE_KEY_M = 16
INPUTDEVICE_KEY_N = 17
INPUTDEVICE_KEY_O = 18
INPUTDEVICE_KEY_P = 19
INPUTDEVICE_KEY_Q = 20
INPUTDEVICE_KEY_R = 21
INPUTDEVICE_KEY_S = 22
INPUTDEVICE_KEY_T = 23
INPUTDEVICE_KEY_U = 24
INPUTDEVICE_KEY_V = 25
INPUTDEVICE_KEY_W = 26
INPUTDEVICE_KEY_X = 27
INPUTDEVICE_KEY_Y = 28
INPUTDEVICE_KEY_Z = 29
INPUTDEVICE_KEY_1 = 30
INPUTDEVICE_KEY_2 = 31
INPUTDEVICE_KEY_3 = 32
INPUTDEVICE_KEY_4 = 33
INPUTDEVICE_KEY_5 = 34
INPUTDEVICE_KEY_6 = 35
INPUTDEVICE_KEY_7 = 36
INPUTDEVICE_KEY_8 = 37
INPUTDEVICE_KEY_9 = 38
INPUTDEVICE_KEY_0 = 39
INPUTDEVICE_KEY_RETURN = 40
INPUTDEVICE_KEY_ESCAPE = 41
INPUTDEVICE_KEY_BACKSPACE = 42
INPUTDEVICE_KEY_TAB = 43
INPUTDEVICE_KEY_SPACE = 44
INPUTDEVICE_KEY_MINUS = 45
INPUTDEVICE_KEY_EQUALS = 46
INPUTDEVICE_KEY_LEFTBRACKET = 47
INPUTDEVICE_KEY_RIGHTBRACKET = 48
INPUTDEVICE_KEY_BACKSLASH = 49
INPUTDEVICE_KEY_NONUSHASH = 50
INPUTDEVICE_KEY_SEMICOLON = 51
INPUTDEVICE_KEY_APOSTROPHE = 52
INPUTDEVICE_KEY_GRAVE = 53
INPUTDEVICE_KEY_COMMA = 54
INPUTDEVICE_KEY_PERIOD = 55
INPUTDEVICE_KEY_SLASH = 56
INPUTDEVICE_KEY_CAPSLOCK = 57
INPUTDEVICE_KEY_F1 = 58
INPUTDEVICE_KEY_F2 = 59
INPUTDEVICE_KEY_F3 = 60
INPUTDEVICE_KEY_F4 = 61
INPUTDEVICE_KEY_F5 = 62
INPUTDEVICE_KEY_F6 = 63
INPUTDEVICE_KEY_F7 = 64
INPUTDEVICE_KEY_F8 = 65
INPUTDEVICE_KEY_F9 = 66
INPUTDEVICE_KEY_F10 = 67
INPUTDEVICE_KEY_F11 = 68
INPUTDEVICE_KEY_F12 = 69
INPUTDEVICE_KEY_PRINTSCREEN = 70
INPUTDEVICE_KEY_SCROLLLOCK = 71
INPUTDEVICE_KEY_PAUSE = 72
INPUTDEVICE_KEY_INSERT = 73
INPUTDEVICE_KEY_HOME = 74
INPUTDEVICE_KEY_PAGEUP = 75
INPUTDEVICE_KEY_DELETE = 76
INPUTDEVICE_KEY_END = 77
INPUTDEVICE_KEY_PAGEDOWN = 78
INPUTDEVICE_KEY_RIGHT = 79
INPUTDEVICE_KEY_LEFT = 80
INPUTDEVICE_KEY_DOWN = 81
INPUTDEVICE_KEY_UP = 82
INPUTDEVICE_KEY_NUMLOCKCLEAR = 83
INPUTDEVICE_KEY_KP_DIVIDE = 84
INPUTDEVICE_KEY_KP_MULTIPLY = 85
INPUTDEVICE_KEY_KP_MINUS = 86
INPUTDEVICE_KEY_KP_PLUS = 87
INPUTDEVICE_KEY_KP_ENTER = 88
INPUTDEVICE_KEY_KP_1 = 89
INPUTDEVICE_KEY_KP_2 = 90
INPUTDEVICE_KEY_KP_3 = 91
INPUTDEVICE_KEY_KP_4 = 92
INPUTDEVICE_KEY_KP_5 = 93
INPUTDEVICE_KEY_KP_6 = 94
INPUTDEVICE_KEY_KP_7 = 95
INPUTDEVICE_KEY_KP_8 = 96
INPUTDEVICE_KEY_KP_9 = 97
INPUTDEVICE_KEY_KP_0 = 98
INPUTDEVICE_KEY_KP_PERIOD = 99
INPUTDEVICE_KEY_NONUSBACKSLASH = 100
INPUTDEVICE_KEY_APPLICATION = 101
INPUTDEVICE_KEY_POWER = 102
INPUTDEVICE_KEY_KPEQUALS = 103
INPUTDEVICE_KEY_F13 = 104
INPUTDEVICE_KEY_F14 = 105
INPUTDEVICE_KEY_F15 = 106
INPUTDEVICE_KEY_F16 = 107
INPUTDEVICE_KEY_F17 = 108
INPUTDEVICE_KEY_F18 = 109
INPUTDEVICE_KEY_F19 = 110
INPUTDEVICE_KEY_F20 = 111
INPUTDEVICE_KEY_F21 = 112
INPUTDEVICE_KEY_F22 = 113
INPUTDEVICE_KEY_F23 = 114
INPUTDEVICE_KEY_F24 = 115
INPUTDEVICE_KEY_EXECUTE = 116
INPUTDEVICE_KEY_HELP = 117
INPUTDEVICE_KEY_MENU = 118
# Disabled for now to avoid confusion about select button gamepads.
# SELECT = 119
INPUTDEVICE_KEY_STOP = 120
INPUTDEVICE_KEY_AGAIN = 121
INPUTDEVICE_KEY_UNDO = 122
INPUTDEVICE_KEY_CUT = 123
INPUTDEVICE_KEY_COPY = 124
INPUTDEVICE_KEY_PASTE = 125
INPUTDEVICE_KEY_FIND = 126
INPUTDEVICE_KEY_MUTE = 127
INPUTDEVICE_KEY_VOLUMEUP = 128
INPUTDEVICE_KEY_VOLUMEDOWN = 129

INPUTDEVICE_KEY_KPCOMMA = 133
INPUTDEVICE_KEY_KPEQUALSAS400 = 134
INPUTDEVICE_KEY_INTERNATIONAL1 = 135
INPUTDEVICE_KEY_INTERNATIONAL2 = 136
INPUTDEVICE_KEY_INTERNATIONAL3 = 137
INPUTDEVICE_KEY_INTERNATIONAL4 = 138
INPUTDEVICE_KEY_INTERNATIONAL5 = 139
INPUTDEVICE_KEY_INTERNATIONAL6 = 140
INPUTDEVICE_KEY_INTERNATIONAL7 = 141
INPUTDEVICE_KEY_INTERNATIONAL8 = 142
INPUTDEVICE_KEY_INTERNATIONAL9 = 143
INPUTDEVICE_KEY_LANG1 = 144
INPUTDEVICE_KEY_LANG2 = 145
INPUTDEVICE_KEY_LANG3 = 146
INPUTDEVICE_KEY_LANG4 = 147
INPUTDEVICE_KEY_LANG5 = 148
INPUTDEVICE_KEY_LANG6 = 149
INPUTDEVICE_KEY_LANG7 = 150
INPUTDEVICE_KEY_LANG8 = 151
INPUTDEVICE_KEY_LANG9 = 152
INPUTDEVICE_KEY_ALTERASE = 153
INPUTDEVICE_KEY_SYSREQ = 154
INPUTDEVICE_KEY_CANCEL = 155
INPUTDEVICE_KEY_CLEAR = 156
INPUTDEVICE_KEY_PRIOR = 157
INPUTDEVICE_KEY_RETURN2 = 158
INPUTDEVICE_KEY_SEPARATOR = 159
INPUTDEVICE_KEY_OUT = 160
INPUTDEVICE_KEY_OPER = 161
INPUTDEVICE_KEY_CLEARAGAIN = 162
INPUTDEVICE_KEY_CRSEL = 163
INPUTDEVICE_KEY_EXSEL = 164

INPUTDEVICE_KEY_KP00 = 176
INPUTDEVICE_KEY_KP000 = 177
INPUTDEVICE_KEY_THOUSANDSSEPARATOR = 178
INPUTDEVICE_KEY_DECIMALSEPARATOR = 179
INPUTDEVICE_KEY_CURRENCYUNIT = 180
INPUTDEVICE_KEY_CURRENCYSUBUNIT = 181
INPUTDEVICE_KEY_KPLEFTPAREN = 182
INPUTDEVICE_KEY_KPRIGHTPAREN = 183
INPUTDEVICE_KEY_KPLEFTBRACE = 184
INPUTDEVICE_KEY_KPRIGHTBRACE = 185
INPUTDEVICE_KEY_KPTAB = 186
INPUTDEVICE_KEY_KPBACKSPACE = 187
INPUTDEVICE_KEY_KPA = 188
INPUTDEVICE_KEY_KPB = 189
INPUTDEVICE_KEY_KPC = 190
INPUTDEVICE_KEY_KPD = 191
INPUTDEVICE_KEY_KPE = 192
INPUTDEVICE_KEY_KPF = 193
INPUTDEVICE_KEY_KPXOR = 194
INPUTDEVICE_KEY_KPPOWER = 195
INPUTDEVICE_KEY_KPPERCENT = 196
INPUTDEVICE_KEY_KPLESS = 197
INPUTDEVICE_KEY_KPGREATER = 198
INPUTDEVICE_KEY_KPAMPERSAND = 199
INPUTDEVICE_KEY_KPDBLAMPERSAND = 200
INPUTDEVICE_KEY_KPVERTICALBAR = 201
INPUTDEVICE_KEY_KPDBLVERTICALBAR = 202
INPUTDEVICE_KEY_KPCOLON = 203
INPUTDEVICE_KEY_KPHASH = 204
INPUTDEVICE_KEY_KPSPACE = 205
INPUTDEVICE_KEY_KPAT = 206
INPUTDEVICE_KEY_KPEXCLAM = 207
INPUTDEVICE_KEY_KPMEMSTORE = 208
INPUTDEVICE_KEY_KPMEMRECALL = 209
INPUTDEVICE_KEY_KPMEMCLEAR = 210
INPUTDEVICE_KEY_KPMEMADD = 211
INPUTDEVICE_KEY_KPMEMSUBTRACT = 212
INPUTDEVICE_KEY_KPMEMMULTIPLY = 213
INPUTDEVICE_KEY_KPMEMDIVIDE = 214
INPUTDEVICE_KEY_KPPLUSMINUS = 215
INPUTDEVICE_KEY_KPCLEAR = 216
INPUTDEVICE_KEY_KPCLEARENTRY = 217
INPUTDEVICE_KEY_KPBINARY = 218
INPUTDEVICE_KEY_KPOCTAL = 219
INPUTDEVICE_KEY_KPDECIMAL = 220
INPUTDEVICE_KEY_KPHEXADECIMAL = 221

INPUTDEVICE_KEY_LCTRL = 224
INPUTDEVICE_KEY_LSHIFT = 225
INPUTDEVICE_KEY_LALT = 226
INPUTDEVICE_KEY_LGUI = 227
INPUTDEVICE_KEY_RCTRL = 228
INPUTDEVICE_KEY_RSHIFT = 229
INPUTDEVICE_KEY_RALT = 230
INPUTDEVICE_KEY_RGUI = 231

INPUTDEVICE_KEY_MODE = 257

# SDL_SCANCODE_SLEEP = 258
# SDL_SCANCODE_WAKE = 259

# SDL_SCANCODE_CHANNEL_INCREMENT = 260
# SDL_SCANCODE_CHANNEL_DECREMENT = 261

# SDL_SCANCODE_MEDIA_PLAY = 262
# SDL_SCANCODE_MEDIA_PAUSE = 263
# SDL_SCANCODE_MEDIA_RECORD = 264
# SDL_SCANCODE_MEDIA_FAST_FORWARD = 265
# SDL_SCANCODE_MEDIA_REWIND = 266
# SDL_SCANCODE_MEDIA_NEXT_TRACK = 267
# SDL_SCANCODE_MEDIA_PREVIOUS_TRACK = 268
# SDL_SCANCODE_MEDIA_STOP = 269
# SDL_SCANCODE_MEDIA_EJECT = 270
# SDL_SCANCODE_MEDIA_PLAY_PAUSE = 271
# SDL_SCANCODE_MEDIA_SELECT = 272

# SDL_SCANCODE_AC_NEW = 273
# SDL_SCANCODE_AC_OPEN = 274
# SDL_SCANCODE_AC_CLOSE = 275
# SDL_SCANCODE_AC_EXIT = 276
# SDL_SCANCODE_AC_SAVE = 277
# SDL_SCANCODE_AC_PRINT = 278
# SDL_SCANCODE_AC_PROPERTIES = 279

# SDL_SCANCODE_AC_SEARCH = 280
# SDL_SCANCODE_AC_HOME = 281
# SDL_SCANCODE_AC_BACK = 282
# SDL_SCANCODE_AC_FORWARD = 283
# SDL_SCANCODE_AC_STOP = 284
# SDL_SCANCODE_AC_REFRESH = 285
# SDL_SCANCODE_AC_BOOKMARKS = 286

# SDL_SCANCODE_SOFTLEFT = 287
# SDL_SCANCODE_SOFTRIGHT = 288
# SDL_SCANCODE_CALL = 289
# SDL_SCANCODE_ENDCALL = 290

# SDL_SCANCODE_RESERVED = 400
# SDL_SCANCODE_COUNT = 512

# INPUTDEVICE_AFTER_LAST_KEY,

# // Section for scancodes + modifier
# // FSEMU_NUM_SCANCODES_2__ = INPUTDEVICE_NUM_KEYS * 2,
# // Section for scancodes + modifier + shift
# // FSEMU_NUM_SCANCODES_3__ = INPUTDEVICE_NUM_KEYS * 3,

# -----------------------------------------------------------------------------

# INPUTDEVICE_CONTROLLER_OFFSET,
# INPUTDEVICE_BEFORE_FIRST_BUTTON =
# INPUTDEVICE_CONTROLLER_OFFSET,
# // Buttons in the same order as SDL2 gamecontroller

# -----------------------------------------------------------------------------

INPUTDEVICE_BUTTON_SOUTH = 1536
INPUTDEVICE_BUTTON_EAST = 1537
INPUTDEVICE_BUTTON_WEST = 1538
INPUTDEVICE_BUTTON_NORTH = 1539
INPUTDEVICE_BUTTON_BACK = 1540
INPUTDEVICE_BUTTON_GUIDE = 1541
INPUTDEVICE_BUTTON_START = 1542
INPUTDEVICE_BUTTON_LEFT_STICK = 1543
INPUTDEVICE_BUTTON_RIGHT_STICK = 1544
INPUTDEVICE_BUTTON_LEFT_SHOULDER = 1545
INPUTDEVICE_BUTTON_RIGHT_SHOULDER = 1546
INPUTDEVICE_BUTTON_DPAD_UP = 1547
INPUTDEVICE_BUTTON_DPAD_DOWN = 1548
INPUTDEVICE_BUTTON_DPAD_LEFT = 1549
INPUTDEVICE_BUTTON_DPAD_RIGHT = 1550
INPUTDEVICE_BUTTON_MISC1 = 1551
INPUTDEVICE_BUTTON_RIGHT_PADDLE1 = 1552
INPUTDEVICE_BUTTON_LEFT_PADDLE1 = 1553
INPUTDEVICE_BUTTON_RIGHT_PADDLE2 = 1554
INPUTDEVICE_BUTTON_LEFT_PADDLE2 = 1555
INPUTDEVICE_BUTTON_TOUCHPAD = 1556
INPUTDEVICE_BUTTON_MISC2 = 1557
INPUTDEVICE_BUTTON_MISC3 = 1558
INPUTDEVICE_BUTTON_MISC4 = 1559
INPUTDEVICE_BUTTON_MISC5 = 1560
INPUTDEVICE_BUTTON_MISC6 = 1561

INPUTDEVICE_LEFTXNEG = 1561
INPUTDEVICE_LEFTXPOS = 1562
INPUTDEVICE_LEFTYNEG = 1563
INPUTDEVICE_LEFTYPOS = 1564

# -----------------------------------------------------------------------------

# INPUTDEVICE_AFTER_LAST_BUTTON,

# INPUTDEVICE_BEFORE_FIRST_AXIS,
# // Axes in the same order as SDL2 gamecontroller
# INPUTDEVICE_LEFTX,
# INPUTDEVICE_LEFTY,
# INPUTDEVICE_RIGHTX,
# INPUTDEVICE_RIGHTY,
# INPUTDEVICE_LEFTTRIGGER,
# INPUTDEVICE_RIGHTTRIGGER,
# INPUTDEVICE_AFTER_LAST_AXIS,

# INPUTDEVICE_BEFORE_FIRST_HALF_AXIS,
# // Half-axes (no corresponding concept in SDL2 gamecontroller).
# INPUTDEVICE_LEFTXNEG,
# INPUTDEVICE_LEFTXPOS,
# INPUTDEVICE_LEFTYNEG,
# INPUTDEVICE_LEFTYPOS,
# INPUTDEVICE_RIGHTXNEG,
# INPUTDEVICE_RIGHTXPOS,
# INPUTDEVICE_RIGHTYNEG,
# INPUTDEVICE_RIGHTYPOS,
# INPUTDEVICE_AFTER_LAST_HALF_AXIS,

# #if 0
# INPUTDEVICE_BUTTON_INVALID,
# INPUTDEVICE_BUTTON_0,
# INPUTDEVICE_BUTTON_1,
# INPUTDEVICE_BUTTON_2,
# INPUTDEVICE_BUTTON_3,
# INPUTDEVICE_BUTTON_4,
# INPUTDEVICE_BUTTON_5,
# INPUTDEVICE_BUTTON_6,
# INPUTDEVICE_BUTTON_7,
# INPUTDEVICE_BUTTON_8,
# INPUTDEVICE_BUTTON_9,
# INPUTDEVICE_BUTTON_10,
# INPUTDEVICE_BUTTON_11,
# INPUTDEVICE_BUTTON_12,
# INPUTDEVICE_BUTTON_13,
# INPUTDEVICE_BUTTON_14,
# INPUTDEVICE_BUTTON_15,
# INPUTDEVICE_BUTTON_16,
# INPUTDEVICE_BUTTON_17,
# INPUTDEVICE_BUTTON_18,
# INPUTDEVICE_BUTTON_19,
# INPUTDEVICE_BUTTON_20,
# INPUTDEVICE_BUTTON_21,
# INPUTDEVICE_BUTTON_22,
# INPUTDEVICE_BUTTON_23,
# INPUTDEVICE_BUTTON_24,
# INPUTDEVICE_BUTTON_25,
# INPUTDEVICE_BUTTON_26,
# INPUTDEVICE_BUTTON_27,
# INPUTDEVICE_BUTTON_28,
# INPUTDEVICE_BUTTON_29,
# INPUTDEVICE_BUTTON_30,
# INPUTDEVICE_BUTTON_31,
# INPUTDEVICE_BUTTON_MAX,
# #endif

INPUTDEVICE_MOUSE_OFFSET = 1900
INPUTDEVICE_LEFTMOUSE = 1901
INPUTDEVICE_MIDDLEMOUSE = 1902
INPUTDEVICE_RIGHTMOUSE = 1903
INPUTDEVICE_MOUSEX = 1904
INPUTDEVICE_MOUSEXNEG = 1905
INPUTDEVICE_MOUSEXPOS = 1906
INPUTDEVICE_MOUSEY = 1907
INPUTDEVICE_MOUSEYNEG = 1908
INPUTDEVICE_MOUSEYPOS = 1909
