Previous Thread
Next Thread
Print Thread
Page 1 of 3 1 2 3
Joined: May 2009
Posts: 2,214
Likes: 382
J
Very Senior Member
OP Offline
Very Senior Member
J
Joined: May 2009
Posts: 2,214
Likes: 382
This question is primarily directed at Golden Child, but I'm hoping Vas might be able to provide some insight as well. This is in regards to my thread here: https://old.reddit.com/r/MAME/comments/17i3er5/input_question_for_anyone_who_uses_the_nes_driver/

I know that there are video overlays that one can use with OBS to record the state of a controller at any given moment, what I want is to re-create such a thing within MAME itself in order to compare the two.

All I really want is for there to be well-positioned boxes for: D-pad L/R/U/D, and Buttons 1-4. If it's possible to make a Lua script to read the current inputs that MAME is registering, and either fill or not-fill a surrounding with a highlight whenever that button is considered to be pressed, that would be a huge help, because if it's overlaid on the window, then I'll capture it while recording a given session. I can then see where the disagreement originates: If MAME's idea of "which button is pressed" differs from the controller overlay, then that could point the finger one way. If not, then it makes it clearer that the MAME driver for the NES itself is flawed in how it handles inputs.

Joined: Feb 2004
Posts: 2,597
Likes: 300
Very Senior Member
Offline
Very Senior Member
Joined: Feb 2004
Posts: 2,597
Likes: 300
If you just want to display inputs as seen by the emulated system, you’re better off just making a layout file. Use the inputs to set the state of elements, and make them draw a different colour box depending on the state. You can do it with Lua script, but it’s a lot more work. If you ask over at the MAME Artwork forum, most of the more experienced guys there have mastered doing this for simple cases, so you could probably get more detailed examples from them. Also it’s kind of hap’s thing.

Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172
Hi, JD,

sure I can whip something up, gimme an hour or two, gotta work out how to read an nes ioport in a lua script

print(manager.machine.ioport.ports[":ctrl1:joypad:JOYPAD"]:read())

I'll also try Vas's suggestion to make a simple layout.

(woo hoo crossed the 1000 post mark)

Last edited by Golden Child; 10/28/23 06:31 PM.
1 member likes this: robcfg
Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172
Ok, here's a little script that will show the buttons for the left controller:

Code
function iifnot0(a,b,c) if a~=0 then return b else return c end end
function drawoverlay()
dpadx,dpady = 50, 170 padx,pady = 30, 30 cposx,cposy = 120, 170 rposx, rposy = 190,170
buttons = {up = 16, down = 32, left = 64, right = 128, a=1, b=2, select=4, start=8} 
buttonpos = {up = {dpadx, dpady-pady},  down = {dpadx,dpady + pady}, right = {dpadx+padx, dpady}, left={dpadx-padx, dpady}, select={cposx, cposy}, start={cposx+padx,cposy}, b={rposx,rposy},a={rposx+padx,rposy}}
for i,j in pairs(buttons) do 
 manager.machine.screens[":screen"]:draw_box(buttonpos[i][1],buttonpos[i][2],buttonpos[i][1]+20,buttonpos[i][2]+20,
 0x88ffffff, iifnot0(manager.machine.ioport.ports[":ctrl1:joypad:JOYPAD"]:read() & buttons[i], 0x88ff0000, 0x88000000)) 
 manager.machine.screens[":screen"]:draw_text(buttonpos[i][1]+2,buttonpos[i][2]+4,i)
end
end
emu.register_frame_done(drawoverlay)


You can paste it in on the lua console or save it to a file and dofile("myfile.lua")

Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172
Here's a layout file for nes, put it in a file called artwork/nes1/nes1.lay and then use "-override_artwork nes1"


Code


<mamelayout version="2">
	<element name="button">
		<rect state="1"><color alpha="0.5" red="1.0" green="0" blue="0"/></rect>
		<rect state="0"><color alpha="0.5" red="0" green="0" blue="0"/></rect>
	</element>


	<view name="Controllers Overlay">
		<screen index="0">
			<bounds x="0" y="0" width="256" height="240" />
		</screen>

<!-- a -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x1">
		<bounds x="220" y="170" width="20" height="20"/>
		</element>
<!-- b -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x2">
		<bounds x="190" y="170" width="20" height="20"/>
		</element>


<!-- select -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x4">
		<bounds x="120" y="170" width="20" height="20"/>
		</element>

<!-- start -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x8">
		<bounds x="150" y="170" width="20" height="20"/>
		</element>

<!-- up -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x10">
		<bounds x="50" y="140" width="20" height="20"/>
		</element>
<!-- down -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x20">
		<bounds x="50" y="200" width="20" height="20"/>
		</element>

<!-- left -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x40">
		<bounds x="20" y="170" width="20" height="20"/>
		</element>

<!-- right -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x80">
		<bounds x="80" y="170" width="20" height="20"/>
		</element>

	</view>
</mamelayout>



3 members like this: ICEknight, robcfg, R. Belmont
Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172
For fun, I thought I'd add the ability to move the overlay up and down with keypad 2 and 8, adjust the alpha with keypad 4 and 6, and turn the overlay off and on with [ and ]

Code
function iifnot0(a,b,c) if a~=0 then return b else return c end end

displayoverlay=true
originx,originy=50,170
alphavalue=0.5

function drawoverlay()
dpadx,dpady = 50,originy padx,pady = 30,30 cposx,cposy = 120,originy rposx, rposy = 190,originy
buttons = {up = 16, down = 32, left = 64, right = 128, a=1, b=2, select=4, start=8} 
buttonpos = {up = {dpadx, dpady-pady},  down = {dpadx,dpady + pady}, right = {dpadx+padx, dpady}, left={dpadx-padx, dpady}, select={cposx, cposy}, start={cposx+padx,cposy}, b={rposx,rposy},a={rposx+padx,rposy}}
if displayoverlay==true then
for i,j in pairs(buttons) do 
 manager.machine.screens[":screen"]:draw_box(buttonpos[i][1],buttonpos[i][2],buttonpos[i][1]+20,buttonpos[i][2]+20,
   0x00ffffff | math.floor(alphavalue*255)<<24, 
   iifnot0(manager.machine.ioport.ports[":ctrl1:joypad:JOYPAD"]:read() & buttons[i], 
     0x00ff0000 | math.floor(alphavalue*255)<<24, 
     0x00000000 | math.floor(alphavalue*255)<<24))
 manager.machine.screens[":screen"]:draw_text(buttonpos[i][1]+2, buttonpos[i][2]+4, i,
     0xffffff | math.floor(alphavalue*255)<<24)
end
end
input=manager.machine.input
if input:code_pressed(input:code_from_token("KEYCODE_OPENBRACE")) then displayoverlay = false end
if input:code_pressed(input:code_from_token("KEYCODE_CLOSEBRACE")) then displayoverlay = true end
if input:code_pressed(input:code_from_token("KEYCODE_8PAD")) then originy = originy - 1 end
if input:code_pressed(input:code_from_token("KEYCODE_2PAD")) then originy = originy + 1 end
if input:code_pressed(input:code_from_token("KEYCODE_4PAD")) then alphavalue = alphavalue-0.01 if alphavalue<0 then alphavalue=0 end end
if input:code_pressed(input:code_from_token("KEYCODE_6PAD")) then alphavalue = alphavalue+0.01 if alphavalue>1.0 then alphavalue=1.0 end end
end

emu.register_frame_done(drawoverlay)



1 member likes this: RomKnight
Joined: May 2009
Posts: 2,214
Likes: 382
J
Very Senior Member
OP Offline
Very Senior Member
J
Joined: May 2009
Posts: 2,214
Likes: 382
By the way, I do apologize for not having had a chance to dig into this. My weekend was topsy-turvy schedule-wise, and this week I just don't have much spare time. I'll get onto this this coming weekend.

Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172
If it helps, I added a framecounter display on the layout.

Interestingly, it seems to use up all the textures if you set the maxstate of the counter to something like 999999.
If I omit the maxstate, it will "wrap" the counter at 2048.

FRAME:2045
Searching font Liberation Sans in -. path/s
Matching font: 0x55578a018070
FRAME:2046
Searching font Liberation Sans in -. path/s
Matching font: 0x55578a957cf0
FRAME:2047
Searching font Liberation Sans in -. path/s
Matching font: 0x55578a983500
FRAME:2048
FRAME:2049
FRAME:2050

and if I set the maxstate to "99999" then it will count up to 4523 and fatal error
FRAME:4522
Searching font Liberation Sans in -. path/s
Matching font: 0x55c577436580
FRAME:4523
Searching font Liberation Sans in -. path/s
Matching font: 0x55c5774f96f0
Ignoring MAME exception: renderer_ogl::texture_create: texture hash exhausted ...
Fatal error: renderer_ogl::texture_create: texture hash exhausted ...
Average speed: 99.42% (74 seconds)


Code

<mamelayout version="2">
	<element name="button">
		<rect state="1"><color alpha="0.5" red="1.0" green="0.0" blue="0.0"/></rect>
		<rect state="0"><color alpha="0.5" red="0.0" green="0.0" blue="0.0"/></rect>
	</element>


<group name="controller">

<!-- a -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x1">
		<bounds x="220" y="170" width="20" height="20"/>
		</element>
<!-- b -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x2">
		<bounds x="190" y="170" width="20" height="20"/>
		</element>


<!-- select -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x4">
		<bounds x="120" y="170" width="20" height="20"/>
		</element>

<!-- start -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x8">
		<bounds x="150" y="170" width="20" height="20"/>
		</element>

<!-- up -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x10">
		<bounds x="50" y="140" width="20" height="20"/>
		</element>
<!-- down -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x20">
		<bounds x="50" y="200" width="20" height="20"/>
		</element>

<!-- left -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x40">
		<bounds x="20" y="170" width="20" height="20"/>
		</element>

