-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinput-display.lua
136 lines (125 loc) · 3.94 KB
/
input-display.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
--[[
FBA-rr and MAME-rr input display script
written by Dammit
last update 2/18/2010
User: Do not edit this file.
This script depends on input-modules.lua.
]]
if not (mame or fba) then error("This script is only intended for FBA-rr and MAME-rr.", 0) end
if not emu.registerstart then error("This script requires a newer version of FBA-rr.", 0) end
col,inp,module = {},{}
local module_file = "input-modules.lua"
if not io.open(module_file, "r") then
print("Warning: unable to open '" .. module_file .. "'")
col = { --default colors:
on1 = 0xffff00ff, --pressed: yellow inside
on2 = 0x000000ff, --pressed: black border
off1 = 0x00000000, --unpressed: clear inside
off2 = 0x00000040, --unpressed: mostly clear black border
}
else
dofile(module_file, "r")
end
local function generic() --try to detect controls and make a generic module
local c,width,height = joypad.get(),emu.screenwidth(),emu.screenheight()
local stick,nbuttons,nplayers,label = 0,0,1
if c["P1 Up"] ~= nil and c["P1 Down"] ~= nil and c["P1 Left"] ~= nil and c["P1 Right"] ~= nil then
stick = 1
end
for b = 10,1,-1 do
for _,v in ipairs({"P1 Button " .. b, "P1 Fire " .. b}) do
if c[v] ~= nil then
nbuttons = b
label = v:gsub("[(P1)(%d+)]", "")
break
end
end
if nbuttons > 0 then
break
end
end
for n = 4,1,-1 do
if c["P"..n.." Button 1"] ~= nil or c["P"..n.." Fire 1"] ~= nil then
nplayers = n
break
end
end
if stick+nbuttons == 0 then return end --found neither stick nor buttons
print("Generic input display: "..nplayers.."-player, "..nbuttons.."-button"..(stick > 0 and "" or ", no joystick"))
module = {}
if stick > 0 then
for n = 1,nplayers do
module[n .. "^"] = {(n-1)/n*width + 0x10, height - 0x10, "P" .. n .. " Up"}
module[n .. "v"] = {(n-1)/n*width + 0x10, height - 0x08, "P" .. n .. " Down"}
module[n .. "<"] = {(n-1)/n*width + 0x08, height - 0x0c, "P" .. n .. " Left"}
module[n .. ">"] = {(n-1)/n*width + 0x18, height - 0x0c, "P" .. n .. " Right"}
end
end
for n = 1,nplayers do
for b = 1,nbuttons do
module[n .. b] = {(n-1)/n*width + stick*0x18 + 0x8 + math.floor((b-1)%(nbuttons/2))*0x8,
height - 0x10 + math.floor((b-1)*2/nbuttons)*0x08, "P" .. n .. label .. b}
end
end
for n = 1,nplayers do
for _,v in ipairs({n..(n==1 and " Player" or " Players").." Start", "P"..n.." Start", "Start "..n}) do
if c[v] ~= nil then
module[n .. "S"] = {(n-1)/n*width, height - 0x10, v}
break
end
end
for _,v in ipairs({"Coin "..n, "P"..n.." Coin"}) do
if c[v] ~= nil then
module[n .. "C"] = {(n-1)/n*width, height - 0x08, v}
break
end
end
end
end
local function pickmodule()
module = nil
for _,v in pairs(inp) do
for _,romname in ipairs(v[1]) do
if emu.romname() == romname or emu.parentname() == romname or emu.sourcename() == romname then
module = v[2]
for _,keyname in pairs(module) do
keyname[3] = mame and keyname[4] or keyname[3]
end
return
end
end
end
generic()
end
if not macrolua then --don't override macrolua's own registerstart function
emu.registerstart(function()
pickmodule()
end)
else
pickmodule()
end
function displayfunc(showinput)
if not showinput then
return
end
for k,v in pairs(module) do
local color1,color2 = col.on1,col.on2
if v[5] then --analog control
gui.text(v[1]+v[5], v[2], tostring(joypad.get()[v[3]]), color1, color2) --display analog value
elseif joypad.get()[v[3]] == false then --digital control, unpressed
color1,color2 = col.off1,col.off2
end --(otherwise digital control, pressed)
gui.text(v[1], v[2], string.sub(k, 2), color1, color2)
end
end
showinput = true
gui.register(function()
displayfunc(showinput)
end)
print("* Press Lua hotkey 5 to toggle input display.")
input.registerhotkey(5, function()
showinput = not showinput
if not showinput then
gui.clearuncommitted()
end
end)