# QEMU Wrapper # # Copyright (c) Adonis Deliannis. All rights reserved. # # MIT License # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the ""Software""), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # Note: This script can be ran anywhere on your system so as long as you specify exactly where your drive and cdrom images are param ( [parameter(Mandatory=$false)] [switch]$boot2cdrom = $false, [parameter(Mandatory=$false)] [string] $cdrom_image = "", [parameter(Mandatory=$true)] [string] $hdd_image = "", [parameter(Mandatory=$false)] [int] $mem_size = 512, [parameter(Mandatory=$false)] [switch] $g3, [parameter(Mandatory=$false)] [switch] $machg3, [parameter(Mandatory=$false)] [switch] $debug_instance, [parameter(Mandatory=$false)] [switch] $do_all_audio, [parameter(Mandatory=$false)] [switch] $use_net_device, [parameter(Mandatory=$false)] [switch] $disable_auto_boot, [parameter(Mandatory=$false)] [switch] $disable_network ) $argument_list = [ordered]@{} # Drive Variable function Drive() { param( [parameter(Mandatory=$true)] [string] $file, [parameter(Mandatory=$false)] [string] $format = "raw", [parameter(Mandatory=$false)] [string] $type = "disk" ) return "drive ""file=$file,format=$format,media=$type"""; } # Constructs the Argument list function Build_Argument_List() { return ($argument_list.GetEnumerator() | % {"-$($_.Key)$(&{if($_.Value -ne $null) {"" $($_.Value)""} else {""""}})"}) -join ' ' } # Device Variable function Device() { param( [parameter(Mandatory=$true)] [string] $value ) return "device $value" } # PROM Environment variable function Prom_Env() { param( [parameter(Mandatory=$true)] [string] $key, [parameter(Mandatory=$false)] [string] $value ) return "prom-env ""$key$(&{ if ($value -ne $null) {""=$value""} else {""""}})""" } [Environment]::CurrentDirectory = $PWD.Path # Debug step to see why the working directory was located in System32.... The above line fixed it # Write-Host "Environment's Directory is ""$([Environment]::CurrentDirectory)"", the Working Directory ""$($PWD.Path)""; But $hdd_image is located in this directory, but resolves to $([System.IO.Path]::GetFullPath($hdd_image))" # Property List $bios="openbios-ppc" $biosdir="pc-bios" $mem=$mem_size $cpu= &{if($g3) {"G3"} else {"G4"}} $mach= &{ if($machg3) {"g3beige"} else {"mac99"}} $netopts="nic,model=rtl8139" $net_style="user,id=network01" $hdd=$hdd_image $hdfmt="raw" $cdrom=$cdrom_image $cdfmt="raw" $gmode="1280x720x32" $bootflag= &{if($boot2cdrom) {"d"} else {"c"}} $auto_boot_prom_env=&{if($disable_auto_boot) {"false"} else {"true"}} $vga_prom_env="true" $usb_dev="-device usb-mouse" $soundhw = &{if($do_all_audio) {"all"} else {"hda"}} # I can't seem to get this to work. $computer_specs = "boot-command=dev / \"" PowerMac1,1\"" encode-string \"" model\"" property \"" PowerMac1,1\"" encode-string \"" compatible\"" property boot" # Standard run of the mill arguments $argument_list.Add("bios", $bios) $argument_list.Add("L", $biosdir) $argument_list.Add("boot", $bootflag) $argument_list.Add("g", $gmode) $argument_list.Add("m", $mem) $argument_list.Add("machine", $mach) $argument_list.Add("cpu", $cpu) # SDL because it's better than the other options at this point $argument_list.Add("sdl", $null) # Disable the network if it's not absolutely needed, else add device specs if($disable_network) { $argument_list.Add("net", "none") } else { if($use_net_device) { # Not part of the Script's property list, but should probably be considered the _alt of net_style and netops $argument_list.Add("netdev", "user,id=network01") $argument_list.Add("device", "sungem,netdev=network01") } else { $argument_list.Add("net", $net_style) $argument_list.Add("net", $netopts) } } # Check to see if we have a CD loaded, if so, let's check if we should boot to it first if($cdrom_image -ne "") { if ($bootflag -eq "d") { $argument_list.Add($(Drive $cdrom $cdfmt "cdrom"), $null) $argument_list.Add($(Drive $hdd $hdfmt), $null) } elseif ($bootflag -eq "c") { $argument_list.Add($(Drive $hdd $hdfmt), $null) $argument_list.Add($(Drive $cdrom $cdfmt "cdrom"), $null) } } else { $argument_list.Add($(Drive $hdd $hdfmt)) } $argument_list.Add($(Prom_Env "vga-ndrv?" "true"), $null) $argument_list.Add($(Prom_Env "auto-boot?" $auto_boot_prom_env), $null) $argument_list.Add("soundhw", $soundhw) $argument_list.Add("usb", $null) $argument_list.Add($(Device "usb-mouse"), $null) # I can't seem to get this to work. # $argument_list.Add($(Prom_Env $computer_specs), $null) # Finally, parse those Arguments! $arguments = Build_Argument_List # Construct the Process $exec = new-object System.Diagnostics.Process $exec.StartInfo = New-Object System.Diagnostics.ProcessStartInfo $exec.StartInfo.FileName = "qemu-system-ppc.exe" $exec.StartInfo.Arguments = $arguments $exec.StartInfo.RedirectStandardError = $true $exec.StartInfo.RedirectStandardInput = $true $exec.StartInfo.RedirectStandardOutput = $true $exec.StartInfo.UseShellExecute = $false # Prints only the command and its arguments for, visual reasons... but could use some more debug things if($debug_instance) { Write-Host "$($exec.StartInfo.FileName) $($exec.StartInfo.Arguments)" } # Start the process $started = $exec.Start() # Silently weep while it tries to work but it ends up just failing $exec.WaitForExit() # Print what we generated in case we need to send this off to the developer and or forums Write-Error $exec.StandardError.ReadToEnd() Write-Output $exec.StandardOutput.ReadToEnd()