Skip to content

Instantly share code, notes, and snippets.

@milnak
Created November 22, 2023 23:08
Show Gist options
  • Save milnak/05cb7d8ffb30477af006bc425529cb84 to your computer and use it in GitHub Desktop.
Save milnak/05cb7d8ffb30477af006bc425529cb84 to your computer and use it in GitHub Desktop.
Script to verify PinHP Roms and dependent BIOS and samples. #pinhp
# Script to verify PinHP Roms and dependent BIOS and samples.
param (
# Path to mame.exe
[string]$MamePath = '.',
# Path to rpi2jamma folder which contains "roms_advmame" and "samples_advmame".
[string]$RpiJammaPath = 'rpi2jamma'
)
function Verify-MameExe {
Param(
[Parameter(Mandatory)][string]$MamePath,
[Parameter(Mandatory)][string]$ExpectedVersion
)
$mameExe = Join-Path $MamePath 'mame.exe'
try {
$mame = & $mameExe
}
catch {
return $false
}
return ($mame[0] -match "v$ExpectedVersion")
}
function Verify-Roms {
Param(
[Parameter(Mandatory)][string]$MamePath,
[Parameter(Mandatory)][string]$RomsFolder,
[Parameter(Mandatory)][string]$SamplesFolder,
[Parameter(Mandatory)][string]$BiosFolder
)
$mameExe = Join-Path $MamePath 'mame.exe'
# Hash from path to incomplete ROM to MAME output
$incorrectROMs = @{}
# Hash from path to missing sample to MAME output
$missingSamples = @{}
# hash from path where BIOS should be placed to bios name
$missingBIOS = @{}
$roms = Get-ChildItem $RomsFolder -Recurse -File -Filter '*.zip' | Sort-Object BaseName
$index = 0
foreach ($rom in $roms) {
$directoryName = $rom.DirectoryName
$romName = $rom.BaseName
Write-Progress `
-Activity 'Scanning ROMs' `
-Status $romName `
-PercentComplete ((($index++) / $roms.Count) * 100)
$romPaths = ($directoryName, $BiosFolder) -join ';'
$result = & $mameExe -rompath $romPaths -verifyroms $romName 2>$null
if ($result -match 'is bad') {
$incorrectRomFile = $null
$missingBiosFile = $null
if ($result -match 'NO GOOD DUMP KNOWN') {
$incorrectRomFile = $rom.FullName
}
elseif ($result -match 'sfix.sfx') {
# NeoGeo BIOS
$missingBiosFile = 'neogeo.zip'
}
elseif ($result -match '999a01.7e') {
# Konami System GV BIOS
$missingBiosFile = 'konamigv.zip'
}
elseif ($result -match '300a01.34k') {
# Konami System GX BIOS
$missingBiosFile = 'konamigx.zip'
}
elseif ($result -match 'mx27l1000.u14') {
# Crystal System BIOS
$missingBiosFile = 'crysbios.zip'
}
elseif ($result -match 'ep15294.ic2') {
# Sega Mega Play BIOS
$missingBiosFile = 'megaplay.zip'
}
elseif ($result -match 'sknsj1.u10') {
# Super Kaneko Nova System BIOS
$missingBiosFile = 'skns.zip'
}
elseif ($result -match 'pgm_p01s.rom') {
# PGM (Polygame Master) System BIOS
$missingBiosFile = 'pgm.zip'
}
else {
# General "is bad" MAME output.
$incorrectRomFile = $rom.FullName
}
if ($incorrectRomFile) {
$incorrectROMs[$incorrectRomFile] = $result
}
if ($missingBiosFile) {
$missingBIOS[$directoryName] = $missingBiosFile
}
}
# Show missing samples
$result = & $mameExe -samplepath $SamplesFolder -verifysamples $romName 2>$null
if ($result -match 'not found!') {
$missingSamples[$rom.FullName] = $result
}
}
if ($incorrectROMs.Count -ne 0) {
'Incorrect ROMS:'
$incorrectROMs | Format-List
''
}
if ($missingSamples.Count -ne 0) {
'Missing samples:'
$missingSamples | Format-List
''
}
if ($missingBIOS.Count -ne 0) {
'Missing BIOS files:'
$missingBIOS | Format-Table -AutoSize
}
}
#
# main
#
if (-not (Verify-MameExe -MamePath $MamePath -ExpectedVersion '0.106')) {
Write-Warning 'mame.exe not found or wrong version.'
'Download "mame0106b.exe" from https://www.mamedev.org/oldrel.html'
'and specify path with -MamePath argument.'
return
}
Verify-Roms `
-MamePath $MamePath `
-RomsFolder (Join-Path $RpiJammaPath 'roms_advmame') `
-SamplesFolder (Join-Path $RpiJammaPath 'samples_advmame') `
-BiosFolder (Join-Path $RpiJammaPath 'bios_advmame')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment