diff --git a/src/frontend/qt_sdl/EmuInstance.h b/src/frontend/qt_sdl/EmuInstance.h index cec62394..2dcdfa49 100644 --- a/src/frontend/qt_sdl/EmuInstance.h +++ b/src/frontend/qt_sdl/EmuInstance.h @@ -149,6 +149,8 @@ public: std::vector heldKeys; std::vector keyStrokes; + Sint16 getJoyStickAxis(int axisNum); + void touchScreen(int x, int y); void releaseScreen(); diff --git a/src/frontend/qt_sdl/EmuInstanceInput.cpp b/src/frontend/qt_sdl/EmuInstanceInput.cpp index da0cd391..24dd2e76 100644 --- a/src/frontend/qt_sdl/EmuInstanceInput.cpp +++ b/src/frontend/qt_sdl/EmuInstanceInput.cpp @@ -361,6 +361,16 @@ void EmuInstance::inputProcess() lastHotkeyMask = hotkeyMask; } +//Used By Lua Scripts +Sint16 EmuInstance::getJoyStickAxis(int axisNum){ + if (joystick) + { + axisNum = axisNum & 0xF; + return SDL_JoystickGetAxis(joystick, axisNum); + } + return 0; +} + void EmuInstance::touchScreen(int x, int y) { touchX = x; diff --git a/src/frontend/qt_sdl/LuaMain.cpp b/src/frontend/qt_sdl/LuaMain.cpp index b5ec7cbb..a7b47c78 100644 --- a/src/frontend/qt_sdl/LuaMain.cpp +++ b/src/frontend/qt_sdl/LuaMain.cpp @@ -347,10 +347,9 @@ AddLuaFunction(Lua_Reads32,Reads32); int Lua_NDSTapDown(lua_State* L) { LuaBundle* bundle = get_bundle(L); - melonDS::NDS* nds = bundle->getEmuInstance()->getNDS(); int x = luaL_checkinteger(L,1); int y = luaL_checkinteger(L,2); - nds->TouchScreen(x,y); + bundle->getEmuInstance()->touchScreen(x,y); return 0; } AddLuaFunction(Lua_NDSTapDown,NDSTapDown); @@ -358,8 +357,7 @@ AddLuaFunction(Lua_NDSTapDown,NDSTapDown); int Lua_NDSTapUp(lua_State* L) { LuaBundle* bundle = get_bundle(L); - melonDS::NDS* nds = bundle->getEmuInstance()->getNDS(); - nds->ReleaseScreen(); + bundle->getEmuInstance()->releaseScreen(); return 0; } AddLuaFunction(Lua_NDSTapUp,NDSTapUp); @@ -630,4 +628,14 @@ int Lua_getJoy(lua_State* L) } AddLuaFunction(Lua_getJoy,GetJoy); +int Lua_getJoyStick(lua_State* L) +{ + LuaBundle* bundle = get_bundle(L); + int axisNum = luaL_checknumber(L,1); + int val = bundle->getEmuInstance()->getJoyStickAxis(axisNum); + lua_pushinteger(L,val); + return 1; +} +AddLuaFunction(Lua_getJoyStick,GetJoyStick); + } \ No newline at end of file diff --git a/src/frontend/qt_sdl/Screen.cpp b/src/frontend/qt_sdl/Screen.cpp index 5c671f39..8da00cff 100644 --- a/src/frontend/qt_sdl/Screen.cpp +++ b/src/frontend/qt_sdl/Screen.cpp @@ -1163,17 +1163,18 @@ void ScreenPanelGL::drawOverlays(int screenType,int screen) glTexSubImage2D(GL_TEXTURE_2D,0,0,0,overlay.rectangle.width(),overlay.rectangle.height(),GL_RGBA,GL_UNSIGNED_BYTE,overlay.displayBuffer->bits()); overlay.flipped = false; } - + glBindTexture(GL_TEXTURE_2D, overlay.GLTexture); - glUniform2f(overlayPosULoc,overlay.rectangle.left(),overlay.rectangle.top()); - glUniform2f(overlaySizeULoc,overlay.rectangle.width(),overlay.rectangle.height()); - + if(screenType == canvasTarget_OSD) // OSD gets drawn differently then top or bottom screen target { + glUniform2i(osdPosULoc,overlay.rectangle.left(),overlay.rectangle.top()); + glUniform2i(osdSizeULoc,overlay.rectangle.width(),overlay.rectangle.height()); glDrawArrays(GL_TRIANGLES, 0, 2*3); continue; } - + glUniform2f(overlayPosULoc,overlay.rectangle.left(),overlay.rectangle.top()); + glUniform2f(overlaySizeULoc,overlay.rectangle.width(),overlay.rectangle.height()); glUniform1i(overlayScreenTypeULoc, screenType); glUniformMatrix2x3fv(overlayTransformULoc, 1, GL_TRUE,screenMatrix[screen]); glDrawArrays(GL_TRIANGLES,screenType == 0 ? 0 : 2*3, 2*3); diff --git a/tools/LuaScripts/LuaScriptTest.lua b/tools/LuaScripts/LuaScriptTest.lua index 93c52211..f1231a48 100644 --- a/tools/LuaScripts/LuaScriptTest.lua +++ b/tools/LuaScripts/LuaScriptTest.lua @@ -46,7 +46,8 @@ function _Update() MousePosText, MouseButtonText, KeysText, - JoyText + JoyText, + JoyStickText, }) do y = y+10 Text(0,y,tfunct(),0xffffff) @@ -90,6 +91,12 @@ function MousePosText() return "MousePos:"..mouse.X..","..mouse.Y end +function JoyStickText() + local x = GetJoyStick(0) + local y = GetJoyStick(1) + return "JoyStick:"..x..","..y +end + function MouseButtonText() str = "" for k,v in pairs(GetMouse()) do diff --git a/tools/LuaScripts/Lua_Docs.md b/tools/LuaScripts/Lua_Docs.md index 6fef3045..7b894328 100644 --- a/tools/LuaScripts/Lua_Docs.md +++ b/tools/LuaScripts/Lua_Docs.md @@ -69,6 +69,10 @@ end end ``` +`nAxisValue GetJoyStick(nAxisNum)` +- Returns the current value of the connected analoge joystick axis +- nAxisNum is a 4 bit int, (0-15) + `tJoyState GetJoy()` - Returns a lua table of the Joypad button states. - Table keys are: `A,B,Select,Start,Right,Left,Up,Down,R,L,X,Y`