Jump to content
LaunchBox Community Forums

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


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. If you don't know how to create and run a powershell script, follow this: https://www.youtube.com/watch?v=s3sWPUBLxmc . You can turn into an exe via the Invoke-PS2EXE command line and then put into your shell:startup folder to run on boot like this: https://imgur.com/a/FL2sZFJ

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
  • Unusual Gem 1
  • 8 months later...
Posted

I copy this and changed the pathnames to my proper folders. I'm getting the popup window of \\.\Display14 for my primary screen. But I'm not seeing the change in the mame.ini file

 

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

#Run mame in verbose to grab display info. Wait 1 second so the file can be written
$proc = Start-Process -FilePath "E:\Launchbox\Emulators\MAME Lightgun\mame.exe" -ArgumentList "-verbose" -RedirectStandardOutput output.txt
Start-Sleep -Seconds 1
$inputs = Get-Content -Path 'E:\Launchbox\Emulators\MAME Lightgun\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 'E:\Launchbox\Emulators\MAME Lightgun\ini\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 "E:\Launchbox\Emulators\MAME Lightgun\ini\mame.ini"

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

 

Posted (edited)

It might be because you have two digits in your displayname. Try changing this:

$content = $content -replace '(DISPLAY\d)',"$primarydisplay"

To this:

$content = $content -replace '(DISPLAY\d{1,2})',"$primarydisplay"

And uncomment this out right below it (remove the #) to see if it worked:

#Write-Output $content

If that worked, then it should write it correctly to the mame.ini file.

If that's not working then double check that it's reading in the mame file by uncommenting the Write-Output line here:

#Read in mame.ini
$content = Get-Content -Path 'E:\Launchbox\Emulators\MAME Lightgun\ini\mame.ini'
#Write-Output $content
Edited by Hamburglin
Posted (edited)

so its reading but its either not writing or not saving after it writes.

 

ahhh the ini folder was read only. I'll try again. ok so I use three instances of mame.  2 of them switched.  Jasen Baker's Integrum Retro Lightgun drive is read only so thats a problem. I'm waiting to hear back from him

 

 

Edited by midd
Posted

yes even with the original script, 2 of my mame ini files are showing Display14.  the lightgun drive mame is read only.  I've tried changing the permissions to allow write but the mame folder is still showing read only. He's got it locked down. I'm waiting for a reply from him.

Posted

Ok. Hopefully that works when he unlocks it.

If it still doesn't, you'll want to check on that Write-Output uncomment above to confirm that the main display line is being updated before it even tries writing to mame.ini. This is not the same thing as the DISPLAY14 line you're seeing.

Posted

then what am I looking for when I uncomment it.  I did it for both areas as you instructed and a popup window appeared for every line of the .ini file, twice so I assumed it was for read and write. I had to select ok for each line to cycle through it all

Posted

You want to look at the first output of the ini file ( the Write-Output that was near primardisplay yhat you uncommented) and make the that the DISPLAYXX is set on the correct ini line. It's showing what it WOULD write to the ini file if you could (seems like yo can't right now). So it should be set correctly there.

I think the line in the ini that should be chanhed us display 1 or main display. I can't remember off the top of my head.

The second ini i suhhest to uncomment us literally just reading in the mame.ini file and showing you what it is, unedited. You can comment that back out for now since you know that's working.

Posted

Oh, there's nothing to change in any files. There output you see if just temporally in memory. Does the output look right? Is the correct display where it should be in the output of the script? 

If this is confusing, let me know and I can share some pictures later.

Posted

So your program didn’t update the lightgun ini. . But I downloaded arcade64 to make some changes using the gui.  I can assign the screen, display14 and it will show in the ini file, but it’s still going to the marquee if I launch it through Launchbox. If I launch the game just through arcade64, it goes to the main display.

 

must be something with his scripts.

Posted

Yeah so I'm not talking about files at all. Forget about that.

In the output of the script on screen, you need to look at the blob of the ini it's going to write to a file later. You'll need to tell me if that looks right not. Check if the right display is in the right spot or not.

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...