Skip to content
This repository has been archived by the owner on Aug 6, 2020. It is now read-only.

Commit

Permalink
Added controller options
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBrainAFK committed Dec 23, 2018
1 parent 1223bbf commit 685db3f
Show file tree
Hide file tree
Showing 10 changed files with 446 additions and 131 deletions.
8 changes: 4 additions & 4 deletions XQEMU-GUI/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup>
</configuration>
24 changes: 18 additions & 6 deletions XQEMU-GUI/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 105 additions & 22 deletions XQEMU-GUI/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@
using System.Windows.Forms;
using Nini.Config;

namespace XQEMU_GUI
namespace xqemu_gui
{
public partial class Main : Form
{
private IniConfigSource configSource;
private IConfig config;
private IConfig configGeneral;
private IConfig configController;
string selectedISO = "";
bool skipAnim = false;

public Main()
{
InitializeComponent();

LoadConfigs();

selectedISO = config.GetString("Recent_ISO", "");
if (selectedISO.Length > 0) lblLoaded.Text = selectedISO;
selectedISO = configGeneral.GetString("Recent_ISO", "");
lblLoaded.Text = selectedISO.Length > 0 ? selectedISO : "No ISO selected. This will launch the XBox Dashboard.";

skipAnim = configGeneral.GetBoolean("Skip_Animation", false);
menuSkipAnimation.Checked = skipAnim;
}

private void MenuOptions_Click(object sender, EventArgs e)
Expand All @@ -40,7 +45,7 @@ private void Form_Close(object sender, FormClosedEventArgs e)

private void MenuOpenFile_Click(object sender, EventArgs e)
{
string tempGamesFolder = config.GetString("Games_Folder", "");
string tempGamesFolder = configGeneral.GetString("Games_Folder", "");

openISODialog.InitialDirectory = selectedISO.Length > 0
? Path.GetDirectoryName(selectedISO)
Expand All @@ -52,7 +57,7 @@ private void MenuOpenFile_Click(object sender, EventArgs e)
{
selectedISO = openISODialog.FileName;
lblLoaded.Text = selectedISO;
config.Set("Recent_ISO", selectedISO);
configGeneral.Set("Recent_ISO", selectedISO);
configSource.Save();
}
}
Expand All @@ -68,27 +73,54 @@ private void LoadConfigs()

if (configSource.Configs["default"] != null)
{
config = configSource.Configs["default"];
configGeneral = configSource.Configs["default"];
}
else
{
SetDefaultGeneral(configSource);
}

if (configSource.Configs["controller"] != null)
{
configController = configSource.Configs["controller"];
}
else
{
SetDefault(configSource);
SetDefaultController(configSource);
}
}

private void SetDefault(IniConfigSource configSource)
private void SetDefaultGeneral(IniConfigSource configSource)
{
if (configSource.Configs["default"] == null) configSource.AddConfig("default");

config = configSource.Configs["default"];
configGeneral = configSource.Configs["default"];

config.Set("Recent_ISO", "");
configGeneral.Set("Recent_ISO", "");
configGeneral.Set("Skip_Animation", false);
configGeneral.Set("Games_Folder", "");
configGeneral.Set("MCPX", "");
configGeneral.Set("BIOS", "");
configGeneral.Set("HDD", "");
configSource.Save();
}

private void SetDefaultController(IniConfigSource configSource)
{
if (configSource.Configs["controller"] == null) configSource.AddConfig("controller");

configController = configSource.Configs["controller"];

configController.Set("Controller1", 1);
configController.Set("Controller2", 0);
configController.Set("Controller3", 0);
configController.Set("Controller4", 0);
configSource.Save();
}

private void BtnStart_Click(object sender, EventArgs e)
{
string MCPX = config.GetString("MCPX", "");
string MCPX = configGeneral.GetString("MCPX", "");
if (MCPX.Length == 0)
{
MessageBox.Show(
Expand All @@ -99,7 +131,7 @@ private void BtnStart_Click(object sender, EventArgs e)
return;
}

string BIOS = config.GetString("BIOS", "");
string BIOS = configGeneral.GetString("BIOS", "");
if (BIOS.Length == 0)
{
MessageBox.Show(
Expand All @@ -110,7 +142,7 @@ private void BtnStart_Click(object sender, EventArgs e)
return;
}

string HDD = config.GetString("HDD", "");
string HDD = configGeneral.GetString("HDD", "");
if (HDD.Length == 0)
{
MessageBox.Show(
Expand All @@ -121,27 +153,25 @@ private void BtnStart_Click(object sender, EventArgs e)
return;
}

bool launchDash = false;
if (selectedISO.Length == 0)
{
MessageBox.Show(
"No ISO seleced. Please open one!",
"No ISO selected",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
launchDash = true;
}

string skipAnims = menuSkipAnimation.Checked ? ",short-animation" : "";

string usb = BuildUSBInput();

Process xqemu = new Process();
xqemu.StartInfo.FileName = @".\xqemu.exe";
xqemu.StartInfo.Arguments = " -cpu pentium3"
+ $" -machine xbox,bootrom={MCPX.Replace(@"\", @"\\")}{skipAnims}"
+ " -m 64"
+ $" -bios \"{BIOS.Replace(@"\", @"\\")}\""
+ $" -drive index=0,media=disk,file={HDD.Replace(@"\", @"\\")},locked"
+ $" -drive index=1,media=cdrom,file={selectedISO.Replace(@"\", @"\\")}"
+ " -usb -device usb-xbox-gamepad";
+ " -drive index=1,media=cdrom," + ( launchDash ? "" : $"file={selectedISO.Replace(@"\", @"\\")}" )
+ $" -usb{usb}";
xqemu.Start();
}

Expand All @@ -164,5 +194,58 @@ private void Main_Shown(object sender, EventArgs e)
}
}
}

private void MenuSkipAnimation_Click(object sender, EventArgs e)
{
configGeneral.Set("Skip_Animation", menuSkipAnimation.Checked);
configSource.Save();
}

private string BuildUSBInput()
{
string build = "";
string[] magicTable = { "", "usb-host", "usb-xbox-gamepad-sdl", "usb-xbox-gamepad" };

int[] controllers = {
configController.GetInt("Controller3", 0) > 3 ? 0 : configController.GetInt("Controller3", 0),
configController.GetInt("Controller4", 0) > 3 ? 0 : configController.GetInt("Controller4", 0),
configController.GetInt("Controller1", 1) > 3 ? 1 : configController.GetInt("Controller1", 1),
configController.GetInt("Controller2", 0) > 3 ? 0 : configController.GetInt("Controller2", 0),
};

int sdlIndex = 0;
int port = 0;

foreach (int controller in controllers)
{
++port;
switch (controller)
{
case 1:
continue; //build support for usb passthrough of original xbox controller
case 2:
build += $" -device {magicTable[controller]},index={sdlIndex},port={port}";
++sdlIndex;
break;
case 3:
build += $" -device {magicTable[controller]},port={port}";
break;
default:
continue;
}
}

if (build == "") build += "-device usb-xbox-gamepad,port=3";

return build;
}

private void EjectISOToolStripMenuItem_Click(object sender, EventArgs e)
{
selectedISO = "";
lblLoaded.Text = "No ISO selected. This will launch the XBox Dashboard.";
configGeneral.Set("Recent_ISO", selectedISO);
configSource.Save();
}
}
}
Loading

0 comments on commit 685db3f

Please sign in to comment.