Strange. I didn't see any thread about general purpose lua stuff here. I figure I'd create one.
In creation of this thread, I will start off by posting a quick script to help with handling the analog input using the main PSXjin window, instead of that clunky analog control window.
Download analog.luaLanguage: lua
-- Simplify handling analog input. 1 player only.
-- FatRatKnight
local keys, lastkeys= input.get(),input.get()
--*****************************************************************************
local function UpdateKeys() lastkeys= keys; keys= input.get() end
--*****************************************************************************
local function Press(k) return keys[k] and (not lastkeys[k]) end
--*****************************************************************************
local function Limits(v,l,h) return math.max(math.min(v,h),l) end
--*****************************************************************************
--*****************************************************************************
local function GuiTextRight(x,y,t,c)
--*****************************************************************************
x= x - #tostring(t)*4
gui.text(x,y,t,c)
end
local CA= {
xleft= 128, xright= 128,
yleft= 128, yright= 128
}
--*****************************************************************************
local function ResetAnalog()
--*****************************************************************************
-- Should be obvious: Restore defaults.
CA.xleft= 128; CA.xright= 128
CA.yleft= 128; CA.yright= 128
end
local StickyAnalog= true
--*****************************************************************************
local function HandleAnalog()
--*****************************************************************************
-- Apply the input each frame. Reset it too, depending on mode.
joypad.setanalog(1,CA)
if not StickyAnalog then ResetAnalog() end
end
emu.registerbefore(HandleAnalog)
--*****************************************************************************
local function ControlAnalog()
--*****************************************************************************
-- Handle user input through main window
UpdateKeys()
-- Analog handler and display
if keys.leftclick then
CA.xleft= Limits(CA.xleft + keys.xmouse - lastkeys.xmouse, 0,255)
CA.yleft= Limits(CA.yleft + keys.ymouse - lastkeys.ymouse, 0,255)
gui.line(keys.xmouse,
keys.ymouse,
keys.xmouse - CA.xleft + 128,
keys.ymouse - CA.yleft + 128, 0x0040FFFF) -- Blue
end
if keys.rightclick then
CA.xright= Limits(CA.xright + keys.xmouse - lastkeys.xmouse, 0,255)
CA.yright= Limits(CA.yright + keys.ymouse - lastkeys.ymouse, 0,255)
gui.line(keys.xmouse,
keys.ymouse,
keys.xmouse - CA.xright + 128,
keys.ymouse - CA.yright + 128, -0x00BFFF01) -- Red; 80Red bug
end
-- Option and reset switches.
if Press("insert") then StickyAnalog = not StickyAnalog end
if Press("delete") then ResetAnalog() end
-- Handle displaying the coordinates.
local color= -0x00000001 -- White. 80Red glitch bypass
if StickyAnalog then color= 0x00FF80FF end -- Mostly Green
GuiTextRight(70, 5,CA.xleft, color)
GuiTextRight(70,13,CA.yleft, color)
GuiTextRight(90, 5,CA.xright,color)
GuiTextRight(90,13,CA.yright,color)
end
gui.register(ControlAnalog)
--*****************************************************************************
while true do
--*****************************************************************************
-- I have observed glitches without this in place.
emu.frameadvance()
end
Well... That was the main point of my creating this thread, to share this code. But an entire thread dedicated to this one thing felt out of place, so I'll make it a general-purpose thread instead.
So, uh... Someone find something to discuss...? I mainly wanted to share that code.