Hamburglin Posted May 19, 2024 Posted May 19, 2024 (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 Sunday at 09:51 PM by Hamburglin 1 Quote
kyzumi Posted Friday at 08:42 PM Posted Friday at 08:42 PM Thank you so much! I can't believe I found this! It was so annoying having to manually change the mame.ini everyday! (I have 3 monitors). Thank you! 1 Quote
midd Posted Sunday at 09:25 PM Posted Sunday at 09:25 PM 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 Quote
Hamburglin Posted Sunday at 09:46 PM Author Posted Sunday at 09:46 PM (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 Sunday at 09:47 PM by Hamburglin Quote
midd Posted Monday at 01:57 AM Posted Monday at 01:57 AM (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 Monday at 02:18 AM by midd Quote
Hamburglin Posted Monday at 02:42 AM Author Posted Monday at 02:42 AM Is it correctly setting the display14, or whatever it is now, too? You'll see it printed via the first Write-Output I showed above. Quote
midd Posted Monday at 12:32 PM Posted Monday at 12:32 PM 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. Quote
Hamburglin Posted Monday at 02:25 PM Author Posted Monday at 02:25 PM 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. Quote
midd Posted Monday at 03:08 PM Posted Monday at 03:08 PM 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 Quote
Hamburglin Posted Monday at 03:54 PM Author Posted Monday at 03:54 PM 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. Quote
midd Posted Monday at 04:08 PM Posted Monday at 04:08 PM ok it didnt change in the lightgun drive Quote
Hamburglin Posted Monday at 04:14 PM Author Posted Monday at 04:14 PM 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. Quote
midd Posted Monday at 04:26 PM Posted Monday at 04:26 PM 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. Quote
Hamburglin Posted Monday at 04:33 PM Author Posted Monday at 04:33 PM 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.