Last active
March 28, 2025 19:11
-
-
Save milnak/e77335e0e1a88664a820966c342eef00 to your computer and use it in GitHub Desktop.
List installed MAME ROMs, suitable for filtering.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| List installed MAME ROMs, suitable for filtering. | |
| Prerequisite: MAME DAT file from "mame.exe -listxml", e.g. | |
| advmame106.xml file from "MAME config files" at https://MAME.github.io/docs/download.html | |
| .EXAMPLE | |
| Generate table of all ROMs in a folder | |
| # Note: Doesn't include non-runnable ROMs. | |
| $roms = .\List-MAME-Roms.ps1 -DatFile 'advmame106.xml' -RomFolder 'D:\temp\pinhp-roms\' | |
| $roms ` | |
| | Sort-Object Description ` | |
| | Format-Table ` | |
| @{Name='Description';Expression={$_.Description.Substring(0,[Math]::Min($_.Description.Length,40))}},` | |
| @{Name='Manufacturer';Expression={$_.Manufacturer.Substring(0,[Math]::Min($_.Manufacturer.Length,24))}},` | |
| Year,` | |
| Name | |
| .EXAMPLE | |
| Filter by: | |
| * runnable: yes | |
| * cloneof: <empty> | |
| * buttons: <= 6 | |
| * orientation: horizontal | |
| * control: joystick(s) | |
| (doublejoy2way, doublejoy8way, joy2way, joy8way, vdoublejoy2way, vjoy2way, stick) | |
| $roms ` | |
| | Sort-Object -Property Description ` | |
| | Where-Object { ` | |
| $_.cloneof -eq $null -and ` | |
| $_.buttons -le 6 -and ` | |
| $_.orientation -eq 'horizontal' -and ` | |
| ($control -eq $null -or $_.control -like '*joy*' -or $_.control -eq 'stick') | |
| } ` | |
| | Format-Table @{Name='Description';Expression={$_.Description.Substring(0,[Math]::Min($_.Description.Length,40))}},@{Name='Manufacturer';Expression={$_.Manufacturer.Substring(0,[Math]::Min($_.Manufacturer.Length,25))}},Year,Name,Control | |
| .EXAMPLE | |
| List all required BIOS | |
| $roms | Where-Object RomOf | Select-Object -Unique RomOf | |
| .EXAMPLE | |
| List all installed ROMs that require more than 5 buttons: | |
| $roms | Where-Object Buttons -gt 5 | Select-Object Name,Buttons | |
| .EXAMPLE | |
| List path and parent of all installed ROMs that are clones: | |
| $roms | Where-Object CloneOf -ne $null | Select-Object Name,CloneOf | |
| #> | |
| Param( | |
| # Path to MAME ROMs. | |
| [string]$RomFolder = 'roms', | |
| # MAME "listxml" file. | |
| [string]$DatFile = 'advmame106.xml' | |
| ) | |
| if (-not (Test-Path -LiteralPath $RomFolder -PathType Container)) { | |
| Write-Warning "RomFolder not found: $RomFolder" | |
| return | |
| } | |
| # Build up hash of rom properties from advmame.xml | |
| # Not including non-runnable ROMS. | |
| $advmame = [xml](Get-Content($DatFile) -ErrorAction Stop) | |
| $hash = @{} | |
| $advmame.mame.game | |
| | Where-Object { $_.runnable -eq 'yes' } | |
| | ForEach-Object { | |
| $hash[$_.name] = [PSCustomObject]@{ | |
| Name = $_.name | |
| CloneOf = $_.cloneof | |
| # RomOf is required BIOS | |
| RomOf = $_.romof | |
| Description = $_.Description | |
| Manufacturer = $_.Manufacturer | |
| Buttons = $_.input.buttons | |
| Control = $_.input.control | |
| Players = $_.input.players | |
| Orientation = $_.video.orientation | |
| Resolution = '{0}x{1}' -f $_.video.width, $_.video.height | |
| Year = $_.year | |
| Driver = $_.driver | |
| } | |
| } | |
| # Iterate rom folder, and list properties for each rom | |
| Get-ChildItem $RomFolder -File -Filter '*.zip' | ForEach-Object { | |
| $info = $hash[$_.BaseName] | |
| if ($info) { | |
| # Show warning if driver has issues. | |
| if ($info.Driver.status -ne 'good') { | |
| $attribs = $info.Driver.Attributes ` | |
| | Where-Object { $_.Name -notin 'status', 'palettesize', 'savestate' -and $_.Value -ne 'good' } ` | |
| | ForEach-Object { | |
| '{0}: {1}' -f $_.Name, $_.Value | |
| } | |
| Write-Warning ('Driver issue: {0} ({1}) {{ {2} }}' -f $info.Name, $info.Description, ($attribs -join '; ')) | |
| } | |
| $info | |
| } | |
| else { | |
| Write-Warning "Unknown ROM: $_" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment