Hi.
I tinkered around a bit with the Lua scripts, and came up with an idea I tried to implement. The idea is to take the intersection between button presses on controller 1 and button presses on controller 2, and only pass that as the input to controller 1. In essence, both players has to play at the same time.
But I ran into a problem: if I set the joypad of controller 1, the next frame I can only retrieve what I assigned to the joypad the previous frame (this is made clear in the documentation too). So, I was wondering, is it possible to access the raw input from both players, and not the joypad state as seen by the emulator?
Here is my current script:
Language: lua
-- Filter out the input on a certain player
function split(player, joypad)
local ret = {}
for k,v in pairs(joypad) do
if k:sub(1,2) == player then ret[k:sub(4)]=v end
end
return ret
end
function intersection(p1, p2)
local ret = {}
for k,v in pairs(p1) do
ret[k]= p1[k] and p2[k]
end
return ret
end
-- Make string from all pressed buttons
function dump(o)
local s = ''
for k,v in pairs(o) do
if v then s = s .. tostring(k) .. ' ' end
end
return s
end
while true do
-- Read the current joypad state
local pad = joypad.getimmediate()
-- Split the input for player 1 and player 2
local p1 = split("P1", pad)
local p2 = split("P2", pad)
-- Find the intersection between the two
local inter = intersection(p1, p2)
-- Render some help text
gui.drawText(0,10, "P1: " .. dump(p1), null, null, 10)
gui.drawText(0,25, "P2: " .. dump(p2), null, null, 10)
gui.drawText(0,40, "Out: " .. dump(inter), null, null, 10)
-- Set joypad 1 to the intersection of the two
joypad.set(inter, 1)
emu.frameadvance()
end
Thanks!