MCPcopy Create free account
hub / github.com/TASEmulators/fceux / joy_get_internal

Function joy_get_internal

src/lua-engine.cpp:2819–2844  ·  view source on GitHub ↗

table joypad.read(int which = 1) Reads the joypads as inputted by the user. TODO: Don't read in *everything*...

Source from the content-addressed store, hash-verified

2817// Reads the joypads as inputted by the user.
2818// TODO: Don't read in *everything*...
2819static 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

Callers 3

joypad_getFunction · 0.85
joypad_getdownFunction · 0.85
joypad_getupFunction · 0.85

Calls 4

luaL_checkintegerFunction · 0.85
luaL_errorFunction · 0.85
lua_pushbooleanFunction · 0.85
lua_setfieldFunction · 0.85

Tested by

no test coverage detected