Jump to content
LaunchBox Community Forums

Automatically set correct DISPLAY in mame.ini at startup - Marquee setups


Hamburglin

Recommended Posts

Posted (edited)

Mame has a problem choosing the correct monitor to run in if you have a setup that uses multiple monitors. Monitor indexes get changed in Windows but doesn't get updated in the mame.ini. This happens when you boot with one monitor off, or unplug one and plug it back in.

This is frustrating when you're trying to host an arcade cabinet and have it "just work". My games end up on the marquee screens which is a show stopper because it requires editing a text file to fix.

Here's a powershell script that permanently fixes this issue. You can turn into an exe via Invoke-PS2EXE and then put into your shell:startup folder to run on boot.

It runs mame in verbose mode to grab your (primary) display and then correctly uses that to overwrite the current DISPLAY setting in the mame.ini file. It then immediately shuts down mame.

Change the directories to yours:

#Set working dir to mame directory so that it can read and write the mame.ini
Set-Location -Path "C:\Emulation\Emulators\MAME 250\"
#Get-Location

#Run mame in verbose to grab display info. Wait 1 second so the file can be written
$proc = Start-Process -FilePath "C:\Emulation\Emulators\MAME 250\mame.exe" -ArgumentList "-verbose" -RedirectStandardOutput output.txt
Start-Sleep -Seconds 1
$inputs = Get-Content -Path 'C:\Emulation\Emulators\MAME 250\output.txt'
#Write-Output $inputs
#Find primary DISPLAY
$primarydisplayline = ($inputs | Select-String "\(primary\)").Line
$primarydisplay = $primarydisplayline -replace '.*(DISPLAY\d).*',"`$1"
Write-Output $primarydisplayline
Write-Output $primarydisplay

#Read in mame.ini
$content = Get-Content -Path 'C:\Emulation\Emulators\MAME 250\mame.ini'
#Write-Output $content

#Edit mame.ini mouse related lines
#Update DISPLAYx with primary DISPLAYy
$content = $content -replace '(DISPLAY\d)',"$primarydisplay"
#Write-Output $content

#Write new mame.ini file
$content | Set-Content -Path "C:\Emulation\Emulators\MAME 250\mame.ini"

#Kill mame
Get-Process -Name MAME -ErrorAction SilentlyContinue | Stop-Process -Force

#Make guns rumble so we know this all worked
cmd.exe /c "echo F.1.2.1 > \\.\COM11"
cmd.exe /c "echo F.1.2.1 > \\.\COM12"

 

Edited by Hamburglin
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...