table joypad.read(int which = 1) Reads the joypads as inputted by the user. TODO: Don't read in *everything*...
| 2817 | // Reads the joypads as inputted by the user. |
| 2818 | // TODO: Don't read in *everything*... |
| 2819 | static int joy_get_internal(lua_State *L, bool reportUp, bool reportDown) { |
| 2820 | |
| 2821 | // Reads the joypads as inputted by the user |
| 2822 | int which = luaL_checkinteger(L,1); |
| 2823 | |
| 2824 | if (which < 1 || which > 4) { |
| 2825 | luaL_error(L,"Invalid input port (valid range 1-4, specified %d)", which); |
| 2826 | } |
| 2827 | |
| 2828 | // Use the OS-specific code to do the reading. |
| 2829 | extern SFORMAT FCEUCTRL_STATEINFO[]; |
| 2830 | uint8 buttons = ((uint8 *) FCEUCTRL_STATEINFO[1].v)[which - 1]; |
| 2831 | |
| 2832 | lua_newtable(L); |
| 2833 | |
| 2834 | int i; |
| 2835 | for (i = 0; i < 8; i++) { |
| 2836 | bool pressed = (buttons & (1<<i))!=0; |
| 2837 | if ((pressed && reportDown) || (!pressed && reportUp)) { |
| 2838 | lua_pushboolean(L, pressed); |
| 2839 | lua_setfield(L, -2, button_mappings[i]); |
| 2840 | } |
| 2841 | } |
| 2842 | |
| 2843 | return 1; |
| 2844 | } |
| 2845 | // joypad.get(which) |
| 2846 | // returns a table of every game button, |
| 2847 | // true meaning currently-held and false meaning not-currently-held |
no test coverage detected