Advertisement
Blizzardo1

Start-Qemu.ps1

Aug 12th, 2019
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # QEMU Wrapper
  2. #
  3. # Copyright (c) Adonis Deliannis. All rights reserved.
  4. #
  5. # MIT License
  6. #
  7. # Permission is hereby granted, free of charge, to any person obtaining a copy
  8. # of this software and associated documentation files (the ""Software""), to deal
  9. # in the Software without restriction, including without limitation the rights
  10. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. # copies of the Software, and to permit persons to whom the Software is
  12. # furnished to do so, subject to the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be included in all
  15. # copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. # SOFTWARE.
  24.  
  25. # Note: This script can be ran anywhere on your system so as long as you specify exactly where your drive and cdrom images are
  26. param (
  27.         [parameter(Mandatory=$false)] [switch]$boot2cdrom = $false,
  28.         [parameter(Mandatory=$false)] [string] $cdrom_image = "",
  29.         [parameter(Mandatory=$true)] [string] $hdd_image = "",
  30.         [parameter(Mandatory=$false)] [int] $mem_size = 512,
  31.         [parameter(Mandatory=$false)] [switch] $g3,
  32.         [parameter(Mandatory=$false)] [switch] $machg3,
  33.         [parameter(Mandatory=$false)] [switch] $debug_instance,
  34.         [parameter(Mandatory=$false)] [switch] $do_all_audio,
  35.         [parameter(Mandatory=$false)] [switch] $use_net_device,
  36.         [parameter(Mandatory=$false)] [switch] $disable_auto_boot,
  37.         [parameter(Mandatory=$false)] [switch] $disable_network
  38. )
  39.  
  40. $argument_list = [ordered]@{}
  41.  
  42. # Drive Variable
  43. function Drive() {
  44.     param(
  45.         [parameter(Mandatory=$true)] [string] $file,
  46.         [parameter(Mandatory=$false)] [string] $format = "raw",
  47.         [parameter(Mandatory=$false)] [string] $type = "disk"
  48.        
  49.     )
  50.  
  51.     return "drive ""file=$file,format=$format,media=$type""";
  52. }
  53.  
  54. # Constructs the Argument list
  55. function Build_Argument_List() {
  56.     return ($argument_list.GetEnumerator() | % {"-$($_.Key)$(&{if($_.Value -ne $null) {"" $($_.Value)""} else {""""}})"}) -join ' '
  57. }
  58.  
  59. # Device Variable
  60. function Device() {
  61.     param(
  62.         [parameter(Mandatory=$true)] [string] $value
  63.     )
  64.     return "device $value"
  65. }
  66.  
  67. # PROM Environment variable
  68. function Prom_Env() {
  69.     param(
  70.         [parameter(Mandatory=$true)] [string] $key,
  71.         [parameter(Mandatory=$false)] [string] $value
  72.     )
  73.  
  74.     return "prom-env ""$key$(&{ if ($value -ne $null) {""=$value""} else {""""}})"""
  75. }
  76.  
  77. [Environment]::CurrentDirectory = $PWD.Path
  78. # Debug step to see why the working directory was located in System32.... The above line fixed it
  79. # 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))"
  80.  
  81. # Property List
  82. $bios="openbios-ppc"
  83. $biosdir="pc-bios"
  84. $mem=$mem_size
  85. $cpu= &{if($g3) {"G3"} else {"G4"}}
  86. $mach= &{ if($machg3) {"g3beige"} else {"mac99"}}
  87. $netopts="nic,model=rtl8139"
  88. $net_style="user,id=network01"
  89. $hdd=$hdd_image
  90. $hdfmt="raw"
  91. $cdrom=$cdrom_image
  92. $cdfmt="raw"
  93. $gmode="1280x720x32"
  94. $bootflag= &{if($boot2cdrom) {"d"} else {"c"}}
  95. $auto_boot_prom_env=&{if($disable_auto_boot) {"false"} else {"true"}}
  96. $vga_prom_env="true"
  97. $usb_dev="-device usb-mouse"
  98. $soundhw = &{if($do_all_audio) {"all"} else {"hda"}}
  99.  
  100. # I can't seem to get this to work.
  101. $computer_specs = "boot-command=dev / \"" PowerMac1,1\"" encode-string \"" model\"" property \"" PowerMac1,1\"" encode-string \"" compatible\"" property boot"
  102.  
  103. # Standard run of the mill arguments
  104. $argument_list.Add("bios", $bios)
  105. $argument_list.Add("L", $biosdir)
  106. $argument_list.Add("boot", $bootflag)
  107. $argument_list.Add("g", $gmode)
  108. $argument_list.Add("m", $mem)
  109. $argument_list.Add("machine", $mach)
  110. $argument_list.Add("cpu", $cpu)
  111. # SDL because it's better than the other options at this point
  112. $argument_list.Add("sdl", $null)
  113.  
  114. # Disable the network if it's not absolutely needed, else add device specs
  115. if($disable_network) { $argument_list.Add("net", "none") } else {
  116.     if($use_net_device) {
  117.         # Not part of the Script's property list, but should probably be considered the _alt of net_style and netops
  118.         $argument_list.Add("netdev", "user,id=network01")
  119.         $argument_list.Add("device", "sungem,netdev=network01")
  120.     } else {
  121.         $argument_list.Add("net", $net_style)
  122.         $argument_list.Add("net", $netopts)
  123.     }
  124. }
  125.  
  126. # Check to see if we have a CD loaded, if so, let's check if we should boot to it first
  127. if($cdrom_image -ne "") {
  128.     if ($bootflag -eq "d") {
  129.         $argument_list.Add($(Drive $cdrom $cdfmt "cdrom"), $null)
  130.         $argument_list.Add($(Drive $hdd $hdfmt), $null)
  131.     } elseif ($bootflag -eq "c") {
  132.         $argument_list.Add($(Drive $hdd $hdfmt), $null)
  133.         $argument_list.Add($(Drive $cdrom $cdfmt "cdrom"), $null)
  134.     }
  135. } else {
  136.     $argument_list.Add($(Drive $hdd $hdfmt))
  137. }
  138.  
  139. $argument_list.Add($(Prom_Env "vga-ndrv?" "true"), $null)
  140. $argument_list.Add($(Prom_Env "auto-boot?" $auto_boot_prom_env), $null)
  141. $argument_list.Add("soundhw", $soundhw)
  142. $argument_list.Add("usb", $null)
  143. $argument_list.Add($(Device "usb-mouse"), $null)
  144.  
  145. # I can't seem to get this to work.
  146. # $argument_list.Add($(Prom_Env $computer_specs), $null)
  147.  
  148. # Finally, parse those Arguments!
  149. $arguments = Build_Argument_List
  150.  
  151. # Construct the Process
  152. $exec = new-object System.Diagnostics.Process
  153. $exec.StartInfo = New-Object System.Diagnostics.ProcessStartInfo
  154. $exec.StartInfo.FileName = "qemu-system-ppc.exe"
  155. $exec.StartInfo.Arguments = $arguments
  156. $exec.StartInfo.RedirectStandardError = $true
  157. $exec.StartInfo.RedirectStandardInput = $true
  158. $exec.StartInfo.RedirectStandardOutput = $true
  159. $exec.StartInfo.UseShellExecute = $false
  160.  
  161. # Prints only the command and its arguments for, visual reasons... but could use some more debug things
  162. if($debug_instance) {
  163.     Write-Host "$($exec.StartInfo.FileName) $($exec.StartInfo.Arguments)"
  164. }
  165.  
  166. # Start the process
  167. $started = $exec.Start()
  168.  
  169. # Silently weep while it tries to work but it ends up just failing
  170. $exec.WaitForExit()
  171.  
  172. # Print what we generated in case we need to send this off to the developer and or forums
  173. Write-Error $exec.StandardError.ReadToEnd()
  174. Write-Output $exec.StandardOutput.ReadToEnd()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement