Skip to content

Commit c5e4ac3

Browse files
author
Juan Segura
committed
Advanced settings working (beta)
1 parent 981cc8c commit c5e4ac3

File tree

4 files changed

+117
-83
lines changed

4 files changed

+117
-83
lines changed

ZXBStudio/BuildSystem/ZXProjectBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ private static bool PostBuild(bool debug, string path, ZXProgram CompiledProgram
753753
}
754754

755755

756-
private static bool ExecuteFile(string preBuildValue, string[] parameters, string workingPath, TextWriter outLog)
756+
public static bool ExecuteFile(string preBuildValue, string[] parameters, string workingPath, TextWriter outLog)
757757
{
758758
try
759759
{

ZXBStudio/Dialogs/ZXBuildSettingsDialog.axaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,14 @@
9393
<Button Classes="dialog" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Name="btnPostbuild">...</Button>
9494
</Grid>
9595

96-
<CheckBox Name="chkEmulator" Grid.Row="5" Grid.Column="6" Margin="0,8,0,0">Launch external emulator</CheckBox>
96+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
97+
<CheckBox Name="chkEmulator" Grid.Row="5" Grid.Column="6" Margin="0,8,4,0">Launch external emulator (program or bash to launch)</CheckBox>
98+
<svg:Svg Path="/Svg/White/circle-info-solid.svg" Width="16" ToolTip.Tip="Parameters: %1=project path, %2=compiled file without extension"></svg:Svg>
99+
</StackPanel>
97100
<Grid Name="grdEmulator" ColumnDefinitions="*,Auto" RowDefinitions="Auto,Auto" IsEnabled="False" Margin="20,4,8,8">
98101
<TextBox Name="txtEmulator" Grid.Row="1" Classes="dialogfw"/>
99102
<Button Classes="dialog" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Name="btnEmulator">...</Button>
100103
</Grid>
101-
102104
</StackPanel>
103105
</Grid>
104106

ZXBStudio/Dialogs/ZXBuildSettingsDialog.axaml.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,20 @@ private async void BtnPostbuild_Tapped(object? sender, Avalonia.Input.TappedEven
120120
private async void BtnEmulator_Tapped(object? sender, Avalonia.Input.TappedEventArgs e)
121121
{
122122
var fileTypes = new FilePickerFileType[3];
123-
fileTypes[0] = new FilePickerFileType("Executable files (*.exe)") { Patterns = new[] { "*.exe" } };
124-
fileTypes[1] = new FilePickerFileType("Batch/Shell files (*.bat, *.sh)") { Patterns = new[] { "*.bat", "*.sh" } };
123+
fileTypes[0] = new FilePickerFileType("Batch/Shell files (*.bat, *.sh)") { Patterns = new[] { "*.bat", "*.sh" } };
124+
fileTypes[1] = new FilePickerFileType("Executable files (*.exe)") { Patterns = new[] { "*.exe" } };
125125
fileTypes[2] = new FilePickerFileType("All files (*.*)") { Patterns = new[] { "*", "*.*" } };
126126

127-
var select = await StorageProvider.SaveFilePickerAsync(new Avalonia.Platform.Storage.FilePickerSaveOptions
127+
var select = await StorageProvider.OpenFilePickerAsync(new Avalonia.Platform.Storage.FilePickerOpenOptions
128128
{
129-
ShowOverwritePrompt = true,
130-
FileTypeChoices = fileTypes,
131-
Title = "Select prebuild file...",
129+
FileTypeFilter = fileTypes.ToArray(),
130+
Title = "Select emulator launcher file...",
132131
});
133132

134-
if (select != null)
133+
if (select != null && select.Count() != 0)
135134
{
136-
txtEmulator.Text = Path.GetFullPath(select.Path.LocalPath);
135+
var fileName = Path.GetFullPath(select[0].Path.LocalPath);
136+
txtEmulator.Text = fileName;
137137
}
138138
}
139139

@@ -219,14 +219,7 @@ private void UpdateUI()
219219
chkPostbuild.IsChecked = _settings.PostBuild;
220220
txtPostbuild.Text = _settings.PostBuildValue.ToStringNoNull();
221221
chkEmulator.IsChecked = _settings.ExternalEmulator;
222-
if (_settings.ExternalEmulator)
223-
{
224-
txtEmulator.Text = _settings.ExternalEmuladorValue.ToStringNoNull();
225-
}
226-
else
227-
{
228-
txtEmulator.Text = "Use the emulator with integrated debugger";
229-
}
222+
txtEmulator.Text = _settings.ExternalEmuladorValue.ToStringNoNull();
230223
}
231224
else
232225
{
@@ -252,7 +245,7 @@ private void UpdateUI()
252245
chkPostbuild.IsChecked = false;
253246
txtPostbuild.Text = "";
254247
chkEmulator.IsChecked = false;
255-
txtEmulator.Text = "Use the emulator with integrated debugger";
248+
txtEmulator.Text = "";
256249
}
257250
UpdateCustomBuilder();
258251
}

ZXBStudio/MainWindow.axaml.cs

Lines changed: 102 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public MainWindow()
302302
ZXLayoutPersister.RestoreLayout(grdMain, dockLeft, dockRight, dockBottom, new[] { _playerDock });
303303
}
304304

305-
305+
306306
private void OpenAbout(object? sender, RoutedEventArgs e)
307307
{
308308
ZXAboutDialog zXAboutDialog = new ZXAboutDialog();
@@ -1400,10 +1400,13 @@ private async void Build(object? sender, Avalonia.Interactivity.RoutedEventArgs
14001400
EmulatorInfo.CanDebug = false;
14011401
EmulatorInfo.CanRun = false;
14021402
BlockEditors();
1403+
14031404
_ = Task.Run(() =>
14041405
{
14051406
if (peExplorer.RootPath != null)
1407+
{
14061408
ZXProjectBuilder.Build(outLog.Writer);
1409+
}
14071410

14081411
Dispatcher.UIThread.InvokeAsync(() =>
14091412
{
@@ -1413,6 +1416,8 @@ private async void Build(object? sender, Avalonia.Interactivity.RoutedEventArgs
14131416
});
14141417
});
14151418
}
1419+
1420+
14161421
private async void BuildAndRun(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
14171422
{
14181423
if (string.IsNullOrWhiteSpace(ZXOptions.Current.ZxbcPath) || string.IsNullOrWhiteSpace(ZXOptions.Current.ZxbasmPath))
@@ -1480,45 +1485,56 @@ private async void BuildAndRun(object? sender, Avalonia.Interactivity.RoutedEven
14801485
{
14811486
var emulatorName = Path.GetFileNameWithoutExtension(emulatorPath);
14821487
var nextDrive = Path.Combine(project.ProjectPath, "nextdrive");
1483-
switch (emulatorName.ToLower())
1488+
1489+
if (settings.ExternalEmulator)
14841490
{
1485-
case "cspect":
1491+
outLog.Writer.WriteLine($"Custom emulator launcher: {settings.ExternalEmuladorValue}");
1492+
if (!ZXProjectBuilder.ExecuteFile(settings.ExternalEmuladorValue, new string[]
14861493
{
1487-
outLog.Writer.WriteLine("Launching CSpect...");
1488-
Process process = new Process();
1489-
process.StartInfo.FileName = emulatorPath;
1490-
process.StartInfo.Arguments = string.Format(
1491-
"-zxnext -tv -w3 -brk -r -mmc=\"{0}\" \"{1}\"",
1492-
nextDrive,
1493-
Path.Combine(nextDrive, Path.GetFileNameWithoutExtension(settings.MainFile) + ".nex"));
1494-
process.StartInfo.WorkingDirectory = project.ProjectPath;
1495-
process.StartInfo.UseShellExecute = true;
1496-
process.StartInfo.CreateNoWindow = false;
1497-
outLog.Writer.WriteLine(process.StartInfo.FileName + " " + process.StartInfo.Arguments);
1498-
process.Start();
1499-
process.WaitForExit();
1500-
}
1501-
break;
1502-
case "zesarux":
1503-
{
1504-
outLog.Writer.WriteLine("Launching ZEsarUX...");
1505-
Process process = new Process();
1506-
process.StartInfo.FileName = emulatorPath;
1507-
process.StartInfo.Arguments = string.Format(
1508-
"--noconfigfile --zoom 1 --machine TBBlue --realvideo --enabletimexvideo --tbblue-fast-boot-mode --enable-esxdos-handler --esxdos-root-dir \"{0}\" \"{1}\" --snap-no-change-machine",
1509-
nextDrive,
1510-
Path.Combine(nextDrive, Path.GetFileNameWithoutExtension(settings.MainFile) + ".nex"));
1511-
process.StartInfo.WorkingDirectory = Path.GetDirectoryName(emulatorPath);
1512-
process.StartInfo.UseShellExecute = true;
1513-
process.StartInfo.CreateNoWindow = false;
1514-
outLog.Writer.WriteLine(process.StartInfo.FileName + " " + process.StartInfo.Arguments);
1515-
process.Start();
1516-
process.WaitForExit();
1517-
}
1518-
break;
1519-
default:
1520-
errorMsg = "There is no valid emulator configured for Next. Please configure an emulator (CSpect or ZEsarUX) from the Tools -> Options menu.";
1521-
break;
1494+
nextDrive,
1495+
Path.GetFileNameWithoutExtension(settings.MainFile)
1496+
},
1497+
project.ProjectPath,
1498+
outLog.Writer))
1499+
{
1500+
errorMsg = "Error executing custom emulator launcher.";
1501+
}
1502+
}
1503+
else if (emulatorName.ToLower() == "cspect")
1504+
{
1505+
outLog.Writer.WriteLine("Launching CSpect...");
1506+
Process process = new Process();
1507+
process.StartInfo.FileName = emulatorPath;
1508+
process.StartInfo.Arguments = string.Format(
1509+
"-zxnext -tv -w3 -brk -r -mmc=\"{0}\" \"{1}\"",
1510+
nextDrive,
1511+
Path.Combine(nextDrive, Path.GetFileNameWithoutExtension(settings.MainFile) + ".nex"));
1512+
process.StartInfo.WorkingDirectory = project.ProjectPath;
1513+
process.StartInfo.UseShellExecute = true;
1514+
process.StartInfo.CreateNoWindow = false;
1515+
outLog.Writer.WriteLine(process.StartInfo.FileName + " " + process.StartInfo.Arguments);
1516+
process.Start();
1517+
process.WaitForExit();
1518+
}
1519+
else if (emulatorName.ToLower() == "zesarux")
1520+
{
1521+
outLog.Writer.WriteLine("Launching ZEsarUX...");
1522+
Process process = new Process();
1523+
process.StartInfo.FileName = emulatorPath;
1524+
process.StartInfo.Arguments = string.Format(
1525+
"--noconfigfile --zoom 1 --machine TBBlue --realvideo --enabletimexvideo --tbblue-fast-boot-mode --enable-esxdos-handler --esxdos-root-dir \"{0}\" \"{1}\" --snap-no-change-machine",
1526+
nextDrive,
1527+
Path.Combine(nextDrive, Path.GetFileNameWithoutExtension(settings.MainFile) + ".nex"));
1528+
process.StartInfo.WorkingDirectory = Path.GetDirectoryName(emulatorPath);
1529+
process.StartInfo.UseShellExecute = true;
1530+
process.StartInfo.CreateNoWindow = false;
1531+
outLog.Writer.WriteLine(process.StartInfo.FileName + " " + process.StartInfo.Arguments);
1532+
process.Start();
1533+
process.WaitForExit();
1534+
}
1535+
else
1536+
{
1537+
errorMsg = "There is no valid emulator configured for Next. Please configure an emulator (CSpect or ZEsarUX) from the Tools -> Options menu.";
15221538
}
15231539
}
15241540
catch (Exception ex)
@@ -1541,38 +1557,61 @@ private async void BuildAndRun(object? sender, Avalonia.Interactivity.RoutedEven
15411557
else if (program != null)
15421558
{
15431559
// No Next mode :)
1544-
loadedProgram = program;
1545-
var disas = openDocuments.FirstOrDefault(e => e.DocumentPath == ZXConstants.DISASSEMBLY_DOC) as ZXTextEditor;
1546-
1547-
Dispatcher.UIThread.InvokeAsync(async () =>
1560+
if (settings.ExternalEmulator)
15481561
{
1549-
if (disas != null)
1562+
outLog.Writer.WriteLine($"Custom emulator launcher: {settings.ExternalEmuladorValue}");
1563+
if (!ZXProjectBuilder.ExecuteFile(settings.ExternalEmuladorValue, new string[]
1564+
{
1565+
project.ProjectPath,
1566+
Path.GetFileNameWithoutExtension(settings.MainFile)
1567+
},
1568+
project.ProjectPath,
1569+
outLog.Writer))
1570+
{
1571+
outLog.Writer.WriteLine("Error executing custom emulator launcher.");
1572+
}
1573+
Dispatcher.UIThread.InvokeAsync(() =>
15501574
{
1551-
if (loadedProgram.Disassembly == null)
1575+
UnblockEditors();
1576+
EmulatorInfo.CanDebug = FileInfo.ProjectLoaded;
1577+
EmulatorInfo.CanRun = FileInfo.ProjectLoaded;
1578+
});
1579+
}
1580+
else
1581+
{
1582+
loadedProgram = program;
1583+
var disas = openDocuments.FirstOrDefault(e => e.DocumentPath == ZXConstants.DISASSEMBLY_DOC) as ZXTextEditor;
1584+
1585+
Dispatcher.UIThread.InvokeAsync(async () =>
1586+
{
1587+
if (disas != null)
15521588
{
1553-
var parent = disas.Parent as TabItem;
1554-
if (parent != null)
1589+
if (loadedProgram.Disassembly == null)
15551590
{
1556-
parent.IsSelected = true;
1557-
CloseFile(null, e);
1591+
var parent = disas.Parent as TabItem;
1592+
if (parent != null)
1593+
{
1594+
parent.IsSelected = true;
1595+
CloseFile(null, e);
1596+
}
15581597
}
1598+
else
1599+
disas.Text = loadedProgram.Disassembly.Content;
15591600
}
1560-
else
1561-
disas.Text = loadedProgram.Disassembly.Content;
1562-
}
15631601

1564-
if (!emu.InjectProgram(program.Org, program.Binary, program.Banks?.ToArray(), true))
1565-
{
1566-
await this.ShowError("Error", "Cannot inject program! Check program size and address.");
1567-
}
1568-
else
1569-
{
1570-
emuDock.Select();
1571-
emu.Focus();
1572-
}
1573-
EmulatorInfo.CanDebug = FileInfo.ProjectLoaded;
1574-
EmulatorInfo.CanRun = FileInfo.ProjectLoaded;
1575-
});
1602+
if (!emu.InjectProgram(program.Org, program.Binary, program.Banks?.ToArray(), true))
1603+
{
1604+
await this.ShowError("Error", "Cannot inject program! Check program size and address.");
1605+
}
1606+
else
1607+
{
1608+
emuDock.Select();
1609+
emu.Focus();
1610+
}
1611+
EmulatorInfo.CanDebug = FileInfo.ProjectLoaded;
1612+
EmulatorInfo.CanRun = FileInfo.ProjectLoaded;
1613+
});
1614+
}
15761615
}
15771616
else
15781617
{

0 commit comments

Comments
 (0)