diff --git a/controls.cpp b/controls.cpp index 030a7b8c..2bf918ec 100644 --- a/controls.cpp +++ b/controls.cpp @@ -3588,12 +3588,13 @@ uint16 MovieGetJoypad (int i) return (joypad[i].buttons); } -void MovieSetJoypad (int i, uint16 buttons) +void MovieSetJoypad (int i, uint16 buttons, uint16 mask) { if (i < 0 || i > 7) return; - joypad[i].buttons = buttons; + joypad[i].buttons &= ~mask; + joypad[i].buttons |= buttons; } bool MovieGetMouse (int i, uint8 out[5]) diff --git a/lua-engine.cpp b/lua-engine.cpp index b9349329..22f45708 100644 --- a/lua-engine.cpp +++ b/lua-engine.cpp @@ -2156,33 +2156,6 @@ DEFINE_LUA_FUNCTION(state_savescriptdata, "location") } -//joypad lib - -static const char *button_mappings[] = { -"I","II","Select","Run","Up","Right","Down","Left" -}; - -// table joypad.read(int which = 1) -// -// Reads the joypads as inputted by the user. -/*static int joy_get(lua_State *L) { - - lua_newtable(L); - - int which = luaL_checkinteger(L,1)-1; - - int i; - for (i = 0; i < 8; i++) { - if (pcejin.pads[which] & (1< 8) + luaL_error(L, "controller number must be within the range 1 to 8"); return controllerNumber; } -*/ -static const struct ButtonDesc -{ - unsigned short controllerNum; - unsigned short bit; - const char* name; -} - -s_buttonDescs [] = -{ - {1, 0, "I"}, - {1, 1, "II"}, - {1, 2, "Select"}, - {1, 3, "Run"}, - {1, 4, "Up"}, - {1, 5, "Right"}, - {1, 6, "Down"}, - {1, 7, "Left"}, -}; // joypad.set(controllerNum = 1, inputTable) -// controllerNum can be 1, 2, '1B', or '1C' -/*DEFINE_LUA_FUNCTION(joy_set, "[controller=1,]inputtable") +// controllerNum can be within the range 1 to 8 +DEFINE_LUA_FUNCTION(joy_set, "[controller=1,]inputtable") { int index = 1; - int controllerNumber = 1;//joy_getArgControllerNum(L, index); + int controllerNumber = joy_getArgControllerNum(L, index); luaL_checktype(L, index, LUA_TTABLE); - int input = ~0; - int mask = 0; + uint32 input = 0; + uint32 mask = 0; for(int i = 0; i < sizeof(s_buttonDescs)/sizeof(*s_buttonDescs); i++) { @@ -2309,25 +2305,22 @@ s_buttonDescs [] = if (!lua_isnil(L,-1)) { bool pressed = lua_toboolean(L,-1) != 0; - int bitmask = ((long long)1 << bd.bit); + uint32 bitmask = ((uint32)1 << bd.bit); if(pressed) - input &= ~bitmask; - else input |= bitmask; + else + input &= ~bitmask; mask |= bitmask; } lua_pop(L,1); } } - pcejin.pads[0]=mask; - -// SetNextInputCondensed(input, mask); - + MovieSetJoypad(controllerNumber - 1, input, mask); return 0; -}*/ -/* +} + // joypad.get(controllerNum = 1) -// controllerNum can be 1, 2, '1B', or '1C' +// controllerNum can be within the range 1 to 8 int joy_get_internal(lua_State* L, bool reportUp, bool reportDown) { int index = 1; @@ -2335,14 +2328,14 @@ int joy_get_internal(lua_State* L, bool reportUp, bool reportDown) lua_newtable(L); - long long input = GetCurrentInputCondensed(); + uint32 input = MovieGetJoypad(controllerNumber - 1); for(int i = 0; i < sizeof(s_buttonDescs)/sizeof(*s_buttonDescs); i++) { const ButtonDesc& bd = s_buttonDescs[i]; if(bd.controllerNum == controllerNumber) { - bool pressed = (input & ((long long)1<