<!-- right -->
		<element ref="button" inputtag=":ctrl1:joypad:JOYPAD" inputmask="0x80">
		<bounds x="80" y="170" width="20" height="20"/>
		</element>

</group>

	<element name="framecount"><simplecounter align="2" /></element>

	<view name="Controllers Overlay">
		<screen index="0">
			<bounds x="0" y="0" width="256" height="240" />
		</screen>
		<group ref="controller">
		</group>
		<element ref="framecount" id="framecount">
	  		<bounds x="0" y="0" width="50" height="10"/>
		</element>
	</view>
	
	
	
	
	
	
	
	
<script><![CDATA[

-- file is the layout file object

print("LAYOUT LOADED  file.device.name = "..file.device.name)
print("LAYOUT LOADED  file.device.shortname = "..file.device.shortname)
print("LAYOUT LOADED  file.device.tag = = "..file.device.tag)


file:set_resolve_tags_callback(
	function ()

file.views["Controllers Overlay"].items["framecount"]:set_element_state_callback(
		function () 
		--print("FRAME:"..machine.screens[":screen"]:frame_number())
		return machine.screens[":screen"]:frame_number()
		end)

end)

]]></script>
	
	

</mamelayout>

Last edited by Golden Child; 11/01/23 09:27 AM.
Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172
And a framenumber on the lua script:

Code
function iifnot0(a,b,c) if a~=0 then return b else return c end end

displayoverlay=true
originx,originy=50,170
alphavalue=0.5

function drawoverlay()
dpadx,dpady = 50,originy padx,pady = 30,30 cposx,cposy = 120,originy rposx, rposy = 190,originy
buttons = {up = 16, down = 32, left = 64, right = 128, a=1, b=2, select=4, start=8} 
buttonpos = {up = {dpadx, dpady-pady},  down = {dpadx,dpady + pady}, right = {dpadx+padx, dpady}, left={dpadx-padx, dpady}, select={cposx, cposy}, start={cposx+padx,cposy}, b={rposx,rposy},a={rposx+padx,rposy}}
if displayoverlay==true then
for i,j in pairs(buttons) do 
 manager.machine.screens[":screen"]:draw_box(buttonpos[i][1],buttonpos[i][2],buttonpos[i][1]+20,buttonpos[i][2]+20,
   0x00ffffff | math.floor(alphavalue*255)<<24, 
   iifnot0(manager.machine.ioport.ports[":ctrl1:joypad:JOYPAD"]:read() & buttons[i], 
     0x00ff0000 | math.floor(alphavalue*255)<<24, 
     0x00000000 | math.floor(alphavalue*255)<<24))
 manager.machine.screens[":screen"]:draw_text(buttonpos[i][1]+2, buttonpos[i][2]+4, i,
     0xffffff | math.floor(alphavalue*255)<<24)
end
framenum = manager.machine.screens[":screen"]:frame_number()
 manager.machine.screens[":screen"]:draw_text(5,5,"Frame Number: "..framenum,
     0xffffff | math.floor(alphavalue*255)<<24)
 manager.machine.screens[":screen"]:draw_text(5,5,"Frame Number: "..framenum.."   "..string.rep(" ",framenum % 10 * 2)..framenum % 10,
     0xffffff | math.floor(alphavalue*255)<<24)
end
input=manager.machine.input
if input:code_pressed(input:code_from_token("KEYCODE_OPENBRACE")) then displayoverlay = false end
if input:code_pressed(input:code_from_token("KEYCODE_CLOSEBRACE")) then displayoverlay = true end
if input:code_pressed(input:code_from_token("KEYCODE_8PAD")) then originy = originy - 1 end
if input:code_pressed(input:code_from_token("KEYCODE_2PAD")) then originy = originy + 1 end
if input:code_pressed(input:code_from_token("KEYCODE_4PAD")) then alphavalue = alphavalue-0.01 if alphavalue<0 then alphavalue=0 end end
if input:code_pressed(input:code_from_token("KEYCODE_6PAD")) then alphavalue = alphavalue+0.01 if alphavalue>1.0 then alphavalue=1.0 end end
end

emu.register_frame_done(drawoverlay)

Joined: Feb 2014
Posts: 1,100
Likes: 172
G
Very Senior Member
Online Content
Very Senior Member
G
Joined: Feb 2014
Posts: 1,100
Likes: 172
[Linked Image from i.imgur.com]

layout version:

[Linked Image from i.imgur.com]

Last edited by Golden Child; 11/01/23 05:06 PM.
1 member likes this: ICEknight
Page 1 of 3 1 2 3

Link Copied to Clipboard
Who's Online Now
2 members (Reznor007, AJR), 326 guests, and 1 robot.
Key: Admin, Global Mod, Mod
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics9,320
Posts121,925
Members5,074
Most Online1,283
Dec 21st, 2022
Our Sponsor
These forums are sponsored by Superior Solitaire, an ad-free card game collection for macOS and iOS. Download it today!

Superior Solitaire
Forum hosted by www.retrogamesformac.com