Evdev joystick plugin
[lsnes.git] / lua / input.cpp
blobe91e16466f3bbfd1a0aa7b2fdd9ef5d64ca10b47
1 #include "lua-int.hpp"
3 namespace
5 function_ptr_luafun iset("input.set", [](lua_State* LS, const std::string& fname) -> int {
6 if(!lua_input_controllerdata)
7 return 0;
8 unsigned controller = get_numeric_argument<unsigned>(LS, 1, fname.c_str());
9 unsigned index = get_numeric_argument<unsigned>(LS, 2, fname.c_str());
10 short value = get_numeric_argument<short>(LS, 3, fname.c_str());
11 if(controller > 7 || index > 11)
12 return 0;
13 (*lua_input_controllerdata)(controller >> 2, controller & 3, index) = value;
14 return 0;
15 });
17 function_ptr_luafun iget("input.get", [](lua_State* LS, const std::string& fname) -> int {
18 if(!lua_input_controllerdata)
19 return 0;
20 unsigned controller = get_numeric_argument<unsigned>(LS, 1, fname.c_str());
21 unsigned index = get_numeric_argument<unsigned>(LS, 2, fname.c_str());
22 if(controller > 7 || index > 11)
23 return 0;
24 lua_pushnumber(LS, (*lua_input_controllerdata)(controller >> 2, controller & 3, index));
25 return 1;
26 });
28 function_ptr_luafun ireset("input.reset", [](lua_State* LS, const std::string& fname) -> int {
29 if(!lua_input_controllerdata)
30 return 0;
31 long cycles = 0;
32 get_numeric_argument(LS, 1, cycles, fname.c_str());
33 if(cycles < 0)
34 return 0;
35 short lo = cycles % 10000;
36 short hi = cycles / 10000;
37 (*lua_input_controllerdata)(CONTROL_SYSTEM_RESET) = 1;
38 (*lua_input_controllerdata)(CONTROL_SYSTEM_RESET_CYCLES_HI) = hi;
39 (*lua_input_controllerdata)(CONTROL_SYSTEM_RESET_CYCLES_LO) = lo;
40 return 0;
41 });